PERFORCE change 180985 for review
Zheng Liu
lz at FreeBSD.org
Thu Jul 15 10:32:58 UTC 2010
http://p4web.freebsd.org/@@180985?ac=10
Change 180985 by lz at 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);
}
More information about the p4-projects
mailing list