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