1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/*
* volume_id - reads filesystem label and uuid
*
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <asm/types.h>
#include "volume_id.h"
#include "logging.h"
#include "util.h"
#include "ufs.h"
struct ufs_super_block {
__u32 fs_link;
__u32 fs_rlink;
__u32 fs_sblkno;
__u32 fs_cblkno;
__u32 fs_iblkno;
__u32 fs_dblkno;
__u32 fs_cgoffset;
__u32 fs_cgmask;
__u32 fs_time;
__u32 fs_size;
__u32 fs_dsize;
__u32 fs_ncg;
__u32 fs_bsize;
__u32 fs_fsize;
__u32 fs_frag;
__u32 fs_minfree;
__u32 fs_rotdelay;
__u32 fs_rps;
__u32 fs_bmask;
__u32 fs_fmask;
__u32 fs_bshift;
__u32 fs_fshift;
__u32 fs_maxcontig;
__u32 fs_maxbpg;
__u32 fs_fragshift;
__u32 fs_fsbtodb;
__u32 fs_sbsize;
__u32 fs_csmask;
__u32 fs_csshift;
__u32 fs_nindir;
__u32 fs_inopb;
__u32 fs_nspf;
__u32 fs_optim;
__u32 fs_npsect_state;
__u32 fs_interleave;
__u32 fs_trackskew;
__u32 fs_id[2];
__u32 fs_csaddr;
__u32 fs_cssize;
__u32 fs_cgsize;
__u32 fs_ntrak;
__u32 fs_nsect;
__u32 fs_spc;
__u32 fs_ncyl;
__u32 fs_cpg;
__u32 fs_ipg;
__u32 fs_fpg;
struct ufs_csum {
__u32 cs_ndir;
__u32 cs_nbfree;
__u32 cs_nifree;
__u32 cs_nffree;
} __attribute__((__packed__)) fs_cstotal;
__s8 fs_fmod;
__s8 fs_clean;
__s8 fs_ronly;
__s8 fs_flags;
union {
struct {
__s8 fs_fsmnt[512];
__u32 fs_cgrotor;
__u32 fs_csp[31];
__u32 fs_maxcluster;
__u32 fs_cpc;
__u16 fs_opostbl[16][8];
} __attribute__((__packed__)) fs_u1;
struct {
__s8 fs_fsmnt[468];
__u8 fs_volname[32];
__u64 fs_swuid;
__s32 fs_pad;
__u32 fs_cgrotor;
__u32 fs_ocsp[28];
__u32 fs_contigdirs;
__u32 fs_csp;
__u32 fs_maxcluster;
__u32 fs_active;
__s32 fs_old_cpc;
__s32 fs_maxbsize;
__s64 fs_sparecon64[17];
__s64 fs_sblockloc;
struct ufs2_csum_total {
__u64 cs_ndir;
__u64 cs_nbfree;
__u64 cs_nifree;
__u64 cs_nffree;
__u64 cs_numclusters;
__u64 cs_spare[3];
} __attribute__((__packed__)) fs_cstotal;
struct ufs_timeval {
__s32 tv_sec;
__s32 tv_usec;
} __attribute__((__packed__)) fs_time;
__s64 fs_size;
__s64 fs_dsize;
__u64 fs_csaddr;
__s64 fs_pendingblocks;
__s32 fs_pendinginodes;
} __attribute__((__packed__)) fs_u2;
} fs_u11;
union {
struct {
__s32 fs_sparecon[53];
__s32 fs_reclaim;
__s32 fs_sparecon2[1];
__s32 fs_state;
__u32 fs_qbmask[2];
__u32 fs_qfmask[2];
} __attribute__((__packed__)) fs_sun;
struct {
__s32 fs_sparecon[53];
__s32 fs_reclaim;
__s32 fs_sparecon2[1];
__u32 fs_npsect;
__u32 fs_qbmask[2];
__u32 fs_qfmask[2];
} __attribute__((__packed__)) fs_sunx86;
struct {
__s32 fs_sparecon[50];
__s32 fs_contigsumsize;
__s32 fs_maxsymlinklen;
__s32 fs_inodefmt;
__u32 fs_maxfilesize[2];
__u32 fs_qbmask[2];
__u32 fs_qfmask[2];
__s32 fs_state;
} __attribute__((__packed__)) fs_44;
} fs_u2;
__s32 fs_postblformat;
__s32 fs_nrpos;
__s32 fs_postbloff;
__s32 fs_rotbloff;
__u32 fs_magic;
__u8 fs_space[1];
} __attribute__((__packed__));
#define UFS_MAGIC 0x00011954
#define UFS2_MAGIC 0x19540119
#define UFS_MAGIC_FEA 0x00195612
#define UFS_MAGIC_LFN 0x00095014
int volume_id_probe_ufs(struct volume_id *id, __u64 off)
{
__u32 magic;
int i;
struct ufs_super_block *ufs;
int offsets[] = {0, 8, 64, 256, -1};
dbg("probing at offset 0x%llx", (unsigned long long) off);
for (i = 0; offsets[i] >= 0; i++) {
ufs = (struct ufs_super_block *) volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800);
if (ufs == NULL)
return -1;
dbg("offset 0x%x", offsets[i] * 0x400);
magic = be32_to_cpu(ufs->fs_magic);
if ((magic == UFS_MAGIC) ||
(magic == UFS2_MAGIC) ||
(magic == UFS_MAGIC_FEA) ||
(magic == UFS_MAGIC_LFN)) {
dbg("magic 0x%08x(be)", magic);
goto found;
}
magic = le32_to_cpu(ufs->fs_magic);
if ((magic == UFS_MAGIC) ||
(magic == UFS2_MAGIC) ||
(magic == UFS_MAGIC_FEA) ||
(magic == UFS_MAGIC_LFN)) {
dbg("magic 0x%08x(le)", magic);
goto found;
}
}
return -1;
found:
volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
id->type = "ufs";
return 0;
}
|