[ext2resize] [PATCH] More endian-fixes (from fedora patch)
Status: Inactive
Brought to you by:
adilger
From: Petter R. <pe...@hu...> - 2006-06-10 06:11:54
|
I've read through the 01_endianess-fixes-fedora patch from the debian package, and compared it to the current CVS source. These are the changes I believe are left to apply. Can anyone have a look at let me know if it seem correct? The change to ext2_fs.h seem to be mostly irrelevant, just document more of the blocks content. The rest look relevant to this change. Should I commit the changes to the ext2_super_block struct, or just drop that part? I do not have a big-endian machine to test on, so I have no idea if this actually work there or not. Index: src/ext2_fs.h =================================================================== RCS file: /cvsroot/ext2resize/ext2resize/src/ext2_fs.h,v retrieving revision 1.8 diff -u -3 -p -u -r1.8 ext2_fs.h --- src/ext2_fs.h 3 Jul 2002 17:52:24 -0000 1.8 +++ src/ext2_fs.h 10 Jun 2006 06:09:01 -0000 @@ -459,8 +459,16 @@ struct ext2_super_block { __u32 s_journal_inum; /* inode number of journal file */ __u32 s_journal_dev; /* device number of journal file */ __u32 s_last_orphan; /* start of list of inodes to delete */ + __u32 s_hash_seed[4]; /* HTREE hash seed */ + __u8 s_def_hash_version; /* Default hash version to use */ + __u8 s_jnl_backup_type; /* Default type of journal backup */ + __u16 s_reserved_word_pad; + __u32 s_default_mount_opts; + __u32 s_first_meta_bg; /* First metablock group */ + __u32 s_mkfs_time; /* When the filesystem was created */ + __u32 s_jnl_blocks[17]; /* Backup of the journal inode */ - __u32 s_reserved[197]; /* Padding to the end of the block */ + __u32 s_reserved[172]; /* Padding to the end of the block */ }; /* Index: src/ext2.h =================================================================== RCS file: /cvsroot/ext2resize/ext2resize/src/ext2.h,v retrieving revision 1.25 diff -u -3 -p -u -r1.25 ext2.h --- src/ext2.h 9 Jun 2006 21:25:47 -0000 1.25 +++ src/ext2.h 10 Jun 2006 06:09:01 -0000 @@ -238,6 +238,9 @@ struct ext2_fs *ext2_mkfs(struct ext2_de /* resize */ int ext2_resize_fs(struct ext2_fs *fs); +/* fs byte-swap */ +void ext2fs_swab_group_desc(struct ext2_fs *fs, struct ext2_group_desc *gdp); + /* unix I/O */ loff_t ext2_llseek(unsigned int fd, loff_t offset, unsigned int whence); struct ext2_dev_handle *ext2_make_dev_handle_from_file(char *dev, char *dir, Index: src/ext2.c =================================================================== RCS file: /cvsroot/ext2resize/ext2resize/src/ext2.c,v retrieving revision 1.32 diff -u -3 -p -u -r1.32 ext2.c --- src/ext2.c 9 Jun 2006 21:25:47 -0000 1.32 +++ src/ext2.c 10 Jun 2006 06:09:01 -0000 @@ -35,6 +35,9 @@ static const char _ext2_c[] = "$Id: ext2 unsigned char _bitmap[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; +static void ext2_swab_inode(struct ext2_fs *fs, + struct ext2_inode *t, struct ext2_inode *f, + int hostorder); void ext2_print_version(FILE *outfile, char *progname) { @@ -258,6 +261,7 @@ void ext2_read_inode(struct ext2_fs *fs, bh = ext2_bread(fs, blk); memcpy(inode, bh->data + off, sizeof(struct ext2_inode)); ext2_brelse(bh, 0); + ext2_swab_inode(fs, inode, inode, 0); } void ext2_set_inode_state(struct ext2_fs *fs, ino_t ino, int state, @@ -885,17 +889,112 @@ void ext2_swab_super(struct ext2_fs *fs) } } +void ext2fs_swab_group_desc(struct ext2_fs *fs, struct ext2_group_desc *gdp) +{ + if(fs->flags & FL_SWAB_BYTES) { + gdp->bg_block_bitmap = ext2fs_swab32(gdp->bg_block_bitmap); + gdp->bg_inode_bitmap = ext2fs_swab32(gdp->bg_inode_bitmap); + gdp->bg_inode_table = ext2fs_swab32(gdp->bg_inode_table); + gdp->bg_free_blocks_count = ext2fs_swab16(gdp->bg_free_blocks_count); + gdp->bg_free_inodes_count = ext2fs_swab16(gdp->bg_free_inodes_count); + gdp->bg_used_dirs_count = ext2fs_swab16(gdp->bg_used_dirs_count); + } +} void ext2_swab_gds(struct ext2_fs *fs) { if(fs->flags & FL_SWAB_BYTES) { int group; for(group = 0; group < fs->gdblocks; group++) { - fs->gd[group].bg_block_bitmap = ext2fs_swab32(fs->gd[group].bg_block_bitmap); - fs->gd[group].bg_inode_bitmap = ext2fs_swab32(fs->gd[group].bg_inode_bitmap); - fs->gd[group].bg_inode_table = ext2fs_swab32(fs->gd[group].bg_inode_table); - fs->gd[group].bg_free_blocks_count = ext2fs_swab16(fs->gd[group].bg_free_blocks_count); - fs->gd[group].bg_free_inodes_count = ext2fs_swab16(fs->gd[group].bg_free_inodes_count); - fs->gd[group].bg_used_dirs_count = ext2fs_swab16(fs->gd[group].bg_used_dirs_count); + ext2fs_swab_group_desc(fs, &(fs->gd[group])); + } + } +} + +static inline blk_t ext2fs_inode_data_blocks(struct ext2_fs *fs, + struct ext2_inode *inode) +{ + return inode->i_blocks - + (inode->i_file_acl ? fs->blocksize >> 9 : 0); +} + +#define LINUX_S_IFMT 00170000 +#define LINUX_S_IFLNK 00120000 +#define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK) + +static void ext2_swab_inode(struct ext2_fs *fs, + struct ext2_inode *t, struct ext2_inode *f, + int hostorder) +{ + if(fs->flags & FL_SWAB_BYTES) { + unsigned i; + int islnk = 0; + + if (hostorder && LINUX_S_ISLNK(f->i_mode)) + islnk = 1; + t->i_mode = ext2fs_swab16(f->i_mode); + if (!hostorder && LINUX_S_ISLNK(t->i_mode)) + islnk = 1; + t->i_uid = ext2fs_swab16(f->i_uid); + t->i_size = ext2fs_swab32(f->i_size); + t->i_atime = ext2fs_swab32(f->i_atime); + t->i_ctime = ext2fs_swab32(f->i_ctime); + t->i_mtime = ext2fs_swab32(f->i_mtime); + t->i_dtime = ext2fs_swab32(f->i_dtime); + t->i_gid = ext2fs_swab16(f->i_gid); + t->i_links_count = ext2fs_swab16(f->i_links_count); + t->i_blocks = ext2fs_swab32(f->i_blocks); + t->i_flags = ext2fs_swab32(f->i_flags); + t->i_file_acl = ext2fs_swab32(f->i_file_acl); + t->i_dir_acl = ext2fs_swab32(f->i_dir_acl); + if (!islnk || ext2fs_inode_data_blocks(fs, t)) { + for (i = 0; i < EXT2_N_BLOCKS; i++) + t->i_block[i] = ext2fs_swab32(f->i_block[i]); + } else if (t != f) { + for (i = 0; i < EXT2_N_BLOCKS; i++) + t->i_block[i] = f->i_block[i]; + } + t->i_generation = ext2fs_swab32(f->i_generation); + t->i_faddr = ext2fs_swab32(f->i_faddr); + + switch (fs->sb.s_creator_os) { + case EXT2_OS_LINUX: + t->osd1.linux1.l_i_reserved1 = + ext2fs_swab32(f->osd1.linux1.l_i_reserved1); + t->osd2.linux2.l_i_frag = f->osd2.linux2.l_i_frag; + t->osd2.linux2.l_i_fsize = f->osd2.linux2.l_i_fsize; + t->osd2.linux2.i_pad1 = ext2fs_swab16(f->osd2.linux2.i_pad1); + t->osd2.linux2.l_i_uid_high = + ext2fs_swab16 (f->osd2.linux2.l_i_uid_high); + t->osd2.linux2.l_i_gid_high = + ext2fs_swab16 (f->osd2.linux2.l_i_gid_high); + t->osd2.linux2.l_i_reserved2 = + ext2fs_swab32(f->osd2.linux2.l_i_reserved2); + break; + case EXT2_OS_HURD: + t->osd1.hurd1.h_i_translator = + ext2fs_swab32 (f->osd1.hurd1.h_i_translator); + t->osd2.hurd2.h_i_frag = f->osd2.hurd2.h_i_frag; + t->osd2.hurd2.h_i_fsize = f->osd2.hurd2.h_i_fsize; + t->osd2.hurd2.h_i_mode_high = + ext2fs_swab16 (f->osd2.hurd2.h_i_mode_high); + t->osd2.hurd2.h_i_uid_high = + ext2fs_swab16 (f->osd2.hurd2.h_i_uid_high); + t->osd2.hurd2.h_i_gid_high = + ext2fs_swab16 (f->osd2.hurd2.h_i_gid_high); + t->osd2.hurd2.h_i_author = + ext2fs_swab32 (f->osd2.hurd2.h_i_author); + break; + case EXT2_OS_MASIX: + t->osd1.masix1.m_i_reserved1 = + ext2fs_swab32(f->osd1.masix1.m_i_reserved1); + t->osd2.masix2.m_i_frag = f->osd2.masix2.m_i_frag; + t->osd2.masix2.m_i_fsize = f->osd2.masix2.m_i_fsize; + t->osd2.masix2.m_pad1 = ext2fs_swab16(f->osd2.masix2.m_pad1); + t->osd2.masix2.m_i_reserved2[0] = + ext2fs_swab32(f->osd2.masix2.m_i_reserved2[0]); + t->osd2.masix2.m_i_reserved2[1] = + ext2fs_swab32(f->osd2.masix2.m_i_reserved2[1]); + break; } } } Index: src/ext2online.c =================================================================== RCS file: /cvsroot/ext2resize/ext2resize/src/ext2online.c,v retrieving revision 1.24 diff -u -3 -p -u -r1.24 ext2online.c --- src/ext2online.c 30 Sep 2004 14:12:01 -0000 1.24 +++ src/ext2online.c 10 Jun 2006 06:09:01 -0000 @@ -238,10 +238,12 @@ static int ext2_check_one_rsv(struct ext unsigned int three = 1, five = 5, seven = 7; unsigned int group; int last = 0; - - if (dindir_buf[gdb_num % apb] != pri_blk) { + blk_t dblk; + + dblk = le32_to_cpu(dindir_buf[gdb_num % apb]); + if (dblk != pri_blk) { fprintf(stderr, "found %d not %d at %d[%d]\n", - dindir_buf[gdb_num % apb], pri_blk, + dblk, pri_blk, fs->resize.i_block[EXT2_DIND_BLOCK], gdb_num % apb); ret = 0; @@ -253,16 +255,17 @@ static int ext2_check_one_rsv(struct ext while ((group = ext2_list_backups(fs, &three, &five, &seven)) < fs->numgroups) { __u32 *pri_buf = (__u32 *)(pri_bh->data); - blk_t bku_blk; + blk_t bku_blk, pblk; bku_blk = pri_blk + group * fs->sb.s_blocks_per_group; if (fs->flags & FL_DEBUG) printf("checking for group block %d in Bond\n", bku_blk); - if (pri_buf[last] != bku_blk) { + pblk = le32_to_cpu(pri_buf[last]); + if (pblk != bku_blk) { fprintf(stderr, "found %d not %d at %d[%d]\n", - pri_buf[last], bku_blk, pri_blk, last); + pblk, bku_blk, pri_blk, last); ext2_brelse(pri_bh, 0); ret = 0; goto exit_dind; @@ -340,6 +343,7 @@ static blk_t ext2_make_group(struct ext2 } gdp = (struct ext2_group_desc *)bh->data + (group % (fs->blocksize/sizeof(struct ext2_group_desc))); + ext2fs_swab_group_desc(fs, gdp); gdp->bg_block_bitmap = start + new_bb; gdp->bg_inode_bitmap = start + new_ib; |