]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/init.c
2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
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.
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.
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
32 static char **cmdline
;
39 struct xfs_mount xmount
;
43 xfs_agnumber_t cur_agno
= NULLAGNUMBER
;
49 "Usage: %s [-ifFrxV] [-p prog] [-l logdev] [-c cmd]... device\n"
64 setlocale(LC_ALL
, "");
65 bindtextdomain(PACKAGE
, LOCALEDIR
);
68 progname
= basename(argv
[0]);
69 while ((c
= getopt(argc
, argv
, "c:fFip:rxVl:")) != EOF
) {
72 cmdline
= xrealloc(cmdline
, (ncmdline
+1)*sizeof(char*));
73 cmdline
[ncmdline
++] = optarg
;
82 x
.isreadonly
= (LIBXFS_ISREADONLY
|LIBXFS_ISINACTIVE
);
88 x
.isreadonly
= LIBXFS_ISREADONLY
;
97 printf(_("%s version %s\n"), progname
, VERSION
);
104 if (optind
+ 1 != argc
) {
109 fsdevice
= argv
[optind
];
111 x
.volname
= fsdevice
;
115 x
.bcache_flags
= CACHE_MISCOMPARE_PURGE
;
116 if (!libxfs_init(&x
)) {
117 fputs(_("\nfatal error -- couldn't initialize XFS library\n"),
123 * Read the superblock, but don't validate it - we are a diagnostic
124 * tool and so need to be able to mount busted filesystems.
126 memset(&xmount
, 0, sizeof(struct xfs_mount
));
127 libxfs_buftarg_init(&xmount
, x
.ddev
, x
.logdev
, x
.rtdev
);
128 bp
= libxfs_readbuf(xmount
.m_ddev_targp
, XFS_SB_DADDR
,
129 1 << (XFS_MAX_SECTORSIZE_LOG
- BBSHIFT
), 0, NULL
);
131 if (!bp
|| bp
->b_error
) {
132 fprintf(stderr
, _("%s: %s is invalid (cannot read first 512 "
133 "bytes)\n"), progname
, fsdevice
);
137 /* copy SB from buffer to in-core, converting architecture as we go */
138 libxfs_sb_from_disk(&xmount
.m_sb
, XFS_BUF_TO_SBP(bp
));
143 if (sbp
->sb_magicnum
!= XFS_SB_MAGIC
) {
144 fprintf(stderr
, _("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n"),
145 progname
, fsdevice
, sbp
->sb_magicnum
);
147 fprintf(stderr
, _("Use -F to force a read attempt.\n"));
152 agcount
= sbp
->sb_agcount
;
153 mp
= libxfs_mount(&xmount
, sbp
, x
.ddev
, x
.logdev
, x
.rtdev
,
154 LIBXFS_MOUNT_DEBUGGER
);
157 _("%s: device %s unusable (not an XFS filesystem?)\n"),
162 blkbb
= 1 << mp
->m_blkbb_log
;
164 /* Did we limit a broken agcount in libxfs_mount? */
165 if (sbp
->sb_agcount
!= agcount
)
169 * xfs_check needs corrected incore superblock values
171 if (sbp
->sb_rootino
!= NULLFSINO
&&
172 xfs_sb_version_haslazysbcount(&mp
->m_sb
)) {
173 int error
= -libxfs_initialize_perag_data(mp
, sbp
->sb_agcount
);
176 _("%s: cannot init perag data (%d). Continuing anyway.\n"),
181 if (xfs_sb_version_hassparseinodes(&mp
->m_sb
))
182 type_set_tab_spcrc();
183 else if (xfs_sb_version_hascrc(&mp
->m_sb
))
202 start_iocur_sp
= iocur_sp
;
204 for (i
= 0; !done
&& i
< ncmdline
; i
++) {
205 v
= breakline(cmdline
[i
], &c
);
207 done
= command(c
, v
);
217 if ((input
= fetchline()) == NULL
)
219 v
= breakline(input
, &c
);
221 done
= command(c
, v
);
227 * Make sure that we pop the all the buffer contexts we hold so that
228 * they are released before we purge the caches during unmount.
230 while (iocur_sp
> start_iocur_sp
)
234 libxfs_device_close(x
.ddev
);
235 if (x
.logdev
&& x
.logdev
!= x
.ddev
)
236 libxfs_device_close(x
.logdev
);
238 libxfs_device_close(x
.rtdev
);