Use 0xff for CHS when past 1024 cyls.

Fix (hopefully) a bug Gary found.
This commit is contained in:
Poul-Henning Kamp 1995-04-30 07:30:45 +00:00
parent 98fc07cacb
commit e6b172ee57
4 changed files with 94 additions and 56 deletions

View File

@ -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.5 1995/04/29 07:21:11 phk Exp $
* $Id: disk.c,v 1.6 1995/04/30 06:09:26 phk Exp $
*
*/
@ -131,21 +131,28 @@ Int_Open_Disk(char *name, u_long size)
warn("failed to add MBR chunk for slice %d",i - 1);
if (ds.dss_slices[i].ds_type == 0xa5) {
struct disklabel *dl;
int j;
dl = read_disklabel(fd,
ds.dss_slices[i].ds_offset + LABELSECTOR);
if(dl) {
char pname[20];
int j;
u_long l;
if (dl->d_partitions[RAW_PART].p_offset == 0 &&
dl->d_partitions[RAW_PART].p_size ==
ds.dss_slices[i].ds_size)
l = ds.dss_slices[i].ds_offset;
else
l = 0;
for(j=0; j < dl->d_npartitions; j++) {
sprintf(pname,"%s%c",sname,j+'a');
if (j == 2 || j == 3)
if (j == RAW_PART || j == 3)
continue;
if (!dl->d_partitions[j].p_size)
continue;
if (Add_Chunk(d,
dl->d_partitions[j].p_offset +
ds.dss_slices[i].ds_offset,
l,
dl->d_partitions[j].p_size,
pname,part,0,0))
warn(
@ -156,11 +163,11 @@ Int_Open_Disk(char *name, u_long size)
if (dl->d_partitions[3].p_size)
Add_Chunk(d,
dl->d_partitions[3].p_offset +
ds.dss_slices[i].ds_offset,
l,
dl->d_partitions[3].p_size,
pname,part,0,0);
free(dl);
}
free(dl);
}
}
close(fd);

View File

@ -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.1 1995/04/29 07:21:14 phk Exp $
* $Id: write_disk.c,v 1.2 1995/04/30 06:09:29 phk Exp $
*
*/
@ -109,7 +109,7 @@ Write_Disk(struct disk *d1)
struct chunk *c1;
int ret = 0;
char device[64];
void *mbr;
u_char *mbr;
struct dos_partition *dp;
int s[4];
@ -141,28 +141,38 @@ Write_Disk(struct disk *d1)
dp[j].dp_size = c1->size;
i = c1->offset;
if (i >= 1024*d1->bios_sect*d1->bios_hd)
i = 1024*d1->bios_sect*d1->bios_hd - 1;
dp[j].dp_ssect = i % d1->bios_sect;
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;
if (i >= 1024*d1->bios_sect*d1->bios_hd) {
dp[j].dp_ssect = 0xff;
dp[j].dp_shd = 0xff;
dp[j].dp_scyl = 0xff;
} else {
dp[j].dp_ssect = i % d1->bios_sect;
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 = c1->end;
if (i >= 1024*d1->bios_sect*d1->bios_hd)
i = 1024*d1->bios_sect*d1->bios_hd - 1;
dp[j].dp_esect = i % d1->bios_sect;
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;
if (i >= 1024*d1->bios_sect*d1->bios_hd) {
dp[j].dp_esect = 0xff;
dp[j].dp_ehd = 0xff;
dp[j].dp_ecyl = 0xff;
} else {
dp[j].dp_esect = i % d1->bios_sect;
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;
}
switch (c1->type) {
case freebsd:
dp[j].dp_typ = 0xa5;
@ -182,6 +192,8 @@ Write_Disk(struct disk *d1)
if (!s[i])
memset(dp+i,0,sizeof *dp);
mbr[512-2] = 0x55;
mbr[512-1] = 0xaa;
write_block(fd,WHERE(0,d1),mbr);
close(fd);

View File

@ -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.5 1995/04/29 07:21:11 phk Exp $
* $Id: disk.c,v 1.6 1995/04/30 06:09:26 phk Exp $
*
*/
@ -131,21 +131,28 @@ Int_Open_Disk(char *name, u_long size)
warn("failed to add MBR chunk for slice %d",i - 1);
if (ds.dss_slices[i].ds_type == 0xa5) {
struct disklabel *dl;
int j;
dl = read_disklabel(fd,
ds.dss_slices[i].ds_offset + LABELSECTOR);
if(dl) {
char pname[20];
int j;
u_long l;
if (dl->d_partitions[RAW_PART].p_offset == 0 &&
dl->d_partitions[RAW_PART].p_size ==
ds.dss_slices[i].ds_size)
l = ds.dss_slices[i].ds_offset;
else
l = 0;
for(j=0; j < dl->d_npartitions; j++) {
sprintf(pname,"%s%c",sname,j+'a');
if (j == 2 || j == 3)
if (j == RAW_PART || j == 3)
continue;
if (!dl->d_partitions[j].p_size)
continue;
if (Add_Chunk(d,
dl->d_partitions[j].p_offset +
ds.dss_slices[i].ds_offset,
l,
dl->d_partitions[j].p_size,
pname,part,0,0))
warn(
@ -156,11 +163,11 @@ Int_Open_Disk(char *name, u_long size)
if (dl->d_partitions[3].p_size)
Add_Chunk(d,
dl->d_partitions[3].p_offset +
ds.dss_slices[i].ds_offset,
l,
dl->d_partitions[3].p_size,
pname,part,0,0);
free(dl);
}
free(dl);
}
}
close(fd);

View File

@ -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.1 1995/04/29 07:21:14 phk Exp $
* $Id: write_disk.c,v 1.2 1995/04/30 06:09:29 phk Exp $
*
*/
@ -109,7 +109,7 @@ Write_Disk(struct disk *d1)
struct chunk *c1;
int ret = 0;
char device[64];
void *mbr;
u_char *mbr;
struct dos_partition *dp;
int s[4];
@ -141,28 +141,38 @@ Write_Disk(struct disk *d1)
dp[j].dp_size = c1->size;
i = c1->offset;
if (i >= 1024*d1->bios_sect*d1->bios_hd)
i = 1024*d1->bios_sect*d1->bios_hd - 1;
dp[j].dp_ssect = i % d1->bios_sect;
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;
if (i >= 1024*d1->bios_sect*d1->bios_hd) {
dp[j].dp_ssect = 0xff;
dp[j].dp_shd = 0xff;
dp[j].dp_scyl = 0xff;
} else {
dp[j].dp_ssect = i % d1->bios_sect;
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 = c1->end;
if (i >= 1024*d1->bios_sect*d1->bios_hd)
i = 1024*d1->bios_sect*d1->bios_hd - 1;
dp[j].dp_esect = i % d1->bios_sect;
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;
if (i >= 1024*d1->bios_sect*d1->bios_hd) {
dp[j].dp_esect = 0xff;
dp[j].dp_ehd = 0xff;
dp[j].dp_ecyl = 0xff;
} else {
dp[j].dp_esect = i % d1->bios_sect;
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;
}
switch (c1->type) {
case freebsd:
dp[j].dp_typ = 0xa5;
@ -182,6 +192,8 @@ Write_Disk(struct disk *d1)
if (!s[i])
memset(dp+i,0,sizeof *dp);
mbr[512-2] = 0x55;
mbr[512-1] = 0xaa;
write_block(fd,WHERE(0,d1),mbr);
close(fd);