2018-07-19 08:42:12 +01:00
|
|
|
#include "devoptab_fs.h"
|
2018-05-27 12:11:45 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
__wut_fs_dirnext(struct _reent *r,
|
|
|
|
DIR_ITER *dirState,
|
|
|
|
char *filename,
|
|
|
|
struct stat *filestat)
|
|
|
|
{
|
2018-10-06 10:41:24 +01:00
|
|
|
FSStatus status;
|
|
|
|
FSCmdBlock cmd;
|
|
|
|
__wut_fs_dir_t *dir;
|
2018-05-27 12:11:45 +01:00
|
|
|
|
2018-10-06 10:41:24 +01:00
|
|
|
if (!dirState || !filename || !filestat) {
|
|
|
|
r->_errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2018-05-27 12:11:45 +01:00
|
|
|
|
2018-10-06 10:41:24 +01:00
|
|
|
FSInitCmdBlock(&cmd);
|
|
|
|
dir = (__wut_fs_dir_t *)(dirState->dirStruct);
|
2018-05-27 12:11:45 +01:00
|
|
|
memset(&dir->entry_data, 0, sizeof(dir->entry_data));
|
2018-10-06 10:41:24 +01:00
|
|
|
status = FSReadDir(__wut_devoptab_fs_client, &cmd, dir->fd, &dir->entry_data,
|
|
|
|
-1);
|
|
|
|
if (status < 0) {
|
|
|
|
r->_errno = __wut_fs_translate_error(status);
|
2018-05-27 12:11:45 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-06 10:41:24 +01:00
|
|
|
// Fill in the stat info
|
|
|
|
memset(filestat, 0, sizeof(struct stat));
|
|
|
|
filestat->st_ino = 0;
|
2018-05-27 12:11:45 +01:00
|
|
|
|
2018-10-06 10:41:24 +01:00
|
|
|
if (dir->entry_data.info.flags & FS_STAT_DIRECTORY) {
|
|
|
|
filestat->st_mode = S_IFDIR;
|
|
|
|
} else {
|
|
|
|
filestat->st_mode = S_IFREG;
|
2018-05-27 12:11:45 +01:00
|
|
|
}
|
|
|
|
|
2018-10-06 10:41:24 +01:00
|
|
|
filestat->st_uid = dir->entry_data.info.owner;
|
|
|
|
filestat->st_gid = dir->entry_data.info.group;
|
|
|
|
filestat->st_size = dir->entry_data.info.size;
|
|
|
|
|
|
|
|
memset(filename, 0, NAME_MAX);
|
|
|
|
strcpy(filename, dir->entry_data.name);
|
|
|
|
return 0;
|
2018-05-27 12:11:45 +01:00
|
|
|
}
|