summaryrefslogtreecommitdiffstats
path: root/lib/libdisk/write_sparc64_disk.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-10-29 07:35:36 +0000
committerphk <phk@FreeBSD.org>2002-10-29 07:35:36 +0000
commitaee7fb11fe4d5f75a6b006ea8f5e420ae6520a8a (patch)
tree64f1deb969ed58f30108f06b3bdbbd6ace6fb8d7 /lib/libdisk/write_sparc64_disk.c
parentb676b9e9b3390019c2b232fed7b7efbf5235f20b (diff)
downloadFreeBSD-src-aee7fb11fe4d5f75a6b006ea8f5e420ae6520a8a.zip
FreeBSD-src-aee7fb11fe4d5f75a6b006ea8f5e420ae6520a8a.tar.gz
Add the write_spar64_disk.c to make life easier for testers.
This file depends on some major surgery in the rest of libdisk which is not yet committed.
Diffstat (limited to 'lib/libdisk/write_sparc64_disk.c')
-rw-r--r--lib/libdisk/write_sparc64_disk.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/lib/libdisk/write_sparc64_disk.c b/lib/libdisk/write_sparc64_disk.c
new file mode 100644
index 0000000..9431907
--- /dev/null
+++ b/lib/libdisk/write_sparc64_disk.c
@@ -0,0 +1,94 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <err.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/sun_disklabel.h>
+#include <paths.h>
+#include <errno.h>
+#include "libdisk.h"
+
+int
+Write_Disk(const struct disk *d1)
+{
+ struct sun_disklabel *sl;
+ struct chunk *c, *c1, *c2;
+ int i;
+ char *p;
+ u_long secpercyl;
+ u_short *sp1, *sp2, cksum;
+ char device[64];
+ int fd;
+
+ sl = calloc(sizeof *sl, 1);
+ c = d1->chunks;
+ c2 = c->part;
+ secpercyl = d1->bios_sect * d1->bios_hd;
+ sl->sl_pcylinders = c->size / secpercyl;
+ sl->sl_ncylinders = c2->size / secpercyl;
+ sl->sl_acylinders = sl->sl_pcylinders - sl->sl_ncylinders;
+ sl->sl_magic = SUN_DKMAGIC;
+ sl->sl_nsectors = d1->bios_sect;
+ sl->sl_ntracks = d1->bios_hd;
+ if (c->size > 4999 * 1024 * 2) {
+ sprintf(sl->sl_text, "FreeBSD%luG cyl %u alt %u hd %u sec %u",
+ (c->size + 1024 * 1024) / (2 * 1024 * 1024),
+ sl->sl_ncylinders, sl->sl_acylinders,
+ sl->sl_ntracks, sl->sl_nsectors);
+ } else {
+ sprintf(sl->sl_text, "FreeBSD%luM cyl %u alt %u hd %u sec %u",
+ (c->size + 1024) / (2 * 1024),
+ sl->sl_ncylinders, sl->sl_acylinders,
+ sl->sl_ntracks, sl->sl_nsectors);
+ }
+ sl->sl_interleave = 1;
+ sl->sl_sparespercyl = 0;
+ sl->sl_rpm = 3600;
+
+ for (c1 = c2->part; c1 != NULL; c1 = c1->next) {
+ p = c1->name;
+ p += strlen(p);
+ p--;
+ if (*p < 'a' || *p > 'h')
+ continue;
+ i = *p - 'a';
+ sl->sl_part[i].sdkp_cyloffset = c1->offset / secpercyl;
+ sl->sl_part[i].sdkp_nsectors = c1->size;
+ }
+
+ sp1 = (u_short *)sl;
+ sp2 = (u_short *)(sl + 1);
+ sl->sl_cksum = cksum = 0;
+ while (sp1 < sp2)
+ cksum ^= *sp1++;
+ sl->sl_cksum = cksum;
+
+ strcpy(device,_PATH_DEV);
+ strcat(device,d1->name);
+
+ fd = open(device,O_RDWR);
+ if (fd < 0) {
+ warn("open(%s) failed", device);
+ return (1);
+ }
+
+ write_block(fd, 0, sl, sizeof *sl);
+ close(fd);
+ return 0;
+}
OpenPOWER on IntegriCloud