From owner-p4-projects@FreeBSD.ORG Wed Jul 21 13:38:19 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8FD841065771; Wed, 21 Jul 2010 13:38:19 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ABAF81065673 for ; Wed, 21 Jul 2010 13:38:18 +0000 (UTC) (envelope-from lz@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 98CDE8FC14 for ; Wed, 21 Jul 2010 13:38:18 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o6LDcIXA050412 for ; Wed, 21 Jul 2010 13:38:18 GMT (envelope-from lz@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o6LDcIRS050410 for perforce@freebsd.org; Wed, 21 Jul 2010 13:38:18 GMT (envelope-from lz@FreeBSD.org) Date: Wed, 21 Jul 2010 13:38:18 GMT Message-Id: <201007211338.o6LDcIRS050410@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to lz@FreeBSD.org using -f From: Zheng Liu To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 181260 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jul 2010 13:38:19 -0000 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 #include +#include #include #include #include +#include + +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);