Deleted Added
full compact
mcd.c (14074) mcd.c (14285)
1/*
2 * Copyright 1993 by Holger Veit (data part)
3 * Copyright 1993 by Brian Moore (audio part)
4 * Changes Copyright 1993 by Gary Clark II
5 * Changes Copyright (C) 1994-1995 by Andrey A. Chernov, Moscow, Russia
6 *
7 * Rewrote probe routine to work on newer Mitsumi drives.
8 * Additional changes (C) 1994 by Jordan K. Hubbard

--- 26 unchanged lines hidden (view full) ---

35 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
36 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
37 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
1/*
2 * Copyright 1993 by Holger Veit (data part)
3 * Copyright 1993 by Brian Moore (audio part)
4 * Changes Copyright 1993 by Gary Clark II
5 * Changes Copyright (C) 1994-1995 by Andrey A. Chernov, Moscow, Russia
6 *
7 * Rewrote probe routine to work on newer Mitsumi drives.
8 * Additional changes (C) 1994 by Jordan K. Hubbard

--- 26 unchanged lines hidden (view full) ---

35 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
36 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
37 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 * $Id: mcd.c,v 1.70 1996/02/03 14:33:56 ache Exp $
43 * $Id: mcd.c,v 1.71 1996/02/13 02:32:36 ache Exp $
44 */
45static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";
46
47#include "mcd.h"
48#if NMCD > 0
49#include <sys/types.h>
50#include <sys/param.h>
51#include <sys/systm.h>

--- 285 unchanged lines hidden (view full) ---

337 return ENXIO;
338
339 if (mcd_getstat(unit,1) == -1)
340 return EIO;
341
342 if ( (cd->status & (MCDDSKCHNG|MCDDOOROPEN))
343 || !(cd->status & MCDDSKIN))
344 for (retry = 0; retry < DISK_SENSE_SECS * WAIT_FRAC; retry++) {
44 */
45static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";
46
47#include "mcd.h"
48#if NMCD > 0
49#include <sys/types.h>
50#include <sys/param.h>
51#include <sys/systm.h>

--- 285 unchanged lines hidden (view full) ---

337 return ENXIO;
338
339 if (mcd_getstat(unit,1) == -1)
340 return EIO;
341
342 if ( (cd->status & (MCDDSKCHNG|MCDDOOROPEN))
343 || !(cd->status & MCDDSKIN))
344 for (retry = 0; retry < DISK_SENSE_SECS * WAIT_FRAC; retry++) {
345 (void) tsleep((caddr_t)cd, PSOCK | PCATCH, "mcdsns", hz/WAIT_FRAC);
345 (void) tsleep((caddr_t)cd, PSOCK | PCATCH, "mcdsn1", hz/WAIT_FRAC);
346 if ((r = mcd_getstat(unit,1)) == -1)
347 return EIO;
348 if (r != -2)
349 break;
350 }
351
346 if ((r = mcd_getstat(unit,1)) == -1)
347 return EIO;
348 if (r != -2)
349 break;
350 }
351
352 if (( (cd->status & (MCDDOOROPEN|MCDDSKCHNG))
353 || !(cd->status & MCDDSKIN)
354 )
355 && major(dev) == CDEV_MAJOR && part == RAW_PART
356 ) {
357 cd->openflags |= (1<<part);
358 kdc_mcd[unit].kdc_state = DC_BUSY;
359 return 0;
360 }
352 if (cd->status & MCDDOOROPEN) {
353 printf("mcd%d: door is open\n", unit);
354 return ENXIO;
355 }
356 if (!(cd->status & MCDDSKIN)) {
357 printf("mcd%d: no CD inside\n", unit);
358 return ENXIO;
359 }
360 if (cd->status & MCDDSKCHNG) {
361 printf("mcd%d: CD not sensed\n", unit);
362 return ENXIO;
363 }
364
365 if (mcdsize(dev) < 0) {
361 if (cd->status & MCDDOOROPEN) {
362 printf("mcd%d: door is open\n", unit);
363 return ENXIO;
364 }
365 if (!(cd->status & MCDDSKIN)) {
366 printf("mcd%d: no CD inside\n", unit);
367 return ENXIO;
368 }
369 if (cd->status & MCDDSKCHNG) {
370 printf("mcd%d: CD not sensed\n", unit);
371 return ENXIO;
372 }
373
374 if (mcdsize(dev) < 0) {
375 if (major(dev) == CDEV_MAJOR && part == RAW_PART) {
376 cd->openflags |= (1<<part);
377 kdc_mcd[unit].kdc_state = DC_BUSY;
378 return 0;
379 }
366 printf("mcd%d: failed to get disk size\n",unit);
367 return ENXIO;
368 } else
369 cd->flags |= MCDVALID;
370
371 /* XXX get a default disklabel */
372 mcd_getdisklabel(unit);
373

--- 164 unchanged lines hidden (view full) ---

538 mcd_doread(MCD_S_BEGIN,&(cd->mbx));
539 /* triggers mcd_start, when successful finished */
540 return;
541}
542
543int mcdioctl(dev_t dev, int cmd, caddr_t addr, int flags, struct proc *p)
544{
545 struct mcd_data *cd;
380 printf("mcd%d: failed to get disk size\n",unit);
381 return ENXIO;
382 } else
383 cd->flags |= MCDVALID;
384
385 /* XXX get a default disklabel */
386 mcd_getdisklabel(unit);
387

--- 164 unchanged lines hidden (view full) ---

552 mcd_doread(MCD_S_BEGIN,&(cd->mbx));
553 /* triggers mcd_start, when successful finished */
554 return;
555}
556
557int mcdioctl(dev_t dev, int cmd, caddr_t addr, int flags, struct proc *p)
558{
559 struct mcd_data *cd;
546 int unit,part;
560 int unit,part,retry,r;
547
548 unit = mcd_unit(dev);
549 part = mcd_part(dev);
550 cd = mcd_data + unit;
551
552 if (mcd_getstat(unit, 1) == -1) /* detect disk change too */
553 return EIO;
554MCD_TRACE("ioctl called 0x%x\n", cmd);
555
556 switch (cmd) {
561
562 unit = mcd_unit(dev);
563 part = mcd_part(dev);
564 cd = mcd_data + unit;
565
566 if (mcd_getstat(unit, 1) == -1) /* detect disk change too */
567 return EIO;
568MCD_TRACE("ioctl called 0x%x\n", cmd);
569
570 switch (cmd) {
557 case DIOCSBAD:
571 case CDIOCSETPATCH:
572 case CDIOCGETVOL:
573 case CDIOCSETVOL:
574 case CDIOCSETMONO:
575 case CDIOCSETSTERIO:
576 case CDIOCSETMUTE:
577 case CDIOCSETLEFT:
578 case CDIOCSETRIGHT:
579 return EINVAL;
580 case CDIOCEJECT:
581 return mcd_eject(unit);
582 case CDIOCSETDEBUG:
583 cd->debug = 1;
584 return 0;
585 case CDIOCCLRDEBUG:
586 cd->debug = 0;
587 return 0;
588 case CDIOCRESET:
589 return mcd_hard_reset(unit);
590 case CDIOCALLOW:
591 return mcd_lock_door(unit, MCD_LK_UNLOCK);
592 case CDIOCPREVENT:
593 return mcd_lock_door(unit, MCD_LK_LOCK);
594 case CDIOCCLOSE:
595 return mcd_inject(unit);
596 }
597
598 if (!(cd->flags & MCDVALID)) {
599 if ( major(dev) != CDEV_MAJOR
600 || !(cd->openflags & (1<<RAW_PART))
601 )
602 return ENXIO;
603 if ( (cd->status & (MCDDSKCHNG|MCDDOOROPEN))
604 || !(cd->status & MCDDSKIN))
605 for (retry = 0; retry < DISK_SENSE_SECS * WAIT_FRAC; retry++) {
606 (void) tsleep((caddr_t)cd, PSOCK | PCATCH, "mcdsn2", hz/WAIT_FRAC);
607 if ((r = mcd_getstat(unit,1)) == -1)
608 return EIO;
609 if (r != -2)
610 break;
611 }
612 if ( (cd->status & (MCDDOOROPEN|MCDDSKCHNG))
613 || !(cd->status & MCDDSKIN)
614 || mcdsize(dev) < 0
615 )
616 return ENXIO;
617 cd->flags |= MCDVALID;
618 mcd_getdisklabel(unit);
619 cd->partflags[RAW_PART] |= MCDOPEN;
620 (void) mcd_lock_door(unit, MCD_LK_LOCK);
558 if (!(cd->flags & MCDVALID))
559 return ENXIO;
621 if (!(cd->flags & MCDVALID))
622 return ENXIO;
623 }
624
625 switch (cmd) {
626 case DIOCSBAD:
560 return EINVAL;
561 case DIOCGDINFO:
627 return EINVAL;
628 case DIOCGDINFO:
562 if (!(cd->flags & MCDVALID))
563 return ENXIO;
564 *(struct disklabel *) addr = cd->dlabel;
565 return 0;
566 case DIOCGPART:
629 *(struct disklabel *) addr = cd->dlabel;
630 return 0;
631 case DIOCGPART:
567 if (!(cd->flags & MCDVALID))
568 return ENXIO;
569 ((struct partinfo *) addr)->disklab = &cd->dlabel;
570 ((struct partinfo *) addr)->part =
571 &cd->dlabel.d_partitions[mcd_part(dev)];
572 return 0;
573
574 /*
575 * a bit silly, but someone might want to test something on a
576 * section of cdrom.
577 */
578 case DIOCWDINFO:
579 case DIOCSDINFO:
632 ((struct partinfo *) addr)->disklab = &cd->dlabel;
633 ((struct partinfo *) addr)->part =
634 &cd->dlabel.d_partitions[mcd_part(dev)];
635 return 0;
636
637 /*
638 * a bit silly, but someone might want to test something on a
639 * section of cdrom.
640 */
641 case DIOCWDINFO:
642 case DIOCSDINFO:
580 if (!(cd->flags & MCDVALID))
581 return ENXIO;
582 if ((flags & FWRITE) == 0)
583 return EBADF;
584 else {
585 return setdisklabel(&cd->dlabel,
586 (struct disklabel *) addr,
587 0);
588 }
589 case DIOCWLABEL:
643 if ((flags & FWRITE) == 0)
644 return EBADF;
645 else {
646 return setdisklabel(&cd->dlabel,
647 (struct disklabel *) addr,
648 0);
649 }
650 case DIOCWLABEL:
590 if (!(cd->flags & MCDVALID))
591 return ENXIO;
592 return EBADF;
593 case CDIOCPLAYTRACKS:
651 return EBADF;
652 case CDIOCPLAYTRACKS:
594 if (!(cd->flags & MCDVALID))
595 return ENXIO;
596 return mcd_playtracks(unit, (struct ioc_play_track *) addr);
597 case CDIOCPLAYBLOCKS:
653 return mcd_playtracks(unit, (struct ioc_play_track *) addr);
654 case CDIOCPLAYBLOCKS:
598 if (!(cd->flags & MCDVALID))
599 return ENXIO;
600 return mcd_playblocks(unit, (struct ioc_play_blocks *) addr);
601 case CDIOCPLAYMSF:
655 return mcd_playblocks(unit, (struct ioc_play_blocks *) addr);
656 case CDIOCPLAYMSF:
602 if (!(cd->flags & MCDVALID))
603 return ENXIO;
604 return mcd_playmsf(unit, (struct ioc_play_msf *) addr);
605 case CDIOCREADSUBCHANNEL:
657 return mcd_playmsf(unit, (struct ioc_play_msf *) addr);
658 case CDIOCREADSUBCHANNEL:
606 if (!(cd->flags & MCDVALID))
607 return ENXIO;
608 return mcd_subchan(unit, (struct ioc_read_subchannel *) addr);
609 case CDIOREADTOCHEADER:
659 return mcd_subchan(unit, (struct ioc_read_subchannel *) addr);
660 case CDIOREADTOCHEADER:
610 if (!(cd->flags & MCDVALID))
611 return ENXIO;
612 return mcd_toc_header(unit, (struct ioc_toc_header *) addr);
613 case CDIOREADTOCENTRYS:
661 return mcd_toc_header(unit, (struct ioc_toc_header *) addr);
662 case CDIOREADTOCENTRYS:
614 if (!(cd->flags & MCDVALID))
615 return ENXIO;
616 return mcd_toc_entrys(unit, (struct ioc_read_toc_entry *) addr);
663 return mcd_toc_entrys(unit, (struct ioc_read_toc_entry *) addr);
617 case CDIOCSETPATCH:
618 case CDIOCGETVOL:
619 case CDIOCSETVOL:
620 case CDIOCSETMONO:
621 case CDIOCSETSTERIO:
622 case CDIOCSETMUTE:
623 case CDIOCSETLEFT:
624 case CDIOCSETRIGHT:
625 return EINVAL;
626 case CDIOCRESUME:
664 case CDIOCRESUME:
627 if (!(cd->flags & MCDVALID))
628 return ENXIO;
629 return mcd_resume(unit);
630 case CDIOCPAUSE:
665 return mcd_resume(unit);
666 case CDIOCPAUSE:
631 if (!(cd->flags & MCDVALID))
632 return ENXIO;
633 return mcd_pause(unit);
634 case CDIOCSTART:
667 return mcd_pause(unit);
668 case CDIOCSTART:
635 if (!(cd->flags & MCDVALID))
636 return ENXIO;
637 if (mcd_setmode(unit, MCD_MD_COOKED) != 0)
638 return EIO;
639 return 0;
640 case CDIOCSTOP:
669 if (mcd_setmode(unit, MCD_MD_COOKED) != 0)
670 return EIO;
671 return 0;
672 case CDIOCSTOP:
641 if (!(cd->flags & MCDVALID))
642 return ENXIO;
643 return mcd_stop(unit);
673 return mcd_stop(unit);
644 case CDIOCEJECT:
645 return mcd_eject(unit);
646 case CDIOCSETDEBUG:
647 cd->debug = 1;
648 return 0;
649 case CDIOCCLRDEBUG:
650 cd->debug = 0;
651 return 0;
652 case CDIOCRESET:
653 return mcd_hard_reset(unit);
654 case CDIOCALLOW:
655 return mcd_lock_door(unit, MCD_LK_UNLOCK);
656 case CDIOCPREVENT:
657 return mcd_lock_door(unit, MCD_LK_LOCK);
658 case CDIOCCLOSE:
659 return mcd_inject(unit);
660 default:
661 return ENOTTY;
662 }
663 /*NOTREACHED*/
664}
665
666/* this could have been taken from scsi/cd.c, but it is not clear
667 * whether the scsi cd driver is linked in

--- 649 unchanged lines hidden (view full) ---

1317}
1318
1319static void
1320mcd_soft_reset(int unit)
1321{
1322 struct mcd_data *cd = mcd_data + unit;
1323 int i;
1324
674 default:
675 return ENOTTY;
676 }
677 /*NOTREACHED*/
678}
679
680/* this could have been taken from scsi/cd.c, but it is not clear
681 * whether the scsi cd driver is linked in

--- 649 unchanged lines hidden (view full) ---

1331}
1332
1333static void
1334mcd_soft_reset(int unit)
1335{
1336 struct mcd_data *cd = mcd_data + unit;
1337 int i;
1338
1325 cd->openflags = 0;
1326 cd->flags &= (MCDINIT|MCDPROBING|MCDNEWMODEL);
1327 cd->curr_mode = MCD_MD_UNKNOWN;
1328 for (i=0; i<MAXPARTITIONS; i++) cd->partflags[i] = 0;
1329 cd->audio_status = CD_AS_AUDIO_INVALID;
1330}
1331
1332static int
1333mcd_setmode(int unit, int mode)

--- 496 unchanged lines hidden ---
1339 cd->flags &= (MCDINIT|MCDPROBING|MCDNEWMODEL);
1340 cd->curr_mode = MCD_MD_UNKNOWN;
1341 for (i=0; i<MAXPARTITIONS; i++) cd->partflags[i] = 0;
1342 cd->audio_status = CD_AS_AUDIO_INVALID;
1343}
1344
1345static int
1346mcd_setmode(int unit, int mode)

--- 496 unchanged lines hidden ---