]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - repair/versions.c
libxfs: refactor manage_zones()
[thirdparty/xfsprogs-dev.git] / repair / versions.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
2bd0ea18 2/*
da23017d
NS
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
2bd0ea18
NS
5 */
6
6b803e5a 7#include "libxfs.h"
2bd0ea18 8
2bd0ea18
NS
9#include "err_protos.h"
10#include "globals.h"
a5e09451
ES
11#include "versions.h"
12
13/*
14 * filesystem feature global vars, set to 1 if the feature
15 * is on, 0 otherwise
16 */
17
18int fs_attributes;
19int fs_attributes2;
20int fs_inode_nlink;
21int fs_quotas;
22int fs_aligned_inodes;
23int fs_sb_feature_bits;
24int fs_has_extflgbit;
25
26/*
27 * inode chunk alignment, fsblocks
28 */
29
30xfs_extlen_t fs_ino_alignment;
2bd0ea18
NS
31
32void
33update_sb_version(xfs_mount_t *mp)
34{
35 xfs_sb_t *sb;
2bd0ea18
NS
36
37 sb = &mp->m_sb;
38
497d0706 39 if (fs_attributes && !xfs_sb_version_hasattr(sb))
5e656dbb 40 xfs_sb_version_addattr(sb);
2bd0ea18 41
232470f2 42 if (fs_attributes2 && !xfs_sb_version_hasattr2(sb))
5e656dbb 43 xfs_sb_version_addattr2(sb);
9b1d68ec 44
5f6f3660
DC
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;
2bd0ea18
NS
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) {
99a1e0da 55 if (!xfs_sb_version_hasquota(sb))
5e656dbb 56 xfs_sb_version_addquota(sb);
2bd0ea18
NS
57
58 /*
59 * protect against stray bits in the quota flag field
60 */
342aef1e 61 if (sb->sb_qflags & ~XFS_MOUNT_QUOTA_ALL) {
2bd0ea18
NS
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 */
507f4e33 67 do_warn(_("bogus quota flags 0x%x set in superblock"),
342aef1e
CS
68 sb->sb_qflags & ~XFS_MOUNT_QUOTA_ALL);
69
70 sb->sb_qflags &= XFS_MOUNT_QUOTA_ALL;
2bd0ea18
NS
71
72 if (!no_modify)
507f4e33 73 do_warn(_(", bogus flags will be cleared\n"));
2bd0ea18 74 else
507f4e33 75 do_warn(_(", bogus flags would be cleared\n"));
2bd0ea18
NS
76 }
77 } else {
78 sb->sb_qflags = 0;
79
5e656dbb 80 if (xfs_sb_version_hasquota(sb)) {
2bd0ea18 81 lost_quotas = 1;
5f6f3660 82 sb->sb_versionnum &= ~XFS_SB_VERSION_QUOTABIT;
2bd0ea18
NS
83 }
84 }
85
f8149110 86 if (!fs_aligned_inodes && xfs_sb_version_hasalign(sb))
5e656dbb 87 sb->sb_versionnum &= ~XFS_SB_VERSION_ALIGNBIT;
2bd0ea18
NS
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 */
95int
96parse_sb_version(xfs_sb_t *sb)
97{
2bd0ea18 98 fs_attributes = 0;
9b1d68ec 99 fs_attributes2 = 0;
5f6f3660 100 fs_inode_nlink = 1;
2bd0ea18
NS
101 fs_quotas = 0;
102 fs_aligned_inodes = 0;
103 fs_sb_feature_bits = 0;
104 fs_ino_alignment = 0;
b7fdeb4d 105 fs_has_extflgbit = 1;
2bd0ea18 106 have_uquotino = 0;
b36eef04 107 have_gquotino = 0;
0340d706 108 have_pquotino = 0;
2bd0ea18 109
5f6f3660
DC
110 if (sb->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) {
111 do_warn(_("Shared Version bit set. Not supported. Ever.\n"));
ff105f75
DC
112 return 1;
113 }
114
2bd0ea18
NS
115 /*
116 * ok, check to make sure that the sb isn't newer
117 * than we are
118 */
5e656dbb 119 if (!xfs_sb_good_version(sb)) {
507f4e33
NS
120 do_warn(_("WARNING: unknown superblock version %d\n"),
121 XFS_SB_VERSION_NUM(sb));
2bd0ea18 122 do_warn(
507f4e33 123_("This filesystem contains features not understood by this program.\n"));
2bd0ea18
NS
124 return(1);
125 }
126
644589b1
ES
127 if (XFS_SB_VERSION_NUM(sb) >= XFS_SB_VERSION_4)
128 fs_sb_feature_bits = 1;
2bd0ea18 129
a98b22b6
DW
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
497d0706
ES
144 if (xfs_sb_version_hasattr(sb))
145 fs_attributes = 1;
2bd0ea18 146
232470f2
ES
147 if (xfs_sb_version_hasattr2(sb))
148 fs_attributes2 = 1;
9b1d68ec 149
5f6f3660 150 if (!(sb->sb_versionnum & XFS_SB_VERSION_NLINKBIT)) {
add8ff67
ES
151 if (!no_modify) {
152 do_warn(
153_("WARNING: you have a V1 inode filesystem. It will be converted to a\n"
5f6f3660 154 "\tversion 2 inode filesystem. If you do not want this, run an older\n"
add8ff67
ES
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 }
2bd0ea18
NS
162 }
163
5e656dbb 164 if (xfs_sb_version_hasquota(sb)) {
99a1e0da 165 fs_quotas = 1;
2bd0ea18 166
99a1e0da
ES
167 if (sb->sb_uquotino != 0 && sb->sb_uquotino != NULLFSINO)
168 have_uquotino = 1;
2bd0ea18 169
99a1e0da
ES
170 if (sb->sb_gquotino != 0 && sb->sb_gquotino != NULLFSINO)
171 have_gquotino = 1;
0340d706 172
99a1e0da
ES
173 if (sb->sb_pquotino != 0 && sb->sb_pquotino != NULLFSINO)
174 have_pquotino = 1;
2bd0ea18
NS
175 }
176
5e656dbb 177 if (xfs_sb_version_hasalign(sb)) {
dd17791c
ES
178 fs_aligned_inodes = 1;
179 fs_ino_alignment = sb->sb_inoalignmt;
2bd0ea18
NS
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}