]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/init.c
2 * Copyright (c) 2003-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
20 #include "platform_defs.h"
31 struct timeval stopwatch
;
37 _("Usage: %s [-adfinrRstVx] [-m mode] [-p prog] [[-c|-C] cmd]... file\n"),
47 if (!file
|| (file
->flags
& IO_FOREIGN
)) {
51 *blocksize
= file
->geom
.blocksize
;
52 *sectsize
= file
->geom
.sectsize
;
100 * This allows xfs_io commands specified on the command line to be run on every
101 * open file in the file table. Commands that should not be iterated across all
102 * open files need to specify CMD_FLAG_ONESHOT in their command flags.
108 if (index
>= filecount
)
110 file
= &filetable
[index
++];
118 if (!file
&& !(ct
->flags
& CMD_NOFILE_OK
)) {
119 fprintf(stderr
, _("no files are open, try 'help open'\n"));
122 if (!mapping
&& !(ct
->flags
& CMD_NOMAP_OK
)) {
123 fprintf(stderr
, _("no mapped regions, try 'help mmap'\n"));
126 if (file
&& !(ct
->flags
& CMD_FOREIGN_OK
) &&
127 (file
->flags
& IO_FOREIGN
)) {
129 _("foreign file active, %s command is for XFS filesystems only\n"),
144 xfs_fsop_geom_t geometry
= { 0 };
147 progname
= basename(argv
[0]);
148 setlocale(LC_ALL
, "");
149 bindtextdomain(PACKAGE
, LOCALEDIR
);
152 pagesize
= getpagesize();
153 gettimeofday(&stopwatch
, NULL
);
155 fs_table_initialise(0, NULL
, 0, NULL
);
156 while ((c
= getopt(argc
, argv
, "ac:C:dFfim:p:nrRstTVx")) != EOF
) {
162 add_user_command(optarg
);
165 add_oneshot_user_command(optarg
);
171 /* Ignored / deprecated now, handled automatically */
180 mode
= strtoul(optarg
, &sp
, 0);
181 if (!sp
|| sp
== optarg
) {
182 fprintf(stderr
, _("non-numeric mode -- %s\n"),
188 flags
|= IO_NONBLOCK
;
194 flags
|= IO_READONLY
;
203 flags
|= IO_REALTIME
;
212 printf(_("%s version %s\n"), progname
, VERSION
);
219 while (optind
< argc
) {
220 c
= openfile(argv
[optind
], &geometry
, flags
, mode
, &fsp
);
223 if (!platform_test_xfs_fd(c
))
225 if (addfile(argv
[optind
], c
, &geometry
, flags
, &fsp
) < 0)
231 add_command_iterator(filetable_iterator
);
232 add_check_command(init_check_command
);
236 * The purpose of this idle thread is to test io from a multi threaded process.
237 * With single threaded process, the file table is not shared and file structs
238 * are not reference counted. Spawning an idle thread can help detecting file
239 * struct reference leaks.
253 if (pthread_create(&t
, NULL
, idle_loop
, NULL
)) {
254 fprintf(stderr
, "Error creating idle thread\n");