New prototype for test_BSD()
This commit is contained in:
parent
eb48734418
commit
95b4788896
1 changed files with 62 additions and 67 deletions
129
src/bsd.c
129
src/bsd.c
|
@ -33,7 +33,7 @@
|
||||||
#include "bsd.h"
|
#include "bsd.h"
|
||||||
#include "intrf.h"
|
#include "intrf.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
static int test_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t *partition,const int verbose, const int dump_ind, const unsigned int max_partitions);
|
static int test_BSD(disk_t *disk_car, const struct disklabel*bsd_header, const partition_t *partition, const int verbose, const int dump_ind, const unsigned int max_partitions);
|
||||||
|
|
||||||
int check_BSD(disk_t *disk_car,partition_t *partition,const int verbose, const unsigned int max_partitions)
|
int check_BSD(disk_t *disk_car,partition_t *partition,const int verbose, const unsigned int max_partitions)
|
||||||
{
|
{
|
||||||
|
@ -54,82 +54,75 @@ int check_BSD(disk_t *disk_car,partition_t *partition,const int verbose, const u
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t *partition,const int verbose, const int dump_ind, const unsigned int max_partitions)
|
static int test_BSD(disk_t *disk_car, const struct disklabel*bsd_header, const partition_t *partition,const int verbose, const int dump_ind, const unsigned int max_partitions)
|
||||||
{
|
{
|
||||||
if((le32(bsd_header->d_magic) == DISKMAGIC)&&
|
unsigned int i;
|
||||||
(le32(bsd_header->d_magic2)==DISKMAGIC))
|
const uint16_t* cp;
|
||||||
|
uint16_t crc;
|
||||||
|
if(le32(bsd_header->d_magic) != DISKMAGIC || le32(bsd_header->d_magic2)!=DISKMAGIC)
|
||||||
|
return 0;
|
||||||
|
if(verbose)
|
||||||
|
log_info("\nBSD offset %lu, nbr_part %u, CHS=(%u,%u,%u) ",
|
||||||
|
(long unsigned)(partition->part_offset/disk_car->sector_size),
|
||||||
|
(unsigned int)le16(bsd_header->d_npartitions),
|
||||||
|
(unsigned int)le32(bsd_header->d_ncylinders),
|
||||||
|
(unsigned int)le32(bsd_header->d_ntracks),
|
||||||
|
(unsigned int)le32(bsd_header->d_nsectors));
|
||||||
|
if(le16(bsd_header->d_npartitions) > max_partitions)
|
||||||
|
return 1;
|
||||||
|
crc=0;
|
||||||
|
for(cp=(const uint16_t*)bsd_header;
|
||||||
|
cp<(const uint16_t*)&bsd_header->d_partitions[le16(bsd_header->d_npartitions)];cp++)
|
||||||
|
crc^=*cp;
|
||||||
|
if(crc==0)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
if(verbose>0)
|
||||||
const uint16_t* cp;
|
{
|
||||||
uint16_t crc;
|
log_info("CRC Ok\n");
|
||||||
if(verbose)
|
}
|
||||||
log_info("\nBSD offset %lu, nbr_part %u, CHS=(%u,%u,%u) ",
|
}
|
||||||
(long unsigned)(partition->part_offset/disk_car->sector_size),
|
else
|
||||||
(unsigned int)le16(bsd_header->d_npartitions),
|
log_error("Bad CRC! CRC must be xor'd by %04X\n",crc);
|
||||||
(unsigned int)le32(bsd_header->d_ncylinders),
|
for(i=0;i<le16(bsd_header->d_npartitions);i++)
|
||||||
(unsigned int)le32(bsd_header->d_ntracks),
|
{
|
||||||
(unsigned int)le32(bsd_header->d_nsectors));
|
if(bsd_header->d_partitions[i].p_fstype>0)
|
||||||
if(le16(bsd_header->d_npartitions) > max_partitions)
|
|
||||||
return 1;
|
|
||||||
crc=0;
|
|
||||||
for(cp=(const uint16_t*)bsd_header;
|
|
||||||
cp<(const uint16_t*)&bsd_header->d_partitions[le16(bsd_header->d_npartitions)];cp++)
|
|
||||||
crc^=*cp;
|
|
||||||
if(crc==0)
|
|
||||||
{
|
{
|
||||||
if(verbose>0)
|
if(verbose>0)
|
||||||
{
|
{
|
||||||
log_info("CRC Ok\n");
|
/* UFS UFS2 SWAP */
|
||||||
}
|
log_info("BSD %c: ", 'a'+i);
|
||||||
}
|
switch(bsd_header->d_partitions[i].p_fstype)
|
||||||
else
|
|
||||||
log_error("Bad CRC! CRC must be xor'd by %04X\n",crc);
|
|
||||||
for(i=0;i<le16(bsd_header->d_npartitions);i++)
|
|
||||||
{
|
|
||||||
if(bsd_header->d_partitions[i].p_fstype>0)
|
|
||||||
{
|
|
||||||
if(verbose>0)
|
|
||||||
{
|
{
|
||||||
/* UFS UFS2 SWAP */
|
case TST_FS_SWAP:
|
||||||
log_info("BSD %c: ", 'a'+i);
|
log_info("swap");
|
||||||
switch(bsd_header->d_partitions[i].p_fstype)
|
break;
|
||||||
{
|
case TST_FS_BSDFFS:
|
||||||
case TST_FS_SWAP:
|
log_info("4.2BSD fast filesystem");
|
||||||
log_info("swap");
|
break;
|
||||||
break;
|
case TST_FS_BSDLFS:
|
||||||
case TST_FS_BSDFFS:
|
log_info("4.4BSD log-structured filesystem");
|
||||||
log_info("4.2BSD fast filesystem");
|
break;
|
||||||
break;
|
default:
|
||||||
case TST_FS_BSDLFS:
|
log_info("type %02X", bsd_header->d_partitions[i].p_fstype);
|
||||||
log_info("4.4BSD log-structured filesystem");
|
break;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
log_info("type %02X", bsd_header->d_partitions[i].p_fstype);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
log_info(", offset %9u, size %9u ",
|
|
||||||
(unsigned int)le32(bsd_header->d_partitions[i].p_offset),
|
|
||||||
(unsigned int)le32(bsd_header->d_partitions[i].p_size));
|
|
||||||
log_CHS_from_LBA(disk_car,le32(bsd_header->d_partitions[i].p_offset));
|
|
||||||
log_info(" -> ");
|
|
||||||
log_CHS_from_LBA(disk_car,le32(bsd_header->d_partitions[i].p_offset)+le32(bsd_header->d_partitions[i].p_size)-1);
|
|
||||||
log_info("\n");
|
|
||||||
}
|
}
|
||||||
|
log_info(", offset %9u, size %9u ",
|
||||||
|
(unsigned int)le32(bsd_header->d_partitions[i].p_offset),
|
||||||
|
(unsigned int)le32(bsd_header->d_partitions[i].p_size));
|
||||||
|
log_CHS_from_LBA(disk_car,le32(bsd_header->d_partitions[i].p_offset));
|
||||||
|
log_info(" -> ");
|
||||||
|
log_CHS_from_LBA(disk_car,le32(bsd_header->d_partitions[i].p_offset)+le32(bsd_header->d_partitions[i].p_size)-1);
|
||||||
|
log_info("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(crc)
|
|
||||||
return 1;
|
|
||||||
if(max_partitions==BSD_MAXPARTITIONS)
|
|
||||||
partition->upart_type=UP_FREEBSD;
|
|
||||||
else
|
|
||||||
partition->upart_type=UP_OPENBSD;
|
|
||||||
if(dump_ind!=0)
|
|
||||||
{
|
|
||||||
dump_log(bsd_header,DEFAULT_SECTOR_SIZE);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
return 1;
|
if(crc)
|
||||||
|
return 1;
|
||||||
|
if(dump_ind!=0)
|
||||||
|
{
|
||||||
|
dump_log(bsd_header,DEFAULT_SECTOR_SIZE);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int recover_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t *partition,const int verbose, const int dump_ind)
|
int recover_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t *partition,const int verbose, const int dump_ind)
|
||||||
|
@ -138,6 +131,7 @@ int recover_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t
|
||||||
int i_max_p_offset=-1;
|
int i_max_p_offset=-1;
|
||||||
if(test_BSD(disk_car,bsd_header,partition,verbose,dump_ind,BSD_MAXPARTITIONS)==0)
|
if(test_BSD(disk_car,bsd_header,partition,verbose,dump_ind,BSD_MAXPARTITIONS)==0)
|
||||||
{
|
{
|
||||||
|
partition->upart_type=UP_FREEBSD;
|
||||||
for(i=0;i<BSD_MAXPARTITIONS;i++)
|
for(i=0;i<BSD_MAXPARTITIONS;i++)
|
||||||
{
|
{
|
||||||
if(bsd_header->d_partitions[i].p_fstype>0)
|
if(bsd_header->d_partitions[i].p_fstype>0)
|
||||||
|
@ -158,6 +152,7 @@ int recover_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t
|
||||||
}
|
}
|
||||||
if(test_BSD(disk_car,bsd_header,partition,verbose,dump_ind,OPENBSD_MAXPARTITIONS)==0)
|
if(test_BSD(disk_car,bsd_header,partition,verbose,dump_ind,OPENBSD_MAXPARTITIONS)==0)
|
||||||
{
|
{
|
||||||
|
partition->upart_type=UP_OPENBSD;
|
||||||
for(i=0;i<OPENBSD_MAXPARTITIONS;i++)
|
for(i=0;i<OPENBSD_MAXPARTITIONS;i++)
|
||||||
{
|
{
|
||||||
if(bsd_header->d_partitions[i].p_fstype>0)
|
if(bsd_header->d_partitions[i].p_fstype>0)
|
||||||
|
|
Loading…
Reference in a new issue