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