Merge the last couple of my changes to fd.c into the pc98 version.

Sponsored by:	DARPA & NAI Labs
This commit is contained in:
phk 2002-10-05 15:15:43 +00:00
parent 7e92934dd9
commit 761d709aa1
2 changed files with 40 additions and 102 deletions

View File

@ -63,7 +63,6 @@
#include <sys/conf.h>
#include <sys/devicestat.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/fcntl.h>
#include <sys/fdcio.h>
#include <sys/filio.h>
@ -190,7 +189,7 @@ struct fdc_data
#endif
};
#define BIO_FORMAT BIO_CMD2
#define FDBIO_FORMAT BIO_CMD2
typedef int fdu_t;
typedef int fdcu_t;
@ -264,7 +263,7 @@ FDC_ACCESSOR(fdunit, FDUNIT, int)
#define NUMDENS 16
#endif
#define BIO_RDSECTID BIO_CMD1
#define FDBIO_RDSECTID BIO_CMD1
/*
* List of native drive densities. Order must match enum fd_drivetype
@ -2102,7 +2101,7 @@ fdstrategy(struct bio *bp)
goto bad;
}
fdblk = 128 << (fd->ft->secsize);
if (bp->bio_cmd != BIO_FORMAT && bp->bio_cmd != BIO_RDSECTID) {
if (bp->bio_cmd != FDBIO_FORMAT && bp->bio_cmd != FDBIO_RDSECTID) {
if (fd->flags & FD_NONBLOCK) {
bp->bio_error = EAGAIN;
bp->bio_flags |= BIO_ERROR;
@ -2345,7 +2344,7 @@ fdautoselect(dev_t dev)
fd->ft = fdtp;
id.cyl = id.head = 0;
rv = fdmisccmd(dev, BIO_RDSECTID, &id);
rv = fdmisccmd(dev, FDBIO_RDSECTID, &id);
if (rv != 0)
continue;
if (id.cyl != 0 || id.head != 0 ||
@ -2353,7 +2352,7 @@ fdautoselect(dev_t dev)
continue;
id.cyl = 2;
id.head = fd->ft->heads - 1;
rv = fdmisccmd(dev, BIO_RDSECTID, &id);
rv = fdmisccmd(dev, FDBIO_RDSECTID, &id);
if (id.cyl != 2 || id.head != fdtp->heads - 1 ||
id.secshift != fdtp->secsize)
continue;
@ -2429,8 +2428,8 @@ fdstate(fdc_p fdc)
idf = ISADMA_READ;
else
idf = ISADMA_WRITE;
format = bp->bio_cmd == BIO_FORMAT;
rdsectid = bp->bio_cmd == BIO_RDSECTID;
format = bp->bio_cmd == FDBIO_FORMAT;
rdsectid = bp->bio_cmd == FDBIO_RDSECTID;
if (format)
finfo = (struct fd_formb *)bp->bio_data;
TRACE1("fd%d", fdu);
@ -3120,14 +3119,14 @@ fdmisccmd(dev_t dev, u_int cmd, void *data)
* cylinder, and use the desired head.
*/
bp->bio_cmd = cmd;
if (cmd == BIO_FORMAT) {
if (cmd == FDBIO_FORMAT) {
bp->bio_blkno =
(finfo->cyl * (fd->ft->sectrac * fd->ft->heads) +
finfo->head * fd->ft->sectrac) *
fdblk / DEV_BSIZE;
bp->bio_bcount = sizeof(struct fd_idfield_data) *
finfo->fd_formb_nsecs;
} else if (cmd == BIO_RDSECTID) {
} else if (cmd == FDBIO_RDSECTID) {
bp->bio_blkno =
(idfield->cyl * (fd->ft->sectrac * fd->ft->heads) +
idfield->head * fd->ft->sectrac) *
@ -3153,8 +3152,6 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
{
fdu_t fdu;
fd_p fd;
struct fd_type *fdt;
struct disklabel *lp;
struct fdc_status *fsp;
struct fdc_readid *rid;
size_t fdblk;
@ -3173,6 +3170,15 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
* FD_NONBLOCK still being set.
*/
switch (cmd) {
case DIOCGMEDIASIZE:
*(off_t *)addr = (128 << (fd->ft->secsize)) * fd->ft->size;
return (0);
case DIOCGSECTORSIZE:
*(u_int *)addr = 128 << (fd->ft->secsize);
return (0);
case FIONBIO:
if (*(int *)addr != 0)
fd->flags |= FD_NONBLOCK;
@ -3271,43 +3277,6 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
error = 0;
switch (cmd) {
case DIOCGDINFO:
lp = malloc(sizeof(*lp), M_TEMP, M_ZERO);
lp->d_secsize = fdblk;
fdt = fd->ft;
lp->d_secpercyl = fdt->size / fdt->tracks;
lp->d_type = DTYPE_FLOPPY;
if (readdisklabel(dev, lp) != NULL)
error = EINVAL;
else
*(struct disklabel *)addr = *lp;
free(lp, M_TEMP);
break;
case DIOCSDINFO:
if ((flag & FWRITE) == 0)
return (EBADF);
/*
* XXX perhaps should call setdisklabel() to do error checking
* although there is nowhere to "set" the result. Perhaps
* should always just fail.
*/
break;
case DIOCWLABEL:
if ((flag & FWRITE) == 0)
return (EBADF);
break;
case DIOCWDINFO:
if ((flag & FWRITE) == 0)
return (EBADF);
lp = malloc(DEV_BSIZE, M_TEMP, M_ZERO);
error = setdisklabel(lp, (struct disklabel *)addr, (u_long)0);
if (error != 0)
error = writedisklabel(dev, lp);
free(lp, M_TEMP);
break;
case FD_FORM:
if ((flag & FWRITE) == 0)
@ -3315,7 +3284,7 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
if (((struct fd_formb *)addr)->format_version !=
FD_FORMAT_VERSION)
return (EINVAL); /* wrong version of formatting prog */
error = fdmisccmd(dev, BIO_FORMAT, addr);
error = fdmisccmd(dev, FDBIO_FORMAT, addr);
break;
case FD_GTYPE: /* get drive type */
@ -3364,7 +3333,7 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
rid = (struct fdc_readid *)addr;
if (rid->cyl > MAX_CYLINDER || rid->head > MAX_HEAD)
return (EINVAL);
error = fdmisccmd(dev, BIO_RDSECTID, addr);
error = fdmisccmd(dev, FDBIO_RDSECTID, addr);
break;
default:

View File

@ -63,7 +63,6 @@
#include <sys/conf.h>
#include <sys/devicestat.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/fcntl.h>
#include <sys/fdcio.h>
#include <sys/filio.h>
@ -190,7 +189,7 @@ struct fdc_data
#endif
};
#define BIO_FORMAT BIO_CMD2
#define FDBIO_FORMAT BIO_CMD2
typedef int fdu_t;
typedef int fdcu_t;
@ -264,7 +263,7 @@ FDC_ACCESSOR(fdunit, FDUNIT, int)
#define NUMDENS 16
#endif
#define BIO_RDSECTID BIO_CMD1
#define FDBIO_RDSECTID BIO_CMD1
/*
* List of native drive densities. Order must match enum fd_drivetype
@ -2102,7 +2101,7 @@ fdstrategy(struct bio *bp)
goto bad;
}
fdblk = 128 << (fd->ft->secsize);
if (bp->bio_cmd != BIO_FORMAT && bp->bio_cmd != BIO_RDSECTID) {
if (bp->bio_cmd != FDBIO_FORMAT && bp->bio_cmd != FDBIO_RDSECTID) {
if (fd->flags & FD_NONBLOCK) {
bp->bio_error = EAGAIN;
bp->bio_flags |= BIO_ERROR;
@ -2345,7 +2344,7 @@ fdautoselect(dev_t dev)
fd->ft = fdtp;
id.cyl = id.head = 0;
rv = fdmisccmd(dev, BIO_RDSECTID, &id);
rv = fdmisccmd(dev, FDBIO_RDSECTID, &id);
if (rv != 0)
continue;
if (id.cyl != 0 || id.head != 0 ||
@ -2353,7 +2352,7 @@ fdautoselect(dev_t dev)
continue;
id.cyl = 2;
id.head = fd->ft->heads - 1;
rv = fdmisccmd(dev, BIO_RDSECTID, &id);
rv = fdmisccmd(dev, FDBIO_RDSECTID, &id);
if (id.cyl != 2 || id.head != fdtp->heads - 1 ||
id.secshift != fdtp->secsize)
continue;
@ -2429,8 +2428,8 @@ fdstate(fdc_p fdc)
idf = ISADMA_READ;
else
idf = ISADMA_WRITE;
format = bp->bio_cmd == BIO_FORMAT;
rdsectid = bp->bio_cmd == BIO_RDSECTID;
format = bp->bio_cmd == FDBIO_FORMAT;
rdsectid = bp->bio_cmd == FDBIO_RDSECTID;
if (format)
finfo = (struct fd_formb *)bp->bio_data;
TRACE1("fd%d", fdu);
@ -3120,14 +3119,14 @@ fdmisccmd(dev_t dev, u_int cmd, void *data)
* cylinder, and use the desired head.
*/
bp->bio_cmd = cmd;
if (cmd == BIO_FORMAT) {
if (cmd == FDBIO_FORMAT) {
bp->bio_blkno =
(finfo->cyl * (fd->ft->sectrac * fd->ft->heads) +
finfo->head * fd->ft->sectrac) *
fdblk / DEV_BSIZE;
bp->bio_bcount = sizeof(struct fd_idfield_data) *
finfo->fd_formb_nsecs;
} else if (cmd == BIO_RDSECTID) {
} else if (cmd == FDBIO_RDSECTID) {
bp->bio_blkno =
(idfield->cyl * (fd->ft->sectrac * fd->ft->heads) +
idfield->head * fd->ft->sectrac) *
@ -3153,8 +3152,6 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
{
fdu_t fdu;
fd_p fd;
struct fd_type *fdt;
struct disklabel *lp;
struct fdc_status *fsp;
struct fdc_readid *rid;
size_t fdblk;
@ -3173,6 +3170,15 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
* FD_NONBLOCK still being set.
*/
switch (cmd) {
case DIOCGMEDIASIZE:
*(off_t *)addr = (128 << (fd->ft->secsize)) * fd->ft->size;
return (0);
case DIOCGSECTORSIZE:
*(u_int *)addr = 128 << (fd->ft->secsize);
return (0);
case FIONBIO:
if (*(int *)addr != 0)
fd->flags |= FD_NONBLOCK;
@ -3271,43 +3277,6 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
error = 0;
switch (cmd) {
case DIOCGDINFO:
lp = malloc(sizeof(*lp), M_TEMP, M_ZERO);
lp->d_secsize = fdblk;
fdt = fd->ft;
lp->d_secpercyl = fdt->size / fdt->tracks;
lp->d_type = DTYPE_FLOPPY;
if (readdisklabel(dev, lp) != NULL)
error = EINVAL;
else
*(struct disklabel *)addr = *lp;
free(lp, M_TEMP);
break;
case DIOCSDINFO:
if ((flag & FWRITE) == 0)
return (EBADF);
/*
* XXX perhaps should call setdisklabel() to do error checking
* although there is nowhere to "set" the result. Perhaps
* should always just fail.
*/
break;
case DIOCWLABEL:
if ((flag & FWRITE) == 0)
return (EBADF);
break;
case DIOCWDINFO:
if ((flag & FWRITE) == 0)
return (EBADF);
lp = malloc(DEV_BSIZE, M_TEMP, M_ZERO);
error = setdisklabel(lp, (struct disklabel *)addr, (u_long)0);
if (error != 0)
error = writedisklabel(dev, lp);
free(lp, M_TEMP);
break;
case FD_FORM:
if ((flag & FWRITE) == 0)
@ -3315,7 +3284,7 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
if (((struct fd_formb *)addr)->format_version !=
FD_FORMAT_VERSION)
return (EINVAL); /* wrong version of formatting prog */
error = fdmisccmd(dev, BIO_FORMAT, addr);
error = fdmisccmd(dev, FDBIO_FORMAT, addr);
break;
case FD_GTYPE: /* get drive type */
@ -3364,7 +3333,7 @@ fdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
rid = (struct fdc_readid *)addr;
if (rid->cyl > MAX_CYLINDER || rid->head > MAX_HEAD)
return (EINVAL);
error = fdmisccmd(dev, BIO_RDSECTID, addr);
error = fdmisccmd(dev, FDBIO_RDSECTID, addr);
break;
default: