]>
Commit | Line | Data |
---|---|---|
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 NS |
8 | #include "globals.h" |
9 | #include "agheader.h" | |
10 | #include "protos.h" | |
11 | #include "err_protos.h" | |
12 | ||
8b8a6b02 | 13 | static void |
2bd0ea18 NS |
14 | no_sb(void) |
15 | { | |
507f4e33 NS |
16 | do_warn(_("Sorry, could not find valid secondary superblock\n")); |
17 | do_warn(_("Exiting now.\n")); | |
2bd0ea18 NS |
18 | exit(1); |
19 | } | |
20 | ||
21 | char * | |
22 | alloc_ag_buf(int size) | |
23 | { | |
dfc130f3 | 24 | char *bp; |
2bd0ea18 | 25 | |
b74a1f6a | 26 | bp = (char *)memalign(libxfs_device_alignment(), size); |
dfc130f3 | 27 | if (!bp) |
507f4e33 | 28 | do_error(_("could not allocate ag header buffer (%d bytes)\n"), |
2bd0ea18 NS |
29 | size); |
30 | return(bp); | |
31 | } | |
32 | ||
33 | /* | |
34 | * this has got to be big enough to hold 4 sectors | |
35 | */ | |
36 | #define MAX_SECTSIZE (512 * 1024) | |
37 | ||
38 | /* ARGSUSED */ | |
39 | void | |
40 | phase1(xfs_mount_t *mp) | |
41 | { | |
42 | xfs_sb_t *sb; | |
43 | char *ag_bp; | |
44 | int rval; | |
45 | ||
507f4e33 | 46 | do_log(_("Phase 1 - find and verify superblock...\n")); |
2bd0ea18 NS |
47 | |
48 | primary_sb_modified = 0; | |
49 | need_root_inode = 0; | |
50 | need_root_dotdot = 0; | |
51 | need_rbmino = 0; | |
52 | need_rsumino = 0; | |
53 | lost_quotas = 0; | |
2bd0ea18 NS |
54 | |
55 | /* | |
56 | * get AG 0 into ag header buf | |
57 | */ | |
58 | ag_bp = alloc_ag_buf(MAX_SECTSIZE); | |
59 | sb = (xfs_sb_t *) ag_bp; | |
60 | ||
88f364a9 DC |
61 | rval = get_sb(sb, 0LL, MAX_SECTSIZE, 0); |
62 | if (rval == XR_EOF) | |
507f4e33 | 63 | do_error(_("error reading primary superblock\n")); |
2bd0ea18 NS |
64 | |
65 | /* | |
66 | * is this really an sb, verify internal consistency | |
67 | */ | |
88f364a9 | 68 | if (rval != XR_OK) { |
507f4e33 | 69 | do_warn(_("bad primary superblock - %s !!!\n"), |
2bd0ea18 NS |
70 | err_string(rval)); |
71 | if (!find_secondary_sb(sb)) | |
72 | no_sb(); | |
73 | primary_sb_modified = 1; | |
74 | } else if ((rval = verify_set_primary_sb(sb, 0, | |
75 | &primary_sb_modified)) != XR_OK) { | |
507f4e33 | 76 | do_warn(_("couldn't verify primary superblock - %s !!!\n"), |
2bd0ea18 NS |
77 | err_string(rval)); |
78 | if (!find_secondary_sb(sb)) | |
79 | no_sb(); | |
80 | primary_sb_modified = 1; | |
81 | } | |
dfc130f3 | 82 | |
45935737 BN |
83 | /* |
84 | * Check bad_features2 and make sure features2 the same as | |
85 | * bad_features (ORing the two together). Leave bad_features2 | |
86 | * set so older kernels can still use it and not mount unsupported | |
87 | * filesystems when it reads bad_features2. | |
88 | */ | |
89 | if (sb->sb_bad_features2 != 0 && | |
90 | sb->sb_bad_features2 != sb->sb_features2) { | |
91 | sb->sb_features2 |= sb->sb_bad_features2; | |
92 | sb->sb_bad_features2 = sb->sb_features2; | |
93 | primary_sb_modified = 1; | |
94 | do_warn(_("superblock has a features2 mismatch, correcting\n")); | |
95 | } | |
96 | ||
4af916f8 BN |
97 | /* |
98 | * apply any version changes or conversions after the primary | |
99 | * superblock has been verified or repaired | |
100 | * | |
101 | * Send output to stdout as do_log and everything else in repair | |
102 | * is sent to stderr and there is no "quiet" option. xfs_admin | |
103 | * will filter stderr but not stdout. This situation must be improved. | |
104 | */ | |
105 | if (convert_lazy_count) { | |
106 | if (lazy_count && !xfs_sb_version_haslazysbcount(sb)) { | |
107 | sb->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT; | |
108 | sb->sb_features2 |= XFS_SB_VERSION2_LAZYSBCOUNTBIT; | |
63b84a85 | 109 | sb->sb_bad_features2 |= XFS_SB_VERSION2_LAZYSBCOUNTBIT; |
4af916f8 BN |
110 | primary_sb_modified = 1; |
111 | printf(_("Enabling lazy-counters\n")); | |
c40f279a ES |
112 | } else if (!lazy_count && xfs_sb_version_haslazysbcount(sb)) { |
113 | if (XFS_SB_VERSION_NUM(sb) == XFS_SB_VERSION_5) { | |
114 | printf( | |
115 | _("Cannot disable lazy-counters on V5 fs\n")); | |
116 | exit(1); | |
117 | } | |
4af916f8 | 118 | sb->sb_features2 &= ~XFS_SB_VERSION2_LAZYSBCOUNTBIT; |
63b84a85 | 119 | sb->sb_bad_features2 &= ~XFS_SB_VERSION2_LAZYSBCOUNTBIT; |
4af916f8 BN |
120 | printf(_("Disabling lazy-counters\n")); |
121 | primary_sb_modified = 1; | |
122 | } else { | |
123 | printf(_("Lazy-counters are already %s\n"), | |
124 | lazy_count ? _("enabled") : _("disabled")); | |
125 | exit(0); /* no conversion required, exit */ | |
126 | } | |
127 | } | |
128 | ||
fa2a8c17 DW |
129 | /* shared_vn should be zero */ |
130 | if (sb->sb_shared_vn) { | |
131 | do_warn(_("resetting shared_vn to zero\n")); | |
132 | sb->sb_shared_vn = 0; | |
133 | primary_sb_modified = 1; | |
134 | } | |
135 | ||
2bd0ea18 NS |
136 | if (primary_sb_modified) { |
137 | if (!no_modify) { | |
507f4e33 | 138 | do_warn(_("writing modified primary superblock\n")); |
2bd0ea18 NS |
139 | write_primary_sb(sb, sb->sb_sectsize); |
140 | } else { | |
507f4e33 | 141 | do_warn(_("would write modified primary superblock\n")); |
2bd0ea18 NS |
142 | } |
143 | } | |
144 | ||
145 | /* | |
146 | * misc. global var initialization | |
147 | */ | |
148 | sb_ifree = sb_icount = sb_fdblocks = sb_frextents = 0; | |
149 | ||
150 | free(sb); | |
151 | } |