summaryrefslogtreecommitdiffstats
path: root/lib/libdisk
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-10-23 19:32:18 +0000
committerphk <phk@FreeBSD.org>2002-10-23 19:32:18 +0000
commita422fc77aed8e1bd796a01b2de09138e90fabad5 (patch)
tree95a0a3830071caeb219d8d39b725ba9efa31f0ad /lib/libdisk
parentfba4a6dd09d9f8496ff611a9366f8571dfb394d3 (diff)
downloadFreeBSD-src-a422fc77aed8e1bd796a01b2de09138e90fabad5.zip
FreeBSD-src-a422fc77aed8e1bd796a01b2de09138e90fabad5.tar.gz
Separate the struct disklabel filling stuff from the rest of Write_FreeBSD().
Diffstat (limited to 'lib/libdisk')
-rw-r--r--lib/libdisk/write_disk.c83
1 files changed, 41 insertions, 42 deletions
diff --git a/lib/libdisk/write_disk.c b/lib/libdisk/write_disk.c
index d3ad912..f889c11 100644
--- a/lib/libdisk/write_disk.c
+++ b/lib/libdisk/write_disk.c
@@ -28,56 +28,23 @@ __FBSDID("$FreeBSD$");
#include <paths.h>
#include "libdisk.h"
-#define DEF_RPM 3600
-#define DEF_INTERLEAVE 1
-
/* XXX: A lot of hardcoded 512s probably should be foo->sector_size;
I'm not sure which, so I leave it like it worked before. --schweikh */
-static int
-Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, const struct chunk *c1)
+
+static void
+Fill_Disklabel(struct disklabel *dl, const struct disk *new, const struct disk *old, const struct chunk *c1)
{
- struct disklabel *dl;
struct chunk *c2;
- int i,j;
- void *p;
- u_char buf[BBSIZE];
-#ifdef __alpha__
- u_long *lp, sum;
-#endif
-
- for(i = 0; i < BBSIZE/512; i++) {
- p = read_block(fd, i + c1->offset, 512);
- memcpy(buf + 512 * i, p, 512);
- free(p);
- }
-#if defined(__i386__)
- if(new->boot1)
- memcpy(buf, new->boot1, 512);
-
- if(new->boot2)
- memcpy(buf + 512, new->boot2, BBSIZE-512);
-#elif defined(__alpha__)
- if(new->boot1)
- memcpy(buf + 512, new->boot1, BBSIZE-512);
-#endif
+ int j;
- dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
memset(dl, 0, sizeof *dl);
for(c2 = c1->part; c2; c2 = c2->next) {
if (c2->type == unused) continue;
if (!strcmp(c2->name, "X")) continue;
-#ifdef __alpha__
j = c2->name[strlen(c2->name) - 1] - 'a';
-#else
- j = c2->name[strlen(new->name) + 2] - 'a';
-#endif
- if (j < 0 || j >= MAXPARTITIONS || j == RAW_PART) {
-#ifdef DEBUG
- warn("weird partition letter %c", c2->name[strlen(new->name) + 2]);
-#endif
+ if (j < 0 || j >= MAXPARTITIONS || j == RAW_PART)
continue;
- }
dl->d_partitions[j].p_size = c2->size;
dl->d_partitions[j].p_offset = c2->offset;
dl->d_partitions[j].p_fstype = c2->subtype;
@@ -88,8 +55,6 @@ Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, const stru
* Add in defaults for superblock size, interleave, and rpms
*/
dl->d_sbsize = 0;
- dl->d_interleave = DEF_INTERLEAVE;
- dl->d_rpm = DEF_RPM;
strcpy(dl->d_typename, c1->name);
@@ -106,15 +71,49 @@ Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, const stru
new->name[0] == 'o' ? DTYPE_SCSI : DTYPE_ESDI;
dl->d_partitions[RAW_PART].p_size = c1->size;
dl->d_partitions[RAW_PART].p_offset = c1->offset;
-#ifdef PC98
dl->d_rpm = 3600;
dl->d_interleave = 1;
-#endif
dl->d_magic = DISKMAGIC;
dl->d_magic2 = DISKMAGIC;
dl->d_checksum = dkcksum(dl);
+ return;
+}
+
+
+/* XXX: A lot of hardcoded 512s probably should be foo->sector_size;
+ I'm not sure which, so I leave it like it worked before. --schweikh */
+static int
+Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, const struct chunk *c1)
+{
+ struct disklabel *dl;
+ int i;
+ void *p;
+ u_char buf[BBSIZE];
+#ifdef __alpha__
+ u_long *lp, sum;
+#endif
+
+ for(i = 0; i < BBSIZE/512; i++) {
+ p = read_block(fd, i + c1->offset, 512);
+ memcpy(buf + 512 * i, p, 512);
+ free(p);
+ }
+#if defined(__i386__)
+ if(new->boot1)
+ memcpy(buf, new->boot1, 512);
+
+ if(new->boot2)
+ memcpy(buf + 512, new->boot2, BBSIZE-512);
+#elif defined(__alpha__)
+ if(new->boot1)
+ memcpy(buf + 512, new->boot1, BBSIZE-512);
+#endif
+
+ dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
+ Fill_Disklabel(dl, new, old, c1);
+
#ifdef __alpha__
/*
* Tell SRM where the bootstrap is.
OpenPOWER on IntegriCloud