chiark / gitweb /
volume_id: ext4 detection
[elogind.git] / extras / volume_id / lib / ext.c
index 51c0011218f5ac1551acdd3d40f62f4d686344a2..1997d42e0bcac2e67510982d2bc55e16ba656f7f 100644 (file)
@@ -63,19 +63,25 @@ struct ext2_super_block {
 } PACKED;
 
 #define EXT_SUPER_MAGIC                                0xEF53
-#define EXT3_FEATURE_COMPAT_HAS_JOURNAL                0x00000004
-#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x00000008
+#define EXT3_FEATURE_COMPAT_HAS_JOURNAL                0x0004
+#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008
+#define EXT3_FEATURE_INCOMPAT_EXTENTS          0x0040
+#define EXT4_FEATURE_INCOMPAT_64BIT            0x0080
+#define EXT4_FEATURE_INCOMPAT_MMP              0x0100
+
 #define EXT_SUPERBLOCK_OFFSET                  0x400
 
 #define EXT3_MIN_BLOCK_SIZE                    0x400
 #define EXT3_MAX_BLOCK_SIZE                    0x1000
 
-int volume_id_probe_ext(struct volume_id *id, uint64_t off)
+int volume_id_probe_ext(struct volume_id *id, uint64_t off, uint64_t size)
 {
        struct ext2_super_block *es;
        size_t bsize;
+       uint32_t feature_compat;
+       uint32_t feature_incompat;
 
-       dbg("probing at offset 0x%llx", (unsigned long long) off);
+       info("probing at offset 0x%llx", (unsigned long long) off);
 
        es = (struct ext2_super_block *) volume_id_get_buffer(id, off + EXT_SUPERBLOCK_OFFSET, 0x200);
        if (es == NULL)
@@ -93,23 +99,36 @@ int volume_id_probe_ext(struct volume_id *id, uint64_t off)
 
        volume_id_set_label_raw(id, es->s_volume_name, 16);
        volume_id_set_label_string(id, es->s_volume_name, 16);
-       volume_id_set_uuid(id, es->s_uuid, UUID_DCE);
-       snprintf(id->type_version, sizeof(id->type_version)-1,
-                "%u.%u", es->s_rev_level, es->s_minor_rev_level);
+       volume_id_set_uuid(id, es->s_uuid, 0, UUID_DCE);
+       snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u",
+                le32_to_cpu(es->s_rev_level), le16_to_cpu(es->s_minor_rev_level));
+
+       feature_compat = le32_to_cpu(es->s_feature_compat);
+       feature_incompat = le32_to_cpu(es->s_feature_incompat);
 
        /* check for external journal device */
-       if ((le32_to_cpu(es->s_feature_incompat) & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) != 0) {
+       if ((feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) != 0) {
                volume_id_set_usage(id, VOLUME_ID_OTHER);
                id->type = "jbd";
-               return 0;
+               goto out;
        }
 
-       /* check for ext2 / ext3 */
        volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
-       if ((le32_to_cpu(es->s_feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0)
+
+       if ((feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) != 0 ||
+           (feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) != 0 ||
+           (feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) != 0) {
+               id->type = "ext4";
+               goto out;
+       }
+
+       if ((feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0) {
                id->type = "ext3";
-       else
-               id->type = "ext2";
+               goto out;
+       }
+
+       id->type = "ext2";
 
+out:
        return 0;
 }