1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2000-2001 Christoph Hellwig.
7 * Veritas filesystem driver - filesystem to disk block mapping.
10 #include <linux/buffer_head.h>
11 #include <linux/kernel.h>
14 #include "vxfs_inode.h"
15 #include "vxfs_extern.h"
20 vxfs_typdump(struct vxfs_typed
*typ
)
22 printk(KERN_DEBUG
"type=%Lu ", typ
->vt_hdr
>> VXFS_TYPED_TYPESHIFT
);
23 printk("offset=%Lx ", typ
->vt_hdr
& VXFS_TYPED_OFFSETMASK
);
24 printk("block=%x ", typ
->vt_block
);
25 printk("size=%x\n", typ
->vt_size
);
30 * vxfs_bmap_ext4 - do bmap for ext4 extents
31 * @ip: pointer to the inode we do bmap for
35 * vxfs_bmap_ext4 performs the bmap operation for inodes with
36 * ext4-style extents (which are much like the traditional UNIX
37 * inode organisation).
40 * The physical block number on success, else Zero.
43 vxfs_bmap_ext4(struct inode
*ip
, long bn
)
45 struct super_block
*sb
= ip
->i_sb
;
46 struct vxfs_inode_info
*vip
= VXFS_INO(ip
);
47 struct vxfs_sb_info
*sbi
= VXFS_SBI(sb
);
48 unsigned long bsize
= sb
->s_blocksize
;
49 u32 indsize
= fs32_to_cpu(sbi
, vip
->vii_ext4
.ve4_indsize
);
52 if (indsize
> sb
->s_blocksize
)
55 for (i
= 0; i
< VXFS_NDADDR
; i
++) {
56 struct direct
*d
= vip
->vii_ext4
.ve4_direct
+ i
;
57 if (bn
>= 0 && bn
< fs32_to_cpu(sbi
, d
->size
))
58 return (bn
+ fs32_to_cpu(sbi
, d
->extent
));
59 bn
-= fs32_to_cpu(sbi
, d
->size
);
62 if ((bn
/ (indsize
* indsize
* bsize
/ 4)) == 0) {
63 struct buffer_head
*buf
;
68 fs32_to_cpu(sbi
, vip
->vii_ext4
.ve4_indir
[0]));
69 if (!buf
|| !buffer_mapped(buf
))
72 indir
= (__fs32
*)buf
->b_data
;
73 bno
= fs32_to_cpu(sbi
, indir
[(bn
/ indsize
) % (indsize
* bn
)]) +
79 printk(KERN_WARNING
"no matching indir?");
84 printk("vxfs: indirect extent too big!\n");
90 * vxfs_bmap_indir - recursion for vxfs_bmap_typed
91 * @ip: pointer to the inode we do bmap for
92 * @indir: indirect block we start reading at
93 * @size: size of the typed area to search
94 * @block: partially result from further searches
97 * vxfs_bmap_indir reads a &struct vxfs_typed at @indir
98 * and performs the type-defined action.
101 * The physical block number on success, else Zero.
104 * Kernelstack is rare. Unrecurse?
107 vxfs_bmap_indir(struct inode
*ip
, long indir
, int size
, long block
)
109 struct vxfs_sb_info
*sbi
= VXFS_SBI(ip
->i_sb
);
110 struct buffer_head
*bp
= NULL
;
114 for (i
= 0; i
< size
* VXFS_TYPED_PER_BLOCK(ip
->i_sb
); i
++) {
115 struct vxfs_typed
*typ
;
118 bp
= sb_bread(ip
->i_sb
,
119 indir
+ (i
/ VXFS_TYPED_PER_BLOCK(ip
->i_sb
)));
120 if (!bp
|| !buffer_mapped(bp
))
123 typ
= ((struct vxfs_typed
*)bp
->b_data
) +
124 (i
% VXFS_TYPED_PER_BLOCK(ip
->i_sb
));
125 off
= fs64_to_cpu(sbi
, typ
->vt_hdr
) & VXFS_TYPED_OFFSETMASK
;
132 switch ((u_int32_t
)(fs64_to_cpu(sbi
, typ
->vt_hdr
) >>
133 VXFS_TYPED_TYPESHIFT
)) {
134 case VXFS_TYPED_INDIRECT
:
135 pblock
= vxfs_bmap_indir(ip
,
136 fs32_to_cpu(sbi
, typ
->vt_block
),
137 fs32_to_cpu(sbi
, typ
->vt_size
),
142 case VXFS_TYPED_DATA
:
143 if ((block
- off
) >= fs32_to_cpu(sbi
, typ
->vt_size
))
145 pblock
= fs32_to_cpu(sbi
, typ
->vt_block
) + block
- off
;
147 case VXFS_TYPED_INDIRECT_DEV4
:
148 case VXFS_TYPED_DATA_DEV4
: {
149 struct vxfs_typed_dev4
*typ4
=
150 (struct vxfs_typed_dev4
*)typ
;
152 printk(KERN_INFO
"\n\nTYPED_DEV4 detected!\n");
153 printk(KERN_INFO
"block: %llu\tsize: %lld\tdev: %d\n",
154 fs64_to_cpu(sbi
, typ4
->vd4_block
),
155 fs64_to_cpu(sbi
, typ4
->vd4_size
),
156 fs32_to_cpu(sbi
, typ4
->vd4_dev
));
160 printk(KERN_ERR
"%s:%d vt_hdr %llu\n", __func__
,
161 __LINE__
, fs64_to_cpu(sbi
, typ
->vt_hdr
));
175 * vxfs_bmap_typed - bmap for typed extents
176 * @ip: pointer to the inode we do bmap for
177 * @iblock: logical block
180 * Performs the bmap operation for typed extents.
183 * The physical block number on success, else Zero.
186 vxfs_bmap_typed(struct inode
*ip
, long iblock
)
188 struct vxfs_inode_info
*vip
= VXFS_INO(ip
);
189 struct vxfs_sb_info
*sbi
= VXFS_SBI(ip
->i_sb
);
193 for (i
= 0; i
< VXFS_NTYPED
; i
++) {
194 struct vxfs_typed
*typ
= vip
->vii_org
.typed
+ i
;
195 u64 hdr
= fs64_to_cpu(sbi
, typ
->vt_hdr
);
196 int64_t off
= (hdr
& VXFS_TYPED_OFFSETMASK
);
203 switch ((u32
)(hdr
>> VXFS_TYPED_TYPESHIFT
)) {
204 case VXFS_TYPED_INDIRECT
:
205 pblock
= vxfs_bmap_indir(ip
,
206 fs32_to_cpu(sbi
, typ
->vt_block
),
207 fs32_to_cpu(sbi
, typ
->vt_size
),
212 case VXFS_TYPED_DATA
:
213 if ((iblock
- off
) < fs32_to_cpu(sbi
, typ
->vt_size
))
214 return (fs32_to_cpu(sbi
, typ
->vt_block
) +
217 case VXFS_TYPED_INDIRECT_DEV4
:
218 case VXFS_TYPED_DATA_DEV4
: {
219 struct vxfs_typed_dev4
*typ4
=
220 (struct vxfs_typed_dev4
*)typ
;
222 printk(KERN_INFO
"\n\nTYPED_DEV4 detected!\n");
223 printk(KERN_INFO
"block: %llu\tsize: %lld\tdev: %d\n",
224 fs64_to_cpu(sbi
, typ4
->vd4_block
),
225 fs64_to_cpu(sbi
, typ4
->vd4_size
),
226 fs32_to_cpu(sbi
, typ4
->vd4_dev
));
238 * vxfs_bmap1 - vxfs-internal bmap operation
239 * @ip: pointer to the inode we do bmap for
240 * @iblock: logical block
243 * vxfs_bmap1 perfoms a logical to physical block mapping
244 * for vxfs-internal purposes.
247 * The physical block number on success, else Zero.
250 vxfs_bmap1(struct inode
*ip
, long iblock
)
252 struct vxfs_inode_info
*vip
= VXFS_INO(ip
);
254 if (VXFS_ISEXT4(vip
))
255 return vxfs_bmap_ext4(ip
, iblock
);
256 if (VXFS_ISTYPED(vip
))
257 return vxfs_bmap_typed(ip
, iblock
);
258 if (VXFS_ISNONE(vip
))
260 if (VXFS_ISIMMED(vip
))
263 printk(KERN_WARNING
"vxfs: inode %ld has no valid orgtype (%x)\n",
264 ip
->i_ino
, vip
->vii_orgtype
);
268 printk(KERN_WARNING
"vxfs: inode %ld has an unsupported orgtype (%x)\n",
269 ip
->i_ino
, vip
->vii_orgtype
);