2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
10 #include <sys/cdefs.h>
11 __FBSDID("$FreeBSD$");
19 #include <sys/types.h>
21 #include <sys/ioctl.h>
22 #include <sys/disklabel.h>
23 #include <sys/diskpc98.h>
28 * XXX: A lot of hardcoded 512s probably should be foo->sector_size;
29 * I'm not sure which, so I leave it like it worked before. --schweikh
32 Write_FreeBSD(int fd, const struct disk *new, const struct chunk *c1)
39 for (i = 0; i < BBSIZE / 512; i++) {
40 if (!(p = read_block(fd, i + c1->offset, 512)))
42 memcpy(buf + 512 * i, p, 512);
46 memcpy(buf, new->boot1, 512);
49 memcpy(buf + 512, new->boot2, BBSIZE - 512);
51 dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
52 Fill_Disklabel(dl, new, c1);
54 for (i = 0; i < BBSIZE / 512; i++)
55 write_block(fd, i + c1->offset, buf + 512 * i, 512);
62 Write_Disk(const struct disk *d1)
69 struct pc98_partition *dp, work[NDOSPART];
71 int PC98_EntireDisk = 0;
73 strcpy(device, _PATH_DEV);
74 strcat(device, d1->name);
76 /* XXX - for entire FreeBSD(98) */
77 for (c1 = d1->chunks->part; c1; c1 = c1->next) {
78 if ((c1->type == freebsd) || (c1->offset == 0))
82 fd = open(device, O_RDWR);
85 warn("open(%s) failed", device);
90 memset(s, 0, sizeof s);
91 if (!(mbrblk = read_block(fd, 1, d1->sector_size))) {
95 dp = (struct pc98_partition *)(mbrblk + DOSPARTOFF);
96 memcpy(work, dp, sizeof work);
99 for (c1 = d1->chunks->part; c1; c1 = c1->next) {
100 if (c1->type == unused)
102 if (!strcmp(c1->name, "X"))
104 j = c1->name[strlen(d1->name) + 1] - '1';
108 if (c1->type == freebsd)
109 ret += Write_FreeBSD(fd, d1, c1);
112 dp[j].dp_ssect = dp[j].dp_ipl_sct = i % d1->bios_sect;
115 dp[j].dp_shd = dp[j].dp_ipl_head = i % d1->bios_hd;
118 dp[j].dp_scyl = dp[j].dp_ipl_cyl = i;
120 printf("S:%lu = (%x/%x/%x)", c1->offset,
121 dp[j].dp_scyl, dp[j].dp_shd, dp[j].dp_ssect);
126 dp[j].dp_esect = dp[j].dp_ehd = 0;
127 dp[j].dp_ecyl = i / (d1->bios_sect * d1->bios_hd);
129 dp[j].dp_esect = i % d1->bios_sect;
132 dp[j].dp_ehd = i % d1->bios_hd;
138 printf(" E:%lu = (%x/%x/%x)\n", c1->end,
139 dp[j].dp_ecyl, dp[j].dp_ehd, dp[j].dp_esect);
142 dp[j].dp_mid = c1->subtype & 0xff;
143 dp[j].dp_sid = c1->subtype >> 8;
144 if (c1->flags & CHUNK_ACTIVE)
145 dp[j].dp_mid |= 0x80;
147 strncpy(dp[j].dp_name, c1->sname, 16);
150 for (i = 0; i < NDOSPART; i++) {
152 memset(dp + i, 0, sizeof *dp);
156 write_block(fd, 0, d1->bootipl, d1->sector_size);
158 if (!(mbrblk = read_block(fd, 1, d1->sector_size))) {
162 memcpy(mbrblk + DOSPARTOFF, dp, sizeof *dp * NDOSPART);
163 /* XXX - for entire FreeBSD(98) */
164 for (c1 = d1->chunks->part; c1; c1 = c1->next)
165 if (((c1->type == freebsd) || (c1->type == fat))
166 && (c1->offset == 0))
168 if (PC98_EntireDisk == 0)
169 write_block(fd, 1, mbrblk, d1->sector_size);
172 for (i = 0; i * d1->sector_size < d1->bootmenu_size; i++)
173 write_block(fd, 2 + i,
174 &d1->bootmenu[i * d1->sector_size],