summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1995-04-30 22:51:05 +0000
committerphk <phk@FreeBSD.org>1995-04-30 22:51:05 +0000
commit0ffc27529d2c7ca6ee9effc3d7b9992202957586 (patch)
tree52fa95719c11c41eb13898b8e89eb62713ab669f
parent98983f573b28e96799662ad8c01789ef1ef7c9e7 (diff)
downloadFreeBSD-src-0ffc27529d2c7ca6ee9effc3d7b9992202957586.zip
FreeBSD-src-0ffc27529d2c7ca6ee9effc3d7b9992202957586.tar.gz
Use the DIOCSYNCSLICE ioctl now. (use only with kernel from this morning).
Get the CHS's right. Get the disklabels (more) right.
-rw-r--r--lib/libdisk/Makefile3
-rw-r--r--lib/libdisk/change.c4
-rw-r--r--lib/libdisk/disk.c21
-rw-r--r--lib/libdisk/write_disk.c60
-rw-r--r--release/libdisk/Makefile3
-rw-r--r--release/libdisk/change.c4
-rw-r--r--release/libdisk/disk.c21
-rw-r--r--release/libdisk/write_disk.c60
8 files changed, 90 insertions, 86 deletions
diff --git a/lib/libdisk/Makefile b/lib/libdisk/Makefile
index 0bd35b0..a1d03db 100644
--- a/lib/libdisk/Makefile
+++ b/lib/libdisk/Makefile
@@ -25,10 +25,11 @@ data.o:
file2c 'const unsigned char boot2[] = {' '};' \
< ${BOOTS}/boot2 >> tmp.c
cc ${CFLAGS} -o data.o -c tmp.c
+ rm -f tmp.c
tst01: ${OBJS}
#cc ${CFLAGS} -DREADLINE -static -o tst01 ${OBJS} -lreadline -ltermcap
cc ${CFLAGS} -static -o tst01 ${OBJS}
clean:
- rm -f *.o *.core tst01
+ rm -f *.o *.core tst01 tmp.c
diff --git a/lib/libdisk/change.c b/lib/libdisk/change.c
index 76d28cf..cd78f45 100644
--- a/lib/libdisk/change.c
+++ b/lib/libdisk/change.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: change.c,v 1.2 1995/04/29 01:55:18 phk Exp $
+ * $Id: change.c,v 1.3 1995/04/29 04:00:53 phk Exp $
*
*/
@@ -55,5 +55,5 @@ All_FreeBSD(struct disk *d)
goto again;
}
c=d->chunks;
- Create_Chunk(d,c->offset,c->size,freebsd,0,0);
+ Create_Chunk(d,c->offset,c->size,freebsd,0xa5,0);
}
diff --git a/lib/libdisk/disk.c b/lib/libdisk/disk.c
index f421224..b9363a0 100644
--- a/lib/libdisk/disk.c
+++ b/lib/libdisk/disk.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: disk.c,v 1.7 1995/04/30 07:30:43 phk Exp $
+ * $Id: disk.c,v 1.8 1995/04/30 11:04:13 phk Exp $
*
*/
@@ -99,10 +99,6 @@ Int_Open_Disk(char *name, u_long size)
if (Add_Chunk(d, 0, size, name,whole,0,0))
warn("Failed to add 'whole' chunk");
- if (ds.dss_slices[COMPATIBILITY_SLICE].ds_offset)
- if (Add_Chunk(d, 0, 1, "-",reserved,0,0))
- warn("Failed to add MBR chunk");
-
for(i=BASE_SLICE;i<ds.dss_nslices;i++) {
char sname[20];
chunk_e ce;
@@ -131,10 +127,7 @@ Int_Open_Disk(char *name, u_long size)
if (Add_Chunk(d,ds.dss_slices[i].ds_offset,
ds.dss_slices[i].ds_size, sname,ce,subtype,flags))
warn("failed to add chunk for slice %d",i - 1);
- if (ce == extended)
- if (Add_Chunk(d,ds.dss_slices[i].ds_offset,
- 1, "-",reserved, subtype, flags))
- warn("failed to add MBR chunk for slice %d",i - 1);
+
if (ds.dss_slices[i].ds_type != 0xa5)
continue;
{
@@ -288,9 +281,13 @@ Set_Boot_Mgr(struct disk *d, u_char *b)
{
if (d->bootmgr)
free(d->bootmgr);
- d->bootmgr = malloc(DOSPARTOFF);
- if(!d->bootmgr) err(1,"malloc failed");
- memcpy(d->bootmgr,b,DOSPARTOFF);
+ if (!b) {
+ d->bootmgr = 0;
+ } else {
+ d->bootmgr = malloc(DOSPARTOFF);
+ if(!d->bootmgr) err(1,"malloc failed");
+ memcpy(d->bootmgr,b,DOSPARTOFF);
+ }
}
void
diff --git a/lib/libdisk/write_disk.c b/lib/libdisk/write_disk.c
index d4d1c8a..c97727c 100644
--- a/lib/libdisk/write_disk.c
+++ b/lib/libdisk/write_disk.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: write_disk.c,v 1.3 1995/04/30 07:30:45 phk Exp $
+ * $Id: write_disk.c,v 1.4 1995/04/30 11:04:16 phk Exp $
*
*/
@@ -63,7 +63,7 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
continue;
}
dl->d_partitions[j].p_size = c2->size;
- dl->d_partitions[j].p_offset = c2->offset - c1->offset;
+ dl->d_partitions[j].p_offset = c2->offset;
dl->d_partitions[j].p_fstype = c2->subtype;
}
@@ -83,7 +83,7 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
dl->d_type = new->name[0] == 's' ? DTYPE_SCSI : DTYPE_ESDI;
dl->d_partitions[RAW_PART].p_size = c1->size;
- dl->d_partitions[RAW_PART].p_offset = 0;
+ dl->d_partitions[RAW_PART].p_offset = c1->offset;
dl->d_magic = DISKMAGIC;
dl->d_magic2 = DISKMAGIC;
@@ -112,7 +112,7 @@ Write_Disk(struct disk *d1)
int ret = 0;
char device[64];
u_char *mbr;
- struct dos_partition *dp;
+ struct dos_partition *dp,work[NDOSPART];
int s[4];
strcpy(device,"/dev/r");
@@ -127,18 +127,22 @@ Write_Disk(struct disk *d1)
memset(s,0,sizeof s);
mbr = read_block(fd,0);
dp = (struct dos_partition*) (mbr + DOSPARTOFF);
+ memcpy(work,dp,sizeof work);
+ dp = work;
+ free(mbr);
for (c1=d1->chunks->part; c1 ; c1 = c1->next) {
if (c1->type == unused) continue;
if (c1->type == reserved) continue;
if (!strcmp(c1->name,"X")) continue;
- if (c1->type == extended)
- ret += Write_Extended(fd, d1,old,c1);
- if (c1->type == freebsd)
- ret += Write_FreeBSD(fd, d1,old,c1);
j = c1->name[4] - '1';
if (j < 0 || j > 3)
continue;
s[j]++;
+ if (c1->type == extended)
+ ret += Write_Extended(fd, d1,old,c1);
+ if (c1->type == freebsd)
+ ret += Write_FreeBSD(fd, d1,old,c1);
+
dp[j].dp_start = c1->offset;
dp[j].dp_size = c1->size;
@@ -150,14 +154,17 @@ Write_Disk(struct disk *d1)
} else {
dp[j].dp_ssect = i % d1->bios_sect;
- i -= dp[j].dp_ssect;
+ i -= dp[j].dp_ssect++;
i /= d1->bios_sect;
- dp[j].dp_ssect++;
dp[j].dp_shd = i % d1->bios_hd;
i -= dp[j].dp_shd;
i /= d1->bios_hd;
dp[j].dp_scyl = i;
+ i -= dp[j].dp_scyl;
+ dp[j].dp_ssect |= i >> 2;
}
+ printf("S:%lu = (%x/%x/%x)",
+ c1->offset,dp[j].dp_scyl,dp[j].dp_shd,dp[j].dp_ssect);
i = c1->end;
if (i >= 1024*d1->bios_sect*d1->bios_hd) {
@@ -166,40 +173,37 @@ Write_Disk(struct disk *d1)
dp[j].dp_ecyl = 0xff;
} else {
dp[j].dp_esect = i % d1->bios_sect;
- i -= dp[j].dp_esect;
+ i -= dp[j].dp_esect++;
i /= d1->bios_sect;
- dp[j].dp_esect++;
dp[j].dp_ehd = i % d1->bios_hd;
i -= dp[j].dp_ehd;
i /= d1->bios_hd;
dp[j].dp_ecyl = i;
+ i -= dp[j].dp_ecyl;
+ dp[j].dp_esect |= i >> 2;
+
}
+ printf(" E:%lu = (%x/%x/%x)\n",
+ c1->end,dp[j].dp_ecyl,dp[j].dp_ehd,dp[j].dp_esect);
- switch (c1->type) {
- case freebsd:
- dp[j].dp_typ = 0xa5;
- break;
- case fat:
- dp[j].dp_typ = 1;
- break;
- case extended:
- dp[j].dp_typ = 5;
- break;
- case foo:
- dp[j].dp_typ = - c1->subtype;
- break;
- default:
- break;
- }
+ dp[j].dp_typ = c1->subtype;
}
for(i=0;i<NDOSPART;i++)
if (!s[i])
memset(dp+i,0,sizeof *dp);
+ mbr = read_block(fd,0);
+ if (d1->bootmgr)
+ memcpy(mbr,d1->bootmgr,DOSPARTOFF);
+ memcpy(mbr+DOSPARTOFF,dp,sizeof *dp * NDOSPART);
mbr[512-2] = 0x55;
mbr[512-1] = 0xaa;
write_block(fd,WHERE(0,d1),mbr);
+ i = 1;
+ i = ioctl(fd,DIOCSYNCSLICEINFO,&i);
+ if (i != 0)
+ warn("ioctl(DIOCSYNCSLICEINFO)");
close(fd);
return 0;
}
diff --git a/release/libdisk/Makefile b/release/libdisk/Makefile
index 0bd35b0..a1d03db 100644
--- a/release/libdisk/Makefile
+++ b/release/libdisk/Makefile
@@ -25,10 +25,11 @@ data.o:
file2c 'const unsigned char boot2[] = {' '};' \
< ${BOOTS}/boot2 >> tmp.c
cc ${CFLAGS} -o data.o -c tmp.c
+ rm -f tmp.c
tst01: ${OBJS}
#cc ${CFLAGS} -DREADLINE -static -o tst01 ${OBJS} -lreadline -ltermcap
cc ${CFLAGS} -static -o tst01 ${OBJS}
clean:
- rm -f *.o *.core tst01
+ rm -f *.o *.core tst01 tmp.c
diff --git a/release/libdisk/change.c b/release/libdisk/change.c
index 76d28cf..cd78f45 100644
--- a/release/libdisk/change.c
+++ b/release/libdisk/change.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: change.c,v 1.2 1995/04/29 01:55:18 phk Exp $
+ * $Id: change.c,v 1.3 1995/04/29 04:00:53 phk Exp $
*
*/
@@ -55,5 +55,5 @@ All_FreeBSD(struct disk *d)
goto again;
}
c=d->chunks;
- Create_Chunk(d,c->offset,c->size,freebsd,0,0);
+ Create_Chunk(d,c->offset,c->size,freebsd,0xa5,0);
}
diff --git a/release/libdisk/disk.c b/release/libdisk/disk.c
index f421224..b9363a0 100644
--- a/release/libdisk/disk.c
+++ b/release/libdisk/disk.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: disk.c,v 1.7 1995/04/30 07:30:43 phk Exp $
+ * $Id: disk.c,v 1.8 1995/04/30 11:04:13 phk Exp $
*
*/
@@ -99,10 +99,6 @@ Int_Open_Disk(char *name, u_long size)
if (Add_Chunk(d, 0, size, name,whole,0,0))
warn("Failed to add 'whole' chunk");
- if (ds.dss_slices[COMPATIBILITY_SLICE].ds_offset)
- if (Add_Chunk(d, 0, 1, "-",reserved,0,0))
- warn("Failed to add MBR chunk");
-
for(i=BASE_SLICE;i<ds.dss_nslices;i++) {
char sname[20];
chunk_e ce;
@@ -131,10 +127,7 @@ Int_Open_Disk(char *name, u_long size)
if (Add_Chunk(d,ds.dss_slices[i].ds_offset,
ds.dss_slices[i].ds_size, sname,ce,subtype,flags))
warn("failed to add chunk for slice %d",i - 1);
- if (ce == extended)
- if (Add_Chunk(d,ds.dss_slices[i].ds_offset,
- 1, "-",reserved, subtype, flags))
- warn("failed to add MBR chunk for slice %d",i - 1);
+
if (ds.dss_slices[i].ds_type != 0xa5)
continue;
{
@@ -288,9 +281,13 @@ Set_Boot_Mgr(struct disk *d, u_char *b)
{
if (d->bootmgr)
free(d->bootmgr);
- d->bootmgr = malloc(DOSPARTOFF);
- if(!d->bootmgr) err(1,"malloc failed");
- memcpy(d->bootmgr,b,DOSPARTOFF);
+ if (!b) {
+ d->bootmgr = 0;
+ } else {
+ d->bootmgr = malloc(DOSPARTOFF);
+ if(!d->bootmgr) err(1,"malloc failed");
+ memcpy(d->bootmgr,b,DOSPARTOFF);
+ }
}
void
diff --git a/release/libdisk/write_disk.c b/release/libdisk/write_disk.c
index d4d1c8a..c97727c 100644
--- a/release/libdisk/write_disk.c
+++ b/release/libdisk/write_disk.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: write_disk.c,v 1.3 1995/04/30 07:30:45 phk Exp $
+ * $Id: write_disk.c,v 1.4 1995/04/30 11:04:16 phk Exp $
*
*/
@@ -63,7 +63,7 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
continue;
}
dl->d_partitions[j].p_size = c2->size;
- dl->d_partitions[j].p_offset = c2->offset - c1->offset;
+ dl->d_partitions[j].p_offset = c2->offset;
dl->d_partitions[j].p_fstype = c2->subtype;
}
@@ -83,7 +83,7 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
dl->d_type = new->name[0] == 's' ? DTYPE_SCSI : DTYPE_ESDI;
dl->d_partitions[RAW_PART].p_size = c1->size;
- dl->d_partitions[RAW_PART].p_offset = 0;
+ dl->d_partitions[RAW_PART].p_offset = c1->offset;
dl->d_magic = DISKMAGIC;
dl->d_magic2 = DISKMAGIC;
@@ -112,7 +112,7 @@ Write_Disk(struct disk *d1)
int ret = 0;
char device[64];
u_char *mbr;
- struct dos_partition *dp;
+ struct dos_partition *dp,work[NDOSPART];
int s[4];
strcpy(device,"/dev/r");
@@ -127,18 +127,22 @@ Write_Disk(struct disk *d1)
memset(s,0,sizeof s);
mbr = read_block(fd,0);
dp = (struct dos_partition*) (mbr + DOSPARTOFF);
+ memcpy(work,dp,sizeof work);
+ dp = work;
+ free(mbr);
for (c1=d1->chunks->part; c1 ; c1 = c1->next) {
if (c1->type == unused) continue;
if (c1->type == reserved) continue;
if (!strcmp(c1->name,"X")) continue;
- if (c1->type == extended)
- ret += Write_Extended(fd, d1,old,c1);
- if (c1->type == freebsd)
- ret += Write_FreeBSD(fd, d1,old,c1);
j = c1->name[4] - '1';
if (j < 0 || j > 3)
continue;
s[j]++;
+ if (c1->type == extended)
+ ret += Write_Extended(fd, d1,old,c1);
+ if (c1->type == freebsd)
+ ret += Write_FreeBSD(fd, d1,old,c1);
+
dp[j].dp_start = c1->offset;
dp[j].dp_size = c1->size;
@@ -150,14 +154,17 @@ Write_Disk(struct disk *d1)
} else {
dp[j].dp_ssect = i % d1->bios_sect;
- i -= dp[j].dp_ssect;
+ i -= dp[j].dp_ssect++;
i /= d1->bios_sect;
- dp[j].dp_ssect++;
dp[j].dp_shd = i % d1->bios_hd;
i -= dp[j].dp_shd;
i /= d1->bios_hd;
dp[j].dp_scyl = i;
+ i -= dp[j].dp_scyl;
+ dp[j].dp_ssect |= i >> 2;
}
+ printf("S:%lu = (%x/%x/%x)",
+ c1->offset,dp[j].dp_scyl,dp[j].dp_shd,dp[j].dp_ssect);
i = c1->end;
if (i >= 1024*d1->bios_sect*d1->bios_hd) {
@@ -166,40 +173,37 @@ Write_Disk(struct disk *d1)
dp[j].dp_ecyl = 0xff;
} else {
dp[j].dp_esect = i % d1->bios_sect;
- i -= dp[j].dp_esect;
+ i -= dp[j].dp_esect++;
i /= d1->bios_sect;
- dp[j].dp_esect++;
dp[j].dp_ehd = i % d1->bios_hd;
i -= dp[j].dp_ehd;
i /= d1->bios_hd;
dp[j].dp_ecyl = i;
+ i -= dp[j].dp_ecyl;
+ dp[j].dp_esect |= i >> 2;
+
}
+ printf(" E:%lu = (%x/%x/%x)\n",
+ c1->end,dp[j].dp_ecyl,dp[j].dp_ehd,dp[j].dp_esect);
- switch (c1->type) {
- case freebsd:
- dp[j].dp_typ = 0xa5;
- break;
- case fat:
- dp[j].dp_typ = 1;
- break;
- case extended:
- dp[j].dp_typ = 5;
- break;
- case foo:
- dp[j].dp_typ = - c1->subtype;
- break;
- default:
- break;
- }
+ dp[j].dp_typ = c1->subtype;
}
for(i=0;i<NDOSPART;i++)
if (!s[i])
memset(dp+i,0,sizeof *dp);
+ mbr = read_block(fd,0);
+ if (d1->bootmgr)
+ memcpy(mbr,d1->bootmgr,DOSPARTOFF);
+ memcpy(mbr+DOSPARTOFF,dp,sizeof *dp * NDOSPART);
mbr[512-2] = 0x55;
mbr[512-1] = 0xaa;
write_block(fd,WHERE(0,d1),mbr);
+ i = 1;
+ i = ioctl(fd,DIOCSYNCSLICEINFO,&i);
+ if (i != 0)
+ warn("ioctl(DIOCSYNCSLICEINFO)");
close(fd);
return 0;
}
OpenPOWER on IntegriCloud