]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sfdisk: add --list-free
authorKarel Zak <kzak@redhat.com>
Tue, 28 Jul 2015 13:54:07 +0000 (15:54 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 28 Jul 2015 13:54:07 +0000 (15:54 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
bash-completion/sfdisk
disk-utils/sfdisk.8
disk-utils/sfdisk.c

index 16ada3f19039c27cf791cf4453a48f208ab8f11f..9128313ee766a49f2d0d06498aa6f3a059cbc0ca 100644 (file)
@@ -33,6 +33,7 @@ _sfdisk_module()
                                --change-id
                                --print-id
                                --list
+                               --list-free
                                --dump
                                --increment
                                --unit
index 671dc2e4b06aaaa63425d98bf7b90704c30e6611..b5fdcc5dc5d78906cbf2ad90fe6ca2f79d18a613 100644 (file)
@@ -85,6 +85,9 @@ not able to use JSON as input format.
 List the partitions of all or the specified devices.  This command can be used
 together with \fB\-\-verify\fR.
 .TP
+.BR \-F , " \-\-list-free " [ \fIdevice ...]
+List the free unpartitioned areas on all or the specified devices.
+.TP
 .BR \-\-part\-attrs " \fIdevice partno [" \fIattrs ]
 Change the GPT partition attribute bits.  If \fIattrs\fR is not specified,
 then print the current partition settings.  The \fIattrs\fR argument is a
index e1d5e5acff7aae7bab41d948eebdf6789e9f4d12..d3b9baa30e371b3019802e5d4ddfed85d2e2aacd 100644 (file)
@@ -71,6 +71,7 @@ enum {
        ACT_CHANGE_ID,
        ACT_DUMP,
        ACT_LIST,
+       ACT_LIST_FREE,
        ACT_LIST_TYPES,
        ACT_SHOW_SIZE,
        ACT_SHOW_GEOM,
@@ -360,6 +361,28 @@ static int command_list_partitions(struct sfdisk *sf, int argc, char **argv)
        return 0;
 }
 
+/*
+ * sfdisk --list-free [<device ..]
+ */
+static int command_list_freespace(struct sfdisk *sf, int argc, char **argv)
+{
+       fdisk_enable_listonly(sf->cxt, 1);
+
+       if (argc) {
+               int i, ct = 0;
+
+               for (i = 0; i < argc; i++) {
+                       if (ct)
+                               fputs("\n\n", stdout);
+                       if (print_device_freespace(sf->cxt, argv[i], 0) == 0)
+                               ct++;
+               }
+       } else
+               print_all_devices_freespace(sf->cxt);
+
+       return 0;
+}
+
 /*
  * sfdisk --list-types
  */
@@ -1413,6 +1436,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
        fputs(_(" -J, --json <dev>                  dump partition table in JSON format\n"), out);
        fputs(_(" -g, --show-geometry [<dev> ...]   list geometry of all or specified devices\n"), out);
        fputs(_(" -l, --list [<dev> ...]            list partitions of each device\n"), out);
+       fputs(_(" -F, --list-free [<dev> ...]       list unpartitions free areas of each device\n"), out);
        fputs(_(" -s, --show-size [<dev> ...]       list sizes of all or specified devices\n"), out);
        fputs(_(" -T, --list-types                  print the recognized types (see -X)\n"), out);
        fputs(_(" -V, --verify [<dev> ...]          test whether partitions seem correct\n"), out);
@@ -1496,6 +1520,7 @@ int main(int argc, char *argv[])
                { "label",   required_argument, NULL, 'X' },
                { "label-nested", required_argument, NULL, 'Y' },
                { "list",    no_argument,       NULL, 'l' },
+               { "list-free", no_argument,     NULL, 'F' },
                { "list-types", no_argument,    NULL, 'T' },
                { "no-act",  no_argument,       NULL, 'n' },
                { "no-reread", no_argument,     NULL, OPT_NOREREAD },
@@ -1527,7 +1552,7 @@ int main(int argc, char *argv[])
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       while ((c = getopt_long(argc, argv, "aAbcdfghJlLo:O:nN:qsTu:vVX:Y:",
+       while ((c = getopt_long(argc, argv, "aAbcdfFghJlLo:O:nN:qsTu:vVX:Y:",
                                        longopts, &longidx)) != -1) {
                switch(c) {
                case 'A':
@@ -1556,6 +1581,9 @@ int main(int argc, char *argv[])
                case 'd':
                        sf->act = ACT_DUMP;
                        break;
+               case 'F':
+                       sf->act = ACT_LIST_FREE;
+                       break;
                case 'f':
                        sf->force = 1;
                        break;
@@ -1667,6 +1695,10 @@ int main(int argc, char *argv[])
                rc = command_list_types(sf);
                break;
 
+       case ACT_LIST_FREE:
+               rc = command_list_freespace(sf, argc - optind, argv + optind);
+               break;
+
        case ACT_FDISK:
                rc = command_fdisk(sf, argc - optind, argv + optind);
                break;