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