2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) Andre Masella <andre@masella.no-ip.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"
32 /* All these values are taken from ocfs2-tools's ocfs2_fs.h */
33 #define OCFS2_VOL_UUID_LEN 16
34 #define OCFS2_MAX_VOL_LABEL_LEN 64
35 #define OCFS2_SUPERBLOCK_OFFSET 0x2000
38 /* This is the superblock. The OCFS2 header files have structs in structs.
39 This is one has been simplified since we only care about the superblock.
42 struct ocfs2_super_block {
43 uint8_t i_signature[8]; /* Signature for validation */
44 uint32_t i_generation; /* Generation number */
45 int16_t i_suballoc_slot; /* Slot suballocator this inode belongs to */
46 uint16_t i_suballoc_bit; /* Bit offset in suballocator block group */
48 uint32_t i_clusters; /* Cluster count */
49 uint32_t i_uid; /* Owner UID */
50 uint32_t i_gid; /* Owning GID */
51 uint64_t i_size; /* Size in bytes */
52 uint16_t i_mode; /* File mode */
53 uint16_t i_links_count; /* Links count */
54 uint32_t i_flags; /* File flags */
55 uint64_t i_atime; /* Access time */
56 uint64_t i_ctime; /* Creation time */
57 uint64_t i_mtime; /* Modification time */
58 uint64_t i_dtime; /* Deletion time */
59 uint64_t i_blkno; /* Offset on disk, in blocks */
60 uint64_t i_last_eb_blk; /* Pointer to last extent block */
61 uint32_t i_fs_generation; /* Generation per fs-instance */
62 uint32_t i_atime_nsec;
63 uint32_t i_ctime_nsec;
64 uint32_t i_mtime_nsec;
65 uint64_t i_reserved1[9];
66 uint64_t i_pad1; /* Generic way to refer to this 64bit union */
67 /* Normally there is a union of the different block types, but we only care about the superblock. */
68 uint16_t s_major_rev_level;
69 uint16_t s_minor_rev_level;
71 int16_t s_max_mnt_count;
72 uint16_t s_state; /* File system state */
73 uint16_t s_errors; /* Behaviour when detecting errors */
74 uint32_t s_checkinterval; /* Max time between checks */
75 uint64_t s_lastcheck; /* Time of last check */
76 uint32_t s_creator_os; /* OS */
77 uint32_t s_feature_compat; /* Compatible feature set */
78 uint32_t s_feature_incompat; /* Incompatible feature set */
79 uint32_t s_feature_ro_compat; /* Readonly-compatible feature set */
80 uint64_t s_root_blkno; /* Offset, in blocks, of root directory dinode */
81 uint64_t s_system_dir_blkno; /* Offset, in blocks, of system directory dinode */
82 uint32_t s_blocksize_bits; /* Blocksize for this fs */
83 uint32_t s_clustersize_bits; /* Clustersize for this fs */
84 uint16_t s_max_slots; /* Max number of simultaneous mounts before tunefs required */
87 uint64_t s_first_cluster_group; /* Block offset of 1st cluster group header */
88 uint8_t s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
89 uint8_t s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
90 } __attribute__((__packed__));
92 int volume_id_probe_ocfs2(struct volume_id *id, uint64_t off)
94 struct ocfs2_super_block *os;
96 dbg("probing at offset 0x%llx", (unsigned long long) off);
98 os = (struct ocfs2_super_block *) volume_id_get_buffer(id, off + OCFS2_SUPERBLOCK_OFFSET, 0x200);
102 if (memcmp(os->i_signature, "OCFSV2", 6) != 0) {
106 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
107 volume_id_set_label_raw(id, os->s_label, OCFS2_MAX_VOL_LABEL_LEN < VOLUME_ID_LABEL_SIZE ?
108 OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE);
109 volume_id_set_label_string(id, os->s_label, OCFS2_MAX_VOL_LABEL_LEN < VOLUME_ID_LABEL_SIZE ?
110 OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE);
111 volume_id_set_uuid(id, os->s_uuid, UUID_DCE);