Many files:
  alloc.c (ext2fs_alloc_block): New function which allocates a
  	block and updates the filesystem accounting records
  	appropriately.
  ext2_err.et.in: Added new error codes: EXT2_NO_MEMORY,
  	EXT2_INVALID_ARGUMENT, EXT2_BLOCK_ALLOC_FAIL, EXT2_INODE_ALLOC_FAIL,
  	EXT2_NOT_DIRECTORY
  Change various library files to use these functions instead of EINVAL,
  ENOENT, etc.
ChangeLog, pass1.c, pass3.c:
  pass3.c (get_lost_and_found): Check error return of
  	EXT2_FILE_NOT_FOUND instead of ENOTDIR
  pass1.c (pass1_check_directory): Return EXT2_NO_DIRECTORY instead of
  	ENOTDIR
expect.icount:
  Change expected error string to be "Invalid argument passed to ext2 library"
  instead of just "Invalid argument"

diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog
index 260e981..df30e50 100644
--- a/e2fsck/ChangeLog
+++ b/e2fsck/ChangeLog
@@ -1,3 +1,11 @@
+Sat Oct 25 00:10:58 1997  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+	* pass3.c (get_lost_and_found): Check error return of 
+		EXT2_FILE_NOT_FOUND instead of ENOTDIR
+
+	* pass1.c (pass1_check_directory): Return EXT2_NO_DIRECTORY
+		instead of ENOTDIR
+
 Fri Oct 24 00:12:39 1997  Theodore Ts'o  <tytso@rsts-11.mit.edu>
 
 	* unix.c (PRS): Make the variable which getopt returns into be
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index bda1a51..43ff878 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -1213,6 +1213,6 @@
 		return EXT2_ET_CALLBACK_NOTHANDLED;
 
 	if (!LINUX_S_ISDIR(ctx->stashed_inode->i_mode))
-		return ENOTDIR;
+		return EXT2_NO_DIRECTORY;
 	return 0;
 }
diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c
index 52c19c9..33541aa 100644
--- a/e2fsck/pass3.c
+++ b/e2fsck/pass3.c
@@ -310,7 +310,7 @@
 			       sizeof(name)-1, 0, &ino);
 	if (!retval)
 		return ino;
-	if (retval != ENOENT) {
+	if (retval != EXT2_FILE_NOT_FOUND) {
 		pctx.errcode = retval;
 		fix_problem(ctx, PR_3_ERR_FIND_LPF, &pctx);
 	}
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index e312c20..865f1ef 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,3 +1,18 @@
+Sat Oct 25 00:06:58 1997  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+	* alloc.c (ext2fs_alloc_block): New function which allocates a
+		block and updates the filesystem accounting records
+		appropriately. 
+
+Wed Oct 22 16:47:27 1997  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+	* ext2_err.et.in: Added new error codes: EXT2_NO_MEMORY,
+		EXT2_INVALID_ARGUMENT, EXT2_BLOCK_ALLOC_FAIL,
+		EXT2_INODE_ALLOC_FAIL, EXT2_NOT_DIRECTORY
+
+	* Change various library files to use these functions instead of
+		EINVAL, ENOENT, etc.
+
 Mon Oct 20 19:32:40 1997  Theodore Ts'o  <tytso@rsts-11.mit.edu>
 
 	* llseek.c: Check HAVE_LLSEEK_PROTOTYPE to see whether or not we
diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c
index eaf2758..446184d 100644
--- a/lib/ext2fs/alloc.c
+++ b/lib/ext2fs/alloc.c
@@ -22,9 +22,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -67,7 +64,7 @@
 	} while (i != start_inode);
 	
 	if (ext2fs_test_inode_bitmap(map, i))
-		return ENOSPC;
+		return EXT2_INODE_ALLOC_FAIL;
 	*ret = i;
 	return 0;
 }
@@ -99,7 +96,33 @@
 		if (i >= fs->super->s_blocks_count)
 			i = fs->super->s_first_data_block;
 	} while (i != goal);
-	return ENOSPC;
+	return EXT2_BLOCK_ALLOC_FAIL;
+}
+
+/*
+ * This function uses fs->block_map, and updates the filesystem
+ * accounting records appropriately.
+ */
+errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, blk_t *ret)
+{
+	errcode_t	retval;
+	int		group;
+
+	if (!fs->block_map)
+		ext2fs_read_block_bitmap(fs);
+
+	retval = ext2fs_new_block(fs, goal, 0, ret);
+	if (retval)
+		return retval;
+	
+	fs->super->s_free_blocks_count--;
+	group = ((*ret - fs->super->s_first_data_block) /
+		 fs->super->s_blocks_per_group);
+	fs->group_desc[group].bg_free_blocks_count--;
+	ext2fs_mark_block_bitmap(fs->block_map, *ret);
+	ext2fs_mark_super_dirty(fs);
+	ext2fs_mark_bb_dirty(fs);
+	return 0;
 }
 
 errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish,
@@ -128,6 +151,6 @@
 		}
 		b++;
 	} while (b != finish);
-	return ENOSPC;
+	return EXT2_BLOCK_ALLOC_FAIL;
 }
 
diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c
index b888414..769aec9 100644
--- a/lib/ext2fs/alloc_tables.c
+++ b/lib/ext2fs/alloc_tables.c
@@ -24,9 +24,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
diff --git a/lib/ext2fs/badblocks.c b/lib/ext2fs/badblocks.c
index 38e9f6e..0b9bbff 100644
--- a/lib/ext2fs/badblocks.c
+++ b/lib/ext2fs/badblocks.c
@@ -23,9 +23,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -41,7 +38,7 @@
 	
 	bb = malloc(sizeof(struct ext2_struct_badblocks_list));
 	if (!bb)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(bb, 0, sizeof(struct ext2_struct_badblocks_list));
 	bb->magic = EXT2_ET_MAGIC_BADBLOCKS_LIST;
 	bb->size = size ? size : 10;
@@ -49,7 +46,7 @@
 	bb->list = malloc(bb->size * sizeof(blk_t));
 	if (!bb->list) {
 		free(bb);
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	}
 	if (list)
 		memcpy(bb->list, list, bb->size * sizeof(blk_t));
@@ -106,7 +103,7 @@
 		bb->size += 10;
 		new_list = realloc(bb->list, bb->size * sizeof(blk_t));
 		if (!new_list)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		bb->list = new_list;
 	}
 
@@ -170,7 +167,7 @@
 
 	iter = malloc(sizeof(struct ext2_struct_badblocks_iterate));
 	if (!iter)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 
 	iter->magic = EXT2_ET_MAGIC_BADBLOCKS_ITERATE;
 	iter->bb = bb;
diff --git a/lib/ext2fs/bb_compat.c b/lib/ext2fs/bb_compat.c
index d47a916..4b52675 100644
--- a/lib/ext2fs/bb_compat.c
+++ b/lib/ext2fs/bb_compat.c
@@ -23,9 +23,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
diff --git a/lib/ext2fs/bb_inode.c b/lib/ext2fs/bb_inode.c
index 6859700..fdcebc4 100644
--- a/lib/ext2fs/bb_inode.c
+++ b/lib/ext2fs/bb_inode.c
@@ -27,9 +27,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -73,11 +70,11 @@
 	rec.max_ind_blocks = 10;
 	rec.ind_blocks = malloc(rec.max_ind_blocks * sizeof(blk_t));
 	if (!rec.ind_blocks)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(rec.ind_blocks, 0, rec.max_ind_blocks * sizeof(blk_t));
 	rec.block_buf = malloc(fs->blocksize);
 	if (!rec.block_buf) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	memset(rec.block_buf, 0, fs->blocksize);
@@ -189,7 +186,7 @@
 						  rec->max_ind_blocks *
 						  sizeof(blk_t));
 			if (!rec->ind_blocks) {
-				rec->err = ENOMEM;
+				rec->err = EXT2_NO_MEMORY;
 				return BLOCK_ABORT;
 			}
 		}
diff --git a/lib/ext2fs/bitmaps.c b/lib/ext2fs/bitmaps.c
index 9fe2d16..76dbc1c 100644
--- a/lib/ext2fs/bitmaps.c
+++ b/lib/ext2fs/bitmaps.c
@@ -24,9 +24,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -41,7 +38,7 @@
 
 	bitmap = malloc(sizeof(struct ext2fs_struct_generic_bitmap));
 	if (!bitmap)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 
 	bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
 	bitmap->fs = NULL;
@@ -53,7 +50,7 @@
 		bitmap->description = malloc(strlen(descr)+1);
 		if (!bitmap->description) {
 			free(bitmap);
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		}
 		strcpy(bitmap->description, descr);
 	} else
@@ -64,7 +61,7 @@
 	if (!bitmap->bitmap) {
 		free(bitmap->description);
 		free(bitmap);
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	}
 
 	if (init_map)
diff --git a/lib/ext2fs/block.c b/lib/ext2fs/block.c
index 0a3e32f..f938380 100644
--- a/lib/ext2fs/block.c
+++ b/lib/ext2fs/block.c
@@ -15,9 +15,6 @@
 #include <unistd.h>
 #endif
 #include <stdlib.h>
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -337,7 +334,7 @@
 	} else {
 		ctx.ind_buf = malloc(fs->blocksize * 3);
 		if (!ctx.ind_buf)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 	}
 	ctx.dind_buf = ctx.ind_buf + fs->blocksize;
 	ctx.tind_buf = ctx.dind_buf + fs->blocksize;
diff --git a/lib/ext2fs/bmove.c b/lib/ext2fs/bmove.c
index b100793..61bc790 100644
--- a/lib/ext2fs/bmove.c
+++ b/lib/ext2fs/bmove.c
@@ -18,9 +18,6 @@
 #if HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 #include "ext2fs/ext2fs.h"
@@ -56,7 +53,7 @@
 			if (++block >= fs->super->s_blocks_count)
 				block = fs->super->s_first_data_block;
 			if (block == orig) {
-				pb->error = ENOSPC;
+				pb->error = EXT2_BLOCK_ALLOC_FAIL;
 				return BLOCK_ABORT;
 			}
 		} while (ext2fs_test_block_bitmap(pb->reserve, block) ||
@@ -113,7 +110,7 @@
 	
 	block_buf = malloc(fs->blocksize * 4);
 	if (!block_buf)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	pb.buf = block_buf + fs->blocksize * 3;
 
 	/*
diff --git a/lib/ext2fs/brel_ma.c b/lib/ext2fs/brel_ma.c
index 583ee85..8913688 100644
--- a/lib/ext2fs/brel_ma.c
+++ b/lib/ext2fs/brel_ma.c
@@ -58,7 +58,7 @@
 	/*
 	 * Allocate memory structures
 	 */
-	retval = ENOMEM;
+	retval = EXT2_NO_MEMORY;
 	brel = malloc(sizeof(struct ext2_block_relocation_table));
 	if (!brel)
 		goto errout;
@@ -109,7 +109,7 @@
 
 	ma = brel->private;
 	if (old > ma->max_block)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	ma->entries[(unsigned)old] = *ent;
 	return 0;
 }
@@ -121,7 +121,7 @@
 
 	ma = brel->private;
 	if (old > ma->max_block)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	if (ma->entries[(unsigned)old].new == 0)
 		return ENOENT;
 	*ent = ma->entries[old];
@@ -157,7 +157,7 @@
 
 	ma = brel->private;
 	if ((old > ma->max_block) || (new > ma->max_block))
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	if (ma->entries[(unsigned)old].new == 0)
 		return ENOENT;
 	ma->entries[(unsigned)new] = ma->entries[old];
@@ -171,7 +171,7 @@
 
 	ma = brel->private;
 	if (old > ma->max_block)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	if (ma->entries[(unsigned)old].new == 0)
 		return ENOENT;
 	ma->entries[(unsigned)old].new = 0;
diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index cdc8597..4016a7c 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -16,9 +16,6 @@
 #include <stdlib.h>
 #include <time.h>
 #include <string.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -73,7 +70,7 @@
 
 	fs->super->s_wtime = time(NULL);
 	if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		if (!(super_shadow = malloc(SUPERBLOCK_SIZE)))
 			goto errout;
 		if (!(group_shadow = malloc((size_t) fs->blocksize *
diff --git a/lib/ext2fs/cmp_bitmaps.c b/lib/ext2fs/cmp_bitmaps.c
index 9e583a7..9cec4d7 100644
--- a/lib/ext2fs/cmp_bitmaps.c
+++ b/lib/ext2fs/cmp_bitmaps.c
@@ -23,9 +23,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c
index 7c83c69..867ba9a 100644
--- a/lib/ext2fs/dblist.c
+++ b/lib/ext2fs/dblist.c
@@ -17,9 +17,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -68,7 +65,7 @@
 
 	dblist = malloc(sizeof(struct ext2_struct_dblist));
 	if (!dblist)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(dblist, 0, sizeof(struct ext2_struct_dblist));
 
 	dblist->magic = EXT2_ET_MAGIC_DBLIST;
@@ -85,7 +82,7 @@
 	dblist->count = count;
 	dblist->list = malloc(len);
 	if (dblist->list == NULL) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	if (list)
@@ -161,7 +158,7 @@
 				sizeof(struct ext2_db_entry));
 		if (nlist == 0) {
 			dblist->size -= 100;
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		}
 		dblist->list = nlist;
 	}
diff --git a/lib/ext2fs/dblist_dir.c b/lib/ext2fs/dblist_dir.c
index ebbf17a..131f965 100644
--- a/lib/ext2fs/dblist_dir.c
+++ b/lib/ext2fs/dblist_dir.c
@@ -17,9 +17,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -53,7 +50,7 @@
 	else {
 		ctx.buf = malloc(dblist->fs->blocksize);
 		if (!ctx.buf)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 	}
 	ctx.func = 0;
 	ctx.func2 = func;
diff --git a/lib/ext2fs/dir_iterate.c b/lib/ext2fs/dir_iterate.c
index 40c289b..8d8de57 100644
--- a/lib/ext2fs/dir_iterate.c
+++ b/lib/ext2fs/dir_iterate.c
@@ -50,7 +50,7 @@
 	else {
 		ctx.buf = malloc(fs->blocksize);
 		if (!ctx.buf)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 	}
 	ctx.func = func;
 	ctx.func2 = 0;
diff --git a/lib/ext2fs/dirblock.c b/lib/ext2fs/dirblock.c
index 4f8b94b..6958bee 100644
--- a/lib/ext2fs/dirblock.c
+++ b/lib/ext2fs/dirblock.c
@@ -16,9 +16,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -61,7 +58,7 @@
 	    (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) {
 		write_buf = buf = malloc(fs->blocksize);
 		if (!buf)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		memcpy(buf, inbuf, fs->blocksize);
 		p = buf;
 		end = buf + fs->blocksize;
diff --git a/lib/ext2fs/dupfs.c b/lib/ext2fs/dupfs.c
index 8f9787c..8c6f159 100644
--- a/lib/ext2fs/dupfs.c
+++ b/lib/ext2fs/dupfs.c
@@ -16,9 +16,6 @@
 #include <stdlib.h>
 #include <time.h>
 #include <string.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -33,7 +30,7 @@
 	
 	fs = (ext2_filsys) malloc(sizeof(struct struct_ext2_filsys));
 	if (!fs)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 
 	*fs = *src;
 	fs->device_name = 0;
@@ -48,7 +45,7 @@
 	if (fs->icache)
 		fs->icache->refcount++;
 
-	retval = ENOMEM;
+	retval = EXT2_NO_MEMORY;
 	fs->device_name = malloc(strlen(src->device_name)+1);
 	if (!fs->device_name)
 		goto errout;
diff --git a/lib/ext2fs/expanddir.c b/lib/ext2fs/expanddir.c
index 39852c2..46ada20 100644
--- a/lib/ext2fs/expanddir.c
+++ b/lib/ext2fs/expanddir.c
@@ -15,9 +15,6 @@
 #include <unistd.h>
 #endif
 #include <stdlib.h>
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -59,7 +56,7 @@
 	} else {
 		block = malloc(fs->blocksize);
 		if (!block) {
-			es->err = ENOMEM;
+			es->err = EXT2_NO_MEMORY;
 			return BLOCK_ABORT;
 		}
 		memset(block, 0, fs->blocksize);
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 334a576..f257a2b 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -381,6 +381,7 @@
 					blk_t finish, int num,
 					ext2fs_block_bitmap map,
 					blk_t *ret);
+extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, blk_t *ret);
 
 /* alloc_tables.c */
 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
diff --git a/lib/ext2fs/get_pathname.c b/lib/ext2fs/get_pathname.c
index adce200..f4f6db7 100644
--- a/lib/ext2fs/get_pathname.c
+++ b/lib/ext2fs/get_pathname.c
@@ -24,9 +24,6 @@
 #include <unistd.h>
 #endif
 #include <stdlib.h>
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -58,7 +55,7 @@
 	if (dirent->inode == gp->search_ino) {
 		gp->name = malloc(dirent->name_len + 1);
 		if (!gp->name) {
-			gp->errcode = ENOMEM;
+			gp->errcode = EXT2_NO_MEMORY;
 			return DIRENT_ABORT;
 		}
 		strncpy(gp->name, dirent->name, dirent->name_len);
@@ -78,7 +75,7 @@
 	if (dir == ino) {
 		*name = malloc(2);
 		if (!*name)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		strcpy(*name, (dir == EXT2_ROOT_INO) ? "/" : ".");
 		return 0;
 	}
@@ -86,7 +83,7 @@
 	if (!dir || (maxdepth < 0)) {
 		*name = malloc(4);
 		if (!*name)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		strcpy(*name, "...");
 		return 0;
 	}
@@ -119,7 +116,7 @@
 		ret = malloc(strlen(parent_name)+5); /* strlen("???") + 2 */
 		
 	if (!ret) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	ret[0] = 0;
@@ -150,7 +147,7 @@
 
 	buf = malloc(fs->blocksize);
 	if (!buf)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	if (dir == ino)
 		ino = 0;
 	retval = ext2fs_get_pathname_int(fs, dir, ino, 32, buf, name);
diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c
index 0246545..c90708e 100644
--- a/lib/ext2fs/getsize.c
+++ b/lib/ext2fs/getsize.c
@@ -16,9 +16,6 @@
 #if HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 #include <fcntl.h>
 #ifdef HAVE_LINUX_FS_H
 #include <linux/fs.h>
diff --git a/lib/ext2fs/icount.c b/lib/ext2fs/icount.c
index 4e074c0..84d0a97 100644
--- a/lib/ext2fs/icount.c
+++ b/lib/ext2fs/icount.c
@@ -16,9 +16,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 #include "ext2fs.h"
@@ -89,7 +86,7 @@
 	
 	icount = malloc(sizeof(struct ext2_icount));
 	if (!icount)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(icount, 0, sizeof(struct ext2_icount));
 
 	retval = ext2fs_allocate_inode_bitmap(fs, 0, 
@@ -282,14 +279,14 @@
 
 	if (icount->count > icount->size) {
 		fprintf(out, "%s: count > size\n", bad);
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	}
 	for (i=1; i < icount->count; i++) {
 		if (icount->list[i-1].ino >= icount->list[i].ino) {
 			fprintf(out, "%s: list[%d].ino=%ld, list[%d].ino=%ld\n",
 				bad, i-1, icount->list[i-1].ino,
 				i, icount->list[i].ino);
-			ret = EINVAL;
+			ret = EXT2_INVALID_ARGUMENT;
 		}
 	}
 	return ret;
@@ -302,7 +299,7 @@
 	EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT);
 
 	if (!ino || (ino > icount->num_inodes))
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	if (ext2fs_test_inode_bitmap(icount->single, ino)) {
 		*ret = 1;
@@ -330,7 +327,7 @@
 	EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT);
 
 	if (!ino || (ino > icount->num_inodes))
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	if (ext2fs_test_inode_bitmap(icount->single, ino)) {
 		/*
@@ -339,7 +336,7 @@
 		 */
 		el = get_icount_el(icount, ino, 1);
 		if (!el)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		ext2fs_unmark_inode_bitmap(icount->single, ino);
 		el->count = 2;
 	} else if (icount->multiple) {
@@ -352,7 +349,7 @@
 		if (ext2fs_test_inode_bitmap(icount->multiple, ino)) {
 			el = get_icount_el(icount, ino, 1);
 			if (!el)
-				return ENOMEM;
+				return EXT2_NO_MEMORY;
 			el->count++;
 		} else {
 			/*
@@ -377,7 +374,7 @@
 		}
 		el = get_icount_el(icount, ino, 1);
 		if (!el)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		el->count++;
 	}
 	if (icount->multiple)
@@ -393,7 +390,7 @@
 	struct ext2_icount_el	*el;
 
 	if (!ino || (ino > icount->num_inodes))
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT);
 
@@ -413,11 +410,11 @@
 
 	if (icount->multiple &&
 	    !ext2fs_test_inode_bitmap(icount->multiple, ino))
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	
 	el = get_icount_el(icount, ino, 0);
 	if (!el || el->count == 0)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	el->count--;
 	if (el->count == 1)
@@ -436,7 +433,7 @@
 	struct ext2_icount_el	*el;
 
 	if (!ino || (ino > icount->num_inodes))
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT);
 
@@ -467,7 +464,7 @@
 	 */
 	el = get_icount_el(icount, ino, 1);
 	if (!el)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	el->count = count;
 	ext2fs_unmark_inode_bitmap(icount->single, ino);
 	if (icount->multiple)
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index 1057ff6..f1fa7d7 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -24,9 +24,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -73,11 +70,11 @@
 	char		*buf;
 
 	if (!param || !param->s_blocks_count)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	
 	fs = (ext2_filsys) malloc(sizeof(struct struct_ext2_filsys));
 	if (!fs)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	
 	memset(fs, 0, sizeof(struct struct_ext2_filsys));
 	fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
@@ -88,13 +85,13 @@
 	fs->io->app_data = fs;
 	fs->device_name = malloc(strlen(name)+1);
 	if (!fs->device_name) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	strcpy(fs->device_name, name);
 	fs->super = super = malloc(SUPERBLOCK_SIZE);
 	if (!super) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	memset(super, 0, SUPERBLOCK_SIZE);
@@ -142,7 +139,7 @@
 	super->s_blocks_count = param->s_blocks_count;
 	super->s_r_blocks_count = param->s_r_blocks_count;
 	if (super->s_r_blocks_count >= param->s_blocks_count) {
-		retval = EINVAL;
+		retval = EXT2_INVALID_ARGUMENT;
 		goto cleanup;
 	}
 
@@ -234,7 +231,7 @@
 
 	buf = malloc(strlen(fs->device_name) + 80);
 	if (!buf) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	
@@ -252,7 +249,7 @@
 
 	fs->group_desc = malloc((size_t) fs->desc_blocks * fs->blocksize);
 	if (!fs->group_desc) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	memset(fs->group_desc, 0, (size_t) fs->desc_blocks * fs->blocksize);
diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c
index c84b27f..fe26b3f 100644
--- a/lib/ext2fs/inode.c
+++ b/lib/ext2fs/inode.c
@@ -21,9 +21,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -65,7 +62,7 @@
 	fs->icache->buffer = malloc(fs->blocksize);
 	if (!fs->icache->buffer) {
 		free(fs->icache);
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	}
 	fs->icache->buffer_blk = 0;
 	fs->icache->cache_last = -1;
@@ -76,7 +73,7 @@
 	if (!fs->icache->cache) {
 		free(fs->icache->buffer);
 		free(fs->icache);
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	}
 	for (i=0; i < fs->icache->cache_size; i++)
 		fs->icache->cache[i].ino = 0;
@@ -113,7 +110,7 @@
 
 	scan = (ext2_inode_scan) malloc(sizeof(struct ext2_struct_inode_scan));
 	if (!scan)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(scan, 0, sizeof(struct ext2_struct_inode_scan));
 
 	scan->magic = EXT2_ET_MAGIC_INODE_SCAN;
@@ -130,13 +127,13 @@
 	scan->bad_block_ptr = 0;
 	if (!scan->inode_buffer) {
 		free(scan);
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	}
 	scan->temp_buffer = malloc(scan->inode_size);
 	if (!scan->temp_buffer) {
 		free(scan->inode_buffer);
 		free(scan);
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	}
 	if (scan->fs->badblocks && scan->fs->badblocks->num)
 		scan->scan_flags |= EXT2_SF_CHK_BADBLOCKS;
@@ -642,7 +639,7 @@
 	if (retval)
 		return retval;
 	if (!LINUX_S_ISDIR(inode.i_mode))
-		return ENOTDIR;
+		return EXT2_NO_DIRECTORY;
 	return 0;
 }
 
diff --git a/lib/ext2fs/irel_ma.c b/lib/ext2fs/irel_ma.c
index 54b71dd..86055e2 100644
--- a/lib/ext2fs/irel_ma.c
+++ b/lib/ext2fs/irel_ma.c
@@ -74,7 +74,7 @@
 	/*
 	 * Allocate memory structures
 	 */
-	retval = ENOMEM;
+	retval = EXT2_NO_MEMORY;
 	irel = malloc(sizeof(struct ext2_inode_relocation_table));
 	if (!irel)
 		goto errout;
@@ -145,7 +145,7 @@
 
 	ma = irel->private;
 	if (old > ma->max_inode)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	/*
 	 * Force the orig field to the correct value; the application
@@ -165,7 +165,7 @@
 		size = (sizeof(struct ext2_inode_reference) * ent->max_refs);
 		new_refs = realloc(ref_ent->refs, size);
 		if (!new_refs)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		ref_ent->refs = new_refs;
 	}
 
@@ -181,7 +181,7 @@
 
 	ma = irel->private;
 	if (old > ma->max_inode)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	if (ma->entries[(unsigned) old].new == 0)
 		return ENOENT;
 	*ent = ma->entries[(unsigned) old];
@@ -196,7 +196,7 @@
 
 	ma = irel->private;
 	if (orig > ma->max_inode)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	ino = ma->orig_map[(unsigned) orig];
 	if (ino == 0)
 		return ENOENT;
@@ -238,7 +238,7 @@
 
 	ma = irel->private;
 	if (ino > ma->max_inode)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	ref_ent = ma->ref_entries + (unsigned) ino;
 	ent = ma->entries + (unsigned) ino;
@@ -251,13 +251,13 @@
 				  ent->max_refs));
 		ref_ent->refs = malloc(size);
 		if (ref_ent->refs == 0)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		memset(ref_ent->refs, 0, size);
 		ref_ent->num = 0;
 	}
 
 	if (ref_ent->num >= ent->max_refs)
-		return ENOSPC;
+		return EXT2_TOO_MANY_REFS;
 
 	ref_ent->refs[(unsigned) ref_ent->num++] = *ref;
 	return 0;
@@ -269,7 +269,7 @@
 
 	ma = irel->private;
 	if (ino > ma->max_inode)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	if (ma->entries[(unsigned) ino].new == 0)
 		return ENOENT;
 	ma->ref_current = ino;
@@ -304,7 +304,7 @@
 
 	ma = irel->private;
 	if ((old > ma->max_inode) || (new > ma->max_inode))
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	if (ma->entries[(unsigned) old].new == 0)
 		return ENOENT;
 	
@@ -327,7 +327,7 @@
 
 	ma = irel->private;
 	if (old > ma->max_inode)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 	if (ma->entries[(unsigned) old].new == 0)
 		return ENOENT;
 	
diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index ad4c736..621fd18 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -16,9 +16,6 @@
 #if HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 #include <fcntl.h>
 #ifdef HAVE_LINUX_FS_H
 #include <linux/fs.h>
diff --git a/lib/ext2fs/llseek.c b/lib/ext2fs/llseek.c
index 40275e7..46b82e7 100644
--- a/lib/ext2fs/llseek.c
+++ b/lib/ext2fs/llseek.c
@@ -13,7 +13,9 @@
 #include <sys/types.h>
 #endif
 
+#if HAVE_ERRNO_H
 #include <errno.h>
+#endif
 #include <stdlib.h>
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -112,7 +114,7 @@
 {
 	if ((sizeof(off_t) < sizeof(ext2_loff_t)) &&
 	    (offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) {
-		errno = EINVAL;
+		errno = EXT2_INVALID_ARGUMENT;
 		return -1;
 	}
 	return lseek (fd, (off_t) offset, origin);
diff --git a/lib/ext2fs/lookup.c b/lib/ext2fs/lookup.c
index cedaa04..7f17afa 100644
--- a/lib/ext2fs/lookup.c
+++ b/lib/ext2fs/lookup.c
@@ -15,9 +15,6 @@
 #include <unistd.h>
 #endif
 #include <stdlib.h>
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -68,7 +65,7 @@
 	if (retval)
 		return retval;
 
-	return (ls.found) ? 0 : ENOENT;
+	return (ls.found) ? 0 : EXT2_FILE_NOT_FOUND;
 }
 
 
diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c
index 2bfceb9..4a9f824 100644
--- a/lib/ext2fs/mkdir.c
+++ b/lib/ext2fs/mkdir.c
@@ -23,9 +23,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -114,7 +111,7 @@
 			name = 0;
 			goto cleanup;
 		}
-		if (retval != ENOENT)
+		if (retval != EXT2_FILE_NOT_FOUND)
 			goto cleanup;
 		retval = ext2fs_link(fs, parent, name, ino, 0);
 		if (retval)
diff --git a/lib/ext2fs/namei.c b/lib/ext2fs/namei.c
index a79cc72..9b718fe 100644
--- a/lib/ext2fs/namei.c
+++ b/lib/ext2fs/namei.c
@@ -15,9 +15,6 @@
 #include <unistd.h>
 #endif
 #include <stdlib.h>
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 /* #define NAMEI_DEBUG */
 
@@ -55,7 +52,7 @@
 	if (ei.i_blocks) {
 		buffer = malloc (fs->blocksize);
 		if (!buffer)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		retval = io_channel_read_blk(fs->io, ei.i_block[0], 1, buffer);
 		if (retval) {
 			free(buffer);
@@ -161,7 +158,7 @@
 
 	buf = malloc(fs->blocksize);
 	if (!buf)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	
 	retval = open_namei(fs, root, cwd, name, strlen(name), 0, 0,
 			    buf, inode);
@@ -180,7 +177,7 @@
 
 	buf = malloc(fs->blocksize);
 	if (!buf)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	
 	retval = open_namei(fs, root, cwd, name, strlen(name), 1, 0,
 			    buf, inode);
@@ -199,7 +196,7 @@
 
 	buf = malloc(fs->blocksize);
 	if (!buf)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	
 	retval = follow_link(fs, root, cwd, inode, 0, buf, res_inode);
 
diff --git a/lib/ext2fs/newdir.c b/lib/ext2fs/newdir.c
index 074a722..e9fdc29 100644
--- a/lib/ext2fs/newdir.c
+++ b/lib/ext2fs/newdir.c
@@ -15,9 +15,6 @@
 #include <unistd.h>
 #endif
 #include <stdlib.h>
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -37,7 +34,7 @@
 
 	buf = malloc(fs->blocksize);
 	if (!buf)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(buf, 0, fs->blocksize);
 	dir = (struct ext2_dir_entry *) buf;
 	dir->rec_len = fs->blocksize;
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 6b27397..07f47a5 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -19,9 +19,6 @@
 #endif
 #include <fcntl.h>
 #include <time.h>
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
@@ -58,7 +55,7 @@
 	
 	fs = (ext2_filsys) malloc(sizeof(struct struct_ext2_filsys));
 	if (!fs)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	
 	memset(fs, 0, sizeof(struct struct_ext2_filsys));
 	fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
@@ -70,13 +67,13 @@
 	fs->io->app_data = fs;
 	fs->device_name = malloc(strlen(name)+1);
 	if (!fs->device_name) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	strcpy(fs->device_name, name);
 	fs->super = malloc(SUPERBLOCK_SIZE);
 	if (!fs->super) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 
@@ -88,7 +85,7 @@
 	 */
 	if (superblock) {
 		if (!block_size) {
-			retval = EINVAL;
+			retval = EXT2_INVALID_ARGUMENT;
 			goto cleanup;
 		}
 		io_channel_set_blksize(fs->io, block_size);
@@ -177,7 +174,7 @@
 		/ EXT2_DESC_PER_BLOCK(fs->super);
 	fs->group_desc = malloc((size_t) (fs->desc_blocks * fs->blocksize));
 	if (!fs->group_desc) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	if (!group_block)
diff --git a/lib/ext2fs/rs_bitmap.c b/lib/ext2fs/rs_bitmap.c
index 9ee0da8..843482c 100644
--- a/lib/ext2fs/rs_bitmap.c
+++ b/lib/ext2fs/rs_bitmap.c
@@ -23,9 +23,6 @@
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -39,7 +36,7 @@
 	__u32	bitno;
 
 	if (!bmap)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_GENERIC_BITMAP);
 
@@ -64,7 +61,7 @@
 
 	new_bitmap = realloc(bmap->bitmap, new_size);
 	if (!new_bitmap)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	if (new_size > size)
 		memset(new_bitmap + size, 0, new_size - size);
 
@@ -80,7 +77,7 @@
 	errcode_t	retval;
 	
 	if (!bmap)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_INODE_BITMAP);
 
@@ -97,7 +94,7 @@
 	errcode_t	retval;
 	
 	if (!bmap)
-		return EINVAL;
+		return EXT2_INVALID_ARGUMENT;
 
 	EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_BLOCK_BITMAP);
 
diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c
index 015334f..a473d17 100644
--- a/lib/ext2fs/rw_bitmaps.c
+++ b/lib/ext2fs/rw_bitmaps.c
@@ -23,9 +23,6 @@
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
@@ -74,7 +71,7 @@
 	
 	bitmap_block = malloc(fs->blocksize);
 	if (!bitmap_block)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(bitmap_block, 0xff, fs->blocksize);
 	for (i = 0; i < fs->group_desc_count; i++) {
 		memcpy(bitmap_block, inode_bitmap, nbytes);
@@ -118,7 +115,7 @@
 	nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
 	bitmap_block = malloc(fs->blocksize);
 	if (!bitmap_block)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(bitmap_block, 0xff, fs->blocksize);
 	for (i = 0; i < fs->group_desc_count; i++) {
 		memcpy(bitmap_block, block_bitmap, nbytes);
diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c
index 3569482..7467815 100644
--- a/lib/ext2fs/test_io.c
+++ b/lib/ext2fs/test_io.c
@@ -23,9 +23,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include "et/com_err.h"
 #include "ext2fs/ext2_err.h"
@@ -90,19 +87,19 @@
 		return EXT2_ET_BAD_DEVICE_NAME;
 	io = (io_channel) malloc(sizeof(struct struct_io_channel));
 	if (!io)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(io, 0, sizeof(struct struct_io_channel));
 	io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
 	data = (struct test_private_data *)
 		malloc(sizeof(struct test_private_data));
 	if (!data) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	io->manager = test_io_manager;
 	io->name = malloc(strlen(name)+1);
 	if (!io->name) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	strcpy(io->name, name);
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 203ce57..f1d37b5 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -25,9 +25,6 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include "et/com_err.h"
 #include "ext2fs/ext2_err.h"
@@ -80,19 +77,19 @@
 		return EXT2_ET_BAD_DEVICE_NAME;
 	io = (io_channel) malloc(sizeof(struct struct_io_channel));
 	if (!io)
-		return ENOMEM;
+		return EXT2_NO_MEMORY;
 	memset(io, 0, sizeof(struct struct_io_channel));
 	io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
 	data = (struct unix_private_data *)
 		malloc(sizeof(struct unix_private_data));
 	if (!data) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	io->manager = unix_io_manager;
 	io->name = malloc(strlen(name)+1);
 	if (!io->name) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	strcpy(io->name, name);
@@ -107,7 +104,7 @@
 	data->buf = malloc(io->block_size);
 	data->buf_block_nr = -1;
 	if (!data->buf) {
-		retval = ENOMEM;
+		retval = EXT2_NO_MEMORY;
 		goto cleanup;
 	}
 	data->dev = open(name, (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY);
@@ -166,7 +163,7 @@
 		free(data->buf);
 		data->buf = malloc(blksize);
 		if (!data->buf)
-			return ENOMEM;
+			return EXT2_NO_MEMORY;
 		data->buf_block_nr = -1;
 	}
 	return 0;
diff --git a/lib/ext2fs/valid_blk.c b/lib/ext2fs/valid_blk.c
index ff49f80..c7ca2b3 100644
--- a/lib/ext2fs/valid_blk.c
+++ b/lib/ext2fs/valid_blk.c
@@ -17,9 +17,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 
diff --git a/lib/ext2fs/version.c b/lib/ext2fs/version.c
index 9e489ec..4e72f5c 100644
--- a/lib/ext2fs/version.c
+++ b/lib/ext2fs/version.c
@@ -17,9 +17,6 @@
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #include <linux/ext2_fs.h>
 #include "ext2fs.h"
diff --git a/tests/progs/test_data/expect.icount b/tests/progs/test_data/expect.icount
index 507550f..726d4f9 100644
--- a/tests/progs/test_data/expect.icount
+++ b/tests/progs/test_data/expect.icount
@@ -2,18 +2,18 @@
 Icount structure successfully validated
 test_icount: store 0
 usage: store inode counttest_icount: fetch 0
-fetch: Invalid argument while calling ext2fs_icount_fetch
+fetch: Invalid argument passed to ext2 library while calling ext2fs_icount_fetch
 test_icount: increment 0
-increment: Invalid argument while calling ext2fs_icount_increment
+increment: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: decrement 0
-decrement: Invalid argument while calling ext2fs_icount_increment
+decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: store 20001
 usage: store inode counttest_icount: fetch 20001
-fetch: Invalid argument while calling ext2fs_icount_fetch
+fetch: Invalid argument passed to ext2 library while calling ext2fs_icount_fetch
 test_icount: increment 20001
-increment: Invalid argument while calling ext2fs_icount_increment
+increment: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: decrement 20001
-decrement: Invalid argument while calling ext2fs_icount_increment
+decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: validate
 Icount structure successfully validated
 test_icount: fetch 1
@@ -56,7 +56,7 @@
 test_icount: get_size
 Size of icount is: 5
 test_icount: decrement 2
-decrement: Invalid argument while calling ext2fs_icount_increment
+decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: increment 2
 Count is now 1
 test_icount: fetch 2
@@ -88,7 +88,7 @@
 test_icount: decrement 2
 Count is now 0
 test_icount: decrement 2
-decrement: Invalid argument while calling ext2fs_icount_increment
+decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: store 3 1
 test_icount: increment 3
 Count is now 2
@@ -128,9 +128,9 @@
 test_icount: decrement 4
 Count is now 0
 test_icount: decrement 4
-decrement: Invalid argument while calling ext2fs_icount_increment
+decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: decrement 4
-decrement: Invalid argument while calling ext2fs_icount_increment
+decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: store 5 4
 test_icount: decrement 5
 Count is now 3
@@ -141,7 +141,7 @@
 test_icount: decrement 5
 Count is now 0
 test_icount: decrement 5
-decrement: Invalid argument while calling ext2fs_icount_increment
+decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
 test_icount: get_size
 Size of icount is: 105
 test_icount: validate