1995-04-29 07:21:14 +00:00
|
|
|
/*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
2002-03-25 13:52:45 +00:00
|
|
|
* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
|
1995-04-29 07:21:14 +00:00
|
|
|
* 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
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2001-09-30 21:16:57 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1995-04-29 07:21:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/diskslice.h>
|
2000-06-28 22:28:50 +00:00
|
|
|
#include <paths.h>
|
1995-04-29 07:21:14 +00:00
|
|
|
#include "libdisk.h"
|
|
|
|
|
|
|
|
#define DOSPTYP_EXTENDED 5
|
1995-05-30 08:29:07 +00:00
|
|
|
#define BBSIZE 8192
|
1995-08-26 04:57:03 +00:00
|
|
|
#define SBSIZE 8192
|
|
|
|
#define DEF_RPM 3600
|
|
|
|
#define DEF_INTERLEAVE 1
|
1995-04-30 06:09:29 +00:00
|
|
|
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#define WHERE(offset,disk) (offset)
|
|
|
|
#else
|
1995-04-30 06:09:29 +00:00
|
|
|
#define WHERE(offset,disk) (disk->flags & DISK_ON_TRACK ? offset + 63 : offset)
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
2001-05-13 20:08:54 +00:00
|
|
|
|
|
|
|
/* 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 */
|
1995-04-30 06:09:29 +00:00
|
|
|
int
|
|
|
|
Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
|
|
|
|
{
|
|
|
|
struct disklabel *dl;
|
|
|
|
struct chunk *c2;
|
|
|
|
int i,j;
|
|
|
|
void *p;
|
|
|
|
u_char buf[BBSIZE];
|
1998-10-06 11:57:08 +00:00
|
|
|
#ifdef __alpha__
|
|
|
|
u_long *lp, sum;
|
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
|
2001-04-01 12:18:20 +00:00
|
|
|
for(i = 0; i < BBSIZE/512; i++) {
|
2001-05-13 20:08:54 +00:00
|
|
|
p = read_block(fd, WHERE(i + c1->offset, new), 512);
|
2001-04-01 12:18:20 +00:00
|
|
|
memcpy(buf + 512 * i, p, 512);
|
1995-04-30 06:09:29 +00:00
|
|
|
free(p);
|
|
|
|
}
|
1998-10-06 11:57:08 +00:00
|
|
|
#if defined(__i386__)
|
1995-04-30 06:09:29 +00:00
|
|
|
if(new->boot1)
|
2001-04-01 12:18:20 +00:00
|
|
|
memcpy(buf, new->boot1, 512);
|
1995-04-30 06:09:29 +00:00
|
|
|
|
|
|
|
if(new->boot2)
|
2001-04-01 12:18:20 +00:00
|
|
|
memcpy(buf + 512, new->boot2, BBSIZE-512);
|
1998-10-06 11:57:08 +00:00
|
|
|
#elif defined(__alpha__)
|
|
|
|
if(new->boot1)
|
2001-04-01 12:18:20 +00:00
|
|
|
memcpy(buf + 512, new->boot1, BBSIZE-512);
|
1998-10-06 11:57:08 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
|
2001-04-01 12:18:20 +00:00
|
|
|
dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
|
|
|
|
memset(dl, 0, sizeof *dl);
|
1995-04-30 06:09:29 +00:00
|
|
|
|
2001-04-01 12:18:20 +00:00
|
|
|
for(c2 = c1->part; c2; c2 = c2->next) {
|
1995-04-30 06:09:29 +00:00
|
|
|
if (c2->type == unused) continue;
|
2001-04-01 12:18:20 +00:00
|
|
|
if (!strcmp(c2->name, "X")) continue;
|
1999-01-29 11:39:24 +00:00
|
|
|
#ifdef __alpha__
|
|
|
|
j = c2->name[strlen(c2->name) - 1] - 'a';
|
|
|
|
#else
|
1998-10-27 21:14:03 +00:00
|
|
|
j = c2->name[strlen(new->name) + 2] - 'a';
|
1999-01-29 11:39:24 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
if (j < 0 || j >= MAXPARTITIONS || j == RAW_PART) {
|
1996-04-29 05:03:02 +00:00
|
|
|
#ifdef DEBUG
|
2001-04-01 12:18:20 +00:00
|
|
|
warn("weird partition letter %c", c2->name[strlen(new->name) + 2]);
|
1996-04-29 05:03:02 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dl->d_partitions[j].p_size = c2->size;
|
1995-04-30 22:51:05 +00:00
|
|
|
dl->d_partitions[j].p_offset = c2->offset;
|
1995-04-30 11:04:16 +00:00
|
|
|
dl->d_partitions[j].p_fstype = c2->subtype;
|
1995-04-30 06:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dl->d_bbsize = BBSIZE;
|
1995-08-26 04:57:03 +00:00
|
|
|
/*
|
|
|
|
* Add in defaults for superblock size, interleave, and rpms
|
|
|
|
*/
|
|
|
|
dl->d_sbsize = SBSIZE;
|
|
|
|
dl->d_interleave = DEF_INTERLEAVE;
|
|
|
|
dl->d_rpm = DEF_RPM;
|
1995-04-30 06:09:29 +00:00
|
|
|
|
2001-04-01 12:18:20 +00:00
|
|
|
strcpy(dl->d_typename, c1->name);
|
1995-04-30 06:09:29 +00:00
|
|
|
|
1995-04-30 11:04:16 +00:00
|
|
|
dl->d_secsize = 512;
|
1995-04-30 06:09:29 +00:00
|
|
|
dl->d_secperunit = new->chunks->size;
|
1995-12-07 10:34:59 +00:00
|
|
|
dl->d_ncylinders = new->bios_cyl;
|
1995-06-11 19:33:05 +00:00
|
|
|
dl->d_ntracks = new->bios_hd;
|
|
|
|
dl->d_nsectors = new->bios_sect;
|
1995-04-30 11:04:16 +00:00
|
|
|
dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors;
|
1995-04-30 06:09:29 +00:00
|
|
|
|
|
|
|
dl->d_npartitions = MAXPARTITIONS;
|
|
|
|
|
1998-06-27 02:01:25 +00:00
|
|
|
dl->d_type = new->name[0] == 's' || new->name[0] == 'd' ||
|
|
|
|
new->name[0] == 'o' ? DTYPE_SCSI : DTYPE_ESDI;
|
1995-04-30 06:09:29 +00:00
|
|
|
dl->d_partitions[RAW_PART].p_size = c1->size;
|
1995-04-30 22:51:05 +00:00
|
|
|
dl->d_partitions[RAW_PART].p_offset = c1->offset;
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
|
|
|
dl->d_rpm = 3600;
|
|
|
|
dl->d_interleave = 1;
|
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifndef PC98
|
1995-05-08 02:08:33 +00:00
|
|
|
if(new->flags & DISK_ON_TRACK)
|
|
|
|
for(i=0;i<MAXPARTITIONS;i++)
|
|
|
|
if (dl->d_partitions[i].p_size)
|
|
|
|
dl->d_partitions[i].p_offset += 63;
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
dl->d_magic = DISKMAGIC;
|
|
|
|
dl->d_magic2 = DISKMAGIC;
|
|
|
|
dl->d_checksum = dkcksum(dl);
|
|
|
|
|
1998-10-06 11:57:08 +00:00
|
|
|
#ifdef __alpha__
|
1999-01-08 00:32:19 +00:00
|
|
|
/*
|
|
|
|
* Tell SRM where the bootstrap is.
|
|
|
|
*/
|
|
|
|
lp = (u_long *)buf;
|
|
|
|
lp[60] = 15;
|
|
|
|
lp[61] = 1;
|
|
|
|
lp[62] = 0;
|
|
|
|
|
1998-10-06 11:57:08 +00:00
|
|
|
/*
|
|
|
|
* Generate the bootblock checksum for the SRM console.
|
|
|
|
*/
|
|
|
|
for (lp = (u_long *)buf, i = 0, sum = 0; i < 63; i++)
|
|
|
|
sum += lp[i];
|
|
|
|
lp[63] = sum;
|
2001-04-01 11:37:31 +00:00
|
|
|
#endif /*__alpha__*/
|
1998-10-06 11:57:08 +00:00
|
|
|
|
1995-04-30 06:09:29 +00:00
|
|
|
for(i=0;i<BBSIZE/512;i++) {
|
2001-05-13 20:08:54 +00:00
|
|
|
write_block(fd,WHERE(i + c1->offset, new), buf + 512 * i, 512);
|
1995-04-30 06:09:29 +00:00
|
|
|
}
|
1995-05-30 08:29:07 +00:00
|
|
|
|
1995-04-30 06:09:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Write_Extended(int fd, struct disk *new, struct disk *old, struct chunk *c1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
1995-04-29 07:21:14 +00:00
|
|
|
|
2001-04-01 11:37:31 +00:00
|
|
|
#if defined(__i386__) && !defined(PC98)
|
1998-09-30 21:40:51 +00:00
|
|
|
static void
|
|
|
|
Write_Int32(u_int32_t *p, u_int32_t v)
|
|
|
|
{
|
|
|
|
u_int8_t *bp = (u_int8_t *)p;
|
|
|
|
bp[0] = (v >> 0) & 0xff;
|
|
|
|
bp[1] = (v >> 8) & 0xff;
|
|
|
|
bp[2] = (v >> 16) & 0xff;
|
|
|
|
bp[3] = (v >> 24) & 0xff;
|
|
|
|
}
|
2001-04-01 11:37:31 +00:00
|
|
|
#endif
|
2000-12-12 17:25:06 +00:00
|
|
|
|
2001-04-01 11:37:31 +00:00
|
|
|
#if defined(__i386__) && !defined(PC98)
|
2000-12-12 17:25:06 +00:00
|
|
|
/*
|
|
|
|
* Special install-time configuration for the i386 boot0 boot manager.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
Cfg_Boot_Mgr(u_char *mbr, int edd)
|
|
|
|
{
|
|
|
|
if (mbr[0x1b0] == 0x66 && mbr[0x1b1] == 0xbb) {
|
|
|
|
if (edd)
|
|
|
|
mbr[0x1bb] |= 0x80; /* Packet mode on */
|
|
|
|
else
|
|
|
|
mbr[0x1bb] &= 0x7f; /* Packet mode off */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1998-09-30 21:40:51 +00:00
|
|
|
|
1995-04-29 07:21:14 +00:00
|
|
|
int
|
|
|
|
Write_Disk(struct disk *d1)
|
|
|
|
{
|
2001-04-01 11:22:40 +00:00
|
|
|
int fd,i;
|
|
|
|
#ifdef __i386__
|
|
|
|
int j;
|
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
struct disk *old = 0;
|
|
|
|
struct chunk *c1;
|
|
|
|
int ret = 0;
|
|
|
|
char device[64];
|
1995-04-30 07:30:45 +00:00
|
|
|
u_char *mbr;
|
1995-04-30 22:51:05 +00:00
|
|
|
struct dos_partition *dp,work[NDOSPART];
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
|
|
|
int s[7];
|
|
|
|
int PC98_EntireDisk = 0;
|
|
|
|
#else
|
1995-04-30 06:09:29 +00:00
|
|
|
int s[4];
|
2001-04-01 11:37:31 +00:00
|
|
|
#ifdef __i386__
|
2000-12-12 17:25:06 +00:00
|
|
|
int need_edd = 0; /* Need EDD (packet interface) */
|
|
|
|
#endif
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1999-05-09 11:34:58 +00:00
|
|
|
int one = 1;
|
|
|
|
int zero = 0;
|
1995-04-30 06:09:29 +00:00
|
|
|
|
2000-06-28 22:28:50 +00:00
|
|
|
strcpy(device,_PATH_DEV);
|
1995-04-30 06:09:29 +00:00
|
|
|
strcat(device,d1->name);
|
|
|
|
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
|
|
|
/* XXX - for entire FreeBSD(98) */
|
|
|
|
for (c1 = d1->chunks->part; c1; c1 = c1->next) {
|
|
|
|
if ((c1->type == freebsd) || (c1->offset == 0))
|
|
|
|
device[9] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-04-30 06:09:29 +00:00
|
|
|
fd = open(device,O_RDWR);
|
|
|
|
if (fd < 0) {
|
1996-04-29 05:03:02 +00:00
|
|
|
#ifdef DEBUG
|
2001-04-01 12:18:20 +00:00
|
|
|
warn("open(%s) failed", device);
|
1996-04-29 05:03:02 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1999-05-09 11:34:58 +00:00
|
|
|
ioctl(fd, DIOCWLABEL, &one);
|
1995-04-30 06:09:29 +00:00
|
|
|
|
|
|
|
memset(s,0,sizeof s);
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
2001-05-13 20:08:54 +00:00
|
|
|
mbr = read_block(fd, WHERE(1, d1), d1->sector_size);
|
2000-03-29 15:10:28 +00:00
|
|
|
#else
|
2001-05-13 20:08:54 +00:00
|
|
|
mbr = read_block(fd, WHERE(0, d1), d1->sector_size);
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
2001-04-01 12:18:20 +00:00
|
|
|
dp = (struct dos_partition*)(mbr + DOSPARTOFF);
|
|
|
|
memcpy(work, dp, sizeof work);
|
1995-04-30 22:51:05 +00:00
|
|
|
dp = work;
|
|
|
|
free(mbr);
|
2001-04-01 12:18:20 +00:00
|
|
|
for (c1 = d1->chunks->part; c1; c1 = c1->next) {
|
1995-04-30 06:09:29 +00:00
|
|
|
if (c1->type == unused) continue;
|
2001-04-01 12:18:20 +00:00
|
|
|
if (!strcmp(c1->name, "X")) continue;
|
2001-04-01 11:37:31 +00:00
|
|
|
#ifdef __i386__
|
1995-04-30 06:09:29 +00:00
|
|
|
j = c1->name[4] - '1';
|
1998-10-27 21:14:03 +00:00
|
|
|
j = c1->name[strlen(d1->name) + 1] - '1';
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
|
|
|
if (j < 0 || j > 7)
|
|
|
|
#else
|
1995-04-30 06:09:29 +00:00
|
|
|
if (j < 0 || j > 3)
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
continue;
|
|
|
|
s[j]++;
|
1999-01-29 11:39:24 +00:00
|
|
|
#endif
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifndef PC98
|
1995-04-30 22:51:05 +00:00
|
|
|
if (c1->type == extended)
|
2001-04-01 12:18:20 +00:00
|
|
|
ret += Write_Extended(fd, d1, old, c1);
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1995-04-30 22:51:05 +00:00
|
|
|
if (c1->type == freebsd)
|
2001-04-01 12:18:20 +00:00
|
|
|
ret += Write_FreeBSD(fd, d1, old, c1);
|
1995-04-30 22:51:05 +00:00
|
|
|
|
2001-04-01 11:37:31 +00:00
|
|
|
#ifdef __i386__
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifndef PC98
|
1998-09-30 21:40:51 +00:00
|
|
|
Write_Int32(&dp[j].dp_start, c1->offset);
|
|
|
|
Write_Int32(&dp[j].dp_size, c1->size);
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
|
|
|
|
i = c1->offset;
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
|
|
|
dp[j].dp_ssect = dp[j].dp_ipl_sct = i % d1->bios_sect;
|
|
|
|
i -= dp[j].dp_ssect;
|
|
|
|
i /= d1->bios_sect;
|
|
|
|
dp[j].dp_shd = dp[j].dp_ipl_head = i % d1->bios_hd;
|
|
|
|
i -= dp[j].dp_shd;
|
|
|
|
i /= d1->bios_hd;
|
|
|
|
dp[j].dp_scyl = dp[j].dp_ipl_cyl = i;
|
|
|
|
#else
|
1995-04-30 07:30:45 +00:00
|
|
|
if (i >= 1024*d1->bios_sect*d1->bios_hd) {
|
|
|
|
dp[j].dp_ssect = 0xff;
|
|
|
|
dp[j].dp_shd = 0xff;
|
|
|
|
dp[j].dp_scyl = 0xff;
|
2000-12-12 17:25:06 +00:00
|
|
|
need_edd++;
|
1995-04-30 07:30:45 +00:00
|
|
|
} else {
|
|
|
|
dp[j].dp_ssect = i % d1->bios_sect;
|
1995-04-30 22:51:05 +00:00
|
|
|
i -= dp[j].dp_ssect++;
|
1995-05-30 08:29:07 +00:00
|
|
|
i /= d1->bios_sect;
|
1995-04-30 07:30:45 +00:00
|
|
|
dp[j].dp_shd = i % d1->bios_hd;
|
|
|
|
i -= dp[j].dp_shd;
|
|
|
|
i /= d1->bios_hd;
|
|
|
|
dp[j].dp_scyl = i;
|
1995-04-30 22:51:05 +00:00
|
|
|
i -= dp[j].dp_scyl;
|
|
|
|
dp[j].dp_ssect |= i >> 2;
|
1995-04-30 07:30:45 +00:00
|
|
|
}
|
2001-04-01 11:37:31 +00:00
|
|
|
#endif /* PC98 */
|
1995-05-01 04:05:27 +00:00
|
|
|
|
1995-05-04 07:00:57 +00:00
|
|
|
#ifdef DEBUG
|
1995-05-30 08:29:07 +00:00
|
|
|
printf("S:%lu = (%x/%x/%x)",
|
2001-04-01 12:18:20 +00:00
|
|
|
c1->offset, dp[j].dp_scyl, dp[j].dp_shd, dp[j].dp_ssect);
|
1995-05-04 07:00:57 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
|
|
|
|
i = c1->end;
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#if 1
|
|
|
|
dp[j].dp_esect = dp[j].dp_ehd = 0;
|
|
|
|
dp[j].dp_ecyl = i / (d1->bios_sect * d1->bios_hd);
|
|
|
|
#else
|
|
|
|
dp[j].dp_esect = i % d1->bios_sect;
|
|
|
|
i -= dp[j].dp_esect;
|
|
|
|
i /= d1->bios_sect;
|
|
|
|
dp[j].dp_ehd = i % d1->bios_hd;
|
|
|
|
i -= dp[j].dp_ehd;
|
|
|
|
i /= d1->bios_hd;
|
|
|
|
dp[j].dp_ecyl = i;
|
|
|
|
#endif
|
|
|
|
#else
|
1995-05-01 04:05:27 +00:00
|
|
|
dp[j].dp_esect = i % d1->bios_sect;
|
|
|
|
i -= dp[j].dp_esect++;
|
1995-05-30 08:29:07 +00:00
|
|
|
i /= d1->bios_sect;
|
1995-05-01 04:05:27 +00:00
|
|
|
dp[j].dp_ehd = i % d1->bios_hd;
|
|
|
|
i -= dp[j].dp_ehd;
|
|
|
|
i /= d1->bios_hd;
|
|
|
|
if (i>1023) i = 1023;
|
|
|
|
dp[j].dp_ecyl = i;
|
|
|
|
i -= dp[j].dp_ecyl;
|
|
|
|
dp[j].dp_esect |= i >> 2;
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1995-05-01 04:05:27 +00:00
|
|
|
|
1995-05-04 07:00:57 +00:00
|
|
|
#ifdef DEBUG
|
1995-05-30 08:29:07 +00:00
|
|
|
printf(" E:%lu = (%x/%x/%x)\n",
|
2001-04-01 12:18:20 +00:00
|
|
|
c1->end, dp[j].dp_ecyl, dp[j].dp_ehd, dp[j].dp_esect);
|
1995-05-04 07:00:57 +00:00
|
|
|
#endif
|
1995-04-30 07:30:45 +00:00
|
|
|
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
|
|
|
dp[j].dp_mid = c1->subtype & 0xff;
|
|
|
|
dp[j].dp_sid = c1->subtype >> 8;
|
|
|
|
if (c1->flags & CHUNK_ACTIVE)
|
|
|
|
dp[j].dp_mid |= 0x80;
|
|
|
|
|
|
|
|
strncpy(dp[j].dp_name, c1->sname, 16);
|
|
|
|
#else
|
1995-04-30 22:51:05 +00:00
|
|
|
dp[j].dp_typ = c1->subtype;
|
1995-05-04 07:00:57 +00:00
|
|
|
if (c1->flags & CHUNK_ACTIVE)
|
|
|
|
dp[j].dp_flag = 0x80;
|
|
|
|
else
|
|
|
|
dp[j].dp_flag = 0;
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1999-01-29 11:39:24 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
}
|
2001-04-01 11:37:31 +00:00
|
|
|
#ifdef __i386__
|
1995-05-08 02:08:33 +00:00
|
|
|
j = 0;
|
2001-04-01 12:18:20 +00:00
|
|
|
for(i = 0; i < NDOSPART; i++) {
|
1995-04-30 06:09:29 +00:00
|
|
|
if (!s[i])
|
2001-04-01 12:18:20 +00:00
|
|
|
memset(dp + i, 0, sizeof *dp);
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifndef PC98
|
1995-05-08 02:08:33 +00:00
|
|
|
if (dp[i].dp_flag)
|
|
|
|
j++;
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1995-05-08 02:08:33 +00:00
|
|
|
}
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifndef PC98
|
1995-05-08 02:08:33 +00:00
|
|
|
if (!j)
|
2001-04-01 12:18:20 +00:00
|
|
|
for(i = 0; i < NDOSPART; i++)
|
1995-05-21 07:47:24 +00:00
|
|
|
if (dp[i].dp_typ == 0xa5)
|
1995-05-08 02:08:33 +00:00
|
|
|
dp[i].dp_flag = 0x80;
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1995-05-30 08:29:07 +00:00
|
|
|
|
2000-03-29 15:10:28 +00:00
|
|
|
#ifdef PC98
|
2000-08-12 14:20:31 +00:00
|
|
|
if (d1->bootipl)
|
2001-05-13 20:08:54 +00:00
|
|
|
write_block(fd, WHERE(0, d1), d1->bootipl, d1->sector_size);
|
2000-08-12 14:20:31 +00:00
|
|
|
|
2001-05-13 20:08:54 +00:00
|
|
|
mbr = read_block(fd, WHERE(1, d1), d1->sector_size);
|
2001-04-01 12:18:20 +00:00
|
|
|
memcpy(mbr + DOSPARTOFF, dp, sizeof *dp * NDOSPART);
|
2000-03-29 15:10:28 +00:00
|
|
|
/* XXX - for entire FreeBSD(98) */
|
|
|
|
for (c1 = d1->chunks->part; c1; c1 = c1->next)
|
|
|
|
if (((c1->type == freebsd) || (c1->type == fat))
|
|
|
|
&& (c1->offset == 0))
|
|
|
|
PC98_EntireDisk = 1;
|
|
|
|
if (PC98_EntireDisk == 0)
|
2001-05-13 20:08:54 +00:00
|
|
|
write_block(fd, WHERE(1, d1), mbr, d1->sector_size);
|
2000-08-12 14:20:31 +00:00
|
|
|
|
|
|
|
if (d1->bootmenu)
|
2001-05-13 20:08:54 +00:00
|
|
|
for (i = 0; i * d1->sector_size < d1->bootmenu_size; i++)
|
|
|
|
write_block(fd, WHERE(2 + i, d1), &d1->bootmenu[i * d1->sector_size], d1->sector_size);
|
2000-03-29 15:10:28 +00:00
|
|
|
#else
|
2001-05-13 20:08:54 +00:00
|
|
|
mbr = read_block(fd, WHERE(0, d1), d1->sector_size);
|
2000-12-12 17:25:06 +00:00
|
|
|
if (d1->bootmgr) {
|
2001-04-01 12:18:20 +00:00
|
|
|
memcpy(mbr, d1->bootmgr, DOSPARTOFF);
|
2000-12-12 17:25:06 +00:00
|
|
|
Cfg_Boot_Mgr(mbr, need_edd);
|
|
|
|
}
|
2001-04-01 12:18:20 +00:00
|
|
|
memcpy(mbr + DOSPARTOFF, dp, sizeof *dp * NDOSPART);
|
1995-04-30 07:30:45 +00:00
|
|
|
mbr[512-2] = 0x55;
|
|
|
|
mbr[512-1] = 0xaa;
|
2001-05-13 20:08:54 +00:00
|
|
|
write_block(fd, WHERE(0, d1), mbr, d1->sector_size);
|
|
|
|
if (d1->bootmgr && d1->bootmgr_size > d1->sector_size)
|
|
|
|
for(i = 1; i * d1->sector_size <= d1->bootmgr_size; i++)
|
|
|
|
write_block(fd, WHERE(i, d1), &d1->bootmgr[i * d1->sector_size], d1->sector_size);
|
2000-03-29 15:10:28 +00:00
|
|
|
#endif
|
1999-01-08 00:32:19 +00:00
|
|
|
#endif
|
1995-04-30 06:09:29 +00:00
|
|
|
|
1995-04-30 22:51:05 +00:00
|
|
|
i = 1;
|
2001-04-01 12:18:20 +00:00
|
|
|
i = ioctl(fd, DIOCSYNCSLICEINFO, &i);
|
1996-04-29 05:03:02 +00:00
|
|
|
#ifdef DEBUG
|
1995-04-30 22:51:05 +00:00
|
|
|
if (i != 0)
|
|
|
|
warn("ioctl(DIOCSYNCSLICEINFO)");
|
1996-04-29 05:03:02 +00:00
|
|
|
#endif
|
1999-05-09 11:34:58 +00:00
|
|
|
ioctl(fd, DIOCWLABEL, &zero);
|
1995-04-30 06:09:29 +00:00
|
|
|
close(fd);
|
1995-04-29 07:21:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|