ext2_extents.h revision 294545
1294190Sdes/*- 2238106Sdes * Copyright (c) 2012, 2010 Zheng Liu <lz@freebsd.org> 3238106Sdes * All rights reserved. 4238106Sdes * 5238106Sdes * Redistribution and use in source and binary forms, with or without 6238106Sdes * modification, are permitted provided that the following conditions 7238106Sdes * are met: 8238106Sdes * 1. Redistributions of source code must retain the above copyright 9238106Sdes * notice, this list of conditions and the following disclaimer. 10238106Sdes * 2. Redistributions in binary form must reproduce the above copyright 11238106Sdes * notice, this list of conditions and the following disclaimer in the 12238106Sdes * documentation and/or other materials provided with the distribution. 13238106Sdes * 14238106Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15238106Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16238106Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17238106Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18238106Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19238106Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20238106Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21238106Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22238106Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23238106Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24238106Sdes * SUCH DAMAGE. 25285206Sdes * 26238106Sdes * $FreeBSD: stable/10/sys/fs/ext2fs/ext2_extents.h 294545 2016-01-22 03:25:06Z pfg $ 27238106Sdes */ 28238106Sdes#ifndef _FS_EXT2FS_EXT2_EXTENTS_H_ 29238106Sdes#define _FS_EXT2FS_EXT2_EXTENTS_H_ 30238106Sdes 31238106Sdes#include <sys/types.h> 32238106Sdes 33238106Sdes#define EXT4_EXT_MAGIC 0xf30a 34238106Sdes 35238106Sdes#define EXT4_EXT_CACHE_NO 0 36238106Sdes#define EXT4_EXT_CACHE_GAP 1 37238106Sdes#define EXT4_EXT_CACHE_IN 2 38238106Sdes 39238106Sdes/* 40238106Sdes * Ext4 file system extent on disk. 41238106Sdes */ 42238106Sdesstruct ext4_extent { 43238106Sdes uint32_t e_blk; /* first logical block */ 44238106Sdes uint16_t e_len; /* number of blocks */ 45294190Sdes uint16_t e_start_hi; /* high 16 bits of physical block */ 46238106Sdes uint32_t e_start_lo; /* low 32 bits of physical block */ 47238106Sdes}; 48238106Sdes 49238106Sdes/* 50238106Sdes * Extent index on disk. 51238106Sdes */ 52238106Sdesstruct ext4_extent_index { 53238106Sdes uint32_t ei_blk; /* indexes logical blocks */ 54238106Sdes uint32_t ei_leaf_lo; /* points to physical block of the 55238106Sdes * next level */ 56238106Sdes uint16_t ei_leaf_hi; /* high 16 bits of physical block */ 57238106Sdes uint16_t ei_unused; 58238106Sdes}; 59238106Sdes 60238106Sdes/* 61238106Sdes * Extent tree header. 62238106Sdes */ 63238106Sdesstruct ext4_extent_header { 64238106Sdes uint16_t eh_magic; /* magic number: 0xf30a */ 65238106Sdes uint16_t eh_ecount; /* number of valid entries */ 66238106Sdes uint16_t eh_max; /* capacity of store in entries */ 67238106Sdes uint16_t eh_depth; /* the depth of extent tree */ 68238106Sdes uint32_t eh_gen; /* generation of extent tree */ 69238106Sdes}; 70238106Sdes 71238106Sdes/* 72238106Sdes * Save cached extent. 73238106Sdes */ 74238106Sdesstruct ext4_extent_cache { 75238106Sdes daddr_t ec_start; /* extent start */ 76238106Sdes uint32_t ec_blk; /* logical block */ 77285206Sdes uint32_t ec_len; 78285206Sdes uint32_t ec_type; 79285206Sdes}; 80238106Sdes 81238106Sdes/* 82238106Sdes * Save path to some extent. 83238106Sdes */ 84238106Sdesstruct ext4_extent_path { 85238106Sdes uint16_t ep_depth; 86238106Sdes struct buf *ep_bp; 87238106Sdes struct ext4_extent *ep_ext; 88238106Sdes struct ext4_extent_index *ep_index; 89238106Sdes struct ext4_extent_header *ep_header; 90238106Sdes}; 91238106Sdes 92238106Sdesstruct inode; 93238106Sdesstruct m_ext2fs; 94238106Sdesint ext4_ext_in_cache(struct inode *, daddr_t, struct ext4_extent *); 95238106Sdesvoid ext4_ext_put_cache(struct inode *, struct ext4_extent *, int); 96238106Sdesstruct ext4_extent_path *ext4_ext_find_extent(struct m_ext2fs *fs, 97238106Sdes struct inode *, daddr_t, struct ext4_extent_path *); 98238106Sdes 99238106Sdes#endif /* !_FS_EXT2FS_EXT2_EXTENTS_H_ */ 100238106Sdes