e2fsprogs bmap problem
Quoted 20 lines · --- Theodore Tso
Quoted 2 lines · number9652 wrote:
I am running into a problem with the output of the
function
Quoted 1 line
ext2fs_bmapin the ext2fs library version 1.41.5: whenI send it an
Quoted 1 line
inode structure pointer as the third argument and the
number of a
Quoted 1 line
deleted inode as the second argument, it seems to end
up trying to
Quoted 1 line
read the deleted inode from disk (and results in the
returned value
Quoted 1 line
block number being 0), when I expected it to just get
the values
Quoted 1 line
from the inode structure I send to it. This only
happens if the
Quoted 1 line
inode contains an extent structure within it; when it
has the
Quoted 1 line
indirect block structure it behaves as I expected.
Quoted 8 lines
I suppose we could add a new version of the extent structure which
used a caller-supplied inode structure. This would be mostly safe as
long as you were only doing read-only operations on the buffer head,
and only assuming that all of the extents fit in the inode structure.
I have looked at it a little more closely now, and to me it seems that we could add a new function like ext2fs_extent_open to accept an inode structure, as an alternative to changing the extent structure.
Quoted 5 lines
The short version is it would be possible for us to patch the extents
support code to use a passed-in inode, and then changeext2fs_bmap()
to pass the inode structure to the extents functions, but
Quoted 8 lines
the main
reason why I would do it would be for the optimization, and not to
support (at least officially) the use of an inode structure different
from what is on disk, since that is highly likely to simply not work
correctly.
I didn't consider it, but I agree that the efficiency improvement is a much better reason. I realize there are a lot of pitfalls, some of which you enumerated, for using the inodes in this way. For the particular use I was trying, I had opened the fs read only, and I realize I may get garbage at the end of it, but also that sometimes I will get the file.
Quoted 8 lines
Out of curiosity, where are you getting the data for the inode
structure if it is not on disk? Is this some kind of ext3grep-like
approach where you are grabbing an old version of the inode from the
journal, or some such?
Yes, that is exactly it (see extundelete.sf.net if you are interested). Currently, it has a local copy of ext2fs_block_iterate2 (and most of the rest of block.c and some from extents.c) that was modified to accept an inode to be able to restore files from an ext4 file system; I was hoping it could use bmap to get rid of most of that, but found this during testing.
Quoted 5 lines · On Mon, May 18, 2009 at 07:56:38AM -0700, number9652 wrote:
I have looked at it a little more closely now, and to me it seems that we could add a new function like
ext2fs_extent_opento accept an inode structure, as an alternative to changing the extent structure.
Yes, the right way to do this is to create a new function, ext2fs_extent_open2() which takes a new parameter, struct inode *inode, and then make ext2fs_extent_open() call ext2fs_extent_open2() with the inode parameter set to NULL. In ext2fs_extent_open2(), if struct inode *inode is non-NULL, then we use it instead of reading in the inode. The one tricky bit is that we will need to use ext2fs_read_inode() and ext2fs_write_inode() instead of ext2fs_read_inode_full()/ext2fs_write_inode_full(), but that's OK; the extents code didn't really need to pull in the full inode structure anyway.
- Ted