File: online-ext2-2.3.diff

package info (click to toggle)
ext2resize 1.1.17-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 772 kB
  • ctags: 678
  • sloc: ansic: 4,595; sh: 389; makefile: 56
file content (596 lines) | stat: -rw-r--r-- 20,924 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
diff -ru -X linux-2.3.99p8-online/exclude.lst linux-2.3.99p8/CREDITS linux-2.3.99p8-online/CREDITS
--- linux-2.3.99p8/CREDITS	Sun Mar 26 21:34:39 2000
+++ linux-2.3.99p8-online/CREDITS	Sun Mar 26 21:30:34 2000
@@ -559,6 +559,14 @@
 S: Warrendale, Pennsylvania 15086
 S: USA
 
+N: Andreas Dilger
+E: adilger@turbolinux.com
+W: http://www-mddsp.enel.ucalgary.ca/People/adilger/
+D: Ext2 filesystem online resize capability
+S: 630 Schooner Cove N.W.
+S: Calgary, AB
+S: Canada   T3L 1Z1
+
 N: Alex deVries
 E: adevries@thepuffingroup.com
 D: Various SGI parts, bits of HAL2 and Newport, PA-RISC Linux.
diff -ru -X linux-2.3.99p8-online/exclude.lst linux-2.3.99p8/Documentation/Configure.help linux-2.3.99p8-online/Documentation/Configure.help
--- linux-2.3.99p8/Documentation/Configure.help	Sun Mar 26 21:34:39 2000
+++ linux-2.3.99p8-online/Documentation/Configure.help	Mon Mar 27 17:57:36 2000
@@ -10055,6 +10055,20 @@
   compiled as a module, and so this could be dangerous. Most everyone
   wants to say Y here.
 
+Online resize for ext2 filesystems
+CONFIG_EXT2_RESIZE
+  This option gives you the ability to increase the size of an ext2
+  filesystem while it is mounted (in use).  In order to do this, you
+  must also be able to resize the underlying disk partition, probably
+  via a Logical Volume Manager (LVM), metadevice (MD), or hardware
+  RAID device - none of that capability is included in this feature.
+  If you don't know what any of these things are, or you haven't
+  configured your kernel for them, you should probably say N here.  If
+  you choose Y, then your kernel will be about 3k larger, and you need
+  to get some more software (http://ext2resize.sourceforge.net/) in
+  order to actually resize your filesystem, otherwise this feature
+  will just sit unused inside the kernel.
+
 BFS file system support (EXPERIMENTAL)
 CONFIG_BFS_FS
   Boot File System (BFS) is a file system used under SCO UnixWare to
diff -ru -X linux-2.3.99p8-online/exclude.lst linux-2.3.99p8/fs/Config.in linux-2.3.99p8-online/fs/Config.in
--- linux-2.3.99p8/fs/Config.in	Sun Mar 26 21:34:49 2000
+++ linux-2.3.99p8-online/fs/Config.in	Mon Mar 27 18:24:25 2000
@@ -56,6 +56,7 @@
 tristate 'ROM file system support' CONFIG_ROMFS_FS

 tristate 'Second extended fs support' CONFIG_EXT2_FS
+dep_mbool '  Online ext2 resize support (DANGEROUS)' CONFIG_EXT2_RESIZE $CONFIG_EXT2_FS $CONFIG_EXPERIMENTAL

 tristate 'System V and Coherent file system support (read only)' CONFIG_SYSV_FS
 dep_mbool '  SYSV file system write support (DANGEROUS)' CONFIG_SYSV_FS_WRITE $CONFIG_SYSV_FS $CONFIG_EXPERIMENTAL
diff -ru linux-2.3.99p3/fs/ext2/balloc.c linux-2.3.99p3-ext2base/fs/ext2/balloc.c
--- linux-2.3.99p3/fs/ext2/balloc.c	Sun Mar 26 21:34:49 2000
+++ linux-2.3.99p3-ext2base/fs/ext2/balloc.c	Mon Mar 27 02:47:26 2000
@@ -616,13 +616,13 @@
 
 unsigned long ext2_count_free_blocks (struct super_block * sb)
 {
-#ifdef EXT2FS_DEBUG
 	struct ext2_super_block * es;
 	unsigned long desc_count, bitmap_count, x;
 	int bitmap_nr;
 	struct ext2_group_desc * gdp;
 	int i;
-	
+
+	if (test_opt (sb, DEBUG) && test_opt (sb, CHECK)) {
 	lock_super (sb);
 	es = sb->u.ext2_sb.s_es;
 	desc_count = 0;
@@ -643,13 +643,12 @@
 			i, le16_to_cpu(gdp->bg_free_blocks_count), x);
 		bitmap_count += x;
 	}
-	printk("ext2_count_free_blocks: stored = %lu, computed = %lu, %lu\n",
+	printk(__FUNCTION__": stored = %lu, computed gdt = %lu, bitmap = %lu\n",
 	       le32_to_cpu(es->s_free_blocks_count), desc_count, bitmap_count);
 	unlock_super (sb);
 	return bitmap_count;
-#else
+	} else
 	return le32_to_cpu(sb->u.ext2_sb.s_es->s_free_blocks_count);
-#endif
 }
 
 static inline int block_in_use (unsigned long block,
diff -ru -X linux-2.3.99p8-online/exclude.lst linux-2.3.99p8/fs/ext2/super.c linux-2.3.99p8-online/fs/ext2/super.c
--- linux-2.3.99p8/fs/ext2/super.c	Sun Mar 26 21:34:49 2000
+++ linux-2.3.99p8-online/fs/ext2/super.c	Mon Mar 27 18:24:25 2000
@@ -14,6 +14,7 @@
  *
  *  Big-endian to little-endian byte-swapping/bitmaps by
  *        David S. Miller (davem@caip.rutgers.edu), 1995
+ *  Online resize by Andreas Dilger (adilger@turbolinux.com), July 1999
  */
 
 #include <linux/config.h>
@@ -29,6 +29,10 @@
 
 static char error_buf[1024];
 
+#ifndef MIN
+# define MIN(m,n) ((m) < (n) ? (m) : (n))
+#endif
+
 void ext2_error (struct super_block * sb, const char * function,
 		 const char * fmt, ...)
 {
@@ -140,7 +141,9 @@
  */
 static int parse_options (char * options, unsigned long * sb_block,
 			  unsigned short *resuid, unsigned short * resgid,
-			  unsigned long * mount_options)
+			  unsigned long * mount_options,
+			  unsigned long * n_blocks_count,
+			  unsigned long * resgdt)
 {
 	char * this_char;
 	char * value;
@@ -206,6 +209,31 @@
 		else if (!strcmp (this_char, "nogrpid") ||
 			 !strcmp (this_char, "sysvgroups"))
 			clear_opt (*mount_options, GRPID);
+#ifdef CONFIG_EXT2_RESIZE
+		else if (!strcmp (this_char, "resize")) {
+			printk ("EXT2-fs: parse_options: resize=%s\n", value);
+			if (!n_blocks_count) {
+				printk("EXT2-fs: resize option only available "
+				       "for remount\n");
+				return 0;
+			}
+			if (!value || !*value) {
+				printk ("EXT2-fs: resize requires number of "
+					"blocks\n");
+				return 0;
+			}
+			*n_blocks_count = simple_strtoul (value, &value, 0);
+			if (*value == ':') {
+				value++;
+				*resgdt = simple_strtoul (value, &value, 0);
+			}
+			if (*value) {
+				printk ("EXT2-fs: invalid resize option: %s\n",
+					value);
+				return 0;
+			}
+		}
+#endif /* CONFIG_EXT2_RESIZE */
 		else if (!strcmp (this_char, "resgid")) {
 			if (!value || !*value) {
 				printk ("EXT2-fs: the resgid option requires "
@@ -286,10 +290,10 @@
 		mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 		sb->s_dirt = 1;
 		if (test_opt (sb, DEBUG))
-			printk ("[EXT II FS %s, %s, bs=%lu, fs=%lu, gc=%lu, "
+			printk ("[EXT II FS %s, %s, bs=%lu, bc=%u, gc=%lu, "
 				"bpg=%lu, ipg=%lu, mo=%04lx]\n",
 				EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
-				sb->u.ext2_sb.s_frag_size,
+				le32_to_cpu(es->s_blocks_count),
 				sb->u.ext2_sb.s_groups_count,
 				EXT2_BLOCKS_PER_GROUP(sb),
 				EXT2_INODES_PER_GROUP(sb),
@@ -324,7 +352,7 @@
 		if (le32_to_cpu(gdp->bg_block_bitmap) < block ||
 		    le32_to_cpu(gdp->bg_block_bitmap) >= block + EXT2_BLOCKS_PER_GROUP(sb))
 		{
-			ext2_error (sb, "ext2_check_descriptors",
+			ext2_warning (sb, "ext2_check_descriptors",
 				    "Block bitmap for group %d"
 				    " not in group (block %lu)!",
 				    i, (unsigned long) le32_to_cpu(gdp->bg_block_bitmap));
@@ -333,7 +361,7 @@
 		if (le32_to_cpu(gdp->bg_inode_bitmap) < block ||
 		    le32_to_cpu(gdp->bg_inode_bitmap) >= block + EXT2_BLOCKS_PER_GROUP(sb))
 		{
-			ext2_error (sb, "ext2_check_descriptors",
+			ext2_warning (sb, "ext2_check_descriptors",
 				    "Inode bitmap for group %d"
 				    " not in group (block %lu)!",
 				    i, (unsigned long) le32_to_cpu(gdp->bg_inode_bitmap));
@@ -343,7 +371,7 @@
 		    le32_to_cpu(gdp->bg_inode_table) + sb->u.ext2_sb.s_itb_per_group >=
 		    block + EXT2_BLOCKS_PER_GROUP(sb))
 		{
-			ext2_error (sb, "ext2_check_descriptors",
+			ext2_warning (sb, "ext2_check_descriptors",
 				    "Inode table for group %d"
 				    " not in group (block %lu)!",
 				    i, (unsigned long) le32_to_cpu(gdp->bg_inode_table));
@@ -362,6 +366,271 @@
 	return 1;
 }
 
+static int ext2_read_descriptors (struct super_block * sb,
+				  unsigned long blocks_count)
+{
+	int db_orig;
+	int db_count;
+	unsigned long groups_count;
+	unsigned long o_groups_count;
+	struct buffer_head ** group_desc = NULL;
+	struct buffer_head ** o_group_desc;
+	int i, j;
+
+	o_group_desc = EXT2_SB(sb)->s_group_desc;
+	o_groups_count = EXT2_SB(sb)->s_groups_count;
+
+	db_orig = EXT2_SB(sb)->s_db_per_group;
+	groups_count = (blocks_count -
+			le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block) +
+			EXT2_BLOCKS_PER_GROUP(sb) - 1) /
+			EXT2_BLOCKS_PER_GROUP(sb);
+	db_count = (groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
+		   EXT2_DESC_PER_BLOCK(sb);
+	if (test_opt (sb, DEBUG)) {
+		printk ("EXT2-fs: ext2_read_descriptors: o_groups_count=%lu, "
+			"groups_count=%lu, blocks_count=%lu\n", o_groups_count,
+			groups_count, blocks_count);
+		printk ("EXT2-fs: ext2_read_descriptors: db_orig=%lu, "
+			"db_count=%d\n", db_orig, db_count);
+	}
+
+	if (db_orig != db_count) {
+		unsigned long logic_sb_block = EXT2_SB(sb)->s_sbh->b_blocknr;
+
+		group_desc = (struct buffer_head **) kmalloc (db_count *
+				sizeof (struct buffer_head *), GFP_KERNEL);
+		if (group_desc == NULL) {
+			ext2_warning (sb, __FUNCTION__,
+				      "not enough memory for %d groups",
+				      db_count);
+			return -ENOMEM;
+		}
+		for (i = db_orig; i < db_count; i++) {	/* Add group blocks */
+			group_desc[i] = bread (sb->s_dev,
+					       logic_sb_block + i + 1,
+					       sb->s_blocksize);
+			if (!group_desc[i]) {
+				for (j = db_orig; j < i; j++)
+					brelse (group_desc[j]);
+				kfree(group_desc);
+				ext2_warning (sb, __FUNCTION__,
+					      "unable to read group block %d",
+					      i);
+				return -EIO;
+			}
+		}
+
+		/*
+		 * Copy over old descriptor blocks previously loaded, if any.
+		 * We need to set s_group_desc and s_groups_count now so that
+		 * ext2_check_descriptors() will check the new groups as well.
+		 */
+		memcpy (group_desc, o_group_desc, 
+			MIN(db_orig, db_count) * sizeof (struct buffer_head *));
+		EXT2_SB(sb)->s_group_desc = group_desc;
+	}
+	EXT2_SB(sb)->s_groups_count = groups_count;
+
+	if (!ext2_check_descriptors (sb)) {
+		EXT2_SB(sb)->s_groups_count = o_groups_count;
+		EXT2_SB(sb)->s_group_desc = o_group_desc;
+		for (j = db_orig; j < db_count; j++)
+			brelse (group_desc[j]);
+		if (group_desc != NULL)
+			kfree(group_desc);
+		return -EINVAL;
+	}
+
+	if (o_group_desc && o_group_desc != EXT2_SB(sb)->s_group_desc)
+		kfree(o_group_desc);
+
+	EXT2_SB(sb)->s_db_per_group = db_count;
+
+	return 0;
+} /* ext2_read_descriptors */
+
+
+#ifdef CONFIG_EXT2_RESIZE
+/* Make the disk blocks in a new group available to the filesystem */
+static int ext2_update_group (struct super_block * sb, unsigned int block_group,
+			      unsigned int reserved, unsigned int resgdt)
+{
+	struct ext2_group_desc * gdp;
+	struct ext2_super_block * es;
+	int blocks;
+	int m_blocks;
+	int inodes;
+	int shrink = reserved > 100 ? 1 : 0;
+
+	es = EXT2_SB(sb)->s_es;
+	gdp = ext2_get_group_desc (sb, block_group, NULL);
+
+	inodes = le32_to_cpu(gdp->bg_free_inodes_count);
+	blocks = le32_to_cpu(gdp->bg_free_blocks_count);
+	m_blocks = EXT2_SB(sb)->s_itb_per_group + 2 +
+		((!(EXT2_SB(sb)->s_feature_ro_compat &
+		    EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
+		  ext2_group_sparse(block_group)) ?
+		 1 + EXT2_SB(sb)->s_db_per_group + resgdt : 0) + blocks;
+
+	if (block_group < EXT2_SB(sb)->s_groups_count - 1 &&
+	    m_blocks != EXT2_SB(sb)->s_blocks_per_group) {
+		ext2_warning(sb, __FUNCTION__,
+			     "bad group size for %s group %d (%d blocks) "
+			     "(iblk = %d, GDT blk %d, resgdt %d, blocks %d\n",
+			     (!(sb->u.ext2_sb.s_feature_ro_compat &
+				EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
+			      ext2_group_sparse(block_group)) ? "normal" :
+			     "no-backup", block_group, m_blocks,
+			     sb->u.ext2_sb.s_itb_per_group,
+			     sb->u.ext2_sb.s_db_per_group, resgdt, blocks);
+		return -EINVAL;
+	}
+
+	es->s_free_inodes_count =
+		cpu_to_le32(le32_to_cpu(es->s_free_inodes_count) + inodes);
+	es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) +
+		inodes);
+
+	es->s_free_blocks_count =
+		cpu_to_le32(le32_to_cpu(es->s_free_blocks_count) + blocks);
+	es->s_blocks_count = cpu_to_le32(le32_to_cpu(es->s_blocks_count) +
+		m_blocks);
+	es->s_r_blocks_count = cpu_to_le32(le32_to_cpu(es->s_r_blocks_count) +
+		m_blocks * reserved / 100);
+
+	mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
+	sb->s_dirt = 1;
+
+	if (test_opt (sb, DEBUG)) {
+		printk ("EXT2-fs: ext2_update_group: %s %s group %u: "
+			"%u inodes, %u blocks (%u free), %d (%d%%) reserved\n",
+			shrink ? "removing" : "adding",
+			(!(sb->u.ext2_sb.s_feature_ro_compat &
+			   EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
+			 ext2_group_sparse(block_group)) ? "normal" :
+			"no-super", block_group, inodes, m_blocks, blocks,
+			m_blocks * reserved / 100, reserved);
+		printk ("EXT2-fs: ext2_update_group: %u inodes (%u free), "
+			"%u blocks (%u free)\n",
+			le32_to_cpu(es->s_inodes_count),
+			le32_to_cpu(es->s_free_inodes_count),
+			le32_to_cpu(es->s_blocks_count),
+			le32_to_cpu(es->s_free_blocks_count));
+	}
+
+	return 0;
+} /* ext2_update_group */
+
+/* Resize the filesystem to the new number of blocks specified.  If required,
+ * the new group descriptors should have already been configured for us (we
+ * only check that they are valid).
+ */
+static int ext2_resize_fs (struct super_block * sb,
+			   struct ext2_super_block * es,
+			   unsigned long n_blocks_count, unsigned long resgdt)
+{
+	unsigned long o_blocks_count;
+	unsigned long o_groups_count;
+	unsigned long last, add;
+	unsigned long reserved;
+	struct buffer_head * bh;
+	struct inode inode;
+	unsigned long i;
+	int err = 0;
+
+	o_blocks_count = le32_to_cpu(es->s_blocks_count);
+	o_groups_count = sb->u.ext2_sb.s_groups_count;
+
+	if (test_opt (sb, DEBUG))
+		printk ("EXT2-fs: ext2_resize_fs: from %lu to %lu blocks\n",
+			o_blocks_count, n_blocks_count);
+	
+	if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
+		return 0;
+
+	/* Until we can shrink the FS, we need to check this */
+	if (n_blocks_count < o_blocks_count) {
+		ext2_warning (sb, __FUNCTION__, "error: can't shrink FS!");
+		return -EBUSY;
+	}
+
+	/* See if the device is actually as big as what was requested */
+	bh = bread (sb->s_dev, n_blocks_count - 1, EXT2_BLOCK_SIZE(sb));
+	if (!bh) {
+		ext2_warning (sb, __FUNCTION__,
+			      "unable to read last block, resize aborted");
+		return -ENOSPC;
+	}
+	brelse (bh);
+
+	/* For reserved percentage calculation, we avoid 32-bit overflow. */
+	reserved = o_blocks_count > 10000000 ?
+		(le32_to_cpu(es->s_r_blocks_count) + o_blocks_count / 200) /
+			(o_blocks_count / 100) :
+		(le32_to_cpu(es->s_r_blocks_count) * 100 + o_blocks_count / 2) /
+			o_blocks_count;
+
+	if ((err = ext2_read_descriptors (sb, n_blocks_count))) {
+		ext2_warning (sb, __FUNCTION__,
+			      "group descriptor error %d, resize aborted", err);
+		return err;
+	}
+
+	/* Handle the remaining blocks in the last partial group. */
+	last = (o_blocks_count -
+		le32_to_cpu(sb->u.ext2_sb.s_es->s_first_data_block)) %
+		EXT2_BLOCKS_PER_GROUP(sb);
+	if (last != 0) {	/* The last group isn't full yet */
+		add = EXT2_BLOCKS_PER_GROUP(sb) - last;
+		if (add + o_blocks_count > n_blocks_count)
+			add = n_blocks_count - o_blocks_count;
+		es->s_blocks_count =
+			cpu_to_le32(le32_to_cpu(es->s_blocks_count) + add);
+		es->s_r_blocks_count =
+			cpu_to_le32(le32_to_cpu(es->s_r_blocks_count) +
+				    add * reserved / 100);
+		mark_buffer_dirty (sb->u.ext2_sb.s_sbh, 1);
+		sb->s_dirt = 1;
+		/*
+		 * Fake out an inode enough to "free" the new blocks in this
+		 * group.  Turn off quotas for this inode so it doesn't get
+		 * confused by freeing blocks that don't really exist yet.
+		 */
+		inode.i_sb = sb;
+		for (i = 0; i < MAXQUOTAS; i++)
+			inode.i_dquot[i] = NODQUOT;
+		unlock_super(sb);
+		ext2_free_blocks (&inode, o_blocks_count, add);
+		lock_super(sb);
+		if (test_opt (sb, DEBUG))
+			printk ("EXT2-fs: ext2_resize_fs: added %lu new blocks "
+				"to %lu blocks in last group\n",
+				add, o_blocks_count);
+	}
+
+	/*
+	 * Update superblock with remaining new group block/inode counts
+	 */
+	for (i = o_groups_count; i < sb->u.ext2_sb.s_groups_count &&
+	     !(err = ext2_update_group (sb, i, reserved, resgdt)); i++)
+		/* empty loop */;
+	if (err || le32_to_cpu(es->s_blocks_count) != n_blocks_count) {
+		ext2_warning (sb, __FUNCTION__,
+			      "specified size does not match new block count "
+			      "(%lu != %u) (err %d)", n_blocks_count,
+			      le32_to_cpu(es->s_blocks_count), err);
+		sb->u.ext2_sb.s_mount_state &= ~EXT2_VALID_FS;
+	} else
+		sb->u.ext2_sb.s_mount_state |= EXT2_VALID_FS;
+
+	return err;
+} /* ext2_resize_fs */
+#else  /* !CONFIG_EXT2_RESIZE */
+#define ext2_resize_fs(sb, es, n_blocks_count, resgdt) 0
+#endif /* CONFIG_EXT2_RESIZE */
 
 #define log2(n) ffz(~(n))
 
@@ -478,7 +681,7 @@
 
 	sb->u.ext2_sb.s_mount_opt = 0;
 	if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
-	    &sb->u.ext2_sb.s_mount_opt)) {
+	    &sb->u.ext2_sb.s_mount_opt, NULL, NULL)) {
 		return NULL;
 	}
 
@@ -370,8 +465,7 @@
 	kdev_t dev = sb->s_dev;
 	int blocksize = BLOCK_SIZE;
 	int hblock;
-	int db_count;
-	int i, j;
+	int i;
 
 	/*
 	 * See what the current blocksize for the device is, and
@@ -561,35 +655,12 @@
 		goto failed_mount;
 	}
 
-	sb->u.ext2_sb.s_groups_count = (le32_to_cpu(es->s_blocks_count) -
-				        le32_to_cpu(es->s_first_data_block) +
-				       EXT2_BLOCKS_PER_GROUP(sb) - 1) /
-				       EXT2_BLOCKS_PER_GROUP(sb);
-	db_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
-		   EXT2_DESC_PER_BLOCK(sb);
-	sb->u.ext2_sb.s_group_desc = kmalloc (db_count * sizeof (struct buffer_head *), GFP_KERNEL);
-	if (sb->u.ext2_sb.s_group_desc == NULL) {
-		printk ("EXT2-fs: not enough memory\n");
-		goto failed_mount;
-	}
-	for (i = 0; i < db_count; i++) {
-		sb->u.ext2_sb.s_group_desc[i] = bread (dev, logic_sb_block + i + 1,
-						       sb->s_blocksize);
-		if (!sb->u.ext2_sb.s_group_desc[i]) {
-			for (j = 0; j < i; j++)
-				brelse (sb->u.ext2_sb.s_group_desc[j]);
-			kfree_s (sb->u.ext2_sb.s_group_desc,
-				 db_count * sizeof (struct buffer_head *));
-			printk ("EXT2-fs: unable to read group descriptors\n");
-			goto failed_mount;
-		}
-	}
-	if (!ext2_check_descriptors (sb)) {
-		for (j = 0; j < db_count; j++)
-			brelse (sb->u.ext2_sb.s_group_desc[j]);
-		kfree_s (sb->u.ext2_sb.s_group_desc,
-			 db_count * sizeof (struct buffer_head *));
-		printk ("EXT2-fs: group descriptors corrupted !\n");
+	sb->u.ext2_sb.s_db_per_group = 0;
+	sb->u.ext2_sb.s_groups_count = 0;
+	sb->u.ext2_sb.s_group_desc = NULL;
+	if ((i = ext2_read_descriptors (sb, le32_to_cpu(es->s_blocks_count)))) {
+		ext2_error (sb, __FUNCTION__,
+			    "group descriptor error %d, unable to mount", i);
 		goto failed_mount;
 	}
 	for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
@@ -594,7 +666,6 @@
 	}
 	sb->u.ext2_sb.s_loaded_inode_bitmaps = 0;
 	sb->u.ext2_sb.s_loaded_block_bitmaps = 0;
-	sb->u.ext2_sb.s_db_per_group = db_count;
 	/*
 	 * set up enough so that it can read an inode
 	 */
@@ -608,11 +679,12 @@
 	sb->s_op = &ext2_sops;
 	sb->s_root = d_alloc_root(iget(sb, EXT2_ROOT_INO));
 	if (!sb->s_root) {
-		for (i = 0; i < db_count; i++)
+		for (i = 0; i < sb->u.ext2_sb.s_db_per_group; i++)
 			if (sb->u.ext2_sb.s_group_desc[i])
 				brelse (sb->u.ext2_sb.s_group_desc[i]);
 		kfree_s (sb->u.ext2_sb.s_group_desc,
-			 db_count * sizeof (struct buffer_head *));
+			 sb->u.ext2_sb.s_db_per_group *
+			 sizeof (struct buffer_head *));
 		brelse (bh);
 		printk ("EXT2-fs: get root inode failed\n");
 		return NULL;
@@ -724,6 +927,8 @@
 	struct ext2_super_block * es;
 	unsigned short resuid = sb->u.ext2_sb.s_resuid;
 	unsigned short resgid = sb->u.ext2_sb.s_resgid;
+	unsigned long n_blocks_count = 0;
+	unsigned long resgdt = 0;
 	unsigned long new_mount_opt;
 	unsigned long tmp;
 
@@ -731,14 +936,16 @@
 	 * Allow the "check" option to be passed as a remount option.
 	 */
 	if (!parse_options (data, &tmp, &resuid, &resgid,
-			    &new_mount_opt))
+			    &new_mount_opt, &n_blocks_count, &resgdt))
 		return -EINVAL;
 
 	sb->u.ext2_sb.s_mount_opt = new_mount_opt;
 	sb->u.ext2_sb.s_resuid = resuid;
 	sb->u.ext2_sb.s_resgid = resgid;
 	es = sb->u.ext2_sb.s_es;
-	if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
+	if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY) &&
+	    (n_blocks_count == 0 ||
+	     n_blocks_count == le32_to_cpu(es->s_blocks_count)))
 		return 0;
 	if (*flags & MS_RDONLY) {
 		if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
@@ -762,6 +968,8 @@
 		 */
 		sb->u.ext2_sb.s_mount_state = le16_to_cpu(es->s_state);
 		sb->s_flags &= ~MS_RDONLY;
+		if ((tmp = ext2_resize_fs (sb, es, n_blocks_count, resgdt)))
+			return tmp;
 		ext2_setup_super (sb, es);
 	}
 	return 0;
diff -ru -X linux-2.3.99p8-online/exclude.lst linux-2.3.99p8/include/linux/ext2_fs.h linux-2.3.99p8-online/include/linux/ext2_fs.h
--- linux-2.3.99p8/include/linux/ext2_fs.h	Sun Mar 26 21:34:55 2000
+++ linux-2.3.99p8-online/include/linux/ext2_fs.h	Mon Mar 27 18:12:12 2000
@@ -61,6 +61,7 @@
 #define EXT2_ACL_DATA_INO	 4	/* ACL inode */
 #define EXT2_BOOT_LOADER_INO	 5	/* Boot loader inode */
 #define EXT2_UNDEL_DIR_INO	 6	/* Undelete directory inode */
+#define EXT2_RESIZE_INO		 7	/* Reserved group descriptors inode */
 
 /* First non-reserved inode for old ext2 filesystems */
 #define EXT2_GOOD_OLD_FIRST_INO	11