1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

Merge pull request #17622 from benpicco/sys/shell-ls_size

sc_vfs: print file size
This commit is contained in:
benpicco 2022-02-08 16:11:05 +01:00 committed by GitHub
commit 28fa5c72a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -517,7 +517,10 @@ int _ls_handler(int argc, char **argv)
unsigned int nfiles = 0;
while (1) {
char path_name[2 * (VFS_NAME_MAX + 1)];
vfs_dirent_t entry;
struct stat stat;
res = vfs_readdir(&dir, &entry);
if (res < 0) {
_errno_string(res, (char *)buf, sizeof(buf));
@ -533,8 +536,15 @@ int _ls_handler(int argc, char **argv)
/* end of stream */
break;
}
printf("%s\n", entry.d_name);
++nfiles;
snprintf(path_name, sizeof(path_name), "%s/%s", path, entry.d_name);
vfs_stat(path_name, &stat);
if (stat.st_mode & S_IFDIR) {
printf("%s/\n", entry.d_name);
} else if (stat.st_mode & S_IFREG) {
printf("%s\t%lu B\n", entry.d_name, stat.st_size);
++nfiles;
}
}
if (ret == 0) {
printf("total %u files\n", nfiles);