Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | #ifndef __XFS_DIR2_DATA_H__ |
| 19 | #define __XFS_DIR2_DATA_H__ |
| 20 | |
| 21 | /* |
| 22 | * Directory format 2, data block structures. |
| 23 | */ |
| 24 | |
| 25 | struct xfs_dabuf; |
| 26 | struct xfs_da_args; |
| 27 | struct xfs_inode; |
| 28 | struct xfs_trans; |
| 29 | |
| 30 | /* |
| 31 | * Constants. |
| 32 | */ |
| 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 |
| 38 | |
| 39 | /* |
| 40 | * Directory address space divided into sections, |
| 41 | * spaces separated by 32gb. |
| 42 | */ |
| 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) \ |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame^] | 47 | xfs_dir2_byte_to_db(mp, XFS_DIR2_DATA_OFFSET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Offsets of . and .. in data space (always block 0) |
| 51 | */ |
| 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 \ |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame^] | 55 | (XFS_DIR2_DATA_DOT_OFFSET + xfs_dir2_data_entsize(1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define XFS_DIR2_DATA_FIRST_OFFSET \ |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame^] | 57 | (XFS_DIR2_DATA_DOTDOT_OFFSET + xfs_dir2_data_entsize(2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Structures. |
| 61 | */ |
| 62 | |
| 63 | /* |
| 64 | * Describe a free area in the data block. |
| 65 | * The freespace will be formatted as a xfs_dir2_data_unused_t. |
| 66 | */ |
| 67 | typedef struct xfs_dir2_data_free { |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 68 | __be16 offset; /* start of freespace */ |
| 69 | __be16 length; /* length of freespace */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } xfs_dir2_data_free_t; |
| 71 | |
| 72 | /* |
| 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. |
| 76 | */ |
| 77 | typedef struct xfs_dir2_data_hdr { |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 78 | __be32 magic; /* XFS_DIR2_DATA_MAGIC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* or XFS_DIR2_BLOCK_MAGIC */ |
| 80 | xfs_dir2_data_free_t bestfree[XFS_DIR2_DATA_FD_COUNT]; |
| 81 | } xfs_dir2_data_hdr_t; |
| 82 | |
| 83 | /* |
| 84 | * Active entry in a data block. Aligned to 8 bytes. |
| 85 | * Tag appears as the last 2 bytes. |
| 86 | */ |
| 87 | typedef struct xfs_dir2_data_entry { |
Christoph Hellwig | ff9901c | 2006-06-09 14:48:37 +1000 | [diff] [blame] | 88 | __be64 inumber; /* inode number */ |
| 89 | __u8 namelen; /* name length */ |
| 90 | __u8 name[1]; /* name bytes, no null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* variable offset */ |
Christoph Hellwig | ff9901c | 2006-06-09 14:48:37 +1000 | [diff] [blame] | 92 | __be16 tag; /* starting offset of us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } xfs_dir2_data_entry_t; |
| 94 | |
| 95 | /* |
| 96 | * Unused entry in a data block. Aligned to 8 bytes. |
| 97 | * Tag appears as the last 2 bytes. |
| 98 | */ |
| 99 | typedef struct xfs_dir2_data_unused { |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 100 | __be16 freetag; /* XFS_DIR2_DATA_FREE_TAG */ |
| 101 | __be16 length; /* total free length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | /* variable offset */ |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 103 | __be16 tag; /* starting offset of us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } xfs_dir2_data_unused_t; |
| 105 | |
| 106 | typedef union { |
| 107 | xfs_dir2_data_entry_t entry; |
| 108 | xfs_dir2_data_unused_t unused; |
| 109 | } xfs_dir2_data_union_t; |
| 110 | |
| 111 | /* |
| 112 | * Generic data block structure, for xfs_db. |
| 113 | */ |
| 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]; |
| 117 | } xfs_dir2_data_t; |
| 118 | |
| 119 | /* |
| 120 | * Macros. |
| 121 | */ |
| 122 | |
| 123 | /* |
| 124 | * Size of a data entry. |
| 125 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 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 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Pointer to an entry's tag word. |
| 134 | */ |
Nathan Scott | 3d693c6 | 2006-03-17 17:28:27 +1100 | [diff] [blame] | 135 | static inline __be16 * |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 136 | xfs_dir2_data_entry_tag_p(xfs_dir2_data_entry_t *dep) |
| 137 | { |
Nathan Scott | 3d693c6 | 2006-03-17 17:28:27 +1100 | [diff] [blame] | 138 | return (__be16 *)((char *)dep + |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame^] | 139 | xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16)); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * Pointer to a freespace's tag word. |
| 144 | */ |
Nathan Scott | 1fba9f7 | 2006-03-17 17:27:47 +1100 | [diff] [blame] | 145 | static inline __be16 * |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 146 | xfs_dir2_data_unused_tag_p(xfs_dir2_data_unused_t *dup) |
| 147 | { |
Nathan Scott | 1fba9f7 | 2006-03-17 17:27:47 +1100 | [diff] [blame] | 148 | return (__be16 *)((char *)dup + |
| 149 | be16_to_cpu(dup->length) - sizeof(__be16)); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * Function declarations. |
| 154 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | #ifdef DEBUG |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 156 | extern void xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #else |
| 158 | #define xfs_dir2_data_check(dp,bp) |
| 159 | #endif |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 160 | extern xfs_dir2_data_free_t *xfs_dir2_data_freefind(xfs_dir2_data_t *d, |
| 161 | xfs_dir2_data_unused_t *dup); |
| 162 | extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_t *d, |
| 163 | xfs_dir2_data_unused_t *dup, int *loghead); |
| 164 | extern void xfs_dir2_data_freescan(struct xfs_mount *mp, xfs_dir2_data_t *d, |
Eric Sandeen | ef497f8 | 2007-05-08 13:48:49 +1000 | [diff] [blame] | 165 | int *loghead); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 166 | extern int xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno, |
| 167 | struct xfs_dabuf **bpp); |
| 168 | extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | xfs_dir2_data_entry_t *dep); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 170 | extern void xfs_dir2_data_log_header(struct xfs_trans *tp, |
| 171 | struct xfs_dabuf *bp); |
| 172 | extern void xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_dabuf *bp, |
| 173 | xfs_dir2_data_unused_t *dup); |
| 174 | extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_dabuf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | xfs_dir2_data_aoff_t offset, |
| 176 | xfs_dir2_data_aoff_t len, int *needlogp, |
| 177 | int *needscanp); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 178 | extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_dabuf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | xfs_dir2_data_unused_t *dup, |
| 180 | xfs_dir2_data_aoff_t offset, |
| 181 | xfs_dir2_data_aoff_t len, int *needlogp, |
| 182 | int *needscanp); |
| 183 | |
| 184 | #endif /* __XFS_DIR2_DATA_H__ */ |