blob: d33c10fc41bc21b080f48235f6ebd8bbf128d40c [file] [log] [blame]
Denis Vlasenkode7684a2008-02-18 21:08:49 +00001/*
2 * volume_id - reads filesystem label and uuid
3 *
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
Sven-Göran Bergh3b458012013-07-31 15:45:20 +020021//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_UFS) += ufs.o
22
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +020023//config:
24//config:### config FEATURE_VOLUMEID_UFS
25//config:### bool "ufs filesystem"
26//config:### default y
27//config:### depends on VOLUMEID
28//config:### help
29//config:### TODO
30//config:
31
Denis Vlasenkode7684a2008-02-18 21:08:49 +000032#include "volume_id_internal.h"
33
34struct ufs_super_block {
35 uint32_t fs_link;
36 uint32_t fs_rlink;
37 uint32_t fs_sblkno;
38 uint32_t fs_cblkno;
39 uint32_t fs_iblkno;
40 uint32_t fs_dblkno;
41 uint32_t fs_cgoffset;
42 uint32_t fs_cgmask;
43 uint32_t fs_time;
44 uint32_t fs_size;
45 uint32_t fs_dsize;
Denis Vlasenkoc6938402008-03-24 02:18:03 +000046 uint32_t fs_ncg;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000047 uint32_t fs_bsize;
48 uint32_t fs_fsize;
49 uint32_t fs_frag;
50 uint32_t fs_minfree;
51 uint32_t fs_rotdelay;
Denis Vlasenkoc6938402008-03-24 02:18:03 +000052 uint32_t fs_rps;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000053 uint32_t fs_bmask;
54 uint32_t fs_fmask;
55 uint32_t fs_bshift;
56 uint32_t fs_fshift;
57 uint32_t fs_maxcontig;
58 uint32_t fs_maxbpg;
59 uint32_t fs_fragshift;
60 uint32_t fs_fsbtodb;
61 uint32_t fs_sbsize;
62 uint32_t fs_csmask;
63 uint32_t fs_csshift;
64 uint32_t fs_nindir;
65 uint32_t fs_inopb;
66 uint32_t fs_nspf;
67 uint32_t fs_optim;
68 uint32_t fs_npsect_state;
69 uint32_t fs_interleave;
70 uint32_t fs_trackskew;
71 uint32_t fs_id[2];
72 uint32_t fs_csaddr;
73 uint32_t fs_cssize;
74 uint32_t fs_cgsize;
75 uint32_t fs_ntrak;
76 uint32_t fs_nsect;
Denis Vlasenkoc6938402008-03-24 02:18:03 +000077 uint32_t fs_spc;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000078 uint32_t fs_ncyl;
79 uint32_t fs_cpg;
80 uint32_t fs_ipg;
81 uint32_t fs_fpg;
82 struct ufs_csum {
83 uint32_t cs_ndir;
84 uint32_t cs_nbfree;
85 uint32_t cs_nifree;
86 uint32_t cs_nffree;
Denys Vlasenko8dc0e192009-09-16 00:58:11 +020087 } PACKED fs_cstotal;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000088 int8_t fs_fmod;
89 int8_t fs_clean;
90 int8_t fs_ronly;
91 int8_t fs_flags;
92 union {
93 struct {
94 int8_t fs_fsmnt[512];
95 uint32_t fs_cgrotor;
96 uint32_t fs_csp[31];
97 uint32_t fs_maxcluster;
98 uint32_t fs_cpc;
99 uint16_t fs_opostbl[16][8];
Denys Vlasenko8dc0e192009-09-16 00:58:11 +0200100 } PACKED fs_u1;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000101 struct {
102 int8_t fs_fsmnt[468];
103 uint8_t fs_volname[32];
104 uint64_t fs_swuid;
105 int32_t fs_pad;
106 uint32_t fs_cgrotor;
107 uint32_t fs_ocsp[28];
108 uint32_t fs_contigdirs;
Denis Vlasenkoc6938402008-03-24 02:18:03 +0000109 uint32_t fs_csp;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000110 uint32_t fs_maxcluster;
111 uint32_t fs_active;
112 int32_t fs_old_cpc;
113 int32_t fs_maxbsize;
114 int64_t fs_sparecon64[17];
115 int64_t fs_sblockloc;
116 struct ufs2_csum_total {
117 uint64_t cs_ndir;
118 uint64_t cs_nbfree;
119 uint64_t cs_nifree;
120 uint64_t cs_nffree;
121 uint64_t cs_numclusters;
122 uint64_t cs_spare[3];
Denys Vlasenko8dc0e192009-09-16 00:58:11 +0200123 } PACKED fs_cstotal;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000124 struct ufs_timeval {
125 int32_t tv_sec;
126 int32_t tv_usec;
Denys Vlasenko8dc0e192009-09-16 00:58:11 +0200127 } PACKED fs_time;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000128 int64_t fs_size;
129 int64_t fs_dsize;
130 uint64_t fs_csaddr;
131 int64_t fs_pendingblocks;
132 int32_t fs_pendinginodes;
Denys Vlasenko8dc0e192009-09-16 00:58:11 +0200133 } PACKED fs_u2;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000134 } fs_u11;
135 union {
136 struct {
137 int32_t fs_sparecon[53];
138 int32_t fs_reclaim;
139 int32_t fs_sparecon2[1];
140 int32_t fs_state;
141 uint32_t fs_qbmask[2];
142 uint32_t fs_qfmask[2];
Denys Vlasenko8dc0e192009-09-16 00:58:11 +0200143 } PACKED fs_sun;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000144 struct {
145 int32_t fs_sparecon[53];
146 int32_t fs_reclaim;
147 int32_t fs_sparecon2[1];
148 uint32_t fs_npsect;
149 uint32_t fs_qbmask[2];
150 uint32_t fs_qfmask[2];
Denys Vlasenko8dc0e192009-09-16 00:58:11 +0200151 } PACKED fs_sunx86;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000152 struct {
153 int32_t fs_sparecon[50];
154 int32_t fs_contigsumsize;
155 int32_t fs_maxsymlinklen;
156 int32_t fs_inodefmt;
157 uint32_t fs_maxfilesize[2];
158 uint32_t fs_qbmask[2];
159 uint32_t fs_qfmask[2];
160 int32_t fs_state;
Denys Vlasenko8dc0e192009-09-16 00:58:11 +0200161 } PACKED fs_44;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000162 } fs_u2;
163 int32_t fs_postblformat;
164 int32_t fs_nrpos;
165 int32_t fs_postbloff;
166 int32_t fs_rotbloff;
167 uint32_t fs_magic;
168 uint8_t fs_space[1];
Denys Vlasenko8dc0e192009-09-16 00:58:11 +0200169} PACKED;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000170
171#define UFS_MAGIC 0x00011954
172#define UFS2_MAGIC 0x19540119
173#define UFS_MAGIC_FEA 0x00195612
174#define UFS_MAGIC_LFN 0x00095014
175
Denys Vlasenko89300962009-11-01 23:07:18 +0100176int FAST_FUNC volume_id_probe_ufs(struct volume_id *id, uint64_t off)
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000177{
178 static const short offsets[] = { 0, 8, 64, 256 };
179
180 uint32_t magic;
Denis Vlasenko6b06cb82008-05-15 21:30:45 +0000181 unsigned i;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000182 struct ufs_super_block *ufs;
183
184 dbg("probing at offset 0x%llx", (unsigned long long) off);
185
Denis Vlasenkoc6938402008-03-24 02:18:03 +0000186 for (i = 0; i < ARRAY_SIZE(offsets); i++) {
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000187 ufs = volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800);
188 if (ufs == NULL)
189 return -1;
190
191 dbg("offset 0x%x", offsets[i] * 0x400);
192 magic = ufs->fs_magic;
193 if ((magic == cpu_to_be32(UFS_MAGIC))
194 || (magic == cpu_to_be32(UFS2_MAGIC))
195 || (magic == cpu_to_be32(UFS_MAGIC_FEA))
196 || (magic == cpu_to_be32(UFS_MAGIC_LFN))
197 ) {
198 dbg("magic 0x%08x(be)", magic);
199 goto found;
200 }
201 if ((magic == cpu_to_le32(UFS_MAGIC))
202 || (magic == cpu_to_le32(UFS2_MAGIC))
203 || (magic == cpu_to_le32(UFS_MAGIC_FEA))
204 || (magic == cpu_to_le32(UFS_MAGIC_LFN))
205 ) {
206 dbg("magic 0x%08x(le)", magic);
207 goto found;
208 }
209 }
210 return -1;
211
212 found:
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000213// volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
214// id->type = "ufs";
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000215
216 return 0;
217}