示例#1
0
/*
 * Open the device special file.  Check that a disk is in.
 */
static int mcd_open(struct cdrom_device_info * cdi, int purpose)
{
	int st, count=0;
	if (mcdPresent == 0)
		return -ENXIO;			/* no hardware */

        if (!mcd_open_count && mcd_state == MCD_S_IDLE) {
        mcd_invalidate_buffers();
        do {
                st = statusCmd();               /* check drive status */
                if (st == -1)
                        return -EIO;            /* drive doesn't respond */
                if ((st & MST_READY) == 0) {    /* no disk? wait a sec... */
                        current->state = TASK_INTERRUPTIBLE;
                        schedule_timeout(HZ);
                }
        } while (((st & MST_READY) == 0) && count++ < MCD_RETRY_ATTEMPTS);

        if (updateToc() < 0)
                       return -EIO;
        }
	++mcd_open_count;
        MOD_INC_USE_COUNT;
	return 0;
}
示例#2
0
文件: mcd.c 项目: NandanPhadke/oslab
/*
 * Open the device special file.  Check that a disk is in.
 */
static int mcd_open(struct cdrom_device_info *cdi, int purpose)
{
	int st, count = 0;
	if (mcdPresent == 0)
		return -ENXIO;	/* no hardware */

	if (mcd_open_count || mcd_state != MCD_S_IDLE)
		goto bump_count;

	mcd_invalidate_buffers();
	do {
		st = statusCmd();	/* check drive status */
		if (st == -1)
			goto err_out;	/* drive doesn't respond */
		if ((st & MST_READY) == 0) 	/* no disk? wait a sec... */
			msleep(1000);

	} while (((st & MST_READY) == 0) && count++ < MCD_RETRY_ATTEMPTS);

	if (updateToc() < 0)
		goto err_out;

bump_count:
	++mcd_open_count;
	return 0;

err_out:
	return -EIO;
}
示例#3
0
/* gives current state of the drive This function is quite unreliable, 
   and should probably be rewritten by someone, eventually... */
int mcd_drive_status(struct cdrom_device_info * cdi, int slot_nr)
{
  int st;

  st = statusCmd();               /* check drive status */
  if (st == -1)
      return -EIO;            /* drive doesn't respond */
  if ((st & MST_READY)) return CDS_DISC_OK;
  if ((st & MST_DOOR_OPEN)) return CDS_TRAY_OPEN;
  if ((st & MST_DSK_CHG)) return CDS_NO_DISC;
  if ((st & MST_BUSY)) return CDS_DRIVE_NOT_READY;
  return -EIO;
}
示例#4
0
int
mcd_open(struct inode *ip, struct file *fp)
{
    int st;
    int count = 0;

    if (mcdPresent == 0)
        return -ENXIO;			/* no hardware */

    if (fp->f_mode & 2)			/* write access? */
        return -EROFS;

    if (!mcd_open_count && mcd_state == MCD_S_IDLE) {

        mcd_invalidate_buffers();

        do {
            st = statusCmd();		/* check drive status */
            if (st == -1)
                return -EIO;		/* drive doesn't respond */
            if ((st & MST_READY) == 0) {	/* no disk? wait a sec... */
                current->state = TASK_INTERRUPTIBLE;
                current->timeout = jiffies + HZ;
                schedule();
            }
        } while (((st & MST_READY) == 0) && count++ < MCD_RETRY_ATTEMPTS);

        if ((st & MST_READY) == 0)		/* no disk in drive */
        {
            printk("mcd: no disk in drive\n");
            return -EIO;
        }

        if (updateToc() < 0)
            return -EIO;

    }
    ++mcd_open_count;
    MOD_INC_USE_COUNT;
    return 0;
}
示例#5
0
int mcd_audio_ioctl(struct cdrom_device_info * cdi, unsigned int cmd,
                      void * arg)
{
	int i, st;
	struct mcd_Toc qInfo;
	struct cdrom_ti *ti;
	struct cdrom_tochdr *tocHdr;
	struct cdrom_msf *msf;
	struct cdrom_subchnl *subchnl;
	struct cdrom_tocentry *entry;
	struct mcd_Toc *tocPtr;
	struct cdrom_volctrl *volctrl;

	st = statusCmd();
	if (st < 0)
		return -EIO;

	if (!tocUpToDate)
	{
		i = updateToc();
		if (i < 0) 
			return i;	/* error reading TOC */
	}

	switch (cmd)
	{
	case CDROMSTART:     /* Spin up the drive */
		/* Don't think we can do this.  Even if we could,
 		 * I think the drive times out and stops after a while
		 * anyway.  For now, ignore it.
		 */

		return 0;

	case CDROMSTOP:      /* Spin down the drive */
		outb(MCMD_STOP, MCDPORT(0));
		i = getMcdStatus(MCD_STATUS_DELAY);

		/* should we do anything if it fails? */

		audioStatus = CDROM_AUDIO_NO_STATUS;
		return 0;

	case CDROMPAUSE:     /* Pause the drive */
		if (audioStatus != CDROM_AUDIO_PLAY)
			return -EINVAL;

		outb(MCMD_STOP, MCDPORT(0));
		i = getMcdStatus(MCD_STATUS_DELAY);

		if (GetQChannelInfo(&qInfo) < 0)
		{
			/* didn't get q channel info */

			audioStatus = CDROM_AUDIO_NO_STATUS;
			return 0;
		}

		mcd_Play.start = qInfo.diskTime;	/* remember restart point */

		audioStatus = CDROM_AUDIO_PAUSED;
		return 0;

	case CDROMRESUME:    /* Play it again, Sam */
		if (audioStatus != CDROM_AUDIO_PAUSED)
			return -EINVAL;

		/* restart the drive at the saved position. */

		i = mcdPlay(&mcd_Play);
		if (i < 0)
		{
			audioStatus = CDROM_AUDIO_ERROR;
			return -EIO;
		}

		audioStatus = CDROM_AUDIO_PLAY;
		return 0;

	case CDROMPLAYTRKIND:     /* Play a track.  This currently ignores index. */

		ti=(struct cdrom_ti *) arg;

		if (ti->cdti_trk0 < DiskInfo.first
			|| ti->cdti_trk0 > DiskInfo.last
			|| ti->cdti_trk1 < ti->cdti_trk0)
		{
			return -EINVAL;
		}

		if (ti->cdti_trk1 > DiskInfo.last)
			ti->cdti_trk1 = DiskInfo.last;

		mcd_Play.start = Toc[ti->cdti_trk0].diskTime;
		mcd_Play.end = Toc[ti->cdti_trk1 + 1].diskTime;

#ifdef MCD_DEBUG
printk("play: %02x:%02x.%02x to %02x:%02x.%02x\n",
	mcd_Play.start.min, mcd_Play.start.sec, mcd_Play.start.frame,
	mcd_Play.end.min, mcd_Play.end.sec, mcd_Play.end.frame);
#endif

		i = mcdPlay(&mcd_Play);
		if (i < 0)
		{
			audioStatus = CDROM_AUDIO_ERROR;
			return -EIO;
		}

		audioStatus = CDROM_AUDIO_PLAY;
		return 0;

	case CDROMPLAYMSF:   /* Play starting at the given MSF address. */

		if (audioStatus == CDROM_AUDIO_PLAY) {
		  outb(MCMD_STOP, MCDPORT(0));
		  i = getMcdStatus(MCD_STATUS_DELAY);
		  audioStatus = CDROM_AUDIO_NO_STATUS;
		}

		msf=(struct cdrom_msf *) arg;

		/* convert to bcd */

		bin2bcd(&msf->cdmsf_min0);
		bin2bcd(&msf->cdmsf_sec0);
		bin2bcd(&msf->cdmsf_frame0);
		bin2bcd(&msf->cdmsf_min1);
		bin2bcd(&msf->cdmsf_sec1);
		bin2bcd(&msf->cdmsf_frame1);

		mcd_Play.start.min = msf->cdmsf_min0;
		mcd_Play.start.sec = msf->cdmsf_sec0;
		mcd_Play.start.frame = msf->cdmsf_frame0;
		mcd_Play.end.min = msf->cdmsf_min1;
		mcd_Play.end.sec = msf->cdmsf_sec1;
		mcd_Play.end.frame = msf->cdmsf_frame1;

#ifdef MCD_DEBUG
printk("play: %02x:%02x.%02x to %02x:%02x.%02x\n",
mcd_Play.start.min, mcd_Play.start.sec, mcd_Play.start.frame,
mcd_Play.end.min, mcd_Play.end.sec, mcd_Play.end.frame);
#endif

		i = mcdPlay(&mcd_Play);
		if (i < 0)
		{
			audioStatus = CDROM_AUDIO_ERROR;
			return -EIO;
		}

		audioStatus = CDROM_AUDIO_PLAY;
		return 0;

	case CDROMREADTOCHDR:        /* Read the table of contents header */
	        tocHdr=(struct cdrom_tochdr *) arg; 
		tocHdr->cdth_trk0 = DiskInfo.first;
		tocHdr->cdth_trk1 = DiskInfo.last;
		return 0;

	case CDROMREADTOCENTRY:      /* Read an entry in the table of contents */
		entry=(struct cdrom_tocentry *) arg;
		if (entry->cdte_track == CDROM_LEADOUT)
			tocPtr = &Toc[DiskInfo.last - DiskInfo.first + 1];

		else if (entry->cdte_track > DiskInfo.last
				|| entry->cdte_track < DiskInfo.first)
			return -EINVAL;

		else
			tocPtr = &Toc[entry->cdte_track];

		entry->cdte_adr = tocPtr -> ctrl_addr;
		entry->cdte_ctrl = tocPtr -> ctrl_addr >> 4;

		if (entry->cdte_format == CDROM_LBA)
			entry->cdte_addr.lba = msf2hsg(&tocPtr -> diskTime);

		else if (entry->cdte_format == CDROM_MSF)
		{
			entry->cdte_addr.msf.minute = bcd2bin(tocPtr -> diskTime.min);
			entry->cdte_addr.msf.second = bcd2bin(tocPtr -> diskTime.sec);
			entry->cdte_addr.msf.frame = bcd2bin(tocPtr -> diskTime.frame);
		}

		else
			return -EINVAL;

		return 0;

	case CDROMSUBCHNL:   /* Get subchannel info */

                subchnl=(struct cdrom_subchnl *) arg;
		if (GetQChannelInfo(&qInfo) < 0)
			return -EIO;

		subchnl->cdsc_audiostatus = audioStatus;
		subchnl->cdsc_adr = qInfo.ctrl_addr;
		subchnl->cdsc_ctrl = qInfo.ctrl_addr >> 4;
		subchnl->cdsc_trk = bcd2bin(qInfo.track);
		subchnl->cdsc_ind = bcd2bin(qInfo.pointIndex);
		subchnl->cdsc_absaddr.msf.minute = bcd2bin(qInfo.diskTime.min);
		subchnl->cdsc_absaddr.msf.second = bcd2bin(qInfo.diskTime.sec);
		subchnl->cdsc_absaddr.msf.frame = bcd2bin(qInfo.diskTime.frame);
		subchnl->cdsc_reladdr.msf.minute = bcd2bin(qInfo.trackTime.min);
		subchnl->cdsc_reladdr.msf.second = bcd2bin(qInfo.trackTime.sec);
		subchnl->cdsc_reladdr.msf.frame = bcd2bin(qInfo.trackTime.frame);
		return(0);

	case CDROMVOLCTRL:   /* Volume control */
		volctrl=(struct cdrom_volctrl *) arg;
		outb(MCMD_SET_VOLUME, MCDPORT(0));
		outb(volctrl->channel0, MCDPORT(0));
		outb(255, MCDPORT(0));
		outb(volctrl->channel1, MCDPORT(0));
		outb(255, MCDPORT(0));

		i = getMcdStatus(MCD_STATUS_DELAY);
		if (i < 0)
			return -EIO;

		{
			char a, b, c, d;

			getValue(&a);
			getValue(&b);
			getValue(&c);
			getValue(&d);
		}

		return 0;

	default:
		return -EINVAL;
	}
}
示例#6
0
static int
mcd_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
          unsigned long arg)
{
    int i, st;
    struct mcd_Toc qInfo;
    struct cdrom_ti ti;
    struct cdrom_tochdr tocHdr;
    struct cdrom_msf msf;
    struct cdrom_tocentry entry;
    struct mcd_Toc *tocPtr;
    struct cdrom_subchnl subchnl;
    struct cdrom_volctrl volctrl;

    if (!ip)
        return -EINVAL;

    st = statusCmd();
    if (st < 0)
        return -EIO;

    if (!tocUpToDate)
    {
        i = updateToc();
        if (i < 0)
            /* [email protected]:
            We _can_ open the door even without a CD */
            if (cmd != CDROMEJECT)
                return i;	/* error reading TOC */
    }

    switch (cmd)
    {
    case CDROMSTART:     /* Spin up the drive */
        /* Don't think we can do this.  Even if we could,
         * I think the drive times out and stops after a while
         * anyway.  For now, ignore it.
         */

        return 0;

    case CDROMSTOP:      /* Spin down the drive */
        outb(MCMD_STOP, MCDPORT(0));
        i = getMcdStatus(MCD_STATUS_DELAY);

        /* should we do anything if it fails? */

        audioStatus = CDROM_AUDIO_NO_STATUS;
        return 0;

    case CDROMPAUSE:     /* Pause the drive */
        if (audioStatus != CDROM_AUDIO_PLAY)
            return -EINVAL;

        outb(MCMD_STOP, MCDPORT(0));
        i = getMcdStatus(MCD_STATUS_DELAY);

        if (GetQChannelInfo(&qInfo) < 0)
        {
            /* didn't get q channel info */

            audioStatus = CDROM_AUDIO_NO_STATUS;
            return 0;
        }

        mcd_Play.start = qInfo.diskTime;	/* remember restart point */

        audioStatus = CDROM_AUDIO_PAUSED;
        return 0;

    case CDROMRESUME:    /* Play it again, Sam */
        if (audioStatus != CDROM_AUDIO_PAUSED)
            return -EINVAL;

        /* restart the drive at the saved position. */

        i = mcdPlay(&mcd_Play);
        if (i < 0)
        {
            audioStatus = CDROM_AUDIO_ERROR;
            return -EIO;
        }

        audioStatus = CDROM_AUDIO_PLAY;
        return 0;

    case CDROMPLAYTRKIND:     /* Play a track.  This currently ignores index. */

        st = verify_area(VERIFY_READ, (void *) arg, sizeof ti);
        if (st)
            return st;

        memcpy_fromfs(&ti, (void *) arg, sizeof ti);

        if (ti.cdti_trk0 < DiskInfo.first
                || ti.cdti_trk0 > DiskInfo.last
                || ti.cdti_trk1 < ti.cdti_trk0)
        {
            return -EINVAL;
        }

        if (ti.cdti_trk1 > DiskInfo.last)
            ti. cdti_trk1 = DiskInfo.last;

        mcd_Play.start = Toc[ti.cdti_trk0].diskTime;
        mcd_Play.end = Toc[ti.cdti_trk1 + 1].diskTime;

#ifdef MCD_DEBUG
        printk("play: %02x:%02x.%02x to %02x:%02x.%02x\n",
               mcd_Play.start.min, mcd_Play.start.sec, mcd_Play.start.frame,
               mcd_Play.end.min, mcd_Play.end.sec, mcd_Play.end.frame);
#endif

        i = mcdPlay(&mcd_Play);
        if (i < 0)
        {
            audioStatus = CDROM_AUDIO_ERROR;
            return -EIO;
        }

        audioStatus = CDROM_AUDIO_PLAY;
        return 0;

    case CDROMPLAYMSF:   /* Play starting at the given MSF address. */

        if (audioStatus == CDROM_AUDIO_PLAY) {
            outb(MCMD_STOP, MCDPORT(0));
            i = getMcdStatus(MCD_STATUS_DELAY);
            audioStatus = CDROM_AUDIO_NO_STATUS;
        }

        st = verify_area(VERIFY_READ, (void *) arg, sizeof msf);
        if (st)
            return st;

        memcpy_fromfs(&msf, (void *) arg, sizeof msf);

        /* convert to bcd */

        bin2bcd(&msf.cdmsf_min0);
        bin2bcd(&msf.cdmsf_sec0);
        bin2bcd(&msf.cdmsf_frame0);
        bin2bcd(&msf.cdmsf_min1);
        bin2bcd(&msf.cdmsf_sec1);
        bin2bcd(&msf.cdmsf_frame1);

        mcd_Play.start.min = msf.cdmsf_min0;
        mcd_Play.start.sec = msf.cdmsf_sec0;
        mcd_Play.start.frame = msf.cdmsf_frame0;
        mcd_Play.end.min = msf.cdmsf_min1;
        mcd_Play.end.sec = msf.cdmsf_sec1;
        mcd_Play.end.frame = msf.cdmsf_frame1;

#ifdef MCD_DEBUG
        printk("play: %02x:%02x.%02x to %02x:%02x.%02x\n",
               mcd_Play.start.min, mcd_Play.start.sec, mcd_Play.start.frame,
               mcd_Play.end.min, mcd_Play.end.sec, mcd_Play.end.frame);
#endif

        i = mcdPlay(&mcd_Play);
        if (i < 0)
        {
            audioStatus = CDROM_AUDIO_ERROR;
            return -EIO;
        }

        audioStatus = CDROM_AUDIO_PLAY;
        return 0;

    case CDROMREADTOCHDR:        /* Read the table of contents header */
        st = verify_area(VERIFY_WRITE, (void *) arg, sizeof tocHdr);
        if (st)
            return st;

        tocHdr.cdth_trk0 = DiskInfo.first;
        tocHdr.cdth_trk1 = DiskInfo.last;
        memcpy_tofs((void *) arg, &tocHdr, sizeof tocHdr);
        return 0;

    case CDROMREADTOCENTRY:      /* Read an entry in the table of contents */

        st = verify_area(VERIFY_WRITE, (void *) arg, sizeof entry);
        if (st)
            return st;

        memcpy_fromfs(&entry, (void *) arg, sizeof entry);
        if (entry.cdte_track == CDROM_LEADOUT)
            /* XXX */
            tocPtr = &Toc[DiskInfo.last + 1];

        else if (entry.cdte_track > DiskInfo.last
                 || entry.cdte_track < DiskInfo.first)
            return -EINVAL;

        else
            tocPtr = &Toc[entry.cdte_track];

        entry.cdte_adr = tocPtr -> ctrl_addr;
        entry.cdte_ctrl = tocPtr -> ctrl_addr >> 4;

        if (entry.cdte_format == CDROM_LBA)
            entry.cdte_addr.lba = msf2hsg(&tocPtr -> diskTime);

        else if (entry.cdte_format == CDROM_MSF)
        {
            entry.cdte_addr.msf.minute = bcd2bin(tocPtr -> diskTime.min);
            entry.cdte_addr.msf.second = bcd2bin(tocPtr -> diskTime.sec);
            entry.cdte_addr.msf.frame = bcd2bin(tocPtr -> diskTime.frame);
        }

        else
            return -EINVAL;

        memcpy_tofs((void *) arg, &entry, sizeof entry);
        return 0;

    case CDROMSUBCHNL:   /* Get subchannel info */

        st = verify_area(VERIFY_WRITE, (void *) arg, sizeof subchnl);
        if (st)
            return st;

        memcpy_fromfs(&subchnl, (void *) arg, sizeof subchnl);

        if (GetQChannelInfo(&qInfo) < 0)
            return -EIO;

        subchnl.cdsc_audiostatus = audioStatus;
        subchnl.cdsc_adr = qInfo.ctrl_addr;
        subchnl.cdsc_ctrl = qInfo.ctrl_addr >> 4;
        subchnl.cdsc_trk = bcd2bin(qInfo.track);
        subchnl.cdsc_ind = bcd2bin(qInfo.pointIndex);

        if (subchnl.cdsc_format == CDROM_LBA)
        {
            subchnl.cdsc_absaddr.lba = msf2hsg(&qInfo.diskTime);
            subchnl.cdsc_reladdr.lba = msf2hsg(&qInfo.trackTime);
        }

        else if (subchnl.cdsc_format == CDROM_MSF)
        {
            subchnl.cdsc_absaddr.msf.minute = bcd2bin(qInfo.diskTime.min);
            subchnl.cdsc_absaddr.msf.second = bcd2bin(qInfo.diskTime.sec);
            subchnl.cdsc_absaddr.msf.frame = bcd2bin(qInfo.diskTime.frame);

            subchnl.cdsc_reladdr.msf.minute = bcd2bin(qInfo.trackTime.min);
            subchnl.cdsc_reladdr.msf.second = bcd2bin(qInfo.trackTime.sec);
            subchnl.cdsc_reladdr.msf.frame = bcd2bin(qInfo.trackTime.frame);
        }

        else
            return -EINVAL;

        memcpy_tofs((void *) arg, &subchnl, sizeof subchnl);
        return 0;

    case CDROMVOLCTRL:   /* Volume control */
        st = verify_area(VERIFY_READ, (void *) arg, sizeof(volctrl));
        if (st)
            return st;

        memcpy_fromfs(&volctrl, (char *) arg, sizeof(volctrl));
        outb(MCMD_SET_VOLUME, MCDPORT(0));
        outb(volctrl.channel0, MCDPORT(0));
        outb(255, MCDPORT(0));
        outb(volctrl.channel1, MCDPORT(0));
        outb(255, MCDPORT(0));

        i = getMcdStatus(MCD_STATUS_DELAY);
        if (i < 0)
            return -EIO;

        {
            char a, b, c, d;

            getValue(&a);
            getValue(&b);
            getValue(&c);
            getValue(&d);
        }

        return 0;

    case CDROMEJECT:
        /* all drives can at least stop! */
        if (audioStatus == CDROM_AUDIO_PLAY) {
            outb(MCMD_STOP, MCDPORT(0));
            i = getMcdStatus(MCD_STATUS_DELAY);
        }

        audioStatus = CDROM_AUDIO_NO_STATUS;

        outb(MCMD_EJECT, MCDPORT(0));
        /*
         * the status (i) shows failure on all but the FX drives.
         * But nothing we can do about that in software!
         * So just read the status and forget it. - Jon.
         */
        i = getMcdStatus(MCD_STATUS_DELAY);
        return 0;
    default:
        return -EINVAL;
    }
}