mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Added the lfs_stat function
This commit is contained in:
		
							
								
								
									
										28
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -1376,3 +1376,31 @@ int lfs_remove(lfs_t *lfs, const char *path) { | |||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info) { | ||||||
|  |     lfs_dir_t cwd; | ||||||
|  |     int err = lfs_dir_fetch(lfs, &cwd, lfs->cwd); | ||||||
|  |     if (err) { | ||||||
|  |         return err; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     lfs_entry_t entry; | ||||||
|  |     err = lfs_dir_find(lfs, &cwd, &path, &entry); | ||||||
|  |     if (err) { | ||||||
|  |         return err; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // TODO abstract out info assignment | ||||||
|  |     memset(info, 0, sizeof(*info)); | ||||||
|  |     info->type = entry.d.type & 0xff; | ||||||
|  |     if (info->type == LFS_TYPE_REG) { | ||||||
|  |         info->size = entry.d.u.file.size; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     err = lfs_bd_read(lfs, entry.dir[0], entry.off + sizeof(entry.d), | ||||||
|  |             entry.d.len - sizeof(entry.d), info->name); | ||||||
|  |     if (err) { | ||||||
|  |         return err; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								lfs.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								lfs.h
									
									
									
									
									
								
							| @@ -138,6 +138,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *config); | |||||||
| int lfs_unmount(lfs_t *lfs); | int lfs_unmount(lfs_t *lfs); | ||||||
|  |  | ||||||
| int lfs_remove(lfs_t *lfs, const char *path); | int lfs_remove(lfs_t *lfs, const char *path); | ||||||
|  | int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info); | ||||||
|  |  | ||||||
| int lfs_mkdir(lfs_t *lfs, const char *path); | int lfs_mkdir(lfs_t *lfs, const char *path); | ||||||
| int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path); | int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user