2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * Copyright (c) 2013 Red Hat, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it would be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef __XFS_DA_FORMAT_H__
20 #define __XFS_DA_FORMAT_H__
22 /*========================================================================
23 * Directory Structure when greater than XFS_LBSIZE(mp) bytes.
24 *========================================================================*/
27 * This structure is common to both leaf nodes and non-leaf nodes in the Btree.
29 * It is used to manage a doubly linked list of all blocks at the same
30 * level in the Btree, and to identify which type of block this is.
32 #define XFS_DA_NODE_MAGIC 0xfebe /* magic number: non-leaf blocks */
33 #define XFS_ATTR_LEAF_MAGIC 0xfbee /* magic number: attribute leaf blks */
34 #define XFS_DIR2_LEAF1_MAGIC 0xd2f1 /* magic number: v2 dirlf single blks */
35 #define XFS_DIR2_LEAFN_MAGIC 0xd2ff /* magic number: v2 dirlf multi blks */
37 typedef struct xfs_da_blkinfo {
38 __be32 forw; /* previous block in list */
39 __be32 back; /* following block in list */
40 __be16 magic; /* validity check on block */
41 __be16 pad; /* unused */
45 * CRC enabled directory structure types
47 * The headers change size for the additional verification information, but
48 * otherwise the tree layouts and contents are unchanged. Hence the da btree
49 * code can use the struct xfs_da_blkinfo for manipulating the tree links and
50 * magic numbers without modification for both v2 and v3 nodes.
52 #define XFS_DA3_NODE_MAGIC 0x3ebe /* magic number: non-leaf blocks */
53 #define XFS_ATTR3_LEAF_MAGIC 0x3bee /* magic number: attribute leaf blks */
54 #define XFS_DIR3_LEAF1_MAGIC 0x3df1 /* magic number: v2 dirlf single blks */
55 #define XFS_DIR3_LEAFN_MAGIC 0x3dff /* magic number: v2 dirlf multi blks */
57 struct xfs_da3_blkinfo {
59 * the node link manipulation code relies on the fact that the first
60 * element of this structure is the struct xfs_da_blkinfo so it can
61 * ignore the differences in the rest of the structures.
63 struct xfs_da_blkinfo hdr;
64 __be32 crc; /* CRC of block */
65 __be64 blkno; /* first block of the buffer */
66 __be64 lsn; /* sequence number of last write */
67 uuid_t uuid; /* filesystem we belong to */
68 __be64 owner; /* inode that owns the block */
72 * This is the structure of the root and intermediate nodes in the Btree.
73 * The leaf nodes are defined above.
75 * Entries are not packed.
77 * Since we have duplicate keys, use a binary search but always follow
78 * all match in the block, not just the first match found.
80 #define XFS_DA_NODE_MAXDEPTH 5 /* max depth of Btree */
82 typedef struct xfs_da_node_hdr {
83 struct xfs_da_blkinfo info; /* block type, links, etc. */
84 __be16 __count; /* count of active entries */
85 __be16 __level; /* level above leaves (leaf == 0) */
88 struct xfs_da3_node_hdr {
89 struct xfs_da3_blkinfo info; /* block type, links, etc. */
90 __be16 __count; /* count of active entries */
91 __be16 __level; /* level above leaves (leaf == 0) */
95 #define XFS_DA3_NODE_CRC_OFF (offsetof(struct xfs_da3_node_hdr, info.crc))
97 typedef struct xfs_da_node_entry {
98 __be32 hashval; /* hash value for this descendant */
99 __be32 before; /* Btree block before this key */
100 } xfs_da_node_entry_t;
102 typedef struct xfs_da_intnode {
103 struct xfs_da_node_hdr hdr;
104 struct xfs_da_node_entry __btree[];
107 struct xfs_da3_intnode {
108 struct xfs_da3_node_hdr hdr;
109 struct xfs_da_node_entry __btree[];
113 * In-core version of the node header to abstract the differences in the v2 and
114 * v3 disk format of the headers. Callers need to convert to/from disk format as
117 struct xfs_da3_icnode_hdr {
125 #define XFS_LBSIZE(mp) (mp)->m_sb.sb_blocksize
128 * Directory version 2.
130 * There are 4 possible formats:
131 * - shortform - embedded into the inode
132 * - single block - data with embedded leaf at the end
133 * - multiple data blocks, single leaf+freeindex block
134 * - data blocks, node and leaf blocks (btree), freeindex blocks
136 * Note: many node blocks structures and constants are shared with the attr
137 * code and defined in xfs_da_btree.h.
140 #define XFS_DIR2_BLOCK_MAGIC 0x58443242 /* XD2B: single block dirs */
141 #define XFS_DIR2_DATA_MAGIC 0x58443244 /* XD2D: multiblock dirs */
142 #define XFS_DIR2_FREE_MAGIC 0x58443246 /* XD2F: free index blocks */
145 * Directory Version 3 With CRCs.
147 * The tree formats are the same as for version 2 directories. The difference
148 * is in the block header and dirent formats. In many cases the v3 structures
149 * use v2 definitions as they are no different and this makes code sharing much
152 * Also, the xfs_dir3_*() functions handle both v2 and v3 formats - if the
153 * format is v2 then they switch to the existing v2 code, or the format is v3
154 * they implement the v3 functionality. This means the existing dir2 is a mix of
155 * xfs_dir2/xfs_dir3 calls and functions. The xfs_dir3 functions are called
156 * where there is a difference in the formats, otherwise the code is unchanged.
158 * Where it is possible, the code decides what to do based on the magic numbers
159 * in the blocks rather than feature bits in the superblock. This means the code
160 * is as independent of the external XFS code as possible as doesn't require
161 * passing struct xfs_mount pointers into places where it isn't really
164 * Version 3 includes:
166 * - a larger block header for CRC and identification purposes and so the
167 * offsets of all the structures inside the blocks are different.
169 * - new magic numbers to be able to detect the v2/v3 types on the fly.
172 #define XFS_DIR3_BLOCK_MAGIC 0x58444233 /* XDB3: single block dirs */
173 #define XFS_DIR3_DATA_MAGIC 0x58444433 /* XDD3: multiblock dirs */
174 #define XFS_DIR3_FREE_MAGIC 0x58444633 /* XDF3: free index blocks */
177 * Dirents in version 3 directories have a file type field. Additions to this
178 * list are an on-disk format change, requiring feature bits. Valid values
181 #define XFS_DIR3_FT_UNKNOWN 0
182 #define XFS_DIR3_FT_REG_FILE 1
183 #define XFS_DIR3_FT_DIR 2
184 #define XFS_DIR3_FT_CHRDEV 3
185 #define XFS_DIR3_FT_BLKDEV 4
186 #define XFS_DIR3_FT_FIFO 5
187 #define XFS_DIR3_FT_SOCK 6
188 #define XFS_DIR3_FT_SYMLINK 7
189 #define XFS_DIR3_FT_WHT 8
191 #define XFS_DIR3_FT_MAX 9
194 * Byte offset in data block and shortform entry.
196 typedef __uint16_t xfs_dir2_data_off_t;
197 #define NULLDATAOFF 0xffffU
198 typedef uint xfs_dir2_data_aoff_t; /* argument form */
201 * Normalized offset (in a data block) of the entry, really xfs_dir2_data_off_t.
202 * Only need 16 bits, this is the byte offset into the single block form.
204 typedef struct { __uint8_t i[2]; } __arch_pack xfs_dir2_sf_off_t;
207 * Offset in data space of a data entry.
209 typedef __uint32_t xfs_dir2_dataptr_t;
210 #define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff)
211 #define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
214 * Byte offset in a directory.
216 typedef xfs_off_t xfs_dir2_off_t;
219 * Directory block number (logical dirblk in file)
221 typedef __uint32_t xfs_dir2_db_t;
224 * Inode number stored as 8 8-bit values.
226 typedef struct { __uint8_t i[8]; } xfs_dir2_ino8_t;
229 * Inode number stored as 4 8-bit values.
230 * Works a lot of the time, when all the inode numbers in a directory
233 typedef struct { __uint8_t i[4]; } xfs_dir2_ino4_t;
239 #define XFS_DIR2_MAX_SHORT_INUM ((xfs_ino_t)0xffffffffULL)
242 * Directory layout when stored internal to an inode.
244 * Small directories are packed as tightly as possible so as to fit into the
245 * literal area of the inode. These "shortform" directories consist of a
246 * single xfs_dir2_sf_hdr header followed by zero or more xfs_dir2_sf_entry
247 * structures. Due the different inode number storage size and the variable
248 * length name field in the xfs_dir2_sf_entry all these structure are
249 * variable length, and the accessors in this file should be used to iterate
252 typedef struct xfs_dir2_sf_hdr {
253 __uint8_t count; /* count of entries */
254 __uint8_t i8count; /* count of 8-byte inode #s */
255 xfs_dir2_inou_t parent; /* parent dir inode number */
256 } __arch_pack xfs_dir2_sf_hdr_t;
258 typedef struct xfs_dir2_sf_entry {
259 __u8 namelen; /* actual name length */
260 xfs_dir2_sf_off_t offset; /* saved offset */
261 __u8 name[]; /* name, variable size */
263 * A single byte containing the file type field follows the inode
264 * number for version 3 directory entries.
266 * A xfs_dir2_ino8_t or xfs_dir2_ino4_t follows here, at a
267 * variable offset after the name.
269 } __arch_pack xfs_dir2_sf_entry_t;
271 static inline int xfs_dir2_sf_hdr_size(int i8count)
273 return sizeof(struct xfs_dir2_sf_hdr) -
275 (sizeof(xfs_dir2_ino8_t) - sizeof(xfs_dir2_ino4_t));
278 static inline xfs_dir2_data_aoff_t
279 xfs_dir2_sf_get_offset(xfs_dir2_sf_entry_t *sfep)
281 return get_unaligned_be16(&sfep->offset.i);
285 xfs_dir2_sf_put_offset(xfs_dir2_sf_entry_t *sfep, xfs_dir2_data_aoff_t off)
287 put_unaligned_be16(off, &sfep->offset.i);
290 static inline struct xfs_dir2_sf_entry *
291 xfs_dir2_sf_firstentry(struct xfs_dir2_sf_hdr *hdr)
293 return (struct xfs_dir2_sf_entry *)
294 ((char *)hdr + xfs_dir2_sf_hdr_size(hdr->i8count));
298 * Data block structures.
300 * A pure data block looks like the following drawing on disk:
302 * +-------------------------------------------------+
303 * | xfs_dir2_data_hdr_t |
304 * +-------------------------------------------------+
305 * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
306 * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
307 * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
309 * +-------------------------------------------------+
311 * +-------------------------------------------------+
313 * As all the entries are variable size structures the accessors below should
314 * be used to iterate over them.
316 * In addition to the pure data blocks for the data and node formats,
317 * most structures are also used for the combined data/freespace "block"
321 #define XFS_DIR2_DATA_ALIGN_LOG 3 /* i.e., 8 bytes */
322 #define XFS_DIR2_DATA_ALIGN (1 << XFS_DIR2_DATA_ALIGN_LOG)
323 #define XFS_DIR2_DATA_FREE_TAG 0xffff
324 #define XFS_DIR2_DATA_FD_COUNT 3
327 * Directory address space divided into sections,
328 * spaces separated by 32GB.
330 #define XFS_DIR2_SPACE_SIZE (1ULL << (32 + XFS_DIR2_DATA_ALIGN_LOG))
331 #define XFS_DIR2_DATA_SPACE 0
332 #define XFS_DIR2_DATA_OFFSET (XFS_DIR2_DATA_SPACE * XFS_DIR2_SPACE_SIZE)
335 * Describe a free area in the data block.
337 * The freespace will be formatted as a xfs_dir2_data_unused_t.
339 typedef struct xfs_dir2_data_free {
340 __be16 offset; /* start of freespace */
341 __be16 length; /* length of freespace */
342 } xfs_dir2_data_free_t;
345 * Header for the data blocks.
347 * The code knows that XFS_DIR2_DATA_FD_COUNT is 3.
349 typedef struct xfs_dir2_data_hdr {
350 __be32 magic; /* XFS_DIR2_DATA_MAGIC or */
351 /* XFS_DIR2_BLOCK_MAGIC */
352 xfs_dir2_data_free_t bestfree[XFS_DIR2_DATA_FD_COUNT];
353 } xfs_dir2_data_hdr_t;
356 * define a structure for all the verification fields we are adding to the
357 * directory block structures. This will be used in several structures.
358 * The magic number must be the first entry to align with all the dir2
359 * structures so we determine how to decode them just by the magic number.
361 struct xfs_dir3_blk_hdr {
362 __be32 magic; /* magic number */
363 __be32 crc; /* CRC of block */
364 __be64 blkno; /* first block of the buffer */
365 __be64 lsn; /* sequence number of last write */
366 uuid_t uuid; /* filesystem we belong to */
367 __be64 owner; /* inode that owns the block */
370 struct xfs_dir3_data_hdr {
371 struct xfs_dir3_blk_hdr hdr;
372 xfs_dir2_data_free_t best_free[XFS_DIR2_DATA_FD_COUNT];
373 __be32 pad; /* 64 bit alignment */
376 #define XFS_DIR3_DATA_CRC_OFF offsetof(struct xfs_dir3_data_hdr, hdr.crc)
379 * Active entry in a data block.
381 * Aligned to 8 bytes. After the variable length name field there is a
382 * 2 byte tag field, which can be accessed using xfs_dir3_data_entry_tag_p.
384 * For dir3 structures, there is file type field between the name and the tag.
385 * This can only be manipulated by helper functions. It is packed hard against
386 * the end of the name so any padding for rounding is between the file type and
389 typedef struct xfs_dir2_data_entry {
390 __be64 inumber; /* inode number */
391 __u8 namelen; /* name length */
392 __u8 name[]; /* name bytes, no null */
393 /* __u8 filetype; */ /* type of inode we point to */
394 /* __be16 tag; */ /* starting offset of us */
395 } xfs_dir2_data_entry_t;
398 * Unused entry in a data block.
400 * Aligned to 8 bytes. Tag appears as the last 2 bytes and must be accessed
401 * using xfs_dir2_data_unused_tag_p.
403 typedef struct xfs_dir2_data_unused {
404 __be16 freetag; /* XFS_DIR2_DATA_FREE_TAG */
405 __be16 length; /* total free length */
406 /* variable offset */
407 __be16 tag; /* starting offset of us */
408 } xfs_dir2_data_unused_t;
411 * Pointer to a freespace's tag word.
413 static inline __be16 *
414 xfs_dir2_data_unused_tag_p(struct xfs_dir2_data_unused *dup)
416 return (__be16 *)((char *)dup +
417 be16_to_cpu(dup->length) - sizeof(__be16));
421 * Leaf block structures.
423 * A pure leaf block looks like the following drawing on disk:
425 * +---------------------------+
426 * | xfs_dir2_leaf_hdr_t |
427 * +---------------------------+
428 * | xfs_dir2_leaf_entry_t |
429 * | xfs_dir2_leaf_entry_t |
430 * | xfs_dir2_leaf_entry_t |
431 * | xfs_dir2_leaf_entry_t |
433 * +---------------------------+
434 * | xfs_dir2_data_off_t |
435 * | xfs_dir2_data_off_t |
436 * | xfs_dir2_data_off_t |
438 * +---------------------------+
439 * | xfs_dir2_leaf_tail_t |
440 * +---------------------------+
442 * The xfs_dir2_data_off_t members (bests) and tail are at the end of the block
443 * for single-leaf (magic = XFS_DIR2_LEAF1_MAGIC) blocks only, but not present
444 * for directories with separate leaf nodes and free space blocks
445 * (magic = XFS_DIR2_LEAFN_MAGIC).
447 * As all the entries are variable size structures the accessors below should
448 * be used to iterate over them.
452 * Offset of the leaf/node space. First block in this space
455 #define XFS_DIR2_LEAF_SPACE 1
456 #define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
461 typedef struct xfs_dir2_leaf_hdr {
462 xfs_da_blkinfo_t info; /* header for da routines */
463 __be16 count; /* count of entries */
464 __be16 stale; /* count of stale entries */
465 } xfs_dir2_leaf_hdr_t;
467 struct xfs_dir3_leaf_hdr {
468 struct xfs_da3_blkinfo info; /* header for da routines */
469 __be16 count; /* count of entries */
470 __be16 stale; /* count of stale entries */
471 __be32 pad; /* 64 bit alignment */
474 struct xfs_dir3_icleaf_hdr {
485 typedef struct xfs_dir2_leaf_entry {
486 __be32 hashval; /* hash value of name */
487 __be32 address; /* address of data entry */
488 } xfs_dir2_leaf_entry_t;
493 typedef struct xfs_dir2_leaf_tail {
495 } xfs_dir2_leaf_tail_t;
500 typedef struct xfs_dir2_leaf {
501 xfs_dir2_leaf_hdr_t hdr; /* leaf header */
502 xfs_dir2_leaf_entry_t __ents[]; /* entries */
505 struct xfs_dir3_leaf {
506 struct xfs_dir3_leaf_hdr hdr; /* leaf header */
507 struct xfs_dir2_leaf_entry __ents[]; /* entries */
510 #define XFS_DIR3_LEAF_CRC_OFF offsetof(struct xfs_dir3_leaf_hdr, info.crc)
513 * Get address of the bests array in the single-leaf block.
515 static inline __be16 *
516 xfs_dir2_leaf_bests_p(struct xfs_dir2_leaf_tail *ltp)
518 return (__be16 *)ltp - be32_to_cpu(ltp->bestcount);
522 * Free space block defintions for the node format.
526 * Offset of the freespace index.
528 #define XFS_DIR2_FREE_SPACE 2
529 #define XFS_DIR2_FREE_OFFSET (XFS_DIR2_FREE_SPACE * XFS_DIR2_SPACE_SIZE)
531 typedef struct xfs_dir2_free_hdr {
532 __be32 magic; /* XFS_DIR2_FREE_MAGIC */
533 __be32 firstdb; /* db of first entry */
534 __be32 nvalid; /* count of valid entries */
535 __be32 nused; /* count of used entries */
536 } xfs_dir2_free_hdr_t;
538 typedef struct xfs_dir2_free {
539 xfs_dir2_free_hdr_t hdr; /* block header */
540 __be16 bests[]; /* best free counts */
541 /* unused entries are -1 */
544 struct xfs_dir3_free_hdr {
545 struct xfs_dir3_blk_hdr hdr;
546 __be32 firstdb; /* db of first entry */
547 __be32 nvalid; /* count of valid entries */
548 __be32 nused; /* count of used entries */
549 __be32 pad; /* 64 bit alignment */
552 struct xfs_dir3_free {
553 struct xfs_dir3_free_hdr hdr;
554 __be16 bests[]; /* best free counts */
555 /* unused entries are -1 */
558 #define XFS_DIR3_FREE_CRC_OFF offsetof(struct xfs_dir3_free, hdr.hdr.crc)
561 * In core version of the free block header, abstracted away from on-disk format
562 * differences. Use this in the code, and convert to/from the disk version using
563 * xfs_dir3_free_hdr_from_disk/xfs_dir3_free_hdr_to_disk.
565 struct xfs_dir3_icfree_hdr {
574 * Single block format.
576 * The single block format looks like the following drawing on disk:
578 * +-------------------------------------------------+
579 * | xfs_dir2_data_hdr_t |
580 * +-------------------------------------------------+
581 * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
582 * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
583 * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t :
585 * +-------------------------------------------------+
587 * +-------------------------------------------------+
589 * | xfs_dir2_leaf_entry_t |
590 * | xfs_dir2_leaf_entry_t |
591 * +-------------------------------------------------+
592 * | xfs_dir2_block_tail_t |
593 * +-------------------------------------------------+
595 * As all the entries are variable size structures the accessors below should
596 * be used to iterate over them.
599 typedef struct xfs_dir2_block_tail {
600 __be32 count; /* count of leaf entries */
601 __be32 stale; /* count of stale lf entries */
602 } xfs_dir2_block_tail_t;
605 * Pointer to the leaf entries embedded in a data block (1-block format)
607 static inline struct xfs_dir2_leaf_entry *
608 xfs_dir2_block_leaf_p(struct xfs_dir2_block_tail *btp)
610 return ((struct xfs_dir2_leaf_entry *)btp) - be32_to_cpu(btp->count);
615 * Attribute storage layout
617 * Attribute lists are structured around Btrees where all the data
618 * elements are in the leaf nodes. Attribute names are hashed into an int,
619 * then that int is used as the index into the Btree. Since the hashval
620 * of an attribute name may not be unique, we may have duplicate keys. The
621 * internal links in the Btree are logical block offsets into the file.
623 *========================================================================
624 * Attribute structure when equal to XFS_LBSIZE(mp) bytes.
625 *========================================================================
627 * Struct leaf_entry's are packed from the top. Name/values grow from the
628 * bottom but are not packed. The freemap contains run-length-encoded entries
629 * for the free bytes after the leaf_entry's, but only the N largest such,
630 * smaller runs are dropped. When the freemap doesn't show enough space
631 * for an allocation, we compact the name/value area and try again. If we
632 * still don't have enough space, then we have to split the block. The
633 * name/value structs (both local and remote versions) must be 32bit aligned.
635 * Since we have duplicate hash keys, for each key that matches, compare
636 * the actual name string. The root and intermediate node search always
637 * takes the first-in-the-block key match found, so we should only have
638 * to work "forw"ard. If none matches, continue with the "forw"ard leaf
639 * nodes until the hash key changes or the attribute name is found.
641 * We store the fact that an attribute is a ROOT/USER/SECURE attribute in
642 * the leaf_entry. The namespaces are independent only because we also look
643 * at the namespace bit when we are looking for a matching attribute name.
645 * We also store an "incomplete" bit in the leaf_entry. It shows that an
646 * attribute is in the middle of being created and should not be shown to
647 * the user if we crash during the time that the bit is set. We clear the
648 * bit when we have finished setting up the attribute. We do this because
649 * we cannot create some large attributes inside a single transaction, and we
650 * need some indication that we weren't finished if we crash in the middle.
652 #define XFS_ATTR_LEAF_MAPSIZE 3 /* how many freespace slots */
654 typedef struct xfs_attr_leaf_map { /* RLE map of free bytes */
655 __be16 base; /* base of free region */
656 __be16 size; /* length of free region */
657 } xfs_attr_leaf_map_t;
659 typedef struct xfs_attr_leaf_hdr { /* constant-structure header block */
660 xfs_da_blkinfo_t info; /* block type, links, etc. */
661 __be16 count; /* count of active leaf_entry's */
662 __be16 usedbytes; /* num bytes of names/values stored */
663 __be16 firstused; /* first used byte in name area */
664 __u8 holes; /* != 0 if blk needs compaction */
666 xfs_attr_leaf_map_t freemap[XFS_ATTR_LEAF_MAPSIZE];
667 /* N largest free regions */
668 } xfs_attr_leaf_hdr_t;
670 typedef struct xfs_attr_leaf_entry { /* sorted on key, not name */
671 __be32 hashval; /* hash value of name */
672 __be16 nameidx; /* index into buffer of name/value */
673 __u8 flags; /* LOCAL/ROOT/SECURE/INCOMPLETE flag */
674 __u8 pad2; /* unused pad byte */
675 } xfs_attr_leaf_entry_t;
677 typedef struct xfs_attr_leaf_name_local {
678 __be16 valuelen; /* number of bytes in value */
679 __u8 namelen; /* length of name bytes */
680 __u8 nameval[1]; /* name/value bytes */
681 } xfs_attr_leaf_name_local_t;
683 typedef struct xfs_attr_leaf_name_remote {
684 __be32 valueblk; /* block number of value bytes */
685 __be32 valuelen; /* number of bytes in value */
686 __u8 namelen; /* length of name bytes */
687 __u8 name[1]; /* name bytes */
688 } xfs_attr_leaf_name_remote_t;
690 typedef struct xfs_attr_leafblock {
691 xfs_attr_leaf_hdr_t hdr; /* constant-structure header block */
692 xfs_attr_leaf_entry_t entries[1]; /* sorted on key, not name */
693 xfs_attr_leaf_name_local_t namelist; /* grows from bottom of buf */
694 xfs_attr_leaf_name_remote_t valuelist; /* grows from bottom of buf */
695 } xfs_attr_leafblock_t;
698 * CRC enabled leaf structures. Called "version 3" structures to match the
699 * version number of the directory and dablk structures for this feature, and
700 * attr2 is already taken by the variable inode attribute fork size feature.
702 struct xfs_attr3_leaf_hdr {
703 struct xfs_da3_blkinfo info;
709 struct xfs_attr_leaf_map freemap[XFS_ATTR_LEAF_MAPSIZE];
710 __be32 pad2; /* 64 bit alignment */
713 #define XFS_ATTR3_LEAF_CRC_OFF (offsetof(struct xfs_attr3_leaf_hdr, info.crc))
715 struct xfs_attr3_leafblock {
716 struct xfs_attr3_leaf_hdr hdr;
717 struct xfs_attr_leaf_entry entries[1];
720 * The rest of the block contains the following structures after the
721 * leaf entries, growing from the bottom up. The variables are never
722 * referenced, the locations accessed purely from helper functions.
724 * struct xfs_attr_leaf_name_local
725 * struct xfs_attr_leaf_name_remote
730 * incore, neutral version of the attribute leaf header
732 struct xfs_attr3_icleaf_hdr {
737 __uint16_t usedbytes;
738 __uint16_t firstused;
743 } freemap[XFS_ATTR_LEAF_MAPSIZE];
747 * Flags used in the leaf_entry[i].flags field.
748 * NOTE: the INCOMPLETE bit must not collide with the flags bits specified
749 * on the system call, they are "or"ed together for various operations.
751 #define XFS_ATTR_LOCAL_BIT 0 /* attr is stored locally */
752 #define XFS_ATTR_ROOT_BIT 1 /* limit access to trusted attrs */
753 #define XFS_ATTR_SECURE_BIT 2 /* limit access to secure attrs */
754 #define XFS_ATTR_INCOMPLETE_BIT 7 /* attr in middle of create/delete */
755 #define XFS_ATTR_LOCAL (1 << XFS_ATTR_LOCAL_BIT)
756 #define XFS_ATTR_ROOT (1 << XFS_ATTR_ROOT_BIT)
757 #define XFS_ATTR_SECURE (1 << XFS_ATTR_SECURE_BIT)
758 #define XFS_ATTR_INCOMPLETE (1 << XFS_ATTR_INCOMPLETE_BIT)
761 * Conversion macros for converting namespace bits from argument flags
764 #define XFS_ATTR_NSP_ARGS_MASK (ATTR_ROOT | ATTR_SECURE)
765 #define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE)
766 #define XFS_ATTR_NSP_ONDISK(flags) ((flags) & XFS_ATTR_NSP_ONDISK_MASK)
767 #define XFS_ATTR_NSP_ARGS(flags) ((flags) & XFS_ATTR_NSP_ARGS_MASK)
768 #define XFS_ATTR_NSP_ARGS_TO_ONDISK(x) (((x) & ATTR_ROOT ? XFS_ATTR_ROOT : 0) |\
769 ((x) & ATTR_SECURE ? XFS_ATTR_SECURE : 0))
770 #define XFS_ATTR_NSP_ONDISK_TO_ARGS(x) (((x) & XFS_ATTR_ROOT ? ATTR_ROOT : 0) |\
771 ((x) & XFS_ATTR_SECURE ? ATTR_SECURE : 0))
774 * Alignment for namelist and valuelist entries (since they are mixed
775 * there can be only one alignment value)
777 #define XFS_ATTR_LEAF_NAME_ALIGN ((uint)sizeof(xfs_dablk_t))
780 xfs_attr3_leaf_hdr_size(struct xfs_attr_leafblock *leafp)
782 if (leafp->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
783 return sizeof(struct xfs_attr3_leaf_hdr);
784 return sizeof(struct xfs_attr_leaf_hdr);
787 static inline struct xfs_attr_leaf_entry *
788 xfs_attr3_leaf_entryp(xfs_attr_leafblock_t *leafp)
790 if (leafp->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
791 return &((struct xfs_attr3_leafblock *)leafp)->entries[0];
792 return &leafp->entries[0];
796 * Cast typed pointers for "local" and "remote" name/value structs.
799 xfs_attr3_leaf_name(xfs_attr_leafblock_t *leafp, int idx)
801 struct xfs_attr_leaf_entry *entries = xfs_attr3_leaf_entryp(leafp);
803 return &((char *)leafp)[be16_to_cpu(entries[idx].nameidx)];
806 static inline xfs_attr_leaf_name_remote_t *
807 xfs_attr3_leaf_name_remote(xfs_attr_leafblock_t *leafp, int idx)
809 return (xfs_attr_leaf_name_remote_t *)xfs_attr3_leaf_name(leafp, idx);
812 static inline xfs_attr_leaf_name_local_t *
813 xfs_attr3_leaf_name_local(xfs_attr_leafblock_t *leafp, int idx)
815 return (xfs_attr_leaf_name_local_t *)xfs_attr3_leaf_name(leafp, idx);
819 * Calculate total bytes used (including trailing pad for alignment) for
820 * a "local" name/value structure, a "remote" name/value structure, and
821 * a pointer which might be either.
823 static inline int xfs_attr_leaf_entsize_remote(int nlen)
825 return ((uint)sizeof(xfs_attr_leaf_name_remote_t) - 1 + (nlen) + \
826 XFS_ATTR_LEAF_NAME_ALIGN - 1) & ~(XFS_ATTR_LEAF_NAME_ALIGN - 1);
829 static inline int xfs_attr_leaf_entsize_local(int nlen, int vlen)
831 return ((uint)sizeof(xfs_attr_leaf_name_local_t) - 1 + (nlen) + (vlen) +
832 XFS_ATTR_LEAF_NAME_ALIGN - 1) & ~(XFS_ATTR_LEAF_NAME_ALIGN - 1);
835 static inline int xfs_attr_leaf_entsize_local_max(int bsize)
837 return (((bsize) >> 1) + ((bsize) >> 2));
843 * Remote attribute block format definition
845 * There is one of these headers per filesystem block in a remote attribute.
846 * This is done to ensure there is a 1:1 mapping between the attribute value
847 * length and the number of blocks needed to store the attribute. This makes the
848 * verification of a buffer a little more complex, but greatly simplifies the
849 * allocation, reading and writing of these attributes as we don't have to guess
850 * the number of blocks needed to store the attribute data.
852 #define XFS_ATTR3_RMT_MAGIC 0x5841524d /* XARM */
854 struct xfs_attr3_rmt_hdr {
865 #define XFS_ATTR3_RMT_CRC_OFF offsetof(struct xfs_attr3_rmt_hdr, rm_crc)
867 #define XFS_ATTR3_RMT_BUF_SPACE(mp, bufsize) \
868 ((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
869 sizeof(struct xfs_attr3_rmt_hdr) : 0))
871 #endif /* __XFS_DA_FORMAT_H__ */