]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/phase1.c
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 #include "err_protos.h"
42 do_warn(_("Sorry, could not find valid secondary superblock\n"));
43 do_warn(_("Exiting now.\n"));
48 alloc_ag_buf(int size
)
52 bp
= (char *)memalign(MEM_ALIGN
, size
);
54 do_error(_("could not allocate ag header buffer (%d bytes)\n"),
60 * this has got to be big enough to hold 4 sectors
62 #define MAX_SECTSIZE (512 * 1024)
66 phase1(xfs_mount_t
*mp
)
74 do_log(_("Phase 1 - find and verify superblock...\n"));
76 primary_sb_modified
= 0;
82 old_orphanage_ino
= (xfs_ino_t
) 0;
85 * get AG 0 into ag header buf
87 ag_bp
= alloc_ag_buf(MAX_SECTSIZE
);
88 sb
= (xfs_sb_t
*) ag_bp
;
90 if (get_sb(sb
, 0LL, MAX_SECTSIZE
, 0) == XR_EOF
)
91 do_error(_("error reading primary superblock\n"));
94 * is this really an sb, verify internal consistency
96 if ((rval
= verify_sb(sb
, 1)) != XR_OK
) {
97 do_warn(_("bad primary superblock - %s !!!\n"),
99 if (!find_secondary_sb(sb
))
101 primary_sb_modified
= 1;
102 } else if ((rval
= verify_set_primary_sb(sb
, 0,
103 &primary_sb_modified
)) != XR_OK
) {
104 do_warn(_("couldn't verify primary superblock - %s !!!\n"),
106 if (!find_secondary_sb(sb
))
108 primary_sb_modified
= 1;
111 if (primary_sb_modified
) {
113 do_warn(_("writing modified primary superblock\n"));
114 write_primary_sb(sb
, sb
->sb_sectsize
);
116 do_warn(_("would write modified primary superblock\n"));
121 * misc. global var initialization
123 sb_ifree
= sb_icount
= sb_fdblocks
= sb_frextents
= 0;