]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/fprint.c
cmd/xfs/bmap/Makefile 1.8 Renamed to cmd/xfsprogs/bmap/Makefile
[thirdparty/xfsprogs-dev.git] / db / fprint.c
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34 #include <getopt.h>
35 #include <ctype.h>
36 #include <time.h>
37 #include "type.h"
38 #include "faddr.h"
39 #include "fprint.h"
40 #include "field.h"
41 #include "inode.h"
42 #include "inobt.h"
43 #include "bit.h"
44 #include "print.h"
45 #include "output.h"
46 #include "sig.h"
47 #include "malloc.h"
48
49 int
50 fp_charns(
51 void *obj,
52 int bit,
53 int count,
54 char *fmtstr,
55 int size,
56 int arg,
57 int base,
58 int array)
59 {
60 int i;
61 char *p;
62
63 ASSERT(bitoffs(bit) == 0);
64 ASSERT(size == bitsz(char));
65 dbprintf("\"");
66 for (i = 0, p = (char *)obj + byteize(bit);
67 i < count && !seenint();
68 i++, p++) {
69 if (*p == '\\' || *p == '\'' || *p == '"' || *p == '\?')
70 dbprintf("\\%c", *p);
71 else if (isgraph(*p) || *p == ' ')
72 dbprintf("%c", *p);
73 else if (*p == '\a' || *p == '\b' || *p == '\f' || *p == '\n' ||
74 *p == '\r' || *p == '\t' || *p == '\v')
75 dbprintf("\\%c", *p + ('a' - '\a'));
76 else
77 dbprintf("\\%03o", *p & 0xff);
78 }
79 dbprintf("\"");
80 return 1;
81 }
82
83 int
84 fp_num(
85 void *obj,
86 int bit,
87 int count,
88 char *fmtstr,
89 int size,
90 int arg,
91 int base,
92 int array)
93 {
94 int bitpos;
95 int i;
96 int isnull;
97 __int64_t val;
98
99 for (i = 0, bitpos = bit;
100 i < count && !seenint();
101 i++, bitpos += size) {
102 val = getbitval(obj, bitpos, size,
103 (arg & FTARG_SIGNED) ? BVSIGNED : BVUNSIGNED);
104 if ((arg & FTARG_SKIPZERO) && val == 0)
105 continue;
106 isnull = (arg & FTARG_SIGNED) || size == 64 ?
107 val == -1LL : val == ((1LL << size) - 1LL);
108 if ((arg & FTARG_SKIPNULL) && isnull)
109 continue;
110 if (array)
111 dbprintf("%d:", i + base);
112 if ((arg & FTARG_DONULL) && isnull)
113 dbprintf("null");
114 else if (size > 32)
115 dbprintf(fmtstr, val);
116 else
117 dbprintf(fmtstr, (__int32_t)val);
118 if (i < count - 1)
119 dbprintf(" ");
120 }
121 return 1;
122 }
123
124 /*ARGSUSED*/
125 int
126 fp_sarray(
127 void *obj,
128 int bit,
129 int count,
130 char *fmtstr,
131 int size,
132 int arg,
133 int base,
134 int array)
135 {
136 print_sarray(obj, bit, count, size, base, array,
137 (const field_t *)fmtstr, (arg & FTARG_SKIPNMS) != 0);
138 return 1;
139 }
140
141 /*ARGSUSED*/
142 int
143 fp_time(
144 void *obj,
145 int bit,
146 int count,
147 char *fmtstr,
148 int size,
149 int arg,
150 int base,
151 int array)
152 {
153 int bitpos;
154 char *c;
155 int i;
156 time_t t;
157
158 ASSERT(bitoffs(bit) == 0);
159 for (i = 0, bitpos = bit;
160 i < count && !seenint();
161 i++, bitpos += size) {
162 if (array)
163 dbprintf("%d:", i + base);
164 t=(time_t)getbitval((char *)obj + byteize(bitpos), 0, sizeof(time_t)*8, 0);
165 c = ctime(&t);
166 dbprintf("%24.24s", c);
167 if (i < count - 1)
168 dbprintf(" ");
169 }
170 return 1;
171 }
172
173 /*ARGSUSED*/
174 int
175 fp_uuid(
176 void *obj,
177 int bit,
178 int count,
179 char *fmtstr,
180 int size,
181 int arg,
182 int base,
183 int array)
184 {
185 char bp[40]; /* UUID string is 36 chars + trailing '\0' */
186 int i;
187 uuid_t *p;
188
189 ASSERT(bitoffs(bit) == 0);
190 for (p = (uuid_t *)((char *)obj + byteize(bit)), i = 0;
191 i < count && !seenint();
192 i++, p++) {
193 if (array)
194 dbprintf("%d:", i + base);
195 uuid_unparse(*p, bp);
196 dbprintf("%s", bp);
197 if (i < count - 1)
198 dbprintf(" ");
199 }
200 return 1;
201 }