Skip to content

Commit

Permalink
Merge pull request #14394 from sven-hm/fatfs_vfs_fstat
Browse files Browse the repository at this point in the history
pkg/fatfs/fatfs_vfs: fix _fstat
  • Loading branch information
benpicco committed Jun 30, 2020
2 parents 2250c67 + 75a9ad0 commit e1d27cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 0 additions & 3 deletions pkg/fatfs/fatfs_vfs/fatfs_vfs.c
Expand Up @@ -257,13 +257,10 @@ static off_t _lseek(vfs_file_t *filp, off_t off, int whence)

static int _fstat(vfs_file_t *filp, struct stat *buf)
{
fatfs_file_desc_t *fd = (fatfs_file_desc_t *)filp->private_data.buffer;
fatfs_desc_t *fs_desc = (fatfs_desc_t *)filp->mp->private_data;
FILINFO fi;
FRESULT res;

_build_abs_path(fs_desc, fd->fname);

memset(buf, 0, sizeof(*buf));

res = f_stat(fs_desc->abs_path_str_buff, &fi);
Expand Down
22 changes: 22 additions & 0 deletions tests/pkg_fatfs_vfs/main.c
Expand Up @@ -304,6 +304,27 @@ static void test_create(void)
print_test_result("test_create__umount", vfs_umount(&_test_vfs_mount) == 0);
}

static void test_fstat(void)
{
int fd;
struct stat stat_buf;

print_test_result("test_stat__mount", vfs_mount(&_test_vfs_mount) == 0);

fd = vfs_open(FULL_FNAME1, O_WRONLY | O_TRUNC, 0);
print_test_result("test_stat__open", fd >= 0);
print_test_result("test_stat__write",
vfs_write(fd, test_txt, sizeof(test_txt)) == sizeof(test_txt));
print_test_result("test_stat__close", vfs_close(fd) == 0);

fd = vfs_open(FULL_FNAME1, O_RDONLY, 0);
print_test_result("test_stat__open", fd >= 0);
print_test_result("test_stat__stat", vfs_fstat(fd, &stat_buf) == 0);
print_test_result("test_stat__close", vfs_close(fd) == 0);
print_test_result("test_stat__size", stat_buf.st_size == sizeof(test_txt));
print_test_result("test_stat__umount", vfs_umount(&_test_vfs_mount) == 0);
}

#ifdef MODULE_NEWLIB
static void test_newlib(void)
{
Expand Down Expand Up @@ -399,6 +420,7 @@ int main(void)
test_unlink();
test_mkrmdir();
test_create();
test_fstat();
#ifdef MODULE_NEWLIB
test_newlib();
#endif
Expand Down

0 comments on commit e1d27cb

Please sign in to comment.