]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/phase1.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[thirdparty/xfsprogs-dev.git] / repair / phase1.c
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <libxfs.h>
20 #include "globals.h"
21 #include "agheader.h"
22 #include "protos.h"
23 #include "err_protos.h"
24
25 void
26 no_sb(void)
27 {
28 do_warn(_("Sorry, could not find valid secondary superblock\n"));
29 do_warn(_("Exiting now.\n"));
30 exit(1);
31 }
32
33 char *
34 alloc_ag_buf(int size)
35 {
36 char *bp;
37
38 bp = (char *)memalign(MEM_ALIGN, size);
39 if (!bp)
40 do_error(_("could not allocate ag header buffer (%d bytes)\n"),
41 size);
42 return(bp);
43 }
44
45 /*
46 * this has got to be big enough to hold 4 sectors
47 */
48 #define MAX_SECTSIZE (512 * 1024)
49
50 /* ARGSUSED */
51 void
52 phase1(xfs_mount_t *mp)
53 {
54 xfs_sb_t *sb;
55 char *ag_bp;
56 int rval;
57
58 io_init();
59
60 do_log(_("Phase 1 - find and verify superblock...\n"));
61
62 primary_sb_modified = 0;
63 need_root_inode = 0;
64 need_root_dotdot = 0;
65 need_rbmino = 0;
66 need_rsumino = 0;
67 lost_quotas = 0;
68 old_orphanage_ino = (xfs_ino_t) 0;
69
70 /*
71 * get AG 0 into ag header buf
72 */
73 ag_bp = alloc_ag_buf(MAX_SECTSIZE);
74 sb = (xfs_sb_t *) ag_bp;
75
76 if (get_sb(sb, 0LL, MAX_SECTSIZE, 0) == XR_EOF)
77 do_error(_("error reading primary superblock\n"));
78
79 /*
80 * is this really an sb, verify internal consistency
81 */
82 if ((rval = verify_sb(sb, 1)) != XR_OK) {
83 do_warn(_("bad primary superblock - %s !!!\n"),
84 err_string(rval));
85 if (!find_secondary_sb(sb))
86 no_sb();
87 primary_sb_modified = 1;
88 } else if ((rval = verify_set_primary_sb(sb, 0,
89 &primary_sb_modified)) != XR_OK) {
90 do_warn(_("couldn't verify primary superblock - %s !!!\n"),
91 err_string(rval));
92 if (!find_secondary_sb(sb))
93 no_sb();
94 primary_sb_modified = 1;
95 }
96
97 if (primary_sb_modified) {
98 if (!no_modify) {
99 do_warn(_("writing modified primary superblock\n"));
100 write_primary_sb(sb, sb->sb_sectsize);
101 } else {
102 do_warn(_("would write modified primary superblock\n"));
103 }
104 }
105
106 /*
107 * misc. global var initialization
108 */
109 sb_ifree = sb_icount = sb_fdblocks = sb_frextents = 0;
110
111 free(sb);
112 }