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 on-disk structure
     23  * it's used at the bottom of the tree
     24  */
     25 struct ext3_extent {
     26 	__u32	ee_block;	/* first logical block extent covers */
     27 	__u16	ee_len;		/* number of blocks covered by extent */
     28 	__u16	ee_start_hi;	/* high 16 bits of physical block */
     29 	__u32	ee_start;	/* low 32 bigs of physical block */
     30 };
     31 
     32 /*
     33  * this is index on-disk structure
     34  * it's used at all the levels, but the bottom
     35  */
     36 struct ext3_extent_idx {
     37 	__u32	ei_block;	/* index covers logical blocks from 'block' */
     38 	__u32	ei_leaf;	/* pointer to the physical block of the next *
     39 				 * level. leaf or next index could bet here */
     40 	__u16	ei_leaf_hi;	/* high 16 bits of physical block */
     41 	__u16	ei_unused;
     42 };
     43 
     44 /*
     45  * each block (leaves and indexes), even inode-stored has header
     46  */
     47 struct ext3_extent_header {
     48 	__u16	eh_magic;	/* probably will support different formats */
     49 	__u16	eh_entries;	/* number of valid entries */
     50 	__u16	eh_max;		/* capacity of store in entries */
     51 	__u16	eh_depth;	/* has tree real underlaying blocks? */
     52 	__u32	eh_generation;	/* generation of the tree */
     53 };
     54 
     55 #define EXT3_EXT_MAGIC		0xf30a
     56 
     57 /*
     58  * array of ext3_ext_path contains path to some extent
     59  * creation/lookup routines use it for traversal/splitting/etc
     60  * truncate uses it to simulate recursive walking
     61  */
     62 struct ext3_ext_path {
     63 	__u32				p_block;
     64 	__u16				p_depth;
     65 	struct ext3_extent		*p_ext;
     66 	struct ext3_extent_idx		*p_idx;
     67 	struct ext3_extent_header	*p_hdr;
     68 	struct buffer_head		*p_bh;
     69 };
     70 
     71 /*
     72  * EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an
     73  * initialized extent. This is 2^15 and not (2^16 - 1), since we use the
     74  * MSB of ee_len field in the extent datastructure to signify if this
     75  * particular extent is an initialized extent or an uninitialized (i.e.
     76  * preallocated).
     77  * EXT_UNINIT_MAX_LEN is the maximum number of blocks we can have in an
     78  * uninitialized extent.
     79  * If ee_len is <= 0x8000, it is an initialized extent. Otherwise, it is an
     80  * uninitialized one. In other words, if MSB of ee_len is set, it is an
     81  * uninitialized extent with only one special scenario when ee_len = 0x8000.
     82  * In this case we can not have an uninitialized extent of zero length and
     83  * thus we make it as a special case of initialized extent with 0x8000 length.
     84  * This way we get better extent-to-group alignment for initialized extents.
     85  * Hence, the maximum number of blocks we can have in an *initialized*
     86  * extent is 2^15 (32768) and in an *uninitialized* extent is 2^15-1 (32767).
     87  */
     88 #define EXT_INIT_MAX_LEN	(1UL << 15)
     89 #define EXT_UNINIT_MAX_LEN	(EXT_INIT_MAX_LEN - 1)
     90 
     91 #define EXT_FIRST_EXTENT(__hdr__) \
     92 	((struct ext3_extent *) (((char *) (__hdr__)) +		\
     93 				 sizeof(struct ext3_extent_header)))
     94 #define EXT_FIRST_INDEX(__hdr__) \
     95 	((struct ext3_extent_idx *) (((char *) (__hdr__)) +	\
     96 				     sizeof(struct ext3_extent_header)))
     97 #define EXT_HAS_FREE_INDEX(__path__) \
     98 	((__path__)->p_hdr->eh_entries < (__path__)->p_hdr->eh_max)
     99 #define EXT_LAST_EXTENT(__hdr__) \
    100 	(EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_entries - 1)
    101 #define EXT_LAST_INDEX(__hdr__) \
    102 	(EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_entries - 1)
    103 #define EXT_MAX_EXTENT(__hdr__) \
    104 	(EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_max - 1)
    105 #define EXT_MAX_INDEX(__hdr__) \
    106 	(EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_max - 1)
    107 
    108 #endif /* _LINUX_EXT3_EXTENTS */
    109 
    110