]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/file.c
958cebda315b1e7b893a500e7a1c1268fa78a8a3
[thirdparty/xfsprogs-dev.git] / io / file.c
1 /*
2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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
17 */
18
19 #include <xfs/libxfs.h>
20 #include <xfs/command.h>
21 #include <xfs/input.h>
22 #include <sys/mman.h>
23 #include "init.h"
24 #include "io.h"
25
26 static cmdinfo_t file_cmd;
27 static cmdinfo_t print_cmd;
28
29 fileio_t *filetable;
30 int filecount;
31 fileio_t *file;
32
33 static void
34 print_fileio(
35 fileio_t *file,
36 int index,
37 int braces)
38 {
39 printf(_("%c%03d%c %-14s (%s,%s,%s,%s%s%s%s)\n"),
40 braces? '[' : ' ', index, braces? ']' : ' ', file->name,
41 file->flags & IO_FOREIGN ? _("foreign") : _("xfs"),
42 file->flags & IO_OSYNC ? _("sync") : _("non-sync"),
43 file->flags & IO_DIRECT ? _("direct") : _("non-direct"),
44 file->flags & IO_READONLY ? _("read-only") : _("read-write"),
45 file->flags & IO_REALTIME ? _(",real-time") : "",
46 file->flags & IO_APPEND ? _(",append-only") : "",
47 file->flags & IO_NONBLOCK ? _(",non-block") : "");
48 }
49
50 int
51 filelist_f(void)
52 {
53 int i;
54
55 for (i = 0; i < filecount; i++)
56 print_fileio(&filetable[i], i, &filetable[i] == file);
57 return 0;
58 }
59
60 static int
61 print_f(
62 int argc,
63 char **argv)
64 {
65 filelist_f();
66 maplist_f();
67 return 0;
68 }
69
70 static int
71 file_f(
72 int argc,
73 char **argv)
74 {
75 int i;
76
77 if (argc <= 1)
78 return filelist_f();
79 i = atoi(argv[1]);
80 if (i < 0 || i >= filecount) {
81 printf(_("value %d is out of range (0-%d)\n"), i, filecount-1);
82 } else {
83 file = &filetable[i];
84 filelist_f();
85 }
86 return 0;
87 }
88
89 void
90 file_init(void)
91 {
92 file_cmd.name = _("file");
93 file_cmd.altname = _("f");
94 file_cmd.args = _("[N]");
95 file_cmd.cfunc = file_f;
96 file_cmd.argmin = 0;
97 file_cmd.argmax = 1;
98 file_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
99 file_cmd.oneline = _("set the current file");
100
101 print_cmd.name = _("print");
102 print_cmd.altname = _("p");
103 print_cmd.cfunc = print_f;
104 print_cmd.argmin = 0;
105 print_cmd.argmax = 0;
106 print_cmd.flags = CMD_NOMAP_OK | CMD_NOFILE_OK | CMD_FOREIGN_OK;
107 print_cmd.oneline = _("list current open files and memory mappings");
108
109 add_command(&file_cmd);
110 add_command(&print_cmd);
111 }