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