Index: trunk/minix/commands/ibm/Makefile
===================================================================
--- trunk/minix/commands/ibm/Makefile	(revision 9)
+++ 	(revision )
@@ -1,183 +1,0 @@
-# Makefile for commands/ibm.
-
-# See commands/simple/Makefile for a description.
-
-CFLAGS	= -D_MINIX -D_POSIX_SOURCE
-CCLD	= $(CC) -i $(CFLAGS)
-MAKE	= exec make -$(MAKEFLAGS)
-CC = exec cc
-
-ALL	= \
-	atnormalize \
-	dosread \
-	fdisk \
-	format \
-	loadfont \
-	loadkeys \
-	mixer \
-	autopart \
-	part \
-	partition \
-	playwave \
-	postmort \
-	readclock \
-	recwave \
-	repartition \
-	screendump \
-	sdump \
-
-all:	$(ALL)
-
-dosread:	dosread.c
-	$(CCLD) -o $@ $?
-	install -S 16kw $@
-
-atnormalize:	atnormalize.c
-	$(CCLD) -o $@ $?
-	install -S 16kw $@
-
-fdisk:	fdisk.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-format:	format.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-loadfont:	loadfont.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-loadkeys:	loadkeys.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-mixer:	mixer.c
-	$(CCLD) -o $@ $? -lcurses
-	install -S 16kw $@
-
-autopart:	autopart.c
-	$(CCLD) -o $@ $?
-	install -S 11kw $@
-
-part:	part.c
-	$(CCLD) -o $@ $?
-	install -S 11kw $@
-
-partition:	partition.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-playwave:	playwave.c
-	$(CCLD) -o $@ $?
-	install -S 16kw $@
-
-postmort:	postmort.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-readclock:	readclock.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-recwave:	recwave.c
-	$(CCLD) -o $@ $?
-	install -S 16kw $@
-
-repartition:	repartition.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-screendump:	screendump.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-sdump:	sdump.c
-	$(CCLD) -o $@ $?
-	install -S 4kw $@
-
-install:	\
-	/usr/bin/atnormalize \
-	/usr/bin/dosread \
-		/usr/bin/dosdir \
-		/usr/bin/doswrite \
-	/usr/bin/fdisk \
-	/usr/bin/format \
-	/usr/bin/loadfont \
-	/usr/bin/loadkeys \
-	/usr/bin/mixer \
-	/usr/bin/autopart \
-	/usr/bin/part \
-	/usr/bin/partition \
-	/usr/bin/playwave \
-	/usr/bin/postmort \
-	/usr/bin/readclock \
-	/usr/bin/recwave \
-	/usr/bin/repartition \
-	/usr/bin/screendump \
-	/usr/bin/sdump \
-	/bin/loadkeys \
-	/bin/readclock \
-
-/usr/bin/atnormalize:	atnormalize
-	install -cs -o bin $? $@
-
-/usr/bin/dosread:	dosread
-	install -cs -o bin $? $@
-
-/usr/bin/dosdir /usr/bin/doswrite:	/usr/bin/dosread
-	install -l $? $@
-
-/usr/bin/fdisk:	fdisk
-	install -cs -o bin $? $@
-
-/usr/bin/format:	format
-	install -cs -o root -m 4755 $? $@
-
-/usr/bin/loadfont:	loadfont
-	install -cs -o bin $? $@
-
-/usr/bin/loadkeys:	loadkeys
-	install -cs -o bin $? $@
-
-/usr/bin/mixer:	mixer
-	install -cs -o bin $? $@
-
-/usr/bin/autopart:	autopart
-	install -lcs $? $@
-
-/usr/bin/part:	part
-	install -cs -o bin $? $@
-
-/usr/bin/partition:	partition
-	install -cs -o bin $? $@
-
-/usr/bin/playwave:	playwave
-	install -cs -o bin $? $@
-
-/usr/bin/postmort:	postmort
-	install -cs -o bin $? $@
-
-/usr/bin/readclock:	readclock
-	install -cs -o bin $? $@
-
-/usr/bin/recwave:	recwave
-	install -cs -o bin $? $@
-
-/usr/bin/repartition:	repartition
-	install -cs -o bin $? $@
-
-/usr/bin/screendump:	screendump
-	install -cs -o bin $? $@
-
-/usr/bin/sdump:	sdump
-	install -cs -o bin $? $@
-
-/bin/loadkeys:	/usr/bin/loadkeys
-	install -lcs $? $@
-
-/bin/readclock:	/usr/bin/readclock
-	install -lcs $? $@
-
-clean:
-	rm -rf $(ALL) a.out core
Index: trunk/minix/commands/ibm/atnormalize.c
===================================================================
--- trunk/minix/commands/ibm/atnormalize.c	(revision 9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-#include <sys/types.h>
-#include <stdio.h>
-#include <termcap.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <time.h>
-#include <dirent.h>
-#include <limits.h>
-#include <a.out.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <termios.h>
-#include <stdarg.h>
-
-int main(void)
-{
-	int v, d;
-	char name[20];
-
-	for(d = 0; d < 4; d++) {
-		int device;
-		sprintf(name, "/dev/c0d%d", d);
-		if((device=open(name, O_RDONLY)) >= 0) {
-			v = 0;
-			ioctl(device, DIOCTIMEOUT, &v);
-			close(device);
-		}
-	}
-
-	return 0;
-}
Index: trunk/minix/commands/ibm/autopart.c
===================================================================
--- trunk/minix/commands/ibm/autopart.c	(revision 9)
+++ 	(revision )
@@ -1,2838 +1,0 @@
-/*	part 1.57 - Partition table editor		Author: Kees J. Bot
- *								13 Mar 1992
- * Needs about 22k heap+stack.
- *
- * Forked july 2005 into autopart (Ben Gras), a mode which gives the user
- * an easier time.
- *
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <termcap.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <time.h>
-#include <dirent.h>
-#include <limits.h>
-#include <a.out.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <termios.h>
-#include <stdarg.h>
-
-/* Declare prototype. */
-static void printstep(int step, char *message);
-
-/* True if a partition is an extended partition. */
-#define ext_part(s)	((s) == 0x05 || (s) == 0x0F)
-
-/* Minix master bootstrap code. */
-static char MASTERBOOT[] = "/usr/mdec/masterboot";
-
-/* Template:
-                      ----first----  --geom/last--  ------sectors-----
-    Device             Cyl Head Sec   Cyl Head Sec      Base      Size        Kb
-    /dev/c0d0                          977    5  17
-    /dev/c0d0:2          0    0   2   976    4  16         2     83043     41521
-Num Sort   Type
- 0* p0   81 MINIX        0    0   3    33    4   9         3      2880      1440
- 1  p1   81 MINIX       33    4  10   178    2   2      2883     12284      6142
- 2  p2   81 MINIX      178    2   3   976    4  16     15167     67878     33939
- 3  p3   00 None         0    0   0     0    0  -1         0         0         0
-
- */
-#define MAXSIZE		999999999L
-#define SECTOR_SIZE	512
-#define DEV_FD0		0x200		/* Device number of /dev/fd0 */
-#define DEV_C0D0	0x300		/* Device number of /dev/c0d0 */
-
-int min_region_mb = 500;
-
-#define MIN_REGION_SECTORS (1024*1024*min_region_mb/SECTOR_SIZE)
-
-#define MAX_REGION_MB	4095
-#define MAX_REGION_SECTORS (1024*(1024/SECTOR_SIZE)*MAX_REGION_MB)
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-#define SORNOT(n) ((n) == 1 ? "" : "s")
-
-/* screen colours */
-#define COL_RED		1
-#define COL_GREEN	2
-#define COL_ORANGE	3
-#define COL_BLUE	4
-#define COL_MAGENTA	5
-#define COL_CYAN	6
-
-#define SURE_SERIOUS	1
-#define SURE_BACK	2
-
-void col(int col)
-{
-	if(!col) printf("\033[0m");
-	else printf("\033[3%dm", col % 10);
-}
-
-void type2col(int type)
-{
-	switch(type) {
-		/* minix */
-		case 0x80:
-		case MINIX_PART:	col(COL_GREEN);	break;
-
-		/* dos/windows */
-		case 0x0B: case 0x0C: case 0x0E: case 0x0F: case 0x42:
-		case 0x07: 		col(COL_CYAN);		break;
-
-		/* linux */
-		case 0x82: case 0x83:	col(COL_ORANGE);	break;
-	}
-}
-
-int open_ct_ok(int fd)
-{
-	int c = -1;
-	if(ioctl(fd, DIOCOPENCT, &c) < 0) {
-		printf("Warning: couldn't verify opencount, continuing\n");
-		return 1;
-	}
-
-	if(c == 1) return 1;
-	if(c < 1) { printf("Error: open count %d\n", c); }
-
-	return 0;
-}
-
-void report(const char *label)
-{
-	fprintf(stderr, "part: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-struct termios termios;
-
-void save_ttyflags(void)
-/* Save tty attributes for later restoration. */
-{
-	if (tcgetattr(0, &termios) < 0) fatal("");
-}
-
-void restore_ttyflags(void)
-/* Reset the tty flags to how we got 'em. */
-{
-	if (tcsetattr(0, TCSANOW, &termios) < 0) fatal("");
-}
-
-void tty_raw(void)
-/* Set the terminal to raw mode, no signals, no echoing. */
-{
-	struct termios rawterm;
-
-	rawterm= termios;
-	rawterm.c_lflag &= ~(ICANON|ISIG|ECHO);
-	rawterm.c_iflag &= ~(ICRNL);
-	if (tcsetattr(0, TCSANOW, &rawterm) < 0) fatal("");
-}
-
-#define ctrl(c)		((c) == '?' ? '\177' : ((c) & '\37'))
-
-char t_cd[16], t_cm[32], t_so[16], t_se[16], t_md[16], t_me[16];
-int t_li, t_co;
-#define STATUSROW	10
-
-void init_tty(void)
-/* Get terminal capabilities and set the tty to "editor" mode. */
-{
-	char *term;
-	static char termbuf[1024];
-	char *tp;
-
-	if ((term= getenv("TERM")) == nil || tgetent(termbuf, term) != 1) {
-		fprintf(stderr, "part: Can't get terminal capabilities\n");
-		exit(1);
-	}
-	if (tgetstr("cd", (tp= t_cd, &tp)) == nil
-				|| tgetstr("cm", (tp= t_cm, &tp)) == nil) {
-		fprintf(stderr, "part: This terminal is too dumb\n");
-		exit(1);
-	}
-	t_li= tgetnum("li");
-	t_co= tgetnum("co");
-	(void) tgetstr("so", (tp= t_so, &tp));
-	(void) tgetstr("se", (tp= t_se, &tp));
-	(void) tgetstr("md", (tp= t_md, &tp));
-	(void) tgetstr("me", (tp= t_me, &tp));
-
-	save_ttyflags();
-	tty_raw();
-}
-
-void putchr(int c)
-{
-	putchar(c);
-}
-
-void putstr(char *s)
-{
-	int c;
-
-	while ((c= *s++) != 0) putchr(c);
-}
-
-void set_cursor(int row, int col)
-{
-	tputs(tgoto(t_cm, col, row), 1, putchr);
-}
-
-int statusrow= STATUSROW;
-int stat_ktl= 1;
-int need_help= 1;
-
-void stat_start(int serious)
-/* Prepare for printing on a fresh status line, possibly highlighted. */
-{
-	set_cursor(statusrow++, 0);
-	tputs(t_cd, 1, putchr);
-	if (serious) tputs(t_so, 1, putchr);
-}
-
-void stat_end(int ktl)
-/* Closing bracket for stat_start.  Sets "keystrokes to live" of message. */
-{
-	tputs(t_se, 1, putchr);
-	stat_ktl= ktl;
-	need_help= 1;
-}
-
-void stat_reset(void)
-/* Reset the statusline pointer and clear old messages if expired. */
-{
-	if (stat_ktl > 0 && --stat_ktl == 0) {
-		statusrow= STATUSROW;
-		need_help= 1;
-	}
-	if (need_help && statusrow < (24-2)) {
-		if (statusrow > STATUSROW) stat_start(0);
-		stat_start(0);
-		putstr(
-"Type '+' or '-' to change, 'r' to read, '?' for more help, '!' for advice");
-	}
-	statusrow= STATUSROW;
-	need_help= 0;
-}
-
-void clear_screen(void)
-{
-	set_cursor(0, 0);
-	tputs(t_cd, 1, putchr);
-	stat_ktl= 1;
-	stat_reset();
-}
-
-void reset_tty(void)
-/* Reset the tty to cooked mode. */
-{
-	restore_ttyflags();
-	set_cursor(statusrow, 0);
-	tputs(t_cd, 1, putchr);
-}
-
-void *alloc(size_t n)
-{
-	void *m;
-
-	if ((m= malloc(n)) == nil) { reset_tty(); fatal(""); }
-
-	return m;
-}
-
-#ifndef makedev		/* Missing in sys/types.h */
-#define minor(dev)	(((dev) >> MINOR) & BYTE)
-#define major(dev)	(((dev) >> MAJOR) & BYTE)
-#define makedev(major, minor)	\
-			((dev_t) (((major) << MAJOR) | ((minor) << MINOR)))
-#endif
-
-typedef enum parttype { DUNNO, SUBPART, PRIMARY, FLOPPY } parttype_t;
-
-typedef struct device {
-	struct device *next, *prev;	/* Circular dequeue. */
-	dev_t	rdev;			/* Device number (sorting only). */
-	char	*name;			/* E.g. /dev/c0d0 */
-	char	*subname;		/* E.g. /dev/c0d0:2 */
-	parttype_t parttype;
-	int biosdrive;
-} device_t;
-
-typedef struct region {
-	/* A region is either an existing top-level partition
-	 * entry (used_part is non-NULL) or free space (free_*
-	 * contains data).
-	 */
-	struct part_entry used_part;
-	int is_used_part;
-	int tableno;
-	int free_sec_start, free_sec_last;
-} region_t;
-
-/* A disk has between 1 and 2*partitions+1 regions;
- * the last case is free space before and after every partition.
- */
-#define NR_REGIONS (2*NR_PARTITIONS+1)
-region_t regions[NR_REGIONS];
-int nr_partitions = 0, nr_regions = 0, free_regions, used_regions;
-int nordonly = 0;
-
-device_t *firstdev= nil, *curdev;
-
-#define MAX_DEVICES 100
-	static struct {
-		device_t *dev;
-		int nr_partitions, free_regions, used_regions, sectors, nr_regions;
-		int biosdrive;
-		region_t regions[NR_REGIONS];
-	} devices[MAX_DEVICES];
-
-void newdevice(char *name, int scanning, int disk_only)
-/* Add a device to the device list.  If scanning is set then we are reading
- * /dev, so insert the device in device number order and make /dev/c0d0 current.
- */
-{
-	device_t *new, *nextdev, *prevdev;
-	struct stat st;
-
-	st.st_rdev= 0;
-	if (scanning) {
-		if (stat(name, &st) < 0 || !S_ISBLK(st.st_mode)) return;
-
-		switch (major(st.st_rdev)) {
-		case 3:
-			/* Disk controller */
-			if (minor(st.st_rdev) >= 0x80
-					|| minor(st.st_rdev) % 5 != 0) return;
-			break;
-		default:
-			return;
-		}
-		/* Interesting device found. */
-	} else {
-		if(stat(name, &st) < 0) { perror(name); return; }
-	}
-
-	new= alloc(sizeof(*new));
-	new->rdev= st.st_rdev;
-	new->name= alloc((strlen(name) + 1) * sizeof(new->name[0]));
-	strcpy(new->name, name);
-	new->subname= new->name;
-	new->parttype= DUNNO;
-	if (major(st.st_rdev) == major(DEV_FD0) && minor(st.st_rdev) < 112) {
-		new->parttype= FLOPPY;
-	} else
-	if (st.st_rdev >= DEV_C0D0 && minor(st.st_rdev) < 128
-			&& minor(st.st_rdev) % 5 == 0) {
-		new->parttype= PRIMARY;
-	}
-
-	if (firstdev == nil) {
-		firstdev= new;
-		new->next= new->prev= new;
-		curdev= firstdev;
-		return;
-	}
-	nextdev= firstdev;
-	while (new->rdev >= nextdev->rdev
-				&& (nextdev= nextdev->next) != firstdev) {}
-	prevdev= nextdev->prev;
-	new->next= nextdev;
-	nextdev->prev= new;
-	new->prev= prevdev;
-	prevdev->next= new;
-
-	if (new->rdev < firstdev->rdev) firstdev= new;
-	if (new->rdev == DEV_C0D0) curdev= new;
-	if (curdev->rdev != DEV_C0D0) curdev= firstdev;
-}
-
-void getdevices(int disk_only)
-/* Get all block devices from /dev that look interesting. */
-{
-	DIR *d;
-	struct dirent *e;
-	char name[5 + NAME_MAX + 1];
-
-	if ((d= opendir("/dev")) == nil) fatal("/dev");
-
-	while ((e= readdir(d)) != nil) {
-		strcpy(name, "/dev/");
-		strcpy(name + 5, e->d_name);
-		newdevice(name, 1, disk_only);
-	}
-	(void) closedir(d);
-}
-
-/* One featureful master bootstrap. */
-unsigned char bootstrap[] = {
-0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
-0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
-0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
-0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
-0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
-0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
-0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
-0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
-0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
-0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
-0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
-0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
-0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
-0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
-0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
-0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
-0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
-0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
-0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
-0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
-0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
-0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
-0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
-0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
-0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
-0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
-0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
-0000,0000,
-};
-
-int dirty= 0;
-unsigned char bootblock[SECTOR_SIZE];
-struct part_entry table[1 + NR_PARTITIONS];
-int existing[1 + NR_PARTITIONS];
-unsigned long offset= 0, extbase= 0, extsize;
-int submerged= 0;
-char sort_index[1 + NR_PARTITIONS], sort_order[1 + NR_PARTITIONS];
-unsigned cylinders= 1, heads= 1, sectors= 1, secpcyl= 1;
-unsigned alt_cyls= 1, alt_heads= 1, alt_secs= 1;
-int precise= 0;
-int device= -1;
-
-unsigned long sortbase(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? -1 : pe->lowsec;
-}
-
-void sort(void)
-/* Let the sort_index array show the order partitions are sorted in. */
-{
-	int i, j;
-
-	for (i= 1; i <= NR_PARTITIONS; i++) sort_order[i]= i;
-
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		for (j= 1; j <= NR_PARTITIONS-1; j++) {
-			int sj= sort_order[j], sj1= sort_order[j+1];
-
-			if (sortbase(&table[sj]) > sortbase(&table[sj1])) {
-				sort_order[j]= sj1;
-				sort_order[j+1]= sj;
-			}
-		}
-	}
-	for (i= 1; i <= NR_PARTITIONS; i++) sort_index[sort_order[i]]= i;
-}
-
-void dos2chs(unsigned char *dos, unsigned *chs)
-/* Extract cylinder, head and sector from the three bytes DOS uses to address
- * a sector.  Note that bits 8 & 9 of the cylinder number come from bit 6 & 7
- * of the sector byte.  The sector number is rebased to count from 0.
- */
-{
-	chs[0]= ((dos[1] & 0xC0) << 2) | dos[2];
-	chs[1]= dos[0];
-	chs[2]= (dos[1] & 0x3F) - 1;
-}
-
-void abs2dos(unsigned char *dos, unsigned long pos)
-/* Translate a sector offset to three DOS bytes. */
-{
-	unsigned h, c, s;
-
-	c= pos / secpcyl;
-	h= (pos % secpcyl) / sectors;
-	s= pos % sectors + 1;
-
-	dos[0]= h;
-	dos[1]= s | ((c >> 2) & 0xC0);
-	dos[2]= c & 0xFF;
-}
-
-void recompute0(void)
-/* Recompute the partition size for the device after a geometry change. */
-{
-	if (device < 0) {
-		cylinders= heads= sectors= 1;
-		memset(table, 0, sizeof(table));
-	} else
-	if (!precise && offset == 0) {
-		table[0].lowsec= 0;
-		table[0].size= (unsigned long) cylinders * heads * sectors;
-	}
-	table[0].sysind= device < 0 ? NO_PART : MINIX_PART;
-	secpcyl= heads * sectors;
-}
-
-void guess_geometry(void)
-/* With a bit of work one can deduce the disk geometry from the partition
- * table.  This may be necessary if the driver gets it wrong.  (If partition
- * tables didn't have C/H/S numbers we would not care at all...)
- */
-{
-	int i, n;
-	struct part_entry *pe;
-	unsigned chs[3];
-	unsigned long sec;
-	unsigned h, s;
-	unsigned char HS[256][8];	/* Bit map off all possible H/S */
-
-	alt_cyls= alt_heads= alt_secs= 0;
-
-	/* Initially all possible H/S combinations are possible.  HS[h][0]
-	 * bit 0 is used to rule out a head value.
-	 */
-	for (h= 1; h <= 255; h++) {
-		for (s= 0; s < 8; s++) HS[h][s]= 0xFF;
-	}
-
-	for (i= 0; i < 2*NR_PARTITIONS; i++) {
-		pe= &(table+1)[i >> 1];
-		if (pe->sysind == NO_PART) continue;
-
-		/* Get the end or start sector numbers (in that order). */
-		if ((i & 1) == 0) {
-			dos2chs(&pe->last_head, chs);
-			sec= pe->lowsec + pe->size - 1;
-		} else {
-			dos2chs(&pe->start_head, chs);
-			sec= pe->lowsec;
-		}
-
-		if (chs[0] >= alt_cyls) alt_cyls= chs[0]+1;
-
-		/* Which H/S combinations can be ruled out? */
-		for (h= 1; h <= 255; h++) {
-			if (HS[h][0] == 0) continue;
-			n = 0;
-			for (s= 1; s <= 63; s++) {
-				if ((chs[0] * h + chs[1]) * s + chs[2] != sec) {
-					HS[h][s/8] &= ~(1 << (s%8));
-				}
-				if (HS[h][s/8] & (1 << (s%8))) n++;
-			}
-			if (n == 0) HS[h][0]= 0;
-		}
-	}
-
-	/* See if only one remains. */
-	i= 0;
-	for (h= 1; h <= 255; h++) {
-		if (HS[h][0] == 0) continue;
-		for (s= 1; s <= 63; s++) {
-			if (HS[h][s/8] & (1 << (s%8))) {
-				i++;
-				alt_heads= h;
-				alt_secs= s;
-			}
-		}
-	}
-
-	/* Forget it if more than one choice... */
-	if (i > 1) alt_cyls= alt_heads= alt_secs= 0;
-}
-
-void geometry(void)
-/* Find out the geometry of the device by querying the driver, or by looking
- * at the partition table.  These numbers are crosschecked to make sure that
- * the geometry is correct.  Master bootstraps other than the Minix one use
- * the CHS numbers in the partition table to load the bootstrap of the active
- * partition.
- */
-{
-	struct stat dst;
-	int err= 0;
-	struct partition geometry;
-
-	if (submerged) {
-		/* Geometry already known. */
-		sort();
-		return;
-	}
-	precise= 0;
-	cylinders= 0;
-	recompute0();
-	if (device < 0) return;
-
-	/* Try to guess the geometry from the partition table. */
-	guess_geometry();
-
-	/* Try to get the geometry from the driver. */
-	(void) fstat(device, &dst);
-
-	if (S_ISBLK(dst.st_mode) || S_ISCHR(dst.st_mode)) {
-		/* Try to get the drive's geometry from the driver. */
-
-		if (ioctl(device, DIOCGETP, &geometry) < 0)
-			err= errno;
-		else {
-			table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
-			table[0].size= div64u(geometry.size, SECTOR_SIZE);
-			cylinders= geometry.cylinders;
-			heads= geometry.heads;
-			sectors= geometry.sectors;
-			precise= 1;
-		}
-	} else {
-		err= ENODEV;
-	}
-
-	if (err != 0) {
-		/* Getting the geometry from the driver failed, so use the
-		 * alternate geometry.
-		 */
-		if (alt_heads == 0) {
-			alt_cyls= table[0].size / (64 * 32);
-			alt_heads= 64;
-			alt_secs= 32;
-		}
-
-		cylinders= alt_cyls;
-		heads= alt_heads;
-		sectors= alt_secs;
-
-		stat_start(1);
-		printf("Failure to get the geometry of %s: %s", curdev->name,
-			errno == ENOTTY ? "No driver support" : strerror(err));
-		stat_end(5);
-		stat_start(0);
-		printf("The geometry has been guessed as %ux%ux%u",
-						cylinders, heads, sectors);
-		stat_end(5);
-	} else {
-		if (alt_heads == 0) {
-			alt_cyls= cylinders;
-			alt_heads= heads;
-			alt_secs= sectors;
-		}
-
-		if (heads != alt_heads || sectors != alt_secs) {
-printf(
-"The %ux%ux%u geometry obtained from the driver\n"
-"does not match the %ux%ux%u geometry implied by the partition\n"
-"table. Please use expert mode instead.\n");
-exit(1);
-		}
-	}
-
-	/* Show the base and size of the device instead of the whole drive.
-	 * This makes sense for subpartitioning primary partitions.
-	 */
-	if (precise && ioctl(device, DIOCGETP, &geometry) >= 0) {
-		table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
-		table[0].size= div64u(geometry.size, SECTOR_SIZE);
-	} else {
-		precise= 0;
-	}
-	recompute0();
-	sort();
-}
-
-typedef struct indicators {	/* Partition type to partition name. */
-	unsigned char	ind;
-	char		name[10];
-} indicators_t;
-
-indicators_t ind_table[]= {
-	{ 0x00,		"None"		},
-	{ 0x01,		"FAT-12"	},
-	{ 0x02,		"XENIX /"	},
-	{ 0x03,		"XENIX usr"	},
-	{ 0x04,		"FAT-16"	},
-	{ 0x05,		"EXTENDED"	},
-	{ 0x06,		"FAT-16"	},
-	{ 0x07,		"HPFS/NTFS"	},
-	{ 0x08,		"AIX"		},
-	{ 0x09,		"COHERENT"	},
-	{ 0x0A,		"OS/2"		},
-	{ 0x0B,		"FAT-32"	},
-	{ 0x0C,		"FAT?"		},
-	{ 0x0E,		"FAT?"		},
-	{ 0x0F,		"EXTENDED"	},
-	{ 0x10,		"OPUS"		},
-	{ 0x40,		"VENIX286"	},
-	{ 0x42,		"W2000 Dyn"	},
-	{ 0x52,		"MICROPORT"	},
-	{ 0x63,		"386/IX"	},
-	{ 0x64,		"NOVELL286"	},
-	{ 0x65,		"NOVELL386"	},
-	{ 0x75,		"PC/IX"		},
-	{ 0x80,		"MINIX-OLD"	},
-	{ 0x81,		"MINIX"		},
-	{ 0x82,		"LINUXswap"	},
-	{ 0x83,		"LINUX"		},
-	{ 0x93,		"AMOEBA"	},
-	{ 0x94,		"AMOEBAbad"	},
-	{ 0xA5,		"386BSD"	},
-	{ 0xB7,		"BSDI"		},
-	{ 0xB8,		"BSDI swap"	},
-	{ 0xC7,		"SYRINX"	},
-	{ 0xDB,		"CPM"		},
-	{ 0xFF,		"BADBLOCKS"	},
-};
-
-char *typ2txt(int ind)
-/* Translate a numeric partition indicator for human eyes. */
-{
-	indicators_t *pind;
-
-	for (pind= ind_table; pind < arraylimit(ind_table); pind++) {
-		if (pind->ind == ind) return pind->name;
-	}
-	return "unknown system";
-}
-
-int round_sysind(int ind, int delta)
-/* Find the next known partition type starting with ind in direction delta. */
-{
-	indicators_t *pind;
-
-	ind= (ind + delta) & 0xFF;
-
-	if (delta < 0) {
-		for (pind= arraylimit(ind_table)-1; pind->ind > ind; pind--) {}
-	} else {
-		for (pind= ind_table; pind->ind < ind; pind++) {}
-	}
-	return pind->ind;
-}
-
-/* Objects on the screen, either simple pieces of the text or the cylinder
- * number of the start of partition three.
- */
-typedef enum objtype {
-	O_INFO, O_TEXT, O_DEV, O_SUB,
-	O_TYPTXT, O_SORT, O_NUM, O_TYPHEX,
-	O_CYL, O_HEAD, O_SEC,
-	O_SCYL, O_SHEAD, O_SSEC, O_LCYL, O_LHEAD, O_LSEC, O_BASE, O_SIZE, O_KB
-} objtype_t;
-
-#define rjust(type)	((type) >= O_TYPHEX)
-#define computed(type)	((type) >= O_TYPTXT)
-
-typedef struct object {
-	struct object	*next;
-	objtype_t	type;		/* Text field, cylinder number, etc. */
-	char		flags;		/* Modifiable? */
-	char		row;
-	char		col;
-	char		len;
-	struct part_entry *entry;	/* What does the object refer to? */
-	char		  *text;
-	char		value[20];	/* Value when printed. */
-} object_t;
-
-#define OF_MOD		0x01	/* Object value is modifiable. */
-#define OF_ODD		0x02	/* It has a somewhat odd value. */
-#define OF_BAD		0x04	/* Its value is no good at all. */
-
-/* Events: (Keypress events are the value of the key pressed.) */
-#define E_ENTER		(-1)	/* Cursor moves onto object. */
-#define E_LEAVE		(-2)	/* Cursor leaves object. */
-#define E_WRITE		(-3)	/* Write, but not by typing 'w'. */
-
-/* The O_SIZE objects have a dual identity. */
-enum howend { SIZE, LAST } howend= SIZE;
-
-object_t *world= nil;
-object_t *curobj= nil;
-
-object_t *newobject(objtype_t type, int flags, int row, int col, int len)
-/* Make a new object given a type, flags, position and length on the screen. */
-{
-	object_t *new;
-	object_t **aop= &world;
-
-	new= alloc(sizeof(*new));
-
-	new->type= type;
-	new->flags= flags;
-	new->row= row;
-	new->col= col;
-	new->len= len;
-	new->entry= nil;
-	new->text= "";
-	new->value[0]= 0;
-
-	new->next= *aop;
-	*aop= new;
-
-	return new;
-}
-
-unsigned long entry2base(struct part_entry *pe)
-/* Return the base sector of the partition if defined. */
-{
-	return pe->sysind == NO_PART ? 0 : pe->lowsec;
-}
-
-unsigned long entry2last(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? -1 : pe->lowsec + pe->size - 1;
-}
-
-unsigned long entry2size(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? 0 : pe->size;
-}
-
-int overlap(unsigned long sec)
-/* See if sec is part of another partition. */
-{
-	struct part_entry *pe;
-
-	for (pe= table + 1; pe <= table + NR_PARTITIONS; pe++) {
-		if (pe->sysind == NO_PART) continue;
-
-		if (pe->lowsec < sec && sec < pe->lowsec + pe->size)
-			return 1;
-	}
-	return 0;
-}
-
-int aligned(unsigned long sec, unsigned unit)
-/* True if sec is aligned to unit or if it is no problem if it is unaligned. */
-{
-	return (offset != 0 && extbase == 0) || (sec % unit == 0);
-}
-
-void print(object_t *op)
-/* Print an object's value if it changed. */
-{
-	struct part_entry *pe= op->entry;
-	int n;
-	unsigned long t;
-	char *name;
-	int oldflags;
-	char oldvalue[20];
-
-	/* Remember the old flags and value. */
-	oldflags= op->flags;
-	strcpy(oldvalue, op->value);
-
-	op->flags&= ~(OF_ODD | OF_BAD);
-
-	switch (op->type) {
-	case O_INFO:		{
-				/* Current field. */
-		static struct field { int type; char *name; } fields[]= {
-			{ O_DEV,	"Select device"		},
-			{ O_NUM,	"Active flag"		},
-			{ O_TYPHEX,	"Hex partition type"	},
-			{ O_TYPTXT,	"Partition type"	},
-			{ O_SCYL,	"Start cylinder"	},
-			{ O_SHEAD,	"Start head"		},
-			{ O_SSEC,	"Start sector"		},
-			{ O_CYL,	"Number of cylinders"	},
-			{ O_HEAD,	"Number of heads"	},
-			{ O_SEC,	"Sectors per track"	},
-			{ O_LCYL,	"Last cylinder"		},
-			{ O_LHEAD,	"Last head"		},
-			{ O_LSEC,	"Last sector"		},
-			{ O_BASE,	"Base sector"		},
-			{ O_SIZE,	"Size in sectors"	},
-			{ O_KB,		"Size in kilobytes"	},
-			{ -1,		"?"			},
-		};
-		struct field *fp= fields;
-
-		while (fp->type >= 0 && fp->type != curobj->type) fp++;
-		strcpy(op->value, fp->name);
-		op->flags|= OF_ODD;
-		break;		}
-	case O_TEXT:
-				/* Simple text field. */
-		strcpy(op->value, op->text);
-		break;
-	case O_DEV:
-	case O_SUB:
-				/* Name of currently edited device. */
-		name= op->type == O_DEV ? curdev->name :
-					offset == 0 ? "" : curdev->subname;
-		if ((n= strlen(name)) < op->len) n= op->len;
-		strcpy(op->value, name + (n - op->len));
-		if (device < 0 && op->type == O_DEV) op->flags|= OF_BAD;
-		break;
-	case O_NUM:
-				/* Position and active flag. */
-		sprintf(op->value, "%d%c", (int) (pe - table - 1),
-					pe->bootind & ACTIVE_FLAG ? '*' : ' ');
-		break;
-	case O_SORT:
-				/* Position if the driver sorts the table. */
-		sprintf(op->value, "%s%d",
-			curdev->parttype >= PRIMARY ? "p" :
-				curdev->parttype == SUBPART ? "s" : "",
-			(curdev->parttype == SUBPART ||
-				curdev->parttype == FLOPPY ? pe - table
-					: sort_index[pe - table]) - 1);
-		break;
-	case O_TYPHEX:
-				/* Hex partition type indicator. */
-		sprintf(op->value, "%02X", pe->sysind);
-		break;
-	case O_TYPTXT:
-				/* Ascii partition type indicator. */
-		strcpy(op->value, typ2txt(pe->sysind));
-		break;
-	case O_SCYL:
-				/* Partition's start cylinder. */
-		sprintf(op->value, "%lu", entry2base(pe) / secpcyl);
-		break;
-	case O_SHEAD:
-				/* Start head. */
-		t= entry2base(pe);
-		sprintf(op->value, "%lu", t % secpcyl / sectors);
-		if (!aligned(t, secpcyl) && t != table[0].lowsec + sectors)
-			op->flags|= OF_ODD;
-		break;
-	case O_SSEC:
-				/* Start sector. */
-		t= entry2base(pe);
-		sprintf(op->value, "%lu", t % sectors);
-		if (!aligned(t, sectors)) op->flags|= OF_ODD;
-		break;
-	case O_CYL:
-				/* Number of cylinders. */
-		sprintf(op->value, "%u", cylinders);
-		break;
-	case O_HEAD:
-				/* Number of heads. */
-		sprintf(op->value, "%u", heads);
-		break;
-	case O_SEC:
-				/* Number of sectors per track. */
-		sprintf(op->value, "%u", sectors);
-		break;
-	case O_LCYL:
-				/* Partition's last cylinder. */
-		t= entry2last(pe);
-		sprintf(op->value, "%lu", t == -1 ? 0 : t / secpcyl);
-		break;
-	case O_LHEAD:
-				/* Partition's last head. */
-		t= entry2last(pe);
-		sprintf(op->value, "%lu", t == -1 ? 0 : t % secpcyl / sectors);
-		if (!aligned(t + 1, secpcyl)) op->flags|= OF_ODD;
-		break;
-	case O_LSEC:
-				/* Partition's last sector. */
-		t= entry2last(pe);
-		sprintf(op->value, t == -1 ? "-1" : "%lu", t % sectors);
-		if (!aligned(t + 1, sectors)) op->flags|= OF_ODD;
-		break;
-	case O_BASE:
-				/* Partition's base sector. */
-		sprintf(op->value, "%lu", entry2base(pe));
-		if (pe->sysind != NO_PART && pe != &table[0]
-		   && (pe->lowsec <= table[0].lowsec || overlap(pe->lowsec)))
-			op->flags|= OF_BAD;
-		break;
-	case O_SIZE:
-				/* Size of partitition in sectors. */
-		t= howend == SIZE ? entry2size(pe) : entry2last(pe);
-		sprintf(op->value, "%lu", pe->sysind == NO_PART ? 0 : t);
-		if (pe->sysind != NO_PART && (pe->size == 0
-		    || pe->lowsec + pe->size > table[0].lowsec + table[0].size
-		    || overlap(pe->lowsec + pe->size)))
-			op->flags|= OF_BAD;
-		break;
-	case O_KB:
-				/* Size of partitition in kilobytes. */
-		sprintf(op->value, "%lu", entry2size(pe) / 2);
-		break;
-	default:
-		sprintf(op->value, "?? %d ??", op->type);
-	}
-
-	if (device < 0 && computed(op->type)) strcpy(op->value, "?");
-
-	/* If a value overflows the print field then show a blank
-	 * reverse video field.
-	 */
-	if ((n= strlen(op->value)) > op->len) {
-		n= 0;
-		op->flags|= OF_BAD;
-	}
-
-	/* Right or left justified? */
-	if (rjust(op->type)) {
-		memmove(op->value + (op->len - n), op->value, n);
-		memset(op->value, ' ', op->len - n);
-	} else {
-		memset(op->value + n, ' ', op->len - n);
-	}
-	op->value[op->len]= 0;
-
-	if ((op->flags & (OF_ODD | OF_BAD)) == (oldflags & (OF_ODD | OF_BAD))
-				&& strcmp(op->value, oldvalue) == 0) {
-		/* The value did not change. */
-		return;
-	}
-
-	set_cursor(op->row, rjust(op->type) ? op->col - (op->len-1) : op->col);
-
-	if (op->flags & OF_BAD) tputs(t_so, 1, putchr);
-	else
-	if (op->flags & OF_ODD) tputs(t_md, 1, putchr);
-	putstr(op->value);
-	if (op->flags & OF_BAD) tputs(t_se, 1, putchr);
-	else
-	if (op->flags & OF_ODD) tputs(t_me, 1, putchr);
-}
-
-void display(void)
-/* Repaint all objects that changed. */
-{
-	object_t *op;
-
-	for (op= world; op != nil; op= op->next) print(op);
-}
-
-int typing;	/* Set if a digit has been typed to set a value. */
-int magic;	/* Changes when using the magic key. */
-
-void event(int ev, object_t *op);
-
-void m_redraw(int ev, object_t *op)
-/* Redraw the screen. */
-{
-	object_t *op2;
-
-	if (ev != ctrl('L')) return;
-
-	clear_screen();
-	for (op2= world; op2 != nil; op2= op2->next) op2->value[0]= 0;
-}
-
-void m_toggle(int ev, object_t *op)
-/* Toggle between the driver and alternate geometry. */
-{
-	unsigned t;
-
-	if (ev != 'X') return;
-	if (alt_cyls == cylinders && alt_heads == heads && alt_secs == sectors)
-		return;
-
-	t= cylinders; cylinders= alt_cyls; alt_cyls= t;
-	t= heads; heads= alt_heads; alt_heads= t;
-	t= sectors; sectors= alt_secs; alt_secs= t;
-	dirty= 1;
-	recompute0();
-}
-
-char size_last[]= "Size";
-
-void m_orientation(int ev, object_t *op)
-{
-	if (ev != ' ') return;
-
-	switch (howend) {
-	case SIZE:
-		howend= LAST;
-		strcpy(size_last, "Last");
-		break;
-	case LAST:
-		howend= SIZE;
-		strcpy(size_last, "Size");
-	}
-}
-
-void m_move(int ev, object_t *op)
-/* Move to the nearest modifiably object in the intended direction.  Objects
- * on the same row or column are really near.
- */
-{
-	object_t *near, *op2;
-	unsigned dist, d2, dr, dc;
-
-	if (ev != 'h' && ev != 'j' && ev != 'k' && ev != 'l' && ev != 'H')
-		return;
-
-	if (device < 0) {
-		/* No device open?  Then try to read first. */
-		event('r', op);
-		if (device < 0) return;
-	}
-
-	near= op;
-	dist= -1;
-
-	for (op2= world; op2 != nil; op2= op2->next) {
-		if (op2 == op || !(op2->flags & OF_MOD)) continue;
-
-		dr= abs(op2->row - op->row);
-		dc= abs(op2->col - op->col);
-
-		d2= 25*dr*dr + dc*dc;
-		if (op2->row != op->row && op2->col != op->col) d2+= 1000;
-
-		switch (ev) {
-		case 'h':	/* Left */
-			if (op2->col >= op->col) d2= -1;
-			break;
-		case 'j':	/* Down */
-			if (op2->row <= op->row) d2= -1;
-			break;
-		case 'k':	/* Up */
-			if (op2->row >= op->row) d2= -1;
-			break;
-		case 'l':	/* Right */
-			if (op2->col <= op->col) d2= -1;
-			break;
-		case 'H':	/* Home */
-			if (op2->type == O_DEV) d2= 0;
-		}
-		if (d2 < dist) { near= op2; dist= d2; }
-	}
-	if (near != op) event(E_LEAVE, op);
-	event(E_ENTER, near);
-}
-
-void m_updown(int ev, object_t *op)
-/* Move a partition table entry up or down. */
-{
-	int i, j;
-	struct part_entry tmp;
-	int tmpx;
-
-	if (ev != ctrl('K') && ev != ctrl('J')) return;
-	if (op->entry == nil) return;
-
-	i= op->entry - table;
-	if (ev == ctrl('K')) {
-		if (i <= 1) return;
-		j= i-1;
-	} else {
-		if (i >= NR_PARTITIONS) return;
-		j= i+1;
-	}
-
-	tmp= table[i]; table[i]= table[j]; table[j]= tmp;
-	tmpx= existing[i]; existing[i]= existing[j]; existing[j]= tmpx;
-	sort();
-	dirty= 1;
-	event(ev == ctrl('K') ? 'k' : 'j', op);
-}
-
-void m_enter(int ev, object_t *op)
-/* We've moved onto this object. */
-{
-	if (ev != E_ENTER && ev != ' ' && ev != '<' && ev != '>' && ev != 'X')
-		return;
-	curobj= op;
-	typing= 0;
-	magic= 0;
-}
-
-void m_leave(int ev, object_t *op)
-/* About to leave this object. */
-{
-	if (ev != E_LEAVE) return;
-}
-
-int within(unsigned *var, unsigned low, unsigned value, unsigned high)
-/* Only set *var to value if it looks reasonable. */
-{
-	if (low <= value && value <= high) {
-		*var= value;
-		return 1;
-	} else
-		return 0;
-}
-
-int lwithin(unsigned long *var, unsigned long low, unsigned long value,
-							unsigned long high)
-{
-	if (low <= value && value <= high) {
-		*var= value;
-		return 1;
-	} else
-		return 0;
-}
-
-int nextdevice(object_t *op, int delta)
-/* Select the next or previous device from the device list. */
-{
-	dev_t rdev;
-
-	if (offset != 0) return 0;
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return 0;
-
-	if (device >= 0) {
-		(void) close(device);
-		device= -1;
-	}
-	recompute0();
-
-	rdev= curdev->rdev;
-	if (delta < 0) {
-		do
-			curdev= curdev->prev;
-		while (delta < -1 && major(curdev->rdev) == major(rdev)
-			&& curdev->rdev < rdev);
-	} else {
-		do
-			curdev= curdev->next;
-		while (delta > 1 && major(curdev->rdev) == major(rdev)
-			&& curdev->rdev > rdev);
-	}
-	return 1;
-}
-
-void check_ind(struct part_entry *pe)
-/* If there are no other partitions then make this new one active. */
-{
-	struct part_entry *pe2;
-	int i = 0;
-
-	for (pe2= table + 1; pe2 < table + 1 + NR_PARTITIONS; pe2++, i++)
-		if (pe2->sysind != NO_PART && (pe2->bootind & ACTIVE_FLAG))
-			return;
-
-	pe->bootind= ACTIVE_FLAG;
-	dirty = 1;
-}
-
-int check_existing(struct part_entry *pe)
-/* Check and if not ask if an existing partition may be modified. */
-{
-	static int expert= 0;
-	int c;
-
-	if (expert || pe == nil || !existing[pe - table]) return 1;
-
-	stat_start(1);
-	putstr("Do you wish to modify existing partitions? (y/n) ");
-	fflush(stdout);
-	while ((c= getchar()) != 'y' && c != 'n') {}
-	putchr(c);
-	stat_end(3);
-	return (expert= (c == 'y'));
-}
-
-void m_modify(int ev, object_t *op)
-/* Increment, decrement, set, or toggle the value of an object, using
- * arithmetic tricks the author doesn't understand either.
- */
-{
-	object_t *op2;
-	struct part_entry *pe= op->entry;
-	int mul, delta;
-	unsigned level= 1;
-	unsigned long surplus;
-	int radix= op->type == O_TYPHEX ? 0x10 : 10;
-	unsigned long t;
-
-	if (device < 0 && op->type != O_DEV) return;
-
-	switch (ev) {
-	case '-':
-		mul= radix; delta= -1; typing= 0;
-		break;
-	case '+':
-		mul= radix; delta= 1; typing= 0;
-		break;
-	case '\b':
-		if (!typing) return;
-		mul= 1; delta= 0;
-		break;
-	case '\r':
-		typing= 0;
-		return;
-	default:
-		if ('0' <= ev && ev <= '9')
-			delta= ev - '0';
-		else
-		if (radix == 0x10 && 'a' <= ev && ev <= 'f')
-			delta= ev - 'a' + 10;
-		else
-		if (radix == 0x10 && 'A' <= ev && ev <= 'F')
-			delta= ev - 'A' + 10;
-		else
-			return;
-
-		mul= typing ? radix*radix : 0;
-		typing= 1;
-	}
-	magic= 0;
-
-	if (!check_existing(pe)) return;
-
-	switch (op->type) {
-	case O_DEV:
-		if (ev != '-' && ev != '+') return;
-		if (!nextdevice(op, delta)) return;
-		break;
-	case O_CYL:
-		if (!within(&cylinders, 1,
-			cylinders * mul / radix + delta, 1024)) return;
-		recompute0();
-		break;
-	case O_HEAD:
-		if (!within(&heads, 1, heads * mul / radix + delta, 255))
-			return;
-		recompute0();
-		break;
-	case O_SEC:
-		if (!within(&sectors, 1, sectors * mul / radix + delta, 63))
-			return;
-		recompute0();
-		break;
-	case O_NUM:
-		if (ev != '-' && ev != '+') return;
-		for (op2= world; op2 != nil; op2= op2->next) {
-			if (op2->type == O_NUM && ev == '+')
-				op2->entry->bootind= 0;
-		}
-		op->entry->bootind= ev == '+' ? ACTIVE_FLAG : 0;
-		break;
-	case O_TYPHEX:
-		check_ind(pe);
-		pe->sysind= pe->sysind * mul / radix + delta;
-		break;
-	case O_TYPTXT:
-		if (ev != '-' && ev != '+') return;
-		check_ind(pe);
-		pe->sysind= round_sysind(pe->sysind, delta);
-		break;
-	case O_SCYL:
-		level= heads;
-	case O_SHEAD:
-		level*= sectors;
-	case O_SSEC:
-		if (op->type != O_SCYL && ev != '-' && ev != '+') return;
-	case O_BASE:
-		if (pe->sysind == NO_PART) memset(pe, 0, sizeof(*pe));
-		t= pe->lowsec;
-		surplus= t % level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		if (howend == LAST || op->type != O_BASE)
-			pe->size-= t - pe->lowsec;
-		pe->lowsec= t;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	case O_LCYL:
-		level= heads;
-	case O_LHEAD:
-		level*= sectors;
-	case O_LSEC:
-		if (op->type != O_LCYL && ev != '-' && ev != '+') return;
-
-		if (pe->sysind == NO_PART) memset(pe, 0, sizeof(*pe));
-		t= pe->lowsec + pe->size - 1 + level;
-		surplus= t % level - mul / radix * level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		pe->size= t - pe->lowsec + 1;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	case O_KB:
-		level= 2;
-		if (mul == 0) pe->size= 0;	/* new value, no surplus */
-	case O_SIZE:
-		if (pe->sysind == NO_PART) {
-			if (op->type == O_KB || howend == SIZE) {
-				/* First let loose magic to set the base. */
-				event('m', op);
-				magic= 0;
-				pe->size= 0;
-				event(ev, op);
-				return;
-			}
-			memset(pe, 0, sizeof(*pe));
-		}
-		t= (op->type == O_KB || howend == SIZE) ? pe->size
-						: pe->lowsec + pe->size - 1;
-		surplus= t % level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		pe->size= (op->type == O_KB || howend == SIZE) ? t :
-							t - pe->lowsec + 1;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	default:
-		return;
-	}
-
-	/* The order among the entries may have changed. */
-	sort();
-	dirty= 1;
-}
-
-unsigned long spell[3 + 4 * (1+NR_PARTITIONS)];
-int nspells;
-objtype_t touching;
-
-void newspell(unsigned long charm)
-/* Add a new spell, descending order for the base, ascending for the size. */
-{
-	int i, j;
-
-	if (charm - table[0].lowsec > table[0].size) return;
-
-	for (i= 0; i < nspells; i++) {
-		if (charm == spell[i]) return;	/* duplicate */
-
-		if (touching == O_BASE) {
-			if (charm == table[0].lowsec + table[0].size) return;
-			if ((spell[0] - charm) < (spell[0] - spell[i])) break;
-		} else {
-			if (charm == table[0].lowsec) return;
-			if ((charm - spell[0]) < (spell[i] - spell[0])) break;
-		}
-	}
-	for (j= ++nspells; j > i; j--) spell[j]= spell[j-1];
-	spell[i]= charm;
-}
-
-void m_magic(int ev, object_t *op)
-/* Apply magic onto a base or size number. */
-{
-	struct part_entry *pe= op->entry, *pe2;
-	int rough= (offset != 0 && extbase == 0);
-
-	if (ev != 'm' || device < 0) return;
-	typing= 0;
-
-	if (!check_existing(pe)) return;
-
-	if (magic == 0) {
-		/* See what magic we can let loose on this value. */
-		nspells= 1;
-
-		/* First spell, the current value. */
-		switch (op->type) {
-		case O_SCYL:
-		case O_SHEAD:	/* Start of partition. */
-		case O_SSEC:
-		case O_BASE:
-			touching= O_BASE;
-			spell[0]= pe->lowsec;
-			break;
-		case O_LCYL:
-		case O_LHEAD:
-		case O_LSEC:	/* End of partition. */
-		case O_KB:
-		case O_SIZE:
-			touching= O_SIZE;
-			spell[0]= pe->lowsec + pe->size;
-			break;
-		default:
-			return;
-		}
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-			check_ind(pe);
-			pe->sysind= MINIX_PART;
-			spell[0]= 0;
-			if (touching == O_SIZE) {
-				/* First let loose magic on the base. */
-				object_t *op2;
-
-				for (op2= world; op2 != nil; op2= op2->next) {
-					if (op2->row == op->row &&
-							op2->type == O_BASE) {
-						event('m', op2);
-					}
-				}
-				magic= 0;
-				event('m', op);
-				return;
-			}
-		}
-		/* Avoid the first sector on the device. */
-		if (spell[0] == table[0].lowsec) newspell(spell[0] + 1);
-
-		/* Further interesting values are the the bases of other
-		 * partitions or their ends.
-		 */
-		for (pe2= table; pe2 < table + 1 + NR_PARTITIONS; pe2++) {
-			if (pe2 == pe || pe2->sysind == NO_PART) continue;
-			if (pe2->lowsec == table[0].lowsec)
-				newspell(table[0].lowsec + 1);
-			else
-				newspell(pe2->lowsec);
-			newspell(pe2->lowsec + pe2->size);
-			if (touching == O_BASE && howend == SIZE) {
-				newspell(pe2->lowsec - pe->size);
-				newspell(pe2->lowsec + pe2->size - pe->size);
-			}
-			if (pe2->lowsec % sectors != 0) rough= 1;
-		}
-		/* Present values rounded up to the next cylinder unless
-		 * the table is already a mess.  Use "start + 1 track" instead
-		 * of "start + 1 cylinder".  Also add the end of the last
-		 * cylinder.
-		 */
-		if (!rough) {
-			unsigned long n= spell[0];
-			if (n == table[0].lowsec) n++;
-			n= (n + sectors - 1) / sectors * sectors;
-			if (n != table[0].lowsec + sectors)
-				n= (n + secpcyl - 1) / secpcyl * secpcyl;
-			newspell(n);
-			if (touching == O_SIZE)
-				newspell(table[0].size / secpcyl * secpcyl);
-		}
-	}
-	/* Magic has been applied, a spell needs to be chosen. */
-
-	if (++magic == nspells) magic= 0;
-
-	if (touching == O_BASE) {
-		if (howend == LAST) pe->size-= spell[magic] - pe->lowsec;
-		pe->lowsec= spell[magic];
-	} else
-		pe->size= spell[magic] - pe->lowsec;
-
-	/* The order among the entries may have changed. */
-	sort();
-	dirty= 1;
-}
-
-typedef struct diving {
-	struct diving	*up;
-	struct part_entry  old0;
-	char		*oldsubname;
-	parttype_t	oldparttype;
-	unsigned long	oldoffset;
-	unsigned long	oldextbase;
-} diving_t;
-
-diving_t *diving= nil;
-
-void m_in(int ev, object_t *op)
-/* Go down into a primary or extended partition. */
-{
-	diving_t *newdiv;
-	struct part_entry *pe= op->entry, ext;
-	int n;
-
-	if (ev != '>' || device < 0 || pe == nil || pe == &table[0]
-		|| (!(pe->sysind == MINIX_PART && offset == 0)
-					&& !ext_part(pe->sysind))
-		|| pe->size == 0) return;
-
-	ext= *pe;
-	if (extbase != 0) ext.size= extbase + extsize - ext.lowsec;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return;
-	if (device >= 0) { close(device); device= -1; }
-
-	newdiv= alloc(sizeof(*newdiv));
-	newdiv->old0= table[0];
-	newdiv->oldsubname= curdev->subname;
-	newdiv->oldparttype= curdev->parttype;
-	newdiv->oldoffset= offset;
-	newdiv->oldextbase= extbase;
-	newdiv->up= diving;
-	diving= newdiv;
-
-	table[0]= ext;
-
-	n= strlen(diving->oldsubname);
-	curdev->subname= alloc((n + 3) * sizeof(curdev->subname[0]));
-	strcpy(curdev->subname, diving->oldsubname);
-	curdev->subname[n++]= ':';
-	curdev->subname[n++]= '0' + (pe - table - 1);
-	curdev->subname[n]= 0;
-
-	curdev->parttype= curdev->parttype == PRIMARY ? SUBPART : DUNNO;
-	offset= ext.lowsec;
-	if (ext_part(ext.sysind) && extbase == 0) {
-		extbase= ext.lowsec;
-		extsize= ext.size;
-		curdev->parttype= DUNNO;
-	}
-
-	submerged= 1;
-	event('r', op);
-}
-
-void m_out(int ev, object_t *op)
-/* Go up from an extended or subpartition table to its enclosing. */
-{
-	diving_t *olddiv;
-
-	if (ev != '<' || diving == nil) return;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return;
-	if (device >= 0) { close(device); device= -1; }
-
-	olddiv= diving;
-	diving= olddiv->up;
-
-	table[0]= olddiv->old0;
-
-	free(curdev->subname);
-	curdev->subname= olddiv->oldsubname;
-
-	curdev->parttype= olddiv->oldparttype;
-	offset= olddiv->oldoffset;
-	extbase= olddiv->oldextbase;
-
-	free(olddiv);
-
-	event('r', op);
-	if (diving == nil) submerged= 0;	/* We surfaced. */
-}
-
-void installboot(unsigned char *bootblock, char *masterboot)
-/* Install code from a master bootstrap into a boot block. */
-{
-	FILE *mfp;
-	struct exec hdr;
-	int n;
-	char *err;
-
-	if ((mfp= fopen(masterboot, "r")) == nil) {
-		err= strerror(errno);
-		goto m_err;
-	}
-
-	n= fread(&hdr, sizeof(char), A_MINHDR, mfp);
-	if (ferror(mfp)) {
-		err= strerror(errno);
-		fclose(mfp);
-		goto m_err;
-	}
-
-	if (n < A_MINHDR || BADMAG(hdr) || hdr.a_cpu != A_I8086) {
-		err= "Not an 8086 executable";
-		fclose(mfp);
-		goto m_err;
-	}
-
-	if (hdr.a_text + hdr.a_data > PART_TABLE_OFF) {
-		err= "Does not fit in a boot sector";
-		fclose(mfp);
-		goto m_err;
-	}
-
-	fseek(mfp, hdr.a_hdrlen, 0);
-	fread(bootblock, sizeof(char), (size_t) (hdr.a_text + hdr.a_data), mfp);
-	if (ferror(mfp)) {
-		err= strerror(errno);
-		fclose(mfp);
-		goto m_err;
-	}
-	fclose(mfp);
-
-	/* Bootstrap installed. */
-	return;
-
-    m_err:
-	stat_start(1);
-	printf("%s: %s", masterboot, err);
-	stat_end(5);
-}
-
-ssize_t boot_readwrite(int rw)
-/* Read (0) or write (1) the boot sector. */
-{
-	u64_t off64 = mul64u(offset, SECTOR_SIZE);
-	int r;
-
-#if __minix_vmd
-	/* Minix-vmd has a 64 bit seek. */
-	if (fcntl(device, F_SEEK, off64) < 0) return -1;
-#else
-	/* Minix has to gross things with the partition base. */
-	struct partition geom0, geom_seek;
-
-	if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) {
-		/* Move partition base. */
-		if (ioctl(device, DIOCGETP, &geom0) < 0) return -1;
-		geom_seek.base = add64(geom0.base, off64);
-		geom_seek.size = cvu64(cmp64(add64u(off64, SECTOR_SIZE),
-			geom0.size) <= 0 ? _STATIC_BLOCK_SIZE : 0);
-		sync();
-		if (ioctl(device, DIOCSETP, &geom_seek) < 0) return -1;
-		if (lseek(device, (off_t) 0, SEEK_SET) == -1) return -1;
-	} else {
-		/* Can reach this point normally. */
-		if (lseek(device, (off_t) offset * SECTOR_SIZE, SEEK_SET) == -1)
-			return -1;
-	}
-#endif
-
-	switch (rw) {
-	case 0:	r= read(device, bootblock, SECTOR_SIZE);	break;
-	case 1:	r= write(device, bootblock, SECTOR_SIZE);	break;
-	}
-
-#if !__minix_vmd
-	if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) {
-		/* Restore partition base and size. */
-		sync();
-		if (ioctl(device, DIOCSETP, &geom0) < 0) return -1;
-	}
-#endif
-	return r;
-}
-
-int cylinderalign(region_t *reg)
-{
-	if(reg->is_used_part) {
-		if(reg->used_part.lowsec != table[0].lowsec + sectors
-			&& (reg->used_part.lowsec % secpcyl)) {
-			int extra;
-			extra = secpcyl - (reg->used_part.lowsec % secpcyl);
-			reg->used_part.lowsec += extra;
-			reg->used_part.size -= extra;
-		}
-		if((reg->used_part.size+1) % secpcyl) {
-			reg->used_part.size -= secpcyl - ((reg->used_part.size + 1) % secpcyl);
-		}
-		return reg->used_part.size > 0;
-	}
-
-	if(reg->free_sec_start != table[0].lowsec + sectors && (reg->free_sec_start % secpcyl)) {
-		/* Start is unaligned. Round up. */
-		reg->free_sec_start += secpcyl - (reg->free_sec_start % secpcyl);
-	}
-	if((reg->free_sec_last+1) % secpcyl) {
-		/* End is unaligned. Round down. */
-		reg->free_sec_last -= (reg->free_sec_last+1) % secpcyl;
-	}
-	
-	/* Return nonzero if anything remains of the region after rounding. */
-	return reg->free_sec_last > reg->free_sec_start;
-}
-
-void regionize(void)
-{
-	int free_sec, i, si;
-
-	sort();
-
-	free_sec = table[0].lowsec + sectors;
-
-	/* Create region data used in autopart mode. */
-	free_regions = used_regions = nr_regions = nr_partitions = 0;
-	if(table[0].lowsec > table[sort_order[1]].lowsec &&
-		table[sort_order[1]].sysind != NO_PART) {
-		printf("\nSanity check failed on %s - first partition starts before disk.\n"
-			"Please use expert mode to correct it.\n", curdev->name);
-		exit(1);
-	}
-	for(si = 1; si <= NR_PARTITIONS; si++) {
-		i = sort_order[si];
-		if(i < 1 || i > NR_PARTITIONS) {
-			printf("Sorry, something unexpected has happened (%d out of range).\n", i);
-			exit(1);
-		}
-
-		if(table[i].sysind == NO_PART)
-			break;
-
-		/* Free space before this partition? */
-		if(table[i].lowsec > free_sec) {
-			/* Free region before this partition. */
-			regions[nr_regions].free_sec_start = free_sec;
-			regions[nr_regions].free_sec_last = table[i].lowsec-1;
-			regions[nr_regions].is_used_part = 0;
-			if(cylinderalign(&regions[nr_regions])) {
-				nr_regions++;
-				free_regions++;
-			}
-		}
-
-		/* Sanity check. */
-		if(si > 1) {
-			if(table[i].lowsec < table[sort_order[si-1]].lowsec ||
-			   table[i].lowsec < table[sort_order[si-1]].lowsec + table[sort_order[si-1]].size) {
-				printf("\nSanity check failed on %s - partitions overlap.\n"
-					"Please use expert mode to correct it.\n", curdev->name);
-				exit(1);
-			}
-		}
-		if(table[i].size > table[0].size) {
-			printf("\nSanity check failed on %s - partition is larger than disk.\n"
-				"Please use expert mode to correct it.\n", curdev->name);
-			exit(1);
-		}
-		if(table[i].size < 1) {
-			printf("\nSanity check failed on %s - zero-sized partition.\n"
-				"Please use expert mode to correct it.\n", curdev->name);
-			exit(1);
-		} 
-
-		/* Remember used region. */
-		memcpy(&regions[nr_regions].used_part, &table[i], sizeof(table[i]));
-		free_sec = table[i].lowsec+table[i].size;
-		regions[nr_regions].is_used_part = 1;
-		regions[nr_regions].tableno = i;
-		nr_partitions++;
-		nr_regions++;
-		used_regions++;
-	}
-
-	/* Special case: space after partitions. */
-	if(free_sec <   table[0].lowsec + table[0].size-1) {
-		regions[nr_regions].free_sec_start = free_sec;
-		regions[nr_regions].free_sec_last = table[0].lowsec + table[0].size-1;
-		regions[nr_regions].is_used_part = 0;
-		if(cylinderalign(&regions[nr_regions])) {
-			nr_regions++;
-			free_regions++;
-		}
-	}
-
-}
-
-void m_read(int ev, int *biosdrive)
-/* Read the partition table from the current device. */
-{
-	int si, i, mode, n, r, v;
-	struct part_entry *pe;
-
-	if (ev != 'r' || device >= 0) return;
-
-	/* Open() may cause kernel messages: */
-	stat_start(0);
-	fflush(stdout);
-
-	if ((device= open(curdev->name, mode= O_RDWR, 0666)) < 0) {
-		if (device >= 0) { close(device); device= -1; }
-		return;
-	}
-
-	v = 2*HZ;
-	ioctl(device, DIOCTIMEOUT, &v);
-
-	memset(bootblock, 0, sizeof(bootblock));
-
-	n= boot_readwrite(0);
-
-	if (n <= 0) stat_start(1);
-	if (n < 0) {
-		close(device);
-		device= -1;
-	} else
-	if (n < SECTOR_SIZE) {
-		close(device);
-		device= -1;
-		return;
-	}
-	if (n <= 0) stat_end(5);
-
-	if (n < SECTOR_SIZE) n= SECTOR_SIZE;
-
-	if(biosdrive) (*biosdrive)++;
-
-	if(!open_ct_ok(device)) {
-		printf("\n%s: device in use! skipping it.", curdev->subname);
-		fflush(stdout);
-		close(device);
-		device= -1;
-		return;
-	}
-
-	memcpy(table+1, bootblock+PART_TABLE_OFF,
-					NR_PARTITIONS * sizeof(table[1]));
-	if (bootblock[510] != 0x55 || bootblock[511] != 0xAA) {
-		/* Invalid boot block, install bootstrap, wipe partition table.
-		 */
-		memset(bootblock, 0, sizeof(bootblock));
-		installboot(bootblock, MASTERBOOT);
-		memset(table+1, 0, NR_PARTITIONS * sizeof(table[1]));
-	}
-
-	/* Fix an extended partition table up to something mere mortals can
-	 * understand.  Record already defined partitions.
-	 */
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		pe= &table[i];
-		if (extbase != 0 && pe->sysind != NO_PART)
-			pe->lowsec+= ext_part(pe->sysind) ? extbase : offset;
-		existing[i]= pe->sysind != NO_PART;
-	}
-	geometry();
-	dirty= 0;
-
-	/* Warn about grave dangers ahead. */
-	if (extbase != 0) {
-		stat_start(1);
-		printf("Warning: You are in an extended partition.");
-		stat_end(5);
-	}
-
-	regionize();
-}
-
-void m_write(int ev, object_t *op)
-/* Write the partition table back if modified. */
-{
-	int c;
-	struct part_entry new_table[NR_PARTITIONS], *pe;
-
-	if (ev != 'w' && ev != E_WRITE) return;
-	if (device < 0) { dirty= 0; return; }
-	if (!dirty) {
-		if (ev == 'w') {
-			stat_start(1);
-			printf("%s is not changed, or has already been written",
-							curdev->subname);
-			stat_end(2);
-		}
-		return;
-	}
-
-	if (extbase != 0) {
-		/* Will this stop him?  Probably not... */
-		stat_start(1);
-		printf("You have changed an extended partition.  Bad Idea.");
-		stat_end(5);
-	}
-
-	memcpy(new_table, table+1, NR_PARTITIONS * sizeof(table[1]));
-	for (pe= new_table; pe < new_table + NR_PARTITIONS; pe++) {
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-		} else {
-			abs2dos(&pe->start_head, pe->lowsec);
-			abs2dos(&pe->last_head, pe->lowsec + pe->size - 1);
-
-			/* Fear and loathing time: */
-			if (extbase != 0)
-				pe->lowsec-= ext_part(pe->sysind)
-						? extbase : offset;
-		}
-	}
-	memcpy(bootblock+PART_TABLE_OFF, new_table, sizeof(new_table));
-	bootblock[510]= 0x55;
-	bootblock[511]= 0xAA;
-
-	if (boot_readwrite(1) < 0) {
-		stat_start(1);
-		printf("%s: %s", curdev->name, strerror(errno));
-		stat_end(5);
-		return;
-	}
-	dirty= 0;
-}
-
-void m_shell(int ev, object_t *op)
-/* Shell escape, to do calculations for instance. */
-{
-	int r, pid, status;
-	void (*sigint)(int), (*sigquit)(int), (*sigterm)(int);
-
-	if (ev != 's') return;
-
-	reset_tty();
-	fflush(stdout);
-
-	switch (pid= fork()) {
-	case -1:
-		stat_start(1);
-		printf("can't fork: %s\n", strerror(errno));
-		stat_end(3);
-		break;
-	case 0:
-		if (device >= 0) (void) close(device);
-		execl("/bin/sh", "sh", (char *) nil);
-		r= errno;
-		stat_start(1);
-		printf("/bin/sh: %s\n", strerror(errno));
-		stat_end(3);
-		exit(127);
-	}
-	sigint= signal(SIGINT, SIG_IGN);
-	sigquit= signal(SIGQUIT, SIG_IGN);
-	sigterm= signal(SIGTERM, SIG_IGN);
-	while (pid >= 0 && (r= wait(&status)) >= 0 && r != pid) {}
-	(void) signal(SIGINT, sigint);
-	(void) signal(SIGQUIT, sigquit);
-	(void) signal(SIGTERM, sigterm);
-	tty_raw();
-	if (pid < 0)
-		;
-	else
-	if (WIFEXITED(status) && WEXITSTATUS(status) == 127)
-		stat_start(0);	/* Match the stat_start in the child. */
-	else
-		event(ctrl('L'), op);
-}
-
-void m_dump(struct part_entry *print_table)
-/* Raw dump of the partition table. */
-{
-	struct part_entry *pe;
-	int i;
-	unsigned chs[3];
-
-printf(" Partition + type      Cyl Head Sec   Cyl Head Sec      Base      Size       Kb\n");
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		pe= &print_table[i];
-		dos2chs(&pe->start_head, chs);
-		printf("%2d%c      %02X%15d%5d%4d",
-			i,
-			pe->bootind & ACTIVE_FLAG ? '*' : ' ',
-			pe->sysind,
-			chs[0], chs[1], chs[2]);
-		dos2chs(&pe->last_head, chs);
-		printf("%6d%5d%4d%10lu%10ld%9lu\n",
-			chs[0], chs[1], chs[2],
-			pe->lowsec,
-			howend == SIZE ? pe->size : pe->size + pe->lowsec - 1,
-			pe->size / 2);
-	}
-}
-
-int quitting= 0;
-
-void m_quit(int ev, object_t *op)
-/* Write the partition table if modified and exit. */
-{
-	if (ev != 'q' && ev != 'x') return;
-
-	quitting= 1;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) quitting= 0;
-}
-
-void m_help(int ev, object_t *op)
-/* For people without a clue; let's hope they can find the '?' key. */
-{
-	static struct help {
-		char	*keys;
-		char	*what;
-	} help[]= {
-	 { "? !",		 "This help / more advice!" },
-	 { "+ - (= _ PgUp PgDn)","Select/increment/decrement/make active" },
-	 { "0-9 (a-f)",		 "Enter value" },
-	 { "hjkl (arrow keys)",	 "Move around" },
-	 { "CTRL-K CTRL-J",	 "Move entry up/down" },
-	 { "CTRL-L",		 "Redraw screen" },
-	 { ">",			 "Start a subpartition table" },
-	 { "<",			 "Back to the primary partition table" },
-	 { "m",			 "Cycle through magic values" },
-	 { "spacebar",		 "Show \"Size\" or \"Last\"" },
-	 { "r w",		 "Read/write partition table" },
-	 { "p s q x",		 "Raw dump / Shell escape / Quit / Exit" },
-	 { "y n DEL",		 "Answer \"yes\", \"no\", \"cancel\"" },
-	};
-	static char *advice[] = {
-"* Choose a disk with '+' and '-', then hit 'r'.",
-"* To change any value: Move to it and use '+', '-' or type the desired value.",
-"* To make a new partition:  Move over to the Size or Kb field of an unused",
-"  partition and type the size.  Hit the 'm' key to pad the partition out to",
-"  a cylinder boundary.  Hit 'm' again to pad it out to the end of the disk.",
-"  You can hit 'm' more than once on a base or size field to see several",
-"  interesting values go by.  Note: Other Operating Systems can be picky about",
-"  partitions that are not padded to cylinder boundaries.  Look for highlighted",
-"  head or sector numbers.",
-"* To reuse a partition:  Change the type to MINIX.",
-"* To delete a partition:  Type a zero in the hex Type field.",
-"* To make a partition active:  Type '+' in the Num field.",
-"* To study the list of keys:  Type '?'.",
-	};
-
-	if (ev == '?') {
-		struct help *hp;
-
-		for (hp= help; hp < arraylimit(help); hp++) {
-			stat_start(0);
-			printf("%-25s - %s", hp->keys, hp->what);
-			stat_end(0);
-		}
-		stat_start(0);
-		putstr("Things like ");
-		putstr(t_so); putstr("this"); putstr(t_se);
-		putstr(" must be checked, but ");
-		putstr(t_md); putstr("this"); putstr(t_me);
-		putstr(" is not really a problem");
-		stat_end(0);
-	} else
-	if (ev == '!') {
-		char **ap;
-
-		for (ap= advice; ap < arraylimit(advice); ap++) {
-			stat_start(0);
-			putstr(*ap);
-			stat_end(0);
-		}
-	}
-}
-
-void event(int ev, object_t *op)
-/* Simply call all modifiers for an event, each one knows when to act. */
-{
-	m_help(ev, op);
-	m_redraw(ev, op);
-	m_toggle(ev, op);
-	m_orientation(ev, op);
-	m_move(ev, op);
-	m_updown(ev, op);
-	m_enter(ev, op);
-	m_leave(ev, op);
-	m_modify(ev, op);
-	m_magic(ev, op);
-	m_in(ev, op);
-	m_out(ev, op);
-	m_read(ev, NULL);
-	m_write(ev, op);
-	m_shell(ev, op);
-	m_quit(ev, op);
-}
-
-int keypress(void)
-/* Get a single keypress.  Translate compound keypresses (arrow keys) to
- * their simpler equivalents.
- */
-{
-	char ch;
-	int c;
-	int esc= 0;
-
-	set_cursor(curobj->row, curobj->col);
-	fflush(stdout);
-
-	do {
-		if (read(0, &ch, sizeof(ch)) < 0) fatal("stdin");
-		c= (unsigned char) ch;
-		switch (esc) {
-		case 0:
-			switch (c) {
-			case ctrl('['):	esc= 1; break;
-			case '_':	c= '-'; break;
-			case '=':	c= '+'; break;
-			}
-			break;
-		case 1:
-			esc= c == '[' ? 2 : 0;
-			break;
-		case 2:
-			switch (c) {
-			case 'D':	c= 'h';	break;
-			case 'B':	c= 'j';	break;
-			case 'A':	c= 'k';	break;
-			case 'C':	c= 'l';	break;
-			case 'H':	c= 'H';	break;
-			case 'U':
-			case 'S':	c= '-';	break;
-			case 'V':
-			case 'T':	c= '+';	break;
-			}
-			/*FALL THROUGH*/
-		default:
-			esc= 0;
-		}
-	} while (esc > 0);
-
-	switch (c) {
-	case ctrl('B'):	c= 'h';	break;
-	case ctrl('N'):	c= 'j';	break;
-	case ctrl('P'):	c= 'k';	break;
-	case ctrl('F'):	c= 'l';	break;
-	}
-
-	return c;
-}
-
-void mainloop(void)
-/* Get keypress, handle event, display results, reset screen, ad infinitum. */
-{
-	int key;
-
-	while (!quitting) {
-		stat_reset();
-
-		key= keypress();
-
-		event(key, curobj);
-
-		display();
-	}
-}
-
-char *
-prettysizeprint(int kb)
-{
-	int toosmall = 0;
-	static char str[200];
-	char unit = 'k';
-	if(MIN_REGION_SECTORS > kb*2)
-		toosmall = 1;
-	if(kb >= 5*1024) {
-		kb /= 1024;
-		unit = 'M';
-		if(kb >= 5*1024) {
-			kb /= 1024;
-			unit = 'G';
-		}
-	}
-	sprintf(str, "%4d %cB%s", kb, unit,
-		toosmall ? ", too small for MINIX 3" : "");
-	return str;
-}
-
-void
-printregions(region_t *theregions, int indent, int p_nr_partitions, int p_free_regions, int p_nr_regions, int numbers)
-{
-	int r, nofree = 0;
-	region_t *reg;
-	reg = theregions;
-
-	if((p_nr_partitions >= NR_PARTITIONS || !p_free_regions) && p_free_regions)
-		nofree = 1;
-	for(r = 0; r < p_nr_regions; r++, reg++) {
-		unsigned long units;
-		if(reg->is_used_part) {
-			char *name;
-			name = typ2txt(reg->used_part.sysind);
-			printf("%*s", indent, ""); type2col(reg->used_part.sysind);
-			if(numbers) printf("[%d]  ", r);
-			printf("In use by %-10s ", name);
-			units = reg->used_part.size / 2;
-			col(0);
-			printf(" (%s)\n", prettysizeprint(units));
-		} else {
-			printf("%*s", indent, ""); 
-			if(numbers) {
-				if(!nofree) printf("[%d]  ", r);
-				else printf("[-]  ");
-			}
-			printf("Free space           ");
-			units = ((reg->free_sec_last - reg->free_sec_start+1))/2;
-			printf(" (%s)\n", prettysizeprint(units));
-		}
-	}
-
-	if(numbers && p_nr_partitions >= NR_PARTITIONS && p_free_regions) {
-		printf(
-"\nNote: there is free space on this disk, but you can't select it,\n"
-"because there isn't a free slot in the partition table to use it.\n"
-"You can reclaim the free space by deleting an adjacent region.\n");
-	}
-
-	return;
-}
-
-#define IS_YES   3
-#define IS_NO    4
-#define IS_OTHER 5
-int
-is_sure(char *fmt, ...)
-{
-	char yesno[10];
-	va_list ap;
-	va_start (ap, fmt);
-	vprintf(fmt, ap);
-	va_end(ap);
-	printf("  Please enter 'yes' or 'no': ");
-	fflush(stdout);
-	if(!fgets(yesno, sizeof(yesno)-1, stdin)) exit(1);
-
-	if (strcmp(yesno, "yes\n") == 0) return(IS_YES);
-	if (strcmp(yesno, "no\n") == 0) return(IS_NO);
-	return IS_OTHER;
-}
-
-void warn(char *message)
-{
-	printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ! %s\n",message);
-}
-
-int
-may_kill_region(void)
-{
-        int confirmation;
-	char line[100];
-	int r, i;
-
-	if(used_regions < 1) return 1;
-
-	printf("\n -- Delete in-use region? --\n\n");
-
-	printregions(regions, 3, nr_partitions, free_regions, nr_regions, 1);
-	printf("\nEnter the region number to delete or ENTER to continue: ");
-	fflush(NULL);
-	fgets(line, sizeof(line)-2, stdin);
-	if(!isdigit(line[0]))
-		return 1;
-
-	r=atoi(line);
-	if(r < 0 || r >= nr_regions) {
-		printf("This choice is out of range.\n");
-		return 0;
-	}
-
-	if(!regions[r].is_used_part) {
-		printf("This region is not in use.\n");
-		return 0;
-	}
-
-	i = regions[r].tableno;
-
-	printf("\nPlease confirm that you want to delete region %d, losing all data it", r); 
-	printf("\ncontains. You're disk is not actually updated right away, but still.");
-	printf("\n\n");
-
- 	do {
-		confirmation = is_sure("Are you sure you want to continue?");
-		if (confirmation == IS_NO) return 0;
-	} while (confirmation != IS_YES);
-
-		table[i].sysind = NO_PART;
-		dirty = 1;
-		regionize();
-
-	/* User may go again. */
-	return 0;
-}
-
-
-region_t *
-select_region(void)
-{
-	int r, rem, rn, done = 0;
-	static char line[100];
-	region_t *reg;
-	int nofree = 0;
-
-	printstep(2, "Select a disk region");
-
-	if(nr_regions < 1) {
-		printf("\nNo regions found - maybe the drive is too small.\n"
-			"Please try expert mode.\n");
-		exit(1);
-	}
-
-	if(nr_partitions >= NR_PARTITIONS || !free_regions) {
-		if(free_regions) {
-			nofree = 1;
-		}
-	}
-
-
-	printf("\nPlease select the region that you want to use for the MINIX 3 setup.");
-	printf("\nIf you select an in-use region it will be overwritten by MINIX. The");
-	printf("\nfollowing region%s were found on the selected disk:\n\n",
-		SORNOT(nr_regions));
-	printregions(regions, 3, nr_partitions, free_regions, nr_regions, 1);
-
-
-	printf("\n");
-	do {
-		printf("Enter the region number to use or type 'delete': ");
-		if(nr_regions == 1) printf(" [0] ");
-		fflush(NULL);
-
-		if(!fgets(line, sizeof(line)-2, stdin))
-			exit(1);
-
-		if (nr_regions == 1 && line[0] == '\n') {
-		    rn = 0;
-		    done = 1;
-		}
-		else {
-			if(strcmp(line,"delete\n") == 0) {
-				may_kill_region();
-				return NULL;
-			}
-
-			if(sscanf(line, "%d", &rn) != 1)  {
-				warn("invalid choice");
-				continue;
-			}
-
-			if(rn < 0 || rn >= nr_regions) {
-				warn("out of range");
-				continue;
-			}
-
-			if(nofree && !regions[rn].is_used_part) {
-				warn("not available");
-				continue;
-			}
-
-			done = 1;
-		} 
-	} while(! done);
-
-	return(&regions[rn]);
-}
-
-static void printstep(int step, char *str)
-{
-	int n;
-	n = printf("\n --- Substep 4.%d: %s ---", step, str);
-	while(n++ < 73) printf("-");
-	printf("\n");
-}
-
-device_t *
-select_disk(void)
-{
-	int done = 0;
-	int i, choice, drives;
-	static char line[500];
-	int biosdrive = 0;
-
-	printstep(1, "Select a disk to install MINIX 3");
-	printf("\nProbing for disks. This may take a short while.");
-
-		i = 0;
-		curdev=firstdev;
-
-		for(; i < MAX_DEVICES;) {
-			printf("."); 
-			fflush(stdout);
-			m_read('r', &biosdrive);
-			if(device >= 0) {
-				devices[i].dev = curdev;
-				devices[i].free_regions = free_regions;
-				devices[i].nr_regions = nr_regions;
-				devices[i].nr_partitions = nr_partitions;
-				devices[i].used_regions = used_regions;
-				devices[i].sectors = table[0].size;
-				curdev->biosdrive = biosdrive-1;
-				memcpy(devices[i].regions, regions, sizeof(regions));
-				i++;
-			}
-
-			nextdevice(NULL, 1);
-			if(curdev == firstdev)
-				break;
-		}
-
-		drives = i;
-
-		if(drives < 1) {
-			printf("\nFound no drives - can't partition.\n");
-			exit(1);
-		}
-
-		printf(" Probing done.\n"); 
-		printf("The following disk%s %s found on your system:\n\n", SORNOT(drives),
-			drives == 1 ? "was" : "were");
-
-			for(i = 0; i < drives; i++) {
-				printf("  ");
-				printf("Disk [%d]:  ", i);
-				printf("%s, ", devices[i].dev->name);
-				printf("%s\n", prettysizeprint(devices[i].sectors/2));
-				printregions(devices[i].regions, 8,
-					devices[i].nr_partitions,
-					devices[i].free_regions,
-					devices[i].nr_regions, 0);
-			}
-	
-	   printf("\n");
-		do {
-			printf("Enter the disk number to use: ");
-	   		if (drives == 1) printf("[0] ");
-			fflush(NULL);
-			if(!fgets(line, sizeof(line)-2, stdin))
-				exit(1);
-			if (line[0] == '\n' && drives == 1) {
-				choice = 0;
-				done = 1;
-			} else {
-			    if(sscanf(line, "%d", &choice) != 1) {
-				warn("choose a disk");
-			 	continue;
-			    }
-			    if(choice < 0 || choice >= i) {
-				warn("out of range");
-				continue;
-			    }
-			    done = 1;
-			}
-		} while(! done);
-	return devices[choice].dev;
-}
-
-int
-scribble_region(region_t *reg, struct part_entry **pe, int *made_new)
-{
-	int ex, trunc = 0, changed = 0, i;
-	struct part_entry *newpart;
-	if(reg->is_used_part && reg->used_part.size > MAX_REGION_SECTORS) {
-		reg->used_part.size = MAX_REGION_SECTORS;
-		trunc = 1;
-		changed = 1;
-		cylinderalign(reg);
-	}
-	if(!reg->is_used_part) {
-		ex = reg->free_sec_last - reg->free_sec_start + 1;
-		if(ex > MAX_REGION_SECTORS) {
-			reg->free_sec_last -= ex - MAX_REGION_SECTORS;
-			trunc = 1;
-			changed = 1;
-			cylinderalign(reg);
-		}
-		if(made_new) *made_new = 1;
-	} else if(made_new) *made_new = 0;
-#if 0
-	if(trunc) {
-		printf("\nWill only use %dMB.\n", MAX_REGION_MB);
-	}
-#endif
-	if(!reg->is_used_part) {
-		for(i = 1; i <= NR_PARTITIONS; i++)
-			if(table[i].sysind == NO_PART)
-				break;
-		if(i > NR_PARTITIONS) {
-			/* Bug, should've been caught earlier. */
-			printf("Couldn't find a free slot. Please try expert mode.\n");
-			exit(1);
-		}
-		newpart = &table[i];
-		newpart->lowsec = reg->free_sec_start;
-		newpart->size = reg->free_sec_last - reg->free_sec_start + 1;
-		changed = 1;
-		newpart->sysind = MINIX_PART;
-	} else  {
-		newpart = &reg->used_part;
-	}
-	*pe = newpart;
-	changed = 1;
-	dirty = 1;
-	return changed;
-}
-
-int
-sanitycheck_failed(char *dev, struct part_entry *pe)
-{
-	struct partition part;
-	int fd;
-	unsigned long it_lowsec, it_secsize;
-
-	if((fd = open(dev, O_RDONLY)) < 0) {
-		perror(dev);
-		return 1;
-	}
-
-	if (ioctl(fd, DIOCGETP, &part) < 0) {
-		fprintf(stderr, "DIOCGETP failed\n");
-		perror(dev);
-		return 1;
-	}
-
-	if(!open_ct_ok(fd)) {
-		printf("\nAutopart error: the disk is in use. This means that although a\n"
-			"new table has been written, it won't be in use by the system\n"
-			"until it's no longer in use (or a reboot is done). Just in case,\n"
-			"I'm not going to continue. Please un-use the disk (or reboot) and try\n"
-			"again.\n\n");
-		return 1;
-	}
-
-	close(fd);
-
-	it_lowsec = div64u(part.base, SECTOR_SIZE);
-	it_secsize = div64u(part.size, SECTOR_SIZE);
-
-	if(it_lowsec != pe->lowsec || it_secsize != pe->size) {
-		fprintf(stderr, "\nReturned and set numbers don't match up!\n");
-		fprintf(stderr, "This can happen if the disk is still opened.\n");
-		return 1;
-	}
-
-	return 0;
-}
-
-int
-do_autopart(int resultfd)
-{
-	int confirmation;
-	region_t *r;
-	struct part_entry *pe;
-	char sure[50];
-	struct part_entry orig_table[1 + NR_PARTITIONS];
-	int region, disk, newp;
-
-	nordonly = 1; 
-
-	do {
-		curdev = select_disk();
-	} while(!curdev);
-
-	if(device >= 0) {
-		close(device);
-		device = -1;
-	}
-	recompute0();
-
-	m_read('r', NULL);
-
-	memcpy(orig_table, table, sizeof(table));
-
-	do {
-		/* Show regions. */
-		r = select_region();
-	} while(!r);	/* Back to step 2. */
-
-	/* Write things. */
-	if(scribble_region(r, &pe, &newp)) {
-		char *name;
-		int i, found = -1;
-		char partbuf[100], devname[100];
-		struct part_entry *tpe;
-
-		printstep(3, "Confirm your choices");
-
-		region =  (int)(r-regions); 
-		/* disk = (int) (curdev-devices); */
-
-		printf("\nThis is the point of no return.  You have selected to install MINIX 3\n");
-		printf("into region %d of disk %s.  Please confirm that you want\n",
-			region, curdev->name);
-		printf("to use this selection to install MINIX 3.\n\n");
-
-		do {
-			confirmation = is_sure("Are you sure you want to continue?");
-			if (confirmation == IS_NO) return 1;
-		} while (confirmation != IS_YES);
-
-		/* Retrieve partition number in sorted order that we
-		 * have scribbled in.
-		 */
-		sort();
-		for(i = 1; i <= NR_PARTITIONS; i++) {
-			int si;
-			si = sort_order[i];
-			if(si < 1 || si > NR_PARTITIONS) {
-				fprintf(stderr, "Autopart internal error (out of range) (nothing written).\n");
-				exit(1);
-			}
-			if(table[si].lowsec == pe->lowsec) {
-				if(found > 0) {
-					fprintf(stderr, "Autopart internal error (part found twice) (nothing written).\n");
-					exit(1);
-				}
-				check_ind(&table[si]);
-				table[si].sysind = MINIX_PART;
-				found = i;
-				tpe = &table[si];
-			}
-		}
-		if(found < 1) {
-			fprintf(stderr, "Autopart internal error (part not found) (nothing written).\n");
-			exit(1);
-		}
-		m_write('w', NULL);
-		if(dirty) {
-			fprintf(stderr, "Autopart internal error (couldn't update disk).\n");
-			exit(1);
-		}
-		name=strrchr(curdev->name, '/');
-		if(!name) name = curdev->name;
-		else name++;
-
-		sprintf(partbuf, "%sp%d d%dp%d\n", name, found-1,
-			curdev->biosdrive, found-1);
-		sprintf(devname, "/dev/%sp%d", name, found-1);
-		if(resultfd >= 0 && write(resultfd, partbuf, strlen(partbuf)) < strlen(partbuf)) {
-			fprintf(stderr, "Autopart internal error (couldn't write result).\n");
-			exit(1);
-		}
-		if(device >= 0) {
-			close(device);
-			device = -1;
-		}
-
-#if 0
-		m_dump(orig_table);
-		printf("\n");
-		m_dump(table);
-#endif
-
-		if(sanitycheck_failed(devname, tpe)) {
-			fprintf(stderr, "Autopart internal error (disk sanity check failed).\n");
-			exit(1);
-		}
-
-		if(newp) {
-			int fd;
-			if((fd=open(devname, O_WRONLY)) < 0) {
-				perror(devname);
-			} else {
-				/* Clear any subpartitioning. */
-				static unsigned char sub[2048];
-				sub[510] = 0x55;
-				sub[511] = 0xAA;
-				write(fd, sub, sizeof(sub));
-				close(fd);
-			}
-		}
-		return 0;
-	}
-
-	return 1;
-}
-
-int main(int argc, char **argv)
-{
-	object_t *op;
-	int i, r, key;
-	struct part_entry *pe;
-	char *name;
-	int autopart = 0;
-	int resultfd = -1;
-
-	/* Autopilot mode if invoked as autopart. */
-	if(!(name = strrchr(argv[0], '/'))) name = argv[0];
-	else name++;
-	if(!strcmp(name, "autopart"))
-		autopart = 1;
-
-    if(!autopart) {
-	/* Define a few objects to show on the screen.  First text: */
-	op= newobject(O_INFO, 0, 0,  2, 19);
-	op= newobject(O_TEXT, 0, 0, 22, 13); op->text= "----first----";
-	op= newobject(O_TEXT, 0, 0, 37, 13); op->text= "--geom/last--";
-	op= newobject(O_TEXT, 0, 0, 52, 18); op->text= "------sectors-----";
-	op= newobject(O_TEXT, 0, 1,  4,  6); op->text= "Device";
-	op= newobject(O_TEXT, 0, 1, 23, 12); op->text= "Cyl Head Sec";
-	op= newobject(O_TEXT, 0, 1, 38, 12); op->text= "Cyl Head Sec";
-	op= newobject(O_TEXT, 0, 1, 56,  4); op->text= "Base";
-	op= newobject(O_TEXT, 0, 1, 66,  4); op->text= size_last;
-	op= newobject(O_TEXT, 0, 1, 78,  2); op->text= "Kb";
-	op= newobject(O_TEXT, 0, 4,  0, 15); op->text= "Num Sort   Type";
-
-	/* The device is the current object: */
-    curobj= newobject(O_DEV,  OF_MOD, 2,  4, 15);
-	op= newobject(O_SUB,       0, 3,  4, 15);
-
-	/* Geometry: */
-	op= newobject(O_CYL,  OF_MOD, 2, 40,  5); op->entry= &table[0];
-	op= newobject(O_HEAD, OF_MOD, 2, 45,  3); op->entry= &table[0];
-	op= newobject(O_SEC,  OF_MOD, 2, 49,  2); op->entry= &table[0];
-
-	/* Objects for the device: */
-	op= newobject(O_SCYL,  0, 3, 25,  5); op->entry= &table[0];
-	op= newobject(O_SHEAD, 0, 3, 30,  3); op->entry= &table[0];
-	op= newobject(O_SSEC,  0, 3, 34,  2); op->entry= &table[0];
-	op= newobject(O_LCYL,  0, 3, 40,  5); op->entry= &table[0];
-	op= newobject(O_LHEAD, 0, 3, 45,  3); op->entry= &table[0];
-	op= newobject(O_LSEC,  0, 3, 49,  2); op->entry= &table[0];
-	op= newobject(O_BASE,  0, 3, 59,  9); op->entry= &table[0];
-	op= newobject(O_SIZE,  0, 3, 69,  9); op->entry= &table[0];
-	op= newobject(O_KB,    0, 3, 79,  9); op->entry= &table[0];
-
-	/* Objects for each partition: */
-	for (r= 5, pe= table+1; pe <= table+NR_PARTITIONS; r++, pe++) {
-		op= newobject(O_NUM,    OF_MOD, r,  1,  2); op->entry= pe;
-		op= newobject(O_SORT,        0, r,  5,  2); op->entry= pe;
-		op= newobject(O_TYPHEX, OF_MOD, r, 10,  2); op->entry= pe;
-		op= newobject(O_TYPTXT, OF_MOD, r, 12,  9); op->entry= pe;
-		op= newobject(O_SCYL,   OF_MOD, r, 25,  5); op->entry= pe;
-		op= newobject(O_SHEAD,  OF_MOD, r, 30,  3); op->entry= pe;
-		op= newobject(O_SSEC,   OF_MOD, r, 34,  2); op->entry= pe;
-		op= newobject(O_LCYL,   OF_MOD, r, 40,  5); op->entry= pe;
-		op= newobject(O_LHEAD,  OF_MOD, r, 45,  3); op->entry= pe;
-		op= newobject(O_LSEC,   OF_MOD, r, 49,  2); op->entry= pe;
-		op= newobject(O_BASE,   OF_MOD, r, 59,  9); op->entry= pe;
-		op= newobject(O_SIZE,   OF_MOD, r, 69,  9); op->entry= pe;
-		op= newobject(O_KB,     OF_MOD, r, 79,  9); op->entry= pe;
-	}
-     } else {
-     	int c;
-     	/* autopart uses getopt() */
-     	while((c = getopt(argc, argv, "m:f:")) != EOF) {
-     		switch(c) {
-			case 'm':
-				min_region_mb = atoi(optarg);
-				break;
-     			case 'f':
-				/* Make sure old data file is gone. */
-     				unlink(optarg);
-     				if((resultfd=open(optarg, O_CREAT | O_WRONLY | O_TRUNC)) < 0) {
-     					perror(optarg);
-     					return 1;
-     				}
-     				sync();	/* Make sure no old data file lingers. */
-     				break;
-     			default:
-     				fprintf(stderr, "Unknown option\n");
-     				return 1;
-     		}
-     	}
-     }
-     argc -= optind;
-     argv += optind;
-
-	for (i= 0; i < argc; i++) {
-	 newdevice(argv[i], 0, 0);
-	 }
-
-	if (firstdev == nil) {
-		getdevices(autopart);
-		key= ctrl('L');
-	} else {
-		key= 'r';
-	}
-
-	if(autopart) {
-		int r;
-		if (firstdev == nil) {
-			fprintf(stderr, "autopart couldn't find any devices.\n");
-			return 1;
-		}
-		r = do_autopart(resultfd);
-		if(resultfd >= 0) { close(resultfd); }
-		return r;
-	}
-
-	if (firstdev != nil) {
-		init_tty();
-		clear_screen();
-		event(key, curobj);
-		display();
-		mainloop();
-		reset_tty();
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/backup.c
===================================================================
--- trunk/minix/commands/ibm/backup.c	(revision 9)
+++ 	(revision )
@@ -1,398 +1,0 @@
-/* readclock - read the real time clock		Authors: T. Holm & E. Froese */
-
-/************************************************************************/
-/*									*/
-/*   readclock.c							*/
-/*									*/
-/*		Read the clock value from the 64 byte CMOS RAM		*/
-/*		area, then set system time.				*/
-/*									*/
-/*		If the machine ID byte is 0xFC or 0xF8, the device	*/
-/*		/dev/mem exists and can be opened for reading,		*/
-/*		and no errors in the CMOS RAM are reported by the	*/
-/*		RTC, then the time is read from the clock RAM		*/
-/*		area maintained by the RTC.				*/
-/*									*/
-/*		The clock RAM values are decoded and fed to mktime	*/
-/*		to make a time_t value, then stime(2) is called.	*/
-/*									*/
-/*		This fails if:						*/
-/*									*/
-/*		If the machine ID does not match 0xFC or 0xF8 (no	*/
-/*		error message.)						*/
-/*									*/
-/*		If the machine ID is 0xFC or 0xF8 and /dev/mem		*/
-/*		is missing, or cannot be accessed.			*/
-/*									*/
-/*		If the RTC reports errors in the CMOS RAM.		*/
-/*									*/
-/************************************************************************/
-/*    origination          1987-Dec-29              efth                */
-/*    robustness	   1990-Oct-06		    C. Sylvain		*/
-/* incorp. B. Evans ideas  1991-Jul-06		    C. Sylvain		*/
-/*    set time & calibrate 1992-Dec-17		    Kees J. Bot		*/
-/*    clock timezone	   1993-Oct-10		    Kees J. Bot		*/
-/*    set CMOS clock	   1994-Jun-12		    Kees J. Bot		*/
-/************************************************************************/
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <signal.h>
-#include <ibm/portio.h>
-#include <ibm/cmos.h>
-#include <sys/svrctl.h>
-
-int nflag = 0;		/* Tell what, but don't do it. */
-int wflag = 0;		/* Set the CMOS clock. */
-int Wflag = 0;		/* Also set the CMOS clock register bits. */
-int y2kflag = 0;	/* Interpret 1980 as 2000 for clock with Y2K bug. */
-
-char clocktz[128];	/* Timezone of the clock. */
-
-#define MACH_ID_ADDR	0xFFFFE		/* BIOS Machine ID at FFFF:000E */
-
-#define PC_AT		   0xFC		/* Machine ID byte for PC/AT,
-					   PC/XT286, and PS/2 Models 50, 60 */
-#define PS_386		   0xF8		/* Machine ID byte for PS/2 Model 80 */
-
-/* Manufacturers usually use the ID value of the IBM model they emulate.
- * However some manufacturers, notably HP and COMPAQ, have had different
- * ideas in the past.
- *
- * Machine ID byte information source:
- *	_The Programmer's PC Sourcebook_ by Thom Hogan,
- *	published by Microsoft Press
- */
-
-void errmsg(char *s);
-void get_time(struct tm *t);
-int read_register(int reg_addr);
-void set_time(struct tm *t);
-void write_register(int reg_addr, int value);
-int bcd_to_dec(int n);
-int dec_to_bcd(int n);
-void usage(void);
-
-int main(int argc, char **argv)
-{
-  struct tm time1;
-  struct tm time2;
-  struct tm tmnow;
-  char date[64];
-  time_t now, rtc;
-  int i, mem;
-  unsigned char mach_id, cmos_state;
-  struct sysgetenv sysgetenv;
-
-  /* Open /dev/mem to get access to physical memory. */
-  if ((mem = open("/dev/mem", O_RDONLY)) == -1) {
-	errmsg( "Permission denied." );
-	exit(1);
-  }
-  if (lseek(mem, (off_t) MACH_ID_ADDR, SEEK_SET) == -1
-		|| read(mem, (void *) &mach_id, sizeof(mach_id)) < 0) {
-	mach_id = -1;
-  }
-  if (mach_id != PS_386 && mach_id != PC_AT) {
-	errmsg( "Machine ID unknown." );
-	fprintf( stderr, "Machine ID byte = %02x\n", mach_id );
-
-	exit(1);
-  }
-  cmos_state = read_register(CMOS_STATUS);
-  if (cmos_state & (CS_LOST_POWER | CS_BAD_CHKSUM | CS_BAD_TIME)) {
-	errmsg( "CMOS RAM error(s) found..." );
-	fprintf( stderr, "CMOS state = 0x%02x\n", cmos_state );
-
-	if (cmos_state & CS_LOST_POWER)
-	    errmsg( "RTC lost power. Reset CMOS RAM with SETUP." );
-	if (cmos_state & CS_BAD_CHKSUM)
-	    errmsg( "CMOS RAM checksum is bad. Run SETUP." );
-	if (cmos_state & CS_BAD_TIME)
-	    errmsg( "Time invalid in CMOS RAM. Reset clock." );
-	exit(1);
-  }
-
-  /* Process options. */
-  while (argc > 1) {
-	char *p = *++argv;
-
-	if (*p++ != '-') usage();
-
-	while (*p != 0) {
-		switch (*p++) {
-		case 'n':	nflag = 1;	break;
-		case 'w':	wflag = 1;	break;
-		case 'W':	Wflag = 1;	break;
-		case '2':	y2kflag = 1;	break;
-		default:	usage();
-		}
-	}
-	argc--;
-  }
-  if (Wflag) wflag = 1;		/* -W implies -w */
-
-  /* The hardware clock may run in a different time zone, likely GMT or
-   * winter time.  Select that time zone.
-   */
-  strcpy(clocktz, "TZ=");
-  sysgetenv.key = "TZ";
-  sysgetenv.keylen = 2+1;
-  sysgetenv.val = clocktz+3;
-  sysgetenv.vallen = sizeof(clocktz)-3;
-  if (svrctl(SYSGETENV, &sysgetenv) == 0) {
-	putenv(clocktz);
-	tzset();
-  }
-
-  /* Read the CMOS real time clock. */
-  for (i = 0; i < 10; i++) {
-	get_time(&time1);
-	now = time(NULL);
-
-	time1.tm_isdst = -1;	/* Do timezone calculations. */
-	time2 = time1;
-
-	rtc= mktime(&time1);	/* Transform to a time_t. */
-	if (rtc != -1) break;
-
-	fprintf(stderr,
-"readclock: Invalid time read from CMOS RTC: %d-%02d-%02d %02d:%02d:%02d\n",
-		time2.tm_year+1900, time2.tm_mon+1, time2.tm_mday,
-		time2.tm_hour, time2.tm_min, time2.tm_sec);
-	sleep(5);
-  }
-  if (i == 10) exit(1);
-
-  if (!wflag) {
-	/* Set system time. */
-	if (nflag) {
-		printf("stime(%lu)\n", (unsigned long) rtc);
-	} else {
-		if (stime(&rtc) < 0) {
-			errmsg( "Not allowed to set time." );
-			exit(1);
-		}
-	}
-	tmnow = *localtime(&rtc);
-	if (strftime(date, sizeof(date),
-				"%a %b %d %H:%M:%S %Z %Y", &tmnow) != 0) {
-		if (date[8] == '0') date[8]= ' ';
-		printf("Result: %s\n", date);
-	}
-  } else {
-	/* Set the CMOS clock to the system time. */
-	tmnow = *localtime(&now);
-	if (nflag) {
-		printf("%04d-%02d-%02d %02d:%02d:%02d\n",
-			tmnow.tm_year + 1900,
-			tmnow.tm_mon + 1,
-			tmnow.tm_mday,
-			tmnow.tm_hour,
-			tmnow.tm_min,
-			tmnow.tm_sec);
-	} else {
-		set_time(&tmnow);
-	}
-  }
-  exit(0);
-}
-
-void errmsg(char *s)
-{
-  static char *prompt = "readclock: ";
-
-  fprintf(stderr, "%s%s\n", prompt, s);
-  prompt = "";
-}
-
-
-/***********************************************************************/
-/*                                                                     */
-/*    get_time( time )                                                 */
-/*                                                                     */
-/*    Update the structure pointed to by time with the current time    */
-/*    as read from CMOS RAM of the RTC.				       */
-/*    If necessary, the time is converted into a binary format before  */
-/*    being stored in the structure.                                   */
-/*                                                                     */
-/***********************************************************************/
-
-int dead;
-void timeout(int sig) { dead= 1; }
-
-void get_time(struct tm *t)
-{
-  int osec, n;
-  unsigned long i;
-  struct sigaction sa;
-
-  /* Start a timer to keep us from getting stuck on a dead clock. */
-  sigemptyset(&sa.sa_mask);
-  sa.sa_flags = 0;
-  sa.sa_handler = timeout;
-  sigaction(SIGALRM, &sa, NULL);
-  dead = 0;
-  alarm(5);
-
-  do {
-	osec = -1;
-	n = 0;
-	do {
-		if (dead) {
-			fprintf(stderr, "readclock: CMOS clock appears dead\n");
-			exit(1);
-		}
-
-		/* Clock update in progress? */
-		if (read_register(RTC_REG_A) & RTC_A_UIP) continue;
-
-		t->tm_sec = read_register(RTC_SEC);
-		if (t->tm_sec != osec) {
-			/* Seconds changed.  First from -1, then because the
-			 * clock ticked, which is what we're waiting for to
-			 * get a precise reading.
-			 */
-			osec = t->tm_sec;
-			n++;
-		}
-	} while (n < 2);
-
-	/* Read the other registers. */
-	t->tm_min = read_register(RTC_MIN);
-	t->tm_hour = read_register(RTC_HOUR);
-	t->tm_mday = read_register(RTC_MDAY);
-	t->tm_mon = read_register(RTC_MONTH);
-	t->tm_year = read_register(RTC_YEAR);
-
-	/* Time stable? */
-  } while (read_register(RTC_SEC) != t->tm_sec
-	|| read_register(RTC_MIN) != t->tm_min
-	|| read_register(RTC_HOUR) != t->tm_hour
-	|| read_register(RTC_MDAY) != t->tm_mday
-	|| read_register(RTC_MONTH) != t->tm_mon
-	|| read_register(RTC_YEAR) != t->tm_year);
-
-  if ((read_register(RTC_REG_B) & RTC_B_DM_BCD) == 0) {
-	/* Convert BCD to binary (default RTC mode). */
-	t->tm_year = bcd_to_dec(t->tm_year);
-	t->tm_mon = bcd_to_dec(t->tm_mon);
-	t->tm_mday = bcd_to_dec(t->tm_mday);
-	t->tm_hour = bcd_to_dec(t->tm_hour);
-	t->tm_min = bcd_to_dec(t->tm_min);
-	t->tm_sec = bcd_to_dec(t->tm_sec);
-  }
-  t->tm_mon--;	/* Counts from 0. */
-
-  /* Correct the year, good until 2080. */
-  if (t->tm_year < 80) t->tm_year += 100;
-
-  if (y2kflag) {
-	/* Clock with Y2K bug, interpret 1980 as 2000, good until 2020. */
-	if (t->tm_year < 100) t->tm_year += 20;
-  }
-}
-
-
-int read_register(int reg_addr)
-{
-  int r;
-
-  intr_disable();
-  outb(RTC_INDEX, reg_addr);
-  r= inb(RTC_IO);
-  intr_enable();
-  return r;
-}
-
-
-
-/***********************************************************************/
-/*                                                                     */
-/*    set_time( time )                                                 */
-/*                                                                     */
-/*    Set the CMOS RTC to the time found in the structure.             */
-/*                                                                     */
-/***********************************************************************/
-
-void set_time(struct tm *t)
-{
-  int regA, regB;
-
-  if (Wflag) {
-	/* Set A and B registers to their proper values according to the AT
-	 * reference manual.  (For if it gets messed up, but the BIOS doesn't
-	 * repair it.)
-	 */
-	write_register(RTC_REG_A, RTC_A_DV_OK | RTC_A_RS_DEF);
-	write_register(RTC_REG_B, RTC_B_24);
-  }
-
-  /* Inhibit updates. */
-  regB= read_register(RTC_REG_B);
-  write_register(RTC_REG_B, regB | RTC_B_SET);
-
-  t->tm_mon++;	/* Counts from 1. */
-
-  if (y2kflag) {
-	/* Set the clock back 20 years to avoid Y2K bug, good until 2020. */
-	if (t->tm_year >= 100) t->tm_year -= 20;
-  }
-
-  if ((regB & 0x04) == 0) {
-	/* Convert binary to BCD (default RTC mode) */
-	t->tm_year = dec_to_bcd(t->tm_year % 100);
-	t->tm_mon = dec_to_bcd(t->tm_mon);
-	t->tm_mday = dec_to_bcd(t->tm_mday);
-	t->tm_hour = dec_to_bcd(t->tm_hour);
-	t->tm_min = dec_to_bcd(t->tm_min);
-	t->tm_sec = dec_to_bcd(t->tm_sec);
-  }
-  write_register(RTC_YEAR, t->tm_year);
-  write_register(RTC_MONTH, t->tm_mon);
-  write_register(RTC_MDAY, t->tm_mday);
-  write_register(RTC_HOUR, t->tm_hour);
-  write_register(RTC_MIN, t->tm_min);
-  write_register(RTC_SEC, t->tm_sec);
-
-  /* Stop the clock. */
-  regA= read_register(RTC_REG_A);
-  write_register(RTC_REG_A, regA | RTC_A_DV_STOP);
-
-  /* Allow updates and restart the clock. */
-  write_register(RTC_REG_B, regB);
-  write_register(RTC_REG_A, regA);
-}
-
-
-void write_register(int reg_addr, int value)
-{
-  intr_disable();
-  outb(RTC_INDEX, reg_addr);
-  outb(RTC_IO, value);
-  intr_enable();
-}
-
-int bcd_to_dec(int n)
-{
-  return ((n >> 4) & 0x0F) * 10 + (n & 0x0F);
-}
-
-int dec_to_bcd(int n)
-{
-  return ((n / 10) << 4) | (n % 10);
-}
-
-void usage(void)
-{
-  fprintf(stderr, "Usage: readclock [-nwW2]\n");
-  exit(1);
-}
Index: trunk/minix/commands/ibm/build
===================================================================
--- trunk/minix/commands/ibm/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/ibm/dosread.c
===================================================================
--- trunk/minix/commands/ibm/dosread.c	(revision 9)
+++ 	(revision )
@@ -1,1120 +1,0 @@
-/* dos{dir|read|write} - {list|read|write} MS-DOS disks	 Author: M. Huisjes */
-
-/* Dosdir - list MS-DOS directories. doswrite - write stdin to DOS-file
- * dosread - read DOS-file to stdout
- *
- * Author: Michiel Huisjes.
- *
- * Usage: dos... [-lra] drive [file/dir]
- *	  l: Give long listing.
- *	  r: List recursively.
- *	  a: Set ASCII bit.
- */
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <sys/times.h>
-#include <unistd.h>
-
-
-#define MAX_CLUSTER_SIZE	4096
-#define MAX_ROOT_ENTRIES	512
-#define FAT_START		512L	/* After bootsector */
-#define ROOTADDR		(FAT_START + 2L * fat_size)
-#define clus_add(cl_no)		((long) (((long) cl_no - 2L) \
-				 * (long) cluster_size \
-				 + data_start \
-			        ))
-struct dir_entry {
-  unsigned char d_name[8];
-  unsigned char d_ext[3];
-  unsigned char d_attribute;
-  unsigned char d_reserved[10];
-  unsigned short d_time;
-  unsigned short d_date;
-  unsigned short d_cluster;
-  unsigned long d_size;
-};
-
-typedef struct dir_entry DIRECTORY;
-
-#define NOT_USED	0x00
-#define ERASED		0xE5
-#define DIR		0x2E
-#define DIR_SIZE	(sizeof (struct dir_entry))
-#define SUB_DIR		0x10
-#define NIL_DIR		((DIRECTORY *) 0)
-
-#define LAST_CLUSTER12	0xFFF
-#define LAST_CLUSTER	0xFFFF
-#define FREE		0x000
-#define BAD		0xFF0
-#define BAD16		0xFFF0
-
-typedef int BOOL;
-
-#define TRUE	1
-#define FALSE	0
-#define NIL_PTR	((char *) 0)
-
-#define DOS_TIME	315532800L	/* 1970 - 1980 */
-
-#define READ			0
-#define WRITE			1
-
-#define FIND	3
-#define LABEL	4
-#define ENTRY	5
-#define find_entry(d, e, p)	directory(d, e, FIND, p)
-#define list_dir(d, e, f)	(void) directory(d, e, f, NIL_PTR)
-#define label()			directory(root, root_entries, LABEL, NIL_PTR)
-#define new_entry(d, e)		directory(d, e, ENTRY, NIL_PTR)
-
-#define is_dir(d)		((d)->d_attribute & SUB_DIR)
-
-#define STD_OUT			1
-
-char	*cmnd;
-
-static int disk;	/* File descriptor for disk I/O */
-
-static DIRECTORY root[MAX_ROOT_ENTRIES];
-static DIRECTORY save_entry;
-static char drive[] = "/dev/dosX";
-#define DRIVE_NR	(sizeof (drive) - 2)
-static char null[MAX_CLUSTER_SIZE], *device = drive, path[128];
-static long data_start;
-static long mark;	/* offset of directory entry to be written */
-static unsigned short total_clusters, cluster_size, root_entries, sub_entries;
-static unsigned long fat_size;
-
-static BOOL Rflag, Lflag, Aflag, dos_read, dos_write, dos_dir, fat_16 = 0;
-static BOOL big_endian;
-
-/* maximum size of a cooked 12bit FAT. Also Size of 16bit FAT cache
- * if not enough memory for whole FAT
- */
-#define COOKED_SIZE		8192
-/* raw FAT. Only used for 12bit FAT to make conversion easier 
- */
-static unsigned char	*raw_fat;
-/* Cooked FAT. May be only part of the FAT for 16 bit FATs
- */
-static unsigned short	*cooked_fat;
-/* lowest and highest entry in fat cache
- */
-static unsigned short	fat_low = USHRT_MAX,
-			fat_high = 0;
-static BOOL		fat_dirty = FALSE;
-static unsigned int	cache_size;
-
-
-/* Prototypes. */
-_PROTOTYPE(void usage, (char *prog_name) );
-_PROTOTYPE(unsigned c2u2, (unsigned char *ucarray) );
-_PROTOTYPE(unsigned long c4u4, (unsigned char *ucarray) );
-_PROTOTYPE(void determine, (void));
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(DIRECTORY *directory, (DIRECTORY *dir, int entries, BOOL function, char *pathname) );
-_PROTOTYPE(void extract, (DIRECTORY *entry) );
-_PROTOTYPE(void make_file, (DIRECTORY *dir_ptr, int entries, char *name) );
-_PROTOTYPE(void fill_date, (DIRECTORY *entry) );
-_PROTOTYPE(char *make_name, (DIRECTORY *dir_ptr, int dir_fl) );
-_PROTOTYPE(int fill, (char *buffer, size_t size) );
-_PROTOTYPE(void xmodes, (int mode) );
-_PROTOTYPE(void show, (DIRECTORY *dir_ptr, char *name) );
-_PROTOTYPE(void free_blocks, (void));
-_PROTOTYPE(DIRECTORY *read_cluster, (unsigned int cluster) );
-_PROTOTYPE(unsigned short free_cluster, (BOOL leave_fl) );
-_PROTOTYPE(void link_fat, (unsigned int cl_1, unsigned int cl_2) );
-_PROTOTYPE(unsigned short next_cluster, (unsigned int cl_no) );
-_PROTOTYPE(char *slash, (char *str) );
-_PROTOTYPE(void add_path, (char *file, BOOL slash_fl) );
-_PROTOTYPE(void disk_io, (BOOL op, unsigned long seek, void *address, unsigned bytes) );
-_PROTOTYPE(void flush_fat, (void));
-_PROTOTYPE(void read_fat, (unsigned int cl_no));
-_PROTOTYPE(BOOL free_range, (unsigned short *first, unsigned short *last));
-_PROTOTYPE(long lmin, (long a, long b));
-
-
-void usage(prog_name)
-register char *prog_name;
-{
-  fprintf (stderr, "Usage: %s [%s\n", prog_name,
-	     (dos_dir ? "-lr] drive [dir]" : "-a] drive file"));
-  exit(1);
-}
-
-unsigned c2u2(ucarray)
-unsigned char *ucarray;
-{
-  return ucarray[0] + (ucarray[1] << 8);	/* parens vital */
-}
-
-unsigned long c4u4(ucarray)
-unsigned char *ucarray;
-{
-  return ucarray[0] + ((unsigned long) ucarray[1] << 8) +
-		      ((unsigned long) ucarray[2] << 16) +
-		      ((unsigned long) ucarray[3] << 24);
-}
-
-void determine()
-{
-  struct dosboot {
-	unsigned char cjump[2];	/* unsigneds avoid bugs */
-	unsigned char nop;
-	unsigned char name[8];
-	unsigned char cbytepers[2];	/* don't use shorts, etc */
-	unsigned char secpclus;		/* to avoid struct member */
-	unsigned char creservsec[2];	/* alignment and byte */
-	unsigned char fats;		/* order bugs */
-	unsigned char cdirents[2];
-	unsigned char ctotsec[2];
-	unsigned char media;
-	unsigned char csecpfat[2];
-	unsigned char csecptrack[2];
-	unsigned char cheads[2];
-	unsigned char chiddensec[2];
-	unsigned char dos4hidd2[2];
-	unsigned char dos4totsec[4];
-	/* Char    fill[476]; */
-  } boot;
-  unsigned short boot_magic;	/* last of boot block */
-  unsigned bytepers, reservsec, dirents;
-  unsigned secpfat, secptrack, heads, hiddensec;
-  unsigned long totsec;
-  unsigned char fat_info, fat_check;
-  unsigned short endiantest = 1;
-  int errcount = 0;
-
-  big_endian = !(*(unsigned char *)&endiantest);
-
-  /* Read Bios-Parameterblock */
-  disk_io(READ, 0L, &boot, sizeof boot);
-  disk_io(READ, 0x1FEL, &boot_magic, sizeof boot_magic);
-
-  /* Convert some arrays */
-  bytepers = c2u2(boot.cbytepers);
-  reservsec = c2u2(boot.creservsec);
-  dirents = c2u2(boot.cdirents);
-  totsec = c2u2(boot.ctotsec);
-  if (totsec == 0) totsec = c4u4(boot.dos4totsec);
-  secpfat = c2u2(boot.csecpfat);
-  secptrack = c2u2(boot.csecptrack);
-  heads = c2u2(boot.cheads);
-
-  /* The `hidden sectors' are the sectors before the partition.
-   * The calculation here is probably wrong (I think the dos4hidd2
-   * bytes are the msbs), but that doesn't matter, since the
-   * value isn't used anyway
-   */
-  hiddensec = c2u2(boot.chiddensec);
-  if (hiddensec == 0) hiddensec = c2u2 (boot.dos4hidd2);
-
-  /* Safety checking */
-  if (boot_magic != 0xAA55) {
-	fprintf (stderr, "%s: magic != 0xAA55\n", cmnd);
-	++errcount;
-  }
-
-  /* Check sectors per track instead of inadequate media byte */
-  if (secptrack < 15 &&		/* assume > 15 hard disk & wini OK */
-#ifdef SECT10			/* BIOS modified for 10 sec/track */
-      secptrack != 10 &&
-#endif
-#ifdef SECT8			/* BIOS modified for 8 sec/track */
-      secptrack != 8 &&
-#endif
-      secptrack != 9) {
-	fprintf (stderr, "%s: %d sectors per track not supported\n", cmnd, secptrack);
-	++errcount;
-  }
-  if (bytepers == 0) {
-	fprintf (stderr, "%s: bytes per sector == 0\n", cmnd);
-	++errcount;
-  }
-  if (boot.secpclus == 0) {
-	fprintf (stderr, "%s: sectors per cluster == 0\n", cmnd);
-	++errcount;
-  }
-  if (boot.fats != 2 && dos_write) {
-	fprintf (stderr, "%s: fats != 2\n", cmnd);
-	++errcount;
-  }
-  if (reservsec != 1) {
-	fprintf (stderr, "%s: reserved != 1\n", cmnd);
-	++errcount;
-  }
-  if (errcount != 0) {
-	fprintf (stderr, "%s: Can't handle disk\n", cmnd);
-	exit(2);
-  }
-
-  /* Calculate everything. */
-  if (boot.secpclus == 0) boot.secpclus = 1;
-  total_clusters =
-	(totsec - boot.fats * secpfat - reservsec -
-	 dirents * 32L / bytepers		    ) / boot.secpclus + 2;
-  	/* first 2 entries in FAT aren't used */
-  cluster_size = bytepers * boot.secpclus;
-  fat_size = (unsigned long) secpfat * (unsigned long) bytepers;
-  data_start = (long) bytepers + (long) boot.fats * fat_size
-	+ (long) dirents *32L;
-  root_entries = dirents;
-  sub_entries = boot.secpclus * bytepers / 32;
-  if (total_clusters > 4096) fat_16 = 1;
-
-  /* Further safety checking */
-  if (cluster_size > MAX_CLUSTER_SIZE) {
-	fprintf (stderr, "%s: cluster size too big\n", cmnd);
-	++errcount;
-  }
-
-  disk_io(READ, FAT_START, &fat_info, 1);
-  disk_io(READ, FAT_START + fat_size, &fat_check, 1);
-  if (fat_check != fat_info) {
-	fprintf (stderr, "%s: Disk type in FAT copy differs from disk type in FAT original.\n", cmnd);
-	++errcount;
-  }
-  if (errcount != 0) {
-	fprintf (stderr, "%s: Can't handle disk\n", cmnd);
-	exit(2);
-  }
-}
-
-int main(argc, argv)
-int argc;
-register char *argv[];
-{
-  register char *arg_ptr = slash(argv[0]);
-  DIRECTORY *entry;
-  short idx = 1;
-  char dev_nr = '0';
-
-  cmnd = arg_ptr;	/* needed for error messages */
-  if (!strcmp(arg_ptr, "dosdir"))
-	dos_dir = TRUE;
-  else if (!strcmp(arg_ptr, "dosread"))
-	dos_read = TRUE;
-  else if (!strcmp(arg_ptr, "doswrite"))
-	dos_write = TRUE;
-  else {
-	fprintf (stderr, "%s: Program should be named dosread, doswrite or dosdir.\n", cmnd);
-	exit(1);
-  }
-
-  if (argc == 1) usage(argv[0]);
-
-  if (argv[1][0] == '-') {
-	for (arg_ptr = &argv[1][1]; *arg_ptr; arg_ptr++) {
-		if (*arg_ptr == 'l' && dos_dir) {
-			Lflag = TRUE;
-		} else if (*arg_ptr == 'r' && dos_dir) {
-			Rflag = TRUE;
-		} else if (*arg_ptr == 'a' && !dos_dir) {
-			assert ('\n' == 10);
-			assert ('\r' == 13);
-			Aflag = TRUE;
-		} else {
-			usage(argv[0]);
-		}
-	}
-	idx++;
-  }
-  if (idx == argc) usage(argv[0]);
-
-  if (strlen(argv[idx]) > 1) {
-	device = argv[idx++];
-
-	/* If the device does not contain a / we assume that it
-	 * is the name of a device in /dev. Instead of prepending
-	 * /dev/ we try to chdir there.
-	 */
-	if (strchr(device, '/') == NULL && chdir("/dev") < 0) {
-		perror("/dev");
-		exit(1);
-	}
-  } else {
-	if ((dev_nr = toupper (*argv[idx++])) < 'A' || dev_nr > 'Z')
-		usage(argv[0]);
-
-	device[DRIVE_NR] = dev_nr;
-  }
-
-  if ((disk = open(device, dos_write ? O_RDWR : O_RDONLY)) < 0) {
-	fprintf (stderr, "%s: cannot open %s: %s\n",
-		 cmnd, device, strerror (errno));
-	exit(1);
-  }
-  determine();
-  disk_io(READ, ROOTADDR, root, DIR_SIZE * root_entries);
-
-  if (dos_dir && Lflag) {
-	entry = label();
-	printf ("Volume in drive %c ", dev_nr);
-	if (entry == NIL_DIR)
-		printf("has no label.\n\n");
-	else
-		printf ("is %.11s\n\n", entry->d_name);
-  }
-  if (argv[idx] == NIL_PTR) {
-	if (!dos_dir) usage(argv[0]);
-	if (Lflag) printf ("Root directory:\n");
-	list_dir(root, root_entries, FALSE);
-	if (Lflag) free_blocks();
-	fflush (stdout);
-	exit(0);
-  }
-  for (arg_ptr = argv[idx]; *arg_ptr; arg_ptr++)
-	if (*arg_ptr == '\\')	*arg_ptr = '/';
-	else		     	*arg_ptr = toupper (*arg_ptr);
-  if (*--arg_ptr == '/') *arg_ptr = '\0';	/* skip trailing '/' */
-
-  add_path(argv[idx], FALSE);
-  add_path("/", FALSE);
-
-  if (dos_dir && Lflag) printf ( "Directory %s:\n", path);
-
-  entry = find_entry(root, root_entries, argv[idx]);
-
-  if (dos_dir) {
-	list_dir(entry, sub_entries, FALSE);
-	if (Lflag) free_blocks();
-  } else if (dos_read)
-	extract(entry);
-  else {
-	if (entry != NIL_DIR) {
-		fflush (stdout);
-		if (is_dir(entry))
-			fprintf (stderr, "%s: %s is a directory.\n", cmnd, path);
-		else
-			fprintf (stderr, "%s: %s already exists.\n", cmnd, argv[idx]);
-		exit(1);
-	}
-	add_path(NIL_PTR, TRUE);
-
-	if (*path) make_file(find_entry(root, root_entries, path),
-			  sub_entries, slash(argv[idx]));
-	else
-		make_file(root, root_entries, argv[idx]);
-  }
-
-  (void) close(disk);
-  fflush (stdout);
-  exit(0);
-  return(0);
-}
-
-
-/* General directory search routine.
- * 
- * dir:
- *	Points to one or more directory entries
- * entries:
- *	number of entries
- *	if entries == root_entries, dir points to the entire
- *	root directory. Otherwise it points to a single directory
- *	entry describing the directory to be searched.
- *	
- * function:
- *	FIND ... find pathname relative to directory dir.
- *	LABEL ... find first label entry in dir.
- *	ENTRY ... create a new empty entry.
- *	FALSE ... list directory
- *
- * pathname:
- *	name of the file to be found or directory to be listed.
- *	must be in upper case, pathname components must be
- *	separated by slashes, but can be longer than than 
- *	8+3 characters (The rest is ignored).
- */
-DIRECTORY *directory(dir, entries, function, pathname)
-DIRECTORY *dir;
-int entries;
-int function;
-register char *pathname;
-{
-  register DIRECTORY *dir_ptr = dir;
-  DIRECTORY *mem = NIL_DIR;
-  unsigned short cl_no = dir->d_cluster;
-  unsigned short type, last = 0;
-  char file_name[14];
-  char *name;
-  int i = 0;
-
-  if (function == FIND) {
-	while (*pathname != '/' && *pathname != '.' && *pathname &&
-	       i < 8) {
-		file_name[i++] = *pathname++;
-	}
-	if (*pathname == '.') {
-		int j = 0;
-		file_name[i++] = *pathname++;
-		while (*pathname != '/' && *pathname != '.' && *pathname &&
-		       j++ < 3) {
-			file_name[i++] = *pathname++;
-		}
-	}
-	while (*pathname != '/' && *pathname) pathname++;
-	file_name[i] = '\0';
-  }
-  do {
-	if (entries != root_entries) {
-		mem = dir_ptr = read_cluster(cl_no);
-		last = cl_no;
-		cl_no = next_cluster(cl_no);
-	}
-	for (i = 0; i < entries; i++, dir_ptr++) {
-		type = dir_ptr->d_name[0] & 0x0FF;
-		if (function == ENTRY) {
-			if (type == NOT_USED || type == ERASED) {
-				if (!mem)
-					mark = ROOTADDR + (long) i *(long) DIR_SIZE;
-				else
-					mark = clus_add(last) + (long) i *(long) DIR_SIZE;
-				return dir_ptr;
-			}
-			continue;
-		}
-		if (type == NOT_USED) break;
-		if (dir_ptr->d_attribute & 0x08) {
-			if (function == LABEL) return dir_ptr;
-			continue;
-		}
-		if (type == DIR || type == ERASED || function == LABEL)
-			continue;
-		type = is_dir(dir_ptr);
-		name = make_name(dir_ptr,
-				 (function == FIND) ?  FALSE : type);
-		if (function == FIND) {
-			if (strcmp(file_name, name) != 0) continue;
-			if (!type) {
-				if (dos_dir || *pathname) {
-					fflush (stdout);
-					fprintf (stderr, "%s: Not a directory: %s\n", cmnd, file_name);
-					exit(1);
-				}
-			} else if (*pathname == '\0' && dos_read) {
-				fflush (stdout);
-				fprintf (stderr, "%s: %s is a directory.\n", cmnd, path);
-				exit(1);
-			}
-			if (*pathname) {
-				dir_ptr = find_entry(dir_ptr,
-					 sub_entries, pathname + 1);
-			}
-			if (mem) {
-				if (dir_ptr) {
-					memcpy((char *)&save_entry, (char *)dir_ptr, DIR_SIZE);
-					dir_ptr = &save_entry;
-				}
-				free( (void *) mem);
-			}
-			return dir_ptr;
-		} else {
-			if (function == FALSE) {
-				show(dir_ptr, name);
-			} else if (type) {	/* Recursive */
-				printf ( "Directory %s%s:\n", path, name);
-				add_path(name, FALSE);
-				list_dir(dir_ptr, sub_entries, FALSE);
-				add_path(NIL_PTR, FALSE);
-			}
-		}
-	}
-	if (mem) free( (void *) mem);
-  } while (cl_no != LAST_CLUSTER && mem);
-
-  switch (function) {
-      case FIND:
-	if (dos_write && *pathname == '\0') return NIL_DIR;
-	fflush (stdout);
-	fprintf (stderr, "%s: Cannot find `%s'.\n", cmnd, file_name);
-	exit(1);
-      case LABEL:
-	return NIL_DIR;
-      case ENTRY:
-	if (!mem) {
-		fflush (stdout);
-		fprintf (stderr, "%s: No entries left in root directory.\n", cmnd);
-		exit(1);
-	}
-	cl_no = free_cluster(TRUE);
-	link_fat(last, cl_no);
-	link_fat(cl_no, LAST_CLUSTER);
-	disk_io(WRITE, clus_add(cl_no), null, cluster_size);
-
-	return new_entry(dir, entries);
-      case FALSE:
-	if (Rflag) {
-		printf ("\n");
-		list_dir(dir, entries, TRUE);
-	}
-  }
-  return NULL;
-}
-
-void extract(entry)
-register DIRECTORY *entry;
-{
-  register unsigned short cl_no = entry->d_cluster;
-  char buffer[MAX_CLUSTER_SIZE];
-  int rest, i;
-
-  if (entry->d_size == 0)	/* Empty file */
-	return;
-
-  do {
-	disk_io(READ, clus_add(cl_no), buffer, cluster_size);
-	rest = (entry->d_size > (long) cluster_size) ? cluster_size : (short) entry->d_size;
-
-	if (Aflag) {
-		for (i = 0; i < rest; i ++) {
-			if (buffer [i] != '\r') putchar (buffer [i]);
-		}
-		if (ferror (stdout)) {
-			fprintf (stderr, "%s: cannot write to stdout: %s\n",
-				 cmnd, strerror (errno));
-			exit (1);
-		}
-	} else {
-		if (fwrite (buffer, 1, rest, stdout) != rest) {
-			fprintf (stderr, "%s: cannot write to stdout: %s\n",
-				 cmnd, strerror (errno));
-			exit (1);
-		}
-	}
-	entry->d_size -= (long) rest;
-	cl_no = next_cluster(cl_no);
-	if (cl_no == BAD16) {
-		fflush (stdout);
-		fprintf (stderr, "%s: reserved cluster value %x encountered.\n",
-			 cmnd, cl_no);
-		exit (1);
-	}
-  } while (entry->d_size && cl_no != LAST_CLUSTER);
-
-  if (cl_no != LAST_CLUSTER)
-	fprintf (stderr, "%s: Too many clusters allocated for file.\n", cmnd);
-  else if (entry->d_size != 0)
-	fprintf (stderr, "%s: Premature EOF: %ld bytes left.\n", cmnd,
-		     entry->d_size);
-}
-
-
-/* Minimum of two long values
- */
-long lmin (a, b)
-long a, b;
-{
-	if (a < b) return a;
-	else return b;
-}
-
-
-void make_file(dir_ptr, entries, name)
-DIRECTORY *dir_ptr;
-int entries;
-char *name;
-{
-  register DIRECTORY *entry = new_entry(dir_ptr, entries);
-  register char *ptr;
-  char buffer[MAX_CLUSTER_SIZE];
-  unsigned short cl_no = 0;
-  int i, r;
-  long size = 0L;
-  unsigned short first_cluster, last_cluster;
-  long chunk;
-
-  memset (&entry->d_name[0], ' ', 11);    /* clear entry */
-  for (i = 0, ptr = name; i < 8 && *ptr != '.' && *ptr; i++)
-	entry->d_name[i] = *ptr++;
-  while (*ptr != '.' && *ptr) ptr++;
-  if (*ptr == '.') ptr++;
-  for (i = 0; i < 3 && *ptr != '.' && *ptr; i++) entry->d_ext[i] = *ptr++;
-
-  for (i = 0; i < 10; i++) entry->d_reserved[i] = '\0';
-  entry->d_attribute = '\0';
-
-  entry->d_cluster = 0;
-
-  while (free_range (&first_cluster, &last_cluster)) {
-	do {
-		unsigned short	nr_clus;
-
-		chunk = lmin ((long) (last_cluster - first_cluster + 1) *
-			     		  cluster_size,
-			      (long) MAX_CLUSTER_SIZE);
-		r = fill(buffer, chunk);
-		if (r == 0) goto done;
-		nr_clus = (r + cluster_size - 1) / cluster_size;
-		disk_io(WRITE, clus_add(first_cluster), buffer, r);
-
-		for (i = 0; i < nr_clus; i ++) {
-			if (entry->d_cluster == 0)
-				cl_no = entry->d_cluster = first_cluster;
-			else {
-				link_fat(cl_no, first_cluster);
-				cl_no = first_cluster;
-			}
-			first_cluster ++;
-		}
-
-		size += r;
-	} while (first_cluster <= last_cluster);
-  }
-  fprintf (stderr, "%s: disk full. File truncated\n", cmnd);
-done:
-  if (entry->d_cluster != 0) link_fat(cl_no, LAST_CLUSTER);
-  entry->d_size = size;
-  fill_date(entry);
-  disk_io(WRITE, mark, entry, DIR_SIZE);
-
-  if (fat_dirty) flush_fat ();
-
-}
-
-
-#define SEC_MIN	60L
-#define SEC_HOUR	(60L * SEC_MIN)
-#define SEC_DAY	(24L * SEC_HOUR)
-#define SEC_YEAR	(365L * SEC_DAY)
-#define SEC_LYEAR	(366L * SEC_DAY)
-
-unsigned short mon_len[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
-void fill_date(entry)
-DIRECTORY *entry;
-{
-  register long cur_time = time((long *) 0) - DOS_TIME;
-  unsigned short year = 0, month = 1, day, hour, minutes, seconds;
-  int i;
-  long tmp;
-
-  if (cur_time < 0)		/* Date not set on booting ... */
-	cur_time = 0;
-  for (;;) {
-	tmp = (year % 4 == 0) ? SEC_LYEAR : SEC_YEAR;
-	if (cur_time < tmp) break;
-	cur_time -= tmp;
-	year++;
-  }
-
-  day = (unsigned short) (cur_time / SEC_DAY);
-  cur_time -= (long) day *SEC_DAY;
-
-  hour = (unsigned short) (cur_time / SEC_HOUR);
-  cur_time -= (long) hour *SEC_HOUR;
-
-  minutes = (unsigned short) (cur_time / SEC_MIN);
-  cur_time -= (long) minutes *SEC_MIN;
-
-  seconds = (unsigned short) cur_time;
-
-  mon_len[1] = (year % 4 == 0) ? 29 : 28;
-  i = 0;
-  while (day >= mon_len[i]) {
-	month++;
-	day -= mon_len[i++];
-  }
-  day++;
-
-  entry->d_date = (year << 9) | (month << 5) | day;
-  entry->d_time = (hour << 11) | (minutes << 5) | seconds;
-}
-
-char *make_name(dir_ptr, dir_fl)
-register DIRECTORY *dir_ptr;
-short dir_fl;
-{
-  static char name_buf[14];
-  register char *ptr = name_buf;
-  short i;
-
-  for (i = 0; i < 8; i++) *ptr++ = dir_ptr->d_name[i];
-
-  while (*--ptr == ' ');
-  assert (ptr >= name_buf);
-
-  ptr++;
-  if (dir_ptr->d_ext[0] != ' ') {
-	*ptr++ = '.';
-	for (i = 0; i < 3; i++) *ptr++ = dir_ptr->d_ext[i];
-	while (*--ptr == ' ');
-	ptr++;
-  }
-  if (dir_fl) *ptr++ = '/';
-  *ptr = '\0';
-
-  return name_buf;
-}
-
-
-int fill(buffer, size)
-register char *buffer;
-size_t	size;
-{
-  static BOOL nl_mark = FALSE;
-  char *last = &buffer[size];
-  char *begin = buffer;
-  register int c;
-
-  while (buffer < last) {
-  	if (nl_mark) {
-  		*buffer ++ = '\n';
-  		nl_mark = FALSE;
-  	} else {
-		c = getchar();
-		if (c == EOF) break;
-		if (Aflag && c == '\n') {
-			*buffer ++ = '\r';
-			nl_mark = TRUE;
-		} else {
-			*buffer++ = c;
-		}
-	}
-  }
-
-  return (buffer - begin);
-}
-
-#define HOUR	0xF800		/* Upper 5 bits */
-#define MIN	0x07E0		/* Middle 6 bits */
-#define YEAR	0xFE00		/* Upper 7 bits */
-#define MONTH	0x01E0		/* Mid 4 bits */
-#define DAY	0x01F		/* Lowest 5 bits */
-
-char *month[] = {
-	 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-	 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-void xmodes(mode)
-int mode;
-{
-  printf ( "\t%c%c%c%c%c", (mode & SUB_DIR) ? 'd' : '-',
-	     (mode & 02) ? 'h' : '-', (mode & 04) ? 's' : '-',
-	     (mode & 01) ? '-' : 'w', (mode & 0x20) ? 'a' : '-');
-}
-
-void show(dir_ptr, name)
-DIRECTORY *dir_ptr;
-char *name;
-{
-  register unsigned short e_date = dir_ptr->d_date;
-  register unsigned short e_time = dir_ptr->d_time;
-  unsigned short next;
-  char bname[20];
-  short i = 0;
-
-  while (*name && *name != '/') bname[i++] = *name++;
-  bname[i] = '\0';
-  if (!Lflag) {
-	printf ( "%s\n", bname);
-	return;
-  }
-  xmodes( (int) dir_ptr->d_attribute);
-  printf ( "\t%s%s", bname, strlen(bname) < 8 ? "\t\t" : "\t");
-  i = 1;
-  if (is_dir(dir_ptr)) {
-	next = dir_ptr->d_cluster;
-	while ((next = next_cluster(next)) != LAST_CLUSTER) i++;
-	printf ("%8ld", (long) i * (long) cluster_size);
-  } else
-	printf ("%8ld", dir_ptr->d_size);
-  printf (" %02d:%02d %2d %s %d\n", ((e_time & HOUR) >> 11),
-	     ((e_time & MIN) >> 5), (e_date & DAY),
-   month[((e_date & MONTH) >> 5) - 1], ((e_date & YEAR) >> 9) + 1980);
-}
-
-void free_blocks()
-{
-  register unsigned short cl_no;
-  long nr_free = 0;
-  long nr_bad = 0;
-
-  for (cl_no = 2; cl_no < total_clusters; cl_no++) {
-	switch (next_cluster(cl_no)) {
-	    case FREE:	nr_free++;	break;
-	    case BAD16:	nr_bad++;	break;
-	}
-  }
-
-  printf ("Free space: %ld bytes.\n", nr_free * (long) cluster_size);
-  if (nr_bad != 0)
-	printf ("Bad sectors: %ld bytes.\n", nr_bad * (long) cluster_size);
-}
-
-
-DIRECTORY *read_cluster(cluster)
-register unsigned int cluster;
-{
-  register DIRECTORY *sub_dir;
-
-  if ((sub_dir = malloc(cluster_size)) == NULL) {
-	fprintf (stderr, "%s: Cannot set break!\n", cmnd);
-	exit(1);
-  }
-  disk_io(READ, clus_add(cluster), sub_dir, cluster_size);
-
-  return sub_dir;
-}
-
-static unsigned short cl_index = 2;
-
-/* find a range of consecutive free clusters. Return TRUE if found
- * and return the first and last cluster in the |*first| and |*last|.
- * If no free clusters are left, return FALSE.
- *
- * Warning: Assumes that all of the range is used before the next call
- *	to free_range or free_cluster.
- */
-BOOL free_range (first, last)
-unsigned short *first, *last;
-{
-  while (cl_index < total_clusters && next_cluster(cl_index) != FREE)
-	cl_index++;
-  if (cl_index >= total_clusters) return FALSE;
-  *first = cl_index;
-  while (cl_index < total_clusters && next_cluster(cl_index) == FREE)
-	cl_index++;
-  *last = cl_index - 1;
-  return TRUE;
-}
-
-
-/* find a free cluster.
- * Return the number of the free cluster or a number > |total_clusters|
- * if none is found.
- * If |leave_fl| is TRUE, the the program will be terminated if 
- * no free cluster can be found
- *
- * Warning: Assumes that the cluster is used before the next call
- *	to free_range or free_cluster.
- */
-unsigned short free_cluster(leave_fl)
-BOOL leave_fl;
-{
-  while (cl_index < total_clusters && next_cluster(cl_index) != FREE)
-	cl_index++;
-
-  if (leave_fl && cl_index >= total_clusters) {
-	fprintf (stderr, "%s: Diskette full. File not added.\n", cmnd);
-	exit(1);
-  }
-  return cl_index++;
-}
-
-
-/* read a portion of the fat containing |cl_no| into the cache
- */
-void read_fat (cl_no) 
-  unsigned int cl_no;
-{
-
-  if (!cooked_fat) {
-  	/* Read the fat for the first time. We have to allocate all the
-  	 * buffers
-  	 */
-  	if (fat_16) {
-		/* FAT consists of little endian shorts. Easy to convert
-		 */
-		if ((cooked_fat = malloc (fat_size)) == NULL) {
-			/* Oops, FAT doesn't fit into memory, just read
-			 * a chunk
-			 */
-			if ((cooked_fat = malloc (COOKED_SIZE)) == NULL) {
-				fprintf (stderr, "%s: not enough memory for FAT cache. Use chmem\n",
-					 cmnd);
-				exit (1);
-			}
-			cache_size = COOKED_SIZE / 2;
-		} else {
-			cache_size = fat_size / 2;
-		}
-	} else {
-		/* 12 bit FAT. Difficult encoding, but small. Keep
-		 * both raw FAT and cooked version in memory.
-		 */
-		if ((cooked_fat = malloc (total_clusters * sizeof (short))) == NULL ||
-		    (raw_fat = malloc (fat_size)) == NULL) {
-			fprintf (stderr, "%s: not enough memory for FAT cache. Use chmem\n",
-				 cmnd);
-			exit (1);
-		}
-		cache_size = total_clusters;
-	}
-  }
-  fat_low = cl_no / cache_size * cache_size;
-  fat_high = fat_low + cache_size - 1;
-
-  if (!fat_16) {
-  	unsigned short	*cp;
-  	unsigned char	*rp;
-  	unsigned short	i;
-
-	disk_io (READ, FAT_START, raw_fat, fat_size);
-	for (rp = raw_fat, cp = cooked_fat, i = 0;
-	     i < cache_size;
-	     rp += 3, i += 2) {
-	     	*cp = *rp + ((*(rp + 1) & 0x0f) << 8);
-	     	if (*cp == BAD) *cp = BAD16;
-	     	else if (*cp == LAST_CLUSTER12) *cp = LAST_CLUSTER;
-	     	cp ++;
-	     	*cp = ((*(rp + 1) & 0xf0) >> 4) + (*(rp + 2) << 4);
-	     	if (*cp == BAD) *cp = BAD16;
-	     	else if (*cp == LAST_CLUSTER12) *cp = LAST_CLUSTER;
-	     	cp ++;
-	}
-  } else {
-
-	assert (sizeof (short) == 2);
-	assert (CHAR_BIT == 8);		/* just in case */
-
-	disk_io (READ, FAT_START + fat_low * 2, (void *)cooked_fat, cache_size * 2);
-	if (big_endian) {
-		unsigned short	*cp;
-		unsigned char	*rp;
-		unsigned short	i;
-
-		for (i = 0, rp = (unsigned char *)cooked_fat /* sic */, cp = cooked_fat;
-		     i < cache_size;
-		     rp += 2, cp ++, i ++) {
-		     	*cp = c2u2 (rp);
-		}
-	}
-  }
-}
-
-
-/* flush the fat cache out to disk
- */
-void flush_fat ()
-{
-  if (fat_16) {
-	if (big_endian) {
-		unsigned short	*cp;
-		unsigned char	*rp;
-		unsigned short	i;
-
-		for (i = 0, rp = (unsigned char *)cooked_fat /* sic */, cp = cooked_fat;
-		     i < cache_size;
-		     rp += 2, cp ++, i ++) {
-		     	*rp = *cp;
-		     	*(rp + 1) = *cp >> 8;
-		}
-	}
-	disk_io (WRITE, FAT_START + fat_low * 2, (void *)cooked_fat, cache_size * 2);
-	disk_io (WRITE, FAT_START + fat_size + fat_low * 2, (void *)cooked_fat, cache_size * 2);
-  } else {
-  	unsigned short	*cp;
-  	unsigned char	*rp;
-  	unsigned short	i;
-
-	for (rp = raw_fat, cp = cooked_fat, i = 0;
-	     i < cache_size;
-	     rp += 3, cp += 2, i += 2) {
-	     	*rp = *cp;
-	     	*(rp + 1) = ((*cp & 0xf00) >> 8) |
-	     		    ((*(cp + 1) & 0x00f) << 4);
-	     	*(rp + 2) = ((*(cp + 1) & 0xff0) >> 4);
-	}
-	disk_io (WRITE, FAT_START, raw_fat, fat_size);
-	disk_io (WRITE, FAT_START + fat_size, raw_fat, fat_size);
-  }
-}
-
-
-/* make cl_2 the successor of cl_1
- */
-void link_fat(cl_1, cl_2)
-unsigned int cl_1;
-unsigned int cl_2;
-{
-  if (cl_1 < fat_low || cl_1 > fat_high) {
-  	if (fat_dirty) flush_fat ();
-  	read_fat (cl_1);
-  }
-  cooked_fat [cl_1 - fat_low] = cl_2;
-  fat_dirty = TRUE;
-}
-
-
-unsigned short next_cluster(cl_no)
-register unsigned int cl_no;
-{
-  if (cl_no < fat_low || cl_no > fat_high) {
-  	if (fat_dirty) flush_fat ();
-  	read_fat (cl_no);
-  }
-  return cooked_fat [cl_no - fat_low];
-}
-
-char *slash(str)
-register char *str;
-{
-  register char *result = str;
-
-  while (*str)
-	if (*str++ == '/') result = str;
-
-  return result;
-}
-
-void add_path(file, slash_fl)
-char *file;
-BOOL slash_fl;
-{
-  register char *ptr = path;
-
-  while (*ptr) ptr++;
-
-  if (file == NIL_PTR) {
-	if (ptr != path) ptr--;
-	if (ptr != path) do {
-			ptr--;
-		} while (*ptr != '/' && ptr != path);
-	if (ptr != path && !slash_fl) *ptr++ = '/';
-	*ptr = '\0';
-  } else
-	strcpy (ptr, file);
-}
-
-
-void disk_io(op, seek, address, bytes)
-register BOOL op;
-unsigned long seek;
-void *address;
-register unsigned bytes;
-{
-  unsigned int r;
-
-  if (lseek(disk, seek, SEEK_SET) < 0L) {
-	fflush (stdout);
-	fprintf (stderr, "%s: Bad lseek: %s\n", cmnd, strerror (errno));
-	exit(1);
-  }
-  if (op == READ)
-	r = read(disk, (char *) address, bytes);
-  else {
-	r = write(disk, (char *) address, bytes);
-  }
-
-  if (r != bytes) {
-  	fprintf (stderr, "%s: read error: %s\n", cmnd, strerror (errno));
-  	exit (1);
-  }
-}
-
-char dosread_c_rcs_id [] = 
-	"$Id: dosread.c,v 1.2 2005/07/13 10:02:14 beng Exp $";
Index: trunk/minix/commands/ibm/fdisk.c
===================================================================
--- trunk/minix/commands/ibm/fdisk.c	(revision 9)
+++ 	(revision )
@@ -1,1009 +1,0 @@
-/* fdisk - partition a hard disk	Author: Jakob Schripsema */
-
-/* Run this with:
- *
- *	fdisk [-hheads] [-ssectors] [device]
- *
- * e.g.,
- *
- *	fdisk				(to get the default)
- *	fdisk -h4 -s17 /dev/hd0		(MINIX default)
- *	fdisk -h4 -s17 c:		(DOS default)
- *	fdisk -h6 -s25 /dev/hd5		(second drive, probably RLL)
- *	fdisk junkfile			(to experiment safely)
- *
- * The device is opened in read-only mode if the file permissions do not
- * permit read-write mode, so it is convenient to use a login account with
- * only read permission to look at the partition table safely.
- *
- * Compile with:
- *
- *	cc -i -o fdisk fdisk.c		(MINIX)
- *	cl -DDOS fdisk.c		(DOS with MS C compiler)
- *
- * This was modified extensively by Bruce Evans 28 Dec 89.
- * The new version has not been tried with DOS.  The open modes are suspect
- * (everyone should convert to use fcntl.h).
- *
- * Changed 18 Dec 92 by Kees J. Bot: Bootstrap code and geometry from device.
- *
- * modified 01 March 95 by asw: updated list of known partition types. Also
- * changed display format slightly to allow for partition type names of
- * up to 9 chars (previous format allowed for 7, but there were already
- * some 8 char names in the list).
-*/
-
-#include <sys/types.h>
-#include <ibm/partition.h>
-#include <minix/partition.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-
-#ifdef DOS
-#include <dos.h>
-#define DEFAULT_DEV	"c:"
-#define LOAD_OPEN_MODE	0x8000
-#define SAVE_CREAT_MODE	0644
-#else
-#define DEFAULT_DEV	"/dev/hd0"
-#define LOAD_OPEN_MODE	0
-#define SAVE_CREAT_MODE	0644
-#define UNIX			/* for MINIX */
-#endif
-
-/* Constants */
-
-#define	DEFAULT_NHEAD	4	/* # heads		 */
-#define	DEFAULT_NSEC	17	/* sectors / track	 */
-#define SECSIZE		512	/* sector size		 */
-#define	OK		0
-#define	ERR		1
-
-#define CYL_MASK	0xc0	/* mask to extract cyl bits from sec field */
-#define CYL_SHIFT	2	/* shift to extract cyl bits from sec field */
-#define SEC_MASK	0x3f	/* mask to extract sec bits from sec field */
-
-/* Globals  */
-char rawsecbuf[SECSIZE + sizeof(long)];
-char *secbuf;
-int badbases;
-int badsizes;
-int badorders;
-char *devname;
-int nhead;
-int nsec;
-int ncyl = 1024;
-int readonly;
-int override= 0;
-
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(void getgeom, (void));
-_PROTOTYPE(int getboot, (char *buffer));
-_PROTOTYPE(int putboot, (char *buffer));
-_PROTOTYPE(int load_from_file, (void));
-_PROTOTYPE(int save_to_file, (void));
-_PROTOTYPE(int dpl_partitions, (int rawflag));
-_PROTOTYPE(int chk_table, (void));
-_PROTOTYPE(int sec_to_hst, (long logsec, unsigned char *hd, unsigned char *sec,
-							 unsigned char *cyl));
-_PROTOTYPE(int mark_partition, (struct part_entry *pe));
-_PROTOTYPE(int change_partition, (struct part_entry *entry));
-_PROTOTYPE(int get_a_char, (void));
-_PROTOTYPE(int print_menu, (void));
-_PROTOTYPE(void adj_base, (struct part_entry *pe));
-_PROTOTYPE(void adj_size, (struct part_entry *pe));
-_PROTOTYPE(struct part_entry *ask_partition, (void));
-_PROTOTYPE(void footnotes, (void));
-_PROTOTYPE(int get_an_int, (char *prompt, int *intptr));
-_PROTOTYPE(void list_part_types, (void));
-_PROTOTYPE(void mark_npartition, (struct part_entry *pe));
-_PROTOTYPE(int mygets, (char *buf, int length));
-_PROTOTYPE(char *systype, (int type));
-_PROTOTYPE(void toggle_active, (struct part_entry *pe));
-_PROTOTYPE(void usage, (void));
-
-/* One featureful master bootstrap. */
-char bootstrap[] = {
-0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
-0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
-0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
-0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
-0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
-0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
-0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
-0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
-0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
-0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
-0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
-0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
-0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
-0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
-0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
-0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
-0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
-0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
-0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
-0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
-0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
-0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
-0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
-0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
-0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
-0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
-0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
-0000,0000,
-};
-
-main(argc, argv)
-int argc;
-char *argv[];
-{
-  int argn;
-  char *argp;
-  int ch;
-
-  /* Init */
-
-  nhead = DEFAULT_NHEAD;
-  nsec = DEFAULT_NSEC;
-  for (argn = 1; argn < argc && (argp = argv[argn])[0] == '-'; ++argn) {
-	if (argp[1] == 'h')
-		nhead = atoi(argp + 2);
-	else
-		if (argp[1] == 's') nsec = atoi(argp + 2);
-	else
-		usage();
-	override= 1;
-  }
-
-  if (argn == argc)
-	devname = DEFAULT_DEV;
-  else if (argn == argc - 1)
-	devname = argv[argn];
-  else
-	usage();
-
-  /* Align the sector buffer in such a way that the partition table is at
-   * a mod 4 offset in memory.  Some weird people add alignment checks to
-   * their Minix!
-   */
-  secbuf = rawsecbuf;
-  while ((long)(secbuf + PART_TABLE_OFF) % sizeof(long) != 0) secbuf++;
-
-  getgeom();
-  getboot(secbuf);
-  chk_table();
-
-  do {
-	putchar('\n');
-	dpl_partitions(0);
-	printf(
-	  "\n(Enter 'h' for help.  A null line will abort any operation) ");
-	ch = get_a_char();
-	putchar('\n');
-	switch (ch) {
-	    case '+':	footnotes();			break;
-	    case 'a':	toggle_active(ask_partition());	break;
-	    case 'B':	adj_base(ask_partition()); 	break;
-	    case 'c':	change_partition(ask_partition());	break;
-	    case 'h':	print_menu();			break;
-	    case 'l':	load_from_file();	  	break;
-	    case 'm':	mark_partition(ask_partition());	break;
-	    case 'n':	mark_npartition(ask_partition());	break;
-	    case 'p':	dpl_partitions(1);  		break;
-	    case 0:
-	    case 'q':	exit(0);
-	    case 'S':	adj_size(ask_partition()); 	break;
-	    case 's':	save_to_file();	  		break;
-	    case 't':	list_part_types();	 	break;
-	    case 'v':
-		printf("Partition table is %svalid\n",
-			chk_table() == OK ? "" : "in");
-		break;
-	    case 'w':
-		if (readonly)
-			printf("Write disabled\n");
-		else if(chk_table() == OK) {
-			putboot(secbuf);
-			printf(
-	"Partition table has been updated and the file system synced.\n");
-			printf("Please reboot now.\n");
-			exit(0);
-		} else
-			printf("Not written\n");
-		break;
-	    default:	printf(" %c ????\n", ch);	break;
-  	}
-  }
-  while (1);
-}
-
-
-#ifdef UNIX
-
-void getgeom()
-{
-  struct partition geom;
-  int fd, r;
-
-  if (override) return;
-
-  if ((fd= open(devname, O_RDONLY)) < 0) return;
-
-  r = ioctl(fd, DIOCGETP, &geom);
-  close(fd);
-  if (r < 0) return;
-
-  nhead = geom.heads;
-  nsec = geom.sectors;
-  ncyl = geom.cylinders;
-
-  printf("Geometry of %s: %dx%dx%d\n", devname, ncyl, nhead, nsec);
-}
-
-static int devfd;
-
-getboot(buffer)
-char *buffer;
-{
-  devfd = open(devname, 2);
-  if (devfd < 0) {
-	printf("No write permission on %s\n", devname);
-	readonly = 1;
-	devfd = open(devname, 0);
-  }
-  if (devfd < 0) {
-	printf("Cannot open device %s\n", devname);
-	exit(1);
-  }
-  if (read(devfd, buffer, SECSIZE) != SECSIZE) {
-	printf("Cannot read boot sector\n");
-	exit(1);
-  }
-  if (* (unsigned short *) &buffer[510] != 0xAA55) {
-	printf("Invalid boot sector on %s.\n", devname);
-	printf("Partition table reset and boot code installed.\n");
-	memset(buffer, 0, 512);
-	memcpy(buffer, bootstrap, sizeof(bootstrap));
-	* (unsigned short *) &buffer[510] = 0xAA55;
-  }
-}
-
-putboot(buffer)
-char *buffer;
-{
-  if (lseek(devfd, 0L, 0) < 0) {
-	printf("Seek error during write\n");
-	exit(1);
-  }
-  if (write(devfd, buffer, SECSIZE) != SECSIZE) {
-	printf("Write error\n");
-	exit(1);
-  }
-  sync();
-}
-
-#endif
-
-
-load_from_file()
-{
-/* Load buffer from file  */
-
-  char file[80];
-  int fd;
-
-  printf("Enter name of file to load from: ");
-  if (!mygets(file, (int) sizeof file)) return;
-  fd = open(file, LOAD_OPEN_MODE);
-  if (fd < 0) {
-	printf("Cannot open %s\n", file);
-	return;
-  }
-  if (read(fd, secbuf, SECSIZE) != SECSIZE || close(fd) != 0) {
-	printf("Read error\n");
-	exit(1);
-  }
-  printf("Loaded from %s OK\n", file);
-  chk_table();
-}
-
-
-save_to_file()
-{
-/* Save to file  */
-
-  char file[80];
-  int fd;
-
-  printf("Enter name of file to save to: ");
-  if (!mygets(file, (int) sizeof file)) return;
-  if(chk_table() != OK) printf("Saving anyway\n");
-  fd = creat(file, SAVE_CREAT_MODE);
-#ifdef DOS
-  if (fd < 0) {
-	printf("Cannot creat %s\n", file);
-	return;
-  }
-  close(fd);
-  fd = open(file, 0x8001);
-#endif
-  if (fd < 0)
-	printf("Cannot open %s\n", file);
-  else if (write(fd, secbuf, SECSIZE) != SECSIZE || close(fd) != 0)
-	printf("Write error\n");
-  else
-	printf("Saved to %s OK\n", file);
-}
-
-
-dpl_partitions(rawflag)
-int rawflag;
-{
-/* Display partition table */
-
-  char active[5];
-  char basefootnote;
-  int cyl_mask;
-  int devnum;
-  char *format;
-  int i;
-  int i1;
-  char orderfootnote;
-  struct part_entry *pe;
-  struct part_entry *pe1;
-  int sec_mask;
-  char sizefootnote;
-  char type[10];
-
-  badbases = 0;
-  badsizes = 0;
-  badorders = 0;
-  if (rawflag) {
-	cyl_mask = 0;		/* no contribution of cyl to sec */
-	sec_mask = 0xff;
-        format =
-"%2d   %3d%c  %4s %-9s  x%02x %3d  x%02x   x%02x %3d  x%02x %7ld%c%7ld %7ld%c\n";
-  } else {
-	cyl_mask = CYL_MASK;
-	sec_mask = SEC_MASK;
-	format =
-"%2d   %3d%c  %4s %-9s %4d %3d %3d   %4d %3d  %3d %7ld%c%7ld %7ld%c\n";
-  }
-  printf(
-"                          ----first----  -----last----  --------sectors-------\n"
-	);
-  printf(
-"Num Sorted Act  Type     Cyl Head Sec   Cyl Head Sec    Base    Last    Size\n"
-	);
-  pe = (struct part_entry *) &secbuf[PART_TABLE_OFF];
-  for (i = 1; i <= NR_PARTITIONS; i++, pe++) {
-	if (rawflag) {
-		sprintf(active, "0x%02x", pe->bootind);
-		sprintf(type, "0x%02x", pe->sysind);
-	} else {
-		sprintf(active, "%s", pe->bootind == ACTIVE_FLAG ? "A  " : "");
-		sprintf(type, "%s", systype(pe->sysind));
-	}
-
-	/* Prepare warnings about confusing setups from old versions. */
-	basefootnote = orderfootnote = sizefootnote = ' ';
-	if (pe->sysind == MINIX_PART && pe->lowsec & 1) {
-		basefootnote = '+';
-		++badbases;
-	}
-	if (pe->size & 1) {
-		sizefootnote = '-';
-		++badsizes;
-	}
-
-	/* Calculate the "device numbers" resulting from the misguided sorting
-	 * in the wini drivers.  The drivers use this conditional for
-	 * swapping wn[j] > wn[j+1]:
-	 *
-	 *	if ((wn[j].wn_low == 0 && wn[j+1].wn_low != 0) ||
-	 *	    (wn[j].wn_low > wn[j+1].wn_low && wn[j+1].wn_low != 0)) {
-	 *
-	 * which simplifies to:
-	 *
-	 *	if (wn[j+1].wn_low != 0 &&
-	 *	    (wn[j].wn_low == 0 || wn[j].wn_low > wn[j+1].wn_low)) {
-	 */
-	devnum = 1;
-	for (i1 = 1, pe1 = (struct part_entry *) &secbuf[PART_TABLE_OFF];
-	     i1 <= NR_PARTITIONS; ++i1, ++pe1)
-		if (pe1->lowsec == 0 && pe->lowsec == 0 && pe1 < pe ||
-		    pe1->lowsec != 0 &&
-		    (pe->lowsec == 0 || pe->lowsec > pe1->lowsec))
-			++devnum;	/* pe1 contents < pe contents */
-	if (devnum != i) {
-		orderfootnote = '#';
-		++badorders;
-	}
-
-	printf(format,
-		i,
-		devnum,
-		orderfootnote,
-		active,
-		type,
-		pe->start_cyl + ((pe->start_sec & cyl_mask) << CYL_SHIFT),
-		pe->start_head,
-		pe->start_sec & sec_mask,
-		pe->last_cyl + ((pe->last_sec & cyl_mask) << CYL_SHIFT),
-		pe->last_head,
-		pe->last_sec & sec_mask,
-		pe->lowsec,
-		basefootnote,
-		pe->lowsec + (pe->size == 0 ? 0 : pe->size - 1),
-		pe->size,
-		sizefootnote);
-  }
-}
-
-
-int chk_table()
-{
-/* Check partition table */
-
-  int active;
-  unsigned char cylinder;
-  unsigned char head;
-  int i;
-  int i1;
-  int maxhead;
-  int maxsec;
-  struct part_entry *pe;
-  struct part_entry *pe1;
-  unsigned char sector;
-  int seenpart;
-  int status;
-
-  active = 0;
-  maxhead = 0;
-  maxsec = 0;
-  pe = (struct part_entry *) &secbuf[PART_TABLE_OFF];
-  seenpart = 0;
-  status = OK;
-  for (i = 1; i <= NR_PARTITIONS; i++, ++pe) {
-	if (pe->bootind == ACTIVE_FLAG) active++;
-	sec_to_hst(pe->lowsec, &head, &sector, &cylinder);
-	if (pe->size == 0 && pe->lowsec == 0) sector = 0;
-	if (head != pe->start_head || sector != pe->start_sec ||
-	    cylinder != pe->start_cyl) {
-		printf("Inconsistent base in partition %d.\n", i);
-		printf("Suspect head and sector parameters.\n");
-		status = ERR;
-	}
-	if (pe->size != 0 || pe->lowsec != 0)
-	      sec_to_hst(pe->lowsec + pe->size - 1, &head, &sector, &cylinder);
-	if (head != pe->last_head || sector != pe->last_sec ||
-	    cylinder != pe->last_cyl) {
-		printf("Inconsistent size in partition %d.\n", i);
-		printf("Suspect head and sector parameters.\n");
-		status = ERR;
-	}
-	if (pe->size == 0) continue;
-	seenpart = 1;
-	for (i1 = i + 1, pe1 = pe + 1; i1 <= NR_PARTITIONS; ++i1, ++pe1) {
-		if (pe->lowsec >= pe1->lowsec &&
-		    pe->lowsec < pe1->lowsec + pe1->size ||
-		    pe->lowsec + pe->size - 1 >= pe1->lowsec &&
-		    pe->lowsec + pe->size - 1 < pe1->lowsec + pe1->size)
-		{
-			printf("Overlap between partitions %d and %d\n",
-				i, i1);
-			status = ERR;
-		}
-	}
-	if (pe->lowsec + pe->size < pe->lowsec) {
-		printf("Overflow from preposterous size in partition %d.\n",
-			i);
-		status = ERR;
-	}
-	if (maxhead < pe->start_head) maxhead = pe->start_head;
-	if (maxhead < pe->last_head) maxhead = pe->last_head;
-	if (maxsec < (pe->start_sec & SEC_MASK))
-		maxsec = (pe->start_sec & SEC_MASK);
-	if (maxsec < (pe->last_sec & SEC_MASK))
-		maxsec = (pe->last_sec & SEC_MASK);
-  }
-  if (seenpart) {
-	if (maxhead + 1 != nhead || maxsec != nsec) {
-		printf(
-	"Disk appears to have mis-specified number of heads or sectors.\n");
-		printf("Try  fdisk -h%d -s%d %s  instead of\n",
-			maxhead + 1, maxsec, devname);
-		printf("     fdisk -h%d -s%d %s\n", nhead, nsec, devname);
-		seenpart = 0;
-	}
-  } else {
-	printf(
-	"Empty table - skipping test on number of heads and sectors.\n");
-	printf("Assuming %d heads and %d sectors.\n", nhead, nsec);
-  }
-  if (!seenpart) printf("Do not write the table if you are not sure!.\n");
-  if (active > 1) {
-	printf("%d active partitions\n", active);
-	status = ERR;	
-  }
-  return(status);
-}
-
-sec_to_hst(logsec, hd, sec, cyl)
-long logsec;
-unsigned char *hd, *sec, *cyl;
-{
-/* Convert a logical sector number to  head / sector / cylinder */
-
-  int bigcyl;
-
-  bigcyl = logsec / (nhead * nsec);
-  *sec = (logsec % nsec) + 1 + ((bigcyl >> CYL_SHIFT) & CYL_MASK);
-  *cyl = bigcyl;
-  *hd = (logsec % (nhead * nsec)) / nsec;
-}
-
-mark_partition(pe)
-struct part_entry *pe;
-{
-/* Mark a partition as being of type MINIX. */
-
-  if (pe != NULL) {
-	pe->sysind = MINIX_PART;
-	printf("Partition type is now MINIX\n");
-  }
-}
-
-change_partition(entry)
-struct part_entry *entry;
-{
-/* Get partition info : first & last cylinder */
-
-  int first, last;
-  long low, high;
-  int ch;
-
-  if (entry == NULL) return;
-  while (1) {
-	if (!get_an_int("\tEnter first cylinder (an integer >= 0): ", &first))
-		return;
-	if (first >= 0) break;
-	printf("\t\tThat looks like %d which is negative\n", first);
-  }
-  while (1) {
-	if (!get_an_int(
-	"\tEnter last cylinder (an integer >= the first cylinder): ", &last))
-		return;
-	if (last >= first) break;
-	printf("\t\tThat looks like %d which is too small\n", last);
-  }
-  if (first == 0 && last == 0) {
-	entry->bootind = 0;
-	entry->start_head = 0;
-	entry->start_sec = 0;
-	entry->start_cyl = 0;
-	entry->sysind = NO_PART;
-	entry->last_head = 0;
-	entry->last_sec = 0;
-	entry->last_cyl = 0;
-	entry->lowsec = 0;
-	entry->size = 0;
-	printf("Partition deleted\n");
-	return;
-  }
-  low = first & 0xffff;
-  low = low * nsec * nhead;
-  if (low == 0) low = 1;	/* sec0 is master boot record */
-  high = last & 0xffff;
-  high = (high + 1) * nsec * nhead - 1;
-  entry->lowsec = low;
-  entry->size = high - low + 1;
-  if (entry->size & 1) {
-	/* Adjust size to even since Minix works with blocks of 2 sectors. */
-	--high;
-	--entry->size;
-	printf("Size reduced by 1 to make it even\n");
-  }
-  sec_to_hst(low, &entry->start_head, &entry->start_sec, &entry->start_cyl);
-  sec_to_hst(high, &entry->last_head, &entry->last_sec, &entry->last_cyl);
-  printf("Base of partition changed to %ld, size changed to %ld\n",
-	 entry->lowsec, entry->size);
-
-  /* Accept the MINIX partition type.  Usually ignore foreign types, so this
-   * fdisk can be used on foreign partitions.  Don't allow NO_PART, because
-   * many DOS fdisks crash on it.
-   */
-  if (entry->sysind == NO_PART) {
-	entry->sysind = MINIX_PART;
-	printf("Partition type changed from None to MINIX\n");
-  } else if (entry->sysind == MINIX_PART)
-	printf("Leaving partition type as MINIX\n");
-  else while (1) {
-	printf("\tChange partition type from %s to MINIX? (y/n) ",
-		systype(entry->sysind));
-	ch = get_a_char();
-	if (ch == 0 || ch == 'n') {
-		printf("Leaving partition type as %s\n",
-			systype(entry->sysind));
-		break;
-	} else if (ch == 'y') {
-		entry->sysind = MINIX_PART;
-		printf("Partition type changed from %s to MINIX\n",
-			systype(entry->sysind));
-		break;
-	}
-  }
-
-  if (entry->bootind == ACTIVE_FLAG)
-	printf("Leaving partition active\n");
-  else while (1) {
-	printf("\tChange partition to active? (y/n) ");
-	ch = get_a_char();
-	if (ch == 0 || ch == 'n') {
-		printf("Leaving partition inactive\n");
-		break;
-	} else if (ch == 'y') {
-		toggle_active(entry);
-		break;
-	}
-  }
-}
-
-get_a_char()
-{
-/* Read 1 character and discard rest of line */
-
-  char buf[80];
-  int ch;
-
-  if (!mygets(buf, (int) sizeof buf)) return(0);
-  return(*buf);
-}
-
-print_menu()
-{
-  printf("Type a command letter, then a carriage return:\n");
-  printf("   + - explain any footnotes (+, -, #)\n");
-  printf("   a - toggle an active flag\n");
-  printf("   B - adjust a base sector\n");
-  printf("   c - change a partition\n");
-  printf("   l - load boot block (including partition table) from a file\n");
-  printf("   m - mark a partition as a MINIX partition\n");
-  printf("   n - mark a partition as a non-MINIX partition\n");
-  printf("   p - print raw partition table\n");
-  printf("   q - quit without making any changes\n");
-  printf("   S - adjust a size (by changing the last sector)\n");
-  printf("   s - save boot block (including partition table) on a file\n");
-  printf("   t - print known partition types\n");
-  printf("   v - verify partition table\n");
- if (readonly)
-  printf("   w - write (disabled)\n");
- else
-  printf("   w - write changed partition table back to disk and exit\n");
-}
-
-
-/* Here are the DOS routines for reading and writing the boot sector. */
-
-#ifdef DOS
-
-union REGS regs;
-struct SREGS sregs;
-int drivenum;
-
-getboot(buffer)
-char *buffer;
-{
-/* Read boot sector  */
-
-  segread(&sregs);		/* get ds */
-
-  if (devname[1] != ':') {
-	printf("Invalid drive %s\n", devname);
-	exit(1);
-  }
-  if (*devname >= 'a') *devname += 'A' - 'a';
-  drivenum = (*devname - 'C') & 0xff;
-  if (drivenum < 0 || drivenum > 7) {
-	printf("Funny drive number %d\n", drivenum);
-	exit(1);
-  }
-  regs.x.ax = 0x201;		/* read 1 sectors	 */
-  regs.h.ch = 0;		/* cylinder		 */
-  regs.h.cl = 1;		/* first sector = 1	 */
-  regs.h.dh = 0;		/* head = 0		 */
-  regs.h.dl = 0x80 + drivenum;	/* drive = 0		 */
-  sregs.es = sregs.ds;		/* buffer address	 */
-  regs.x.bx = (int) buffer;
-
-  int86x(0x13, &regs, &regs, &sregs);
-  if (regs.x.cflag) {
-	printf("Cannot read boot sector\n");
-	exit(1);
-  }
-}
-
-
-putboot(buffer)
-char *buffer;
-{
-/* Write boot sector  */
-
-  regs.x.ax = 0x301;		/* read 1 sectors	 */
-  regs.h.ch = 0;		/* cylinder		 */
-  regs.h.cl = 1;		/* first sector = 1	 */
-  regs.h.dh = 0;		/* head = 0		 */
-  regs.h.dl = 0x80 + drivenum;	/* drive = 0		 */
-  sregs.es = sregs.ds;		/* buffer address	 */
-  regs.x.bx = (int) buffer;
-
-  int86x(0x13, &regs, &regs, &sregs);
-  if (regs.x.cflag) {
-	printf("Cannot write boot sector\n");
-	exit(1);
-  }
-}
-
-#endif
-
-void adj_base(pe)
-struct part_entry *pe;
-{
-/* Adjust base sector of partition, usually to make it even. */
-
-  int adj;
-
-  if (pe == NULL) return;
-  while (1) {
-	
-	if (!get_an_int("\tEnter adjustment to base (an integer): ", &adj))
-		return;
-	if (pe->lowsec + adj < 1)
-		printf(
-    "\t\tThat would make the base %d and too small\n", pe->lowsec + adj);
-	else if (pe->size - adj < 1)
-		printf(
-    "\t\tThat would make the size %d and too small\n", pe->size - adj);
-	else
-		break;
-  }
-  pe->lowsec += adj; 
-  pe->size -= adj;
-  sec_to_hst(pe->lowsec, &pe->start_head, &pe->start_sec, &pe->start_cyl);
-  printf("Base of partition adjusted to %ld, size adjusted to %ld\n",
-	 pe->lowsec, pe->size);
-}
-
-void adj_size(pe)
-struct part_entry *pe;
-{
-/* Adjust size of partition by reducing high sector. */
-
-  int adj;
-
-  if (pe == NULL) return;
-  while (1) {
-	if (!get_an_int("\tEnter adjustment to size (an integer): ", &adj))
-		return;
-	if (pe->size + adj >= 1) break;
-	printf("\t\tThat would make the size %d and too small \n",
-		pe->size + adj);
-  }
-  pe->size += adj;
-  sec_to_hst(pe->lowsec + pe->size - 1,
-	     &pe->last_head, &pe->last_sec, &pe->last_cyl);
-  printf("Size of partition adjusted to %ld\n", pe->size);
-}
-
-struct part_entry *ask_partition()
-{
-/* Ask for a valid partition number and return its entry. */
-
-  int num;
-
-  while (1) {
-	
-	if (!get_an_int("Enter partition number (1 to 4): ", &num))
-		return(NULL);
-	if (num >= 1 && num <= NR_PARTITIONS) break;
-	printf("\tThat does not look like 1 to 4\n");
-  }
-  printf("Partition %d\n", num);
-  return((struct part_entry *) &secbuf[PART_TABLE_OFF] + (num - 1));
-}
-
-void footnotes()
-{
-/* Explain the footnotes. */
-
-  if (badbases != 0) {
-	printf(
-"+ The old Minix wini drivers (before V1.5) discarded odd base sectors.\n");
-	printf(
-"  This causes some old (Minix) file systems to be offset by 1 sector.\n");
-	printf(
-"  To use these with the new drivers, increase the base by 1 using 'B'.\n");
-  }
-
-  if (badsizes != 0) {
-	if (badbases != 0) putchar('\n');
-	printf(
-"- Minix cannot access the last sector on an odd-sized partition.  This\n");
-	printf(
-"  causes trouble for programs like dosread.  This program will by default\n");
-	printf(
-"  only create partitions with even sizes.  If possible, the current odd\n");
-	printf(
-"  sizes should be decreased by 1 using 'S'.  This is safe for all Minix\n");
-	printf(
-"  partitions, and may be safe for other partitions which are about to be\n");
-	printf(
-"  reformatted.\n");
-  }
-
-  if (badorders!= 0 ) {
-	if (badbases != 0 || badsizes != 0) putchar('\n');
-	printf(
-"# The partitions are in a funny order. This is normal if they were created\n");
-	printf(
-"  by DOS fdisks prior to DOS 3.3.  The Minix wini drivers further confuse\n");
-	printf(
-"  the order by sorting the partitions on their base.  Be careful if the\n");
-	printf(
-"  device numbers of unchanged partitions have changed.\n");
-  }
-}
-
-int get_an_int(prompt, intptr)
-char *prompt;
-int *intptr;
-{
-/* Read an int from the start of line of stdin, discard rest of line. */
-
-  char buf[80];
-
-  while (1) {
-	printf("%s", prompt);
-	if (!mygets(buf, (int) sizeof buf)) return(0);
-	if ((sscanf(buf, "%d", intptr)) == 1) return(1);
-	printf("\t\tThat does not look like an integer\n");
-  }
-}
-
-void list_part_types()
-{
-/* Print all known partition types. */
-
-  int column;
-  int type;
-
-  for (column = 0, type = 0; type < 0x100; ++type)
-	if (strcmp(systype(type), "Unknown") != 0) {
-		printf("0x%02x: %-9s", type, systype(type));
-		column += 16;
-		if (column < 80)
-			putchar(' ');
-		else {
-			putchar('\n');
-			column = 0;
-		}
-	}
-  if (column != 0) putchar('\n');
-}
-
-void mark_npartition(pe)
-struct part_entry *pe;
-{
-/* Mark a partition with arbitrary type. */
-
-  char buf[80];
-  unsigned type;
-
-  if (pe == NULL) return;
-  printf("\nKnown partition types are:\n\n");
-  list_part_types();
-  while (1) {
-	printf("\nEnter partition type (in 2-digit hex): ");
-	if (!mygets(buf, (int) sizeof buf)) return;
-	if (sscanf(buf, "%x", &type) != 1)
-		printf("Invalid hex number\n");
-  	else if (type >= 0x100)
-		printf("Hex number too large\n");
-	else
-		break;
-  }
-  pe->sysind = type;
-  printf("Partition type changed to 0x%02x (%s)\n", type, systype(type));
-}
-
-int mygets(buf, length)
-char *buf;
-int length;			/* as for fgets(), but must be >= 2 */
-{
-/* Get a non-empty line of maximum length 'length'. */
-
-  while (1) {
-	fflush(stdout);
-	if (fgets(buf, length, stdin) == NULL) {
-		putchar('\n');
-		return(0);
-	}
-	if (strrchr(buf, '\n') != NULL) *strrchr(buf, '\n') = 0;
-	if (*buf != 0) return(1);
-	printf("Use the EOF character to create a null line.\n");
-	printf("Otherwise, please type something before the newline: ");
-  }
-}
-
-char *systype(type)
-int type;
-{
-/* Convert system indicator into system name. */
-/* asw 01.03.95: added types based on info in kjb's part.c and output
- * from Linux (1.0.8) fdisk. Note comments here, there are disagreements.
-*/
-  switch(type) {
-	case NO_PART: 
-	           return("None");
-	case 1:    return("DOS-12");
-	case 2:    return("XENIX");
-	case 3:    return("XENIX usr");
-	case 4:    return("DOS-16");
-	case 5:    return("DOS-EXT");
-	case 6:    return("DOS-BIG");
-	case 7:    return("HPFS");
-	case 8:    return("AIX");
-	case 9:    return("COHERENT");	/* LINUX says AIX bootable */
-	case 0x0a: return("OS/2");	/* LINUX says OPUS */
-	case 0x10: return("OPUS");
-	case 0x40: return("VENIX286");
-	case 0x51: return("NOVELL?");
-	case 0x52: return("MICROPORT");
-	case 0x63: return("386/IX");	/*LINUX calls this GNU HURD */
-	case 0x64: return("NOVELL286");
-	case 0x65: return("NOVELL386");
-	case 0x75: return("PC/IX");
-	case 0x80: return("MINIX old");
-	case 0x81: return("MINIX");
-	case 0x82: return("LINUXswap");
-	case 0x83: return("LINUX");
-	case 0x93: return("AMOEBA");
-	case 0x94: return("AMOEBAbad");
-	case 0xa5: return("386BSD");
-	case 0xb7: return("BSDI");
-	case 0xb8: return("BSDIswap");
-	case 0xc7: return("Syrinx");
-	case 0xDB: return("CP/M");
-	case 0xe1: return("DOS acc");
-	case 0xe3: return("DOS r/o");
-	case 0xf2: return("DOS 2ary");
-	case 0xFF: return("Badblocks");
-	default:   return("Unknown");
-  }
-}
-
-void toggle_active(pe)
-struct part_entry *pe;
-{
-/* Toggle active flag of a partition. */
-
-  if (pe == NULL) return;
-  pe->bootind = (pe->bootind == ACTIVE_FLAG) ? 0 : ACTIVE_FLAG;
-  printf("Partition changed to %sactive\n", pe->bootind ? "" : "in");
-}
-
-void usage()
-{
-/* Print usage message and exit. */
-
-  printf("Usage: fdisk [-hheads] [-ssectors] [device]\n");
-  exit(1);
-}
-
Index: trunk/minix/commands/ibm/format.c
===================================================================
--- trunk/minix/commands/ibm/format.c	(revision 9)
+++ 	(revision )
@@ -1,422 +1,0 @@
-/*	format 1.1 - format PC floppy disk		Author: Kees J. Bot
- *								5 Mar 1994
- */
-#define nil 0
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <limits.h>
-#include <ibm/diskparm.h>
-#include <minix/minlib.h>
-
-/* Constants. */
-#define SECTOR_SIZE	512
-#define NR_HEADS	  2
-#define MAX_SECTORS	 18	/* 1.44Mb is the largest. */
-
-/* Name error in <ibm/diskparm.h>, left over from the days floppies were
- * single sided.
- */
-#define sectors_per_track	sectors_per_cylinder
-
-/* From floppy device number to drive/type/format-bit and back.  See fd(4). */
-#define isfloppy(dev)		(((dev) & 0xFF00) == 0x0200)
-#define fl_drive(dev)		(((dev) & 0x0003) >> 0)
-#define fl_type(dev)		(((dev) & 0x007C) >> 2)
-#define fl_format(dev)		(((dev) & 0x0080) >> 7)
-#define fl_makedev(drive, type, fmt)	\
-	((dev_t) (0x0200 | ((fmt) << 7) | ((type) << 2) | ((drive) << 0)))
-
-/* Recognize floppy types. */
-#define NR_TYPES		7	/* # non-auto types */
-#define isflauto(type)		((type) == 0)
-#define isfltyped(type)		((unsigned) ((type) - 1) < NR_TYPES)
-#define isflpart(type)		((unsigned) (type) >= 28)
-
-/* Formatting parameters per type.  (Most of these parameters have no use
- * for formatting, disk_parameter_s probably matches a BIOS parameter table.)
- */
-typedef struct disk_parameter_s	fmt_params_t;
-
-typedef struct type_parameters {
-	unsigned		media_size;
-	unsigned		drive_size;
-	fmt_params_t		fmt_params;
-} type_parameters_t;
-
-#define DC	0	/* Don't care. */
-
-type_parameters_t parameters[NR_TYPES] = {
-	/* mediasize       s1     off   sec/cyl  dlen       fill    start */
-	/*       drivesize     s2   sizecode  gap    fmtgap     settle    */
-  /* pc */ {  360,  360, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* at */ { 1200, 1200, { DC, DC, DC, 2, 15, DC, DC, 0x54, 0xF6, DC, DC }},
-  /* qd */ {  360,  720, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* ps */ {  720,  720, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* pat */{  360, 1200, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* qh */ {  720, 1200, { DC, DC, DC, 2,  9, DC, DC, 0x50, 0xF6, DC, DC }},
-  /* PS */ { 1440, 1440, { DC, DC, DC, 2, 18, DC, DC, 0x54, 0xF6, DC, DC }},
-};
-
-/* Per sector ID to be sent to the controller by the driver. */
-typedef struct sector_id {
-	unsigned char	cyl;
-	unsigned char	head;
-	unsigned char	sector;
-	unsigned char	sector_size_code;
-} sector_id_t;
-
-/* Data to be "written" to the driver to format a track.  (lseek to the track
- * first.)  The first sector contains sector ID's, the second format params.
- */
-
-typedef struct track_data {
-	sector_id_t	sec_ids[SECTOR_SIZE / sizeof(sector_id_t)];
-	fmt_params_t	fmt_params;
-	char		padding[SECTOR_SIZE - sizeof(fmt_params_t)];
-} track_data_t;
-
-void report(const char *label)
-{
-	fprintf(stderr, "format: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-void format_track(int ffd, unsigned type, unsigned cyl, unsigned head)
-/* Format a single track on a floppy. */
-{
-	type_parameters_t *tparams= &parameters[type - 1];
-	track_data_t track_data;
-	off_t track_pos;
-	unsigned sector;
-	unsigned nr_sectors= tparams->fmt_params.sectors_per_track;
-	sector_id_t *sid;
-
-	memset(&track_data, 0, sizeof(track_data));
-
-	/* Set the sector id's.  (Note that sectors count from 1.) */
-	for (sector= 0; sector <= nr_sectors; sector++) {
-		sid= &track_data.sec_ids[sector];
-
-		sid->cyl= cyl;
-		sid->head= head;
-		sid->sector= sector + 1;
-		sid->sector_size_code= tparams->fmt_params.sector_size_code;
-	}
-
-	/* Format parameters. */
-	track_data.fmt_params= tparams->fmt_params;
-
-	/* Seek to the right track. */
-	track_pos= (off_t) (cyl * NR_HEADS + head) * nr_sectors * SECTOR_SIZE;
-	if (lseek(ffd, track_pos, SEEK_SET) == -1) {
-		fprintf(stderr,
-		"format: seeking to cyl %u, head %u (pos %ld) failed: %s\n",
-			cyl, head, track_pos, strerror(errno));
-		exit(1);
-	}
-
-	/* Format track. */
-	if (write(ffd, &track_data, sizeof(track_data)) < 0) {
-		fprintf(stderr,
-			"format: formatting cyl %d, head %d failed: %s\n",
-			cyl, head, strerror(errno));
-		exit(1);
-	}
-}
-
-void verify_track(int vfd, unsigned type, unsigned cyl, unsigned head)
-/* Verify a track by reading it.  On error read sector by sector. */
-{
-	type_parameters_t *tparams= &parameters[type - 1];
-	off_t track_pos;
-	unsigned sector;
-	unsigned nr_sectors= tparams->fmt_params.sectors_per_track;
-	size_t track_bytes;
-	static char buf[MAX_SECTORS * SECTOR_SIZE];
-	static unsigned bad_count;
-
-	/* Seek to the right track. */
-	track_pos= (off_t) (cyl * NR_HEADS + head) * nr_sectors * SECTOR_SIZE;
-	if (lseek(vfd, track_pos, SEEK_SET) == -1) {
-		fprintf(stderr,
-		"format: seeking to cyl %u, head %u (pos %ld) failed: %s\n",
-			cyl, head, track_pos, strerror(errno));
-		exit(1);
-	}
-
-	/* Read the track whole. */
-	track_bytes= nr_sectors * SECTOR_SIZE;
-	if (read(vfd, buf, track_bytes) == track_bytes) return;
-
-	/* An error occurred, retry sector by sector. */
-	for (sector= 0; sector < nr_sectors; sector++) {
-		if (lseek(vfd, track_pos, SEEK_SET) == -1) {
-			fprintf(stderr,
-	"format: seeking to cyl %u, head %u, sector %u (pos %ld) failed: %s\n",
-				cyl, head, sector, track_pos, strerror(errno));
-			exit(1);
-		}
-
-		switch (read(vfd, buf, SECTOR_SIZE)) {
-		case -1:
-			fprintf(stderr,
-		"format: bad sector at cyl %u, head %u, sector %u (pos %ld)\n",
-				cyl, head, sector, track_pos);
-			bad_count++;
-			break;
-		case SECTOR_SIZE:
-			/* Fine. */
-			break;
-		default:
-			fprintf(stderr, "format: short read at pos %ld\n",
-				track_pos);
-			bad_count++;
-		}
-		track_pos+= SECTOR_SIZE;
-		if (bad_count >= nr_sectors) {
-	fprintf(stderr, "format: too many bad sectors, floppy unusable\n");
-			exit(1);
-		}
-	}
-}
-
-void format_device(unsigned drive, unsigned type, int verify)
-{
-	int ffd, vfd;
-	char *fmt_dev, *ver_dev;
-	struct stat st;
-	unsigned cyl, head;
-	unsigned nr_cyls;
-	type_parameters_t *tparams= &parameters[type - 1];
-	int verbose= isatty(1);
-
-	fmt_dev= tmpnam(nil);
-
-	if (mknod(fmt_dev, S_IFCHR | 0700, fl_makedev(drive, type, 1)) < 0) {
-		fprintf(stderr, "format: making format device failed: %s\n",
-			strerror(errno));
-		exit(1);
-	}
-
-	if ((ffd= open(fmt_dev, O_WRONLY)) < 0 || fstat(ffd, &st) < 0) {
-		report(fmt_dev);
-		(void) unlink(fmt_dev);
-		exit(1);
-	}
-
-	(void) unlink(fmt_dev);
-
-	if (st.st_rdev != fl_makedev(drive, type, 1)) {
-		/* Someone is trying to trick me. */
-		exit(1);
-	}
-
-	if (verify) {
-		ver_dev= tmpnam(nil);
-
-		if (mknod(ver_dev, S_IFCHR | 0700, fl_makedev(drive, type, 0))
-									< 0) {
-			fprintf(stderr,
-				"format: making verify device failed: %s\n",
-				strerror(errno));
-			exit(1);
-		}
-
-		if ((vfd= open(ver_dev, O_RDONLY)) < 0) {
-			report(ver_dev);
-			(void) unlink(ver_dev);
-			exit(1);
-		}
-
-		(void) unlink(ver_dev);
-	}
-
-	nr_cyls= tparams->media_size * (1024 / SECTOR_SIZE) / NR_HEADS
-				/ tparams->fmt_params.sectors_per_track;
-
-	if (verbose) {
-		printf("Formatting a %uk diskette in a %uk drive\n",
-			tparams->media_size, tparams->drive_size);
-	}
-
-	for (cyl= 0; cyl < nr_cyls; cyl++) {
-		for (head= 0; head < NR_HEADS; head++) {
-			if (verbose) {
-				printf(" Cyl. %2u, Head %u\r", cyl, head);
-				fflush(stdout);
-			}
-#if __minix_vmd
-			/* After formatting a track we are too late to format
-			 * the next track.  So we can sleep at most 1/6 sec to
-			 * allow the above printf to get displayed before we
-			 * lock Minix into the floppy driver again.
-			 */
-			usleep(50000);	/* 1/20 sec will do. */
-#endif
-			format_track(ffd, type, cyl, head);
-			if (verify) verify_track(vfd, type, cyl, head);
-		}
-	}
-	if (verbose) fputc('\n', stdout);
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-		"Usage: format [-v] <device> [<media size> [<drive size>]]\n");
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	char *device;
-	unsigned drive;
-	unsigned type;
-	unsigned media_size;
-	unsigned drive_size;
-	int verify= 0;
-	struct stat st0, st;
-	FILE *mfp;
-	char special[PATH_MAX + 1], mounted_on[PATH_MAX + 1];
-	char version[10], rw_flag[10];
-
-	/* Option -v. */
-	while (argc > 1 && argv[1][0] == '-') {
-		char *p;
-
-		for (p= argv[1]; *p == '-' || *p == 'v'; p++) {
-			if (*p == 'v') verify= 1;
-		}
-		if (*p != 0) usage();
-		argc--;
-		argv++;
-		if (strcmp(argv[0], "--") == 0) break;
-	}
-
-	if (argc < 2 || argc > 4) usage();
-
-	/* Check if the caller has read-write permission.  Use the access()
-	 * call to check with the real uid & gid.  This program is usually
-	 * set-uid root.
-	 */
-	device= argv[1];
-	if (stat(device, &st0) < 0
-		|| access(device, R_OK|W_OK) < 0
-		|| stat(device, &st) < 0
-		|| (errno= EACCES, 0)	/* set errno for following tests */
-		|| st.st_dev != st0.st_dev
-		|| st.st_ino != st0.st_ino
-	) {
-		fatal(device);
-	}
-
-	if ((!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
-						|| !isfloppy(st.st_rdev)) {
-		fprintf(stderr, "format: %s: not a floppy device\n", device);
-		exit(1);
-	}
-
-	drive= fl_drive(st.st_rdev);
-	type= fl_type(st.st_rdev);
-
-	/* The drive should not be mounted. */
-	if (load_mtab("mkfs") < 0) return;
-
-	while (get_mtab_entry(special, mounted_on, version, rw_flag) == 0) {
-		if (stat(special, &st) >= 0 && isfloppy(st.st_rdev)
-					&& fl_drive(st.st_rdev) == drive) {
-			fprintf(stderr, "format: %s is mounted on %s\n",
-				device, mounted_on);
-			exit(1);
-		}
-	}
-
-	if (isflauto(type)) {
-		/* Auto type 0 requires size(s). */
-		unsigned long lmedia, ldrive;
-		char *end;
-
-		if (argc < 3) {
-			fprintf(stderr,
-			"format: no size specified for auto floppy device %s\n",
-				device);
-			usage();
-		}
-
-		lmedia= strtoul(argv[2], &end, 10);
-		if (end == argv[2] || *end != 0 || lmedia > 20 * 1024)
-			usage();
-
-		if (argc == 4) {
-			ldrive= strtoul(argv[3], &end, 10);
-			if (end == argv[3] || *end != 0 || ldrive > 20 * 1024)
-				usage();
-		} else {
-			ldrive= lmedia;
-		}
-
-		/* Silently correct wrong ordered sizes. */
-		if (lmedia > ldrive) {
-			media_size= ldrive;
-			drive_size= lmedia;
-		} else {
-			media_size= lmedia;
-			drive_size= ldrive;
-		}
-
-		/* A 1.44M drive can do 720k diskettes with no extra tricks.
-		 * Diddle with the 720k params so it is found.
-		 */
-		if (media_size == 720 && drive_size == 1440)
-			parameters[4 - 1].drive_size= 1440;
-
-		/* Translate the auto type to a known type. */
-		for (type= 1; type <= NR_TYPES; type++) {
-			if (parameters[type - 1].media_size == media_size
-				&& parameters[type - 1].drive_size == drive_size
-			) break;
-		}
-
-		if (!isfltyped(type)) {
-			fprintf(stderr,
-			"format: can't format a %uk floppy in a %uk drive\n",
-				media_size, drive_size);
-			exit(1);
-		}
-	} else
-	if (isfltyped(type)) {
-		/* No sizes needed for a non-auto type. */
-
-		if (argc > 2) {
-			fprintf(stderr,
-	"format: no sizes need to be specified for non-auto floppy device %s\n",
-				device);
-			usage();
-		}
-	} else
-	if (isflpart(type)) {
-		fprintf(stderr,
-			"format: floppy partition %s can't be formatted\n",
-			device);
-		exit(1);
-	} else {
-		fprintf(stderr,
-			"format: %s: can't format strange type %d\n",
-			device, type);
-	}
-
-	format_device(drive, type, verify);
-	exit(0);
-}
Index: trunk/minix/commands/ibm/loadfont.c
===================================================================
--- trunk/minix/commands/ibm/loadfont.c	(revision 9)
+++ 	(revision )
@@ -1,122 +1,0 @@
-/* loadfont.c - Load custom font into EGA, VGA video card
- *
- * Author: Hrvoje Stipetic (hs@hck.hr) Jun-1995.
- *
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-void tell(char *s)
-{
-  write(2, s, strlen(s));
-}
-
-char *itoa(unsigned i)
-{
-  static char a[3*sizeof(int)];
-  char *p = a+sizeof(a)-1;
-
-  do {
-	*--p = '0' + i%10;
-  } while ((i /= 10) > 0);
-
-  return p;
-}
-
-void report(char *say)
-{
-  int err = errno;
-  tell("loadfont: ");
-  if (say != NULL) {
-	tell(say);
-	tell(": ");
-  }
-  tell(strerror(err));
-  tell("\n");
-}
-
-void usage(void)
-{
-  tell("Usage: loadfont fontfile\n");
-  exit(1);
-}
-
-
-int main(int argc, char *argv[])
-{
-  static u8_t font[256][32];
-  static u8_t font_file[256 * (16+14+8) + 1];
-  u8_t *ff;
-  int fd, size, tsize, ch, ln;
-  struct winsize ws;
-
-
-  if (argc != 2)
-	usage();
-
-  if ((fd = open(argv[1], O_RDONLY)) < 0) {
-	report(argv[1]);
-	exit(1);
-  }
-
-  switch (read(fd, font_file, sizeof(font_file))) {
-  case 256 * 8:
-  	size = 8;
-  	break;
-  case 256 * 14:
-  	size = 14;
-  	break;
-  case 256 * 16:
-  	size = 16;
-  	break;
-  case 256 * (16+14+8):
-  	size = 0;
-  	break;
-  case -1:
-	report(argv[1]);
-	exit(1);
-  default:
-	tell("loadfont: ");
-	tell(argv[1]);
-	tell(": fontfile is not an 8x8, 8x14, 8x16, or compound font\n");
-	exit(1);
-  }
-  close(fd);
-
-  if (ioctl(0, TIOCGWINSZ, &ws) < 0 || (errno= ENOTTY, ws.ws_row == 0)) {
-	report(NULL);
-	exit(1);
-  }
-  tsize = ws.ws_ypixel / ws.ws_row;
-
-  if (size == 0) {
-	if (tsize >= 16) {
-		ff = font_file + 256 * (0);
-	} else
-	if (tsize >= 14) {
-		ff = font_file + 256 * (16);
-	} else {
-		ff = font_file + 256 * (16 + 14);
-	}
-	size = tsize;
-  } else {
-	ff = font_file;
-  }
-
-  for (ch = 0; ch < 256; ch++) {
-	for (ln = 0; ln < size; ln++) font[ch][ln] = ff[ch * size + ln]; 
-  }
-
-  if (ioctl(0, TIOCSFON, font) < 0) {
-	report(NULL);
-	exit(1);
-  }
-  exit(0);
-}
Index: trunk/minix/commands/ibm/loadkeys.c
===================================================================
--- trunk/minix/commands/ibm/loadkeys.c	(revision 9)
+++ 	(revision )
@@ -1,91 +1,0 @@
-/*	loadkeys - load national keyboard map		Author: Marcus Hampel
- */
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <minix/keymap.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#if __minix_vmd
-#define KBD_DEVICE	"/dev/kbd"
-#else
-#define KBD_DEVICE	"/dev/console"
-#endif
-
-u16_t keymap[NR_SCAN_CODES * MAP_COLS];
-u8_t comprmap[4 + NR_SCAN_CODES * MAP_COLS * 9/8 * 2 + 1];
-
-
-void tell(char *s)
-{
-  write(2, s, strlen(s));
-}
-
-
-void fatal(char *say)
-{
-  int err = errno;
-  tell("loadkeys: ");
-  if (say != NULL) {
-	tell(say);
-	tell(": ");
-  }
-  tell(strerror(err));
-  tell("\n");
-  exit(1);
-}
-
-
-void usage(void)
-{
-  tell("Usage: loadkeys mapfile\n");
-  exit(1);
-}
-
-
-int main(int argc, char *argv[])
-{
-  u8_t *cm;
-  u16_t *km;
-  int fd, n, fb;
-
-  if (argc != 2)
-	usage();
-
-  if ((fd = open(argv[1], O_RDONLY)) < 0) fatal(argv[1]);
-
-  if (read(fd, comprmap, sizeof(comprmap)) < 0) fatal(argv[1]);
-
-  if (memcmp(comprmap, KEY_MAGIC, 4) != 0) {
-	tell("loadkeys: ");
-	tell(argv[1]);
-	tell(": not a keymap file\n");
-	exit(1);
-  }
-  close(fd);
-
-  /* Decompress the keymap data. */
-  cm = comprmap + 4;
-  n = 8;
-  for (km = keymap; km < keymap + NR_SCAN_CODES * MAP_COLS; km++) {
-	if (n == 8) {
-		/* Need a new flag byte. */
-		fb = *cm++;
-		n = 0;
-	}
-	*km = *cm++;			/* Low byte. */
-	if (fb & (1 << n)) {
-		*km |= (*cm++ << 8);	/* One of the few special keys. */
-	}
-	n++;
-  }
-
-  if ((fd = open(KBD_DEVICE, O_WRONLY)) < 0) fatal(KBD_DEVICE);
-
-  if (ioctl(fd, KIOCSMAP, keymap) < 0) fatal(KBD_DEVICE);
-
-  return 0;
-}
Index: trunk/minix/commands/ibm/mixer.c
===================================================================
--- trunk/minix/commands/ibm/mixer.c	(revision 9)
+++ 	(revision )
@@ -1,658 +1,0 @@
-/*   
- *  mixer
- *
- *  Michel R. Prevenier.
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <curses.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <minix/sound.h>
-
-#define CURS_CTRL	'\033'
-#define ESCAPE		27
-#define UP   		'A'
-#define DOWN		'B'
-#define LEFT		'D'
-#define RIGHT		'C'
-#define SPACE		' '
-
-
-_PROTOTYPE ( int main, (int arg, char **argv));
-_PROTOTYPE ( void usage, (void));
-_PROTOTYPE ( void non_interactive, (void));
-_PROTOTYPE ( void setup_screen, (void));
-_PROTOTYPE ( int read_settings, (void));
-_PROTOTYPE ( int write_settings, (void));
-_PROTOTYPE ( void rdwr_levels, (int flag));
-_PROTOTYPE ( void rdwr_inputs, (int flag));
-_PROTOTYPE ( void rdwr_outputs, (int flag));
-_PROTOTYPE ( void create_slider, (int x, int y, enum Device device));
-_PROTOTYPE ( void show_inputs, (int x, int y));
-_PROTOTYPE ( void show_outputs, (int x, int y));
-_PROTOTYPE ( char *d_name, (enum Device device, char *name));
-_PROTOTYPE ( void user_interface, (void));
-_PROTOTYPE ( void terminate, (int s));
-
-WINDOW *main_win;
-int old_stdin;
-int fd;
-char name[9];
-char *file_name;
-struct volume_level levels[9];
-struct inout_ctrl inputs_left[9];
-struct inout_ctrl inputs_right[9];
-struct inout_ctrl outputs[9];
-
-
-void usage()
-{
-  fprintf(stderr, "Usage: mixer [-r]\n");
-  exit(-1);
-}
-
-
-void terminate(s)
-int s;
-{
-  /* Restore terminal parameters and exit */
-
-  (void) fcntl(0,F_SETFL,old_stdin);
-  move(23, 0);			
-  refresh();			
-  resetty();
-  endwin();			
-  exit(1);		
-}
-
-
-int write_settings()
-{
-  /* Write the current mixer settings to $HOME/.mixer */
-
-  int fd;
-
-  if ((fd = creat(file_name, 0x124)) > 0)
-  {
-    write(fd, levels, sizeof(levels));
-    write(fd, inputs_left, sizeof(inputs_left));
-    write(fd, inputs_right, sizeof(inputs_right));
-    write(fd, outputs, sizeof(outputs));
-    close(fd);
-    return 1;
-  }
-
-  return 0;
-}
-
-
-int read_settings()
-{
-  /* Restore mixer settings saved in $HOME/.mixer */
-
-  int fd;
-
-  if ((fd = open(file_name, O_RDONLY)) > 0)
-  {
-    read(fd, levels, sizeof(levels));
-    read(fd, inputs_left, sizeof(inputs_left));
-    read(fd, inputs_right, sizeof(inputs_right));
-    read(fd, outputs, sizeof(outputs));
-    close(fd);
-    rdwr_levels(1);
-    rdwr_outputs(1);
-    rdwr_inputs(1);
-    return 1;
-  }
-  return 0;
-}
-
-
-void rdwr_levels(flag)
-int flag;             /* 0 = read, 1 = write */
-{
-  /* Get or set mixer settings */
-
-  int i;
-  int cmd;
- 
-  cmd = (flag == 0 ? MIXIOGETVOLUME : MIXIOSETVOLUME);  
-  
-  for(i = Master; i <= Bass; i++)
-    (void) (ioctl(fd, cmd, &levels[i])); 
-}    
-
-
-void rdwr_inputs(flag)
-int flag;              /* 0 = read, 1 = write */
-{
-  /* Get or set input settings */
-
-  int i;
-  int cmd_left, cmd_right;
-  
-  cmd_left = (flag == 0 ? MIXIOGETINPUTLEFT : MIXIOSETINPUTLEFT);  
-  cmd_right = (flag == 0 ? MIXIOGETINPUTRIGHT : MIXIOSETINPUTRIGHT);  
-
-  for(i = Fm; i <= Mic; i++)
-  {
-    (void) (ioctl(fd, cmd_left, &inputs_left[i])); 
-    (void) (ioctl(fd, cmd_right, &inputs_right[i])); 
-  }
-}
-
-
-void rdwr_outputs(flag)
-int flag;               /* 0 = read, 1 = write */
-{
-  /* Get or set output settings */
-
-  int i;
-  int cmd; 
-
-  cmd = (flag == 0 ? MIXIOGETOUTPUT : MIXIOSETOUTPUT);  
-
-  for(i = Cd; i <= Mic; i++)
-    (void) (ioctl(fd, cmd, &outputs[i])); 
-}
-
-
-int main(argc, argv)
-int argc;
-char **argv;
-
-{
-  int i;
-  char *home_ptr;
-  int fd2;
-
-  /* Open mixer */
-  if ((fd = open("/dev/mixer",O_RDONLY)) < 0)
-  {
-    fprintf(stderr, "Cannot open /dev/mixer\n");
-    exit(-1);
-  }
-
-  /* Get user's home directory and construct the $HOME/.mixer
-   * file name 
-   */
-  home_ptr = getenv("HOME");
-  file_name = malloc(strlen(home_ptr)+strlen("mixer.ini\0"));
-  if (file_name == (char *)0) 
-  {
-    fprintf(stderr, "Not enough memory\n");
-    exit(-1);
-  }
-  strncpy(file_name, home_ptr, strlen(home_ptr));
-  strncpy(file_name+strlen(home_ptr), "/.mixer\0", 9);
-
-  /* Fill in the device numbers */    
-  for(i = Master; i <= Bass; i++) 
-  {
-    levels[i].device = i;
-    inputs_left[i].device = i;
-    inputs_right[i].device = i;
-    outputs[i].device = i;
-  }
-
-  /* Get arguments */
-  if (argc > 1)
-  {
-    if (strncmp(argv[1], "-r", 2) == 0)
-    {
-      if (read_settings())
-      {
-        printf("Mixer settings restored\n");
-        exit(0);
-      }
-      else
-      {
-        fprintf(stderr, "Could not restore mixer settings\n");
-        exit(-1);
-      }
-    } 
-    else usage();
-  }
-
-  /* Initialize windows. */
-  (void) initscr();
-  signal(SIGINT, terminate);
-  old_stdin = fcntl(0,F_GETFL);
-  cbreak();
-  noecho();
-  main_win = newwin(23,80,0,0);
-  scrollok(main_win, FALSE);
-
-  /* Read all current mixer settings */
-  rdwr_levels(0);
-  rdwr_inputs(0);
-  rdwr_outputs(0);
-
-  /* Set up the user screen and handle user input */
-  setup_screen();
-  user_interface();
-}
-
-
-void user_interface()
-{
-  /* This is the user interface. */
- 
-  char c;
-  int x,y;
-  int right;
-  int input_scr, input_pos;
-  int output_scr, output_pos;
-  int max_level;
-  enum Device device;
-  int fd2;
- 
-  device = Master;
-  right = 0;
-  input_scr = 0;
-  output_scr = 0;
-  input_pos = 0;
-  output_pos = 0;
-
-  while(1)
-  {
-    if (input_scr)
-    {
-      y = device + 9;
-      x = 51 + input_pos + (device == Mic ? 2 : 0);
-    }
-    else if (output_scr)
-    {
-      y = device + 15;
-      x = 53 + output_pos + (device == Mic ? 4 : 0);
-    }
-    else
-    {
-      y = (device != Speaker ? 2 : 1) + 
-          (device - (device < Treble ? 0 : Treble)) * 3 + 
-          (right == 0 ? 0 : 1);
-      if (!right)
-        x = 9 + levels[device].left / (device < Speaker ? 2 : 1 ) +
-              (device > Speaker ? 39 : 0);
-      else
-        x = 9 + levels[device].right / (device < Speaker ? 2 : 1) +
-              (device > Speaker ? 39 : 0);
-    }
-    
-    wmove(main_win,y,x);
-    wrefresh(main_win);
-    c = wgetch(main_win);
-
-    switch(c)
-    {
-      case CURS_CTRL:
-      {
-        (void) wgetch(main_win);
-        c = wgetch(main_win);
-        
-        switch(c)
-        { 
-          case DOWN: 
-          {
-           if (output_scr) 
-           {
-             if (device < Mic)
-             {
-                device++;
-                if (device == Mic) output_pos = 0;
-             }
-           }
-           else if (right || input_scr)
-           {
-             if (!input_scr)
-             {
-               if (device < Bass) 
-               {
-                 device++;         
-                 right = 0;
-               }
-               else
-               {  
-                 input_scr = 1;
-                 input_pos = 0;
-                 device = Fm;
-               }
-             }
-             else
-             {
-               if (device < Mic) 
-               {
-                 device++;
-                 if (device == Mic && input_pos > 8) input_pos = 8;
-               }
-               else 
-               { 
-                 device = Cd; 
-                 output_scr = 1; 
-                 input_scr = 0; 
-                 output_pos = 0; 
-               }
-             }
-           }
-           else 
-           {
-             if (device != Mic && device != Speaker)  right = 1;
-             else { device++; right = 0; }
-           }
-          };break;
-          case UP: 
-          {
-           if (output_scr) 
-           {
-             if (device > Cd) device--;
-             else 
-             {
-               device = Mic; 
-               output_scr = 0;
-               input_scr = 1;
-             }
-           }
-           else if (!right || input_scr)
-           {
-             if (input_scr)
-             {
-               if (device > Fm) device--;
-               else 
-               {
-                 input_scr = 0;
-                 device = Bass;
-                 right = 1;
-               }
-             }
-             else 
-             {
-               if (device > Master) 
-               {
-                 device--;         
-                 if (device != Mic && device != Speaker) right = 1;
-               }
-             }
-           }
-           else 
-             right = 0;
-          };break;
-          case RIGHT: 
-          {
-            if (output_scr) 
-            {
-              if (output_pos < 8 && device != Mic) output_pos = 8;
-            }
-            else if (!input_scr)
-            {
-              if (device < Speaker) max_level = 31;
-              else if (device > Speaker) max_level = 15;
-              else max_level = 4;
-
-              if (!right) 
-              {
-                if (levels[device].left < max_level) levels[device].left+=
-                  (device < Speaker ? 2 : 1);
-              }
-              else
-              {
-                if (levels[device].right < max_level) levels[device].right+=
-                  (device < Speaker ? 2 : 1);
-              }
-              ioctl(fd, MIXIOSETVOLUME, &levels[device]); 
-              ioctl(fd, MIXIOGETVOLUME, &levels[device]); 
-              create_slider(1 + (device < Treble ? 0 : 39), 
-                            (device - (device < Treble ? 0 : Treble))*3 +
-                            (device != Speaker ? 2 : 1), device);
-            }
-            else
-            {
-              if ((device != Mic && input_pos < 12) ||
-                  (device == Mic && input_pos < 8))
-                input_pos += (4 + (device == Mic ? 4 : 0));
-            }
-          };break;
-          case LEFT: 
-          {
-            if (output_scr)
-            {
-              if (output_pos > 0) output_pos = 0;
-            }
-            else if (!input_scr)
-            {
-              if (!right)
-              {
-                if (levels[device].left > 0) levels[device].left-=
-                  (device < Speaker ? 2 : 1);
-              }
-              else
-              {
-                if (levels[device].right > 0) levels[device].right-=
-                  (device < Speaker ? 2 : 1);
-              }
-              ioctl(fd, MIXIOSETVOLUME, &levels[device]); 
-              ioctl(fd, MIXIOGETVOLUME, &levels[device]); 
-              create_slider(1 + (device < Treble ? 0 : 39), 
-                            (device - (device < Treble ? 0 : Treble))*3 +
-                            (device != Speaker ? 2 : 1), device);
-            }
-            else
-            {
-              if (input_pos > 0) 
-                input_pos -= (4 + (device == Mic ? 4 : 0));
-            } 
-          };break;
-        } 
-      };break;
-    case SPACE:
-      {
-        if (output_scr)
-        {
-          switch(output_pos)
-          {
-            case 0:
-            case 4:
-            {
-              outputs[device].left = 
-               (outputs[device].left == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETOUTPUT, &outputs[device]);
-            };break;
-            case 8:
-            {
-              outputs[device].right = 
-               (outputs[device].right == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETOUTPUT, &outputs[device]);
-            };break;
-          }
-          ioctl(fd, MIXIOGETOUTPUT, &outputs[device]);
-          show_outputs(41,16);
-        }
-        else if (input_scr)
-        { 
-          switch(input_pos)
-          {
-            case 0:
-            {
-              inputs_left[device].left = 
-               (inputs_left[device].left == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETINPUTLEFT, &inputs_left[device]);
-            };break;
-            case 4:
-            {
-              inputs_left[device].right = 
-               (inputs_left[device].right == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETINPUTLEFT, &inputs_left[device]);
-            };break;
-            case 8:
-            {
-              inputs_right[device].left = 
-               (inputs_right[device].left == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETINPUTRIGHT, &inputs_right[device]);
-            };break;
-            case 12:
-            {
-              inputs_right[device].right = 
-               (inputs_right[device].right == ON ? OFF : ON);
-              ioctl(fd, MIXIOSETINPUTRIGHT, &inputs_right[device]);
-            };break;
-          }
-          ioctl(fd, MIXIOGETINPUTLEFT, &inputs_left[device]);
-          ioctl(fd, MIXIOGETINPUTRIGHT, &inputs_right[device]);
-          show_inputs(41,8);
-        }
-      };break;
-      case 's':
-      {
-        if (write_settings())  
-          mvwprintw(main_win,22,28, "mixer settings saved");
-        else
-          mvwprintw(main_win,22,28, "error: file not saved");
-        wrefresh(main_win);
-        sleep(1);
-        mvwprintw(main_win,22,28, "                           ");
-      };break;
-      case 'r':
-      {
-        if (read_settings())
-          mvwprintw(main_win,22,28, "mixer settings restored");
-        else
-          mvwprintw(main_win,22,28, "error: could not open");
-        wrefresh(main_win);
-        sleep(1);
-        setup_screen();
-      };break;
-      case 'e': terminate(1);
-    }
-  } 
-}
-
-
-char *d_name(device, name)
-enum Device device;
-char *name;
-{
-  /* Convert the device number to a name */
-
-  switch (device)
-  {
-    case Master:	strncpy(name, "Master  \0", 9);break;
-    case Dac:		strncpy(name, "Dac     \0", 9);break;
-    case Fm:		strncpy(name, "Fm      \0", 9);break;
-    case Cd:		strncpy(name, "CD      \0", 9);break;
-    case Line:		strncpy(name, "Line    \0", 9);break;
-    case Mic:		strncpy(name, "Mic     \0", 9);break;
-    case Speaker:	strncpy(name, "Speaker \0", 9);break;
-    case Treble:	strncpy(name, "Treble  \0", 9);break;
-    case Bass:		strncpy(name, "Bass    \0", 9);break;
-  }
-  return name;
-}
-
-
-void create_slider(x, y, device)
-int x;
-int y;
-enum Device device;
-{
-  /* Create a slider on the screen */
-
-  int left;
-  int right;
-  int i;
-
-  mvwprintw(main_win,y,x, "%s", d_name(device, name));
-
-  left = levels[device].left / (device < Speaker ? 2 : 1); 
-  right = levels[device].right / (device < Speaker ? 2 : 1); 
-
-  for (i = 0; i < 16; i++)
-  {
-    if (device != Speaker || i < 4)
-      mvwprintw(main_win,y,x+i+8, (i == left ? "*" : "-"));
-    if (device < Mic || device > Speaker) 
-      mvwprintw(main_win,y+1,x+i+8, (i == right ? "*" : "-"));
-  }
-
-  if (device < Mic || device > Speaker)
-  {
-    mvwprintw(main_win,y,x+i+10, "left");
-    mvwprintw(main_win,y+1,x+i+10, "right");
-  }
-  wrefresh(main_win);
-} 
-  
-void show_inputs(x,y)
-int x;
-int y;
-{
-  /* Show the input settings */
-
-  int i;
-
-  mvwprintw(main_win,y,x,  "             Rec-In  ");
-  mvwprintw(main_win,y+1,x,"          left    right");
-  mvwprintw(main_win,y+2,x,"          l   r   l   r");
-  for (i = Fm; i <= Line; i++)
-  {
-    mvwprintw(main_win,y+i+1,x,  "%s  %d   %d   %d   %d", 
-      d_name(i, (char *)name),
-      (inputs_left[i].left == ON ? 1 : 0),
-      (inputs_left[i].right == ON ? 1 : 0),
-      (inputs_right[i].left == ON ? 1 : 0),
-      (inputs_right[i].right == ON ? 1 : 0));
-  }
-  mvwprintw(main_win,y+i+1,x,  "%s    %d       %d", 
-    d_name(Mic, (char *)name),
-    (inputs_left[Mic].left == ON ? 1 : 0),
-    (inputs_right[Mic].left == ON ? 1 : 0));
-  wrefresh(main_win);
-}
-
-void show_outputs(x,y)
-int x;
-int y;
-{
-  /* Show the output settings */
-
-  int i;
-
-  mvwprintw(main_win,y,x,      "            Mix-Out  ");
-  mvwprintw(main_win,y+1,x,    "          left    right");
-  for (i = Cd; i <= Line; i++)
-  {
-    mvwprintw(main_win,y+i-1,x,"%s    %d       %d", 
-      d_name(i, (char *)name),
-      (outputs[i].left == ON ? 1 : 0),
-      (outputs[i].right == ON ? 1 : 0));
-  }
-  mvwprintw(main_win,y+i-1,x,"%s        %d", 
-    d_name(Mic, (char *)name),
-    (outputs[Mic].left == ON ? 1 : 0));
-
-  wrefresh(main_win);
-}
-
-
-void setup_screen()
-{
-  int i;
-
-  wclear(main_win);
-  mvwprintw(main_win,0,23,"------- Mixer Controls -------");
-  wrefresh(main_win);
- 
-  for(i = 0; i <= Speaker; i++)
-   create_slider(1, i*3+(i <= Mic ? 2 : 1), i);
-
-   create_slider(40, 2, Treble);
-   create_slider(40, 5, Bass);
- 
-   show_inputs(41,8);
-   show_outputs(41,16);
-}
Index: trunk/minix/commands/ibm/part.c
===================================================================
--- trunk/minix/commands/ibm/part.c	(revision 9)
+++ 	(revision )
@@ -1,2124 +1,0 @@
-/*	part 1.57 - Partition table editor		Author: Kees J. Bot
- *								13 Mar 1992
- * Needs about 22k heap+stack.
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdio.h>
-#include <termcap.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <time.h>
-#include <dirent.h>
-#include <limits.h>
-#include <a.out.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/ioctl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <termios.h>
-
-/* True if a partition is an extended partition. */
-#define ext_part(s)	((s) == 0x05 || (s) == 0x0F)
-
-/* Minix master bootstrap code. */
-static char MASTERBOOT[] = "/usr/mdec/masterboot";
-
-/* Template:
-                      ----first----  --geom/last--  ------sectors-----
-    Device             Cyl Head Sec   Cyl Head Sec      Base      Size        Kb
-    /dev/c0d0                          977    5  17
-    /dev/c0d0:2          0    0   2   976    4  16         2     83043     41521
-Num Sort   Type
- 0* p0   81 MINIX        0    0   3    33    4   9         3      2880      1440
- 1  p1   81 MINIX       33    4  10   178    2   2      2883     12284      6142
- 2  p2   81 MINIX      178    2   3   976    4  16     15167     67878     33939
- 3  p3   00 None         0    0   0     0    0  -1         0         0         0
-
- */
-#define MAXSIZE		999999999L	/* Will 1T be enough this year? */
-#define SECTOR_SIZE	512
-#define DEV_FD0		0x200		/* Device number of /dev/fd0 */
-#define DEV_C0D0	0x300		/* Device number of /dev/c0d0 */
-
-#define arraysize(a)	(sizeof(a) / sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-void report(const char *label)
-{
-	fprintf(stderr, "part: %s: %s\n", label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-struct termios termios;
-
-void save_ttyflags(void)
-/* Save tty attributes for later restoration. */
-{
-	if (tcgetattr(0, &termios) < 0) fatal("");
-}
-
-void restore_ttyflags(void)
-/* Reset the tty flags to how we got 'em. */
-{
-	if (tcsetattr(0, TCSANOW, &termios) < 0) fatal("");
-}
-
-void tty_raw(void)
-/* Set the terminal to raw mode, no signals, no echoing. */
-{
-	struct termios rawterm;
-
-	rawterm= termios;
-	rawterm.c_lflag &= ~(ICANON|ISIG|ECHO);
-	rawterm.c_iflag &= ~(ICRNL);
-	if (tcsetattr(0, TCSANOW, &rawterm) < 0) fatal("");
-}
-
-#define ctrl(c)		((c) == '?' ? '\177' : ((c) & '\37'))
-
-char t_cd[16], t_cm[32], t_so[16], t_se[16], t_md[16], t_me[16];
-int t_li, t_co;
-#define STATUSROW	10
-
-void init_tty(void)
-/* Get terminal capabilities and set the tty to "editor" mode. */
-{
-	char *term;
-	static char termbuf[1024];
-	char *tp;
-
-	if ((term= getenv("TERM")) == nil || tgetent(termbuf, term) != 1) {
-		fprintf(stderr, "part: Can't get terminal capabilities\n");
-		exit(1);
-	}
-	if (tgetstr("cd", (tp= t_cd, &tp)) == nil
-				|| tgetstr("cm", (tp= t_cm, &tp)) == nil) {
-		fprintf(stderr, "part: This terminal is too dumb\n");
-		exit(1);
-	}
-	t_li= tgetnum("li");
-	t_co= tgetnum("co");
-	(void) tgetstr("so", (tp= t_so, &tp));
-	(void) tgetstr("se", (tp= t_se, &tp));
-	(void) tgetstr("md", (tp= t_md, &tp));
-	(void) tgetstr("me", (tp= t_me, &tp));
-
-	save_ttyflags();
-	tty_raw();
-}
-
-void putchr(int c)
-{
-	putchar(c);
-}
-
-void putstr(char *s)
-{
-	int c;
-
-	while ((c= *s++) != 0) putchr(c);
-}
-
-void set_cursor(int row, int col)
-{
-	tputs(tgoto(t_cm, col, row), 1, putchr);
-}
-
-int statusrow= STATUSROW;
-int stat_ktl= 1;
-int need_help= 1;
-
-void stat_start(int serious)
-/* Prepare for printing on a fresh status line, possibly highlighted. */
-{
-	set_cursor(statusrow++, 0);
-	tputs(t_cd, 1, putchr);
-	if (serious) tputs(t_so, 1, putchr);
-}
-
-void stat_end(int ktl)
-/* Closing bracket for stat_start.  Sets "keystrokes to live" of message. */
-{
-	tputs(t_se, 1, putchr);
-	stat_ktl= ktl;
-	need_help= 1;
-}
-
-void stat_reset(void)
-/* Reset the statusline pointer and clear old messages if expired. */
-{
-	if (stat_ktl > 0 && --stat_ktl == 0) {
-		statusrow= STATUSROW;
-		need_help= 1;
-	}
-	if (need_help && statusrow < (24-2)) {
-		if (statusrow > STATUSROW) stat_start(0);
-		stat_start(0);
-		putstr(
-"Type '+' or '-' to change, 'r' to read, '?' for more help, 'q' to exit");
-	}
-	statusrow= STATUSROW;
-	need_help= 0;
-}
-
-void clear_screen(void)
-{
-	set_cursor(0, 0);
-	tputs(t_cd, 1, putchr);
-	stat_ktl= 1;
-	stat_reset();
-}
-
-void reset_tty(void)
-/* Reset the tty to cooked mode. */
-{
-	restore_ttyflags();
-	set_cursor(statusrow, 0);
-	tputs(t_cd, 1, putchr);
-}
-
-void *alloc(size_t n)
-{
-	void *m;
-
-	if ((m= malloc(n)) == nil) { reset_tty(); fatal(""); }
-
-	return m;
-}
-
-#ifndef makedev		/* Missing in sys/types.h */
-#define minor(dev)	(((dev) >> MINOR) & BYTE)
-#define major(dev)	(((dev) >> MAJOR) & BYTE)
-#define makedev(major, minor)	\
-			((dev_t) (((major) << MAJOR) | ((minor) << MINOR)))
-#endif
-
-typedef enum parttype { DUNNO, SUBPART, PRIMARY, FLOPPY } parttype_t;
-
-typedef struct device {
-	struct device *next, *prev;	/* Circular dequeue. */
-	dev_t	rdev;			/* Device number (sorting only). */
-	char	*name;			/* E.g. /dev/c0d0 */
-	char	*subname;		/* E.g. /dev/c0d0:2 */
-	parttype_t parttype;
-} device_t;
-
-device_t *firstdev= nil, *curdev;
-
-void newdevice(char *name, int scanning)
-/* Add a device to the device list.  If scanning is set then we are reading
- * /dev, so insert the device in device number order and make /dev/c0d0 current.
- */
-{
-	device_t *new, *nextdev, *prevdev;
-	struct stat st;
-
-	st.st_rdev= 0;
-	if (scanning) {
-		if (stat(name, &st) < 0 || !S_ISBLK(st.st_mode)) return;
-
-		switch (major(st.st_rdev)) {
-		case 2:
-			/* Floppy */
-			if (minor(st.st_rdev) >= 4) return;
-			break;
-		case 3:
-		case 8:
-		case 10:
-		case 12:
-		case 16:
-			/* Disk controller */
-			if (minor(st.st_rdev) >= 0x80
-					|| minor(st.st_rdev) % 5 != 0) return;
-			break;
-		default:
-			return;
-		}
-		/* Interesting device found. */
-	} else {
-		(void) stat(name, &st);
-	}
-
-	new= alloc(sizeof(*new));
-	new->rdev= st.st_rdev;
-	new->name= alloc((strlen(name) + 1) * sizeof(new->name[0]));
-	strcpy(new->name, name);
-	new->subname= new->name;
-	new->parttype= DUNNO;
-	if (major(st.st_rdev) == major(DEV_FD0) && minor(st.st_rdev) < 112) {
-		new->parttype= FLOPPY;
-	} else
-	if (st.st_rdev >= DEV_C0D0 && minor(st.st_rdev) < 128
-			&& minor(st.st_rdev) % 5 == 0) {
-		new->parttype= PRIMARY;
-	}
-
-	if (firstdev == nil) {
-		firstdev= new;
-		new->next= new->prev= new;
-		curdev= firstdev;
-		return;
-	}
-	nextdev= firstdev;
-	while (new->rdev >= nextdev->rdev
-				&& (nextdev= nextdev->next) != firstdev) {}
-	prevdev= nextdev->prev;
-	new->next= nextdev;
-	nextdev->prev= new;
-	new->prev= prevdev;
-	prevdev->next= new;
-
-	if (new->rdev < firstdev->rdev) firstdev= new;
-	if (new->rdev == DEV_C0D0) curdev= new;
-	if (curdev->rdev != DEV_C0D0) curdev= firstdev;
-}
-
-void getdevices(void)
-/* Get all block devices from /dev that look interesting. */
-{
-	DIR *d;
-	struct dirent *e;
-	char name[5 + NAME_MAX + 1];
-
-	if ((d= opendir("/dev")) == nil) fatal("/dev");
-
-	while ((e= readdir(d)) != nil) {
-		strcpy(name, "/dev/");
-		strcpy(name + 5, e->d_name);
-		newdevice(name, 1);
-	}
-	(void) closedir(d);
-}
-
-/* One featureful master bootstrap. */
-unsigned char bootstrap[] = {
-0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
-0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
-0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
-0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
-0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
-0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
-0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
-0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
-0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
-0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
-0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
-0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
-0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
-0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
-0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
-0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
-0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
-0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
-0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
-0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
-0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
-0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
-0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
-0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
-0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
-0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
-0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
-0000,0000,
-};
-
-int dirty= 0;
-unsigned char bootblock[SECTOR_SIZE];
-struct part_entry table[1 + NR_PARTITIONS];
-int existing[1 + NR_PARTITIONS];
-unsigned long offset= 0, extbase= 0, extsize;
-int submerged= 0;
-char sort_index[1 + NR_PARTITIONS];
-unsigned cylinders= 1, heads= 1, sectors= 1, secpcyl= 1;
-unsigned alt_cyls= 1, alt_heads= 1, alt_secs= 1;
-int precise= 0;
-int device= -1;
-
-unsigned long sortbase(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? -1 : pe->lowsec;
-}
-
-void sort(void)
-/* Let the sort_index array show the order partitions are sorted in. */
-{
-	int i, j;
-	int idx[1 + NR_PARTITIONS];
-
-	for (i= 1; i <= NR_PARTITIONS; i++) idx[i]= i;
-
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		for (j= 1; j <= NR_PARTITIONS-1; j++) {
-			int sj= idx[j], sj1= idx[j+1];
-
-			if (sortbase(&table[sj]) > sortbase(&table[sj1])) {
-				idx[j]= sj1;
-				idx[j+1]= sj;
-			}
-		}
-	}
-	for (i= 1; i <= NR_PARTITIONS; i++) sort_index[idx[i]]= i;
-}
-
-void dos2chs(unsigned char *dos, unsigned *chs)
-/* Extract cylinder, head and sector from the three bytes DOS uses to address
- * a sector.  Note that bits 8 & 9 of the cylinder number come from bit 6 & 7
- * of the sector byte.  The sector number is rebased to count from 0.
- */
-{
-	chs[0]= ((dos[1] & 0xC0) << 2) | dos[2];
-	chs[1]= dos[0];
-	chs[2]= (dos[1] & 0x3F) - 1;
-}
-
-void abs2dos(unsigned char *dos, unsigned long pos)
-/* Translate a sector offset to three DOS bytes. */
-{
-	unsigned h, c, s;
-
-	c= pos / secpcyl;
-	h= (pos % secpcyl) / sectors;
-	s= pos % sectors + 1;
-
-	dos[0]= h;
-	dos[1]= s | ((c >> 2) & 0xC0);
-	dos[2]= c & 0xFF;
-}
-
-void recompute0(void)
-/* Recompute the partition size for the device after a geometry change. */
-{
-	if (device < 0) {
-		cylinders= heads= sectors= 1;
-		memset(table, 0, sizeof(table));
-	} else
-	if (!precise && offset == 0) {
-		table[0].lowsec= 0;
-		table[0].size= (unsigned long) cylinders * heads * sectors;
-	}
-	table[0].sysind= device < 0 ? NO_PART : MINIX_PART;
-	secpcyl= heads * sectors;
-}
-
-void guess_geometry(void)
-/* With a bit of work one can deduce the disk geometry from the partition
- * table.  This may be necessary if the driver gets it wrong.  (If partition
- * tables didn't have C/H/S numbers we would not care at all...)
- */
-{
-	int i, n;
-	struct part_entry *pe;
-	unsigned chs[3];
-	unsigned long sec;
-	unsigned h, s;
-	unsigned char HS[256][8];	/* Bit map off all possible H/S */
-
-	alt_cyls= alt_heads= alt_secs= 0;
-
-	/* Initially all possible H/S combinations are possible.  HS[h][0]
-	 * bit 0 is used to rule out a head value.
-	 */
-	for (h= 1; h <= 255; h++) {
-		for (s= 0; s < 8; s++) HS[h][s]= 0xFF;
-	}
-
-	for (i= 0; i < 2*NR_PARTITIONS; i++) {
-		pe= &(table+1)[i >> 1];
-		if (pe->sysind == NO_PART) continue;
-
-		/* Get the end or start sector numbers (in that order). */
-		if ((i & 1) == 0) {
-			dos2chs(&pe->last_head, chs);
-			sec= pe->lowsec + pe->size - 1;
-		} else {
-			dos2chs(&pe->start_head, chs);
-			sec= pe->lowsec;
-		}
-
-		if (chs[0] >= alt_cyls) alt_cyls= chs[0]+1;
-
-		/* Which H/S combinations can be ruled out? */
-		for (h= 1; h <= 255; h++) {
-			if (HS[h][0] == 0) continue;
-			n = 0;
-			for (s= 1; s <= 63; s++) {
-				if ((chs[0] * h + chs[1]) * s + chs[2] != sec) {
-					HS[h][s/8] &= ~(1 << (s%8));
-				}
-				if (HS[h][s/8] & (1 << (s%8))) n++;
-			}
-			if (n == 0) HS[h][0]= 0;
-		}
-	}
-
-	/* See if only one remains. */
-	i= 0;
-	for (h= 1; h <= 255; h++) {
-		if (HS[h][0] == 0) continue;
-		for (s= 1; s <= 63; s++) {
-			if (HS[h][s/8] & (1 << (s%8))) {
-				i++;
-				alt_heads= h;
-				alt_secs= s;
-			}
-		}
-	}
-
-	/* Forget it if more than one choice... */
-	if (i > 1) alt_cyls= alt_heads= alt_secs= 0;
-}
-
-void geometry(void)
-/* Find out the geometry of the device by querying the driver, or by looking
- * at the partition table.  These numbers are crosschecked to make sure that
- * the geometry is correct.  Master bootstraps other than the Minix one use
- * the CHS numbers in the partition table to load the bootstrap of the active
- * partition.
- */
-{
-	struct stat dst;
-	int err= 0;
-	struct partition geometry;
-
-	if (submerged) {
-		/* Geometry already known. */
-		sort();
-		return;
-	}
-	precise= 0;
-	cylinders= 0;
-	recompute0();
-	if (device < 0) return;
-
-	/* Try to guess the geometry from the partition table. */
-	guess_geometry();
-
-	/* Try to get the geometry from the driver. */
-	(void) fstat(device, &dst);
-
-	if (S_ISBLK(dst.st_mode) || S_ISCHR(dst.st_mode)) {
-		/* Try to get the drive's geometry from the driver. */
-
-		if (ioctl(device, DIOCGETP, &geometry) < 0)
-			err= errno;
-		else {
-			table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
-			table[0].size= div64u(geometry.size, SECTOR_SIZE);
-			cylinders= geometry.cylinders;
-			heads= geometry.heads;
-			sectors= geometry.sectors;
-			precise= 1;
-		}
-	} else {
-		err= ENODEV;
-	}
-
-	if (err != 0) {
-		/* Getting the geometry from the driver failed, so use the
-		 * alternate geometry.
-		 */
-		if (alt_heads == 0) {
-			alt_cyls= table[0].size / (64 * 32);
-			alt_heads= 64;
-			alt_secs= 32;
-		}
-
-		cylinders= alt_cyls;
-		heads= alt_heads;
-		sectors= alt_secs;
-
-		stat_start(1);
-		printf("Failure to get the geometry of %s: %s", curdev->name,
-			errno == ENOTTY ? "No driver support" : strerror(err));
-		stat_end(5);
-		stat_start(0);
-		printf("The geometry has been guessed as %ux%ux%u",
-						cylinders, heads, sectors);
-		stat_end(5);
-	} else {
-		if (alt_heads == 0) {
-			alt_cyls= cylinders;
-			alt_heads= heads;
-			alt_secs= sectors;
-		}
-
-		if (heads != alt_heads || sectors != alt_secs) {
-			stat_start(1);
-			printf("WARNING:");
-			stat_end(10);
-			stat_start(0);
-			printf(
-"The %ux%ux%u geometry obtained from the device driver does not match",
-				cylinders, heads, sectors);
-			stat_end(10);
-			stat_start(0);
-			printf(
-"the %ux%ux%u geometry implied by the partition table.  Hit 'X' to switch",
-				alt_cyls, alt_heads, alt_secs);
-			stat_end(10);
-			stat_start(0);
-			printf(
-"between the two geometries to see what is best.  Note that the geometry");
-			stat_end(10);
-			stat_start(0);
-			printf(
-"must be correct when the table is written or the system may not boot!");
-			stat_end(10);
-		}
-	}
-
-	/* Show the base and size of the device instead of the whole drive.
-	 * This makes sense for subpartitioning primary partitions.
-	 */
-	if (precise && ioctl(device, DIOCGETP, &geometry) >= 0) {
-		table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
-		table[0].size= div64u(geometry.size, SECTOR_SIZE);
-	} else {
-		precise= 0;
-	}
-	recompute0();
-	sort();
-}
-
-typedef struct indicators {	/* Partition type to partition name. */
-	unsigned char	ind;
-	char		name[10];
-} indicators_t;
-
-indicators_t ind_table[]= {
-	{ 0x00,		"None"		},
-	{ 0x01,		"FAT-12"	},
-	{ 0x02,		"XENIX /"	},
-	{ 0x03,		"XENIX usr"	},
-	{ 0x04,		"FAT-16"	},
-	{ 0x05,		"EXTENDED"	},
-	{ 0x06,		"FAT-16"	},
-	{ 0x07,		"HPFS/NTFS"	},
-	{ 0x08,		"AIX"		},
-	{ 0x09,		"COHERENT"	},
-	{ 0x0A,		"OS/2"		},
-	{ 0x0B,		"FAT-32"	},
-	{ 0x0C,		"FAT?"		},
-	{ 0x0E,		"FAT?"		},
-	{ 0x0F,		"EXTENDED"	},
-	{ 0x10,		"OPUS"		},
-	{ 0x40,		"VENIX286"	},
-	{ 0x42,		"W2000 Dyn"	},
-	{ 0x52,		"MICROPORT"	},
-	{ 0x63,		"386/IX"	},
-	{ 0x64,		"NOVELL286"	},
-	{ 0x65,		"NOVELL386"	},
-	{ 0x75,		"PC/IX"		},
-	{ 0x80,		"MINIX-OLD"	},
-	{ 0x81,		"MINIX"		},
-	{ 0x82,		"LINUXswap"	},
-	{ 0x83,		"LINUX"		},
-	{ 0x93,		"AMOEBA"	},
-	{ 0x94,		"AMOEBAbad"	},
-	{ 0xA5,		"386BSD"	},
-	{ 0xB7,		"BSDI"		},
-	{ 0xB8,		"BSDI swap"	},
-	{ 0xC7,		"SYRINX"	},
-	{ 0xDB,		"CPM"		},
-	{ 0xFF,		"BADBLOCKS"	},
-};
-
-char *typ2txt(int ind)
-/* Translate a numeric partition indicator for human eyes. */
-{
-	indicators_t *pind;
-
-	for (pind= ind_table; pind < arraylimit(ind_table); pind++) {
-		if (pind->ind == ind) return pind->name;
-	}
-	return "";
-}
-
-int round_sysind(int ind, int delta)
-/* Find the next known partition type starting with ind in direction delta. */
-{
-	indicators_t *pind;
-
-	ind= (ind + delta) & 0xFF;
-
-	if (delta < 0) {
-		for (pind= arraylimit(ind_table)-1; pind->ind > ind; pind--) {}
-	} else {
-		for (pind= ind_table; pind->ind < ind; pind++) {}
-	}
-	return pind->ind;
-}
-
-/* Objects on the screen, either simple pieces of the text or the cylinder
- * number of the start of partition three.
- */
-typedef enum objtype {
-	O_INFO, O_TEXT, O_DEV, O_SUB,
-	O_TYPTXT, O_SORT, O_NUM, O_TYPHEX,
-	O_CYL, O_HEAD, O_SEC,
-	O_SCYL, O_SHEAD, O_SSEC, O_LCYL, O_LHEAD, O_LSEC, O_BASE, O_SIZE, O_KB
-} objtype_t;
-
-#define rjust(type)	((type) >= O_TYPHEX)
-#define computed(type)	((type) >= O_TYPTXT)
-
-typedef struct object {
-	struct object	*next;
-	objtype_t	type;		/* Text field, cylinder number, etc. */
-	char		flags;		/* Modifiable? */
-	char		row;
-	char		col;
-	char		len;
-	struct part_entry *entry;	/* What does the object refer to? */
-	char		  *text;
-	char		value[20];	/* Value when printed. */
-} object_t;
-
-#define OF_MOD		0x01	/* Object value is modifiable. */
-#define OF_ODD		0x02	/* It has a somewhat odd value. */
-#define OF_BAD		0x04	/* Its value is no good at all. */
-
-/* Events: (Keypress events are the value of the key pressed.) */
-#define E_ENTER		(-1)	/* Cursor moves onto object. */
-#define E_LEAVE		(-2)	/* Cursor leaves object. */
-#define E_WRITE		(-3)	/* Write, but not by typing 'w'. */
-
-/* The O_SIZE objects have a dual identity. */
-enum howend { SIZE, LAST } howend= SIZE;
-
-object_t *world= nil;
-object_t *curobj= nil;
-
-object_t *newobject(objtype_t type, int flags, int row, int col, int len)
-/* Make a new object given a type, flags, position and length on the screen. */
-{
-	object_t *new;
-	object_t **aop= &world;
-
-	new= alloc(sizeof(*new));
-
-	new->type= type;
-	new->flags= flags;
-	new->row= row;
-	new->col= col;
-	new->len= len;
-	new->entry= nil;
-	new->text= "";
-	new->value[0]= 0;
-
-	new->next= *aop;
-	*aop= new;
-
-	return new;
-}
-
-unsigned long entry2base(struct part_entry *pe)
-/* Return the base sector of the partition if defined. */
-{
-	return pe->sysind == NO_PART ? 0 : pe->lowsec;
-}
-
-unsigned long entry2last(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? -1 : pe->lowsec + pe->size - 1;
-}
-
-unsigned long entry2size(struct part_entry *pe)
-{
-	return pe->sysind == NO_PART ? 0 : pe->size;
-}
-
-int overlap(unsigned long sec)
-/* See if sec is part of another partition. */
-{
-	struct part_entry *pe;
-
-	for (pe= table + 1; pe <= table + NR_PARTITIONS; pe++) {
-		if (pe->sysind == NO_PART) continue;
-
-		if (pe->lowsec < sec && sec < pe->lowsec + pe->size)
-			return 1;
-	}
-	return 0;
-}
-
-int aligned(unsigned long sec, unsigned unit)
-/* True if sec is aligned to unit or if it is no problem if it is unaligned. */
-{
-	return (offset != 0 && extbase == 0) || (sec % unit == 0);
-}
-
-void print(object_t *op)
-/* Print an object's value if it changed. */
-{
-	struct part_entry *pe= op->entry;
-	int n;
-	unsigned long t;
-	char *name;
-	int oldflags;
-	char oldvalue[20];
-
-	/* Remember the old flags and value. */
-	oldflags= op->flags;
-	strcpy(oldvalue, op->value);
-
-	op->flags&= ~(OF_ODD | OF_BAD);
-
-	switch (op->type) {
-	case O_INFO:		{
-				/* Current field. */
-		static struct field { int type; char *name; } fields[]= {
-			{ O_DEV,	"Select device"		},
-			{ O_NUM,	"Active flag"		},
-			{ O_TYPHEX,	"Hex partition type"	},
-			{ O_TYPTXT,	"Partition type"	},
-			{ O_SCYL,	"Start cylinder"	},
-			{ O_SHEAD,	"Start head"		},
-			{ O_SSEC,	"Start sector"		},
-			{ O_CYL,	"Number of cylinders"	},
-			{ O_HEAD,	"Number of heads"	},
-			{ O_SEC,	"Sectors per track"	},
-			{ O_LCYL,	"Last cylinder"		},
-			{ O_LHEAD,	"Last head"		},
-			{ O_LSEC,	"Last sector"		},
-			{ O_BASE,	"Base sector"		},
-			{ O_SIZE,	"Size in sectors"	},
-			{ O_KB,		"Size in kilobytes"	},
-			{ -1,		"?"			},
-		};
-		struct field *fp= fields;
-
-		while (fp->type >= 0 && fp->type != curobj->type) fp++;
-		strcpy(op->value, fp->name);
-		op->flags|= OF_ODD;
-		break;		}
-	case O_TEXT:
-				/* Simple text field. */
-		strcpy(op->value, op->text);
-		break;
-	case O_DEV:
-	case O_SUB:
-				/* Name of currently edited device. */
-		name= op->type == O_DEV ? curdev->name :
-					offset == 0 ? "" : curdev->subname;
-		if ((n= strlen(name)) < op->len) n= op->len;
-		strcpy(op->value, name + (n - op->len));
-		if (device < 0 && op->type == O_DEV) op->flags|= OF_BAD;
-		break;
-	case O_NUM:
-				/* Position and active flag. */
-		sprintf(op->value, "%d%c", (int) (pe - table - 1),
-					pe->bootind & ACTIVE_FLAG ? '*' : ' ');
-		break;
-	case O_SORT:
-				/* Position if the driver sorts the table. */
-		sprintf(op->value, "%s%d",
-			curdev->parttype >= PRIMARY ? "p" :
-				curdev->parttype == SUBPART ? "s" : "",
-			(curdev->parttype == SUBPART ||
-				curdev->parttype == FLOPPY ? pe - table
-					: sort_index[pe - table]) - 1);
-		break;
-	case O_TYPHEX:
-				/* Hex partition type indicator. */
-		sprintf(op->value, "%02X", pe->sysind);
-		break;
-	case O_TYPTXT:
-				/* Ascii partition type indicator. */
-		strcpy(op->value, typ2txt(pe->sysind));
-		break;
-	case O_SCYL:
-				/* Partition's start cylinder. */
-		sprintf(op->value, "%lu", entry2base(pe) / secpcyl);
-		break;
-	case O_SHEAD:
-				/* Start head. */
-		t= entry2base(pe);
-		sprintf(op->value, "%lu", t % secpcyl / sectors);
-		if (!aligned(t, secpcyl) && t != table[0].lowsec + sectors)
-			op->flags|= OF_ODD;
-		break;
-	case O_SSEC:
-				/* Start sector. */
-		t= entry2base(pe);
-		sprintf(op->value, "%lu", t % sectors);
-		if (!aligned(t, sectors)) op->flags|= OF_ODD;
-		break;
-	case O_CYL:
-				/* Number of cylinders. */
-		sprintf(op->value, "%u", cylinders);
-		break;
-	case O_HEAD:
-				/* Number of heads. */
-		sprintf(op->value, "%u", heads);
-		break;
-	case O_SEC:
-				/* Number of sectors per track. */
-		sprintf(op->value, "%u", sectors);
-		break;
-	case O_LCYL:
-				/* Partition's last cylinder. */
-		t= entry2last(pe);
-		sprintf(op->value, "%lu", t == -1 ? 0 : t / secpcyl);
-		break;
-	case O_LHEAD:
-				/* Partition's last head. */
-		t= entry2last(pe);
-		sprintf(op->value, "%lu", t == -1 ? 0 : t % secpcyl / sectors);
-		if (!aligned(t + 1, secpcyl)) op->flags|= OF_ODD;
-		break;
-	case O_LSEC:
-				/* Partition's last sector. */
-		t= entry2last(pe);
-		sprintf(op->value, t == -1 ? "-1" : "%lu", t % sectors);
-		if (!aligned(t + 1, sectors)) op->flags|= OF_ODD;
-		break;
-	case O_BASE:
-				/* Partition's base sector. */
-		sprintf(op->value, "%lu", entry2base(pe));
-		if (pe->sysind != NO_PART && pe != &table[0]
-		   && (pe->lowsec <= table[0].lowsec || overlap(pe->lowsec)))
-			op->flags|= OF_BAD;
-		break;
-	case O_SIZE:
-				/* Size of partitition in sectors. */
-		t= howend == SIZE ? entry2size(pe) : entry2last(pe);
-		sprintf(op->value, "%lu", pe->sysind == NO_PART ? 0 : t);
-		if (pe->sysind != NO_PART && (pe->size == 0
-		    || pe->lowsec + pe->size > table[0].lowsec + table[0].size
-		    || overlap(pe->lowsec + pe->size)))
-			op->flags|= OF_BAD;
-		break;
-	case O_KB:
-				/* Size of partitition in kilobytes. */
-		sprintf(op->value, "%lu", entry2size(pe) / 2);
-		break;
-	default:
-		sprintf(op->value, "?? %d ??", op->type);
-	}
-
-	if (device < 0 && computed(op->type)) strcpy(op->value, "?");
-
-	/* If a value overflows the print field then show a blank
-	 * reverse video field.
-	 */
-	if ((n= strlen(op->value)) > op->len) {
-		n= 0;
-		op->flags|= OF_BAD;
-	}
-
-	/* Right or left justified? */
-	if (rjust(op->type)) {
-		memmove(op->value + (op->len - n), op->value, n);
-		memset(op->value, ' ', op->len - n);
-	} else {
-		memset(op->value + n, ' ', op->len - n);
-	}
-	op->value[op->len]= 0;
-
-	if ((op->flags & (OF_ODD | OF_BAD)) == (oldflags & (OF_ODD | OF_BAD))
-				&& strcmp(op->value, oldvalue) == 0) {
-		/* The value did not change. */
-		return;
-	}
-
-	set_cursor(op->row, rjust(op->type) ? op->col - (op->len-1) : op->col);
-
-	if (op->flags & OF_BAD) tputs(t_so, 1, putchr);
-	else
-	if (op->flags & OF_ODD) tputs(t_md, 1, putchr);
-	putstr(op->value);
-	if (op->flags & OF_BAD) tputs(t_se, 1, putchr);
-	else
-	if (op->flags & OF_ODD) tputs(t_me, 1, putchr);
-}
-
-void display(void)
-/* Repaint all objects that changed. */
-{
-	object_t *op;
-
-	for (op= world; op != nil; op= op->next) print(op);
-}
-
-int typing;	/* Set if a digit has been typed to set a value. */
-int magic;	/* Changes when using the magic key. */
-
-void event(int ev, object_t *op);
-
-void m_redraw(int ev, object_t *op)
-/* Redraw the screen. */
-{
-	object_t *op2;
-
-	if (ev != ctrl('L')) return;
-
-	clear_screen();
-	for (op2= world; op2 != nil; op2= op2->next) op2->value[0]= 0;
-}
-
-void m_toggle(int ev, object_t *op)
-/* Toggle between the driver and alternate geometry. */
-{
-	unsigned t;
-
-	if (ev != 'X') return;
-	if (alt_cyls == cylinders && alt_heads == heads && alt_secs == sectors)
-		return;
-
-	t= cylinders; cylinders= alt_cyls; alt_cyls= t;
-	t= heads; heads= alt_heads; alt_heads= t;
-	t= sectors; sectors= alt_secs; alt_secs= t;
-	dirty= 1;
-	recompute0();
-}
-
-char size_last[]= "Size";
-
-void m_orientation(int ev, object_t *op)
-{
-	if (ev != ' ') return;
-
-	switch (howend) {
-	case SIZE:
-		howend= LAST;
-		strcpy(size_last, "Last");
-		break;
-	case LAST:
-		howend= SIZE;
-		strcpy(size_last, "Size");
-	}
-}
-
-void m_move(int ev, object_t *op)
-/* Move to the nearest modifiably object in the intended direction.  Objects
- * on the same row or column are really near.
- */
-{
-	object_t *near, *op2;
-	unsigned dist, d2, dr, dc;
-
-	if (ev != 'h' && ev != 'j' && ev != 'k' && ev != 'l' && ev != 'H')
-		return;
-
-	if (device < 0) {
-		/* No device open?  Then try to read first. */
-		event('r', op);
-		if (device < 0) return;
-	}
-
-	near= op;
-	dist= -1;
-
-	for (op2= world; op2 != nil; op2= op2->next) {
-		if (op2 == op || !(op2->flags & OF_MOD)) continue;
-
-		dr= abs(op2->row - op->row);
-		dc= abs(op2->col - op->col);
-
-		d2= 25*dr*dr + dc*dc;
-		if (op2->row != op->row && op2->col != op->col) d2+= 1000;
-
-		switch (ev) {
-		case 'h':	/* Left */
-			if (op2->col >= op->col) d2= -1;
-			break;
-		case 'j':	/* Down */
-			if (op2->row <= op->row) d2= -1;
-			break;
-		case 'k':	/* Up */
-			if (op2->row >= op->row) d2= -1;
-			break;
-		case 'l':	/* Right */
-			if (op2->col <= op->col) d2= -1;
-			break;
-		case 'H':	/* Home */
-			if (op2->type == O_DEV) d2= 0;
-		}
-		if (d2 < dist) { near= op2; dist= d2; }
-	}
-	if (near != op) event(E_LEAVE, op);
-	event(E_ENTER, near);
-}
-
-void m_updown(int ev, object_t *op)
-/* Move a partition table entry up or down. */
-{
-	int i, j;
-	struct part_entry tmp;
-	int tmpx;
-
-	if (ev != ctrl('K') && ev != ctrl('J')) return;
-	if (op->entry == nil) return;
-
-	i= op->entry - table;
-	if (ev == ctrl('K')) {
-		if (i <= 1) return;
-		j= i-1;
-	} else {
-		if (i >= NR_PARTITIONS) return;
-		j= i+1;
-	}
-
-	tmp= table[i]; table[i]= table[j]; table[j]= tmp;
-	tmpx= existing[i]; existing[i]= existing[j]; existing[j]= tmpx;
-	sort();
-	dirty= 1;
-	event(ev == ctrl('K') ? 'k' : 'j', op);
-}
-
-void m_enter(int ev, object_t *op)
-/* We've moved onto this object. */
-{
-	if (ev != E_ENTER && ev != ' ' && ev != '<' && ev != '>' && ev != 'X')
-		return;
-	curobj= op;
-	typing= 0;
-	magic= 0;
-}
-
-void m_leave(int ev, object_t *op)
-/* About to leave this object. */
-{
-	if (ev != E_LEAVE) return;
-}
-
-int within(unsigned *var, unsigned low, unsigned value, unsigned high)
-/* Only set *var to value if it looks reasonable. */
-{
-	if (low <= value && value <= high) {
-		*var= value;
-		return 1;
-	} else
-		return 0;
-}
-
-int lwithin(unsigned long *var, unsigned long low, unsigned long value,
-							unsigned long high)
-{
-	if (low <= value && value <= high) {
-		*var= value;
-		return 1;
-	} else
-		return 0;
-}
-
-int nextdevice(object_t *op, int delta)
-/* Select the next or previous device from the device list. */
-{
-	dev_t rdev;
-
-	if (offset != 0) return 0;
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return 0;
-
-	if (device >= 0) {
-		(void) close(device);
-		device= -1;
-	}
-	recompute0();
-
-	rdev= curdev->rdev;
-	if (delta < 0) {
-		do
-			curdev= curdev->prev;
-		while (delta < -1 && major(curdev->rdev) == major(rdev)
-			&& curdev->rdev < rdev);
-	} else {
-		do
-			curdev= curdev->next;
-		while (delta > 1 && major(curdev->rdev) == major(rdev)
-			&& curdev->rdev > rdev);
-	}
-	return 1;
-}
-
-void check_ind(struct part_entry *pe)
-/* If there are no other partitions then make this new one active. */
-{
-	struct part_entry *pe2;
-
-	if (pe->sysind != NO_PART) return;
-
-	for (pe2= table + 1; pe2 < table + 1 + NR_PARTITIONS; pe2++)
-		if (pe2->sysind != NO_PART || pe2->bootind & ACTIVE_FLAG) break;
-
-	if (pe2 == table + 1 + NR_PARTITIONS) pe->bootind= ACTIVE_FLAG;
-}
-
-int check_existing(struct part_entry *pe)
-/* Check and if not ask if an existing partition may be modified. */
-{
-	static int expert= 0;
-	int c;
-
-	if (expert || pe == nil || !existing[pe - table]) return 1;
-
-	stat_start(1);
-	putstr("Do you wish to modify existing partitions? (y/n) ");
-	fflush(stdout);
-	while ((c= getchar()) != 'y' && c != 'n') {}
-	putchr(c);
-	stat_end(3);
-	return (expert= (c == 'y'));
-}
-
-void m_modify(int ev, object_t *op)
-/* Increment, decrement, set, or toggle the value of an object, using
- * arithmetic tricks the author doesn't understand either.
- */
-{
-	object_t *op2;
-	struct part_entry *pe= op->entry;
-	int mul, delta;
-	unsigned level= 1;
-	unsigned long surplus;
-	int radix= op->type == O_TYPHEX ? 0x10 : 10;
-	unsigned long t;
-
-	if (device < 0 && op->type != O_DEV) return;
-
-	switch (ev) {
-	case '-':
-		mul= radix; delta= -1; typing= 0;
-		break;
-	case '+':
-		mul= radix; delta= 1; typing= 0;
-		break;
-	case '\b':
-		if (!typing) return;
-		mul= 1; delta= 0;
-		break;
-	case '\r':
-		typing= 0;
-		return;
-	default:
-		if ('0' <= ev && ev <= '9')
-			delta= ev - '0';
-		else
-		if (radix == 0x10 && 'a' <= ev && ev <= 'f')
-			delta= ev - 'a' + 10;
-		else
-		if (radix == 0x10 && 'A' <= ev && ev <= 'F')
-			delta= ev - 'A' + 10;
-		else
-			return;
-
-		mul= typing ? radix*radix : 0;
-		typing= 1;
-	}
-	magic= 0;
-
-	if (!check_existing(pe)) return;
-
-	switch (op->type) {
-	case O_DEV:
-		if (ev != '-' && ev != '+') return;
-		if (!nextdevice(op, delta)) return;
-		break;
-	case O_CYL:
-		if (!within(&cylinders, 1,
-			cylinders * mul / radix + delta, 1024)) return;
-		recompute0();
-		break;
-	case O_HEAD:
-		if (!within(&heads, 1, heads * mul / radix + delta, 255))
-			return;
-		recompute0();
-		break;
-	case O_SEC:
-		if (!within(&sectors, 1, sectors * mul / radix + delta, 63))
-			return;
-		recompute0();
-		break;
-	case O_NUM:
-		if (ev != '-' && ev != '+') return;
-		for (op2= world; op2 != nil; op2= op2->next) {
-			if (op2->type == O_NUM && ev == '+')
-				op2->entry->bootind= 0;
-		}
-		op->entry->bootind= ev == '+' ? ACTIVE_FLAG : 0;
-		break;
-	case O_TYPHEX:
-		check_ind(pe);
-		pe->sysind= pe->sysind * mul / radix + delta;
-		break;
-	case O_TYPTXT:
-		if (ev != '-' && ev != '+') return;
-		check_ind(pe);
-		pe->sysind= round_sysind(pe->sysind, delta);
-		break;
-	case O_SCYL:
-		level= heads;
-	case O_SHEAD:
-		level*= sectors;
-	case O_SSEC:
-		if (op->type != O_SCYL && ev != '-' && ev != '+') return;
-	case O_BASE:
-		if (pe->sysind == NO_PART) memset(pe, 0, sizeof(*pe));
-		t= pe->lowsec;
-		surplus= t % level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		if (howend == LAST || op->type != O_BASE)
-			pe->size-= t - pe->lowsec;
-		pe->lowsec= t;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	case O_LCYL:
-		level= heads;
-	case O_LHEAD:
-		level*= sectors;
-	case O_LSEC:
-		if (op->type != O_LCYL && ev != '-' && ev != '+') return;
-
-		if (pe->sysind == NO_PART) memset(pe, 0, sizeof(*pe));
-		t= pe->lowsec + pe->size - 1 + level;
-		surplus= t % level - mul / radix * level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		pe->size= t - pe->lowsec + 1;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	case O_KB:
-		level= 2;
-		if (mul == 0) pe->size= 0;	/* new value, no surplus */
-	case O_SIZE:
-		if (pe->sysind == NO_PART) {
-			if (op->type == O_KB || howend == SIZE) {
-				/* First let loose magic to set the base. */
-				event('m', op);
-				magic= 0;
-				pe->size= 0;
-				event(ev, op);
-				return;
-			}
-			memset(pe, 0, sizeof(*pe));
-		}
-		t= (op->type == O_KB || howend == SIZE) ? pe->size
-						: pe->lowsec + pe->size - 1;
-		surplus= t % level;
-		if (!lwithin(&t, 0L,
-			(t / level * mul / radix + delta) * level + surplus,
-			MAXSIZE)) return;
-		pe->size= (op->type == O_KB || howend == SIZE) ? t :
-							t - pe->lowsec + 1;
-		check_ind(pe);
-		if (pe->sysind == NO_PART) pe->sysind= MINIX_PART;
-		break;
-	default:
-		return;
-	}
-
-	/* The order among the entries may have changed. */
-	sort();
-	dirty= 1;
-}
-
-unsigned long spell[3 + 4 * (1+NR_PARTITIONS)];
-int nspells;
-objtype_t touching;
-
-void newspell(unsigned long charm)
-/* Add a new spell, descending order for the base, ascending for the size. */
-{
-	int i, j;
-
-	if (charm - table[0].lowsec > table[0].size) return;
-
-	for (i= 0; i < nspells; i++) {
-		if (charm == spell[i]) return;	/* duplicate */
-
-		if (touching == O_BASE) {
-			if (charm == table[0].lowsec + table[0].size) return;
-			if ((spell[0] - charm) < (spell[0] - spell[i])) break;
-		} else {
-			if (charm == table[0].lowsec) return;
-			if ((charm - spell[0]) < (spell[i] - spell[0])) break;
-		}
-	}
-	for (j= ++nspells; j > i; j--) spell[j]= spell[j-1];
-	spell[i]= charm;
-}
-
-void m_magic(int ev, object_t *op)
-/* Apply magic onto a base or size number. */
-{
-	struct part_entry *pe= op->entry, *pe2;
-	int rough= (offset != 0 && extbase == 0);
-
-	if (ev != 'm' || device < 0) return;
-	typing= 0;
-
-	if (!check_existing(pe)) return;
-
-	if (magic == 0) {
-		/* See what magic we can let loose on this value. */
-		nspells= 1;
-
-		/* First spell, the current value. */
-		switch (op->type) {
-		case O_SCYL:
-		case O_SHEAD:	/* Start of partition. */
-		case O_SSEC:
-		case O_BASE:
-			touching= O_BASE;
-			spell[0]= pe->lowsec;
-			break;
-		case O_LCYL:
-		case O_LHEAD:
-		case O_LSEC:	/* End of partition. */
-		case O_KB:
-		case O_SIZE:
-			touching= O_SIZE;
-			spell[0]= pe->lowsec + pe->size;
-			break;
-		default:
-			return;
-		}
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-			check_ind(pe);
-			pe->sysind= MINIX_PART;
-			spell[0]= 0;
-			if (touching == O_SIZE) {
-				/* First let loose magic on the base. */
-				object_t *op2;
-
-				for (op2= world; op2 != nil; op2= op2->next) {
-					if (op2->row == op->row &&
-							op2->type == O_BASE) {
-						event('m', op2);
-					}
-				}
-				magic= 0;
-				event('m', op);
-				return;
-			}
-		}
-		/* Avoid the first sector on the device. */
-		if (spell[0] == table[0].lowsec) newspell(spell[0] + 1);
-
-		/* Further interesting values are the the bases of other
-		 * partitions or their ends.
-		 */
-		for (pe2= table; pe2 < table + 1 + NR_PARTITIONS; pe2++) {
-			if (pe2 == pe || pe2->sysind == NO_PART) continue;
-			if (pe2->lowsec == table[0].lowsec)
-				newspell(table[0].lowsec + 1);
-			else
-				newspell(pe2->lowsec);
-			newspell(pe2->lowsec + pe2->size);
-			if (touching == O_BASE && howend == SIZE) {
-				newspell(pe2->lowsec - pe->size);
-				newspell(pe2->lowsec + pe2->size - pe->size);
-			}
-			if (pe2->lowsec % sectors != 0) rough= 1;
-		}
-		/* Present values rounded up to the next cylinder unless
-		 * the table is already a mess.  Use "start + 1 track" instead
-		 * of "start + 1 cylinder".  Also add the end of the last
-		 * cylinder.
-		 */
-		if (!rough) {
-			unsigned long n= spell[0];
-			if (n == table[0].lowsec) n++;
-			n= (n + sectors - 1) / sectors * sectors;
-			if (n != table[0].lowsec + sectors)
-				n= (n + secpcyl - 1) / secpcyl * secpcyl;
-			newspell(n);
-			if (touching == O_SIZE)
-				newspell(table[0].size / secpcyl * secpcyl);
-		}
-	}
-	/* Magic has been applied, a spell needs to be chosen. */
-
-	if (++magic == nspells) magic= 0;
-
-	if (touching == O_BASE) {
-		if (howend == LAST) pe->size-= spell[magic] - pe->lowsec;
-		pe->lowsec= spell[magic];
-	} else
-		pe->size= spell[magic] - pe->lowsec;
-
-	/* The order among the entries may have changed. */
-	sort();
-	dirty= 1;
-}
-
-typedef struct diving {
-	struct diving	*up;
-	struct part_entry  old0;
-	char		*oldsubname;
-	parttype_t	oldparttype;
-	unsigned long	oldoffset;
-	unsigned long	oldextbase;
-} diving_t;
-
-diving_t *diving= nil;
-
-void m_in(int ev, object_t *op)
-/* Go down into a primary or extended partition. */
-{
-	diving_t *newdiv;
-	struct part_entry *pe= op->entry, ext;
-	int n;
-
-	if (ev != '>' || device < 0 || pe == nil || pe == &table[0]
-		|| (!(pe->sysind == MINIX_PART && offset == 0)
-					&& !ext_part(pe->sysind))
-		|| pe->size == 0) return;
-
-	ext= *pe;
-	if (extbase != 0) ext.size= extbase + extsize - ext.lowsec;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return;
-	if (device >= 0) { close(device); device= -1; }
-
-	newdiv= alloc(sizeof(*newdiv));
-	newdiv->old0= table[0];
-	newdiv->oldsubname= curdev->subname;
-	newdiv->oldparttype= curdev->parttype;
-	newdiv->oldoffset= offset;
-	newdiv->oldextbase= extbase;
-	newdiv->up= diving;
-	diving= newdiv;
-
-	table[0]= ext;
-
-	n= strlen(diving->oldsubname);
-	curdev->subname= alloc((n + 3) * sizeof(curdev->subname[0]));
-	strcpy(curdev->subname, diving->oldsubname);
-	curdev->subname[n++]= ':';
-	curdev->subname[n++]= '0' + (pe - table - 1);
-	curdev->subname[n]= 0;
-
-	curdev->parttype= curdev->parttype == PRIMARY ? SUBPART : DUNNO;
-	offset= ext.lowsec;
-	if (ext_part(ext.sysind) && extbase == 0) {
-		extbase= ext.lowsec;
-		extsize= ext.size;
-		curdev->parttype= DUNNO;
-	}
-
-	submerged= 1;
-	event('r', op);
-}
-
-void m_out(int ev, object_t *op)
-/* Go up from an extended or subpartition table to its enclosing. */
-{
-	diving_t *olddiv;
-
-	if (ev != '<' || diving == nil) return;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) return;
-	if (device >= 0) { close(device); device= -1; }
-
-	olddiv= diving;
-	diving= olddiv->up;
-
-	table[0]= olddiv->old0;
-
-	free(curdev->subname);
-	curdev->subname= olddiv->oldsubname;
-
-	curdev->parttype= olddiv->oldparttype;
-	offset= olddiv->oldoffset;
-	extbase= olddiv->oldextbase;
-
-	free(olddiv);
-
-	event('r', op);
-	if (diving == nil) submerged= 0;	/* We surfaced. */
-}
-
-void installboot(unsigned char *bootblock, char *masterboot)
-/* Install code from a master bootstrap into a boot block. */
-{
-	FILE *mfp;
-	struct exec hdr;
-	int n;
-	char *err;
-
-	if ((mfp= fopen(masterboot, "r")) == nil) {
-		err= strerror(errno);
-		goto m_err;
-	}
-
-	n= fread(&hdr, sizeof(char), A_MINHDR, mfp);
-	if (ferror(mfp)) {
-		err= strerror(errno);
-		fclose(mfp);
-		goto m_err;
-	}
-
-	if (n < A_MINHDR || BADMAG(hdr) || hdr.a_cpu != A_I8086) {
-		err= "Not an 8086 executable";
-		fclose(mfp);
-		goto m_err;
-	}
-
-	if (hdr.a_text + hdr.a_data > PART_TABLE_OFF) {
-		err= "Does not fit in a boot sector";
-		fclose(mfp);
-		goto m_err;
-	}
-
-	fseek(mfp, hdr.a_hdrlen, 0);
-	fread(bootblock, sizeof(char), (size_t) (hdr.a_text + hdr.a_data), mfp);
-	if (ferror(mfp)) {
-		err= strerror(errno);
-		fclose(mfp);
-		goto m_err;
-	}
-	fclose(mfp);
-
-	/* Bootstrap installed. */
-	return;
-
-    m_err:
-	stat_start(1);
-	printf("%s: %s", masterboot, err);
-	stat_end(5);
-}
-
-ssize_t boot_readwrite(int rw)
-/* Read (0) or write (1) the boot sector. */
-{
-	u64_t off64 = mul64u(offset, SECTOR_SIZE);
-	int r;
-
-#if __minix_vmd
-	/* Minix-vmd has a 64 bit seek. */
-	if (fcntl(device, F_SEEK, off64) < 0) return -1;
-#else
-	/* Minix has to gross things with the partition base. */
-	struct partition geom0, geom_seek;
-
-	if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) {
-		/* Move partition base. */
-		if (ioctl(device, DIOCGETP, &geom0) < 0) return -1;
-		geom_seek.base = add64(geom0.base, off64);
-		geom_seek.size = cvu64(cmp64(add64u(off64, SECTOR_SIZE),
-			geom0.size) <= 0 ? _STATIC_BLOCK_SIZE : 0);
-		sync();
-		if (ioctl(device, DIOCSETP, &geom_seek) < 0) return -1;
-		if (lseek(device, (off_t) 0, SEEK_SET) == -1) return -1;
-	} else {
-		/* Can reach this point normally. */
-		if (lseek(device, (off_t) offset * SECTOR_SIZE, SEEK_SET) == -1)
-			return -1;
-	}
-#endif
-
-	switch (rw) {
-	case 0:	r= read(device, bootblock, SECTOR_SIZE);	break;
-	case 1:	r= write(device, bootblock, SECTOR_SIZE);	break;
-	}
-
-#if !__minix_vmd
-	if (offset >= (LONG_MAX / SECTOR_SIZE - 1)) {
-		/* Restore partition base and size. */
-		sync();
-		if (ioctl(device, DIOCSETP, &geom0) < 0) return -1;
-	}
-#endif
-	return r;
-}
-
-void m_read(int ev, object_t *op)
-/* Read the partition table from the current device. */
-{
-	int i, mode, n;
-	struct part_entry *pe;
-
-	if (ev != 'r' || device >= 0) return;
-
-	/* Open() may cause kernel messages: */
-	stat_start(0);
-	fflush(stdout);
-
-	if (((device= open(curdev->name, mode= O_RDWR, 0666)) < 0
-		&& (errno != EACCES
-			|| (device= open(curdev->name, mode= O_RDONLY)) < 0))
-	) {
-		stat_start(1);
-		printf("%s: %s", curdev->name, strerror(errno));
-		stat_end(5);
-		if (device >= 0) { close(device); device= -1; }
-		return;
-	}
-
-	/* Assume up to five lines of kernel messages. */
-	statusrow+= 5-1;
-	stat_end(5);
-
-	if (mode == O_RDONLY) {
-		stat_start(1);
-		printf("%s: Readonly", curdev->name);
-		stat_end(5);
-	}
-	memset(bootblock, 0, sizeof(bootblock));
-
-	n= boot_readwrite(0);
-
-	if (n <= 0) stat_start(1);
-	if (n < 0) {
-		printf("%s: %s", curdev->name, strerror(errno));
-		close(device);
-		device= -1;
-	} else
-	if (n < SECTOR_SIZE) printf("%s: Unexpected EOF", curdev->subname);
-	if (n <= 0) stat_end(5);
-
-	if (n < SECTOR_SIZE) n= SECTOR_SIZE;
-
-	memcpy(table+1, bootblock+PART_TABLE_OFF,
-					NR_PARTITIONS * sizeof(table[1]));
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		if ((table[i].bootind & ~ACTIVE_FLAG) != 0) break;
-	}
-	if (i <= NR_PARTITIONS || bootblock[510] != 0x55
-				|| bootblock[511] != 0xAA) {
-		/* Invalid boot block, install bootstrap, wipe partition table.
-		 */
-		memset(bootblock, 0, sizeof(bootblock));
-		installboot(bootblock, MASTERBOOT);
-		memset(table+1, 0, NR_PARTITIONS * sizeof(table[1]));
-		stat_start(1);
-		printf("%s: Invalid partition table (reset)", curdev->subname);
-		stat_end(5);
-	}
-
-	/* Fix an extended partition table up to something mere mortals can
-	 * understand.  Record already defined partitions.
-	 */
-	for (i= 1; i <= NR_PARTITIONS; i++) {
-		pe= &table[i];
-		if (extbase != 0 && pe->sysind != NO_PART)
-			pe->lowsec+= ext_part(pe->sysind) ? extbase : offset;
-		existing[i]= pe->sysind != NO_PART;
-	}
-	geometry();
-	dirty= 0;
-
-	/* Warn about grave dangers ahead. */
-	if (extbase != 0) {
-		stat_start(1);
-		printf("Warning: You are in an extended partition.");
-		stat_end(5);
-	}
-}
-
-void m_write(int ev, object_t *op)
-/* Write the partition table back if modified. */
-{
-	int c;
-	struct part_entry new_table[NR_PARTITIONS], *pe;
-
-	if (ev != 'w' && ev != E_WRITE) return;
-	if (device < 0) { dirty= 0; return; }
-	if (!dirty) {
-		if (ev == 'w') {
-			stat_start(1);
-			printf("%s is not changed, or has already been written",
-							curdev->subname);
-			stat_end(2);
-		}
-		return;
-	}
-
-	if (bootblock[510] != 0x55 || bootblock[511] != 0xAA) {
-		/* Invalid boot block, warn user. */
-		stat_start(1);
-		printf("Warning: About to write a new table on %s",
-							curdev->subname);
-		stat_end(5);
-	}
-	if (extbase != 0) {
-		/* Will this stop the luser?  Probably not... */
-		stat_start(1);
-		printf("You have changed an extended partition.  Bad Idea.");
-		stat_end(5);
-	}
-	stat_start(1);
-	putstr("Save partition table? (y/n) ");
-	fflush(stdout);
-
-	while ((c= getchar()) != 'y' && c != 'n' && c != ctrl('?')) {}
-
-	if (c == ctrl('?')) putstr("DEL"); else putchr(c);
-	stat_end(5);
-	if (c == 'n' && ev == E_WRITE) dirty= 0;
-	if (c != 'y') return;
-
-	memcpy(new_table, table+1, NR_PARTITIONS * sizeof(table[1]));
-	for (pe= new_table; pe < new_table + NR_PARTITIONS; pe++) {
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-		} else {
-			abs2dos(&pe->start_head, pe->lowsec);
-			abs2dos(&pe->last_head, pe->lowsec + pe->size - 1);
-
-			/* Fear and loathing time: */
-			if (extbase != 0)
-				pe->lowsec-= ext_part(pe->sysind)
-						? extbase : offset;
-		}
-	}
-	memcpy(bootblock+PART_TABLE_OFF, new_table, sizeof(new_table));
-	bootblock[510]= 0x55;
-	bootblock[511]= 0xAA;
-
-	if (boot_readwrite(1) < 0) {
-		stat_start(1);
-		printf("%s: %s", curdev->name, strerror(errno));
-		stat_end(5);
-		return;
-	}
-	dirty= 0;
-}
-
-void m_shell(int ev, object_t *op)
-/* Shell escape, to do calculations for instance. */
-{
-	int r, pid, status;
-	void (*sigint)(int), (*sigquit)(int), (*sigterm)(int);
-
-	if (ev != 's') return;
-
-	reset_tty();
-	fflush(stdout);
-
-	switch (pid= fork()) {
-	case -1:
-		stat_start(1);
-		printf("can't fork: %s\n", strerror(errno));
-		stat_end(3);
-		break;
-	case 0:
-		if (device >= 0) (void) close(device);
-		execl("/bin/sh", "sh", (char *) nil);
-		r= errno;
-		stat_start(1);
-		printf("/bin/sh: %s\n", strerror(errno));
-		stat_end(3);
-		exit(127);
-	}
-	sigint= signal(SIGINT, SIG_IGN);
-	sigquit= signal(SIGQUIT, SIG_IGN);
-	sigterm= signal(SIGTERM, SIG_IGN);
-	while (pid >= 0 && (r= wait(&status)) >= 0 && r != pid) {}
-	(void) signal(SIGINT, sigint);
-	(void) signal(SIGQUIT, sigquit);
-	(void) signal(SIGTERM, sigterm);
-	tty_raw();
-	if (pid < 0)
-		;
-	else
-	if (WIFEXITED(status) && WEXITSTATUS(status) == 127)
-		stat_start(0);	/* Match the stat_start in the child. */
-	else
-		event(ctrl('L'), op);
-}
-
-void m_dump(int ev, object_t *op)
-/* Raw dump of the partition table. */
-{
-	struct part_entry table[NR_PARTITIONS], *pe;
-	int i;
-	unsigned chs[3];
-
-	if (ev != 'p' || device < 0) return;
-
-	memcpy(table, bootblock+PART_TABLE_OFF,
-					NR_PARTITIONS * sizeof(table[0]));
-	for (i= 0; i < NR_PARTITIONS; i++) {
-		pe= &table[i];
-		stat_start(0);
-		dos2chs(&pe->start_head, chs);
-		printf("%2d%c      %02X%15d%5d%4d",
-			i+1,
-			pe->bootind & ACTIVE_FLAG ? '*' : ' ',
-			pe->sysind,
-			chs[0], chs[1], chs[2]);
-		dos2chs(&pe->last_head, chs);
-		printf("%6d%5d%4d%10lu%10ld%9lu",
-			chs[0], chs[1], chs[2],
-			pe->lowsec,
-			howend == SIZE ? pe->size : pe->size + pe->lowsec - 1,
-			pe->size / 2);
-		stat_end(10);
-	}
-	stat_start(0);
-	printf("(Raw dump of the original %.40s table)",
-		curdev->subname);
-	stat_end(10);
-}
-
-int quitting= 0;
-
-void m_quit(int ev, object_t *op)
-/* Write the partition table if modified and exit. */
-{
-	if (ev != 'q' && ev != 'x') return;
-
-	quitting= 1;
-
-	if (dirty) event(E_WRITE, op);
-	if (dirty) quitting= 0;
-}
-
-void m_help(int ev, object_t *op)
-/* For people without a clue; let's hope they can find the '?' key. */
-{
-	static struct help {
-		char	*keys;
-		char	*what;
-	} help[]= {
-	 { "? !",		 "This help / more advice!" },
-	 { "+ - (= _ PgUp PgDn)","Select/increment/decrement/make active" },
-	 { "0-9 (a-f)",		 "Enter value" },
-	 { "hjkl (arrow keys)",	 "Move around" },
-	 { "CTRL-K CTRL-J",	 "Move entry up/down" },
-	 { "CTRL-L",		 "Redraw screen" },
-	 { ">",			 "Start a subpartition table" },
-	 { "<",			 "Back to the primary partition table" },
-	 { "m",			 "Cycle through magic values" },
-	 { "spacebar",		 "Show \"Size\" or \"Last\"" },
-	 { "r w",		 "Read/write partition table" },
-	 { "p s q x",		 "Raw dump / Shell escape / Quit / Exit" },
-	 { "y n DEL",		 "Answer \"yes\", \"no\", \"cancel\"" },
-	};
-	static char *advice[] = {
-"* Choose a disk with '+' and '-', then hit 'r'.",
-"* To change any value: Move to it and use '+', '-' or type the desired value.",
-"* To make a new partition:  Move over to the Size or Kb field of an unused",
-"  partition and type the size.  Hit the 'm' key to pad the partition out to",
-"  a cylinder boundary.  Hit 'm' again to pad it out to the end of the disk.",
-"  You can hit 'm' more than once on a base or size field to see several",
-"  interesting values go by.  Note: Other Operating Systems can be picky about",
-"  partitions that are not padded to cylinder boundaries.  Look for highlighted",
-"  head or sector numbers.",
-"* To reuse a partition:  Change the type to MINIX.",
-"* To delete a partition:  Type a zero in the hex Type field.",
-"* To make a partition active:  Type '+' in the Num field.",
-"* To study the list of keys:  Type '?'.",
-	};
-
-	if (ev == '?') {
-		struct help *hp;
-
-		for (hp= help; hp < arraylimit(help); hp++) {
-			stat_start(0);
-			printf("%-25s - %s", hp->keys, hp->what);
-			stat_end(0);
-		}
-		stat_start(0);
-		putstr("Things like ");
-		putstr(t_so); putstr("this"); putstr(t_se);
-		putstr(" must be checked, but ");
-		putstr(t_md); putstr("this"); putstr(t_me);
-		putstr(" is not really a problem");
-		stat_end(0);
-	} else
-	if (ev == '!') {
-		char **ap;
-
-		for (ap= advice; ap < arraylimit(advice); ap++) {
-			stat_start(0);
-			putstr(*ap);
-			stat_end(0);
-		}
-	}
-}
-
-void event(int ev, object_t *op)
-/* Simply call all modifiers for an event, each one knows when to act. */
-{
-	m_help(ev, op);
-	m_redraw(ev, op);
-	m_toggle(ev, op);
-	m_orientation(ev, op);
-	m_move(ev, op);
-	m_updown(ev, op);
-	m_enter(ev, op);
-	m_leave(ev, op);
-	m_modify(ev, op);
-	m_magic(ev, op);
-	m_in(ev, op);
-	m_out(ev, op);
-	m_read(ev, op);
-	m_write(ev, op);
-	m_shell(ev, op);
-	m_dump(ev, op);
-	m_quit(ev, op);
-}
-
-int keypress(void)
-/* Get a single keypress.  Translate compound keypresses (arrow keys) to
- * their simpler equivalents.
- */
-{
-	char ch;
-	int c;
-	int esc= 0;
-
-	set_cursor(curobj->row, curobj->col);
-	fflush(stdout);
-
-	do {
-		if (read(0, &ch, sizeof(ch)) < 0) fatal("stdin");
-		c= (unsigned char) ch;
-		switch (esc) {
-		case 0:
-			switch (c) {
-			case ctrl('['):	esc= 1; break;
-			case '_':	c= '-'; break;
-			case '=':	c= '+'; break;
-			}
-			break;
-		case 1:
-			esc= c == '[' ? 2 : 0;
-			break;
-		case 2:
-			switch (c) {
-			case 'D':	c= 'h';	break;
-			case 'B':	c= 'j';	break;
-			case 'A':	c= 'k';	break;
-			case 'C':	c= 'l';	break;
-			case 'H':	c= 'H';	break;
-			case 'U':
-			case 'S':	c= '-';	break;
-			case 'V':
-			case 'T':	c= '+';	break;
-			}
-			/*FALL THROUGH*/
-		default:
-			esc= 0;
-		}
-	} while (esc > 0);
-
-	switch (c) {
-	case ctrl('B'):	c= 'h';	break;
-	case ctrl('N'):	c= 'j';	break;
-	case ctrl('P'):	c= 'k';	break;
-	case ctrl('F'):	c= 'l';	break;
-	}
-
-	return c;
-}
-
-void mainloop(void)
-/* Get keypress, handle event, display results, reset screen, ad infinitum. */
-{
-	int key;
-
-	while (!quitting) {
-		stat_reset();
-
-		key= keypress();
-
-		event(key, curobj);
-
-		display();
-	}
-}
-
-int main(int argc, char **argv)
-{
-	object_t *op;
-	int i, r, key;
-	struct part_entry *pe;
-
-	/* Define a few objects to show on the screen.  First text: */
-	op= newobject(O_INFO, 0, 0,  2, 19);
-	op= newobject(O_TEXT, 0, 0, 22, 13); op->text= "----first----";
-	op= newobject(O_TEXT, 0, 0, 37, 13); op->text= "--geom/last--";
-	op= newobject(O_TEXT, 0, 0, 52, 18); op->text= "------sectors-----";
-	op= newobject(O_TEXT, 0, 1,  4,  6); op->text= "Device";
-	op= newobject(O_TEXT, 0, 1, 23, 12); op->text= "Cyl Head Sec";
-	op= newobject(O_TEXT, 0, 1, 38, 12); op->text= "Cyl Head Sec";
-	op= newobject(O_TEXT, 0, 1, 56,  4); op->text= "Base";
-	op= newobject(O_TEXT, 0, 1, 66,  4); op->text= size_last;
-	op= newobject(O_TEXT, 0, 1, 78,  2); op->text= "Kb";
-	op= newobject(O_TEXT, 0, 4,  0, 15); op->text= "Num Sort   Type";
-
-	/* The device is the current object: */
-    curobj= newobject(O_DEV,  OF_MOD, 2,  4, 15);
-	op= newobject(O_SUB,       0, 3,  4, 15);
-
-	/* Geometry: */
-	op= newobject(O_CYL,  OF_MOD, 2, 40,  5); op->entry= &table[0];
-	op= newobject(O_HEAD, OF_MOD, 2, 45,  3); op->entry= &table[0];
-	op= newobject(O_SEC,  OF_MOD, 2, 49,  2); op->entry= &table[0];
-
-	/* Objects for the device: */
-	op= newobject(O_SCYL,  0, 3, 25,  5); op->entry= &table[0];
-	op= newobject(O_SHEAD, 0, 3, 30,  3); op->entry= &table[0];
-	op= newobject(O_SSEC,  0, 3, 34,  2); op->entry= &table[0];
-	op= newobject(O_LCYL,  0, 3, 40,  5); op->entry= &table[0];
-	op= newobject(O_LHEAD, 0, 3, 45,  3); op->entry= &table[0];
-	op= newobject(O_LSEC,  0, 3, 49,  2); op->entry= &table[0];
-	op= newobject(O_BASE,  0, 3, 59,  9); op->entry= &table[0];
-	op= newobject(O_SIZE,  0, 3, 69,  9); op->entry= &table[0];
-	op= newobject(O_KB,    0, 3, 79,  9); op->entry= &table[0];
-
-	/* Objects for each partition: */
-	for (r= 5, pe= table+1; pe <= table+NR_PARTITIONS; r++, pe++) {
-		op= newobject(O_NUM,    OF_MOD, r,  1,  2); op->entry= pe;
-		op= newobject(O_SORT,        0, r,  5,  2); op->entry= pe;
-		op= newobject(O_TYPHEX, OF_MOD, r, 10,  2); op->entry= pe;
-		op= newobject(O_TYPTXT, OF_MOD, r, 12,  9); op->entry= pe;
-		op= newobject(O_SCYL,   OF_MOD, r, 25,  5); op->entry= pe;
-		op= newobject(O_SHEAD,  OF_MOD, r, 30,  3); op->entry= pe;
-		op= newobject(O_SSEC,   OF_MOD, r, 34,  2); op->entry= pe;
-		op= newobject(O_LCYL,   OF_MOD, r, 40,  5); op->entry= pe;
-		op= newobject(O_LHEAD,  OF_MOD, r, 45,  3); op->entry= pe;
-		op= newobject(O_LSEC,   OF_MOD, r, 49,  2); op->entry= pe;
-		op= newobject(O_BASE,   OF_MOD, r, 59,  9); op->entry= pe;
-		op= newobject(O_SIZE,   OF_MOD, r, 69,  9); op->entry= pe;
-		op= newobject(O_KB,     OF_MOD, r, 79,  9); op->entry= pe;
-	}
-
-	for (i= 1; i < argc; i++) newdevice(argv[i], 0);
-
-	if (firstdev == nil) {
-		getdevices();
-		key= ctrl('L');
-	} else {
-		key= 'r';
-	}
-
-	if (firstdev != nil) {
-		init_tty();
-		clear_screen();
-		event(key, curobj);
-		display();
-		mainloop();
-		reset_tty();
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/partition.c
===================================================================
--- trunk/minix/commands/ibm/partition.c	(revision 9)
+++ 	(revision )
@@ -1,437 +1,0 @@
-/*	partition 1.13 - Make a partition table		Author: Kees J. Bot
- *								27 Apr 1992
- */
-#define nil ((void*)0)
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <limits.h>
-
-#define SECTOR_SIZE	512
-
-#define arraysize(a)	(sizeof(a)/sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-char *arg0;
-
-void report(const char *label)
-{
-	fprintf(stderr, "%s: %s: %s\n", arg0, label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-#ifndef makedev
-#define minor(dev)	(((dev) >> MINOR) & BYTE)
-#define major(dev)	(((dev) >> MAJOR) & BYTE)
-#define makedev(major, minor)	\
-			((dev_t) (((major) << MAJOR) | ((minor) << MINOR)))
-#endif
-
-int aflag;			/* Add a new partition to the current table. */
-int mflag;			/* Minix rules, no need for alignment. */
-int rflag;			/* Report current partitions. */
-int fflag;			/* Force making a table even if too small. */
-int nflag;			/* Play-act, don't really do it. */
-
-int cylinders, heads, sectors;	/* Device's geometry */
-int pad;			/* Partitions must be padded. */
-
-/* Descriptions of the device to divide and the partitions to make, including
- * gaps between partitions.
- */
-char *device;
-struct part_entry primary, table[2 * NR_PARTITIONS + 1];
-int npart;
-
-/* Extra flags at construction time. */
-#define EXPAND_FLAG	0x01	/* Add the remaining sectors to this one */
-#define EXIST_FLAG	0x02	/* Use existing partition */
-
-void find_exist(struct part_entry *exist, int sysind, int nr)
-{
-	int f;
-	u16_t signature;
-	struct part_entry oldtable[NR_PARTITIONS];
-	int n, i;
-	u32_t minlow, curlow;
-	struct part_entry *cur;
-	char *nr_s[] = { "", "second ", "third ", "fourth" };
-
-	if ((f= open(device, O_RDONLY)) < 0
-
-		|| lseek(f, (off_t) PART_TABLE_OFF, SEEK_SET) == -1
-
-		|| read(f, oldtable, sizeof(oldtable)) < 0
-
-		|| read(f, &signature, sizeof(signature)) < 0
-
-		|| close(f) < 0
-	) fatal(device);
-
-	minlow= 0;
-	n= 0;
-	for (;;) {
-		curlow= -1;
-		cur= nil;
-		for (i= 0; i < NR_PARTITIONS; i++) {
-			if (signature == 0xAA55
-				&& oldtable[i].sysind != NO_PART
-				&& oldtable[i].lowsec >= minlow
-				&& oldtable[i].lowsec < curlow
-			) {
-				cur= &oldtable[i];
-				curlow= oldtable[i].lowsec;
-			}
-		}
-		if (n == nr) break;
-		n++;
-		minlow= curlow+1;
-	}
-
-	if (cur == nil || cur->sysind != sysind) {
-		fprintf(stderr,
-		"%s: Can't find a %sexisting partition of type 0x%02X\n",
-			arg0, nr_s[nr], sysind);
-		exit(1);
-	}
-	*exist = *cur;
-}
-
-void write_table(void)
-{
-	int f;
-	u16_t signature= 0xAA55;
-	struct part_entry newtable[NR_PARTITIONS];
-	int i;
-
-	if (nflag) {
-		printf("(Table not written)\n");
-		return;
-	}
-
-	for (i= 0; i < NR_PARTITIONS; i++) newtable[i]= table[1 + 2*i];
-
-	if ((f= open(device, O_WRONLY)) < 0
-
-		|| lseek(f, (off_t) PART_TABLE_OFF, SEEK_SET) == -1
-
-		|| write(f, newtable, sizeof(newtable)) < 0
-
-		|| write(f, &signature, sizeof(signature)) < 0
-
-		|| close(f) < 0
-	) fatal(device);
-}
-
-void sec2dos(unsigned long sec, unsigned char *dos)
-/* Translate a sector number into the three bytes DOS uses. */
-{
-	unsigned secspcyl= heads * sectors;
-	unsigned cyl;
-
-	cyl= sec / secspcyl;
-	dos[2]= cyl;
-	dos[1]= ((sec % sectors) + 1) | ((cyl >> 2) & 0xC0);
-	dos[0]= (sec % secspcyl) / sectors;
-}
-
-void show_chs(unsigned long pos)
-{
-	int cyl, head, sec;
-
-	if (pos == -1) {
-		cyl= head= 0;
-		sec= -1;
-	} else {
-		cyl= pos / (heads * sectors);
-		head= (pos / sectors) - (cyl * heads);
-		sec= pos % sectors;
-	}
-	printf("  %4d/%03d/%02d", cyl, head, sec);
-}
-
-void show_part(struct part_entry *p)
-{
-	static int banner= 0;
-	int n;
-
-	n= p - table;
-	if ((n % 2) == 0) return;
-
-	if (!banner) {
-		printf(
-	"Part     First         Last         Base      Size       Kb\n");
-		banner= 1;
-	}
-
-	printf("%3d ", (n-1) / 2);
-	show_chs(p->lowsec);
-	show_chs(p->lowsec + p->size - 1);
-	printf("  %8lu  %8lu  %7lu\n", p->lowsec, p->size, p->size / 2);
-}
-
-void usage(void)
-{
-	fprintf(stderr,
-		"Usage: partition [-mfn] device [type:]length[+*] ...\n");
-	exit(1);
-}
-
-#define between(a, c, z)	((unsigned) ((c) - (a)) <= ((z) - (a)))
-
-void parse(char *descr)
-{
-	int seen= 0, sysind, flags, c;
-	unsigned long lowsec, size;
-
-	lowsec= 0;
-
-	if (strchr(descr, ':') == nil) {
-		/* A hole. */
-		if ((npart % 2) != 0) {
-			fprintf(stderr, "%s: Two holes can't be adjacent.\n",
-				arg0);
-			exit(1);
-		}
-		sysind= NO_PART;
-		seen|= 1;
-	} else {
-		/* A partition. */
-		if ((npart % 2) == 0) {
-			/* Need a hole before this partition. */
-			if (npart == 0) {
-				/* First hole contains the partition table. */
-				table[0].size= 1;
-			}
-			npart++;
-		}
-		sysind= 0;
-		for (;;) {
-			c= *descr++;
-			if (between('0', c, '9'))
-				c= (c - '0') + 0x0;
-			else
-			if (between('a', c, 'z'))
-				c= (c - 'a') + 0xa;
-			else
-			if (between('A', c, 'Z'))
-				c= (c - 'A') + 0xA;
-			else
-				break;
-			sysind= 0x10 * sysind + c;
-			seen|= 1;
-		}
-		if (c != ':') usage();
-	}
-
-	flags= 0;
-
-	if (strncmp(descr, "exist", 5) == 0 && (npart % 2) == 1) {
-		struct part_entry exist;
-
-		find_exist(&exist, sysind, (npart - 1) / 2);
-		sysind= exist.sysind;
-		lowsec= exist.lowsec;
-		size= exist.size;
-		flags |= EXIST_FLAG;
-		descr += 5;
-		c= *descr++;
-		seen|= 2;
-	} else {
-		size= 0;
-		while (between('0', (c= *descr++), '9')) {
-			size= 10 * size + (c - '0');
-			seen|= 2;
-		}
-	}
-
-	for (;;) {
-		if (c == '*')
-			flags|= ACTIVE_FLAG;
-		else
-		if (c == '+' && !(flags & EXIST_FLAG))
-			flags|= EXPAND_FLAG;
-		else
-			break;
-		c= *descr++;
-	}
-
-	if (seen != 3 || c != 0) usage();
-
-	if (npart == arraysize(table)) {
-		fprintf(stderr, "%s: too many partitions, only %d possible.\n",
-			arg0, NR_PARTITIONS);
-		exit(1);
-	}
-	table[npart].bootind= flags;
-	table[npart].sysind= sysind;
-	table[npart].lowsec= lowsec;
-	table[npart].size= size;
-	npart++;
-}
-
-void geometry(void)
-/* Get the geometry of the drive the device lives on, and the base and size
- * of the device.
- */
-{
-	int fd;
-	struct partition geometry;
-	struct stat sb;
-
-	if ((fd= open(device, O_RDONLY)) < 0) fatal(device);
-
-	/* Get the geometry of the drive, and the device's base and size. */
-	if (ioctl(fd, DIOCGETP, &geometry) < 0)
-	{
-		/* Use the same fake geometry as part. */
-		if (fstat(fd, &sb) < 0)
-			fatal(device);
-		geometry.base= cvul64(0);
-		geometry.size= cvul64(sb.st_size);
-		geometry.sectors= 32;
-		geometry.heads= 64;
-		geometry.cylinders= (sb.st_size-1)/SECTOR_SIZE/
-			(geometry.sectors*geometry.heads) + 1;
-	}
-	close(fd);
-	primary.lowsec= div64u(geometry.base, SECTOR_SIZE);
-	primary.size= div64u(geometry.size, SECTOR_SIZE);
-	cylinders= geometry.cylinders;
-	heads= geometry.heads;
-	sectors= geometry.sectors;
-
-	/* Is this a primary partition table?  If so then pad partitions. */
-	pad= (!mflag && primary.lowsec == 0);
-}
-
-void boundary(struct part_entry *pe, int exp)
-/* Expand or reduce a primary partition to a track or cylinder boundary to
- * avoid giving the fdisk's of simpler operating systems a fit.
- */
-{
-	unsigned n;
-
-	n= !pad ? 1 : pe == &table[0] ? sectors : heads * sectors;
-	if (exp) pe->size+= n - 1;
-	pe->size= ((pe->lowsec + pe->size) / n * n) - pe->lowsec;
-}
-
-void distribute(void)
-/* Fit the partitions onto the device.  Try to start and end them on a
- * cylinder boundary if so required.  The first partition is to start on
- * track 1, not on cylinder 1.
- */
-{
-	struct part_entry *pe, *exp;
-	long count;
-	unsigned long base, size, oldbase;
-
-	do {
-		exp= nil;
-		base= primary.lowsec;
-		count= primary.size;
-
-		for (pe= table; pe < arraylimit(table); pe++) {
-			oldbase= base;
-			if (pe->bootind & EXIST_FLAG) {
-				if (base > pe->lowsec) {
-					fprintf(stderr,
-	"%s: fixed partition %d is preceded by too big partitions/holes\n",
-						arg0, ((pe - table) - 1) / 2);
-					exit(1);
-				}
-				exp= nil;	/* XXX - Extend before? */
-			} else {
-				pe->lowsec= base;
-				boundary(pe, 1);
-				if (pe->bootind & EXPAND_FLAG) exp= pe;
-			}
-			base= pe->lowsec + pe->size;
-			count-= base - oldbase;
-		}
-		if (count < 0) {
-			if (fflag) break;
-			fprintf(stderr, "%s: %s is %ld sectors too small\n",
-				arg0, device, -count);
-			exit(1);
-		}
-		if (exp != nil) {
-			/* Add leftover space to the partition marked for
-			 * expanding.
-			 */
-			exp->size+= count;
-			boundary(exp, 0);
-			exp->bootind&= ~EXPAND_FLAG;
-		}
-	} while (exp != nil);
-
-	for (pe= table; pe < arraylimit(table); pe++) {
-		if (pe->sysind == NO_PART) {
-			memset(pe, 0, sizeof(*pe));
-		} else {
-			sec2dos(pe->lowsec, &pe->start_head);
-			sec2dos(pe->lowsec + pe->size - 1, &pe->last_head);
-			pe->bootind&= ACTIVE_FLAG;
-		}
-		show_part(pe);
-	}
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-
-	if ((arg0= strrchr(argv[0], '/')) == nil) arg0= argv[0]; else arg0++;
-
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++] + 1;
-
-		if (opt[0] == '-' && opt[1] == 0) break;
-
-		while (*opt != 0) switch (*opt++) {
-		case 'a':	aflag= 1;	break;
-		case 'm':	mflag= 1;	break;
-		case 'r':	rflag= 1;	break;
-		case 'f':	fflag= 1;	break;
-		case 'n':	nflag= 1;	break;
-		default:	usage();
-		}
-	}
-
-	if (rflag) {
-		if (aflag) usage();
-		if ((argc - i) != 1) usage();
-		fprintf(stderr, "%s: -r is not yet implemented\n");
-		exit(1);
-	} else {
-		if ((argc - i) < 1) usage();
-		if (aflag) fprintf(stderr, "%s: -a is not yet implemented\n");
-
-		device= argv[i++];
-		geometry();
-
-		while (i < argc) parse(argv[i++]);
-
-		distribute();
-		write_table();
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/playwave.c
===================================================================
--- trunk/minix/commands/ibm/playwave.c	(revision 9)
+++ 	(revision )
@@ -1,201 +1,0 @@
-/*   
- *  playwave.c
- *
- *  Play sound files in wave format. Only MicroSoft PCM is supported. 
- *
- *  Michel R. Prevenier.
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <minix/sound.h>
-
-_PROTOTYPE( void main, (int argc, char **argv));
-_PROTOTYPE( void usage, (void));
-
-/******* Wave format definitions *********/
-
-#define RIFF_ID		0x46464952
-#define WAVE_ID1	0x45564157
-#define WAVE_ID2	0x20746D66
-#define DATA_ID		0x61746164
-#define MS_PCM_FORMAT	0x0001
-	
-#define WORD	short  
-#define DWORD   unsigned long
-
-struct RIFF_fields
-{
-  DWORD RIFF_id;
-  DWORD RIFF_len;
-  DWORD WAVE_id1;
-  DWORD WAVE_id2;
-  DWORD data_ptr;
-} r_fields; 
-
-struct common_fields
-{
-  WORD  FormatTag;
-  WORD  Channels;
-  DWORD SamplesPerSec;
-  DWORD AvgBytesPerSec;
-  WORD  BlockAlign;
-} c_fields;
-
-struct specific_fields
-{
-  WORD BitsPerSample;
-} s_fields;
-
-DWORD data_id;
-DWORD data_len;
-
-/******** End of wave definitions *********/
-
-
-void usage()
-{
-  fprintf(stderr, "Usage: playwav [-i] file\n");
-  exit(-1);
-}
-
-
-void main ( int argc, char *argv[] )
-{
-  int i, audio, file;
-  char *buffer, *file_name;
-  unsigned int sign;
-  unsigned int fragment_size;
-  unsigned int channels;
-  unsigned int bits;
-  long data_pos;  
-  int showinfo = 0;
-
-  /* Check Parameters */
-  if (argc > 2)
-  {
-    if (strncmp(argv[1], "-i", 2) == 0)
-    {
-      showinfo = 1;
-      file_name = argv[2];
-    }
-    else
-      usage();
-  }
-  else file_name = argv[1];
-
-  /* Open DSP */
-  if ((audio = open("/dev/audio", O_RDWR)) < 0) 
-  {
-    printf("Cannot open /dev/audio\n");
-    exit(-1);
-  }
-
-  /* Get maximum fragment size and try to allocate a buffer */
-  ioctl(audio, DSPIOMAX, &fragment_size);
-  if ((buffer = malloc(fragment_size)) == (char *)0)
-  {
-    fprintf(stderr, "Cannot allocate buffer\n");
-    exit(-1);
-  } 
-  ioctl(audio, DSPIOSIZE, &fragment_size);
-
-  /* Open wav file */
-  if((file = open(file_name, O_RDONLY)) < 0)
-  {
-    printf("Cannot open %s\n", file_name);
-    exit(-1);
-  }
-
-  /* Check for valid wave format */
-  read(file, &r_fields, 20);
-  if(r_fields.RIFF_id != RIFF_ID)
-  {
-      printf("%s not in RIFF format\n", file_name);
-      exit(1);
-  }
-  if(r_fields.WAVE_id1 != WAVE_ID1 || r_fields.WAVE_id2 != WAVE_ID2)
-  {
-      printf("%s not in WAVE format\n", file_name);
-      exit(1);
-  }
-
-  /* Store data_chunk position */
-  data_pos = lseek(file, 0L, 1) + r_fields.data_ptr;
-
-  /* Read the common and specific fields */
-  read(file, &c_fields, 14);
-  read(file, &s_fields, 2);
-
-  /* Check for valid wave format, we can only play MicroSoft PCM */
-  if(c_fields.FormatTag != MS_PCM_FORMAT)
-  {
-    printf("%s not in MicroSoft PCM format\n", file_name);
-    exit(1);
-  }
-
-  /* Set DSP parameters */
-  channels = c_fields.Channels;
-  channels--;
-  bits = s_fields.BitsPerSample;
-  ioctl(audio, DSPIOSTEREO, &channels); 
-  ioctl(audio, DSPIORATE, &c_fields.SamplesPerSec);
-  ioctl(audio, DSPIOBITS, &bits); 
-  sign = (bits == 16 ? 1 : 0);
-  ioctl(audio, DSPIOSIGN, &sign); 
-
-  /* Goto data chunk */
-  lseek(file, data_pos, SEEK_SET);
-
-  /* Check for valid data chunk */
-  read(file, &data_id, sizeof(data_id));
-  if(data_id != DATA_ID)
-  {
-    printf("Invalid data chunk\n");
-    exit(1);
-  }
-
-  /* Get length of data */
-  read(file, &data_len, sizeof(data_len));
-
-  if (showinfo)
-  {
-    printf("\nBits per sample   : %d \n", s_fields.BitsPerSample);
-    printf("Stereo            : %s \n", (c_fields.Channels == 1 ? "yes" : "no"));
-    printf("Samples per second: %ld \n", c_fields.SamplesPerSec); 
-    printf("Average bytes/sec : %ld \n", c_fields.AvgBytesPerSec);
-    printf("Block alignment   : %d \n", c_fields.BlockAlign);
-    printf("Datalength (bytes): %ld \n\n", data_len);
-  }
-    
-  /* Play data */
-  while(data_len > 0)
-  {
-    if (data_len > fragment_size) 
-    {
-      /* Read next fragment */
-      read(file, buffer, fragment_size); 
-      data_len-= fragment_size;
-    }
-    else 
-    { 
-      /* Read until end of file and fill rest of buffer with silence,
-       * in PCM this means: fill buffer with last played value
-       */
-      read(file, buffer, data_len); 
-      for (i = data_len; i< fragment_size; i++) 
-        buffer[i] = buffer[(int)data_len-1];
-      data_len = 0;
-    }
-
-    /* Copy data to DSP */
-    write(audio, buffer,  fragment_size);
-  }
-}
Index: trunk/minix/commands/ibm/postmort.c
===================================================================
--- trunk/minix/commands/ibm/postmort.c	(revision 9)
+++ 	(revision )
@@ -1,656 +1,0 @@
-/* postmort - post mortem dump		Author: C. W. Rose */
-
-/* Postmort: perform post-mortem on PC Minix 1.7 core files.
- *
- */
-
- /* The 1.5 core file structure is a struct mem_map, the segment memory map,
-  * followed by a struct proc, the process table, followed by a dump of the
-  * text, data, and stack segments.
-  * 
-  * This is the 8086/Intel version; 386 and 68K will differ.  It defaults to
-  * using the name 'core' for the core file, and 'a.out' for the symbol file.
-  * If there is no 'a.out', it will try and read the symbol table from
-  * 'symbol.out', then give up.  A non-existant symbol table is not a fatal
-  * error unless the -s option was used.
-  * 
-  * The PC 1.5 kernel dump routines are odd - they dump the memory maps twice,
-  * the second time as part of the kernel process table, and the kernel
-  * process table size must be a multiple of 4.  Should a core file have a
-  * header with a magic number in future?
-  * 
-  * The kernel include file paths need to be edited for each machine. */
-
-#include <sys/types.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include <minix/ipc.h>
-#include <limits.h>
-#include <timers.h>
-#include <signal.h>
-#include <stdlib.h>
-
-#undef EXTERN			/* <minix/const.h> defined this */
-#define EXTERN			/* so we get proc & mproc */
-#include "../../kernel/const.h"
-#include "../../kernel/type.h"
-#include "../../kernel/proc.h"
-#undef printf			/* kernel's const.h defined this */
-#include "../../servers/pm/mproc.h"
-
-#include <a.out.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#undef NULL
-#include <string.h>
-#include <unistd.h>
-
-#define FALSE		0
-#undef TRUE
-#define TRUE		~FALSE
-#define OK		1
-#define FAILED		-1
-
-#define CORE		"core"
-#define AOUT		"a.out"
-#define SYMB		"symbol.out"
-#define LINE_LEN	16
-#define MAXSYM		200
-#define SYMLEN		8
-
-/* Global variables */
-int opt_c = FALSE;		/* name of core file */
-int opt_d = FALSE;		/* dump raw data and stack segments */
-int opt_p = FALSE;		/* dump the kernel process table */
-int opt_s = FALSE;		/* name of symbol file */
-int opt_t = FALSE;		/* trace back the stack */
-int opt_x = FALSE;		/* debugging flag */
-
-char progname[20];		/* program name */
-char *segment_name[] = {	/* array of segment names */
-  "Text",
-  "Data",
-  "Stack"
-};
-
-int dbglvl = 0;			/* debugging level */
-int maxsym;			/* maximum symbol number */
-unsigned int baseptr;		/* reference copy of stack base pointer */
-unsigned int stackptr;		/* reference copy of stack pointer */
-long int lengths[NR_LOCAL_SEGS];	/* segment lengths */
-long int bases[NR_LOCAL_SEGS];	/* segment base addresses */
-
-struct sym {			/* symbol table addresses and labels */
-  unsigned int addr;
-  char label[SYMLEN + 1];
-} symtab[MAXSYM];
-
-/* Used by getopt(3) package */
-extern int optind, opterr, optopt;
-extern char *optarg;
-
-_PROTOTYPE(int binary, (int uc, char *sp));
-_PROTOTYPE(void dump_all_segs, (int fd));
-_PROTOTYPE(void dump_maps, (struct mem_map * mp));
-_PROTOTYPE(void dump_one_seg, (int fd, int segindex));
-_PROTOTYPE(void dump_proc_table, (struct proc * pt));
-_PROTOTYPE(void dump_registers, (struct proc * pt));
-_PROTOTYPE(void dump_sym_tab, (struct sym *st));
-_PROTOTYPE(void dump_stack, (struct stackframe_s * sp));
-_PROTOTYPE(int main, (int argc, char *argv[]));
-_PROTOTYPE(int parse_line, (char *ps));
-_PROTOTYPE(int read_symbol, (int fd));
-_PROTOTYPE(void stack_trace, (int fd));
-_PROTOTYPE(void usage, (void));
-
-
-/* B i n a r y
- *
- * Produce a binary representation of an 8-bit number.
- */
-int binary(ucc, sp)
-int ucc;
-char *sp;
-{
-  int j;
-  unsigned char k, uc;
-
-  uc = (unsigned char) ucc;
-  for (k = 0x80, j = 0; j < 8; j++) {
-	if ((uc & k) == 0)
-		*sp++ = '0';
-	else
-		*sp++ = '1';
-	if (j == 3) *sp++ = '$';
-	k >>= 1;
-  }
-  *sp = '\0';
-
-  return(0);
-}
-
-
-/* D u m p _ a l l _ s e g s
- *
- * Dump all the segments except for text
- */
-void dump_all_segs(fd)
-int fd;
-{
-  int j;
-  long int start;
-
-  start = (long) (NR_LOCAL_SEGS * sizeof(struct mem_map)) + sizeof(struct proc);
-  for (j = 1; j < NR_LOCAL_SEGS; j++) {
-	start += lengths[j - 1];
-	(void) lseek(fd, start, 0);
-	printf("\n");
-	dump_one_seg(fd, j);
-  }
-}
-
-
-/* D u m p _ m a p s
- *
- * Dump the memory maps
- */
-void dump_maps(mp)
-struct mem_map *mp;
-{
-  int j;
-  long int vir, phy, len;
-
-  printf("\t  Virtual\t  Physical\tLength\n");
-  printf("\t  address\t  address\n");
-  for (j = 0; j < NR_LOCAL_SEGS; j++) {
-	vir = (long) mp[j].mem_vir << CLICK_SHIFT;
-	phy = (long) mp[j].mem_phys << CLICK_SHIFT;
-	len = (long) mp[j].mem_len << CLICK_SHIFT;
-	printf("%s:\t0x%08.8lx\t0x%08.8lx\t%8ld (0x%08.8lx)\n",
-	       segment_name[j], vir, phy, len, len);
-	lengths[j] = len;
-	bases[j] = vir;
-  }
-}
-
-
-/* D u m p _ o n e _ s e g
- *
- * Dump a single segment
- */
-void dump_one_seg(fd, segindex)
-int fd, segindex;
-{
-  unsigned char dlen[LINE_LEN];
-  int i, amt, amt_read;
-  long int len, offset;
-
-  printf("%s segment\n\n", segment_name[segindex]);
-  len = lengths[segindex];
-  amt = LINE_LEN;
-  for (offset = 0; offset < len; offset += amt) {
-	if ((len - offset) < LINE_LEN) amt = (int) (len - offset);
-	if (dbglvl > 0)
-		printf("Length %ld, offset %ld, amt %d\n", len, offset, amt);
-	if ((amt_read = read(fd, (char *) dlen, (unsigned int) amt)) == -1) {
-		printf("Unexpected end of file\n");
-		exit(1);
-	}
-	printf("%08.8lx: ", bases[segindex] + offset);
-	for (i = 0; i < amt_read; i++) {
-		if (i == LINE_LEN / 2) printf("- ");
-		printf("%02.2x ", dlen[i]);
-	}
-	printf("  ");
-	for (i = 0; i < amt_read; i++) {
-		if (isprint(dlen[i]))
-			(void) putchar((char) dlen[i]);
-		else
-			(void) putchar('.');
-	}
-	(void) putchar('\n');
-	if (dbglvl > 0 && amt_read != amt)
-		printf("wanted = %d, got = %d, offset = %ld\n",
-		       amt, amt_read, offset);
-  }
-}
-
-
-/* D u m p _ p r o c _ t a b l e
- *
- * Dump the entire kernel proc table
- */
-void dump_proc_table(pt)
-struct proc *pt;
-{
-  printf("Kernel process table entries:\n\n");
-#if 0
-  printf("Process' registers:			0x%04.4x\n", pt->p_reg);	/* struct stackframe_s */
-  printf("Selector in gdt:			0x%04.4x\n", pt->p_ldt_sel);	/* reg_t */
-  printf("Descriptors for code and data:	0x%04.4x\n", pt->p_ldt[2]);	/* struct segdesc_s */
-#endif
-  printf("Number of this process:			0x%04.4x\n", pt->p_nr);	/* int */
-#if 0
-  printf("Nonzero if blocked by busy task:	0x%04.4x\n", pt->p_ntf_blocked);	/* int */
-  printf("Nonzero if held by busy syscall:	0x%04.4x\n", pt->p_ntf_held);	/* int */
-  printf("Next in chain of held-up processes:	0x%04.4x\n", pt->p_ntf_nextheld);	/* struct proc * */
-#endif
-  printf("SENDING, RECEIVING, etc.:		0x%04.4x\n", pt->p_rts_flags);	/* int */
-#if 0
-  printf("Memory map:				0x%04.4x\n", pt->p_map[NR_LOCAL_SEGS]);	/* struct mem_map */
-#endif
-#if DEAD_CODE
-  printf("Process id passed in from MM:		0x%04.4x\n", pt->p_pid);	/* int */
-#endif
-#if 0
-  printf("User time in ticks:			%ld\n", pt->user_time);	/* time_t */
-  printf("Sys time in ticks:			%ld\n", pt->sys_time);	/* time_t */
-  printf("Cumulative user time of children:	%ld\n", pt->child_utime);	/* time_t */
-  printf("Cumulative sys time of children:	%ld\n", pt->child_stime);	/* time_t */
-  printf("Ticks used in current quantum:	%d\n", pt->quantum_time);	/* int */
-  printf("Ticks used in last quantum:		%d\n", pt->quantum_last);	/* int */
-  printf("Current priority of the process:	%d\n", pt->curr_prio);	/* int */
-  printf("Base priority of the process:		%d\n", pt->base_prio);	/* int */
-  printf("Scale for profiling, 0 = none:	%u\n", pt->p_pscale);	/* unsigned */
-  printf("Profiling pc lower boundary:		%d\n", pt->p_plow);	/* vir_bytes */
-  printf("Profiling pc upper boundary:		%d\n", pt->p_phigh);	/* vir_bytes */
-  printf("Profiling buffer:			%d\n", pt->p_pbuf);	/* vir_bytes */
-  printf("Profiling buffer size:		%d\n", pt->p_psiz);	/* vir_bytes */
-#endif
-#if 0
-  printf("First proc wishing to send:		0x%04.4x\n", pt->p_callerq);	/* struct proc * */
-  printf("Link to next proc wishing to send:	0x%04.4x\n", pt->p_sendlink);	/* struct proc * */
-  printf("Pointer to message buffer:		0x%04.4x\n", pt->p_messbuf);	/* message * */
-#endif
-  printf("Expecting message from:			0x%04.4x\n", pt->p_getfrom_e);	/* int */
-#if 0
-  printf("Pointer to next ready process:	0x%04.4x\n", pt->p_nextready);	/* struct proc * */
-#endif
-  printf("Bit map for pending signals 1-16:	0x%04.4x\n", pt->p_pending);	/* int */
-#if 0
-  printf("Count of pending/unfinished signals:	0x%04.4x\n", pt->p_pendcount);	/* unsigned */
-#endif
-}
-
-
-/* D u m p _ r e g i s t e r s
- *
- * Dump the registers from the proc table
- */
-void dump_registers(pt)
-struct proc *pt;
-{
-  char buff[32];
-  unsigned char uc;
-
-  /* Print the registers */
-  dump_stack(&pt->p_reg);
-
-  /* Build up a binary representation of the signal flags */
-  uc = (pt->p_pending >> 8) & 0xff;
-  (void) binary((int) uc, buff);
-  buff[9] = '$';
-  uc = pt->p_pending & 0xff;
-  (void) binary((int) uc, buff + 10);
-  printf("Pending signals = %s\n", buff);
-}
-
-
-/* D u m p _ s y m _ t a b
- *
- * Dump the symbol table
- */
-void dump_sym_tab(st)
-struct sym *st;
-{
-  int j;
-
-  printf("Symbol table entries (text):\n\n");
-  for (j = 0; j < maxsym; j++) 
-	printf("0x%08.8x T %s\n", symtab[j].addr, symtab[j].label);
-}
-
-
-/* D u m p _ s t a c k
- *
- * Dump the stack frame
- */
-void dump_stack(sp)
-struct stackframe_s *sp;
-{
-  char buff[32];
-  unsigned char uc;
-
-  /* Build up the binary PSW representation */
-  uc = (sp->psw >> 8) & 0xff;
-  (void) binary((int) uc, buff);
-  uc = sp->psw & 0xff;
-  buff[9] = '$';
-  (void) binary((int) uc, buff + 10);
-
-  /* Print all the information */
-  printf("Stack Frame:\tPC = %04.4x\t\t   PSW = %s\n",
-         sp->pc, buff);
-  printf("\t\t\t\t\tStatus = ____ ODIT SZ_A _P_C\n");
-
-  printf("  ax	bx	cx	dx	di	si\n");
-  printf("  %04.4x\t%04.4x\t%04.4x\t%04.4x\t%04.4x\t%04.4x\n",
-         sp->retreg, sp->bx, sp->cx, sp->dx, sp->di, sp->si);
-  printf("  sp	bp	ss\n");
-  printf("  %04.4x\t%04.4x\t%04.4x\n",
-         sp->sp, sp->fp, sp->ss);
-  printf("  cs	ds	es\n");
-  printf("  %04.4x\t%04.4x\t%04.4x\n",
-         sp->cs, sp->ds, sp->es);
-
-  /* Store for future reference */
-  stackptr = sp->sp;
-  baseptr = sp->fp;
-  if (dbglvl > 0)
-	printf("\nStack pointer 0x%x, Base pointer 0x%x\n", stackptr, baseptr);
-}
-
-
-/* M a i n
- *
- * Main program
- */
-main(argc, argv)
-int argc;
-char *argv[];
-{
-  int j, fdc, fds;
-  char *cp, corefile[132], symbfile[132];
-  struct proc proc_entry;
-  struct mem_map mp_segs[NR_LOCAL_SEGS];
-
-  /* Initial set up */
-  if ((cp = strrchr(argv[0], '/')) == (char *) NULL)
-	cp = argv[0];
-  else
-	cp++;
-  strncpy(progname, cp, 19);
-  strncpy(corefile, CORE, 131);
-  strncpy(symbfile, AOUT, 131);
-
-  /* Parse arguments */
-  opterr = 0;
-  while ((j = getopt(argc, argv, "c:dps:tx:")) != EOF) {
-	switch (j & 0177) {
-	    case 'c':
-		opt_c = TRUE;
-		strncpy(corefile, optarg, 131);
-		break;
-	    case 'd':	opt_d = TRUE;	break;
-	    case 'p':	opt_p = TRUE;	break;
-	    case 's':
-		opt_s = TRUE;
-		strncpy(symbfile, optarg, 131);
-		break;
-	    case 't':	opt_t = TRUE;	break;
-	    case 'x':
-		dbglvl = atoi(optarg);
-		opt_x = TRUE;
-		break;
-	    case '?':
-	    default:
-		usage();
-		exit(1);
-		break;
-	}
-  }
-
-  /* We must have a core file */
-  if ((fdc = open(corefile, O_RDONLY)) == -1) {
-	fprintf(stderr, "Cannot open %s\n", corefile);
-	exit(1);
-  }
-
-  /* We'd like an a.out file or a symbol table */
-  if ((fds = open(symbfile, O_RDONLY)) == -1) {
-	if (opt_s)
-		j = FAILED;
-	else {
-		strncpy(symbfile, AOUT, 131);
-		if ((fds = open(symbfile, O_RDONLY)) == -1)
-			j = FAILED;
-		else
-			j = read_symbol(fds);
-	}
-  } else
-	j = read_symbol(fds);
-
-  /* Only fatal if we insisted */
-  if (opt_s && j == FAILED) {
-	fprintf(stderr, "Cannot find symbols in %s\n", symbfile);
-	exit(1);
-  }
-
-  /* Read the process table */
-  if (dbglvl > 0) {
-	printf("\n");
-	printf("Size of mproc entry %d\n", NR_LOCAL_SEGS * sizeof(struct mem_map));
-	printf("Size of process table %d\n", sizeof(proc_entry));
-  }
-  if (read(fdc, (char *) mp_segs, sizeof(mp_segs)) != sizeof(mp_segs) ||
-      read(fdc, (char *) &proc_entry,
-	 sizeof(struct proc)) != sizeof(struct proc)) {
-	fprintf(stderr, "Cannot open %s\n", corefile);
-	exit(1);
-  }
-
-  /* Do the work */
-#if 0
-  dump_maps(mp_segs);		/* duplicated in the kernel */
-  printf("\n");
-	/* XXX broken */
-  dump_maps(proc_entry.p_map);
-#endif
-  printf("\n");
-  dump_registers(&proc_entry);
-  if (opt_t) {
-	printf("\n");
-	stack_trace(fdc);
-  }
-  if (opt_p) {
-	printf("\n");
-	dump_proc_table(&proc_entry);
-  }
-  if (opt_d) {
-	printf("\n");
-	dump_sym_tab(symtab);
-	dump_all_segs(fdc);
-  }
-
-  /* Wrap up */
-  (void) close(fdc);
-  if (fds != -1) (void) close(fds);
-
-  exit(0);
-  /* NOTREACHED */
-}
-
-
-/* P a r s e _ l i n e
- *
- * Parse a line of the symbol table
- */
-int parse_line(ps)
-char *ps;
-{
-  char c, s[80];
-  int j, k;
-  unsigned int u;
-
-  /* We must have space in the table */
-  if (maxsym == MAXSYM) return(FAILED);
-
-  /* Lines must be a minimum length to contain information */
-  if (strlen(ps) < 8) return(FAILED);
-
-  /* Lines must have a definite structure */
-  if (ps[1] != ' ' || ps[6] != ' ') return(FAILED);
-  for (j = 2; j < 6; j++)
-	if (!isxdigit(ps[j])) return(FAILED);
-  if (sscanf(ps, "%c %x %s", &c, &u, s) != 3) return (FAILED);
-
-  if (dbglvl > 0) printf("Address 0x%04.4x, label %s\n", u, s);
-
-  /* Load the symbol table in sorted order */
-  for (j = 0; j < maxsym; j++) {
-	if (u < symtab[j].addr) {
-		for (k = maxsym; k > j; k--) symtab[k] = symtab[k - 1];
-		break;
-	}
-  }
-  symtab[j].addr = u;
-  strncpy(symtab[j].label, s, SYMLEN);
-  maxsym++;
-
-  return(OK);
-}
-
-
-/* R e a d _ s y m b o l
- *
- * Read the symbol table
- */
-int read_symbol(fd)
-int fd;
-{
-  char sym[80], buff[BUFSIZ];
-  int j, k, m;
-  long int offset;
-  struct exec *ep;
-  struct nlist *np;
-
-  /* We collect only text symbols, since that's all that's needed here */
-
-  /* Initialise the buffer */
-  if ((j = read(fd, buff, BUFSIZ)) == 0 || j == -1) return(FAILED);
-
-  k = maxsym = 0;
-
-  /* Find out what we've got */
-  ep = (struct exec *) buff;
-  np = (struct nlist *) buff;
-  if (BADMAG(*ep)) {
-	/* Must be a separate symbol table */
-	while (TRUE) {
-		if (buff[k] == 'T') {
-			for (m = 0; m < 78; m++) {
-				sym[m] = buff[k];
-				if (++k == j) {
-					if ((j = read(fd, buff, BUFSIZ)) == 0 || j == -1)
-						break;
-					k = 0;
-				}
-				if (buff[k] == '\n') break;
-			}
-			sym[m + 1] = '\0';
-			(void) parse_line(sym);
-		}
-		if (++k == j) {
-			if ((j = read(fd, buff, BUFSIZ)) == 0 || j == -1)
-				break;
-			k = 0;
-		}
-	}
-  } else if (ep->a_syms != 0L) {
-	/* There's symbols in them thar hills */
-	offset = 8 * sizeof(long) + ep->a_text + ep->a_data;
-	if (lseek(fd, offset, 0) == -1L) return(FAILED);
-	/* Symbols are in an unsorted list */
-	while (read(fd, buff, sizeof(struct nlist)) == sizeof(struct nlist)) {
-		if (np->n_sclass == (N_TEXT + C_EXT)) {	/* external text symbols */
-			for (j = 0; j < maxsym; j++) {
-				if (np->n_value < symtab[j].addr) {
-					for (k = maxsym; k > j; k--)
-						symtab[k] = symtab[k - 1];
-					break;
-				}
-			}
-			symtab[j].addr = np->n_value;
-			strncpy(symtab[j].label, np->n_name, SYMLEN);
-			if (maxsym++ == MAXSYM) break;
-		}
-	}
-  } else if (opt_s)
-	return(FAILED);
-
-  if (dbglvl > 0) {
-	for (m = 0; m < maxsym; m++) printf("Addr 0x%04.4x, label %s\n",
-		       symtab[m].addr, symtab[m].label);
-	printf("Maxsym %d\n", maxsym);
-  }
-  return(OK);
-}
-
-
-/* S t a c k _ t r a c e
- *
- * Trace back down the stack frames.
- *
- * WARNING: very, very, non-portable code
- */
-void stack_trace(fd)
-int fd;
-{
-  int j;
-  unsigned int framepointer, lastpointer, returnvalue, end;
-  long int offset, bp;
-
-  /* Bp actually gives the offset from the base of the data segment */
-  bp = (long) (NR_LOCAL_SEGS * sizeof(struct mem_map)) + sizeof(struct proc)
-	+ lengths[0] + lengths[1] - bases[2];
-  if ((offset = lseek(fd, bp + (long int) baseptr, 0)) == -1L) return;
-  end = (bases[2] + lengths[2] - 1) & 0xffff;
-
-  if (dbglvl > 0)
-	printf("Baseptr %x, End %x, Bp %ld, Offset %ld\n", baseptr, end, bp, offset);
-
-  /* Print the header, then try to backtrace  */
-  printf("Stack back trace:\n\n");
-  printf("Frame address.  Contents.  Return address.");
-  if (maxsym != 0) printf("  Previous label.");
-  printf("\n");
-
-  lastpointer = baseptr;
-  while (TRUE) {
-	/* Read the frame pointer and return address values */
-	if (read(fd, (char *) &framepointer, sizeof(int)) == -1 ||
-	    read(fd, (char *) &returnvalue, sizeof(int)) == -1)
-		break;
-
-	/* Look up the return address - ignored if maxsym == 0 */
-	for (j = 0; j < maxsym; j++) {
-		if (symtab[j].addr >= returnvalue) break;
-	}
-	if (j > 0) j--;
-	printf("    0x%04.4x        0x%04.4x      0x%04.4x          %s\n",
-	       lastpointer, framepointer, returnvalue,
-	       (maxsym == 0) ? "" : symtab[j].label);
-
-	/* If the result is clearly invalid, quit */
-	if (framepointer == 0 || framepointer >= end || framepointer <= lastpointer)
-		break;
-
-	/* Otherwise try to move to the next frame base */
-	lastpointer = framepointer;
-	if ((offset = lseek(fd, bp + (long int) framepointer, 0)) == -1L || offset == 0L)
-		break;
-  }
-}
-
-
-/* U s a g e
- *
- * Usage message
- */
-void usage()
-{
-  fprintf(stderr, "Usage: %s [-dpt] [-c corefile] [-s symbfile]\n", progname);
-}
Index: trunk/minix/commands/ibm/readclock.c
===================================================================
--- trunk/minix/commands/ibm/readclock.c	(revision 9)
+++ 	(revision )
@@ -1,226 +1,0 @@
-/* setime - set the system time from the real time clock
-					Authors: T. Holm & E. Froese
-					Adapted by: Jorrit .N. Herder */
-
-/************************************************************************/
-/*   Readclock was updated for security reasons: openeing /dev/mem no	*/
-/*   longer automatically grants I/O privileges to the calling process	*/
-/*   so that the CMOS' clock could not be read from this program. The	*/
-/*   new approach is to rely on the FS to do the CMOS I/O, via the new  */
-/*   system call CMOSTIME (which only reads the current clock value and */
-/*   cannot update the CMOS clock). 					*/
-/*   The original readclock.c is still available under backup.c.	*/
-/************************************************************************/
-/*									*/
-/*   readclock.c							*/
-/*									*/
-/*		Read the clock value from the 64 byte CMOS RAM		*/
-/*		area, then set system time.				*/
-/*									*/
-/*		If the machine ID byte is 0xFC or 0xF8, the device	*/
-/*		/dev/mem exists and can be opened for reading,		*/
-/*		and no errors in the CMOS RAM are reported by the	*/
-/*		RTC, then the time is read from the clock RAM		*/
-/*		area maintained by the RTC.				*/
-/*									*/
-/*		The clock RAM values are decoded and fed to mktime	*/
-/*		to make a time_t value, then stime(2) is called.	*/
-/*									*/
-/*		This fails if:						*/
-/*									*/
-/*		If the machine ID does not match 0xFC or 0xF8 (no	*/
-/*		error message.)						*/
-/*									*/
-/*		If the machine ID is 0xFC or 0xF8 and /dev/mem		*/
-/*		is missing, or cannot be accessed.			*/
-/*									*/
-/*		If the RTC reports errors in the CMOS RAM.		*/
-/*									*/
-/************************************************************************/
-/*    origination          1987-Dec-29              efth                */
-/*    robustness	   1990-Oct-06		    C. Sylvain		*/
-/* incorp. B. Evans ideas  1991-Jul-06		    C. Sylvain		*/
-/*    set time & calibrate 1992-Dec-17		    Kees J. Bot		*/
-/*    clock timezone	   1993-Oct-10		    Kees J. Bot		*/
-/*    set CMOS clock	   1994-Jun-12		    Kees J. Bot		*/
-/*    removed set CMOS	   2004-Sep-06		    Jorrit N. Herder    */
-/************************************************************************/
-
-#include <minix/callnr.h>
-#include <minix/config.h>
-#include <minix/type.h>
-#include <minix/const.h>
-#include <minix/com.h>
-#include <minix/syslib.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioc_cmos.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <signal.h>
-#include <ibm/portio.h>
-#include <ibm/cmos.h>
-#include <sys/svrctl.h>
-
-#define MAX_RETRIES	1
-
-int nflag = 0;		/* Tell what, but don't do it. */
-int y2kflag = 0;	/* Interpret 1980 as 2000 for clock with Y2K bug. */
-
-char clocktz[128];	/* Timezone of the clock. */
-
-#define MACH_ID_ADDR	0xFFFFE		/* BIOS Machine ID at FFFF:000E */
-
-#define PC_AT		   0xFC		/* Machine ID byte for PC/AT,
-					   PC/XT286, and PS/2 Models 50, 60 */
-#define PS_386		   0xF8		/* Machine ID byte for PS/2 Model 80 */
-
-/* Manufacturers usually use the ID value of the IBM model they emulate.
- * However some manufacturers, notably HP and COMPAQ, have had different
- * ideas in the past.
- *
- * Machine ID byte information source:
- *	_The Programmer's PC Sourcebook_ by Thom Hogan,
- *	published by Microsoft Press
- */
-
-void errmsg(char *s);
-int bcd_to_dec(int n);
-int dec_to_bcd(int n);
-void usage(void);
-
-#define CMOS_DEV "/dev/cmos"
-
-PUBLIC int main(int argc, char **argv)
-{
-  int fd;
-  struct tm time1;
-  struct tm time2;
-  struct tm tmnow;
-  char date[64];
-  time_t now, rtc;
-  int i, s, mem;
-  unsigned char mach_id, cmos_state;
-  struct sysgetenv sysgetenv;
-  message m;
-  int request;
-
-
-  /* Process options. */
-  while (argc > 1) {
-	char *p = *++argv;
-
-	if (*p++ != '-') usage();
-
-	while (*p != 0) {
-		switch (*p++) {
-		case 'n':	nflag = 1;	break;
-		case '2':	y2kflag = 1;	break;
-		default:	usage();
-		}
-	}
-	argc--;
-  }
-
-#if DEAD_CODE
-  /* The hardware clock may run in a different time zone, likely GMT or
-   * winter time.  Select that time zone.
-   */
-  strcpy(clocktz, "TZ=");
-  sysgetenv.key = "TZ";
-  sysgetenv.keylen = 2+1;
-  sysgetenv.val = clocktz+3;
-  sysgetenv.vallen = sizeof(clocktz)-3;
-  if (svrctl(SYSGETENV, &sysgetenv) == 0) {
-	putenv(clocktz);
-	tzset();
-  }
-#endif
-
-  /* Read the CMOS real time clock. */
-  for (i = 0; i < MAX_RETRIES; i++) {
-
-	/* sleep, unless first iteration */
-	if (i > 0) sleep(5);
-
-	/* Open the CMOS device to read the system time. */
-	if ((fd = open(CMOS_DEV, O_RDONLY)) < 0) {
-		perror(CMOS_DEV);
-		fprintf(stderr, "Couldn't open CMOS device.\n");
-		exit(1);
-	}
-        request = (y2kflag) ? CIOCGETTIME : CIOCGETTIMEY2K;
-	if ((s=ioctl(fd, request, (void *) &time1)) < 0) {
-		perror("ioctl");
-		fprintf(stderr, "Couldn't do CMOS ioctl.\n");
-		exit(1);
-	}
-	close(fd);
-
-	now = time(NULL);
-
-	time1.tm_isdst = -1;	/* Do timezone calculations. */
-	time2 = time1;
-
-	rtc= mktime(&time1);	/* Transform to a time_t. */
-	if (rtc != -1) {
-		break;
-	}
-
-	fprintf(stderr,
-"readclock: Invalid time read from CMOS RTC: %d-%02d-%02d %02d:%02d:%02d\n",
-		time2.tm_year+1900, time2.tm_mon+1, time2.tm_mday,
-		time2.tm_hour, time2.tm_min, time2.tm_sec);
-  }
-  if (i >= MAX_RETRIES) exit(1);
-
-  /* Now set system time. */
-  if (nflag) {
-		printf("stime(%lu)\n", (unsigned long) rtc);
-  } else {
-	if (stime(&rtc) < 0) {
-		errmsg( "Not allowed to set time." );
-		exit(1);
-	}
-  }
-  tmnow = *localtime(&rtc);
-  if (strftime(date, sizeof(date),
-			"%a %b %d %H:%M:%S %Z %Y", &tmnow) != 0) {
-	if (date[8] == '0') date[8]= ' ';
-#if 0
-	printf("%s [CMOS read via FS, see command/ibm/readclock.c]\n", date);
-#endif
-  }
-  exit(0);
-}
-
-void errmsg(char *s)
-{
-  static char *prompt = "readclock: ";
-
-  fprintf(stderr, "%s%s\n", prompt, s);
-  prompt = "";
-}
-
-
-int bcd_to_dec(int n)
-{
-  return ((n >> 4) & 0x0F) * 10 + (n & 0x0F);
-}
-
-int dec_to_bcd(int n)
-{
-  return ((n / 10) << 4) | (n % 10);
-}
-
-void usage(void)
-{
-  fprintf(stderr, "Usage: settime [-n2]\n");
-  exit(1);
-}
Index: trunk/minix/commands/ibm/recwave.c
===================================================================
--- trunk/minix/commands/ibm/recwave.c	(revision 9)
+++ 	(revision )
@@ -1,237 +1,0 @@
-/*   
- *  recwave.c
- *
- *  Record sound files in wave format. Only MicroSoft PCM is supported. 
- *
- *  Michel R. Prevenier.
- */
-
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <termios.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/ioctl.h>
-#include <minix/sound.h>
-
-_PROTOTYPE (void main, (int argc, char **argv));
-_PROTOTYPE (void usage, (void));
-_PROTOTYPE ( void write_wave_header, (void));
-_PROTOTYPE ( void terminate, (int s));
-
-
-/******* Wave format definitions *********/
-
-#define RIFF_ID		0x46464952
-#define WAVE_ID1	0x45564157
-#define WAVE_ID2	0x20746D66
-#define DATA_ID		0x61746164
-#define MS_PCM_FORMAT	0x0001
-
-#define WORD	short 
-#define DWORD   unsigned long
-
-struct RIFF_fields
-{
-  DWORD RIFF_id;
-  DWORD RIFF_len;
-  DWORD WAVE_id1;
-  DWORD WAVE_id2;
-  DWORD data_ptr;
-} r_fields; 
-
-struct common_fields
-{
-  WORD  FormatTag;
-  WORD  Channels;
-  DWORD SamplesPerSec;
-  DWORD AvgBytesPerSec;
-  WORD  BlockAlign;
-} c_fields;
-
-struct specific_fields
-{
-  WORD BitsPerSample;
-} s_fields;
-
-DWORD data_id;
-DWORD data_len;
-
-/******** End of wave format definitions *********/
-
-/* Default recording values */
-unsigned int sign = 0; 
-unsigned int bits = 8; 
-unsigned int stereo = 0; 
-unsigned int rate = 22050; 
-unsigned int time = 10;
-
-int old_stdin;
-struct termios old_tty, new_tty;
-int audio, file;
-
-void usage()
-{
-  fprintf(stderr, "Usage: recwav [-b -s -r] file_name\n");
-  exit(-1);
-}
-
-void terminate(s)
-int s;
-{
-  /* Restore terminal parameters */
-  tcsetattr(0, TCSANOW, &old_tty);
-  (void) fcntl(0,F_SETFL,old_stdin);
-  close(audio);
-  close(file);
-  exit(0);		
-}
-
-void write_wave_header()
-{
-  /* RIFF fields */
-  r_fields.RIFF_id = RIFF_ID;
-  r_fields.WAVE_id1 = WAVE_ID1;
-  r_fields.WAVE_id2 = WAVE_ID2;
-  r_fields.data_ptr = 16;
-  r_fields.RIFF_len = 20 + r_fields.data_ptr + data_len;
-
-  /* MicroSoft PCM specific fields */
-  s_fields.BitsPerSample = bits;
-
-  /* Common fields */
-  c_fields.FormatTag = MS_PCM_FORMAT;
-  c_fields.Channels = stereo + 1;
-  c_fields.SamplesPerSec = rate;
-  c_fields.AvgBytesPerSec =  c_fields.Channels * rate * (bits / 8);
-  c_fields.BlockAlign = c_fields.Channels * (bits / 8);
-
-  /* Data chunk */
-  data_id = DATA_ID;
-
-  /* Write wave-file header */
-  lseek(file, 0L, SEEK_SET);
-  write(file, &r_fields, 20);
-  write(file, &c_fields, 14);
-  write(file, &s_fields, 2);
-  write(file, &data_id, sizeof(data_id)); 
-  write(file, &data_len, sizeof(data_len)); 
-}
-
-
-void main(argc, argv)
-int argc;
-char **argv;
-{
-  unsigned int fragment_size;
-  char *buffer, *file_name;
-  char c;
-  int i;
-
-  /* Read parameters */
-  if (argc < 2) usage();
-
-  i = 1;
-  while (argv[i][0] == '-' && i < argc)
-  {
-    if (strncmp(argv[i], "-b", 2) == 0)
-      bits = atoi(argv[i] + 2);
-    else if (strncmp(argv[i], "-s", 2) == 0) 
-      stereo = atoi(argv[i] + 2);
-    else if (strncmp(argv[i], "-r", 2) == 0) 
-      rate = (unsigned int) atol(argv[i] + 2);
-    else usage();
-    i++;
-  }
-  if (i == argc) usage();
-
-  file_name = argv[i];
-
-  /* Some sanity checks */
-  if ((bits != 8 && bits != 16) || 
-      (rate < 4000 || rate > 44100) ||
-      (stereo != 0 && stereo != 1))
-  {
-    fprintf(stderr, "Invalid parameters\n");
-    exit(-1);
-  }
-
-  /* Open DSP */
-  if ((audio = open("/dev/rec", O_RDWR)) < 0) 
-  {
-    fprintf(stderr, "Cannot open /dev/rec\n");
-    exit(-1);
-  }
-
-  /* Get maximum fragment size and try to allocate a buffer */
-  ioctl(audio, DSPIOMAX, &fragment_size);
-  if ((buffer = malloc(fragment_size)) == (char *) 0)
-  {
-    fprintf(stderr, "Cannot allocate buffer\n");
-    exit(-1);
-  } 
-
-  /* Set sample parameters */
-  ioctl(audio, DSPIOSIZE, &fragment_size); 
-  ioctl(audio, DSPIOSTEREO, &stereo); 
-  ioctl(audio, DSPIORATE, &rate);
-  ioctl(audio, DSPIOBITS, &bits); 
-  sign = (bits == 16 ? 1 : 0);
-  ioctl(audio, DSPIOSIGN, &sign); 
-
-  /* Create sample file */
-  if ((file = creat(file_name, 511)) < 0) 
-  {
-    fprintf(stderr, "Cannot create %s\n", argv[1]);
-    exit(-1);
-  } 
-  /* Skip wave header */
-  lseek(file, (long)(sizeof(r_fields) + 
-                     sizeof(c_fields) + 
-                     sizeof(s_fields) + 
-                     sizeof(data_id) + 
-                     sizeof(data_len)), SEEK_SET); 
-
-  printf("\nBits per sample   : %u\n", bits);
-  printf("Stereo            : %s\n", (stereo == 1 ? "yes" : "no"));
-  printf("Samples per second: %u\n", rate);
-
-  /* Set terminal parameters and remember the old ones */
-  tcgetattr(0, &old_tty);
-  new_tty = old_tty;
-  new_tty.c_lflag &= ~(ICANON|ECHO);
-  old_stdin = fcntl(0, F_GETFL);
-
-  /* Catch break signal to be able to restore terminal parameters in case
-   * of a user interrupt
-   */
-  signal(SIGINT, terminate);
-
-  /* Go to non-blocking mode */
-  tcsetattr(0, TCSANOW, &new_tty);
-  (void) fcntl(0, F_SETFL, old_stdin | O_NONBLOCK);
-
-  printf("\nPress spacebar to start sampling...\n");
-  while(!(read(0, &c, 1) == 1 && c == ' '));
-
-  printf("Sampling, press spacebar to stop...\n");
-  while(!(read(0, &c, 1) == 1 && c == ' '))
-  {
-    /* Read sample fragment and write to sample file */
-    read(audio, buffer, fragment_size);
-    write(file, buffer, fragment_size);
-    data_len+= fragment_size;
-  }
-  printf("%ld bytes sampled. \n\n", data_len);
- 
-  /* Construct the wave header in front of the raw sample data */
-  write_wave_header();
-  
-  /* Restore terminal parameters and exit */
-  terminate(1);
-}
Index: trunk/minix/commands/ibm/repartition.c
===================================================================
--- trunk/minix/commands/ibm/repartition.c	(revision 9)
+++ 	(revision )
@@ -1,283 +1,0 @@
-/*	repartition 1.18 - Load a partition table	Author: Kees J. Bot
- *								30 Nov 1991
- */
-#define nil 0
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <minix/config.h>
-#include <minix/const.h>
-#include <minix/partition.h>
-#include <minix/u64.h>
-#include <ibm/partition.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <errno.h>
-#include <dirent.h>
-#include <limits.h>
-
-#define DEV_FD0		0x200
-
-#define SECTOR_SIZE	512
-
-#define arraysize(a)	(sizeof(a)/sizeof((a)[0]))
-#define arraylimit(a)	((a) + arraysize(a))
-
-char *arg0;
-char *dev_file;		/* Device to repartition. */
-
-#ifndef S_ISLNK
-/* There were no symlinks in medieval times. */
-#define lstat		stat
-#endif
-
-void report(const char *label)
-{
-	fprintf(stderr, "%s: %s: %s\n", arg0, label, strerror(errno));
-}
-
-void fatal(const char *label)
-{
-	report(label);
-	exit(1);
-}
-
-#ifndef makedev
-#define minor(dev)	(((dev) >> MINOR) & BYTE)
-#define major(dev)	(((dev) >> MAJOR) & BYTE)
-#define makedev(major, minor)	\
-			((dev_t) (((major) << MAJOR) | ((minor) << MINOR)))
-#endif
-
-#define MINOR_d0p0s0	128
-
-void partsort(struct part_entry *pe)
-/* DOS has the misguided idea that partition tables must be sorted. */
-{
-  int i,j;
-  struct part_entry tmp;
-
-  for (i = 0; i < NR_PARTITIONS; i++)
-	for (j = 0; j < NR_PARTITIONS-1; j++)
-		if ((pe[j].sysind == NO_PART && pe[j+1].sysind != NO_PART) ||
-		 (pe[j].lowsec > pe[j+1].lowsec && pe[j+1].sysind != NO_PART)) {
-			tmp = pe[j];
-			pe[j] = pe[j+1];
-			pe[j+1] = tmp;
-		}
-}
-
-char *finddev(dev_t device)
-/* Find the device next to dev_file with the given device number. */
-{
-	DIR *dp;
-	struct dirent *de;
-	static char name[PATH_MAX];
-	char *np;
-	size_t nlen;
-	struct stat st;
-
-	if ((np= strrchr(dev_file, '/')) == nil) np= dev_file; else np++;
-	nlen= np - dev_file;
-	if (nlen > PATH_MAX - NAME_MAX - 1) {
-		fprintf(stderr, "%s: %s: Name is way too long\n",
-			arg0, dev_file);
-		exit(1);
-	}
-	memcpy(name, dev_file, nlen);
-
-	if ((dp= opendir("/dev")) == nil) fatal("/dev");
-	while ((de= readdir(dp)) != nil) {
-		strcpy(name+nlen, de->d_name);
-		if (lstat(name, &st) == 0
-			&& (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
-			&& st.st_rdev == device
-		) {
-			closedir(dp);
-			return name;
-		}
-	}
-	fprintf(stderr, "%s: Can't find partition devices associated with %s\n",
-		arg0, dev_file);
-	exit(1);
-}
-
-#define DSETP	0
-#define DGETP	1
-
-int diocntl(dev_t device, int request, struct partition *entry)
-/* Get or set the geometry of a device. */
-{
-	char *name;
-	int r, f, err;
-	struct partition geometry;
-
-	name= finddev(device);
-	if ((f= open(name, O_RDONLY)) < 0) return -1;
-	r= ioctl(f, request == DSETP ? DIOCSETP : DIOCGETP, (void *) entry);
-	err= errno;
-	(void) close(f);
-	errno= err;
-	return r;
-}
-
-struct partition geometry;	/* Geometry of the device. */
-
-void print_chs(unsigned long sector)
-{
-	unsigned secspcyl = geometry.heads * geometry.sectors;
-	int delta= 0;
-
-	if (sector == -1) { sector= 0; delta= -1; }
-
-	printf(" %5d/%03d/%02d",
-		(int) (sector / secspcyl),
-		(int) (sector % secspcyl) / geometry.sectors,
-		(int) (sector % geometry.sectors) + delta);
-}
-
-void show_part(char *name, unsigned long base, unsigned long size)
-{
-	int i;
-	static int len= 0;
-
-	if (len == 0) {
-		len= strlen(name) + 3;
-		printf("device");
-		for (i = 6; i < len; i++) fputc(' ', stdout);
-		printf(
-	"      first         last        base      size        kb\n");
-	}
-
-	printf("%s", name);
-	for (i = strlen(name); i < len; i++) fputc(' ', stdout);
-
-	print_chs(base);
-	print_chs(base + size - 1);
-	printf(" %9lu %9lu %9lu\n", base, size, size / (1024/SECTOR_SIZE));
-}
-
-int main(int argc, char **argv)
-{
-	struct stat hdst;
-	struct partition whole, entry;
-	struct part_entry table[4], *pe;
-	int drive, par, device, incr;
-	int partf;
-	char *table_file;
-	int hd_major, hd_minor;
-	int needsort;
-	int shrink;		/* True if partitions are shrinked to fit. */
-	unsigned long base, size, limit;
-
-	if ((arg0= strrchr(argv[0], '/')) == nil) arg0= argv[0]; else arg0++;
-
-	if (argc < 2 || argc > 3) {
-		fprintf(stderr,
-			"Usage: %s device [partition-file]\n", arg0);
-		exit(1);
-	}
-	dev_file= argv[1];
-	table_file= argv[argc - 1];
-	shrink= (argc == 2);
-
-	if (stat(dev_file, &hdst) < 0) fatal(dev_file);
-
-	/* Geometry (to print nice numbers.) */
-	if (diocntl(hdst.st_rdev, DGETP, &geometry) < 0) fatal(dev_file);
-
-	if (!S_ISBLK(hdst.st_mode)) {
-		fprintf(stderr, "%s: %s is not a device\n", arg0, dev_file);
-		exit(1);
-	}
-	hd_major= major(hdst.st_rdev);
-	hd_minor= minor(hdst.st_rdev);
-
-	if (hd_minor >= MINOR_d0p0s0) {
-		errno= EINVAL;
-		fatal(dev_file);
-	}
-
-	if (hd_major == major(DEV_FD0)) {
-		/* HD is actually a floppy. */
-		if (hd_minor >= 4) {
-			errno= EINVAL;
-			fatal(dev_file);
-		}
-		device= hd_minor + (28 << 2);
-		incr= 4;
-		needsort= 0;
-	} else
-	if (hd_minor % (1 + NR_PARTITIONS) == 0) {
-		/* Partitioning hd0, hd5, ... */
-		device= hd_minor + 1;
-		incr= 1;
-		needsort= 1;
-	} else {
-		/* Subpartitioning hd[1-4], hd[6-9], ... */
-		drive= hd_minor / (1 + NR_PARTITIONS);
-		par= hd_minor % (1 + NR_PARTITIONS) - 1;
-
-		device= MINOR_d0p0s0
-				+ (drive * NR_PARTITIONS + par) * NR_PARTITIONS;
-		if (device + NR_PARTITIONS - 1 > BYTE) {
-			errno= EINVAL;
-			fatal(dev_file);
-		}
-		incr= 1;
-		needsort= 0;
-	}
-	/* Device is now the first of the minor devices to be repartitioned. */
-
-	/* Read the partition table from the boot block. */
-	if ((partf= open(table_file, O_RDONLY)) < 0
-		|| lseek(partf, (off_t) PART_TABLE_OFF, SEEK_SET) == -1
-		|| (par= read(partf, (char *) table, (int) sizeof(table))) < 0
-	) fatal(table_file);
-
-	if (par < sizeof(table)) {
-		fprintf(stderr, "%s: %s does not contain a partition table\n",
-			arg0, table_file);
-		exit(1);
-	}
-	if (needsort) partsort(table);
-
-	/* Show the geometry of the affected drive or partition. */
-	if (diocntl(hdst.st_rdev, DGETP, &whole) < 0) fatal(dev_file);
-
-	/* Use sector numbers. */
-	base = div64u(whole.base, SECTOR_SIZE);
-	size = div64u(whole.size, SECTOR_SIZE);
-	limit = base + size;
-
-	show_part(dev_file, base, size);
-
-	/* Send the partition table entries to the device driver. */
-	for (par= 0; par < NR_PARTITIONS; par++, device+= incr) {
-		pe = &table[par];
-		if (shrink && pe->size != 0) {
-			/* Shrink the partition entry to fit within the
-			 * enclosing device just like the driver does.
-			 */
-			unsigned long part_limit= pe->lowsec + pe->size;
-
-			if (part_limit < pe->lowsec) part_limit= limit;
-			if (part_limit > limit) part_limit= limit;
-			if (pe->lowsec < base) pe->lowsec= base;
-			if (part_limit < pe->lowsec) part_limit= pe->lowsec;
-			pe->size= part_limit - pe->lowsec;
-		}
-
-		entry.base= mul64u(pe->lowsec, SECTOR_SIZE);
-		entry.size= mul64u(pe->size, SECTOR_SIZE);
-		if (diocntl(makedev(hd_major, device), DSETP, &entry) < 0)
-			fatal(dev_file);
-
-		show_part(finddev(makedev(hd_major, device)),
-							pe->lowsec, pe->size);
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/screendump.c
===================================================================
--- trunk/minix/commands/ibm/screendump.c	(revision 9)
+++ 	(revision )
@@ -1,136 +1,0 @@
-/*	screendump 1.2 - dump the contents of the console
- *							Author: Kees J. Bot
- *								16 Dec 1994
- */
-#define nil 0
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-#define BIOS_CRTBASE	0x00463L	/* BIOS parameters: CRT base. */
-#define CRTBASE_MONO	0x03B4		/* Value of CRT base for mono mode. */
-
-#define MONO_BASE	0xB0000L	/* Screen memory in monochrome mode. */
-#define COLOR_BASE	0xB8000L	/* ... colour mode. */
-
-#define DEF_COLS	80		/* Default screen geometry. */
-#define DEF_ROWS	25
-
-#define MAX_COLS	132		/* Maximum screen geometry. */
-#define MAX_ROWS	60
-
-char MEMORY[] =		"/dev/mem";	/* Memory device to read screen. */
-int mfd;				/* Open memory device. */
-
-void tell(const char *message)
-{
-	write(2, message, strlen(message));
-}
-
-void fatal(const char *label)
-{
-	const char *err= strerror(errno);
-
-	tell("screendump: ");
-	tell(label);
-	tell(": ");
-	tell(err);
-	tell("\n");
-	exit(1);
-}
-
-long video_base(void)
-/* Is it monochrome or colour? */
-{
-	static unsigned short bios_crtbase;
-
-	if (lseek(mfd, (off_t) BIOS_CRTBASE, SEEK_SET) == -1) fatal(MEMORY);
-	switch (read(mfd, &bios_crtbase, sizeof(bios_crtbase))) {
-	case -1:
-		fatal(MEMORY);
-	default:
-		tell("screendump: can't obtain BIOS parameter: short read\n");
-		exit(1);
-	case sizeof(bios_crtbase):
-		/* Fine */;
-	}
-
-	return bios_crtbase == CRTBASE_MONO ? MONO_BASE : COLOR_BASE;
-}
-
-void main(void)
-{
-	static unsigned char screen[MAX_COLS * MAX_ROWS * 2];
-	unsigned char *ps;
-	long base;
-	int lfd;
-	int row;
-	int nrows, ncols;
-	struct winsize winsize;
-
-	/* Open the memory device. */
-	if ((mfd= open(MEMORY, O_RDONLY)) < 0) fatal(MEMORY);
-
-	base= video_base();
-
-	/* Read screen memory. */
-	if (lseek(mfd, base, SEEK_SET) == -1) fatal(MEMORY);
-
-	switch (read(mfd, screen, sizeof(screen))) {
-	case -1:
-		fatal(MEMORY);
-	default:
-		tell("screendump: can't obtain screen dump: short read\n");
-		exit(1);
-	case sizeof(screen):
-		/* Fine */;
-	}
-
-	/* Try to obtain the screen geometry from /dev/log. */
-	ncols= DEF_COLS;
-	nrows= DEF_ROWS;
-	if ((lfd= open("/dev/log", O_WRONLY)) != -1
-		&& ioctl(lfd, TIOCGWINSZ, &winsize) == 0
-	) {
-		if (40 <= winsize.ws_col && winsize.ws_col <= MAX_COLS) {
-			ncols= winsize.ws_col;
-		}
-		if (25 <= winsize.ws_row && winsize.ws_row <= MAX_COLS) {
-			nrows= winsize.ws_row;
-		}
-	}
-	if (lfd != -1) close(lfd);
-
-	/* Print the contents of the screen line by line.  Omit trailing
-	 * blanks.  Note that screen memory consists of pairs of characters
-	 * and attribute bytes.
-	 */
-	ps= screen;
-	for (row= 0; row < nrows; row++) {
-		char line[MAX_COLS + 1];
-		char *pl= line;
-		int column;
-		int blanks= 0;
-
-		for (column= 0; column < ncols; column++) {
-			if (*ps <= ' ') {
-				/* Skip trailing junk. */
-				blanks++;
-			} else {
-				/* Reinsert blanks and add a character. */
-				while (blanks > 0) { *pl++= ' '; blanks--; }
-				*pl++= *ps;
-			}
-			/* Skip character and attribute byte. */
-			ps+= 2;
-		}
-		*pl++= '\n';
-		if (write(1, line, pl - line) < 0) fatal("stdout");
-	}
-	exit(0);
-}
Index: trunk/minix/commands/ibm/sdump.c
===================================================================
--- trunk/minix/commands/ibm/sdump.c	(revision 9)
+++ 	(revision )
@@ -1,191 +1,0 @@
-/* sdump - dump memory */
-
-#include <minix/config.h>
-#include <sys/types.h>
-#include <minix/const.h>
-#include <minix/type.h>
-#include <minix/ipc.h>
-#include <timers.h>
-#include <signal.h>
-
-#undef EXTERN
-#define EXTERN
-#include "../../servers/pm/const.h"
-#include "../../servers/pm/type.h"
-#include "../../servers/pm/mproc.h"
-#include "../../kernel/const.h"
-#include "../../kernel/type.h"
-#include "../../kernel/proc.h"
-#undef printf			/* printf was misdefined by the sys headers */
-
-#include <ctype.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#define STACK_BYTES 30000
-
-char *default_core = "core";
-int stack[STACK_BYTES / sizeof (int)];
-
-_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void read_segmap, (int fd, struct mproc *mp, long *seg_size));
-_PROTOTYPE(void read_registers, (int fd, struct proc *p));
-_PROTOTYPE(void dump_stack, (int fd, struct mproc *mp, long *seg_size));
-_PROTOTYPE(void error, (char *s1, char *s2));
-
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-  int fd;
-  long seg_size[NR_LOCAL_SEGS];	/* segment sizes in bytes */
-  struct mproc *mp;
-  struct proc *p;
-  char *file;
-
-  if (argc > 2) error("Usage: rdump [core_file]\n", "");
-
-  if (argc == 1)
-	file = default_core;
-  else
-	file = argv[1];
-
-  if ( (fd = open(file, O_RDONLY)) < 0) error("Cannot open", file);
-
-  mp = &mproc[0];
-  p = &proc[0];
-  read_segmap(fd, mp, seg_size);
-  read_registers(fd, p);
-  dump_stack(fd, mp, seg_size);
-  return(0);
-}
-
-void read_segmap(fd, mp, seg_size)
-int fd;
-struct mproc *mp;
-long seg_size[NR_LOCAL_SEGS];
-{
-  int i, segmap_size;
-
-  /* Read in the segment map. */
-  segmap_size = sizeof mp->mp_seg;
-  if (read(fd, (char *) mp, segmap_size) != segmap_size)
-	error("Cannot read segmap map from core image file", "");
-
-  for (i = 0; i < NR_LOCAL_SEGS; i++)
-	seg_size[i] = (long) mp->mp_seg[i].mem_len << CLICK_SHIFT;
-  printf("Seg sizes in bytes:  Text: %ld  Data: %ld, Stack: %ld\n",
-	 seg_size[T], seg_size[D], seg_size[S]);
-}
-
-void read_registers(fd, p)
-int fd;
-struct proc *p;
-{
-  int proctblsize;
-  struct stackframe_s r;
-
-  proctblsize = sizeof (struct proc);
-  if (read(fd, (char *) p, proctblsize) != proctblsize)
-	error("Cannot read process table from core image file", "");
-  r = p->p_reg;
-
-  /* Print proc table. */
-  printf("\n");
-#if (CHIP == INTEL)
-#if _WORD_SIZE == 4
-  printf("eax=%8lX   ebx=%8lX   ecx=%8lX   edx=%8lX\n",
-	 r.retreg, r.bx, r.cx, r.dx);
-  printf("esi=%8lX   edi=%8lX   ebp=%8lX   esp=%8lX   eip=%8lX\n",
-	 r.si, r.di, r.fp, r.sp, r.pc);
-  printf(" ds=%8lX    es=%8lX                   ss=%8lX    cs=%8lX\n",
-	 r.ds, r.es, r.ss, r.cs);
-  printf(" fs=%8lX    gs=%8lX                                  ef=%8lX\n",
-         r.fs, r.gs, r.psw);
-#else
-  printf(
-"ax=%4X  bx=%4X  cx=%4X  dx=%4X  si=%4X  di=%4X  bp=%4X  sp=%4X  ip=%4X\n",
-	 r.retreg, r.bx, r.cx, r.dx, r.si, r.di, r.fp, r.sp, r.pc);
-  printf(
-" f=%4X                             ds=%4X  es=%4X           ss=%4X  cs=%4X\n",
-	 r.psw, r.ds, r.es, r.ss, r.cs);
-#endif
-#endif /* (CHIP == INTEL) */
-#if (CHIP == M68000)
-  printf("pc=%8lx   psw=%4x\n", r.pc, r.psw);
-  printf("d0=%8lx   d1=%8lx   d2=%8lx   d3=%8lx\n", r.retreg, r.d1, r.d2, r.d3);
-  printf("d4=%8lx   d5=%8lx   d6=%8lx   d7=%8lx\n", r.d4, r.d5, r.d6, r.d7);
-  printf("a0=%8lx   a1=%8lx   a2=%8lx   a3=%8lx\n", r.a0, r.a1, r.a2, r.a3);
-  printf("a4=%8lx   a5=%8lx   a6=%8lx   a7=%8lx\n", r.a4, r.a5, r.a6, r.sp);
-#endif
-  printf("\n");
-}
-
-void dump_stack(fd, mp, seg_size)
-int fd;
-struct mproc *mp;
-long seg_size[NR_LOCAL_SEGS];
-{
-  unsigned char ch;
-  char format[32];
-  int word, i, stack_size, j;
-  vir_bytes v, vi;
-
-  /* Seek past text and data segments. */
-  lseek(fd, seg_size[T] + seg_size[D], SEEK_CUR);
-  v = mp->mp_seg[S].mem_vir << CLICK_SHIFT;
-
-  stack_size = (int) seg_size[S];
-  if (stack_size != seg_size[S] || stack_size < 0 || stack_size > STACK_BYTES)
-	error("Stack too large", "");
-
-  /* Dump the stack. */
-  if (read(fd, (char *) stack, stack_size) != stack_size)
-	error("Error reading stack from core file", "");
-
-#define BYTES(num)      ((unsigned) sizeof (num))
-#define DEC_DIGITS(num) (sizeof (num) <= 2 ? 6 : 11)	/* for 16/32 bit num */
-#define HEX_DIGITS(num) (((unsigned) sizeof (num) * CHAR_BIT + 3) / 4)
-
-  printf("%*s   %*s  %*s  %*s\n",
-	 HEX_DIGITS(vi), "Addr",
-	 HEX_DIGITS(word), "Hex",
-	 DEC_DIGITS(word), "Dec",
-	 BYTES(word), "Char");
-
-  /* The format string depends messily on the size of various things. */
-  strcpy(format, "%*");
-  if (sizeof v > sizeof (int)) strcat(format, "l");
-  strcat(format, "X:  %*");
-  if (sizeof word > sizeof (int)) strcat(format, "l");
-  strcat(format, "X  %*");
-  if (sizeof word > sizeof (int)) strcat(format, "l");
-  strcat(format, "d  ");
-  
-  for (i = stack_size / sizeof (int) - 1, vi = v + stack_size - sizeof (int);
-       i >= 0; --i, vi -= sizeof (int)) {
-	word = stack[i];
-	printf(format,
-	       HEX_DIGITS(vi), vi,
-	       HEX_DIGITS(word), word,
-	       DEC_DIGITS(word), word);
-	for (j = 0; j < BYTES(word); ++j, word >>= CHAR_BIT) {
-		ch = (unsigned char) word;
-		if (!isprint(ch)) ch = '.';
-		putchar(ch);
-	}
-	putchar('\n');
-  }
-}
-
-void error(s1, s2)
-char *s1, *s2;
-{
-  printf("%s %s\n", s1, s2);
-  exit(1);
-}
