Skip to contentSkip to conversation

libext2fs: write only core inode in update_path()

PATCH number9652 2 participants 2 messages Jun 17, 2009

lore
Share & tools
lore

number9652

author
#0 lore raw
Quoted 9 lines · Eric Sandeen
Quoted 1 line · Theodore Tso

Probably it would be better/simpler to replace this

with:

Quoted 2 lines

retval =

ext2fs_write_inode(handle->fs, handle->ino,
handle->inode);
- Ted

Quoted 1 line
Quoted 8 lines

Sure, that makes more sense, revised below:

libext2fs: write only core inode in update_path()

The ext2_extent_handle only has a struct ext2_inode allocated on
it, and the same amount copied into it in that same function,

First, sorry for the original bug. I don't think the above is the right way to fix it, however. I am concerned that I may have basically broken write_inode_full on any inode with extents. For example, there is another call to write_inode_full in extent.c that might exhibit this same problem. I think the right fix would be to return to reading the full inode into memory in the extent_open function. See the patch below for what I am talking about.

libext2fs: read the full inode in extent_open2

The inode pointed to in the extent handle structure is expected to have the same size as the on-disk inode so the entire inode can be updated and written to disk, but in extent_open2, only 128 bytes was read into the inode, regardless of the on-disk inode size. Instead, read the entire inode.

Signed-off-by Nic Case

---

e2fsprogs-1.41.6/lib/ext2fs/extent.c renamed from e2fsprogs-1.41.6-orig/lib/ext2fs/extent.c +4 -3
index b7eb617..aebb9bc 100644
@@ -189,6 +189,7 @@ extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
 {
 	struct ext2_extent_handle	*handle;
 	errcode_t			retval;
+	int				isize = EXT2_INODE_SIZE(fs->super);
 	int				i;
 	struct ext3_extent_header	*eh;
 
@@ -203,7 +204,7 @@ extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
 		return retval;
 	memset(handle, 0, sizeof(struct ext2_extent_handle));
 
-	retval = ext2fs_get_mem(sizeof(struct ext2_inode), &handle->inode);
+	retval = ext2fs_get_mem(isize, &handle->inode);
 	if (retval)
 		goto errout;
 
@@ -211,10 +212,10 @@ extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
 	handle->fs = fs;
 
 	if (inode) {
-		memcpy(handle->inode, inode, sizeof(struct ext2_inode));
+		memcpy(handle->inode, inode, isize);
 	}
 	else {
-		retval = ext2fs_read_inode(fs, ino, handle->inode);
+		retval = ext2fs_read_inode_full(fs, ino, handle->inode, isize);
 		if (retval)
 			goto errout;
 	}

---

#1 lore raw
Quoted 14 lines · number9652 wrote:
Quoted 4 lines · Eric Sandeen
Quoted 1 line · Theodore Tso

Probably it would be better/simpler to replace this

with:

Quoted 1 line

retval =

Quoted 8 lines

ext2fs_write_inode(handle->fs, handle->ino, handle->inode); - Ted

Quoted 1 line

Sure, that makes more sense, revised below:

libext2fs: write only core inode in update_path()

The ext2_extent_handle only has a struct ext2_inode allocated on it, and the same amount copied into it in that same function,

Quoted 7 lines

First, sorry for the original bug. I don't think the above is the right way to fix it, however. I am concerned that I may have basically broken write_inode_full on any inode with extents. For example, there is another call to write_inode_full in extent.c that might exhibit this same problem. I think the right fix would be to return to reading the full inode into memory in the extent_open function. See the patch below for what I am talking about.

Hm, well, I wondered about that. IMHO having these 2 inode sizes is a big pain in the butt, and the shuffling back and forth is just asking for bugs.

If this is the case (that it's broken now), then we really need something in the regression suite to catch it - all tests pass in 1.41.6
....

-Eric