]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/fprint.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[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 <xfs/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 "inobt.h"
28 #include "bit.h"
29 #include "print.h"
30 #include "output.h"
31 #include "sig.h"
32 #include "malloc.h"
33
34 int
35 fp_charns(
36 void *obj,
37 int bit,
38 int count,
39 char *fmtstr,
40 int size,
41 int arg,
42 int base,
43 int array)
44 {
45 int i;
46 char *p;
47
48 ASSERT(bitoffs(bit) == 0);
49 ASSERT(size == bitsz(char));
50 dbprintf("\"");
51 for (i = 0, p = (char *)obj + byteize(bit);
52 i < count && !seenint();
53 i++, p++) {
54 if (*p == '\\' || *p == '\'' || *p == '"' || *p == '\?')
55 dbprintf("\\%c", *p);
56 else if (isgraph((int)*p) || *p == ' ')
57 dbprintf("%c", *p);
58 else if (*p == '\a' || *p == '\b' || *p == '\f' || *p == '\n' ||
59 *p == '\r' || *p == '\t' || *p == '\v')
60 dbprintf("\\%c", *p + ('a' - '\a'));
61 else
62 dbprintf("\\%03o", *p & 0xff);
63 }
64 dbprintf("\"");
65 return 1;
66 }
67
68 int
69 fp_num(
70 void *obj,
71 int bit,
72 int count,
73 char *fmtstr,
74 int size,
75 int arg,
76 int base,
77 int array)
78 {
79 int bitpos;
80 int i;
81 int isnull;
82 __int64_t val;
83
84 for (i = 0, bitpos = bit;
85 i < count && !seenint();
86 i++, bitpos += size) {
87 val = getbitval(obj, bitpos, size,
88 (arg & FTARG_SIGNED) ? BVSIGNED : BVUNSIGNED);
89 if ((arg & FTARG_SKIPZERO) && val == 0)
90 continue;
91 isnull = (arg & FTARG_SIGNED) || size == 64 ?
92 val == -1LL : val == ((1LL << size) - 1LL);
93 if ((arg & FTARG_SKIPNULL) && isnull)
94 continue;
95 if (array)
96 dbprintf("%d:", i + base);
97 if ((arg & FTARG_DONULL) && isnull)
98 dbprintf("null");
99 else if (size > 32)
100 dbprintf(fmtstr, val);
101 else
102 dbprintf(fmtstr, (__int32_t)val);
103 if (i < count - 1)
104 dbprintf(" ");
105 }
106 return 1;
107 }
108
109 /*ARGSUSED*/
110 int
111 fp_sarray(
112 void *obj,
113 int bit,
114 int count,
115 char *fmtstr,
116 int size,
117 int arg,
118 int base,
119 int array)
120 {
121 print_sarray(obj, bit, count, size, base, array,
122 (const field_t *)fmtstr, (arg & FTARG_SKIPNMS) != 0);
123 return 1;
124 }
125
126 /*ARGSUSED*/
127 int
128 fp_time(
129 void *obj,
130 int bit,
131 int count,
132 char *fmtstr,
133 int size,
134 int arg,
135 int base,
136 int array)
137 {
138 int bitpos;
139 char *c;
140 int i;
141 time_t t;
142
143 ASSERT(bitoffs(bit) == 0);
144 for (i = 0, bitpos = bit;
145 i < count && !seenint();
146 i++, bitpos += size) {
147 if (array)
148 dbprintf("%d:", i + base);
149 t=(time_t)getbitval((char *)obj + byteize(bitpos), 0, sizeof(int32_t)*8, 0);
150 c = ctime(&t);
151 dbprintf("%24.24s", c);
152 if (i < count - 1)
153 dbprintf(" ");
154 }
155 return 1;
156 }
157
158 /*ARGSUSED*/
159 int
160 fp_uuid(
161 void *obj,
162 int bit,
163 int count,
164 char *fmtstr,
165 int size,
166 int arg,
167 int base,
168 int array)
169 {
170 char bp[40]; /* UUID string is 36 chars + trailing '\0' */
171 int i;
172 uuid_t *p;
173
174 ASSERT(bitoffs(bit) == 0);
175 for (p = (uuid_t *)((char *)obj + byteize(bit)), i = 0;
176 i < count && !seenint();
177 i++, p++) {
178 if (array)
179 dbprintf("%d:", i + base);
180 uuid_unparse(*p, bp);
181 dbprintf("%s", bp);
182 if (i < count - 1)
183 dbprintf(" ");
184 }
185 return 1;
186 }