Commit 2a6d6929 authored by Utsav Munendra's avatar Utsav Munendra Committed by Benjamin Cabé
Browse files

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: default avatarUtsav Munendra <utsavm@meta.com>
parent 8e63bbd6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -189,6 +189,10 @@ New APIs and options
      * :kconfig:option:`CONFIG_SHELL_MQTT_WORK_DELAY_MS`
      * :kconfig:option:`CONFIG_SHELL_MQTT_LISTEN_TIMEOUT_MS`

* Storage

    * :kconfig:option:`CONFIG_FILE_SYSTEM_SHELL_LS_SIZE`

* Sys

  * :c:func:`sys_count_bits`
+7 −0
Original line number Diff line number Diff line
@@ -85,6 +85,13 @@ config FILE_SYSTEM_SHELL_BUFFER_SIZE
	  maximum size that can be used with a read/write test. Note that this
	  is used on the stack.

config FILE_SYSTEM_SHELL_LS_SIZE
	bool "File system shell ls command to also list size"
	default y
	help
	  While listing files in the file system shell, also list the size of
	  each file.

endif # FILE_SYSTEM_SHELL

config FILE_SYSTEM_MKFS
+7 −1
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ static int cmd_ls(const struct shell *sh, size_t argc, char **argv)

	while (1) {
		struct fs_dirent entry;
		const char *name_end;

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

		shell_print(sh, "%s%s", entry.name, (entry.type == FS_DIR_ENTRY_DIR) ? "/" : "");
		name_end = (entry.type == FS_DIR_ENTRY_DIR) ? "/" : "";
		if (IS_ENABLED(CONFIG_FILE_SYSTEM_SHELL_LS_SIZE)) {
			shell_print(sh, "%8zu %s%s", entry.size, entry.name, name_end);
		} else {
			shell_print(sh, "%s%s", entry.name, name_end);
		}
	}

	fs_closedir(&dir);