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