245 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
247 #define REVISION "Revision: 3.20"
248 #define VERSION "Id: cdrom.c 3.20 2003/12/17"
252 #define CD_NOTHING 0x0
253 #define CD_WARNING 0x1
254 #define CD_REG_UNREG 0x2
255 #define CD_DO_IOCTL 0x4
257 #define CD_CLOSE 0x10
258 #define CD_COUNT_TRACKS 0x20
259 #define CD_CHANGER 0x40
264 #define ERRLOGMASK CD_WARNING
268 #include <linux/module.h>
269 #include <linux/fs.h>
271 #include <linux/types.h>
272 #include <linux/errno.h>
273 #include <linux/kernel.h>
275 #include <linux/slab.h>
276 #include <linux/cdrom.h>
277 #include <linux/sysctl.h>
281 #include <linux/fcntl.h>
285 #include <asm/uaccess.h>
290 static bool autoclose=1;
291 static bool autoeject;
292 static bool lockdoor = 1;
294 static bool check_media_type;
296 static bool mrw_format_restart = 1;
306 static const char *mrw_format_status[] = {
313 static const char *mrw_address_space[] = {
"DMA",
"GAA" };
315 #if (ERRLOGMASK!=CD_NOTHING)
316 #define cdinfo(type, fmt, args...) \
318 if ((ERRLOGMASK & type) || debug == 1) \
319 pr_info(fmt, ##args); \
322 #define cdinfo(type, fmt, args...) \
324 if (0 && (ERRLOGMASK & type) || debug == 1) \
325 pr_info(fmt, ##args); \
330 #define IOCTL_IN(arg, type, in) \
331 if (copy_from_user(&(in), (type __user *) (arg), sizeof (in))) \
334 #define IOCTL_OUT(arg, type, out) \
335 if (copy_to_user((type __user *) (arg), &(out), sizeof (out))) \
340 #define CDROM_CAN(type) (cdi->ops->capability & ~cdi->mask & (type))
343 #define CHECKAUDIO if ((ret=check_for_audio_disc(cdi, cdo))) return ret
349 #define CDROM_DEF_TIMEOUT (7 * HZ)
368 static void cdrom_sysctl_register(
void);
376 cgc->
sense->sense_key = 0x05;
377 cgc->
sense->asc = 0x20;
378 cgc->
sense->ascq = 0x00;
390 #define ENSURE(call, bits) if (cdo->call == NULL) *change_capability &= ~(bits)
394 static char banner_printed;
396 int *change_capability = (
int *)&cdo->
capability;
402 if (!banner_printed) {
405 cdrom_sysctl_register();
428 if (check_media_type==1)
432 cdi->
exit = cdrom_mrw_exit;
444 list_add(&cdi->
list, &cdrom_list);
461 cdi->
ops->n_minors--;
479 if (cdi->
ops->generic_packet(cdi, &cgc))
485 if (eh->nea || eh->notification_class != 0x4)
488 memcpy(med, &buffer[
sizeof(*eh)],
sizeof(*med));
521 unsigned char buffer[16];
533 if ((ret = cdi->
ops->generic_packet(cdi, &cgc)))
541 if ((ret = cdrom_mrw_probe_pc(cdi))) {
552 unsigned char buffer[12];
555 pr_info(
"%sstarting format\n", cont ?
"Re" :
"");
562 cgc.
cmd[1] = (1 << 4) | 1;
580 buffer[8] = 0x24 << 2;
583 ret = cdi->
ops->generic_packet(cdi, &cgc);
600 cgc.
cmd[1] = !!immed;
605 return cdi->
ops->generic_packet(cdi, &cgc);
617 return cdi->
ops->generic_packet(cdi, &cgc);
625 ret = cdrom_get_disc_info(cdi, &di);
631 pr_info(
"issuing MRW background format suspend\n");
632 ret = cdrom_mrw_bgformat_susp(cdi, 0);
636 ret = cdrom_flush_cache(cdi);
660 buffer[offset + 3] = space;
666 pr_info(
"%s: mrw address space %s selected\n",
667 cdi->
name, mrw_address_space[space]);
685 if ((ret = cdi->
ops->generic_packet(cdi, &cgc)))
706 if ((ret = cdi->
ops->generic_packet(cdi, &cgc)))
724 if ((ret = cdrom_get_random_writable(cdi, &rfd)))
738 ret = cdrom_get_disc_info(cdi, &di);
750 int ret = cdrom_media_erasable(cdi);
771 pr_err(
"failed setting lba address space\n");
775 ret = cdrom_get_disc_info(cdi, &di);
790 pr_info(
"open: mrw_status '%s'\n", mrw_format_status[di.mrw_status]);
795 ret = cdrom_mrw_bgformat(cdi, 1);
826 return buffer[3] & 0x80;
834 if ((ret = cdrom_has_defect_mgt(cdi)))
837 if ((ret = cdrom_get_random_writable(cdi, &rfd)))
850 int ret, mmc3_profile;
856 cgc.
cmd[2] = cgc.
cmd[3] = 0;
860 if ((ret = cdi->
ops->generic_packet(cdi, &cgc)))
861 mmc3_profile = 0xffff;
863 mmc3_profile = (buffer[6] << 8) | buffer[7];
884 int mrw, mrw_write, ram_write;
888 if (!cdrom_is_mrw(cdi, &mrw_write))
894 (
void) cdrom_is_random_writable(cdi, &ram_write);
912 ret = cdrom_mrw_open_write(cdi);
914 ret = cdrom_dvdram_open_write(cdi);
917 ret = cdrom_ram_open_write(cdi);
919 ret = mo_open_write(cdi);
920 else if (!cdrom_is_dvd_rw(cdi))
940 pr_info(
"%s: dirty DVD+RW media, \"finalizing\"\n", cdi->
name);
945 cdi->
ops->generic_packet(cdi, &cgc);
951 cdi->
ops->generic_packet(cdi, &cgc);
958 cdi->
ops->generic_packet(cdi, &cgc);
966 return cdrom_flush_cache(cdi);
993 ret = cdi->
ops->open(cdi, 1);
995 ret = open_for_data(cdi);
998 cdrom_mmc3_profile(cdi);
1001 if (cdrom_open_write(cdi))
1018 cdi->
ops->lock_door(cdi, 0);
1021 cdi->
ops->release(cdi);
1047 cdinfo(
CD_OPEN,
"bummer. tried to close the tray but failed.\n");
1054 goto clean_up_and_return;
1057 cdinfo(
CD_OPEN,
"bummer. this drive can't close the tray.\n");
1059 goto clean_up_and_return;
1067 goto clean_up_and_return;
1075 goto clean_up_and_return;
1078 cdrom_count_tracks(cdi, &tracks);
1082 goto clean_up_and_return;
1086 if (tracks.
data==0) {
1092 (
unsigned int)task_pid_nr(
current));
1094 goto clean_up_and_return;
1097 cdinfo(
CD_OPEN,
"wrong media type, but CDO_CHECK_TYPE not set.\n");
1104 ret = cdo->
open(cdi, 0);
1111 goto clean_up_and_return;
1125 clean_up_and_return:
1156 cdinfo(
CD_OPEN,
"bummer. tried to close tray but failed.\n");
1165 cdinfo(
CD_OPEN,
"bummer. this driver can't close the tray.\n");
1181 cdrom_count_tracks(cdi, &tracks);
1183 return(tracks.
error);
1185 if (tracks.
audio==0)
1194 int opened_for_data;
1203 cdrom_dvd_rw_close_write(cdi);
1218 cdrom_close_write(cdi);
1222 if (opened_for_data &&
1241 buf->
hdr.nslots = 3;
1243 for (length = 0; length < 3; length++) {
1255 cgc.
cmd[8] = (length >> 8) & 0xff;
1256 cgc.
cmd[9] = length & 0xff;
1273 if ((ret = cdrom_read_mech_status(cdi, info)))
1276 if (info->
slots[slot].disc_present)
1303 if ((status = cdrom_read_mech_status(cdi, info)) == 0)
1304 nslots = info->
hdr.nslots;
1322 cgc.
cmd[4] = 2 + (slot >= 0);
1332 cgc.
cmd[4] = cgc.
cmd[8] = 0;
1336 return cdi->
ops->generic_packet(cdi, &cgc);
1349 if (cdi->
ops->check_events)
1350 cdi->
ops->check_events(cdi, 0, slot);
1352 cdi->
ops->media_changed(cdi, slot);
1357 return cdrom_load_unload(cdi, -1);
1364 if ((ret = cdrom_read_mech_status(cdi, info))) {
1369 curslot = info->
hdr.curslot;
1390 if ((ret = cdrom_load_unload(cdi, slot)))
1411 unsigned int clearing)
1421 unsigned int clearing)
1425 cdrom_update_events(cdi, clearing);
1441 unsigned int mask = (1 << (queue & 1));
1449 if (cdi->
ops->check_events) {
1451 cdrom_update_events(cdi, DISK_EVENT_MEDIA_CHANGE);
1472 if (cdi ==
NULL || cdi->
ops->media_changed ==
NULL)
1476 return media_changed(cdi, 0);
1501 for (i =
header.cdth_trk0; i <=
header.cdth_trk1; i++) {
1508 if (
entry.cdte_format == 0x10)
1510 else if (
entry.cdte_format == 0x20)
1521 tracks->
cdi, tracks->
xa);
1544 if (*curr == requested)
1548 75 * (addr->
msf.second - 2 + 60 * addr->
msf.minute);
1551 addr->
msf.frame = lba % 75;
1554 addr->
msf.second = lba % 60;
1555 addr->
msf.minute = lba / 60;
1566 cgc->
buffer = (
char *) buf;
1574 #define copy_key(dest,src) memcpy((dest), (src), sizeof(dvd_key))
1575 #define copy_chal(dest,src) memcpy((dest), (src), sizeof(dvd_challenge))
1577 static void setup_report_key(
struct packet_command *cgc,
unsigned agid,
unsigned type)
1580 cgc->
cmd[10] = type | (agid << 6);
1582 case 0:
case 8:
case 5: {
1602 cgc->
cmd[10] = type | (agid << 6);
1629 memset(buf, 0,
sizeof(buf));
1637 setup_report_key(&cgc, ai->
lsa.agid, 0);
1642 ai->
lsa.agid = buf[7] >> 6;
1648 setup_report_key(&cgc, ai->
lsk.agid, 2);
1659 setup_report_key(&cgc, ai->
lsc.agid, 1);
1672 setup_report_key(&cgc, ai->
lstk.agid, 4);
1674 cgc.
cmd[4] = ai->
lstk.lba >> 8;
1675 cgc.
cmd[3] = ai->
lstk.lba >> 16;
1676 cgc.
cmd[2] = ai->
lstk.lba >> 24;
1681 ai->
lstk.cpm = (buf[4] >> 7) & 1;
1682 ai->
lstk.cp_sec = (buf[4] >> 6) & 1;
1683 ai->
lstk.cgms = (buf[4] >> 4) & 3;
1690 setup_report_key(&cgc, ai->
lsasf.agid, 5);
1695 ai->
lsasf.asf = buf[7] & 1;
1701 setup_send_key(&cgc, ai->
hsc.agid, 1);
1713 setup_send_key(&cgc, ai->
hsk.agid, 3);
1728 setup_report_key(&cgc, ai->
lsa.agid, 0x3f);
1736 setup_report_key(&cgc, 0, 8);
1738 cgc.
buffer = (
char *) &rpc_state;
1743 ai->
lrpcs.type = rpc_state.type_code;
1744 ai->
lrpcs.vra = rpc_state.vra;
1745 ai->
lrpcs.ucca = rpc_state.ucca;
1753 setup_send_key(&cgc, 0, 6);
1755 buf[4] = ai->
hrpcs.pdrc;
1772 unsigned char buf[21], *
base;
1782 cgc->
cmd[6] = layer_num;
1796 layer = &s->
physical.layer[layer_num];
1802 memset(layer, 0,
sizeof(*layer));
1809 layer->
nlayers = (base[2] >> 5) & 3;
1812 layer->
start_sector = base[5] << 16 | base[6] << 8 | base[7];
1813 layer->
end_sector = base[9] << 16 | base[10] << 8 | base[11];
1814 layer->
end_sector_l0 = base[13] << 16 | base[14] << 8 | base[15];
1815 layer->
bca = base[16] >> 7;
1851 size =
sizeof(s->
disckey.value) + 4;
1860 cgc->
cmd[8] = size >> 8;
1861 cgc->
cmd[9] = size & 0xff;
1875 int ret, size = 4 + 188;
1892 s->
bca.len = buf[0] << 8 | buf[1];
1893 if (s->
bca.len < 12 || s->
bca.len > 188) {
1912 size =
sizeof(s->
manufact.value) + 4;
1921 cgc->
cmd[8] = size >> 8;
1922 cgc->
cmd[9] = size & 0xff;
1928 s->
manufact.len = buf[0] << 8 | buf[1];
1936 "length (%d): truncating to 2048\n",
1953 return dvd_read_physical(cdi, s, cgc);
1956 return dvd_read_copyright(cdi, s, cgc);
1959 return dvd_read_disckey(cdi, s, cgc);
1962 return dvd_read_bca(cdi, s, cgc);
1965 return dvd_read_manufact(cdi, s, cgc);
1983 cgc->
cmd[2] = page_code | (page_control << 6);
2017 cgc.
cmd[3] = mcn ? 2 : 1;
2044 int blocksize,
int nblocks)
2050 cgc->
cmd[2] = (lba >> 24) & 0xff;
2051 cgc->
cmd[3] = (lba >> 16) & 0xff;
2052 cgc->
cmd[4] = (lba >> 8) & 0xff;
2053 cgc->
cmd[5] = lba & 0xff;
2054 cgc->
cmd[6] = (nblocks >> 16) & 0xff;
2055 cgc->
cmd[7] = (nblocks >> 8) & 0xff;
2056 cgc->
cmd[8] = nblocks & 0xff;
2057 cgc->
buflen = blocksize * nblocks;
2064 int lba,
int nblocks,
int format,
int blksize)
2071 cgc->
cmd[1] = format << 2;
2073 cgc->
cmd[2] = (lba >> 24) & 0xff;
2074 cgc->
cmd[3] = (lba >> 16) & 0xff;
2075 cgc->
cmd[4] = (lba >> 8) & 0xff;
2076 cgc->
cmd[5] = lba & 0xff;
2078 cgc->
cmd[6] = (nblocks >> 16) & 0xff;
2079 cgc->
cmd[7] = (nblocks >> 8) & 0xff;
2080 cgc->
cmd[8] = nblocks & 0xff;
2081 cgc->
buflen = blksize * nblocks;
2088 default : cgc->
cmd[9] = 0x10;
2095 int lba,
int nframes)
2103 memset(&cgc, 0,
sizeof(cgc));
2121 while (nframes > 0) {
2141 int lba,
int nframes)
2176 rq->cmd[1] = 1 << 2;
2177 rq->cmd[2] = (lba >> 24) & 0xff;
2178 rq->cmd[3] = (lba >> 16) & 0xff;
2179 rq->cmd[4] = (lba >> 8) & 0xff;
2180 rq->cmd[5] = lba & 0xff;
2181 rq->cmd[6] = (nr >> 16) & 0xff;
2182 rq->cmd[7] = (nr >> 8) & 0xff;
2183 rq->cmd[8] = nr & 0xff;
2187 rq->cmd_type = REQ_TYPE_BLOCK_PC;
2188 rq->timeout = 60 *
HZ;
2213 int lba,
int nframes)
2218 return cdrom_read_cdda_old(cdi, ubuf, lba, nframes);
2224 ret = cdrom_read_cdda_bpc(cdi, ubuf, lba, nframes);
2225 if (!ret || ret != -
EIO)
2233 pr_info(
"dropping to single frame dma\n");
2248 return cdrom_read_cdda_old(cdi, ubuf, lba, nframes);
2255 u8 requested_format;
2266 requested_format =
ms_info.addr_format;
2271 ret = cdi->
ops->get_last_session(cdi, &
ms_info);
2275 sanitize_format(&
ms_info.addr, &
ms_info.addr_format, requested_format);
2293 int ret = cdi->
ops->lock_door(cdi, 0);
2298 return cdi->
ops->tray_move(cdi, 1);
2307 return cdi->
ops->tray_move(cdi, 0);
2339 return media_changed(cdi, 1);
2341 if ((
unsigned int)arg >= cdi->
capacity)
2348 ret = cdrom_read_mech_status(cdi, info);
2399 return cdi->
ops->select_speed(cdi, arg);
2420 if (cdi->
ops->select_disc)
2421 return cdi->
ops->select_disc(cdi, arg);
2424 return cdrom_select_disc(cdi, arg);
2437 return cdi->
ops->reset(cdi);
2456 return cdi->
ops->lock_door(cdi, arg);
2466 debug = arg ? 1 : 0;
2473 return (cdi->
ops->capability & ~cdi->
mask);
2492 ret = cdi->
ops->get_mcn(cdi, &mcn);
2514 return cdrom_slot_status(cdi, arg);
2540 cdrom_count_tracks(cdi, &tracks);
2542 return tracks.
error;
2545 if (tracks.
audio > 0) {
2546 if (!tracks.
data && !tracks.
cdi && !tracks.
xa)
2556 if (tracks.
data > 0)
2582 requested = q.cdsc_format;
2591 back = q.cdsc_format;
2592 sanitize_format(&q.cdsc_absaddr, &back, requested);
2593 sanitize_format(&q.cdsc_reladdr, &q.cdsc_format, requested);
2626 u8 requested_format;
2634 requested_format =
entry.cdte_format;
2642 sanitize_format(&
entry.cdte_addr, &
entry.cdte_format, requested_format);
2677 ret = check_for_audio_disc(cdi, cdi->
ops);
2725 ret = check_for_audio_disc(cdi, cdi->
ops);
2728 return cdi->
ops->audio_ioctl(cdi, cmd,
NULL);
2737 fmode_t mode,
unsigned int cmd,
unsigned long arg)
2751 return cdrom_ioctl_multisession(cdi, argp);
2753 return cdrom_ioctl_eject(cdi);
2755 return cdrom_ioctl_closetray(cdi);
2757 return cdrom_ioctl_eject_sw(cdi, arg);
2759 return cdrom_ioctl_media_changed(cdi, arg);
2761 return cdrom_ioctl_set_options(cdi, arg);
2763 return cdrom_ioctl_clear_options(cdi, arg);
2765 return cdrom_ioctl_select_speed(cdi, arg);
2767 return cdrom_ioctl_select_disc(cdi, arg);
2769 return cdrom_ioctl_reset(cdi, bdev);
2771 return cdrom_ioctl_lock_door(cdi, arg);
2773 return cdrom_ioctl_debug(cdi, arg);
2775 return cdrom_ioctl_get_capability(cdi);
2777 return cdrom_ioctl_get_mcn(cdi, argp);
2779 return cdrom_ioctl_drive_status(cdi, arg);
2781 return cdrom_ioctl_disc_status(cdi);
2783 return cdrom_ioctl_changer_nslots(cdi);
2793 ret = mmc_ioctl(cdi, cmd, arg);
2805 return cdrom_ioctl_get_subchnl(cdi, argp);
2807 return cdrom_ioctl_read_tochdr(cdi, argp);
2809 return cdrom_ioctl_read_tocentry(cdi, argp);
2811 return cdrom_ioctl_play_msf(cdi, argp);
2813 return cdrom_ioctl_play_trkind(cdi, argp);
2815 return cdrom_ioctl_volctrl(cdi, argp);
2817 return cdrom_ioctl_volread(cdi, argp);
2822 return cdrom_ioctl_audioctl(cdi, cmd);
2838 memset(&mh, 0,
sizeof(mh));
2839 mh.block_desc_length = 0x08;
2840 mh.block_length_med = (size >> 8) & 0xff;
2841 mh.block_length_lo = size & 0xff;
2843 memset(&cgc, 0,
sizeof(cgc));
2845 cgc.
cmd[1] = 1 << 4;
2848 cgc.
buffer = (
char *) &mh;
2850 mh.block_desc_length = 0x08;
2851 mh.block_length_med = (size >> 8) & 0xff;
2852 mh.block_length_lo = size & 0xff;
2864 int blocksize = 0, format = 0,
lba;
2880 lba = msf_to_lba(msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0);
2892 ret = cdrom_read_block(cdi, cgc, lba, 1, format, blocksize);
2893 if (ret &&
sense.sense_key == 0x05 &&
2894 sense.asc == 0x20 &&
2895 sense.ascq == 0x00) {
2901 ret = cdrom_switch_blocksize(cdi, blocksize);
2905 ret = cdrom_read_cd(cdi, cgc, lba, blocksize, 1);
2906 ret |= cdrom_switch_blocksize(cdi, blocksize);
2924 lba = msf_to_lba(
ra.addr.msf.minute,
2936 return cdrom_read_cdda(cdi,
ra.buf, lba,
ra.nframes);
2946 requested = q.cdsc_format;
2951 ret = cdrom_read_subchannel(cdi, &q, 0);
2954 back = q.cdsc_format;
2955 sanitize_format(&q.cdsc_absaddr, &back, requested);
2956 sanitize_format(&q.cdsc_reladdr, &q.cdsc_format, requested);
2971 cgc->
cmd[3] = msf.cdmsf_min0;
2972 cgc->
cmd[4] = msf.cdmsf_sec0;
2973 cgc->
cmd[5] = msf.cdmsf_frame0;
2974 cgc->
cmd[6] = msf.cdmsf_min1;
2975 cgc->
cmd[7] = msf.cdmsf_sec1;
2976 cgc->
cmd[8] = msf.cdmsf_frame1;
2990 cgc->
cmd[2] = (
blk.from >> 24) & 0xff;
2991 cgc->
cmd[3] = (
blk.from >> 16) & 0xff;
2992 cgc->
cmd[4] = (
blk.from >> 8) & 0xff;
2993 cgc->
cmd[5] =
blk.from & 0xff;
2994 cgc->
cmd[7] = (
blk.len >> 8) & 0xff;
2995 cgc->
cmd[8] =
blk.len & 0xff;
3006 unsigned char buffer[32];
3007 char mask[
sizeof(
buffer)];
3027 if (offset + 16 >
sizeof(buffer))
3030 if (offset + 16 > cgc->
buflen) {
3031 cgc->
buflen = offset + 16;
3040 buffer[offset + 1] < 14)
3046 volctrl.channel0 = buffer[offset+9];
3047 volctrl.channel1 = buffer[offset+11];
3048 volctrl.channel2 = buffer[offset+13];
3049 volctrl.channel3 = buffer[offset+15];
3060 buffer[offset + 9] = volctrl.channel0 & mask[offset + 9];
3061 buffer[offset + 11] = volctrl.channel1 & mask[offset + 11];
3062 buffer[offset + 13] = volctrl.channel2 & mask[offset + 13];
3063 buffer[offset + 15] = volctrl.channel3 & mask[offset + 15];
3066 cgc->
buffer = buffer + offset - 8;
3117 ret = dvd_read_struct(cdi, s, cgc);
3137 ret = dvd_do_auth(cdi, &ai);
3150 ret = cdrom_get_next_writable(cdi, &next);
3176 memset(&cgc, 0,
sizeof(cgc));
3184 return mmc_ioctl_cdrom_read_data(cdi, userptr, &cgc, cmd);
3186 return mmc_ioctl_cdrom_read_audio(cdi, userptr);
3188 return mmc_ioctl_cdrom_subchannel(cdi, userptr);
3190 return mmc_ioctl_cdrom_play_msf(cdi, userptr, &cgc);
3192 return mmc_ioctl_cdrom_play_blk(cdi, userptr, &cgc);
3195 return mmc_ioctl_cdrom_volume(cdi, userptr, &cgc, cmd);
3198 return mmc_ioctl_cdrom_start_stop(cdi, &cgc, cmd);
3201 return mmc_ioctl_cdrom_pause_resume(cdi, &cgc, cmd);
3203 return mmc_ioctl_dvd_read_struct(cdi, userptr, &cgc);
3205 return mmc_ioctl_dvd_auth(cdi, userptr);
3207 return mmc_ioctl_cdrom_next_writable(cdi, userptr);
3209 return mmc_ioctl_cdrom_last_written(cdi, userptr);
3224 cgc.
cmd[1] = type & 3;
3225 cgc.
cmd[4] = (track & 0xff00) >> 8;
3226 cgc.
cmd[5] = track & 0xff;
3288 int ret = -1, ti_size;
3293 ret = cdrom_get_disc_info(cdi, &di);
3295 +
sizeof(di.last_track_lsb)))
3299 last_track = (di.last_track_msb << 8) | di.last_track_lsb;
3300 ti_size = cdrom_get_track_info(cdi, last_track, 1, &ti);
3309 ti_size = cdrom_get_track_info(cdi, last_track, 1, &ti);
3317 if (ti.lra_v && ti_size >= (
int)(
offsetof(
typeof(ti), last_rec_address)
3344 static int cdrom_get_next_writable(
struct cdrom_device_info *cdi,
long *next_writable)
3352 goto use_last_written;
3354 ret = cdrom_get_disc_info(cdi, &di);
3357 goto use_last_written;
3361 ti_size = cdrom_get_track_info(cdi, last_track, 1, &ti);
3363 goto use_last_written;
3367 if (last_track == 1)
3368 goto use_last_written;
3370 ti_size = cdrom_get_track_info(cdi, last_track, 1, &ti);
3372 goto use_last_written;
3387 *next_writable += 7;
3405 #ifdef CONFIG_SYSCTL
3407 #define CDROM_STR_SIZE 1000
3409 static struct cdrom_sysctl_settings {
3410 char info[CDROM_STR_SIZE];
3416 } cdrom_sysctl_settings;
3418 enum cdrom_print_option {
3425 static int cdrom_print_info(
const char *
header,
int val,
char *info,
3426 int *
pos,
enum cdrom_print_option
option)
3428 const int max_size =
sizeof(cdrom_sysctl_settings.info);
3432 ret =
scnprintf(info + *pos, max_size - *pos, header);
3441 ret =
scnprintf(info + *pos, max_size - *pos,
3445 ret =
scnprintf(info + *pos, max_size - *pos,
3446 "\t%d", cdi->
speed);
3449 ret =
scnprintf(info + *pos, max_size - *pos,
3452 case CTL_CAPABILITY:
3453 ret =
scnprintf(info + *pos, max_size - *pos,
3457 pr_info(
"invalid option%d\n", option);
3468 static int cdrom_sysctl_info(
ctl_table *
ctl,
int write,
3469 void __user *buffer,
size_t *lenp, loff_t *ppos)
3472 char *info = cdrom_sysctl_settings.info;
3473 const int max_size =
sizeof(cdrom_sysctl_settings.info);
3475 if (!*lenp || (*ppos && !write)) {
3484 if (cdrom_print_info(
"\ndrive name:\t", 0, info, &pos, CTL_NAME))
3486 if (cdrom_print_info(
"\ndrive speed:\t", 0, info, &pos, CTL_SPEED))
3488 if (cdrom_print_info(
"\ndrive # of slots:", 0, info, &pos, CTL_SLOTS))
3490 if (cdrom_print_info(
"\nCan close tray:\t",
3493 if (cdrom_print_info(
"\nCan open tray:\t",
3496 if (cdrom_print_info(
"\nCan lock tray:\t",
3497 CDC_LOCK, info, &pos, CTL_CAPABILITY))
3499 if (cdrom_print_info(
"\nCan change speed:",
3502 if (cdrom_print_info(
"\nCan select disk:",
3505 if (cdrom_print_info(
"\nCan read multisession:",
3508 if (cdrom_print_info(
"\nCan read MCN:\t",
3509 CDC_MCN, info, &pos, CTL_CAPABILITY))
3511 if (cdrom_print_info(
"\nReports media changed:",
3514 if (cdrom_print_info(
"\nCan play audio:\t",
3517 if (cdrom_print_info(
"\nCan write CD-R:\t",
3518 CDC_CD_R, info, &pos, CTL_CAPABILITY))
3520 if (cdrom_print_info(
"\nCan write CD-RW:",
3523 if (cdrom_print_info(
"\nCan read DVD:\t",
3524 CDC_DVD, info, &pos, CTL_CAPABILITY))
3526 if (cdrom_print_info(
"\nCan write DVD-R:",
3529 if (cdrom_print_info(
"\nCan write DVD-RAM:",
3532 if (cdrom_print_info(
"\nCan read MRW:\t",
3533 CDC_MRW, info, &pos, CTL_CAPABILITY))
3535 if (cdrom_print_info(
"\nCan write MRW:\t",
3538 if (cdrom_print_info(
"\nCan write RAM:\t",
3539 CDC_RAM, info, &pos, CTL_CAPABILITY))
3541 if (!
scnprintf(info + pos, max_size - pos,
"\n\n"))
3547 pr_info(
"info buffer too small\n");
3555 static void cdrom_update_settings(
void)
3563 else if (!autoclose)
3567 else if (!autoeject)
3573 if (check_media_type)
3581 static int cdrom_sysctl_handler(
ctl_table *ctl,
int write,
3582 void __user *buffer,
size_t *lenp, loff_t *ppos)
3591 autoclose = !!cdrom_sysctl_settings.autoclose;
3592 autoeject = !!cdrom_sysctl_settings.autoeject;
3593 debug = !!cdrom_sysctl_settings.debug;
3594 lockdoor = !!cdrom_sysctl_settings.lock;
3595 check_media_type = !!cdrom_sysctl_settings.check;
3600 cdrom_update_settings();
3610 .data = &cdrom_sysctl_settings.info,
3611 .maxlen = CDROM_STR_SIZE,
3613 .proc_handler = cdrom_sysctl_info,
3616 .procname =
"autoclose",
3617 .data = &cdrom_sysctl_settings.autoclose,
3618 .maxlen =
sizeof(
int),
3623 .procname =
"autoeject",
3624 .data = &cdrom_sysctl_settings.autoeject,
3625 .maxlen =
sizeof(
int),
3630 .procname =
"debug",
3631 .data = &cdrom_sysctl_settings.debug,
3632 .maxlen =
sizeof(
int),
3638 .data = &cdrom_sysctl_settings.lock,
3639 .maxlen =
sizeof(
int),
3644 .procname =
"check_media",
3645 .data = &cdrom_sysctl_settings.check,
3646 .maxlen =
sizeof(
int),
3653 static ctl_table cdrom_cdrom_table[] = {
3658 .child = cdrom_table,
3669 .child = cdrom_cdrom_table,
3675 static void cdrom_sysctl_register(
void)
3679 if (initialized == 1)
3685 cdrom_sysctl_settings.autoclose = autoclose;
3686 cdrom_sysctl_settings.autoeject = autoeject;
3687 cdrom_sysctl_settings.debug =
debug;
3688 cdrom_sysctl_settings.lock = lockdoor;
3689 cdrom_sysctl_settings.check = check_media_type;
3694 static void cdrom_sysctl_unregister(
void)
3696 if (cdrom_sysctl_header)
3702 static void cdrom_sysctl_register(
void)
3706 static void cdrom_sysctl_unregister(
void)
3712 static int __init cdrom_init(
void)
3714 cdrom_sysctl_register();
3719 static void __exit cdrom_exit(
void)
3721 pr_info(
"Uniform CD-ROM driver unloaded\n");
3722 cdrom_sysctl_unregister();