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