diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h index 1cfbc35..7008826 100644 --- a/lib/ext2fs/ext2_fs.h +++ b/lib/ext2fs/ext2_fs.h @@ -296,7 +296,8 @@ struct ext2_inode { __u32 i_generation; /* File version (for NFS) */ __u32 i_file_acl; /* File ACL */ __u32 i_dir_acl; /* Directory ACL */ - __u32 i_faddr; /* Fragment address */ + __u32 i_faddr; /* Fragment address */ + __u8 s_uuid[16]; union { struct { __u8 l_i_frag; /* Fragment number */ @@ -354,6 +355,7 @@ struct ext2_inode_large { __u32 i_file_acl; /* File ACL */ __u32 i_dir_acl; /* Directory ACL */ __u32 i_faddr; /* Fragment address */ + __u8 s_uuid[16]; union { struct { __u8 l_i_frag; /* Fragment number */ @@ -547,7 +549,7 @@ #define EXT2_DYNAMIC_REV 1 /* V2 format #define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV #define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV -#define EXT2_GOOD_OLD_INODE_SIZE 128 +#define EXT2_GOOD_OLD_INODE_SIZE (128+(16*8)) /* * Journal inode backup types diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c index 8d528b4..af3b87f 100644 --- a/lib/ext2fs/inode.c +++ b/lib/ext2fs/inode.c @@ -381,6 +381,8 @@ static inline int is_empty_scan(ext2_ino } #endif +errcode_t ext2fs_check_inode_uuid(ext2_filsys fs, struct ext2_inode* inode); + errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, ext2_ino_t *ino, struct ext2_inode *inode, int bufsize) { @@ -452,7 +454,7 @@ #endif scan->inode_size - extra_bytes); scan->ptr += scan->inode_size - extra_bytes; scan->bytes_left -= scan->inode_size - extra_bytes; - + /* CHECK */ #ifdef EXT2FS_ENABLE_SWAPFS if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) || (scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) @@ -463,10 +465,12 @@ #ifdef EXT2FS_ENABLE_SWAPFS else #endif *inode = *((struct ext2_inode *) scan->temp_buffer); + ext2fs_check_inode_uuid(scan->fs,inode); if (scan->scan_flags & EXT2_SF_BAD_EXTRA_BYTES) retval = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE; scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES; } else { + /* CHECK */ #ifdef EXT2FS_ENABLE_SWAPFS if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) || (scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) @@ -477,6 +481,7 @@ #ifdef EXT2FS_ENABLE_SWAPFS else #endif memcpy(inode, scan->ptr, bufsize); + ext2fs_check_inode_uuid(scan->fs,inode); scan->ptr += scan->inode_size; scan->bytes_left -= scan->inode_size; if (scan->scan_flags & EXT2_SF_BAD_INODE_BLK) @@ -496,6 +501,17 @@ errcode_t ext2fs_get_next_inode(ext2_ino sizeof(struct ext2_inode)); } +errcode_t ext2fs_update_inode_uuid(ext2_filsys fs, struct ext2_inode* inode); + +errcode_t ext2fs_check_inode_uuid(ext2_filsys fs, struct ext2_inode* inode) +{ + if(memcmp(inode->s_uuid,fs->super->s_uuid,sizeof(__u8)*16)) { + memset(inode, 0, sizeof(struct ext2_inode)); + ext2fs_update_inode_uuid(fs, inode); + } + return 0; +} + /* * Functions to read and write a single inode. */ @@ -589,6 +605,9 @@ #ifdef EXT2FS_ENABLE_SWAPFS 0, length); #endif + + ext2fs_check_inode_uuid(fs,inode); + /* Update the inode cache */ fs->icache->cache_last = (fs->icache->cache_last + 1) % fs->icache->cache_size; @@ -605,6 +624,18 @@ errcode_t ext2fs_read_inode(ext2_filsys sizeof(struct ext2_inode)); } + +/* + NODE CONNECTIVITY!!! + */ +errcode_t ext2fs_update_inode_uuid(ext2_filsys fs, struct ext2_inode* inode) +{ + + memcpy(inode->s_uuid,fs->super->s_uuid, sizeof(__u8) * 16); + return 0; +} + + errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode * inode, int bufsize) { @@ -615,6 +646,8 @@ errcode_t ext2fs_write_inode_full(ext2_f int clen, i, length; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + ext2fs_update_inode_uuid(fs,inode); /* Check to see if user provided an override function */ if (fs->write_inode) { diff --git a/misc/mke2fs.c b/misc/mke2fs.c index d008e15..e786938 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -398,7 +398,7 @@ static errcode_t zero_blocks(ext2_filsys static void write_inode_tables(ext2_filsys fs) { - errcode_t retval; + errcode_t retval = 0; blk_t blk; dgrp_t i; int num; @@ -423,7 +423,7 @@ static void write_inode_tables(ext2_fils if (!(lazy_flag && (fs->group_desc[i].bg_flags & EXT2_BG_INODE_UNINIT))) { - retval = zero_blocks(fs, blk, num, 0, &blk, &num); + // retval = zero_blocks(fs, blk, num, 0, &blk, &num); if (retval) { fprintf(stderr, _("\nCould not write %d " "blocks in inode table starting at %u: %s\n"),