From owner-p4-projects@FreeBSD.ORG Thu Jul 15 10:32:58 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 175381065675; Thu, 15 Jul 2010 10:32:58 +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 D00FA1065670 for ; Thu, 15 Jul 2010 10:32:57 +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 BD0028FC0A for ; Thu, 15 Jul 2010 10:32:57 +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 o6FAWvjK019036 for ; Thu, 15 Jul 2010 10:32:57 GMT (envelope-from lz@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o6FAWv7r019034 for perforce@freebsd.org; Thu, 15 Jul 2010 10:32:57 GMT (envelope-from lz@FreeBSD.org) Date: Thu, 15 Jul 2010 10:32:57 GMT Message-Id: <201007151032.o6FAWv7r019034@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 180985 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: Thu, 15 Jul 2010 10:32:58 -0000 http://p4web.freebsd.org/@@180985?ac=10 Change 180985 by lz@gnehzuil-freebsd on 2010/07/15 10:32:11 ext2fs can read ext4 extents in read-only mode. * it doesn't implement a ext4 cache. * it has a bug. mmap(2) doesn't work well. Affected files ... .. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extents.c#6 edit .. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_readwrite.c#7 edit Differences ... ==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extents.c#6 (text+ko) ==== @@ -53,8 +53,9 @@ struct ext4_extent_index *l, *r, *m; l = (struct ext4_extent_index *)(((char *)(ehp) + - sizeof(struct ext4_extent_header))) + 1; - r = l + ehp->eh_ecount; + sizeof(struct ext4_extent_header))); + r = (struct ext4_extent_index *)(((char *)(ehp) + + sizeof(struct ext4_extent_header))) + ehp->eh_ecount - 1; while (l <= r) { m = l + (r - l) / 2; if (lbn < m->ei_blk) @@ -76,7 +77,7 @@ return; l = (struct ext4_extent *)(((char *)(ehp) + - sizeof(struct ext4_extent_header))) + 1; + sizeof(struct ext4_extent_header))); r = (struct ext4_extent *)(((char *)(ehp) + sizeof(struct ext4_extent_header))) + ehp->eh_ecount - 1; while (l <= r) { @@ -126,7 +127,8 @@ struct vnode *vp; struct ext4_extent_header *ehp; struct buf *bp = NULL; - int depth, i, error, size, pos = 0; + int depth, i, error, size; + daddr_t nblk; vp = ITOV(ip); ehp = (struct ext4_extent_header *)((char *)ip->i_db); @@ -135,45 +137,42 @@ if (ehp->eh_magic != EXT4_EXT_MAGIC) return (NULL); - if (path == NULL) { - path = malloc(sizeof(struct ext4_extent_path) * (depth * 2), - M_EXT2NODE, M_WAITOK | M_ZERO); + path->ep_header = ehp; - if (path == NULL) - return NULL; - } - - path[0].ep_header = ehp; - i = depth; while (i) { - ext4_ext_binsearch_index(ip, path + pos, lbn); - path[pos].ep_blk = (((daddr_t)(path[pos].ep_index->ei_leaf_hi) << 31) << 1) | - path[pos].ep_index->ei_leaf_lo; - path[pos].ep_depth = i; - path[pos].ep_ext = NULL; + ext4_ext_binsearch_index(ip, path, lbn); + path->ep_blk = (((daddr_t)(path->ep_index->ei_leaf_hi) << 31) << 1) | + path->ep_index->ei_leaf_lo; + path->ep_depth = i; + path->ep_ext = NULL; - size = blksize(fs, ip, path[pos].ep_blk); - error = bread(vp, path[pos].ep_blk, size, NOCRED, &bp); + size = blksize(fs, ip, path->ep_blk); + nblk = path->ep_blk; + if (bp != NULL) + brelse(bp); + error = bread(ip->i_devvp, fsbtodb(fs, nblk), size, NOCRED, &bp); if (error) { brelse(bp); bp = NULL; return NULL; } ehp = (struct ext4_extent_header *)bp->b_data; - pos++; - path[pos].ep_header = ehp; + path->ep_header = ehp; i--; } - path[pos].ep_depth = i; - path[pos].ep_ext = NULL; - path[pos].ep_index = NULL; + path->ep_depth = i; + path->ep_ext = NULL; + path->ep_index = NULL; + + ext4_ext_binsearch(ip, path, lbn); + if (path->ep_ext != NULL) + path->ep_blk = (((daddr_t)(path->ep_ext->e_start_hi) << 31) << 1) | + path->ep_ext->e_start_lo; - ext4_ext_binsearch(ip, path + pos, lbn); - if (path[pos].ep_ext != NULL) - path[pos].ep_blk = (((daddr_t)(path[pos].ep_ext->e_start_hi) << 31) << 1) | - path[pos].ep_ext->e_start_lo; + if (bp != NULL) + brelse(bp); return path; } ==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_readwrite.c#7 (text+ko) ==== @@ -64,15 +64,14 @@ struct buf *bp; struct ext4_extent nex, *ep; struct ext4_extent_header *ehp; - /*struct ext4_extent_path *path = NULL;*/ - struct ext4_extent_path path[20]; + struct ext4_extent_path path; daddr_t lbn, nextlbn, newblk = 0; off_t bytesinfile; u_short mode; int cache_type; int orig_resid; int error = 0; - int depth; + int depth = 0; long size, xfersize, blkoffset; vp = ap->a_vp; @@ -113,23 +112,13 @@ newblk = lbn - nex.e_blk + (nex.e_start_lo | ((daddr_t)(nex.e_start_hi) << 31) << 1); } else { - /*path = ext4_ext_find_extent(fs, ip, lbn, NULL);*/ - ext4_ext_find_extent(fs, ip, lbn, path); -#if 0 - if (path == NULL) { - path = NULL; - return (error); - } -#endif - + ext4_ext_find_extent(fs, ip, lbn, &path); 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) return (EIO); - ehp = path[depth].ep_header; - ep = path[depth].ep_ext; - + ehp = path.ep_header; + ep = path.ep_ext; if (ep == NULL) return (EIO); @@ -161,11 +150,6 @@ if (bp != NULL) bqrelse(bp); -#if 0 - if (path != NULL) - free(path, M_EXT2NODE); -#endif - return (error); }