FreeBSD/sys/fs/ext2fs/ext2_bmap.c
/*
 * Convert the logical block number of a file to its physical block number
 * on the disk within ext4 extents.
 */
Convert the logical block number of a file to its physical block number
on the disk within ext4 extents.
Convert the logical block number of a file to its physical block number on the disk within ext4 extents .
static int
ext4_bmapext(struct vnode *vp, int32_t bn, int64_t *bnp, int *runp, int *runb)
{
	struct inode *ip;
	struct m_ext2fs *fs;
	struct ext4_extent *ep;
	struct ext4_extent_path path = { .ep_bp = NULL };
	daddr_t lbn;
	int error;
	ip = VTOI(vp);
	fs = ip->i_e2fs;
	lbn = bn;
	if (runp != NULL)
		*runp = 0;
	if (runb != NULL)
		*runb = 0;
	error = 0;
	ext4_ext_find_extent(fs, ip, lbn, &path);
	if (path.ep_is_sparse) {
		*bnp = -1;
		if (runp != NULL)
			*runp = path.ep_sparse_ext.e_len -
			    (lbn - path.ep_sparse_ext.e_blk) - 1;
		if (runb != NULL)
			*runb = lbn - path.ep_sparse_ext.e_blk;
	} else {
		if (path.ep_ext == NULL) {
			error = EIO;
			goto out;
		}
		ep = path.ep_ext;
		*bnp = fsbtodb(fs, lbn - ep->e_blk +
		    (ep->e_start_lo | (daddr_t)ep->e_start_hi << 32));
		if (*bnp == 0)
			*bnp = -1;
		if (runp != NULL)
			*runp = ep->e_len - (lbn - ep->e_blk) - 1;
		if (runb != NULL)
			*runb = lbn - ep->e_blk;
	}
out:
	if (path.ep_bp != NULL)
		brelse(path.ep_bp);
	return (error);
}
static int ext4_bmapext ( struct vnode * vp , int32_t bn , int64_t * bnp , int * runp , int * runb ) { struct inode * ip ; struct m_ext2fs * fs ; struct ext4_extent * ep ; struct ext4_extent_path path = { . ep_bp = NULL } ; daddr_t lbn ; int error ; ip = VTOI ( vp ) ; fs = ip -> i_e2fs ; lbn = bn ; if ( runp != NULL ) * runp = 0 ; if ( runb != NULL ) * runb = 0 ; error = 0 ; ext4_ext_find_extent ( fs , ip , lbn , & path ) ; if ( path . ep_is_sparse ) { * bnp = -1 ; if ( runp != NULL ) * runp = path . ep_sparse_ext . e_len - ( lbn - path . ep_sparse_ext . e_blk ) - 1 ; if ( runb != NULL ) * runb = lbn - path . ep_sparse_ext . e_blk ; } else { if ( path . ep_ext == NULL ) { error = EIO ; goto out ; } ep = path . ep_ext ; * bnp = fsbtodb ( fs , lbn - ep -> e_blk + ( ep -> e_start_lo | ( daddr_t ) ep -> e_start_hi << 32 ) ) ; if ( * bnp == 0 ) * bnp = -1 ; if ( runp != NULL ) * runp = ep -> e_len - ( lbn - ep -> e_blk ) - 1 ; if ( runb != NULL ) * runb = lbn - ep -> e_blk ; } out : if ( path . ep_bp != NULL ) brelse ( path . ep_bp ) ; return ( error ) ; }
Convert the logical block number of a file to its physical block number
 on the disk within ext4 extents.
Convert the logical block number of a file to its physical block number on the disk within ext4 extents .