xref: /dragonfly/sys/vfs/ext2fs/ext2_extents.c (revision cfe60390)
1*cfe60390STomohiro Kusumi /*-
2*cfe60390STomohiro Kusumi  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*cfe60390STomohiro Kusumi  *
4*cfe60390STomohiro Kusumi  * Copyright (c) 2010 Zheng Liu <lz@freebsd.org>
5*cfe60390STomohiro Kusumi  * All rights reserved.
6*cfe60390STomohiro Kusumi  *
7*cfe60390STomohiro Kusumi  * Redistribution and use in source and binary forms, with or without
8*cfe60390STomohiro Kusumi  * modification, are permitted provided that the following conditions
9*cfe60390STomohiro Kusumi  * are met:
10*cfe60390STomohiro Kusumi  * 1. Redistributions of source code must retain the above copyright
11*cfe60390STomohiro Kusumi  *    notice, this list of conditions and the following disclaimer.
12*cfe60390STomohiro Kusumi  * 2. Redistributions in binary form must reproduce the above copyright
13*cfe60390STomohiro Kusumi  *    notice, this list of conditions and the following disclaimer in the
14*cfe60390STomohiro Kusumi  *    documentation and/or other materials provided with the distribution.
15*cfe60390STomohiro Kusumi  *
16*cfe60390STomohiro Kusumi  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*cfe60390STomohiro Kusumi  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*cfe60390STomohiro Kusumi  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*cfe60390STomohiro Kusumi  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*cfe60390STomohiro Kusumi  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*cfe60390STomohiro Kusumi  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*cfe60390STomohiro Kusumi  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*cfe60390STomohiro Kusumi  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*cfe60390STomohiro Kusumi  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*cfe60390STomohiro Kusumi  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*cfe60390STomohiro Kusumi  * SUCH DAMAGE.
27*cfe60390STomohiro Kusumi  *
28*cfe60390STomohiro Kusumi  * $FreeBSD$
29*cfe60390STomohiro Kusumi  */
30*cfe60390STomohiro Kusumi 
31*cfe60390STomohiro Kusumi #include <sys/param.h>
32*cfe60390STomohiro Kusumi #include <sys/systm.h>
33*cfe60390STomohiro Kusumi #include <sys/types.h>
34*cfe60390STomohiro Kusumi #include <sys/kernel.h>
35*cfe60390STomohiro Kusumi #include <sys/malloc.h>
36*cfe60390STomohiro Kusumi #include <sys/vnode.h>
37*cfe60390STomohiro Kusumi #include <sys/bio.h>
38*cfe60390STomohiro Kusumi #include <sys/buf.h>
39*cfe60390STomohiro Kusumi #include <sys/endian.h>
40*cfe60390STomohiro Kusumi #include <sys/conf.h>
41*cfe60390STomohiro Kusumi #include <sys/stat.h>
42*cfe60390STomohiro Kusumi #include <sys/mount.h>
43*cfe60390STomohiro Kusumi #include <sys/mutex.h>
44*cfe60390STomohiro Kusumi 
45*cfe60390STomohiro Kusumi #include <vfs/ext2fs/ext2_mount.h>
46*cfe60390STomohiro Kusumi #include <vfs/ext2fs/fs.h>
47*cfe60390STomohiro Kusumi #include <vfs/ext2fs/inode.h>
48*cfe60390STomohiro Kusumi #include <vfs/ext2fs/ext2fs.h>
49*cfe60390STomohiro Kusumi #include <vfs/ext2fs/ext2_extents.h>
50*cfe60390STomohiro Kusumi #include <vfs/ext2fs/ext2_extern.h>
51*cfe60390STomohiro Kusumi 
52*cfe60390STomohiro Kusumi SDT_PROVIDER_DECLARE(ext2fs);
53*cfe60390STomohiro Kusumi /*
54*cfe60390STomohiro Kusumi  * ext2fs trace probe:
55*cfe60390STomohiro Kusumi  * arg0: verbosity. Higher numbers give more verbose messages
56*cfe60390STomohiro Kusumi  * arg1: Textual message
57*cfe60390STomohiro Kusumi  */
58*cfe60390STomohiro Kusumi SDT_PROBE_DEFINE2(ext2fs, , trace, extents, "int", "char*");
59*cfe60390STomohiro Kusumi 
60*cfe60390STomohiro Kusumi #ifdef EXT2FS_PRINT_EXTENTS
61*cfe60390STomohiro Kusumi static void
ext4_ext_print_extent(struct ext4_extent * ep)62*cfe60390STomohiro Kusumi ext4_ext_print_extent(struct ext4_extent *ep)
63*cfe60390STomohiro Kusumi {
64*cfe60390STomohiro Kusumi }
65*cfe60390STomohiro Kusumi 
66*cfe60390STomohiro Kusumi static void
ext4_ext_print_index(struct inode * ip,struct ext4_extent_index * ex,int do_walk)67*cfe60390STomohiro Kusumi ext4_ext_print_index(struct inode *ip, struct ext4_extent_index *ex, int do_walk)
68*cfe60390STomohiro Kusumi {
69*cfe60390STomohiro Kusumi }
70*cfe60390STomohiro Kusumi 
71*cfe60390STomohiro Kusumi static void
ext4_ext_print_header(struct inode * ip,struct ext4_extent_header * ehp)72*cfe60390STomohiro Kusumi ext4_ext_print_header(struct inode *ip, struct ext4_extent_header *ehp)
73*cfe60390STomohiro Kusumi {
74*cfe60390STomohiro Kusumi }
75*cfe60390STomohiro Kusumi 
76*cfe60390STomohiro Kusumi static void
ext4_ext_print_path(struct inode * ip,struct ext4_extent_path * path)77*cfe60390STomohiro Kusumi ext4_ext_print_path(struct inode *ip, struct ext4_extent_path *path)
78*cfe60390STomohiro Kusumi {
79*cfe60390STomohiro Kusumi }
80*cfe60390STomohiro Kusumi 
81*cfe60390STomohiro Kusumi void
ext4_ext_print_extent_tree_status(struct inode * ip)82*cfe60390STomohiro Kusumi ext4_ext_print_extent_tree_status(struct inode *ip)
83*cfe60390STomohiro Kusumi {
84*cfe60390STomohiro Kusumi }
85*cfe60390STomohiro Kusumi #endif
86*cfe60390STomohiro Kusumi 
87*cfe60390STomohiro Kusumi static inline struct ext4_extent_header *
ext4_ext_inode_header(struct inode * ip)88*cfe60390STomohiro Kusumi ext4_ext_inode_header(struct inode *ip)
89*cfe60390STomohiro Kusumi {
90*cfe60390STomohiro Kusumi 	return (NULL);
91*cfe60390STomohiro Kusumi }
92*cfe60390STomohiro Kusumi 
93*cfe60390STomohiro Kusumi static inline struct ext4_extent_header *
ext4_ext_block_header(char * bdata)94*cfe60390STomohiro Kusumi ext4_ext_block_header(char *bdata)
95*cfe60390STomohiro Kusumi {
96*cfe60390STomohiro Kusumi 	return (NULL);
97*cfe60390STomohiro Kusumi }
98*cfe60390STomohiro Kusumi 
99*cfe60390STomohiro Kusumi static inline unsigned short
ext4_ext_inode_depth(struct inode * ip)100*cfe60390STomohiro Kusumi ext4_ext_inode_depth(struct inode *ip)
101*cfe60390STomohiro Kusumi {
102*cfe60390STomohiro Kusumi 	return (0);
103*cfe60390STomohiro Kusumi }
104*cfe60390STomohiro Kusumi 
105*cfe60390STomohiro Kusumi static inline e4fs_daddr_t
ext4_ext_index_pblock(struct ext4_extent_index * index)106*cfe60390STomohiro Kusumi ext4_ext_index_pblock(struct ext4_extent_index *index)
107*cfe60390STomohiro Kusumi {
108*cfe60390STomohiro Kusumi 	return (0);
109*cfe60390STomohiro Kusumi }
110*cfe60390STomohiro Kusumi 
111*cfe60390STomohiro Kusumi static inline void
ext4_index_store_pblock(struct ext4_extent_index * index,e4fs_daddr_t pb)112*cfe60390STomohiro Kusumi ext4_index_store_pblock(struct ext4_extent_index *index, e4fs_daddr_t pb)
113*cfe60390STomohiro Kusumi {
114*cfe60390STomohiro Kusumi }
115*cfe60390STomohiro Kusumi 
116*cfe60390STomohiro Kusumi static inline e4fs_daddr_t
ext4_ext_extent_pblock(struct ext4_extent * extent)117*cfe60390STomohiro Kusumi ext4_ext_extent_pblock(struct ext4_extent *extent)
118*cfe60390STomohiro Kusumi {
119*cfe60390STomohiro Kusumi 	return (0);
120*cfe60390STomohiro Kusumi }
121*cfe60390STomohiro Kusumi 
122*cfe60390STomohiro Kusumi static inline void
ext4_ext_store_pblock(struct ext4_extent * ex,e4fs_daddr_t pb)123*cfe60390STomohiro Kusumi ext4_ext_store_pblock(struct ext4_extent *ex, e4fs_daddr_t pb)
124*cfe60390STomohiro Kusumi {
125*cfe60390STomohiro Kusumi }
126*cfe60390STomohiro Kusumi 
127*cfe60390STomohiro Kusumi int
ext4_ext_in_cache(struct inode * ip,daddr_t lbn,struct ext4_extent * ep)128*cfe60390STomohiro Kusumi ext4_ext_in_cache(struct inode *ip, daddr_t lbn, struct ext4_extent *ep)
129*cfe60390STomohiro Kusumi {
130*cfe60390STomohiro Kusumi 	return (EXT4_EXT_CACHE_NO);
131*cfe60390STomohiro Kusumi }
132*cfe60390STomohiro Kusumi 
133*cfe60390STomohiro Kusumi void
ext4_ext_path_free(struct ext4_extent_path * path)134*cfe60390STomohiro Kusumi ext4_ext_path_free(struct ext4_extent_path *path)
135*cfe60390STomohiro Kusumi {
136*cfe60390STomohiro Kusumi }
137*cfe60390STomohiro Kusumi 
138*cfe60390STomohiro Kusumi int
ext4_ext_find_extent(struct inode * ip,daddr_t block,struct ext4_extent_path ** ppath)139*cfe60390STomohiro Kusumi ext4_ext_find_extent(struct inode *ip, daddr_t block,
140*cfe60390STomohiro Kusumi     struct ext4_extent_path **ppath)
141*cfe60390STomohiro Kusumi {
142*cfe60390STomohiro Kusumi 	return (EINVAL);
143*cfe60390STomohiro Kusumi }
144*cfe60390STomohiro Kusumi 
145*cfe60390STomohiro Kusumi static inline int
ext4_ext_space_root(struct inode * ip)146*cfe60390STomohiro Kusumi ext4_ext_space_root(struct inode *ip)
147*cfe60390STomohiro Kusumi {
148*cfe60390STomohiro Kusumi 	return (0);
149*cfe60390STomohiro Kusumi }
150*cfe60390STomohiro Kusumi 
151*cfe60390STomohiro Kusumi static inline int
ext4_ext_space_block(struct inode * ip)152*cfe60390STomohiro Kusumi ext4_ext_space_block(struct inode *ip)
153*cfe60390STomohiro Kusumi {
154*cfe60390STomohiro Kusumi 	return (0);
155*cfe60390STomohiro Kusumi }
156*cfe60390STomohiro Kusumi 
157*cfe60390STomohiro Kusumi static inline int
ext4_ext_space_block_index(struct inode * ip)158*cfe60390STomohiro Kusumi ext4_ext_space_block_index(struct inode *ip)
159*cfe60390STomohiro Kusumi {
160*cfe60390STomohiro Kusumi 	return (0);
161*cfe60390STomohiro Kusumi }
162*cfe60390STomohiro Kusumi 
163*cfe60390STomohiro Kusumi void
ext4_ext_tree_init(struct inode * ip)164*cfe60390STomohiro Kusumi ext4_ext_tree_init(struct inode *ip)
165*cfe60390STomohiro Kusumi {
166*cfe60390STomohiro Kusumi }
167*cfe60390STomohiro Kusumi 
168*cfe60390STomohiro Kusumi static inline void
ext4_ext_put_in_cache(struct inode * ip,uint32_t blk,uint32_t len,uint32_t start,int type)169*cfe60390STomohiro Kusumi ext4_ext_put_in_cache(struct inode *ip, uint32_t blk,
170*cfe60390STomohiro Kusumi 			uint32_t len, uint32_t start, int type)
171*cfe60390STomohiro Kusumi {
172*cfe60390STomohiro Kusumi }
173*cfe60390STomohiro Kusumi 
174*cfe60390STomohiro Kusumi static inline int
ext4_can_extents_be_merged(struct ext4_extent * ex1,struct ext4_extent * ex2)175*cfe60390STomohiro Kusumi ext4_can_extents_be_merged(struct ext4_extent *ex1,
176*cfe60390STomohiro Kusumi     struct ext4_extent *ex2)
177*cfe60390STomohiro Kusumi {
178*cfe60390STomohiro Kusumi 	return (0);
179*cfe60390STomohiro Kusumi }
180*cfe60390STomohiro Kusumi 
181*cfe60390STomohiro Kusumi int
ext4_ext_get_blocks(struct inode * ip,e4fs_daddr_t iblk,unsigned long max_blocks,struct ucred * cred,struct buf ** bpp,int * pallocated,daddr_t * nb)182*cfe60390STomohiro Kusumi ext4_ext_get_blocks(struct inode *ip, e4fs_daddr_t iblk,
183*cfe60390STomohiro Kusumi     unsigned long max_blocks, struct ucred *cred, struct buf **bpp,
184*cfe60390STomohiro Kusumi     int *pallocated, daddr_t *nb)
185*cfe60390STomohiro Kusumi {
186*cfe60390STomohiro Kusumi 	return (EINVAL);
187*cfe60390STomohiro Kusumi }
188*cfe60390STomohiro Kusumi 
189*cfe60390STomohiro Kusumi static inline uint16_t
ext4_ext_get_actual_len(struct ext4_extent * ext)190*cfe60390STomohiro Kusumi ext4_ext_get_actual_len(struct ext4_extent *ext)
191*cfe60390STomohiro Kusumi {
192*cfe60390STomohiro Kusumi 	return (0);
193*cfe60390STomohiro Kusumi }
194*cfe60390STomohiro Kusumi 
195*cfe60390STomohiro Kusumi static inline struct ext4_extent_header *
ext4_ext_header(struct inode * ip)196*cfe60390STomohiro Kusumi ext4_ext_header(struct inode *ip)
197*cfe60390STomohiro Kusumi {
198*cfe60390STomohiro Kusumi 	return (NULL);
199*cfe60390STomohiro Kusumi }
200*cfe60390STomohiro Kusumi 
201*cfe60390STomohiro Kusumi static inline int
ext4_ext_more_to_rm(struct ext4_extent_path * path)202*cfe60390STomohiro Kusumi ext4_ext_more_to_rm(struct ext4_extent_path *path)
203*cfe60390STomohiro Kusumi {
204*cfe60390STomohiro Kusumi 	return (0);
205*cfe60390STomohiro Kusumi }
206*cfe60390STomohiro Kusumi 
207*cfe60390STomohiro Kusumi int
ext4_ext_remove_space(struct inode * ip,off_t length,int flags,struct ucred * cred,struct thread * td)208*cfe60390STomohiro Kusumi ext4_ext_remove_space(struct inode *ip, off_t length, int flags,
209*cfe60390STomohiro Kusumi     struct ucred *cred, struct thread *td)
210*cfe60390STomohiro Kusumi {
211*cfe60390STomohiro Kusumi 	return (EINVAL);
212*cfe60390STomohiro Kusumi }
213