blkid: optional support for TYPE="fstype"
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 29 Dec 2010 23:40:11 +0000 (00:40 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 29 Dec 2010 23:40:11 +0000 (00:40 +0100)
Adapted from patch created by T4ndeta <t4ndeta@gmail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
21 files changed:
include/volume_id.h
util-linux/Config.src
util-linux/blkid.c
util-linux/volume_id/cramfs.c
util-linux/volume_id/ext.c
util-linux/volume_id/fat.c
util-linux/volume_id/get_devname.c
util-linux/volume_id/hfs.c
util-linux/volume_id/iso9660.c
util-linux/volume_id/jfs.c
util-linux/volume_id/linux_raid.c
util-linux/volume_id/linux_swap.c
util-linux/volume_id/luks.c
util-linux/volume_id/ntfs.c
util-linux/volume_id/ocfs2.c
util-linux/volume_id/reiserfs.c
util-linux/volume_id/romfs.c
util-linux/volume_id/sysv.c
util-linux/volume_id/udf.c
util-linux/volume_id/volume_id_internal.h
util-linux/volume_id/xfs.c

index 77e874d402e762fc4dd8e515ab906a9cb6a35827..4a78cd1e462f699baabbbdcaff41179285f3b680 100644 (file)
@@ -28,3 +28,4 @@ void display_uuid_cache(void);
  *    *fsname is replaced if device with such UUID or LABEL is found
  */
 int resolve_mount_spec(char **fsname);
+int add_to_uuid_cache(const char *device);
index c71b4de3820f8fbb56fb0fbf91e6225124972e6c..dbf2b0d85d59aefac9467fddb1e096d0ab4993f9 100644 (file)
@@ -40,6 +40,13 @@ config BLKID
          WARNING:
          With all submodules selected, it will add ~8k to busybox.
 
+config FEATURE_BLKID_TYPE
+       bool "Print filesystem type"
+       default n
+       depends on BLKID
+       help
+         Show TYPE="filesystem type"
+
 config DMESG
        bool "dmesg"
        default y
index 53f13a99c50ba975bdae1bfdf3be5e8a991e98f1..fe88fb31de685b5fe0785bd5a91c5bfec0ae9943 100644 (file)
 //TODO: extend to take BLOCKDEV args, and show TYPE="fstype"
 
 int blkid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int blkid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+int blkid_main(int argc UNUSED_PARAM, char **argv)
 {
+       while (*++argv) {
+               /* Note: bogus device names don't cause any error messages */
+               add_to_uuid_cache(*argv);
+       }
+
        display_uuid_cache();
        return 0;
 }
index b84a6f0b21990158e9d2b3afda04b7f510e64978..28e997043177433670118bdb58e5ac1c3e3a42cd 100644 (file)
@@ -51,7 +51,7 @@ int FAST_FUNC volume_id_probe_cramfs(struct volume_id *id /*,uint64_t off*/)
                volume_id_set_label_string(id, cs->name, 16);
 
 //             volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//             id->type = "cramfs";
+               IF_FEATURE_BLKID_TYPE(id->type = "cramfs";)
                return 0;
        }
 
index 80c217f9829347e6b9240fe0ca7a7859b9134eb2..b5194a7b56d92b7b86846823d8ba4fe9b1856a67 100644 (file)
@@ -65,10 +65,12 @@ int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/)
        volume_id_set_uuid(id, es->uuid, UUID_DCE);
        dbg("ext: label '%s' uuid '%s'", id->label, id->uuid);
 
-//     if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0)
-//             id->type = "ext3";
-//     else
-//             id->type = "ext2";
+#if ENABLE_FEATURE_BLKID_TYPE
+       if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0)
+               id->type = "ext3";
+       else
+               id->type = "ext2";
+#endif
 
        return 0;
 }
index b0f427c74a0734cd35e3d847987b74420adf4bc4..904fbb201dd0eb7b4d6846d106a88309dc30f8bc 100644 (file)
@@ -332,7 +332,7 @@ int FAST_FUNC volume_id_probe_vfat(struct volume_id *id /*,uint64_t fat_partitio
 
  ret:
 //     volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//     id->type = "vfat";
+       IF_FEATURE_BLKID_TYPE(id->type = "vfat";)
 
        return 0;
 }
index bf32e6a8ca484b7cd4d701c853714655bf67602a..7c9930543782c5916e8e3abd9626e4418a301029 100644 (file)
@@ -19,14 +19,22 @@ static struct uuidCache_s {
        char *device;
        char *label;
        char *uc_uuid; /* prefix makes it easier to grep for */
+       IF_FEATURE_BLKID_TYPE(const char *type;)
 } *uuidCache;
 
+#if !ENABLE_FEATURE_BLKID_TYPE
+#define get_label_uuid(fd, label, uuid, type) \
+       get_label_uuid(fd, label, uuid)
+#define uuidcache_addentry(device, label, uuid, type) \
+       uuidcache_addentry(device, label, uuid)
+#endif
+
 /* Returns !0 on error.
  * Otherwise, returns malloc'ed strings for label and uuid
  * (and they can't be NULL, although they can be "").
  * NB: closes fd. */
 static int
-get_label_uuid(int fd, char **label, char **uuid)
+get_label_uuid(int fd, char **label, char **uuid, const char **type)
 {
        int rv = 1;
        uint64_t size;
@@ -44,7 +52,12 @@ get_label_uuid(int fd, char **label, char **uuid)
        if (vid->label[0] != '\0' || vid->uuid[0] != '\0') {
                *label = xstrndup(vid->label, sizeof(vid->label));
                *uuid  = xstrndup(vid->uuid, sizeof(vid->uuid));
+#if ENABLE_FEATURE_BLKID_TYPE
+               *type = vid->type;
+               dbg("found label '%s', uuid '%s', type '%s'", *label, *uuid, *type);
+#else
                dbg("found label '%s', uuid '%s'", *label, *uuid);
+#endif
                rv = 0;
        }
  ret:
@@ -54,7 +67,7 @@ get_label_uuid(int fd, char **label, char **uuid)
 
 /* NB: we take ownership of (malloc'ed) label and uuid */
 static void
-uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid)
+uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid, const char *type)
 {
        struct uuidCache_s *last;
 
@@ -72,6 +85,7 @@ uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uu
        last->device = device;
        last->label = label;
        last->uc_uuid = uuid;
+       IF_FEATURE_BLKID_TYPE(last->type = type;)
 }
 
 /* If get_label_uuid() on device_name returns success,
@@ -83,10 +97,6 @@ uuidcache_check_device(const char *device,
                void *userData UNUSED_PARAM,
                int depth UNUSED_PARAM)
 {
-       char *uuid = uuid; /* for compiler */
-       char *label = label;
-       int fd;
-
        /* note: this check rejects links to devices, among other nodes */
        if (!S_ISBLK(statbuf->st_mode))
                return TRUE;
@@ -99,21 +109,15 @@ uuidcache_check_device(const char *device,
        if (major(statbuf->st_rdev) == 2)
                return TRUE;
 
-       fd = open(device, O_RDONLY);
-       if (fd < 0)
-               return TRUE;
+       add_to_uuid_cache(device);
 
-       /* get_label_uuid() closes fd in all cases (success & failure) */
-       if (get_label_uuid(fd, &label, &uuid) == 0) {
-               /* uuidcache_addentry() takes ownership of all three params */
-               uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid);
-       }
        return TRUE;
 }
 
 static void
 uuidcache_init(void)
 {
+       dbg("DBG: uuidCache=%x, uuidCache");
        if (uuidCache)
                return;
 
@@ -223,11 +227,38 @@ void display_uuid_cache(void)
                        printf(" LABEL=\"%s\"", u->label);
                if (u->uc_uuid[0])
                        printf(" UUID=\"%s\"", u->uc_uuid);
+#if ENABLE_FEATURE_BLKID_TYPE
+       if (u->type)
+               printf(" TYPE=\"%s\"", u->type);
+#endif
                bb_putchar('\n');
                u = u->next;
        }
 }
 
+int add_to_uuid_cache(const char *device)
+{
+       char *uuid = uuid; /* for compiler */
+       char *label = label;
+#if ENABLE_FEATURE_BLKID_TYPE
+       const char *type = type;
+#endif
+       int fd;
+
+       fd = open(device, O_RDONLY);
+       if (fd < 0)
+               return 0;
+
+       /* get_label_uuid() closes fd in all cases (success & failure) */
+       if (get_label_uuid(fd, &label, &uuid, &type) == 0) {
+               /* uuidcache_addentry() takes ownership of all four params */
+               uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid, type);
+               return 1;
+       }
+       return 0;
+}
+
+
 /* Used by mount and findfs */
 
 char *get_devname_from_label(const char *spec)
index cf7585138c6f8fbe4b061fba3cb7cad1d0ac8b22..f3f19dba71b52b53734184e639ac822209b2e787 100644 (file)
@@ -195,7 +195,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/
 
        volume_id_set_uuid(id, hfs->finder_info.id, UUID_HFS);
 //     volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//     id->type = "hfs";
+       IF_FEATURE_BLKID_TYPE(id->type = "hfs";)
 
        return 0;
 
index 1519de496c837ae4036fe107308be53cac399f82..1d7693a9c50edfcb8e1595f3f8da594d9eb8358c 100644 (file)
@@ -114,7 +114,7 @@ int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id /*,uint64_t off*/)
 
  found:
 //     volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//     id->type = "iso9660";
+       IF_FEATURE_BLKID_TYPE(id->type = "iso9660";)
 
        return 0;
 }
index eb7a448722e075ba208bea6b54aa27cae804c3b5..5333af2c38aee6698fb37fc8d67614b13786305e 100644 (file)
@@ -54,7 +54,7 @@ int FAST_FUNC volume_id_probe_jfs(struct volume_id *id /*,uint64_t off*/)
        volume_id_set_uuid(id, js->uuid, UUID_DCE);
 
 //     volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//     id->type = "jfs";
+       IF_FEATURE_BLKID_TYPE(id->type = "jfs";)
 
        return 0;
 }
index e1c86369d448f0f2256cf490a3656d08ba99bbfd..761e54f9f3e5c9803c7b42992743befc69f30b9e 100644 (file)
@@ -75,7 +75,7 @@ int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/,
 
        dbg("found raid signature");
 //     volume_id_set_usage(id, VOLUME_ID_RAID);
-//     id->type = "linux_raid_member";
+       IF_FEATURE_BLKID_TYPE(id->type = "linux_raid_member";)
 
        return 0;
 }
index 0aa43f3dee560642b6158891daa8fd5d0bb5cdc2..62d5885225c13db3318ab15163882eefc193d045 100644 (file)
@@ -73,7 +73,7 @@ int FAST_FUNC volume_id_probe_linux_swap(struct volume_id *id /*,uint64_t off*/)
 
 found:
 //     volume_id_set_usage(id, VOLUME_ID_OTHER);
-//     id->type = "swap";
+       IF_FEATURE_BLKID_TYPE(id->type = "swap";)
 
        return 0;
 }
index 8ab09e3816da12c01219954465d28024589fa557..f9b3766722aea4a242cce6fb1eba2870d52181cd 100644 (file)
@@ -94,7 +94,7 @@ int FAST_FUNC volume_id_probe_luks(struct volume_id *id /*,uint64_t off*/)
 
 //     volume_id_set_usage(id, VOLUME_ID_CRYPTO);
        volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING);
-//     id->type = "crypto_LUKS";
+       IF_FEATURE_BLKID_TYPE(id->type = "crypto_LUKS";)
 
        return 0;
 }
index 17b1fe8b32ffac20b89c92f8e7cf501c7d9bfd55..547f141c9cc086a364409c43fc3b4eeb67eb3c1b 100644 (file)
@@ -188,7 +188,7 @@ int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/)
 
  found:
 //     volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//     id->type = "ntfs";
+       IF_FEATURE_BLKID_TYPE(id->type = "ntfs";)
 
        return 0;
 }
index e6c4559654ad89ebac74ff283fe4c15cd6342dfe..fcdb15192784913ae01dd39e48e27817f4a6f317 100644 (file)
@@ -101,6 +101,6 @@ int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id /*,uint64_t off*/)
        volume_id_set_label_string(id, os->s_label, OCFS2_MAX_VOL_LABEL_LEN < VOLUME_ID_LABEL_SIZE ?
                                        OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE);
        volume_id_set_uuid(id, os->s_uuid, UUID_DCE);
-//     id->type = "ocfs2";
+       IF_FEATURE_BLKID_TYPE(id->type = "ocfs2";)
        return 0;
 }
index 3120b29a026f884dedce8dd5fdd5af0648ec998a..67b4a1877452e0f4a9044006353500bdb042d179 100644 (file)
@@ -107,7 +107,7 @@ int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id /*,uint64_t off*/)
 
  found:
 //     volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//     id->type = "reiserfs";
+       IF_FEATURE_BLKID_TYPE(id->type = "reiserfs";)
 
        return 0;
 }
index 228e77a41edc6e6e631e4b22666aaa3aded4aff6..15653bedfcc54f7bc051630974b1cea0a9891ca3 100644 (file)
@@ -47,7 +47,7 @@ int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/)
                }
 
 //             volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//             id->type = "romfs";
+               IF_FEATURE_BLKID_TYPE(id->type = "romfs";)
                return 0;
        }
 
index e0fa20a8c8402897e990f8ca9161c18f521aff79..6eb96464d0692f66d301ed959063ef85a9cb00d9 100644 (file)
@@ -99,7 +99,7 @@ int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/)
                if (vs->s_magic == cpu_to_le32(SYSV_MAGIC) || vs->s_magic == cpu_to_be32(SYSV_MAGIC)) {
 //                     volume_id_set_label_raw(id, vs->s_fname, 6);
                        volume_id_set_label_string(id, vs->s_fname, 6);
-//                     id->type = "sysv";
+                       IF_FEATURE_BLKID_TYPE(id->type = "sysv");
                        goto found;
                }
        }
@@ -112,7 +112,7 @@ int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/)
                if (xs->s_magic == cpu_to_le32(XENIX_MAGIC) || xs->s_magic == cpu_to_be32(XENIX_MAGIC)) {
 //                     volume_id_set_label_raw(id, xs->s_fname, 6);
                        volume_id_set_label_string(id, xs->s_fname, 6);
-//                     id->type = "xenix";
+                       IF_FEATURE_BLKID_TYPE(id->type = "xenix";)
                        goto found;
                }
        }
index dd2573171a241860d243d30b15262e13c0004a81..cd63c8d8a775199a0704cef2112be04415b3c99a 100644 (file)
@@ -167,7 +167,6 @@ anchor:
 
  found:
 //     volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//     id->type = "udf";
-
+       IF_FEATURE_BLKID_TYPE(id->type = "udf";)
        return 0;
 }
index 9b808ff6b7f19d832f3f0a67f5cae3e91e25c29a..1c64046e5194344cc3159f22de7c80023d536744 100644 (file)
@@ -80,7 +80,9 @@ struct volume_id {
 //     char            type_version[VOLUME_ID_FORMAT_SIZE];
 //     smallint        usage_id;
 //     const char      *usage;
-//     const char      *type;
+#if ENABLE_FEATURE_BLKID_TYPE
+       const char      *type;
+#endif
 };
 
 struct volume_id* FAST_FUNC volume_id_open_node(int fd);
index 1017d077b5bd806207ab3282fbb024c189b29b5b..84746020eec2985efe74a6fa58296c508374bf8a 100644 (file)
@@ -54,7 +54,7 @@ int FAST_FUNC volume_id_probe_xfs(struct volume_id *id /*,uint64_t off*/)
        volume_id_set_uuid(id, xs->uuid, UUID_DCE);
 
 //     volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-//     id->type = "xfs";
+       IF_FEATURE_BLKID_TYPE(id->type = "xfs";)
 
        return 0;
 }