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