Add portability enhancements for Cygwin32 environment.

diff --git a/lib/e2p/ChangeLog b/lib/e2p/ChangeLog
index 5e7effd..3886e6f 100644
--- a/lib/e2p/ChangeLog
+++ b/lib/e2p/ChangeLog
@@ -1,3 +1,8 @@
+2003-04-12  Theodore Ts'o  <tytso@mit.edu>
+
+	* iod.c (iterate_on_dir): Support systems that don't have d_reclen
+		in struct dirent.
+
 2003-04-11  Theodore Ts'o  <tytso@mit.edu>
 
 	* feature.c: Remove support for EXT2_FEATURE_RO_COMPAT_BTREE_DIR,
diff --git a/lib/e2p/iod.c b/lib/e2p/iod.c
index c5d34cd..42e69d9 100644
--- a/lib/e2p/iod.c
+++ b/lib/e2p/iod.c
@@ -54,11 +54,13 @@
 		return -1;
 	}
 	while ((dep = readdir (dir))) {
-		len = dep->d_reclen;
-		if (len < (sizeof(struct dirent)))
-			len = sizeof(struct dirent);
+		len = sizeof(struct dirent);
+#ifdef HAVE_RECLEN_DIRENT
+		if (len < dep->d_reclen)
+			len = dep->d_reclen;
 		if (len > max_len)
 			len = max_len;
+#endif
 		memcpy(de, dep, len);
 		(*func) (dir_name, de, private);
 	}
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index 91f7627..13423ed 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,3 +1,13 @@
+2003-04-12  Theodore Ts'o  <tytso@mit.edu>
+
+	* unix_io.c (raw_read_blk): Add Cygwin support (the Windows block
+		device only accepts sector aligned read requests.
+
+	* ismounted.c (check_mntent_file): Deal with OS's that don't
+		define MNTOPT_RO.
+
+	* imager.c: If the OS doesn't define ssize_t, typedef it to int.
+
 2003-04-11  Theodore Ts'o  <tytso@mit.edu>
 
 	* ext2_fs.h (EXT2_FEATURE_RO_COMPAT_BTREE_DIR): Comment out unused
diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c
index 242e36a..b72a9fb 100644
--- a/lib/ext2fs/imager.c
+++ b/lib/ext2fs/imager.c
@@ -33,6 +33,10 @@
 #include "ext2_fs.h"
 #include "ext2fs.h"
 
+#ifndef HAVE_TYPE_SSIZE_T
+typedef int ssize_t;
+#endif
+
 /*
  * This function returns 1 if the specified block is all zeros
  */
diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index 26e8054..d3ff276 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -129,9 +129,11 @@
 #endif /* __GNU__ */
 	*mount_flags = EXT2_MF_MOUNTED;
 	
+#ifdef MNTOPT_RO
 	/* Check to see if the ro option is set */
 	if (hasmntopt(mnt, MNTOPT_RO))
 		*mount_flags |= EXT2_MF_READONLY;
+#endif
 
 	if (mtpt)
 		strncpy(mtpt, mnt->mnt_dir, mtlen);
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 3123136..aa9ff14 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -1,8 +1,11 @@
 /*
- * unix_io.c --- This is the Unix I/O interface to the I/O manager.
+ * unix_io.c --- This is the Unix (well, really POSIX) implementation
+ * 	of the I/O manager.
  *
  * Implements a one-block write-through cache.
  *
+ * Includes support for Windows NT support under Cygwin. 
+ *
  * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
  * 	2002 by Theodore Ts'o.
  *
@@ -34,7 +37,9 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
+#if HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
+#endif
 
 #include "ext2_fs.h"
 #include "ext2fs.h"
@@ -89,7 +94,11 @@
 	unix_read_blk,
 	unix_write_blk,
 	unix_flush,
+#ifdef CYGWIN
+	0
+#else
 	unix_write_byte
+#endif
 };
 
 io_manager unix_io_manager = &struct_unix_manager;
@@ -97,6 +106,7 @@
 /*
  * Here are the raw I/O functions
  */
+#ifndef CYGWIN
 static errcode_t raw_read_blk(io_channel channel,
 			      struct unix_private_data *data,
 			      unsigned long block,
@@ -129,6 +139,60 @@
 					       size, actual, retval);
 	return retval;
 }
+#else /* CYGWIN */
+/*
+ * Windows block devices only allow sector alignment IO in offset and size
+ */
+static errcode_t raw_read_blk(io_channel channel,
+			      struct unix_private_data *data,
+			      unsigned long block,
+			      int count, void *buf)
+{
+	errcode_t	retval;
+	size_t		size, alignsize, fragment;
+	ext2_loff_t	location;
+	int		total = 0, actual;
+#define BLOCKALIGN 512
+	char		sector[BLOCKALIGN];
+
+	size = (count < 0) ? -count : count * channel->block_size;
+	location = (ext2_loff_t) block * channel->block_size;
+#ifdef DEBUG
+	printf("count=%d, size=%d, block=%d, blk_size=%d, location=%lx\n",
+	 		count, size, block, channel->block_size, location);
+#endif
+	if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
+		retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
+		goto error_out;
+	}
+	fragment = size % BLOCKALIGN;
+	alignsize = size - fragment;
+	if (alignsize) {
+		actual = read(data->dev, buf, alignsize);
+		if (actual != alignsize)
+			goto short_read;
+	}
+	if (fragment) {
+		actual = read(data->dev, sector, BLOCKALIGN);
+		if (actual != BLOCKALIGN)
+			goto short_read;
+		memcpy(buf+alignsize, sector, fragment);
+	}
+	return 0;
+
+short_read:
+	if (actual>0)
+		total += actual;
+	retval = EXT2_ET_SHORT_READ;
+
+error_out:
+	memset((char *) buf+total, 0, size-actual);
+	if (channel->read_error)
+		retval = (channel->read_error)(channel, block, count, buf,
+					       size, actual, retval);
+	return retval;
+}
+#endif
 
 static errcode_t raw_write_blk(io_channel channel,
 			       struct unix_private_data *data,
@@ -295,8 +359,6 @@
 	return retval2;
 }
 
-
-
 static errcode_t unix_open(const char *name, int flags, io_channel *channel)
 {
 	io_channel	io = NULL;
diff --git a/lib/ss/ChangeLog b/lib/ss/ChangeLog
index 59f0941..075e6bf 100644
--- a/lib/ss/ChangeLog
+++ b/lib/ss/ChangeLog
@@ -1,4 +1,8 @@
-2003-04-11  root  <tytso@mit.edu>
+2003-04-12  Theodore Ts'o  <tytso@mit.edu>
+
+	* help.c: Add #ifdef protection around #include <sys/wait.h>
+
+2003-04-11  Theodore Ts'o  <tytso@mit.edu>
 
 	* get_readline.c (DEFAULT_LIBPATH): Use the SS_READLINE_PATH
 		environment variable to control the search for a suitable
diff --git a/lib/ss/help.c b/lib/ss/help.c
index 1c9b3a2..235633f 100644
--- a/lib/ss/help.c
+++ b/lib/ss/help.c
@@ -30,7 +30,9 @@
 /* just for O_* */
 #include <sys/fcntl.h>
 #endif
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include "ss_internal.h"
 
 void ss_help (argc, argv, sci_idx, info_ptr)
diff --git a/lib/uuid/ChangeLog b/lib/uuid/ChangeLog
index fca6088..ce24a2d 100644
--- a/lib/uuid/ChangeLog
+++ b/lib/uuid/ChangeLog
@@ -1,3 +1,8 @@
+2003-04-12  Theodore Ts'o  <tytso@mit.edu>
+
+	* gen_uuid.c: Add #ifdef checks around #include <sys/ioctl.h> and
+		<sys/socket.h>.
+
 2003-04-03  Theodore Ts'o  <tytso@mit.edu>
 
 	* gen_uuid.c (get_random_bytes): Always xor in a stream of bytes
diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c
index 158b6bd..87755d1 100644
--- a/lib/uuid/gen_uuid.c
+++ b/lib/uuid/gen_uuid.c
@@ -28,8 +28,12 @@
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/file.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
 #ifdef HAVE_SYS_SOCKIO_H
 #include <sys/sockio.h>
 #endif