File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -1376,3 +1376,31 @@ int lfs_remove(lfs_t *lfs, const char *path) {
1376
1376
return 0 ;
1377
1377
}
1378
1378
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
+ }
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *config);
138
138
int lfs_unmount (lfs_t * lfs );
139
139
140
140
int lfs_remove (lfs_t * lfs , const char * path );
141
+ int lfs_stat (lfs_t * lfs , const char * path , struct lfs_info * info );
141
142
142
143
int lfs_mkdir (lfs_t * lfs , const char * path );
143
144
int lfs_dir_open (lfs_t * lfs , lfs_dir_t * dir , const char * path );
You can’t perform that action at this time.
0 commit comments