I just implemented the littlefs and it would be great to have a function to list a directory with the following result:
Hi @guillaumerems, glad to hear you were able to get littlefs working.
You can use the lfs_dir* functions to list a directory like this:
int lfs_ls(lfs_t *lfs, const char *path) {
lfs_dir_t dir;
int err = lfs_dir_open(lfs, &dir, path);
if (err) {
return err;
}
struct lfs_info info;
while (true) {
int res = lfs_dir_read(lfs, &dir, &info);
if (res < 0) {
return res;
}
if (res == 0) {
break;
}
switch (info.type) {
case LFS_TYPE_REG: printf("reg "); break;
case LFS_TYPE_DIR: printf("dir "); break;
default: printf("? "); break;
}
static const char *prefixes[] = {"", "K", "M", "G"};
for (int i = sizeof(prefixes)/sizeof(prefixes[0])-1; i >= 0; i--) {
if (info.size >= (1 << 10*i)-1) {
printf("%*u%sB ", 4-(i != 0), info.size >> 10*i, prefixes[i]);
break;
}
}
printf("%s\n", info.name);
}
err = lfs_dir_close(lfs, &dir);
if (err) {
return err;
}
return 0;
}
lfs_ls(&lfs, "/");
However, there are many different ways to list a directory, so this function probably won't end up in this repo.
This repo's goal is to provide a simple low-level (posix-like) implementation of littlefs that contains all of the core functionality needed for a filesystem. User-friendly bash functions (such as ls, cp, recursive remove) are left up to higher-level APIs.
Thanks @geky it works perfectly
I will continue the tests
Most helpful comment
Thanks @geky it works perfectly
I will continue the tests