Home | History | Annotate | Line # | Download | only in common
linux_cdrom.c revision 1.1
      1  1.1  christos /*	$NetBSD: linux_cdrom.c,v 1.1 1998/01/15 14:52:12 christos Exp $ */
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  1.1  christos  * All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * Redistribution and use in source and binary forms, with or without
      8  1.1  christos  * modification, are permitted provided that the following conditions
      9  1.1  christos  * are met:
     10  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  christos  *    documentation and/or other materials provided with the distribution.
     15  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     16  1.1  christos  *    must display the following acknowledgement:
     17  1.1  christos  *        This product includes software developed by the NetBSD
     18  1.1  christos  *        Foundation, Inc. and its contributors.
     19  1.1  christos  * 4. Neither the name of The NetBSD Foundation nor the names of its
     20  1.1  christos  *    contributors may be used to endorse or promote products derived
     21  1.1  christos  *    from this software without specific prior written permission.
     22  1.1  christos  *
     23  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     34  1.1  christos  */
     35  1.1  christos 
     36  1.1  christos #include <sys/param.h>
     37  1.1  christos #include <sys/systm.h>
     38  1.1  christos #include <sys/ioctl.h>
     39  1.1  christos #include <sys/file.h>
     40  1.1  christos #include <sys/filedesc.h>
     41  1.1  christos #include <sys/mount.h>
     42  1.1  christos #include <sys/proc.h>
     43  1.1  christos #include <sys/cdio.h>
     44  1.1  christos 
     45  1.1  christos #include <compat/linux/linux_types.h>
     46  1.1  christos #include <compat/linux/linux_ioctl.h>
     47  1.1  christos #include <compat/linux/linux_signal.h>
     48  1.1  christos #include <compat/linux/linux_syscallargs.h>
     49  1.1  christos #include <compat/linux/linux_util.h>
     50  1.1  christos #include <compat/linux/linux_cdrom.h>
     51  1.1  christos 
     52  1.1  christos #if 0
     53  1.1  christos #define DPRINTF(x) printf x
     54  1.1  christos #else
     55  1.1  christos #define DPRINTF(x)
     56  1.1  christos #endif
     57  1.1  christos 
     58  1.1  christos int
     59  1.1  christos linux_ioctl_cdrom(p, uap, retval)
     60  1.1  christos 	struct proc *p;
     61  1.1  christos 	struct linux_sys_ioctl_args /* {
     62  1.1  christos 		syscallarg(int) fd;
     63  1.1  christos 		syscallarg(u_long) com;
     64  1.1  christos 		syscallarg(caddr_t) data;
     65  1.1  christos 	} */ *uap;
     66  1.1  christos 	register_t *retval;
     67  1.1  christos {
     68  1.1  christos 	int error, idata;
     69  1.1  christos 	u_long com, ncom;
     70  1.1  christos 	caddr_t sg;
     71  1.1  christos 	struct file *fp;
     72  1.1  christos 	struct filedesc *fdp;
     73  1.1  christos 	int (*ioctlf) __P((struct file *, u_long, caddr_t, struct proc *));
     74  1.1  christos 
     75  1.1  christos 	struct linux_cdrom_blk l_blk;
     76  1.1  christos 	struct linux_cdrom_msf l_msf;
     77  1.1  christos 	struct linux_cdrom_ti l_ti;
     78  1.1  christos 	struct linux_cdrom_tochdr l_tochdr;
     79  1.1  christos 	struct linux_cdrom_tocentry l_tocentry;
     80  1.1  christos 	struct linux_cdrom_subchnl l_subchnl;
     81  1.1  christos 	struct linux_cdrom_volctrl l_volctrl;
     82  1.1  christos 
     83  1.1  christos 	struct ioc_play_blocks t_blocks;
     84  1.1  christos 	struct ioc_play_msf t_msf;
     85  1.1  christos 	struct ioc_play_track t_track;
     86  1.1  christos 	struct ioc_toc_header t_header;
     87  1.1  christos 	struct cd_toc_entry *entry, t_entry;
     88  1.1  christos 	struct ioc_read_toc_entry t_toc_entry;
     89  1.1  christos 	struct cd_sub_channel_info *info, t_info;
     90  1.1  christos 	struct ioc_read_subchannel t_subchannel;
     91  1.1  christos 	struct ioc_vol t_vol;
     92  1.1  christos 
     93  1.1  christos 	fdp = p->p_fd;
     94  1.1  christos 	if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
     95  1.1  christos 	    (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
     96  1.1  christos 		return (EBADF);
     97  1.1  christos 
     98  1.1  christos 	com = SCARG(uap, com);
     99  1.1  christos 	ioctlf = fp->f_ops->fo_ioctl;
    100  1.1  christos 	retval[0] = 0;
    101  1.1  christos 
    102  1.1  christos 	switch(com) {
    103  1.1  christos 	case LINUX_CDROMPLAYMSF:
    104  1.1  christos 		error = copyin(SCARG(uap, data), &l_msf, sizeof l_msf);
    105  1.1  christos 		if (error)
    106  1.1  christos 			return error;
    107  1.1  christos 
    108  1.1  christos 		t_msf.start_m = l_msf.cdmsf_min0;
    109  1.1  christos 		t_msf.start_s = l_msf.cdmsf_sec0;
    110  1.1  christos 		t_msf.start_f = l_msf.cdmsf_frame0;
    111  1.1  christos 		t_msf.end_m = l_msf.cdmsf_min1;
    112  1.1  christos 		t_msf.end_s = l_msf.cdmsf_sec1;
    113  1.1  christos 		t_msf.end_f = l_msf.cdmsf_frame1;
    114  1.1  christos 
    115  1.1  christos 		return ioctlf(fp, CDIOCPLAYMSF, (caddr_t)&t_msf, p);
    116  1.1  christos 
    117  1.1  christos 	case LINUX_CDROMPLAYTRKIND:
    118  1.1  christos 		error = copyin(SCARG(uap, data), &l_ti, sizeof l_ti);
    119  1.1  christos 		if (error)
    120  1.1  christos 			return error;
    121  1.1  christos 
    122  1.1  christos 		t_track.start_track = l_ti.cdti_trk0;
    123  1.1  christos 		t_track.start_index = l_ti.cdti_ind0;
    124  1.1  christos 		t_track.end_track = l_ti.cdti_trk1;
    125  1.1  christos 		t_track.end_index = l_ti.cdti_ind1;
    126  1.1  christos 
    127  1.1  christos 		return ioctlf(fp, CDIOCPLAYTRACKS, (caddr_t)&t_track, p);
    128  1.1  christos 
    129  1.1  christos 	case LINUX_CDROMREADTOCHDR:
    130  1.1  christos 		error = ioctlf(fp, CDIOREADTOCHEADER, (caddr_t)&t_header, p);
    131  1.1  christos 		if (error)
    132  1.1  christos 			return error;
    133  1.1  christos 
    134  1.1  christos 		l_tochdr.cdth_trk0 = t_header.starting_track;
    135  1.1  christos 		l_tochdr.cdth_trk1 = t_header.ending_track;
    136  1.1  christos 
    137  1.1  christos 		return copyout(&l_tochdr, SCARG(uap, data), sizeof l_tochdr);
    138  1.1  christos 
    139  1.1  christos 	case LINUX_CDROMREADTOCENTRY:
    140  1.1  christos 		error = copyin(SCARG(uap, data), &l_tocentry,
    141  1.1  christos 			       sizeof l_tocentry);
    142  1.1  christos 		if (error)
    143  1.1  christos 			return error;
    144  1.1  christos 
    145  1.1  christos 		sg = stackgap_init(p->p_emul);
    146  1.1  christos 		entry = stackgap_alloc(&sg, sizeof *entry);
    147  1.1  christos 		t_toc_entry.address_format = l_tocentry.cdte_format;
    148  1.1  christos 		t_toc_entry.starting_track = l_tocentry.cdte_track;
    149  1.1  christos 		t_toc_entry.data_len = sizeof *entry;
    150  1.1  christos 		t_toc_entry.data = entry;
    151  1.1  christos 
    152  1.1  christos 		error = ioctlf(fp, CDIOREADTOCENTRYS, (caddr_t)&t_toc_entry,
    153  1.1  christos 			       p);
    154  1.1  christos 		if (error)
    155  1.1  christos 			return error;
    156  1.1  christos 
    157  1.1  christos 		error = copyin(entry, &t_entry, sizeof t_entry);
    158  1.1  christos 		if (error)
    159  1.1  christos 			return error;
    160  1.1  christos 
    161  1.1  christos 		l_tocentry.cdte_adr = t_entry.addr_type;
    162  1.1  christos 		l_tocentry.cdte_ctrl = t_entry.control;
    163  1.1  christos 		switch (t_toc_entry.address_format) {
    164  1.1  christos 		case CD_LBA_FORMAT:
    165  1.1  christos 			l_tocentry.cdte_addr.lba = t_entry.addr.lba;
    166  1.1  christos 			break;
    167  1.1  christos 		case CD_MSF_FORMAT:
    168  1.1  christos 			l_tocentry.cdte_addr.msf.minute =
    169  1.1  christos 			    t_entry.addr.msf.minute;
    170  1.1  christos 			l_tocentry.cdte_addr.msf.second =
    171  1.1  christos 			    t_entry.addr.msf.second;
    172  1.1  christos 			l_tocentry.cdte_addr.msf.frame =
    173  1.1  christos 			    t_entry.addr.msf.frame;
    174  1.1  christos 			break;
    175  1.1  christos 		default:
    176  1.1  christos 			printf("linux_ioctl: unknown format msf/lba\n");
    177  1.1  christos 			return EINVAL;
    178  1.1  christos 		}
    179  1.1  christos 
    180  1.1  christos 		return copyout(&l_tocentry, SCARG(uap, data),
    181  1.1  christos 			       sizeof l_tocentry);
    182  1.1  christos 
    183  1.1  christos 	case LINUX_CDROMVOLCTRL:
    184  1.1  christos 		error = copyin(SCARG(uap, data), &l_volctrl, sizeof l_volctrl);
    185  1.1  christos 		if (error)
    186  1.1  christos 			return error;
    187  1.1  christos 
    188  1.1  christos 		t_vol.vol[0] = l_volctrl.channel0;
    189  1.1  christos 		t_vol.vol[1] = l_volctrl.channel1;
    190  1.1  christos 		t_vol.vol[2] = l_volctrl.channel2;
    191  1.1  christos 		t_vol.vol[3] = l_volctrl.channel3;
    192  1.1  christos 
    193  1.1  christos 		return ioctlf(fp, CDIOCSETVOL, (caddr_t)&t_vol, p);
    194  1.1  christos 
    195  1.1  christos 	case LINUX_CDROMVOLREAD:
    196  1.1  christos 		error = ioctlf(fp, CDIOCGETVOL, (caddr_t)&t_vol, p);
    197  1.1  christos 		if (error)
    198  1.1  christos 			return error;
    199  1.1  christos 
    200  1.1  christos 		l_volctrl.channel0 = t_vol.vol[0];
    201  1.1  christos 		l_volctrl.channel1 = t_vol.vol[1];
    202  1.1  christos 		l_volctrl.channel2 = t_vol.vol[2];
    203  1.1  christos 		l_volctrl.channel3 = t_vol.vol[3];
    204  1.1  christos 
    205  1.1  christos 		return copyout(&l_volctrl, SCARG(uap, data), sizeof l_volctrl);
    206  1.1  christos 
    207  1.1  christos 	case LINUX_CDROMSUBCHNL:
    208  1.1  christos 		error = copyin(SCARG(uap, data), &l_subchnl, sizeof l_subchnl);
    209  1.1  christos 		if (error)
    210  1.1  christos 			return error;
    211  1.1  christos 
    212  1.1  christos 		sg = stackgap_init(p->p_emul);
    213  1.1  christos 		info = stackgap_alloc(&sg, sizeof *info);
    214  1.1  christos 		t_subchannel.address_format = l_subchnl.cdsc_format;
    215  1.1  christos 		t_subchannel.data_format = CD_CURRENT_POSITION;
    216  1.1  christos 		t_subchannel.track = l_subchnl.cdsc_trk;
    217  1.1  christos 		t_subchannel.data_len = sizeof *info;
    218  1.1  christos 		t_subchannel.data = info;
    219  1.1  christos 		DPRINTF(("linux_ioctl: CDROMSUBCHNL %d %d\n",
    220  1.1  christos 			 l_subchnl.cdsc_format, l_subchnl.cdsc_trk));
    221  1.1  christos 
    222  1.1  christos 		error = ioctlf(fp, CDIOCREADSUBCHANNEL, (caddr_t)&t_subchannel,
    223  1.1  christos 			       p);
    224  1.1  christos 		if (error)
    225  1.1  christos 		    return error;
    226  1.1  christos 
    227  1.1  christos 		error = copyin(info, &t_info, sizeof t_info);
    228  1.1  christos 		if (error)
    229  1.1  christos 			return error;
    230  1.1  christos 
    231  1.1  christos 	    l_subchnl.cdsc_audiostatus = t_info.header.audio_status;
    232  1.1  christos 	    l_subchnl.cdsc_adr = t_info.what.position.addr_type;
    233  1.1  christos 	    l_subchnl.cdsc_ctrl = t_info.what.position.control;
    234  1.1  christos 	    l_subchnl.cdsc_ind = t_info.what.position.index_number;
    235  1.1  christos 
    236  1.1  christos 	    DPRINTF(("linux_ioctl: CDIOCREADSUBCHANNEL %d %d %d\n",
    237  1.1  christos 		     t_info.header.audio_status,
    238  1.1  christos 		     t_info.header.data_len[0],
    239  1.1  christos 		     t_info.header.data_len[1]));
    240  1.1  christos 	    DPRINTF(("(more) %d %d %d %d %d\n",
    241  1.1  christos 		     t_info.what.position.data_format,
    242  1.1  christos 		     t_info.what.position.control,
    243  1.1  christos 		     t_info.what.position.addr_type,
    244  1.1  christos 		     t_info.what.position.track_number,
    245  1.1  christos 		     t_info.what.position.index_number));
    246  1.1  christos 
    247  1.1  christos 	    switch (t_subchannel.address_format) {
    248  1.1  christos 	    case CD_LBA_FORMAT:
    249  1.1  christos 		    l_subchnl.cdsc_absaddr.lba =
    250  1.1  christos 			t_info.what.position.absaddr.lba;
    251  1.1  christos 		    l_subchnl.cdsc_reladdr.lba =
    252  1.1  christos 			t_info.what.position.reladdr.lba;
    253  1.1  christos 		    DPRINTF(("LBA: %d %d\n",
    254  1.1  christos 			     t_info.what.position.absaddr.lba,
    255  1.1  christos 			     t_info.what.position.reladdr.lba));
    256  1.1  christos 		    break;
    257  1.1  christos 
    258  1.1  christos 	    case CD_MSF_FORMAT:
    259  1.1  christos 		    l_subchnl.cdsc_absaddr.msf.minute =
    260  1.1  christos 			t_info.what.position.absaddr.msf.minute;
    261  1.1  christos 		    l_subchnl.cdsc_absaddr.msf.second =
    262  1.1  christos 			t_info.what.position.absaddr.msf.second;
    263  1.1  christos 		    l_subchnl.cdsc_absaddr.msf.frame =
    264  1.1  christos 			t_info.what.position.absaddr.msf.frame;
    265  1.1  christos 
    266  1.1  christos 		    l_subchnl.cdsc_reladdr.msf.minute =
    267  1.1  christos 			t_info.what.position.reladdr.msf.minute;
    268  1.1  christos 		    l_subchnl.cdsc_reladdr.msf.second =
    269  1.1  christos 			t_info.what.position.reladdr.msf.second;
    270  1.1  christos 		    l_subchnl.cdsc_reladdr.msf.frame =
    271  1.1  christos 			t_info.what.position.reladdr.msf.frame;
    272  1.1  christos 		    DPRINTF(("MSF: %d %d %d %d\n",
    273  1.1  christos 			     t_info.what.position.absaddr.msf.minute,
    274  1.1  christos 			     t_info.what.position.absaddr.msf.second,
    275  1.1  christos 			     t_info.what.position.reladdr.msf.minute,
    276  1.1  christos 			     t_info.what.position.reladdr.msf.second));
    277  1.1  christos 		    break;
    278  1.1  christos 
    279  1.1  christos 	    default:
    280  1.1  christos 		    printf("linux_ioctl: unknown format msf/lba\n");
    281  1.1  christos 		    return EINVAL;
    282  1.1  christos 	    }
    283  1.1  christos 
    284  1.1  christos 	    return copyout(&l_subchnl, SCARG(uap, data), sizeof l_subchnl);
    285  1.1  christos 
    286  1.1  christos 	case LINUX_CDROMPLAYBLK:
    287  1.1  christos 		error = copyin(SCARG(uap, data), &l_blk, sizeof l_blk);
    288  1.1  christos 		if (error)
    289  1.1  christos 			return error;
    290  1.1  christos 
    291  1.1  christos 		t_blocks.blk = l_blk.from;
    292  1.1  christos 		t_blocks.len = l_blk.len;
    293  1.1  christos 
    294  1.1  christos 		return ioctlf(fp, CDIOCPLAYBLOCKS, (caddr_t)&t_blocks, p);
    295  1.1  christos 
    296  1.1  christos 	case LINUX_CDROMEJECT_SW:
    297  1.1  christos 		error = copyin(SCARG(uap, data), &idata, sizeof idata);
    298  1.1  christos 		if (error)
    299  1.1  christos 			return error;
    300  1.1  christos 
    301  1.1  christos 		if (idata == 1)
    302  1.1  christos 			ncom = CDIOCALLOW;
    303  1.1  christos 		else
    304  1.1  christos 			ncom = CDIOCPREVENT;
    305  1.1  christos 		break;
    306  1.1  christos 
    307  1.1  christos 	case LINUX_CDROMPAUSE:
    308  1.1  christos 		ncom = CDIOCPAUSE;
    309  1.1  christos 		break;
    310  1.1  christos 
    311  1.1  christos 	case LINUX_CDROMRESUME:
    312  1.1  christos 		ncom = CDIOCRESUME;
    313  1.1  christos 		break;
    314  1.1  christos 
    315  1.1  christos 	case LINUX_CDROMSTOP:
    316  1.1  christos 		ncom = CDIOCSTOP;
    317  1.1  christos 		break;
    318  1.1  christos 
    319  1.1  christos 	case LINUX_CDROMSTART:
    320  1.1  christos 		ncom = CDIOCSTART;
    321  1.1  christos 		break;
    322  1.1  christos 
    323  1.1  christos 	case LINUX_CDROMEJECT:
    324  1.1  christos 		ncom = CDIOCEJECT;
    325  1.1  christos 		break;
    326  1.1  christos 
    327  1.1  christos 	case LINUX_CDROMRESET:
    328  1.1  christos 		ncom = CDIOCRESET;
    329  1.1  christos 		break;
    330  1.1  christos 
    331  1.1  christos 	default:
    332  1.1  christos 		printf("linux_ioctl: unimplemented ioctl %08lx\n", com);
    333  1.1  christos 		return EINVAL;
    334  1.1  christos 	}
    335  1.1  christos 
    336  1.1  christos 	return ioctlf(fp, ncom, NULL, p);
    337  1.1  christos }
    338