]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - repair/phase1.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / repair / phase1.c
CommitLineData
2bd0ea18 1/*
0d3e0b37 2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
dfc130f3 3 *
2bd0ea18
NS
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.
dfc130f3 7 *
2bd0ea18
NS
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.
dfc130f3 11 *
2bd0ea18
NS
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.
dfc130f3 18 *
2bd0ea18
NS
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.
dfc130f3 22 *
2bd0ea18
NS
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
dfc130f3
RC
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
2bd0ea18
NS
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33#include <libxfs.h>
2bd0ea18
NS
34#include "globals.h"
35#include "agheader.h"
36#include "protos.h"
37#include "err_protos.h"
38
39void
40no_sb(void)
41{
507f4e33
NS
42 do_warn(_("Sorry, could not find valid secondary superblock\n"));
43 do_warn(_("Exiting now.\n"));
2bd0ea18
NS
44 exit(1);
45}
46
47char *
48alloc_ag_buf(int size)
49{
dfc130f3 50 char *bp;
2bd0ea18 51
dfc130f3
RC
52 bp = (char *)memalign(MEM_ALIGN, size);
53 if (!bp)
507f4e33 54 do_error(_("could not allocate ag header buffer (%d bytes)\n"),
2bd0ea18
NS
55 size);
56 return(bp);
57}
58
59/*
60 * this has got to be big enough to hold 4 sectors
61 */
62#define MAX_SECTSIZE (512 * 1024)
63
64/* ARGSUSED */
65void
66phase1(xfs_mount_t *mp)
67{
68 xfs_sb_t *sb;
69 char *ag_bp;
70 int rval;
71
72 io_init();
73
507f4e33 74 do_log(_("Phase 1 - find and verify superblock...\n"));
2bd0ea18
NS
75
76 primary_sb_modified = 0;
77 need_root_inode = 0;
78 need_root_dotdot = 0;
79 need_rbmino = 0;
80 need_rsumino = 0;
81 lost_quotas = 0;
82 old_orphanage_ino = (xfs_ino_t) 0;
83
84 /*
85 * get AG 0 into ag header buf
86 */
87 ag_bp = alloc_ag_buf(MAX_SECTSIZE);
88 sb = (xfs_sb_t *) ag_bp;
89
507f4e33
NS
90 if (get_sb(sb, 0LL, MAX_SECTSIZE, 0) == XR_EOF)
91 do_error(_("error reading primary superblock\n"));
2bd0ea18
NS
92
93 /*
94 * is this really an sb, verify internal consistency
95 */
96 if ((rval = verify_sb(sb, 1)) != XR_OK) {
507f4e33 97 do_warn(_("bad primary superblock - %s !!!\n"),
2bd0ea18
NS
98 err_string(rval));
99 if (!find_secondary_sb(sb))
100 no_sb();
101 primary_sb_modified = 1;
102 } else if ((rval = verify_set_primary_sb(sb, 0,
103 &primary_sb_modified)) != XR_OK) {
507f4e33 104 do_warn(_("couldn't verify primary superblock - %s !!!\n"),
2bd0ea18
NS
105 err_string(rval));
106 if (!find_secondary_sb(sb))
107 no_sb();
108 primary_sb_modified = 1;
109 }
dfc130f3 110
2bd0ea18
NS
111 if (primary_sb_modified) {
112 if (!no_modify) {
507f4e33 113 do_warn(_("writing modified primary superblock\n"));
2bd0ea18
NS
114 write_primary_sb(sb, sb->sb_sectsize);
115 } else {
507f4e33 116 do_warn(_("would write modified primary superblock\n"));
2bd0ea18
NS
117 }
118 }
119
120 /*
121 * misc. global var initialization
122 */
123 sb_ifree = sb_icount = sb_fdblocks = sb_frextents = 0;
124
125 free(sb);
126}