2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
26 #include "volume_id.h"
30 struct ext2_super_block {
31 uint32_t s_inodes_count;
32 uint32_t s_blocks_count;
33 uint32_t s_r_blocks_count;
34 uint32_t s_free_blocks_count;
35 uint32_t s_free_inodes_count;
36 uint32_t s_first_data_block;
37 uint32_t s_log_block_size;
38 uint32_t s_log_frag_size;
39 uint32_t s_blocks_per_group;
40 uint32_t s_frags_per_group;
41 uint32_t s_inodes_per_group;
45 uint16_t s_max_mnt_count;
49 uint16_t s_minor_rev_level;
51 uint32_t s_checkinterval;
52 uint32_t s_creator_os;
54 uint16_t s_def_resuid;
55 uint16_t s_def_resgid;
57 uint16_t s_inode_size;
58 uint16_t s_block_group_nr;
59 uint32_t s_feature_compat;
60 uint32_t s_feature_incompat;
61 uint32_t s_feature_ro_compat;
63 uint8_t s_volume_name[16];
66 #define EXT_SUPER_MAGIC 0xEF53
67 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004
68 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x00000008
69 #define EXT_SUPERBLOCK_OFFSET 0x400
71 #define EXT3_MIN_BLOCK_SIZE 0x400
72 #define EXT3_MAX_BLOCK_SIZE 0x1000
74 int volume_id_probe_ext(struct volume_id *id, uint64_t off)
76 struct ext2_super_block *es;
79 dbg("probing at offset 0x%llx", (unsigned long long) off);
81 es = (struct ext2_super_block *) volume_id_get_buffer(id, off + EXT_SUPERBLOCK_OFFSET, 0x200);
85 if (es->s_magic != cpu_to_le16(EXT_SUPER_MAGIC))
88 bsize = 0x400 << le32_to_cpu(es->s_log_block_size);
89 dbg("ext blocksize 0x%zx", bsize);
90 if (bsize < EXT3_MIN_BLOCK_SIZE || bsize > EXT3_MAX_BLOCK_SIZE) {
91 dbg("invalid ext blocksize");
95 volume_id_set_label_raw(id, es->s_volume_name, 16);
96 volume_id_set_label_string(id, es->s_volume_name, 16);
97 volume_id_set_uuid(id, es->s_uuid, UUID_DCE);
98 snprintf(id->type_version, sizeof(id->type_version)-1,
99 "%u.%u", es->s_rev_level, es->s_minor_rev_level);
101 /* check for external journal device */
102 if ((le32_to_cpu(es->s_feature_incompat) & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) != 0) {
103 volume_id_set_usage(id, VOLUME_ID_OTHER);
108 /* check for ext2 / ext3 */
109 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
110 if ((le32_to_cpu(es->s_feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0)