From 20c9844ca086de197a688babdd6d24a1e040c3d2 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Mon, 1 May 1995 04:05:27 +0000 Subject: [PATCH] start CHS is 0xff,0xff,0xff if past 1024. end CHS is 1023,bios_hd,bios_sect if past 1024. This way we can find bios the geometry again. Added a primitive "scan" to tst01. --- lib/libdisk/create_chunk.c | 4 ++- lib/libdisk/tst01.c | 54 +++++++++++++++++++++++++++++++++- lib/libdisk/write_disk.c | 29 ++++++++---------- release/libdisk/create_chunk.c | 4 ++- release/libdisk/tst01.c | 54 +++++++++++++++++++++++++++++++++- release/libdisk/write_disk.c | 29 ++++++++---------- 6 files changed, 136 insertions(+), 38 deletions(-) diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c index 0bb6c08b1ff..a2027e2e7cb 100644 --- a/lib/libdisk/create_chunk.c +++ b/lib/libdisk/create_chunk.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: create_chunk.c,v 1.4 1995/04/30 06:09:25 phk Exp $ + * $Id: create_chunk.c,v 1.5 1995/04/30 11:04:12 phk Exp $ * */ @@ -129,6 +129,8 @@ Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, int subty { int i; + if (type == freebsd) + subtype = 0xa5; i = Add_Chunk(d,offset,size,"X",type,subtype,flags); Fixup_Names(d); return i; diff --git a/lib/libdisk/tst01.c b/lib/libdisk/tst01.c index 2e8fe535e79..68ecb3dbbd3 100644 --- a/lib/libdisk/tst01.c +++ b/lib/libdisk/tst01.c @@ -6,13 +6,14 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: tst01.c,v 1.6 1995/04/30 06:09:28 phk Exp $ + * $Id: tst01.c,v 1.7 1995/04/30 11:04:16 phk Exp $ * */ #include #include #include +#include #include #include #ifdef READLINE @@ -73,6 +74,52 @@ u_char bteasy17[] = { 0,85,170 }; +int +scan_block(int fd, daddr_t block) +{ + u_char foo[512]; + + if (-1 == lseek(fd,block * 512,SEEK_SET)) + err(1,"lseek"); + if (512 != read(fd,foo, 512)) + return 1; + return 0; +} + +void +Scan_Disk(struct disk *d) +{ + char device[64]; + u_long l; + int i,j,fd; + + strcpy(device,"/dev/r"); + strcat(device,d->name); + + fd = open(device,O_RDWR); + if (fd < 0) { + warn("open(%s) failed",device); + return; + } + for(i=-1,l=0;;l++) { + j = scan_block(fd,l); + if (j != i) { + if (i == -1) { + printf("%c: %lu.",j ? 'B' : 'G', l); + fflush(stdout); + } else if (i == 0) { + printf(".%lu\nB: %lu.",l-1,l); + fflush(stdout); + } else { + printf(".%lu\nG: %lu.",l-1,l); + fflush(stdout); + } + i = j; + } + } + close(fd); +} + int main(int argc, char **argv) { @@ -189,6 +236,10 @@ main(int argc, char **argv) d = db; continue; } + if (!strcasecmp(*cmds,"scan")) { + Scan_Disk(d); + continue; + } if (!strcasecmp(*cmds,"bteasy")) { Set_Boot_Mgr(d,bteasy17); continue; @@ -225,6 +276,7 @@ main(int argc, char **argv) printf("\tphys cyl hd sect\n"); printf("\tquit\n"); printf("\tread [disk]\n"); + printf("\tscan\n"); printf("\twrite\n"); printf("\nENUM:\n\t"); for(i=0;chunk_n[i];i++) diff --git a/lib/libdisk/write_disk.c b/lib/libdisk/write_disk.c index c97727c8cad..818076a3ca9 100644 --- a/lib/libdisk/write_disk.c +++ b/lib/libdisk/write_disk.c @@ -151,7 +151,6 @@ Write_Disk(struct disk *d1) 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++; @@ -163,26 +162,22 @@ Write_Disk(struct disk *d1) 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) { - 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_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; - - } + 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; + if (i>1023) i = 1023; + 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); diff --git a/release/libdisk/create_chunk.c b/release/libdisk/create_chunk.c index 0bb6c08b1ff..a2027e2e7cb 100644 --- a/release/libdisk/create_chunk.c +++ b/release/libdisk/create_chunk.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: create_chunk.c,v 1.4 1995/04/30 06:09:25 phk Exp $ + * $Id: create_chunk.c,v 1.5 1995/04/30 11:04:12 phk Exp $ * */ @@ -129,6 +129,8 @@ Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, int subty { int i; + if (type == freebsd) + subtype = 0xa5; i = Add_Chunk(d,offset,size,"X",type,subtype,flags); Fixup_Names(d); return i; diff --git a/release/libdisk/tst01.c b/release/libdisk/tst01.c index 2e8fe535e79..68ecb3dbbd3 100644 --- a/release/libdisk/tst01.c +++ b/release/libdisk/tst01.c @@ -6,13 +6,14 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: tst01.c,v 1.6 1995/04/30 06:09:28 phk Exp $ + * $Id: tst01.c,v 1.7 1995/04/30 11:04:16 phk Exp $ * */ #include #include #include +#include #include #include #ifdef READLINE @@ -73,6 +74,52 @@ u_char bteasy17[] = { 0,85,170 }; +int +scan_block(int fd, daddr_t block) +{ + u_char foo[512]; + + if (-1 == lseek(fd,block * 512,SEEK_SET)) + err(1,"lseek"); + if (512 != read(fd,foo, 512)) + return 1; + return 0; +} + +void +Scan_Disk(struct disk *d) +{ + char device[64]; + u_long l; + int i,j,fd; + + strcpy(device,"/dev/r"); + strcat(device,d->name); + + fd = open(device,O_RDWR); + if (fd < 0) { + warn("open(%s) failed",device); + return; + } + for(i=-1,l=0;;l++) { + j = scan_block(fd,l); + if (j != i) { + if (i == -1) { + printf("%c: %lu.",j ? 'B' : 'G', l); + fflush(stdout); + } else if (i == 0) { + printf(".%lu\nB: %lu.",l-1,l); + fflush(stdout); + } else { + printf(".%lu\nG: %lu.",l-1,l); + fflush(stdout); + } + i = j; + } + } + close(fd); +} + int main(int argc, char **argv) { @@ -189,6 +236,10 @@ main(int argc, char **argv) d = db; continue; } + if (!strcasecmp(*cmds,"scan")) { + Scan_Disk(d); + continue; + } if (!strcasecmp(*cmds,"bteasy")) { Set_Boot_Mgr(d,bteasy17); continue; @@ -225,6 +276,7 @@ main(int argc, char **argv) printf("\tphys cyl hd sect\n"); printf("\tquit\n"); printf("\tread [disk]\n"); + printf("\tscan\n"); printf("\twrite\n"); printf("\nENUM:\n\t"); for(i=0;chunk_n[i];i++) diff --git a/release/libdisk/write_disk.c b/release/libdisk/write_disk.c index c97727c8cad..818076a3ca9 100644 --- a/release/libdisk/write_disk.c +++ b/release/libdisk/write_disk.c @@ -151,7 +151,6 @@ Write_Disk(struct disk *d1) 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++; @@ -163,26 +162,22 @@ Write_Disk(struct disk *d1) 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) { - 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_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; - - } + 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; + if (i>1023) i = 1023; + 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);