Home | History | Annotate | Download | only in ext2fs
      1 /*
      2  * Copyright (c) 2003,2004 Cluster File Systems, Inc, info (at) clusterfs.com
      3  * Written by Alex Tomas <alex (at) clusterfs.com>
      4  *
      5  * %Begin-Header%
      6  * This file may be redistributed under the terms of the GNU Library
      7  * General Public License, version 2.
      8  * %End-Header%
      9  */
     10 
     11 #ifndef _LINUX_EXT3_EXTENTS
     12 #define _LINUX_EXT3_EXTENTS
     13 
     14 /*
     15  * ext3_inode has i_block array (total 60 bytes)
     16  * first 4 bytes are used to store:
     17  *  - tree depth (0 mean there is no tree yet. all extents in the inode)
     18  *  - number of alive extents in the inode
     19  */
     20 
     21 /*
     22  * This is extent tail on-disk structure.
     23  * All other extent structures are 12 bytes long.  It turns out that
     24  * block_size % 12 >= 4 for at least all powers of 2 greater than 512, which
     25  * covers all valid ext4 block sizes.  Therefore, this tail structure can be
     26  * crammed into the end of the block without having to rebalance the tree.
     27  */
     28 struct ext3_extent_tail {
     29 	__le32	et_checksum;	/* crc32c(uuid+inum+extent_block) */
     30 };
     31 
     32 /*
     33  * this is extent on-disk structure
     34  * it's used at the bottom of the tree
     35  */
     36 struct ext3_extent {
     37 	__le32	ee_block;	/* first logical block extent covers */
     38 	__le16	ee_len;		/* number of blocks covered by extent */
     39 	__le16	ee_start_hi;	/* high 16 bits of physical block */
     40 	__le32	ee_start;	/* low 32 bigs of physical block */
     41 };
     42 
     43 /*
     44  * this is index on-disk structure
     45  * it's used at all the levels, but the bottom
     46  */
     47 struct ext3_extent_idx {
     48 	__le32	ei_block;	/* index covers logical blocks from 'block' */
     49 	__le32	ei_leaf;	/* pointer to the physical block of the next *
     50 				 * level. leaf or next index could bet here */
     51 	__le16	ei_leaf_hi;	/* high 16 bits of physical block */
     52 	__le16	ei_unused;
     53 };
     54 
     55 /*
     56  * each block (leaves and indexes), even inode-stored has header
     57  */
     58 struct ext3_extent_header {
     59 	__le16	eh_magic;	/* probably will support different formats */
     60 	__le16	eh_entries;	/* number of valid entries */
     61 	__le16	eh_max;		/* capacity of store in entries */
     62 	__le16	eh_depth;	/* has tree real underlaying blocks? */
     63 	__le32	eh_generation;	/* generation of the tree */
     64 };
     65 
     66 #define EXT3_EXT_MAGIC		0xf30a
     67 
     68 /*
     69  * array of ext3_ext_path contains path to some extent
     70  * creation/lookup routines use it for traversal/splitting/etc
     71  * truncate uses it to simulate recursive walking
     72  */
     73 struct ext3_ext_path {
     74 	__u32				p_block;
     75 	__u16				p_depth;
     76 	struct ext3_extent		*p_ext;
     77 	struct ext3_extent_idx		*p_idx;
     78 	struct ext3_extent_header	*p_hdr;
     79 	struct buffer_head		*p_bh;
     80 };
     81 
     82 /*
     83  * EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an
     84  * initialized extent. This is 2^15 and not (2^16 - 1), since we use the
     85  * MSB of ee_len field in the extent datastructure to signify if this
     86  * particular extent is an initialized extent or an uninitialized (i.e.
     87  * preallocated).
     88  * EXT_UNINIT_MAX_LEN is the maximum number of blocks we can have in an
     89  * uninitialized extent.
     90  * If ee_len is <= 0x8000, it is an initialized extent. Otherwise, it is an
     91  * uninitialized one. In other words, if MSB of ee_len is set, it is an
     92  * uninitialized extent with only one special scenario when ee_len = 0x8000.
     93  * In this case we can not have an uninitialized extent of zero length and
     94  * thus we make it as a special case of initialized extent with 0x8000 length.
     95  * This way we get better extent-to-group alignment for initialized extents.
     96  * Hence, the maximum number of blocks we can have in an *initialized*
     97  * extent is 2^15 (32768) and in an *uninitialized* extent is 2^15-1 (32767).
     98  */
     99 #define EXT_INIT_MAX_LEN	(1UL << 15)
    100 #define EXT_UNINIT_MAX_LEN	(EXT_INIT_MAX_LEN - 1)
    101 #define EXT_MAX_EXTENT_LBLK	(((__u64) 1 << 32) - 1)
    102 #define EXT_MAX_EXTENT_PBLK	(((__u64) 1 << 48) - 1)
    103 
    104 #define EXT_FIRST_EXTENT(__hdr__) \
    105 	((struct ext3_extent *) (((char *) (__hdr__)) +		\
    106 				 sizeof(struct ext3_extent_header)))
    107 #define EXT_FIRST_INDEX(__hdr__) \
    108 	((struct ext3_extent_idx *) (((char *) (__hdr__)) +	\
    109 				     sizeof(struct ext3_extent_header)))
    110 #define EXT_HAS_FREE_INDEX(__path__) \
    111 	(ext2fs_le16_to_cpu((__path__)->p_hdr->eh_entries) < \
    112 	 ext2fs_le16_to_cpu((__path__)->p_hdr->eh_max))
    113 #define EXT_LAST_EXTENT(__hdr__) \
    114 	(EXT_FIRST_EXTENT((__hdr__)) + \
    115 	ext2fs_le16_to_cpu((__hdr__)->eh_entries) - 1)
    116 #define EXT_LAST_INDEX(__hdr__) \
    117 	(EXT_FIRST_INDEX((__hdr__)) + \
    118 	ext2fs_le16_to_cpu((__hdr__)->eh_entries) - 1)
    119 #define EXT_MAX_EXTENT(__hdr__) \
    120 	(EXT_FIRST_EXTENT((__hdr__)) + \
    121 	ext2fs_le16_to_cpu((__hdr__)->eh_max) - 1)
    122 #define EXT_MAX_INDEX(__hdr__) \
    123 	(EXT_FIRST_INDEX((__hdr__)) + \
    124 	ext2fs_le16_to_cpu((__hdr__)->eh_max) - 1)
    125 
    126 #endif /* _LINUX_EXT3_EXTENTS */
    127 
    128