Fix several BDECFLAGS warnings. Also, actually use the 'verbose' parameter

for lsdev when printing out slice information.  Now, you only get the
sizes and LBA's of slices if you use 'lsdev -v'.
This commit is contained in:
John Baldwin 2000-08-03 09:09:49 +00:00
parent 13ba80d4ce
commit c2fa9f3e89
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=64186

View File

@ -104,14 +104,15 @@ static int bd_read(struct open_disk *od, daddr_t dblk, int blks,
static int bd_int13probe(struct bdinfo *bd); static int bd_int13probe(struct bdinfo *bd);
static void bd_printslice(struct open_disk *od, struct dos_partition *dp, static void bd_printslice(struct open_disk *od, struct dos_partition *dp,
char *prefix); char *prefix, int verbose);
static void bd_printbsdslice(struct open_disk *od, int offset, char *prefix); static void bd_printbsdslice(struct open_disk *od, daddr_t offset,
char *prefix, int verbose);
static int bd_init(void); static int bd_init(void);
static int bd_strategy(void *devdata, int flag, daddr_t dblk, static int bd_strategy(void *devdata, int flag, daddr_t dblk,
size_t size, void *buf, size_t *rsize); size_t size, char *buf, size_t *rsize);
static int bd_realstrategy(void *devdata, int flag, daddr_t dblk, static int bd_realstrategy(void *devdata, int flag, daddr_t dblk,
size_t size, void *buf, size_t *rsize); size_t size, char *buf, size_t *rsize);
static int bd_open(struct open_file *f, ...); static int bd_open(struct open_file *f, ...);
static int bd_close(struct open_file *f); static int bd_close(struct open_file *f);
static void bd_print(int verbose); static void bd_print(int verbose);
@ -124,7 +125,8 @@ struct devsw biosdisk = {
bd_open, bd_open,
bd_close, bd_close,
noioctl, noioctl,
bd_print bd_print,
NULL
}; };
static int bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev); static int bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev);
@ -203,7 +205,7 @@ bd_int13probe(struct bdinfo *bd)
v86int(); v86int();
if (!(v86.efl & 0x1) && /* carry clear */ if (!(v86.efl & 0x1) && /* carry clear */
((v86.edx & 0xff) > (bd->bd_unit & 0x7f))) { /* unit # OK */ ((v86.edx & 0xff) > ((unsigned)bd->bd_unit & 0x7f))) { /* unit # OK */
bd->bd_flags |= BD_MODEINT13; bd->bd_flags |= BD_MODEINT13;
bd->bd_type = v86.ebx & 0xff; bd->bd_type = v86.ebx & 0xff;
@ -216,7 +218,7 @@ bd_int13probe(struct bdinfo *bd)
((v86.ebx & 0xffff) == 0xaa55) && /* signature */ ((v86.ebx & 0xffff) == 0xaa55) && /* signature */
(v86.ecx & 0x1)) { /* packets mode ok */ (v86.ecx & 0x1)) { /* packets mode ok */
bd->bd_flags |= BD_MODEEDD1; bd->bd_flags |= BD_MODEEDD1;
if(v86.eax & 0xff00 > 0x300) if((v86.eax & 0xff00) > 0x300)
bd->bd_flags |= BD_MODEEDD3; bd->bd_flags |= BD_MODEEDD3;
} }
return(1); return(1);
@ -252,16 +254,16 @@ bd_print(int verbose)
if (od->od_flags & BD_PARTTABOK) { if (od->od_flags & BD_PARTTABOK) {
dptr = &od->od_slicetab[0]; dptr = &od->od_slicetab[0];
/* Check for a "truly dedicated" disk */ /* Check for a "dedicated" disk */
if ((dptr[3].dp_typ == DOSPTYP_386BSD) && if ((dptr[3].dp_typ == DOSPTYP_386BSD) &&
(dptr[3].dp_start == 0) && (dptr[3].dp_start == 0) &&
(dptr[3].dp_size == 50000)) { (dptr[3].dp_size == 50000)) {
sprintf(line, " disk%d", i); sprintf(line, " disk%d", i);
bd_printbsdslice(od, 0, line); bd_printbsdslice(od, 0, line, verbose);
} else { } else {
for (j = 0; j < od->od_nslices; j++) { for (j = 0; j < od->od_nslices; j++) {
sprintf(line, " disk%ds%d", i, j + 1); sprintf(line, " disk%ds%d", i, j + 1);
bd_printslice(od, &dptr[j], line); bd_printslice(od, &dptr[j], line, verbose);
} }
} }
} }
@ -271,66 +273,91 @@ bd_print(int verbose)
} }
/* /*
* Print information about slices on a disk * Print information about slices on a disk. For the size calculations we
* assume a 512 byte sector.
*/ */
static void static void
bd_printslice(struct open_disk *od, struct dos_partition *dp, char *prefix) bd_printslice(struct open_disk *od, struct dos_partition *dp, char *prefix,
int verbose)
{ {
char line[80]; char line[80];
switch (dp->dp_typ) { switch (dp->dp_typ) {
case DOSPTYP_386BSD: case DOSPTYP_386BSD:
bd_printbsdslice(od, dp->dp_start, prefix); bd_printbsdslice(od, (daddr_t)dp->dp_start, prefix, verbose);
return; return;
case DOSPTYP_LINSWP: case DOSPTYP_LINSWP:
sprintf(line, "%s: Linux swap %.6dMB (%d - %d)\n", prefix, if (verbose)
dp->dp_size / 2048, /* 512-byte sector assumption */ sprintf(line, "%s: Linux swap %.6dMB (%d - %d)\n",
dp->dp_start, dp->dp_start + dp->dp_size); prefix, dp->dp_size / 2048,
dp->dp_start, dp->dp_start + dp->dp_size);
else
sprintf(line, "%s: Linux swap\n", prefix);
break; break;
case DOSPTYP_LINUX: case DOSPTYP_LINUX:
/* /*
* XXX * XXX
* read the superblock to confirm this is an ext2fs partition? * read the superblock to confirm this is an ext2fs partition?
*/ */
sprintf(line, "%s: ext2fs %.6dMB (%d - %d)\n", prefix, if (verbose)
dp->dp_size / 2048, /* 512-byte sector assumption */ sprintf(line, "%s: ext2fs %.6dMB (%d - %d)\n", prefix,
dp->dp_start, dp->dp_start + dp->dp_size); dp->dp_size / 2048, dp->dp_start,
dp->dp_start + dp->dp_size);
else
sprintf(line, "%s: ext2fs\n", prefix);
break; break;
case 0x00: /* unused partition */ case 0x00: /* unused partition */
case DOSPTYP_EXT: case DOSPTYP_EXT:
return; return;
case 0x01: case 0x01:
sprintf(line, "%s: FAT-12 %.6dMB (%d - %d)\n", prefix, if (verbose)
dp->dp_size / 2048, /* 512-byte sector assumption */ sprintf(line, "%s: FAT-12 %.6dMB (%d - %d)\n", prefix,
dp->dp_start, dp->dp_start + dp->dp_size); dp->dp_size / 2048, dp->dp_start,
dp->dp_start + dp->dp_size);
else
sprintf(line, "%s: FAT-12\n", prefix);
break; break;
case 0x04: case 0x04:
case 0x06: case 0x06:
case 0x0e: case 0x0e:
sprintf(line, "%s: FAT-16 %.6dMB (%d - %d)\n", prefix, if (verbose)
dp->dp_size / 2048, /* 512-byte sector assumption */ sprintf(line, "%s: FAT-16 %.6dMB (%d - %d)\n", prefix,
dp->dp_start, dp->dp_start + dp->dp_size); dp->dp_size / 2048, dp->dp_start,
dp->dp_start + dp->dp_size);
else
sprintf(line, "%s: FAT-16\n", prefix);
break; break;
case 0x0b: case 0x0b:
case 0x0c: case 0x0c:
sprintf(line, "%s: FAT-32 %.6dMB (%d - %d)\n", prefix, if (verbose)
dp->dp_size / 2048, /* 512-byte sector assumption */ sprintf(line, "%s: FAT-32 %.6dMB (%d - %d)\n", prefix,
dp->dp_start, dp->dp_start + dp->dp_size); dp->dp_size / 2048, dp->dp_start,
dp->dp_start + dp->dp_size);
else
sprintf(line, "%s: FAT-32\n", prefix);
break; break;
default: default:
sprintf(line, "%s: Unknown fs: 0x%x %.6dMB (%d - %d)\n", if (verbose)
prefix, dp->dp_typ, sprintf(line, "%s: Unknown fs: 0x%x %.6dMB (%d - %d)\n",
dp->dp_size / 2048, /* 512-byte sector assumption */ prefix, dp->dp_typ, dp->dp_size / 2048,
dp->dp_start, dp->dp_start + dp->dp_size); dp->dp_start, dp->dp_start + dp->dp_size);
else
sprintf(line, "%s: Unknown fs: 0x%x\n", prefix,
dp->dp_typ);
} }
pager_output(line); pager_output(line);
} }
/*
* Print out each valid partition in the disklabel of a FreeBSD slice.
* For size calculations, we assume a 512 byte sector size.
*/
static void static void
bd_printbsdslice(struct open_disk *od, int offset, char *prefix) bd_printbsdslice(struct open_disk *od, daddr_t offset, char *prefix,
int verbose)
{ {
char line[80]; char line[80];
u_char buf[BIOSDISK_SECSIZE]; char buf[BIOSDISK_SECSIZE];
struct disklabel *lp; struct disklabel *lp;
int i; int i;
@ -346,16 +373,32 @@ bd_printbsdslice(struct open_disk *od, int offset, char *prefix)
/* Print partitions */ /* Print partitions */
for (i = 0; i < lp->d_npartitions; i++) { for (i = 0; i < lp->d_npartitions; i++) {
/*
* For each partition, make sure we know what type of fs it is. If
* not, then skip it. However, since floppies often have bogus
* fstypes, print the 'a' partition on a floppy even if it is marked
* unused.
*/
if ((lp->d_partitions[i].p_fstype == FS_BSDFFS) || if ((lp->d_partitions[i].p_fstype == FS_BSDFFS) ||
(lp->d_partitions[i].p_fstype == FS_SWAP) || (lp->d_partitions[i].p_fstype == FS_SWAP) ||
(lp->d_partitions[i].p_fstype == FS_VINUM) || (lp->d_partitions[i].p_fstype == FS_VINUM) ||
((lp->d_partitions[i].p_fstype == FS_UNUSED) && ((lp->d_partitions[i].p_fstype == FS_UNUSED) &&
(od->od_flags & BD_FLOPPY) && (i == 0))) { /* Floppies often have bogus fstype, print 'a' */ (od->od_flags & BD_FLOPPY) && (i == 0))) {
sprintf(line, " %s%c: %s %.6dMB (%d - %d)\n", prefix, 'a' + i,
/* Only print out statistics in verbose mode */
if (verbose)
sprintf(line, " %s%c: %s %.6dMB (%d - %d)\n", prefix, 'a' + i,
(lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap" : (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap" :
(lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" : "FFS", (lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" :
lp->d_partitions[i].p_size / 2048, /* 512-byte sector assumption */ "FFS",
lp->d_partitions[i].p_offset, lp->d_partitions[i].p_offset + lp->d_partitions[i].p_size); lp->d_partitions[i].p_size / 2048,
lp->d_partitions[i].p_offset,
lp->d_partitions[i].p_offset + lp->d_partitions[i].p_size);
else
sprintf(line, " %s%c: %s\n", prefix, 'a' + i,
(lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap" :
(lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" :
"FFS");
pager_output(line); pager_output(line);
} }
} }
@ -402,7 +445,7 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
struct open_disk *od; struct open_disk *od;
int sector, slice, i; int sector, slice, i;
int error; int error;
u_char buf[BUFSIZE]; char buf[BUFSIZE];
if (dev->d_kind.biosdisk.unit >= nbdinfo) { if (dev->d_kind.biosdisk.unit >= nbdinfo) {
DEBUG("attempt to open nonexistent disk"); DEBUG("attempt to open nonexistent disk");
@ -451,7 +494,7 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
/* /*
* Check the slice table magic. * Check the slice table magic.
*/ */
if ((buf[0x1fe] != 0x55) || (buf[0x1ff] != 0xaa)) { if (((u_char)buf[0x1fe] != 0x55) || ((u_char)buf[0x1ff] != 0xaa)) {
/* If a slice number was explicitly supplied, this is an error */ /* If a slice number was explicitly supplied, this is an error */
if (dev->d_kind.biosdisk.slice > 0) { if (dev->d_kind.biosdisk.slice > 0) {
DEBUG("no slice table/MBR (no magic)"); DEBUG("no slice table/MBR (no magic)");
@ -561,10 +604,12 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
} }
/* Complain if the partition type is wrong */ #ifdef DISK_DEBUG
/* Complain if the partition is unused unless this is a floppy. */
if ((lp->d_partitions[dev->d_kind.biosdisk.partition].p_fstype == FS_UNUSED) && if ((lp->d_partitions[dev->d_kind.biosdisk.partition].p_fstype == FS_UNUSED) &&
!(od->od_flags & BD_FLOPPY)) /* Floppies often have bogus fstype */ !(od->od_flags & BD_FLOPPY))
DEBUG("warning, partition marked as unused"); DEBUG("warning, partition marked as unused");
#endif
od->od_boff = lp->d_partitions[dev->d_kind.biosdisk.partition].p_offset; od->od_boff = lp->d_partitions[dev->d_kind.biosdisk.partition].p_offset;
} }
@ -581,7 +626,7 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
static void static void
bd_checkextended(struct open_disk *od, int slicenum) bd_checkextended(struct open_disk *od, int slicenum)
{ {
u_char buf[BIOSDISK_SECSIZE]; char buf[BIOSDISK_SECSIZE];
struct dos_partition *dp; struct dos_partition *dp;
u_int base; u_int base;
int i, start, end; int i, start, end;
@ -593,9 +638,9 @@ bd_checkextended(struct open_disk *od, int slicenum)
goto done; goto done;
if (dp->dp_typ != DOSPTYP_EXT) if (dp->dp_typ != DOSPTYP_EXT)
goto done; goto done;
if (bd_read(od, dp->dp_start, 1, buf)) if (bd_read(od, (daddr_t)dp->dp_start, 1, buf))
goto done; goto done;
if ((buf[0x1fe] != 0x55) || (buf[0x1ff] != 0xaa)) { if (((u_char)buf[0x1fe] != 0x55) || ((u_char)buf[0x1ff] != 0xaa)) {
DEBUG("no magic in extended table"); DEBUG("no magic in extended table");
goto done; goto done;
} }
@ -707,7 +752,7 @@ bd_closedisk(struct open_disk *od)
} }
static int static int
bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize) bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize)
{ {
struct bcache_devdata bcd; struct bcache_devdata bcd;
struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data); struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data);
@ -718,7 +763,7 @@ bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t
} }
static int static int
bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize) bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize)
{ {
struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data); struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data);
int blks; int blks;
@ -767,9 +812,13 @@ bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, siz
static int static int
bd_read(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest) bd_read(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest)
{ {
int x, bpc, cyl, hd, sec, result, resid, cnt, retry, maxfer; u_int x, bpc, cyl, hd, sec, result, resid, retry, maxfer;
caddr_t p, xp, bbuf, breg; caddr_t p, xp, bbuf, breg;
/* Just in case some idiot actually tries to read -1 blocks... */
if (blks < 0)
return (-1);
bpc = (od->od_sec * od->od_hds); /* blocks per cylinder */ bpc = (od->od_sec * od->od_hds); /* blocks per cylinder */
resid = blks; resid = blks;
p = dest; p = dest;
@ -784,7 +833,7 @@ bd_read(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest)
* need to. Use the bottom half unless there is a break there, in which case we * need to. Use the bottom half unless there is a break there, in which case we
* use the top half. * use the top half.
*/ */
x = min(FLOPPY_BOUNCEBUF, blks); x = min(FLOPPY_BOUNCEBUF, (unsigned)blks);
bbuf = malloc(x * 2 * BIOSDISK_SECSIZE); bbuf = malloc(x * 2 * BIOSDISK_SECSIZE);
if (((u_int32_t)VTOP(bbuf) & 0xffff0000) == ((u_int32_t)VTOP(dest + x * BIOSDISK_SECSIZE) & 0xffff0000)) { if (((u_int32_t)VTOP(bbuf) & 0xffff0000) == ((u_int32_t)VTOP(dest + x * BIOSDISK_SECSIZE) & 0xffff0000)) {
breg = bbuf; breg = bbuf;
@ -793,7 +842,7 @@ bd_read(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest)
} }
maxfer = x; /* limit transfers to bounce region size */ maxfer = x; /* limit transfers to bounce region size */
} else { } else {
bbuf = NULL; breg = bbuf = NULL;
maxfer = 0; maxfer = 0;
} }
@ -902,7 +951,7 @@ bd_getgeom(struct open_disk *od)
v86int(); v86int();
if ((v86.efl & 0x1) || /* carry set */ if ((v86.efl & 0x1) || /* carry set */
((v86.edx & 0xff) <= (od->od_unit & 0x7f))) /* unit # bad */ ((v86.edx & 0xff) <= (unsigned)(od->od_unit & 0x7f))) /* unit # bad */
return(1); return(1);
/* convert max cyl # -> # of cylinders */ /* convert max cyl # -> # of cylinders */
@ -993,14 +1042,15 @@ bd_getdev(struct i386_devdesc *dev)
major = WDMAJOR; major = WDMAJOR;
} }
} }
/* default root disk unit number */
unit = (biosdev & 0x7f) - unitofs;
/* XXX a better kludge to set the root disk unit number */ /* XXX a better kludge to set the root disk unit number */
if ((nip = getenv("root_disk_unit")) != NULL) { if ((nip = getenv("root_disk_unit")) != NULL) {
i = strtol(nip, &cp, 0); i = strtol(nip, &cp, 0);
/* check for parse error */ /* check for parse error */
if ((cp != nip) && (*cp == 0)) if ((cp != nip) && (*cp == 0))
unit = i; unit = i;
} else {
unit = (biosdev & 0x7f) - unitofs; /* allow for #wd compenstation in da case */
} }
rootdev = MAKEBOOTDEV(major, rootdev = MAKEBOOTDEV(major,
@ -1011,20 +1061,3 @@ bd_getdev(struct i386_devdesc *dev)
DEBUG("dev is 0x%x\n", rootdev); DEBUG("dev is 0x%x\n", rootdev);
return(rootdev); return(rootdev);
} }
/*
* Fix (dev) so that it refers to the 'real' disk/slice/partition that it implies.
*/
int
bd_fixupdev(struct i386_devdesc *dev)
{
struct open_disk *od;
/*
* Open the disk. This will fix up the slice and partition fields.
*/
if (bd_opendisk(&od, dev) != 0)
return(ENOENT);
bd_closedisk(od);
}