]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkid: list all known filesystems/RAIDs (add -k option)
authorKarel Zak <kzak@redhat.com>
Mon, 20 Jun 2011 14:42:03 +0000 (16:42 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Jun 2011 14:42:03 +0000 (16:42 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/blkid.h.in
libblkid/src/blkid.sym
libblkid/src/superblocks/superblocks.c
misc-utils/blkid.8
misc-utils/blkid.c

index 05527bed88aa9dc5f8a2dbaac88f87b726483f0e..c145ccfd37ddaea7bd8edab81120ba9796204480 100644 (file)
@@ -212,6 +212,8 @@ extern int blkid_probe_get_fd(blkid_probe pr);
  * superblocks probing
  */
 extern int blkid_known_fstype(const char *fstype);
+extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage);
+
 extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable);
 
 #define BLKID_SUBLKS_LABEL     (1 << 1) /* read LABEL from superblock */
index e758ff1a60158e2f1f3394e074b397221e641ba0..fda27ea2b3721ba24d3cf10776309cc9ca536555 100644 (file)
@@ -137,5 +137,6 @@ global:
 BLKID_2.20 {
 global:
        blkid_evaluate_spec;
+       blkid_superblocks_get_name;
 } BLKID_2.18;
 
index 06aa5facd1061ca0e89913d2b2d0917eaf014c49..e177667d2c9881d95ce19d87225c92bd01e2f400 100644 (file)
@@ -294,6 +294,26 @@ int blkid_known_fstype(const char *fstype)
        return 0;
 }
 
+/**
+ * blkid_superblocks_get_name:
+ * @idx: number >= 0
+ * @name: returns name of supported filesystem/raid (optional)
+ * @usage: returns BLKID_USAGE_* flags, (optional)
+ *
+ * Returns: -1 if @idx is out of range, or 0 on success.
+ */
+int blkid_superblocks_get_name(size_t idx, const char **name, int *usage)
+{
+       if (idx >= 0 && idx < ARRAY_SIZE(idinfos)) {
+               if (name)
+                       *name = idinfos[idx]->name;
+               if (usage)
+                       *usage = idinfos[idx]->usage;
+               return 0;
+       }
+       return -1;
+}
+
 /*
  * The blkid_do_probe() backend.
  */
index 92fd3854faf2a8d3bbfe0713fbb5c462ea6a9569..299fbd4fcc4cb52a7e4211224050605df026f9ff 100644 (file)
@@ -102,6 +102,10 @@ automatically enabled.  This option can be used together with the \fB-p\fR optio
 .TP
 .B \-l
 Look up only one device that matches the search parameter specified with the
+.TP
+.B \-k
+List all known filesystems and RAIDs and exit.
+.TP
 .B \-t
 option.  If there are multiple devices that match the specified search
 parameter, then the device with the highest priority is returned, and/or
index 35b3cd4b9647b4135794dff5d8b3c72107e4c203..da13fa941223ea741688b2fa4184dd33130eeaf6 100644 (file)
@@ -73,6 +73,7 @@ static void usage(int error)
                "  -g          garbage collect the blkid cache\n"
                "  -o <format> output format; can be one of:\n"
                "              value, device, list, udev, export or full; (default: full)\n"
+               "  -k          list all known filesystems/RAIDs and exit\n"
                "  -s <tag>    show specified tag(s) (default show all tags)\n"
                "  -t <token>  find device with a specific token (NAME=value pair)\n"
                "  -l          look up only first device with token specified by -t\n"
@@ -690,7 +691,7 @@ int main(int argc, char **argv)
 
        show[0] = NULL;
 
-       while ((c = getopt (argc, argv, "c:df:ghilL:n:o:O:ps:S:t:u:U:w:v")) != EOF)
+       while ((c = getopt (argc, argv, "c:df:ghilL:n:ko:O:ps:S:t:u:U:w:v")) != EOF)
                switch (c) {
                case 'c':
                        if (optarg && !*optarg)
@@ -736,6 +737,15 @@ int main(int argc, char **argv)
                case 'g':
                        gc = 1;
                        break;
+               case 'k':
+               {
+                       size_t idx = 0;
+                       const char *name = NULL;
+
+                       while (blkid_superblocks_get_name(idx++, &name, NULL) == 0)
+                               printf("%s\n", name);
+                       exit(0);
+               }
                case 'o':
                        if (!strcmp(optarg, "value"))
                                output_format = OUTPUT_VALUE_ONLY;