Date: Wed, 21 Jul 2010 13:38:18 GMT From: Zheng Liu <lz@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 181260 for review Message-ID: <201007211338.o6LDcIRS050410@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@181260?ac=10 Change 181260 by lz@gnehzuil-freebsd on 2010/07/21 13:38:12 Make ext2fs can support mmap(2) with ext4 extents. * Modify ext2_bmap() function to support ext4 extents. * New ext2fs support the ext4's features as follow: + has_journal + filetype + sparse_super + huge_file + extents * Now ext2fs can read ext4 extents completely in read-only mode. Affected files ... .. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_bmap.c#3 edit .. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extern.h#3 edit .. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_subr.c#4 edit .. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_vnops.c#3 edit Differences ... ==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_bmap.c#3 (text+ko) ==== @@ -46,10 +46,60 @@ #include <sys/stat.h> #include <fs/ext2fs/inode.h> +#include <fs/ext2fs/fs.h> #include <fs/ext2fs/ext2fs.h> #include <fs/ext2fs/ext2_mount.h> #include <fs/ext2fs/ext2_extern.h> +#include <fs/ext2fs/ext2_dinode.h> + +static int ext4_bmapext(struct vnode *, int32_t, int64_t *, int *, int *); + +/* + * This function converts 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_header *ehp; + struct ext4_extent_path path; + daddr_t lbn; + int bsize; + int depth; + + ip = VTOI(vp); + fs = ip->i_e2fs; + lbn = bn; + bsize = blksize(fs, ip, lbn); + + if (runp != NULL) + *runp = 0; + + if (runb != NULL) + *runb = 0; + ext4_ext_find_extent(fs, ip, lbn, &path); + depth = ((struct ext4_extent_header *)(ip->i_db))->eh_depth; + if (path.ep_ext == NULL && depth != 0) + return (EIO); + + ehp = path.ep_header; + ep = path.ep_ext; + if (ep == NULL) + return (EIO); + + *bnp = fsbtodb(fs, (lbn - ep->e_blk + + (ep->e_start_lo | ((daddr_t)(ep->e_start_hi) << 31) << 1))); + + if (*bnp == 0) + *bnp = -1; + + return (0); +} + /* * Bmap converts the logical block number of a file to its physical block * number on the disk. The conversion is done by using the logical block @@ -66,7 +116,7 @@ int *a_runb; } */ *ap; { - int32_t blkno; + int64_t blkno; int error; /* @@ -78,8 +128,12 @@ if (ap->a_bnp == NULL) return (0); - error = ext2_bmaparray(ap->a_vp, ap->a_bn, &blkno, - ap->a_runp, ap->a_runb); + if (VTOI(ap->a_vp)->i_flags & EXT4_EXTENTS) + error = ext4_bmapext(ap->a_vp, ap->a_bn, &blkno, + ap->a_runp, ap->a_runb); + else + error = ext2_bmaparray(ap->a_vp, ap->a_bn, &blkno, + ap->a_runp, ap->a_runb); *ap->a_bnp = blkno; return (error); } @@ -102,7 +156,7 @@ ext2_bmaparray(vp, bn, bnp, runp, runb) struct vnode *vp; int32_t bn; - int32_t *bnp; + int64_t *bnp; int *runp; int *runb; { ==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extern.h#3 (text+ko) ==== @@ -54,7 +54,7 @@ void ext2_blkfree(struct inode *, int32_t, long); int32_t ext2_blkpref(struct inode *, int32_t, int, int32_t *, int32_t); int ext2_bmap(struct vop_bmap_args *); -int ext2_bmaparray(struct vnode *, int32_t, int32_t *, int *, int *); +int ext2_bmaparray(struct vnode *, int32_t, int64_t *, int *, int *); void ext2_dirbad(struct inode *ip, doff_t offset, char *how); void ext2_ei2i(struct ext2fs_dinode *, struct inode *); int ext2_getlbns(struct vnode *, int32_t, struct indir *, int *); ==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_subr.c#4 (text+ko) ==== @@ -73,7 +73,7 @@ struct buf *bp; struct ext4_extent *ep; struct ext4_extent_header *ehp; - struct ext4_extent_path path[20]; + struct ext4_extent_path path; int32_t lbn; int bsize, error; int depth; @@ -85,13 +85,13 @@ bsize = blksize(fs, ip, lbn); *bpp = NULL; - if (ext4_ext_find_extent(fs, ip, lbn, path) == NULL) + if (ext4_ext_find_extent(fs, ip, lbn, &path) == NULL) goto normal; depth = ((struct ext4_extent_header *)(ip->i_db))->eh_depth; - if (path[depth].ep_ext == NULL && depth != 0) + if (path.ep_ext == NULL && depth != 0) goto normal; - ehp = path[depth].ep_header; - ep = path[depth].ep_ext; + ehp = path.ep_header; + ep = path.ep_ext; if (ep == NULL) goto normal; ==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_vnops.c#3 (text+ko) ==== @@ -1419,7 +1419,7 @@ struct vnode *vp = ap->a_vp; struct inode *ip; struct bufobj *bo; - int32_t blkno; + int64_t blkno; int error; ip = VTOI(vp);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007211338.o6LDcIRS050410>