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.
This commit is contained in:
Poul-Henning Kamp 1995-05-01 04:05:27 +00:00
parent ee1cbe818e
commit 20c9844ca0
6 changed files with 136 additions and 38 deletions

View File

@ -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;

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <err.h>
#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++)

View File

@ -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);

View File

@ -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;

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <err.h>
#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++)

View File

@ -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);