]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/dirshort.c
cmd/xfs/bmap/Makefile 1.8 Renamed to cmd/xfsprogs/bmap/Makefile
[thirdparty/xfsprogs-dev.git] / db / dirshort.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 "type.h"
35 #include "faddr.h"
36 #include "fprint.h"
37 #include "field.h"
38 #include "bit.h"
39 #include "dirshort.h"
40
41 static int dir_sf_entry_name_count(void *obj, int startoff);
42 static int dir_shortform_list_count(void *obj, int startoff);
43 static int dir_shortform_list_offset(void *obj, int startoff, int idx);
44
45 #define OFF(f) bitize(offsetof(xfs_dir_shortform_t, f))
46 const field_t dir_shortform_flds[] = {
47 { "hdr", FLDT_DIR_SF_HDR, OI(OFF(hdr)), C1, 0, TYP_NONE },
48 { "list", FLDT_DIR_SF_ENTRY, dir_shortform_list_offset,
49 dir_shortform_list_count, FLD_ARRAY|FLD_COUNT|FLD_OFFSET, TYP_NONE },
50 { NULL }
51 };
52
53 #define HOFF(f) bitize(offsetof(xfs_dir_sf_hdr_t, f))
54 const field_t dir_sf_hdr_flds[] = {
55 { "parent", FLDT_DIR_INO, OI(HOFF(parent)), C1, 0, TYP_INODE },
56 { "count", FLDT_UINT8D, OI(HOFF(count)), C1, 0, TYP_NONE },
57 { NULL }
58 };
59
60 #define EOFF(f) bitize(offsetof(xfs_dir_sf_entry_t, f))
61 const field_t dir_sf_entry_flds[] = {
62 { "inumber", FLDT_DIR_INO, OI(EOFF(inumber)), C1, 0, TYP_INODE },
63 { "namelen", FLDT_UINT8D, OI(EOFF(namelen)), C1, 0, TYP_NONE },
64 { "name", FLDT_CHARNS, OI(EOFF(name)), dir_sf_entry_name_count,
65 FLD_COUNT, TYP_NONE },
66 { NULL }
67 };
68
69 static int
70 dir_sf_entry_name_count(
71 void *obj,
72 int startoff)
73 {
74 xfs_dir_sf_entry_t *e;
75
76 ASSERT(bitoffs(startoff) == 0);
77 e = (xfs_dir_sf_entry_t *)((char *)obj + byteize(startoff));
78 return e->namelen;
79 }
80
81 int
82 dir_sf_entry_size(
83 void *obj,
84 int startoff,
85 int idx)
86 {
87 xfs_dir_sf_entry_t *e;
88 int i;
89 xfs_dir_shortform_t *sf;
90
91 ASSERT(bitoffs(startoff) == 0);
92 sf = (xfs_dir_shortform_t *)((char *)obj + byteize(startoff));
93 e = &sf->list[0];
94 for (i = 0; i < idx; i++)
95 e = XFS_DIR_SF_NEXTENTRY(e);
96 return bitize((int)XFS_DIR_SF_ENTSIZE_BYENTRY(e));
97 }
98
99 static int
100 dir_shortform_list_count(
101 void *obj,
102 int startoff)
103 {
104 xfs_dir_shortform_t *sf;
105
106 ASSERT(bitoffs(startoff) == 0);
107 sf = (xfs_dir_shortform_t *)((char *)obj + byteize(startoff));
108 return sf->hdr.count;
109 }
110
111 static int
112 dir_shortform_list_offset(
113 void *obj,
114 int startoff,
115 int idx)
116 {
117 xfs_dir_sf_entry_t *e;
118 int i;
119 xfs_dir_shortform_t *sf;
120
121 ASSERT(bitoffs(startoff) == 0);
122 sf = (xfs_dir_shortform_t *)((char *)obj + byteize(startoff));
123 e = &sf->list[0];
124 for (i = 0; i < idx; i++)
125 e = XFS_DIR_SF_NEXTENTRY(e);
126 return bitize((int)((char *)e - (char *)sf));
127 }
128
129 int
130 dirshort_size(
131 void *obj,
132 int startoff,
133 int idx)
134 {
135 xfs_dir_sf_entry_t *e;
136 int i;
137 xfs_dir_shortform_t *sf;
138
139 ASSERT(bitoffs(startoff) == 0);
140 ASSERT(idx == 0);
141 sf = (xfs_dir_shortform_t *)((char *)obj + byteize(startoff));
142 e = &sf->list[0];
143 for (i = 0; i < sf->hdr.count; i++)
144 e = XFS_DIR_SF_NEXTENTRY(e);
145 return bitize((int)((char *)e - (char *)sf));
146 }