Add portability enhancements for Cygwin32 environment.

diff --git a/configure b/configure
index e22c3b8..9ebc5a1 100644
--- a/configure
+++ b/configure
@@ -4168,7 +4168,7 @@
 done
 
 fi
-for ac_hdr in stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h net/if.h netinet/in.h
+for ac_hdr in stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/socket.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h sys/wait.h sys/resource.h net/if.h netinet/in.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
@@ -4313,20 +4313,84 @@
 
 fi
 
-echo $ac_n "checking whether llseek declared in unistd.h""... $ac_c" 1>&6
-echo "configure:4318: checking whether llseek declared in unistd.h" >&5
-if eval "test \"`echo '$''{'e2fsprogs_cv_have_llseek_prototype'+set}'`\" = set"; then
+echo $ac_n "checking whether d_reclen declared in dirent""... $ac_c" 1>&6
+echo "configure:4318: checking whether d_reclen declared in dirent" >&5
+if eval "test \"`echo '$''{'e2fsprogs_cv_have_d_reclen_dirent'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
 #line 4323 "configure"
 #include "confdefs.h"
+#include <dirent.h>
+int main() {
+struct dirent de; de.d_reclen = 0; 
+; return 0; }
+EOF
+if { (eval echo configure:4330: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  rm -rf conftest*
+  e2fsprogs_cv_have_d_reclen_dirent=yes
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  e2fsprogs_cv_have_d_reclen_dirent=no
+fi
+rm -f conftest*
+fi
+
+echo "$ac_t""$e2fsprogs_cv_have_d_reclen_dirent" 1>&6
+if test "$e2fsprogs_cv_have_d_reclen_dirent" = yes; then
+   cat >> confdefs.h <<\EOF
+#define HAVE_RECLEN_DIRENT 1
+EOF
+
+fi
+echo $ac_n "checking whether ssize_t declared""... $ac_c" 1>&6
+echo "configure:4350: checking whether ssize_t declared" >&5
+if eval "test \"`echo '$''{'e2fsprogs_cv_have_ssize_t'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 4355 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+int main() {
+ssize_t a = 0; 
+; return 0; }
+EOF
+if { (eval echo configure:4362: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  rm -rf conftest*
+  e2fsprogs_cv_have_ssize_t=yes
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  e2fsprogs_cv_have_ssize_t=no
+fi
+rm -f conftest*
+fi
+
+echo "$ac_t""$e2fsprogs_cv_have_ssize_t" 1>&6
+if test "$e2fsprogs_cv_have_ssize_t" = yes; then
+   cat >> confdefs.h <<\EOF
+#define HAVE_TYPE_SSIZE_T 1
+EOF
+
+fi
+echo $ac_n "checking whether llseek declared in unistd.h""... $ac_c" 1>&6
+echo "configure:4382: checking whether llseek declared in unistd.h" >&5
+if eval "test \"`echo '$''{'e2fsprogs_cv_have_llseek_prototype'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 4387 "configure"
+#include "confdefs.h"
 #include <unistd.h>
 int main() {
 extern int llseek(int);
 ; return 0; }
 EOF
-if { (eval echo configure:4330: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:4394: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   e2fsprogs_cv_have_llseek_prototype=no
 else
@@ -4346,12 +4410,12 @@
 
 fi
 echo $ac_n "checking whether lseek64 declared in unistd.h""... $ac_c" 1>&6
-echo "configure:4350: checking whether lseek64 declared in unistd.h" >&5
+echo "configure:4414: checking whether lseek64 declared in unistd.h" >&5
 if eval "test \"`echo '$''{'e2fsprogs_cv_have_lseek64_prototype'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4355 "configure"
+#line 4419 "configure"
 #include "confdefs.h"
 #define _LARGEFILE_SOURCE
 #define _LARGEFILE64_SOURCE
@@ -4360,7 +4424,7 @@
 extern int lseek64(int);
 ; return 0; }
 EOF
-if { (eval echo configure:4364: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:4428: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   e2fsprogs_cv_have_lseek64_prototype=no
 else
@@ -4388,7 +4452,7 @@
   echo "configure: warning: Cross-compiling, so cannot check type sizes; assuming short=2, int=4, long=4, long long=8" 1>&2
 fi
 echo $ac_n "checking size of short""... $ac_c" 1>&6
-echo "configure:4392: checking size of short" >&5
+echo "configure:4456: checking size of short" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_short'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -4396,7 +4460,7 @@
     { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
 else
   cat > conftest.$ac_ext <<EOF
-#line 4400 "configure"
+#line 4464 "configure"
 #include "confdefs.h"
 #include <stdio.h>
 #include <sys/types.h>
@@ -4408,7 +4472,7 @@
   exit(0);
 }
 EOF
-if { (eval echo configure:4412: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4476: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_short=`cat conftestval`
 else
@@ -4428,7 +4492,7 @@
 
 
 echo $ac_n "checking size of int""... $ac_c" 1>&6
-echo "configure:4432: checking size of int" >&5
+echo "configure:4496: checking size of int" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -4436,7 +4500,7 @@
     { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
 else
   cat > conftest.$ac_ext <<EOF
-#line 4440 "configure"
+#line 4504 "configure"
 #include "confdefs.h"
 #include <stdio.h>
 #include <sys/types.h>
@@ -4448,7 +4512,7 @@
   exit(0);
 }
 EOF
-if { (eval echo configure:4452: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4516: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_int=`cat conftestval`
 else
@@ -4468,7 +4532,7 @@
 
 
 echo $ac_n "checking size of long""... $ac_c" 1>&6
-echo "configure:4472: checking size of long" >&5
+echo "configure:4536: checking size of long" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_long'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -4476,7 +4540,7 @@
     { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
 else
   cat > conftest.$ac_ext <<EOF
-#line 4480 "configure"
+#line 4544 "configure"
 #include "confdefs.h"
 #include <stdio.h>
 #include <sys/types.h>
@@ -4488,7 +4552,7 @@
   exit(0);
 }
 EOF
-if { (eval echo configure:4492: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4556: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_long=`cat conftestval`
 else
@@ -4508,7 +4572,7 @@
 
 
 echo $ac_n "checking size of long long""... $ac_c" 1>&6
-echo "configure:4512: checking size of long long" >&5
+echo "configure:4576: checking size of long long" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_long_long'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -4516,7 +4580,7 @@
     { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
 else
   cat > conftest.$ac_ext <<EOF
-#line 4520 "configure"
+#line 4584 "configure"
 #include "confdefs.h"
 #include <stdio.h>
 #include <sys/types.h>
@@ -4528,7 +4592,7 @@
   exit(0);
 }
 EOF
-if { (eval echo configure:4532: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4596: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_long_long=`cat conftestval`
 else
@@ -4556,14 +4620,14 @@
 
 
 echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6
-echo "configure:4560: checking whether byte ordering is bigendian" >&5
+echo "configure:4624: checking whether byte ordering is bigendian" >&5
 if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_cv_c_bigendian=unknown
 # See if sys/param.h defines the BYTE_ORDER macro.
 cat > conftest.$ac_ext <<EOF
-#line 4567 "configure"
+#line 4631 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/param.h>
@@ -4574,11 +4638,11 @@
 #endif
 ; return 0; }
 EOF
-if { (eval echo configure:4578: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:4642: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   # It does; now see whether it defined to BIG_ENDIAN or not.
 cat > conftest.$ac_ext <<EOF
-#line 4582 "configure"
+#line 4646 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/param.h>
@@ -4589,7 +4653,7 @@
 #endif
 ; return 0; }
 EOF
-if { (eval echo configure:4593: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:4657: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_bigendian=yes
 else
@@ -4609,7 +4673,7 @@
     { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
 else
   cat > conftest.$ac_ext <<EOF
-#line 4613 "configure"
+#line 4677 "configure"
 #include "confdefs.h"
 main () {
   /* Are we little or big endian?  From Harbison&Steele.  */
@@ -4622,7 +4686,7 @@
   exit (u.c[sizeof (long) - 1] == 1);
 }
 EOF
-if { (eval echo configure:4626: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4690: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_c_bigendian=no
 else
@@ -4646,19 +4710,19 @@
 fi
 
 echo $ac_n "checking whether struct stat has a st_flags field""... $ac_c" 1>&6
-echo "configure:4650: checking whether struct stat has a st_flags field" >&5
+echo "configure:4714: checking whether struct stat has a st_flags field" >&5
 if eval "test \"`echo '$''{'e2fsprogs_cv_struct_st_flags'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4655 "configure"
+#line 4719 "configure"
 #include "confdefs.h"
 #include <sys/stat.h>
 int main() {
 struct stat stat; stat.st_flags = 0;
 ; return 0; }
 EOF
-if { (eval echo configure:4662: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:4726: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   e2fsprogs_cv_struct_st_flags=yes
 else
@@ -4673,19 +4737,19 @@
 echo "$ac_t""$e2fsprogs_cv_struct_st_flags" 1>&6
 if test "$e2fsprogs_cv_struct_st_flags" = yes; then
   echo $ac_n "checking whether st_flags field is useful""... $ac_c" 1>&6
-echo "configure:4677: checking whether st_flags field is useful" >&5
+echo "configure:4741: checking whether st_flags field is useful" >&5
   if eval "test \"`echo '$''{'e2fsprogs_cv_struct_st_flags_immut'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4682 "configure"
+#line 4746 "configure"
 #include "confdefs.h"
 #include <sys/stat.h>
 int main() {
 struct stat stat; stat.st_flags |= UF_IMMUTABLE;
 ; return 0; }
 EOF
-if { (eval echo configure:4689: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:4753: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   e2fsprogs_cv_struct_st_flags_immut=yes
 else
@@ -4708,12 +4772,12 @@
 for ac_func in chflags getrusage llseek lseek64 open64 getmntinfo strtoull strcasecmp srandom fchown mallinfo fdatasync strnlen sysconf pathconf
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4712: checking for $ac_func" >&5
+echo "configure:4776: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4717 "configure"
+#line 4781 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -4736,7 +4800,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:4740: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4804: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -4762,7 +4826,7 @@
 
 SOCKET_LIB=''
 echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6
-echo "configure:4766: checking for socket in -lsocket" >&5
+echo "configure:4830: checking for socket in -lsocket" >&5
 ac_lib_var=`echo socket'_'socket | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -4770,7 +4834,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lsocket  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4774 "configure"
+#line 4838 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -4781,7 +4845,7 @@
 socket()
 ; return 0; }
 EOF
-if { (eval echo configure:4785: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4849: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -4804,7 +4868,7 @@
 
 DLOPEN_LIB=''
 echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4808: checking for dlopen in -ldl" >&5
+echo "configure:4872: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -4812,7 +4876,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4816 "configure"
+#line 4880 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -4823,7 +4887,7 @@
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4827: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4891: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -4849,12 +4913,12 @@
 
 
 echo $ac_n "checking for optreset""... $ac_c" 1>&6
-echo "configure:4853: checking for optreset" >&5
+echo "configure:4917: checking for optreset" >&5
 if eval "test \"`echo '$''{'ac_cv_have_optreset'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4858 "configure"
+#line 4922 "configure"
 #include "confdefs.h"
 #include <unistd.h>
 EOF
@@ -4885,12 +4949,24 @@
 	;;
 esac
 LINUX_CMT="#"
+CYGWIN_CMT="#"
+UNIX_CMT=
 case "$host_os" in
 linux*)
 	LINUX_CMT=
 	;;
+cygwin)
+	CYGWIN_CMT=
+	UNIX_CMT="#"
+	cat >> confdefs.h <<\EOF
+#define WIN32 1
+EOF
+
+	;;
 esac
 
+
+
 case "$host_os" in
 linux* | gnu*)
 	if test "$prefix" = NONE -a "$root_prefix" = NONE ; then
@@ -4933,20 +5009,20 @@
 
 
 echo $ac_n "checking whether linker accepts -static""... $ac_c" 1>&6
-echo "configure:4937: checking whether linker accepts -static" >&5
+echo "configure:5013: checking whether linker accepts -static" >&5
 if eval "test \"`echo '$''{'ac_cv_e2fsprogs_use_static'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   SAVE_LDFLAGS=$LDFLAGS; LDFLAGS="$LDFLAGS -static"
 cat > conftest.$ac_ext <<EOF
-#line 4943 "configure"
+#line 5019 "configure"
 #include "confdefs.h"
 #include <stdio.h>
 int main() {
 fflush(stdout);
 ; return 0; }
 EOF
-if { (eval echo configure:4950: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5026: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_e2fsprogs_use_static=yes
 else
@@ -5241,6 +5317,8 @@
 s%@SOCKET_LIB@%$SOCKET_LIB%g
 s%@DLOPEN_LIB@%$DLOPEN_LIB%g
 s%@LINUX_CMT@%$LINUX_CMT%g
+s%@CYGWIN_CMT@%$CYGWIN_CMT%g
+s%@UNIX_CMT@%$UNIX_CMT%g
 s%@root_prefix@%$root_prefix%g
 s%@root_bindir@%$root_bindir%g
 s%@root_sbindir@%$root_sbindir%g
diff --git a/configure.in b/configure.in
index 368fc4c..01e8290 100644
--- a/configure.in
+++ b/configure.in
@@ -531,8 +531,31 @@
 else
   AC_CHECK_PROGS(BUILD_CC, gcc cc)
 fi
-AC_CHECK_HEADERS(stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h net/if.h netinet/in.h)
+AC_CHECK_HEADERS(stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/socket.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h sys/wait.h sys/resource.h net/if.h netinet/in.h)
 AC_FUNC_VPRINTF
+dnl Check to see if dirent has member d_reclen. On cygwin those d_reclen
+dnl is not decleared.
+AC_MSG_CHECKING(whether d_reclen declared in dirent)
+AC_CACHE_VAL(e2fsprogs_cv_have_d_reclen_dirent,
+	AC_TRY_COMPILE(
+[#include <dirent.h>], [struct dirent de; de.d_reclen = 0; ],
+	[e2fsprogs_cv_have_d_reclen_dirent=yes],
+	[e2fsprogs_cv_have_d_reclen_dirent=no]))
+AC_MSG_RESULT($e2fsprogs_cv_have_d_reclen_dirent)
+if test "$e2fsprogs_cv_have_d_reclen_dirent" = yes; then
+   AC_DEFINE(HAVE_RECLEN_DIRENT)
+fi
+dnl Check to see if ssize_t was decleared
+AC_MSG_CHECKING(whether ssize_t declared)
+AC_CACHE_VAL(e2fsprogs_cv_have_ssize_t,
+	AC_TRY_COMPILE(
+[#include <sys/types.h>], [ssize_t a = 0; ],
+	[e2fsprogs_cv_have_ssize_t=yes],
+	[e2fsprogs_cv_have_ssize_t=no]))
+AC_MSG_RESULT($e2fsprogs_cv_have_ssize_t)
+if test "$e2fsprogs_cv_have_ssize_t" = yes; then
+   AC_DEFINE(HAVE_TYPE_SSIZE_T)
+fi
 dnl
 dnl Check to see if llseek() is declared in unistd.h.  On some libc's 
 dnl it is, and on others it isn't..... Thank you glibc developers....
@@ -654,15 +677,24 @@
 	;;
 esac
 dnl
-dnl Uncomment only if Linux
+dnl OS-specific uncomment control
 dnl
 LINUX_CMT="#"
+CYGWIN_CMT="#"
+UNIX_CMT=
 case "$host_os" in
 linux*)
 	LINUX_CMT=
 	;;
+cygwin)
+	CYGWIN_CMT=
+	UNIX_CMT="#"
+	AC_DEFINE(CYGWIN)
+	;;
 esac
 AC_SUBST(LINUX_CMT)
+AC_SUBST(CYGWIN_CMT)
+AC_SUBST(UNIX_CMT)
 dnl
 dnl Linux and Hurd places root files in the / by default
 dnl
diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog
index 5109482..bb800dc 100644
--- a/e2fsck/ChangeLog
+++ b/e2fsck/ChangeLog
@@ -1,3 +1,7 @@
+2003-04-12  Theodore Ts'o  <tytso@mit.edu>
+
+	* unix.c: Add #ifdef around #include <sys/ioctl.h>
+
 2003-04-05  Theodore Ts'o  <tytso@mit.edu>
 
 	* super.c (check_super_block): Update the global free block and
diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index c9d1da2..3c3acad 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -33,7 +33,9 @@
 #ifdef HAVE_MNTENT_H
 #include <mntent.h>
 #endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #ifdef HAVE_MALLOC_H
 #include <malloc.h>
 #endif
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