]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/flist.c
2e5cced08eca47f5757aee4d0f4bea40a5099034
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #include <xfs/libxfs.h>
43 static void flist_expand_arrays(flist_t
*fl
);
44 static void flist_expand_structs(flist_t
*fl
, void *obj
);
45 static flist_t
*flist_replicate(flist_t
*fl
);
46 static ftok_t
*flist_split(char *s
);
47 static void ftok_free(ftok_t
*ft
);
66 fa
= &ftattrtab
[f
->ftyp
];
68 ASSERT(fa
->ftyp
== f
->ftyp
);
69 ASSERT(f
->flags
& FLD_ARRAY
);
74 for (idx
= low
+ 1, prev
= fl
; idx
<= high
; idx
++) {
75 new = flist_make(f
->name
);
77 new->low
= new->high
= idx
;
78 new->flags
|= FL_OKLOW
| FL_OKHIGH
;
79 new->child
= flist_replicate(fl
->child
);
98 fa
= &ftattrtab
[f
->ftyp
];
99 ASSERT(fa
->ftyp
== f
->ftyp
);
100 ASSERT(fa
->subfld
!= NULL
);
101 ASSERT(fl
->child
== NULL
);
102 for (cf
= fa
->subfld
, prev
= NULL
; cf
->name
!= NULL
; cf
++) {
103 if (fcount(cf
, obj
, fl
->offset
) == 0)
105 if (cf
->flags
& FLD_SKIPALL
)
107 new = flist_make(cf
->name
);
122 flist_free(fl
->child
);
124 flist_free(fl
->sibling
);
136 fl
= xmalloc(sizeof(*fl
));
137 fl
->name
= xstrdup(name
);
150 const field_t
*fields
,
161 f
= findfield(fl
->name
, fields
, obj
, startoff
);
163 dbprintf("field %s not found\n", fl
->name
);
167 fa
= &ftattrtab
[f
->ftyp
];
168 ASSERT(fa
->ftyp
== f
->ftyp
);
169 if (f
->flags
& FLD_ARRAY
) {
170 low
= (f
->flags
& FLD_ABASE1
) != 0;
171 high
= fcount(f
, obj
, startoff
) + low
- 1;
173 dbprintf("no elements in %s\n", fl
->name
);
176 if (fl
->flags
& FL_OKHIGH
) {
177 if (fl
->low
< low
|| fl
->low
> high
||
178 fl
->high
< low
|| fl
->high
> high
) {
179 dbprintf("indices %d-%d for field %s "
180 "out of range %d-%d\n",
181 fl
->low
, fl
->high
, fl
->name
,
185 } else if (fl
->flags
& FL_OKLOW
) {
186 if (fl
->low
< low
|| fl
->low
> high
) {
187 dbprintf("index %d for field %s out of "
189 fl
->low
, fl
->name
, low
, high
);
193 fl
->flags
|= FL_OKHIGH
;
197 fl
->flags
|= FL_OKLOW
| FL_OKHIGH
;
200 if (fl
->flags
& FL_OKLOW
) {
201 dbprintf("field %s is not an array\n",
206 fl
->offset
= startoff
+ bitoffset(f
, obj
, startoff
, fl
->low
);
207 if ((fl
->child
!= NULL
|| fa
->prfunc
== NULL
) &&
208 (f
->flags
& FLD_ARRAY
) && fl
->low
!= fl
->high
)
209 flist_expand_arrays(fl
);
210 if (fa
->prfunc
== NULL
&& fl
->child
== NULL
)
211 flist_expand_structs(fl
, obj
);
213 if (fa
->subfld
== NULL
) {
214 dbprintf("field %s has no subfields\n",
218 if (!flist_parse(fa
->subfld
, fl
->child
, obj
,
231 if (!(debug_state
& DEBUG_FLIST
))
234 dbprintf("fl@%p:\n", fl
);
235 dbprintf("\tname=%s, fld=%p, child=%p, sibling=%p\n",
236 fl
->name
, fl
->fld
, fl
->child
, fl
->sibling
);
237 dbprintf("\tlow=%d, high=%d, flags=%d (%s%s), offset=%d\n",
238 fl
->low
, fl
->high
, fl
->flags
,
239 fl
->flags
& FL_OKLOW
? "oklow " : "",
240 fl
->flags
& FL_OKHIGH
? "okhigh" : "", fl
->offset
);
241 dbprintf("\tfld->name=%s, fld->ftyp=%d (%s)\n",
242 fl
->fld
->name
, fl
->fld
->ftyp
,
243 ftattrtab
[fl
->fld
->ftyp
].name
);
244 dbprintf("\tfld->flags=%d (%s%s%s%s%s)\n", fl
->fld
->flags
,
245 fl
->fld
->flags
& FLD_ABASE1
? "abase1 " : "",
246 fl
->fld
->flags
& FLD_SKIPALL
? "skipall " : "",
247 fl
->fld
->flags
& FLD_ARRAY
? "array " : "",
248 fl
->fld
->flags
& FLD_OFFSET
? "offset " : "",
249 fl
->fld
->flags
& FLD_COUNT
? "count " : "");
251 flist_print(fl
->child
);
264 new = flist_make(f
->name
);
266 new->child
= flist_replicate(f
->child
);
267 new->sibling
= flist_replicate(f
->sibling
);
270 new->flags
= f
->flags
;
271 new->offset
= f
->offset
;
287 v
= flist_split(name
);
292 while (p
->tokty
!= TT_END
) {
293 if (p
->tokty
!= TT_NAME
)
295 nfl
= flist_make(p
->tok
);
302 if (p
->tokty
== TT_LB
) {
304 if (p
->tokty
!= TT_NUM
)
306 num
= (int)strtoul(p
->tok
, &x
, 0);
309 nfl
->flags
|= FL_OKLOW
;
312 if (p
->tokty
== TT_DASH
) {
314 if (p
->tokty
!= TT_NUM
)
316 num
= (int)strtoul(p
->tok
, &x
, 0);
319 nfl
->flags
|= FL_OKHIGH
;
323 if (p
->tokty
!= TT_RB
)
327 if (p
->tokty
== TT_DOT
) {
329 if (p
->tokty
== TT_END
)
336 dbprintf("bad syntax in field name %s\n", name
);
349 static char *idchars
;
350 static char *initidchar
;
353 static char *numchars
;
354 static char *xnumchars
; /* extended for hex conversion */
356 static char punctchars
[] = "[-].";
357 static tokty_t puncttypes
[] = { TT_LB
, TT_DASH
, TT_RB
, TT_DOT
};
361 if (idchars
== NULL
) {
362 idchars
= xmalloc(26 + 10 + 1 + 1);
363 initidchar
= xmalloc(26 + 1);
364 numchars
= xmalloc(10 + 1);
365 xnumchars
= xmalloc(12 + 1);
366 for (i
= 'a'; i
<= 'z'; i
++) {
367 idchars
[i
- 'a'] = i
;
368 initidchar
[i
- 'a'] = i
;
371 for (i
= '0'; i
<= '9'; i
++) {
372 idchars
[26 + (i
- '0')] = i
;
373 numchars
[i
- '0'] = i
;
374 xnumchars
[i
- '0'] = i
;
376 idchars
[26 + 10] = '_';
377 idchars
[26 + 10 + 1] = '\0';
378 initidchar
[26] = '\0';
382 xnumchars
[12] = '\0';
385 v
= xmalloc(sizeof(*v
));
388 /* need to add string handling */
390 s
++; /* skip first quote */
391 if ((a
= strrchr(s
, '\"')) == NULL
) {
392 dbprintf("missing closing quote %s\n", s
);
396 tailskip
= 1; /* skip remaing quote */
399 } else if (strchr(initidchar
, *s
)) {
400 l
= (int)strspn(s
, idchars
);
402 } else if (strchr(numchars
, *s
)) {
403 l
= (int)strspn(s
, xnumchars
);
405 } else if ((a
= strchr(punctchars
, *s
))) {
407 t
= puncttypes
[a
- punctchars
];
409 dbprintf("bad character in field %s\n", s
);
416 v
= xrealloc(v
, (nv
+ 2) * sizeof(*v
));
424 v
[nv
].tokty
= TT_END
;
434 for (p
= ft
; p
->tok
; p
++)