Skip to content

Commit 2a6d692

Browse files
utsavm9kartben
authored andcommitted
fs: Shell command ls to list file sizes
List the file size helps in developer debugging experience. Provide a config to disable new behavior in case any users depended on command output to be a list. Signed-off-by: Utsav Munendra <[email protected]>
1 parent 8e63bbd commit 2a6d692

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

doc/releases/release-notes-4.3.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ New APIs and options
189189
* :kconfig:option:`CONFIG_SHELL_MQTT_WORK_DELAY_MS`
190190
* :kconfig:option:`CONFIG_SHELL_MQTT_LISTEN_TIMEOUT_MS`
191191

192+
* Storage
193+
194+
* :kconfig:option:`CONFIG_FILE_SYSTEM_SHELL_LS_SIZE`
195+
192196
* Sys
193197

194198
* :c:func:`sys_count_bits`

subsys/fs/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ config FILE_SYSTEM_SHELL_BUFFER_SIZE
8585
maximum size that can be used with a read/write test. Note that this
8686
is used on the stack.
8787

88+
config FILE_SYSTEM_SHELL_LS_SIZE
89+
bool "File system shell ls command to also list size"
90+
default y
91+
help
92+
While listing files in the file system shell, also list the size of
93+
each file.
94+
8895
endif # FILE_SYSTEM_SHELL
8996

9097
config FILE_SYSTEM_MKFS

subsys/fs/shell.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ static int cmd_ls(const struct shell *sh, size_t argc, char **argv)
188188

189189
while (1) {
190190
struct fs_dirent entry;
191+
const char *name_end;
191192

192193
err = fs_readdir(&dir, &entry);
193194
if (err != 0) {
@@ -200,7 +201,12 @@ static int cmd_ls(const struct shell *sh, size_t argc, char **argv)
200201
break;
201202
}
202203

203-
shell_print(sh, "%s%s", entry.name, (entry.type == FS_DIR_ENTRY_DIR) ? "/" : "");
204+
name_end = (entry.type == FS_DIR_ENTRY_DIR) ? "/" : "";
205+
if (IS_ENABLED(CONFIG_FILE_SYSTEM_SHELL_LS_SIZE)) {
206+
shell_print(sh, "%8zu %s%s", entry.size, entry.name, name_end);
207+
} else {
208+
shell_print(sh, "%s%s", entry.name, name_end);
209+
}
204210
}
205211

206212
fs_closedir(&dir);

0 commit comments

Comments
 (0)