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 "libvolume_id.h"
27 #include "libvolume_id-private.h"
30 struct ufs_super_block {
53 uint32_t fs_maxcontig;
55 uint32_t fs_fragshift;
64 uint32_t fs_npsect_state;
65 uint32_t fs_interleave;
66 uint32_t fs_trackskew;
93 uint32_t fs_maxcluster;
95 uint16_t fs_opostbl[16][8];
99 uint8_t fs_volname[32];
103 uint32_t fs_ocsp[28];
104 uint32_t fs_contigdirs;
106 uint32_t fs_maxcluster;
110 int64_t fs_sparecon64[17];
111 int64_t fs_sblockloc;
112 struct ufs2_csum_total {
117 uint64_t cs_numclusters;
118 uint64_t cs_spare[3];
127 int64_t fs_pendingblocks;
128 int32_t fs_pendinginodes;
133 int32_t fs_sparecon[53];
135 int32_t fs_sparecon2[1];
137 uint32_t fs_qbmask[2];
138 uint32_t fs_qfmask[2];
141 int32_t fs_sparecon[53];
143 int32_t fs_sparecon2[1];
145 uint32_t fs_qbmask[2];
146 uint32_t fs_qfmask[2];
149 int32_t fs_sparecon[50];
150 int32_t fs_contigsumsize;
151 int32_t fs_maxsymlinklen;
153 uint32_t fs_maxfilesize[2];
154 uint32_t fs_qbmask[2];
155 uint32_t fs_qfmask[2];
159 int32_t fs_postblformat;
161 int32_t fs_postbloff;
167 #define UFS_MAGIC 0x00011954
168 #define UFS2_MAGIC 0x19540119
169 #define UFS_MAGIC_FEA 0x00195612
170 #define UFS_MAGIC_LFN 0x00095014
172 int volume_id_probe_ufs(struct volume_id *id, uint64_t off, uint64_t size)
176 struct ufs_super_block *ufs;
177 int offsets[] = {0, 8, 64, 256, -1};
179 info("probing at offset 0x%llx\n", (unsigned long long) off);
181 for (i = 0; offsets[i] >= 0; i++) {
182 ufs = (struct ufs_super_block *) volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800);
186 dbg("offset 0x%x\n", offsets[i] * 0x400);
187 magic = be32_to_cpu(ufs->fs_magic);
188 if ((magic == UFS_MAGIC) ||
189 (magic == UFS2_MAGIC) ||
190 (magic == UFS_MAGIC_FEA) ||
191 (magic == UFS_MAGIC_LFN)) {
192 dbg("magic 0x%08x(be)\n", magic);
195 magic = le32_to_cpu(ufs->fs_magic);
196 if ((magic == UFS_MAGIC) ||
197 (magic == UFS2_MAGIC) ||
198 (magic == UFS_MAGIC_FEA) ||
199 (magic == UFS_MAGIC_LFN)) {
200 dbg("magic 0x%08x(le)\n", magic);
207 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
211 strcpy(id->type_version, "1");
214 strcpy(id->type_version, "2");
215 volume_id_set_label_raw(id, ufs->fs_u11.fs_u2.fs_volname, 32);
216 volume_id_set_label_string(id, ufs->fs_u11.fs_u2.fs_volname, 32);