]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/phase1.c
a3bc895a94305cb858214107fc3d018f0454f559
2 * Copyright (c) 2000 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/
38 #include "err_protos.h"
43 do_warn("Sorry, could not find valid secondary superblock\n");
44 do_warn("Exiting now.\n");
49 alloc_ag_buf(int size
)
53 bp
= (char *)memalign(MEM_ALIGN
, size
);
55 do_error("could not allocate ag header buffer (%d bytes)\n",
61 * this has got to be big enough to hold 4 sectors
63 #define MAX_SECTSIZE (512 * 1024)
67 phase1(xfs_mount_t
*mp
)
75 do_log("Phase 1 - find and verify superblock...\n");
77 primary_sb_modified
= 0;
83 old_orphanage_ino
= (xfs_ino_t
) 0;
86 * get AG 0 into ag header buf
88 ag_bp
= alloc_ag_buf(MAX_SECTSIZE
);
89 sb
= (xfs_sb_t
*) ag_bp
;
91 if (get_sb(sb
, 0LL, MAX_SECTSIZE
, 0) == XR_EOF
) {
92 do_error("error reading primary superblock\n");
96 * is this really an sb, verify internal consistency
98 if ((rval
= verify_sb(sb
, 1)) != XR_OK
) {
99 do_warn("bad primary superblock - %s !!!\n",
101 if (!find_secondary_sb(sb
))
103 primary_sb_modified
= 1;
104 } else if ((rval
= verify_set_primary_sb(sb
, 0,
105 &primary_sb_modified
)) != XR_OK
) {
106 do_warn("couldn't verify primary superblock - %s !!!\n",
108 if (!find_secondary_sb(sb
))
110 primary_sb_modified
= 1;
113 if (primary_sb_modified
) {
115 do_warn("writing modified primary superblock\n");
116 write_primary_sb(sb
, sb
->sb_sectsize
);
118 do_warn("would write modified primary superblock\n");
123 * misc. global var initialization
125 sb_ifree
= sb_icount
= sb_fdblocks
= sb_frextents
= 0;