2 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
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.
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.
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
18 #ifndef __XFS_DIR2_DATA_H__
19 #define __XFS_DIR2_DATA_H__
22 * Directory format 2, data block structures.
33 #define XFS_DIR2_DATA_MAGIC 0x58443244 /* XD2D: for multiblock dirs */
34 #define XFS_DIR2_DATA_ALIGN_LOG 3 /* i.e., 8 bytes */
35 #define XFS_DIR2_DATA_ALIGN (1 << XFS_DIR2_DATA_ALIGN_LOG)
36 #define XFS_DIR2_DATA_FREE_TAG 0xffff
37 #define XFS_DIR2_DATA_FD_COUNT 3
40 * Directory address space divided into sections,
41 * spaces separated by 32gb.
43 #define XFS_DIR2_SPACE_SIZE (1ULL << (32 + XFS_DIR2_DATA_ALIGN_LOG))
44 #define XFS_DIR2_DATA_SPACE 0
45 #define XFS_DIR2_DATA_OFFSET (XFS_DIR2_DATA_SPACE * XFS_DIR2_SPACE_SIZE)
46 #define XFS_DIR2_DATA_FIRSTDB(mp) \
47 XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATA_OFFSET)
50 * Offsets of . and .. in data space (always block 0)
52 #define XFS_DIR2_DATA_DOT_OFFSET \
53 ((xfs_dir2_data_aoff_t)sizeof(xfs_dir2_data_hdr_t))
54 #define XFS_DIR2_DATA_DOTDOT_OFFSET \
55 (XFS_DIR2_DATA_DOT_OFFSET + XFS_DIR2_DATA_ENTSIZE(1))
56 #define XFS_DIR2_DATA_FIRST_OFFSET \
57 (XFS_DIR2_DATA_DOTDOT_OFFSET + XFS_DIR2_DATA_ENTSIZE(2))
64 * Describe a free area in the data block.
65 * The freespace will be formatted as a xfs_dir2_data_unused_t.
67 typedef struct xfs_dir2_data_free {
68 xfs_dir2_data_off_t offset; /* start of freespace */
69 xfs_dir2_data_off_t length; /* length of freespace */
70 } xfs_dir2_data_free_t;
73 * Header for the data blocks.
74 * Always at the beginning of a directory-sized block.
75 * The code knows that XFS_DIR2_DATA_FD_COUNT is 3.
77 typedef struct xfs_dir2_data_hdr {
78 __uint32_t magic; /* XFS_DIR2_DATA_MAGIC */
79 /* or XFS_DIR2_BLOCK_MAGIC */
80 xfs_dir2_data_free_t bestfree[XFS_DIR2_DATA_FD_COUNT];
81 } xfs_dir2_data_hdr_t;
84 * Active entry in a data block. Aligned to 8 bytes.
85 * Tag appears as the last 2 bytes.
87 typedef struct xfs_dir2_data_entry {
88 xfs_ino_t inumber; /* inode number */
89 __uint8_t namelen; /* name length */
90 __uint8_t name[1]; /* name bytes, no null */
92 xfs_dir2_data_off_t tag; /* starting offset of us */
93 } xfs_dir2_data_entry_t;
96 * Unused entry in a data block. Aligned to 8 bytes.
97 * Tag appears as the last 2 bytes.
99 typedef struct xfs_dir2_data_unused {
100 __uint16_t freetag; /* XFS_DIR2_DATA_FREE_TAG */
101 xfs_dir2_data_off_t length; /* total free length */
102 /* variable offset */
103 xfs_dir2_data_off_t tag; /* starting offset of us */
104 } xfs_dir2_data_unused_t;
107 xfs_dir2_data_entry_t entry;
108 xfs_dir2_data_unused_t unused;
109 } xfs_dir2_data_union_t;
112 * Generic data block structure, for xfs_db.
114 typedef struct xfs_dir2_data {
115 xfs_dir2_data_hdr_t hdr; /* magic XFS_DIR2_DATA_MAGIC */
116 xfs_dir2_data_union_t u[1];
124 * Size of a data entry.
126 #define XFS_DIR2_DATA_ENTSIZE(n) xfs_dir2_data_entsize(n)
127 static inline int xfs_dir2_data_entsize(int n)
129 return (int)roundup(offsetof(xfs_dir2_data_entry_t, name[0]) + (n) + \
130 (uint)sizeof(xfs_dir2_data_off_t), XFS_DIR2_DATA_ALIGN);
134 * Pointer to an entry's tag word.
136 #define XFS_DIR2_DATA_ENTRY_TAG_P(dep) xfs_dir2_data_entry_tag_p(dep)
137 static inline xfs_dir2_data_off_t *
138 xfs_dir2_data_entry_tag_p(xfs_dir2_data_entry_t *dep)
140 return (xfs_dir2_data_off_t *) \
141 ((char *)(dep) + XFS_DIR2_DATA_ENTSIZE((dep)->namelen) - \
142 (uint)sizeof(xfs_dir2_data_off_t));
146 * Pointer to a freespace's tag word.
148 #define XFS_DIR2_DATA_UNUSED_TAG_P(dup) \
149 xfs_dir2_data_unused_tag_p(dup)
150 static inline xfs_dir2_data_off_t *
151 xfs_dir2_data_unused_tag_p(xfs_dir2_data_unused_t *dup)
153 return (xfs_dir2_data_off_t *) \
154 ((char *)(dup) + INT_GET((dup)->length, ARCH_CONVERT) \
155 - (uint)sizeof(xfs_dir2_data_off_t));
159 * Function declarations.
162 extern void xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp);
164 #define xfs_dir2_data_check(dp,bp)
166 extern xfs_dir2_data_free_t *xfs_dir2_data_freefind(xfs_dir2_data_t *d,
167 xfs_dir2_data_unused_t *dup);
168 extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_t *d,
169 xfs_dir2_data_unused_t *dup, int *loghead);
170 extern void xfs_dir2_data_freescan(struct xfs_mount *mp, xfs_dir2_data_t *d,
171 int *loghead, char *aendp);
172 extern int xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
173 struct xfs_dabuf **bpp);
174 extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp,
175 xfs_dir2_data_entry_t *dep);
176 extern void xfs_dir2_data_log_header(struct xfs_trans *tp,
177 struct xfs_dabuf *bp);
178 extern void xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_dabuf *bp,
179 xfs_dir2_data_unused_t *dup);
180 extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
181 xfs_dir2_data_aoff_t offset,
182 xfs_dir2_data_aoff_t len, int *needlogp,
184 extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
185 xfs_dir2_data_unused_t *dup,
186 xfs_dir2_data_aoff_t offset,
187 xfs_dir2_data_aoff_t len, int *needlogp,
190 #endif /* __XFS_DIR2_DATA_H__ */