From a486bae55a9bc98446a1a34606a1f4ae6c4a0387 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 7 Feb 2022 18:09:42 +0100 Subject: [PATCH] sc_vfs: print file size This prints the size of the displayed files in `ls`. It also makes it easier to distinguis files from directories. --- sys/shell/commands/sc_vfs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sys/shell/commands/sc_vfs.c b/sys/shell/commands/sc_vfs.c index 4fe2af77d1..b1d38dc714 100644 --- a/sys/shell/commands/sc_vfs.c +++ b/sys/shell/commands/sc_vfs.c @@ -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);