summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1996-02-03 21:14:09 +0000
committerjoerg <joerg@FreeBSD.org>1996-02-03 21:14:09 +0000
commit0989a701a0e3c83fbe50e3bbe1283714f748d055 (patch)
tree3e242a1ab8c0d4f21666a97084c49520fb6183e3 /sbin
parentb7b17e09c49349923c2547bb86428569cd67e752 (diff)
downloadFreeBSD-src-0989a701a0e3c83fbe50e3bbe1283714f748d055.zip
FreeBSD-src-0989a701a0e3c83fbe50e3bbe1283714f748d055.tar.gz
Try to preserve the fdisk table in the primary bootstrap, should it
already exist. Mention the cases where this doesn't work in the BUGS section of the man page.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/bsdlabel/bsdlabel.820
-rw-r--r--sbin/bsdlabel/bsdlabel.c27
-rw-r--r--sbin/disklabel/disklabel.820
-rw-r--r--sbin/disklabel/disklabel.c27
4 files changed, 94 insertions, 0 deletions
diff --git a/sbin/bsdlabel/bsdlabel.8 b/sbin/bsdlabel/bsdlabel.8
index 1cc33ab..ce1b168 100644
--- a/sbin/bsdlabel/bsdlabel.8
+++ b/sbin/bsdlabel/bsdlabel.8
@@ -362,3 +362,23 @@ will not install bootstrap code that overlaps it.
When a disk name is given without a full pathname,
the constructed device name uses the ``a'' partition on the tahoe,
the ``c'' partition on all others.
+.Pp
+For the i386 architecture, the primary bootstrap sector contains
+an embedded
+.Em fdisk
+table.
+.Nm Disklabel
+takes care to not clobber it when installing a bootstrap only
+.Pq Fl B ,
+or when editing an existing label
+.Pq Fl e ,
+but it unconditionally writes the primary bootstrap program onto
+the disk for
+.Fl w
+or
+.Fl R ,
+thus replacing the
+.Em fdisk
+table by the dummy one in the bootstrap program. This is only of
+concern if the disk is fully dedicated, so that the BSD disklabel
+starts at absolute block 0 on the disk.
diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c
index cf93fc4..3de7004 100644
--- a/sbin/bsdlabel/bsdlabel.c
+++ b/sbin/bsdlabel/bsdlabel.c
@@ -547,6 +547,10 @@ makebootarea(boot, dp, f)
#if NUMBOOT == 1
struct stat sb;
#endif
+#ifdef __i386__
+ char *tmpbuf;
+ int i, found;
+#endif /* i386 */
#endif
/* XXX */
@@ -628,9 +632,32 @@ makebootarea(boot, dp, f)
if (b < 0)
Perror(xxboot);
#if NUMBOOT > 1
+#ifdef __i386__
+ /*
+ * XXX Botch alert.
+ * The i386 has the so-called fdisk table embedded into the
+ * primary bootstrap. We take care to not clobber it, but
+ * only if it does already contain some data. (Otherwise,
+ * the xxboot provides a template.)
+ */
+ if ((tmpbuf = (char *)malloc((int)dp->d_secsize)) == 0)
+ Perror(xxboot);
+ memcpy((void *)tmpbuf, (void *)boot, (int)dp->d_secsize);
+#endif /* i386 */
if (read(b, boot, (int)dp->d_secsize) < 0)
Perror(xxboot);
(void)close(b);
+#ifdef __i386__
+ for (i = DOSPARTOFF, found = 0;
+ !found && i < DOSPARTOFF + NDOSPART*sizeof(struct dos_partition);
+ i++)
+ found = tmpbuf[i] != 0;
+ if (found)
+ memcpy((void *)&boot[DOSPARTOFF],
+ (void *)&tmpbuf[DOSPARTOFF],
+ NDOSPART * sizeof(struct dos_partition));
+ free(tmpbuf);
+#endif /* i386 */
b = open(bootxx, O_RDONLY);
if (b < 0)
Perror(bootxx);
diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8
index 1cc33ab..ce1b168 100644
--- a/sbin/disklabel/disklabel.8
+++ b/sbin/disklabel/disklabel.8
@@ -362,3 +362,23 @@ will not install bootstrap code that overlaps it.
When a disk name is given without a full pathname,
the constructed device name uses the ``a'' partition on the tahoe,
the ``c'' partition on all others.
+.Pp
+For the i386 architecture, the primary bootstrap sector contains
+an embedded
+.Em fdisk
+table.
+.Nm Disklabel
+takes care to not clobber it when installing a bootstrap only
+.Pq Fl B ,
+or when editing an existing label
+.Pq Fl e ,
+but it unconditionally writes the primary bootstrap program onto
+the disk for
+.Fl w
+or
+.Fl R ,
+thus replacing the
+.Em fdisk
+table by the dummy one in the bootstrap program. This is only of
+concern if the disk is fully dedicated, so that the BSD disklabel
+starts at absolute block 0 on the disk.
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index cf93fc4..3de7004 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -547,6 +547,10 @@ makebootarea(boot, dp, f)
#if NUMBOOT == 1
struct stat sb;
#endif
+#ifdef __i386__
+ char *tmpbuf;
+ int i, found;
+#endif /* i386 */
#endif
/* XXX */
@@ -628,9 +632,32 @@ makebootarea(boot, dp, f)
if (b < 0)
Perror(xxboot);
#if NUMBOOT > 1
+#ifdef __i386__
+ /*
+ * XXX Botch alert.
+ * The i386 has the so-called fdisk table embedded into the
+ * primary bootstrap. We take care to not clobber it, but
+ * only if it does already contain some data. (Otherwise,
+ * the xxboot provides a template.)
+ */
+ if ((tmpbuf = (char *)malloc((int)dp->d_secsize)) == 0)
+ Perror(xxboot);
+ memcpy((void *)tmpbuf, (void *)boot, (int)dp->d_secsize);
+#endif /* i386 */
if (read(b, boot, (int)dp->d_secsize) < 0)
Perror(xxboot);
(void)close(b);
+#ifdef __i386__
+ for (i = DOSPARTOFF, found = 0;
+ !found && i < DOSPARTOFF + NDOSPART*sizeof(struct dos_partition);
+ i++)
+ found = tmpbuf[i] != 0;
+ if (found)
+ memcpy((void *)&boot[DOSPARTOFF],
+ (void *)&tmpbuf[DOSPARTOFF],
+ NDOSPART * sizeof(struct dos_partition));
+ free(tmpbuf);
+#endif /* i386 */
b = open(bootxx, O_RDONLY);
if (b < 0)
Perror(bootxx);
OpenPOWER on IntegriCloud