From: Karel Zak Date: Mon, 20 Jun 2011 14:42:03 +0000 (+0200) Subject: blkid: list all known filesystems/RAIDs (add -k option) X-Git-Tag: v2.20-rc1~155 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=70db6c7ef464072d2314b5f7457868ebd96efc06;p=thirdparty%2Futil-linux.git blkid: list all known filesystems/RAIDs (add -k option) Signed-off-by: Karel Zak --- diff --git a/libblkid/src/blkid.h.in b/libblkid/src/blkid.h.in index 05527bed88..c145ccfd37 100644 --- a/libblkid/src/blkid.h.in +++ b/libblkid/src/blkid.h.in @@ -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 */ diff --git a/libblkid/src/blkid.sym b/libblkid/src/blkid.sym index e758ff1a60..fda27ea2b3 100644 --- a/libblkid/src/blkid.sym +++ b/libblkid/src/blkid.sym @@ -137,5 +137,6 @@ global: BLKID_2.20 { global: blkid_evaluate_spec; + blkid_superblocks_get_name; } BLKID_2.18; diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c index 06aa5facd1..e177667d2c 100644 --- a/libblkid/src/superblocks/superblocks.c +++ b/libblkid/src/superblocks/superblocks.c @@ -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. */ diff --git a/misc-utils/blkid.8 b/misc-utils/blkid.8 index 92fd3854fa..299fbd4fcc 100644 --- a/misc-utils/blkid.8 +++ b/misc-utils/blkid.8 @@ -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 diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index 35b3cd4b96..da13fa9412 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -73,6 +73,7 @@ static void usage(int error) " -g garbage collect the blkid cache\n" " -o 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 show specified tag(s) (default show all tags)\n" " -t 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;