--- /dev/null	Tue Jan  1 05:00:00 1980
+++ alloc.c	Tue Jul 20 20:52:32 1999
@@ -0,0 +1,38 @@
+/*
+    alloc.c -- generic memory allocation
+    Copyright (C) 1998,99 Lennert Buytenhek <buytenh@dsv.nl>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+static const char _alloc_c[] = "$Id: rawio.diff,v 1.1 2000/10/20 20:40:20 adilger Exp $";
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include "ext2.h"
+
+void *aalloc(unsigned int size)
+{
+	return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+}
+
+int afree(void *ptr, unsigned int size)
+{
+	return munmap(ptr, size);
+}
--- Makefile.am	1999/07/10 19:34:33	1.3
+++ Makefile.am	1999/07/20 17:24:19
@@ -3,7 +3,7 @@
 
 bin_PROGRAMS = ext2resize
 
-ext2resize_SOURCES = ext2.c ext2_block.c ext2_block_relocator.c ext2_buffer.c ext2_inode_relocator.c ext2_journal.c ext2_resize.c llseek.c tune.c ext2resize.c
+ext2resize_SOURCES = alloc.c ext2.c ext2_block.c ext2_block_relocator.c ext2_buffer.c ext2_inode_relocator.c ext2_journal.c ext2_resize.c llseek.c tune.c ext2resize.c
 
 noinst_HEADERS = ext2.h
 
--- ext2.c	1999/07/20 18:51:52	1.43
+++ ext2.c	1999/07/20 18:15:22
@@ -42,13 +42,17 @@
 
 void ext2_copy_block(struct ext2_fs *fs, blk_t from, blk_t to)
 {
-	unsigned char buf[fs->blocksize];
+	unsigned char *buf;
 
 	ext2_bcache_flush(fs, from);
 	ext2_bcache_flush(fs, to);
 
+	buf = aalloc(fs->blocksize);
+
 	ext2_read_blocks(fs, buf, from, 1);
 	ext2_write_blocks(fs, buf, to, 1);
+
+	afree(buf, fs->blocksize);
 }
 
 blk_t ext2_find_free_block(struct ext2_fs *fs, int group)
@@ -71,9 +75,9 @@
 		}
 	}
 
-	offset = grp * fs->sb.s_blocks_per_group + fs->sb.s_first_data_block;
+	offset = grp * fs->sb->s_blocks_per_group + fs->sb->s_first_data_block;
 
-	for (i=0;i<fs->sb.s_blocks_per_group;i++)
+	for (i=0;i<fs->sb->s_blocks_per_group;i++)
 		if (ext2_is_data_block(fs, i) && !ext2_get_block_state(fs, offset + i))
 			return offset + i;
 
@@ -101,8 +105,8 @@
 		}
 	}
 
-	offset = grp * fs->sb.s_inodes_per_group + 1;
-	for (i=0;i<fs->sb.s_inodes_per_group;i++)
+	offset = grp * fs->sb->s_inodes_per_group + 1;
+	for (i=0;i<fs->sb->s_inodes_per_group;i++)
 		if (!ext2_get_inode_state(fs, offset + i))
 			return offset + i;
 
@@ -118,7 +122,11 @@
 	if (fs->readoff != offset)
 		llseek(fs->fdread, offset, SEEK_SET);
 
-	read(fs->fdread, ptr, numblocks << fs->logsize);
+	if (read(fs->fdread, ptr, numblocks << fs->logsize) < 0)
+	{
+		perror("read");
+		exit(-1);
+	}
 	fs->readoff = ((loff_t)block+numblocks) << fs->logsize;
 }
 
@@ -130,7 +138,11 @@
 	if (fs->writeoff != offset)
 		llseek(fs->fdwrite, offset, SEEK_SET);
 
-	write(fs->fdwrite, ptr, numblocks << fs->logsize);
+	if (write(fs->fdwrite, ptr, numblocks << fs->logsize) < 0)
+	{
+		perror("write");
+		exit(-1);
+	}
 	fs->writeoff = ((loff_t)block+numblocks) << fs->logsize;
 }
 
@@ -170,8 +182,8 @@
 
 	inode--;
 
-	group = inode / fs->sb.s_inodes_per_group;
-	offset = (inode % fs->sb.s_inodes_per_group) * sizeof(struct ext2_inode);
+	group = inode / fs->sb->s_inodes_per_group;
+	offset = (inode % fs->sb->s_inodes_per_group) * sizeof(struct ext2_inode);
 
 	*block = fs->gd[group].bg_inode_table + (offset >> fs->logsize);
 
@@ -186,8 +198,8 @@
 	int                      ret;
 
 	inode--;
-	group = inode / fs->sb.s_inodes_per_group;
-	offset = inode % fs->sb.s_inodes_per_group;
+	group = inode / fs->sb->s_inodes_per_group;
+	offset = inode % fs->sb->s_inodes_per_group;
 
 	bh = ext2_bread(fs, fs->gd[group].bg_inode_bitmap);
 	ret = bh->data[offset>>3] & _bitmap[offset&7];
@@ -216,8 +228,8 @@
 	int                      offset;
 
 	inode--;
-	group = inode / fs->sb.s_inodes_per_group;
-	offset = inode % fs->sb.s_inodes_per_group;
+	group = inode / fs->sb->s_inodes_per_group;
+	offset = inode % fs->sb->s_inodes_per_group;
 
 	bh = ext2_bread(fs, fs->gd[group].bg_inode_bitmap);
 	bh->dirty = 1;
@@ -234,7 +246,7 @@
 		diff = state ? -1 : 1;
 
 		fs->gd[group].bg_free_inodes_count += diff;
-		fs->sb.s_free_inodes_count += diff;
+		fs->sb->s_free_inodes_count += diff;
 		fs->metadirty = 1;
 	}
 }
@@ -307,12 +319,12 @@
 	ext2_journal_deinit(fs);
 
 	if (fs->metadirty)
-		fs->sb.s_r_blocks_count = (fs->r_frac * (loff_t)fs->sb.s_blocks_count) / 100;
+		fs->sb->s_r_blocks_count = (fs->r_frac * (loff_t)fs->sb->s_blocks_count) / 100;
 
 	ext2_commit_metadata(fs, 1);
 	ext2_sync(fs);
 
-	free(fs->relocator_pool);
+	afree(fs->relocator_pool, ext2_relocator_pool_size << 10);
 
 	ext2_bgbitmap_cache_deinit(fs);
 	ext2_bcache_deinit(fs);
@@ -321,7 +333,7 @@
 	close(fs->fdread);
 
 	free(fs->bg_bitmap);
-	free(fs->gd);
+	afree(fs->gd, ext2_max_groups * sizeof(struct ext2_group_desc));
 	free(fs);
 }
 
@@ -337,11 +349,11 @@
 
 	memset(sb, 0, fs->blocksize);
 
-	sboffset = fs->sb.s_first_data_block;
+	sboffset = fs->sb->s_first_data_block;
 	if (sboffset)
-		memcpy(sb, &fs->sb, 1024);
+		memcpy(sb, fs->sb, 1024);
 	else
-		memcpy(sb+1024, &fs->sb, 1024);
+		memcpy(sb+1024, fs->sb, 1024);
 
 	num = 1;
 	if (all_copies)
@@ -360,7 +372,7 @@
 		if (!ext2_is_group_sparse(fs, i))
 			continue;
 
-		sb_block = sboffset + i * fs->sb.s_blocks_per_group;
+		sb_block = sboffset + i * fs->sb->s_blocks_per_group;
 
 		bh = ext2_bcreate(fs, sb_block);
 		memcpy(bh->data, sb, fs->blocksize);
@@ -398,84 +410,90 @@
 		goto err;
 	}
 
-	if ((fs->gd = (struct ext2_group_desc *)malloc(ext2_max_groups * sizeof(struct ext2_group_desc))) == NULL)
+	if ((fs->sb = (struct ext2_super_block *)aalloc(sizeof(struct ext2_super_block))) == NULL)
 	{
 		fprintf(stderr, "ext2_open: MAerror!\n");
 		goto err1;
 	}
 
-	if ((fs->bg_bitmap = (struct ext2_buffer_head **)malloc(ext2_max_groups * sizeof(struct ext2_buffer_head *))) == NULL)
+	if ((fs->gd = (struct ext2_group_desc *)aalloc(ext2_max_groups * sizeof(struct ext2_group_desc))) == NULL)
 	{
 		fprintf(stderr, "ext2_open: MAerror!\n");
 		goto err2;
 	}
 
-	if ((fs->relocator_pool = (unsigned char *)malloc(ext2_relocator_pool_size << 10)) == NULL)
+	if ((fs->bg_bitmap = (struct ext2_buffer_head **)malloc(ext2_max_groups * sizeof(struct ext2_buffer_head *))) == NULL)
 	{
 		fprintf(stderr, "ext2_open: MAerror!\n");
 		goto err3;
 	}
+
+	if ((fs->relocator_pool = (unsigned char *)aalloc(ext2_relocator_pool_size << 10)) == NULL)
+	{
+		fprintf(stderr, "ext2_open: MAerror!\n");
+		goto err4;
+	}
 	fs->relocator_pool_end = fs->relocator_pool + (ext2_relocator_pool_size << 10);
 
 	if ((fs->fdread = open(name, O_RDONLY)) < 0)
 	{
 		perror("open");
-		goto err4;
+		goto err5;
 	}
 
 	if ((fs->fdwrite = open(name, O_WRONLY)) < 0)
 	{
 		perror("dup");
-		goto err5;
+		goto err6;
 	}
 
 	if (fstat(fs->fdread, &st) < 0)
 	{
 		perror("stat");
-		goto err6;
+		goto err7;
 	}
 
 	fs->readoff = 0;
 	fs->writeoff = 0;
 	fs->logsize = 10;
-	ext2_read_blocks(fs, &fs->sb, 1, 1);
+	ext2_read_blocks(fs, fs->sb, 1, 1);
 
-	if (fs->sb.s_magic != EXT2_SUPER_MAGIC)
+	if (fs->sb->s_magic != EXT2_SUPER_MAGIC)
 	{
 		fprintf(stderr, "ext2_open: invalid superblock\n");
-		goto err6;
+		goto err7;
 	}
 
-	if (fs->sb.s_state & EXT2_ERROR_FS)
+	if (fs->sb->s_state & EXT2_ERROR_FS)
 	{
 		fprintf(stderr, "ext2_open: filesystem has errors! e2fsck first!\n");
-		goto err6;
+		goto err7;
 	}
 
-	if (!(fs->sb.s_state & EXT2_VALID_FS))
+	if (!(fs->sb->s_state & EXT2_VALID_FS))
 	{
 		fprintf(stderr, "ext2_open: filesystem was not cleanly unmounted! e2fsck first!\n");
-		goto err6;
+		goto err7;
 	}
 
-	if (fs->sb.s_feature_compat ||
-	    fs->sb.s_feature_incompat ||
-	    (fs->sb.s_feature_ro_compat & ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))
+	if (fs->sb->s_feature_compat ||
+	    fs->sb->s_feature_incompat ||
+	    (fs->sb->s_feature_ro_compat & ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))
 	{
 		fprintf(stderr, "ext2_open: fs has incompatible feature enabled\n");
-		goto err6;
+		goto err7;
 	}
 
 	/* This is needed for the buffer cache initialization (enough
 	   buffer heads must be allocated for the whole buffer cache
 	   pool, and the number of buffer heads depends upon the size
 	   of the blocks we divide the buffer cache pool in) */
-	fs->logsize = fs->sb.s_log_block_size + 10;
+	fs->logsize = fs->sb->s_log_block_size + 10;
 
 	if (!ext2_bcache_init(fs))
 	{
 		fprintf(stderr, "ext2_open: MAerror!\n");
-		goto err6;
+		goto err7;
 	}
 
 	/* From this point on all is well. No more memory allocations
@@ -483,46 +501,52 @@
 
 	fs->blocksize = 1 << fs->logsize;
 
-	fs->numgroups = howmany(fs->sb.s_blocks_count-fs->sb.s_first_data_block, fs->sb.s_blocks_per_group);
+	fs->numgroups = howmany(fs->sb->s_blocks_count-fs->sb->s_first_data_block, fs->sb->s_blocks_per_group);
 	fs->gdblocks = howmany(fs->numgroups * sizeof(struct ext2_group_desc), fs->blocksize);
-	fs->inodeblocks = howmany(fs->sb.s_inodes_per_group * sizeof(struct ext2_inode), fs->blocksize);
-	fs->r_frac = howmany(100 * (u_int64_t)fs->sb.s_r_blocks_count, fs->sb.s_blocks_count);
+	fs->inodeblocks = howmany(fs->sb->s_inodes_per_group * sizeof(struct ext2_inode), fs->blocksize);
+	fs->r_frac = howmany(100 * (u_int64_t)fs->sb->s_r_blocks_count, fs->sb->s_blocks_count);
 	fs->adminblocks = 3 + fs->gdblocks + fs->inodeblocks;
 
 	fs->sparse = 0;
-	if (fs->sb.s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
+	if (fs->sb->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
 		fs->sparse = 1;
 
-	ext2_read_blocks(fs, fs->gd, fs->sb.s_first_data_block + 1, fs->gdblocks);
+	ext2_read_blocks(fs, fs->gd, fs->sb->s_first_data_block + 1, fs->gdblocks);
 
+#if 0
 	if (S_ISBLK(st.st_mode))      /* Thanks to Rolf Jakob */
 	{
 		if (ioctl(fs->fdread, BLKGETSIZE, &fs->containersize) < 0)
 		{
 			perror("ioctl");
-			goto err6;
+			goto err7;
 		}
 
 		fs->containersize >>= fs->logsize - 9;
 	}
 	else
 		fs->containersize = st.st_blocks >> (fs->logsize - 9);
+#else
+	fs->containersize = 90000;
+#endif
 
 	ext2_bgbitmap_cache_init(fs);
 	ext2_journal_init(fs);
 
 	return fs;
 
- err6:
+ err7:
 	close(fs->fdwrite);
- err5:
+ err6:
 	close(fs->fdread);
+ err5:
+	afree(fs->relocator_pool, ext2_relocator_pool_size << 10);
  err4:
-	free(fs->relocator_pool);
- err3:
 	free(fs->bg_bitmap);
+ err3:
+	afree(fs->gd, ext2_max_groups * sizeof(struct ext2_group_desc));
  err2:
-	free(fs->gd);
+	afree(fs->sb, 1024);
  err1:
 	free(fs);
  err:
--- ext2.h	1999/07/18 22:11:43	1.39
+++ ext2.h	1999/07/20 17:26:41
@@ -225,7 +225,7 @@
 	int				  fdwrite;
 	loff_t				  writeoff;
 
-	struct ext2_super_block		  sb;
+	struct ext2_super_block		 *sb;
 	struct ext2_group_desc		 *gd;
 	int				  metadirty;			/* 0:all sb&gd copies clean
 									   1:all sb&gd copies dirty
@@ -257,6 +257,8 @@
 
 
 
+void	       *aalloc				(unsigned int size);
+int		afree				(void *ptr, unsigned int size);
 loff_t		llseek				(unsigned int fd, loff_t offset, unsigned int whence);
 
 /* generic stuff */
@@ -315,13 +317,13 @@
 	blk_t blk;
 	int   group;
 
-	if (block >= fs->sb.s_blocks_count)
+	if (block >= fs->sb->s_blocks_count)
 		fprintf(stderr, "is_data_block(%i): block number invalid!\n", block);
 
-	blk = block - fs->sb.s_first_data_block;
+	blk = block - fs->sb->s_first_data_block;
 
-	group = blk / fs->sb.s_blocks_per_group;
-	blk %= fs->sb.s_blocks_per_group;
+	group = blk / fs->sb->s_blocks_per_group;
+	blk %= fs->sb->s_blocks_per_group;
 
 	if (ext2_is_group_sparse(fs, group) && blk <= fs->gdblocks)
 		return 0;
--- ext2_block.c	1999/07/18 22:11:48	1.12
+++ ext2_block.c	1999/07/20 17:27:01
@@ -68,9 +68,9 @@
 	int group;
 	int offset;
 
-	block -= fs->sb.s_first_data_block;
-	group = block / fs->sb.s_blocks_per_group;
-	offset = block % fs->sb.s_blocks_per_group;
+	block -= fs->sb->s_first_data_block;
+	group = block / fs->sb->s_blocks_per_group;
+	offset = block % fs->sb->s_blocks_per_group;
 
 	ext2_bgbitmap_cache_force_in(fs, group);
 
@@ -83,9 +83,9 @@
 	int                      group;
 	int                      offset;
 
-	block -= fs->sb.s_first_data_block;
-	group = block/fs->sb.s_blocks_per_group;
-	offset = block%fs->sb.s_blocks_per_group;
+	block -= fs->sb->s_first_data_block;
+	group = block/fs->sb->s_blocks_per_group;
+	offset = block%fs->sb->s_blocks_per_group;
 
 	ext2_bgbitmap_cache_force_in(fs, group);
 
@@ -103,7 +103,7 @@
 		diff = state ? -1 : 1;
 
 		fs->gd[group].bg_free_blocks_count += diff;
-		fs->sb.s_free_blocks_count += diff;
+		fs->sb->s_free_blocks_count += diff;
 		fs->metadirty = 1;
 	}
 }
--- ext2_block_relocator.c	1999/07/13 15:39:38	1.31
+++ ext2_block_relocator.c	1999/07/20 17:27:15
@@ -238,7 +238,7 @@
 	{
 		qsort(state->block, state->usedentries, sizeof(struct ext2_block_entry), compare_block_entries);
 
-		for (i=1;i<=fs->sb.s_inodes_count;i++)
+		for (i=1;i<=fs->sb->s_inodes_count;i++)
 			if (ext2_get_inode_state(fs, i))
 				doinode(fs, state, i);
 
@@ -298,7 +298,7 @@
 	printf("ext2_block_relocate_grow\n");
 #endif
 
-	newgroups = howmany(newsize - fs->sb.s_first_data_block, fs->sb.s_blocks_per_group);
+	newgroups = howmany(newsize - fs->sb->s_first_data_block, fs->sb->s_blocks_per_group);
 	newgdblocks = howmany(newgroups * sizeof(struct ext2_group_desc), fs->blocksize);
 	diff = newgdblocks - fs->gdblocks;
 
@@ -309,7 +309,7 @@
 			blk_t start;
 			blk_t j;
 
-			start = i*fs->sb.s_blocks_per_group + fs->sb.s_first_data_block;
+			start = i*fs->sb->s_blocks_per_group + fs->sb->s_first_data_block;
 
 			for (j=0;j<diff;j++)
 				if (ext2_get_block_state(fs, start + fs->adminblocks + j))
@@ -331,7 +331,7 @@
 	printf("ext2_block_relocate_shrink\n");
 #endif
 
-	diff = howmany(newsize - fs->sb.s_first_data_block, fs->sb.s_blocks_per_group);
+	diff = howmany(newsize - fs->sb->s_first_data_block, fs->sb->s_blocks_per_group);
 	diff = howmany(diff * sizeof(struct ext2_group_desc), fs->blocksize);
 	diff = fs->gdblocks - diff;
 
@@ -345,8 +345,8 @@
 		int   type;
 
 		sparse = ext2_is_group_sparse(fs, i);
-		offset = i*fs->sb.s_blocks_per_group + fs->sb.s_first_data_block;
-		end = offset + fs->sb.s_blocks_per_group;
+		offset = i*fs->sb->s_blocks_per_group + fs->sb->s_first_data_block;
+		end = offset + fs->sb->s_blocks_per_group;
 
 		if (newsize >= end)
 			type = 0;
@@ -402,7 +402,7 @@
 	state.newsize = newsize;
 	state.block = (struct ext2_block_entry *)fs->relocator_pool;
 
-	if (newsize < fs->sb.s_blocks_count)
+	if (newsize < fs->sb->s_blocks_count)
 		return ext2_block_relocate_shrink(fs, &state, newsize);
 
 	return ext2_block_relocate_grow(fs, &state, newsize);
--- ext2_buffer.c	1999/07/18 21:53:16	1.26
+++ ext2_buffer.c	1999/07/20 17:38:40
@@ -220,7 +220,7 @@
 void ext2_bcache_deinit(struct ext2_fs *fs)
 {
 	ext2_bcache_sync(fs);
-	free(fs->bc->buffermem);
+	afree(fs->bc->buffermem, ext2_buffer_cache_pool_size << 10);
 	free(fs->bc->hash);
 	free(fs->bc->heads);
 	free(fs->bc);
@@ -283,7 +283,7 @@
 		return 0;
 	}
 
-	if ((bc->buffermem = (unsigned char *)malloc(ext2_buffer_cache_pool_size << 10)) == NULL)
+	if ((bc->buffermem = (unsigned char *)aalloc(ext2_buffer_cache_pool_size << 10)) == NULL)
 	{
 		fprintf(stderr, "MAError!\n");
 		free(bc->hash);
--- ext2_inode_relocator.c	1999/07/13 15:40:47	1.29
+++ ext2_inode_relocator.c	1999/07/20 17:27:34
@@ -236,8 +236,8 @@
 		int oldgroup;
 		int newgroup;
 
-		oldgroup = (entry->num  - 1) / fs->sb.s_inodes_per_group;
-		newgroup = (entry->dest - 1) / fs->sb.s_inodes_per_group;
+		oldgroup = (entry->num  - 1) / fs->sb->s_inodes_per_group;
+		newgroup = (entry->dest - 1) / fs->sb->s_inodes_per_group;
 
 		fs->gd[oldgroup].bg_used_dirs_count--;
 		fs->gd[newgroup].bg_used_dirs_count++;
@@ -280,7 +280,7 @@
 
 	if (state->usedentries)
 	{
-		for (i=1;i<=fs->sb.s_inodes_count;i++)
+		for (i=1;i<=fs->sb->s_inodes_count;i++)
 			if (ext2_get_inode_state(fs, i))
 				doinode(fs, state, i);
 
@@ -350,7 +350,7 @@
 	state.inode = (struct ext2_inode_entry *)fs->relocator_pool;
 	state.last = (struct ext2_reference *)fs->relocator_pool_end;
 
-	for (i=lastinode+1;i<=fs->sb.s_inodes_count;i++)
+	for (i=lastinode+1;i<=fs->sb->s_inodes_count;i++)
 		if (ext2_get_inode_state(fs, i))
 			ext2_inode_relocator_mark(fs, &state, i);
 
--- ext2_journal.c	1999/07/11 13:07:03	1.7
+++ ext2_journal.c	1999/07/20 17:27:44
@@ -90,13 +90,13 @@
 
 	numblocks = ext2_journal_size >> (fs->logsize - 10);
 
-	if (!fs->sb.s_free_inodes_count)
+	if (!fs->sb->s_free_inodes_count)
 	{
 		fprintf(stderr, "need at least 1 free inode for a journal!\n");
 		return 0;
 	}
 
-	if (fs->sb.s_free_blocks_count < numblocks+1)
+	if (fs->sb->s_free_blocks_count < numblocks+1)
 	{
 		fprintf(stderr, "need at least %i free data blocks\n", numblocks+1);
 		return 0;
--- ext2_resize.c	1999/07/20 18:52:01	1.34
+++ ext2_resize.c	1999/07/20 18:17:12
@@ -41,7 +41,7 @@
 
 	printf("ext2_add_group\n");
 
-	if (fs->sb.s_blocks_count != fs->sb.s_first_data_block + fs->numgroups * fs->sb.s_blocks_per_group)
+	if (fs->sb->s_blocks_count != fs->sb->s_first_data_block + fs->numgroups * fs->sb->s_blocks_per_group)
 	{
 		fprintf(stderr, "ext2_add_group: last (existing) group isn't complete!\n");
 		return;
@@ -49,19 +49,19 @@
 
 	group = fs->numgroups;
 	sparse = ext2_is_group_sparse(fs, group);
-	groupstart = fs->sb.s_first_data_block + group * fs->sb.s_blocks_per_group;
+	groupstart = fs->sb->s_first_data_block + group * fs->sb->s_blocks_per_group;
 
 	admin = fs->adminblocks;
 	if (!sparse)
 		admin -= fs->gdblocks + 1;
 
-	if (groupsize < fs->adminblocks || groupsize > fs->sb.s_blocks_per_group)
+	if (groupsize < fs->adminblocks || groupsize > fs->sb->s_blocks_per_group)
 	{
 		fprintf(stderr, "ext2_add_group: groups of %i blocks are impossible!\n", groupsize);
 		return;
 	}
 
-	if (fs->sb.s_blocks_count + groupsize > fs->containersize)
+	if (fs->sb->s_blocks_count + groupsize > fs->containersize)
 	{
 		fprintf(stderr, "ext2_add_group: container is not big enough for another group of %i blocks!\n", groupsize);
 		return;
@@ -82,7 +82,7 @@
 			}
 
 			fs->gd[i].bg_free_blocks_count--;
-			fs->sb.s_free_blocks_count--;
+			fs->sb->s_free_blocks_count--;
 
 			ext2_set_block_state(fs, fromblock, 1, 0);
 
@@ -125,10 +125,10 @@
 
 	fs->metadirty = 1;
 
-	fs->sb.s_inodes_count += fs->sb.s_inodes_per_group;
-	fs->sb.s_blocks_count += groupsize;
-	fs->sb.s_free_blocks_count += groupsize - admin;
-	fs->sb.s_free_inodes_count += fs->sb.s_inodes_per_group;
+	fs->sb->s_inodes_count += fs->sb->s_inodes_per_group;
+	fs->sb->s_blocks_count += groupsize;
+	fs->sb->s_free_blocks_count += groupsize - admin;
+	fs->sb->s_free_inodes_count += fs->sb->s_inodes_per_group;
 
 	{
 		int off;
@@ -152,7 +152,7 @@
 	}
 
 	fs->gd[group].bg_free_blocks_count = groupsize - admin;
-	fs->gd[group].bg_free_inodes_count = fs->sb.s_inodes_per_group;
+	fs->gd[group].bg_free_inodes_count = fs->sb->s_inodes_per_group;
 	fs->gd[group].bg_used_dirs_count   = 0;
 
 	{
@@ -181,7 +181,7 @@
 			bh->data[j>>3] |= _bitmap[j&7];
 		}
 
-		for (i=groupsize;i<fs->sb.s_blocks_per_group;i++)
+		for (i=groupsize;i<fs->sb->s_blocks_per_group;i++)
 			bh->data[i>>3] |= _bitmap[i&7];
 
 		ext2_brelse(bh, 0);         /* this is a block bitmap */
@@ -209,21 +209,21 @@
 	if (!sparse)
 		admin -= fs->gdblocks + 1;
 
-	groupsize = fs->sb.s_blocks_count - fs->sb.s_first_data_block - group * fs->sb.s_blocks_per_group;
+	groupsize = fs->sb->s_blocks_count - fs->sb->s_first_data_block - group * fs->sb->s_blocks_per_group;
 
-	if (fs->sb.s_free_blocks_count < groupsize - admin)
+	if (fs->sb->s_free_blocks_count < groupsize - admin)
 	{
 		fprintf(stderr, "ext2_del_group: filesystem is too occupied to remove a group!\n");
 		return;
 	}
 
-	if (fs->sb.s_free_inodes_count < fs->sb.s_inodes_per_group)
+	if (fs->sb->s_free_inodes_count < fs->sb->s_inodes_per_group)
 	{
 		fprintf(stderr, "ext2_del_group: filesystem has too many allocated inodes to remove a group!\n");
 		return;
 	}
 
-	if (fs->gd[group].bg_free_inodes_count != fs->sb.s_inodes_per_group)
+	if (fs->gd[group].bg_free_inodes_count != fs->sb->s_inodes_per_group)
 	{
 		fprintf(stderr, "ext2_del_group: this should not happen anymore!\n");
 		return;
@@ -293,8 +293,8 @@
 		blk_t num;
 		blk_t offset;
 
-		offset = fs->sb.s_first_data_block + group * fs->sb.s_blocks_per_group;
-		num = fs->sb.s_blocks_per_group;
+		offset = fs->sb->s_first_data_block + group * fs->sb->s_blocks_per_group;
+		num = fs->sb->s_blocks_per_group;
 
 		for (i=0;i<num;i++)
 			if (ext2_is_data_block(fs, offset+i) && ext2_get_block_state(fs, offset+i))
@@ -306,10 +306,10 @@
 
 	fs->numgroups--;
 
-	fs->sb.s_inodes_count -= fs->sb.s_inodes_per_group;
-	fs->sb.s_blocks_count -= groupsize;
-	fs->sb.s_free_blocks_count -= groupsize - admin;
-	fs->sb.s_free_inodes_count -= fs->sb.s_inodes_per_group;
+	fs->sb->s_inodes_count -= fs->sb->s_inodes_per_group;
+	fs->sb->s_blocks_count -= groupsize;
+	fs->sb->s_free_blocks_count -= groupsize - admin;
+	fs->sb->s_free_inodes_count -= fs->sb->s_inodes_per_group;
 
 	fs->metadirty = 1;
 	ext2_sync(fs);
@@ -327,8 +327,8 @@
 	printf("ext2_grow_group\n");
 
 	group = fs->numgroups - 1;
-	groupoff = group * fs->sb.s_blocks_per_group + fs->sb.s_first_data_block;
-	gblocks = fs->sb.s_blocks_count - groupoff;
+	groupoff = group * fs->sb->s_blocks_per_group + fs->sb->s_first_data_block;
+	gblocks = fs->sb->s_blocks_count - groupoff;
 
 	if (newsize < gblocks)
 	{
@@ -351,7 +351,7 @@
 	for (i=gblocks;i<newsize;i++)
 		ext2_set_block_state(fs, groupoff + i, 0, 1);
 
-	fs->sb.s_blocks_count += newsize - gblocks;
+	fs->sb->s_blocks_count += newsize - gblocks;
 
 	fs->metadirty = 1;
 	ext2_sync(fs);
@@ -373,8 +373,8 @@
 	if (!ext2_is_group_sparse(fs, group))
 		admin -= fs->gdblocks + 1;
 
-	groupoff = group * fs->sb.s_blocks_per_group + fs->sb.s_first_data_block;
-	gblocks = fs->sb.s_blocks_count - groupoff;
+	groupoff = group * fs->sb->s_blocks_per_group + fs->sb->s_first_data_block;
+	gblocks = fs->sb->s_blocks_count - groupoff;
 
 	if (newsize < admin)
 	{
@@ -407,8 +407,8 @@
 
 	i = gblocks - newsize;
 	fs->metadirty = 1;
-	fs->sb.s_blocks_count -= i;
-	fs->sb.s_free_blocks_count -= i;
+	fs->sb->s_blocks_count -= i;
+	fs->sb->s_free_blocks_count -= i;
 	fs->gd[group].bg_free_blocks_count -= i;
 
 	fs->metadirty = 1;
@@ -430,16 +430,16 @@
 	if (!ext2_block_relocate(fs, newsize))
 		return 0;
 
-	diff = newsize - fs->sb.s_blocks_count;
-	sizelast = fs->sb.s_blocks_count - fs->sb.s_first_data_block - (fs->numgroups-1)*fs->sb.s_blocks_per_group;
+	diff = newsize - fs->sb->s_blocks_count;
+	sizelast = fs->sb->s_blocks_count - fs->sb->s_first_data_block - (fs->numgroups-1)*fs->sb->s_blocks_per_group;
 
-	if (sizelast != fs->sb.s_blocks_per_group)
+	if (sizelast != fs->sb->s_blocks_per_group)
 	{
 		blk_t growto;
 
 		growto = sizelast + diff;
-		if (growto > fs->sb.s_blocks_per_group)
-			growto = fs->sb.s_blocks_per_group;
+		if (growto > fs->sb->s_blocks_per_group)
+			growto = fs->sb->s_blocks_per_group;
 
 		ext2_grow_group(fs, growto);
 		diff -= growto - sizelast;
@@ -447,7 +447,7 @@
 
 	while (diff)
 	{
-		sizelast = min(diff, fs->sb.s_blocks_per_group);
+		sizelast = min(diff, fs->sb->s_blocks_per_group);
 		ext2_add_group(fs, sizelast);
 		diff -= sizelast;
 	}
@@ -462,20 +462,20 @@
 
 	printf("ext2_shrink_fs\n");
 
-	if (!ext2_inode_relocate(fs, howmany(newsize - fs->sb.s_first_data_block,
-					     fs->sb.s_blocks_per_group) *
-				 fs->sb.s_inodes_per_group))
+	if (!ext2_inode_relocate(fs, howmany(newsize - fs->sb->s_first_data_block,
+					     fs->sb->s_blocks_per_group) *
+				 fs->sb->s_inodes_per_group))
 		return 0;
 
 	if (!ext2_block_relocate(fs, newsize))
 		return 0;
 
-	diff = fs->sb.s_blocks_count - newsize;
+	diff = fs->sb->s_blocks_count - newsize;
 
 	while (diff > 0)
 	{
-		sizelast = fs->sb.s_blocks_count - fs->sb.s_first_data_block -
-			(fs->numgroups - 1) * fs->sb.s_blocks_per_group;
+		sizelast = fs->sb->s_blocks_count - fs->sb->s_first_data_block -
+			(fs->numgroups - 1) * fs->sb->s_blocks_per_group;
 
 		if (diff < sizelast)
 		{
@@ -502,7 +502,7 @@
 
 	printf("ext2_resize_fs\n");
 
-	if (newsize == fs->sb.s_blocks_count)
+	if (newsize == fs->sb->s_blocks_count)
 		return 1;
 
 	if (newsize > fs->containersize)
@@ -514,7 +514,7 @@
 		return 0;
 	}
 
-	residue = (newsize - fs->sb.s_first_data_block) % fs->sb.s_blocks_per_group;
+	residue = (newsize - fs->sb->s_first_data_block) % fs->sb->s_blocks_per_group;
 	if (residue && residue <= fs->adminblocks)
 	{
 		fprintf(stderr, "ext2_resize_fs: %i is an impossible size for an ext2 fs! using %i instead\n",
@@ -522,7 +522,7 @@
 		newsize -= residue;
 	}
 
-	if (newsize < fs->sb.s_blocks_count)
+	if (newsize < fs->sb->s_blocks_count)
 		return ext2_shrink_fs(fs, newsize);
 
 	return ext2_grow_fs(fs, newsize);
