~ubuntu-branches/ubuntu/edgy/xfsprogs/edgy

« back to all changes in this revision

Viewing changes to io/init.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2005-11-16 16:32:35 UTC
  • Revision ID: james.westby@ubuntu.com-20051116163235-synnef6xjj18ny42
Tags: 2.7.7-1
* New upstream release.
* Add support for (optional) ATTR2 format extension (closes: #336350)
* Allow gcc -pedantic option for C++ <xfs.h> users (closes: #249429)
* Fix segv in xfs_db frag command (closes: #338207)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2003-2005 Silicon Graphics, Inc.  All Rights Reserved.
 
2
 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
 
3
 * All Rights Reserved.
3
4
 *
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
 
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
6
7
 * published by the Free Software Foundation.
7
8
 *
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/
 
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
31
17
 */
32
18
 
33
 
#include <xfs/libxfs.h>
34
 
#include "command.h"
35
 
#include "input.h"
 
19
#include <xfs/xfs.h>
 
20
#include <xfs/command.h>
 
21
#include <xfs/input.h>
 
22
#include "init.h"
36
23
#include "io.h"
37
24
 
38
25
char    *progname;
41
28
size_t  pagesize;
42
29
struct timeval stopwatch;
43
30
 
44
 
static int      ncmdline;
45
 
static char     **cmdline;
46
 
 
47
31
void
48
32
usage(void)
49
33
{
54
38
}
55
39
 
56
40
void
 
41
init_cvtnum(
 
42
        size_t *blocksize,
 
43
        size_t *sectsize)
 
44
{
 
45
        if (!file || (file->flags & IO_FOREIGN)) {
 
46
                *blocksize = 4096;
 
47
                *sectsize = 512;
 
48
        } else {
 
49
                *blocksize = file->geom.blocksize;
 
50
                *sectsize = file->geom.sectsize;
 
51
        }
 
52
}
 
53
 
 
54
static void
57
55
init_commands(void)
58
56
{
59
57
        attr_init();
68
66
        inject_init();
69
67
        mmap_init();
70
68
        open_init();
 
69
        parent_init();
71
70
        pread_init();
72
71
        prealloc_init();
73
72
        pwrite_init();
78
77
        truncate_init();
79
78
}
80
79
 
 
80
static int
 
81
init_args_command(
 
82
        int     index)
 
83
{
 
84
        if (index >= filecount)
 
85
                return 0;
 
86
        file = &filetable[index++];
 
87
        return index;
 
88
}
 
89
 
 
90
static int
 
91
init_check_command(
 
92
        const cmdinfo_t *ct)
 
93
{
 
94
        if (!file && !(ct->flags & CMD_NOFILE_OK)) {
 
95
                fprintf(stderr, _("no files are open, try 'help open'\n"));
 
96
                return 0;
 
97
        }
 
98
        if (!mapping && !(ct->flags & CMD_NOMAP_OK)) {
 
99
                fprintf(stderr, _("no mapped regions, try 'help mmap'\n"));
 
100
                return 0;
 
101
        }
 
102
        if (file && !(ct->flags & CMD_FOREIGN_OK) &&
 
103
                                        (file->flags & IO_FOREIGN)) {
 
104
                fprintf(stderr,
 
105
        _("foreign file active, %s command is for XFS filesystems only\n"),
 
106
                        ct->name);
 
107
                return 0;
 
108
        }
 
109
        return 1;
 
110
}
 
111
 
81
112
void
82
113
init(
83
114
        int             argc,
96
127
        pagesize = getpagesize();
97
128
        gettimeofday(&stopwatch, NULL);
98
129
 
99
 
        while ((c = getopt(argc, argv, "ac:dFfmp:rRstVx")) != EOF) {
 
130
        while ((c = getopt(argc, argv, "ac:dFfmp:nrRstVx")) != EOF) {
100
131
                switch (c) {
101
 
                case 'a':       /* append */
 
132
                case 'a':
102
133
                        flags |= IO_APPEND;
103
134
                        break;
104
 
                case 'c':       /* commands */
105
 
                        ncmdline++;
106
 
                        cmdline = realloc(cmdline, sizeof(char*) * (ncmdline));
107
 
                        if (!cmdline) {
108
 
                                perror("realloc");
109
 
                                exit(1);
110
 
                        }
111
 
                        cmdline[ncmdline-1] = optarg;
 
135
                case 'c':
 
136
                        add_user_command(optarg);
112
137
                        break;
113
138
                case 'd':
114
139
                        flags |= IO_DIRECT;
127
152
                                exit(1);
128
153
                        }
129
154
                        break;
 
155
                case 'n':
 
156
                        flags |= IO_NONBLOCK;
 
157
                        break;
130
158
                case 'p':
131
159
                        progname = optarg;
132
160
                        break;
163
191
        }
164
192
 
165
193
        init_commands();
 
194
        add_args_command(init_args_command);
 
195
        add_check_command(init_check_command);
166
196
}
167
197
 
168
198
int
170
200
        int     argc,
171
201
        char    **argv)
172
202
{
173
 
        int     c, i, j, done = 0;
174
 
        char    *input;
175
 
        char    **v;
176
 
 
177
203
        init(argc, argv);
178
 
 
179
 
        for (i = 0; !done && i < ncmdline; i++) {
180
 
                for (j = 0; !done && j < filecount; j++) {
181
 
                        file = &filetable[j];
182
 
                        v = breakline(cmdline[i], &c);
183
 
                        if (c)
184
 
                                done = command(c, v);
185
 
                        free(v);
186
 
                }
187
 
        }
188
 
        if (cmdline) {
189
 
                free(cmdline);
190
 
                return exitcode;
191
 
        }
192
 
        while (!done) {
193
 
                if ((input = fetchline()) == NULL)
194
 
                        break;
195
 
                v = breakline(input, &c);
196
 
                if (c)
197
 
                        done = command(c, v);
198
 
                doneline(input, v);
199
 
        }
 
204
        command_loop();
200
205
        return exitcode;
201
206
}