2 * Copyright (c) 2000-2001 Christoph Hellwig.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
14 * Alternatively, this software may be distributed under the terms of the
15 * GNU General Public License ("GPL").
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Veritas filesystem driver - filesystem to disk block mapping.
34 #include <linux/buffer_head.h>
35 #include <linux/kernel.h>
38 #include "vxfs_inode.h"
43 vxfs_typdump(struct vxfs_typed
*typ
)
45 printk(KERN_DEBUG
"type=%Lu ", typ
->vt_hdr
>> VXFS_TYPED_TYPESHIFT
);
46 printk("offset=%Lx ", typ
->vt_hdr
& VXFS_TYPED_OFFSETMASK
);
47 printk("block=%x ", typ
->vt_block
);
48 printk("size=%x\n", typ
->vt_size
);
53 * vxfs_bmap_ext4 - do bmap for ext4 extents
54 * @ip: pointer to the inode we do bmap for
55 * @iblock: logical block.
58 * vxfs_bmap_ext4 performs the bmap operation for inodes with
59 * ext4-style extents (which are much like the traditional UNIX
60 * inode organisation).
63 * The physical block number on success, else Zero.
66 vxfs_bmap_ext4(struct inode
*ip
, long bn
)
68 struct super_block
*sb
= ip
->i_sb
;
69 struct vxfs_inode_info
*vip
= VXFS_INO(ip
);
70 unsigned long bsize
= sb
->s_blocksize
;
71 u32 indsize
= vip
->vii_ext4
.ve4_indsize
;
74 if (indsize
> sb
->s_blocksize
)
77 for (i
= 0; i
< VXFS_NDADDR
; i
++) {
78 struct direct
*d
= vip
->vii_ext4
.ve4_direct
+ i
;
79 if (bn
>= 0 && bn
< d
->size
)
80 return (bn
+ d
->extent
);
84 if ((bn
/ (indsize
* indsize
* bsize
/ 4)) == 0) {
85 struct buffer_head
*buf
;
89 buf
= sb_bread(sb
, vip
->vii_ext4
.ve4_indir
[0]);
90 if (!buf
|| !buffer_mapped(buf
))
93 indir
= (u32
*)buf
->b_data
;
94 bno
= indir
[(bn
/indsize
) % (indsize
*bn
)] + (bn
%indsize
);
99 printk(KERN_WARNING
"no matching indir?");
104 printk("vxfs: indirect extent to big!\n");
110 * vxfs_bmap_indir - recursion for vxfs_bmap_typed
111 * @ip: pointer to the inode we do bmap for
112 * @indir: indirect block we start reading at
113 * @size: size of the typed area to search
114 * @block: partially result from further searches
117 * vxfs_bmap_indir reads a &struct vxfs_typed at @indir
118 * and performs the type-defined action.
121 * The physical block number on success, else Zero.
124 * Kernelstack is rare. Unrecurse?
127 vxfs_bmap_indir(struct inode
*ip
, long indir
, int size
, long block
)
129 struct buffer_head
*bp
= NULL
;
133 for (i
= 0; i
< size
* VXFS_TYPED_PER_BLOCK(ip
->i_sb
); i
++) {
134 struct vxfs_typed
*typ
;
137 bp
= sb_bread(ip
->i_sb
,
138 indir
+ (i
/ VXFS_TYPED_PER_BLOCK(ip
->i_sb
)));
139 if (!buffer_mapped(bp
))
142 typ
= ((struct vxfs_typed
*)bp
->b_data
) +
143 (i
% VXFS_TYPED_PER_BLOCK(ip
->i_sb
));
144 off
= (typ
->vt_hdr
& VXFS_TYPED_OFFSETMASK
);
151 switch ((u_int32_t
)(typ
->vt_hdr
>> VXFS_TYPED_TYPESHIFT
)) {
152 case VXFS_TYPED_INDIRECT
:
153 pblock
= vxfs_bmap_indir(ip
, typ
->vt_block
,
154 typ
->vt_size
, block
- off
);
158 case VXFS_TYPED_DATA
:
159 if ((block
- off
) >= typ
->vt_size
)
161 pblock
= (typ
->vt_block
+ block
- off
);
163 case VXFS_TYPED_INDIRECT_DEV4
:
164 case VXFS_TYPED_DATA_DEV4
: {
165 struct vxfs_typed_dev4
*typ4
=
166 (struct vxfs_typed_dev4
*)typ
;
168 printk(KERN_INFO
"\n\nTYPED_DEV4 detected!\n");
169 printk(KERN_INFO
"block: %Lu\tsize: %Ld\tdev: %d\n",
170 (unsigned long long) typ4
->vd4_block
,
171 (unsigned long long) typ4
->vd4_size
,
189 * vxfs_bmap_typed - bmap for typed extents
190 * @ip: pointer to the inode we do bmap for
191 * @iblock: logical block
194 * Performs the bmap operation for typed extents.
197 * The physical block number on success, else Zero.
200 vxfs_bmap_typed(struct inode
*ip
, long iblock
)
202 struct vxfs_inode_info
*vip
= VXFS_INO(ip
);
206 for (i
= 0; i
< VXFS_NTYPED
; i
++) {
207 struct vxfs_typed
*typ
= vip
->vii_org
.typed
+ i
;
208 int64_t off
= (typ
->vt_hdr
& VXFS_TYPED_OFFSETMASK
);
215 switch ((u_int32_t
)(typ
->vt_hdr
>> VXFS_TYPED_TYPESHIFT
)) {
216 case VXFS_TYPED_INDIRECT
:
217 pblock
= vxfs_bmap_indir(ip
, typ
->vt_block
,
218 typ
->vt_size
, iblock
- off
);
222 case VXFS_TYPED_DATA
:
223 if ((iblock
- off
) < typ
->vt_size
)
224 return (typ
->vt_block
+ iblock
- off
);
226 case VXFS_TYPED_INDIRECT_DEV4
:
227 case VXFS_TYPED_DATA_DEV4
: {
228 struct vxfs_typed_dev4
*typ4
=
229 (struct vxfs_typed_dev4
*)typ
;
231 printk(KERN_INFO
"\n\nTYPED_DEV4 detected!\n");
232 printk(KERN_INFO
"block: %Lu\tsize: %Ld\tdev: %d\n",
233 (unsigned long long) typ4
->vd4_block
,
234 (unsigned long long) typ4
->vd4_size
,
247 * vxfs_bmap1 - vxfs-internal bmap operation
248 * @ip: pointer to the inode we do bmap for
249 * @iblock: logical block
252 * vxfs_bmap1 perfoms a logical to physical block mapping
253 * for vxfs-internal purposes.
256 * The physical block number on success, else Zero.
259 vxfs_bmap1(struct inode
*ip
, long iblock
)
261 struct vxfs_inode_info
*vip
= VXFS_INO(ip
);
263 if (VXFS_ISEXT4(vip
))
264 return vxfs_bmap_ext4(ip
, iblock
);
265 if (VXFS_ISTYPED(vip
))
266 return vxfs_bmap_typed(ip
, iblock
);
267 if (VXFS_ISNONE(vip
))
269 if (VXFS_ISIMMED(vip
))
272 printk(KERN_WARNING
"vxfs: inode %ld has no valid orgtype (%x)\n",
273 ip
->i_ino
, vip
->vii_orgtype
);
277 printk(KERN_WARNING
"vxfs: inode %ld has an unsupported orgtype (%x)\n",
278 ip
->i_ino
, vip
->vii_orgtype
);