]>
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
19 #include <xfs/libxfs.h>
30 static char **cmdline
;
39 xfs_agnumber_t cur_agno
= NULLAGNUMBER
;
45 "Usage: %s [-frxV] [-p prog] [-l logdev] [-c cmd]... device\n"),
59 progname
= basename(argv
[0]);
60 while ((c
= getopt(argc
, argv
, "c:fip:rxVl:")) != EOF
) {
63 cmdline
= xrealloc(cmdline
, (ncmdline
+1)*sizeof(char*));
64 cmdline
[ncmdline
++] = optarg
;
70 x
.isreadonly
= (LIBXFS_ISREADONLY
|LIBXFS_ISINACTIVE
);
76 x
.isreadonly
= LIBXFS_ISREADONLY
;
85 printf("%s version %s\n", progname
, VERSION
);
92 if (optind
+ 1 != argc
) {
97 fsdevice
= argv
[optind
];
104 if (!libxfs_init(&x
)) {
105 fputs(_("\nfatal error -- couldn't initialize XFS library\n"),
110 if (read_bbs(XFS_SB_DADDR
, 1, &bufp
, NULL
)) {
111 dbprintf(_("%s: %s is invalid (cannot read first 512 bytes)\n"),
116 /* copy SB from buffer to in-core, converting architecture as we go */
117 libxfs_xlate_sb(bufp
, &xmount
.m_sb
, 1, XFS_SB_ALL_BITS
);
121 if (sbp
->sb_magicnum
!= XFS_SB_MAGIC
) {
122 dbprintf(_("%s: unexpected XFS SB magic number 0x%08x\n"),
123 progname
, sbp
->sb_magicnum
);
126 mp
= libxfs_mount(&xmount
, sbp
, x
.ddev
, x
.logdev
, x
.rtdev
,
127 LIBXFS_MOUNT_ROOTINOS
| LIBXFS_MOUNT_DEBUGGER
);
129 dbprintf(_("%s: device %s unusable (not an XFS filesystem?)\n"),
133 blkbb
= 1 << mp
->m_blkbb_log
;
152 for (i
= 0; !done
&& i
< ncmdline
; i
++) {
153 v
= breakline(cmdline
[i
], &c
);
155 done
= command(c
, v
);
164 if ((input
= fetchline()) == NULL
)
166 v
= breakline(input
, &c
);
168 done
= command(c
, v
);