forget about device fd, we don't need it
[arla.git] / appl / fs / fs_nnpfsdebug.c
blob179e4ba8ef524812a6d78e46a0376e154f179d2a
1 /*
2 * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "fs_local.h"
36 RCSID("$Id$");
38 static const unsigned all = (0
39 #ifdef HAVE_XDEBDEV
40 | XDEBDEV
41 #endif
42 #ifdef HAVE_XDEBMSG
43 | XDEBMSG
44 #endif
45 #ifdef HAVE_XDEBDNLC
46 | XDEBDNLC
47 #endif
48 #ifdef HAVE_XDEBNODE
49 | XDEBNODE
50 #endif
51 #ifdef HAVE_XDEBVNOPS
52 | XDEBVNOPS
53 #endif
54 #ifdef HAVE_XDEBVFOPS
55 | XDEBVFOPS
56 #endif
57 #ifdef HAVE_XDEBLKM
58 | XDEBLKM
59 #endif
60 #ifdef HAVE_XDEBSYS
61 | XDEBSYS
62 #endif
63 #ifdef HAVE_XDEBMEM
64 | XDEBMEM
65 #endif
66 #ifdef HAVE_XDEBREADDIR
67 | XDEBREADDIR
68 #endif
69 #ifdef HAVE_XDEBLOCK
70 | XDEBLOCK
71 #endif
72 #ifdef HAVE_XDEBCACHE
73 | XDEBCACHE
74 #endif
77 static const unsigned almost_all_mask = (0
78 #ifdef HAVE_XDEBDEV
79 | XDEBDEV
80 #endif
81 #ifdef HAVE_XDEBMEM
82 | XDEBMEM
83 #endif
84 #ifdef HAVE_XDEBREADDIR
85 | XDEBREADDIR
86 #endif
89 static struct units nnpfsdebug_units[] = {
90 {"all", 0},
91 {"almost-all", 0},
92 #ifdef HAVE_XDEBCACHE
93 {"cache", XDEBCACHE},
94 #endif
95 #ifdef HAVE_XDEBLOCK
96 {"lock", XDEBLOCK},
97 #endif
98 #ifdef HAVE_XDEBREADDIR
99 {"readdir", XDEBREADDIR},
100 #endif
101 #ifdef HAVE_XDEBMEM
102 {"mem", XDEBMEM},
103 #endif
104 #ifdef HAVE_XDEBSYS
105 {"sys", XDEBSYS},
106 #endif
107 #ifdef HAVE_XDEBLKM
108 {"lkm", XDEBLKM},
109 #endif
110 #ifdef HAVE_XDEBVFOPS
111 {"vfsops", XDEBVFOPS},
112 #endif
113 #ifdef HAVE_XDEBVNOPS
114 {"vnops", XDEBVNOPS},
115 #endif
116 #ifdef HAVE_XDEBNODE
117 {"node", XDEBNODE},
118 #endif
119 #ifdef HAVE_XDEBDNLC
120 {"dnlc", XDEBDNLC},
121 #endif
122 #ifdef HAVE_XDEBMSG
123 {"msg", XDEBMSG},
124 #endif
125 #ifdef HAVE_XDEBDEV
126 {"dev", XDEBDEV},
127 #endif
128 {"none", 0 },
129 { NULL, 0 }
133 nnpfsdebug_cmd (int argc, char **argv)
135 int ret;
136 int flags;
138 nnpfsdebug_units[0].mult = all;
139 nnpfsdebug_units[1].mult = all & ~almost_all_mask;
141 if ((argc > 1 && strncmp(argv[1], "-h", 2) == 0) || argc > 2) {
142 fprintf (stderr, "usage: nnpfsdebug [-h] [");
143 print_flags_table (nnpfsdebug_units, stderr);
144 fprintf (stderr, "]\n");
145 return 0;
148 ret = nnpfs_debug (-1, &flags);
149 if (ret) {
150 fprintf (stderr, "nnpfs_debug: %s\n", strerror(ret));
151 return 0;
154 if (argc == 1) {
155 char buf[1024];
157 unparse_flags (flags, nnpfsdebug_units, buf, sizeof(buf));
158 printf("nnpfsdebug is: %s\n", buf);
159 } else if (argc == 2) {
160 char *textflags;
162 textflags = argv[1];
164 ret = parse_flags (textflags, nnpfsdebug_units, flags);
166 if (ret < 0) {
167 fprintf (stderr, "nnpfsdebug: unknown/bad flags `%s'\n",
168 textflags);
169 return 0;
172 flags = ret;
173 ret = nnpfs_debug(flags, NULL);
174 if (ret)
175 fprintf (stderr, "nnpfs_debug: %s\n", strerror(ret));
177 return 0;
181 nnpfsdebug_print_cmd (int argc, char **argv)
183 int ret;
184 int flags = 0;
185 char *textflags;
187 nnpfsdebug_units[0].mult = all;
188 nnpfsdebug_units[1].mult = all & ~almost_all_mask;
190 if (argc != 2 && argc != 3) {
191 fprintf (stderr, "usage: nnpfsprint <");
192 print_flags_table (nnpfsdebug_units, stderr);
193 fprintf (stderr, "> [filename]\n");
194 return 0;
197 textflags = argv[1];
199 ret = parse_flags (textflags, nnpfsdebug_units, flags);
201 if (ret < 0) {
202 fprintf (stderr, "nnpfsprint: unknown/bad flags `%s'\n",
203 textflags);
204 return 0;
207 flags = ret;
208 ret = nnpfs_debug_print(flags, argv[2]);
209 if (ret)
210 fprintf (stderr, "nnpfsprint: %s\n", strerror(ret));
211 return 0;