]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/fprint.c
libxfs: fix xfs_trans_alloc_empty namespace
[thirdparty/xfsprogs-dev.git] / db / fprint.c
1 /*
2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
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.
13 *
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
17 */
18
19 #include "libxfs.h"
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"
27 #include "btblock.h"
28 #include "bit.h"
29 #include "print.h"
30 #include "output.h"
31 #include "sig.h"
32 #include "malloc.h"
33 #include "io.h"
34
35 int
36 fp_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);
57 else if (isgraph((int)*p) || *p == ' ')
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
69 int
70 fp_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;
83 __int64_t val;
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;
96 if (array && count > 1)
97 dbprintf("%d:", i + base);
98 if ((arg & FTARG_DONULL) && isnull)
99 dbprintf(_("null"));
100 else if (size > 32)
101 dbprintf(fmtstr, val);
102 else
103 dbprintf(fmtstr, (__int32_t)val);
104 if (i < count - 1)
105 dbprintf(" ");
106 }
107 return 1;
108 }
109
110 /*ARGSUSED*/
111 int
112 fp_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*/
128 int
129 fp_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;
142 time_t t;
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);
150 t=(time_t)getbitval((char *)obj + byteize(bitpos), 0, sizeof(int32_t)*8, 0);
151 c = ctime(&t);
152 dbprintf("%24.24s", c);
153 if (i < count - 1)
154 dbprintf(" ");
155 }
156 return 1;
157 }
158
159 /*ARGSUSED*/
160 int
161 fp_uuid(
162 void *obj,
163 int bit,
164 int count,
165 char *fmtstr,
166 int size,
167 int arg,
168 int base,
169 int array)
170 {
171 char bp[40]; /* UUID string is 36 chars + trailing '\0' */
172 int i;
173 uuid_t *p;
174
175 ASSERT(bitoffs(bit) == 0);
176 for (p = (uuid_t *)((char *)obj + byteize(bit)), i = 0;
177 i < count && !seenint();
178 i++, p++) {
179 if (array)
180 dbprintf("%d:", i + base);
181 platform_uuid_unparse(p, bp);
182 dbprintf("%s", bp);
183 if (i < count - 1)
184 dbprintf(" ");
185 }
186 return 1;
187 }
188
189 /*
190 * CRC is correct is the current buffer it is being pulled out
191 * of is not marked with a EFSCORRUPTED error.
192 */
193 int
194 fp_crc(
195 void *obj,
196 int bit,
197 int count,
198 char *fmtstr,
199 int size,
200 int arg,
201 int base,
202 int array)
203 {
204 int bitpos;
205 int i;
206 __int64_t val;
207 char *ok;
208
209 switch (iocur_crc_valid()) {
210 case -1:
211 ok = "unchecked";
212 break;
213 case 0:
214 ok = "bad";
215 break;
216 case 1:
217 ok = "correct";
218 break;
219 default:
220 ok = "unknown state";
221 break;
222 }
223
224 for (i = 0, bitpos = bit;
225 i < count && !seenint();
226 i++, bitpos += size) {
227 if (array)
228 dbprintf("%d:", i + base);
229 val = getbitval(obj, bitpos, size, BVUNSIGNED);
230 if (size > 32)
231 dbprintf(fmtstr, val, ok);
232 else
233 dbprintf(fmtstr, (__int32_t)val, ok);
234 if (i < count - 1)
235 dbprintf(" ");
236 }
237 return 1;
238 }