]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
partx: add --sector-size option
authorKarel Zak <kzak@redhat.com>
Fri, 13 Jan 2017 12:30:22 +0000 (13:30 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Jan 2017 12:30:22 +0000 (13:30 +0100)
/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 <kzak@redhat.com>
disk-utils/partx.8
disk-utils/partx.c

index 7ff9b27f3bc2e04c52b012940c1eafe1a512dde5..0d47f1c54e2e81f48206e463dffe1274d7ebf2e4 100644 (file)
@@ -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
index d74a52a6ea5ee4e6e39073167ecba01fa872370b..7442100f33b1ca2ab68853eee7cd2a5ea2092d35 100644 (file)
@@ -766,6 +766,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(_(" -o, --output <list>  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 <num>  overwrite sector size\n"), out);
        fputs(_(" -t, --type <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) {