]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
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 | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
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. | |
1da177e4 | 13 | * |
7b718769 NS |
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 | |
1da177e4 LT |
17 | */ |
18 | #ifndef __XFS_DIR2_DATA_H__ | |
19 | #define __XFS_DIR2_DATA_H__ | |
20 | ||
21 | /* | |
22 | * Directory format 2, data block structures. | |
0ba9cd84 CH |
23 | * |
24 | * A pure data block looks like the following drawing on disk: | |
25 | * | |
26 | * +-------------------------------------------------+ | |
27 | * | xfs_dir2_data_hdr_t | | |
28 | * +-------------------------------------------------+ | |
29 | * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t | | |
30 | * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t | | |
31 | * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t | | |
32 | * | ... | | |
33 | * +-------------------------------------------------+ | |
34 | * | unused space | | |
35 | * +-------------------------------------------------+ | |
36 | * | |
37 | * As all the entries are variable size structures the accessors in this | |
38 | * file should be used to iterate over them. | |
1da177e4 LT |
39 | */ |
40 | ||
41 | struct xfs_dabuf; | |
42 | struct xfs_da_args; | |
43 | struct xfs_inode; | |
44 | struct xfs_trans; | |
45 | ||
46 | /* | |
47 | * Constants. | |
48 | */ | |
49 | #define XFS_DIR2_DATA_MAGIC 0x58443244 /* XD2D: for multiblock dirs */ | |
50 | #define XFS_DIR2_DATA_ALIGN_LOG 3 /* i.e., 8 bytes */ | |
51 | #define XFS_DIR2_DATA_ALIGN (1 << XFS_DIR2_DATA_ALIGN_LOG) | |
52 | #define XFS_DIR2_DATA_FREE_TAG 0xffff | |
53 | #define XFS_DIR2_DATA_FD_COUNT 3 | |
54 | ||
55 | /* | |
56 | * Directory address space divided into sections, | |
9da096fd | 57 | * spaces separated by 32GB. |
1da177e4 LT |
58 | */ |
59 | #define XFS_DIR2_SPACE_SIZE (1ULL << (32 + XFS_DIR2_DATA_ALIGN_LOG)) | |
60 | #define XFS_DIR2_DATA_SPACE 0 | |
61 | #define XFS_DIR2_DATA_OFFSET (XFS_DIR2_DATA_SPACE * XFS_DIR2_SPACE_SIZE) | |
62 | #define XFS_DIR2_DATA_FIRSTDB(mp) \ | |
bbaaf538 | 63 | xfs_dir2_byte_to_db(mp, XFS_DIR2_DATA_OFFSET) |
1da177e4 LT |
64 | |
65 | /* | |
66 | * Offsets of . and .. in data space (always block 0) | |
67 | */ | |
68 | #define XFS_DIR2_DATA_DOT_OFFSET \ | |
69 | ((xfs_dir2_data_aoff_t)sizeof(xfs_dir2_data_hdr_t)) | |
70 | #define XFS_DIR2_DATA_DOTDOT_OFFSET \ | |
bbaaf538 | 71 | (XFS_DIR2_DATA_DOT_OFFSET + xfs_dir2_data_entsize(1)) |
1da177e4 | 72 | #define XFS_DIR2_DATA_FIRST_OFFSET \ |
bbaaf538 | 73 | (XFS_DIR2_DATA_DOTDOT_OFFSET + xfs_dir2_data_entsize(2)) |
1da177e4 LT |
74 | |
75 | /* | |
76 | * Structures. | |
77 | */ | |
78 | ||
79 | /* | |
80 | * Describe a free area in the data block. | |
81 | * The freespace will be formatted as a xfs_dir2_data_unused_t. | |
82 | */ | |
83 | typedef struct xfs_dir2_data_free { | |
70e73f59 NS |
84 | __be16 offset; /* start of freespace */ |
85 | __be16 length; /* length of freespace */ | |
1da177e4 LT |
86 | } xfs_dir2_data_free_t; |
87 | ||
88 | /* | |
89 | * Header for the data blocks. | |
90 | * Always at the beginning of a directory-sized block. | |
91 | * The code knows that XFS_DIR2_DATA_FD_COUNT is 3. | |
92 | */ | |
93 | typedef struct xfs_dir2_data_hdr { | |
70e73f59 | 94 | __be32 magic; /* XFS_DIR2_DATA_MAGIC */ |
1da177e4 LT |
95 | /* or XFS_DIR2_BLOCK_MAGIC */ |
96 | xfs_dir2_data_free_t bestfree[XFS_DIR2_DATA_FD_COUNT]; | |
97 | } xfs_dir2_data_hdr_t; | |
98 | ||
99 | /* | |
100 | * Active entry in a data block. Aligned to 8 bytes. | |
3ed8638f CH |
101 | * |
102 | * After the variable length name field there is a 2 byte tag field, which | |
103 | * can be accessed using xfs_dir2_data_entry_tag_p. | |
1da177e4 LT |
104 | */ |
105 | typedef struct xfs_dir2_data_entry { | |
ff9901c1 CH |
106 | __be64 inumber; /* inode number */ |
107 | __u8 namelen; /* name length */ | |
3ed8638f CH |
108 | __u8 name[]; /* name bytes, no null */ |
109 | /* __be16 tag; */ /* starting offset of us */ | |
1da177e4 LT |
110 | } xfs_dir2_data_entry_t; |
111 | ||
112 | /* | |
113 | * Unused entry in a data block. Aligned to 8 bytes. | |
114 | * Tag appears as the last 2 bytes. | |
115 | */ | |
116 | typedef struct xfs_dir2_data_unused { | |
ad354eb3 NS |
117 | __be16 freetag; /* XFS_DIR2_DATA_FREE_TAG */ |
118 | __be16 length; /* total free length */ | |
1da177e4 | 119 | /* variable offset */ |
ad354eb3 | 120 | __be16 tag; /* starting offset of us */ |
1da177e4 LT |
121 | } xfs_dir2_data_unused_t; |
122 | ||
1da177e4 LT |
123 | /* |
124 | * Size of a data entry. | |
125 | */ | |
a844f451 NS |
126 | static inline int xfs_dir2_data_entsize(int n) |
127 | { | |
128 | return (int)roundup(offsetof(xfs_dir2_data_entry_t, name[0]) + (n) + \ | |
129 | (uint)sizeof(xfs_dir2_data_off_t), XFS_DIR2_DATA_ALIGN); | |
130 | } | |
1da177e4 LT |
131 | |
132 | /* | |
133 | * Pointer to an entry's tag word. | |
134 | */ | |
3d693c6e | 135 | static inline __be16 * |
a844f451 NS |
136 | xfs_dir2_data_entry_tag_p(xfs_dir2_data_entry_t *dep) |
137 | { | |
3d693c6e | 138 | return (__be16 *)((char *)dep + |
bbaaf538 | 139 | xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16)); |
a844f451 | 140 | } |
1da177e4 LT |
141 | |
142 | /* | |
143 | * Pointer to a freespace's tag word. | |
144 | */ | |
1fba9f7f | 145 | static inline __be16 * |
a844f451 NS |
146 | xfs_dir2_data_unused_tag_p(xfs_dir2_data_unused_t *dup) |
147 | { | |
1fba9f7f NS |
148 | return (__be16 *)((char *)dup + |
149 | be16_to_cpu(dup->length) - sizeof(__be16)); | |
a844f451 | 150 | } |
1da177e4 LT |
151 | |
152 | /* | |
153 | * Function declarations. | |
154 | */ | |
1da177e4 | 155 | #ifdef DEBUG |
a844f451 | 156 | extern void xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp); |
1da177e4 LT |
157 | #else |
158 | #define xfs_dir2_data_check(dp,bp) | |
159 | #endif | |
c2066e26 | 160 | extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_hdr_t *hdr, |
a844f451 | 161 | xfs_dir2_data_unused_t *dup, int *loghead); |
c2066e26 CH |
162 | extern void xfs_dir2_data_freescan(struct xfs_mount *mp, |
163 | xfs_dir2_data_hdr_t *hdr, int *loghead); | |
a844f451 NS |
164 | extern int xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno, |
165 | struct xfs_dabuf **bpp); | |
166 | extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp, | |
1da177e4 | 167 | xfs_dir2_data_entry_t *dep); |
a844f451 NS |
168 | extern void xfs_dir2_data_log_header(struct xfs_trans *tp, |
169 | struct xfs_dabuf *bp); | |
170 | extern void xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_dabuf *bp, | |
171 | xfs_dir2_data_unused_t *dup); | |
172 | extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_dabuf *bp, | |
1da177e4 LT |
173 | xfs_dir2_data_aoff_t offset, |
174 | xfs_dir2_data_aoff_t len, int *needlogp, | |
175 | int *needscanp); | |
a844f451 | 176 | extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_dabuf *bp, |
1da177e4 LT |
177 | xfs_dir2_data_unused_t *dup, |
178 | xfs_dir2_data_aoff_t offset, | |
179 | xfs_dir2_data_aoff_t len, int *needlogp, | |
180 | int *needscanp); | |
181 | ||
182 | #endif /* __XFS_DIR2_DATA_H__ */ |