xref: /netbsd-src/sys/ufs/ext2fs/ext2fs_extents.h (revision 9bd4ba417d045dba399c191a33f736de4600c34b)
1*9bd4ba41Sriastradh /*	$NetBSD: ext2fs_extents.h,v 1.5 2023/08/26 05:22:50 riastradh Exp $	*/
24e815995Schristos 
34e815995Schristos /*-
44e815995Schristos  * Copyright (c) 2012, 2010 Zheng Liu <lz@freebsd.org>
54e815995Schristos  * All rights reserved.
64e815995Schristos  *
74e815995Schristos  * Redistribution and use in source and binary forms, with or without
84e815995Schristos  * modification, are permitted provided that the following conditions
94e815995Schristos  * are met:
104e815995Schristos  * 1. Redistributions of source code must retain the above copyright
114e815995Schristos  *    notice, this list of conditions and the following disclaimer.
124e815995Schristos  * 2. Redistributions in binary form must reproduce the above copyright
134e815995Schristos  *    notice, this list of conditions and the following disclaimer in the
144e815995Schristos  *    documentation and/or other materials provided with the distribution.
154e815995Schristos  *
164e815995Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174e815995Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184e815995Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194e815995Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
204e815995Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214e815995Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224e815995Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234e815995Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244e815995Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254e815995Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264e815995Schristos  * SUCH DAMAGE.
274e815995Schristos  *
284e815995Schristos  * $FreeBSD: head/sys/fs/ext2fs/ext2_extents.h 295523 2016-02-11 15:27:14Z pfg $
294e815995Schristos  */
304e815995Schristos 
314e815995Schristos #ifndef _UFS_EXT2FS_EXT2FS_EXTENTS_H_
324e815995Schristos #define	_UFS_EXT2FS_EXT2FS_EXTENTS_H_
334e815995Schristos 
344e815995Schristos #include <sys/types.h>
3509e85cd4Skre #ifndef _KERNEL
3609e85cd4Skre #include <stdbool.h>
3709e85cd4Skre #endif
3809e85cd4Skre 
394e815995Schristos #include <ufs/ufs/inode.h>
404e815995Schristos #define	EXT4_EXT_MAGIC  0xf30a
414e815995Schristos 
424e815995Schristos #define	EXT4_EXT_CACHE_NO	0
434e815995Schristos #define	EXT4_EXT_CACHE_GAP	1
444e815995Schristos #define	EXT4_EXT_CACHE_IN	2
454e815995Schristos 
464e815995Schristos /*
474e815995Schristos  * Ext4 file system extent on disk.
484e815995Schristos  */
494e815995Schristos struct ext4_extent {
504e815995Schristos 	uint32_t e_blk;		/* first logical block */
514e815995Schristos 	uint16_t e_len;		/* number of blocks */
524e815995Schristos 	uint16_t e_start_hi;	/* high 16 bits of physical block */
534e815995Schristos 	uint32_t e_start_lo;	/* low 32 bits of physical block */
544e815995Schristos };
554e815995Schristos 
564e815995Schristos /*
574e815995Schristos  * Extent index on disk.
584e815995Schristos  */
594e815995Schristos struct ext4_extent_index {
604e815995Schristos 	uint32_t ei_blk;	/* indexes logical blocks */
614e815995Schristos 	uint32_t ei_leaf_lo;	/* points to physical block of the
624e815995Schristos 				 * next level */
634e815995Schristos 	uint16_t ei_leaf_hi;	/* high 16 bits of physical block */
644e815995Schristos 	uint16_t ei_unused;
654e815995Schristos };
664e815995Schristos 
674e815995Schristos /*
684e815995Schristos  * Extent tree header.
694e815995Schristos  */
704e815995Schristos struct ext4_extent_header {
714e815995Schristos 	uint16_t eh_magic;	/* magic number: 0xf30a */
724e815995Schristos 	uint16_t eh_ecount;	/* number of valid entries */
734e815995Schristos 	uint16_t eh_max;	/* capacity of store in entries */
744e815995Schristos 	uint16_t eh_depth;	/* the depth of extent tree */
754e815995Schristos 	uint32_t eh_gen;	/* generation of extent tree */
764e815995Schristos };
774e815995Schristos 
784e815995Schristos /*
794e815995Schristos  * Save cached extent.
804e815995Schristos  */
814e815995Schristos struct ext4_extent_cache {
824e815995Schristos 	daddr_t	ec_start;	/* extent start */
834e815995Schristos 	uint32_t ec_blk;	/* logical block */
844e815995Schristos 	uint32_t ec_len;
854e815995Schristos 	uint32_t ec_type;
864e815995Schristos };
874e815995Schristos 
884e815995Schristos /*
894e815995Schristos  * Save path to some extent.
904e815995Schristos  */
914e815995Schristos struct ext4_extent_path {
924e815995Schristos 	uint16_t ep_depth;
934e815995Schristos 	struct buf *ep_bp;
944e815995Schristos 	bool ep_is_sparse;
954e815995Schristos 	union {
964e815995Schristos 		struct ext4_extent ep_sparse_ext;
974e815995Schristos 		struct ext4_extent *ep_ext;
984e815995Schristos 	};
994e815995Schristos 	struct ext4_extent_index *ep_index;
1004e815995Schristos 	struct ext4_extent_header *ep_header;
1014e815995Schristos };
1024e815995Schristos 
1034e815995Schristos struct inode;
1044e815995Schristos struct m_ext2fs;
1054e815995Schristos 
1064e815995Schristos int	ext4_ext_in_cache(struct inode *, daddr_t, struct ext4_extent *);
1074e815995Schristos void	ext4_ext_put_cache(struct inode *, struct ext4_extent *, int);
1084e815995Schristos struct ext4_extent_path *ext4_ext_find_extent(struct m_ext2fs *fs,
1094e815995Schristos     struct inode *, daddr_t, struct ext4_extent_path *);
1104e815995Schristos 
1114e815995Schristos #endif /* !_UFS_EXT2FS_EXT2FS_EXTENTS_H_ */
112