Skip to content

Commit 96a4258

Browse files
committed
Added the lfs_stat function
1 parent a3734ee commit 96a4258

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lfs.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,3 +1376,31 @@ int lfs_remove(lfs_t *lfs, const char *path) {
13761376
return 0;
13771377
}
13781378

1379+
int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info) {
1380+
lfs_dir_t cwd;
1381+
int err = lfs_dir_fetch(lfs, &cwd, lfs->cwd);
1382+
if (err) {
1383+
return err;
1384+
}
1385+
1386+
lfs_entry_t entry;
1387+
err = lfs_dir_find(lfs, &cwd, &path, &entry);
1388+
if (err) {
1389+
return err;
1390+
}
1391+
1392+
// TODO abstract out info assignment
1393+
memset(info, 0, sizeof(*info));
1394+
info->type = entry.d.type & 0xff;
1395+
if (info->type == LFS_TYPE_REG) {
1396+
info->size = entry.d.u.file.size;
1397+
}
1398+
1399+
err = lfs_bd_read(lfs, entry.dir[0], entry.off + sizeof(entry.d),
1400+
entry.d.len - sizeof(entry.d), info->name);
1401+
if (err) {
1402+
return err;
1403+
}
1404+
1405+
return 0;
1406+
}

lfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *config);
138138
int lfs_unmount(lfs_t *lfs);
139139

140140
int lfs_remove(lfs_t *lfs, const char *path);
141+
int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
141142

142143
int lfs_mkdir(lfs_t *lfs, const char *path);
143144
int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path);

0 commit comments

Comments
 (0)