aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/resize.c
diff options
context:
space:
mode:
authorMingming Cao <cmm@us.ibm.com>2006-10-11 04:20:53 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-11 14:14:15 -0400
commit617ba13b31fbf505cc21799826639ef24ed94af0 (patch)
tree2a41e8c993f7c1eed115ad24047d546ba56cbdf5 /fs/ext4/resize.c
parentac27a0ec112a089f1a5102bc8dffc79c8c815571 (diff)
[PATCH] ext4: rename ext4 symbols to avoid duplication of ext3 symbols
Mingming Cao originally did this work, and Shaggy reproduced it using some scripts from her. Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: Dave Kleikamp <shaggy@austin.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/ext4/resize.c')
-rw-r--r--fs/ext4/resize.c412
1 files changed, 206 insertions, 206 deletions
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index b73cba12f79c..4a47895d9d6d 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/fs/ext3/resize.c 2 * linux/fs/ext4/resize.c
3 * 3 *
4 * Support for resizing an ext3 filesystem while it is mounted. 4 * Support for resizing an ext4 filesystem while it is mounted.
5 * 5 *
6 * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com> 6 * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com>
7 * 7 *
@@ -9,11 +9,11 @@
9 */ 9 */
10 10
11 11
12#define EXT3FS_DEBUG 12#define EXT4FS_DEBUG
13 13
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/smp_lock.h> 15#include <linux/smp_lock.h>
16#include <linux/ext3_jbd.h> 16#include <linux/ext4_jbd.h>
17 17
18#include <linux/errno.h> 18#include <linux/errno.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
@@ -23,87 +23,87 @@
23#define inside(b, first, last) ((b) >= (first) && (b) < (last)) 23#define inside(b, first, last) ((b) >= (first) && (b) < (last))
24 24
25static int verify_group_input(struct super_block *sb, 25static int verify_group_input(struct super_block *sb,
26 struct ext3_new_group_data *input) 26 struct ext4_new_group_data *input)
27{ 27{
28 struct ext3_sb_info *sbi = EXT3_SB(sb); 28 struct ext4_sb_info *sbi = EXT4_SB(sb);
29 struct ext3_super_block *es = sbi->s_es; 29 struct ext4_super_block *es = sbi->s_es;
30 ext3_fsblk_t start = le32_to_cpu(es->s_blocks_count); 30 ext4_fsblk_t start = le32_to_cpu(es->s_blocks_count);
31 ext3_fsblk_t end = start + input->blocks_count; 31 ext4_fsblk_t end = start + input->blocks_count;
32 unsigned group = input->group; 32 unsigned group = input->group;
33 ext3_fsblk_t itend = input->inode_table + sbi->s_itb_per_group; 33 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
34 unsigned overhead = ext3_bg_has_super(sb, group) ? 34 unsigned overhead = ext4_bg_has_super(sb, group) ?
35 (1 + ext3_bg_num_gdb(sb, group) + 35 (1 + ext4_bg_num_gdb(sb, group) +
36 le16_to_cpu(es->s_reserved_gdt_blocks)) : 0; 36 le16_to_cpu(es->s_reserved_gdt_blocks)) : 0;
37 ext3_fsblk_t metaend = start + overhead; 37 ext4_fsblk_t metaend = start + overhead;
38 struct buffer_head *bh = NULL; 38 struct buffer_head *bh = NULL;
39 ext3_grpblk_t free_blocks_count; 39 ext4_grpblk_t free_blocks_count;
40 int err = -EINVAL; 40 int err = -EINVAL;
41 41
42 input->free_blocks_count = free_blocks_count = 42 input->free_blocks_count = free_blocks_count =
43 input->blocks_count - 2 - overhead - sbi->s_itb_per_group; 43 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
44 44
45 if (test_opt(sb, DEBUG)) 45 if (test_opt(sb, DEBUG))
46 printk(KERN_DEBUG "EXT3-fs: adding %s group %u: %u blocks " 46 printk(KERN_DEBUG "EXT4-fs: adding %s group %u: %u blocks "
47 "(%d free, %u reserved)\n", 47 "(%d free, %u reserved)\n",
48 ext3_bg_has_super(sb, input->group) ? "normal" : 48 ext4_bg_has_super(sb, input->group) ? "normal" :
49 "no-super", input->group, input->blocks_count, 49 "no-super", input->group, input->blocks_count,
50 free_blocks_count, input->reserved_blocks); 50 free_blocks_count, input->reserved_blocks);
51 51
52 if (group != sbi->s_groups_count) 52 if (group != sbi->s_groups_count)
53 ext3_warning(sb, __FUNCTION__, 53 ext4_warning(sb, __FUNCTION__,
54 "Cannot add at group %u (only %lu groups)", 54 "Cannot add at group %u (only %lu groups)",
55 input->group, sbi->s_groups_count); 55 input->group, sbi->s_groups_count);
56 else if ((start - le32_to_cpu(es->s_first_data_block)) % 56 else if ((start - le32_to_cpu(es->s_first_data_block)) %
57 EXT3_BLOCKS_PER_GROUP(sb)) 57 EXT4_BLOCKS_PER_GROUP(sb))
58 ext3_warning(sb, __FUNCTION__, "Last group not full"); 58 ext4_warning(sb, __FUNCTION__, "Last group not full");
59 else if (input->reserved_blocks > input->blocks_count / 5) 59 else if (input->reserved_blocks > input->blocks_count / 5)
60 ext3_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)", 60 ext4_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)",
61 input->reserved_blocks); 61 input->reserved_blocks);
62 else if (free_blocks_count < 0) 62 else if (free_blocks_count < 0)
63 ext3_warning(sb, __FUNCTION__, "Bad blocks count %u", 63 ext4_warning(sb, __FUNCTION__, "Bad blocks count %u",
64 input->blocks_count); 64 input->blocks_count);
65 else if (!(bh = sb_bread(sb, end - 1))) 65 else if (!(bh = sb_bread(sb, end - 1)))
66 ext3_warning(sb, __FUNCTION__, 66 ext4_warning(sb, __FUNCTION__,
67 "Cannot read last block ("E3FSBLK")", 67 "Cannot read last block ("E3FSBLK")",
68 end - 1); 68 end - 1);
69 else if (outside(input->block_bitmap, start, end)) 69 else if (outside(input->block_bitmap, start, end))
70 ext3_warning(sb, __FUNCTION__, 70 ext4_warning(sb, __FUNCTION__,
71 "Block bitmap not in group (block %u)", 71 "Block bitmap not in group (block %u)",
72 input->block_bitmap); 72 input->block_bitmap);
73 else if (outside(input->inode_bitmap, start, end)) 73 else if (outside(input->inode_bitmap, start, end))
74 ext3_warning(sb, __FUNCTION__, 74 ext4_warning(sb, __FUNCTION__,
75 "Inode bitmap not in group (block %u)", 75 "Inode bitmap not in group (block %u)",
76 input->inode_bitmap); 76 input->inode_bitmap);
77 else if (outside(input->inode_table, start, end) || 77 else if (outside(input->inode_table, start, end) ||
78 outside(itend - 1, start, end)) 78 outside(itend - 1, start, end))
79 ext3_warning(sb, __FUNCTION__, 79 ext4_warning(sb, __FUNCTION__,
80 "Inode table not in group (blocks %u-"E3FSBLK")", 80 "Inode table not in group (blocks %u-"E3FSBLK")",
81 input->inode_table, itend - 1); 81 input->inode_table, itend - 1);
82 else if (input->inode_bitmap == input->block_bitmap) 82 else if (input->inode_bitmap == input->block_bitmap)
83 ext3_warning(sb, __FUNCTION__, 83 ext4_warning(sb, __FUNCTION__,
84 "Block bitmap same as inode bitmap (%u)", 84 "Block bitmap same as inode bitmap (%u)",
85 input->block_bitmap); 85 input->block_bitmap);
86 else if (inside(input->block_bitmap, input->inode_table, itend)) 86 else if (inside(input->block_bitmap, input->inode_table, itend))
87 ext3_warning(sb, __FUNCTION__, 87 ext4_warning(sb, __FUNCTION__,
88 "Block bitmap (%u) in inode table (%u-"E3FSBLK")", 88 "Block bitmap (%u) in inode table (%u-"E3FSBLK")",
89 input->block_bitmap, input->inode_table, itend-1); 89 input->block_bitmap, input->inode_table, itend-1);
90 else if (inside(input->inode_bitmap, input->inode_table, itend)) 90 else if (inside(input->inode_bitmap, input->inode_table, itend))
91 ext3_warning(sb, __FUNCTION__, 91 ext4_warning(sb, __FUNCTION__,
92 "Inode bitmap (%u) in inode table (%u-"E3FSBLK")", 92 "Inode bitmap (%u) in inode table (%u-"E3FSBLK")",
93 input->inode_bitmap, input->inode_table, itend-1); 93 input->inode_bitmap, input->inode_table, itend-1);
94 else if (inside(input->block_bitmap, start, metaend)) 94 else if (inside(input->block_bitmap, start, metaend))
95 ext3_warning(sb, __FUNCTION__, 95 ext4_warning(sb, __FUNCTION__,
96 "Block bitmap (%u) in GDT table" 96 "Block bitmap (%u) in GDT table"
97 " ("E3FSBLK"-"E3FSBLK")", 97 " ("E3FSBLK"-"E3FSBLK")",
98 input->block_bitmap, start, metaend - 1); 98 input->block_bitmap, start, metaend - 1);
99 else if (inside(input->inode_bitmap, start, metaend)) 99 else if (inside(input->inode_bitmap, start, metaend))
100 ext3_warning(sb, __FUNCTION__, 100 ext4_warning(sb, __FUNCTION__,
101 "Inode bitmap (%u) in GDT table" 101 "Inode bitmap (%u) in GDT table"
102 " ("E3FSBLK"-"E3FSBLK")", 102 " ("E3FSBLK"-"E3FSBLK")",
103 input->inode_bitmap, start, metaend - 1); 103 input->inode_bitmap, start, metaend - 1);
104 else if (inside(input->inode_table, start, metaend) || 104 else if (inside(input->inode_table, start, metaend) ||
105 inside(itend - 1, start, metaend)) 105 inside(itend - 1, start, metaend))
106 ext3_warning(sb, __FUNCTION__, 106 ext4_warning(sb, __FUNCTION__,
107 "Inode table (%u-"E3FSBLK") overlaps" 107 "Inode table (%u-"E3FSBLK") overlaps"
108 "GDT table ("E3FSBLK"-"E3FSBLK")", 108 "GDT table ("E3FSBLK"-"E3FSBLK")",
109 input->inode_table, itend - 1, start, metaend - 1); 109 input->inode_table, itend - 1, start, metaend - 1);
@@ -115,7 +115,7 @@ static int verify_group_input(struct super_block *sb,
115} 115}
116 116
117static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, 117static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
118 ext3_fsblk_t blk) 118 ext4_fsblk_t blk)
119{ 119{
120 struct buffer_head *bh; 120 struct buffer_head *bh;
121 int err; 121 int err;
@@ -123,7 +123,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
123 bh = sb_getblk(sb, blk); 123 bh = sb_getblk(sb, blk);
124 if (!bh) 124 if (!bh)
125 return ERR_PTR(-EIO); 125 return ERR_PTR(-EIO);
126 if ((err = ext3_journal_get_write_access(handle, bh))) { 126 if ((err = ext4_journal_get_write_access(handle, bh))) {
127 brelse(bh); 127 brelse(bh);
128 bh = ERR_PTR(err); 128 bh = ERR_PTR(err);
129 } else { 129 } else {
@@ -148,9 +148,9 @@ static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
148 if (start_bit >= end_bit) 148 if (start_bit >= end_bit)
149 return; 149 return;
150 150
151 ext3_debug("mark end bits +%d through +%d used\n", start_bit, end_bit); 151 ext4_debug("mark end bits +%d through +%d used\n", start_bit, end_bit);
152 for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++) 152 for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++)
153 ext3_set_bit(i, bitmap); 153 ext4_set_bit(i, bitmap);
154 if (i < end_bit) 154 if (i < end_bit)
155 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3); 155 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
156} 156}
@@ -163,21 +163,21 @@ static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
163 * If any part of this fails, we simply abort the resize. 163 * If any part of this fails, we simply abort the resize.
164 */ 164 */
165static int setup_new_group_blocks(struct super_block *sb, 165static int setup_new_group_blocks(struct super_block *sb,
166 struct ext3_new_group_data *input) 166 struct ext4_new_group_data *input)
167{ 167{
168 struct ext3_sb_info *sbi = EXT3_SB(sb); 168 struct ext4_sb_info *sbi = EXT4_SB(sb);
169 ext3_fsblk_t start = ext3_group_first_block_no(sb, input->group); 169 ext4_fsblk_t start = ext4_group_first_block_no(sb, input->group);
170 int reserved_gdb = ext3_bg_has_super(sb, input->group) ? 170 int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
171 le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0; 171 le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0;
172 unsigned long gdblocks = ext3_bg_num_gdb(sb, input->group); 172 unsigned long gdblocks = ext4_bg_num_gdb(sb, input->group);
173 struct buffer_head *bh; 173 struct buffer_head *bh;
174 handle_t *handle; 174 handle_t *handle;
175 ext3_fsblk_t block; 175 ext4_fsblk_t block;
176 ext3_grpblk_t bit; 176 ext4_grpblk_t bit;
177 int i; 177 int i;
178 int err = 0, err2; 178 int err = 0, err2;
179 179
180 handle = ext3_journal_start_sb(sb, reserved_gdb + gdblocks + 180 handle = ext4_journal_start_sb(sb, reserved_gdb + gdblocks +
181 2 + sbi->s_itb_per_group); 181 2 + sbi->s_itb_per_group);
182 if (IS_ERR(handle)) 182 if (IS_ERR(handle))
183 return PTR_ERR(handle); 183 return PTR_ERR(handle);
@@ -193,9 +193,9 @@ static int setup_new_group_blocks(struct super_block *sb,
193 goto exit_journal; 193 goto exit_journal;
194 } 194 }
195 195
196 if (ext3_bg_has_super(sb, input->group)) { 196 if (ext4_bg_has_super(sb, input->group)) {
197 ext3_debug("mark backup superblock %#04lx (+0)\n", start); 197 ext4_debug("mark backup superblock %#04lx (+0)\n", start);
198 ext3_set_bit(0, bh->b_data); 198 ext4_set_bit(0, bh->b_data);
199 } 199 }
200 200
201 /* Copy all of the GDT blocks into the backup in this group */ 201 /* Copy all of the GDT blocks into the backup in this group */
@@ -203,14 +203,14 @@ static int setup_new_group_blocks(struct super_block *sb,
203 i < gdblocks; i++, block++, bit++) { 203 i < gdblocks; i++, block++, bit++) {
204 struct buffer_head *gdb; 204 struct buffer_head *gdb;
205 205
206 ext3_debug("update backup group %#04lx (+%d)\n", block, bit); 206 ext4_debug("update backup group %#04lx (+%d)\n", block, bit);
207 207
208 gdb = sb_getblk(sb, block); 208 gdb = sb_getblk(sb, block);
209 if (!gdb) { 209 if (!gdb) {
210 err = -EIO; 210 err = -EIO;
211 goto exit_bh; 211 goto exit_bh;
212 } 212 }
213 if ((err = ext3_journal_get_write_access(handle, gdb))) { 213 if ((err = ext4_journal_get_write_access(handle, gdb))) {
214 brelse(gdb); 214 brelse(gdb);
215 goto exit_bh; 215 goto exit_bh;
216 } 216 }
@@ -218,8 +218,8 @@ static int setup_new_group_blocks(struct super_block *sb,
218 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, bh->b_size); 218 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, bh->b_size);
219 set_buffer_uptodate(gdb); 219 set_buffer_uptodate(gdb);
220 unlock_buffer(bh); 220 unlock_buffer(bh);
221 ext3_journal_dirty_metadata(handle, gdb); 221 ext4_journal_dirty_metadata(handle, gdb);
222 ext3_set_bit(bit, bh->b_data); 222 ext4_set_bit(bit, bh->b_data);
223 brelse(gdb); 223 brelse(gdb);
224 } 224 }
225 225
@@ -228,59 +228,59 @@ static int setup_new_group_blocks(struct super_block *sb,
228 i < reserved_gdb; i++, block++, bit++) { 228 i < reserved_gdb; i++, block++, bit++) {
229 struct buffer_head *gdb; 229 struct buffer_head *gdb;
230 230
231 ext3_debug("clear reserved block %#04lx (+%d)\n", block, bit); 231 ext4_debug("clear reserved block %#04lx (+%d)\n", block, bit);
232 232
233 if (IS_ERR(gdb = bclean(handle, sb, block))) { 233 if (IS_ERR(gdb = bclean(handle, sb, block))) {
234 err = PTR_ERR(bh); 234 err = PTR_ERR(bh);
235 goto exit_bh; 235 goto exit_bh;
236 } 236 }
237 ext3_journal_dirty_metadata(handle, gdb); 237 ext4_journal_dirty_metadata(handle, gdb);
238 ext3_set_bit(bit, bh->b_data); 238 ext4_set_bit(bit, bh->b_data);
239 brelse(gdb); 239 brelse(gdb);
240 } 240 }
241 ext3_debug("mark block bitmap %#04x (+%ld)\n", input->block_bitmap, 241 ext4_debug("mark block bitmap %#04x (+%ld)\n", input->block_bitmap,
242 input->block_bitmap - start); 242 input->block_bitmap - start);
243 ext3_set_bit(input->block_bitmap - start, bh->b_data); 243 ext4_set_bit(input->block_bitmap - start, bh->b_data);
244 ext3_debug("mark inode bitmap %#04x (+%ld)\n", input->inode_bitmap, 244 ext4_debug("mark inode bitmap %#04x (+%ld)\n", input->inode_bitmap,
245 input->inode_bitmap - start); 245 input->inode_bitmap - start);
246 ext3_set_bit(input->inode_bitmap - start, bh->b_data); 246 ext4_set_bit(input->inode_bitmap - start, bh->b_data);
247 247
248 /* Zero out all of the inode table blocks */ 248 /* Zero out all of the inode table blocks */
249 for (i = 0, block = input->inode_table, bit = block - start; 249 for (i = 0, block = input->inode_table, bit = block - start;
250 i < sbi->s_itb_per_group; i++, bit++, block++) { 250 i < sbi->s_itb_per_group; i++, bit++, block++) {
251 struct buffer_head *it; 251 struct buffer_head *it;
252 252
253 ext3_debug("clear inode block %#04lx (+%d)\n", block, bit); 253 ext4_debug("clear inode block %#04lx (+%d)\n", block, bit);
254 if (IS_ERR(it = bclean(handle, sb, block))) { 254 if (IS_ERR(it = bclean(handle, sb, block))) {
255 err = PTR_ERR(it); 255 err = PTR_ERR(it);
256 goto exit_bh; 256 goto exit_bh;
257 } 257 }
258 ext3_journal_dirty_metadata(handle, it); 258 ext4_journal_dirty_metadata(handle, it);
259 brelse(it); 259 brelse(it);
260 ext3_set_bit(bit, bh->b_data); 260 ext4_set_bit(bit, bh->b_data);
261 } 261 }
262 mark_bitmap_end(input->blocks_count, EXT3_BLOCKS_PER_GROUP(sb), 262 mark_bitmap_end(input->blocks_count, EXT4_BLOCKS_PER_GROUP(sb),
263 bh->b_data); 263 bh->b_data);
264 ext3_journal_dirty_metadata(handle, bh); 264 ext4_journal_dirty_metadata(handle, bh);
265 brelse(bh); 265 brelse(bh);
266 266
267 /* Mark unused entries in inode bitmap used */ 267 /* Mark unused entries in inode bitmap used */
268 ext3_debug("clear inode bitmap %#04x (+%ld)\n", 268 ext4_debug("clear inode bitmap %#04x (+%ld)\n",
269 input->inode_bitmap, input->inode_bitmap - start); 269 input->inode_bitmap, input->inode_bitmap - start);
270 if (IS_ERR(bh = bclean(handle, sb, input->inode_bitmap))) { 270 if (IS_ERR(bh = bclean(handle, sb, input->inode_bitmap))) {
271 err = PTR_ERR(bh); 271 err = PTR_ERR(bh);
272 goto exit_journal; 272 goto exit_journal;
273 } 273 }
274 274
275 mark_bitmap_end(EXT3_INODES_PER_GROUP(sb), EXT3_BLOCKS_PER_GROUP(sb), 275 mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), EXT4_BLOCKS_PER_GROUP(sb),
276 bh->b_data); 276 bh->b_data);
277 ext3_journal_dirty_metadata(handle, bh); 277 ext4_journal_dirty_metadata(handle, bh);
278exit_bh: 278exit_bh:
279 brelse(bh); 279 brelse(bh);
280 280
281exit_journal: 281exit_journal:
282 unlock_super(sb); 282 unlock_super(sb);
283 if ((err2 = ext3_journal_stop(handle)) && !err) 283 if ((err2 = ext4_journal_stop(handle)) && !err)
284 err = err2; 284 err = err2;
285 285
286 return err; 286 return err;
@@ -288,20 +288,20 @@ exit_journal:
288 288
289/* 289/*
290 * Iterate through the groups which hold BACKUP superblock/GDT copies in an 290 * Iterate through the groups which hold BACKUP superblock/GDT copies in an
291 * ext3 filesystem. The counters should be initialized to 1, 5, and 7 before 291 * ext4 filesystem. The counters should be initialized to 1, 5, and 7 before
292 * calling this for the first time. In a sparse filesystem it will be the 292 * calling this for the first time. In a sparse filesystem it will be the
293 * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... 293 * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ...
294 * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ... 294 * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ...
295 */ 295 */
296static unsigned ext3_list_backups(struct super_block *sb, unsigned *three, 296static unsigned ext4_list_backups(struct super_block *sb, unsigned *three,
297 unsigned *five, unsigned *seven) 297 unsigned *five, unsigned *seven)
298{ 298{
299 unsigned *min = three; 299 unsigned *min = three;
300 int mult = 3; 300 int mult = 3;
301 unsigned ret; 301 unsigned ret;
302 302
303 if (!EXT3_HAS_RO_COMPAT_FEATURE(sb, 303 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
304 EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { 304 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
305 ret = *min; 305 ret = *min;
306 *min += 1; 306 *min += 1;
307 return ret; 307 return ret;
@@ -330,8 +330,8 @@ static unsigned ext3_list_backups(struct super_block *sb, unsigned *three,
330static int verify_reserved_gdb(struct super_block *sb, 330static int verify_reserved_gdb(struct super_block *sb,
331 struct buffer_head *primary) 331 struct buffer_head *primary)
332{ 332{
333 const ext3_fsblk_t blk = primary->b_blocknr; 333 const ext4_fsblk_t blk = primary->b_blocknr;
334 const unsigned long end = EXT3_SB(sb)->s_groups_count; 334 const unsigned long end = EXT4_SB(sb)->s_groups_count;
335 unsigned three = 1; 335 unsigned three = 1;
336 unsigned five = 5; 336 unsigned five = 5;
337 unsigned seven = 7; 337 unsigned seven = 7;
@@ -339,16 +339,16 @@ static int verify_reserved_gdb(struct super_block *sb,
339 __le32 *p = (__le32 *)primary->b_data; 339 __le32 *p = (__le32 *)primary->b_data;
340 int gdbackups = 0; 340 int gdbackups = 0;
341 341
342 while ((grp = ext3_list_backups(sb, &three, &five, &seven)) < end) { 342 while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) {
343 if (le32_to_cpu(*p++) != grp * EXT3_BLOCKS_PER_GROUP(sb) + blk){ 343 if (le32_to_cpu(*p++) != grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){
344 ext3_warning(sb, __FUNCTION__, 344 ext4_warning(sb, __FUNCTION__,
345 "reserved GDT "E3FSBLK 345 "reserved GDT "E3FSBLK
346 " missing grp %d ("E3FSBLK")", 346 " missing grp %d ("E3FSBLK")",
347 blk, grp, 347 blk, grp,
348 grp * EXT3_BLOCKS_PER_GROUP(sb) + blk); 348 grp * EXT4_BLOCKS_PER_GROUP(sb) + blk);
349 return -EINVAL; 349 return -EINVAL;
350 } 350 }
351 if (++gdbackups > EXT3_ADDR_PER_BLOCK(sb)) 351 if (++gdbackups > EXT4_ADDR_PER_BLOCK(sb))
352 return -EFBIG; 352 return -EFBIG;
353 } 353 }
354 354
@@ -369,23 +369,23 @@ static int verify_reserved_gdb(struct super_block *sb,
369 * fail once we start modifying the data on disk, because JBD has no rollback. 369 * fail once we start modifying the data on disk, because JBD has no rollback.
370 */ 370 */
371static int add_new_gdb(handle_t *handle, struct inode *inode, 371static int add_new_gdb(handle_t *handle, struct inode *inode,
372 struct ext3_new_group_data *input, 372 struct ext4_new_group_data *input,
373 struct buffer_head **primary) 373 struct buffer_head **primary)
374{ 374{
375 struct super_block *sb = inode->i_sb; 375 struct super_block *sb = inode->i_sb;
376 struct ext3_super_block *es = EXT3_SB(sb)->s_es; 376 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
377 unsigned long gdb_num = input->group / EXT3_DESC_PER_BLOCK(sb); 377 unsigned long gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
378 ext3_fsblk_t gdblock = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num; 378 ext4_fsblk_t gdblock = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num;
379 struct buffer_head **o_group_desc, **n_group_desc; 379 struct buffer_head **o_group_desc, **n_group_desc;
380 struct buffer_head *dind; 380 struct buffer_head *dind;
381 int gdbackups; 381 int gdbackups;
382 struct ext3_iloc iloc; 382 struct ext4_iloc iloc;
383 __le32 *data; 383 __le32 *data;
384 int err; 384 int err;
385 385
386 if (test_opt(sb, DEBUG)) 386 if (test_opt(sb, DEBUG))
387 printk(KERN_DEBUG 387 printk(KERN_DEBUG
388 "EXT3-fs: ext3_add_new_gdb: adding group block %lu\n", 388 "EXT4-fs: ext4_add_new_gdb: adding group block %lu\n",
389 gdb_num); 389 gdb_num);
390 390
391 /* 391 /*
@@ -393,11 +393,11 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
393 * because the user tools have no way of handling this. Probably a 393 * because the user tools have no way of handling this. Probably a
394 * bad time to do it anyways. 394 * bad time to do it anyways.
395 */ 395 */
396 if (EXT3_SB(sb)->s_sbh->b_blocknr != 396 if (EXT4_SB(sb)->s_sbh->b_blocknr !=
397 le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) { 397 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) {
398 ext3_warning(sb, __FUNCTION__, 398 ext4_warning(sb, __FUNCTION__,
399 "won't resize using backup superblock at %llu", 399 "won't resize using backup superblock at %llu",
400 (unsigned long long)EXT3_SB(sb)->s_sbh->b_blocknr); 400 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr);
401 return -EPERM; 401 return -EPERM;
402 } 402 }
403 403
@@ -410,7 +410,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
410 goto exit_bh; 410 goto exit_bh;
411 } 411 }
412 412
413 data = EXT3_I(inode)->i_data + EXT3_DIND_BLOCK; 413 data = EXT4_I(inode)->i_data + EXT4_DIND_BLOCK;
414 dind = sb_bread(sb, le32_to_cpu(*data)); 414 dind = sb_bread(sb, le32_to_cpu(*data));
415 if (!dind) { 415 if (!dind) {
416 err = -EIO; 416 err = -EIO;
@@ -418,32 +418,32 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
418 } 418 }
419 419
420 data = (__le32 *)dind->b_data; 420 data = (__le32 *)dind->b_data;
421 if (le32_to_cpu(data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)]) != gdblock) { 421 if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) {
422 ext3_warning(sb, __FUNCTION__, 422 ext4_warning(sb, __FUNCTION__,
423 "new group %u GDT block "E3FSBLK" not reserved", 423 "new group %u GDT block "E3FSBLK" not reserved",
424 input->group, gdblock); 424 input->group, gdblock);
425 err = -EINVAL; 425 err = -EINVAL;
426 goto exit_dind; 426 goto exit_dind;
427 } 427 }
428 428
429 if ((err = ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh))) 429 if ((err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh)))
430 goto exit_dind; 430 goto exit_dind;
431 431
432 if ((err = ext3_journal_get_write_access(handle, *primary))) 432 if ((err = ext4_journal_get_write_access(handle, *primary)))
433 goto exit_sbh; 433 goto exit_sbh;
434 434
435 if ((err = ext3_journal_get_write_access(handle, dind))) 435 if ((err = ext4_journal_get_write_access(handle, dind)))
436 goto exit_primary; 436 goto exit_primary;
437 437
438 /* ext3_reserve_inode_write() gets a reference on the iloc */ 438 /* ext4_reserve_inode_write() gets a reference on the iloc */
439 if ((err = ext3_reserve_inode_write(handle, inode, &iloc))) 439 if ((err = ext4_reserve_inode_write(handle, inode, &iloc)))
440 goto exit_dindj; 440 goto exit_dindj;
441 441
442 n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *), 442 n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *),
443 GFP_KERNEL); 443 GFP_KERNEL);
444 if (!n_group_desc) { 444 if (!n_group_desc) {
445 err = -ENOMEM; 445 err = -ENOMEM;
446 ext3_warning (sb, __FUNCTION__, 446 ext4_warning (sb, __FUNCTION__,
447 "not enough memory for %lu groups", gdb_num + 1); 447 "not enough memory for %lu groups", gdb_num + 1);
448 goto exit_inode; 448 goto exit_inode;
449 } 449 }
@@ -457,43 +457,43 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
457 * these blocks, because they are marked as in-use from being in the 457 * these blocks, because they are marked as in-use from being in the
458 * reserved inode, and will become GDT blocks (primary and backup). 458 * reserved inode, and will become GDT blocks (primary and backup).
459 */ 459 */
460 data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)] = 0; 460 data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)] = 0;
461 ext3_journal_dirty_metadata(handle, dind); 461 ext4_journal_dirty_metadata(handle, dind);
462 brelse(dind); 462 brelse(dind);
463 inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9; 463 inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9;
464 ext3_mark_iloc_dirty(handle, inode, &iloc); 464 ext4_mark_iloc_dirty(handle, inode, &iloc);
465 memset((*primary)->b_data, 0, sb->s_blocksize); 465 memset((*primary)->b_data, 0, sb->s_blocksize);
466 ext3_journal_dirty_metadata(handle, *primary); 466 ext4_journal_dirty_metadata(handle, *primary);
467 467
468 o_group_desc = EXT3_SB(sb)->s_group_desc; 468 o_group_desc = EXT4_SB(sb)->s_group_desc;
469 memcpy(n_group_desc, o_group_desc, 469 memcpy(n_group_desc, o_group_desc,
470 EXT3_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); 470 EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *));
471 n_group_desc[gdb_num] = *primary; 471 n_group_desc[gdb_num] = *primary;
472 EXT3_SB(sb)->s_group_desc = n_group_desc; 472 EXT4_SB(sb)->s_group_desc = n_group_desc;
473 EXT3_SB(sb)->s_gdb_count++; 473 EXT4_SB(sb)->s_gdb_count++;
474 kfree(o_group_desc); 474 kfree(o_group_desc);
475 475
476 es->s_reserved_gdt_blocks = 476 es->s_reserved_gdt_blocks =
477 cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1); 477 cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1);
478 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 478 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
479 479
480 return 0; 480 return 0;
481 481
482exit_inode: 482exit_inode:
483 //ext3_journal_release_buffer(handle, iloc.bh); 483 //ext4_journal_release_buffer(handle, iloc.bh);
484 brelse(iloc.bh); 484 brelse(iloc.bh);
485exit_dindj: 485exit_dindj:
486 //ext3_journal_release_buffer(handle, dind); 486 //ext4_journal_release_buffer(handle, dind);
487exit_primary: 487exit_primary:
488 //ext3_journal_release_buffer(handle, *primary); 488 //ext4_journal_release_buffer(handle, *primary);
489exit_sbh: 489exit_sbh:
490 //ext3_journal_release_buffer(handle, *primary); 490 //ext4_journal_release_buffer(handle, *primary);
491exit_dind: 491exit_dind:
492 brelse(dind); 492 brelse(dind);
493exit_bh: 493exit_bh:
494 brelse(*primary); 494 brelse(*primary);
495 495
496 ext3_debug("leaving with error %d\n", err); 496 ext4_debug("leaving with error %d\n", err);
497 return err; 497 return err;
498} 498}
499 499
@@ -511,14 +511,14 @@ exit_bh:
511 * backup GDT blocks are stored in their reserved primary GDT block. 511 * backup GDT blocks are stored in their reserved primary GDT block.
512 */ 512 */
513static int reserve_backup_gdb(handle_t *handle, struct inode *inode, 513static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
514 struct ext3_new_group_data *input) 514 struct ext4_new_group_data *input)
515{ 515{
516 struct super_block *sb = inode->i_sb; 516 struct super_block *sb = inode->i_sb;
517 int reserved_gdb =le16_to_cpu(EXT3_SB(sb)->s_es->s_reserved_gdt_blocks); 517 int reserved_gdb =le16_to_cpu(EXT4_SB(sb)->s_es->s_reserved_gdt_blocks);
518 struct buffer_head **primary; 518 struct buffer_head **primary;
519 struct buffer_head *dind; 519 struct buffer_head *dind;
520 struct ext3_iloc iloc; 520 struct ext4_iloc iloc;
521 ext3_fsblk_t blk; 521 ext4_fsblk_t blk;
522 __le32 *data, *end; 522 __le32 *data, *end;
523 int gdbackups = 0; 523 int gdbackups = 0;
524 int res, i; 524 int res, i;
@@ -528,21 +528,21 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
528 if (!primary) 528 if (!primary)
529 return -ENOMEM; 529 return -ENOMEM;
530 530
531 data = EXT3_I(inode)->i_data + EXT3_DIND_BLOCK; 531 data = EXT4_I(inode)->i_data + EXT4_DIND_BLOCK;
532 dind = sb_bread(sb, le32_to_cpu(*data)); 532 dind = sb_bread(sb, le32_to_cpu(*data));
533 if (!dind) { 533 if (!dind) {
534 err = -EIO; 534 err = -EIO;
535 goto exit_free; 535 goto exit_free;
536 } 536 }
537 537
538 blk = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + EXT3_SB(sb)->s_gdb_count; 538 blk = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + EXT4_SB(sb)->s_gdb_count;
539 data = (__le32 *)dind->b_data + EXT3_SB(sb)->s_gdb_count; 539 data = (__le32 *)dind->b_data + EXT4_SB(sb)->s_gdb_count;
540 end = (__le32 *)dind->b_data + EXT3_ADDR_PER_BLOCK(sb); 540 end = (__le32 *)dind->b_data + EXT4_ADDR_PER_BLOCK(sb);
541 541
542 /* Get each reserved primary GDT block and verify it holds backups */ 542 /* Get each reserved primary GDT block and verify it holds backups */
543 for (res = 0; res < reserved_gdb; res++, blk++) { 543 for (res = 0; res < reserved_gdb; res++, blk++) {
544 if (le32_to_cpu(*data) != blk) { 544 if (le32_to_cpu(*data) != blk) {
545 ext3_warning(sb, __FUNCTION__, 545 ext4_warning(sb, __FUNCTION__,
546 "reserved block "E3FSBLK 546 "reserved block "E3FSBLK
547 " not at offset %ld", 547 " not at offset %ld",
548 blk, 548 blk,
@@ -565,24 +565,24 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
565 } 565 }
566 566
567 for (i = 0; i < reserved_gdb; i++) { 567 for (i = 0; i < reserved_gdb; i++) {
568 if ((err = ext3_journal_get_write_access(handle, primary[i]))) { 568 if ((err = ext4_journal_get_write_access(handle, primary[i]))) {
569 /* 569 /*
570 int j; 570 int j;
571 for (j = 0; j < i; j++) 571 for (j = 0; j < i; j++)
572 ext3_journal_release_buffer(handle, primary[j]); 572 ext4_journal_release_buffer(handle, primary[j]);
573 */ 573 */
574 goto exit_bh; 574 goto exit_bh;
575 } 575 }
576 } 576 }
577 577
578 if ((err = ext3_reserve_inode_write(handle, inode, &iloc))) 578 if ((err = ext4_reserve_inode_write(handle, inode, &iloc)))
579 goto exit_bh; 579 goto exit_bh;
580 580
581 /* 581 /*
582 * Finally we can add each of the reserved backup GDT blocks from 582 * Finally we can add each of the reserved backup GDT blocks from
583 * the new group to its reserved primary GDT block. 583 * the new group to its reserved primary GDT block.
584 */ 584 */
585 blk = input->group * EXT3_BLOCKS_PER_GROUP(sb); 585 blk = input->group * EXT4_BLOCKS_PER_GROUP(sb);
586 for (i = 0; i < reserved_gdb; i++) { 586 for (i = 0; i < reserved_gdb; i++) {
587 int err2; 587 int err2;
588 data = (__le32 *)primary[i]->b_data; 588 data = (__le32 *)primary[i]->b_data;
@@ -590,12 +590,12 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
590 primary[i]->b_blocknr, gdbackups, 590 primary[i]->b_blocknr, gdbackups,
591 blk + primary[i]->b_blocknr); */ 591 blk + primary[i]->b_blocknr); */
592 data[gdbackups] = cpu_to_le32(blk + primary[i]->b_blocknr); 592 data[gdbackups] = cpu_to_le32(blk + primary[i]->b_blocknr);
593 err2 = ext3_journal_dirty_metadata(handle, primary[i]); 593 err2 = ext4_journal_dirty_metadata(handle, primary[i]);
594 if (!err) 594 if (!err)
595 err = err2; 595 err = err2;
596 } 596 }
597 inode->i_blocks += reserved_gdb * sb->s_blocksize >> 9; 597 inode->i_blocks += reserved_gdb * sb->s_blocksize >> 9;
598 ext3_mark_iloc_dirty(handle, inode, &iloc); 598 ext4_mark_iloc_dirty(handle, inode, &iloc);
599 599
600exit_bh: 600exit_bh:
601 while (--res >= 0) 601 while (--res >= 0)
@@ -609,7 +609,7 @@ exit_free:
609} 609}
610 610
611/* 611/*
612 * Update the backup copies of the ext3 metadata. These don't need to be part 612 * Update the backup copies of the ext4 metadata. These don't need to be part
613 * of the main resize transaction, because e2fsck will re-write them if there 613 * of the main resize transaction, because e2fsck will re-write them if there
614 * is a problem (basically only OOM will cause a problem). However, we 614 * is a problem (basically only OOM will cause a problem). However, we
615 * _should_ update the backups if possible, in case the primary gets trashed 615 * _should_ update the backups if possible, in case the primary gets trashed
@@ -626,9 +626,9 @@ exit_free:
626static void update_backups(struct super_block *sb, 626static void update_backups(struct super_block *sb,
627 int blk_off, char *data, int size) 627 int blk_off, char *data, int size)
628{ 628{
629 struct ext3_sb_info *sbi = EXT3_SB(sb); 629 struct ext4_sb_info *sbi = EXT4_SB(sb);
630 const unsigned long last = sbi->s_groups_count; 630 const unsigned long last = sbi->s_groups_count;
631 const int bpg = EXT3_BLOCKS_PER_GROUP(sb); 631 const int bpg = EXT4_BLOCKS_PER_GROUP(sb);
632 unsigned three = 1; 632 unsigned three = 1;
633 unsigned five = 5; 633 unsigned five = 5;
634 unsigned seven = 7; 634 unsigned seven = 7;
@@ -637,20 +637,20 @@ static void update_backups(struct super_block *sb,
637 handle_t *handle; 637 handle_t *handle;
638 int err = 0, err2; 638 int err = 0, err2;
639 639
640 handle = ext3_journal_start_sb(sb, EXT3_MAX_TRANS_DATA); 640 handle = ext4_journal_start_sb(sb, EXT4_MAX_TRANS_DATA);
641 if (IS_ERR(handle)) { 641 if (IS_ERR(handle)) {
642 group = 1; 642 group = 1;
643 err = PTR_ERR(handle); 643 err = PTR_ERR(handle);
644 goto exit_err; 644 goto exit_err;
645 } 645 }
646 646
647 while ((group = ext3_list_backups(sb, &three, &five, &seven)) < last) { 647 while ((group = ext4_list_backups(sb, &three, &five, &seven)) < last) {
648 struct buffer_head *bh; 648 struct buffer_head *bh;
649 649
650 /* Out of journal space, and can't get more - abort - so sad */ 650 /* Out of journal space, and can't get more - abort - so sad */
651 if (handle->h_buffer_credits == 0 && 651 if (handle->h_buffer_credits == 0 &&
652 ext3_journal_extend(handle, EXT3_MAX_TRANS_DATA) && 652 ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA) &&
653 (err = ext3_journal_restart(handle, EXT3_MAX_TRANS_DATA))) 653 (err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA)))
654 break; 654 break;
655 655
656 bh = sb_getblk(sb, group * bpg + blk_off); 656 bh = sb_getblk(sb, group * bpg + blk_off);
@@ -658,9 +658,9 @@ static void update_backups(struct super_block *sb,
658 err = -EIO; 658 err = -EIO;
659 break; 659 break;
660 } 660 }
661 ext3_debug("update metadata backup %#04lx\n", 661 ext4_debug("update metadata backup %#04lx\n",
662 (unsigned long)bh->b_blocknr); 662 (unsigned long)bh->b_blocknr);
663 if ((err = ext3_journal_get_write_access(handle, bh))) 663 if ((err = ext4_journal_get_write_access(handle, bh)))
664 break; 664 break;
665 lock_buffer(bh); 665 lock_buffer(bh);
666 memcpy(bh->b_data, data, size); 666 memcpy(bh->b_data, data, size);
@@ -668,10 +668,10 @@ static void update_backups(struct super_block *sb,
668 memset(bh->b_data + size, 0, rest); 668 memset(bh->b_data + size, 0, rest);
669 set_buffer_uptodate(bh); 669 set_buffer_uptodate(bh);
670 unlock_buffer(bh); 670 unlock_buffer(bh);
671 ext3_journal_dirty_metadata(handle, bh); 671 ext4_journal_dirty_metadata(handle, bh);
672 brelse(bh); 672 brelse(bh);
673 } 673 }
674 if ((err2 = ext3_journal_stop(handle)) && !err) 674 if ((err2 = ext4_journal_stop(handle)) && !err)
675 err = err2; 675 err = err2;
676 676
677 /* 677 /*
@@ -686,11 +686,11 @@ static void update_backups(struct super_block *sb,
686 */ 686 */
687exit_err: 687exit_err:
688 if (err) { 688 if (err) {
689 ext3_warning(sb, __FUNCTION__, 689 ext4_warning(sb, __FUNCTION__,
690 "can't update backup for group %d (err %d), " 690 "can't update backup for group %d (err %d), "
691 "forcing fsck on next reboot", group, err); 691 "forcing fsck on next reboot", group, err);
692 sbi->s_mount_state &= ~EXT3_VALID_FS; 692 sbi->s_mount_state &= ~EXT4_VALID_FS;
693 sbi->s_es->s_state &= cpu_to_le16(~EXT3_VALID_FS); 693 sbi->s_es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
694 mark_buffer_dirty(sbi->s_sbh); 694 mark_buffer_dirty(sbi->s_sbh);
695 } 695 }
696} 696}
@@ -708,51 +708,51 @@ exit_err:
708 * not really "added" the group at all. We re-check that we are still 708 * not really "added" the group at all. We re-check that we are still
709 * adding in the last group in case things have changed since verifying. 709 * adding in the last group in case things have changed since verifying.
710 */ 710 */
711int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) 711int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
712{ 712{
713 struct ext3_sb_info *sbi = EXT3_SB(sb); 713 struct ext4_sb_info *sbi = EXT4_SB(sb);
714 struct ext3_super_block *es = sbi->s_es; 714 struct ext4_super_block *es = sbi->s_es;
715 int reserved_gdb = ext3_bg_has_super(sb, input->group) ? 715 int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
716 le16_to_cpu(es->s_reserved_gdt_blocks) : 0; 716 le16_to_cpu(es->s_reserved_gdt_blocks) : 0;
717 struct buffer_head *primary = NULL; 717 struct buffer_head *primary = NULL;
718 struct ext3_group_desc *gdp; 718 struct ext4_group_desc *gdp;
719 struct inode *inode = NULL; 719 struct inode *inode = NULL;
720 handle_t *handle; 720 handle_t *handle;
721 int gdb_off, gdb_num; 721 int gdb_off, gdb_num;
722 int err, err2; 722 int err, err2;
723 723
724 gdb_num = input->group / EXT3_DESC_PER_BLOCK(sb); 724 gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
725 gdb_off = input->group % EXT3_DESC_PER_BLOCK(sb); 725 gdb_off = input->group % EXT4_DESC_PER_BLOCK(sb);
726 726
727 if (gdb_off == 0 && !EXT3_HAS_RO_COMPAT_FEATURE(sb, 727 if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb,
728 EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { 728 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
729 ext3_warning(sb, __FUNCTION__, 729 ext4_warning(sb, __FUNCTION__,
730 "Can't resize non-sparse filesystem further"); 730 "Can't resize non-sparse filesystem further");
731 return -EPERM; 731 return -EPERM;
732 } 732 }
733 733
734 if (le32_to_cpu(es->s_blocks_count) + input->blocks_count < 734 if (le32_to_cpu(es->s_blocks_count) + input->blocks_count <
735 le32_to_cpu(es->s_blocks_count)) { 735 le32_to_cpu(es->s_blocks_count)) {
736 ext3_warning(sb, __FUNCTION__, "blocks_count overflow\n"); 736 ext4_warning(sb, __FUNCTION__, "blocks_count overflow\n");
737 return -EINVAL; 737 return -EINVAL;
738 } 738 }
739 739
740 if (le32_to_cpu(es->s_inodes_count) + EXT3_INODES_PER_GROUP(sb) < 740 if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) <
741 le32_to_cpu(es->s_inodes_count)) { 741 le32_to_cpu(es->s_inodes_count)) {
742 ext3_warning(sb, __FUNCTION__, "inodes_count overflow\n"); 742 ext4_warning(sb, __FUNCTION__, "inodes_count overflow\n");
743 return -EINVAL; 743 return -EINVAL;
744 } 744 }
745 745
746 if (reserved_gdb || gdb_off == 0) { 746 if (reserved_gdb || gdb_off == 0) {
747 if (!EXT3_HAS_COMPAT_FEATURE(sb, 747 if (!EXT4_HAS_COMPAT_FEATURE(sb,
748 EXT3_FEATURE_COMPAT_RESIZE_INODE)){ 748 EXT4_FEATURE_COMPAT_RESIZE_INODE)){
749 ext3_warning(sb, __FUNCTION__, 749 ext4_warning(sb, __FUNCTION__,
750 "No reserved GDT blocks, can't resize"); 750 "No reserved GDT blocks, can't resize");
751 return -EPERM; 751 return -EPERM;
752 } 752 }
753 inode = iget(sb, EXT3_RESIZE_INO); 753 inode = iget(sb, EXT4_RESIZE_INO);
754 if (!inode || is_bad_inode(inode)) { 754 if (!inode || is_bad_inode(inode)) {
755 ext3_warning(sb, __FUNCTION__, 755 ext4_warning(sb, __FUNCTION__,
756 "Error opening resize inode"); 756 "Error opening resize inode");
757 iput(inode); 757 iput(inode);
758 return -ENOENT; 758 return -ENOENT;
@@ -772,8 +772,8 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
772 * are adding a group with superblock/GDT backups we will also 772 * are adding a group with superblock/GDT backups we will also
773 * modify each of the reserved GDT dindirect blocks. 773 * modify each of the reserved GDT dindirect blocks.
774 */ 774 */
775 handle = ext3_journal_start_sb(sb, 775 handle = ext4_journal_start_sb(sb,
776 ext3_bg_has_super(sb, input->group) ? 776 ext4_bg_has_super(sb, input->group) ?
777 3 + reserved_gdb : 4); 777 3 + reserved_gdb : 4);
778 if (IS_ERR(handle)) { 778 if (IS_ERR(handle)) {
779 err = PTR_ERR(handle); 779 err = PTR_ERR(handle);
@@ -782,13 +782,13 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
782 782
783 lock_super(sb); 783 lock_super(sb);
784 if (input->group != sbi->s_groups_count) { 784 if (input->group != sbi->s_groups_count) {
785 ext3_warning(sb, __FUNCTION__, 785 ext4_warning(sb, __FUNCTION__,
786 "multiple resizers run on filesystem!"); 786 "multiple resizers run on filesystem!");
787 err = -EBUSY; 787 err = -EBUSY;
788 goto exit_journal; 788 goto exit_journal;
789 } 789 }
790 790
791 if ((err = ext3_journal_get_write_access(handle, sbi->s_sbh))) 791 if ((err = ext4_journal_get_write_access(handle, sbi->s_sbh)))
792 goto exit_journal; 792 goto exit_journal;
793 793
794 /* 794 /*
@@ -799,10 +799,10 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
799 */ 799 */
800 if (gdb_off) { 800 if (gdb_off) {
801 primary = sbi->s_group_desc[gdb_num]; 801 primary = sbi->s_group_desc[gdb_num];
802 if ((err = ext3_journal_get_write_access(handle, primary))) 802 if ((err = ext4_journal_get_write_access(handle, primary)))
803 goto exit_journal; 803 goto exit_journal;
804 804
805 if (reserved_gdb && ext3_bg_num_gdb(sb, input->group) && 805 if (reserved_gdb && ext4_bg_num_gdb(sb, input->group) &&
806 (err = reserve_backup_gdb(handle, inode, input))) 806 (err = reserve_backup_gdb(handle, inode, input)))
807 goto exit_journal; 807 goto exit_journal;
808 } else if ((err = add_new_gdb(handle, inode, input, &primary))) 808 } else if ((err = add_new_gdb(handle, inode, input, &primary)))
@@ -828,13 +828,13 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
828 */ 828 */
829 829
830 /* Update group descriptor block for new group */ 830 /* Update group descriptor block for new group */
831 gdp = (struct ext3_group_desc *)primary->b_data + gdb_off; 831 gdp = (struct ext4_group_desc *)primary->b_data + gdb_off;
832 832
833 gdp->bg_block_bitmap = cpu_to_le32(input->block_bitmap); 833 gdp->bg_block_bitmap = cpu_to_le32(input->block_bitmap);
834 gdp->bg_inode_bitmap = cpu_to_le32(input->inode_bitmap); 834 gdp->bg_inode_bitmap = cpu_to_le32(input->inode_bitmap);
835 gdp->bg_inode_table = cpu_to_le32(input->inode_table); 835 gdp->bg_inode_table = cpu_to_le32(input->inode_table);
836 gdp->bg_free_blocks_count = cpu_to_le16(input->free_blocks_count); 836 gdp->bg_free_blocks_count = cpu_to_le16(input->free_blocks_count);
837 gdp->bg_free_inodes_count = cpu_to_le16(EXT3_INODES_PER_GROUP(sb)); 837 gdp->bg_free_inodes_count = cpu_to_le16(EXT4_INODES_PER_GROUP(sb));
838 838
839 /* 839 /*
840 * Make the new blocks and inodes valid next. We do this before 840 * Make the new blocks and inodes valid next. We do this before
@@ -849,7 +849,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
849 es->s_blocks_count = cpu_to_le32(le32_to_cpu(es->s_blocks_count) + 849 es->s_blocks_count = cpu_to_le32(le32_to_cpu(es->s_blocks_count) +
850 input->blocks_count); 850 input->blocks_count);
851 es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) + 851 es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) +
852 EXT3_INODES_PER_GROUP(sb)); 852 EXT4_INODES_PER_GROUP(sb));
853 853
854 /* 854 /*
855 * We need to protect s_groups_count against other CPUs seeing 855 * We need to protect s_groups_count against other CPUs seeing
@@ -878,7 +878,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
878 /* Update the global fs size fields */ 878 /* Update the global fs size fields */
879 sbi->s_groups_count++; 879 sbi->s_groups_count++;
880 880
881 ext3_journal_dirty_metadata(handle, primary); 881 ext4_journal_dirty_metadata(handle, primary);
882 882
883 /* Update the reserved block counts only once the new group is 883 /* Update the reserved block counts only once the new group is
884 * active. */ 884 * active. */
@@ -889,42 +889,42 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
889 percpu_counter_mod(&sbi->s_freeblocks_counter, 889 percpu_counter_mod(&sbi->s_freeblocks_counter,
890 input->free_blocks_count); 890 input->free_blocks_count);
891 percpu_counter_mod(&sbi->s_freeinodes_counter, 891 percpu_counter_mod(&sbi->s_freeinodes_counter,
892 EXT3_INODES_PER_GROUP(sb)); 892 EXT4_INODES_PER_GROUP(sb));
893 893
894 ext3_journal_dirty_metadata(handle, sbi->s_sbh); 894 ext4_journal_dirty_metadata(handle, sbi->s_sbh);
895 sb->s_dirt = 1; 895 sb->s_dirt = 1;
896 896
897exit_journal: 897exit_journal:
898 unlock_super(sb); 898 unlock_super(sb);
899 if ((err2 = ext3_journal_stop(handle)) && !err) 899 if ((err2 = ext4_journal_stop(handle)) && !err)
900 err = err2; 900 err = err2;
901 if (!err) { 901 if (!err) {
902 update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es, 902 update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es,
903 sizeof(struct ext3_super_block)); 903 sizeof(struct ext4_super_block));
904 update_backups(sb, primary->b_blocknr, primary->b_data, 904 update_backups(sb, primary->b_blocknr, primary->b_data,
905 primary->b_size); 905 primary->b_size);
906 } 906 }
907exit_put: 907exit_put:
908 iput(inode); 908 iput(inode);
909 return err; 909 return err;
910} /* ext3_group_add */ 910} /* ext4_group_add */
911 911
912/* Extend the filesystem to the new number of blocks specified. This entry 912/* Extend the filesystem to the new number of blocks specified. This entry
913 * point is only used to extend the current filesystem to the end of the last 913 * point is only used to extend the current filesystem to the end of the last
914 * existing group. It can be accessed via ioctl, or by "remount,resize=<size>" 914 * existing group. It can be accessed via ioctl, or by "remount,resize=<size>"
915 * for emergencies (because it has no dependencies on reserved blocks). 915 * for emergencies (because it has no dependencies on reserved blocks).
916 * 916 *
917 * If we _really_ wanted, we could use default values to call ext3_group_add() 917 * If we _really_ wanted, we could use default values to call ext4_group_add()
918 * allow the "remount" trick to work for arbitrary resizing, assuming enough 918 * allow the "remount" trick to work for arbitrary resizing, assuming enough
919 * GDT blocks are reserved to grow to the desired size. 919 * GDT blocks are reserved to grow to the desired size.
920 */ 920 */
921int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, 921int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
922 ext3_fsblk_t n_blocks_count) 922 ext4_fsblk_t n_blocks_count)
923{ 923{
924 ext3_fsblk_t o_blocks_count; 924 ext4_fsblk_t o_blocks_count;
925 unsigned long o_groups_count; 925 unsigned long o_groups_count;
926 ext3_grpblk_t last; 926 ext4_grpblk_t last;
927 ext3_grpblk_t add; 927 ext4_grpblk_t add;
928 struct buffer_head * bh; 928 struct buffer_head * bh;
929 handle_t *handle; 929 handle_t *handle;
930 int err; 930 int err;
@@ -934,45 +934,45 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
934 * yet: we're going to revalidate es->s_blocks_count after 934 * yet: we're going to revalidate es->s_blocks_count after
935 * taking lock_super() below. */ 935 * taking lock_super() below. */
936 o_blocks_count = le32_to_cpu(es->s_blocks_count); 936 o_blocks_count = le32_to_cpu(es->s_blocks_count);
937 o_groups_count = EXT3_SB(sb)->s_groups_count; 937 o_groups_count = EXT4_SB(sb)->s_groups_count;
938 938
939 if (test_opt(sb, DEBUG)) 939 if (test_opt(sb, DEBUG))
940 printk(KERN_DEBUG "EXT3-fs: extending last group from "E3FSBLK" uto "E3FSBLK" blocks\n", 940 printk(KERN_DEBUG "EXT4-fs: extending last group from "E3FSBLK" uto "E3FSBLK" blocks\n",
941 o_blocks_count, n_blocks_count); 941 o_blocks_count, n_blocks_count);
942 942
943 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count) 943 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
944 return 0; 944 return 0;
945 945
946 if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 946 if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
947 printk(KERN_ERR "EXT3-fs: filesystem on %s:" 947 printk(KERN_ERR "EXT4-fs: filesystem on %s:"
948 " too large to resize to %lu blocks safely\n", 948 " too large to resize to %lu blocks safely\n",
949 sb->s_id, n_blocks_count); 949 sb->s_id, n_blocks_count);
950 if (sizeof(sector_t) < 8) 950 if (sizeof(sector_t) < 8)
951 ext3_warning(sb, __FUNCTION__, 951 ext4_warning(sb, __FUNCTION__,
952 "CONFIG_LBD not enabled\n"); 952 "CONFIG_LBD not enabled\n");
953 return -EINVAL; 953 return -EINVAL;
954 } 954 }
955 955
956 if (n_blocks_count < o_blocks_count) { 956 if (n_blocks_count < o_blocks_count) {
957 ext3_warning(sb, __FUNCTION__, 957 ext4_warning(sb, __FUNCTION__,
958 "can't shrink FS - resize aborted"); 958 "can't shrink FS - resize aborted");
959 return -EBUSY; 959 return -EBUSY;
960 } 960 }
961 961
962 /* Handle the remaining blocks in the last group only. */ 962 /* Handle the remaining blocks in the last group only. */
963 last = (o_blocks_count - le32_to_cpu(es->s_first_data_block)) % 963 last = (o_blocks_count - le32_to_cpu(es->s_first_data_block)) %
964 EXT3_BLOCKS_PER_GROUP(sb); 964 EXT4_BLOCKS_PER_GROUP(sb);
965 965
966 if (last == 0) { 966 if (last == 0) {
967 ext3_warning(sb, __FUNCTION__, 967 ext4_warning(sb, __FUNCTION__,
968 "need to use ext2online to resize further"); 968 "need to use ext2online to resize further");
969 return -EPERM; 969 return -EPERM;
970 } 970 }
971 971
972 add = EXT3_BLOCKS_PER_GROUP(sb) - last; 972 add = EXT4_BLOCKS_PER_GROUP(sb) - last;
973 973
974 if (o_blocks_count + add < o_blocks_count) { 974 if (o_blocks_count + add < o_blocks_count) {
975 ext3_warning(sb, __FUNCTION__, "blocks_count overflow"); 975 ext4_warning(sb, __FUNCTION__, "blocks_count overflow");
976 return -EINVAL; 976 return -EINVAL;
977 } 977 }
978 978
@@ -980,7 +980,7 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
980 add = n_blocks_count - o_blocks_count; 980 add = n_blocks_count - o_blocks_count;
981 981
982 if (o_blocks_count + add < n_blocks_count) 982 if (o_blocks_count + add < n_blocks_count)
983 ext3_warning(sb, __FUNCTION__, 983 ext4_warning(sb, __FUNCTION__,
984 "will only finish group ("E3FSBLK 984 "will only finish group ("E3FSBLK
985 " blocks, %u new)", 985 " blocks, %u new)",
986 o_blocks_count + add, add); 986 o_blocks_count + add, add);
@@ -988,55 +988,55 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
988 /* See if the device is actually as big as what was requested */ 988 /* See if the device is actually as big as what was requested */
989 bh = sb_bread(sb, o_blocks_count + add -1); 989 bh = sb_bread(sb, o_blocks_count + add -1);
990 if (!bh) { 990 if (!bh) {
991 ext3_warning(sb, __FUNCTION__, 991 ext4_warning(sb, __FUNCTION__,
992 "can't read last block, resize aborted"); 992 "can't read last block, resize aborted");
993 return -ENOSPC; 993 return -ENOSPC;
994 } 994 }
995 brelse(bh); 995 brelse(bh);
996 996
997 /* We will update the superblock, one block bitmap, and 997 /* We will update the superblock, one block bitmap, and
998 * one group descriptor via ext3_free_blocks(). 998 * one group descriptor via ext4_free_blocks().
999 */ 999 */
1000 handle = ext3_journal_start_sb(sb, 3); 1000 handle = ext4_journal_start_sb(sb, 3);
1001 if (IS_ERR(handle)) { 1001 if (IS_ERR(handle)) {
1002 err = PTR_ERR(handle); 1002 err = PTR_ERR(handle);
1003 ext3_warning(sb, __FUNCTION__, "error %d on journal start",err); 1003 ext4_warning(sb, __FUNCTION__, "error %d on journal start",err);
1004 goto exit_put; 1004 goto exit_put;
1005 } 1005 }
1006 1006
1007 lock_super(sb); 1007 lock_super(sb);
1008 if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { 1008 if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) {
1009 ext3_warning(sb, __FUNCTION__, 1009 ext4_warning(sb, __FUNCTION__,
1010 "multiple resizers run on filesystem!"); 1010 "multiple resizers run on filesystem!");
1011 unlock_super(sb); 1011 unlock_super(sb);
1012 err = -EBUSY; 1012 err = -EBUSY;
1013 goto exit_put; 1013 goto exit_put;
1014 } 1014 }
1015 1015
1016 if ((err = ext3_journal_get_write_access(handle, 1016 if ((err = ext4_journal_get_write_access(handle,
1017 EXT3_SB(sb)->s_sbh))) { 1017 EXT4_SB(sb)->s_sbh))) {
1018 ext3_warning(sb, __FUNCTION__, 1018 ext4_warning(sb, __FUNCTION__,
1019 "error %d on journal write access", err); 1019 "error %d on journal write access", err);
1020 unlock_super(sb); 1020 unlock_super(sb);
1021 ext3_journal_stop(handle); 1021 ext4_journal_stop(handle);
1022 goto exit_put; 1022 goto exit_put;
1023 } 1023 }
1024 es->s_blocks_count = cpu_to_le32(o_blocks_count + add); 1024 es->s_blocks_count = cpu_to_le32(o_blocks_count + add);
1025 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 1025 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
1026 sb->s_dirt = 1; 1026 sb->s_dirt = 1;
1027 unlock_super(sb); 1027 unlock_super(sb);
1028 ext3_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count, 1028 ext4_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count,
1029 o_blocks_count + add); 1029 o_blocks_count + add);
1030 ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks); 1030 ext4_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks);
1031 ext3_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n", o_blocks_count, 1031 ext4_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n", o_blocks_count,
1032 o_blocks_count + add); 1032 o_blocks_count + add);
1033 if ((err = ext3_journal_stop(handle))) 1033 if ((err = ext4_journal_stop(handle)))
1034 goto exit_put; 1034 goto exit_put;
1035 if (test_opt(sb, DEBUG)) 1035 if (test_opt(sb, DEBUG))
1036 printk(KERN_DEBUG "EXT3-fs: extended group to %u blocks\n", 1036 printk(KERN_DEBUG "EXT4-fs: extended group to %u blocks\n",
1037 le32_to_cpu(es->s_blocks_count)); 1037 le32_to_cpu(es->s_blocks_count));
1038 update_backups(sb, EXT3_SB(sb)->s_sbh->b_blocknr, (char *)es, 1038 update_backups(sb, EXT4_SB(sb)->s_sbh->b_blocknr, (char *)es,
1039 sizeof(struct ext3_super_block)); 1039 sizeof(struct ext4_super_block));
1040exit_put: 1040exit_put:
1041 return err; 1041 return err;
1042} /* ext3_group_extend */ 1042} /* ext4_group_extend */