From c7fcffd09a4130f0bd1607c2ebdc3c66b168b7fa Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 11 Apr 2022 13:58:04 +0900 Subject: [PATCH] nshlib/nsh_fscmds.c: Make losetup command take optional sector size --- nshlib/nsh_command.c | 3 ++- nshlib/nsh_fscmds.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index 0f8bf8680..61fef3d18 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -278,7 +278,8 @@ static const struct cmdmap_s g_cmdmap[] = #ifndef CONFIG_DISABLE_MOUNTPOINT # if defined(CONFIG_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOSETUP) { "losetup", cmd_losetup, 3, 6, - "[-d ] | [[-o ] [-r] ]" }, + "[-d ] | [[-o ] [-r] [-s ] " + " ]" }, # endif #endif diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index 572753e6f..45c6f64ac 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -670,6 +670,7 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) bool teardown = false; bool readonly = false; off_t offset = 0; + int sectsize = 512; bool badarg = false; int ret = ERROR; int option; @@ -678,13 +679,13 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) /* Get the losetup options: Two forms are supported: * * losetup -d - * losetup [-o ] [-r] + * losetup [-o ] [-r] [-s ] * * NOTE that the -o and -r options are accepted with the -d option, but * will be ignored. */ - while ((option = getopt(argc, argv, "d:o:r")) != ERROR) + while ((option = getopt(argc, argv, "d:o:rs:")) != ERROR) { switch (option) { @@ -701,6 +702,10 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) readonly = true; break; + case 's': + sectsize = atoi(optarg); + break; + case '?': default: nsh_error(vtbl, g_fmtarginvalid, argv[0]); @@ -777,7 +782,7 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) setup.devname = loopdev; /* The loop block device to be created */ setup.filename = filepath; /* The file or character device to use */ - setup.sectsize = 512; /* The sector size to use with the block device */ + setup.sectsize = sectsize; /* The sector size to use with the block device */ setup.offset = offset; /* An offset that may be applied to the device */ setup.readonly = readonly; /* True: Read access will be supported only */