diff options
| author | Karel Zak <kzak@redhat.com> | 2024-10-14 15:50:40 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2024-10-14 15:50:40 +0200 |
| commit | ef7b76baa17ddb5414691fa8f49d61415c30871c (patch) | |
| tree | 8a069211b5a2b71386a525e7f60c3c96c357b91a /disk-utils/sfdisk.c | |
| parent | fd38ee2274f7a30393d3839dfce556260355c3fa (diff) | |
| download | util-linux-ef7b76baa17ddb5414691fa8f49d61415c30871c.tar.gz | |
sfdisk: add --sector-size commanand line option
* improves compatibility with fdisk
* add ability to work with disk images where libfdisk defaults to 512
Addresses: https://github.com/util-linux/util-linux/pull/3235
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/sfdisk.c')
| -rw-r--r-- | disk-utils/sfdisk.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index cf402007b5..5e7c1d926e 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -2155,6 +2155,8 @@ static void __attribute__((__noreturn__)) usage(void) _(" --color[=<when>] colorize output (%s, %s or %s)\n"), "auto", "always", "never"); fprintf(out, " %s\n", USAGE_COLORS_DEFAULT); + fputs(_(" --sector-size <size> physical and logical sector size\n"), out); + fprintf(out, _(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock"); fputs(_(" -N, --partno <num> specify partition number\n"), out); @@ -2191,6 +2193,7 @@ int main(int argc, char *argv[]) const char *outarg = NULL; int rc = -EINVAL, c, longidx = -1, bytes = 0; int colormode = UL_COLORMODE_UNDEF; + size_t user_ss = 0; struct sfdisk _sf = { .partno = -1, .wipemode = WIPEMODE_AUTO, @@ -2217,6 +2220,7 @@ int main(int argc, char *argv[]) OPT_NOTELL, OPT_RELOCATE, OPT_LOCK, + OPT_SECTORSIZE }; static const struct option longopts[] = { @@ -2246,6 +2250,7 @@ int main(int argc, char *argv[]) { "output", required_argument, NULL, 'o' }, { "partno", required_argument, NULL, 'N' }, { "reorder", no_argument, NULL, 'r' }, + { "sector-size", required_argument, NULL, OPT_SECTORSIZE }, { "show-geometry", no_argument, NULL, 'g' }, { "quiet", no_argument, NULL, 'q' }, { "verify", no_argument, NULL, 'V' }, @@ -2450,6 +2455,13 @@ int main(int argc, char *argv[]) sf->lockmode = optarg; } break; + case OPT_SECTORSIZE: + user_ss = strtou32_or_err(optarg, + _("invalid sector size argument")); + if (user_ss != 512 && user_ss != 1024 && + user_ss != 2048 && user_ss != 4096) + errx(EXIT_FAILURE, _("invalid sector size argument")); + break; default: errtryhelp(EXIT_FAILURE); } @@ -2460,6 +2472,8 @@ int main(int argc, char *argv[]) sfdisk_init(sf); if (bytes) fdisk_set_size_unit(sf->cxt, FDISK_SIZEUNIT_BYTES); + if (user_ss) + fdisk_save_user_sector_size(sf->cxt, user_ss, user_ss); if (outarg) init_fields(NULL, outarg, NULL); |
