Many files:
  ext2fs.h, bitops.h: Add support for the Watcom C compiler to do inline
  	functions.
  ext2fs.h, dosio.c: Use asm/types.h instead of linux/types.h to evade a
  	potential problem with glibc's header files trying to spike out
  	linux/types.h.
  ext2fs.h (ext2fs_resize_mem): Change the function prototype to include
  	the old size of the memory, which is needed for some braindamaged
  	memory allocation systems that don't support realloc().
  badblocks.c (ext2fs_badblocks_list_add):
  bb_inode.c (clear_bad_block_proc):
  dblist.c (ext2fs_add_dir_block):
  icount.c (insert_icount_el):
  irel_ma.c (ima_put):
  rs_bitmap.c (ext2fs_resize_generic_bitmap): Update functions to pass
  	the old size of the memory to be resized to ext2fs_resize_mem().
ChangeLog, dirinfo.c:
  dirinfo.c (e2fsck_add_dir_info): Update function to pass the old size
  	of the memory to be resized to ext2fs_resize_mem().
ChangeLog, extent.c, resize2fs.c:
  resize2fs.c (adjust_superblock):
  extent.c (ext2fs_add_extent_entry): Update functions to pass the old
  	size of the memory to be resized to ext2fs_resize_mem().

diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog
index 7442f7a..298385e 100644
--- a/e2fsck/ChangeLog
+++ b/e2fsck/ChangeLog
@@ -1,3 +1,8 @@
+1998-04-26  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+	* dirinfo.c (e2fsck_add_dir_info): Update function to pass the old
+		  size of the memory to be resized to ext2fs_resize_mem().
+
 1998-03-30  Theodore Ts'o  <tytso@rsts-11.mit.edu>
 
 	* Makefile.in: Change to use new installation directory variables
diff --git a/e2fsck/dirinfo.c b/e2fsck/dirinfo.c
index c99b99e..fe8155f 100644
--- a/e2fsck/dirinfo.c
+++ b/e2fsck/dirinfo.c
@@ -18,6 +18,7 @@
 	int		i, j;
 	ino_t		num_dirs;
 	errcode_t	retval;
+	unsigned long	old_size;
 
 #if 0
 	printf("add_dir_info for inode %lu...\n", ino);
@@ -35,8 +36,9 @@
 	}
 	
 	if (ctx->dir_info_count >= ctx->dir_info_size) {
+		old_size = ctx->dir_info_size * sizeof(struct dir_info);
 		ctx->dir_info_size += 10;
-		retval = ext2fs_resize_mem(ctx->dir_info_size *
+		retval = ext2fs_resize_mem(old_size, ctx->dir_info_size *
 					   sizeof(struct dir_info),
 					   (void **) &ctx->dir_info);
 		if (retval) {
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index 4bc5f21..9fcb3ce 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,3 +1,26 @@
+1998-04-26  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+	* ext2fs.h, bitops.h: Add support for the Watcom C compiler to do
+		inline functions.
+
+	* ext2fs.h, dosio.c: Use asm/types.h instead of linux/types.h to
+		evade a potential problem with glibc's header files trying
+		to spike out linux/types.h.
+
+	* ext2fs.h (ext2fs_resize_mem): Change the function prototype to
+		include the old size of the memory, which is needed for
+		some braindamaged memory allocation systems that don't
+		support realloc().
+
+	* badblocks.c (ext2fs_badblocks_list_add):
+	  bb_inode.c (clear_bad_block_proc):
+	  dblist.c (ext2fs_add_dir_block):
+	  icount.c (insert_icount_el):
+	  irel_ma.c (ima_put):
+	  rs_bitmap.c (ext2fs_resize_generic_bitmap): Update functions to
+		  pass the old size of the memory to be resized to
+		  ext2fs_resize_mem(). 
+
 1998-03-30  Theodore Ts'o  <tytso@rsts-11.mit.edu>
 
 	* Makefile.in: Change to use new installation directory variables
diff --git a/lib/ext2fs/badblocks.c b/lib/ext2fs/badblocks.c
index 9d43444..3851ccd 100644
--- a/lib/ext2fs/badblocks.c
+++ b/lib/ext2fs/badblocks.c
@@ -101,15 +101,19 @@
 {
 	errcode_t	retval;
 	int		i, j;
+	unsigned long	old_size;
 
 	EXT2_CHECK_MAGIC(bb, EXT2_ET_MAGIC_BADBLOCKS_LIST);
 
 	if (bb->num >= bb->size) {
+		old_size = bb->size * sizeof(blk_t);
 		bb->size += 10;
-		retval = ext2fs_resize_mem(bb->size * sizeof(blk_t),
+		retval = ext2fs_resize_mem(old_size, bb->size * sizeof(blk_t),
 					   (void **) &bb->list);
-		if (retval)
+		if (retval) {
+			bb->size -= 10;
 			return retval;
+		}
 	}
 
 	j = bb->num;
diff --git a/lib/ext2fs/bb_inode.c b/lib/ext2fs/bb_inode.c
index 995e3ba..38d1052 100644
--- a/lib/ext2fs/bb_inode.c
+++ b/lib/ext2fs/bb_inode.c
@@ -174,6 +174,7 @@
 		priv_data;
 	errcode_t	retval;
 	int		group;
+	unsigned long 	old_size;
 
 	if (!*block_nr)
 		return 0;
@@ -189,11 +190,13 @@
 
 	if (blockcnt < 0) {
 		if (rec->ind_blocks_size >= rec->max_ind_blocks) {
+			old_size = rec->max_ind_blocks * sizeof(blk_t);
 			rec->max_ind_blocks += 10;
-			retval = ext2fs_resize_mem(rec->max_ind_blocks
-						   * sizeof(blk_t),
-						   (void **) &rec->ind_blocks);
+			retval = ext2fs_resize_mem(old_size, 
+				   rec->max_ind_blocks * sizeof(blk_t),
+				   (void **) &rec->ind_blocks);
 			if (retval) {
+				rec->max_ind_blocks -= 10;
 				rec->err = retval;
 				return BLOCK_ABORT;
 			}
diff --git a/lib/ext2fs/bitops.h b/lib/ext2fs/bitops.h
index a3ea2e7..0361d9b 100644
--- a/lib/ext2fs/bitops.h
+++ b/lib/ext2fs/bitops.h
@@ -98,7 +98,11 @@
 #ifdef INCLUDE_INLINE_FUNCS
 #define _INLINE_ extern
 #else
+#ifdef __GNUC__
 #define _INLINE_ extern __inline__
+#else				/* For Watcom C */
+#define _INLINE_ extern inline
+#endif
 #endif
 
 #if ((defined __GNUC__) && (defined(__i386__) || defined(__i486__) || \
diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c
index 5db0c4f..9683ef1 100644
--- a/lib/ext2fs/dblist.c
+++ b/lib/ext2fs/dblist.c
@@ -160,12 +160,14 @@
 {
 	struct ext2_db_entry 	*new_entry;
 	errcode_t		retval;
+	unsigned long		old_size;
 	
 	EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
 
 	if (dblist->count >= dblist->size) {
+		old_size = dblist->size * sizeof(struct ext2_db_entry);
 		dblist->size += 100;
-		retval = ext2fs_resize_mem((size_t) dblist->size *
+		retval = ext2fs_resize_mem(old_size, (size_t) dblist->size *
 					   sizeof(struct ext2_db_entry),
 					   (void **) &dblist->list);
 		if (retval) {
diff --git a/lib/ext2fs/dosio.c b/lib/ext2fs/dosio.c
index c6baddb..a1cbdc2 100644
--- a/lib/ext2fs/dosio.c
+++ b/lib/ext2fs/dosio.c
@@ -17,7 +17,7 @@
 #include <errno.h>
 #endif
 
-#include <linux/types.h>
+#include <asm/types.h>
 #include "utils.h"
 #include "dosio.h"
 #include "et/com_err.h"
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 43ed653..6c84517 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -15,7 +15,7 @@
 /*
  * Non-GNU C compilers won't necessarily understand inline
  */
-#ifndef __GNUC__
+#if (!defined(__GNUC__) && !defined(__WATCOMC__))
 #define NO_INLINE_FUNCS
 #endif
 
@@ -44,7 +44,7 @@
 #if EXT2_FLAT_INCLUDES
 #include "e2_types.h"
 #else
-#include <linux/types.h>
+#include <asm/types.h>
 #if (defined(__GNUC__) && defined(__STRICT_ANSI__) && ((~0UL) == 0xffffffff))
 typedef __signed__ long long __s64;
 typedef unsigned long long __u64;
@@ -783,7 +783,8 @@
 /* inline functions */
 extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
 extern errcode_t ext2fs_free_mem(void **ptr);
-extern errcode_t ext2fs_resize_mem(unsigned long size, void **ptr);
+extern errcode_t ext2fs_resize_mem(unsigned long old_size,
+				   unsigned long size, void **ptr);
 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
 extern void ext2fs_mark_changed(ext2_filsys fs);
 extern int ext2fs_test_changed(ext2_filsys fs);
@@ -807,7 +808,11 @@
 #ifdef INCLUDE_INLINE_FUNCS
 #define _INLINE_ extern
 #else
+#ifdef __GNUC__
 #define _INLINE_ extern __inline__
+#else				/* For Watcom C */
+#define _INLINE_ extern inline
+#endif
 #endif
 
 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
@@ -835,7 +840,8 @@
 /*
  *  Resize memory
  */
-_INLINE_ errcode_t ext2fs_resize_mem(unsigned long size, void **ptr)
+_INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
+				     unsigned long size, void **ptr)
 {
 	void *p;
 
diff --git a/lib/ext2fs/icount.c b/lib/ext2fs/icount.c
index 4acb51e..543187c 100644
--- a/lib/ext2fs/icount.c
+++ b/lib/ext2fs/icount.c
@@ -182,7 +182,9 @@
 #if 0
 		printf("Reallocating icount %d entries...\n", new_size);
 #endif	
-		retval = ext2fs_resize_mem((size_t) new_size *
+		retval = ext2fs_resize_mem((size_t) icount->size *
+					   sizeof(struct ext2_icount_el),
+					   (size_t) new_size *
 					   sizeof(struct ext2_icount_el),
 					   (void **) &icount->list);
 		if (retval)
diff --git a/lib/ext2fs/irel_ma.c b/lib/ext2fs/irel_ma.c
index 97ab825..ee5caf1 100644
--- a/lib/ext2fs/irel_ma.c
+++ b/lib/ext2fs/irel_ma.c
@@ -144,7 +144,7 @@
 	struct inode_reference_entry	*ref_ent;
 	struct irel_ma 			*ma;
 	errcode_t			retval;
-	int				size;
+	size_t				size, old_size;
 
 	ma = irel->priv_data;
 	if (old > ma->max_inode)
@@ -166,7 +166,10 @@
 	if (ref_ent->refs && ent->max_refs !=
 	    ma->entries[(unsigned) old].max_refs) {
 		size = (sizeof(struct ext2_inode_reference) * ent->max_refs);
-		retval = ext2fs_resize_mem(size, (void **) &ref_ent->refs);
+		old_size = (sizeof(struct ext2_inode_reference) *
+			    ma->entries[(unsigned) old].max_refs);
+		retval = ext2fs_resize_mem(old_size, size,
+					   (void **) &ref_ent->refs);
 		if (retval)
 			return retval;
 	}
diff --git a/lib/ext2fs/rs_bitmap.c b/lib/ext2fs/rs_bitmap.c
index 193039a..240994f 100644
--- a/lib/ext2fs/rs_bitmap.c
+++ b/lib/ext2fs/rs_bitmap.c
@@ -62,9 +62,12 @@
 	size = ((bmap->real_end - bmap->start) / 8) + 1;
 	new_size = ((new_real_end - bmap->start) / 8) + 1;
 
-	retval = ext2fs_resize_mem(new_size, (void **) &bmap->bitmap);
-	if (retval)
-		return retval;
+	if (size != new_size) {
+		retval = ext2fs_resize_mem(size, new_size,
+					   (void **) &bmap->bitmap);
+		if (retval)
+			return retval;
+	}
 	if (new_size > size)
 		memset(bmap->bitmap + size, 0, new_size - size);
 
diff --git a/resize/ChangeLog b/resize/ChangeLog
index fea200e..4b85202 100644
--- a/resize/ChangeLog
+++ b/resize/ChangeLog
@@ -1,3 +1,10 @@
+1998-04-26  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+	* resize2fs.c (adjust_superblock): 
+	* extent.c (ext2fs_add_extent_entry): Update functions to
+		  pass the old size of the memory to be resized to
+		  ext2fs_resize_mem(). 
+
 1998-03-30  Theodore Ts'o  <tytso@rsts-11.mit.edu>
 
 	* Makefile.in: Change to use new installation directory variables
diff --git a/resize/extent.c b/resize/extent.c
index 56fb62a..b583baa 100644
--- a/resize/extent.c
+++ b/resize/extent.c
@@ -84,6 +84,8 @@
 	if (extent->num >= extent->size) {
 		newsize = extent->size + 100;
 		retval = ext2fs_resize_mem(sizeof(struct ext2_extent_entry) * 
+					   extent->size, 
+					   sizeof(struct ext2_extent_entry) * 
 					   newsize, (void **) &extent->list);
 		if (retval)
 			return retval;
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 4d85969..1818e02 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -261,7 +261,9 @@
 	 * Reallocate the group descriptors as necessary.
 	 */
 	if (rfs->old_fs->desc_blocks != fs->desc_blocks) {
-		retval = ext2fs_resize_mem(fs->desc_blocks * fs->blocksize,
+		retval = ext2fs_resize_mem(rfs->old_fs->desc_blocks *
+					   fs->blocksize,
+					   fs->desc_blocks * fs->blocksize,
 					   (void **) &fs->group_desc);
 		if (retval)
 			goto errout;