2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
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.
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.
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
23 #include "err_protos.h"
28 do_warn(_("Sorry, could not find valid secondary superblock\n"));
29 do_warn(_("Exiting now.\n"));
34 alloc_ag_buf(int size
)
38 bp
= (char *)memalign(libxfs_device_alignment(), size
);
40 do_error(_("could not allocate ag header buffer (%d bytes)\n"),
46 * this has got to be big enough to hold 4 sectors
48 #define MAX_SECTSIZE (512 * 1024)
52 phase1(xfs_mount_t
*mp
)
58 do_log(_("Phase 1 - find and verify superblock...\n"));
60 primary_sb_modified
= 0;
68 * get AG 0 into ag header buf
70 ag_bp
= alloc_ag_buf(MAX_SECTSIZE
);
71 sb
= (xfs_sb_t
*) ag_bp
;
73 rval
= get_sb(sb
, 0LL, MAX_SECTSIZE
, 0);
75 do_error(_("error reading primary superblock\n"));
78 * is this really an sb, verify internal consistency
81 do_warn(_("bad primary superblock - %s !!!\n"),
83 if (!find_secondary_sb(sb
))
85 primary_sb_modified
= 1;
86 } else if ((rval
= verify_set_primary_sb(sb
, 0,
87 &primary_sb_modified
)) != XR_OK
) {
88 do_warn(_("couldn't verify primary superblock - %s !!!\n"),
90 if (!find_secondary_sb(sb
))
92 primary_sb_modified
= 1;
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.
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"));
110 * apply any version changes or conversions after the primary
111 * superblock has been verified or repaired
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.
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
;
121 sb
->sb_bad_features2
|= XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
122 primary_sb_modified
= 1;
123 printf(_("Enabling lazy-counters\n"));
124 } else if (!lazy_count
&& xfs_sb_version_haslazysbcount(sb
)) {
125 if (XFS_SB_VERSION_NUM(sb
) == XFS_SB_VERSION_5
) {
127 _("Cannot disable lazy-counters on V5 fs\n"));
130 sb
->sb_features2
&= ~XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
131 sb
->sb_bad_features2
&= ~XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
132 printf(_("Disabling lazy-counters\n"));
133 primary_sb_modified
= 1;
135 printf(_("Lazy-counters are already %s\n"),
136 lazy_count
? _("enabled") : _("disabled"));
137 exit(0); /* no conversion required, exit */
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;
148 if (primary_sb_modified
) {
150 do_warn(_("writing modified primary superblock\n"));
151 write_primary_sb(sb
, sb
->sb_sectsize
);
153 do_warn(_("would write modified primary superblock\n"));
158 * misc. global var initialization
160 sb_ifree
= sb_icount
= sb_fdblocks
= sb_frextents
= 0;