From: Karel Zak Date: Fri, 13 Jan 2017 12:30:22 +0000 (+0100) Subject: partx: add --sector-size option X-Git-Tag: v2.30-rc1~304 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8a4a0d4f2fd569252029bd004e24ee433b43fe8;p=thirdparty%2Futil-linux.git partx: add --sector-size option /dev/sdc is 4K disk: # fdisk -l /dev/sdc Disk /dev/sdc: 100 MiB, 104857600 bytes, 25600 sectors ... Device Boot Start End Sectors Size Id Type /dev/sdc1 1024 25599 24576 96M 83 Linux let's use it as disk image: # dd if=/dev/sdc of=~/sdc.img # losetup -f ~/sdc.img old version: # partx --show /dev/loop0 NR START END SECTORS SIZE NAME UUID 1 1024 25599 24576 12M 6a4ba75b-01 new version: # partx --show /dev/loop0 --sector-size 4096 NR START END SECTORS SIZE NAME UUID 1 8192 204799 196608 96M 6a4ba75b-01 Addresses: https://github.com/karelzak/util-linux/issues/396 Signed-off-by: Karel Zak --- diff --git a/disk-utils/partx.8 b/disk-utils/partx.8 index 7ff9b27f3b..0d47f1c54e 100644 --- a/disk-utils/partx.8 +++ b/disk-utils/partx.8 @@ -136,6 +136,9 @@ or .BR \-u , " \-\-update" Update the specified partitions. .TP +.BR \-S , " \-\-sector\-size " \fIsize +Overwrite default sector size. +.TP .BR \-v , " \-\-verbose" Verbose mode. .TP diff --git a/disk-utils/partx.c b/disk-utils/partx.c index d74a52a6ea..7442100f33 100644 --- a/disk-utils/partx.c +++ b/disk-utils/partx.c @@ -766,6 +766,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(_(" -o, --output define which output columns to use\n"), out); fputs(_(" -P, --pairs use key=\"value\" output format\n"), out); fputs(_(" -r, --raw use raw output format\n"), out); + fputs(_(" -S, --sector-size overwrite sector size\n"), out); fputs(_(" -t, --type specify the partition type (dos, bsd, solaris, etc.)\n"), out); fputs(_(" -v, --verbose verbose mode\n"), out); @@ -792,6 +793,7 @@ int main(int argc, char **argv) char *wholedisk = NULL; /* allocated, ie: /dev/sda */ char *outarg = NULL; dev_t disk_devno = 0, part_devno = 0; + unsigned int sector_size = 0; static const struct option long_opts[] = { { "bytes", no_argument, NULL, 'b' }, @@ -806,6 +808,7 @@ int main(int argc, char **argv) { "nr", required_argument, NULL, 'n' }, { "output", required_argument, NULL, 'o' }, { "pairs", no_argument, NULL, 'P' }, + { "sector-size",required_argument, NULL, 'S' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { "verbose", no_argument, NULL, 'v' }, @@ -824,7 +827,7 @@ int main(int argc, char **argv) atexit(close_stdout); while ((c = getopt_long(argc, argv, - "abdglrsuvn:t:o:PhV", long_opts, NULL)) != -1) { + "abdglrsuvn:t:o:PS:hV", long_opts, NULL)) != -1) { err_exclusive_options(c, long_opts, excl, excl_st); @@ -862,6 +865,9 @@ int main(int argc, char **argv) case 's': what = ACT_SHOW; break; + case 'S': + sector_size = strtou32_or_err(optarg, _("invalid sector size argument")); + break; case 't': type = optarg; break; @@ -1001,8 +1007,12 @@ int main(int argc, char **argv) if (!pr || blkid_probe_set_device(pr, fd, 0, 0)) warnx(_("%s: failed to initialize blkid prober"), wholedisk); - else + else { + if (sector_size) + blkid_probe_set_sectorsize(pr, sector_size); + ls = get_partlist(pr, wholedisk, type); + } if (ls) { switch (what) {