]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/versions.c
46b758ba6e39ba5bfa728b9fc908a7ad620eb348
[thirdparty/xfsprogs-dev.git] / repair / versions.c
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34
35 #define EXTERN
36 #include "versions.h"
37 #undef EXTERN
38 #include "err_protos.h"
39 #include "globals.h"
40
41 void
42 update_sb_version(xfs_mount_t *mp)
43 {
44 xfs_sb_t *sb;
45 __uint16_t vn;
46
47 sb = &mp->m_sb;
48
49 if (fs_attributes) {
50 if (!XFS_SB_VERSION_HASATTR(sb)) {
51 ASSERT(fs_attributes_allowed);
52
53 XFS_SB_VERSION_ADDATTR(sb);
54 }
55 }
56
57 if (fs_inode_nlink) {
58 if (!XFS_SB_VERSION_HASNLINK(sb)) {
59 ASSERT(fs_inode_nlink_allowed);
60
61 XFS_SB_VERSION_ADDNLINK(sb);
62 }
63 }
64
65 /*
66 * fix up the superblock version number and feature bits,
67 * turn off quota bits and flags if the filesystem doesn't
68 * have quotas.
69 */
70 if (fs_quotas) {
71 if (!XFS_SB_VERSION_HASQUOTA(sb)) {
72 ASSERT(fs_quotas_allowed);
73
74 XFS_SB_VERSION_ADDQUOTA(sb);
75 }
76
77 /*
78 * protect against stray bits in the quota flag field
79 */
80 if (sb->sb_qflags & ~(XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|
81 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|
82 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD)) {
83 /*
84 * update the incore superblock, if we're in
85 * no_modify mode, it'll never get flushed out
86 * so this is ok.
87 */
88 do_warn("bogus quota flags 0x%x set in superblock",
89 sb->sb_qflags & ~(XFS_UQUOTA_ACCT|
90 XFS_UQUOTA_ENFD|
91 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|
92 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD));
93
94 sb->sb_qflags &= (XFS_UQUOTA_ACCT|
95 XFS_UQUOTA_ENFD|
96 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|
97 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD);
98
99 if (!no_modify)
100 do_warn(", bogus flags will be cleared\n");
101 else
102 do_warn(", bogus flags would be cleared\n");
103 }
104 } else {
105 sb->sb_qflags = 0;
106
107 if (XFS_SB_VERSION_HASQUOTA(sb)) {
108 lost_quotas = 1;
109 vn = sb->sb_versionnum;
110 vn &= ~XFS_SB_VERSION_QUOTABIT;
111
112 if (!(vn & XFS_SB_VERSION_ALLFBITS))
113 vn = XFS_SB_VERSION_TOOLD(vn);
114
115 ASSERT(vn != 0);
116 sb->sb_versionnum = vn;
117 }
118 }
119
120 if (!fs_aligned_inodes) {
121 if (XFS_SB_VERSION_HASALIGN(sb)) {
122 if (XFS_SB_VERSION_NUM(sb) == XFS_SB_VERSION_4)
123 XFS_SB_VERSION_SUBALIGN(sb);
124 }
125 }
126 }
127
128 /*
129 * returns 0 if things are fine, 1 if we don't understand
130 * this superblock version. Sets superblock geometry-dependent
131 * global variables.
132 */
133 int
134 parse_sb_version(xfs_sb_t *sb)
135 {
136 int issue_warning;
137
138 fs_attributes = 0;
139 fs_inode_nlink = 0;
140 fs_quotas = 0;
141 fs_aligned_inodes = 0;
142 fs_sb_feature_bits = 0;
143 fs_ino_alignment = 0;
144 fs_has_extflgbit = 0;
145 have_uquotino = 0;
146 have_gquotino = 0;
147 issue_warning = 0;
148
149 /*
150 * ok, check to make sure that the sb isn't newer
151 * than we are
152 */
153 if (XFS_SB_VERSION_HASEXTFLGBIT(sb)) {
154 fs_has_extflgbit = 1;
155 if (!fs_has_extflgbit_allowed) {
156 issue_warning = 1;
157 do_warn(
158 "This filesystem has uninitialized extent flags.\n");
159 }
160 }
161
162 if (XFS_SB_VERSION_HASSHARED(sb)) {
163 fs_shared = 1;
164 if (!fs_shared_allowed) {
165 issue_warning = 1;
166 do_warn("This filesystem is marked shared.\n");
167 }
168 }
169
170 if (issue_warning) {
171 do_warn(
172 "This filesystem uses 6.5 feature(s) not yet supported in this release.\n\
173 Please run a 6.5 version of xfs_repair.\n");
174 return(1);
175 }
176
177 if (!XFS_SB_GOOD_VERSION(sb)) {
178 do_warn(
179 "WARNING: unknown superblock version %d\n", XFS_SB_VERSION_NUM(sb));
180 do_warn(
181 "This filesystem contains features not understood by this program.\n");
182 return(1);
183 }
184
185 if (XFS_SB_VERSION_NUM(sb) == XFS_SB_VERSION_4) {
186 if (!fs_sb_feature_bits_allowed) {
187 do_warn(
188 "WARNING: you have disallowed superblock feature bits disallowed\n");
189 do_warn(
190 "\tbut this superblock has feature bits. The superblock\n");
191
192 if (!no_modify) {
193 do_warn(
194 "\twill be downgraded. This may cause loss of filesystem meta-data\n");
195 } else {
196 do_warn(
197 "\twould be downgraded. This might cause loss of filesystem\n");
198 do_warn(
199 "\tmeta-data.\n");
200 }
201 } else {
202 fs_sb_feature_bits = 1;
203 }
204 }
205
206 if (XFS_SB_VERSION_HASATTR(sb)) {
207 if (!fs_attributes_allowed) {
208 do_warn(
209 "WARNING: you have disallowed attributes but this filesystem\n");
210 if (!no_modify) {
211 do_warn(
212 "\thas attributes. The filesystem will be downgraded and\n");
213 do_warn(
214 "\tall attributes will be removed.\n");
215 } else {
216 do_warn(
217 "\thas attributes. The filesystem would be downgraded and\n");
218 do_warn(
219 "\tall attributes would be removed.\n");
220 }
221 } else {
222 fs_attributes = 1;
223 }
224 }
225
226 if (XFS_SB_VERSION_HASNLINK(sb)) {
227 if (!fs_inode_nlink_allowed) {
228 do_warn(
229 "WARNING: you have disallowed version 2 inodes but this filesystem\n");
230 if (!no_modify) {
231 do_warn(
232 "\thas version 2 inodes. The filesystem will be downgraded and\n");
233 do_warn(
234 "\tall version 2 inodes will be converted to version 1 inodes.\n");
235 do_warn(
236 "\tThis may cause some hard links to files to be destroyed\n");
237 } else {
238 do_warn(
239 "\thas version 2 inodes. The filesystem would be downgraded and\n");
240 do_warn(
241 "\tall version 2 inodes would be converted to version 1 inodes.\n");
242 do_warn(
243 "\tThis might cause some hard links to files to be destroyed\n");
244 }
245 } else {
246 fs_inode_nlink = 1;
247 }
248 }
249
250 if (XFS_SB_VERSION_HASQUOTA(sb)) {
251 if (!fs_quotas_allowed) {
252 do_warn(
253 "WARNING: you have disallowed quotas but this filesystem\n");
254 if (!no_modify) {
255 do_warn(
256 "\thas quotas. The filesystem will be downgraded and\n");
257 do_warn(
258 "\tall quota information will be removed.\n");
259 } else {
260 do_warn(
261 "\thas quotas. The filesystem would be downgraded and\n");
262 do_warn(
263 "\tall quota information would be removed.\n");
264 }
265 } else {
266 fs_quotas = 1;
267
268 if (sb->sb_uquotino != 0 &&
269 sb->sb_uquotino != NULLFSINO)
270 have_uquotino = 1;
271
272 if (sb->sb_gquotino != 0 &&
273 sb->sb_gquotino != NULLFSINO)
274 have_gquotino = 1;
275 }
276 }
277
278 if (XFS_SB_VERSION_HASALIGN(sb)) {
279 if (fs_aligned_inodes_allowed) {
280 fs_aligned_inodes = 1;
281 fs_ino_alignment = sb->sb_inoalignmt;
282 } else {
283 do_warn(
284 "WARNING: you have disallowed aligned inodes but this filesystem\n");
285 if (!no_modify) {
286 do_warn(
287 "\thas aligned inodes. The filesystem will be downgraded.\n");
288 do_warn(
289 "\tThis will permanently degrade the performance of this filesystem.\n");
290 } else {
291 do_warn(
292 "\thas aligned inodes. The filesystem would be downgraded.\n");
293 do_warn(
294 "\tThis would permanently degrade the performance of this filesystem.\n");
295 }
296 }
297 }
298
299 /*
300 * calculate maximum file offset for this geometry
301 */
302 fs_max_file_offset = 0x7fffffffffffffffLL >> sb->sb_blocklog;
303
304 return(0);
305 }