Fix the Apple Darwin port.

diff --git a/ChangeLog b/ChangeLog
index 1656b93..c6cfaf9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2003-03-17  Theodore Ts'o  <tytso@mit.edu>
+
+	* configure.in: Fix the Apple Darwin port.
+
 2003-03-16  Theodore Ts'o  <tytso@mit.edu>
 
 	* configure.in: Check to see if libdl exists for the sake of dlopen
diff --git a/configure b/configure
index 3c5862f..25987bf 100644
--- a/configure
+++ b/configure
@@ -1215,7 +1215,7 @@
 	MAKEFILE_BSDLIB=$srcdir/lib/Makefile.bsd-lib
 	LIB_EXT=.so
 	case "$host_os" in
-	darwin.*)
+	darwin*)
 		MAKEFILE_BSDLIB=$srcdir/lib/Makefile.darwin-lib
 		LIB_EXT=.dylib
 	;;
diff --git a/configure.in b/configure.in
index 53bb716..89d83ce 100644
--- a/configure.in
+++ b/configure.in
@@ -259,7 +259,7 @@
 	MAKEFILE_BSDLIB=$srcdir/lib/Makefile.bsd-lib
 	LIB_EXT=.so
 	[case "$host_os" in
-	darwin.*)
+	darwin*)
 		MAKEFILE_BSDLIB=$srcdir/lib/Makefile.darwin-lib
 		LIB_EXT=.dylib
 	;;
diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog
index c02827e..0fb8642 100644
--- a/e2fsck/ChangeLog
+++ b/e2fsck/ChangeLog
@@ -1,3 +1,8 @@
+2003-03-17  Theodore Ts'o  <tytso@mit.edu>
+
+	* util.c: Explicitly declare e2fsck_global_ctx as extern for the
+		benefit of the Apple Darwin port.
+
 2003-03-15  Theodore Ts'o  <tytso@mit.edu>
 
 	* rehash.c (e2fsck_rehash_dir): If user specified the -n option,
diff --git a/e2fsck/util.c b/e2fsck/util.c
index b9ad4d4..2c890dc 100644
--- a/e2fsck/util.c
+++ b/e2fsck/util.c
@@ -31,7 +31,7 @@
 
 #include "e2fsck.h"
 
-e2fsck_t e2fsck_global_ctx;	/* Try your very best not to use this! */
+extern e2fsck_t e2fsck_global_ctx;   /* Try your very best not to use this! */
 
 #include <sys/time.h>
 #include <sys/resource.h>
diff --git a/lib/ChangeLog b/lib/ChangeLog
index cb95c34..b4d8f75 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,7 @@
+2003-03-17  Theodore Ts'o  <tytso@mit.edu>
+
+	* Makefile.darwin-lib: Fix Apple Darwin port.
+
 2003-03-14  Theodore Ts'o  <tytso@mit.edu>
 
 	* Makefile.darwin-lib: New file to provide support for e2fsprogs
diff --git a/lib/Makefile.darwin-lib b/lib/Makefile.darwin-lib
index 4bacd27..77c5bac 100644
--- a/lib/Makefile.darwin-lib
+++ b/lib/Makefile.darwin-lib
@@ -2,8 +2,7 @@
 # This is a Makefile stub which handles the creation of Darwin BSD shared
 # libraries.
 #
-# In order to use this stub, the following makefile variables must be 
-efined.
+# In order to use this stub, the following makefile variables must be defined.
 #
 # BSDLIB_VERSION = 1.0
 # BSDLIB_IMAGE = libce
@@ -23,8 +22,7 @@
 image:		$(BSD_LIB)
 
 $(BSD_LIB): $(OBJS)
-	(cd pic; $(CC) -dynamiclib -compatibility_version 1.0 
- -current_version $(BSDLIB_VERSION) \
+	(cd pic; $(CC) -dynamiclib -compatibility_version 1.0 -current_version $(BSDLIB_VERSION) \
 		-flat_namespace -undefined warning -o $(BSD_LIB) $(OBJS))
 	$(MV) pic/$(BSD_LIB) .
 	$(RM) -f ../$(BSD_LIB)
diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog
index a49a16a..c2bf686 100644
--- a/lib/blkid/ChangeLog
+++ b/lib/blkid/ChangeLog
@@ -1,3 +1,7 @@
+2003-03-17  Theodore Ts'o  <tytso@mit.edu>
+
+	* getsize.c (blkid_get_dev_size): Fix Apple Darwin port.
+
 2003-03-06    <tytso@mit.edu>
 
 	* devname.c (probe_one): Fix bug; if a partition has no known
diff --git a/lib/blkid/getsize.c b/lib/blkid/getsize.c
index da809dc..c83b1dd 100644
--- a/lib/blkid/getsize.c
+++ b/lib/blkid/getsize.c
@@ -35,6 +35,13 @@
 #define BLKGETSIZE _IO(0x12,96)	/* return device size */
 #endif
 
+#ifdef APPLE_DARWIN
+#include <sys/ioctl.h>
+#include <sys/disk.h>
+
+#define BLKGETSIZE DKIOCGETBLOCKCOUNT32
+#endif /* APPLE_DARWIN */
+
 static int valid_offset(int fd, blkid_loff_t offset)
 {
 	char ch;
@@ -59,10 +66,11 @@
 	struct floppy_struct this_floppy;
 #endif
 #ifdef HAVE_SYS_DISKLABEL_H
-	int part;
+	int part = -1;
 	struct disklabel lab;
 	struct partition *pp;
 	char ch;
+	struct stat st;
 #endif /* HAVE_SYS_DISKLABEL_H */
 
 #ifdef BLKGETSIZE
@@ -74,21 +82,20 @@
 		return (blkid_loff_t)this_floppy.size << 9;
 #endif
 #ifdef HAVE_SYS_DISKLABEL_H
-	part = strlen(file) - 1;
-	if (part >= 0) {
-		ch = file[part];
-		if (isdigit(ch))
-			part = 0;
-		else if (ch >= 'a' && ch <= 'h')
-			part = ch - 'a';
-		else
-			part = -1;
-	}
+#if 0
+	/*
+	 * This should work in theory but I haven't tested it.  Anyone
+	 * on a BSD system want to test this for me?  In the meantime,
+	 * binary search mechanism should work just fine.
+	 */
+	if ((fstat(fd, &st) >= 0) && S_ISBLK(st.st_mode))
+		part = st.st_rdev & 7;
 	if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) {
 		pp = &lab.d_partitions[part];
 		if (pp->p_size)
 			return pp->p_size << 9;
 	}
+#endif
 #endif /* HAVE_SYS_DISKLABEL_H */
 
 	/*