~ubuntu-branches/ubuntu/hoary/xfsprogs/hoary

« back to all changes in this revision

Viewing changes to db/init.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2004-07-28 21:11:38 UTC
  • Revision ID: james.westby@ubuntu.com-20040728211138-0v4pdnunnp7na5lm
Tags: 2.6.20-1
* New upstream release.
* Fix xfs_io segfault on non-XFS files.  (closes: #260470)
* Fix packaging botch, deleted files included.  (closes: #260491)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3
 
 * 
 
2
 * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
 
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of version 2 of the GNU General Public License as
6
6
 * published by the Free Software Foundation.
7
 
 * 
 
7
 *
8
8
 * This program is distributed in the hope that it would be useful, but
9
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 
 * 
 
11
 *
12
12
 * Further, this software is distributed without any warranty that it is
13
13
 * free of the rightful claim of any third person regarding infringement
14
14
 * or the like.  Any license provided herein, whether implied or
15
15
 * otherwise, applies only to this software file.  Patent licenses, if
16
16
 * any, provided herein do not apply to combinations of this program with
17
17
 * other software, or any other product whatsoever.
18
 
 * 
 
18
 *
19
19
 * You should have received a copy of the GNU General Public License along
20
20
 * with this program; if not, write the Free Software Foundation, Inc., 59
21
21
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22
 
 * 
 
22
 *
23
23
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
24
 * Mountain View, CA  94043, or:
25
 
 * 
26
 
 * http://www.sgi.com 
27
 
 * 
28
 
 * For further information regarding this notice, see: 
29
 
 * 
 
25
 *
 
26
 * http://www.sgi.com
 
27
 *
 
28
 * For further information regarding this notice, see:
 
29
 *
30
30
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31
31
 */
32
32
 
33
 
#include <libxfs.h>
34
 
#include <getopt.h>
 
33
#include <xfs/libxfs.h>
35
34
#include <signal.h>
36
35
#include "command.h"
37
 
#include "data.h"
38
36
#include "init.h"
39
37
#include "input.h"
40
38
#include "io.h"
41
 
#include "mount.h"
 
39
#include "init.h"
42
40
#include "sig.h"
43
41
#include "output.h"
44
42
#include "malloc.h"
45
43
 
46
 
char    *fsdevice;
47
 
char    **cmdline;
48
 
int     ncmdline;
 
44
static char     **cmdline;
 
45
static int      ncmdline;
 
46
char            *fsdevice;
 
47
int             blkbb;
 
48
int             exitcode;
 
49
int             expert_mode;
 
50
xfs_mount_t     xmount;
 
51
xfs_mount_t     *mp;
 
52
libxfs_init_t   x;
 
53
xfs_agnumber_t  cur_agno = NULLAGNUMBER;
49
54
 
50
55
static void
51
56
usage(void)
52
57
{
53
 
        dbprintf("Usage: %s [-c cmd]... [-p prog] [-l logdev] [-frxV] devname\n", progname);
 
58
        fprintf(stderr, _(
 
59
                "Usage: %s [-frxV] [-p prog] [-l logdev] [-c cmd]... device\n"),
 
60
                progname);
54
61
        exit(1);
55
62
}
56
63
 
57
64
void
58
65
init(
59
 
        int     argc,
60
 
        char    **argv)
 
66
        int             argc,
 
67
        char            **argv)
61
68
{
62
 
        int     c;
 
69
        xfs_sb_t        *sbp;
 
70
        void            *bufp = NULL;
 
71
        int             c;
63
72
 
64
73
        progname = basename(argv[0]);
65
74
        while ((c = getopt(argc, argv, "c:fip:rxVl:")) != EOF) {
69
78
                        cmdline[ncmdline++] = optarg;
70
79
                        break;
71
80
                case 'f':
72
 
                        xfsargs.disfile = 1;
 
81
                        x.disfile = 1;
73
82
                        break;
74
83
                case 'i':
75
 
                        xfsargs.isreadonly =
76
 
                                (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE);
77
 
                        flag_readonly = 1;
 
84
                        x.isreadonly = (LIBXFS_ISREADONLY|LIBXFS_ISINACTIVE);
78
85
                        break;
79
86
                case 'p':
80
87
                        progname = optarg;
81
88
                        break;
82
89
                case 'r':
83
 
                        xfsargs.isreadonly = LIBXFS_ISREADONLY;
84
 
                        flag_readonly = 1;
 
90
                        x.isreadonly = LIBXFS_ISREADONLY;
85
91
                        break;
86
92
                case 'l':
87
 
                        xfsargs.logname = optarg;
 
93
                        x.logname = optarg;
88
94
                        break;
89
95
                case 'x':
90
 
                        flag_expert_mode = 1;
 
96
                        expert_mode = 1;
91
97
                        break;
92
98
                case 'V':
93
99
                        printf("%s version %s\n", progname, VERSION);
101
107
                usage();
102
108
                /*NOTREACHED*/
103
109
        }
 
110
 
104
111
        fsdevice = argv[optind];
105
 
        if (!xfsargs.disfile)
106
 
                xfsargs.volname = fsdevice;
 
112
        if (!x.disfile)
 
113
                x.volname = fsdevice;
107
114
        else
108
 
                xfsargs.dname = fsdevice;
109
 
        xfsargs.notvolok = 1;
110
 
        if (!libxfs_init(&xfsargs)) {
111
 
                fputs("\nfatal error -- couldn't initialize XFS library\n",
 
115
                x.dname = fsdevice;
 
116
        x.notvolok = 1;
 
117
 
 
118
        if (!libxfs_init(&x)) {
 
119
                fputs(_("\nfatal error -- couldn't initialize XFS library\n"),
112
120
                        stderr);
113
121
                exit(1);
114
122
        }
115
 
        mp = dbmount();
116
 
        if (mp == NULL) {
117
 
                dbprintf("%s: %s is not a valid filesystem\n",
 
123
 
 
124
        if (read_bbs(XFS_SB_DADDR, 1, &bufp, NULL)) {
 
125
                dbprintf(_("%s: %s is invalid (cannot read first 512 bytes)\n"),
118
126
                        progname, fsdevice);
119
127
                exit(1);
120
 
                /*NOTREACHED*/
121
 
        }
 
128
        }
 
129
 
 
130
        /* copy SB from buffer to in-core, converting architecture as we go */
 
131
        libxfs_xlate_sb(bufp, &xmount.m_sb, 1, ARCH_CONVERT, XFS_SB_ALL_BITS);
 
132
        xfree(bufp);
 
133
 
 
134
        sbp = &xmount.m_sb;
 
135
        if (sbp->sb_magicnum != XFS_SB_MAGIC) {
 
136
                dbprintf(_("%s: unexpected XFS SB magic number 0x%08x\n"),
 
137
                        progname, sbp->sb_magicnum);
 
138
        }
 
139
 
 
140
        mp = libxfs_mount(&xmount, sbp, x.ddev, x.logdev, x.rtdev,
 
141
                                LIBXFS_MOUNT_ROOTINOS | LIBXFS_MOUNT_DEBUGGER);
 
142
 
122
143
        blkbb = 1 << mp->m_blkbb_log;
 
144
 
123
145
        push_cur();
124
146
        init_commands();
125
147
        init_sig();
126
148
}
 
149
 
 
150
int
 
151
main(
 
152
        int     argc,
 
153
        char    **argv)
 
154
{
 
155
        int     c, i, done = 0;
 
156
        char    *input;
 
157
        char    **v;
 
158
 
 
159
        pushfile(stdin);
 
160
        init(argc, argv);
 
161
 
 
162
        for (i = 0; !done && i < ncmdline; i++) {
 
163
                v = breakline(cmdline[i], &c);
 
164
                if (c)
 
165
                        done = command(c, v);
 
166
                xfree(v);
 
167
        }
 
168
        if (cmdline) {
 
169
                xfree(cmdline);
 
170
                return exitcode;
 
171
        }
 
172
 
 
173
        while (!done) {
 
174
                if ((input = fetchline()) == NULL)
 
175
                        break;
 
176
                v = breakline(input, &c);
 
177
                if (c)
 
178
                        done = command(c, v);
 
179
                doneline(input, v);
 
180
        }
 
181
        return exitcode;
 
182
}