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