Lines Matching +full:layer +full:- +full:buffer +full:- +full:offset

9    Uniform CD-ROM driver for Linux.
10 See Documentation/cdrom/cdrom-standard.rst for usage information.
13 software that uses CD-ROMs and the various low-level drivers that
15 Patches that work are more welcome though. ;-)
18 ----------------------------------
19 1.00 Date Unknown -- David van Leeuwen <david@tm.tno.nl>
20 -- Initial version by David A. van Leeuwen. I don't have a detailed
23 2.00 Dec 2, 1997 -- Erik Andersen <andersee@debian.org>
24 -- New maintainer! As David A. van Leeuwen has been too busy to actively
28 -- Added (rudimentary) sysctl interface. I realize this is really weak
31 -- Modified CDROM_DISC_STATUS so that it is now incorporated into
32 the Uniform CD-ROM driver via the cdrom_count_tracks function.
37 -- Remove the calls to verify_area and only use the copy_from_user and
41 -- Major update to return codes so that errors from low-level drivers
45 -- Made it so if a function isn't implemented in a low-level driver,
48 -- Simplified some complex logic so that the source code is easier to read.
50 -- Other stuff I probably forgot to mention (lots of changes).
52 2.01 to 2.11 Dec 1997-Jan 1998
53 -- TO-DO! Write changelogs for 2.01 to 2.12.
55 2.12 Jan 24, 1998 -- Erik Andersen <andersee@debian.org>
56 -- Fixed a bug in the IOCTL_IN and IOCTL_OUT macros. It turns out that
58 of bytes not copied. I was returning whatever non-zero stuff came back from
61 2.13 July 17, 1998 -- Erik Andersen <andersee@debian.org>
62 -- Fixed a bug in CDROM_SELECT_SPEED where you couldn't lower the speed
65 -- Fixed the procfs-unload-module bug with the fill_inode procfs callback.
67 -- Fixed it so that the /proc entry now also shows up when cdrom is
70 2.14 August 17, 1998 -- Erik Andersen <andersee@debian.org>
71 -- Fixed a bug in cdrom_media_changed and handling of reporting that
74 -- Made a few things more pedanticly correct.
76 2.50 Oct 19, 1998 - Jens Axboe <axboe@image.dk>
77 -- New maintainers! Erik was too busy to continue the work on the driver,
81 2.51 Dec 20, 1998 - Jens Axboe <axboe@image.dk>
82 -- Check if drive is capable of doing what we ask before blindly changing
83 cdi->options in various ioctl.
84 -- Added version to proc entry.
86 2.52 Jan 16, 1999 - Jens Axboe <axboe@image.dk>
87 -- Fixed an error in open_for_data where we would sometimes not return
89 -- Fixed module usage count - usage was based on /proc/sys/dev
91 modules had entries in dev. Feb 02 - real bug was in sysctl.c where
95 2.53 Feb 22, 1999 - Jens Axboe <axboe@image.dk>
96 -- Fixup of several ioctl calls, in particular CDROM_SET_OPTIONS has
99 -- Added CDROM_LOCKDOOR ioctl. Locks the door and keeps it that way.
100 -- Added CDROM_RESET ioctl.
101 -- Added CDROM_DEBUG ioctl. Enable debug messages on-the-fly.
102 -- Added CDROM_GET_CAPABILITY ioctl. This relieves userspace programs
105 2.54 Mar 15, 1999 - Jens Axboe <axboe@image.dk>
106 -- Check capability mask from low level driver when counting tracks as
109 2.55 Apr 25, 1999 - Jens Axboe <axboe@image.dk>
110 -- autoclose was mistakenly checked against CDC_OPEN_TRAY instead of
112 -- proc info didn't mask against capabilities mask.
114 3.00 Aug 5, 1999 - Jens Axboe <axboe@image.dk>
115 -- Unified audio ioctl handling across CD-ROM drivers. A lot of the
118 -- First attempt at adding support for MMC2 commands - for DVD and
119 CD-R(W) drives. Only the DVD parts are in now - the interface used is
121 -- ioctl cleanups. if a drive couldn't play audio, it didn't get
123 -- Defined CDROM_CAN(CDC_XXX) for checking the capabilities.
124 -- Put in sysctl files for autoclose, autoeject, check_media, debug,
126 -- /proc/sys/dev/cdrom/info has been updated to also contain info about
127 CD-Rx and DVD capabilities.
128 -- Now default to checking media type.
129 -- CDROM_SEND_PACKET ioctl added. The infrastructure was in place for
132 3.01 Aug 6, 1999 - Jens Axboe <axboe@image.dk>
133 -- Fix up the sysctl handling so that the option flags get set
135 -- Fix up ioctl handling so the device specific ones actually get
138 3.02 Aug 8, 1999 - Jens Axboe <axboe@image.dk>
139 -- Fixed volume control on SCSI drives (or others with longer audio
141 -- Fixed a couple of DVD minors. Thanks to Andrew T. Veliath
144 DVD patches for ide-cd and while I rearranged and unified them, the
147 3.03 Sep 1, 1999 - Jens Axboe <axboe@image.dk>
148 -- Moved the rest of the audio ioctls from the CD-ROM drivers here. Only
150 -- Moved the CDROMREADxxx ioctls in here.
151 -- Defined the cdrom_get_last_written and cdrom_get_next_block as ioctls
153 -- Erik Andersen <andersen@xmission.com> modified all SCMD_ commands
156 -- Various other cleanups.
158 3.04 Sep 12, 1999 - Jens Axboe <axboe@image.dk>
159 -- Fixed a couple of possible memory leaks (if an operation failed and
160 we didn't free the buffer before returning the error).
161 -- Integrated Uniform CD Changer handling from Richard Sharman
163 -- Defined CD_DVD and CD_CHANGER log levels.
164 -- Fixed the CDROMREADxxx ioctls.
165 -- CDROMPLAYTRKIND uses the GPCMD_PLAY_AUDIO_MSF command - too few
167 -- Small modifications to accommodate opens of /dev/hdc1, required
168 for ide-cd to handle multisession discs.
169 -- Export cdrom_mode_sense and cdrom_mode_select.
170 -- init_cdrom_command() for setting up a cgc command.
172 3.05 Oct 24, 1999 - Jens Axboe <axboe@image.dk>
173 -- Changed the interface for CDROM_SEND_PACKET. Before it was virtually
175 -- Lowered stack usage in mmc_ioctl(), dvd_read_disckey(), and
177 -- Added setup of write mode for packet writing.
178 -- Fixed CDDA ripping with cdda2wav - accept much larger requests of
181 3.06 Dec 13, 1999 - Jens Axboe <axboe@image.dk>
182 -- Added support for changing the region of DVD drives.
183 -- Added sense data to generic command.
185 3.07 Feb 2, 2000 - Jens Axboe <axboe@suse.de>
186 -- Do same "read header length" trick in cdrom_get_disc_info() as
187 we do in cdrom_get_track_info() -- some drive don't obey specs and
189 -- Deleted stuff related to setting up write modes. It has a different
191 -- Clear header length in mode_select unconditionally.
192 -- Removed the register_disk() that was added, not needed here.
194 3.08 May 1, 2000 - Jens Axboe <axboe@suse.de>
195 -- Fix direction flag in setup_send_key and setup_report_key. This
197 -- Always return -EROFS for write opens
198 -- Convert to module_init/module_exit style init and remove some
200 -- Fix several dvd errors - DVD_LU_SEND_ASF should pass agid,
201 DVD_HOST_SEND_RPC_STATE did not set buffer size in cdb, and
203 did not clear a 0 sized buffer.
205 3.09 May 12, 2000 - Jens Axboe <axboe@suse.de>
206 -- Fix Video-CD on SCSI drives that don't support READ_CD command. In
210 3.10 Jun 10, 2000 - Jens Axboe <axboe@suse.de>
211 -- Fix volume control on CD's - old SCSI-II drives now use their own
213 -- Use READ_DISC_INFO for more reliable end-of-disc.
215 3.11 Jun 12, 2000 - Jens Axboe <axboe@suse.de>
216 -- Fix bug in getting rpc phase 2 region info.
217 -- Reinstate "correct" CDROMPLAYTRKIND
219 3.12 Oct 18, 2000 - Jens Axboe <axboe@suse.de>
220 -- Use quiet bit on packet commands not known to work
222 3.20 Dec 17, 2003 - Jens Axboe <axboe@suse.de>
223 -- Various fixes and lots of cleanups not listed :-)
224 -- Locking fixes
225 -- Mt Rainier support
226 -- DVD-RAM write open fixes
229 <appro@fy.chalmers.se> to support MMC-3 compliant DVD+RW units.
231 Modified by Nigel Kukard <nkukard@lbsd.net> - support DVD+RW
234 -------------------------------------------------------------------------*/
241 /* I use an error-log mask to give fine grain control over the type of
322 /* The (cdo->capability & ~cdi->mask & CDC_XXX) construct was used in
324 #define CDROM_CAN(type) (cdi->ops->capability & ~cdi->mask & (type))
332 /* Not-exported routines. */
340 cdi->mc_flags = 0x3; /* set media changed bits, on both queues */ in signal_media_change()
341 cdi->last_media_change_ms = ktime_to_ms(ktime_get()); in signal_media_change()
347 if (cgc->sshdr) { in cdrom_dummy_generic_packet()
348 cgc->sshdr->sense_key = 0x05; in cdrom_dummy_generic_packet()
349 cgc->sshdr->asc = 0x20; in cdrom_dummy_generic_packet()
350 cgc->sshdr->ascq = 0x00; in cdrom_dummy_generic_packet()
353 cgc->stat = -EIO; in cdrom_dummy_generic_packet()
354 return -EIO; in cdrom_dummy_generic_packet()
367 return cdi->ops->generic_packet(cdi, &cgc); in cdrom_flush_cache()
374 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_get_disc_info()
384 ret = cdo->generic_packet(cdi, &cgc); in cdrom_get_disc_info()
391 buflen = be16_to_cpu(di->disc_information_length) + in cdrom_get_disc_info()
392 sizeof(di->disc_information_length); in cdrom_get_disc_info()
398 ret = cdo->generic_packet(cdi, &cgc); in cdrom_get_disc_info()
407 * existence in the run-time routines below. Change_capability is a
413 if (cdo->call == NULL) \
414 WARN_ON_ONCE((cdo)->capability & (bits)); \
424 char buffer[16]; in cdrom_mrw_probe_pc() local
426 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ); in cdrom_mrw_probe_pc()
432 cdi->mrw_mode_page = MRW_MODE_PC; in cdrom_mrw_probe_pc()
435 cdi->mrw_mode_page = MRW_MODE_PC_PRE1; in cdrom_mrw_probe_pc()
446 unsigned char buffer[16]; in cdrom_is_mrw() local
451 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ); in cdrom_is_mrw()
455 cgc.cmd[8] = sizeof(buffer); in cdrom_is_mrw()
458 if ((ret = cdi->ops->generic_packet(cdi, &cgc))) in cdrom_is_mrw()
461 mfd = (struct mrw_feature_desc *)&buffer[sizeof(struct feature_header)]; in cdrom_is_mrw()
462 if (be16_to_cpu(mfd->feature_code) != CDF_MRW) in cdrom_is_mrw()
464 *write = mfd->write; in cdrom_is_mrw()
477 unsigned char buffer[12]; in cdrom_mrw_bgformat() local
485 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_WRITE); in cdrom_mrw_bgformat()
494 buffer[1] = 1 << 1; in cdrom_mrw_bgformat()
495 buffer[3] = 8; in cdrom_mrw_bgformat()
500 buffer[4] = 0xff; in cdrom_mrw_bgformat()
501 buffer[5] = 0xff; in cdrom_mrw_bgformat()
502 buffer[6] = 0xff; in cdrom_mrw_bgformat()
503 buffer[7] = 0xff; in cdrom_mrw_bgformat()
505 buffer[8] = 0x24 << 2; in cdrom_mrw_bgformat()
506 buffer[11] = cont; in cdrom_mrw_bgformat()
508 ret = cdi->ops->generic_packet(cdi, &cgc); in cdrom_mrw_bgformat()
530 return cdi->ops->generic_packet(cdi, &cgc); in cdrom_mrw_bgformat_susp()
548 if (!ret && cdi->media_written) in cdrom_mrw_exit()
558 char buffer[16]; in cdrom_mrw_set_lba_space() local
559 int ret, offset, size; in cdrom_mrw_set_lba_space() local
561 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ); in cdrom_mrw_set_lba_space()
563 cgc.buffer = buffer; in cdrom_mrw_set_lba_space()
564 cgc.buflen = sizeof(buffer); in cdrom_mrw_set_lba_space()
566 ret = cdrom_mode_sense(cdi, &cgc, cdi->mrw_mode_page, 0); in cdrom_mrw_set_lba_space()
570 mph = (struct mode_page_header *)buffer; in cdrom_mrw_set_lba_space()
571 offset = be16_to_cpu(mph->desc_length); in cdrom_mrw_set_lba_space()
572 size = be16_to_cpu(mph->mode_data_length) + 2; in cdrom_mrw_set_lba_space()
574 buffer[offset + 3] = space; in cdrom_mrw_set_lba_space()
582 cdi->name, mrw_address_space[space]); in cdrom_mrw_set_lba_space()
589 const struct cdrom_device_ops *cdo = cdi->ops; in register_cdrom()
593 if (cdo->open == NULL || cdo->release == NULL) in register_cdrom()
594 return -EINVAL; in register_cdrom()
596 pr_info("Uniform CD-ROM driver " REVISION "\n"); in register_cdrom()
601 cdi->disk = disk; in register_cdrom()
602 disk->cdi = cdi; in register_cdrom()
605 if (cdo->check_events == NULL) in register_cdrom()
606 WARN_ON_ONCE(cdo->capability & (CDC_MEDIA_CHANGED | CDC_SELECT_DISC)); in register_cdrom()
614 cdi->mc_flags = 0; in register_cdrom()
615 cdi->options = CDO_USE_FFLAGS; in register_cdrom()
616 cdi->last_media_change_ms = ktime_to_ms(ktime_get()); in register_cdrom()
619 cdi->options |= (int) CDO_AUTO_CLOSE; in register_cdrom()
621 cdi->options |= (int) CDO_AUTO_EJECT; in register_cdrom()
623 cdi->options |= (int) CDO_LOCK; in register_cdrom()
625 cdi->options |= (int) CDO_CHECK_TYPE; in register_cdrom()
628 cdi->exit = cdrom_mrw_exit; in register_cdrom()
630 if (cdi->ops->read_cdda_bpc) in register_cdrom()
631 cdi->cdda_method = CDDA_BPC_FULL; in register_cdrom()
633 cdi->cdda_method = CDDA_OLD; in register_cdrom()
635 WARN_ON(!cdo->generic_packet); in register_cdrom()
637 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name); in register_cdrom()
639 list_add(&cdi->list, &cdrom_list); in register_cdrom()
651 list_del(&cdi->list); in unregister_cdrom()
654 if (cdi->exit) in unregister_cdrom()
655 cdi->exit(cdi); in unregister_cdrom()
657 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name); in unregister_cdrom()
665 unsigned char buffer[8]; in cdrom_get_media_event() local
666 struct event_header *eh = (struct event_header *)buffer; in cdrom_get_media_event()
668 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ); in cdrom_get_media_event()
672 cgc.cmd[8] = sizeof(buffer); in cdrom_get_media_event()
675 if (cdi->ops->generic_packet(cdi, &cgc)) in cdrom_get_media_event()
678 if (be16_to_cpu(eh->data_len) < sizeof(*med)) in cdrom_get_media_event()
681 if (eh->nea || eh->notification_class != 0x4) in cdrom_get_media_event()
684 memcpy(med, &buffer[sizeof(*eh)], sizeof(*med)); in cdrom_get_media_event()
693 char buffer[24]; in cdrom_get_random_writable() local
696 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ); in cdrom_get_random_writable()
700 cgc.cmd[8] = sizeof(buffer); /* often 0x18 */ in cdrom_get_random_writable()
703 if ((ret = cdi->ops->generic_packet(cdi, &cgc))) in cdrom_get_random_writable()
706 memcpy(rfd, &buffer[sizeof(struct feature_header)], sizeof (*rfd)); in cdrom_get_random_writable()
713 char buffer[16]; in cdrom_has_defect_mgt() local
717 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ); in cdrom_has_defect_mgt()
721 cgc.cmd[8] = sizeof(buffer); in cdrom_has_defect_mgt()
724 if ((ret = cdi->ops->generic_packet(cdi, &cgc))) in cdrom_has_defect_mgt()
727 feature_code = (__be16 *) &buffer[sizeof(struct feature_header)]; in cdrom_has_defect_mgt()
758 return -1; in cdrom_media_erasable()
802 * 0 - not MRW formatted in cdrom_mrw_open_write()
803 * 1 - MRW bgformat started, but not running or complete in cdrom_mrw_open_write()
804 * 2 - MRW bgformat in progress in cdrom_mrw_open_write()
805 * 3 - MRW formatting complete in cdrom_mrw_open_write()
821 char buffer[255]; in mo_open_write() local
824 init_cdrom_command(&cgc, &buffer, 4, CGC_DATA_READ); in mo_open_write()
844 return buffer[3] & 0x80; in mo_open_write()
867 char buffer[32]; in cdrom_mmc3_profile() local
870 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ); in cdrom_mmc3_profile()
875 cgc.cmd[8] = sizeof(buffer); /* Allocation Length */ in cdrom_mmc3_profile()
878 if (cdi->ops->generic_packet(cdi, &cgc)) in cdrom_mmc3_profile()
881 mmc3_profile = (buffer[6] << 8) | buffer[7]; in cdrom_mmc3_profile()
883 cdi->mmc3_profile = mmc3_profile; in cdrom_mmc3_profile()
888 switch (cdi->mmc3_profile) { in cdrom_is_dvd_rw()
889 case 0x12: /* DVD-RAM */ in cdrom_is_dvd_rw()
891 case 0x43: /* BD-RE */ in cdrom_is_dvd_rw()
899 * returns 0 for ok to open write, non-0 to disallow
916 cdi->mask &= ~CDC_MRW; in cdrom_open_write()
918 cdi->mask |= CDC_MRW; in cdrom_open_write()
921 cdi->mask &= ~CDC_MRW_W; in cdrom_open_write()
923 cdi->mask |= CDC_MRW_W; in cdrom_open_write()
926 cdi->mask &= ~CDC_RAM; in cdrom_open_write()
928 cdi->mask |= CDC_RAM; in cdrom_open_write()
949 if (cdi->mmc3_profile != 0x1a) { in cdrom_dvd_rw_close_write()
950 cd_dbg(CD_CLOSE, "%s: No DVD+RW\n", cdi->name); in cdrom_dvd_rw_close_write()
954 if (!cdi->media_written) { in cdrom_dvd_rw_close_write()
955 cd_dbg(CD_CLOSE, "%s: DVD+RW media clean\n", cdi->name); in cdrom_dvd_rw_close_write()
959 pr_info("%s: dirty DVD+RW media, \"finalizing\"\n", cdi->name); in cdrom_dvd_rw_close_write()
964 cdi->ops->generic_packet(cdi, &cgc); in cdrom_dvd_rw_close_write()
970 cdi->ops->generic_packet(cdi, &cgc); in cdrom_dvd_rw_close_write()
977 cdi->ops->generic_packet(cdi, &cgc); in cdrom_dvd_rw_close_write()
979 cdi->media_written = 0; in cdrom_dvd_rw_close_write()
988 tracks->data = 0; in cdrom_count_tracks()
989 tracks->audio = 0; in cdrom_count_tracks()
990 tracks->cdi = 0; in cdrom_count_tracks()
991 tracks->xa = 0; in cdrom_count_tracks()
992 tracks->error = 0; in cdrom_count_tracks()
996 tracks->error = CDS_NO_INFO; in cdrom_count_tracks()
1001 ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header); in cdrom_count_tracks()
1003 if (ret == -ENOMEDIUM) in cdrom_count_tracks()
1004 tracks->error = CDS_NO_DISC; in cdrom_count_tracks()
1006 tracks->error = CDS_NO_INFO; in cdrom_count_tracks()
1013 if (cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &entry)) { in cdrom_count_tracks()
1014 tracks->error = CDS_NO_INFO; in cdrom_count_tracks()
1019 tracks->cdi++; in cdrom_count_tracks()
1021 tracks->xa++; in cdrom_count_tracks()
1023 tracks->data++; in cdrom_count_tracks()
1025 tracks->audio++; in cdrom_count_tracks()
1030 cd_dbg(CD_COUNT_TRACKS, "disc has %d tracks: %d=audio %d=data %d=Cd-I %d=XA\n", in cdrom_count_tracks()
1031 header.cdth_trk1, tracks->audio, tracks->data, in cdrom_count_tracks()
1032 tracks->cdi, tracks->xa); in cdrom_count_tracks()
1039 const struct cdrom_device_ops *cdo = cdi->ops; in open_for_data()
1044 if (cdo->drive_status != NULL) { in open_for_data()
1045 ret = cdo->drive_status(cdi, CDSL_CURRENT); in open_for_data()
1051 cdi->options & CDO_AUTO_CLOSE) { in open_for_data()
1053 ret=cdo->tray_move(cdi,0); in open_for_data()
1061 ret=-ENOMEDIUM; in open_for_data()
1066 ret=-ENOMEDIUM; in open_for_data()
1070 ret = cdo->drive_status(cdi, CDSL_CURRENT); in open_for_data()
1074 ret=-ENOMEDIUM; in open_for_data()
1080 ret = cdo->drive_status(cdi, CDSL_CURRENT); in open_for_data()
1082 ret = -ENOMEDIUM; in open_for_data()
1089 ret=-ENOMEDIUM; in open_for_data()
1092 /* CD-Players which don't use O_NONBLOCK, workman in open_for_data()
1095 if (cdi->options & CDO_CHECK_TYPE) { in open_for_data()
1101 ret=-EMEDIUMTYPE; in open_for_data()
1112 ret = cdo->open(cdi, 0); /* open for data */ in open_for_data()
1121 if (CDROM_CAN(CDC_LOCK) && (cdi->options & CDO_LOCK)) { in open_for_data()
1122 cdo->lock_door(cdi, 1); in open_for_data()
1129 (notably ide-cd) lock the drive after every command. This produced in open_for_data()
1135 if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) { in open_for_data()
1136 cdo->lock_door(cdi, 0); in open_for_data()
1142 /* We use the open-option O_NONBLOCK to indicate that the
1146 * We hope that all cd-player programs will adopt this convention. It
1158 cdi->use_count++; in cdrom_open()
1159 if ((mode & BLK_OPEN_NDELAY) && (cdi->options & CDO_USE_FFLAGS)) { in cdrom_open()
1160 ret = cdi->ops->open(cdi, 1); in cdrom_open()
1168 ret = -EROFS; in cdrom_open()
1174 cdi->media_written = 0; in cdrom_open()
1176 cdi->opened_for_data = true; in cdrom_open()
1183 cdi->name, cdi->use_count); in cdrom_open()
1186 if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) { in cdrom_open()
1187 cdi->ops->lock_door(cdi, 0); in cdrom_open()
1190 cdi->ops->release(cdi); in cdrom_open()
1192 cdi->use_count--; in cdrom_open()
1206 if (!(cdi->options & CDO_CHECK_TYPE)) in check_for_audio_disc()
1208 if (cdo->drive_status != NULL) { in check_for_audio_disc()
1209 ret = cdo->drive_status(cdi, CDSL_CURRENT); in check_for_audio_disc()
1215 cdi->options & CDO_AUTO_CLOSE) { in check_for_audio_disc()
1217 ret=cdo->tray_move(cdi,0); in check_for_audio_disc()
1225 return -ENOMEDIUM; in check_for_audio_disc()
1229 return -ENOMEDIUM; in check_for_audio_disc()
1232 ret = cdo->drive_status(cdi, CDSL_CURRENT); in check_for_audio_disc()
1235 return -ENOMEDIUM; in check_for_audio_disc()
1239 return -EIO; in check_for_audio_disc()
1249 return -EMEDIUMTYPE; in check_for_audio_disc()
1256 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_release()
1260 if (cdi->use_count > 0) in cdrom_release()
1261 cdi->use_count--; in cdrom_release()
1263 if (cdi->use_count == 0) { in cdrom_release()
1265 cdi->name); in cdrom_release()
1268 if ((cdo->capability & CDC_LOCK) && !cdi->keeplocked) { in cdrom_release()
1270 cdo->lock_door(cdi, 0); in cdrom_release()
1274 cdo->release(cdi); in cdrom_release()
1276 if (cdi->use_count == 0 && cdi->opened_for_data) { in cdrom_release()
1277 if (cdi->options & CDO_AUTO_EJECT && CDROM_CAN(CDC_OPEN_TRAY)) in cdrom_release()
1278 cdo->tray_move(cdi, 1); in cdrom_release()
1279 cdi->opened_for_data = false; in cdrom_release()
1288 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_read_mech_status()
1296 if (cdi->sanyo_slot) { in cdrom_read_mech_status()
1297 buf->hdr.nslots = 3; in cdrom_read_mech_status()
1298 buf->hdr.curslot = cdi->sanyo_slot == 3 ? 0 : cdi->sanyo_slot; in cdrom_read_mech_status()
1300 buf->slots[length].disc_present = 1; in cdrom_read_mech_status()
1301 buf->slots[length].change = 0; in cdrom_read_mech_status()
1307 cdi->capacity * sizeof(struct cdrom_slot); in cdrom_read_mech_status()
1313 return cdo->generic_packet(cdi, &cgc); in cdrom_read_mech_status()
1322 if (cdi->sanyo_slot) in cdrom_slot_status()
1327 return -ENOMEM; in cdrom_slot_status()
1332 if (info->slots[slot].disc_present) in cdrom_slot_status()
1352 cdi->capacity = 0; in cdrom_number_of_slots()
1356 return -ENOMEM; in cdrom_number_of_slots()
1359 nslots = info->hdr.nslots; in cdrom_number_of_slots()
1373 if (cdi->sanyo_slot && slot < 0) in cdrom_load_unload()
1385 if (cdi->sanyo_slot && -1 < slot) { in cdrom_load_unload()
1389 cdi->sanyo_slot = slot ? slot : 3; in cdrom_load_unload()
1392 return cdi->ops->generic_packet(cdi, &cgc); in cdrom_load_unload()
1403 return -EDRIVE_CANT_DO_THIS; in cdrom_select_disc()
1405 if (cdi->ops->check_events) in cdrom_select_disc()
1406 cdi->ops->check_events(cdi, 0, slot); in cdrom_select_disc()
1410 return cdrom_load_unload(cdi, -1); in cdrom_select_disc()
1415 return -ENOMEM; in cdrom_select_disc()
1422 curslot = info->hdr.curslot; in cdrom_select_disc()
1425 if (cdi->use_count > 1 || cdi->keeplocked) { in cdrom_select_disc()
1429 return -EBUSY; in cdrom_select_disc()
1451 * event, it needs to buffer ->check_events() output, such that event
1453 * cdi->{vfs|ioctl}_events are used to buffer pending events for each
1456 * XXX: Locking is non-existent. cdi->ops->check_events() can be
1468 events = cdi->ops->check_events(cdi, clearing, CDSL_CURRENT); in cdrom_update_events()
1469 cdi->vfs_events |= events; in cdrom_update_events()
1470 cdi->ioctl_events |= events; in cdrom_update_events()
1479 events = cdi->vfs_events; in cdrom_check_events()
1480 cdi->vfs_events = 0; in cdrom_check_events()
1486 * ioctl. The main problem now is that we must double-buffer the
1487 * low-level implementation, to assure that the VFS and the user both
1495 int ret = !!(cdi->mc_flags & mask); in media_changed()
1504 changed = cdi->ioctl_events & DISK_EVENT_MEDIA_CHANGE; in media_changed()
1505 cdi->ioctl_events = 0; in media_changed()
1510 cdi->media_written = 0; in media_changed()
1513 cdi->mc_flags &= ~mask; /* clear bit */ in media_changed()
1517 /* Requests to the low-level drivers will /always/ be done in the
1520 CDROM_LBA: all data-related requests.
1521 CDROM_MSF: all audio-related requests.
1523 However, a low-level implementation is allowed to refuse this
1527 format, or ask for multi-session info in MSF format. However, for
1529 the requests to the low-level drivers will be sanitized in the more
1540 addr->lba = (int) addr->msf.frame + in sanitize_format()
1541 75 * (addr->msf.second - 2 + 60 * addr->msf.minute); in sanitize_format()
1543 int lba = addr->lba; in sanitize_format()
1544 addr->msf.frame = lba % 75; in sanitize_format()
1547 addr->msf.second = lba % 60; in sanitize_format()
1548 addr->msf.minute = lba / 60; in sanitize_format()
1559 cgc->buffer = (char *) buf; in init_cdrom_command()
1560 cgc->buflen = len; in init_cdrom_command()
1561 cgc->data_direction = type; in init_cdrom_command()
1562 cgc->timeout = CDROM_DEF_TIMEOUT; in init_cdrom_command()
1573 cgc->cmd[0] = GPCMD_REPORT_KEY; in setup_report_key()
1574 cgc->cmd[10] = type | (agid << 6); in setup_report_key()
1577 cgc->buflen = 8; in setup_report_key()
1581 cgc->buflen = 16; in setup_report_key()
1585 cgc->buflen = 12; in setup_report_key()
1589 cgc->cmd[9] = cgc->buflen; in setup_report_key()
1590 cgc->data_direction = CGC_DATA_READ; in setup_report_key()
1595 cgc->cmd[0] = GPCMD_SEND_KEY; in setup_send_key()
1596 cgc->cmd[10] = type | (agid << 6); in setup_send_key()
1599 cgc->buflen = 16; in setup_send_key()
1603 cgc->buflen = 12; in setup_send_key()
1607 cgc->buflen = 8; in setup_send_key()
1611 cgc->cmd[9] = cgc->buflen; in setup_send_key()
1612 cgc->data_direction = CGC_DATA_WRITE; in setup_send_key()
1620 const struct cdrom_device_ops *cdo = cdi->ops; in dvd_do_auth()
1626 switch (ai->type) { in dvd_do_auth()
1631 setup_report_key(&cgc, ai->lsa.agid, 0); in dvd_do_auth()
1633 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1636 ai->lsa.agid = buf[7] >> 6; in dvd_do_auth()
1642 setup_report_key(&cgc, ai->lsk.agid, 2); in dvd_do_auth()
1644 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1647 copy_key(ai->lsk.key, &buf[4]); in dvd_do_auth()
1653 setup_report_key(&cgc, ai->lsc.agid, 1); in dvd_do_auth()
1655 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1658 copy_chal(ai->lsc.chal, &buf[4]); in dvd_do_auth()
1662 /* Post-auth key */ in dvd_do_auth()
1666 setup_report_key(&cgc, ai->lstk.agid, 4); in dvd_do_auth()
1667 cgc.cmd[5] = ai->lstk.lba; in dvd_do_auth()
1668 cgc.cmd[4] = ai->lstk.lba >> 8; in dvd_do_auth()
1669 cgc.cmd[3] = ai->lstk.lba >> 16; in dvd_do_auth()
1670 cgc.cmd[2] = ai->lstk.lba >> 24; in dvd_do_auth()
1672 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1675 ai->lstk.cpm = (buf[4] >> 7) & 1; in dvd_do_auth()
1676 ai->lstk.cp_sec = (buf[4] >> 6) & 1; in dvd_do_auth()
1677 ai->lstk.cgms = (buf[4] >> 4) & 3; in dvd_do_auth()
1678 copy_key(ai->lstk.title_key, &buf[5]); in dvd_do_auth()
1684 setup_report_key(&cgc, ai->lsasf.agid, 5); in dvd_do_auth()
1686 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1689 ai->lsasf.asf = buf[7] & 1; in dvd_do_auth()
1695 setup_send_key(&cgc, ai->hsc.agid, 1); in dvd_do_auth()
1697 copy_chal(&buf[4], ai->hsc.chal); in dvd_do_auth()
1699 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1702 ai->type = DVD_LU_SEND_KEY1; in dvd_do_auth()
1707 setup_send_key(&cgc, ai->hsk.agid, 3); in dvd_do_auth()
1709 copy_key(&buf[4], ai->hsk.key); in dvd_do_auth()
1711 if ((ret = cdo->generic_packet(cdi, &cgc))) { in dvd_do_auth()
1712 ai->type = DVD_AUTH_FAILURE; in dvd_do_auth()
1715 ai->type = DVD_AUTH_ESTABLISHED; in dvd_do_auth()
1722 setup_report_key(&cgc, ai->lsa.agid, 0x3f); in dvd_do_auth()
1723 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1732 cgc.buffer = (char *) &rpc_state; in dvd_do_auth()
1734 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1737 ai->lrpcs.type = rpc_state.type_code; in dvd_do_auth()
1738 ai->lrpcs.vra = rpc_state.vra; in dvd_do_auth()
1739 ai->lrpcs.ucca = rpc_state.ucca; in dvd_do_auth()
1740 ai->lrpcs.region_mask = rpc_state.region_mask; in dvd_do_auth()
1741 ai->lrpcs.rpc_scheme = rpc_state.rpc_scheme; in dvd_do_auth()
1749 buf[4] = ai->hrpcs.pdrc; in dvd_do_auth()
1751 if ((ret = cdo->generic_packet(cdi, &cgc))) in dvd_do_auth()
1756 cd_dbg(CD_WARNING, "Invalid DVD key ioctl (%d)\n", ai->type); in dvd_do_auth()
1757 return -ENOTTY; in dvd_do_auth()
1767 struct dvd_layer *layer; in dvd_read_physical() local
1768 const struct cdrom_device_ops *cdo = cdi->ops; in dvd_read_physical()
1769 int ret, layer_num = s->physical.layer_num; in dvd_read_physical()
1772 return -EINVAL; in dvd_read_physical()
1775 cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE; in dvd_read_physical()
1776 cgc->cmd[6] = layer_num; in dvd_read_physical()
1777 cgc->cmd[7] = s->type; in dvd_read_physical()
1778 cgc->cmd[9] = cgc->buflen & 0xff; in dvd_read_physical()
1781 * refrain from reporting errors on non-existing layers (mainly) in dvd_read_physical()
1783 cgc->quiet = 1; in dvd_read_physical()
1785 ret = cdo->generic_packet(cdi, cgc); in dvd_read_physical()
1790 layer = &s->physical.layer[layer_num]; in dvd_read_physical()
1796 memset(layer, 0, sizeof(*layer)); in dvd_read_physical()
1797 layer->book_version = base[0] & 0xf; in dvd_read_physical()
1798 layer->book_type = base[0] >> 4; in dvd_read_physical()
1799 layer->min_rate = base[1] & 0xf; in dvd_read_physical()
1800 layer->disc_size = base[1] >> 4; in dvd_read_physical()
1801 layer->layer_type = base[2] & 0xf; in dvd_read_physical()
1802 layer->track_path = (base[2] >> 4) & 1; in dvd_read_physical()
1803 layer->nlayers = (base[2] >> 5) & 3; in dvd_read_physical()
1804 layer->track_density = base[3] & 0xf; in dvd_read_physical()
1805 layer->linear_density = base[3] >> 4; in dvd_read_physical()
1806 layer->start_sector = base[5] << 16 | base[6] << 8 | base[7]; in dvd_read_physical()
1807 layer->end_sector = base[9] << 16 | base[10] << 8 | base[11]; in dvd_read_physical()
1808 layer->end_sector_l0 = base[13] << 16 | base[14] << 8 | base[15]; in dvd_read_physical()
1809 layer->bca = base[16] >> 7; in dvd_read_physical()
1819 const struct cdrom_device_ops *cdo = cdi->ops; in dvd_read_copyright()
1822 cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE; in dvd_read_copyright()
1823 cgc->cmd[6] = s->copyright.layer_num; in dvd_read_copyright()
1824 cgc->cmd[7] = s->type; in dvd_read_copyright()
1825 cgc->cmd[8] = cgc->buflen >> 8; in dvd_read_copyright()
1826 cgc->cmd[9] = cgc->buflen & 0xff; in dvd_read_copyright()
1828 ret = cdo->generic_packet(cdi, cgc); in dvd_read_copyright()
1832 s->copyright.cpst = buf[4]; in dvd_read_copyright()
1833 s->copyright.rmi = buf[5]; in dvd_read_copyright()
1843 const struct cdrom_device_ops *cdo = cdi->ops; in dvd_read_disckey()
1845 size = sizeof(s->disckey.value) + 4; in dvd_read_disckey()
1849 return -ENOMEM; in dvd_read_disckey()
1852 cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE; in dvd_read_disckey()
1853 cgc->cmd[7] = s->type; in dvd_read_disckey()
1854 cgc->cmd[8] = size >> 8; in dvd_read_disckey()
1855 cgc->cmd[9] = size & 0xff; in dvd_read_disckey()
1856 cgc->cmd[10] = s->disckey.agid << 6; in dvd_read_disckey()
1858 ret = cdo->generic_packet(cdi, cgc); in dvd_read_disckey()
1860 memcpy(s->disckey.value, &buf[4], sizeof(s->disckey.value)); in dvd_read_disckey()
1871 const struct cdrom_device_ops *cdo = cdi->ops; in dvd_read_bca()
1875 return -ENOMEM; in dvd_read_bca()
1878 cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE; in dvd_read_bca()
1879 cgc->cmd[7] = s->type; in dvd_read_bca()
1880 cgc->cmd[9] = cgc->buflen & 0xff; in dvd_read_bca()
1882 ret = cdo->generic_packet(cdi, cgc); in dvd_read_bca()
1886 s->bca.len = buf[0] << 8 | buf[1]; in dvd_read_bca()
1887 if (s->bca.len < 12 || s->bca.len > 188) { in dvd_read_bca()
1889 s->bca.len); in dvd_read_bca()
1890 ret = -EIO; in dvd_read_bca()
1893 memcpy(s->bca.value, &buf[4], s->bca.len); in dvd_read_bca()
1905 const struct cdrom_device_ops *cdo = cdi->ops; in dvd_read_manufact()
1907 size = sizeof(s->manufact.value) + 4; in dvd_read_manufact()
1911 return -ENOMEM; in dvd_read_manufact()
1914 cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE; in dvd_read_manufact()
1915 cgc->cmd[7] = s->type; in dvd_read_manufact()
1916 cgc->cmd[8] = size >> 8; in dvd_read_manufact()
1917 cgc->cmd[9] = size & 0xff; in dvd_read_manufact()
1919 ret = cdo->generic_packet(cdi, cgc); in dvd_read_manufact()
1923 s->manufact.len = buf[0] << 8 | buf[1]; in dvd_read_manufact()
1924 if (s->manufact.len < 0) { in dvd_read_manufact()
1926 s->manufact.len); in dvd_read_manufact()
1927 ret = -EIO; in dvd_read_manufact()
1929 if (s->manufact.len > 2048) { in dvd_read_manufact()
1931 s->manufact.len); in dvd_read_manufact()
1932 s->manufact.len = 2048; in dvd_read_manufact()
1934 memcpy(s->manufact.value, &buf[4], s->manufact.len); in dvd_read_manufact()
1945 switch (s->type) { in dvd_read_struct()
1963 s->type); in dvd_read_struct()
1964 return -EINVAL; in dvd_read_struct()
1972 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_mode_sense()
1974 memset(cgc->cmd, 0, sizeof(cgc->cmd)); in cdrom_mode_sense()
1976 cgc->cmd[0] = GPCMD_MODE_SENSE_10; in cdrom_mode_sense()
1977 cgc->cmd[2] = page_code | (page_control << 6); in cdrom_mode_sense()
1978 cgc->cmd[7] = cgc->buflen >> 8; in cdrom_mode_sense()
1979 cgc->cmd[8] = cgc->buflen & 0xff; in cdrom_mode_sense()
1980 cgc->data_direction = CGC_DATA_READ; in cdrom_mode_sense()
1981 return cdo->generic_packet(cdi, cgc); in cdrom_mode_sense()
1988 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_mode_select()
1990 memset(cgc->cmd, 0, sizeof(cgc->cmd)); in cdrom_mode_select()
1991 memset(cgc->buffer, 0, 2); in cdrom_mode_select()
1992 cgc->cmd[0] = GPCMD_MODE_SELECT_10; in cdrom_mode_select()
1993 cgc->cmd[1] = 0x10; /* PF */ in cdrom_mode_select()
1994 cgc->cmd[7] = cgc->buflen >> 8; in cdrom_mode_select()
1995 cgc->cmd[8] = cgc->buflen & 0xff; in cdrom_mode_select()
1996 cgc->data_direction = CGC_DATA_WRITE; in cdrom_mode_select()
1997 return cdo->generic_packet(cdi, cgc); in cdrom_mode_select()
2004 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_read_subchannel()
2006 char buffer[32]; in cdrom_read_subchannel() local
2009 init_cdrom_command(&cgc, buffer, 16, CGC_DATA_READ); in cdrom_read_subchannel()
2011 cgc.cmd[1] = subchnl->cdsc_format;/* MSF or LBA addressing */ in cdrom_read_subchannel()
2016 if ((ret = cdo->generic_packet(cdi, &cgc))) in cdrom_read_subchannel()
2019 subchnl->cdsc_audiostatus = cgc.buffer[1]; in cdrom_read_subchannel()
2020 subchnl->cdsc_ctrl = cgc.buffer[5] & 0xf; in cdrom_read_subchannel()
2021 subchnl->cdsc_trk = cgc.buffer[6]; in cdrom_read_subchannel()
2022 subchnl->cdsc_ind = cgc.buffer[7]; in cdrom_read_subchannel()
2024 if (subchnl->cdsc_format == CDROM_LBA) { in cdrom_read_subchannel()
2025 subchnl->cdsc_absaddr.lba = ((cgc.buffer[8] << 24) | in cdrom_read_subchannel()
2026 (cgc.buffer[9] << 16) | in cdrom_read_subchannel()
2027 (cgc.buffer[10] << 8) | in cdrom_read_subchannel()
2028 (cgc.buffer[11])); in cdrom_read_subchannel()
2029 subchnl->cdsc_reladdr.lba = ((cgc.buffer[12] << 24) | in cdrom_read_subchannel()
2030 (cgc.buffer[13] << 16) | in cdrom_read_subchannel()
2031 (cgc.buffer[14] << 8) | in cdrom_read_subchannel()
2032 (cgc.buffer[15])); in cdrom_read_subchannel()
2034 subchnl->cdsc_reladdr.msf.minute = cgc.buffer[13]; in cdrom_read_subchannel()
2035 subchnl->cdsc_reladdr.msf.second = cgc.buffer[14]; in cdrom_read_subchannel()
2036 subchnl->cdsc_reladdr.msf.frame = cgc.buffer[15]; in cdrom_read_subchannel()
2037 subchnl->cdsc_absaddr.msf.minute = cgc.buffer[9]; in cdrom_read_subchannel()
2038 subchnl->cdsc_absaddr.msf.second = cgc.buffer[10]; in cdrom_read_subchannel()
2039 subchnl->cdsc_absaddr.msf.frame = cgc.buffer[11]; in cdrom_read_subchannel()
2052 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_read_cd()
2054 memset(&cgc->cmd, 0, sizeof(cgc->cmd)); in cdrom_read_cd()
2055 cgc->cmd[0] = GPCMD_READ_10; in cdrom_read_cd()
2056 cgc->cmd[2] = (lba >> 24) & 0xff; in cdrom_read_cd()
2057 cgc->cmd[3] = (lba >> 16) & 0xff; in cdrom_read_cd()
2058 cgc->cmd[4] = (lba >> 8) & 0xff; in cdrom_read_cd()
2059 cgc->cmd[5] = lba & 0xff; in cdrom_read_cd()
2060 cgc->cmd[6] = (nblocks >> 16) & 0xff; in cdrom_read_cd()
2061 cgc->cmd[7] = (nblocks >> 8) & 0xff; in cdrom_read_cd()
2062 cgc->cmd[8] = nblocks & 0xff; in cdrom_read_cd()
2063 cgc->buflen = blocksize * nblocks; in cdrom_read_cd()
2064 return cdo->generic_packet(cdi, cgc); in cdrom_read_cd()
2072 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_read_block()
2074 memset(&cgc->cmd, 0, sizeof(cgc->cmd)); in cdrom_read_block()
2075 cgc->cmd[0] = GPCMD_READ_CD; in cdrom_read_block()
2076 /* expected sector size - cdda,mode1,etc. */ in cdrom_read_block()
2077 cgc->cmd[1] = format << 2; in cdrom_read_block()
2079 cgc->cmd[2] = (lba >> 24) & 0xff; in cdrom_read_block()
2080 cgc->cmd[3] = (lba >> 16) & 0xff; in cdrom_read_block()
2081 cgc->cmd[4] = (lba >> 8) & 0xff; in cdrom_read_block()
2082 cgc->cmd[5] = lba & 0xff; in cdrom_read_block()
2084 cgc->cmd[6] = (nblocks >> 16) & 0xff; in cdrom_read_block()
2085 cgc->cmd[7] = (nblocks >> 8) & 0xff; in cdrom_read_block()
2086 cgc->cmd[8] = nblocks & 0xff; in cdrom_read_block()
2087 cgc->buflen = blksize * nblocks; in cdrom_read_block()
2091 case CD_FRAMESIZE_RAW0 : cgc->cmd[9] = 0x58; break; in cdrom_read_block()
2092 case CD_FRAMESIZE_RAW1 : cgc->cmd[9] = 0x78; break; in cdrom_read_block()
2093 case CD_FRAMESIZE_RAW : cgc->cmd[9] = 0xf8; break; in cdrom_read_block()
2094 default : cgc->cmd[9] = 0x10; in cdrom_read_block()
2097 return cdo->generic_packet(cdi, cgc); in cdrom_read_block()
2107 cdi->last_sense = 0; in cdrom_read_cdda_old()
2116 cgc.buffer = kmalloc_array(nr, CD_FRAMESIZE_RAW, GFP_KERNEL); in cdrom_read_cdda_old()
2117 if (cgc.buffer) in cdrom_read_cdda_old()
2124 return -ENOMEM; in cdrom_read_cdda_old()
2134 if (copy_to_user(ubuf, cgc.buffer, CD_FRAMESIZE_RAW * nr)) { in cdrom_read_cdda_old()
2135 ret = -EFAULT; in cdrom_read_cdda_old()
2139 nframes -= nr; in cdrom_read_cdda_old()
2142 kfree(cgc.buffer); in cdrom_read_cdda_old()
2149 int max_frames = (queue_max_sectors(cdi->disk->queue) << 9) / in cdrom_read_cdda_bpc()
2153 cdi->last_sense = 0; in cdrom_read_cdda_bpc()
2156 if (cdi->cdda_method == CDDA_BPC_SINGLE) in cdrom_read_cdda_bpc()
2161 ret = cdi->ops->read_cdda_bpc(cdi, ubuf, lba, nr, in cdrom_read_cdda_bpc()
2162 &cdi->last_sense); in cdrom_read_cdda_bpc()
2166 nframes -= nr; in cdrom_read_cdda_bpc()
2179 if (cdi->cdda_method == CDDA_OLD) in cdrom_read_cdda()
2187 if (!ret || ret != -EIO) in cdrom_read_cdda()
2194 if (cdi->cdda_method == CDDA_BPC_FULL && nframes > 1) { in cdrom_read_cdda()
2196 cdi->cdda_method = CDDA_BPC_SINGLE; in cdrom_read_cdda()
2205 if (cdi->last_sense != 0x04 && cdi->last_sense != 0x0b) in cdrom_read_cdda()
2208 pr_info("dropping to old style cdda (sense=%x)\n", cdi->last_sense); in cdrom_read_cdda()
2209 cdi->cdda_method = CDDA_OLD; in cdrom_read_cdda()
2219 if (!(cdi->ops->capability & CDC_MULTI_SESSION)) in cdrom_multisession()
2220 return -ENOSYS; in cdrom_multisession()
2222 requested_format = info->addr_format; in cdrom_multisession()
2224 return -EINVAL; in cdrom_multisession()
2225 info->addr_format = CDROM_LBA; in cdrom_multisession()
2227 ret = cdi->ops->get_last_session(cdi, info); in cdrom_multisession()
2229 sanitize_format(&info->addr, &info->addr_format, in cdrom_multisession()
2244 return -EFAULT; in cdrom_ioctl_multisession()
2249 return -EFAULT; in cdrom_ioctl_multisession()
2260 return -ENOSYS; in cdrom_ioctl_eject()
2261 if (cdi->use_count != 1 || cdi->keeplocked) in cdrom_ioctl_eject()
2262 return -EBUSY; in cdrom_ioctl_eject()
2264 int ret = cdi->ops->lock_door(cdi, 0); in cdrom_ioctl_eject()
2269 return cdi->ops->tray_move(cdi, 1); in cdrom_ioctl_eject()
2277 return -ENOSYS; in cdrom_ioctl_closetray()
2278 return cdi->ops->tray_move(cdi, 0); in cdrom_ioctl_closetray()
2287 return -ENOSYS; in cdrom_ioctl_eject_sw()
2288 if (cdi->keeplocked) in cdrom_ioctl_eject_sw()
2289 return -EBUSY; in cdrom_ioctl_eject_sw()
2291 cdi->options &= ~(CDO_AUTO_CLOSE | CDO_AUTO_EJECT); in cdrom_ioctl_eject_sw()
2293 cdi->options |= CDO_AUTO_CLOSE | CDO_AUTO_EJECT; in cdrom_ioctl_eject_sw()
2306 return -ENOSYS; in cdrom_ioctl_media_changed()
2312 if (arg >= cdi->capacity) in cdrom_ioctl_media_changed()
2313 return -EINVAL; in cdrom_ioctl_media_changed()
2316 arg = array_index_nospec(arg, cdi->capacity); in cdrom_ioctl_media_changed()
2320 return -ENOMEM; in cdrom_ioctl_media_changed()
2324 ret = info->slots[arg].change; in cdrom_ioctl_media_changed()
2333 * arg->last_media_change may be set by calling code to signal
2335 * Upon successful return, ioctl call will set arg->last_media_change
2337 * and set arg->has_changed to 1 if that timestamp is more recent
2348 return -ENOSYS; in cdrom_ioctl_timed_media_change()
2358 return -EFAULT; in cdrom_ioctl_timed_media_change()
2361 if (cdi->last_media_change_ms > tmp_info.last_media_change) in cdrom_ioctl_timed_media_change()
2364 tmp_info.last_media_change = cdi->last_media_change_ms; in cdrom_ioctl_timed_media_change()
2367 return -EFAULT; in cdrom_ioctl_timed_media_change()
2387 return -ENOSYS; in cdrom_ioctl_set_options()
2390 return cdi->options; in cdrom_ioctl_set_options()
2394 return -ENOSYS; in cdrom_ioctl_set_options()
2396 cdi->options |= (int) arg; in cdrom_ioctl_set_options()
2397 return cdi->options; in cdrom_ioctl_set_options()
2405 cdi->options &= ~(int) arg; in cdrom_ioctl_clear_options()
2406 return cdi->options; in cdrom_ioctl_clear_options()
2415 return -ENOSYS; in cdrom_ioctl_select_speed()
2416 return cdi->ops->select_speed(cdi, arg); in cdrom_ioctl_select_speed()
2425 return -ENOSYS; in cdrom_ioctl_select_disc()
2428 if (arg >= cdi->capacity) in cdrom_ioctl_select_disc()
2429 return -EINVAL; in cdrom_ioctl_select_disc()
2442 return -EACCES; in cdrom_ioctl_reset()
2444 return -ENOSYS; in cdrom_ioctl_reset()
2446 return cdi->ops->reset(cdi); in cdrom_ioctl_reset()
2455 return -EDRIVE_CANT_DO_THIS; in cdrom_ioctl_lock_door()
2457 cdi->keeplocked = arg ? 1 : 0; in cdrom_ioctl_lock_door()
2463 if (cdi->use_count != 1 && !arg && !capable(CAP_SYS_ADMIN)) in cdrom_ioctl_lock_door()
2464 return -EBUSY; in cdrom_ioctl_lock_door()
2465 return cdi->ops->lock_door(cdi, arg); in cdrom_ioctl_lock_door()
2474 return -EACCES; in cdrom_ioctl_debug()
2482 return (cdi->ops->capability & ~cdi->mask); in cdrom_ioctl_get_capability()
2499 if (!(cdi->ops->capability & CDC_MCN)) in cdrom_ioctl_get_mcn()
2500 return -ENOSYS; in cdrom_ioctl_get_mcn()
2501 ret = cdi->ops->get_mcn(cdi, &mcn); in cdrom_ioctl_get_mcn()
2506 return -EFAULT; in cdrom_ioctl_get_mcn()
2516 if (!(cdi->ops->capability & CDC_DRIVE_STATUS)) in cdrom_ioctl_drive_status()
2517 return -ENOSYS; in cdrom_ioctl_drive_status()
2520 return cdi->ops->drive_status(cdi, CDSL_CURRENT); in cdrom_ioctl_drive_status()
2521 if (arg >= cdi->capacity) in cdrom_ioctl_drive_status()
2522 return -EINVAL; in cdrom_ioctl_drive_status()
2537 * wasn't designed to use bitmasks... -Erik
2539 * Well, now we have the option CDS_MIXED: a mixed-type CD.
2541 * ---david
2576 return cdi->capacity; in cdrom_ioctl_changer_nslots()
2589 return -EFAULT; in cdrom_ioctl_get_subchnl()
2593 return -EINVAL; in cdrom_ioctl_get_subchnl()
2596 ret = cdi->ops->audio_ioctl(cdi, CDROMSUBCHNL, &q); in cdrom_ioctl_get_subchnl()
2605 return -EFAULT; in cdrom_ioctl_get_subchnl()
2619 return -EFAULT; in cdrom_ioctl_read_tochdr()
2621 ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header); in cdrom_ioctl_read_tochdr()
2626 return -EFAULT; in cdrom_ioctl_read_tochdr()
2634 u8 requested_format = entry->cdte_format; in cdrom_read_tocentry()
2638 return -EINVAL; in cdrom_read_tocentry()
2640 /* make interface to low-level uniform */ in cdrom_read_tocentry()
2641 entry->cdte_format = CDROM_MSF; in cdrom_read_tocentry()
2642 ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, entry); in cdrom_read_tocentry()
2644 sanitize_format(&entry->cdte_addr, &entry->cdte_format, in cdrom_read_tocentry()
2657 return -EFAULT; in cdrom_ioctl_read_tocentry()
2660 return -EFAULT; in cdrom_ioctl_read_tocentry()
2672 return -ENOSYS; in cdrom_ioctl_play_msf()
2674 return -EFAULT; in cdrom_ioctl_play_msf()
2675 return cdi->ops->audio_ioctl(cdi, CDROMPLAYMSF, &msf); in cdrom_ioctl_play_msf()
2687 return -ENOSYS; in cdrom_ioctl_play_trkind()
2689 return -EFAULT; in cdrom_ioctl_play_trkind()
2691 ret = check_for_audio_disc(cdi, cdi->ops); in cdrom_ioctl_play_trkind()
2694 return cdi->ops->audio_ioctl(cdi, CDROMPLAYTRKIND, &ti); in cdrom_ioctl_play_trkind()
2704 return -ENOSYS; in cdrom_ioctl_volctrl()
2706 return -EFAULT; in cdrom_ioctl_volctrl()
2707 return cdi->ops->audio_ioctl(cdi, CDROMVOLCTRL, &volume); in cdrom_ioctl_volctrl()
2719 return -ENOSYS; in cdrom_ioctl_volread()
2721 ret = cdi->ops->audio_ioctl(cdi, CDROMVOLREAD, &volume); in cdrom_ioctl_volread()
2726 return -EFAULT; in cdrom_ioctl_volread()
2738 return -ENOSYS; in cdrom_ioctl_audioctl()
2739 ret = check_for_audio_disc(cdi, cdi->ops); in cdrom_ioctl_audioctl()
2742 return cdi->ops->audio_ioctl(cdi, cmd, NULL); in cdrom_ioctl_audioctl()
2751 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_switch_blocksize()
2765 cgc.buffer = (char *) &mh; in cdrom_switch_blocksize()
2771 return cdo->generic_packet(cdi, &cgc); in cdrom_switch_blocksize()
2777 const struct cdrom_device_ops *cdo = cdi->ops; in cdrom_get_track_info()
2789 ret = cdo->generic_packet(cdi, &cgc); in cdrom_get_track_info()
2793 buflen = be16_to_cpu(ti->track_information_length) + in cdrom_get_track_info()
2794 sizeof(ti->track_information_length); in cdrom_get_track_info()
2800 ret = cdo->generic_packet(cdi, &cgc); in cdrom_get_track_info()
2808 /* return the last written block on the CD-R media. this is for the udf
2816 int ret = -1, ti_size; in cdrom_get_last_written()
2836 last_track--; in cdrom_get_last_written()
2853 *last_written -= (be32_to_cpu(ti.free_blocks) + 7); in cdrom_get_last_written()
2863 return -ENOSYS; in cdrom_get_last_written()
2867 if ((ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &toc))) in cdrom_get_last_written()
2902 last_track--; in cdrom_get_next_writable()
2949 return -EFAULT; in mmc_ioctl_cdrom_read_data()
2953 return -EINVAL; in mmc_ioctl_cdrom_read_data()
2955 cgc->buffer = kzalloc(blocksize, GFP_KERNEL); in mmc_ioctl_cdrom_read_data()
2956 if (cgc->buffer == NULL) in mmc_ioctl_cdrom_read_data()
2957 return -ENOMEM; in mmc_ioctl_cdrom_read_data()
2960 cgc->sshdr = &sshdr; in mmc_ioctl_cdrom_read_data()
2961 cgc->data_direction = CGC_DATA_READ; in mmc_ioctl_cdrom_read_data()
2967 * SCSI-II devices are not required to support in mmc_ioctl_cdrom_read_data()
2975 cgc->sshdr = NULL; in mmc_ioctl_cdrom_read_data()
2980 if (!ret && copy_to_user(arg, cgc->buffer, blocksize)) in mmc_ioctl_cdrom_read_data()
2981 ret = -EFAULT; in mmc_ioctl_cdrom_read_data()
2983 kfree(cgc->buffer); in mmc_ioctl_cdrom_read_data()
3003 return -EFAULT; in mmc_ioctl_cdrom_read_audio()
3016 return -EFAULT; in mmc_ioctl_cdrom_read_audio()
3026 return -EINVAL; in mmc_ioctl_cdrom_read_audio()
3030 return -EINVAL; in mmc_ioctl_cdrom_read_audio()
3042 return -EFAULT; in mmc_ioctl_cdrom_subchannel()
3046 return -EINVAL; in mmc_ioctl_cdrom_subchannel()
3055 return -EFAULT; in mmc_ioctl_cdrom_subchannel()
3064 const struct cdrom_device_ops *cdo = cdi->ops; in mmc_ioctl_cdrom_play_msf()
3068 return -EFAULT; in mmc_ioctl_cdrom_play_msf()
3069 cgc->cmd[0] = GPCMD_PLAY_AUDIO_MSF; in mmc_ioctl_cdrom_play_msf()
3070 cgc->cmd[3] = msf.cdmsf_min0; in mmc_ioctl_cdrom_play_msf()
3071 cgc->cmd[4] = msf.cdmsf_sec0; in mmc_ioctl_cdrom_play_msf()
3072 cgc->cmd[5] = msf.cdmsf_frame0; in mmc_ioctl_cdrom_play_msf()
3073 cgc->cmd[6] = msf.cdmsf_min1; in mmc_ioctl_cdrom_play_msf()
3074 cgc->cmd[7] = msf.cdmsf_sec1; in mmc_ioctl_cdrom_play_msf()
3075 cgc->cmd[8] = msf.cdmsf_frame1; in mmc_ioctl_cdrom_play_msf()
3076 cgc->data_direction = CGC_DATA_NONE; in mmc_ioctl_cdrom_play_msf()
3077 return cdo->generic_packet(cdi, cgc); in mmc_ioctl_cdrom_play_msf()
3084 const struct cdrom_device_ops *cdo = cdi->ops; in mmc_ioctl_cdrom_play_blk()
3088 return -EFAULT; in mmc_ioctl_cdrom_play_blk()
3089 cgc->cmd[0] = GPCMD_PLAY_AUDIO_10; in mmc_ioctl_cdrom_play_blk()
3090 cgc->cmd[2] = (blk.from >> 24) & 0xff; in mmc_ioctl_cdrom_play_blk()
3091 cgc->cmd[3] = (blk.from >> 16) & 0xff; in mmc_ioctl_cdrom_play_blk()
3092 cgc->cmd[4] = (blk.from >> 8) & 0xff; in mmc_ioctl_cdrom_play_blk()
3093 cgc->cmd[5] = blk.from & 0xff; in mmc_ioctl_cdrom_play_blk()
3094 cgc->cmd[7] = (blk.len >> 8) & 0xff; in mmc_ioctl_cdrom_play_blk()
3095 cgc->cmd[8] = blk.len & 0xff; in mmc_ioctl_cdrom_play_blk()
3096 cgc->data_direction = CGC_DATA_NONE; in mmc_ioctl_cdrom_play_blk()
3097 return cdo->generic_packet(cdi, cgc); in mmc_ioctl_cdrom_play_blk()
3106 unsigned char buffer[32]; in mmc_ioctl_cdrom_volume() local
3107 char mask[sizeof(buffer)]; in mmc_ioctl_cdrom_volume()
3108 unsigned short offset; in mmc_ioctl_cdrom_volume() local
3115 return -EFAULT; in mmc_ioctl_cdrom_volume()
3117 cgc->buffer = buffer; in mmc_ioctl_cdrom_volume()
3118 cgc->buflen = 24; in mmc_ioctl_cdrom_volume()
3123 /* originally the code depended on buffer[1] to determine in mmc_ioctl_cdrom_volume()
3124 how much data is available for transfer. buffer[1] is in mmc_ioctl_cdrom_volume()
3127 offset = 8 + be16_to_cpu(*(__be16 *)(buffer + 6)); in mmc_ioctl_cdrom_volume()
3129 if (offset + 16 > sizeof(buffer)) in mmc_ioctl_cdrom_volume()
3130 return -E2BIG; in mmc_ioctl_cdrom_volume()
3132 if (offset + 16 > cgc->buflen) { in mmc_ioctl_cdrom_volume()
3133 cgc->buflen = offset + 16; in mmc_ioctl_cdrom_volume()
3141 if ((buffer[offset] & 0x3f) != GPMODE_AUDIO_CTL_PAGE || in mmc_ioctl_cdrom_volume()
3142 buffer[offset + 1] < 14) in mmc_ioctl_cdrom_volume()
3143 return -EINVAL; in mmc_ioctl_cdrom_volume()
3148 volctrl.channel0 = buffer[offset+9]; in mmc_ioctl_cdrom_volume()
3149 volctrl.channel1 = buffer[offset+11]; in mmc_ioctl_cdrom_volume()
3150 volctrl.channel2 = buffer[offset+13]; in mmc_ioctl_cdrom_volume()
3151 volctrl.channel3 = buffer[offset+15]; in mmc_ioctl_cdrom_volume()
3154 return -EFAULT; in mmc_ioctl_cdrom_volume()
3159 cgc->buffer = mask; in mmc_ioctl_cdrom_volume()
3164 buffer[offset + 9] = volctrl.channel0 & mask[offset + 9]; in mmc_ioctl_cdrom_volume()
3165 buffer[offset + 11] = volctrl.channel1 & mask[offset + 11]; in mmc_ioctl_cdrom_volume()
3166 buffer[offset + 13] = volctrl.channel2 & mask[offset + 13]; in mmc_ioctl_cdrom_volume()
3167 buffer[offset + 15] = volctrl.channel3 & mask[offset + 15]; in mmc_ioctl_cdrom_volume()
3170 cgc->buffer = buffer + offset - 8; in mmc_ioctl_cdrom_volume()
3171 memset(cgc->buffer, 0, 8); in mmc_ioctl_cdrom_volume()
3179 const struct cdrom_device_ops *cdo = cdi->ops; in mmc_ioctl_cdrom_start_stop()
3181 cgc->cmd[0] = GPCMD_START_STOP_UNIT; in mmc_ioctl_cdrom_start_stop()
3182 cgc->cmd[1] = 1; in mmc_ioctl_cdrom_start_stop()
3183 cgc->cmd[4] = (cmd == CDROMSTART) ? 1 : 0; in mmc_ioctl_cdrom_start_stop()
3184 cgc->data_direction = CGC_DATA_NONE; in mmc_ioctl_cdrom_start_stop()
3185 return cdo->generic_packet(cdi, cgc); in mmc_ioctl_cdrom_start_stop()
3192 const struct cdrom_device_ops *cdo = cdi->ops; in mmc_ioctl_cdrom_pause_resume()
3194 cgc->cmd[0] = GPCMD_PAUSE_RESUME; in mmc_ioctl_cdrom_pause_resume()
3195 cgc->cmd[8] = (cmd == CDROMRESUME) ? 1 : 0; in mmc_ioctl_cdrom_pause_resume()
3196 cgc->data_direction = CGC_DATA_NONE; in mmc_ioctl_cdrom_pause_resume()
3197 return cdo->generic_packet(cdi, cgc); in mmc_ioctl_cdrom_pause_resume()
3209 return -ENOSYS; in mmc_ioctl_dvd_read_struct()
3222 ret = -EFAULT; in mmc_ioctl_dvd_read_struct()
3234 return -ENOSYS; in mmc_ioctl_dvd_auth()
3237 return -EFAULT; in mmc_ioctl_dvd_auth()
3242 return -EFAULT; in mmc_ioctl_dvd_auth()
3256 return -EFAULT; in mmc_ioctl_cdrom_next_writable()
3284 cdo->generic_packet() */ in mmc_ioctl()
3317 return -ENOTTY; in mmc_ioctl()
3321 * Just about every imaginable ioctl is supported in the Uniform layer
3372 * interface. this may look at bit funny, but if -ENOTTY is in cdrom_ioctl()
3378 if (ret != -ENOTTY) in cdrom_ioctl()
3409 return -ENOSYS; in cdrom_ioctl()
3440 ret = scnprintf(info + *pos, max_size - *pos, header); in cdrom_print_info()
3449 ret = scnprintf(info + *pos, max_size - *pos, in cdrom_print_info()
3450 "\t%s", cdi->name); in cdrom_print_info()
3453 ret = scnprintf(info + *pos, max_size - *pos, in cdrom_print_info()
3454 "\t%d", cdi->speed); in cdrom_print_info()
3457 ret = scnprintf(info + *pos, max_size - *pos, in cdrom_print_info()
3458 "\t%d", cdi->capacity); in cdrom_print_info()
3461 ret = scnprintf(info + *pos, max_size - *pos, in cdrom_print_info()
3477 void *buffer, size_t *lenp, loff_t *ppos) in cdrom_sysctl_info() argument
3490 pos = sprintf(info, "CD-ROM information, " VERSION "\n"); in cdrom_sysctl_info()
3525 if (cdrom_print_info("\nCan write CD-R:\t", in cdrom_sysctl_info()
3528 if (cdrom_print_info("\nCan write CD-RW:", in cdrom_sysctl_info()
3534 if (cdrom_print_info("\nCan write DVD-R:", in cdrom_sysctl_info()
3537 if (cdrom_print_info("\nCan write DVD-RAM:", in cdrom_sysctl_info()
3549 if (!scnprintf(info + pos, max_size - pos, "\n\n")) in cdrom_sysctl_info()
3553 return proc_dostring(ctl, write, buffer, lenp, ppos); in cdrom_sysctl_info()
3555 pr_info("info buffer too small\n"); in cdrom_sysctl_info()
3570 cdi->options |= CDO_AUTO_CLOSE; in cdrom_update_settings()
3572 cdi->options &= ~CDO_AUTO_CLOSE; in cdrom_update_settings()
3574 cdi->options |= CDO_AUTO_EJECT; in cdrom_update_settings()
3576 cdi->options &= ~CDO_AUTO_EJECT; in cdrom_update_settings()
3578 cdi->options |= CDO_LOCK; in cdrom_update_settings()
3580 cdi->options &= ~CDO_LOCK; in cdrom_update_settings()
3582 cdi->options |= CDO_CHECK_TYPE; in cdrom_update_settings()
3584 cdi->options &= ~CDO_CHECK_TYPE; in cdrom_update_settings()
3590 void *buffer, size_t *lenp, loff_t *ppos) in cdrom_sysctl_handler() argument
3594 ret = proc_dointvec(ctl, write, buffer, lenp, ppos); in cdrom_sysctl_handler()
3706 pr_info("Uniform CD-ROM driver unloaded\n"); in cdrom_exit()