wut/libraries/wutdevoptab/devoptab_fs_stat.c
James Benton 690bd6ccbd Revert "Rename wutdevoptab to wutdevoptab_sd"
This reverts commit 865af4609c49015c64f4092fd53315a1110b8042.
Turns out it is for whole filesystem. oops.
2018-07-19 08:51:40 +01:00

43 lines
1013 B
C

#include "devoptab_fs.h"
int
__wut_fs_stat(struct _reent *r,
const char *file,
struct stat *st)
{
int fd;
FSStatus rc;
if (file == NULL) {
return -1;
}
// Set up command block
FSCmdBlock fsCmd;
FSInitCmdBlock(&fsCmd);
// First try open as file
rc = FSOpenFile(__wut_devoptab_fs_client, &fsCmd, file, "r", (FSFileHandle*)&fd, -1);
if (rc >= 0) {
__wut_fs_file_t tmpfd = { .fd = fd };
rc = __wut_fs_fstat(r, &tmpfd, st);
FSCloseFile(__wut_devoptab_fs_client, &fsCmd, fd, -1);
return rc;
}
// File failed, so lets try open as directory
rc = FSOpenDir(__wut_devoptab_fs_client, &fsCmd, file, (FSDirectoryHandle*)&fd, -1);
if (rc >= 0) {
memset(st, 0, sizeof(struct stat));
st->st_nlink = 1;
st->st_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO;
FSCloseDir(__wut_devoptab_fs_client, &fsCmd, fd, -1);
return 0;
}
r->_errno = __wut_fs_translate_error(rc);
return -1;
}