1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 14:33:52 +01:00

Merge pull request #14394 from sven-hm/fatfs_vfs_fstat

pkg/fatfs/fatfs_vfs: fix _fstat
This commit is contained in:
benpicco 2020-06-30 18:30:26 +02:00 committed by GitHub
commit e1d27cb7d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -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);

View File

@ -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)
{
@ -399,6 +420,7 @@ int main(void)
test_unlink();
test_mkrmdir();
test_create();
test_fstat();
#ifdef MODULE_NEWLIB
test_newlib();
#endif