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 77e874d..4a78cd1 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 c71b4de..dbf2b0d 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 53f13a9..fe88fb3 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 b84a6f0..28e9970 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 80c217f..b5194a7 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 b0f427c..904fbb2 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 bf32e6a..7c99305 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 cf75851..f3f19db 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 1519de4..1d7693a 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 eb7a448..5333af2 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 e1c8636..761e54f 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 0aa43f3..62d5885 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 8ab09e3..f9b3766 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 17b1fe8..547f141 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 e6c4559..fcdb151 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 3120b29..67b4a18 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 228e77a..15653be 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 e0fa20a..6eb9646 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 dd25731..cd63c8d 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 9b808ff..1c64046 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 1017d07..8474602 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;
 }