]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/fprint.c
xfsprogs: call libxfs_destroy from other utilities
[thirdparty/xfsprogs-dev.git] / db / fprint.c
CommitLineData
2bd0ea18 1/*
da23017d
NS
2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
dfc130f3 4 *
da23017d
NS
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
2bd0ea18 7 * published by the Free Software Foundation.
dfc130f3 8 *
da23017d
NS
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.
dfc130f3 13 *
da23017d
NS
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
2bd0ea18
NS
17 */
18
6b803e5a 19#include "libxfs.h"
2bd0ea18
NS
20#include <ctype.h>
21#include <time.h>
22#include "type.h"
23#include "faddr.h"
24#include "fprint.h"
25#include "field.h"
26#include "inode.h"
49b31417 27#include "btblock.h"
2bd0ea18
NS
28#include "bit.h"
29#include "print.h"
30#include "output.h"
31#include "sig.h"
32#include "malloc.h"
0522f1cc 33#include "io.h"
2bd0ea18
NS
34
35int
36fp_charns(
37 void *obj,
38 int bit,
39 int count,
40 char *fmtstr,
41 int size,
42 int arg,
43 int base,
44 int array)
45{
46 int i;
47 char *p;
48
49 ASSERT(bitoffs(bit) == 0);
50 ASSERT(size == bitsz(char));
51 dbprintf("\"");
52 for (i = 0, p = (char *)obj + byteize(bit);
53 i < count && !seenint();
54 i++, p++) {
55 if (*p == '\\' || *p == '\'' || *p == '"' || *p == '\?')
56 dbprintf("\\%c", *p);
93d9f139 57 else if (isgraph((int)*p) || *p == ' ')
2bd0ea18
NS
58 dbprintf("%c", *p);
59 else if (*p == '\a' || *p == '\b' || *p == '\f' || *p == '\n' ||
60 *p == '\r' || *p == '\t' || *p == '\v')
61 dbprintf("\\%c", *p + ('a' - '\a'));
62 else
63 dbprintf("\\%03o", *p & 0xff);
64 }
65 dbprintf("\"");
66 return 1;
67}
68
69int
70fp_num(
71 void *obj,
72 int bit,
73 int count,
74 char *fmtstr,
75 int size,
76 int arg,
77 int base,
78 int array)
79{
80 int bitpos;
81 int i;
82 int isnull;
14f8b681 83 int64_t val;
2bd0ea18
NS
84
85 for (i = 0, bitpos = bit;
86 i < count && !seenint();
87 i++, bitpos += size) {
88 val = getbitval(obj, bitpos, size,
89 (arg & FTARG_SIGNED) ? BVSIGNED : BVUNSIGNED);
90 if ((arg & FTARG_SKIPZERO) && val == 0)
91 continue;
92 isnull = (arg & FTARG_SIGNED) || size == 64 ?
93 val == -1LL : val == ((1LL << size) - 1LL);
94 if ((arg & FTARG_SKIPNULL) && isnull)
95 continue;
0ebbf1d5 96 if (array && count > 1)
2bd0ea18
NS
97 dbprintf("%d:", i + base);
98 if ((arg & FTARG_DONULL) && isnull)
9ee7055c 99 dbprintf(_("null"));
2bd0ea18
NS
100 else if (size > 32)
101 dbprintf(fmtstr, val);
102 else
14f8b681 103 dbprintf(fmtstr, (int32_t)val);
2bd0ea18
NS
104 if (i < count - 1)
105 dbprintf(" ");
106 }
107 return 1;
108}
109
110/*ARGSUSED*/
111int
112fp_sarray(
113 void *obj,
114 int bit,
115 int count,
116 char *fmtstr,
117 int size,
118 int arg,
119 int base,
120 int array)
121{
122 print_sarray(obj, bit, count, size, base, array,
123 (const field_t *)fmtstr, (arg & FTARG_SKIPNMS) != 0);
124 return 1;
125}
126
127/*ARGSUSED*/
128int
129fp_time(
130 void *obj,
131 int bit,
132 int count,
133 char *fmtstr,
134 int size,
135 int arg,
136 int base,
137 int array)
138{
139 int bitpos;
140 char *c;
141 int i;
dfc130f3 142 time_t t;
2bd0ea18
NS
143
144 ASSERT(bitoffs(bit) == 0);
145 for (i = 0, bitpos = bit;
146 i < count && !seenint();
147 i++, bitpos += size) {
148 if (array)
149 dbprintf("%d:", i + base);
ba795fb1
DW
150 t = (time_t)getbitval((char *)obj + byteize(bitpos), 0,
151 sizeof(int32_t) * 8, BVSIGNED);
2bd0ea18
NS
152 c = ctime(&t);
153 dbprintf("%24.24s", c);
154 if (i < count - 1)
155 dbprintf(" ");
156 }
157 return 1;
158}
159
160/*ARGSUSED*/
161int
162fp_uuid(
163 void *obj,
164 int bit,
165 int count,
166 char *fmtstr,
167 int size,
168 int arg,
169 int base,
170 int array)
171{
172 char bp[40]; /* UUID string is 36 chars + trailing '\0' */
173 int i;
174 uuid_t *p;
175
176 ASSERT(bitoffs(bit) == 0);
177 for (p = (uuid_t *)((char *)obj + byteize(bit)), i = 0;
178 i < count && !seenint();
179 i++, p++) {
180 if (array)
181 dbprintf("%d:", i + base);
4d32d744 182 platform_uuid_unparse(p, bp);
2bd0ea18
NS
183 dbprintf("%s", bp);
184 if (i < count - 1)
185 dbprintf(" ");
186 }
187 return 1;
188}
0522f1cc
DC
189
190/*
191 * CRC is correct is the current buffer it is being pulled out
192 * of is not marked with a EFSCORRUPTED error.
193 */
194int
195fp_crc(
196 void *obj,
197 int bit,
198 int count,
199 char *fmtstr,
200 int size,
201 int arg,
202 int base,
203 int array)
204{
205 int bitpos;
206 int i;
14f8b681 207 int64_t val;
0522f1cc
DC
208 char *ok;
209
b511ff41
DC
210 switch (iocur_crc_valid()) {
211 case -1:
212 ok = "unchecked";
213 break;
214 case 0:
215 ok = "bad";
216 break;
217 case 1:
218 ok = "correct";
219 break;
220 default:
221 ok = "unknown state";
222 break;
223 }
0522f1cc
DC
224
225 for (i = 0, bitpos = bit;
226 i < count && !seenint();
227 i++, bitpos += size) {
228 if (array)
229 dbprintf("%d:", i + base);
230 val = getbitval(obj, bitpos, size, BVUNSIGNED);
231 if (size > 32)
232 dbprintf(fmtstr, val, ok);
233 else
14f8b681 234 dbprintf(fmtstr, (int32_t)val, ok);
0522f1cc
DC
235 if (i < count - 1)
236 dbprintf(" ");
237 }
238 return 1;
239}