*BSD News Article 20555


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!swrinde!emory!tackle!irbs!jc
From: jc@irbs.UUCP (John Capo)
Newsgroups: comp.os.386bsd.misc
Subject: floppy disklabels
Message-ID: <514@irbs.UUCP>
Date: 7 Sep 93 13:45:04 GMT
Organization: Irbs Engineering
Lines: 82

I needed disklabels on floppies to make mfs work without hacking it up.
I also noticed that the FAQ mentions that floppy labels are still not
supported.  Here is fdioctl() that works for me.  The label is not
remembered in the driver.  It is read from disk each time it is requested.

i386/i386/conf.c needs to have fdioctl() declared and remove the line that
defines fdioctl to be enxio.

Can't produce a diff, my source tree is heavily hacked.

---
jcapo@netcom.com

--------------

int
fdioctl (dev, cmd, addr, flag)
dev_t dev;
int cmd;
caddr_t addr;
int flag;
{
    struct fd_type *fdt;
    struct disklabel *dl;
    char buffer[DEV_BSIZE];
    int error;

    error = 0;

    switch (cmd)
    {
    case DIOCGDINFO:
        bzero(buffer, sizeof (buffer));
        dl = (struct disklabel *)buffer;
        dl->d_secsize = FDBLK;
        fdt = &fd_types[FDUNIT(minor(dev))];
        dl->d_secpercyl = fdt->size / fdt->tracks;
        dl->d_type = DTYPE_FLOPPY;

        if (readdisklabel(dev, fdstrategy, dl, NULL, 0, 0) == NULL)
            error = 0;
        else
            error = EINVAL;

        *(struct disklabel *)addr = *dl;
        break;

    case DIOCSDINFO:

        if ((flag & FWRITE) == 0)
            error = EBADF;

        break;

    case DIOCWLABEL:
        if ((flag & FWRITE) == 0)
            error = EBADF;

        break;

    case DIOCWDINFO:
        if ((flag & FWRITE) == 0)
        {
            error = EBADF;
            break;
        }

        dl = (struct disklabel *)addr;

        if (error = setdisklabel ((struct disklabel *)buffer, dl, 0, NULL))
            break;

        error = writedisklabel(dev, fdstrategy, (struct disklabel *)buffer, NULL);
        break;

     default:
        error = EINVAL;
        break;
    }
    return (error);
}