Date: Sat, 21 Jul 2001 14:47:29 +0100 From: Ian Dowse <iedowse@maths.tcd.ie> To: freebsd-hackers@freebsd.org Subject: fdisk(8) adjusting to head/cylinder bounderies Message-ID: <200107211447.aa29342@salmon.maths.tcd.ie>
next in thread | raw e-mail | index | archive | help
For about a year, fdisk(8) has had code that automatically adjusts partitions to begin on a head boundary and end on a cylinder boundary. This is fine in most situations, but the way it is implemented makes it awkward to override, and more importantly it is way too easy to mess up an existing partition that is not properly aligned on a head/cylinder boundary. Currently, fdisk never asks the user for confirmation of changes to the partition start and size. It just prints out a message such as WARNING: adjusting start offset of partition to 12345 to fall on a head boundary and then it immediately goes on to print out the full slice details, so that warning is easily missed. It is possible to avoid the automatic adjustment by answering "y" to the Explicitly specify beg/end address? question that refers to setting the c/h/s parameters, but if you do that, then you can't make use of the automatic c/h/s calculation. This problem bites me almost every time I use fdisk, since we have a lot of disks that have been split into multiple partitions to get around the 7 partitions/slice limit. I have always just changed the slice to end exactly where the last partition ends, so having fdisk rounding that down by a few sectors is not desirable. These disks are generally SCSI, contain only FreeBSD partitions, and the BIOSes we work with have never had problems with partitions that are not head/cylinder aligned. Below is a patch that makes fdisk request user confirmation before making any changes to the start and end of partitions. It also untangles the automatic c/h/s calculation from the start/size adjustment, and doesn't set the partition type to 0 if the adjustment fails. I haven't put a great deal of thought into the specifics of the patch, so any comments or suggestions are welcome. I just want to avoid the behaviour where carefully calculated partition parameters supplied by the user get changed automatically with only an easily- missed warning printed. Ian Index: fdisk.c =================================================================== RCS file: /dump/FreeBSD-CVS/src/sbin/i386/fdisk/fdisk.c,v retrieving revision 1.50 diff -u -r1.50 fdisk.c --- fdisk.c 2001/07/13 16:48:56 1.50 +++ fdisk.c 2001/07/21 12:02:01 @@ -548,6 +548,7 @@ Decimal("sysid (165=FreeBSD)", partp->dp_typ, tmp); Decimal("start", partp->dp_start, tmp); Decimal("size", partp->dp_size, tmp); + sanitize_partition(partp); if (ok("Explicitly specify beg/end address ?")) { @@ -572,8 +573,6 @@ partp->dp_esect = DOSSECT(tsec,tcyl); partp->dp_ehd = thd; } else { - if (!sanitize_partition(partp)) - partp->dp_typ = 0; dos(partp->dp_start, partp->dp_size, &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd); dos(partp->dp_start + partp->dp_size - 1, partp->dp_size, @@ -1398,6 +1397,17 @@ max_end = partp->dp_start + partp->dp_size; + if (partp->dp_start % dos_sectors != 0 || + (partp->dp_start + partp->dp_size) % dos_sectors != 0) { + if (partp->dp_start % dos_sectors != 0) + warnx("WARNING: partition does not begin on a head boundary"); + if ((partp->dp_start + partp->dp_size) % dos_sectors != 0) + warnx("WARNING: partition does not end on a cylinder boundary"); + warnx("WARNING: this may confuse the BIOS or other operating systems"); + if (!ok("Correct this automatically?")) + return(1); + } + /* * Adjust start upwards, if necessary, to fall on an head boundary. */ @@ -1412,9 +1422,7 @@ "ERROR: unable to adjust start of partition to fall on a head boundary"); return (0); } - warnx( - "WARNING: adjusting start offset of partition\n\ - to %u to fall on a head boundary", + warnx("WARNING: adjusting start offset of partition to %u", (u_int)(prev_head_boundary + dos_sectors)); partp->dp_start = prev_head_boundary + dos_sectors; } @@ -1434,10 +1442,7 @@ return (0); } if (adj_size != partp->dp_size) { - warnx( - "WARNING: adjusting size of partition to %u to end on a\n\ - cylinder boundary", - (u_int)adj_size); + warnx("WARNING: adjusting size of partition to %u", (u_int)adj_size); partp->dp_size = adj_size; } if (partp->dp_size == 0) { To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi? <200107211447.aa29342>