]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/versions.c
e33bda2d9d0ab93957637972e29fec6359968e00
[thirdparty/xfsprogs-dev.git] / repair / versions.c
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
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.
13 *
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
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
27 void
28 update_sb_version(xfs_mount_t *mp)
29 {
30 xfs_sb_t *sb;
31
32 sb = &mp->m_sb;
33
34 if (fs_attributes && !xfs_sb_version_hasattr(sb))
35 xfs_sb_version_addattr(sb);
36
37 if (fs_attributes2 && !xfs_sb_version_hasattr2(sb))
38 xfs_sb_version_addattr2(sb);
39
40 /* V2 inode conversion is now always going to happen */
41 if (!(sb->sb_versionnum & XFS_SB_VERSION_NLINKBIT))
42 sb->sb_versionnum |= XFS_SB_VERSION_NLINKBIT;
43
44 /*
45 * fix up the superblock version number and feature bits,
46 * turn off quota bits and flags if the filesystem doesn't
47 * have quotas.
48 */
49 if (fs_quotas) {
50 if (!xfs_sb_version_hasquota(sb))
51 xfs_sb_version_addquota(sb);
52
53 /*
54 * protect against stray bits in the quota flag field
55 */
56 if (sb->sb_qflags & ~XFS_MOUNT_QUOTA_ALL) {
57 /*
58 * update the incore superblock, if we're in
59 * no_modify mode, it'll never get flushed out
60 * so this is ok.
61 */
62 do_warn(_("bogus quota flags 0x%x set in superblock"),
63 sb->sb_qflags & ~XFS_MOUNT_QUOTA_ALL);
64
65 sb->sb_qflags &= XFS_MOUNT_QUOTA_ALL;
66
67 if (!no_modify)
68 do_warn(_(", bogus flags will be cleared\n"));
69 else
70 do_warn(_(", bogus flags would be cleared\n"));
71 }
72 } else {
73 sb->sb_qflags = 0;
74
75 if (xfs_sb_version_hasquota(sb)) {
76 lost_quotas = 1;
77 sb->sb_versionnum &= ~XFS_SB_VERSION_QUOTABIT;
78 }
79 }
80
81 if (!fs_aligned_inodes && xfs_sb_version_hasalign(sb))
82 sb->sb_versionnum &= ~XFS_SB_VERSION_ALIGNBIT;
83 }
84
85 /*
86 * returns 0 if things are fine, 1 if we don't understand
87 * this superblock version. Sets superblock geometry-dependent
88 * global variables.
89 */
90 int
91 parse_sb_version(xfs_sb_t *sb)
92 {
93 fs_attributes = 0;
94 fs_attributes2 = 0;
95 fs_inode_nlink = 1;
96 fs_quotas = 0;
97 fs_aligned_inodes = 0;
98 fs_sb_feature_bits = 0;
99 fs_ino_alignment = 0;
100 fs_has_extflgbit = 0;
101 have_uquotino = 0;
102 have_gquotino = 0;
103 have_pquotino = 0;
104
105 if (sb->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) {
106 do_warn(_("Shared Version bit set. Not supported. Ever.\n"));
107 return 1;
108 }
109
110 if (sb->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) {
111 do_warn(_("Shared Version bit set. Not supported. Ever.\n"));
112 return 1;
113 }
114
115 if (sb->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) {
116 do_warn(_("Shared Version bit set. Not supported. Ever.\n"));
117 return 1;
118 }
119
120 /*
121 * ok, check to make sure that the sb isn't newer
122 * than we are
123 */
124 if (xfs_sb_version_hasextflgbit(sb))
125 fs_has_extflgbit = 1;
126
127 if (!xfs_sb_good_version(sb)) {
128 do_warn(_("WARNING: unknown superblock version %d\n"),
129 XFS_SB_VERSION_NUM(sb));
130 do_warn(
131 _("This filesystem contains features not understood by this program.\n"));
132 return(1);
133 }
134
135 if (XFS_SB_VERSION_NUM(sb) >= XFS_SB_VERSION_4)
136 fs_sb_feature_bits = 1;
137
138 /* Look for V5 feature flags we don't know about */
139 if (XFS_SB_VERSION_NUM(sb) >= XFS_SB_VERSION_5 &&
140 (xfs_sb_has_compat_feature(sb, XFS_SB_FEAT_COMPAT_UNKNOWN) ||
141 xfs_sb_has_ro_compat_feature(sb, XFS_SB_FEAT_RO_COMPAT_UNKNOWN) ||
142 xfs_sb_has_incompat_feature(sb, XFS_SB_FEAT_INCOMPAT_UNKNOWN))) {
143 do_warn(
144 _("Superblock has unknown compat/rocompat/incompat features (0x%x/0x%x/0x%x).\n"
145 "Using a more recent xfs_repair is recommended.\n"),
146 sb->sb_features_compat & XFS_SB_FEAT_COMPAT_UNKNOWN,
147 sb->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_UNKNOWN,
148 sb->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_UNKNOWN);
149 return 1;
150 }
151
152 if (xfs_sb_version_hasattr(sb))
153 fs_attributes = 1;
154
155 if (xfs_sb_version_hasattr2(sb))
156 fs_attributes2 = 1;
157
158 if (!(sb->sb_versionnum & XFS_SB_VERSION_NLINKBIT)) {
159 if (!no_modify) {
160 do_warn(
161 _("WARNING: you have a V1 inode filesystem. It will be converted to a\n"
162 "\tversion 2 inode filesystem. If you do not want this, run an older\n"
163 "\tversion of xfs_repair.\n"));
164 } else {
165 do_warn(
166 _("WARNING: you have a V1 inode filesystem. It would be converted to a\n"
167 "\tversion 2 inode filesystem. If you do not want this, run an older\n"
168 "\tversion of xfs_repair.\n"));
169 }
170 }
171
172 if (xfs_sb_version_hasquota(sb)) {
173 fs_quotas = 1;
174
175 if (sb->sb_uquotino != 0 && sb->sb_uquotino != NULLFSINO)
176 have_uquotino = 1;
177
178 if (sb->sb_gquotino != 0 && sb->sb_gquotino != NULLFSINO)
179 have_gquotino = 1;
180
181 if (sb->sb_pquotino != 0 && sb->sb_pquotino != NULLFSINO)
182 have_pquotino = 1;
183 }
184
185 if (xfs_sb_version_hasalign(sb)) {
186 fs_aligned_inodes = 1;
187 fs_ino_alignment = sb->sb_inoalignmt;
188 }
189
190 /*
191 * calculate maximum file offset for this geometry
192 */
193 fs_max_file_offset = 0x7fffffffffffffffLL >> sb->sb_blocklog;
194
195 return(0);
196 }