/* vi: set sw=4 ts=4: */
/*
 * sfdisk version 3.0 - aeb - 950813
 *
 * Copyright (C) 1995  Andries E. Brouwer (aeb@cwi.nl)
 *
 * This program is free software. You can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation: either Version 1
 * or (at your option) any later version.
 *
 * A.V. Le Blanc (LeBlanc@mcc.ac.uk) wrote Linux fdisk 1992-1994,
 * patched by various people (faith@cs.unc.edu, martin@cs.unc.edu,
 * leisner@sdsp.mc.xerox.com, esr@snark.thyrsus.com, aeb@cwi.nl)
 * 1993-1995, with version numbers (as far as I have seen) 0.93 - 2.0e.
 * This program had (head,sector,cylinder) as basic unit, and was
 * (therefore) broken in several ways for the use on larger disks -
 * for example, my last patch (from 2.0d to 2.0e) was required
 * to allow a partition to cross cylinder 8064, and to write an
 * extended partition past the 4GB mark.
 *
 * The current program is a rewrite from scratch, and I started a
 * version numbering at 3.0.
 * 	Andries Brouwer, aeb@cwi.nl, 950813
 *
 * Well, a good user interface is still lacking. On the other hand,
 * many configurations cannot be handled by any other fdisk.
 * I changed the name to sfdisk to prevent confusion. - aeb, 970501
 *
 * Changes:
 * 19990319 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> - i18n
 *
 * busyboxed by Erik Andersen <andersee@debian.org> -- I stipped out
 * all the NLS, pulled in some includes, and made stuff smaller...
 */

#define PROGNAME "sfdisk"
#define VERSION "3.07"
#define DATE "990908"

#include "internal.h"
#include <stdio.h>
#include <stdlib.h>				/* atoi, free */
#include <stdarg.h>				/* varargs */
#include <unistd.h>				/* read, write */
#include <fcntl.h>				/* O_RDWR */
#include <errno.h>				/* ERANGE */
#include <string.h>				/* index() */
#include <ctype.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <linux/unistd.h>		/* _syscall */
#include <linux/hdreg.h>		/* HDIO_GETGEO */
#include <linux/fs.h>			/* BLKGETSIZE */


static const char sfdisk_usage[] =
	"sfdisk [options] device ...\n"
	"device: something like /dev/hda or /dev/sda\n"
	"useful options:\n"
	"    -s [or --show-size]: list size of a partition\n"
	"    -c [or --id]:        print or change partition Id\n"
	"    -l [or --list]:      list partitions of each device\n"
	"    -d [or --dump]:      idem, but in a format suitable for later input\n"
	"    -i [or --increment]: number cylinders etc. from 1 instead of from 0\n"
	"    -uS, -uB, -uC, -uM:  accept/report in units of sectors/blocks/cylinders/MB\n"
	"    -T [or --list-types]:list the known partition types\n"
	"    -D [or --DOS]:       for DOS-compatibility: waste a little space\n"
	"    -R [or --re-read]:   make kernel reread partition table\n"
	"    -N# :                change only the partition with number #\n"
	"    -n :                 do not actually write to disk\n"
	"    -O file :            save the sectors that will be overwritten to file\n"
	"    -I file :            restore these sectors again\n"
	"    -v [or --version]:   print version\n"
	"    -? [or --help]:      print this message\n"
	"dangerous options:\n"
	"    -g [or --show-geometry]: print the kernel's idea of the geometry\n"
	"    -x [or --show-extended]: also list extended partitions on output\n\n"
	"                             or expect descriptors for them on input\n"
	"    -L  [or --Linux]:      do not complain about things irrelevant for Linux\n"
	"    -q  [or --quiet]:      suppress warning messages\n"
	"    You can override the detected geometry using:\n"
	"    -C# [or --cylinders #]:set the number of cylinders to use\n"
	"    -H# [or --heads #]:    set the number of heads to use\n"
	"    -S# [or --sectors #]:  set the number of sectors to use\n"

	"You can disable all consistency checking with:\n"
	"    -f  [or --force]:      do what I say, even if it is stupid\n";



/* common stuff for fdisk, cfdisk, sfdisk */
struct systypes {
	unsigned char type;
	char *name;
};

static struct systypes i386_sys_types[] = {
	{0x00, "Empty"},
	{0x01, "FAT12"},
	{0x02, "XENIX root"},
	{0x03, "XENIX usr"},
	{0x04, "FAT16 <32M"},
	{0x05, "Extended"},			/* DOS 3.3+ extended partition */
	{0x06, "FAT16"},			/* DOS 16-bit >=32M */
	{0x07, "HPFS/NTFS"},		/* OS/2 IFS, eg, HPFS or NTFS or QNX */
	{0x08, "AIX"},				/* AIX boot (AIX -- PS/2 port or SplitDrive) */
	{0x09, "AIX bootable"},		/* AIX data or Coherent */
	{0x0a, "OS/2 Boot Manager"},	/* OS/2 Boot Manager */
	{0x0b, "Win95 FAT32"},
	{0x0c, "Win95 FAT32 (LBA)"},	/* LBA really is `Extended Int 13h' */
	{0x0e, "Win95 FAT16 (LBA)"},
	{0x0f, "Win95 Ext'd (LBA)"},
	{0x10, "OPUS"},
	{0x11, "Hidden FAT12"},
	{0x12, "Compaq diagnostics"},
	{0x14, "Hidden FAT16 <32M"},
	{0x16, "Hidden FAT16"},
	{0x17, "Hidden HPFS/NTFS"},
	{0x18, "AST Windows swapfile"},
	{0x1b, "Hidden Win95 FAT32"},
	{0x1c, "Hidden Win95 FAT32 (LBA)"},
	{0x1e, "Hidden Win95 FAT16 (LBA)"},
	{0x24, "NEC DOS"},
	{0x3c, "PartitionMagic recovery"},
	{0x40, "Venix 80286"},
	{0x41, "PPC PReP Boot"},
	{0x42, "SFS"},
	{0x4d, "QNX4.x"},
	{0x4e, "QNX4.x 2nd part"},
	{0x4f, "QNX4.x 3rd part"},
	{0x50, "OnTrack DM"},
	{0x51, "OnTrack DM6 Aux1"},	/* (or Novell) */
	{0x52, "CP/M"},				/* CP/M or Microport SysV/AT */
	{0x53, "OnTrack DM6 Aux3"},
	{0x54, "OnTrackDM6"},
	{0x55, "EZ-Drive"},
	{0x56, "Golden Bow"},
	{0x5c, "Priam Edisk"},
	{0x61, "SpeedStor"},
	{0x63, "GNU HURD or SysV"},	/* GNU HURD or Mach or Sys V/386 (such as ISC UNIX) */
	{0x64, "Novell Netware 286"},
	{0x65, "Novell Netware 386"},
	{0x70, "DiskSecure Multi-Boot"},
	{0x75, "PC/IX"},
	{0x80, "Old Minix"},		/* Minix 1.4a and earlier */
	{0x81, "Minix / old Linux"},	/* Minix 1.4b and later */
	{0x82, "Linux swap"},		/* also Solaris */
	{0x83, "Linux"},
	{0x84, "OS/2 hidden C: drive"},
	{0x85, "Linux extended"},
	{0x86, "NTFS volume set"},
	{0x87, "NTFS volume set"},
	{0x93, "Amoeba"},
	{0x94, "Amoeba BBT"},		/* (bad block table) */
	{0xa0, "IBM Thinkpad hibernation"},
	{0xa5, "BSD/386"},
	{0xa6, "OpenBSD"},
	{0xa7, "NeXTSTEP"},
	{0xb7, "BSDI fs"},
	{0xb8, "BSDI swap"},
	{0xc1, "DRDOS/sec (FAT-12)"},
	{0xc4, "DRDOS/sec (FAT-16 < 32M)"},
	{0xc6, "DRDOS/sec (FAT-16)"},
	{0xc7, "Syrinx"},
	{0xdb, "CP/M / CTOS / ..."},	/* CP/M or Concurrent CP/M or Concurrent DOS or CTOS */
	{0xe1, "DOS access"},		/* DOS access or SpeedStor 12-bit FAT extended partition */
	{0xe3, "DOS R/O"},			/* DOS R/O or SpeedStor */
	{0xe4, "SpeedStor"},		/* SpeedStor 16-bit FAT extended partition < 1024 cyl. */
	{0xeb, "BeOS fs"},
	{0xf1, "SpeedStor"},
	{0xf4, "SpeedStor"},		/* SpeedStor large partition */
	{0xf2, "DOS secondary"},	/* DOS 3.3+ secondary */
	{0xfd, "Linux raid autodetect"},	/* New (2.2.x) raid partition with autodetect
										   using persistent superblock */
	{0xfe, "LANstep"},			/* SpeedStor >1024 cyl. or LANstep */
	{0xff, "BBT"},				/* Xenix Bad Block Table */
	{0, 0}
};

#define SIZE(a)	(sizeof(a)/sizeof(a[0]))

/*
 * Table of contents:
 *  A. About seeking
 *  B. About sectors
 *  C. About heads, sectors and cylinders
 *  D. About system Ids
 *  E. About partitions
 *  F. The standard input
 *  G. The command line
 *  H. Listing the current situation
 *  I. Writing the new situation
 */
static int exit_status = 0;

static int force = 0;			/* 1: do what I say, even if it is stupid ... */
static int quiet = 0;			/* 1: suppress all warnings */
static int Linux = 0;			/* 1: suppress warnings irrelevant for Linux */
static int DOS = 0;				/* 1: shift extended partitions by #sectors, not 1 */
static int dump = 0;			/* 1: list in a format suitable for later input */
static int verify = 0;			/* 1: check that listed partition is reasonable */
static int no_write = 0;		/* 1: do not actually write to disk */
static int no_reread = 0;		/* 1: skip the BLKRRPART ioctl test at startup */
static int leave_last = 0;		/* 1: don't allocate the last cylinder */
static int opt_list = 0;
static char *save_sector_file = NULL;
static char *restore_sector_file = NULL;

static void warn(char *s, ...) __attribute__ ((format (printf, 1, 2)));
static void warn(char *s, ...)
{
	va_list p;

	va_start(p, s);
	fflush(stdout);
	if (!quiet)
		vfprintf(stderr, s, p);
	va_end(p);
}

/*
 *  A. About seeking
 */

/*
 * sseek: seek to specified sector - return 0 on failure
 *
 * For >4GB disks lseek needs a > 32bit arg, and we have to use llseek.
 * On the other hand, a 32 bit sector number is OK until 2TB.
 * The routines _llseek and sseek below are the only ones that
 * know about the loff_t type.
 */
#ifndef __alpha__
static
_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
		  loff_t *, res, uint, wh);
#endif

static int sseek(char *dev, unsigned int fd, unsigned long s)
{
	loff_t in, out;

	in = ((loff_t) s << 9);
	out = 1;

#ifndef __alpha__
	if (_llseek(fd, in >> 32, in & 0xffffffff, &out, SEEK_SET) != 0) {
#else
	if ((out = lseek(fd, in, SEEK_SET)) != in) {
#endif
		perror("llseek");
		errorMsg("seek error on %s - cannot seek to %lu\n", dev, s);
		return 0;
	}

	if (in != out) {
		errorMsg("seek error: wanted 0x%08x%08x, got 0x%08x%08x\n",
			  (uint) (in >> 32), (uint) (in & 0xffffffff),
			  (uint) (out >> 32), (uint) (out & 0xffffffff));
		return 0;
	}
	return 1;
}

/*
 *  B. About sectors
 */

/*
 * We preserve all sectors read in a chain - some of these will
 * have to be modified and written back.
 */
struct sector {
	struct sector *next;
	unsigned long sectornumber;
	int to_be_written;
	char data[512];
} *sectorhead;

static void free_sectors(void)
{
	struct sector *s;

	while (sectorhead) {
		s = sectorhead;
		sectorhead = s->next;
		free(s);
	}
}

static struct sector *get_sector(char *dev, int fd, unsigned long sno)
{
	struct sector *s;

	for (s = sectorhead; s; s = s->next)
		if (s->sectornumber == sno)
			return s;

	if (!sseek(dev, fd, sno))
		return 0;

	s = (struct sector *) xmalloc(sizeof(struct sector));

	if (read(fd, s->data, sizeof(s->data)) != sizeof(s->data)) {
		perror("read");
		errorMsg("read error on %s - cannot read sector %lu\n", dev, sno);
		free(s);
		return 0;
	}

	s->next = sectorhead;
	sectorhead = s;
	s->sectornumber = sno;
	s->to_be_written = 0;

	return s;
}

static int msdos_signature(struct sector *s)
{
	if (*(unsigned short *) (s->data + 0x1fe) != 0xaa55) {
		errorMsg("ERROR: sector %lu does not have an msdos signature\n",
			  s->sectornumber);
		return 0;
	}
	return 1;
}

static int write_sectors(char *dev, int fd)
{
	struct sector *s;

	for (s = sectorhead; s; s = s->next)
		if (s->to_be_written) {
			if (!sseek(dev, fd, s->sectornumber))
				return 0;
			if (write(fd, s->data, sizeof(s->data)) != sizeof(s->data)) {
				perror("write");
				errorMsg("write error on %s - cannot write sector %lu\n",
					  dev, s->sectornumber);
				return 0;
			}
			s->to_be_written = 0;
		}
	return 1;
}

static void ulong_to_chars(unsigned long u, char *uu)
{
	int i;

	for (i = 0; i < 4; i++) {
		uu[i] = (u & 0xff);
		u >>= 8;
	}
}

static unsigned long chars_to_ulong(unsigned char *uu)
{
	int i;
	unsigned long u = 0;

	for (i = 3; i >= 0; i--)
		u = (u << 8) | uu[i];
	return u;
}

static int save_sectors(char *dev, int fdin)
{
	struct sector *s;
	char ss[516];
	int fdout;

	fdout = open(save_sector_file, O_WRONLY | O_CREAT, 0444);
	if (fdout < 0) {
		perror(save_sector_file);
		errorMsg("cannot open partition sector save file (%s)\n",
			  save_sector_file);
		return 0;
	}

	for (s = sectorhead; s; s = s->next)
		if (s->to_be_written) {
			ulong_to_chars(s->sectornumber, ss);
			if (!sseek(dev, fdin, s->sectornumber))
				return 0;
			if (read(fdin, ss + 4, 512) != 512) {
				perror("read");
				errorMsg("read error on %s - cannot read sector %lu\n",
					  dev, s->sectornumber);
				return 0;
			}
			if (write(fdout, ss, sizeof(ss)) != sizeof(ss)) {
				perror("write");
				errorMsg("write error on %s\n", save_sector_file);
				return 0;
			}
		}
	return 1;
}

static void reread_disk_partition(char *dev, int fd);

static int restore_sectors(char *dev)
{
	int fdin, fdout, ct;
	struct stat statbuf;
	char *ss0, *ss;
	unsigned long sno;

	if (stat(restore_sector_file, &statbuf) < 0) {
		perror(restore_sector_file);
		errorMsg("cannot stat partition restore file (%s)\n",
			  restore_sector_file);
		return 0;
	}
	if (statbuf.st_size % 516) {
		errorMsg("partition restore file has wrong size - not restoring\n");
		return 0;
	}
	if (!(ss = (char *) malloc(statbuf.st_size))) {
		errorMsg("out of memory?\n");
		return 0;
	}
	fdin = open(restore_sector_file, O_RDONLY);
	if (fdin < 0) {
		perror(restore_sector_file);
		errorMsg("cannot open partition restore file (%s)\n",
			  restore_sector_file);
		return 0;
	}
	if (read(fdin, ss, statbuf.st_size) != statbuf.st_size) {
		perror("read");
		errorMsg("error reading %s\n", restore_sector_file);
		return 0;
	}

	fdout = open(dev, O_WRONLY);
	if (fdout < 0) {
		perror(dev);
		errorMsg("cannot open device %s for writing\n", dev);
		return 0;
	}

	ss0 = ss;
	ct = statbuf.st_size / 516;
	while (ct--) {
		sno = chars_to_ulong(ss);
		if (!sseek(dev, fdout, sno))
			return 0;
		if (write(fdout, ss + 4, 512) != 512) {
			perror(dev);
			errorMsg("error writing sector %lu on %s\n", sno, dev);
			return 0;
		}
		ss += 516;
	}
	free(ss0);

	reread_disk_partition(dev, fdout);

	return 1;
}

/*
 *  C. About heads, sectors and cylinders
 */

/*
 * <linux/hdreg.h> defines HDIO_GETGEO and
 * struct hd_geometry {
 *      unsigned char heads;
 *      unsigned char sectors;
 *      unsigned short cylinders;
 *      unsigned long start;
 * };
 */

/*
 * We consider several geometries for a disk:
 * B - the BIOS geometry, gotten from the kernel via HDIO_GETGEO
 * F - the fdisk geometry
 * U - the user-specified geometry
 *
 * 0 means unspecified / unknown
 */
struct geometry {
	unsigned long cylindersize;
	unsigned long heads, sectors, cylinders;
} B, F, U;

static void get_cylindersize(char *dev, int fd, int silent)
{
	struct hd_geometry g;
	int ioctl_ok = 0;

	B.heads = B.sectors = B.cylinders = 0;

	if (!ioctl(fd, HDIO_GETGEO, &g)) {
		ioctl_ok = 1;

		B.heads = g.heads;
		B.sectors = g.sectors;
		B.cylinders = g.cylinders;
	}

	if (U.heads)
		B.heads = U.heads;
	if (U.sectors)
		B.sectors = U.sectors;
	if (U.cylinders)
		B.cylinders = U.cylinders;

	B.cylindersize = B.heads * B.sectors;

	if (ioctl_ok) {
		if (g.start && !force) {
			warn
				("Warning: start=%ld - this looks like a partition rather than\n"
				 "the entire disk. Using fdisk on it is probably meaningless.\n"
				 "[Use the --force option if you really want this]\n",
				 g.start);
			exit(1);
		}
		if (B.heads != g.heads)
			warn("Warning: HDIO_GETGEO says that there are %d heads\n",
				 g.heads);
		if (B.sectors != g.sectors)
			warn("Warning: HDIO_GETGEO says that there are %d sectors\n",
				 g.sectors);
		if (B.cylinders != g.cylinders)
			warn("Warning: HDIO_GETGEO says that there are %d cylinders\n",
				 g.cylinders);
	} else if (!silent)
		if (!B.heads || !B.sectors || !B.cylinders)
			printf("Disk %s: cannot get geometry\n", dev);
	if (B.sectors > 63)
		warn
			("Warning: unlikely number of sectors (%ld - usually at most 63\n"
			 "This will give problems with all software that uses C/H/S addressing.\n",
			 B.sectors);
	if (!silent)
		printf("\nDisk %s: %lu cylinders, %lu heads, %lu sectors/track\n",
			   dev, B.cylinders, B.heads, B.sectors);
}

typedef struct {
	unsigned char h, s, c;
} chs;							/* has some c bits in s */
static chs zero_chs = { 0, 0, 0 };

typedef struct {
	unsigned long h, s, c;
} longchs;
static longchs zero_longchs;

static chs longchs_to_chs(longchs aa, struct geometry G)
{
	chs a;

	if (aa.h < 256 && aa.s < 64 && aa.c < 1024) {
		a.h = aa.h;
		a.s = aa.s | ((aa.c >> 2) & 0xc0);
		a.c = (aa.c & 0xff);
	} else if (G.heads && G.sectors) {
		a.h = G.heads - 1;
		a.s = G.sectors | 0xc0;
		a.c = 0xff;
	} else
		a = zero_chs;
	return a;
}

static longchs chs_to_longchs(chs a)
{
	longchs aa;

	aa.h = a.h;
	aa.s = (a.s & 0x3f);
	aa.c = (a.s & 0xc0);
	aa.c = (aa.c << 2) + a.c;
	return aa;
}

static longchs ulong_to_longchs(unsigned long sno, struct geometry G)
{
	longchs aa;

	if (G.heads && G.sectors && G.cylindersize) {
		aa.s = 1 + sno % G.sectors;
		aa.h = (sno / G.sectors) % G.heads;
		aa.c = sno / G.cylindersize;
		return aa;
	} else {
		return zero_longchs;
	}
}

//static unsigned long
//longchs_to_ulong (longchs aa, struct geometry G) {
//    return (aa.c*G.cylindersize + aa.h*G.sectors + aa.s - 1);
//}

static chs ulong_to_chs(unsigned long sno, struct geometry G)
{
	return longchs_to_chs(ulong_to_longchs(sno, G), G);
}

//static unsigned long
//chs_to_ulong (chs a, struct geometry G) {
//    return longchs_to_ulong(chs_to_longchs(a), G);
//}

static int is_equal_chs(chs a, chs b)
{
	return (a.h == b.h && a.s == b.s && a.c == b.c);
}

static int chs_ok(chs a, char *v, char *w)
{
	longchs aa = chs_to_longchs(a);
	int ret = 1;

	if (is_equal_chs(a, zero_chs))
		return 1;
	if (B.heads && aa.h >= B.heads) {
		warn("%s of partition %s has impossible value for head: "
			 "%ld (should be in 0-%ld)\n", w, v, aa.h, B.heads - 1);
		ret = 0;
	}
	if (B.sectors && (aa.s == 0 || aa.s > B.sectors)) {
		warn("%s of partition %s has impossible value for sector: "
			 "%ld (should be in 1-%ld)\n", w, v, aa.s, B.sectors);
		ret = 0;
	}
	if (B.cylinders && aa.c >= B.cylinders) {
		warn("%s of partition %s has impossible value for cylinders: "
			 "%ld (should be in 0-%ld)\n", w, v, aa.c, B.cylinders - 1);
		ret = 0;
	}
	return ret;
}

/*
 *  D. About system Ids
 */

#define EMPTY_PARTITION		0
#define EXTENDED_PARTITION	5
#define WIN98_EXTENDED		0x0f
#define DM6_AUX1PARTITION	0x51
#define DM6_AUX3PARTITION	0x53
#define DM6_PARTITION		0x54
#define EZD_PARTITION		0x55
#define LINUX_SWAP              0x82
#define LINUX_NATIVE	        0x83
#define LINUX_EXTENDED		0x85
#define BSD_PARTITION		0xa5

/* List of partition types now in i386_sys_types.c */

static const char *sysname(unsigned char type)
{
	struct systypes *s;

	for (s = i386_sys_types; s->name; s++)
		if (s->type == type)
			return s->name;
	return "Unknown";
}

static void list_types(void)
{
	struct systypes *s;

	printf("Id  Name\n\n");
	for (s = i386_sys_types; s->name; s++)
		printf("%2x  %s\n", s->type, s->name);
}

static int is_extended(unsigned char type)
{
	return (type == EXTENDED_PARTITION
			|| type == LINUX_EXTENDED || type == WIN98_EXTENDED);
}

static int is_bsd(unsigned char type)
{
	return (type == BSD_PARTITION);
}

/*
 *  E. About partitions
 */

/* MS/DOS partition */

struct partition {
	unsigned char bootable;		/* 0 or 0x80 */
	chs begin_chs;
	unsigned char sys_type;
	chs end_chs;
	unsigned int start_sect;	/* starting sector counting from 0 */
	unsigned int nr_sects;		/* nr of sectors in partition */
};

/* Unfortunately, partitions are not aligned, and non-Intel machines
   are unhappy with non-aligned integers. So, we need a copy by hand. */
static int copy_to_int(unsigned char *cp)
{
	unsigned int m;

	m = *cp++;
	m += (*cp++ << 8);
	m += (*cp++ << 16);
	m += (*cp++ << 24);
	return m;
}

static void copy_from_int(int m, char *cp)
{
	*cp++ = (m & 0xff);
	m >>= 8;
	*cp++ = (m & 0xff);
	m >>= 8;
	*cp++ = (m & 0xff);
	m >>= 8;
	*cp++ = (m & 0xff);
}

static void copy_to_part(char *cp, struct partition *p)
{
	p->bootable = *cp++;
	p->begin_chs.h = *cp++;
	p->begin_chs.s = *cp++;
	p->begin_chs.c = *cp++;
	p->sys_type = *cp++;
	p->end_chs.h = *cp++;
	p->end_chs.s = *cp++;
	p->end_chs.c = *cp++;
	p->start_sect = copy_to_int(cp);
	p->nr_sects = copy_to_int(cp + 4);
}

static void copy_from_part(struct partition *p, char *cp)
{
	*cp++ = p->bootable;
	*cp++ = p->begin_chs.h;
	*cp++ = p->begin_chs.s;
	*cp++ = p->begin_chs.c;
	*cp++ = p->sys_type;
	*cp++ = p->end_chs.h;
	*cp++ = p->end_chs.s;
	*cp++ = p->end_chs.c;
	copy_from_int(p->start_sect, cp);
	copy_from_int(p->nr_sects, cp + 4);
}

/* Roughly speaking, Linux doesn't use any of the above fields except
   for partition type, start sector and number of sectors. (However,
   see also linux/drivers/scsi/fdomain.c.)
   The only way partition type is used (in the kernel) is the comparison
   for equality with EXTENDED_PARTITION (and these Disk Manager types). */

struct part_desc {
	unsigned long start;
	unsigned long size;
	unsigned long sector, offset;	/* disk location of this info */
	struct partition p;
	struct part_desc *ep;		/* extended partition containing this one */
	int ptype;
#define DOS_TYPE	0
#define BSD_TYPE	1
} zero_part_desc;

struct part_desc *outer_extended_partition(struct part_desc *p)
{
	while (p->ep)
		p = p->ep;
	return p;
}

static int is_parent(struct part_desc *pp, struct part_desc *p)
{
	while (p) {
		if (pp == p)
			return 1;
		p = p->ep;
	}
	return 0;
}

struct disk_desc {
	struct part_desc partitions[128];
	int partno;
} oldp, newp;

/* determine where on the disk this information goes */
static void add_sector_and_offset(struct disk_desc *z)
{
	int pno;
	struct part_desc *p;

	for (pno = 0; pno < z->partno; pno++) {
		p = &(z->partitions[pno]);
		p->offset = 0x1be + (pno % 4) * sizeof(struct partition);

		p->sector = (p->ep ? p->ep->start : 0);
	}
}

/* tell the kernel to reread the partition tables */
static int reread_ioctl(int fd)
{
	if (ioctl(fd, BLKRRPART)) {
		perror("BLKRRPART");
		return -1;
	}
	return 0;
}

static int is_blockdev(int fd)
{
	struct stat statbuf;

	return (fstat(fd, &statbuf) == 0 && S_ISBLK(statbuf.st_mode));
}

/* reread after writing */
static void reread_disk_partition(char *dev, int fd)
{
	printf("Re-reading the partition table ...\n");
	fflush(stdout);
	sync();
	sleep(3);					/* superfluous since 1.3.20 */

	if (reread_ioctl(fd) && is_blockdev(fd))
		printf("The command to re-read the partition table failed\n"
			   "Reboot your system now, before using mkfs\n");

	if (close(fd)) {
		perror(dev);
		printf("Error closing %s\n", dev);
	}
	printf("\n");
}

/* find Linux name of this partition, assuming that it will have a name */
static int index_to_linux(int pno, struct disk_desc *z)
{
	int i, ct = 1;
	struct part_desc *p = &(z->partitions[0]);

	for (i = 0; i < pno; i++, p++)
		if (i < 4 || (p->size > 0 && !is_extended(p->p.sys_type)))
			ct++;
	return ct;
}

static int linux_to_index(int lpno, struct disk_desc *z)
{
	int i, ct = 0;
	struct part_desc *p = &(z->partitions[0]);

	for (i = 0; i < z->partno && ct < lpno; i++, p++)
		if ((i < 4 || (p->size > 0 && !is_extended(p->p.sys_type)))
			&& ++ct == lpno)
			return i;
	return -1;
}

static int asc_to_index(char *pnam, struct disk_desc *z)
{
	int pnum, pno;

	if (*pnam == '#') {
		pno = atoi(pnam + 1);
	} else {
		pnum = atoi(pnam);
		pno = linux_to_index(pnum, z);
	}
	if (!(pno >= 0 && pno < z->partno))
		fatalError("%s: no such partition\n", pnam);
	return pno;
}

/*
 * List partitions - in terms of sectors, blocks or cylinders
 */
#define F_SECTOR   1
#define F_BLOCK    2
#define F_CYLINDER 3
#define F_MEGABYTE 4

static int default_format = F_MEGABYTE;
static int specified_format = 0;
static int show_extended = 0;
static int one_only = 0;
static int one_only_pno;
static int increment = 0;

static void set_format(char c)
{
	switch (c) {
	default:
		printf("unrecognized format - using sectors\n");
	case 'S':
		specified_format = F_SECTOR;
		break;
	case 'B':
		specified_format = F_BLOCK;
		break;
	case 'C':
		specified_format = F_CYLINDER;
		break;
	case 'M':
		specified_format = F_MEGABYTE;
		break;
	}
}

static unsigned long unitsize(int format)
{
	default_format = (B.cylindersize ? F_CYLINDER : F_MEGABYTE);
	if (!format && !(format = specified_format))
		format = default_format;

	switch (format) {
	default:
	case F_CYLINDER:
		if (B.cylindersize)
			return B.cylindersize;
	case F_SECTOR:
		return 1;
	case F_BLOCK:
		return 2;
	case F_MEGABYTE:
		return 2048;
	}
}

static unsigned long get_disksize(int format)
{
	unsigned long cs = B.cylinders;

	if (cs && leave_last)
		cs--;
	return (cs * B.cylindersize) / unitsize(format);
}

static void out_partition_header(char *dev, int format, struct geometry G)
{
	if (dump) {
		printf("# partition table of %s\n", dev);
		printf("unit: sectors\n\n");
		return;
	}

	default_format = (G.cylindersize ? F_CYLINDER : F_MEGABYTE);
	if (!format && !(format = specified_format))
		format = default_format;

	switch (format) {
	default:
		printf("unimplemented format - using %s\n",
			   G.cylindersize ? "cylinders" : "sectors");
	case F_CYLINDER:
		if (G.cylindersize) {
			printf("Units = cylinders of %lu bytes, blocks of 1024 bytes"
				   ", counting from %d\n\n",
				   G.cylindersize << 9, increment);
			printf
				("   Device Boot Start     End   #cyls   #blocks   Id  System\n");
			break;
		}
		/* fall through */
	case F_SECTOR:
		printf("Units = sectors of 512 bytes, counting from %d\n\n",
			   increment);
		printf
			("   Device Boot    Start       End  #sectors  Id  System\n");
		break;
	case F_BLOCK:
		printf("Units = blocks of 1024 bytes, counting from %d\n\n",
			   increment);
		printf
			("   Device Boot   Start       End   #blocks   Id  System\n");
		break;
	case F_MEGABYTE:
		printf("Units = megabytes of 1048576 bytes, blocks of 1024 bytes"
			   ", counting from %d\n\n", increment);
		printf
			("   Device Boot Start   End     MB   #blocks   Id  System\n");
		break;
	}
}

static void
out_rounddown(int width, unsigned long n, unsigned long unit, int inc)
{
	printf("%*lu", width, inc + n / unit);
	if (unit != 1)
		putchar((n % unit) ? '+' : ' ');
	putchar(' ');
}

static void
out_roundup(int width, unsigned long n, unsigned long unit, int inc)
{
	if (n == (unsigned long) (-1))
		printf("%*s", width, "-");
	else
		printf("%*lu", width, inc + n / unit);
	if (unit != 1)
		putchar(((n + 1) % unit) ? '-' : ' ');
	putchar(' ');
}

static void
out_roundup_size(int width, unsigned long n, unsigned long unit)
{
	printf("%*lu", width, (n + unit - 1) / unit);
	if (unit != 1)
		putchar((n % unit) ? '-' : ' ');
	putchar(' ');
}

static int get_fdisk_geometry(struct part_desc *p)
{
	chs b = p->p.end_chs;
	longchs bb = chs_to_longchs(b);

	F.heads = bb.h + 1;
	F.sectors = bb.s;
	F.cylindersize = F.heads * F.sectors;
	return (F.sectors != B.sectors || F.heads != B.heads);
}

static void
out_partition(char *dev, int format, struct part_desc *p,
			  struct disk_desc *z, struct geometry G)
{
	unsigned long start, end, size;
	int pno, lpno;

	if (!format && !(format = specified_format))
		format = default_format;

	pno = p - &(z->partitions[0]);	/* our index */
	lpno = index_to_linux(pno, z);	/* name of next one that has a name */
	if (pno == linux_to_index(lpno, z))	/* was that us? */
		printf("%8s%-2u", dev, lpno);	/* yes */
	else if (show_extended)
		printf("    -     ");
	else
		return;
	putchar(dump ? ':' : ' ');

	start = p->start;
	end = p->start + p->size - 1;
	size = p->size;

	if (dump) {
		printf(" start=%9lu", start);
		printf(", size=%8lu", size);
		if (p->ptype == DOS_TYPE) {
			printf(", Id=%2x", p->p.sys_type);
			if (p->p.bootable == 0x80)
				printf(", bootable");
		}
		printf("\n");
		return;
	}

	if (p->ptype != DOS_TYPE || p->p.bootable == 0)
		printf("   ");
	else if (p->p.bootable == 0x80)
		printf(" * ");
	else
		printf(" ? ");			/* garbage */

	switch (format) {
	case F_CYLINDER:
		if (G.cylindersize) {
			out_rounddown(6, start, G.cylindersize, increment);
			out_roundup(6, end, G.cylindersize, increment);
			out_roundup_size(6, size, G.cylindersize);
			out_rounddown(8, size, 2, 0);
			break;
		}
		/* fall through */
	default:
	case F_SECTOR:
		out_rounddown(9, start, 1, increment);
		out_roundup(9, end, 1, increment);
		out_rounddown(9, size, 1, 0);
		break;
	case F_BLOCK:
#if 0
		printf("%8lu,%3lu ",
			   p->sector / 2, ((p->sector & 1) ? 512 : 0) + p->offset);
#endif
		out_rounddown(8, start, 2, increment);
		out_roundup(8, end, 2, increment);
		out_rounddown(8, size, 2, 0);
		break;
	case F_MEGABYTE:
		out_rounddown(5, start, 2048, increment);
		out_roundup(5, end, 2048, increment);
		out_roundup_size(5, size, 2048);
		out_rounddown(8, size, 2, 0);
		break;
	}
	if (p->ptype == DOS_TYPE) {
		printf(" %2x  %s\n", p->p.sys_type, sysname(p->p.sys_type));
	} else {
		printf("\n");
	}

	/* Is chs as we expect? */
	if (!quiet && p->ptype == DOS_TYPE) {
		chs a, b;
		longchs aa, bb;

		a = (size ? ulong_to_chs(start, G) : zero_chs);
		b = p->p.begin_chs;
		aa = chs_to_longchs(a);
		bb = chs_to_longchs(b);
		if (a.s && !is_equal_chs(a, b))
			printf
				("\t\tstart: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n",
				 aa.c, aa.h, aa.s, bb.c, bb.h, bb.s);
		a = (size ? ulong_to_chs(end, G) : zero_chs);
		b = p->p.end_chs;
		aa = chs_to_longchs(a);
		bb = chs_to_longchs(b);
		if (a.s && !is_equal_chs(a, b))
			printf
				("\t\tend: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n",
				 aa.c, aa.h, aa.s, bb.c, bb.h, bb.s);
		if (G.cylinders && G.cylinders < 1024 && bb.c > G.cylinders)
			printf
				("partition ends on cylinder %ld, beyond the end of the disk\n",
				 bb.c);
	}
}

static void out_partitions(char *dev, struct disk_desc *z)
{
	struct part_desc *p;
	int pno, format = 0;

	if (z->partno == 0)
		printf("No partitions found\n");
	else {
		for (pno = 0; pno < z->partno; pno++) {
			p = &(z->partitions[pno]);
			if (p->size != 0 && p->p.sys_type != 0) {
				if (get_fdisk_geometry(p))
					printf
						("Warning: The first partition looks like it was made\n"
						 "  for C/H/S=*/%ld/%ld (instead of %ld/%ld/%ld).\n"
						 "For this listing I'll assume that geometry.\n",
						 F.heads, F.sectors, B.cylinders, B.heads,
						 B.sectors);
				break;
			}
		}
		out_partition_header(dev, format, F);
		for (pno = 0; pno < z->partno; pno++) {
			out_partition(dev, format, &(z->partitions[pno]), z, F);
			if (show_extended && pno % 4 == 3)
				printf("\n");
		}
	}
}

static int disj(struct part_desc *p, struct part_desc *q)
{
	return ((p->start + p->size <= q->start)
			|| (is_extended(p->p.sys_type)
				&& q->start + q->size <= p->start + p->size));
}

static char *pnumber(struct part_desc *p, struct disk_desc *z)
{
	static char buf[20];
	int this, next;
	struct part_desc *p0 = &(z->partitions[0]);

	this = index_to_linux(p - p0, z);
	next = index_to_linux(p - p0 + 1, z);

	if (next > this)
		sprintf(buf, "%d", this);
	else
		sprintf(buf, "[%d]", this);
	return buf;
}

static int partitions_ok(struct disk_desc *z)
{
	struct part_desc *partitions = &(z->partitions[0]), *p, *q;
	int partno = z->partno;

#define PNO(p) pnumber(p, z)

	/* Have at least 4 partitions been defined? */
	if (partno < 4) {
		if (!partno)
			fatalError("no partition table present.\n");
		else
			fatalError("strange, only %d partitions defined.\n", partno);
		return 0;
	}

	/* Are the partitions of size 0 marked empty?
	   And do they have start = 0? And bootable = 0? */
	for (p = partitions; p - partitions < partno; p++)
		if (p->size == 0) {
			if (p->p.sys_type != EMPTY_PARTITION)
				warn
					("Warning: partition %s has size 0 but is not marked Empty\n",
					 PNO(p));
			else if (p->p.bootable != 0)
				warn("Warning: partition %s has size 0 and is bootable\n",
					 PNO(p));
			else if (p->p.start_sect != 0)
				warn
					("Warning: partition %s has size 0 and nonzero start\n",
					 PNO(p));
			/* all this is probably harmless, no error return */
		}

	/* Are the logical partitions contained in their extended partitions? */
	for (p = partitions + 4; p < partitions + partno; p++)
		if (p->ptype == DOS_TYPE)
			if (p->size && !is_extended(p->p.sys_type)) {
				q = p->ep;
				if (p->start < q->start
					|| p->start + p->size > q->start + q->size) {
					warn("Warning: partition %s ", PNO(p));
					warn("is not contained in partition %s\n", PNO(q));
					return 0;
				}
			}

	/* Are the data partitions mutually disjoint? */
	for (p = partitions; p < partitions + partno; p++)
		if (p->size && !is_extended(p->p.sys_type))
			for (q = p + 1; q < partitions + partno; q++)
				if (q->size && !is_extended(q->p.sys_type))
					if (!((p->start > q->start) ? disj(q, p) : disj(p, q))) {
						warn("Warning: partitions %s ", PNO(p));
						warn("and %s overlap\n", PNO(q));
						return 0;
					}

	/* Are the data partitions and the extended partition
	   table sectors disjoint? */
	for (p = partitions; p < partitions + partno; p++)
		if (p->size && !is_extended(p->p.sys_type))
			for (q = partitions; q < partitions + partno; q++)
				if (is_extended(q->p.sys_type))
					if (p->start <= q->start
						&& p->start + p->size > q->start) {
						warn("Warning: partition %s contains part of ",
							 PNO(p));
						warn("the partition table (sector %lu),\n",
							 q->start);
						warn("and will destroy it when filled\n");
						return 0;
					}

	/* Do they start past zero and end before end-of-disk? */
	{
		unsigned long ds = get_disksize(F_SECTOR);

		for (p = partitions; p < partitions + partno; p++)
			if (p->size) {
				if (p->start == 0) {
					warn("Warning: partition %s starts at sector 0\n",
						 PNO(p));
					return 0;
				}
				if (p->size && p->start + p->size > ds) {
					warn
						("Warning: partition %s extends past end of disk\n",
						 PNO(p));
					return 0;
				}
			}
	}

	/* At most one chain of DOS extended partitions ? */
	/* It seems that the OS/2 fdisk has the additional requirement
	   that the extended partition must be the fourth one */
	{
		int ect = 0;

		for (p = partitions; p < partitions + 4; p++)
			if (p->p.sys_type == EXTENDED_PARTITION)
				ect++;
		if (ect > 1 && !Linux) {
			warn
				("Among the primary partitions, at most one can be extended\n");
			warn(" (although this is not a problem under Linux)\n");
			return 0;
		}
	}

	/*
	 * Do all partitions start at a cylinder boundary ?
	 * (this is not required for Linux)
	 * The first partition starts after MBR.
	 * Logical partitions start slightly after the containing extended partn.
	 */
	if (B.cylindersize) {
		for (p = partitions; p < partitions + partno; p++)
			if (p->size) {
				if (p->start % B.cylindersize != 0
					&& (!p->ep
						|| p->start / B.cylindersize !=
						p->ep->start / B.cylindersize)
					&& (p->p.start_sect >= B.cylindersize)) {
					warn("Warning: partition %s does not start "
						 "at a cylinder boundary\n", PNO(p));
					if (!Linux)
						return 0;
				}
				if ((p->start + p->size) % B.cylindersize) {
					warn("Warning: partition %s does not end "
						 "at a cylinder boundary\n", PNO(p));
					if (!Linux)
						return 0;
				}
			}
	}

	/* Usually, one can boot only from primary partitions. */
	/* In fact, from a unique one only. */
	/* do not warn about bootable extended partitions -
	   often LILO is there */
	{
		int pno = -1;

		for (p = partitions; p < partitions + partno; p++)
			if (p->p.bootable) {
				if (pno == -1)
					pno = p - partitions;
				else if (p - partitions < 4) {
					warn
						("Warning: more than one primary partition is marked "
						 "bootable (active)\n"
						 "This does not matter for LILO, but the DOS MBR will "
						 "not boot this disk.\n");
					break;
				}
				if (p - partitions >= 4) {
					warn
						("Warning: usually one can boot from primary partitions "
						 "only\nLILO disregards the `bootable' flag.\n");
					break;
				}
			}
		if (pno == -1 || pno >= 4)
			warn
				("Warning: no primary partition is marked bootable (active)\n"
				 "This does not matter for LILO, but the DOS MBR will "
				 "not boot this disk.\n");
	}

	/* Is chs as we expect? */
	for (p = partitions; p < partitions + partno; p++)
		if (p->ptype == DOS_TYPE) {
			chs a, b;
			longchs aa, bb;

			a = p->size ? ulong_to_chs(p->start, B) : zero_chs;
			b = p->p.begin_chs;
			aa = chs_to_longchs(a);
			bb = chs_to_longchs(b);
			if (!chs_ok(b, PNO(p), "start"))
				return 0;
			if (a.s && !is_equal_chs(a, b))
				warn
					("partition %s: start: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n",
					 PNO(p), aa.c, aa.h, aa.s, bb.c, bb.h, bb.s);
			a =
				p->size ? ulong_to_chs(p->start + p->size - 1,
									   B) : zero_chs;
			b = p->p.end_chs;
			aa = chs_to_longchs(a);
			bb = chs_to_longchs(b);
			if (!chs_ok(b, PNO(p), "end"))
				return 0;
			if (a.s && !is_equal_chs(a, b))
				warn
					("partition %s: end: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n",
					 PNO(p), aa.c, aa.h, aa.s, bb.c, bb.h, bb.s);
			if (B.cylinders && B.cylinders < 1024 && bb.c > B.cylinders)
				warn
					("partition %s ends on cylinder %ld, beyond the end of the disk\n",
					 PNO(p), bb.c);
		}

	return 1;

#undef PNO
}

static void
extended_partition(char *dev, int fd, struct part_desc *ep,
				   struct disk_desc *z)
{
	char *cp;
	struct sector *s;
	unsigned long start, here, next;
	int i, moretodo = 1;
	struct partition p;
	struct part_desc *partitions = &(z->partitions[0]);
	int pno = z->partno;

	here = start = ep->start;

	while (moretodo) {
		moretodo = 0;

		if (!(s = get_sector(dev, fd, here)))
			break;

		if (!msdos_signature(s))
			break;

		cp = s->data + 0x1be;

		if (pno + 4 >= SIZE(z->partitions)) {
			printf("too many partitions - ignoring those past nr (%d)\n",
				   pno - 1);
			break;
		}

		next = 0;

		for (i = 0; i < 4; i++, cp += sizeof(struct partition)) {
			partitions[pno].sector = here;
			partitions[pno].offset = cp - s->data;
			partitions[pno].ep = ep;
			copy_to_part(cp, &p);
			if (is_extended(p.sys_type)) {
				partitions[pno].start = start + p.start_sect;
				if (next)
					printf("tree of partitions?\n");
				else
					next = partitions[pno].start;	/* follow `upper' branch */
				moretodo = 1;
			} else {
				partitions[pno].start = here + p.start_sect;
			}
			partitions[pno].size = p.nr_sects;
			partitions[pno].ptype = DOS_TYPE;
			partitions[pno].p = p;
			pno++;
		}
		here = next;
	}

	z->partno = pno;
}

#define BSD_DISKMAGIC   (0x82564557UL)
#define BSD_MAXPARTITIONS       8
#define BSD_FS_UNUSED           0
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
struct bsd_disklabel {
	u32 d_magic;
	char d_junk1[4];
	char d_typename[16];
	char d_packname[16];
	char d_junk2[92];
	u32 d_magic2;
	char d_junk3[2];
	u16 d_npartitions;			/* number of partitions in following */
	char d_junk4[8];
	struct bsd_partition {		/* the partition table */
		u32 p_size;				/* number of sectors in partition */
		u32 p_offset;			/* starting sector */
		u32 p_fsize;			/* filesystem basic fragment size */
		u8 p_fstype;			/* filesystem type, see below */
		u8 p_frag;				/* filesystem fragments per block */
		u16 p_cpg;				/* filesystem cylinders per group */
	} d_partitions[BSD_MAXPARTITIONS];	/* actually may be more */
};

static void
bsd_partition(char *dev, int fd, struct part_desc *ep, struct disk_desc *z)
{
	struct bsd_disklabel *l;
	struct bsd_partition *bp, *bp0;
	unsigned long start = ep->start;
	struct sector *s;
	struct part_desc *partitions = &(z->partitions[0]);
	int pno = z->partno;

	if (!(s = get_sector(dev, fd, start + 1)))
		return;
	l = (struct bsd_disklabel *) (s->data);
	if (l->d_magic != BSD_DISKMAGIC)
		return;

	bp = bp0 = &l->d_partitions[0];
	while (bp - bp0 <= BSD_MAXPARTITIONS) {
		if (pno + 1 >= SIZE(z->partitions)) {
			printf("too many partitions - ignoring those "
				   "past nr (%d)\n", pno - 1);
			break;
		}
		if (bp->p_fstype != BSD_FS_UNUSED) {
			partitions[pno].start = bp->p_offset;
			partitions[pno].size = bp->p_size;
			partitions[pno].sector = start + 1;
			partitions[pno].offset = (char *) bp - (char *) bp0;
			partitions[pno].ep = 0;
			partitions[pno].ptype = BSD_TYPE;
			pno++;
		}
		bp++;
	}
	z->partno = pno;
}

static int
msdos_partition(char *dev, int fd, unsigned long start,
				struct disk_desc *z)
{
	int i;
	char *cp;
	struct partition pt;
	struct sector *s;
	struct part_desc *partitions = &(z->partitions[0]);
	int pno = z->partno;

	if (!(s = get_sector(dev, fd, start)))
		return 0;

	if (!msdos_signature(s))
		return 0;

	cp = s->data + 0x1be;
	copy_to_part(cp, &pt);

	/* If I am not mistaken, recent kernels will hide this from us,
	   so we will never actually see traces of a Disk Manager */
	if (pt.sys_type == DM6_PARTITION
		|| pt.sys_type == EZD_PARTITION
		|| pt.sys_type == DM6_AUX1PARTITION
		|| pt.sys_type == DM6_AUX3PARTITION) {
		printf("detected Disk Manager - unable to handle that\n");
		return 0;
	}
	{
		unsigned int sig = *(unsigned short *) (s->data + 2);

		if (sig <= 0x1ae
			&& *(unsigned short *) (s->data + sig) == 0x55aa
			&& (1 & *(unsigned char *) (s->data + sig + 2))) {
			printf("DM6 signature found - giving up\n");
			return 0;
		}
	}

	for (pno = 0; pno < 4; pno++, cp += sizeof(struct partition)) {
		partitions[pno].sector = start;
		partitions[pno].offset = cp - s->data;
		copy_to_part(cp, &pt);
		partitions[pno].start = start + pt.start_sect;
		partitions[pno].size = pt.nr_sects;
		partitions[pno].ep = 0;
		partitions[pno].p = pt;
	}

	z->partno = pno;

	for (i = 0; i < 4; i++) {
		if (is_extended(partitions[i].p.sys_type)) {
			if (!partitions[i].size) {
				printf("strange..., an extended partition of size 0?\n");
				continue;
			}
			extended_partition(dev, fd, &partitions[i], z);
		}
		if (is_bsd(partitions[i].p.sys_type)) {
			if (!partitions[i].size) {
				printf("strange..., a BSD partition of size 0?\n");
				continue;
			}
			bsd_partition(dev, fd, &partitions[i], z);
		}
	}
	return 1;
}

static int
osf_partition(char *dev, int fd, unsigned long start, struct disk_desc *z)
{
	return 0;
}

static int
sun_partition(char *dev, int fd, unsigned long start, struct disk_desc *z)
{
	return 0;
}

static int
amiga_partition(char *dev, int fd, unsigned long start,
				struct disk_desc *z)
{
	return 0;
}

static void get_partitions(char *dev, int fd, struct disk_desc *z)
{
	z->partno = 0;

	if (!msdos_partition(dev, fd, 0, z)
		&& !osf_partition(dev, fd, 0, z)
		&& !sun_partition(dev, fd, 0, z)
		&& !amiga_partition(dev, fd, 0, z)) {
		printf(" %s: unrecognized partition\n", dev);
		return;
	}
}

static int write_partitions(char *dev, int fd, struct disk_desc *z)
{
	struct sector *s;
	struct part_desc *partitions = &(z->partitions[0]), *p;
	int pno = z->partno;

	if (no_write) {
		printf("-n flag was given: Nothing changed\n");
		exit(0);
	}

	for (p = partitions; p < partitions + pno; p++) {
		s = get_sector(dev, fd, p->sector);
		if (!s)
			return 0;
		s->to_be_written = 1;
		copy_from_part(&(p->p), s->data + p->offset);
		*(unsigned short *) (&(s->data[0x1fe])) = 0xaa55;
	}
	if (save_sector_file) {
		if (!save_sectors(dev, fd)) {
			fatalError("Failed saving the old sectors - aborting\n");
			return 0;
		}
	}
	if (!write_sectors(dev, fd)) {
		errorMsg("Failed writing the partition on %s\n", dev);
		return 0;
	}
	return 1;
}

/*
 *  F. The standard input
 */

/*
 * Input format:
 * <start> <size> <type> <bootable> <c,h,s> <c,h,s>
 * Fields are separated by whitespace or comma or semicolon possibly
 * followed by whitespace; initial and trailing whitespace is ignored.
 * Numbers can be octal, decimal or hexadecimal, decimal is default
 * The <c,h,s> parts can (and probably should) be omitted.
 * Bootable is specified as [*|-], with as default not-bootable.
 * Type is given in hex, without the 0x prefix, or is [E|S|L|X], where
 * L (LINUX_NATIVE (83)) is the default, S is LINUX_SWAP (82), and E
 * is EXTENDED_PARTITION (5), X is LINUX_EXTENDED (85).
 * The default value of start is the first nonassigned sector/cylinder/...
 * The default value of size is as much as possible (until next
 * partition or end-of-disk).
 * .: end of chain of extended partitions.
 *
 * On interactive input an empty line means: all defaults.
 * Otherwise empty lines are ignored.
 */

static int eof, eob;

struct dumpfld {
	int fldno;
	char *fldname;
	int is_bool;
} dumpflds[] = {
	{
	0, "start", 0}, {
	1, "size", 0}, {
	2, "Id", 0}, {
	3, "bootable", 1}, {
	4, "bh", 0}, {
	5, "bs", 0}, {
	6, "bc", 0}, {
	7, "eh", 0}, {
	8, "es", 0}, {
	9, "ec", 0}
};

/*
 * Read a line, split it into fields
 *
 * (some primitive handwork, but a more elaborate parser seems
 *  unnecessary)
 */
#define RD_EOF (-1)
#define RD_CMD (-2)

static int
read_stdin(unsigned char **fields, unsigned char *line, int fieldssize,
		   int linesize)
{
	unsigned char *lp, *ip;
	int c, fno;

	/* boolean true and empty string at start */
	line[0] = '*';
	line[1] = 0;
	for (fno = 0; fno < fieldssize; fno++)
		fields[fno] = line + 1;
	fno = 0;

	/* read a line from stdin */
	lp = fgets(line + 2, linesize, stdin);
	if (lp == NULL) {
		eof = 1;
		return RD_EOF;
	}
	if (!(lp = index(lp, '\n')))
		fatalError("long or incomplete input line - quitting\n");
	*lp = 0;

	/* remove comments, if any */
	if ((lp = index(line + 2, '#')) != 0)
		*lp = 0;

	/* recognize a few commands - to be expanded */
	if (!strcmp(line + 2, "unit: sectors")) {
		specified_format = F_SECTOR;
		return RD_CMD;
	}

	/* dump style? - then bad input is fatal */
	if ((ip = index(line + 2, ':')) != 0) {
		struct dumpfld *d;

	  nxtfld:
		ip++;
		while (isspace(*ip))
			ip++;
		if (*ip == 0)
			return fno;
		for (d = dumpflds; d - dumpflds < SIZE(dumpflds); d++) {
			if (!strncmp(ip, d->fldname, strlen(d->fldname))) {
				ip += strlen(d->fldname);
				while (isspace(*ip))
					ip++;
				if (d->is_bool)
					fields[d->fldno] = line;
				else if (*ip == '=') {
					while (isspace(*++ip));
					fields[d->fldno] = ip;
					while (isalnum(*ip))	/* 0x07FF */
						ip++;
				} else
					fatalError("input error: `=' expected after %s field\n",
						  d->fldname);
				if (fno <= d->fldno)
					fno = d->fldno + 1;
				if (*ip == 0)
					return fno;
				if (*ip != ',' && *ip != ';')
					fatalError
						("input error: unexpected character %c after %s field\n",
						 *ip, d->fldname);
				*ip = 0;
				goto nxtfld;
			}
		}
		fatalError("unrecognized input: %s\n", ip);
	}

	/* split line into fields */
	lp = ip = line + 2;
	fields[fno++] = lp;
	while ((c = *ip++) != 0) {
		if (!lp[-1] && (c == '\t' || c == ' '));
		else if (c == '\t' || c == ' ' || c == ',' || c == ';') {
			*lp++ = 0;
			if (fno < fieldssize)
				fields[fno++] = lp;
			continue;
		} else
			*lp++ = c;
	}

	if (lp == fields[fno - 1])
		fno--;
	return fno;
}

/* read a number, use default if absent */
static int get_ul(char *u, unsigned long *up, unsigned long def, int base)
{
	char *nu;

	if (*u) {
		errno = 0;
		*up = strtoul(u, &nu, base);
		if (errno == ERANGE) {
			printf("number too big\n");
			return -1;
		}
		if (*nu) {
			printf("trailing junk after number\n");
			return -1;
		}
	} else
		*up = def;
	return 0;
}

/* There are two common ways to structure extended partitions:
   as nested boxes, and as a chain. Sometimes the partitions
   must be given in order. Sometimes all logical partitions
   must lie inside the outermost extended partition.
NESTED: every partition is contained in the surrounding partitions
   and is disjoint from all others.
CHAINED: every data partition is contained in the surrounding partitions
   and disjoint from all others, but extended partitions may lie outside
   (insofar as allowed by all_logicals_inside_outermost_extended).
ONESECTOR: all data partitions are mutually disjoint; extended partitions
   each use one sector only (except perhaps for the outermost one).
*/
static int partitions_in_order = 0;
static int all_logicals_inside_outermost_extended = 1;
static enum { NESTED, CHAINED, ONESECTOR } boxes = NESTED;

/* find the default value for <start> - assuming entire units */
static unsigned long
first_free(int pno, int is_extended, struct part_desc *ep, int format,
		   unsigned long mid, struct disk_desc *z)
{
	unsigned long ff, fff;
	unsigned long unit = unitsize(format);
	struct part_desc *partitions = &(z->partitions[0]), *pp = 0;

	/* if containing ep undefined, look at its container */
	if (ep && ep->p.sys_type == EMPTY_PARTITION)
		ep = ep->ep;

	if (ep) {
		if (boxes == NESTED || (boxes == CHAINED && !is_extended))
			pp = ep;
		else if (all_logicals_inside_outermost_extended)
			pp = outer_extended_partition(ep);
	}
#if 0
	ff = pp ? (pp->start + unit - 1) / unit : 0;
#else
	/* rounding up wastes almost an entire cylinder - round down
	   and leave it to compute_start_sect() to fix the difference */
	ff = pp ? pp->start / unit : 0;
#endif
	/* MBR and 1st sector of an extended partition are never free */
	if (unit == 1)
		ff++;

  again:
	for (pp = partitions; pp < partitions + pno; pp++) {
		if (!is_parent(pp, ep) && pp->size > 0) {
			if ((partitions_in_order || pp->start / unit <= ff
				 || (mid && pp->start / unit <= mid))
				&& (fff = (pp->start + pp->size + unit - 1) / unit) > ff) {
				ff = fff;
				goto again;
			}
		}
	}

	return ff;
}

/* find the default value for <size> - assuming entire units */
static unsigned long
max_length(int pno, int is_extended, struct part_desc *ep, int format,
		   unsigned long start, struct disk_desc *z)
{
	unsigned long fu;
	unsigned long unit = unitsize(format);
	struct part_desc *partitions = &(z->partitions[0]), *pp = 0;

	/* if containing ep undefined, look at its container */
	if (ep && ep->p.sys_type == EMPTY_PARTITION)
		ep = ep->ep;

	if (ep) {
		if (boxes == NESTED || (boxes == CHAINED && !is_extended))
			pp = ep;
		else if (all_logicals_inside_outermost_extended)
			pp = outer_extended_partition(ep);
	}
	fu = pp ? (pp->start + pp->size) / unit : get_disksize(format);

	for (pp = partitions; pp < partitions + pno; pp++)
		if (!is_parent(pp, ep) && pp->size > 0
			&& pp->start / unit >= start && pp->start / unit < fu)
			fu = pp->start / unit;

	return (fu > start) ? fu - start : 0;
}

/* compute starting sector of a partition inside an extended one */
/* ep is 0 or points to surrounding extended partition */
static int compute_start_sect(struct part_desc *p, struct part_desc *ep)
{
	unsigned long base;
	int inc = (DOS && B.sectors) ? B.sectors : 1;
	int delta;

	if (ep && p->start + p->size >= ep->start + 1)
		delta = p->start - ep->start - inc;
	else if (p->start == 0 && p->size > 0)
		delta = -inc;
	else
		delta = 0;
	if (delta < 0) {
		p->start -= delta;
		p->size += delta;
		if (is_extended(p->p.sys_type) && boxes == ONESECTOR)
			p->size = inc;
		else if ((int) (p->size) <= 0) {
			warn("no room for partition descriptor\n");
			return 0;
		}
	}
	base = (!ep ? 0
			: (is_extended(p->p.sys_type) ?
			   outer_extended_partition(ep) : ep)->start);
	p->ep = ep;
	if (p->p.sys_type == EMPTY_PARTITION && p->size == 0) {
		p->p.start_sect = 0;
		p->p.begin_chs = zero_chs;
		p->p.end_chs = zero_chs;
	} else {
		p->p.start_sect = p->start - base;
		p->p.begin_chs = ulong_to_chs(p->start, B);
		p->p.end_chs = ulong_to_chs(p->start + p->size - 1, B);
	}
	p->p.nr_sects = p->size;
	return 1;
}

/* build the extended partition surrounding a given logical partition */
static int
build_surrounding_extended(struct part_desc *p, struct part_desc *ep,
						   struct disk_desc *z)
{
	int inc = (DOS && B.sectors) ? B.sectors : 1;
	int format = F_SECTOR;
	struct part_desc *p0 = &(z->partitions[0]), *eep = ep->ep;

	if (boxes == NESTED) {
		ep->start = first_free(ep - p0, 1, eep, format, p->start, z);
		ep->size = max_length(ep - p0, 1, eep, format, ep->start, z);
		if (ep->start > p->start
			|| ep->start + ep->size < p->start + p->size) {
			warn("cannot build surrounding extended partition\n");
			return 0;
		}
	} else {
		ep->start = p->start;
		if (boxes == CHAINED)
			ep->size = p->size;
		else
			ep->size = inc;
	}

	ep->p.nr_sects = ep->size;
	ep->p.bootable = 0;
	ep->p.sys_type = EXTENDED_PARTITION;
	if (!compute_start_sect(ep, eep) || !compute_start_sect(p, ep)) {
		ep->p.sys_type = EMPTY_PARTITION;
		ep->size = 0;
		return 0;
	}

	return 1;
}

static int
read_line(int pno, struct part_desc *ep, char *dev, int interactive,
		  struct disk_desc *z)
{
	unsigned char line[1000];
	unsigned char *fields[11];
	int fno, pct = pno % 4;
	struct part_desc p, *orig;
	unsigned long ff, ff1, ul, ml, ml1, def;
	int format, lpno, is_extd;

	if (eof || eob)
		return -1;

	lpno = index_to_linux(pno, z);

	if (interactive) {
		if (pct == 0 && (show_extended || pno == 0))
			warn("\n");
		warn("%8s%d: ", dev, lpno);
	}

	/* read input line - skip blank lines when reading from a file */
	do {
		fno = read_stdin(fields, line, SIZE(fields), SIZE(line));
	} while (fno == RD_CMD || (fno == 0 && !interactive));
	if (fno == RD_EOF) {
		return -1;
	} else if (fno > 10 && *(fields[10]) != 0) {
		printf("too many input fields\n");
		return 0;
	}

	if (fno == 1 && !strcmp(fields[0], ".")) {
		eob = 1;
		return -1;
	}

	/* use specified format, but round to cylinders if F_MEGABYTE specified */
	format = 0;
	if (B.cylindersize && specified_format == F_MEGABYTE)
		format = F_CYLINDER;

	orig = (one_only ? &(oldp.partitions[pno]) : 0);

	p = zero_part_desc;
	p.ep = ep;

	/* first read the type - we need to know whether it is extended */
	/* stop reading when input blank (defaults) and all is full */
	is_extd = 0;
	if (fno == 0) {				/* empty line */
		if (orig && is_extended(orig->p.sys_type))
			is_extd = 1;
		ff = first_free(pno, is_extd, ep, format, 0, z);
		ml = max_length(pno, is_extd, ep, format, ff, z);
		if (ml == 0 && is_extd == 0) {
			is_extd = 1;
			ff = first_free(pno, is_extd, ep, format, 0, z);
			ml = max_length(pno, is_extd, ep, format, ff, z);
		}
		if (ml == 0 && pno >= 4) {
			/* no free blocks left - don't read any further */
			warn("No room for more\n");
			return -1;
		}
	}
	if (fno < 3 || !*(fields[2]))
		ul = orig ? orig->p.sys_type :
			(is_extd || (pno > 3 && pct == 1 && show_extended))
			? EXTENDED_PARTITION : LINUX_NATIVE;
	else if (!strcmp(fields[2], "L"))
		ul = LINUX_NATIVE;
	else if (!strcmp(fields[2], "S"))
		ul = LINUX_SWAP;
	else if (!strcmp(fields[2], "E"))
		ul = EXTENDED_PARTITION;
	else if (!strcmp(fields[2], "X"))
		ul = LINUX_EXTENDED;
	else if (get_ul(fields[2], &ul, LINUX_NATIVE, 16))
		return 0;
	if (ul > 255) {
		warn("Illegal type\n");
		return 0;
	}
	p.p.sys_type = ul;
	is_extd = is_extended(ul);

	/* find start */
	ff = first_free(pno, is_extd, ep, format, 0, z);
	ff1 = ff * unitsize(format);
	def = orig ? orig->start : (pno > 4 && pct > 1) ? 0 : ff1;
	if (fno < 1 || !*(fields[0]))
		p.start = def;
	else {
		if (get_ul(fields[0], &ul, def / unitsize(0), 0))
			return 0;
		p.start = ul * unitsize(0);
		p.start -= (p.start % unitsize(format));
	}

	/* find length */
	ml =
		max_length(pno, is_extd, ep, format, p.start / unitsize(format),
				   z);
	ml1 = ml * unitsize(format);
	def = orig ? orig->size : (pno > 4 && pct > 1) ? 0 : ml1;
	if (fno < 2 || !*(fields[1]))
		p.size = def;
	else {
		if (get_ul(fields[1], &ul, def / unitsize(0), 0))
			return 0;
		p.size = ul * unitsize(0) + unitsize(format) - 1;
		p.size -= (p.size % unitsize(format));
	}
	if (p.size > ml1) {
		warn("Warning: exceeds max allowable size (%lu)\n",
			 ml1 / unitsize(0));
		if (!force)
			return 0;
	}
	if (p.size == 0 && pno >= 4 && (fno < 2 || !*(fields[1]))) {
		warn("Warning: empty partition\n");
		if (!force)
			return 0;
	}
	p.p.nr_sects = p.size;

	if (p.size == 0 && !orig) {
		if (fno < 1 || !*(fields[0]))
			p.start = 0;
		if (fno < 3 || !*(fields[2]))
			p.p.sys_type = EMPTY_PARTITION;
	}

	if (p.start < ff1 && p.size > 0) {
		warn("Warning: bad partition start (earliest %lu)\n",
			 (ff1 + unitsize(0) - 1) / unitsize(0));
		if (!force)
			return 0;
	}

	if (fno < 4 || !*(fields[3]))
		ul = (orig ? orig->p.bootable : 0);
	else if (!strcmp(fields[3], "-"))
		ul = 0;
	else if (!strcmp(fields[3], "*") || !strcmp(fields[3], "+"))
		ul = 0x80;
	else {
		warn("unrecognized bootable flag - choose - or *\n");
		return 0;
	}
	p.p.bootable = ul;

	if (ep && ep->p.sys_type == EMPTY_PARTITION) {
		if (!build_surrounding_extended(&p, ep, z))
			return 0;
	} else if (!compute_start_sect(&p, ep))
		return 0;

	{
		longchs aa = chs_to_longchs(p.p.begin_chs), bb;

		if (fno < 5) {
			bb = aa;
		} else if (fno < 7) {
			warn("partial c,h,s specification?\n");
			return 0;
		} else if (get_ul(fields[4], &bb.c, aa.c, 0) ||
				   get_ul(fields[5], &bb.h, aa.h, 0) ||
				   get_ul(fields[6], &bb.s, aa.s, 0))
			return 0;
		p.p.begin_chs = longchs_to_chs(bb, B);
	}
	{
		longchs aa = chs_to_longchs(p.p.end_chs), bb;

		if (fno < 8) {
			bb = aa;
		} else if (fno < 10) {
			warn("partial c,h,s specification?\n");
			return 0;
		} else if (get_ul(fields[7], &bb.c, aa.c, 0) ||
				   get_ul(fields[8], &bb.h, aa.h, 0) ||
				   get_ul(fields[9], &bb.s, aa.s, 0))
			return 0;
		p.p.end_chs = longchs_to_chs(bb, B);
	}

	if (pno > 3 && p.size && show_extended
		&& p.p.sys_type != EMPTY_PARTITION
		&& (is_extended(p.p.sys_type) != (pct == 1))) {
		warn("Extended partition not where expected\n");
		if (!force)
			return 0;
	}

	z->partitions[pno] = p;
	if (pno >= z->partno)
		z->partno += 4;			/* reqd for out_partition() */

	if (interactive)
		out_partition(dev, 0, &(z->partitions[pno]), z, B);

	return 1;
}

/* ep either points to the extended partition to contain this one,
   or to the empty partition that may become extended or is 0 */
static int
read_partition(char *dev, int interactive, int pno, struct part_desc *ep,
			   struct disk_desc *z)
{
	struct part_desc *p = &(z->partitions[pno]);
	int i;

	if (one_only) {
		*p = oldp.partitions[pno];
		if (one_only_pno != pno)
			goto ret;
	} else if (!show_extended && pno > 4 && pno % 4)
		goto ret;

	while (!(i = read_line(pno, ep, dev, interactive, z)))
		if (!interactive)
			fatalError("bad input\n");
	if (i < 0) {
		p->ep = ep;
		return 0;
	}

  ret:
	p->ep = ep;
	if (pno >= z->partno)
		z->partno += 4;
	return 1;
}

static void
read_partition_chain(char *dev, int interactive, struct part_desc *ep,
					 struct disk_desc *z)
{
	int i, base;

	eob = 0;
	while (1) {
		base = z->partno;
		if (base + 4 > SIZE(z->partitions)) {
			printf("too many partitions\n");
			break;
		}
		for (i = 0; i < 4; i++)
			if (!read_partition(dev, interactive, base + i, ep, z))
				return;
		for (i = 0; i < 4; i++) {
			ep = &(z->partitions[base + i]);
			if (is_extended(ep->p.sys_type) && ep->size)
				break;
		}
		if (i == 4) {
			/* nothing found - maybe an empty partition is going
			   to be extended */
			if (one_only || show_extended)
				break;
			ep = &(z->partitions[base + 1]);
			if (ep->size || ep->p.sys_type != EMPTY_PARTITION)
				break;
		}
	}
}

static void read_input(char *dev, int interactive, struct disk_desc *z)
{
	int i;
	struct part_desc *partitions = &(z->partitions[0]), *ep;

	for (i = 0; i < SIZE(z->partitions); i++)
		partitions[i] = zero_part_desc;
	z->partno = 0;

	if (interactive)
		warn
			("Input in the following format; absent fields get a default value.\n"
			 "<start> <size> <type [E,S,L,X,hex]> <bootable [-,*]> <c,h,s> <c,h,s>\n"
			 "Usually you only need to specify <start> and <size> (and perhaps <type>).\n");
	eof = 0;

	for (i = 0; i < 4; i++)
		read_partition(dev, interactive, i, 0, z);
	for (i = 0; i < 4; i++) {
		ep = partitions + i;
		if (is_extended(ep->p.sys_type) && ep->size)
			read_partition_chain(dev, interactive, ep, z);
	}
	add_sector_and_offset(z);
}

/*
 *  G. The command line
 */

static void version(void)
{
	printf("%s %s %s (aeb@cwi.nl, %s)\n", PROGNAME, "version", VERSION,
		   DATE);
}

static char short_opts[] = "cdfgilnqsu:vx?1A::C:DH:I:LN:O:RS:TU::V";

#define PRINT_ID 0400
#define CHANGE_ID 01000

static const struct option long_opts[] = {
	{"change-id", no_argument, NULL, 'c' + CHANGE_ID},
	{"print-id", no_argument, NULL, 'c' + PRINT_ID},
	{"id", no_argument, NULL, 'c'},
	{"dump", no_argument, NULL, 'd'},
	{"force", no_argument, NULL, 'f'},
	{"show-geometry", no_argument, NULL, 'g'},
	{"increment", no_argument, NULL, 'i'},
	{"list", no_argument, NULL, 'l'},
	{"quiet", no_argument, NULL, 'q'},
	{"show-size", no_argument, NULL, 's'},
	{"unit", required_argument, NULL, 'u'},
	{"version", no_argument, NULL, 'v'},
	{"show-extended", no_argument, NULL, 'x'},
	{"help", no_argument, NULL, '?'},
	{"one-only", no_argument, NULL, '1'},
	{"cylinders", required_argument, NULL, 'C'},
	{"heads", required_argument, NULL, 'H'},
	{"sectors", required_argument, NULL, 'S'},
	{"activate", optional_argument, NULL, 'A'},
	{"DOS", no_argument, NULL, 'D'},
	{"Linux", no_argument, NULL, 'L'},
	{"re-read", no_argument, NULL, 'R'},
	{"list-types", no_argument, NULL, 'T'},
	{"unhide", optional_argument, NULL, 'U'},
	{"no-reread", no_argument, NULL, 160},
	{"IBM", no_argument, NULL, 161},
	{"leave-last", no_argument, NULL, 161},
/* undocumented flags - not all completely implemented */
	{"in-order", no_argument, NULL, 128},
	{"not-in-order", no_argument, NULL, 129},
	{"inside-outer", no_argument, NULL, 130},
	{"not-inside-outer", no_argument, NULL, 131},
	{"nested", no_argument, NULL, 132},
	{"chained", no_argument, NULL, 133},
	{"onesector", no_argument, NULL, 134},
	{NULL, 0, NULL, 0}
};

/* default devices to list */
static struct devd {
	char *pref, *letters;
} defdevs[] = {
	{
	"hd", "abcdefgh"}, {
	"sd", "abcde"}, {
	"xd", "ab"}, {
	"ed", "abcd"}
};

static int is_ide_cdrom(char *device)
{
	/* No device was given explicitly, and we are trying some
	   likely things.  But opening /dev/hdc may produce errors like
	   "hdc: tray open or drive not ready"
	   if it happens to be a CD-ROM drive. So try to be careful.
	   This only works since 2.1.73. */

	FILE *procf;
	char buf[100];
	struct stat statbuf;

	sprintf(buf, "/proc/ide/%s/media", device + 5);
	procf = fopen(buf, "r");
	if (procf != NULL && fgets(buf, sizeof(buf), procf))
		return !strncmp(buf, "cdrom", 5);

	/* Now when this proc file does not exist, skip the
	   device when it is read-only. */
	if (stat(device, &statbuf) == 0)
		return (statbuf.st_mode & 0222) == 0;

	return 0;
}

static void do_list(char *dev, int silent);
static void do_size(char *dev, int silent);
static void do_geom(char *dev, int silent);
static void do_fdisk(char *dev);
static void do_reread(char *dev);
static void do_change_id(char *dev, char *part, char *id);
static void do_unhide(char **av, int ac, char *arg);
static void do_activate(char **av, int ac, char *arg);

static int total_size;

extern int sfdisk_main(int argc, char **argv)
{
	int c;
	char *dev;
	int opt_size = 0;
	int opt_out_geom = 0;
	int opt_reread = 0;
	int activate = 0;
	int do_id = 0;
	int unhide = 0;
	char *activatearg = 0;
	char *unhidearg = 0;

	if (argc < 1)
		usage(sfdisk_usage);

	while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) !=
		   -1) {
		switch (c) {
		case 'f':
			force = 1;
			break;				/* does not imply quiet */
		case 'g':
			opt_out_geom = 1;
			break;
		case 'i':
			increment = 1;
			break;
		case 'c':
		case 'c' + PRINT_ID:
		case 'c' + CHANGE_ID:
			do_id = c;
			break;
		case 'd':
			dump = 1;			/* fall through */
		case 'l':
			opt_list = 1;
			break;
		case 'n':
			no_write = 1;
			break;
		case 'q':
			quiet = 1;
			break;
		case 's':
			opt_size = 1;
			break;
		case 'u':
			set_format(*optarg);
			break;
		case 'v':
			version();
			exit(0);
		case 'x':
			show_extended = 1;
			break;
		case 'A':
			activatearg = optarg;
			activate = 1;
			break;
		case 'C':
			U.cylinders = atoi(optarg);
			break;
		case 'D':
			DOS = 1;
			break;
		case 'H':
			U.heads = atoi(optarg);
			break;
		case 'L':
			Linux = 1;
			break;
		case 'N':
			one_only = atoi(optarg);
			break;
		case 'I':
			restore_sector_file = optarg;
			break;
		case 'O':
			save_sector_file = optarg;
			break;
		case 'R':
			opt_reread = 1;
			break;
		case 'S':
			U.sectors = atoi(optarg);
			break;
		case 'T':
			list_types();
			exit(0);
		case 'U':
			unhidearg = optarg;
			unhide = 1;
			break;
		case 'V':
			verify = 1;
			break;
		case '?':
		default:
			usage(sfdisk_usage);

			/* undocumented flags */
		case 128:
			partitions_in_order = 1;
			break;
		case 129:
			partitions_in_order = 0;
			break;
		case 130:
			all_logicals_inside_outermost_extended = 1;
			break;
		case 131:
			all_logicals_inside_outermost_extended = 0;
			break;
		case 132:
			boxes = NESTED;
			break;
		case 133:
			boxes = CHAINED;
			break;
		case 134:
			boxes = ONESECTOR;
			break;

			/* more flags */
		case 160:
			no_reread = 1;
			break;
		case 161:
			leave_last = 1;
			break;
		}
	}

	if (optind == argc && (opt_list || opt_out_geom || opt_size || verify)) {
		struct devd *dp;
		char *lp;
		char device[10];

		total_size = 0;

		for (dp = defdevs; dp - defdevs < SIZE(defdevs); dp++) {
			lp = dp->letters;
			while (*lp) {
				sprintf(device, "/dev/%s%c", dp->pref, *lp++);
				if (!strcmp(dp->pref, "hd") && is_ide_cdrom(device))
					continue;
				if (opt_out_geom)
					do_geom(device, 1);
				if (opt_size)
					do_size(device, 1);
				if (opt_list || verify)
					do_list(device, 1);
			}
		}

		if (opt_size)
			printf("total: %d blocks\n", total_size);

		exit(exit_status);
	}

	if (optind == argc)
		usage(sfdisk_usage);

	if (opt_list || opt_out_geom || opt_size || verify) {
		while (optind < argc) {
			if (opt_out_geom)
				do_geom(argv[optind], 0);
			if (opt_size)
				do_size(argv[optind], 0);
			if (opt_list || verify)
				do_list(argv[optind], 0);
			optind++;
		}
		exit(exit_status);
	}

	if (activate) {
		do_activate(argv + optind, argc - optind, activatearg);
		exit(exit_status);
	}
	if (unhide) {
		do_unhide(argv + optind, argc - optind, unhidearg);
		exit(exit_status);
	}
	if (do_id) {
		if ((do_id & PRINT_ID) != 0 && optind != argc - 2)
			fatalError("usage: sfdisk --print-id device partition-number\n");
		else if ((do_id & CHANGE_ID) != 0 && optind != argc - 3)
			fatalError
				("usage: sfdisk --change-id device partition-number Id\n");
		else if (optind != argc - 3 && optind != argc - 2)
			fatalError("usage: sfdisk --id device partition-number [Id]\n");
		do_change_id(argv[optind], argv[optind + 1],
					 (optind == argc - 2) ? 0 : argv[optind + 2]);
		exit(exit_status);
	}

	if (optind != argc - 1)
		fatalError("can specify only one device (except with -l or -s)\n");
	dev = argv[optind];

	if (opt_reread)
		do_reread(dev);
	else if (restore_sector_file)
		restore_sectors(dev);
	else
		do_fdisk(dev);

	return (TRUE);
}

/*
 *  H. Listing the current situation
 */

static int my_open(char *dev, int rw, int silent)
{
	int fd, mode;

	mode = (rw ? O_RDWR : O_RDONLY);
	fd = open(dev, mode);
	if (fd < 0 && !silent) {
		perror(dev);
		fatalError("cannot open %s %s\n", dev,
			  rw ? "read-write" : "for reading");
	}
	return fd;
}

static void do_list(char *dev, int silent)
{
	int fd;
	struct disk_desc *z;

	fd = my_open(dev, 0, silent);
	if (fd < 0)
		return;

	z = &oldp;

	free_sectors();
	get_cylindersize(dev, fd, dump ? 1 : opt_list ? 0 : 1);
	get_partitions(dev, fd, z);

	if (opt_list)
		out_partitions(dev, z);

	if (verify) {
		if (partitions_ok(z))
			warn("%s: OK\n", dev);
		else
			exit_status = 1;
	}
}

static void do_geom(char *dev, int silent)
{
	int fd;
	struct hd_geometry g;

	fd = my_open(dev, 0, silent);
	if (fd < 0)
		return;

	/* get_cylindersize(dev, fd, silent); */
	if (!ioctl(fd, HDIO_GETGEO, &g))
		printf("%s: %d cylinders, %d heads, %d sectors/track\n",
			   dev, g.cylinders, g.heads, g.sectors);
	else
		printf("%s: unknown geometry\n", dev);
}

/* for compatibility with earlier fdisk: provide option -s */
static void do_size(char *dev, int silent)
{
	int fd;
	long size;

	fd = my_open(dev, 0, silent);
	if (fd < 0)
		return;

	if (ioctl(fd, BLKGETSIZE, &size)) {
		if (!silent) {
			perror(dev);
			fatalError("BLKGETSIZE ioctl failed for %s\n", dev);
		}
		return;
	}

	size /= 2;					/* convert sectors to blocks */

	/* a CDROM drive without mounted CD yields MAXINT */
	if (silent && size == ((1 << 30) - 1))
		return;

	if (silent)
		printf("%s: %9ld\n", dev, size);
	else
		printf("%ld\n", size);

	total_size += size;
}

/*
 * Activate: usually one wants to have a single primary partition
 * to be active. OS/2 fdisk makes non-bootable logical partitions
 * active - I don't know what that means to OS/2 Boot Manager.
 *
 * Call: activate /dev/hda 2 5 7	make these partitions active
 *					and the remaining ones inactive
 * Or:   sfdisk -A /dev/hda 2 5 7
 *
 * If only a single partition must be active, one may also use the form
 *       sfdisk -A2 /dev/hda
 *
 * With "activate /dev/hda" or "sfdisk -A /dev/hda" the active partitions
 * are listed but not changed. To get zero active partitions, use
 * "activate /dev/hda none" or "sfdisk -A /dev/hda none".
 * Use something like `echo ",,,*" | sfdisk -N2 /dev/hda' to only make
 * /dev/hda2 active, without changing other partitions.
 *
 * A warning will be given if after the change not precisely one primary
 * partition is active.
 *
 * The present syntax was chosen to be (somewhat) compatible with the
 * activate from the LILO package.
 */
static void set_active(struct disk_desc *z, char *pnam)
{
	int pno;

	pno = asc_to_index(pnam, z);
	z->partitions[pno].p.bootable = 0x80;
}

static void do_activate(char **av, int ac, char *arg)
{
	char *dev = av[0];
	int fd;
	int rw, i, pno, lpno;
	struct disk_desc *z;

	z = &oldp;

	rw = (!no_write && (arg || ac > 1));
	fd = my_open(dev, rw, 0);

	free_sectors();
	get_cylindersize(dev, fd, 1);
	get_partitions(dev, fd, z);

	if (!arg && ac == 1) {
		/* list active partitions */
		for (pno = 0; pno < z->partno; pno++) {
			if (z->partitions[pno].p.bootable) {
				lpno = index_to_linux(pno, z);
				if (pno == linux_to_index(lpno, z))
					printf("%s%d\n", dev, lpno);
				else
					printf("%s#%d\n", dev, pno);
				if (z->partitions[pno].p.bootable != 0x80)
					warn("bad active byte: 0x%x instead of 0x80\n",
						 z->partitions[pno].p.bootable);
			}
		}
	} else {
		/* clear `active byte' everywhere */
		for (pno = 0; pno < z->partno; pno++)
			z->partitions[pno].p.bootable = 0;

		/* then set where desired */
		if (ac == 1)
			set_active(z, arg);
		else
			for (i = 1; i < ac; i++)
				set_active(z, av[i]);

		/* then write to disk */
		if (write_partitions(dev, fd, z))
			warn("Done\n\n");
		else
			exit_status = 1;
	}
	i = 0;
	for (pno = 0; pno < z->partno && pno < 4; pno++)
		if (z->partitions[pno].p.bootable)
			i++;
	if (i != 1)
		warn
			("You have %d active primary partitions. This does not matter for LILO,\n"
			 "but the DOS MBR will only boot a disk with 1 active partition.\n",
			 i);
}

static void set_unhidden(struct disk_desc *z, char *pnam)
{
	int pno;
	unsigned char id;

	pno = asc_to_index(pnam, z);
	id = z->partitions[pno].p.sys_type;
	if (id == 0x11 || id == 0x14 || id == 0x16 || id == 0x17)
		id -= 0x10;
	else
		fatalError("partition %s has id %x and is not hidden\n", pnam, id);
	z->partitions[pno].p.sys_type = id;
}

/*
 * maybe remove and make part of --change-id
 */
static void do_unhide(char **av, int ac, char *arg)
{
	char *dev = av[0];
	int fd, rw, i;
	struct disk_desc *z;

	z = &oldp;

	rw = !no_write;
	fd = my_open(dev, rw, 0);

	free_sectors();
	get_cylindersize(dev, fd, 1);
	get_partitions(dev, fd, z);

	/* unhide where desired */
	if (ac == 1)
		set_unhidden(z, arg);
	else
		for (i = 1; i < ac; i++)
			set_unhidden(z, av[i]);

	/* then write to disk */
	if (write_partitions(dev, fd, z))
		warn("Done\n\n");
	else
		exit_status = 1;
}

static void do_change_id(char *dev, char *pnam, char *id)
{
	int fd, rw, pno;
	struct disk_desc *z;
	unsigned long i;

	z = &oldp;

	rw = !no_write;
	fd = my_open(dev, rw, 0);

	free_sectors();
	get_cylindersize(dev, fd, 1);
	get_partitions(dev, fd, z);

	pno = asc_to_index(pnam, z);
	if (id == 0) {
		printf("%x\n", z->partitions[pno].p.sys_type);
		return;
	}
	i = strtoul(id, NULL, 16);
	if (i > 255)
		fatalError("Bad Id %lx\n", i);
	z->partitions[pno].p.sys_type = i;

	if (write_partitions(dev, fd, z))
		warn("Done\n\n");
	else
		exit_status = 1;
}

static void do_reread(char *dev)
{
	int fd;

	fd = my_open(dev, 0, 0);
	if (reread_ioctl(fd))
		printf("This disk is currently in use.\n");
}

/*
 *  I. Writing the new situation
 */

static void do_fdisk(char *dev)
{
	int fd;
	int c, answer;
	struct stat statbuf;
	int interactive = isatty(0);
	struct disk_desc *z;

	if (stat(dev, &statbuf) < 0) {
		perror(dev);
		fatalError("Fatal error: cannot find %s\n", dev);
	}
	if (!S_ISBLK(statbuf.st_mode)) {
		warn("Warning: %s is not a block device\n", dev);
		no_reread = 1;
	}
	fd = my_open(dev, !no_write, 0);

	if (!no_write && !no_reread) {
		warn("Checking that no-one is using this disk right now ...\n");
		if (reread_ioctl(fd)) {
			printf
				("\nThis disk is currently in use - repartitioning is probably a bad idea."
				 "Umount all file systems, and swapoff all swap partitions on this disk."
				 "Use the --no-reread flag to suppress this check.\n");
			if (!force) {
				printf("Use the --force flag to overrule all checks.\n");
				exit(1);
			}
		} else
			warn("OK");
	}

	z = &oldp;

	free_sectors();
	get_cylindersize(dev, fd, 0);
	get_partitions(dev, fd, z);

	printf("Old situation:\n");
	out_partitions(dev, z);

	if (one_only && (one_only_pno = linux_to_index(one_only, z)) < 0)
		fatalError("Partition %d does not exist, cannot change it\n", one_only);

	z = &newp;

	while (1) {

		read_input(dev, interactive, z);

		printf("New situation:\n");
		out_partitions(dev, z);

		if (!partitions_ok(z) && !force) {
			if (!interactive)
				fatalError("I don't like these partitions - nothing changed.\n"
					  "(If you really want this, use the --force option.)\n");
			else
				printf
					("I don't like this - probably you should answer No\n");
		}
	  ask:
		if (interactive) {
			if (no_write)
				printf("Are you satisfied with this? [ynq] ");
			else
				printf("Do you want to write this to disk? [ynq] ");
			answer = c = getchar();
			while (c != '\n' && c != EOF)
				c = getchar();
			if (c == EOF)
				printf("\nsfdisk: premature end of input\n");
			if (c == EOF || answer == 'q' || answer == 'Q') {
				fatalError("Quitting - nothing changed\n");
			} else if (answer == 'n' || answer == 'N') {
				continue;
			} else if (answer == 'y' || answer == 'Y') {
				break;
			} else {
				printf("Please answer one of y,n,q\n");
				goto ask;
			}
		} else
			break;
	}

	if (write_partitions(dev, fd, z))
		printf("Successfully wrote the new partition table\n\n");
	else
		exit_status = 1;

	reread_disk_partition(dev, fd);

	warn
		("If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)\n"
		 "to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1\n"
		 "(See fdisk(8).)\n");

	sync();						/* superstition */
	sleep(3);
	exit(exit_status);
}
