]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - io/file.c
xfs: add xfs_verify_agino_or_null helper
[thirdparty/xfsprogs-dev.git] / io / file.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
48c46ee3 2/*
da23017d
NS
3 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
48c46ee3
NS
5 */
6
6b803e5a
CH
7#include "command.h"
8#include "input.h"
48c46ee3 9#include <sys/mman.h>
48c46ee3
NS
10#include "init.h"
11#include "io.h"
12
13static cmdinfo_t file_cmd;
14static cmdinfo_t print_cmd;
15
16fileio_t *filetable;
17int filecount;
18fileio_t *file;
19
20static void
21print_fileio(
22 fileio_t *file,
23 int index,
24 int braces)
25{
fc52865c 26 printf(_("%c%03d%c %-14s (%s,%s,%s,%s%s%s%s%s%s%s)\n"),
48c46ee3
NS
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") : "",
57f46ec0 33 file->flags & IO_APPEND ? _(",append-only") : "",
da2b3c09 34 file->flags & IO_NONBLOCK ? _(",non-block") : "",
fc52865c
DH
35 file->flags & IO_TMPFILE ? _(",tmpfile") : "",
36 file->flags & IO_PATH ? _(",path") : "",
37 file->flags & IO_NOFOLLOW ? _(",nofollow") : "");
48c46ee3
NS
38}
39
40int
41filelist_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
50static int
51print_f(
52 int argc,
53 char **argv)
54{
55 filelist_f();
56 maplist_f();
57 return 0;
58}
59
60static int
61file_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) {
24cd0fec 71 printf(_("value %d is out of range (0-%d)\n"), i, filecount-1);
48c46ee3
NS
72 } else {
73 file = &filetable[i];
74 filelist_f();
75 }
76 return 0;
77}
78
79void
80file_init(void)
81{
ad765595
AM
82 file_cmd.name = "file";
83 file_cmd.altname = "f";
48c46ee3
NS
84 file_cmd.args = _("[N]");
85 file_cmd.cfunc = file_f;
86 file_cmd.argmin = 0;
87 file_cmd.argmax = 1;
16bf0464 88 file_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK | CMD_FLAG_ONESHOT;
48c46ee3
NS
89 file_cmd.oneline = _("set the current file");
90
ad765595
AM
91 print_cmd.name = "print";
92 print_cmd.altname = "p";
48c46ee3
NS
93 print_cmd.cfunc = print_f;
94 print_cmd.argmin = 0;
95 print_cmd.argmax = 0;
802d66e3 96 print_cmd.flags = CMD_NOMAP_OK | CMD_NOFILE_OK | CMD_FOREIGN_OK |
7a9b7314 97 CMD_FLAG_ONESHOT;
48c46ee3
NS
98 print_cmd.oneline = _("list current open files and memory mappings");
99
100 add_command(&file_cmd);
101 add_command(&print_cmd);
102}