Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) /* linux/drivers/cdrom/cdrom.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)    Copyright (c) 1996, 1997 David A. van Leeuwen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)    Copyright (c) 1997, 1998 Erik Andersen <andersee@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)    Copyright (c) 1998, 1999 Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)    May be copied or modified under the terms of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)    License.  See linux/COPYING for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)    Uniform CD-ROM driver for Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)    See Documentation/cdrom/cdrom-standard.rst for usage information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)    The routines in the file provide a uniform interface between the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)    software that uses CD-ROMs and the various low-level drivers that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)    actually talk to the hardware. Suggestions are welcome.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)    Patches that work are more welcome though.  ;-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  To Do List:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  ----------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  -- Modify sysctl/proc interface. I plan on having one directory per
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  drive, with entries for outputing general drive information, and sysctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  based tunable parameters such as whether the tray should auto-close for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  that drive. Suggestions (or patches) for this welcome!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  Revision History
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  ----------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  1.00  Date Unknown -- David van Leeuwen <david@tm.tno.nl>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  -- Initial version by David A. van Leeuwen. I don't have a detailed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)   changelog for the 1.x series, David?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 2.00  Dec  2, 1997 -- Erik Andersen <andersee@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)   -- New maintainer! As David A. van Leeuwen has been too busy to actively
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)   maintain and improve this driver, I am now carrying on the torch. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)   you have a problem with this driver, please feel free to contact me.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)   -- Added (rudimentary) sysctl interface. I realize this is really weak
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)   right now, and is _very_ badly implemented. It will be improved...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)   -- Modified CDROM_DISC_STATUS so that it is now incorporated into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)   the Uniform CD-ROM driver via the cdrom_count_tracks function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)   The cdrom_count_tracks function helps resolve some of the false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)   assumptions of the CDROM_DISC_STATUS ioctl, and is also used to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)   for the correct media type when mounting or playing audio from a CD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)   -- Remove the calls to verify_area and only use the copy_from_user and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)   copy_to_user stuff, since these calls now provide their own memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)   checking with the 2.1.x kernels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)   -- Major update to return codes so that errors from low-level drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)   are passed on through (thanks to Gerd Knorr for pointing out this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)   problem).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)   -- Made it so if a function isn't implemented in a low-level driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)   ENOSYS is now returned instead of EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)   -- Simplified some complex logic so that the source code is easier to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)   -- Other stuff I probably forgot to mention (lots of changes).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 2.01 to 2.11 Dec 1997-Jan 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)   -- TO-DO!  Write changelogs for 2.01 to 2.12.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 2.12  Jan  24, 1998 -- Erik Andersen <andersee@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)   -- Fixed a bug in the IOCTL_IN and IOCTL_OUT macros.  It turns out that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)   copy_*_user does not return EFAULT on error, but instead returns the number 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)   of bytes not copied.  I was returning whatever non-zero stuff came back from 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)   the copy_*_user functions directly, which would result in strange errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 2.13  July 17, 1998 -- Erik Andersen <andersee@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)   -- Fixed a bug in CDROM_SELECT_SPEED where you couldn't lower the speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)   of the drive.  Thanks to Tobias Ringstr|m <tori@prosolvia.se> for pointing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)   this out and providing a simple fix.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)   -- Fixed the procfs-unload-module bug with the fill_inode procfs callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)   thanks to Andrea Arcangeli
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)   -- Fixed it so that the /proc entry now also shows up when cdrom is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)   compiled into the kernel.  Before it only worked when loaded as a module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)   2.14 August 17, 1998 -- Erik Andersen <andersee@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)   -- Fixed a bug in cdrom_media_changed and handling of reporting that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)   the media had changed for devices that _don't_ implement media_changed.  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)   Thanks to Grant R. Guenther <grant@torque.net> for spotting this bug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)   -- Made a few things more pedanticly correct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 2.50 Oct 19, 1998 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)   -- New maintainers! Erik was too busy to continue the work on the driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)   so now Chris Zwilling <chris@cloudnet.com> and Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)   will do their best to follow in his footsteps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)   2.51 Dec 20, 1998 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)   -- Check if drive is capable of doing what we ask before blindly changing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)   cdi->options in various ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)   -- Added version to proc entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)   2.52 Jan 16, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)   -- Fixed an error in open_for_data where we would sometimes not return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)   the correct error value. Thanks Huba Gaspar <huba@softcell.hu>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)   -- Fixed module usage count - usage was based on /proc/sys/dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)   instead of /proc/sys/dev/cdrom. This could lead to an oops when other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)   modules had entries in dev. Feb 02 - real bug was in sysctl.c where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)   dev would be removed even though it was used. cdrom.c just illuminated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)   that bug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)   2.53 Feb 22, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)   -- Fixup of several ioctl calls, in particular CDROM_SET_OPTIONS has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)   been "rewritten" because capabilities and options aren't in sync. They
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)   should be...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)   -- Added CDROM_LOCKDOOR ioctl. Locks the door and keeps it that way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)   -- Added CDROM_RESET ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)   -- Added CDROM_DEBUG ioctl. Enable debug messages on-the-fly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)   -- Added CDROM_GET_CAPABILITY ioctl. This relieves userspace programs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)   from parsing /proc/sys/dev/cdrom/info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)   2.54 Mar 15, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)   -- Check capability mask from low level driver when counting tracks as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)   per suggestion from Corey J. Scotts <cstotts@blue.weeg.uiowa.edu>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)   2.55 Apr 25, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119)   -- autoclose was mistakenly checked against CDC_OPEN_TRAY instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120)   CDC_CLOSE_TRAY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121)   -- proc info didn't mask against capabilities mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)   3.00 Aug 5, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)   -- Unified audio ioctl handling across CD-ROM drivers. A lot of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)   code was duplicated before. Drives that support the generic packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)   interface are now being fed packets from here instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)   -- First attempt at adding support for MMC2 commands - for DVD and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)   CD-R(W) drives. Only the DVD parts are in now - the interface used is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)   the same as for the audio ioctls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)   -- ioctl cleanups. if a drive couldn't play audio, it didn't get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)   a change to perform device specific ioctls as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)   -- Defined CDROM_CAN(CDC_XXX) for checking the capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)   -- Put in sysctl files for autoclose, autoeject, check_media, debug,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)   and lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)   -- /proc/sys/dev/cdrom/info has been updated to also contain info about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)   CD-Rx and DVD capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)   -- Now default to checking media type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)   -- CDROM_SEND_PACKET ioctl added. The infrastructure was in place for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139)   doing this anyway, with the generic_packet addition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141)   3.01 Aug 6, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142)   -- Fix up the sysctl handling so that the option flags get set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143)   correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144)   -- Fix up ioctl handling so the device specific ones actually get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145)   called :).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147)   3.02 Aug 8, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148)   -- Fixed volume control on SCSI drives (or others with longer audio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149)   page).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150)   -- Fixed a couple of DVD minors. Thanks to Andrew T. Veliath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151)   <andrewtv@usa.net> for telling me and for having defined the various
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152)   DVD structures and ioctls in the first place! He designed the original
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153)   DVD patches for ide-cd and while I rearranged and unified them, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154)   interface is still the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156)   3.03 Sep 1, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157)   -- Moved the rest of the audio ioctls from the CD-ROM drivers here. Only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158)   CDROMREADTOCENTRY and CDROMREADTOCHDR are left.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159)   -- Moved the CDROMREADxxx ioctls in here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)   -- Defined the cdrom_get_last_written and cdrom_get_next_block as ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)   and exported functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)   -- Erik Andersen <andersen@xmission.com> modified all SCMD_ commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)   to now read GPCMD_ for the new generic packet interface. All low level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)   drivers are updated as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165)   -- Various other cleanups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)   3.04 Sep 12, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)   -- Fixed a couple of possible memory leaks (if an operation failed and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)   we didn't free the buffer before returning the error).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)   -- Integrated Uniform CD Changer handling from Richard Sharman
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)   <rsharman@pobox.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)   -- Defined CD_DVD and CD_CHANGER log levels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)   -- Fixed the CDROMREADxxx ioctls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)   -- CDROMPLAYTRKIND uses the GPCMD_PLAY_AUDIO_MSF command - too few
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175)   drives supported it. We lose the index part, however.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176)   -- Small modifications to accommodate opens of /dev/hdc1, required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177)   for ide-cd to handle multisession discs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178)   -- Export cdrom_mode_sense and cdrom_mode_select.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179)   -- init_cdrom_command() for setting up a cgc command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181)   3.05 Oct 24, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182)   -- Changed the interface for CDROM_SEND_PACKET. Before it was virtually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183)   impossible to send the drive data in a sensible way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184)   -- Lowered stack usage in mmc_ioctl(), dvd_read_disckey(), and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)   dvd_read_manufact.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186)   -- Added setup of write mode for packet writing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187)   -- Fixed CDDA ripping with cdda2wav - accept much larger requests of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)   number of frames and split the reads in blocks of 8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)   3.06 Dec 13, 1999 - Jens Axboe <axboe@image.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)   -- Added support for changing the region of DVD drives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)   -- Added sense data to generic command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)   3.07 Feb 2, 2000 - Jens Axboe <axboe@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)   -- Do same "read header length" trick in cdrom_get_disc_info() as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)   we do in cdrom_get_track_info() -- some drive don't obey specs and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)   fail if they can't supply the full Mt Fuji size table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)   -- Deleted stuff related to setting up write modes. It has a different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)   home now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200)   -- Clear header length in mode_select unconditionally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201)   -- Removed the register_disk() that was added, not needed here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203)   3.08 May 1, 2000 - Jens Axboe <axboe@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204)   -- Fix direction flag in setup_send_key and setup_report_key. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205)   gave some SCSI adapters problems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206)   -- Always return -EROFS for write opens
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207)   -- Convert to module_init/module_exit style init and remove some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208)   of the #ifdef MODULE stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209)   -- Fix several dvd errors - DVD_LU_SEND_ASF should pass agid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)   DVD_HOST_SEND_RPC_STATE did not set buffer size in cdb, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211)   dvd_do_auth passed uninitialized data to drive because init_cdrom_command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)   did not clear a 0 sized buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214)   3.09 May 12, 2000 - Jens Axboe <axboe@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215)   -- Fix Video-CD on SCSI drives that don't support READ_CD command. In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216)   that case switch block size and issue plain READ_10 again, then switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)   back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)   3.10 Jun 10, 2000 - Jens Axboe <axboe@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)   -- Fix volume control on CD's - old SCSI-II drives now use their own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)   code, as doing MODE6 stuff in here is really not my intention.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)   -- Use READ_DISC_INFO for more reliable end-of-disc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224)   3.11 Jun 12, 2000 - Jens Axboe <axboe@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)   -- Fix bug in getting rpc phase 2 region info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226)   -- Reinstate "correct" CDROMPLAYTRKIND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)    3.12 Oct 18, 2000 - Jens Axboe <axboe@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229)   -- Use quiet bit on packet commands not known to work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231)    3.20 Dec 17, 2003 - Jens Axboe <axboe@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232)   -- Various fixes and lots of cleanups not listed :-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233)   -- Locking fixes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)   -- Mt Rainier support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235)   -- DVD-RAM write open fixes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237)   Nov 5 2001, Aug 8 2002. Modified by Andy Polyakov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238)   <appro@fy.chalmers.se> to support MMC-3 compliant DVD+RW units.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240)   Modified by Nigel Kukard <nkukard@lbsd.net> - support DVD+RW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241)   2.4.x patch by Andy Polyakov <appro@fy.chalmers.se>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) -------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) #define REVISION "Revision: 3.20"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) #define VERSION "Id: cdrom.c 3.20 2003/12/17"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) /* I use an error-log mask to give fine grain control over the type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251)    messages dumped to the system logs.  The available masks include: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) #define CD_NOTHING      0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) #define CD_WARNING	0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) #define CD_REG_UNREG	0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) #define CD_DO_IOCTL	0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) #define CD_OPEN		0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) #define CD_CLOSE	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) #define CD_COUNT_TRACKS 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) #define CD_CHANGER	0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) #define CD_DVD		0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) /* Define this to remove _all_ the debugging messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) /* #define ERRLOGMASK CD_NOTHING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) #define ERRLOGMASK CD_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) /* #define ERRLOGMASK (CD_WARNING|CD_OPEN|CD_COUNT_TRACKS|CD_CLOSE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) /* #define ERRLOGMASK (CD_WARNING|CD_REG_UNREG|CD_DO_IOCTL|CD_OPEN|CD_CLOSE|CD_COUNT_TRACKS) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) #include <linux/slab.h> 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) #include <linux/cdrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) #include <linux/blkpg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) #include <linux/times.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) #include <scsi/scsi_common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) #include <scsi/scsi_request.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) /* used to tell the module to turn on full debugging messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) static bool debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) /* default compatibility mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) static bool autoclose=1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) static bool autoeject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) static bool lockdoor = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) /* will we ever get to use this... sigh. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) static bool check_media_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) /* automatically restart mrw format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) static bool mrw_format_restart = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) module_param(debug, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) module_param(autoclose, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) module_param(autoeject, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) module_param(lockdoor, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) module_param(check_media_type, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) module_param(mrw_format_restart, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) static DEFINE_MUTEX(cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) static const char *mrw_format_status[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	"not mrw",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	"bgformat inactive",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	"bgformat active",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	"mrw complete",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) static const char *mrw_address_space[] = { "DMA", "GAA" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) #if (ERRLOGMASK != CD_NOTHING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) #define cd_dbg(type, fmt, ...)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) do {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	if ((ERRLOGMASK & type) || debug == 1)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		pr_debug(fmt, ##__VA_ARGS__);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) #define cd_dbg(type, fmt, ...)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) do {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	if (0 && (ERRLOGMASK & type) || debug == 1)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		pr_debug(fmt, ##__VA_ARGS__);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) /* The (cdo->capability & ~cdi->mask & CDC_XXX) construct was used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332)    a lot of places. This macro makes the code more clear. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) #define CDROM_CAN(type) (cdi->ops->capability & ~cdi->mask & (type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336)  * Another popular OS uses 7 seconds as the hard timeout for default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337)  * commands, so it is a good choice for us as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) #define CDROM_DEF_TIMEOUT	(7 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) /* Not-exported routines. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) static void cdrom_sysctl_register(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) static LIST_HEAD(cdrom_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			       struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	if (cgc->sshdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		cgc->sshdr->sense_key = 0x05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		cgc->sshdr->asc = 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		cgc->sshdr->ascq = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	cgc->stat = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) EXPORT_SYMBOL(cdrom_dummy_generic_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) static int cdrom_flush_cache(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	init_cdrom_command(&cgc, NULL, 0, CGC_DATA_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	cgc.cmd[0] = GPCMD_FLUSH_CACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	cgc.timeout = 5 * 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	return cdi->ops->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) /* requires CD R/RW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) static int cdrom_get_disc_info(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			       disc_information *di)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	int ret, buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	/* set up command and get the disc info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	init_cdrom_command(&cgc, di, sizeof(*di), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	cgc.cmd[0] = GPCMD_READ_DISC_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	cgc.cmd[8] = cgc.buflen = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	ret = cdo->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	/* not all drives have the same disc_info length, so requeue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	 * packet with the length the drive tells us it can supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	buflen = be16_to_cpu(di->disc_information_length) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		sizeof(di->disc_information_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	if (buflen > sizeof(disc_information))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		buflen = sizeof(disc_information);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	cgc.cmd[8] = cgc.buflen = buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	ret = cdo->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	/* return actual fill size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	return buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) /* This macro makes sure we don't have to check on cdrom_device_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  * existence in the run-time routines below. Change_capability is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  * hack to have the capability flags defined const, while we can still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  * change it here without gcc complaining at every line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) #define ENSURE(cdo, call, bits)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	if (cdo->call == NULL)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		WARN_ON_ONCE((cdo)->capability & (bits));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421)  * the first prototypes used 0x2c as the page code for the mrw mode page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422)  * subsequently this was changed to 0x03. probe the one used by this drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) static int cdrom_mrw_probe_pc(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	char buffer[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	cgc.timeout = HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	if (!cdrom_mode_sense(cdi, &cgc, MRW_MODE_PC, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		cdi->mrw_mode_page = MRW_MODE_PC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	} else if (!cdrom_mode_sense(cdi, &cgc, MRW_MODE_PC_PRE1, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		cdi->mrw_mode_page = MRW_MODE_PC_PRE1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) static int cdrom_is_mrw(struct cdrom_device_info *cdi, int *write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	struct mrw_feature_desc *mfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	unsigned char buffer[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	*write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	cgc.cmd[0] = GPCMD_GET_CONFIGURATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	cgc.cmd[3] = CDF_MRW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	cgc.cmd[8] = sizeof(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	mfd = (struct mrw_feature_desc *)&buffer[sizeof(struct feature_header)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	if (be16_to_cpu(mfd->feature_code) != CDF_MRW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	*write = mfd->write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	if ((ret = cdrom_mrw_probe_pc(cdi))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		*write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) static int cdrom_mrw_bgformat(struct cdrom_device_info *cdi, int cont)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	unsigned char buffer[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	pr_info("%sstarting format\n", cont ? "Re" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	 * FmtData bit set (bit 4), format type is 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	cgc.cmd[0] = GPCMD_FORMAT_UNIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	cgc.cmd[1] = (1 << 4) | 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	cgc.timeout = 5 * 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	 * 4 byte format list header, 8 byte format list descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	buffer[1] = 1 << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	buffer[3] = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	 * nr_blocks field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	buffer[4] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	buffer[5] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	buffer[6] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	buffer[7] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	buffer[8] = 0x24 << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	buffer[11] = cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	ret = cdi->ops->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		pr_info("bgformat failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) static int cdrom_mrw_bgformat_susp(struct cdrom_device_info *cdi, int immed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	init_cdrom_command(&cgc, NULL, 0, CGC_DATA_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	cgc.cmd[0] = GPCMD_CLOSE_TRACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	 * Session = 1, Track = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	cgc.cmd[1] = !!immed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	cgc.cmd[2] = 1 << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	cgc.timeout = 5 * 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	return cdi->ops->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) static int cdrom_mrw_exit(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	disc_information di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	ret = cdrom_get_disc_info(cdi, &di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	if (ret < 0 || ret < (int)offsetof(typeof(di),disc_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	if (di.mrw_status == CDM_MRW_BGFORMAT_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		pr_info("issuing MRW background format suspend\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		ret = cdrom_mrw_bgformat_susp(cdi, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	if (!ret && cdi->media_written)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		ret = cdrom_flush_cache(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) static int cdrom_mrw_set_lba_space(struct cdrom_device_info *cdi, int space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	struct mode_page_header *mph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	char buffer[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	int ret, offset, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	cgc.buffer = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	cgc.buflen = sizeof(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	ret = cdrom_mode_sense(cdi, &cgc, cdi->mrw_mode_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	mph = (struct mode_page_header *)buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	offset = be16_to_cpu(mph->desc_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	size = be16_to_cpu(mph->mode_data_length) + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	buffer[offset + 3] = space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	cgc.buflen = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	ret = cdrom_mode_select(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	pr_info("%s: mrw address space %s selected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		cdi->name, mrw_address_space[space]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	static char banner_printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	cd_dbg(CD_OPEN, "entering register_cdrom\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	if (cdo->open == NULL || cdo->release == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	if (!banner_printed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		pr_info("Uniform CD-ROM driver " REVISION "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		banner_printed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		cdrom_sysctl_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	cdi->disk = disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	disk->cdi = cdi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	ENSURE(cdo, drive_status, CDC_DRIVE_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	if (cdo->check_events == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		WARN_ON_ONCE(cdo->capability & (CDC_MEDIA_CHANGED | CDC_SELECT_DISC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	ENSURE(cdo, tray_move, CDC_CLOSE_TRAY | CDC_OPEN_TRAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	ENSURE(cdo, lock_door, CDC_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	ENSURE(cdo, select_speed, CDC_SELECT_SPEED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	ENSURE(cdo, get_last_session, CDC_MULTI_SESSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	ENSURE(cdo, get_mcn, CDC_MCN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	ENSURE(cdo, reset, CDC_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	ENSURE(cdo, generic_packet, CDC_GENERIC_PACKET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	cdi->mc_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	cdi->options = CDO_USE_FFLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		cdi->options |= (int) CDO_AUTO_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	if (autoeject == 1 && CDROM_CAN(CDC_OPEN_TRAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		cdi->options |= (int) CDO_AUTO_EJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	if (lockdoor == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		cdi->options |= (int) CDO_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	if (check_media_type == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		cdi->options |= (int) CDO_CHECK_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	if (CDROM_CAN(CDC_MRW_W))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		cdi->exit = cdrom_mrw_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	if (cdi->disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		cdi->cdda_method = CDDA_BPC_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		cdi->cdda_method = CDDA_OLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	WARN_ON(!cdo->generic_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	mutex_lock(&cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	list_add(&cdi->list, &cdrom_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	mutex_unlock(&cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) #undef ENSURE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) void unregister_cdrom(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	cd_dbg(CD_OPEN, "entering unregister_cdrom\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	mutex_lock(&cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	list_del(&cdi->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	mutex_unlock(&cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	if (cdi->exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		cdi->exit(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) int cdrom_get_media_event(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			  struct media_event_desc *med)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	unsigned char buffer[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	struct event_header *eh = (struct event_header *)buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	cgc.cmd[0] = GPCMD_GET_EVENT_STATUS_NOTIFICATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	cgc.cmd[1] = 1;		/* IMMED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	cgc.cmd[4] = 1 << 4;	/* media event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	cgc.cmd[8] = sizeof(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	if (cdi->ops->generic_packet(cdi, &cgc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	if (be16_to_cpu(eh->data_len) < sizeof(*med))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	if (eh->nea || eh->notification_class != 0x4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	memcpy(med, &buffer[sizeof(*eh)], sizeof(*med));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) static int cdrom_get_random_writable(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 			      struct rwrt_feature_desc *rfd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	char buffer[24];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	cgc.cmd[0] = GPCMD_GET_CONFIGURATION;	/* often 0x46 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	cgc.cmd[3] = CDF_RWRT;			/* often 0x0020 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	cgc.cmd[8] = sizeof(buffer);		/* often 0x18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	memcpy(rfd, &buffer[sizeof(struct feature_header)], sizeof (*rfd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) static int cdrom_has_defect_mgt(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	char buffer[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	__be16 *feature_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	cgc.cmd[0] = GPCMD_GET_CONFIGURATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	cgc.cmd[3] = CDF_HWDM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	cgc.cmd[8] = sizeof(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	feature_code = (__be16 *) &buffer[sizeof(struct feature_header)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (be16_to_cpu(*feature_code) == CDF_HWDM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) static int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	struct rwrt_feature_desc rfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	*write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	if ((ret = cdrom_get_random_writable(cdi, &rfd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		*write = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) static int cdrom_media_erasable(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	disc_information di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	ret = cdrom_get_disc_info(cdi, &di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	if (ret < 0 || ret < offsetof(typeof(di), n_first_track))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	return di.erasable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763)  * FIXME: check RO bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) static int cdrom_dvdram_open_write(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	int ret = cdrom_media_erasable(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	 * allow writable open if media info read worked and media is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	 * erasable, _or_ if it fails since not all drives support it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) static int cdrom_mrw_open_write(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	disc_information di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	 * always reset to DMA lba space on open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	if (cdrom_mrw_set_lba_space(cdi, MRW_LBA_DMA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		pr_err("failed setting lba address space\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	ret = cdrom_get_disc_info(cdi, &di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	if (ret < 0 || ret < offsetof(typeof(di),disc_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	if (!di.erasable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	 * mrw_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	 * 0	-	not MRW formatted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	 * 1	-	MRW bgformat started, but not running or complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	 * 2	-	MRW bgformat in progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	 * 3	-	MRW formatting complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	pr_info("open: mrw_status '%s'\n", mrw_format_status[di.mrw_status]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	if (!di.mrw_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	else if (di.mrw_status == CDM_MRW_BGFORMAT_INACTIVE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 			mrw_format_restart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		ret = cdrom_mrw_bgformat(cdi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) static int mo_open_write(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	char buffer[255];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	init_cdrom_command(&cgc, &buffer, 4, CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	 * obtain write protect information as per
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	 * drivers/scsi/sd.c:sd_read_write_protect_flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	ret = cdrom_mode_sense(cdi, &cgc, GPMODE_ALL_PAGES, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		ret = cdrom_mode_sense(cdi, &cgc, GPMODE_VENDOR_PAGE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		cgc.buflen = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		ret = cdrom_mode_sense(cdi, &cgc, GPMODE_ALL_PAGES, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	/* drive gave us no info, let the user go ahead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	return buffer[3] & 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) static int cdrom_ram_open_write(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	struct rwrt_feature_desc rfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	if ((ret = cdrom_has_defect_mgt(cdi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	if ((ret = cdrom_get_random_writable(cdi, &rfd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	else if (CDF_RWRT == be16_to_cpu(rfd.feature_code))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		ret = !rfd.curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	cd_dbg(CD_OPEN, "can open for random write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) static void cdrom_mmc3_profile(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	char buffer[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	int ret, mmc3_profile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	cgc.cmd[0] = GPCMD_GET_CONFIGURATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	cgc.cmd[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	cgc.cmd[2] = cgc.cmd[3] = 0;		/* Starting Feature Number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	cgc.cmd[8] = sizeof(buffer);		/* Allocation Length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		mmc3_profile = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		mmc3_profile = (buffer[6] << 8) | buffer[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	cdi->mmc3_profile = mmc3_profile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) static int cdrom_is_dvd_rw(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	switch (cdi->mmc3_profile) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	case 0x12:	/* DVD-RAM	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	case 0x1A:	/* DVD+RW	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	case 0x43:	/* BD-RE	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898)  * returns 0 for ok to open write, non-0 to disallow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) static int cdrom_open_write(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	int mrw, mrw_write, ram_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	int ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	mrw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	if (!cdrom_is_mrw(cdi, &mrw_write))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		mrw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	if (CDROM_CAN(CDC_MO_DRIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		ram_write = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		(void) cdrom_is_random_writable(cdi, &ram_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	if (mrw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		cdi->mask &= ~CDC_MRW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		cdi->mask |= CDC_MRW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	if (mrw_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		cdi->mask &= ~CDC_MRW_W;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		cdi->mask |= CDC_MRW_W;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	if (ram_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		cdi->mask &= ~CDC_RAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		cdi->mask |= CDC_RAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	if (CDROM_CAN(CDC_MRW_W))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		ret = cdrom_mrw_open_write(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	else if (CDROM_CAN(CDC_DVD_RAM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		ret = cdrom_dvdram_open_write(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933)  	else if (CDROM_CAN(CDC_RAM) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934)  		 !CDROM_CAN(CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_MRW|CDC_MO_DRIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935)  		ret = cdrom_ram_open_write(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	else if (CDROM_CAN(CDC_MO_DRIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		ret = mo_open_write(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	else if (!cdrom_is_dvd_rw(cdi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) static void cdrom_dvd_rw_close_write(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	if (cdi->mmc3_profile != 0x1a) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		cd_dbg(CD_CLOSE, "%s: No DVD+RW\n", cdi->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	if (!cdi->media_written) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		cd_dbg(CD_CLOSE, "%s: DVD+RW media clean\n", cdi->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	pr_info("%s: dirty DVD+RW media, \"finalizing\"\n", cdi->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	init_cdrom_command(&cgc, NULL, 0, CGC_DATA_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	cgc.cmd[0] = GPCMD_FLUSH_CACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	cgc.timeout = 30*HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	cdi->ops->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	init_cdrom_command(&cgc, NULL, 0, CGC_DATA_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	cgc.cmd[0] = GPCMD_CLOSE_TRACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	cgc.timeout = 3000*HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	cdi->ops->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	init_cdrom_command(&cgc, NULL, 0, CGC_DATA_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	cgc.cmd[0] = GPCMD_CLOSE_TRACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	cgc.cmd[2] = 2;	 /* Close session */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	cgc.timeout = 3000*HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	cdi->ops->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	cdi->media_written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) static int cdrom_close_write(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	return cdrom_flush_cache(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) /* badly broken, I know. Is due for a fixup anytime. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) static void cdrom_count_tracks(struct cdrom_device_info *cdi, tracktype *tracks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	struct cdrom_tochdr header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	struct cdrom_tocentry entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	tracks->data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	tracks->audio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	tracks->cdi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	tracks->xa = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	tracks->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	cd_dbg(CD_COUNT_TRACKS, "entering cdrom_count_tracks\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	if (!CDROM_CAN(CDC_PLAY_AUDIO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		tracks->error = CDS_NO_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	/* Grab the TOC header so we can see how many tracks there are */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		if (ret == -ENOMEDIUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 			tracks->error = CDS_NO_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 			tracks->error = CDS_NO_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	/* check what type of tracks are on this disc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	entry.cdte_format = CDROM_MSF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	for (i = header.cdth_trk0; i <= header.cdth_trk1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		entry.cdte_track = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		if (cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 			tracks->error = CDS_NO_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		if (entry.cdte_ctrl & CDROM_DATA_TRACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 			if (entry.cdte_format == 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 				tracks->cdi++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 			else if (entry.cdte_format == 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 				tracks->xa++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 				tracks->data++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			tracks->audio++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		cd_dbg(CD_COUNT_TRACKS, "track %d: format=%d, ctrl=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		       i, entry.cdte_format, entry.cdte_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	cd_dbg(CD_COUNT_TRACKS, "disc has %d tracks: %d=audio %d=data %d=Cd-I %d=XA\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	       header.cdth_trk1, tracks->audio, tracks->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	       tracks->cdi, tracks->xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) int open_for_data(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	tracktype tracks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	cd_dbg(CD_OPEN, "entering open_for_data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	/* Check if the driver can report drive status.  If it can, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	   can do clever things.  If it can't, well, we at least tried! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (cdo->drive_status != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		ret = cdo->drive_status(cdi, CDSL_CURRENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		cd_dbg(CD_OPEN, "drive_status=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		if (ret == CDS_TRAY_OPEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 			cd_dbg(CD_OPEN, "the tray is open...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 			/* can/may i close it? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 			if (CDROM_CAN(CDC_CLOSE_TRAY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 			    cdi->options & CDO_AUTO_CLOSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 				cd_dbg(CD_OPEN, "trying to close the tray\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 				ret=cdo->tray_move(cdi,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 				if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 					cd_dbg(CD_OPEN, "bummer. tried to close the tray but failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 					/* Ignore the error from the low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 					level driver.  We don't care why it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 					couldn't close the tray.  We only care 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 					that there is no disc in the drive, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 					since that is the _REAL_ problem here.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 					ret=-ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 					goto clean_up_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 				cd_dbg(CD_OPEN, "bummer. this drive can't close the tray.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 				ret=-ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 				goto clean_up_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 			/* Ok, the door should be closed now.. Check again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 			ret = cdo->drive_status(cdi, CDSL_CURRENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 			if ((ret == CDS_NO_DISC) || (ret==CDS_TRAY_OPEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 				cd_dbg(CD_OPEN, "bummer. the tray is still not closed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 				cd_dbg(CD_OPEN, "tray might not contain a medium\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 				ret=-ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 				goto clean_up_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 			cd_dbg(CD_OPEN, "the tray is now closed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		/* the door should be closed now, check for the disc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		ret = cdo->drive_status(cdi, CDSL_CURRENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		if (ret!=CDS_DISC_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 			ret = -ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 			goto clean_up_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	cdrom_count_tracks(cdi, &tracks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	if (tracks.error == CDS_NO_DISC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		cd_dbg(CD_OPEN, "bummer. no disc.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		ret=-ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		goto clean_up_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	/* CD-Players which don't use O_NONBLOCK, workman
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	 * for example, need bit CDO_CHECK_TYPE cleared! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	if (tracks.data==0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		if (cdi->options & CDO_CHECK_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		    /* give people a warning shot, now that CDO_CHECK_TYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		       is the default case! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		    cd_dbg(CD_OPEN, "bummer. wrong media type.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		    cd_dbg(CD_WARNING, "pid %d must open device O_NONBLOCK!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 			   (unsigned int)task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		    ret=-EMEDIUMTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		    goto clean_up_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		    cd_dbg(CD_OPEN, "wrong media type, but CDO_CHECK_TYPE not set\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	cd_dbg(CD_OPEN, "all seems well, opening the devicen");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	/* all seems well, we can open the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	ret = cdo->open(cdi, 0); /* open for data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	cd_dbg(CD_OPEN, "opening the device gave me %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	/* After all this careful checking, we shouldn't have problems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	   opening the device, but we don't want the device locked if 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	   this somehow fails... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		cd_dbg(CD_OPEN, "open device failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		goto clean_up_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	if (CDROM_CAN(CDC_LOCK) && (cdi->options & CDO_LOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			cdo->lock_door(cdi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 			cd_dbg(CD_OPEN, "door locked\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	cd_dbg(CD_OPEN, "device opened successfully\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	/* Something failed.  Try to unlock the drive, because some drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	(notably ide-cd) lock the drive after every command.  This produced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	a nasty bug where after mount failed, the drive would remain locked!  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	This ensures that the drive gets unlocked after a mount fails.  This 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	is a goto to avoid bloating the driver with redundant code. */ 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) clean_up_and_return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	cd_dbg(CD_OPEN, "open failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 			cdo->lock_door(cdi, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 			cd_dbg(CD_OPEN, "door unlocked\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) /* We use the open-option O_NONBLOCK to indicate that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  * purpose of opening is only for subsequent ioctl() calls; no device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * integrity checks are performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  * We hope that all cd-player programs will adopt this convention. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  * is in their own interest: device control becomes a lot easier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)  * this way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	       fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	cd_dbg(CD_OPEN, "entering cdrom_open\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	/* if this was a O_NONBLOCK open and we should honor the flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	 * do a quick open without drive/disc integrity checks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	cdi->use_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	if ((mode & FMODE_NDELAY) && (cdi->options & CDO_USE_FFLAGS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		ret = cdi->ops->open(cdi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		ret = open_for_data(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		if (CDROM_CAN(CDC_GENERIC_PACKET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 			cdrom_mmc3_profile(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		if (mode & FMODE_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 			ret = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 			if (cdrom_open_write(cdi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 				goto err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 			if (!CDROM_CAN(CDC_RAM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 				goto err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 			cdi->media_written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	cd_dbg(CD_OPEN, "Use count for \"/dev/%s\" now %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	       cdi->name, cdi->use_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) err_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		cdi->ops->lock_door(cdi, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		cd_dbg(CD_OPEN, "door unlocked\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	cdi->ops->release(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	cdi->use_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) /* This code is similar to that in open_for_data. The routine is called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)    whenever an audio play operation is requested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) static int check_for_audio_disc(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 				const struct cdrom_device_ops *cdo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)         int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	tracktype tracks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	cd_dbg(CD_OPEN, "entering check_for_audio_disc\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	if (!(cdi->options & CDO_CHECK_TYPE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	if (cdo->drive_status != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		ret = cdo->drive_status(cdi, CDSL_CURRENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 		cd_dbg(CD_OPEN, "drive_status=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		if (ret == CDS_TRAY_OPEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 			cd_dbg(CD_OPEN, "the tray is open...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 			/* can/may i close it? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			if (CDROM_CAN(CDC_CLOSE_TRAY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 			    cdi->options & CDO_AUTO_CLOSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 				cd_dbg(CD_OPEN, "trying to close the tray\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 				ret=cdo->tray_move(cdi,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 				if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 					cd_dbg(CD_OPEN, "bummer. tried to close tray but failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 					/* Ignore the error from the low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 					level driver.  We don't care why it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 					couldn't close the tray.  We only care 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 					that there is no disc in the drive, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 					since that is the _REAL_ problem here.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 					return -ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 				cd_dbg(CD_OPEN, "bummer. this driver can't close the tray.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 				return -ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 			/* Ok, the door should be closed now.. Check again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 			ret = cdo->drive_status(cdi, CDSL_CURRENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 			if ((ret == CDS_NO_DISC) || (ret==CDS_TRAY_OPEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 				cd_dbg(CD_OPEN, "bummer. the tray is still not closed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 				return -ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 			}	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 			if (ret!=CDS_DISC_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 				cd_dbg(CD_OPEN, "bummer. disc isn't ready.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 			}	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 			cd_dbg(CD_OPEN, "the tray is now closed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		}	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	cdrom_count_tracks(cdi, &tracks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	if (tracks.error) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		return(tracks.error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	if (tracks.audio==0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 		return -EMEDIUMTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	int opened_for_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	cd_dbg(CD_CLOSE, "entering cdrom_release\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	if (cdi->use_count > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		cdi->use_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	if (cdi->use_count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		cd_dbg(CD_CLOSE, "Use count for \"/dev/%s\" now zero\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		       cdi->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		cdrom_dvd_rw_close_write(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		if ((cdo->capability & CDC_LOCK) && !cdi->keeplocked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 			cd_dbg(CD_CLOSE, "Unlocking door!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 			cdo->lock_door(cdi, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	opened_for_data = !(cdi->options & CDO_USE_FFLAGS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		!(mode & FMODE_NDELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	 * flush cache on last write release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	if (CDROM_CAN(CDC_RAM) && !cdi->use_count && cdi->for_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		cdrom_close_write(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	cdo->release(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	if (cdi->use_count == 0) {      /* last process that closes dev*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 		if (opened_for_data &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		    cdi->options & CDO_AUTO_EJECT && CDROM_CAN(CDC_OPEN_TRAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 			cdo->tray_move(cdi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) static int cdrom_read_mech_status(struct cdrom_device_info *cdi, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 				  struct cdrom_changer_info *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	 * Sanyo changer isn't spec compliant (doesn't use regular change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	 * LOAD_UNLOAD command, and it doesn't implement the mech status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	 * command below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	if (cdi->sanyo_slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		buf->hdr.nslots = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		buf->hdr.curslot = cdi->sanyo_slot == 3 ? 0 : cdi->sanyo_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		for (length = 0; length < 3; length++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 			buf->slots[length].disc_present = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 			buf->slots[length].change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	length = sizeof(struct cdrom_mechstat_header) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		 cdi->capacity * sizeof(struct cdrom_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	init_cdrom_command(&cgc, buf, length, CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	cgc.cmd[0] = GPCMD_MECHANISM_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	cgc.cmd[8] = (length >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	cgc.cmd[9] = length & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	return cdo->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) static int cdrom_slot_status(struct cdrom_device_info *cdi, int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	struct cdrom_changer_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	cd_dbg(CD_CHANGER, "entering cdrom_slot_status()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	if (cdi->sanyo_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		return CDS_NO_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	info = kmalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	if ((ret = cdrom_read_mech_status(cdi, info)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	if (info->slots[slot].disc_present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		ret = CDS_DISC_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		ret = CDS_NO_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) /* Return the number of slots for an ATAPI/SCSI cdrom, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)  * return 1 if not a changer. 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) int cdrom_number_of_slots(struct cdrom_device_info *cdi) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	int nslots = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	struct cdrom_changer_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	cd_dbg(CD_CHANGER, "entering cdrom_number_of_slots()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	/* cdrom_read_mech_status requires a valid value for capacity: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	cdi->capacity = 0; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	info = kmalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	if ((status = cdrom_read_mech_status(cdi, info)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 		nslots = info->hdr.nslots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	return nslots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) /* If SLOT < 0, unload the current slot.  Otherwise, try to load SLOT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) static int cdrom_load_unload(struct cdrom_device_info *cdi, int slot) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	cd_dbg(CD_CHANGER, "entering cdrom_load_unload()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	if (cdi->sanyo_slot && slot < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	init_cdrom_command(&cgc, NULL, 0, CGC_DATA_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	cgc.cmd[0] = GPCMD_LOAD_UNLOAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	cgc.cmd[4] = 2 + (slot >= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	cgc.cmd[8] = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	cgc.timeout = 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	/* The Sanyo 3 CD changer uses byte 7 of the 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	GPCMD_TEST_UNIT_READY to command to switch CDs instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	using the GPCMD_LOAD_UNLOAD opcode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	if (cdi->sanyo_slot && -1 < slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		cgc.cmd[0] = GPCMD_TEST_UNIT_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		cgc.cmd[7] = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		cgc.cmd[4] = cgc.cmd[8] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		cdi->sanyo_slot = slot ? slot : 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	return cdi->ops->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) static int cdrom_select_disc(struct cdrom_device_info *cdi, int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	struct cdrom_changer_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	int curslot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	cd_dbg(CD_CHANGER, "entering cdrom_select_disc()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	if (!CDROM_CAN(CDC_SELECT_DISC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		return -EDRIVE_CANT_DO_THIS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	if (cdi->ops->check_events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		cdi->ops->check_events(cdi, 0, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	if (slot == CDSL_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		/* set media changed bits, on both queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 		cdi->mc_flags = 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 		return cdrom_load_unload(cdi, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	info = kmalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	if ((ret = cdrom_read_mech_status(cdi, info))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	curslot = info->hdr.curslot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	if (cdi->use_count > 1 || cdi->keeplocked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		if (slot == CDSL_CURRENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	    		return curslot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 			return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	/* Specifying CDSL_CURRENT will attempt to load the currnet slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	which is useful if it had been previously unloaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	Whether it can or not, it returns the current slot. 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	Similarly,  if slot happens to be the current one, we still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	try and load it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	if (slot == CDSL_CURRENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		slot = curslot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	/* set media changed bits on both queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	cdi->mc_flags = 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	if ((ret = cdrom_load_unload(cdi, slot)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	return slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466)  * As cdrom implements an extra ioctl consumer for media changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)  * event, it needs to buffer ->check_events() output, such that event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)  * is not lost for both the usual VFS and ioctl paths.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)  * cdi->{vfs|ioctl}_events are used to buffer pending events for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)  * path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)  * XXX: Locking is non-existent.  cdi->ops->check_events() can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)  * called in parallel and buffering fields are accessed without any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)  * exclusion.  The original media_changed code had the same problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)  * It might be better to simply deprecate CDROM_MEDIA_CHANGED ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)  * and remove this cruft altogether.  It doesn't have much usefulness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)  * at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) static void cdrom_update_events(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 				unsigned int clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	unsigned int events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	events = cdi->ops->check_events(cdi, clearing, CDSL_CURRENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	cdi->vfs_events |= events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	cdi->ioctl_events |= events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 				unsigned int clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	unsigned int events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	cdrom_update_events(cdi, clearing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	events = cdi->vfs_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	cdi->vfs_events = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	return events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) EXPORT_SYMBOL(cdrom_check_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) /* We want to make media_changed accessible to the user through an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)  * ioctl. The main problem now is that we must double-buffer the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)  * low-level implementation, to assure that the VFS and the user both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)  * see a medium change once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) int media_changed(struct cdrom_device_info *cdi, int queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	unsigned int mask = (1 << (queue & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	int ret = !!(cdi->mc_flags & mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	bool changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	if (!CDROM_CAN(CDC_MEDIA_CHANGED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	/* changed since last call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	BUG_ON(!queue);	/* shouldn't be called from VFS path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	cdrom_update_events(cdi, DISK_EVENT_MEDIA_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	changed = cdi->ioctl_events & DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	cdi->ioctl_events = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	if (changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 		cdi->mc_flags = 0x3;    /* set bit on both queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 		ret |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		cdi->media_written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	cdi->mc_flags &= ~mask;         /* clear bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) /* Requests to the low-level drivers will /always/ be done in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)    following format convention:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)    CDROM_LBA: all data-related requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)    CDROM_MSF: all audio-related requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)    However, a low-level implementation is allowed to refuse this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)    request, and return information in its own favorite format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)    It doesn't make sense /at all/ to ask for a play_audio in LBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)    format, or ask for multi-session info in MSF format. However, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)    backward compatibility these format requests will be satisfied, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)    the requests to the low-level drivers will be sanitized in the more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)    meaningful format indicated above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) void sanitize_format(union cdrom_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		     u_char * curr, u_char requested)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	if (*curr == requested)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		return;                 /* nothing to be done! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	if (requested == CDROM_LBA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 		addr->lba = (int) addr->msf.frame +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 			75 * (addr->msf.second - 2 + 60 * addr->msf.minute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	} else {                        /* CDROM_MSF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 		int lba = addr->lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		addr->msf.frame = lba % 75;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 		lba /= 75;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		lba += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 		addr->msf.second = lba % 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		addr->msf.minute = lba / 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	*curr = requested;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) void init_cdrom_command(struct packet_command *cgc, void *buf, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 			int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	memset(cgc, 0, sizeof(struct packet_command));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	if (buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		memset(buf, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	cgc->buffer = (char *) buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	cgc->buflen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	cgc->data_direction = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	cgc->timeout = CDROM_DEF_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) /* DVD handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) #define copy_key(dest,src)	memcpy((dest), (src), sizeof(dvd_key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) #define copy_chal(dest,src)	memcpy((dest), (src), sizeof(dvd_challenge))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) static void setup_report_key(struct packet_command *cgc, unsigned agid, unsigned type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	cgc->cmd[0] = GPCMD_REPORT_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	cgc->cmd[10] = type | (agid << 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		case 0: case 8: case 5: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 			cgc->buflen = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 		case 1: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 			cgc->buflen = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		case 2: case 4: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 			cgc->buflen = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	cgc->cmd[9] = cgc->buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	cgc->data_direction = CGC_DATA_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) static void setup_send_key(struct packet_command *cgc, unsigned agid, unsigned type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	cgc->cmd[0] = GPCMD_SEND_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	cgc->cmd[10] = type | (agid << 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 		case 1: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 			cgc->buflen = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 		case 3: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 			cgc->buflen = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 		case 6: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 			cgc->buflen = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	cgc->cmd[9] = cgc->buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	cgc->data_direction = CGC_DATA_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	u_char buf[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	rpc_state_t rpc_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	memset(buf, 0, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	init_cdrom_command(&cgc, buf, 0, CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	switch (ai->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	/* LU data send */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	case DVD_LU_SEND_AGID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 		cd_dbg(CD_DVD, "entering DVD_LU_SEND_AGID\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 		cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 		setup_report_key(&cgc, ai->lsa.agid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 		ai->lsa.agid = buf[7] >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 		/* Returning data, let host change state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	case DVD_LU_SEND_KEY1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		cd_dbg(CD_DVD, "entering DVD_LU_SEND_KEY1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		setup_report_key(&cgc, ai->lsk.agid, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 		copy_key(ai->lsk.key, &buf[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		/* Returning data, let host change state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	case DVD_LU_SEND_CHALLENGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 		cd_dbg(CD_DVD, "entering DVD_LU_SEND_CHALLENGE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		setup_report_key(&cgc, ai->lsc.agid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		copy_chal(ai->lsc.chal, &buf[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 		/* Returning data, let host change state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	/* Post-auth key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	case DVD_LU_SEND_TITLE_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 		cd_dbg(CD_DVD, "entering DVD_LU_SEND_TITLE_KEY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		setup_report_key(&cgc, ai->lstk.agid, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		cgc.cmd[5] = ai->lstk.lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		cgc.cmd[4] = ai->lstk.lba >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		cgc.cmd[3] = ai->lstk.lba >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		cgc.cmd[2] = ai->lstk.lba >> 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 		ai->lstk.cpm = (buf[4] >> 7) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 		ai->lstk.cp_sec = (buf[4] >> 6) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		ai->lstk.cgms = (buf[4] >> 4) & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		copy_key(ai->lstk.title_key, &buf[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 		/* Returning data, let host change state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	case DVD_LU_SEND_ASF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 		cd_dbg(CD_DVD, "entering DVD_LU_SEND_ASF\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		setup_report_key(&cgc, ai->lsasf.agid, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 		ai->lsasf.asf = buf[7] & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	/* LU data receive (LU changes state) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	case DVD_HOST_SEND_CHALLENGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 		cd_dbg(CD_DVD, "entering DVD_HOST_SEND_CHALLENGE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 		setup_send_key(&cgc, ai->hsc.agid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 		buf[1] = 0xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 		copy_chal(&buf[4], ai->hsc.chal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 		ai->type = DVD_LU_SEND_KEY1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	case DVD_HOST_SEND_KEY2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 		cd_dbg(CD_DVD, "entering DVD_HOST_SEND_KEY2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 		setup_send_key(&cgc, ai->hsk.agid, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 		buf[1] = 0xa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		copy_key(&buf[4], ai->hsk.key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 		if ((ret = cdo->generic_packet(cdi, &cgc))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 			ai->type = DVD_AUTH_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 		ai->type = DVD_AUTH_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	/* Misc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	case DVD_INVALIDATE_AGID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 		cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 		cd_dbg(CD_DVD, "entering DVD_INVALIDATE_AGID\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 		setup_report_key(&cgc, ai->lsa.agid, 0x3f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	/* Get region settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	case DVD_LU_SEND_RPC_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		cd_dbg(CD_DVD, "entering DVD_LU_SEND_RPC_STATE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 		setup_report_key(&cgc, 0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		memset(&rpc_state, 0, sizeof(rpc_state_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 		cgc.buffer = (char *) &rpc_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 		ai->lrpcs.type = rpc_state.type_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 		ai->lrpcs.vra = rpc_state.vra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 		ai->lrpcs.ucca = rpc_state.ucca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 		ai->lrpcs.region_mask = rpc_state.region_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 		ai->lrpcs.rpc_scheme = rpc_state.rpc_scheme;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	/* Set region settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	case DVD_HOST_SEND_RPC_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 		cd_dbg(CD_DVD, "entering DVD_HOST_SEND_RPC_STATE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 		setup_send_key(&cgc, 0, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 		buf[1] = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 		buf[4] = ai->hrpcs.pdrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 		if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		cd_dbg(CD_WARNING, "Invalid DVD key ioctl (%d)\n", ai->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) static int dvd_read_physical(struct cdrom_device_info *cdi, dvd_struct *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 				struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	unsigned char buf[21], *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	struct dvd_layer *layer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	int ret, layer_num = s->physical.layer_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	if (layer_num >= DVD_LAYERS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	init_cdrom_command(cgc, buf, sizeof(buf), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	cgc->cmd[6] = layer_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	cgc->cmd[7] = s->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	cgc->cmd[9] = cgc->buflen & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	 * refrain from reporting errors on non-existing layers (mainly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	cgc->quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	ret = cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	base = &buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	layer = &s->physical.layer[layer_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	 * place the data... really ugly, but at least we won't have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	 * worry about endianess in userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	memset(layer, 0, sizeof(*layer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	layer->book_version = base[0] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	layer->book_type = base[0] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	layer->min_rate = base[1] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	layer->disc_size = base[1] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	layer->layer_type = base[2] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	layer->track_path = (base[2] >> 4) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	layer->nlayers = (base[2] >> 5) & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	layer->track_density = base[3] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	layer->linear_density = base[3] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	layer->start_sector = base[5] << 16 | base[6] << 8 | base[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	layer->end_sector = base[9] << 16 | base[10] << 8 | base[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	layer->end_sector_l0 = base[13] << 16 | base[14] << 8 | base[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	layer->bca = base[16] >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) static int dvd_read_copyright(struct cdrom_device_info *cdi, dvd_struct *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 				struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	u_char buf[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	init_cdrom_command(cgc, buf, sizeof(buf), CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	cgc->cmd[6] = s->copyright.layer_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	cgc->cmd[7] = s->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	cgc->cmd[8] = cgc->buflen >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	cgc->cmd[9] = cgc->buflen & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 	ret = cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	s->copyright.cpst = buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	s->copyright.rmi = buf[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) static int dvd_read_disckey(struct cdrom_device_info *cdi, dvd_struct *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 				struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	int ret, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	u_char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	size = sizeof(s->disckey.value) + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	buf = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	init_cdrom_command(cgc, buf, size, CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	cgc->cmd[7] = s->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	cgc->cmd[8] = size >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	cgc->cmd[9] = size & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	cgc->cmd[10] = s->disckey.agid << 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	ret = cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 		memcpy(s->disckey.value, &buf[4], sizeof(s->disckey.value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) static int dvd_read_bca(struct cdrom_device_info *cdi, dvd_struct *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 			struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	int ret, size = 4 + 188;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	u_char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	buf = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	init_cdrom_command(cgc, buf, size, CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	cgc->cmd[7] = s->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	cgc->cmd[9] = cgc->buflen & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	ret = cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	s->bca.len = buf[0] << 8 | buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 	if (s->bca.len < 12 || s->bca.len > 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 		cd_dbg(CD_WARNING, "Received invalid BCA length (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 		       s->bca.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	memcpy(s->bca.value, &buf[4], s->bca.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) static int dvd_read_manufact(struct cdrom_device_info *cdi, dvd_struct *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 				struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	int ret = 0, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	u_char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	size = sizeof(s->manufact.value) + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 	buf = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	init_cdrom_command(cgc, buf, size, CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	cgc->cmd[0] = GPCMD_READ_DVD_STRUCTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 	cgc->cmd[7] = s->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 	cgc->cmd[8] = size >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	cgc->cmd[9] = size & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	ret = cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	s->manufact.len = buf[0] << 8 | buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	if (s->manufact.len < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 		cd_dbg(CD_WARNING, "Received invalid manufacture info length (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 		       s->manufact.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		if (s->manufact.len > 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 			cd_dbg(CD_WARNING, "Received invalid manufacture info length (%d): truncating to 2048\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 			       s->manufact.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 			s->manufact.len = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 		memcpy(s->manufact.value, &buf[4], s->manufact.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) static int dvd_read_struct(struct cdrom_device_info *cdi, dvd_struct *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 				struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 	switch (s->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	case DVD_STRUCT_PHYSICAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 		return dvd_read_physical(cdi, s, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	case DVD_STRUCT_COPYRIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 		return dvd_read_copyright(cdi, s, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	case DVD_STRUCT_DISCKEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 		return dvd_read_disckey(cdi, s, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	case DVD_STRUCT_BCA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 		return dvd_read_bca(cdi, s, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	case DVD_STRUCT_MANUFACT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 		return dvd_read_manufact(cdi, s, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 		cd_dbg(CD_WARNING, ": Invalid DVD structure read requested (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 		       s->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) int cdrom_mode_sense(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 		     struct packet_command *cgc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 		     int page_code, int page_control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 	memset(cgc->cmd, 0, sizeof(cgc->cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 	cgc->cmd[0] = GPCMD_MODE_SENSE_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 	cgc->cmd[2] = page_code | (page_control << 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 	cgc->cmd[7] = cgc->buflen >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 	cgc->cmd[8] = cgc->buflen & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 	cgc->data_direction = CGC_DATA_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 	return cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) int cdrom_mode_select(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 		      struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	memset(cgc->cmd, 0, sizeof(cgc->cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 	memset(cgc->buffer, 0, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 	cgc->cmd[0] = GPCMD_MODE_SELECT_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	cgc->cmd[1] = 0x10;		/* PF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	cgc->cmd[7] = cgc->buflen >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	cgc->cmd[8] = cgc->buflen & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	cgc->data_direction = CGC_DATA_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	return cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) static int cdrom_read_subchannel(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 				 struct cdrom_subchnl *subchnl, int mcn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	char buffer[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	init_cdrom_command(&cgc, buffer, 16, CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	cgc.cmd[1] = subchnl->cdsc_format;/* MSF or LBA addressing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	cgc.cmd[2] = 0x40;  /* request subQ data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 	cgc.cmd[3] = mcn ? 2 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	cgc.cmd[8] = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	if ((ret = cdo->generic_packet(cdi, &cgc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	subchnl->cdsc_audiostatus = cgc.buffer[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	subchnl->cdsc_ctrl = cgc.buffer[5] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	subchnl->cdsc_trk = cgc.buffer[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	subchnl->cdsc_ind = cgc.buffer[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	if (subchnl->cdsc_format == CDROM_LBA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 		subchnl->cdsc_absaddr.lba = ((cgc.buffer[8] << 24) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 						(cgc.buffer[9] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 						(cgc.buffer[10] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 						(cgc.buffer[11]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 		subchnl->cdsc_reladdr.lba = ((cgc.buffer[12] << 24) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 						(cgc.buffer[13] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 						(cgc.buffer[14] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 						(cgc.buffer[15]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		subchnl->cdsc_reladdr.msf.minute = cgc.buffer[13];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		subchnl->cdsc_reladdr.msf.second = cgc.buffer[14];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 		subchnl->cdsc_reladdr.msf.frame = cgc.buffer[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 		subchnl->cdsc_absaddr.msf.minute = cgc.buffer[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		subchnl->cdsc_absaddr.msf.second = cgc.buffer[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 		subchnl->cdsc_absaddr.msf.frame = cgc.buffer[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)  * Specific READ_10 interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) static int cdrom_read_cd(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 			 struct packet_command *cgc, int lba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 			 int blocksize, int nblocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 	memset(&cgc->cmd, 0, sizeof(cgc->cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	cgc->cmd[0] = GPCMD_READ_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	cgc->cmd[2] = (lba >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 	cgc->cmd[3] = (lba >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	cgc->cmd[4] = (lba >>  8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 	cgc->cmd[5] = lba & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 	cgc->cmd[6] = (nblocks >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	cgc->cmd[7] = (nblocks >>  8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	cgc->cmd[8] = nblocks & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	cgc->buflen = blocksize * nblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	return cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) /* very generic interface for reading the various types of blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) static int cdrom_read_block(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 			    struct packet_command *cgc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 			    int lba, int nblocks, int format, int blksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	memset(&cgc->cmd, 0, sizeof(cgc->cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	cgc->cmd[0] = GPCMD_READ_CD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 	/* expected sector size - cdda,mode1,etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	cgc->cmd[1] = format << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	/* starting address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 	cgc->cmd[2] = (lba >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	cgc->cmd[3] = (lba >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	cgc->cmd[4] = (lba >>  8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 	cgc->cmd[5] = lba & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	/* number of blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 	cgc->cmd[6] = (nblocks >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	cgc->cmd[7] = (nblocks >>  8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	cgc->cmd[8] = nblocks & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 	cgc->buflen = blksize * nblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	/* set the header info returned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	switch (blksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	case CD_FRAMESIZE_RAW0	: cgc->cmd[9] = 0x58; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 	case CD_FRAMESIZE_RAW1	: cgc->cmd[9] = 0x78; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 	case CD_FRAMESIZE_RAW	: cgc->cmd[9] = 0xf8; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	default			: cgc->cmd[9] = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 	return cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 			       int lba, int nframes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 	int nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	cdi->last_sense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 	memset(&cgc, 0, sizeof(cgc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 	 * start with will ra.nframes size, back down if alloc fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 	nr = nframes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 		cgc.buffer = kmalloc_array(nr, CD_FRAMESIZE_RAW, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 		if (cgc.buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		nr >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 	} while (nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	if (!nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	cgc.data_direction = CGC_DATA_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	while (nframes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 		if (nr > nframes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 			nr = nframes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 		ret = cdrom_read_block(cdi, &cgc, lba, nr, 1, CD_FRAMESIZE_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		if (copy_to_user(ubuf, cgc.buffer, CD_FRAMESIZE_RAW * nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 		ubuf += CD_FRAMESIZE_RAW * nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		nframes -= nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 		lba += nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	kfree(cgc.buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 			       int lba, int nframes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 	struct request_queue *q = cdi->disk->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 	struct request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 	struct scsi_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	int nr, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	if (!q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	if (!blk_queue_scsi_passthrough(q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 		WARN_ONCE(true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 			  "Attempt read CDDA info through a non-SCSI queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	cdi->last_sense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	while (nframes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		nr = nframes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		if (cdi->cdda_method == CDDA_BPC_SINGLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 			nr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		if (nr * CD_FRAMESIZE_RAW > (queue_max_sectors(q) << 9))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 			nr = (queue_max_sectors(q) << 9) / CD_FRAMESIZE_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 		len = nr * CD_FRAMESIZE_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 		rq = blk_get_request(q, REQ_OP_SCSI_IN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 		if (IS_ERR(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 			ret = PTR_ERR(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		req = scsi_req(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 		ret = blk_rq_map_user(q, rq, NULL, ubuf, len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 			blk_put_request(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 		req->cmd[0] = GPCMD_READ_CD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 		req->cmd[1] = 1 << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		req->cmd[2] = (lba >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 		req->cmd[3] = (lba >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 		req->cmd[4] = (lba >>  8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 		req->cmd[5] = lba & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 		req->cmd[6] = (nr >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 		req->cmd[7] = (nr >>  8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 		req->cmd[8] = nr & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 		req->cmd[9] = 0xf8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 		req->cmd_len = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 		rq->timeout = 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 		bio = rq->bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 		blk_execute_rq(q, cdi->disk, rq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 		if (scsi_req(rq)->result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 			struct scsi_sense_hdr sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 			scsi_normalize_sense(req->sense, req->sense_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 					     &sshdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 			cdi->last_sense = sshdr.sense_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 		if (blk_rq_unmap_user(bio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 		blk_put_request(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		nframes -= nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 		lba += nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 		ubuf += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) static int cdrom_read_cdda(struct cdrom_device_info *cdi, __u8 __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 			   int lba, int nframes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	if (cdi->cdda_method == CDDA_OLD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 		return cdrom_read_cdda_old(cdi, ubuf, lba, nframes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	 * for anything else than success and io error, we need to retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	ret = cdrom_read_cdda_bpc(cdi, ubuf, lba, nframes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	if (!ret || ret != -EIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	 * I've seen drives get sense 4/8/3 udma crc errors on multi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 	 * frame dma, so drop to single frame dma if we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 	if (cdi->cdda_method == CDDA_BPC_FULL && nframes > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 		pr_info("dropping to single frame dma\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 		cdi->cdda_method = CDDA_BPC_SINGLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	 * so we have an io error of some sort with multi frame dma. if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 	 * condition wasn't a hardware error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	 * problems, not for any error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	if (cdi->last_sense != 0x04 && cdi->last_sense != 0x0b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 	pr_info("dropping to old style cdda (sense=%x)\n", cdi->last_sense);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 	cdi->cdda_method = CDDA_OLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 	return cdrom_read_cdda_old(cdi, ubuf, lba, nframes);	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) int cdrom_multisession(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 		struct cdrom_multisession *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	u8 requested_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	if (!(cdi->ops->capability & CDC_MULTI_SESSION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 	requested_format = info->addr_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	if (requested_format != CDROM_MSF && requested_format != CDROM_LBA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 	info->addr_format = CDROM_LBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 	ret = cdi->ops->get_last_session(cdi, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 		sanitize_format(&info->addr, &info->addr_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 				requested_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) EXPORT_SYMBOL_GPL(cdrom_multisession);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) static int cdrom_ioctl_multisession(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 	struct cdrom_multisession info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	cd_dbg(CD_DO_IOCTL, "entering CDROMMULTISESSION\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 	if (copy_from_user(&info, argp, sizeof(info)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	ret = cdrom_multisession(cdi, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 	if (copy_to_user(argp, &info, sizeof(info)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 	cd_dbg(CD_DO_IOCTL, "CDROMMULTISESSION successful\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) static int cdrom_ioctl_eject(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 	cd_dbg(CD_DO_IOCTL, "entering CDROMEJECT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	if (!CDROM_CAN(CDC_OPEN_TRAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	if (cdi->use_count != 1 || cdi->keeplocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	if (CDROM_CAN(CDC_LOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 		int ret = cdi->ops->lock_door(cdi, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 	return cdi->ops->tray_move(cdi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) static int cdrom_ioctl_closetray(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	cd_dbg(CD_DO_IOCTL, "entering CDROMCLOSETRAY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	if (!CDROM_CAN(CDC_CLOSE_TRAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 	return cdi->ops->tray_move(cdi, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) static int cdrom_ioctl_eject_sw(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	cd_dbg(CD_DO_IOCTL, "entering CDROMEJECT_SW\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 	if (!CDROM_CAN(CDC_OPEN_TRAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	if (cdi->keeplocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 	cdi->options &= ~(CDO_AUTO_CLOSE | CDO_AUTO_EJECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 	if (arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 		cdi->options |= CDO_AUTO_CLOSE | CDO_AUTO_EJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) static int cdrom_ioctl_media_changed(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	struct cdrom_changer_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_MEDIA_CHANGED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 	if (!CDROM_CAN(CDC_MEDIA_CHANGED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 	/* cannot select disc or select current disc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 	if (!CDROM_CAN(CDC_SELECT_DISC) || arg == CDSL_CURRENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 		return media_changed(cdi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	if (arg >= cdi->capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 	info = kmalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	ret = cdrom_read_mech_status(cdi, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 		ret = info->slots[arg].change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) static int cdrom_ioctl_set_options(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_SET_OPTIONS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 	 * Options need to be in sync with capability.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	 * Too late for that, so we have to check each one separately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	switch (arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 	case CDO_USE_FFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 	case CDO_CHECK_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 	case CDO_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 		if (!CDROM_CAN(CDC_LOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 			return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 		return cdi->options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 	/* default is basically CDO_[AUTO_CLOSE|AUTO_EJECT] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 		if (!CDROM_CAN(arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 			return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 	cdi->options |= (int) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 	return cdi->options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) static int cdrom_ioctl_clear_options(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_CLEAR_OPTIONS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 	cdi->options &= ~(int) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 	return cdi->options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) static int cdrom_ioctl_select_speed(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_SELECT_SPEED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	if (!CDROM_CAN(CDC_SELECT_SPEED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 	return cdi->ops->select_speed(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) static int cdrom_ioctl_select_disc(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_SELECT_DISC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	if (!CDROM_CAN(CDC_SELECT_DISC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	if (arg != CDSL_CURRENT && arg != CDSL_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 		if (arg >= cdi->capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 	 * ->select_disc is a hook to allow a driver-specific way of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 	 * seleting disc.  However, since there is no equivalent hook for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 	 * cdrom_slot_status this may not actually be useful...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 	if (cdi->ops->select_disc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 		return cdi->ops->select_disc(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	cd_dbg(CD_CHANGER, "Using generic cdrom_select_disc()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 	return cdrom_select_disc(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) static int cdrom_ioctl_reset(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 		struct block_device *bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_RESET\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 	if (!CDROM_CAN(CDC_RESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 	invalidate_bdev(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 	return cdi->ops->reset(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) static int cdrom_ioctl_lock_door(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 	cd_dbg(CD_DO_IOCTL, "%socking door\n", arg ? "L" : "Unl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 	if (!CDROM_CAN(CDC_LOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		return -EDRIVE_CANT_DO_THIS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 	cdi->keeplocked = arg ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 	 * Don't unlock the door on multiple opens by default, but allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 	 * root to do so.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 	if (cdi->use_count != 1 && !arg && !capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 	return cdi->ops->lock_door(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) static int cdrom_ioctl_debug(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 	cd_dbg(CD_DO_IOCTL, "%sabling debug\n", arg ? "En" : "Dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 	debug = arg ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 	return debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) static int cdrom_ioctl_get_capability(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_GET_CAPABILITY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 	return (cdi->ops->capability & ~cdi->mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516)  * The following function is implemented, although very few audio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)  * discs give Universal Product Code information, which should just be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518)  * the Medium Catalog Number on the box.  Note, that the way the code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519)  * is written on the CD is /not/ uniform across all discs!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) static int cdrom_ioctl_get_mcn(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 	struct cdrom_mcn mcn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_GET_MCN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	if (!(cdi->ops->capability & CDC_MCN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	ret = cdi->ops->get_mcn(cdi, &mcn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 	if (copy_to_user(argp, &mcn, sizeof(mcn)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 	cd_dbg(CD_DO_IOCTL, "CDROM_GET_MCN successful\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) static int cdrom_ioctl_drive_status(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_DRIVE_STATUS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 	if (!(cdi->ops->capability & CDC_DRIVE_STATUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 	if (!CDROM_CAN(CDC_SELECT_DISC) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 	    (arg == CDSL_CURRENT || arg == CDSL_NONE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 		return cdi->ops->drive_status(cdi, CDSL_CURRENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 	if (arg >= cdi->capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 	return cdrom_slot_status(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557)  * Ok, this is where problems start.  The current interface for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558)  * CDROM_DISC_STATUS ioctl is flawed.  It makes the false assumption that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559)  * CDs are all CDS_DATA_1 or all CDS_AUDIO, etc.  Unfortunately, while this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)  * is often the case, it is also very common for CDs to have some tracks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561)  * with data, and some tracks with audio.  Just because I feel like it,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562)  * I declare the following to be the best way to cope.  If the CD has ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563)  * data tracks on it, it will be returned as a data CD.  If it has any XA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564)  * tracks, I will return it as that.  Now I could simplify this interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565)  * by combining these  returns with the above, but this more clearly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566)  * demonstrates the problem with the current interface.  Too bad this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)  * wasn't designed to use bitmasks...         -Erik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)  * Well, now we have the option CDS_MIXED: a mixed-type CD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570)  * User level programmers might feel the ioctl is not very useful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)  *					---david
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) static int cdrom_ioctl_disc_status(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 	tracktype tracks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_DISC_STATUS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 	cdrom_count_tracks(cdi, &tracks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 	if (tracks.error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		return tracks.error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 	/* Policy mode on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 	if (tracks.audio > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 		if (!tracks.data && !tracks.cdi && !tracks.xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 			return CDS_AUDIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 			return CDS_MIXED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 	if (tracks.cdi > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 		return CDS_XA_2_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	if (tracks.xa > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 		return CDS_XA_2_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 	if (tracks.data > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 		return CDS_DATA_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	/* Policy mode off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 	cd_dbg(CD_WARNING, "This disc doesn't have any tracks I recognize!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 	return CDS_NO_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) static int cdrom_ioctl_changer_nslots(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_CHANGER_NSLOTS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 	return cdi->capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) static int cdrom_ioctl_get_subchnl(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 	struct cdrom_subchnl q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 	u8 requested, back;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 	/* cd_dbg(CD_DO_IOCTL,"entering CDROMSUBCHNL\n");*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 	if (copy_from_user(&q, argp, sizeof(q)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 	requested = q.cdsc_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 	if (requested != CDROM_MSF && requested != CDROM_LBA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 	q.cdsc_format = CDROM_MSF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 	ret = cdi->ops->audio_ioctl(cdi, CDROMSUBCHNL, &q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 	back = q.cdsc_format; /* local copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 	sanitize_format(&q.cdsc_absaddr, &back, requested);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 	sanitize_format(&q.cdsc_reladdr, &q.cdsc_format, requested);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 	if (copy_to_user(argp, &q, sizeof(q)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 	/* cd_dbg(CD_DO_IOCTL, "CDROMSUBCHNL successful\n"); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) static int cdrom_ioctl_read_tochdr(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 	struct cdrom_tochdr header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 	/* cd_dbg(CD_DO_IOCTL, "entering CDROMREADTOCHDR\n"); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 	if (copy_from_user(&header, argp, sizeof(header)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 	ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 	if (copy_to_user(argp, &header, sizeof(header)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 	/* cd_dbg(CD_DO_IOCTL, "CDROMREADTOCHDR successful\n"); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) int cdrom_read_tocentry(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 		struct cdrom_tocentry *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 	u8 requested_format = entry->cdte_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 	if (requested_format != CDROM_MSF && requested_format != CDROM_LBA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	/* make interface to low-level uniform */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 	entry->cdte_format = CDROM_MSF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 	ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 		sanitize_format(&entry->cdte_addr, &entry->cdte_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 				requested_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) EXPORT_SYMBOL_GPL(cdrom_read_tocentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) static int cdrom_ioctl_read_tocentry(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 	struct cdrom_tocentry entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 	if (copy_from_user(&entry, argp, sizeof(entry)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	ret = cdrom_read_tocentry(cdi, &entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 	if (!ret && copy_to_user(argp, &entry, sizeof(entry)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) static int cdrom_ioctl_play_msf(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 	struct cdrom_msf msf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 	cd_dbg(CD_DO_IOCTL, "entering CDROMPLAYMSF\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 	if (!CDROM_CAN(CDC_PLAY_AUDIO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 	if (copy_from_user(&msf, argp, sizeof(msf)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 	return cdi->ops->audio_ioctl(cdi, CDROMPLAYMSF, &msf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) static int cdrom_ioctl_play_trkind(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 	struct cdrom_ti ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 	cd_dbg(CD_DO_IOCTL, "entering CDROMPLAYTRKIND\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 	if (!CDROM_CAN(CDC_PLAY_AUDIO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 	if (copy_from_user(&ti, argp, sizeof(ti)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 	ret = check_for_audio_disc(cdi, cdi->ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 	return cdi->ops->audio_ioctl(cdi, CDROMPLAYTRKIND, &ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) static int cdrom_ioctl_volctrl(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 	struct cdrom_volctrl volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 	cd_dbg(CD_DO_IOCTL, "entering CDROMVOLCTRL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	if (!CDROM_CAN(CDC_PLAY_AUDIO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 	if (copy_from_user(&volume, argp, sizeof(volume)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 	return cdi->ops->audio_ioctl(cdi, CDROMVOLCTRL, &volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) static int cdrom_ioctl_volread(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 		void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	struct cdrom_volctrl volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 	cd_dbg(CD_DO_IOCTL, "entering CDROMVOLREAD\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	if (!CDROM_CAN(CDC_PLAY_AUDIO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 	ret = cdi->ops->audio_ioctl(cdi, CDROMVOLREAD, &volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 	if (copy_to_user(argp, &volume, sizeof(volume)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) static int cdrom_ioctl_audioctl(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 		unsigned int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 	cd_dbg(CD_DO_IOCTL, "doing audio ioctl (start/stop/pause/resume)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 	if (!CDROM_CAN(CDC_PLAY_AUDIO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 	ret = check_for_audio_disc(cdi, cdi->ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 	return cdi->ops->audio_ioctl(cdi, cmd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776)  * Required when we need to use READ_10 to issue other than 2048 block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)  * reads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) static int cdrom_switch_blocksize(struct cdrom_device_info *cdi, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 	struct modesel_head mh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 	memset(&mh, 0, sizeof(mh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 	mh.block_desc_length = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 	mh.block_length_med = (size >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 	mh.block_length_lo = size & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 	memset(&cgc, 0, sizeof(cgc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 	cgc.cmd[0] = 0x15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 	cgc.cmd[1] = 1 << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 	cgc.cmd[4] = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 	cgc.buflen = sizeof(mh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 	cgc.buffer = (char *) &mh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	cgc.data_direction = CGC_DATA_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 	mh.block_desc_length = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 	mh.block_length_med = (size >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 	mh.block_length_lo = size & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 	return cdo->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) static int cdrom_get_track_info(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 				__u16 track, __u8 type, track_information *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 	int ret, buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 	init_cdrom_command(&cgc, ti, 8, CGC_DATA_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 	cgc.cmd[0] = GPCMD_READ_TRACK_RZONE_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 	cgc.cmd[1] = type & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 	cgc.cmd[4] = (track & 0xff00) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 	cgc.cmd[5] = track & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 	cgc.cmd[8] = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 	cgc.quiet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 	ret = cdo->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 	buflen = be16_to_cpu(ti->track_information_length) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 		sizeof(ti->track_information_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	if (buflen > sizeof(track_information))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 		buflen = sizeof(track_information);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 	cgc.cmd[8] = cgc.buflen = buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 	ret = cdo->generic_packet(cdi, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 	/* return actual fill size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 	return buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) /* return the last written block on the CD-R media. this is for the udf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839)    file system. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 	struct cdrom_tocentry toc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 	disc_information di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 	track_information ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 	__u32 last_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 	int ret = -1, ti_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 	if (!CDROM_CAN(CDC_GENERIC_PACKET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 		goto use_toc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 	ret = cdrom_get_disc_info(cdi, &di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 	if (ret < (int)(offsetof(typeof(di), last_track_lsb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 			+ sizeof(di.last_track_lsb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 		goto use_toc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 	/* if unit didn't return msb, it's zeroed by cdrom_get_disc_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 	last_track = (di.last_track_msb << 8) | di.last_track_lsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 	ti_size = cdrom_get_track_info(cdi, last_track, 1, &ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 	if (ti_size < (int)offsetof(typeof(ti), track_start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 		goto use_toc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 	/* if this track is blank, try the previous. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 	if (ti.blank) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 		if (last_track == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 			goto use_toc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 		last_track--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 		ti_size = cdrom_get_track_info(cdi, last_track, 1, &ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 	if (ti_size < (int)(offsetof(typeof(ti), track_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 				+ sizeof(ti.track_size)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 		goto use_toc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 	/* if last recorded field is valid, return it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 	if (ti.lra_v && ti_size >= (int)(offsetof(typeof(ti), last_rec_address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 				+ sizeof(ti.last_rec_address))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 		*last_written = be32_to_cpu(ti.last_rec_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 		/* make it up instead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 		*last_written = be32_to_cpu(ti.track_start) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 				be32_to_cpu(ti.track_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 		if (ti.free_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 			*last_written -= (be32_to_cpu(ti.free_blocks) + 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 	/* this is where we end up if the drive either can't do a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 	   GPCMD_READ_DISC_INFO or GPCMD_READ_TRACK_RZONE_INFO or if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 	   it doesn't give enough information or fails. then we return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 	   the toc contents. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) use_toc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 	if (!CDROM_CAN(CDC_PLAY_AUDIO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 	toc.cdte_format = CDROM_MSF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 	toc.cdte_track = CDROM_LEADOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 	if ((ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &toc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 	sanitize_format(&toc.cdte_addr, &toc.cdte_format, CDROM_LBA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 	*last_written = toc.cdte_addr.lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) /* return the next writable block. also for udf file system. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) static int cdrom_get_next_writable(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 				   long *next_writable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 	disc_information di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 	track_information ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 	__u16 last_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 	int ret, ti_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 	if (!CDROM_CAN(CDC_GENERIC_PACKET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 		goto use_last_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 	ret = cdrom_get_disc_info(cdi, &di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 	if (ret < 0 || ret < offsetof(typeof(di), last_track_lsb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 				+ sizeof(di.last_track_lsb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 		goto use_last_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 	/* if unit didn't return msb, it's zeroed by cdrom_get_disc_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 	last_track = (di.last_track_msb << 8) | di.last_track_lsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 	ti_size = cdrom_get_track_info(cdi, last_track, 1, &ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 	if (ti_size < 0 || ti_size < offsetof(typeof(ti), track_start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 		goto use_last_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 	/* if this track is blank, try the previous. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	if (ti.blank) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 		if (last_track == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 			goto use_last_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 		last_track--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 		ti_size = cdrom_get_track_info(cdi, last_track, 1, &ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 		if (ti_size < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 			goto use_last_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 	/* if next recordable address field is valid, use it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 	if (ti.nwa_v && ti_size >= offsetof(typeof(ti), next_writable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 				+ sizeof(ti.next_writable)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 		*next_writable = be32_to_cpu(ti.next_writable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) use_last_written:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 	ret = cdrom_get_last_written(cdi, next_writable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 		*next_writable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 		*next_writable += 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) static noinline int mmc_ioctl_cdrom_read_data(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 					      void __user *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 					      struct packet_command *cgc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 					      int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 	struct scsi_sense_hdr sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 	struct cdrom_msf msf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 	int blocksize = 0, format = 0, lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 	case CDROMREADRAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 		blocksize = CD_FRAMESIZE_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 	case CDROMREADMODE1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 		blocksize = CD_FRAMESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 		format = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 	case CDROMREADMODE2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 		blocksize = CD_FRAMESIZE_RAW0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 	if (copy_from_user(&msf, (struct cdrom_msf __user *)arg, sizeof(msf)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 	lba = msf_to_lba(msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 	/* FIXME: we need upper bound checking, too!! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 	if (lba < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 	cgc->buffer = kzalloc(blocksize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 	if (cgc->buffer == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 	memset(&sshdr, 0, sizeof(sshdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 	cgc->sshdr = &sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 	cgc->data_direction = CGC_DATA_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 	ret = cdrom_read_block(cdi, cgc, lba, 1, format, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 	if (ret && sshdr.sense_key == 0x05 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 	    sshdr.asc == 0x20 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 	    sshdr.ascq == 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 		 * SCSI-II devices are not required to support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 		 * READ_CD, so let's try switching block size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 		/* FIXME: switch back again... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 		ret = cdrom_switch_blocksize(cdi, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 		cgc->sshdr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 		ret = cdrom_read_cd(cdi, cgc, lba, blocksize, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 		ret |= cdrom_switch_blocksize(cdi, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 	if (!ret && copy_to_user(arg, cgc->buffer, blocksize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 		ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 	kfree(cgc->buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) static noinline int mmc_ioctl_cdrom_read_audio(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 					       void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 	struct cdrom_read_audio ra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 	int lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 	if (in_compat_syscall()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 		struct compat_cdrom_read_audio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 			union cdrom_addr	addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 			u8			addr_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 			compat_int_t		nframes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 			compat_caddr_t		buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 		} ra32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 		if (copy_from_user(&ra32, arg, sizeof(ra32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 		ra = (struct cdrom_read_audio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 			.addr		= ra32.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 			.addr_format	= ra32.addr_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 			.nframes	= ra32.nframes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 			.buf		= compat_ptr(ra32.buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 		if (copy_from_user(&ra, (struct cdrom_read_audio __user *)arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 				   sizeof(ra)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 	if (ra.addr_format == CDROM_MSF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 		lba = msf_to_lba(ra.addr.msf.minute,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 				 ra.addr.msf.second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 				 ra.addr.msf.frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 	else if (ra.addr_format == CDROM_LBA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 		lba = ra.addr.lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 	/* FIXME: we need upper bound checking, too!! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 	if (lba < 0 || ra.nframes <= 0 || ra.nframes > CD_FRAMES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 	return cdrom_read_cdda(cdi, ra.buf, lba, ra.nframes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) static noinline int mmc_ioctl_cdrom_subchannel(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 					       void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 	struct cdrom_subchnl q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 	u_char requested, back;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 	if (copy_from_user(&q, (struct cdrom_subchnl __user *)arg, sizeof(q)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 	requested = q.cdsc_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 	if (!((requested == CDROM_MSF) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	      (requested == CDROM_LBA)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 	ret = cdrom_read_subchannel(cdi, &q, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 	back = q.cdsc_format; /* local copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 	sanitize_format(&q.cdsc_absaddr, &back, requested);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 	sanitize_format(&q.cdsc_reladdr, &q.cdsc_format, requested);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 	if (copy_to_user((struct cdrom_subchnl __user *)arg, &q, sizeof(q)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 	/* cd_dbg(CD_DO_IOCTL, "CDROMSUBCHNL successful\n"); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) static noinline int mmc_ioctl_cdrom_play_msf(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 					     void __user *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 					     struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 	struct cdrom_msf msf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 	cd_dbg(CD_DO_IOCTL, "entering CDROMPLAYMSF\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 	if (copy_from_user(&msf, (struct cdrom_msf __user *)arg, sizeof(msf)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 	cgc->cmd[0] = GPCMD_PLAY_AUDIO_MSF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 	cgc->cmd[3] = msf.cdmsf_min0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 	cgc->cmd[4] = msf.cdmsf_sec0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 	cgc->cmd[5] = msf.cdmsf_frame0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 	cgc->cmd[6] = msf.cdmsf_min1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 	cgc->cmd[7] = msf.cdmsf_sec1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 	cgc->cmd[8] = msf.cdmsf_frame1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 	cgc->data_direction = CGC_DATA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 	return cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) static noinline int mmc_ioctl_cdrom_play_blk(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 					     void __user *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) 					     struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 	struct cdrom_blk blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 	cd_dbg(CD_DO_IOCTL, "entering CDROMPLAYBLK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 	if (copy_from_user(&blk, (struct cdrom_blk __user *)arg, sizeof(blk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 	cgc->cmd[0] = GPCMD_PLAY_AUDIO_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 	cgc->cmd[2] = (blk.from >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 	cgc->cmd[3] = (blk.from >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 	cgc->cmd[4] = (blk.from >>  8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 	cgc->cmd[5] = blk.from & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 	cgc->cmd[7] = (blk.len >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 	cgc->cmd[8] = blk.len & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 	cgc->data_direction = CGC_DATA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 	return cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) static noinline int mmc_ioctl_cdrom_volume(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 					   void __user *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 					   struct packet_command *cgc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 					   unsigned int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 	struct cdrom_volctrl volctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 	unsigned char buffer[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 	char mask[sizeof(buffer)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 	unsigned short offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 	cd_dbg(CD_DO_IOCTL, "entering CDROMVOLUME\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 	if (copy_from_user(&volctrl, (struct cdrom_volctrl __user *)arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 			   sizeof(volctrl)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 	cgc->buffer = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 	cgc->buflen = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 	ret = cdrom_mode_sense(cdi, cgc, GPMODE_AUDIO_CTL_PAGE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 	/* originally the code depended on buffer[1] to determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 	   how much data is available for transfer. buffer[1] is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 	   unfortunately ambigious and the only reliable way seem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 	   to be to simply skip over the block descriptor... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 	offset = 8 + be16_to_cpu(*(__be16 *)(buffer + 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 	if (offset + 16 > sizeof(buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 		return -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 	if (offset + 16 > cgc->buflen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 		cgc->buflen = offset + 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 		ret = cdrom_mode_sense(cdi, cgc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 				       GPMODE_AUDIO_CTL_PAGE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 	/* sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 	if ((buffer[offset] & 0x3f) != GPMODE_AUDIO_CTL_PAGE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 	    buffer[offset + 1] < 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 	/* now we have the current volume settings. if it was only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 	   a CDROMVOLREAD, return these values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 	if (cmd == CDROMVOLREAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 		volctrl.channel0 = buffer[offset+9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 		volctrl.channel1 = buffer[offset+11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 		volctrl.channel2 = buffer[offset+13];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 		volctrl.channel3 = buffer[offset+15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 		if (copy_to_user((struct cdrom_volctrl __user *)arg, &volctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 				 sizeof(volctrl)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 	/* get the volume mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 	cgc->buffer = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 	ret = cdrom_mode_sense(cdi, cgc, GPMODE_AUDIO_CTL_PAGE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 	buffer[offset + 9]  = volctrl.channel0 & mask[offset + 9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 	buffer[offset + 11] = volctrl.channel1 & mask[offset + 11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 	buffer[offset + 13] = volctrl.channel2 & mask[offset + 13];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 	buffer[offset + 15] = volctrl.channel3 & mask[offset + 15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 	/* set volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 	cgc->buffer = buffer + offset - 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 	memset(cgc->buffer, 0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 	return cdrom_mode_select(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) static noinline int mmc_ioctl_cdrom_start_stop(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 					       struct packet_command *cgc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 					       int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 	cd_dbg(CD_DO_IOCTL, "entering CDROMSTART/CDROMSTOP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 	cgc->cmd[0] = GPCMD_START_STOP_UNIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 	cgc->cmd[1] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 	cgc->cmd[4] = (cmd == CDROMSTART) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 	cgc->data_direction = CGC_DATA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) 	return cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) static noinline int mmc_ioctl_cdrom_pause_resume(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 						 struct packet_command *cgc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 						 int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 	const struct cdrom_device_ops *cdo = cdi->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 	cd_dbg(CD_DO_IOCTL, "entering CDROMPAUSE/CDROMRESUME\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 	cgc->cmd[0] = GPCMD_PAUSE_RESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 	cgc->cmd[8] = (cmd == CDROMRESUME) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 	cgc->data_direction = CGC_DATA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 	return cdo->generic_packet(cdi, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) static noinline int mmc_ioctl_dvd_read_struct(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 					      void __user *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 					      struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 	dvd_struct *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 	int size = sizeof(dvd_struct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 	if (!CDROM_CAN(CDC_DVD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 	s = memdup_user(arg, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 	if (IS_ERR(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 		return PTR_ERR(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 	cd_dbg(CD_DO_IOCTL, "entering DVD_READ_STRUCT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 	ret = dvd_read_struct(cdi, s, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 	if (copy_to_user(arg, s, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 		ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 	kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) static noinline int mmc_ioctl_dvd_auth(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 				       void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 	dvd_authinfo ai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 	if (!CDROM_CAN(CDC_DVD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 	cd_dbg(CD_DO_IOCTL, "entering DVD_AUTH\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 	if (copy_from_user(&ai, (dvd_authinfo __user *)arg, sizeof(ai)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 	ret = dvd_do_auth(cdi, &ai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 	if (copy_to_user((dvd_authinfo __user *)arg, &ai, sizeof(ai)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) static noinline int mmc_ioctl_cdrom_next_writable(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 						  void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 	long next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_NEXT_WRITABLE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 	ret = cdrom_get_next_writable(cdi, &next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 	if (copy_to_user((long __user *)arg, &next, sizeof(next)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) static noinline int mmc_ioctl_cdrom_last_written(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 						 void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 	long last = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 	cd_dbg(CD_DO_IOCTL, "entering CDROM_LAST_WRITTEN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 	ret = cdrom_get_last_written(cdi, &last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 	if (in_compat_syscall())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 		return put_user(last, (__s32 __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 	return put_user(last, (long __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) static int mmc_ioctl(struct cdrom_device_info *cdi, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 		     unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 	struct packet_command cgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 	void __user *userptr = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 	memset(&cgc, 0, sizeof(cgc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 	/* build a unified command and queue it through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 	   cdo->generic_packet() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 	case CDROMREADRAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 	case CDROMREADMODE1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 	case CDROMREADMODE2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 		return mmc_ioctl_cdrom_read_data(cdi, userptr, &cgc, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 	case CDROMREADAUDIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 		return mmc_ioctl_cdrom_read_audio(cdi, userptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 	case CDROMSUBCHNL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 		return mmc_ioctl_cdrom_subchannel(cdi, userptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 	case CDROMPLAYMSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 		return mmc_ioctl_cdrom_play_msf(cdi, userptr, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) 	case CDROMPLAYBLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 		return mmc_ioctl_cdrom_play_blk(cdi, userptr, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) 	case CDROMVOLCTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 	case CDROMVOLREAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) 		return mmc_ioctl_cdrom_volume(cdi, userptr, &cgc, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 	case CDROMSTART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 	case CDROMSTOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 		return mmc_ioctl_cdrom_start_stop(cdi, &cgc, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 	case CDROMPAUSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 	case CDROMRESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 		return mmc_ioctl_cdrom_pause_resume(cdi, &cgc, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 	case DVD_READ_STRUCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 		return mmc_ioctl_dvd_read_struct(cdi, userptr, &cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 	case DVD_AUTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 		return mmc_ioctl_dvd_auth(cdi, userptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 	case CDROM_NEXT_WRITABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 		return mmc_ioctl_cdrom_next_writable(cdi, userptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 	case CDROM_LAST_WRITTEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 		return mmc_ioctl_cdrom_last_written(cdi, userptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 	return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348)  * Just about every imaginable ioctl is supported in the Uniform layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349)  * these days.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350)  * ATAPI / SCSI specific code now mainly resides in mmc_ioctl().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 		fmode_t mode, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 	 * Try the generic SCSI command ioctl's first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 	ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 	if (ret != -ENOTTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 	case CDROMMULTISESSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 		return cdrom_ioctl_multisession(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 	case CDROMEJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 		return cdrom_ioctl_eject(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 	case CDROMCLOSETRAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 		return cdrom_ioctl_closetray(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 	case CDROMEJECT_SW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 		return cdrom_ioctl_eject_sw(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 	case CDROM_MEDIA_CHANGED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 		return cdrom_ioctl_media_changed(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 	case CDROM_SET_OPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 		return cdrom_ioctl_set_options(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 	case CDROM_CLEAR_OPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 		return cdrom_ioctl_clear_options(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 	case CDROM_SELECT_SPEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 		return cdrom_ioctl_select_speed(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 	case CDROM_SELECT_DISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 		return cdrom_ioctl_select_disc(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 	case CDROMRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 		return cdrom_ioctl_reset(cdi, bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) 	case CDROM_LOCKDOOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) 		return cdrom_ioctl_lock_door(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) 	case CDROM_DEBUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) 		return cdrom_ioctl_debug(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 	case CDROM_GET_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 		return cdrom_ioctl_get_capability(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 	case CDROM_GET_MCN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 		return cdrom_ioctl_get_mcn(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) 	case CDROM_DRIVE_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 		return cdrom_ioctl_drive_status(cdi, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 	case CDROM_DISC_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 		return cdrom_ioctl_disc_status(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 	case CDROM_CHANGER_NSLOTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 		return cdrom_ioctl_changer_nslots(cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) 	 * Use the ioctls that are implemented through the generic_packet()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 	 * interface. this may look at bit funny, but if -ENOTTY is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 	 * returned that particular ioctl is not implemented and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 	 * let it go through the device specific ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 	if (CDROM_CAN(CDC_GENERIC_PACKET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 		ret = mmc_ioctl(cdi, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 		if (ret != -ENOTTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 	 * Note: most of the cd_dbg() calls are commented out here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 	 * because they fill up the sys log when CD players poll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 	 * the drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 	case CDROMSUBCHNL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 		return cdrom_ioctl_get_subchnl(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 	case CDROMREADTOCHDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 		return cdrom_ioctl_read_tochdr(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 	case CDROMREADTOCENTRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 		return cdrom_ioctl_read_tocentry(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 	case CDROMPLAYMSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 		return cdrom_ioctl_play_msf(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 	case CDROMPLAYTRKIND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 		return cdrom_ioctl_play_trkind(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 	case CDROMVOLCTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 		return cdrom_ioctl_volctrl(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 	case CDROMVOLREAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 		return cdrom_ioctl_volread(cdi, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 	case CDROMSTART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 	case CDROMSTOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 	case CDROMPAUSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 	case CDROMRESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 		return cdrom_ioctl_audioctl(cdi, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 	return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) EXPORT_SYMBOL(cdrom_get_last_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) EXPORT_SYMBOL(register_cdrom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) EXPORT_SYMBOL(unregister_cdrom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) EXPORT_SYMBOL(cdrom_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) EXPORT_SYMBOL(cdrom_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) EXPORT_SYMBOL(cdrom_ioctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) EXPORT_SYMBOL(cdrom_number_of_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) EXPORT_SYMBOL(cdrom_mode_select);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) EXPORT_SYMBOL(cdrom_mode_sense);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) EXPORT_SYMBOL(init_cdrom_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) EXPORT_SYMBOL(cdrom_get_media_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) #define CDROM_STR_SIZE 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) static struct cdrom_sysctl_settings {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 	char	info[CDROM_STR_SIZE];	/* general info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 	int	autoclose;		/* close tray upon mount, etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 	int	autoeject;		/* eject on umount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 	int	debug;			/* turn on debugging messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 	int	lock;			/* lock the door on device open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 	int	check;			/* check media type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) } cdrom_sysctl_settings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) enum cdrom_print_option {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 	CTL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 	CTL_SPEED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 	CTL_SLOTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 	CTL_CAPABILITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) static int cdrom_print_info(const char *header, int val, char *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 				int *pos, enum cdrom_print_option option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 	const int max_size = sizeof(cdrom_sysctl_settings.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 	struct cdrom_device_info *cdi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 	ret = scnprintf(info + *pos, max_size - *pos, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) 	*pos += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 	list_for_each_entry(cdi, &cdrom_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) 		switch (option) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 		case CTL_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) 			ret = scnprintf(info + *pos, max_size - *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 					"\t%s", cdi->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 		case CTL_SPEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 			ret = scnprintf(info + *pos, max_size - *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 					"\t%d", cdi->speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 		case CTL_SLOTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 			ret = scnprintf(info + *pos, max_size - *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) 					"\t%d", cdi->capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 		case CTL_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 			ret = scnprintf(info + *pos, max_size - *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 					"\t%d", CDROM_CAN(val) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 			pr_info("invalid option%d\n", option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 		*pos += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) static int cdrom_sysctl_info(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520)                            void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) 	int pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 	char *info = cdrom_sysctl_settings.info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 	const int max_size = sizeof(cdrom_sysctl_settings.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) 	if (!*lenp || (*ppos && !write)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) 		*lenp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 	mutex_lock(&cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 	pos = sprintf(info, "CD-ROM information, " VERSION "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 	if (cdrom_print_info("\ndrive name:\t", 0, info, &pos, CTL_NAME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 	if (cdrom_print_info("\ndrive speed:\t", 0, info, &pos, CTL_SPEED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 	if (cdrom_print_info("\ndrive # of slots:", 0, info, &pos, CTL_SLOTS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 	if (cdrom_print_info("\nCan close tray:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 				CDC_CLOSE_TRAY, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 	if (cdrom_print_info("\nCan open tray:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 				CDC_OPEN_TRAY, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 	if (cdrom_print_info("\nCan lock tray:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 				CDC_LOCK, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 	if (cdrom_print_info("\nCan change speed:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 				CDC_SELECT_SPEED, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 	if (cdrom_print_info("\nCan select disk:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) 				CDC_SELECT_DISC, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 	if (cdrom_print_info("\nCan read multisession:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 				CDC_MULTI_SESSION, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 	if (cdrom_print_info("\nCan read MCN:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 				CDC_MCN, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 	if (cdrom_print_info("\nReports media changed:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 				CDC_MEDIA_CHANGED, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 	if (cdrom_print_info("\nCan play audio:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 				CDC_PLAY_AUDIO, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 	if (cdrom_print_info("\nCan write CD-R:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 				CDC_CD_R, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 	if (cdrom_print_info("\nCan write CD-RW:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 				CDC_CD_RW, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) 	if (cdrom_print_info("\nCan read DVD:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 				CDC_DVD, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 	if (cdrom_print_info("\nCan write DVD-R:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 				CDC_DVD_R, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 	if (cdrom_print_info("\nCan write DVD-RAM:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 				CDC_DVD_RAM, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 	if (cdrom_print_info("\nCan read MRW:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 				CDC_MRW, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 	if (cdrom_print_info("\nCan write MRW:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 				CDC_MRW_W, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 	if (cdrom_print_info("\nCan write RAM:\t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 				CDC_RAM, info, &pos, CTL_CAPABILITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 	if (!scnprintf(info + pos, max_size - pos, "\n\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) doit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 	mutex_unlock(&cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 	return proc_dostring(ctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 	pr_info("info buffer too small\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 	goto doit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) /* Unfortunately, per device settings are not implemented through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603)    procfs/sysctl yet. When they are, this will naturally disappear. For now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604)    just update all drives. Later this will become the template on which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605)    new registered drives will be based. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) static void cdrom_update_settings(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 	struct cdrom_device_info *cdi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 	mutex_lock(&cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 	list_for_each_entry(cdi, &cdrom_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 		if (autoclose && CDROM_CAN(CDC_CLOSE_TRAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 			cdi->options |= CDO_AUTO_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 		else if (!autoclose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 			cdi->options &= ~CDO_AUTO_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 		if (autoeject && CDROM_CAN(CDC_OPEN_TRAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 			cdi->options |= CDO_AUTO_EJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 		else if (!autoeject)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 			cdi->options &= ~CDO_AUTO_EJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 		if (lockdoor && CDROM_CAN(CDC_LOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 			cdi->options |= CDO_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 		else if (!lockdoor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 			cdi->options &= ~CDO_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 		if (check_media_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 			cdi->options |= CDO_CHECK_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 			cdi->options &= ~CDO_CHECK_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) 	mutex_unlock(&cdrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) static int cdrom_sysctl_handler(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 				void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 	ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 	if (write) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 		/* we only care for 1 or 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 		autoclose        = !!cdrom_sysctl_settings.autoclose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 		autoeject        = !!cdrom_sysctl_settings.autoeject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 		debug	         = !!cdrom_sysctl_settings.debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 		lockdoor         = !!cdrom_sysctl_settings.lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 		check_media_type = !!cdrom_sysctl_settings.check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 		/* update the option flags according to the changes. we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 		   don't have per device options through sysctl yet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 		   but we will have and then this will disappear. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) 		cdrom_update_settings();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654)         return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) /* Place files in /proc/sys/dev/cdrom */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) static struct ctl_table cdrom_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 		.procname	= "info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 		.data		= &cdrom_sysctl_settings.info, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) 		.maxlen		= CDROM_STR_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) 		.mode		= 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) 		.proc_handler	= cdrom_sysctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 		.procname	= "autoclose",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 		.data		= &cdrom_sysctl_settings.autoclose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 		.proc_handler	= cdrom_sysctl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 		.procname	= "autoeject",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 		.data		= &cdrom_sysctl_settings.autoeject,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 		.proc_handler	= cdrom_sysctl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 		.procname	= "debug",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 		.data		= &cdrom_sysctl_settings.debug,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 		.proc_handler	= cdrom_sysctl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 		.procname	= "lock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 		.data		= &cdrom_sysctl_settings.lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 		.proc_handler	= cdrom_sysctl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 		.procname	= "check_media",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 		.data		= &cdrom_sysctl_settings.check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 		.proc_handler	= cdrom_sysctl_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) static struct ctl_table cdrom_cdrom_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 		.procname	= "cdrom",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 		.maxlen		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 		.mode		= 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 		.child		= cdrom_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) /* Make sure that /proc/sys/dev is there */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) static struct ctl_table cdrom_root_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 		.procname	= "dev",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 		.maxlen		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 		.mode		= 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 		.child		= cdrom_cdrom_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) static struct ctl_table_header *cdrom_sysctl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) static void cdrom_sysctl_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 	static atomic_t initialized = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 	if (!atomic_add_unless(&initialized, 1, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 	cdrom_sysctl_header = register_sysctl_table(cdrom_root_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 	/* set the defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 	cdrom_sysctl_settings.autoclose = autoclose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 	cdrom_sysctl_settings.autoeject = autoeject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) 	cdrom_sysctl_settings.debug = debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 	cdrom_sysctl_settings.lock = lockdoor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 	cdrom_sysctl_settings.check = check_media_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) static void cdrom_sysctl_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 	if (cdrom_sysctl_header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 		unregister_sysctl_table(cdrom_sysctl_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) #else /* CONFIG_SYSCTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) static void cdrom_sysctl_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) static void cdrom_sysctl_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) #endif /* CONFIG_SYSCTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) static int __init cdrom_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 	cdrom_sysctl_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) static void __exit cdrom_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 	pr_info("Uniform CD-ROM driver unloaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 	cdrom_sysctl_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) module_init(cdrom_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) module_exit(cdrom_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) MODULE_LICENSE("GPL");