]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/init.c
29afe09a6a29b8de7f714de672f04612574f81db
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
8 #include "platform_defs.h"
19 struct timeval stopwatch
;
25 _("Usage: %s [-adfinrRstVx] [-m mode] [-p prog] [[-c|-C] cmd]... file\n"),
35 if (!file
|| (file
->flags
& IO_FOREIGN
)) {
39 *blocksize
= file
->geom
.blocksize
;
40 *sectsize
= file
->geom
.sectsize
;
91 * This allows xfs_io commands specified on the command line to be run on every
92 * open file in the file table. Commands that should not be iterated across all
93 * open files need to specify CMD_FLAG_ONESHOT in their command flags.
99 if (index
>= filecount
)
101 file
= &filetable
[index
++];
109 if (!file
&& !(ct
->flags
& CMD_NOFILE_OK
)) {
110 fprintf(stderr
, _("no files are open, try 'help open'\n"));
113 if (!mapping
&& !(ct
->flags
& CMD_NOMAP_OK
)) {
114 fprintf(stderr
, _("no mapped regions, try 'help mmap'\n"));
117 if (file
&& !(ct
->flags
& CMD_FOREIGN_OK
) &&
118 (file
->flags
& IO_FOREIGN
)) {
120 _("foreign file active, %s command is for XFS filesystems only\n"),
135 xfs_fsop_geom_t geometry
= { 0 };
138 progname
= basename(argv
[0]);
139 setlocale(LC_ALL
, "");
140 bindtextdomain(PACKAGE
, LOCALEDIR
);
143 pagesize
= getpagesize();
144 gettimeofday(&stopwatch
, NULL
);
146 fs_table_initialise(0, NULL
, 0, NULL
);
147 while ((c
= getopt(argc
, argv
, "ac:C:dFfiLm:p:PnrRstTVx")) != EOF
) {
153 add_user_command(optarg
);
156 add_oneshot_user_command(optarg
);
162 /* Ignored / deprecated now, handled automatically */
171 mode
= strtoul(optarg
, &sp
, 0);
172 if (!sp
|| sp
== optarg
) {
173 fprintf(stderr
, _("non-numeric mode -- %s\n"),
179 flags
|= IO_NONBLOCK
;
185 flags
|= IO_READONLY
;
197 flags
|= IO_NOFOLLOW
;
200 flags
|= IO_REALTIME
;
209 printf(_("%s version %s\n"), progname
, VERSION
);
216 while (optind
< argc
) {
217 c
= openfile(argv
[optind
], &geometry
, flags
, mode
, &fsp
);
220 if (!platform_test_xfs_fd(c
))
222 if (addfile(argv
[optind
], c
, &geometry
, flags
, &fsp
) < 0)
228 add_command_iterator(filetable_iterator
);
229 add_check_command(init_check_command
);
233 * The purpose of this idle thread is to test io from a multi threaded process.
234 * With single threaded process, the file table is not shared and file structs
235 * are not reference counted. Spawning an idle thread can help detecting file
236 * struct reference leaks.
247 start_idle_thread(void)
251 if (pthread_create(&t
, NULL
, idle_loop
, NULL
)) {
252 fprintf(stderr
, "Error creating idle thread\n");