Package: util-linux
Version: 2.12m
Author: Guillem Jover <guillem@debian.org>
Status: obsolete
Description:
 Resync port to GNU variants.

diff -Naur util-linux-2.12m/configure util-linux-2.12m.port/configure
--- util-linux-2.12m/configure	2004-12-12 20:36:03.000000000 +0100
+++ util-linux-2.12m.port/configure	2004-12-22 11:19:11.000000000 +0100
@@ -304,6 +304,7 @@
 
 #
 # F6. For agetty.c: is updwtmp() available?
+# F7. For mcookie.c: is gettimeofday() available?
 #
 echo '
 #include <string.h>
@@ -520,6 +521,28 @@
 fi
 rm -f conftest conftest.c
 
+#
+# F7. For mcookie.c: is gettimeofday() available?
+#
+echo '
+#include <sys/time.h>
+#include <unistd.h>
+main(int a, char **v){
+  struct timeval    tv;
+  struct timezone   tz;
+  gettimeofday( &tv, &tz );
+  exit(0);
+}
+' > conftest.c
+eval $compile
+if test -s conftest && ./conftest 2>/dev/null; then
+        echo "#define HAVE_gettimeofday" >> defines.h
+        echo "You have gettimeofday()"
+else
+        echo "You don't have gettimeofday()"
+fi
+rm -f conftest conftest.c
+
 
 #
 # 7. Does xgettext exist and take the option --foreign-user?
diff -Naur util-linux-2.12m/disk-utils/fsck.cramfs.c util-linux-2.12m.port/disk-utils/fsck.cramfs.c
--- util-linux-2.12m/disk-utils/fsck.cramfs.c	2004-12-11 15:53:16.000000000 +0100
+++ util-linux-2.12m.port/disk-utils/fsck.cramfs.c	2004-12-22 11:19:11.000000000 +0100
@@ -47,14 +47,12 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
-#include <sys/ioctl.h>
 #include <sys/sysmacros.h>	/* for major, minor */
 
 #include "cramfs.h"
 #include "../defines.h"		/* for HAVE_lchown */
 #include "nls.h"
-
-#define BLKGETSIZE _IO(0x12,96) /* return device size */
+#include "disk_size.h"
 
 static const char *progname = "cramfsck";
 
@@ -503,22 +501,8 @@
 		perror(filename);
 		exit(8);
 	}
-	if (S_ISBLK(st.st_mode)) {
-		if (ioctl(fd, BLKGETSIZE, &length) < 0) {
-			fprintf(stderr, _("%s: warning--unable to determine "
-					  "filesystem size \n"), filename);
-			exit(4);
-		}
-		length = length * 512;
-	}
-	else if (S_ISREG(st.st_mode)) {
-		length = st.st_size;
-	}
-	else {
-		fprintf(stderr, _("%s is not a block device or file\n"),
-			filename);
-		exit(8);
-	}
+
+	length = (size_t)disk_get_sectors(fd) * 512;
 
 	if (length < sizeof(struct cramfs_super)) {
 		fprintf(stderr, _("%s: invalid cramfs--file length "
diff -Naur util-linux-2.12m/disk-utils/fsck.minix.c util-linux-2.12m.port/disk-utils/fsck.minix.c
--- util-linux-2.12m/disk-utils/fsck.minix.c	2004-08-25 00:21:39.000000000 +0200
+++ util-linux-2.12m.port/disk-utils/fsck.minix.c	2004-12-22 11:20:17.000000000 +0100
@@ -99,10 +99,6 @@
 #include "minix.h"
 #include "nls.h"
 
-#ifndef __linux__
-#define volatile
-#endif
-
 #define ROOT_INO 1
 
 #define UPPER(size,n) ((size+((n)-1))/(n))
diff -Naur util-linux-2.12m/disk-utils/Makefile util-linux-2.12m.port/disk-utils/Makefile
--- util-linux-2.12m/disk-utils/Makefile	2002-11-02 14:52:47.000000000 +0100
+++ util-linux-2.12m.port/disk-utils/Makefile	2004-12-22 12:42:12.000000000 +0100
@@ -8,24 +8,34 @@
 
 # Where to put man pages?
 
-MAN8= 	blockdev.8 fdformat.8 isosize.8 mkfs.8 mkswap.8 elvtune.8 \
-	fsck.minix.8 mkfs.minix.8 mkfs.bfs.8
+MAN8= 	isosize.8 mkfs.8 mkswap.8 fsck.minix.8 mkfs.minix.8 mkfs.bfs.8
+ifeq "$(KERNEL)" "linux"
+MAN8:=$(MAN8) fdformat.8 blockdev.8 elvtune.8
+endif
 
 # Where to put binaries?
 # See the "install" rule for the links. . .
 
-SBIN= 	mkfs mkswap blockdev elvtune fsck.minix mkfs.minix mkfs.bfs
+SBIN= 	mkfs mkswap fsck.minix mkfs.minix mkfs.bfs
+ifeq "$(KERNEL)" "linux"
+SBIN:=$(SBIN) blockdev elvtune
+endif
 
-USRBIN=	fdformat isosize
+USRBIN=	isosize
+ifeq "$(KERNEL)" "linux"
+USRBIN:=$(USRBIN) fdformat
+endif
 
 ETC=	fdprm
 
 MAYBE=  setfdprm raw fsck.cramfs mkfs.cramfs
 
+ifeq "$(KERNEL)" "linux"
 ifneq "$(HAVE_FDUTILS)" "yes"
 USRBIN:=$(USRBIN) setfdprm
 MAN8:=$(MAN8) setfdprm.8
 endif
+endif
 
 ifeq "$(HAVE_RAW_H)" "yes"
 USRBIN:=$(USRBIN) raw
@@ -39,7 +49,7 @@
 all: $(SBIN) $(USRBIN)
 
 fsck.cramfs: fsck.cramfs.o
-	$(CC) $(LDFLAGS) -o fsck.cramfs fsck.cramfs.o -lz
+	$(CC) $(LDFLAGS) -o fsck.cramfs fsck.cramfs.o $(LIB)/disk_size.o -lz
 
 mkfs.cramfs: mkfs.cramfs.o $(LIB)/md5.o
 	$(CC) $(LDFLAGS) -o mkfs.cramfs mkfs.cramfs.o $(LIB)/md5.o -lz
@@ -50,13 +60,17 @@
 
 fsck.minix.o mkfs.minix.o: bitops.h minix.h
 
+mkfs.minix mkfs.bfs mkswap: $(LIB)/disk_size.o
+
 install: all
 	$(INSTALLDIR) $(SBINDIR) $(USRBINDIR) $(ETCDIR)
 	$(INSTALLBIN) $(SBIN) $(SBINDIR)
 	$(INSTALLBIN) $(USRBIN) $(USRBINDIR)
+ifeq "$(KERNEL)" "linux"
 ifneq "$(HAVE_FDUTILS)" "yes"
 	$(INSTALLDAT) $(ETC) $(ETCDIR)
 endif
+endif
 	$(INSTALLDIR) $(MAN8DIR)
 	$(INSTALLMAN) $(MAN8) $(MAN8DIR)
 
diff -Naur util-linux-2.12m/disk-utils/mkfs.bfs.c util-linux-2.12m.port/disk-utils/mkfs.bfs.c
--- util-linux-2.12m/disk-utils/mkfs.bfs.c	2002-03-08 23:58:05.000000000 +0100
+++ util-linux-2.12m.port/disk-utils/mkfs.bfs.c	2004-12-22 11:19:29.000000000 +0100
@@ -10,17 +10,12 @@
 #include <stdarg.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/ioctl.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 #include <time.h>
 #include "nls.h"
-
-/* cannot include <linux/fs.h> */
-#ifndef BLKGETSIZE
-#define BLKGETSIZE _IO(0x12,96)    /* return device size */
-#endif
+#include "disk_size.h"
 
 #define BFS_ROOT_INO		2
 #define BFS_NAMELEN		14
@@ -181,13 +176,9 @@
 	else if (optind != argc)
 		usage();
 
-	if (ioctl(fd, BLKGETSIZE, &total_blocks) == -1) {
-		if (!user_specified_total_blocks) {
-			perror("BLKGETSIZE");
-			fatal(_("cannot get size of %s"), device);
-		}
-		total_blocks = user_specified_total_blocks;
-	} else if (user_specified_total_blocks) {
+	total_blocks = disk_get_sectors(fd);
+
+	if (user_specified_total_blocks) {
 		if (user_specified_total_blocks > total_blocks)
 			fatal(_("blocks argument too large, max is %lu"),
 			      total_blocks);
diff -Naur util-linux-2.12m/disk-utils/mkfs.c util-linux-2.12m.port/disk-utils/mkfs.c
--- util-linux-2.12m/disk-utils/mkfs.c	2004-09-06 19:06:21.000000000 +0200
+++ util-linux-2.12m.port/disk-utils/mkfs.c	2004-12-22 11:19:29.000000000 +0100
@@ -36,7 +36,7 @@
 
 int main(int argc, char *argv[])
 {
-  char progname[NAME_MAX];
+  char *progname;
   char *fstype = NULL;
   int i, more = 0, verbose = 0;
   char *oldpath, *newpath;
@@ -92,7 +92,12 @@
   }
   sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
   putenv(newpath);
-  snprintf(progname, sizeof(progname), PROGNAME, fstype);
+  progname = (char *) malloc(sizeof(PROGNAME) + strlen(fstype) + 1);
+  if (!progname) {
+    fprintf(stderr, _("%s: Out of memory!\n"), "mkfs");
+    exit(1);
+  }
+  sprintf(progname, PROGNAME, fstype);
   argv[--optind] = progname;
 
   if (verbose) {
diff -Naur util-linux-2.12m/disk-utils/mkfs.minix.c util-linux-2.12m.port/disk-utils/mkfs.minix.c
--- util-linux-2.12m/disk-utils/mkfs.minix.c	2004-08-25 00:32:36.000000000 +0200
+++ util-linux-2.12m.port/disk-utils/mkfs.minix.c	2004-12-22 11:19:29.000000000 +0100
@@ -68,16 +68,12 @@
 #include <stdlib.h>
 #include <termios.h>
 #include <sys/stat.h>
-#include <sys/ioctl.h>
 #include <mntent.h>
 #include <getopt.h>
 
 #include "minix.h"
 #include "nls.h"
-
-#ifndef BLKGETSIZE
-#define BLKGETSIZE _IO(0x12,96)    /* return device size */
-#endif
+#include "disk_size.h"
 
 #ifndef __GNUC__
 #error "needs gcc for the bitop-__asm__'s"
@@ -188,37 +184,6 @@
 }
 
 static long
-valid_offset (int fd, int offset) {
-	char ch;
-
-	if (lseek (fd, offset, 0) < 0)
-		return 0;
-	if (read (fd, &ch, 1) < 1)
-		return 0;
-	return 1;
-}
-
-static int
-count_blocks (int fd) {
-	int high, low;
-
-	low = 0;
-	for (high = 1; valid_offset (fd, high); high *= 2)
-		low = high;
-	while (low < high - 1)
-	{
-		const int mid = (low + high) / 2;
-
-		if (valid_offset (fd, mid))
-			low = mid;
-		else
-			high = mid;
-	}
-	valid_offset (fd, 0);
-	return (low + 1);
-}
-
-static int
 get_size(const char  *file) {
 	int	fd;
 	long	size;
@@ -228,12 +193,8 @@
 		perror(file);
 		exit(1);
 	}
-	if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
-		close(fd);
-		return (size * 512);
-	}
-		
-	size = count_blocks(fd);
+	size = disk_get_sectors(fd);
+
 	close(fd);
 	return size;
 }
@@ -676,8 +637,10 @@
      }
   }
 
-  if (device_name && !BLOCKS)
-    BLOCKS = get_size (device_name) / 1024;
+  if (device_name && !BLOCKS) {
+    int sectors_per_block = 1024 / 512;
+    BLOCKS = get_size (device_name) / sectors_per_block;
+  }
   if (!device_name || BLOCKS<10) {
     usage();
   }
diff -Naur util-linux-2.12m/disk-utils/mkswap.c util-linux-2.12m.port/disk-utils/mkswap.c
--- util-linux-2.12m/disk-utils/mkswap.c	2004-12-14 02:51:28.000000000 +0100
+++ util-linux-2.12m.port/disk-utils/mkswap.c	2004-12-22 11:19:29.000000000 +0100
@@ -36,10 +36,12 @@
 #include <string.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <sys/ioctl.h>		/* for _IO */
+#ifdef __linux__
 #include <sys/utsname.h>
+#endif /* __linux__ */
 #include <sys/stat.h>
 #include "nls.h"
+#include "disk_size.h"
 
 /* Try to get PAGE_SIZE from libc or kernel includes */
 #ifdef HAVE_sys_user_h
@@ -52,14 +54,6 @@
 #endif
 #endif
 
-#ifndef _IO
-/* pre-1.3.45 */
-#define BLKGETSIZE 0x1260
-#else
-/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */
-#define BLKGETSIZE _IO(0x12,96)
-#endif
-
 static char * program_name = "mkswap";
 static char * device_name = NULL;
 static int DEV = -1;
@@ -68,6 +62,7 @@
 static int check = 0;
 static int version = -1;
 
+#ifdef __linux__
 #define MAKE_VERSION(p,q,r)	(65536*(p) + 256*(q) + (r))
 
 static int
@@ -83,6 +78,7 @@
 	}
 	return 0;
 }
+#endif /* __linux__ */
 
 #ifdef __sparc__
 # ifdef __arch64__
@@ -382,39 +378,11 @@
 		printf(_("%lu bad pages\n"), badpages);
 }
 
-static long
-valid_offset (int fd, off_t offset) {
-	char ch;
-
-	if (lseek (fd, offset, 0) < 0)
-		return 0;
-	if (read (fd, &ch, 1) < 1)
-		return 0;
-	return 1;
-}
-
-static off_t
-find_size (int fd) {
-	off_t high, low;
-
-	low = 0;
-	for (high = 1; high > 0 && valid_offset (fd, high); high *= 2)
-		low = high;
-	while (low < high - 1) {
-		const off_t mid = (low + high) / 2;
-
-		if (valid_offset (fd, mid))
-			low = mid;
-		else
-			high = mid;
-	}
-	return (low + 1);
-}
-
 /* return size in pages, to avoid integer overflow */
 static unsigned long
 get_size(const char  *file) {
 	int	fd;
+	int	sectors_per_page = pagesize / 512;
 	unsigned long	size;
 
 	fd = open(file, O_RDONLY);
@@ -422,14 +390,10 @@
 		perror(file);
 		exit(1);
 	}
-	if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
-		int sectors_per_page = pagesize/512;
-		size /= sectors_per_page;
-	} else {
-		size = find_size(fd) / pagesize;
-	}
+	size = disk_get_sectors(fd);
+
 	close(fd);
-	return size;
+	return (size / sectors_per_page);
 }
 
 static int
@@ -528,8 +492,10 @@
 		/* use version 1 as default, if possible */
 		if (PAGES <= V0_MAX_PAGES && PAGES > V1_MAX_PAGES)
 			version = 0;
+#ifdef __linux__
 		else if (linux_version_code() < MAKE_VERSION(2,1,117))
 			version = 0;
+#endif
 		else if (pagesize < 2048)
 			version = 0;
 		else
@@ -550,12 +516,17 @@
 
 	if (version == 0)
 		maxpages = V0_MAX_PAGES;
+#ifdef __linux__
 	else if (linux_version_code() >= MAKE_VERSION(2,3,4))
 		maxpages = PAGES;
 	else if (linux_version_code() >= MAKE_VERSION(2,2,1))
 		maxpages = V1_MAX_PAGES;
-	else
+#endif
+	else {
 		maxpages = V1_OLD_MAX_PAGES;
+		if (maxpages > V1_MAX_PAGES)
+			maxpages = V1_MAX_PAGES;
+	}
 
 	if (PAGES > maxpages) {
 		PAGES = maxpages;
diff -Naur util-linux-2.12m/fdisk/cfdisk.c util-linux-2.12m.port/fdisk/cfdisk.c
--- util-linux-2.12m/fdisk/cfdisk.c	2004-12-19 20:36:11.000000000 +0100
+++ util-linux-2.12m.port/fdisk/cfdisk.c	2004-12-22 12:12:47.000000000 +0100
@@ -77,11 +77,11 @@
 #include <math.h>
 #include <string.h>
 #include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <linux/types.h>
 
 #include "nls.h"
 #include "xstrncpy.h"
+#include "disk_size.h"
+#include "disk_geom.h"
 #include "common.h"
 
 extern long long ext2_llseek(unsigned int fd, long long offset,
@@ -89,8 +89,16 @@
 
 #define VERSION UTIL_LINUX_VERSION
 
+#ifdef __GNU__
+#define DEFAULT_DEVICE "/dev/hd0"
+#define ALTERNATE_DEVICE "/dev/sd0"
+#elif defined(__FreeBSD__)
+#define DEFAULT_DEVICE "/dev/ad0"
+#define ALTERNATE_DEVICE "/dev/da0"
+#else
 #define DEFAULT_DEVICE "/dev/hda"
 #define ALTERNATE_DEVICE "/dev/sda"
+#endif
 
 /* With K=1024 we have `binary' megabytes, gigabytes, etc.
    Some misguided hackers like that.
@@ -172,7 +180,7 @@
 long long cylinders = 0;
 int cylinder_size = 0;		/* heads * sectors */
 long long total_size = 0;	/* actual_size rounded down */
-long long actual_size = 0;	/* (in 512-byte sectors) - set using ioctl */
+long long actual_size = 0;	/* (in 512-byte sectors) */
 				/* explicitly given user values */
 int user_heads = 0, user_sectors = 0;
 long long user_cylinders = 0;
@@ -1512,18 +1520,6 @@
 	    print_warning(errmsg);
 }
 
-static void
-get_kernel_geometry(void) {
-#ifdef HDIO_GETGEO
-    struct hd_geometry geometry;
-
-    if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
-	kern_heads = geometry.heads;
-	kern_sectors = geometry.sectors;
-    }
-#endif
-}
-
 static int
 said_yes(char answer) {
 #ifdef HAVE_rpmatch
@@ -1645,7 +1641,7 @@
 fill_p_info(void) {
     int pn, i;
     long long bs, bsz;
-    unsigned long long llsectors;
+    struct disk_geom g;
     struct partition *p;
     partition_table buffer;
     partition_info tmp_ext = { 0, 0, 0, 0, FREE_SPACE, PRIMARY };
@@ -1664,23 +1660,15 @@
 	 opentype = O_RDWR;
     opened = TRUE;
 
-    /* Blocks are visible in more than one way:
-       e.g. as block on /dev/hda and as block on /dev/hda3
-       By a bug in the Linux buffer cache, we will see the old
-       contents of /dev/hda when the change was made to /dev/hda3.
-       In order to avoid this, discard all blocks on /dev/hda.
-       Note that partition table blocks do not live in /dev/hdaN,
-       so this only plays a role if we want to show volume labels. */
-    ioctl(fd, BLKFLSBUF);	/* ignore errors */
-				/* e.g. Permission Denied */
-
-    if (disksize(fd, &llsectors))
-	    fatal(_("Cannot get disk size"), 3);
-    actual_size = llsectors;
+    disk_flush_cache(fd);
+
+    actual_size = disk_get_sectors(fd);
 
     read_sector(buffer.c.b, 0);
 
-    get_kernel_geometry();
+    disk_get_geometry(fd, &g);
+    kern_heads = g.heads;
+    kern_sectors = g.sectors;
 
     if (!zero_table || use_partition_table_geometry)
 	get_partition_table_geometry(& buffer);
@@ -1882,12 +1870,8 @@
 	}
 
     if (is_bdev) {
-	 sync();
-	 sleep(2);
-	 if (!ioctl(fd,BLKRRPART))
+	 if (disk_reread_partition_table(fd) == 0)
 	      changed = TRUE;
-	 sync();
-	 sleep(4);
 
 	 clear_warning();
 	 if (changed)
diff -Naur util-linux-2.12m/fdisk/common.h util-linux-2.12m.port/fdisk/common.h
--- util-linux-2.12m/fdisk/common.h	2004-09-06 20:07:11.000000000 +0200
+++ util-linux-2.12m.port/fdisk/common.h	2004-12-22 11:41:00.000000000 +0100
@@ -1,25 +1,5 @@
 /* common stuff for fdisk, cfdisk, sfdisk */
 
-/* including <linux/fs.h> fails */
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#define BLKRRPART    _IO(0x12,95)    /* re-read partition table */
-#define BLKGETSIZE   _IO(0x12,96)    /* return device size */
-#define BLKFLSBUF    _IO(0x12,97)    /* flush buffer cache */
-#define BLKSSZGET    _IO(0x12,104)   /* get block device sector size */
-#define BLKGETSIZE64 _IOR(0x12,114,size_t)	/* size in bytes */
-
-/* including <linux/hdreg.h> also fails */
-struct hd_geometry {
-      unsigned char heads;
-      unsigned char sectors;
-      unsigned short cylinders;
-      unsigned long start;
-};
-
-#define HDIO_GETGEO		0x0301	/* get device geometry */
-
-
 struct systypes {
 	unsigned char type;
 	char *name;
@@ -29,4 +9,3 @@
 
 extern char *partname(char *dev, int pno, int lth);
 
-int disksize(int fd, unsigned long long *sectors);
diff -Naur util-linux-2.12m/fdisk/disksize.c util-linux-2.12m.port/fdisk/disksize.c
--- util-linux-2.12m/fdisk/disksize.c	2004-12-14 02:52:07.000000000 +0100
+++ util-linux-2.12m.port/fdisk/disksize.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,17 +0,0 @@
-#include "common.h"
-
-int disksize(int fd, unsigned long long *sectors) {
-	int err;
-	long sz;
-	long long b;
-
-	err = ioctl(fd, BLKGETSIZE, &sz);
-	if (err)
-		return err;
-	err = ioctl(fd, BLKGETSIZE64, &b);
-	if (err || b == 0 || b == sz)
-		*sectors = sz;
-	else
-		*sectors = (b >> 9);
-	return 0;
-}
diff -Naur util-linux-2.12m/fdisk/fdisk.8 util-linux-2.12m.port/fdisk/fdisk.8
--- util-linux-2.12m/fdisk/fdisk.8	2004-08-24 15:29:15.000000000 +0200
+++ util-linux-2.12m.port/fdisk/fdisk.8	2004-12-22 11:19:34.000000000 +0100
@@ -132,7 +132,7 @@
 Partitions beginning in cylinder 1 cannot begin on a cylinder boundary, but
 this is unlikely to cause difficulty unless you have OS/2 on your machine.
 
-A sync() and a BLKRRPART ioctl() (reread partition table from disk)
+A sync() and a disk_reread_partition_table()
 are performed before exiting when the partition table has been updated.
 Long ago it used to be necessary to reboot after the use of fdisk.
 I do not think this is the case anymore - indeed, rebooting too quickly
diff -Naur util-linux-2.12m/fdisk/fdiskaixlabel.h util-linux-2.12m.port/fdisk/fdiskaixlabel.h
--- util-linux-2.12m/fdisk/fdiskaixlabel.h	2004-12-14 00:39:47.000000000 +0100
+++ util-linux-2.12m.port/fdisk/fdiskaixlabel.h	2004-12-22 11:19:34.000000000 +0100
@@ -1,4 +1,3 @@
-#include <linux/types.h>   /* for __u32 etc */
 /*
  * Copyright (C) Andreas Neuper, Sep 1998.
  *	This file may be redistributed under
diff -Naur util-linux-2.12m/fdisk/fdiskbsdlabel.c util-linux-2.12m.port/fdisk/fdiskbsdlabel.c
--- util-linux-2.12m/fdisk/fdiskbsdlabel.c	2003-07-13 23:12:47.000000000 +0200
+++ util-linux-2.12m.port/fdisk/fdiskbsdlabel.c	2004-12-22 11:19:34.000000000 +0100
@@ -52,7 +52,6 @@
 #include <errno.h>
 #include "nls.h"
 
-#include <sys/ioctl.h>
 #include <sys/param.h>
 
 #include "common.h"
@@ -515,7 +514,7 @@
 xbsd_write_bootstrap (void)
 {
   char *bootdir = BSD_LINUX_BOOTDIR;
-  char path[MAXPATHLEN];
+  char *path;
   char *dkbasename;
   struct xbsd_disklabel dl;
   char *d, *p, *e;
@@ -532,9 +531,15 @@
     line_ptr[strlen (line_ptr)-1] = '\0';
     dkbasename = line_ptr;
   }
-  snprintf (path, sizeof(path), "%s/%sboot", bootdir, dkbasename);
-  if (!xbsd_get_bootstrap (path, disklabelbuffer, (int) xbsd_dlabel.d_secsize))
+  path = (char *) malloc (sizeof("/boot") + 1 + strlen (bootdir) +
+			  strlen (dkbasename));
+  if (!path)
+    fatal (out_of_memory);
+  sprintf (path, "%s/%sboot", bootdir, dkbasename);
+  if (!xbsd_get_bootstrap (path, disklabelbuffer, (int) xbsd_dlabel.d_secsize)) {
+    free (path);
     return;
+  }
 
   /* We need a backup of the disklabel (xbsd_dlabel might have changed). */
   d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE];
@@ -543,10 +548,13 @@
   /* The disklabel will be overwritten by 0's from bootxx anyway */
   bzero (d, sizeof (struct xbsd_disklabel));
 
+  sprintf (path, "%s/boot%s", bootdir, dkbasename);
   snprintf (path, sizeof(path), "%s/boot%s", bootdir, dkbasename);
   if (!xbsd_get_bootstrap (path, &disklabelbuffer[xbsd_dlabel.d_secsize],
-			  (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize))
+			  (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) {
+    free(path);
     return;
+  }
 
   e = d + sizeof (struct xbsd_disklabel);
   for (p=d; p < e; p++)
@@ -579,6 +587,8 @@
 #endif
 
   sync_disks ();
+
+  free(path);
 }
 
 static void
diff -Naur util-linux-2.12m/fdisk/fdiskbsdlabel.h util-linux-2.12m.port/fdisk/fdiskbsdlabel.h
--- util-linux-2.12m/fdisk/fdiskbsdlabel.h	2002-10-31 14:45:34.000000000 +0100
+++ util-linux-2.12m.port/fdisk/fdiskbsdlabel.h	2004-12-22 11:19:34.000000000 +0100
@@ -31,10 +31,10 @@
  * SUCH DAMAGE.
  */
 
-#include <linux/types.h>	/* for __u32, __u16, __u8, __s16 */
+#include <stdint.h>	/* for uint32_t, uint16_t, uint8_t, int16_t */
 
 #ifndef BSD_DISKMAGIC
-#define BSD_DISKMAGIC     ((__u32) 0x82564557)
+#define BSD_DISKMAGIC     ((uint32_t) 0x82564557)
 #endif
 
 #ifndef BSD_MAXPARTITIONS
@@ -60,31 +60,31 @@
 #define	BSD_SBSIZE        8192		/* max size of fs superblock */
 
 struct xbsd_disklabel {
-	__u32	d_magic;		/* the magic number */
-	__s16	d_type;			/* drive type */
-	__s16	d_subtype;		/* controller/d_type specific */
-	char	d_typename[16];		/* type name, e.g. "eagle" */
-	char	d_packname[16];			/* pack identifier */ 
+	uint32_t	d_magic;		/* the magic number */
+	int16_t		d_type;			/* drive type */
+	int16_t		d_subtype;		/* controller/d_type specific */
+	char		d_typename[16];		/* type name, e.g. "eagle" */
+	char		d_packname[16];		/* pack identifier */ 
 			/* disk geometry: */
-	__u32	d_secsize;		/* # of bytes per sector */
-	__u32	d_nsectors;		/* # of data sectors per track */
-	__u32	d_ntracks;		/* # of tracks per cylinder */
-	__u32	d_ncylinders;		/* # of data cylinders per unit */
-	__u32	d_secpercyl;		/* # of data sectors per cylinder */
-	__u32	d_secperunit;		/* # of data sectors per unit */
+	uint32_t	d_secsize;		/* # of bytes per sector */
+	uint32_t	d_nsectors;		/* # of data sectors per track */
+	uint32_t	d_ntracks;		/* # of tracks per cylinder */
+	uint32_t	d_ncylinders;		/* # of data cylinders per unit */
+	uint32_t	d_secpercyl;		/* # of data sectors per cylinder */
+	uint32_t	d_secperunit;		/* # of data sectors per unit */
 	/*
 	 * Spares (bad sector replacements) below
 	 * are not counted in d_nsectors or d_secpercyl.
 	 * Spare sectors are assumed to be physical sectors
 	 * which occupy space at the end of each track and/or cylinder.
 	 */
-	__u16	d_sparespertrack;	/* # of spare sectors per track */
-	__u16	d_sparespercyl;		/* # of spare sectors per cylinder */
+	uint16_t	d_sparespertrack;	/* # of spare sectors per track */
+	uint16_t	d_sparespercyl;		/* # of spare sectors per cylinder */
 	/*
 	 * Alternate cylinders include maintenance, replacement,
 	 * configuration description areas, etc.
 	 */
-	__u32	d_acylinders;		/* # of alt. cylinders per unit */
+	uint32_t	d_acylinders;		/* # of alt. cylinders per unit */
 
 			/* hardware characteristics: */
 	/*
@@ -103,30 +103,30 @@
 	 * Finally, d_cylskew is the offset of sector 0 on cylinder N
 	 * relative to sector 0 on cylinder N-1.
 	 */
-	__u16	d_rpm;			/* rotational speed */
-	__u16	d_interleave;		/* hardware sector interleave */
-	__u16	d_trackskew;		/* sector 0 skew, per track */
-	__u16	d_cylskew;		/* sector 0 skew, per cylinder */
-	__u32	d_headswitch;		/* head switch time, usec */
-	__u32	d_trkseek;		/* track-to-track seek, usec */
-	__u32	d_flags;		/* generic flags */
+	uint16_t	d_rpm;			/* rotational speed */
+	uint16_t	d_interleave;		/* hardware sector interleave */
+	uint16_t	d_trackskew;		/* sector 0 skew, per track */
+	uint16_t	d_cylskew;		/* sector 0 skew, per cylinder */
+	uint32_t	d_headswitch;		/* head switch time, usec */
+	uint32_t	d_trkseek;		/* track-to-track seek, usec */
+	uint32_t	d_flags;		/* generic flags */
 #define NDDATA 5
-	__u32	d_drivedata[NDDATA];	/* drive-type specific information */
+	uint32_t	d_drivedata[NDDATA];	/* drive-type specific information */
 #define NSPARE 5
-	__u32	d_spare[NSPARE];	/* reserved for future use */
-	__u32	d_magic2;		/* the magic number (again) */
-	__u16	d_checksum;		/* xor of data incl. partitions */
+	uint32_t	d_spare[NSPARE];	/* reserved for future use */
+	uint32_t	d_magic2;		/* the magic number (again) */
+	uint16_t	d_checksum;		/* xor of data incl. partitions */
 			/* filesystem and partition information: */
-	__u16	d_npartitions;	        /* number of partitions in following */
-	__u32	d_bbsize;	        /* size of boot area at sn0, bytes */
-	__u32	d_sbsize;	        /* max size of fs superblock, bytes */
+	uint16_t	d_npartitions;	        /* number of partitions in following */
+	uint32_t	d_bbsize;	        /* size of boot area at sn0, bytes */
+	uint32_t	d_sbsize;	        /* max size of fs superblock, bytes */
 	struct xbsd_partition	 {	/* the partition table */
-		__u32	p_size;	        /* number of sectors in partition */
-		__u32	p_offset;       /* starting sector */
-		__u32	p_fsize;        /* filesystem basic fragment size */
-		__u8	p_fstype;       /* filesystem type, see below */
-		__u8	p_frag;	        /* filesystem fragments per block */
-		__u16	p_cpg;	        /* filesystem cylinders per group */
+		uint32_t	p_size;	        /* number of sectors in partition */
+		uint32_t	p_offset;       /* starting sector */
+		uint32_t	p_fsize;        /* filesystem basic fragment size */
+		uint8_t		p_fstype;       /* filesystem type, see below */
+		uint8_t		p_frag;	        /* filesystem fragments per block */
+		uint16_t	p_cpg;	        /* filesystem cylinders per group */
 	} d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
 };
 
diff -Naur util-linux-2.12m/fdisk/fdisk.c util-linux-2.12m.port/fdisk/fdisk.c
--- util-linux-2.12m/fdisk/fdisk.c	2004-12-18 03:00:31.000000000 +0100
+++ util-linux-2.12m.port/fdisk/fdisk.c	2004-12-22 12:37:37.000000000 +0100
@@ -21,6 +21,8 @@
 
 #include "nls.h"
 #include "common.h"
+#include "disk_size.h"
+#include "disk_geom.h"
 #include "fdisk.h"
 
 #include "fdisksunlabel.h"
@@ -220,11 +222,6 @@
 			snprintf(error, sizeof(error),
 				_("Unable to write %s\n"), disk_device);
 			break;
-		case ioctl_error:
-			snprintf(error, sizeof(error),
-				 _("BLKGETSIZE ioctl failed on %s\n"),
-				disk_device);
-			break;
 		case out_of_memory:
 			message = _("Unable to allocate any more memory\n");
 			break;
@@ -736,73 +733,29 @@
 	get_boot(create_empty_dos);
 }
 
-#include <sys/utsname.h>
-#define MAKE_VERSION(p,q,r)     (65536*(p) + 256*(q) + (r))
-
-static int
-linux_version_code(void) {
-	static int kernel_version = 0;
-        struct utsname my_utsname;
-        int p, q, r;
-
-        if (!kernel_version && uname(&my_utsname) == 0) {
-                p = atoi(strtok(my_utsname.release, "."));
-                q = atoi(strtok(NULL, "."));
-                r = atoi(strtok(NULL, "."));
-                kernel_version = MAKE_VERSION(p,q,r);
-        }
-        return kernel_version;
-}
-
 static void
 get_sectorsize(int fd) {
-#if defined(BLKSSZGET)
-	if (!user_set_sector_size &&
-	    linux_version_code() >= MAKE_VERSION(2,3,3)) {
-		int arg;
-		if (ioctl(fd, BLKSSZGET, &arg) == 0)
-			sector_size = arg;
+	/* maybe the user specified it; and otherwise we still
+	   have the DEFAULT_SECTOR_SIZE default */
+	if (!user_set_sector_size) {
+		sector_size = disk_get_sector_size(fd);
 		if (sector_size != DEFAULT_SECTOR_SIZE)
 			printf(_("Note: sector size is %d (not %d)\n"),
 			       sector_size, DEFAULT_SECTOR_SIZE);
 	}
-#else
-	/* maybe the user specified it; and otherwise we still
-	   have the DEFAULT_SECTOR_SIZE default */
-#endif
-}
-
-static void
-get_kernel_geometry(int fd) {
-#ifdef HDIO_GETGEO
-	struct hd_geometry geometry;
-
-	if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
-		kern_heads = geometry.heads;
-		kern_sectors = geometry.sectors;
-		/* never use geometry.cylinders - it is truncated */
-	}
-#endif
 }
 
 static int
 is_probably_full_disk(char *name) {
-#ifdef HDIO_GETGEO
-	struct hd_geometry geometry;
-	int fd, i = 0;
+	struct disk_geom geometry;
+	int fd;
 
 	fd = open(name, O_RDONLY);
 	if (fd >= 0) {
-		i = ioctl(fd, HDIO_GETGEO, &geometry);
+		disk_get_geometry(fd, &geometry);
 		close(fd);
 	}
-	return (fd >= 0 && i == 0 && geometry.start == 0);
-#else
-	/* silly heuristic */
-	while (*name)
-		name++;
-	return !isdigit(name[-1]);
-#endif
+	return (fd >= 0 && geometry.start == 0);
 }
 
 static void
@@ -840,7 +793,8 @@
 void
 get_geometry(int fd, struct geom *g) {
 	int sec_fac;
-	unsigned long long llsectors, llcyls;
+	unsigned long long llcyls;
+	struct disk_geom dg;
 
 	get_sectorsize(fd);
 	sec_fac = sector_size / 512;
@@ -849,7 +803,10 @@
 	kern_heads = kern_sectors = 0;
 	pt_heads = pt_sectors = 0;
 
-	get_kernel_geometry(fd);
+	disk_get_geometry(fd, &dg);
+	kern_heads = dg.heads;
+	kern_sectors = dg.sectors;
+
 	get_partition_table_geometry();
 
 	heads = user_heads ? user_heads :
@@ -859,10 +816,7 @@
 		pt_sectors ? pt_sectors :
 		kern_sectors ? kern_sectors : 63;
 
-	if (disksize(fd, &llsectors))
-		llsectors = 0;
-
-	total_number_of_sectors = llsectors;
+	total_number_of_sectors = disk_get_sectors(fd);
 
 	sector_offset = 1;
 	if (dos_compatible_flag)
@@ -2160,24 +2114,11 @@
 void
 reread_partition_table(int leave) {
 	int error = 0;
-	int i;
 
-	printf(_("Calling ioctl() to re-read partition table.\n"));
-	sync();
-	sleep(2);
-	if ((i = ioctl(fd, BLKRRPART)) != 0) {
-                error = errno;
-        } else {
-                /* some kernel versions (1.2.x) seem to have trouble
-                   rereading the partition table, but if asked to do it
-		   twice, the second time works. - biro@yggdrasil.com */
-                sync();
-                sleep(2);
-                if ((i = ioctl(fd, BLKRRPART)) != 0)
-                        error = errno;
-        }
+	printf(_("Asking the kernel to to re-read partition table.\n"));
+	error = disk_reread_partition_table(fd);
 
-	if (i) {
+	if (error) {
 		printf(_("\nWARNING: Re-reading the partition table "
 			 "failed with error %d: %s.\n"
 			 "The kernel still uses the old table.\n"
@@ -2201,7 +2142,7 @@
 		printf(_("Syncing disks.\n"));
 		sync();
 		sleep(4);		/* for sync() */
-		exit(!!i);
+		exit(!!error);
 	}
 }
 
@@ -2564,8 +2505,7 @@
 			disk_device = argv[j];
 			if ((fd = open(disk_device, type_open)) < 0)
 				fatal(unable_to_open);
-			if (disksize(fd, &size))
-				fatal(ioctl_error);
+			size = disk_get_sectors(fd);
 			close(fd);
 			if (opts == 1)
 				printf("%llu\n", size/2);
diff -Naur util-linux-2.12m/fdisk/fdisksgilabel.c util-linux-2.12m.port/fdisk/fdisksgilabel.c
--- util-linux-2.12m/fdisk/fdisksgilabel.c	2004-12-18 02:53:45.000000000 +0100
+++ util-linux-2.12m.port/fdisk/fdisksgilabel.c	2004-12-22 12:20:19.000000000 +0100
@@ -16,13 +16,11 @@
 #include <stdlib.h>		/* exit */
 #include <string.h>             /* strstr */
 #include <unistd.h>             /* write */
-#include <sys/ioctl.h>          /* ioctl */
 #include <sys/stat.h>           /* stat */
 #include <assert.h>             /* assert */
 
 #include <endian.h>
 #include "nls.h"
-#include <linux/major.h>        /* FLOPPY_MAJOR */
 
 #include "common.h"
 #include "fdisk.h"
@@ -98,13 +96,13 @@
 	{0, NULL }
 };
 
-static inline unsigned short
-__swap16(unsigned short x) {
-        return (((__u16)(x) & 0xFF) << 8) | (((__u16)(x) & 0xFF00) >> 8);
+static inline uint32_t
+__swap16(uint32_t x) {
+        return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
 }
 
-static inline __u32
-__swap32(__u32 x) {
+static inline uint32_t
+__swap32(uint32_t x) {
         return (((x & 0xFF) << 24) |
 		((x & 0xFF00) << 8) |
 		((x & 0xFF0000) >> 8) |
@@ -222,8 +220,8 @@
 	       w + 1, _("Device"));
 	for (i = 0 ; i < partitions; i++) {
 		if (sgi_get_num_sectors(i) || debug) {
-			__u32 start = sgi_get_start_sector(i);
-			__u32 len = sgi_get_num_sectors(i);
+			uint32_t start = sgi_get_start_sector(i);
+			uint32_t len = sgi_get_num_sectors(i);
 			kpi++;		/* only count nonempty partitions */
 			printf(
 				"%2d: %s %4s %9ld %9ld %9ld  %2x  %s\n",
@@ -244,8 +242,8 @@
 	       sgilabel->boot_file);
 	for (i = 0 ; i < volumes; i++) {
 		if (sgilabel->directory[i].vol_file_size) {
-			__u32 start = SSWAP32(sgilabel->directory[i].vol_file_start);
-			__u32 len = SSWAP32(sgilabel->directory[i].vol_file_size);
+			uint32_t start = SSWAP32(sgilabel->directory[i].vol_file_start);
+			uint32_t len = SSWAP32(sgilabel->directory[i].vol_file_size);
 			char *name = sgilabel->directory[i].vol_file_name;
 			printf(_("%2d: %-10s sector%5u size%8u\n"),
 			       i, name, (unsigned int) start,
@@ -689,15 +687,13 @@
 void
 create_sgilabel(void)
 {
-	struct hd_geometry geometry;
+	struct geom geometry;
 	struct {
 		unsigned int start;
 		unsigned int nsect;
 		int sysid;
 	} old[4];
 	int i=0;
-	unsigned long long llsectors;
-	int res; 		/* the result from the ioctl */
 	int sec_fac; 		/* the sector factor */
 
 	sec_fac = sector_size / 512;	/* determine the sector factor */
@@ -709,28 +705,8 @@
 
 	other_endian = (BYTE_ORDER == LITTLE_ENDIAN);
 
-	res = disksize(fd, &llsectors);
+	get_geometry(fd, &geometry);
 
-	if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
-		heads = geometry.heads;
-		sectors = geometry.sectors;
-		if (res == 0) {
-			/* the get device size ioctl was successful */
-			unsigned long long llcyls;
-			llcyls = llsectors / (heads * sectors * sec_fac);
-			cylinders = llcyls;
-			if (cylinders != llcyls)	/* truncated? */
-				cylinders = ~0;
-		} else {
-			/* otherwise print error and use truncated version */
-			cylinders = geometry.cylinders;
-			fprintf(stderr,
-				_("Warning:  BLKGETSIZE ioctl failed on %s.  "
-				  "Using geometry cylinder value of %d.\n"
-				  "This value may be truncated for devices"
-				  " > 33.8 GB.\n"), disk_device, cylinders);
-		}
-	}
 	for (i = 0; i < 4; i++) {
 		old[i].sysid = 0;
 		if (valid_part_table_flag(MBRbuffer)) {
diff -Naur util-linux-2.12m/fdisk/fdisksgilabel.h util-linux-2.12m.port/fdisk/fdisksgilabel.h
--- util-linux-2.12m/fdisk/fdisksgilabel.h	2004-12-14 00:39:29.000000000 +0100
+++ util-linux-2.12m.port/fdisk/fdisksgilabel.h	2004-12-22 11:19:34.000000000 +0100
@@ -1,4 +1,4 @@
-#include <linux/types.h>   /* for __u32 etc */
+#include <stdint.h>	/* for uint32_t, uint16_t, uint8_t, int16_t */
 /*
  * Copyright (C) Andreas Neuper, Sep 1998.
  *	This file may be modified and redistributed under
@@ -96,9 +96,9 @@
 #define	SGI_INFO_MAGIC		0x00072959
 #define	SGI_INFO_MAGIC_SWAPPED	0x59290700
 #define SSWAP16(x) (other_endian ? __swap16(x) \
-                                 : (__u16)(x))
+                                 : (uint16_t)(x))
 #define SSWAP32(x) (other_endian ? __swap32(x) \
-                                 : (__u32)(x))
+                                 : (uint32_t)(x))
 
 /* fdisk.c */
 #define sgilabel ((sgi_partition *)MBRbuffer)
diff -Naur util-linux-2.12m/fdisk/fdisksunlabel.c util-linux-2.12m.port/fdisk/fdisksunlabel.c
--- util-linux-2.12m/fdisk/fdisksunlabel.c	2004-12-13 23:57:44.000000000 +0100
+++ util-linux-2.12m.port/fdisk/fdisksunlabel.c	2004-12-22 11:19:34.000000000 +0100
@@ -27,7 +27,9 @@
 #include <scsi/scsi.h>		/* SCSI_IOCTL_GET_IDLUN */
 #undef u_char
 #endif
+#ifdef __linux__
 #include <linux/major.h>	/* FLOPPY_MAJOR */
+#endif
 
 #include "common.h"
 #include "fdisk.h"
@@ -60,10 +62,10 @@
 };
 
 static inline unsigned short __swap16(unsigned short x) {
-        return (((__u16)(x) & 0xFF) << 8) | (((__u16)(x) & 0xFF00) >> 8);
+        return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
 }
-static inline __u32 __swap32(__u32 x) {
-        return (((__u32)(x) & 0xFF) << 24) | (((__u32)(x) & 0xFF00) << 8) | (((__u32)(x) & 0xFF0000) >> 8) | (((__u32)(x) & 0xFF000000) >> 24);
+static inline uint32_t __swap32(uint32_t x) {
+        return (((uint32_t)(x) & 0xFF) << 24) | (((uint32_t)(x) & 0xFF00) << 8) | (((uint32_t)(x) & 0xFF0000) >> 8) | (((uint32_t)(x) & 0xFF000000) >> 24);
 }
 
 int
@@ -71,18 +73,21 @@
 	return SSWAP32(p.num_sectors);
 }
 
+#ifdef __linux__
 #ifndef IDE0_MAJOR
 #define IDE0_MAJOR 3
 #endif
 #ifndef IDE1_MAJOR
 #define IDE1_MAJOR 22
 #endif
+#endif
 void guess_device_type(int fd) {
 	struct stat bootstat;
 
 	if (fstat (fd, &bootstat) < 0) {
                 scsi_disk = 0;
                 floppy = 0;
+#ifdef __linux__
 	} else if (S_ISBLK(bootstat.st_mode)
 		   && (major(bootstat.st_rdev) == IDE0_MAJOR ||
 		       major(bootstat.st_rdev) == IDE1_MAJOR)) {
@@ -92,6 +97,7 @@
 		   && major(bootstat.st_rdev) == FLOPPY_MAJOR) {
                 scsi_disk = 0;
                 floppy = 1;
+#endif
 	} else {
                 scsi_disk = 1;
                 floppy = 0;
@@ -249,7 +255,7 @@
 
 void create_sunlabel(void)
 {
-	struct hd_geometry geometry;
+	struct geom geometry;
 	unsigned int ndiv;
 	int i;
 	unsigned char c;
@@ -296,15 +302,8 @@
 	    }
 	}
 	if (!p || floppy) {
-	    if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
-	        heads = geometry.heads;
-	        sectors = geometry.sectors;
-	        cylinders = geometry.cylinders;
-	    } else {
-	        heads = 0;
-	        sectors = 0;
-	        cylinders = 0;
-	    }
+	    get_geometry(fd, &geometry);
+
 	    if (floppy) {
 	        sunlabel->nacyl = 0;
 	        sunlabel->pcylcount = SSWAP16(cylinders);
@@ -674,8 +673,8 @@
 	       w + 1, _("Device"));
 	for (i = 0 ; i < partitions; i++) {
 		if (sunlabel->partitions[i].num_sectors) {
-			__u32 start = SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
-			__u32 len = SSWAP32(sunlabel->partitions[i].num_sectors);
+			uint32_t start = SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
+			uint32_t len = SSWAP32(sunlabel->partitions[i].num_sectors);
 			printf(
 			    "%s %c%c %9ld %9ld %9ld%c  %2x  %s\n",
 /* device */		  partname(disk_device, i+1, w),
diff -Naur util-linux-2.12m/fdisk/fdisksunlabel.h util-linux-2.12m.port/fdisk/fdisksunlabel.h
--- util-linux-2.12m/fdisk/fdisksunlabel.h	2004-12-14 00:39:18.000000000 +0100
+++ util-linux-2.12m.port/fdisk/fdisksunlabel.h	2004-12-22 11:19:34.000000000 +0100
@@ -1,4 +1,4 @@
-#include <linux/types.h>   /* for __u16, __u32 */
+#include <stdint.h>	/* for uint32_t, uint16_t, uint8_t, int16_t */
 
 typedef struct {
 	unsigned char info[128];   /* Informative text string */
@@ -21,8 +21,8 @@
 	unsigned short nsect;      /* Sectors per track */
 	unsigned char spare3[4];   /* Even more magic... */
 	struct sun_partition {
-		__u32 start_cylinder;
-		__u32 num_sectors;
+		uint32_t start_cylinder;
+		uint32_t num_sectors;
 	} partitions[8];
 	unsigned short magic;      /* Magic number */
 	unsigned short csum;       /* Label xor'd checksum */
@@ -32,9 +32,9 @@
 #define SUN_LABEL_MAGIC_SWAPPED  0xBEDA
 #define sunlabel ((sun_partition *)MBRbuffer)
 #define SSWAP16(x) (other_endian ? __swap16(x) \
-				 : (__u16)(x))
+				 : (uint16_t)(x))
 #define SSWAP32(x) (other_endian ? __swap32(x) \
-				 : (__u32)(x))
+				 : (uint32_t)(x))
 				 
 /* fdisk.c */
 extern char MBRbuffer[MAX_SECTOR_SIZE];
diff -Naur util-linux-2.12m/fdisk/Makefile util-linux-2.12m.port/fdisk/Makefile
--- util-linux-2.12m/fdisk/Makefile	2004-09-06 22:28:58.000000000 +0200
+++ util-linux-2.12m.port/fdisk/Makefile	2004-12-22 11:39:15.000000000 +0100
@@ -39,7 +39,8 @@
 endif
 endif
 
-cfdisk: cfdisk.o llseek.o disksize.o i386_sys_types.o $(LIB)/xstrncpy.o
+cfdisk: cfdisk.o llseek.o i386_sys_types.o $(LIB)/xstrncpy.o \
+		$(LIB)/disk_size.o $(LIB)/disk_geom.o
 ifeq "$(HAVE_SLANG)" "yes"
 	$(CC) $(LDFLAGS) $^ -o $@ $(LIBSLANG)
 else
@@ -55,15 +56,17 @@
 	rm -f activate
 	ln -s sfdisk activate
 
-fdisk: fdisk.o llseek.o disksize.o fdiskbsdlabel.o fdisksgilabel.o \
-	fdisksunlabel.o fdiskaixlabel.o i386_sys_types.o partname.o
+fdisk: fdisk.o llseek.o fdiskbsdlabel.o fdisksgilabel.o fdisksunlabel.o \
+	fdiskaixlabel.o i386_sys_types.o partname.o \
+	$(LIB)/disk_geom.o $(LIB)/disk_size.o
 fdisk.o: fdisk.c fdisk.h
 fdiskbsdlabel.o: fdiskbsdlabel.c fdisk.h fdiskbsdlabel.h
 fdisksunlabel.o: fdisksunlabel.c fdisksunlabel.h fdisk.h
 fdiskaixlabel.o: fdiskaixlabel.c fdiskaixlabel.h fdisk.h
 fdisk.o cfdisk.o sfdisk.o fdiskbsdlabel.o fdisksunlabel.o \
 	fdisksgilabel.o fdiskaixlabel.o i386_sys_types.o partname.o: common.h
-sfdisk: sfdisk.o disksize.o i386_sys_types.o partname.o
+sfdisk: sfdisk.o i386_sys_types.o partname.o \
+	$(LIB)/disk_size.o $(LIB)/disk_geom.o
 
 install: all
 	$(INSTALLDIR) $(SBINDIR)
diff -Naur util-linux-2.12m/fdisk/README.fdisk util-linux-2.12m.port/fdisk/README.fdisk
--- util-linux-2.12m/fdisk/README.fdisk	2002-04-22 01:57:13.000000000 +0200
+++ util-linux-2.12m.port/fdisk/README.fdisk	2004-12-22 11:19:34.000000000 +0100
@@ -414,7 +414,7 @@
 precaution.  After giving the Write command, you will see this message:
 
      The partition table has been altered!
-     Calling ioctl() to re-read partition table.
+     Asking the kernel to to re-read partition table.
      Syncing disks.
 
 If there are no further messages, the kernel has successfully copied
diff -Naur util-linux-2.12m/fdisk/sfdisk.8 util-linux-2.12m.port/fdisk/sfdisk.8
--- util-linux-2.12m/fdisk/sfdisk.8	2004-12-15 23:39:27.000000000 +0100
+++ util-linux-2.12m.port/fdisk/sfdisk.8	2004-12-22 11:19:34.000000000 +0100
@@ -288,9 +288,9 @@
 Go through all the motions, but do not actually write to disk.
 .TP
 .B \-R
-Only execute the BLKRRPART ioctl (to make the kernel re-read
+Only execute the disk_reread_partition_table (to make the kernel re-read
 the partition table). This can be useful for checking in advance
-that the final BLKRRPART will be successful, and also when you
+that the final call to this function will be successful, and also when you
 changed the partition table `by hand' (e.g., using dd from a backup).
 If the kernel complains (`device busy for revalidation (usage = 2)')
 then something still uses the device, and you still have to unmount
diff -Naur util-linux-2.12m/fdisk/sfdisk.c util-linux-2.12m.port/fdisk/sfdisk.c
--- util-linux-2.12m/fdisk/sfdisk.c	2004-12-15 19:18:30.000000000 +0100
+++ util-linux-2.12m.port/fdisk/sfdisk.c	2004-12-22 12:34:41.000000000 +0100
@@ -45,11 +45,14 @@
 #include <string.h>		/* index() */
 #include <ctype.h>
 #include <getopt.h>
-#include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
+#ifdef __linux__
 #include <linux/unistd.h>	/* _syscall */
+#endif
 #include "nls.h"
+#include "disk_geom.h"
+#include "disk_size.h"
 #include "common.h"
 
 #define SIZE(a)	(sizeof(a)/sizeof(a[0]))
@@ -78,7 +81,7 @@
 int dump = 0;           /* 1: list in a format suitable for later input */
 int verify = 0;         /* 1: check that listed partition is reasonable */
 int no_write = 0;	/* 1: do not actually write to disk */
-int no_reread = 0;	/* 1: skip the BLKRRPART ioctl test at startup */
+int no_reread = 0;	/* 1: skip the reread partition test at startup */
 int leave_last = 0;	/* 1: don't allocate the last cylinder */
 int opt_list = 0;
 char *save_sector_file = NULL;
@@ -172,7 +175,7 @@
  * Note: we use 512-byte sectors here, irrespective of the hardware ss.
  */
 #undef use_lseek
-#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (__s390x__)
+#if defined(__linux__) && !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__)
 #define use_lseek
 #endif
 
@@ -414,18 +417,6 @@
  */
 
 /*
- * <linux/hdreg.h> defines HDIO_GETGEO and
- * struct hd_geometry {
- *      unsigned char heads;
- *      unsigned char sectors;
- *      unsigned short cylinders;
- *      unsigned long start;
- * };
- *
- * For large disks g.cylinders is truncated, so we use BLKGETSIZE.
- */
-
-/*
  * We consider several geometries for a disk:
  * B - the BIOS geometry, gotten from the kernel via HDIO_GETGEO
  * F - the fdisk geometry
@@ -442,25 +433,25 @@
 
 static struct geometry
 get_geometry(char *dev, int fd, int silent) {
-    struct hd_geometry g;
+    struct disk_geom g;
     unsigned long cyls;
     unsigned long long sectors;
     struct geometry R;
 
-    if (ioctl(fd, HDIO_GETGEO, &g)) {
-	g.heads = g.sectors = g.cylinders = g.start = 0;
+    if (disk_get_geometry(fd, &g)) {
+	R.heads = g.heads;
+	R.sectors = g.sectors;
+	R.cylindersize = R.heads * R.sectors;
+	R.cylinders = (R.cylindersize ? size / R.cylindersize : 0);
+	R.start = g.start;
+    } else {
+	R.heads = R.sectors = R.cylindersize = R.cylinders = R.start = 0;
 	if (!silent)
 	    do_warn(_("Disk %s: cannot get geometry\n"), dev);
     }
 
-    R.start = g.start;
-    R.heads = g.heads;
-    R.sectors = g.sectors;
-    R.cylindersize = R.heads * R.sectors;
-    R.cylinders = 0;
-    R.total_size = 0;
-
-    if (disksize(fd, &sectors)) {
+    sectors = disk_get_sectors(fd);
+    if (!sectors) {
 	/* maybe an ordinary file */
 	struct stat s;
 
@@ -469,7 +460,7 @@
 	else if (!silent)
 	    do_warn(_("Disk %s: cannot get size\n"), dev);
     } else
-	    R.total_size = sectors;
+	    R.total_size = size;
 
     if (R.cylindersize && R.total_size) {
 	    sectors /= R.cylindersize;
@@ -787,19 +778,6 @@
     }
 }
 
-/* tell the kernel to reread the partition tables */
-static int
-reread_ioctl(int fd) {
-    if (ioctl(fd, BLKRRPART)) {
-	perror("BLKRRPART");
-
-	/* 2.6.8 returns EIO for a zero table */
-	if (errno == EBUSY)
-		return -1;
-    }
-    return 0;
-}
-
 static int
 is_blockdev(int fd) {
     struct stat statbuf;
@@ -815,7 +793,7 @@
     sync();
     sleep(3);			/* superfluous since 1.3.20 */
 
-    if (reread_ioctl(fd) && is_blockdev(fd))
+    if (disk_reread_partition_table(fd) && is_blockdev(fd))
       do_warn(_("The command to re-read the partition table failed\n"
 	     "Reboot your system now, before using mkfs\n"));
 
@@ -1500,6 +1478,7 @@
 	z->partno = pno;
 }
 
+#ifdef __linux__
 #define MAKE_VERSION(p,q,r)     (65536*(p) + 256*(q) + (r))
 
 static int
@@ -1515,6 +1494,7 @@
         }
         return 0;
 }
+#endif
 
 static int
 msdos_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
@@ -1524,7 +1504,11 @@
     struct sector *s;
     struct part_desc *partitions = &(z->partitions[0]);
     int pno = z->partno;
+#ifdef __linux__
     int bsd_later = (linux_version_code() >= MAKE_VERSION(2,3,40));
+#else
+    int bsd_later = 0;
+#endif
 
     if (!(s = get_sector(dev, fd, start)))
 	return 0;
@@ -2433,15 +2417,15 @@
 
 static int
 is_probably_full_disk(char *name) {
-	struct hd_geometry geometry;
-	int fd, i = 0;
+	struct disk_geom geometry;
+	int fd;
 
 	fd = open(name, O_RDONLY);
 	if (fd >= 0) {
-		i = ioctl(fd, HDIO_GETGEO, &geometry);
+		disk_get_geometry(fd, &geometry);
 		close(fd);
 	}
-	return (fd >= 0 && i == 0 && geometry.start == 0);
+	return (fd >= 0 && geometry.start == 0);
 }
 
 #define PROC_PARTITIONS	"/proc/partitions"
@@ -2758,7 +2742,8 @@
     if (fd < 0)
 	return;
 
-    if (disksize(fd, &size)) {
+    size = disk_get_sectors(fd);
+    if (!size) {
 	if (!silent) {
 	    perror(dev);
 	    fatal(_("Cannot get size of %s\n"), dev);
@@ -2951,7 +2936,7 @@
     int fd;
 
     fd = my_open(dev, 0, 0);
-    if (reread_ioctl(fd))
+    if (disk_reread_partition_table(fd))
       do_warn(_("This disk is currently in use.\n"));
 }
 
@@ -2979,7 +2964,7 @@
 
     if (!no_write && !no_reread) {
 	warn(_("Checking that no-one is using this disk right now ...\n"));
-	if (reread_ioctl(fd)) {
+	if (disk_reread_partition_table(fd)) {
 	    do_warn(_("\nThis disk is currently in use - repartitioning is probably a bad idea.\n"
 		   "Umount all file systems, and swapoff all swap partitions on this disk.\n"
 		   "Use the --no-reread flag to suppress this check.\n"));
diff -Naur util-linux-2.12m/fdisk/sfdisk.examples util-linux-2.12m.port/fdisk/sfdisk.examples
--- util-linux-2.12m/fdisk/sfdisk.examples	1999-07-09 04:56:35.000000000 +0200
+++ util-linux-2.12m.port/fdisk/sfdisk.examples	2004-12-22 11:19:34.000000000 +0100
@@ -4,9 +4,9 @@
 
 Before doing anything with a disk, make sure it is not in use;
 unmount all its file systems, and say swapoff to its swap partitions.
-(The final BLKRRPART ioctl will fail if anything else still uses
-the disk, and you will have to reboot. It is easier to first make
-sure that nothing uses the disk, e.g., by testing:
+(The function disk_reread_partition_table will fail if anything else
+still uses the disk, and you will have to reboot. It is easier to first
+make sure that nothing uses the disk, e.g., by testing:
 	% umount /dev/sdb1
 	% sfdisk -R /dev/sdb
 	BLKRRPART: Device or resource busy
diff -Naur util-linux-2.12m/hwclock/Makefile util-linux-2.12m.port/hwclock/Makefile
--- util-linux-2.12m/hwclock/Makefile	2004-12-15 20:11:59.000000000 +0100
+++ util-linux-2.12m.port/hwclock/Makefile	2004-12-22 12:42:38.000000000 +0100
@@ -3,6 +3,7 @@
 include ../make_include
 include ../MCONFIG
 
+ifeq "$(KERNEL)" "linux"
 # Where to put man pages?
 
 MAN8= 		hwclock.8
@@ -11,6 +12,7 @@
 # See the "install" rule for the links. . .
 
 SBIN= 		hwclock
+endif
 
 
 all: $(SBIN)
diff -Naur util-linux-2.12m/lib/disk_geom.c util-linux-2.12m.port/lib/disk_geom.c
--- util-linux-2.12m/lib/disk_geom.c	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/disk_geom.c	2004-12-22 11:19:34.000000000 +0100
@@ -0,0 +1,114 @@
+#include "disk_geom.h"
+
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <unistd.h>
+
+#ifdef __linux__
+
+/* including <linux/fs.h> fails */
+#define BLKRRPART    _IO(0x12,95)	/* re-read partition table */
+#define BLKFLSBUF    _IO(0x12,97)	/* flush buffer cache */
+#define BLKGETSIZE64 _IOR(0x12,114,8)	/* 8 = sizeof(u64) */
+
+/*
+ * For large disks g.cylinders is truncated, so we use BLKGETSIZE.
+ */
+
+/* including <linux/hdreg.h> also fails */
+struct hd_geometry {
+      unsigned char heads;
+      unsigned char sectors;
+      unsigned short cylinders;
+      unsigned long start;
+};
+
+#define HDIO_GETGEO		0x0301	/* get device geometry */
+
+#elif defined(__FreeBSD__kernel__) || defined(__OpenBSD__) || defined(__NetBSD__)
+#include <sys/disklabel.h>
+#endif
+
+
+int
+disk_get_geometry(int fd, struct disk_geom *geometry)
+{
+	int error = 0;
+#ifdef __linux__
+	struct hd_geometry linux_geom;
+
+	if (!ioctl(fd, HDIO_GETGEO, &linux_geom)) {
+		geometry->cylinders = linux_geom.cylinders;
+		geometry->heads = linux_geom.heads;
+		geometry->sectors = linux_geom.sectors;
+		geometry->start = linux_geom.start;
+		error = 1;
+	}
+#elif defined(__FreeBSD_kernel__)
+	struct disklabel dlabel;
+
+	if (!ioctl(fd, DIOCGDINFO, &dlabel)) {
+		gemoetry->cylinders = dlabel.d_ncylinders;
+		gemoetry->heads = dlabel.d_ntracks;
+		gemoetry->sectors = dlabel.d_nsectors;
+		gemoetry->start = 0;
+		error = 1;
+	}
+#endif
+
+	return error;
+}
+
+int
+disk_flush_cache(int fd)
+{
+#ifdef __linux__
+	/*
+	 * Blocks are visible in more than one way:
+	 * e.g. as block on /dev/hda and as block on /dev/hda3
+	 * By a bug in the Linux buffer cache, we will see the old
+	 * contents of /dev/hda when the change was made to /dev/hda3.
+	 * In order to avoid this, discard all blocks on /dev/hda.
+	 * Note that partition table blocks do not live in /dev/hdaN,
+	 * so this only plays a role if we want to show volume labels.
+	 */
+	ioctl(fd, BLKFLSBUF);	/* ignore errors */
+				/* e.g. Permission Denied */
+#else
+	sync();
+#endif
+
+	return 0;
+}
+
+int
+disk_reread_partition_table(int fd)
+{
+	int error = 0;
+
+#ifdef __linux__
+	sync();
+	sleep(2);
+	error = ioctl(fd,BLKRRPART);
+	if (error != 0)
+		error = errno;
+	else {
+		/* Some kernel versions (1.2.x) seem to have trouble
+		 * rereading the partition table, but if asked to do it
+		 * twice, the second time works.  -- biro@yggdrasil.com
+		 */
+		sync();
+		sleep(2);
+		error = ioctl(fd, BLKRRPART);
+		if (error != 0)
+			error = errno;
+        }
+	sync();
+	sleep(4);
+#else
+	error = ENOSYS;
+#endif
+
+	return error;
+}
+
diff -Naur util-linux-2.12m/lib/disk_geom.h util-linux-2.12m.port/lib/disk_geom.h
--- util-linux-2.12m/lib/disk_geom.h	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/disk_geom.h	2004-12-22 11:19:34.000000000 +0100
@@ -0,0 +1,18 @@
+#ifndef DISK_GEOM_H
+#define DISK_GEOM_H
+
+#include <sys/types.h>
+
+struct disk_geom {
+	unsigned int heads;
+	unsigned int sectors;
+	unsigned int cylinders;
+	off_t start;
+};
+
+extern int disk_get_geometry(int fd, struct disk_geom *geometry);
+extern int disk_reread_partition_table(int fd);
+extern int disk_flush_cache(int fd);
+
+#endif
+
diff -Naur util-linux-2.12m/lib/disk_size.c util-linux-2.12m.port/lib/disk_size.c
--- util-linux-2.12m/lib/disk_size.c	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/disk_size.c	2004-12-22 11:40:36.000000000 +0100
@@ -0,0 +1,162 @@
+/*
+ * unsigned long disk_get_sectors (int fd)
+ *
+ * 	returns the number of 512-byte sectors of fd
+ *
+ * Most code ripped from:
+ * 
+ * 	mkswap.c
+ * 	mkfs.bfs.c
+ * 	mkfs.minix.c
+ *
+ * by Guillem Jover <guillem@debian.org>
+ * 
+ */
+
+#include "../defines.h"
+#include "disk_size.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef __linux__
+#include <sys/ioctl.h>
+
+/* cannot #include <linux/fs.h>, because it uses u64... */
+#ifndef BLKGETSIZE
+/* return device size */
+#ifndef _IO
+/* pre-1.3.45 */
+#define BLKGETSIZE 0x1260
+#else
+/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */
+#define BLKGETSIZE	_IO(0x12,96)	/* return device size */
+#define BLKSSZGET	_IO(0x12,104)	/* get block device sector size */
+#define BLKGETSIZE64	_IOR(0x12,114,size_t)	/* size in bytes */
+#endif
+#endif
+#elif defined(__FreeBSD_kernel__)
+#define DIOCGMEDIASIZE	_IOR('d', 129, off_t)
+#define DIOCGSECTORSIZE	_IOR('d', 128, u_int)
+#endif
+
+static int
+valid_offset (int fd, off_t offset)
+{
+	char ch;
+
+	if (lseek (fd, offset, 0) < 0)
+		return 0;
+	if (read (fd, &ch, 1) < 1)
+		return 0;
+	return 1;
+}
+
+static off_t
+count_sectors (int fd)
+{
+	off_t high, low, sectors;
+
+	low = 0;
+	for (high = 1; high > 0 && valid_offset (fd, high); high *= 2)
+		low = high;
+	while (low < high - 1) {
+		const off_t mid = (low + high) / 2;
+
+		if (valid_offset (fd, mid))
+			low = mid;
+		else
+			high = mid;
+	}
+	sectors = (low + 1) / 512;
+	return sectors;
+}
+
+off_t
+disk_get_sectors (int fd)
+{
+	struct stat st;
+	off_t sectors = 0;
+
+#ifdef __linux__
+	{
+		unsigned long ioctl_sectors;
+		off_t bytes;
+
+		if (ioctl(fd, BLKGETSIZE, &ioctl_sectors))
+			ioctl_sectors = 0;
+		if (ioctl(fd, BLKGETSIZE64, &bytes))
+			bytes = 0;
+
+		/*
+		 * If BLKGETSIZE64 was unknown or broken, use sectors.
+		 * (Kernels 2.4.15-2.4.17 had a broken BLKGETSIZE64
+		 * that returns sectors instead of bytes.)
+		 */
+		if (bytes != 0 && ioctl_sectors != 0) {
+			if (bytes == ioctl_sectors)
+				sectors = ioctl_sectors;
+			else
+				sectors = bytes >> 9;
+		} else if (bytes != 0) {
+			sectors = bytes >> 9;
+		} else if (ioctl_sectors != 0) {
+			sectors = ioctl_sectors;
+		}
+
+		return sectors;
+	}
+#elif defined(__FreeBSD_kernel__)
+	{
+		ioctl(fd, DIOCGMEDIASIZE, &sectors);
+		return sectors;
+	}
+#endif
+
+	if (fstat(fd, &st) == 0)
+		return st.st_size / 512;
+
+	return count_sectors(fd);
+}
+
+#ifdef __linux__
+#include <sys/utsname.h>
+#define MAKE_VERSION(p,q,r)     (65536*(p) + 256*(q) + (r))
+
+static int
+linux_version_code(void) {
+	static int kernel_version = 0;
+	struct utsname my_utsname;
+	int p, q, r;
+
+	if (!kernel_version && uname(&my_utsname) == 0) {
+		p = atoi(strtok(my_utsname.release, "."));
+		q = atoi(strtok(NULL, "."));
+		r = atoi(strtok(NULL, "."));
+		kernel_version = MAKE_VERSION(p,q,r);
+	}
+	return kernel_version;
+}
+#endif
+
+int
+disk_get_sector_size (int fd)
+{
+	int sector_size = 512;
+
+#ifdef __linux__
+	if (linux_version_code() >= MAKE_VERSION(2,3,3)) {
+		int arg;
+
+		if (ioctl(fd, BLKSSZGET, &arg) == 0)
+			sector_size = arg;
+	}
+#elif defined(__FreeBSD_kernel__)
+	ioctl(fd, DIOCGSECTORSIZE, &sector_size);
+#endif
+
+	return sector_size;
+}
+
diff -Naur util-linux-2.12m/lib/disk_size.h util-linux-2.12m.port/lib/disk_size.h
--- util-linux-2.12m/lib/disk_size.h	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/disk_size.h	2004-12-22 11:36:54.000000000 +0100
@@ -0,0 +1,10 @@
+#ifndef DISK_SIZE_H
+#define DISK_SIZE_H
+
+#include <sys/types.h>
+
+extern off_t disk_get_sectors (int fd);
+extern int disk_get_sector_size (int fd);
+
+#endif
+
diff -Naur util-linux-2.12m/lib/linux_reboot.h util-linux-2.12m.port/lib/linux_reboot.h
--- util-linux-2.12m/lib/linux_reboot.h	1999-07-09 04:56:36.000000000 +0200
+++ util-linux-2.12m.port/lib/linux_reboot.h	1970-01-01 01:00:00.000000000 +0100
@@ -1,30 +0,0 @@
-extern int my_reboot(int);
-
-/*
- * Magic values required to use _reboot() system call.
- */
-
-#define	LINUX_REBOOT_MAGIC1	0xfee1dead
-#define	LINUX_REBOOT_MAGIC2	672274793
-#define	LINUX_REBOOT_MAGIC2A	85072278
-#define	LINUX_REBOOT_MAGIC2B	369367448
-
-
-/*
- * Commands accepted by the _reboot() system call.
- *
- * RESTART     Restart system using default command and mode.
- * HALT        Stop OS and give system control to ROM monitor, if any.
- * CAD_ON      Ctrl-Alt-Del sequence causes RESTART command.
- * CAD_OFF     Ctrl-Alt-Del sequence sends SIGINT to init task.
- * POWER_OFF   Stop OS and remove all power from system, if possible.
- * RESTART2    Restart system using given command string.
- */
-
-#define	LINUX_REBOOT_CMD_RESTART	0x01234567
-#define	LINUX_REBOOT_CMD_HALT		0xCDEF0123
-#define	LINUX_REBOOT_CMD_CAD_ON		0x89ABCDEF
-#define	LINUX_REBOOT_CMD_CAD_OFF	0x00000000
-#define	LINUX_REBOOT_CMD_POWER_OFF	0x4321FEDC
-#define	LINUX_REBOOT_CMD_RESTART2	0xA1B2C3D4
-
diff -Naur util-linux-2.12m/lib/Makefile util-linux-2.12m.port/lib/Makefile
--- util-linux-2.12m/lib/Makefile	2002-11-02 14:51:26.000000000 +0100
+++ util-linux-2.12m.port/lib/Makefile	2004-12-22 11:19:34.000000000 +0100
@@ -1,11 +1,12 @@
 include ../make_include
 include ../MCONFIG
 
-all: err.o my_reboot.o setproctitle.o env.o carefulputc.o xstrncpy.o md5.o
-
+all: err.o my_reboot.o setproctitle.o env.o carefulputc.o md5.o \
+	xgethostname.o xstrncpy.o disk_geom.o disk_size.o
+ 
 err.o: err.c
 
-my_reboot.o: my_reboot.c linux_reboot.h
+my_reboot.o: my_reboot.c my_reboot.h
 
 env.o: env.h
 
@@ -15,6 +16,12 @@
 
 xstrncpy.o: xstrncpy.h
 
+xgethostname.o: xgethostname.h
+
+disk_geom.o: disk_geom.h
+
+disk_size.o: disk_size.h
+
 md5.o: md5.c md5.h
 
 .PHONY: clean
diff -Naur util-linux-2.12m/lib/my_reboot.c util-linux-2.12m.port/lib/my_reboot.c
--- util-linux-2.12m/lib/my_reboot.c	1999-07-09 04:56:36.000000000 +0200
+++ util-linux-2.12m.port/lib/my_reboot.c	2004-12-22 11:19:34.000000000 +0100
@@ -1,7 +1,7 @@
 /* Including <unistd.h> makes sure that on a glibc system
    <features.h> is included, which again defines __GLIBC__ */
 #include <unistd.h>
-#include "linux_reboot.h"
+#include "my_reboot.h"
 
 #define USE_LIBC
 
@@ -17,7 +17,10 @@
 #endif
 int
 my_reboot(int cmd) {
-	return REBOOT(cmd);
+#ifndef __linux__
+	if (cmd != MY_REBOOT_CMD_CAD_ON && cmd != MY_REBOOT_CMD_CAD_OFF)
+#endif
+		return REBOOT(cmd);
 }
 
 #else /* no USE_LIBC */
diff -Naur util-linux-2.12m/lib/my_reboot.h util-linux-2.12m.port/lib/my_reboot.h
--- util-linux-2.12m/lib/my_reboot.h	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/my_reboot.h	2004-12-22 12:54:48.000000000 +0100
@@ -0,0 +1,51 @@
+#ifndef MY_REBOOT_H
+#define MY_REBOOT_H
+
+extern int my_reboot(int);
+
+#if defined(__linux__)
+/*
+ * Magic values required to use _reboot() system call.
+ */
+
+#define	LINUX_REBOOT_MAGIC1	0xfee1dead
+#define	LINUX_REBOOT_MAGIC2	672274793
+#define	LINUX_REBOOT_MAGIC2A	85072278
+#define	LINUX_REBOOT_MAGIC2B	369367448
+
+
+/*
+ * Commands accepted by the _reboot() system call.
+ *
+ * RESTART     Restart system using default command and mode.
+ * HALT        Stop OS and give system control to ROM monitor, if any.
+ * CAD_ON      Ctrl-Alt-Del sequence causes RESTART command.
+ * CAD_OFF     Ctrl-Alt-Del sequence sends SIGINT to init task.
+ * POWER_OFF   Stop OS and remove all power from system, if possible.
+ * RESTART2    Restart system using given command string.
+ */
+
+#define	MY_REBOOT_CMD_RESTART	0x01234567
+#define	MY_REBOOT_CMD_HALT	0xCDEF0123
+#define	MY_REBOOT_CMD_CAD_ON	0x89ABCDEF
+#define	MY_REBOOT_CMD_CAD_OFF	0x00000000
+#define	MY_REBOOT_CMD_POWER_OFF	0x4321FEDC
+#define	MY_REBOOT_CMD_RESTART2	0xA1B2C3D4
+
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+
+#include <sys/reboot.h>
+
+#define	MY_REBOOT_CMD_RESTART	RB_AUTOBOOT
+#define	MY_REBOOT_CMD_HALT	RB_HALT
+#define	MY_REBOOT_CMD_CAD_ON	0xFFFFFFFF
+#define	MY_REBOOT_CMD_CAD_OFF	0xFFFFFFFF
+#define	MY_REBOOT_CMD_POWER_OFF	RB_POWEROFF
+#define	MY_REBOOT_CMD_RESTART2	RB_AUTOBOOT
+
+#else
+#error "No reboot commands defined on this port"
+#endif
+
+#endif
+
diff -Naur util-linux-2.12m/lib/README.xgethostname util-linux-2.12m.port/lib/README.xgethostname
--- util-linux-2.12m/lib/README.xgethostname	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/README.xgethostname	2004-12-22 11:19:34.000000000 +0100
@@ -0,0 +1,76 @@
+A wrapper for gethostname that automatically checks system limitations.
+
+Latest version can always be found at:
+ftp://walfield.org/pub/people/neal/xgethostname/xgethostname-latest.tar.gz
+
+Author:
+Neal H Walfield <neal@cs.uml.edu>
+
+Version:
+April 13, 2002
+
+ChangeLog:
+2002-04-13  Neal H Walfield  <neal@walfield.org>
+
+	* VERSION: Update to 20010413.
+	* Release version 20010413.
+	
+2002-04-13  Neal H Walfield  <neal@walfield.org>
+
+	* xgethostname.c (xgethostname): gethostname returns -1 on error,
+	not the error code.  There is no need to use realloc as it copies
+	the unused buffer.
+
+2001-08-03  Neal H Walfield  <neal@cs.uml.edu>
+
+	* VERSION: Update to 20010803.
+	* Release version 20010803.
+
+2001-08-03  Neal H Walfield  <neal@cs.uml.edu>
+
+	* Makefile: Make no assumptions about the make that the user
+	will be using.
+	* xgethostname.c (xgethostname): Be explicitly sure that the
+	returned buffer is NULL terminated.
+	Always compile in the while (err = ENAMETOOLONG) loop; this
+	may help to catch a very exotic implementation and does not
+	hurt anyone.
+
+2001-08-02  Neal H Walfield  <neal@cs.uml.edu>
+
+	* Release version 20010802.
+
+2001-08-01  Neal H Walfield  <neal@cs.uml.edu>
+
+	* Makefile: New file.
+	* README: New file.
+	* xgethostname.c (xgethostname) [!_SC_HOST_NAME_MAX]: Should
+	not be subject to this condition.
+	(xgethostname): If the system defines a limit < 256 and > 0,
+	do not artificially inflate it, rather, respect it.
+
+2001-07-30  Neal H Walfield  <neal@cs.uml.edu>
+
+	* REAMME: Move from here . . .
+	* xgethostname.2: to here.
+	Format it for man.
+
+2001-07-30  Neal H Walfield  <neal@cs.uml.edu>
+
+	* README: Fix grammer error.
+	* xgethostname.c: Likewise.
+	* xgethostname.h: Likewise.
+
+	* Makefile: New file.
+
+2001-07-29  Neal H Walfield  <neal@cs.uml.edu>
+
+	* Release version 20010729.
+
+	* AUTHOR: New file.
+	* ChangeLog: New file.
+	* COPYING: New file.
+	* README: New file.
+	* VERSION: New file.
+	* xgethostname.c: New file.
+	* xgethostname.h: New file.
diff -Naur util-linux-2.12m/lib/xgethostname.2 util-linux-2.12m.port/lib/xgethostname.2
--- util-linux-2.12m/lib/xgethostname.2	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/xgethostname.2	2004-12-22 11:19:34.000000000 +0100
@@ -0,0 +1,37 @@
+.TH XGETHOSTNAME 2 "30 July 2001" "xgethostname"
+.SH NAME
+xgethostname \- get the host name.
+.SH
+SYNOPSIS
+.BI "char *xgethostname (void);"
+.SH DESCRIPTION
+The xhostname function is intended to replace
+.BR gethostname(2),
+a function used to access the host name.  The old interface is
+inflexable given that it assumes the existance of the
+.BR MAXHOSTNAMELEN
+macro, which neither
+.BR POSIX
+nor the proposed
+.BR "Single Unix Specification version 3"
+guarantee to be defined.
+.SH RETURN VALUE
+On success, a malloced, null terminated (possibly truncated)
+string containing the host name is returned.  On failure,
+.I NULL
+is returned and errno is set.
+.SH ERRORS
+.TP
+.BR ENOMEM
+Failed to allocate memory.
+.LP
+As 
+.BR xgethostname
+is really just a wrapper around your systems
+.BR gethostname (2),
+see that man page for additional details.
+.SH "SEE ALSO"
+.BR gethostname (2)
+.SH AUTHOR
+.BR xgethostname
+was written by Neal H Walfield  <neal@cs.uml.edu>.
diff -Naur util-linux-2.12m/lib/xgethostname.c util-linux-2.12m.port/lib/xgethostname.c
--- util-linux-2.12m/lib/xgethostname.c	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/xgethostname.c	2004-12-22 11:19:34.000000000 +0100
@@ -0,0 +1,126 @@
+/* Copyright (c) 2001 Neal H Walfield <neal@cs.uml.edu>.
+   
+   This file is placed into the public domain.  Its distribution
+   is unlimited.
+
+   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+   IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
+   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+   IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* NAME
+
+	xgethostname - get the host name.
+
+   SYNOPSIS
+
+   	char *xgethostname (void);
+
+   DESCRIPTION
+
+	The xhostname function is intended to replace gethostname(2), a
+	function used to access the host name.  The old interface is
+	inflexable given that it assumes the existance of the
+	MAXHOSTNAMELEN macro, which neither POSIX nor the proposed
+	Single Unix Specification version 3 guarantee to be defined.
+
+   RETURN VALUE
+
+	On success, a malloced, null terminated (possibly truncated)
+	string containing the host name is returned.  On failure,
+	NULL is returned and errno is set.
+ */
+
+#include <sys/param.h>	/* For MAXHOSTNAMELEN */
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include "xgethostname.h"
+
+char *
+xgethostname (void)
+{
+  int size = 0;
+  int addnull = 0;
+  char *buf;
+  int err;
+
+#ifdef MAXHOSTNAMELEN
+  size = MAXHOSTNAMELEN;
+  addnull = 1;
+#else /* MAXHOSTNAMELEN */
+#ifdef _SC_HOST_NAME_MAX
+  size = sysconf (_SC_HOST_NAME_MAX);
+  addnull = 1;
+#endif /* _SC_HOST_NAME_MAX */
+  if (size <= 0)
+    size = 256;
+#endif /* MAXHOSTNAMELEN */
+
+  buf = malloc (size + addnull);
+  if (! buf)
+    {
+      errno = ENOMEM;
+      return NULL;
+    }
+
+  err = gethostname (buf, size);
+  while (err == -1 && errno == ENAMETOOLONG)
+    {
+      free (buf);
+
+      size *= 2;
+      buf = malloc (size + addnull);
+      if (! buf)
+	{
+	  errno = ENOMEM;
+	  return NULL;
+	}
+      
+      err = gethostname (buf, size);
+    }
+
+  if (err)
+    {
+      if (buf)
+        free (buf);
+      errno = err;
+      return NULL;
+    }
+
+  if (addnull)
+    buf[size] = '\0';
+
+  return buf;
+}
+
+#ifdef WANT_TO_TEST_XGETHOSTNAME
+#include <stdio.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+  char *hostname;
+
+  hostname = xgethostname ();
+  if (! hostname)
+    {
+      perror ("xgethostname");
+      return 1;
+    }
+
+  printf ("%s\n", hostname);
+  free (hostname);
+
+  return 0;
+}
+#endif /* WANT_TO_TEST_XGETHOSTNAME */
diff -Naur util-linux-2.12m/lib/xgethostname.h util-linux-2.12m.port/lib/xgethostname.h
--- util-linux-2.12m/lib/xgethostname.h	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.12m.port/lib/xgethostname.h	2004-12-22 11:19:34.000000000 +0100
@@ -0,0 +1,48 @@
+/* Copyright (c) 2001 Neal H Walfield <neal@cs.uml.edu>.
+   
+   This file is placed into the public domain.  Its distribution
+   is unlimited.
+
+   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+   IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
+   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+   IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* NAME
+
+	xgethostname - get the host name.
+
+   SYNOPSIS
+
+   	char *xgethostname (void);
+
+   DESCRIPTION
+
+	The xhostname function is intended to replace gethostname(2), a
+	function used to access the host name.  The old interface is
+	inflexable given that it assumes the existance of the
+	MAXHOSTNAMELEN macro, which neither POSIX nor the proposed
+	Single Unix Specification version 3 guarantee to be defined.
+
+   RETURN VALUE
+
+	On success, a malloced, null terminated (possibly truncated)
+	string containing the host name is returned.  On failure,
+	NULL is returned and errno is set.
+ */
+
+#ifndef XGETHOSTNAME
+#define XGETHOSTNAME
+
+char * xgethostname (void);
+
+#endif /* XGETHOSTNAME */
+
diff -Naur util-linux-2.12m/login-utils/agetty.c util-linux-2.12m.port/login-utils/agetty.c
--- util-linux-2.12m/login-utils/agetty.c	2002-07-29 09:36:42.000000000 +0200
+++ util-linux-2.12m.port/login-utils/agetty.c	2004-12-22 11:19:34.000000000 +0100
@@ -17,8 +17,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/ioctl.h>
-#include <termio.h>
+#include <termios.h>
 #include <signal.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -30,10 +29,11 @@
 #include <getopt.h>
 #include <time.h>
 #include <sys/file.h>
+#include "xgethostname.h"
 #include "xstrncpy.h"
 #include "nls.h"
 
-#ifdef __linux__
+#if defined(unix)
 #include "pathnames.h"
 #include <sys/param.h>
 #define USE_SYSLOG
@@ -93,27 +93,6 @@
 #define DEF_SWITCH	0		/* default switch char */
 
  /*
-  * SunOS 4.1.1 termio is broken. We must use the termios stuff instead,
-  * because the termio -> termios translation does not clear the termios
-  * CIBAUD bits. Therefore, the tty driver would sometimes report that input
-  * baud rate != output baud rate. I did not notice that problem with SunOS
-  * 4.1. We will use termios where available, and termio otherwise.
-  */
-
-/* linux 0.12 termio is broken too, if we use it c_cc[VERASE] isn't set
-   properly, but all is well if we use termios?! */
-
-#ifdef	TCGETS
-#undef	TCGETA
-#undef	TCSETA
-#undef	TCSETAW
-#define	termio	termios
-#define	TCGETA	TCGETS
-#define	TCSETA	TCSETS
-#define	TCSETAW	TCSETSW
-#endif
-
- /*
   * This program tries to not use the standard-i/o library.  This keeps the
   * executable small on systems that do not have shared libraries (System V
   * Release <3).
@@ -221,13 +200,13 @@
 void parse_args P_((int argc, char **argv, struct options *op));
 void parse_speeds P_((struct options *op, char *arg));
 void update_utmp P_((char *line));
-void open_tty P_((char *tty, struct termio *tp, int local));
-void termio_init P_((struct termio *tp, int speed, struct options *op));
-void auto_baud P_((struct termio *tp));
-void do_prompt P_((struct options *op, struct termio *tp));
-void next_speed P_((struct termio *tp, struct options *op));
-char *get_logname P_((struct options *op, struct chardata *cp, struct termio *tp));
-void termio_final P_((struct options *op, struct termio *tp, struct chardata *cp));
+void open_tty P_((char *tty, struct termios *tp, int local));
+void termios_init P_((struct termios *tp, int speed, struct options *op));
+void auto_baud P_((struct termios *tp));
+void do_prompt P_((struct options *op, struct termios *tp));
+void next_speed P_((struct termios *tp, struct options *op));
+char *get_logname P_((struct options *op, struct chardata *cp, struct termios *tp));
+void termios_final P_((struct options *op, struct termios *tp, struct chardata *cp));
 int caps_lock P_((char *s));
 int bcode P_((char *s));
 void usage P_((void));
@@ -256,7 +235,7 @@
 {
     char   *logname = NULL;		/* login name, given to /bin/login */
     struct chardata chardata;		/* set by get_logname() */
-    struct termio termio;		/* terminal mode bits */
+    struct termios termios;		/* terminal mode bits */
     static struct options options = {
 	F_ISSUE,			/* show /etc/issue (SYSV_STYLE) */
 	0,				/* no timeout */
@@ -299,7 +278,7 @@
 
     parse_args(argc, argv, &options);
 
-#ifdef __linux__
+#if defined(unix)
 	setsid();
 #endif
 	
@@ -311,19 +290,19 @@
 
     debug(_("calling open_tty\n"));
     /* Open the tty as standard { input, output, error }. */
-    open_tty(options.tty, &termio, options.flags & F_LOCAL);
+    open_tty(options.tty, &termios, options.flags & F_LOCAL);
 
-#ifdef __linux__
+#if defined(unix)
 	{
 		int iv;
 		
 		iv = getpid();
-		(void) ioctl(0, TIOCSPGRP, &iv);
+		(void) tcsetpgrp(0, iv);
 	}
 #endif
-    /* Initialize the termio settings (raw mode, eight-bit, blocking i/o). */
-    debug(_("calling termio_init\n"));
-    termio_init(&termio, options.speeds[FIRST_SPEED], &options);
+    /* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */
+    debug(_("calling termios_init\n"));
+    termios_init(&termios, options.speeds[FIRST_SPEED], &options);
 
     /* write the modem init string and DON'T flush the buffers */
     if (options.flags & F_INITSTRING) {
@@ -339,7 +318,7 @@
     /* Optionally detect the baud rate from the modem status message. */
     debug(_("before autobaud\n"));
     if (options.flags & F_PARSE)
-	auto_baud(&termio);
+	auto_baud(&termios);
 
     /* Set the optional timer. */
     if (options.timeout)
@@ -363,8 +342,8 @@
     if (!(options.flags & F_NOPROMPT)) {
 	/* Read the login name. */
 	debug(_("reading login name\n"));
-	while ((logname = get_logname(&options, &chardata, &termio)) == 0)
-	  next_speed(&termio, &options);
+	while ((logname = get_logname(&options, &chardata, &termios)) == 0)
+	  next_speed(&termios, &options);
     }
 
     /* Disable timer. */
@@ -372,9 +351,9 @@
     if (options.timeout)
 	(void) alarm(0);
 
-    /* Finalize the termio settings. */
+    /* Finalize the termios settings. */
 
-    termio_final(&options, &termio, &chardata);
+    termios_final(&options, &termios, &chardata);
 
     /* Now the newline character should be properly written. */
 
@@ -629,7 +608,7 @@
 void
 open_tty(tty, tp, local)
      char   *tty;
-     struct termio *tp;
+     struct termios *tp;
      int    local;
 {
     /* Get rid of the present standard { output, error} if any. */
@@ -678,7 +657,7 @@
 	error(_("%s: dup problem: %m"), tty);	/* we have a problem */
 
     /*
-     * The following ioctl will fail if stdin is not a tty, but also when
+     * The following function will fail if stdin is not a tty, but also when
      * there is noise on the modem control lines. In the latter case, the
      * common course of action is (1) fix your cables (2) give the modem more
      * time to properly reset after hanging up. SunOS users can achieve (2)
@@ -686,8 +665,8 @@
      * 5 seconds seems to be a good value.
      */
 
-    if (ioctl(0, TCGETA, tp) < 0)
-	error("%s: ioctl: %m", tty);
+    if (tcgetattr(0, tp) < 0)
+	error("%s: tcgetattr: %m", tty);
 
     /*
      * It seems to be a terminal. Set proper protections and ownership. Mode
@@ -705,27 +684,27 @@
     errno = 0;					/* ignore above errors */
 }
 
-/* termio_init - initialize termio settings */
+/* termios_init - initialize termios settings */
 
 char gbuf[1024];
 char area[1024];
 
 void
-termio_init(tp, speed, op)
-     struct termio *tp;
+termios_init(tp, speed, op)
+     struct termios *tp;
      int     speed;
      struct options *op;
 {
 
     /*
-     * Initial termio settings: 8-bit characters, raw-mode, blocking i/o.
+     * Initial termios settings: 8-bit characters, raw-mode, blocking i/o.
      * Special characters are set after we have read the login name; all
      * reads will be done in raw mode anyway. Errors will be dealt with
      * lateron.
      */
-#ifdef __linux__
+#if defined(unix)
     /* flush input and output queues, important for modems! */
-    (void) ioctl(0, TCFLSH, TCIOFLUSH);
+    (void) tcflush(0, TCIOFLUSH);
 #endif
 
     tp->c_cflag = CS8 | HUPCL | CREAD | speed;
@@ -733,7 +712,10 @@
 	tp->c_cflag |= CLOCAL;
     }
 
-    tp->c_iflag = tp->c_lflag = tp->c_oflag = tp->c_line = 0;
+    tp->c_iflag = tp->c_lflag = tp->c_oflag = 0;
+#if defined(__linux__)
+    tp->c_line = 0;
+#endif
     tp->c_cc[VMIN] = 1;
     tp->c_cc[VTIME] = 0;
 
@@ -744,7 +726,7 @@
 	tp->c_cflag |= CRTSCTS;
 #endif
 
-    (void) ioctl(0, TCSETA, tp);
+    (void) tcsetattr(0, TCSANOW, tp);
 
     /* go to blocking input even in local mode */
     fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) & ~O_NONBLOCK);
@@ -755,7 +737,7 @@
 /* auto_baud - extract baud rate from modem status message */
 void
 auto_baud(tp)
-     struct termio *tp;
+     struct termios *tp;
 {
     int     speed;
     int     vmin;
@@ -788,7 +770,7 @@
     tp->c_iflag |= ISTRIP;			/* enable 8th-bit stripping */
     vmin = tp->c_cc[VMIN];
     tp->c_cc[VMIN] = 0;				/* don't block if queue empty */
-    (void) ioctl(0, TCSETA, tp);
+    (void) tcsetattr(0, TCSANOW, tp);
 
     /*
      * Wait for a while, then read everything the modem has said so far and
@@ -801,8 +783,7 @@
 	for (bp = buf; bp < buf + nread; bp++) {
 	    if (isascii(*bp) && isdigit(*bp)) {
 		if ((speed = bcode(bp))) {
-		    tp->c_cflag &= ~CBAUD;
-		    tp->c_cflag |= speed;
+		    (void) cfsetospeed(tp, speed);
 		}
 		break;
 	    }
@@ -812,14 +793,14 @@
 
     tp->c_iflag = iflag;
     tp->c_cc[VMIN] = vmin;
-    (void) ioctl(0, TCSETA, tp);
+    (void) tcsetattr(0, TCSANOW, tp);
 }
 
 /* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
 void
 do_prompt(op, tp)
      struct options *op;
-     struct termio *tp;
+     struct termios *tp;
 {
 #ifdef	ISSUE
     FILE    *fd;
@@ -835,7 +816,7 @@
     if ((op->flags & F_ISSUE) && (fd = fopen(op->issue, "r"))) {
 	oflag = tp->c_oflag;			/* save current setting */
 	tp->c_oflag |= (ONLCR | OPOST);		/* map NL in output to CR-NL */
-	(void) ioctl(0, TCSETAW, tp);
+	(void) tcsetattr(0, TCSADRAIN, tp);
 
 
 	while ((c = getc(fd)) != EOF)
@@ -915,7 +896,7 @@
 			int i;
 
 			for (i = 0; speedtab[i].speed; i++) {
-			    if (speedtab[i].code == (tp->c_cflag & CBAUD)) {
+			    if (speedtab[i].code == cfgetospeed(tp)) {
 				printf("%ld", speedtab[i].speed);
 				break;
 			    }
@@ -947,16 +928,18 @@
 	fflush(stdout);
 
 	tp->c_oflag = oflag;			/* restore settings */
-	(void) ioctl(0, TCSETAW, tp);		/* wait till output is gone */
+	(void) tcsetattr(0, TCSADRAIN, tp);	/* wait till output is gone */
 	(void) fclose(fd);
     }
 #endif
-#ifdef __linux__
+#if defined(unix)
 	{
-		char hn[MAXHOSTNAMELEN+1];
+		char *hn;
 
-		(void) gethostname(hn, MAXHOSTNAMELEN);
+		if (!(hn = xgethostname()))
+			error(_("can't get hostname"));
 		write(1, hn, strlen(hn));
+		free(hn);
 	}
 #endif		
     (void) write(1, LOGIN, sizeof(LOGIN) - 1);	/* always show login prompt */
@@ -965,15 +948,14 @@
 /* next_speed - select next baud rate */
 void
 next_speed(tp, op)
-     struct termio *tp;
+     struct termios *tp;
      struct options *op;
 {
     static int baud_index = FIRST_SPEED;/* current speed index */
 
     baud_index = (baud_index + 1) % op->numspeed;
-    tp->c_cflag &= ~CBAUD;
-    tp->c_cflag |= op->speeds[baud_index];
-    (void) ioctl(0, TCSETA, tp);
+    (void) cfsetospeed(0, op->speeds[baud_index]);
+    (void) tcsetattr(0, TCSANOW, tp);
 }
 
 /* get_logname - get user name, establish parity, speed, erase, kill, eol */
@@ -981,7 +963,7 @@
 char   *get_logname(op, cp, tp)
      struct options *op;
      struct chardata *cp;
-     struct termio *tp;
+     struct termios *tp;
 {
     static char logname[BUFSIZ];
     char   *bp;
@@ -1003,7 +985,7 @@
     /* Flush pending input (esp. after parsing or switching the baud rate). */
 
     (void) sleep(1);
-    (void) ioctl(0, TCFLSH, TCIFLUSH);
+    (void) tcflush(0, TCIFLUSH);
 
     /* Prompt for and read a login name. */
 
@@ -1087,11 +1069,11 @@
     return (logname);
 }
 
-/* termio_final - set the final tty mode bits */
+/* termios_final - set the final tty mode bits */
 void
-termio_final(op, tp, cp)
+termios_final(op, tp, cp)
      struct options *op;
-     struct termio *tp;
+     struct termios *tp;
      struct chardata *cp;
 {
     /* General terminal-independent stuff. */
@@ -1107,7 +1089,7 @@
     tp->c_cc[VEOL] = DEF_EOL;
 #ifdef __linux__
     tp->c_cc[VSWTC] = DEF_SWITCH;		/* default switch character */
-#else
+#elif defined(VSWTCH)
     tp->c_cc[VSWTCH] = DEF_SWITCH;		/* default switch character */
 #endif
 
@@ -1139,11 +1121,13 @@
     }
     /* Account for upper case without lower case. */
 
+#if defined(IUCLC) && defined(XCASE) && defined(OLCUC)
     if (cp->capslock) {
 	tp->c_iflag |= IUCLC;
 	tp->c_lflag |= XCASE;
 	tp->c_oflag |= OLCUC;
     }
+#endif
     /* Optionally enable hardware flow control */
 
 #ifdef	CRTSCTS
@@ -1153,8 +1137,8 @@
 
     /* Finally, make the new settings effective */
 
-    if (ioctl(0, TCSETA, tp) < 0)
-	error("%s: ioctl: TCSETA: %m", op->tty);
+    if (tcsetattr(0, TCSADRAIN, tp) < 0)
+	error("%s: tcsetattr: %m", op->tty);
 }
 
 /* caps_lock - string contains upper case without lower case */
diff -Naur util-linux-2.12m/login-utils/checktty.c util-linux-2.12m.port/login-utils/checktty.c
--- util-linux-2.12m/login-utils/checktty.c	2001-05-19 23:53:18.000000000 +0200
+++ util-linux-2.12m.port/login-utils/checktty.c	2004-12-22 11:19:34.000000000 +0100
@@ -138,7 +138,9 @@
 isapty(const char *tty)
 {
     char devname[100];
+#if defined(__linux__)
     struct stat stb;
+#endif
 
     /* avoid snprintf - old systems do not have it */
     if (strlen(tty) + 6 > sizeof(devname))
diff -Naur util-linux-2.12m/login-utils/last.c util-linux-2.12m.port/login-utils/last.c
--- util-linux-2.12m/login-utils/last.c	2002-03-08 23:59:41.000000000 +0100
+++ util-linux-2.12m.port/login-utils/last.c	2004-12-22 11:19:34.000000000 +0100
@@ -49,6 +49,7 @@
 
 #include "pathnames.h"
 #include "nls.h"
+#include "xgethostname.h"
 
 #define	SECDAY	(24*60*60)			/* seconds in a day */
 #define	NO	0				/* false/no */
@@ -430,15 +431,15 @@
 hostconv(char *arg) {
 	static int	first = 1;
 	static char	*hostdot,
-			name[MAXHOSTNAMELEN];
+			*name;
 	char	*argdot;
 
 	if (!(argdot = strchr(arg, '.')))
 		return;
 	if (first) {
 		first = 0;
-		if (gethostname(name, sizeof(name))) {
-			perror(_("last: gethostname"));
+		if (!(name = xgethostname())) {
+			perror(_("last: can't get hostname"));
 			exit(1);
 		}
 		hostdot = strchr(name, '.');
diff -Naur util-linux-2.12m/login-utils/login.c util-linux-2.12m.port/login-utils/login.c
--- util-linux-2.12m/login-utils/login.c	2004-12-05 03:37:12.000000000 +0100
+++ util-linux-2.12m.port/login-utils/login.c	2004-12-22 11:19:34.000000000 +0100
@@ -116,6 +116,7 @@
 #include "my_crypt.h"
 #include "login.h"
 #include "xstrncpy.h"
+#include "xgethostname.h"
 #include "nls.h"
 
 #ifdef __linux__
@@ -149,7 +150,7 @@
 }
 #endif
 
-#ifndef __linux__
+#if !defined(__GLIBC__)
 #  include <tzfile.h>
 #endif
 #include <lastlog.h>
@@ -202,15 +203,11 @@
 
 #define	TTYGRPNAME	"tty"		/* name of group to own ttys */
 
-#ifndef MAXPATHLEN
-#  define MAXPATHLEN 1024
-#endif
-
 /*
  * This bounds the time given to login.  Not a define so it can
  * be patched on machines where it's too small.
  */
-#ifndef __linux__
+#if !defined(__GLIBC__)
 int	timeout = 300;
 #else
 int     timeout = 60;		/* used in cryptocard.c */
@@ -223,7 +220,7 @@
 char    hostaddress[4];		/* used in checktty.c */
 char	*hostname;		/* idem */
 static char	*username, *tty_name, *tty_number;
-static char	thishost[100];
+static char	*thishost;
 static int	failures = 1;
 static pid_t	pid;
 
@@ -288,6 +285,7 @@
 	}
 }
 
+#ifdef CHOWNVCS
 /* true if the filedescriptor fd is a console tty, very Linux specific */
 static int
 consoletty(int fd) {
@@ -302,6 +300,7 @@
 #endif
     return 0;
 }
+#endif
 
 #if USE_PAM
 /*
@@ -356,7 +355,7 @@
     int ask, fflag, hflag, pflag, cnt, errsv;
     int quietlog, passwd_req;
     char *domain, *ttyn;
-    char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10];
+    char tname[sizeof(_PATH_TTY) + 10];
     char *termenv;
     char *childArgv[10];
     char *buff;
@@ -398,9 +397,11 @@
      * -h is used by other servers to pass the name of the remote
      *    host to login so that it may be placed in utmp and wtmp
      */
-    gethostname(tbuf, sizeof(tbuf));
-    xstrncpy(thishost, tbuf, sizeof(thishost));
-    domain = index(tbuf, '.');
+    if (!(thishost = xgethostname())) {
+	    fprintf(stderr, _("login: can't get hostname\n"));
+	    exit(1);
+    }
+    domain = index(thishost, '.');
     
     username = tty_name = hostname = NULL;
     fflag = hflag = pflag = 0;
@@ -861,23 +862,21 @@
        having the BSD setreuid() */
     
     {
-	char tmpstr[MAXPATHLEN];
+	char *tmpstr;
 	uid_t ruid = getuid();
 	gid_t egid = getegid();
 
 	/* avoid snprintf - old systems do not have it, or worse,
 	   have a libc in which snprintf is the same as sprintf */
-	if (strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2 > MAXPATHLEN)
-		quietlog = 0;
-	else {
-		sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN);
-		setregid(-1, pwd->pw_gid);
-		setreuid(0, pwd->pw_uid);
-		quietlog = (access(tmpstr, R_OK) == 0);
-		setuid(0); /* setreuid doesn't do it alone! */
-		setreuid(ruid, 0);
-		setregid(-1, egid);
-	}
+	tmpstr = malloc(strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2);
+	sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN);
+	setregid(-1, pwd->pw_gid);
+	setreuid(0, pwd->pw_uid);
+	quietlog = (access(tmpstr, R_OK) == 0);
+	setuid(0); /* setreuid doesn't do it alone! */
+	setreuid(ruid, 0);
+	setregid(-1, egid);
+	free(tmpstr);
     }
     
     /* for linux, write entries in utmp and wtmp */
@@ -1028,12 +1027,13 @@
     
     /* mailx will give a funny error msg if you forget this one */
     {
-      char tmp[MAXPATHLEN];
+      char *tmp;
+
       /* avoid snprintf */
-      if (sizeof(_PATH_MAILDIR) + strlen(pwd->pw_name) + 1 < MAXPATHLEN) {
-	      sprintf(tmp, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
-	      setenv("MAIL",tmp,0);
-      }
+      tmp = malloc(sizeof(_PATH_MAILDIR) + strlen(pwd->pw_name) + 2);
+      sprintf(tmp, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
+      setenv("MAIL", tmp, 0);
+      free(tmp);
     }
     
     /* LOGNAME is not documented in login(1) but
@@ -1191,13 +1191,15 @@
 	childArgv[childArgc++] = "-c";
 	childArgv[childArgc++] = buff;
     } else {
-	tbuf[0] = '-';
-	xstrncpy(tbuf + 1, ((p = rindex(pwd->pw_shell, '/')) ?
-			   p + 1 : pwd->pw_shell),
-		sizeof(tbuf)-1);
+	char *tbuf, *shell_cmd;
+
+	tbuf = ((p = rindex(pwd->pw_shell, '/')) ? p + 1 : pwd->pw_shell);
+	shell_cmd = malloc(strlen(tbuf));
+	shell_cmd[0] = '-';
+	xstrncpy(shell_cmd + 1, tbuf, strlen(tbuf)-1);
 	
 	childArgv[childArgc++] = pwd->pw_shell;
-	childArgv[childArgc++] = tbuf;
+	childArgv[childArgc++] = shell_cmd;
     }
 
     childArgv[childArgc++] = NULL;
@@ -1274,12 +1276,12 @@
 
 static void
 timedout2(int sig) {
-	struct termio ti;
+	struct termios ti;
     
 	/* reset echo */
-	ioctl(0, TCGETA, &ti);
+	tcgetattr(0, &ti);
 	ti.c_lflag |= ECHO;
-	ioctl(0, TCSETA, &ti);
+	tcsetattr(0, TCSANOW, &ti);
 	exit(0);			/* %% */
 }
 
diff -Naur util-linux-2.12m/login-utils/Makefile util-linux-2.12m.port/login-utils/Makefile
--- util-linux-2.12m/login-utils/Makefile	2004-11-23 17:06:57.000000000 +0100
+++ util-linux-2.12m.port/login-utils/Makefile	2004-12-22 12:43:06.000000000 +0100
@@ -18,8 +18,10 @@
 
 MAN8.GETTY=	agetty.8
 
-MAN8.INIT=	fastboot.8 fasthalt.8 halt.8 reboot.8 simpleinit.8 shutdown.8 \
-		initctl.8
+MAN8.INIT=	simpleinit.8 initctl.8
+ifeq "$(KERNEL)" "linux"
+MAN8.INIT:=	$(MAN8.INIT) fastboot.8 fasthalt.8 halt.8 reboot.8 shutdown.8
+endif
 
 MAN8.PUTILS=	vipw.8 vigr.8
 
@@ -28,7 +30,10 @@
 
 SBIN.GETTY=	agetty
 
-SBIN.INIT=	simpleinit shutdown initctl
+SBIN.INIT=	simpleinit initctl
+ifeq "$(KERNEL)" "linux"
+SBIN.INIT:=	$(SBIN.INIT) shutdown
+endif
 
 BIN.PUTILS=	login
 
@@ -97,21 +102,22 @@
 initctl.o simpleinit.o: simpleinit.h
 agetty.o islocal.o last.o setpwnam.o shutdown.o simpleinit.o \
 	vipw.o: $(LIB)/pathnames.h
-shutdown.o simpleinit.o: $(LIB)/linux_reboot.h
+shutdown.o simpleinit.o: $(LIB)/my_reboot.h
 wall.o: ttymsg.h $(LIB)/carefulputc.h
 
-agetty: agetty.o $(LIB)/xstrncpy.o
+agetty: agetty.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o
 chfn: chfn.o islocal.o setpwnam.o $(SELINUXOBJS) $(LIB)/env.o $(LIB)/xstrncpy.o
 	$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM) $(SELINUXLLIB)
 chsh: chsh.o islocal.o setpwnam.o $(SELINUXOBJS) $(LIB)/env.o
 	$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM) $(SELINUXLLIB)
-last: last.o
+last: last.o $(LIB)/xgethostname.o
 
 ifeq "$(HAVE_PAM)" "yes"
-login: login.o $(LIB)/setproctitle.o $(LIB)/xstrncpy.o
+login: login.o $(LIB)/setproctitle.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o
 	$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM) $(SELINUXLLIB)
 else
-login: login.o $(LIB)/xstrncpy.o $(LIB)/setproctitle.o checktty.o 
+login: login.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o $(LIB)/setproctitle.o \
+		checktty.o
 	$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(SELINUXLLIB)
 endif
 
@@ -134,20 +140,24 @@
 newgrp.o: $(LIB)/pathnames.h
 	$(CC) -c $(CFLAGS) $(PAMFL) newgrp.c 
 
-wall: wall.o ttymsg.o $(LIB)/carefulputc.o $(LIB)/xstrncpy.o
+wall: wall.o ttymsg.o $(LIB)/carefulputc.o $(LIB)/xstrncpy.o \
+		$(LIB)/xgethostname.o
 
 LOGINFLAGS=
 ifeq "$(USE_TTY_GROUP)" "yes"
 	LOGINFLAGS += -DUSE_TTY_GROUP
 endif
+ifeq "$(KERNEL)" "linux"
 ifeq "$(ALLOW_VCS_USE)" "yes"
 	LOGINFLAGS += -DCHOWNVCS
 endif
+endif
 ifeq "$(DO_STAT_MAIL)" "yes"
 	LOGINFLAGS += -DDO_STAT_MAIL
 endif
 
-login.o: login.c $(LIB)/pathnames.h $(LIB)/setproctitle.c $(LIB)/setproctitle.h
+login.o: login.c $(LIB)/pathnames.h $(LIB)/setproctitle.c \
+		$(LIB)/setproctitle.h $(LIB)/xgethostname.h
 	$(CC) -c $(CFLAGS) $(PAMFL) $(LOGINFLAGS) login.c
 
 # LOGINFLAGS here only for -DUSE_TTY_GROUP
@@ -195,10 +205,12 @@
 	$(INSTALLDIR) $(MAN8DIR)
 	$(INSTALLMAN) $(MAN8.INIT) $(MAN8DIR)
 	# Make *relative* links for these
+ifeq "$(KERNEL)" "linux"
 	(cd $(SHUTDOWNDIR); ln -sf shutdown reboot)
 	(cd $(SHUTDOWNDIR); ln -sf shutdown fastboot)
 	(cd $(SHUTDOWNDIR); ln -sf shutdown halt)
 	(cd $(SHUTDOWNDIR); ln -sf shutdown fasthalt)
+endif
 	(cd $(SHUTDOWNDIR); ln -sf initctl need)
 	(cd $(SHUTDOWNDIR); ln -sf initctl display-services)
 	(cd $(SHUTDOWNDIR); ln -sf initctl provide)
diff -Naur util-linux-2.12m/login-utils/shutdown.c util-linux-2.12m.port/login-utils/shutdown.c
--- util-linux-2.12m/login-utils/shutdown.c	2004-09-17 00:38:16.000000000 +0200
+++ util-linux-2.12m.port/login-utils/shutdown.c	2004-12-22 11:19:34.000000000 +0100
@@ -72,7 +72,7 @@
 #include <dirent.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
-#include "linux_reboot.h"
+#include "my_reboot.h"
 #include "pathnames.h"
 #include "xstrncpy.h"
 #include "nls.h"
@@ -425,13 +425,13 @@
 	syncwait (1);
 
 	if(opt_reboot) {
-		my_reboot(LINUX_REBOOT_CMD_RESTART); /* RB_AUTOBOOT */
+		my_reboot(MY_REBOOT_CMD_RESTART); /* RB_AUTOBOOT */
 		my_puts(_("\nWhy am I still alive after reboot?"));
 	} else {
 		my_puts(_("\nNow you can turn off the power..."));
 
 		/* allow C-A-D now, faith@cs.unc.edu, re-fixed 8-Jul-96 */
-		my_reboot(LINUX_REBOOT_CMD_CAD_ON); /* RB_ENABLE_CAD */
+		my_reboot(MY_REBOOT_CMD_CAD_ON); /* RB_ENABLE_CAD */
 		sleep (1);  /*  Wait for devices to finish writing to media  */
 		do_halt(halt_action);
 	}
@@ -446,7 +446,7 @@
 	if (strcasecmp (action, "power_off") == 0) {
 		printf(_("Calling kernel power-off facility...\n"));
 		fflush(stdout);
-		my_reboot(LINUX_REBOOT_CMD_POWER_OFF);
+		my_reboot(MY_REBOOT_CMD_POWER_OFF);
 		printf(_("Error powering off\t%s\n"), ERRSTRING);
 		fflush(stdout);
 		sleep (2);
@@ -463,7 +463,7 @@
 		sleep (2);
 	}
 
-	my_reboot(LINUX_REBOOT_CMD_HALT); /* RB_HALT_SYSTEM */
+	my_reboot(MY_REBOOT_CMD_HALT); /* RB_HALT_SYSTEM */
 }
 
 void
diff -Naur util-linux-2.12m/login-utils/simpleinit.c util-linux-2.12m.port/login-utils/simpleinit.c
--- util-linux-2.12m/login-utils/simpleinit.c	2004-12-15 21:23:25.000000000 +0100
+++ util-linux-2.12m.port/login-utils/simpleinit.c	2004-12-22 11:19:34.000000000 +0100
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <fcntl.h>
+#include <time.h>
 #include <string.h>
 #include <signal.h>
 #include <errno.h>
@@ -44,7 +45,7 @@
 #endif
 #include "my_crypt.h"
 #include "pathnames.h"
-#include "linux_reboot.h"
+#include "my_reboot.h"
 #include "xstrncpy.h"
 #include "nls.h"
 #include "simpleinit.h"
@@ -171,7 +172,7 @@
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	my_reboot (LINUX_REBOOT_CMD_CAD_OFF);
+	my_reboot (MY_REBOOT_CMD_CAD_OFF);
 	/*  Find script to run. Command-line overrides config file overrides
 	    built-in default  */
 	for (i = 0; i < NUMCMD; i++) inittab[i].pid = -1;
@@ -707,7 +708,7 @@
 	execl (_PATH_REBOOT, _PATH_REBOOT, (char *) 0);
 
     /* fork or exec failed, try the hard way... */
-    my_reboot (LINUX_REBOOT_CMD_RESTART);
+    my_reboot (MY_REBOOT_CMD_RESTART);
 }   /*  End Function sigint_handler  */
 
 static void sigchild_handler (int sig)
diff -Naur util-linux-2.12m/login-utils/simpleinit.h util-linux-2.12m.port/login-utils/simpleinit.h
--- util-linux-2.12m/login-utils/simpleinit.h	2000-11-05 13:41:35.000000000 +0100
+++ util-linux-2.12m.port/login-utils/simpleinit.h	2004-12-22 11:19:34.000000000 +0100
@@ -3,7 +3,7 @@
 
 
 #define ERRSTRING strerror (errno)
-#define COMMAND_SIZE  (PIPE_BUF - 4)
+#define COMMAND_SIZE  (_POSIX_PIPE_BUF - 4)
 
 
 #define COMMAND_TEST       0  /*  No wait, signal                            */
diff -Naur util-linux-2.12m/login-utils/wall.c util-linux-2.12m.port/login-utils/wall.c
--- util-linux-2.12m/login-utils/wall.c	2002-03-09 00:00:19.000000000 +0100
+++ util-linux-2.12m.port/login-utils/wall.c	2004-12-22 11:19:34.000000000 +0100
@@ -58,6 +58,7 @@
 #include <utmp.h>
 
 #include "nls.h"
+#include "xgethostname.h"
 #include "xstrncpy.h"
 #include "ttymsg.h"
 #include "pathnames.h"
@@ -150,8 +151,7 @@
 	time_t now;
 	FILE *fp;
 	int fd;
-	char *p, *whom, *where, hostname[MAXHOSTNAMELEN],
-		lbuf[MAXHOSTNAMELEN + 320],
+	char *p, *whom, *where, *hostname, lbuf[1024],
 		tmpname[sizeof(_PATH_TMP) + 20];
 
 	(void)sprintf(tmpname, "%s/wall.XXXXXX", _PATH_TMP);
@@ -162,6 +162,9 @@
 	(void)unlink(tmpname);
 
 	if (!nobanner) {
+		char *mesg, *mesg_notice;
+		int mesg_size, size;
+
 		if (!(whom = getlogin()) || !*whom)
 			whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
 		if (!whom || strlen(whom) > 100)
@@ -169,7 +172,11 @@
 		where = ttyname(2);
 		if (!where || strlen(where) > 100)
 			where = "somewhere";
-		(void)gethostname(hostname, sizeof(hostname));
+		if (!(hostname = xgethostname())) {
+			(void)fprintf(stderr, _("%s: can't get hostname.\n"),
+				progname);
+			exit(1);
+		}
 		(void)time(&now);
 		lt = localtime(&now);
 
@@ -182,13 +189,35 @@
 		 */
 		/* snprintf is not always available, but the sprintf's here
 		   will not overflow as long as %d takes at most 100 chars */
+
+		mesg_notice = _("Broadcast Message from %s@%s");
+		mesg_size = strlen(whom) + strlen(hostname) +
+			strlen(mesg_notice);
+		if (!(mesg = malloc(mesg_size))) {
+			(void)fprintf(stderr, _("%s: Out of memory!\n"),
+				progname);
+			exit(1);
+		}
+
 		(void)fprintf(fp, "\r%79s\r\n", " ");
-		(void)sprintf(lbuf, _("Broadcast Message from %s@%s"),
-			      whom, hostname);
-		(void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf);
-		(void)sprintf(lbuf, "        (%s) at %d:%02d ...",
-			      where, lt->tm_hour, lt->tm_min);
-		(void)fprintf(fp, "%-79.79s\r\n", lbuf);
+		(void)sprintf(mesg, mesg_notice, whom, hostname);
+		(void)fprintf(fp, "%-79.79s\007\007\r\n", mesg);
+
+		mesg_notice = "        (%s) at %d:%02d ...";
+		size = strlen(mesg_notice) + strlen(where);
+		if (mesg_size < size) {
+			if (!realloc(mesg, size)) {
+				(void)fprintf(stderr, _("%s: Out of memory!\n"),
+					progname);
+				exit(1);
+			}
+		}
+
+		(void)sprintf(mesg, mesg_notice, where,
+			lt->tm_hour, lt->tm_min);
+		(void)fprintf(fp, "%-79.79s\r\n", mesg);
+
+		free(mesg);
 	}
 	(void)fprintf(fp, "%79s\r\n", " ");
 
diff -Naur util-linux-2.12m/MCONFIG util-linux-2.12m.port/MCONFIG
--- util-linux-2.12m/MCONFIG	2004-12-13 00:15:48.000000000 +0100
+++ util-linux-2.12m.port/MCONFIG	2004-12-22 12:41:35.000000000 +0100
@@ -17,7 +17,8 @@
 # Select for CPU i386 if the binaries must be able to run on an intel 386
 # (by default i486 code is generated, see below)
 CPU=$(shell uname -m)
-ARCH=$(shell echo $(CPU) | sed 's/i.86/intel/;s/arm.*/arm/')
+ARCH=$(shell echo $(CPU) | sed 's/i.86.*/intel/;s/arm.*/arm/')
+KERNEL=$(shell uname -s | tr '[:upper:]' '[:lower:]')
 
 # If HAVE_PAM is set to "yes", then login, chfn, chsh, and newgrp
 # will use PAM for authentication. Additionally, passwd will not be
diff -Naur util-linux-2.12m/misc-utils/Makefile util-linux-2.12m.port/misc-utils/Makefile
--- util-linux-2.12m/misc-utils/Makefile	2004-12-05 20:09:12.000000000 +0100
+++ util-linux-2.12m.port/misc-utils/Makefile	2004-12-22 11:19:34.000000000 +0100
@@ -96,8 +96,8 @@
 mcookie.o: mcookie.c $(LIB)/md5.h
 reset: reset.sh
 script: script.o
-write.o: $(LIB)/carefulputc.h
-write: write.o $(LIB)/carefulputc.o
+write.o: $(LIB)/carefulputc.h $(LIB)/xgethostname.h
+write: write.o $(LIB)/carefulputc.o $(LIB)/xgethostname.o
 
 ifeq "$(HAVE_NCURSES)" "yes"
 setterm: setterm.o
diff -Naur util-linux-2.12m/misc-utils/mcookie.c util-linux-2.12m.port/misc-utils/mcookie.c
--- util-linux-2.12m/misc-utils/mcookie.c	2002-03-09 00:00:52.000000000 +0100
+++ util-linux-2.12m.port/misc-utils/mcookie.c	2004-12-22 11:19:34.000000000 +0100
@@ -20,18 +20,16 @@
  *
  */
 
-#ifdef __linux__
-#define HAVE_GETTIMEOFDAY 1
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include "md5.h"
-#if HAVE_GETTIMEOFDAY
+#include "../defines.h"
+#ifdef HAVE_gettimeofday
 #include <sys/time.h>
-#include <unistd.h>
 #endif
+#include <time.h>
+#include <unistd.h>
 #include "nls.h"
 
 #define BUFFERSIZE 4096
@@ -79,7 +77,7 @@
    pid_t             pid;
    char              *file = NULL;
    int               r;
-#if HAVE_GETTIMEOFDAY
+#ifdef HAVE_gettimeofday
    struct timeval    tv;
    struct timezone   tz;
 #else
@@ -98,7 +96,7 @@
 
    MD5Init( &ctx );
    
-#if HAVE_GETTIMEOFDAY
+#ifdef HAVE_gettimeofday
    gettimeofday( &tv, &tz );
    MD5Update( &ctx, (unsigned char *)&tv, sizeof( tv ) );
 #else
diff -Naur util-linux-2.12m/misc-utils/namei.c util-linux-2.12m.port/misc-utils/namei.c
--- util-linux-2.12m/misc-utils/namei.c	2004-09-06 23:06:47.000000000 +0200
+++ util-linux-2.12m.port/misc-utils/namei.c	2004-12-22 11:19:34.000000000 +0100
@@ -73,7 +73,8 @@
 main(int argc, char **argv) {
     extern int optind;
     int c;
-    char curdir[MAXPATHLEN];
+    int curdir_size;
+    char *curdir;
 
     setlocale(LC_ALL, "");
     bindtextdomain(PACKAGE, LOCALEDIR);
@@ -98,13 +99,28 @@
 	}
     }
 
-    if(getcwd(curdir, sizeof(curdir)) == NULL){
-	(void)fprintf(stderr,
-		      _("namei: unable to get current directory - %s\n"),
-		      curdir);
+    curdir_size = 1024;
+    curdir = malloc(curdir_size);
+    if (curdir==NULL){
+	(void)fprintf(stderr, _("namei: out of memory\n"));
 	exit(1);
     }
 
+    while (getcwd(curdir, curdir_size) == NULL){
+	if (errno!=ERANGE){
+	    (void)fprintf(stderr,
+			  _("namei: unable to get current directory - %s\n"),
+			  curdir);
+	    exit(1);
+	}
+	curdir_size *= 2;
+	realloc(curdir, curdir_size);
+	if (curdir==NULL){
+	    (void)fprintf(stderr, _("namei: out of memory\n"));
+	    exit(1);
+	}
+    }
+
 
     for(; optind < argc; optind++){
 	(void)printf("f: %s\n", argv[optind]);
diff -Naur util-linux-2.12m/misc-utils/script.c util-linux-2.12m.port/misc-utils/script.c
--- util-linux-2.12m/misc-utils/script.c	2004-03-26 18:07:16.000000000 +0100
+++ util-linux-2.12m.port/misc-utils/script.c	2004-12-22 11:19:34.000000000 +0100
@@ -54,10 +54,8 @@
 #include <sys/signal.h>
 #include "nls.h"
 
-#ifdef __linux__
 #include <unistd.h>
 #include <string.h>
-#endif
 
 #include "../defines.h"
 #ifdef HAVE_openpty
diff -Naur util-linux-2.12m/misc-utils/setterm.c util-linux-2.12m.port/misc-utils/setterm.c
--- util-linux-2.12m/misc-utils/setterm.c	2003-10-17 18:17:51.000000000 +0200
+++ util-linux-2.12m.port/misc-utils/setterm.c	2004-12-22 11:19:34.000000000 +0100
@@ -107,16 +107,14 @@
 #else
 #include <curses.h>
 #endif
+#ifdef __linux__
 #include <sys/param.h>		/* for MAXPATHLEN */
+#endif
 #include <sys/ioctl.h>
 #include <sys/time.h>
 #include "nls.h"
 
-#ifndef TCGETS
-/* TCGETS is either defined in termios.h, or here: */
-#include <asm/ioctls.h>
-#endif
-
+#ifdef __linux__
 #if __GNU_LIBRARY__ < 5
 #ifndef __alpha__
 # include <linux/unistd.h>
@@ -127,6 +125,7 @@
 #endif
 #endif
 extern int klogctl(int type, char *buf, int len);
+#endif /* __linux__ */
 
 /* Constants. */
 
@@ -165,19 +164,24 @@
 int opt_term, opt_reset, opt_initialize, opt_cursor;
 int opt_linewrap, opt_snow, opt_softscroll, opt_default, opt_foreground;
 int opt_background, opt_bold, opt_blink, opt_reverse, opt_underline;
-int opt_store, opt_clear, opt_blank, opt_snap, opt_snapfile, opt_standout;
-int opt_append, opt_ulcolor, opt_hbcolor, opt_halfbright, opt_repeat;
+int opt_store, opt_clear, opt_blank, opt_standout;
+int opt_ulcolor, opt_hbcolor, opt_halfbright, opt_repeat;
 int opt_tabs, opt_clrtabs, opt_regtabs, opt_appcursorkeys, opt_inversescreen;
-int opt_msg, opt_msglevel, opt_powersave, opt_powerdown;
+int opt_powerdown;
 int opt_blength, opt_bfreq;
+#ifdef __linux__
+int opt_append, opt_snap, opt_snapfile;
+int opt_powersave;
+int opt_msg, opt_msglevel;
+#endif /* __linux__ */
 
 /* Option controls.  The variable names have been contracted to ensure
  * uniqueness.
  */
 char *opt_te_terminal_name;	/* Terminal name. */
-int opt_cu_on, opt_li_on, opt_sn_on, opt_so_on, opt_bo_on, opt_hb_on, opt_bl_on;
-int opt_re_on, opt_un_on, opt_rep_on, opt_appck_on, opt_invsc_on;
-int opt_msg_on;			/* Boolean switches. */
+int opt_cu_on, opt_li_on, opt_sn_on, opt_so_on, opt_bo_on, opt_hb_on;
+int opt_bl_on, opt_re_on, opt_un_on, opt_rep_on, opt_appck_on;
+int opt_invsc_on;		/* Boolean switches. */
 int opt_ke_type;		/* Keyboard type. */
 int opt_fo_color, opt_ba_color;	/* Colors. */
 int opt_ul_color, opt_hb_color;
@@ -185,16 +189,20 @@
 int opt_bl_min;			/* Blank screen. */
 int opt_blength_l;
 int opt_bfreq_f;
-int opt_sn_num;			/* Snap screen. */
 int opt_st_attr;
 int opt_rt_len;			/* regular tab length */
 int opt_tb_array[161];		/* Array for tab list */
-int opt_msglevel_num;
 int opt_ps_mode, opt_pd_min;	/* powersave mode/powerdown time */
 
+#ifdef __linux__
+int opt_msg_on;
+int opt_msglevel_num;
+
+int opt_sn_num;			/* Snap screen. */
 char opt_sn_name[200] = "screen.dump";
 
 static void screendump(int vcnum, FILE *F);
+#endif /* __linux__ */
 
 /* Command line parsing routines.
  *
@@ -402,6 +410,7 @@
 	}
 }
 
+#ifdef __linux__
 static void
 parse_powersave(int argc, char **argv, int *option, int *opt_mode, int *bad_arg) {
 	/* argc: Number of arguments for this option. */
@@ -432,6 +441,7 @@
 		*opt_mode = 0;
 	}
 }
+#endif /* __linux__ */
 
 #if 0
 static void
@@ -454,6 +464,7 @@
 }
 #endif
 
+#ifdef __linux__
 static void
 parse_msglevel(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {
 	/* argc: Number of arguments for this option. */
@@ -512,6 +523,7 @@
 	if (argc == 1)
 		strcpy((char *)opt_all, argv[0]);
 }
+#endif /* __linux__ */
 
 static void
 parse_tabs(int argc, char **argv, int *option, int *tab_array, int *bad_arg) {
@@ -709,6 +721,7 @@
 		parse_regtabs(argc, argv, &opt_regtabs, &opt_rt_len, bad_arg);
 	else if (STRCMP(option, "blank") == 0)
 		parse_blank(argc, argv, &opt_blank, &opt_bl_min, bad_arg);
+#ifdef __linux__
 	else if (STRCMP(option, "dump") == 0)
 		parse_snap(argc, argv, &opt_snap, &opt_sn_num, bad_arg);
 	else if (STRCMP(option, "append") == 0)
@@ -721,6 +734,7 @@
 		parse_msglevel(argc, argv, &opt_msglevel, &opt_msglevel_num, bad_arg);
 	else if (STRCMP(option, "powersave") == 0)
 		parse_powersave(argc, argv, &opt_powersave, &opt_ps_mode, bad_arg);
+#endif /* __linux__ */
 	else if (STRCMP(option, "powerdown") == 0)
 		parse_blank(argc, argv, &opt_powerdown, &opt_pd_min, bad_arg);
 	else if (STRCMP(option, "blength") == 0)
@@ -783,12 +797,14 @@
 	fprintf(stderr, _("  [ -clrtabs [ tab1 tab2 tab3 ... ] ]   (tabn = 1-160)\n"));
 	fprintf(stderr, _("  [ -regtabs [1-160] ]\n"));
 	fprintf(stderr, _("  [ -blank [0-60] ]\n"));
+#ifdef __linux__
 	fprintf(stderr, _("  [ -dump   [1-NR_CONSOLES] ]\n"));
 	fprintf(stderr, _("  [ -append [1-NR_CONSOLES] ]\n"));
 	fprintf(stderr, _("  [ -file dumpfilename ]\n"));
 	fprintf(stderr, _("  [ -msg [on|off] ]\n"));
 	fprintf(stderr, _("  [ -msglevel [0-8] ]\n"));
 	fprintf(stderr, _("  [ -powersave [on|vsync|hsync|powerdown|off] ]\n"));
+#endif /* __linux__ */
 	fprintf(stderr, _("  [ -powerdown [0-60] ]\n"));
 	fprintf(stderr, _("  [ -blength [0-2000] ]\n"));
 	fprintf(stderr, _("  [ -bfreq freqnumber ]\n"));
@@ -811,8 +827,9 @@
 static void
 perform_sequence(int vcterm) {
 	/* vcterm: Set if terminal is a virtual console. */
-
+#ifdef __linux__
 	int result;
+#endif
 /* Perform the selected options. */
 
 	/* -reset. */
@@ -1040,6 +1057,7 @@
 	if (opt_blank && vcterm) 
 		printf("\033[9;%d]", opt_bl_min);
     
+#ifdef __linux__
 	/* -powersave [on|vsync|hsync|powerdown|off] (console) */
 	if (opt_powersave) {
 		char ioctlarg[2];
@@ -1048,6 +1066,7 @@
 		if (ioctl(0,TIOCLINUX,ioctlarg))
 			fprintf(stderr,_("cannot (un)set powersave mode\n"));
 	}
+#endif /* __linux__ */
 
 	/* -powerdown [0-60]. */
 	if (opt_powerdown) {
@@ -1060,6 +1079,7 @@
 		/* nothing */;
 #endif
 
+#ifdef __linux__
 	/* -snap [1-NR_CONS]. */
 	if (opt_snap || opt_append) {
 		FILE *F;
@@ -1095,6 +1115,7 @@
 		if (result != 0)
 			printf(_("klogctl error: %s\n"), strerror(errno));
 	}
+#endif /* __linux__ */
 
 	/* -blength [0-2000] */
 	if (opt_blength && vcterm) {
@@ -1108,6 +1129,7 @@
 
 }
 
+#ifdef __linux__
 static void
 screendump(int vcnum, FILE *F) {
     char infile[MAXPATHLEN];
@@ -1193,6 +1215,7 @@
 	}
     }
 }
+#endif /* __linux__ */
 
 int
 main(int argc, char **argv) {
diff -Naur util-linux-2.12m/misc-utils/write.c util-linux-2.12m.port/misc-utils/write.c
--- util-linux-2.12m/misc-utils/write.c	2001-03-15 11:09:58.000000000 +0100
+++ util-linux-2.12m.port/misc-utils/write.c	2004-12-22 11:19:34.000000000 +0100
@@ -64,9 +64,10 @@
 #include <paths.h>
 #include "pathnames.h"
 #include "carefulputc.h"
+#include "xgethostname.h"
 #include "nls.h"
  
-void search_utmp(char *, char *, char *, uid_t);
+void search_utmp(char *, char **, char *, uid_t);
 void do_write(char *, char *, uid_t);
 void wr_fputs(char *);
 static void done(int);
@@ -78,7 +79,7 @@
 	time_t atime;
 	uid_t myuid;
 	int msgsok, myttyfd;
-	char tty[MAXPATHLEN], *mytty;
+	char *tty, *mytty;
 
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
@@ -120,7 +121,7 @@
 	/* check args */
 	switch (argc) {
 	case 2:
-		search_utmp(argv[1], tty, mytty, myuid);
+		search_utmp(argv[1], &tty, mytty, myuid);
 		do_write(tty, mytty, myuid);
 		break;
 	case 3:
@@ -189,8 +190,10 @@
  *
  * Special case for writing to yourself - ignore the terminal you're
  * writing from, unless that's the only terminal with messages enabled.
+ *
+ * Returns tty as an allocated string.
  */
-void search_utmp(char *user, char *tty, char *mytty, uid_t myuid)
+void search_utmp(char *user, char **tty, char *mytty, uid_t myuid)
 
 {
 	struct utmp u;
@@ -224,7 +227,11 @@
 			++nttys;
 			if (atime > bestatime) {
 				bestatime = atime;
-				(void)strcpy(tty, atty);
+				if ((*tty = strdup(atty)) == NULL) {
+					(void)fprintf(stderr,
+						_("write: out of memory\n"));
+					exit(1);
+				}
 			}
 		}
 	}
@@ -236,7 +243,12 @@
 	}
 	if (nttys == 0) {
 		if (user_is_me) {		/* ok, so write to yourself! */
-			(void)strcpy(tty, mytty);
+			if ((*tty = strdup(mytty)) == NULL) {
+				(void)fprintf(stderr,
+					_("write: out of memory\n"));
+				exit(1);
+			}
+
 			return;
 		}
 		(void)fprintf(stderr,
@@ -245,7 +257,7 @@
 	} else if (nttys > 1) {
 		(void)fprintf(stderr,
 		    _("write: %s is logged in more than once; writing to %s\n"),
-		    user, tty);
+		    user, *tty);
 	}
 }
 
@@ -257,19 +269,23 @@
 
 {
 	struct stat s;
-	char path[MAXPATHLEN];
+	char *path;
 
-	if (strlen(tty) + 6 > sizeof(path))
-		return(1);
+	if ((path = malloc(strlen(tty) + sizeof("/dev/") + 1)) == NULL){
+		(void)fprintf(stderr,_("write: out of memory\n"));
+		exit(1);
+	}
 	(void)sprintf(path, "/dev/%s", tty);
 	if (stat(path, &s) < 0) {
 		if (showerror)
 			(void)fprintf(stderr,
 			    "write: %s: %s\n", path, strerror(errno));
+		free(path);
 		return(1);
 	}
 	*msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0;	/* group write bit */
 	*atimeP = s.st_atime;
+	free(path);
 	return(0);
 }
 
@@ -280,7 +296,7 @@
 	char *login, *pwuid, *nows;
 	struct passwd *pwd;
 	time_t now;
-	char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512];
+	char *path, *host, *host_tmp, line[512];
 
 	/* Determine our login name(s) before the we reopen() stdout */
 	if ((pwd = getpwuid(myuid)) != NULL)
@@ -290,8 +306,10 @@
 	if ((login = getlogin()) == NULL)
 		login = pwuid;
 
-	if (strlen(tty) + 6 > sizeof(path))
+	if ((path = malloc(strlen(tty) + sizeof("/dev/") + 1)) == NULL) {
+		(void)fprintf(stderr, _("write: out of memory\n"));
 		exit(1);
+	}
 	(void)sprintf(path, "/dev/%s", tty);
 	if ((freopen(path, "w", stdout)) == NULL) {
 		(void)fprintf(stderr, "write: %s: %s\n",
@@ -299,12 +317,16 @@
 		exit(1);
 	}
 
+	free(path);
+
 	(void)signal(SIGINT, done);
 	(void)signal(SIGHUP, done);
 
 	/* print greeting */
-	if (gethostname(host, sizeof(host)) < 0)
-		(void)strcpy(host, "???");
+	if ((host_tmp = xgethostname()) != NULL)
+		host = host_tmp;
+	else
+		host = "???";
 	now = time((time_t *)NULL);
 	nows = ctime(&now);
 	nows[16] = '\0';
@@ -317,6 +339,8 @@
 			     login, host, mytty, nows + 11);
 	printf("\r\n");
 
+	free(host_tmp);
+
 	while (fgets(line, sizeof(line), stdin) != NULL)
 		wr_fputs(line);
 }
diff -Naur util-linux-2.12m/mount/linux_fs.h util-linux-2.12m.port/mount/linux_fs.h
--- util-linux-2.12m/mount/linux_fs.h	2004-09-16 19:01:11.000000000 +0200
+++ util-linux-2.12m.port/mount/linux_fs.h	2004-12-22 11:19:34.000000000 +0100
@@ -3,16 +3,6 @@
    only designed to be able to check a magic number
    in case no filesystem type was given. */
 
-#ifndef BLKGETSIZE
-#ifndef _IO
-/* pre-1.3.45 */
-#define BLKGETSIZE 0x1260		   /* return device size */
-#else
-/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */
-#define BLKGETSIZE _IO(0x12,96)
-#endif
-#endif
-
 #define MINIX_SUPER_MAGIC   0x137F         /* minix v1, 14 char names */
 #define MINIX_SUPER_MAGIC2  0x138F         /* minix v1, 30 char names */
 #define MINIX2_SUPER_MAGIC  0x2468	   /* minix v2, 14 char names */
diff -Naur util-linux-2.12m/mount/Makefile util-linux-2.12m.port/mount/Makefile
--- util-linux-2.12m/mount/Makefile	2004-08-25 02:31:37.000000000 +0200
+++ util-linux-2.12m.port/mount/Makefile	2004-12-22 12:43:31.000000000 +0100
@@ -10,10 +10,12 @@
 COMPILE = $(CC) -c $(CFLAGS) $(DEFINES)
 LINK = $(CC) $(LDFLAGS)
 
+ifeq "$(KERNEL)" "linux"
 SUID_PROGS = mount umount
 NOSUID_PROGS = swapon losetup
 MAN5 = fstab.5 nfs.5
 MAN8 = mount.8 swapoff.8 swapon.8 umount.8 losetup.8
+endif
 
 ifeq "$(HAVE_PIVOT_ROOT)" "yes"
 NOSUID_PROGS := $(NOSUID_PROGS) pivot_root
@@ -49,7 +51,8 @@
 
 mount: mount.o fstab.o sundries.o realpath.o mntent.o version.o \
        get_label_uuid.o mount_by_label.o mount_blkid.o mount_guess_fstype.o \
-       getusername.o $(LIB)/setproctitle.o $(LIB)/env.o $(NFS_OBJS) $(LO_OBJS)
+       getusername.o $(LIB)/setproctitle.o $(LIB)/env.o $(LIB)/disk_size.o \
+       $(NFS_OBJS) $(LO_OBJS)
 	$(LINK) $^ -o $@ $(BLKID_LIB)
 
 umount: umount.o fstab.o sundries.o realpath.o mntent.o getusername.o \
diff -Naur util-linux-2.12m/mount/mount.c util-linux-2.12m.port/mount/mount.c
--- util-linux-2.12m/mount/mount.c	2004-12-19 23:51:00.000000000 +0100
+++ util-linux-2.12m.port/mount/mount.c	2004-12-22 11:30:31.000000000 +0100
@@ -28,7 +28,7 @@
 #include "fstab.h"
 #include "lomount.h"
 #include "loop.h"
-#include "linux_fs.h"		/* for BLKGETSIZE */
+#include "disk_size.h"
 #include "mount_guess_rootdev.h"
 #include "mount_guess_fstype.h"
 #include "mount_by_label.h"
@@ -968,21 +968,21 @@
 
 	if (stat(spec, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)
 	   && (fd = open(spec, O_RDONLY | O_NONBLOCK)) >= 0) {
-	  if (ioctl(fd, BLKGETSIZE, &size) == 0) {
-	    if (size == 0 && !loop) {
-	      warned++;
-	      error(_(
+	  size = disk_get_sectors(fd);
+	  if (size == 0 && !loop) {
+	    warned++;
+	    error(_(
 		 "       (could this be the IDE device where you in fact use\n"
 		 "       ide-scsi so that sr0 or sda or so is needed?)"));
-	    }
-	    if (size && size <= 2) {
-	      warned++;
-	      error(_(
+	  }
+	  if (size && size <= 2) {
+	    warned++;
+	    error(_(
 		  "       (aren't you trying to mount an extended partition,\n"
 		  "       instead of some logical partition inside?)"));
-	    }
-	  close(fd);
 	  }
+	  close(fd);
+	}
 #if 0
 	  /* 0xf for SCSI, 0x3f for IDE. One might check /proc/partitions
 	     to see whether this thing really is partitioned.
diff -Naur util-linux-2.12m/sys-utils/ctrlaltdel.c util-linux-2.12m.port/sys-utils/ctrlaltdel.c
--- util-linux-2.12m/sys-utils/ctrlaltdel.c	2001-03-15 11:09:59.000000000 +0100
+++ util-linux-2.12m.port/sys-utils/ctrlaltdel.c	2004-12-22 11:19:34.000000000 +0100
@@ -11,7 +11,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
-#include "linux_reboot.h"
+#include "my_reboot.h"
 #include "nls.h"
 
 int
@@ -29,12 +29,12 @@
 	}
 
 	if(argc == 2 && !strcmp("hard", argv[1])) {
-		if(my_reboot(LINUX_REBOOT_CMD_CAD_ON) < 0) {
+		if(my_reboot(MY_REBOOT_CMD_CAD_ON) < 0) {
 			perror("ctrlaltdel: reboot");
 			exit(1);
 		}
 	} else if(argc == 2 && !strcmp("soft", argv[1])) {
-		if(my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0) {
+		if(my_reboot(MY_REBOOT_CMD_CAD_OFF) < 0) {
 			perror("ctrlaltdel: reboot");
 			exit(1);
 		}
diff -Naur util-linux-2.12m/sys-utils/ipcrm.c util-linux-2.12m.port/sys-utils/ipcrm.c
--- util-linux-2.12m/sys-utils/ipcrm.c	2002-04-24 16:42:54.000000000 +0200
+++ util-linux-2.12m.port/sys-utils/ipcrm.c	2004-12-22 11:19:34.000000000 +0100
@@ -26,7 +26,8 @@
 /* for tolower and isupper */
 #include <ctype.h>
 
-#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
+#if (defined (__GNU_LIBRARY__) || defined (__GLIBC__)) && \
+    !defined(_SEM_SEMUN_UNDEFINED)
 /* union semun is defined by including <sys/sem.h> */
 #else
 /* according to X/OPEN we have to define it ourselves */
diff -Naur util-linux-2.12m/sys-utils/ipcs.c util-linux-2.12m.port/sys-utils/ipcs.c
--- util-linux-2.12m/sys-utils/ipcs.c	2004-03-04 20:28:42.000000000 +0100
+++ util-linux-2.12m.port/sys-utils/ipcs.c	2004-12-22 11:19:34.000000000 +0100
@@ -78,7 +78,8 @@
 /* The last arg of semctl is a union semun, but where is it defined?
    X/OPEN tells us to define it ourselves, but until recently
    Linux include files would also define it. */
-#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
+#if (defined (__GNU_LIBRARY__) || defined (__GLIBC__)) && \
+    !defined(_SEM_SEMUN_UNDEFINED)
 /* union semun is defined by including <sys/sem.h> */
 #else
 /* according to X/OPEN we have to define it ourselves */
@@ -95,7 +96,8 @@
    <linux/ipc.h>, which defines a struct ipc_perm with such fields.
    glibc-1.09 has no support for sysv ipc.
    glibc 2 uses __key, __seq */
-#if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
+#if (defined (__GNU_LIBRARY__) && __GNU_LIBRARY > 1) || \
+    (defined (__GLIBC__) && __GLIBC__ > 1)
 #define KEY __key
 #else
 #define KEY key
diff -Naur util-linux-2.12m/sys-utils/Makefile util-linux-2.12m.port/sys-utils/Makefile
--- util-linux-2.12m/sys-utils/Makefile	2004-11-15 18:47:47.000000000 +0100
+++ util-linux-2.12m.port/sys-utils/Makefile	2004-12-22 12:44:05.000000000 +0100
@@ -8,22 +8,34 @@
 
 # Where to put man pages?
 
-MAN1=		arch.1 flock.1 readprofile.1
+MAN1=		arch.1 flock.1
 
-MAN8= 		ctrlaltdel.8 cytune.8 dmesg.8 \
-		ipcrm.8 ipcs.8 renice.8 \
-		setsid.8 sln.8 tunelp.8
+MAN8=		ipcrm.8 ipcs.8 renice.8 \
+		setsid.8 sln.8
+
+ifeq "$(KERNEL)" "linux"
+MAN1:= $(MAN1) readprofile.1
+MAN8:= $(MAN8) ctrlaltdel.8 cytune.8 dmesg.8 tunelp.8
+endif
 
 # Where to put binaries?
 # See the "install" rule for the links. . .
 
-BIN=            arch dmesg
+BIN=            arch
+
+ifeq "$(KERNEL)" "linux"
+BIN:= $(BIN) dmesg
+endif
+
+USRBIN=		flock ipcrm ipcs renice setsid
 
-USRBIN=		cytune flock ipcrm ipcs renice setsid
+ifeq "$(KERNEL)" "linux"
+USRBIN:= $(USRBIN) cytune
 
 USRSBIN=	readprofile tunelp
 
 SBIN= 		ctrlaltdel
+endif
 
 NOTMADE=
 
@@ -37,7 +49,7 @@
 endif
 endif
 
-ifeq "$(ARCH)" "intel"
+ifeq "$(KERNEL):$(ARCH)" "linux:intel"
 MAN8:=$(MAN8) rdev.8 ramsize.8 rootflags.8 vidmode.8
 USRSBIN:=$(USRSBIN) rdev
 endif
@@ -67,7 +79,7 @@
 # Rules for everything else
 
 arch: arch.o
-ctrlaltdel.o: ctrlaltdel.c $(LIB)/linux_reboot.h
+ctrlaltdel.o: ctrlaltdel.c $(LIB)/my_reboot.h
 ctrlaltdel: ctrlaltdel.o $(LIB)/my_reboot.o
 cytune.o: cytune.c cyclades.h
 cytune: cytune.o
@@ -87,7 +99,7 @@
 	$(INSTALLBIN) $(BIN) $(BINDIR)
 	$(INSTALLBIN) $(USRBIN) $(USRBINDIR)
 	$(INSTALLBIN) $(USRSBIN) $(USRSBINDIR)
-ifeq "$(ARCH)" "intel"
+ifeq "$(KERNEL):$(ARCH)" "linux:intel"
 	(cd $(USRSBINDIR); ln -sf rdev ramsize)
 	(cd $(USRSBINDIR); ln -sf rdev vidmode)
 	(cd $(USRSBINDIR); ln -sf rdev rootflags)
diff -Naur util-linux-2.12m/text-utils/more.c util-linux-2.12m.port/text-utils/more.c
--- util-linux-2.12m/text-utils/more.c	2004-12-05 17:57:57.000000000 +0100
+++ util-linux-2.12m.port/text-utils/more.c	2004-12-22 11:19:34.000000000 +0100
@@ -76,6 +76,14 @@
 
 #define stty(fd,argp)  tcsetattr(fd,TCSANOW,argp)
 
+/* TAB3 and TABDLY are in XPG3 and up */
+#if !defined(TABDLY) && defined(TBDELAY)
+#define TABDLY		TBDELAY
+#endif
+#if !defined(TAB3) && defined(XTABS)
+#define TAB3		XTABS
+#endif
+
 /* some function declarations */
 void initterm(void);
 void kill_line(void);
@@ -1561,7 +1569,7 @@
     }
     if (feof (file)) {
 	if (!no_intty) {
-#ifndef __linux__
+#ifdef STDIO_S_EOF_SEEN
 				/* No longer in libc 4.5.8. . . */
 	    file->_flags &= ~STDIO_S_EOF_SEEN; /* why doesn't fseek do this ??!!??! */
 #endif
@@ -1805,8 +1813,8 @@
     no_intty = tcgetattr(fileno(stdin), &otty);
     tcgetattr(fileno(stderr), &otty);
     savetty0 = otty;
-    slow_tty = (otty.c_cflag & CBAUD) < B1200;
-    hardtabs = (otty.c_oflag & TABDLY) != XTABS;
+    slow_tty = cfgetospeed(&otty) < B1200;
+    hardtabs = (otty.c_oflag & TABDLY) != TAB3;
     if (!no_tty) {
 	otty.c_lflag &= ~(ICANON|ECHO);
 	otty.c_cc[VMIN] = 1;
