xfs_dir2_data.h 5.4 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3
 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
 * All Rights Reserved.
L
Linus Torvalds 已提交
4
 *
5 6
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
L
Linus Torvalds 已提交
7 8
 * published by the Free Software Foundation.
 *
9 10 11 12
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
L
Linus Torvalds 已提交
13
 *
14 15 16
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
L
Linus Torvalds 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 */
#ifndef __XFS_DIR2_DATA_H__
#define	__XFS_DIR2_DATA_H__

/*
 * Directory format 2, data block structures.
 */

struct xfs_dabuf;
struct xfs_da_args;
struct xfs_inode;
struct xfs_trans;

/*
 * Constants.
 */
#define	XFS_DIR2_DATA_MAGIC	0x58443244	/* XD2D: for multiblock dirs */
#define	XFS_DIR2_DATA_ALIGN_LOG	3		/* i.e., 8 bytes */
#define	XFS_DIR2_DATA_ALIGN	(1 << XFS_DIR2_DATA_ALIGN_LOG)
#define	XFS_DIR2_DATA_FREE_TAG	0xffff
#define	XFS_DIR2_DATA_FD_COUNT	3

/*
 * Directory address space divided into sections,
M
Malcolm Parsons 已提交
41
 * spaces separated by 32GB.
L
Linus Torvalds 已提交
42 43 44 45 46
 */
#define	XFS_DIR2_SPACE_SIZE	(1ULL << (32 + XFS_DIR2_DATA_ALIGN_LOG))
#define	XFS_DIR2_DATA_SPACE	0
#define	XFS_DIR2_DATA_OFFSET	(XFS_DIR2_DATA_SPACE * XFS_DIR2_SPACE_SIZE)
#define	XFS_DIR2_DATA_FIRSTDB(mp)	\
47
	xfs_dir2_byte_to_db(mp, XFS_DIR2_DATA_OFFSET)
L
Linus Torvalds 已提交
48 49 50 51 52 53 54

/*
 * Offsets of . and .. in data space (always block 0)
 */
#define	XFS_DIR2_DATA_DOT_OFFSET	\
	((xfs_dir2_data_aoff_t)sizeof(xfs_dir2_data_hdr_t))
#define	XFS_DIR2_DATA_DOTDOT_OFFSET	\
55
	(XFS_DIR2_DATA_DOT_OFFSET + xfs_dir2_data_entsize(1))
L
Linus Torvalds 已提交
56
#define	XFS_DIR2_DATA_FIRST_OFFSET		\
57
	(XFS_DIR2_DATA_DOTDOT_OFFSET + xfs_dir2_data_entsize(2))
L
Linus Torvalds 已提交
58 59 60 61 62 63 64 65 66 67

/*
 * Structures.
 */

/*
 * Describe a free area in the data block.
 * The freespace will be formatted as a xfs_dir2_data_unused_t.
 */
typedef struct xfs_dir2_data_free {
68 69
	__be16			offset;		/* start of freespace */
	__be16			length;		/* length of freespace */
L
Linus Torvalds 已提交
70 71 72 73 74 75 76 77
} xfs_dir2_data_free_t;

/*
 * Header for the data blocks.
 * Always at the beginning of a directory-sized block.
 * The code knows that XFS_DIR2_DATA_FD_COUNT is 3.
 */
typedef struct xfs_dir2_data_hdr {
78
	__be32			magic;		/* XFS_DIR2_DATA_MAGIC */
L
Linus Torvalds 已提交
79 80 81 82 83 84 85 86 87
						/* or XFS_DIR2_BLOCK_MAGIC */
	xfs_dir2_data_free_t	bestfree[XFS_DIR2_DATA_FD_COUNT];
} xfs_dir2_data_hdr_t;

/*
 * Active entry in a data block.  Aligned to 8 bytes.
 * Tag appears as the last 2 bytes.
 */
typedef struct xfs_dir2_data_entry {
88 89 90
	__be64			inumber;	/* inode number */
	__u8			namelen;	/* name length */
	__u8			name[1];	/* name bytes, no null */
L
Linus Torvalds 已提交
91
						/* variable offset */
92
	__be16			tag;		/* starting offset of us */
L
Linus Torvalds 已提交
93 94 95 96 97 98 99
} xfs_dir2_data_entry_t;

/*
 * Unused entry in a data block.  Aligned to 8 bytes.
 * Tag appears as the last 2 bytes.
 */
typedef struct xfs_dir2_data_unused {
100 101
	__be16			freetag;	/* XFS_DIR2_DATA_FREE_TAG */
	__be16			length;		/* total free length */
L
Linus Torvalds 已提交
102
						/* variable offset */
103
	__be16			tag;		/* starting offset of us */
L
Linus Torvalds 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
} xfs_dir2_data_unused_t;

typedef union {
	xfs_dir2_data_entry_t	entry;
	xfs_dir2_data_unused_t	unused;
} xfs_dir2_data_union_t;

/*
 * Generic data block structure, for xfs_db.
 */
typedef struct xfs_dir2_data {
	xfs_dir2_data_hdr_t	hdr;		/* magic XFS_DIR2_DATA_MAGIC */
	xfs_dir2_data_union_t	u[1];
} xfs_dir2_data_t;

/*
 * Macros.
 */

/*
 * Size of a data entry.
 */
126 127 128 129 130
static inline int xfs_dir2_data_entsize(int n)
{
	return (int)roundup(offsetof(xfs_dir2_data_entry_t, name[0]) + (n) + \
		 (uint)sizeof(xfs_dir2_data_off_t), XFS_DIR2_DATA_ALIGN);
}
L
Linus Torvalds 已提交
131 132 133 134

/*
 * Pointer to an entry's tag word.
 */
135
static inline __be16 *
136 137
xfs_dir2_data_entry_tag_p(xfs_dir2_data_entry_t *dep)
{
138
	return (__be16 *)((char *)dep +
139
		xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16));
140
}
L
Linus Torvalds 已提交
141 142 143 144

/*
 * Pointer to a freespace's tag word.
 */
145
static inline __be16 *
146 147
xfs_dir2_data_unused_tag_p(xfs_dir2_data_unused_t *dup)
{
148 149
	return (__be16 *)((char *)dup +
			be16_to_cpu(dup->length) - sizeof(__be16));
150
}
L
Linus Torvalds 已提交
151 152 153 154 155

/*
 * Function declarations.
 */
#ifdef DEBUG
156
extern void xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp);
L
Linus Torvalds 已提交
157 158 159
#else
#define	xfs_dir2_data_check(dp,bp)
#endif
160 161 162 163 164
extern xfs_dir2_data_free_t *xfs_dir2_data_freefind(xfs_dir2_data_t *d,
				xfs_dir2_data_unused_t *dup);
extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_t *d,
				xfs_dir2_data_unused_t *dup, int *loghead);
extern void xfs_dir2_data_freescan(struct xfs_mount *mp, xfs_dir2_data_t *d,
165
				int *loghead);
166 167 168
extern int xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
				struct xfs_dabuf **bpp);
extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp,
L
Linus Torvalds 已提交
169
				xfs_dir2_data_entry_t *dep);
170 171 172 173 174
extern void xfs_dir2_data_log_header(struct xfs_trans *tp,
				struct xfs_dabuf *bp);
extern void xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_dabuf *bp,
				xfs_dir2_data_unused_t *dup);
extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
L
Linus Torvalds 已提交
175 176 177
				xfs_dir2_data_aoff_t offset,
				xfs_dir2_data_aoff_t len, int *needlogp,
				int *needscanp);
178
extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
L
Linus Torvalds 已提交
179 180 181 182 183 184
			       xfs_dir2_data_unused_t *dup,
			       xfs_dir2_data_aoff_t offset,
			       xfs_dir2_data_aoff_t len, int *needlogp,
			       int *needscanp);

#endif	/* __XFS_DIR2_DATA_H__ */