1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
11 #include "err_protos.h"
16 do_warn(_("Sorry, could not find valid secondary superblock\n"));
17 do_warn(_("Exiting now.\n"));
22 alloc_ag_buf(int size
)
26 bp
= (char *)memalign(libxfs_device_alignment(), size
);
28 do_error(_("could not allocate ag header buffer (%d bytes)\n"),
34 * this has got to be big enough to hold 4 sectors
36 #define MAX_SECTSIZE (512 * 1024)
40 phase1(xfs_mount_t
*mp
)
46 do_log(_("Phase 1 - find and verify superblock...\n"));
48 primary_sb_modified
= 0;
56 * get AG 0 into ag header buf
58 ag_bp
= alloc_ag_buf(MAX_SECTSIZE
);
59 sb
= (xfs_sb_t
*) ag_bp
;
61 rval
= get_sb(sb
, 0LL, MAX_SECTSIZE
, 0);
63 do_error(_("error reading primary superblock\n"));
66 * is this really an sb, verify internal consistency
69 do_warn(_("bad primary superblock - %s !!!\n"),
71 if (!find_secondary_sb(sb
))
73 primary_sb_modified
= 1;
74 } else if ((rval
= verify_set_primary_sb(sb
, 0,
75 &primary_sb_modified
)) != XR_OK
) {
76 do_warn(_("couldn't verify primary superblock - %s !!!\n"),
78 if (!find_secondary_sb(sb
))
80 primary_sb_modified
= 1;
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.
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"));
98 * apply any version changes or conversions after the primary
99 * superblock has been verified or repaired
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.
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
;
109 sb
->sb_bad_features2
|= XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
110 primary_sb_modified
= 1;
111 printf(_("Enabling lazy-counters\n"));
112 } else if (!lazy_count
&& xfs_sb_version_haslazysbcount(sb
)) {
113 if (XFS_SB_VERSION_NUM(sb
) == XFS_SB_VERSION_5
) {
115 _("Cannot disable lazy-counters on V5 fs\n"));
118 sb
->sb_features2
&= ~XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
119 sb
->sb_bad_features2
&= ~XFS_SB_VERSION2_LAZYSBCOUNTBIT
;
120 printf(_("Disabling lazy-counters\n"));
121 primary_sb_modified
= 1;
123 printf(_("Lazy-counters are already %s\n"),
124 lazy_count
? _("enabled") : _("disabled"));
125 exit(0); /* no conversion required, exit */
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;
136 if (primary_sb_modified
) {
138 do_warn(_("writing modified primary superblock\n"));
139 write_primary_sb(sb
, sb
->sb_sectsize
);
141 do_warn(_("would write modified primary superblock\n"));
146 * misc. global var initialization
148 sb_ifree
= sb_icount
= sb_fdblocks
= sb_frextents
= 0;