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

« back to all changes in this revision

Viewing changes to io/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
/*
 
2
 * Copyright (c) 2003-2004 Silicon Graphics, Inc.  All Rights Reserved.
 
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 <xfs/libxfs.h>
 
34
#include "command.h"
 
35
#include "input.h"
 
36
#include "io.h"
 
37
 
 
38
char    *progname;
 
39
int     exitcode;
 
40
int     expert;
 
41
size_t  pagesize;
 
42
 
 
43
static int      ncmdline;
 
44
static char     **cmdline;
 
45
 
 
46
void
 
47
usage(void)
 
48
{
 
49
        fprintf(stderr,
 
50
                _("Usage: %s [-adFfmrRstx] [-p prog] [-c cmd]... file\n"),
 
51
                progname);
 
52
        exit(1);
 
53
}
 
54
 
 
55
void
 
56
init(
 
57
        int             argc,
 
58
        char            **argv)
 
59
{
 
60
        int             c, flags = 0;
 
61
        char            *sp;
 
62
        mode_t          mode = 0600;
 
63
        xfs_fsop_geom_t geometry = { 0 };
 
64
 
 
65
        progname = basename(argv[0]);
 
66
        pagesize = getpagesize();
 
67
        setlocale(LC_ALL, "");
 
68
        bindtextdomain(PACKAGE, LOCALEDIR);
 
69
        textdomain(PACKAGE);
 
70
 
 
71
        while ((c = getopt(argc, argv, "ac:dFfmp:rRstVx")) != EOF) {
 
72
                switch (c) {
 
73
                case 'a':       /* append */
 
74
                        flags |= IO_APPEND;
 
75
                        break;
 
76
                case 'c':       /* commands */
 
77
                        ncmdline++;
 
78
                        cmdline = realloc(cmdline, sizeof(char*) * (ncmdline));
 
79
                        if (!cmdline) {
 
80
                                perror("realloc");
 
81
                                exit(1);
 
82
                        }
 
83
                        cmdline[ncmdline-1] = optarg;
 
84
                        break;
 
85
                case 'd':
 
86
                        flags |= IO_DIRECT;
 
87
                        break;
 
88
                case 'F':
 
89
                        flags |= IO_FOREIGN;
 
90
                        break;
 
91
                case 'f':
 
92
                        flags |= IO_CREAT;
 
93
                        break;
 
94
                case 'm':
 
95
                        mode = strtoul(optarg, &sp, 0);
 
96
                        if (!sp || sp == optarg) {
 
97
                                fprintf(stderr, _("non-numeric mode -- %s\n"),
 
98
                                        optarg);
 
99
                                exit(1);
 
100
                        }
 
101
                        break;
 
102
                case 'p':
 
103
                        progname = optarg;
 
104
                        break;
 
105
                case 'r':
 
106
                        flags |= IO_READONLY;
 
107
                        break;
 
108
                case 's':
 
109
                        flags |= IO_OSYNC;
 
110
                        break;
 
111
                case 't':
 
112
                        flags |= IO_TRUNC;
 
113
                        break;
 
114
                case 'R':
 
115
                        flags |= IO_REALTIME;
 
116
                        break;
 
117
                case 'x':
 
118
                        expert = 1;
 
119
                        break;
 
120
                case 'V':
 
121
                        printf(_("%s version %s\n"), progname, VERSION);
 
122
                        exit(0);
 
123
                default:
 
124
                        usage();
 
125
                }
 
126
        }
 
127
 
 
128
        while (optind < argc) {
 
129
                if ((c = openfile(argv[optind], flags & IO_FOREIGN ?
 
130
                                        NULL : &geometry, flags, mode)) < 0)
 
131
                        exit(1);
 
132
                if (addfile(argv[optind], c, &geometry, flags) < 0)
 
133
                        exit(1);
 
134
                optind++;
 
135
        }
 
136
 
 
137
        init_commands();
 
138
}
 
139
 
 
140
int
 
141
main(
 
142
        int     argc,
 
143
        char    **argv)
 
144
{
 
145
        int     c, i, done = 0;
 
146
        char    *input;
 
147
        char    **v;
 
148
 
 
149
        init(argc, argv);
 
150
 
 
151
        for (i = 0; !done && i < ncmdline; i++) {
 
152
                v = breakline(cmdline[i], &c);
 
153
                if (c)
 
154
                        done = command(c, v);
 
155
                free(v);
 
156
        }
 
157
        if (cmdline) {
 
158
                free(cmdline);
 
159
                return exitcode;
 
160
        }
 
161
        while (!done) {
 
162
                if ((input = fetchline()) == NULL)
 
163
                        break;
 
164
                v = breakline(input, &c);
 
165
                if (c)
 
166
                        done = command(c, v);
 
167
                doneline(input, v);
 
168
        }
 
169
        return exitcode;
 
170
}