diff --git a/Ext4Fsd/ext3/generic.c b/Ext4Fsd/ext3/generic.c index 1ca0d95..a8d7323 100644 --- a/Ext4Fsd/ext3/generic.c +++ b/Ext4Fsd/ext3/generic.c @@ -505,25 +505,31 @@ BOOLEAN Ext2LoadInode (IN PEXT2_VCB Vcb, IN struct inode *Inode) { - struct ext4_inode ext3i = {0}; - struct ext4_inode_info ei = {0}; - LONGLONG offset; + struct ext4_inode* ext4i; + struct ext4_inode_info unused = {0}; + LONGLONG offset; if (!Ext2GetInodeLba(Vcb, Inode->i_ino, &offset)) { DEBUG(DL_ERR, ("Ext2LoadInode: failed inode %u.\n", Inode->i_ino)); return FALSE; } - if (!Ext2LoadBuffer(NULL, Vcb, offset, sizeof(ext3i), &ext3i)) { + ext4i = (struct ext4_inode*) Ext2AllocatePool(NonPagedPool, EXT4_INODE_SIZE(Inode->i_sb), EXT2_INODE_MAGIC); + if (!ext4i) { return FALSE; } - Ext2DecodeInode(Inode, &ext3i); - - if (!ext4_inode_csum_verify(Inode, &ext3i, &ei)) { - //DbgPrint("inod %d checksum invalid\n", Inode->i_ino); + if (!Ext2LoadBuffer(NULL, Vcb, offset, EXT4_INODE_SIZE(Inode->i_sb), ext4i)) { + ExFreePool(ext4i); + return FALSE; } + Ext2DecodeInode(Inode, ext4i); + + ext4_inode_csum_verify(Inode, ext4i, &unused); + + ExFreePool(ext4i); + return TRUE; } @@ -555,42 +561,44 @@ Ext2SaveInode ( IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN struct inode *Inode) { - struct ext4_inode ext4i = {0}; - struct ext4_inode_info ei = {0}; - - LONGLONG Offset = 0; - ULONG InodeSize = sizeof(ext4i); - BOOLEAN rc = 0; + struct ext4_inode* ext4i; + struct ext4_inode_info unused = {0}; + LONGLONG offset; + BOOLEAN rc = 0; DEBUG(DL_INF, ( "Ext2SaveInode: Saving Inode %xh: Mode=%xh Size=%xh\n", Inode->i_ino, Inode->i_mode, Inode->i_size)); - rc = Ext2GetInodeLba(Vcb, Inode->i_ino, &Offset); + rc = Ext2GetInodeLba(Vcb, Inode->i_ino, &offset); if (!rc) { DEBUG(DL_ERR, ( "Ext2SaveInode: failed inode %u.\n", Inode->i_ino)); goto errorout; } - rc = Ext2LoadBuffer(NULL, Vcb, Offset, InodeSize, &ext4i); + ext4i = (struct ext4_inode*) Ext2AllocatePool(NonPagedPool, EXT4_INODE_SIZE(Inode->i_sb), EXT2_INODE_MAGIC); + if (!ext4i) { + rc = FALSE; + goto errorout; + } + + rc = Ext2LoadBuffer(NULL, Vcb, offset, EXT4_INODE_SIZE(Inode->i_sb), ext4i); if (!rc) { DEBUG(DL_ERR, ( "Ext2SaveInode: failed reading inode %u.\n", Inode->i_ino)); - goto errorout;; + ExFreePool(ext4i); + goto errorout; } - Ext2EncodeInode(&ext4i, Inode); + Ext2EncodeInode(ext4i, Inode); - ext4_inode_csum_set(Inode, &ext4i, &ei); + ext4_inode_csum_set(Inode, ext4i, &unused); - if (InodeSize > Vcb->InodeSize) - { - DbgPrint("InodeSize > Vcb->InodeSize\n"); - InodeSize = Vcb->InodeSize; - } - rc = Ext2SaveBuffer(IrpContext, Vcb, Offset, InodeSize, &ext4i); + rc = Ext2SaveBuffer(IrpContext, Vcb, offset, EXT4_INODE_SIZE(Inode->i_sb), ext4i); if (rc && IsFlagOn(Vcb->Flags, VCB_FLOPPY_DISK)) { Ext2StartFloppyFlushDpc(Vcb, NULL, NULL); } + ExFreePool(ext4i); + errorout: return rc; } diff --git a/Ext4Fsd/ext4/ext4_csum.c b/Ext4Fsd/ext4/ext4_csum.c index cb27fb7..326d444 100644 --- a/Ext4Fsd/ext4/ext4_csum.c +++ b/Ext4Fsd/ext4/ext4_csum.c @@ -437,7 +437,7 @@ void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw, if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE && offsetof(struct ext4_inode, i_checksum_hi) + sizeof(raw->i_checksum_hi) <= EXT4_GOOD_OLD_INODE_SIZE + raw->i_extra_isize) raw->i_checksum_hi = cpu_to_le16(csum >> 16); - DbgPrint("set checksum on inode %u: csum == %lx\n", inode->i_ino, csum); + //DbgPrint("set checksum on inode %u: csum == %lx\n", inode->i_ino, csum); ext4_inode_csum_verify(inode, raw, unused); } diff --git a/Ext4Fsd/include/ext2fs.h b/Ext4Fsd/include/ext2fs.h index 69a7e51..9f0bfc5 100644 --- a/Ext4Fsd/include/ext2fs.h +++ b/Ext4Fsd/include/ext2fs.h @@ -280,6 +280,7 @@ Ext2ClearFlag(PULONG Flags, ULONG FlagBit) #define EXT2_DIRSP_MAGIC 'SD2E' #define EXT2_SB_MAGIC 'BS2E' #define EXT2_GD_MAGIC 'DG2E' +#define EXT2_INODE_MAGIC 'EI2E' #define EXT2_FLIST_MAGIC 'LF2E' #define EXT2_PARAM_MAGIC 'PP2E' #define EXT2_RWC_MAGIC 'WR2E' diff --git a/README.md b/README.md index 7a6145f..db9a7b4 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ About and Visual Studio 2019. This is work in progress. If you need a stable driver you should get the latest official release from http://www.ext2fsd.com. If you want to try this branch you should still install the oficial release and then copy this driver over the old in \windows\system32\drivers. - The current status of the development is that metadata checksums is implemented but there is an - calculation error in the inode checksums that must be investigated before I start with jbd2. + The current status of the development is that all metadata checksums is implemented. To make a + filesystem to test this run mkfs.ext4 with the options -O "metadata_csum,^64bit". + This work is dedicated to my mother Berit Ingegerd Branten. Bo Branten.