From 5c4f8d674845095050f94ea95f3c73072cbe34b5 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 7 Jun 2008 13:13:16 -0400 Subject: [PATCH] resize2fs: Add support to use the ext4 online resize ioctl's First try the ext3 ioctl, but if we get an error, try using the ext4 ioctl. Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/ext2_fs.h | 11 +++++++++++ resize/online.c | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h index bba5be8..554c708 100644 --- a/lib/ext2fs/ext2_fs.h +++ b/lib/ext2fs/ext2_fs.h @@ -293,6 +293,16 @@ struct ext2_new_group_input { __u16 unused; /* Number of reserved GDT blocks in group */ }; +struct ext4_new_group_input { + __u32 group; /* Group number for this data */ + __u64 block_bitmap; /* Absolute block number of block bitmap */ + __u64 inode_bitmap; /* Absolute block number of inode bitmap */ + __u64 inode_table; /* Absolute block number of inode table start */ + __u32 blocks_count; /* Total number of blocks in this group */ + __u16 reserved_blocks; /* Number of reserved blocks in this group */ + __u16 unused; +}; + #ifdef __GNU__ /* Needed for the Hurd */ #define _IOT_ext2_new_group_input _IOT (_IOTS(__u32), 5, _IOTS(__u16), 2, 0, 0) #endif @@ -305,6 +315,7 @@ struct ext2_new_group_input { #define EXT2_IOC_SETVERSION_NEW _IOW('f', 4, long) #define EXT2_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) #define EXT2_IOC_GROUP_ADD _IOW('f', 8,struct ext2_new_group_input) +#define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input) /* * Structure of an inode on the disk diff --git a/resize/online.c b/resize/online.c index fc1f7a2..d7dc857 100644 --- a/resize/online.c +++ b/resize/online.c @@ -23,6 +23,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, { #ifdef __linux__ struct ext2_new_group_input input; + struct ext4_new_group_input input64; struct ext2_super_block *sb = fs->super; unsigned long new_desc_blocks; ext2_filsys new_fs; @@ -30,6 +31,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, dgrp_t i; blk_t size; int fd, r_frac, overhead; + int use_old_ioctl = 1; printf(_("Filesystem at %s is mounted on %s; " "on-line resizing required\n"), fs->device_name, mtpt); @@ -147,7 +149,21 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, printf("Adding group #%d\n", input.group); #endif - if (ioctl(fd, EXT2_IOC_GROUP_ADD, &input) < 0) { + if (use_old_ioctl && + ioctl(fd, EXT2_IOC_GROUP_ADD, &input) == 0) + continue; + else + use_old_ioctl = 1; + + input64.group = input.group; + input64.block_bitmap = input.block_bitmap; + input64.inode_bitmap = input.inode_bitmap; + input64.inode_table = input.inode_table; + input64.blocks_count = input.blocks_count; + input64.reserved_blocks = input.reserved_blocks; + input64.unused = input.unused; + + if (ioctl(fd, EXT4_IOC_GROUP_ADD, &input64) < 0) { com_err(program_name, errno, _("While trying to add group #%d"), input.group); -- 1.8.3.1