Commit Graph

28 Commits

Author SHA1 Message Date
Sami Kerola 6f7f155c0c eject: move unreachable code to preprocessor #else block [smatch scan]
eject.c:466 toggle_tray() info: ignoring unreachable code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-20 14:07:18 +02:00
Sami Kerola 25a3fa8159 eject: make open_device() and select_speed() to use struct eject_control
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-09-19 19:31:02 +01:00
Sami Kerola 257a003528 eject: add struct eject_control to remove global variables
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-09-19 19:31:02 +01:00
Karel Zak 50fccba1ab misc: use libmnt_table reference counter
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 16:07:51 +02:00
Karel Zak 6195f9e6fa misc: use libmnt_cache reference counting
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 14:38:38 +02:00
Sami Kerola 31f65a8e45 eject: assigned value is never read [clang-analyzer]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:10 +02:00
Karel Zak 90a0e97c7b eject: Check host_status and driver_status when using SG_IO.
Based on Suse patch, originally from
	Anna Bernathova <anicka@suse.cz>, May 2008

  SG_IO completion status is weird but still well defined. You'll need
  to check both host_status, driver_status and status to determine that
  a command actually succeeded. -- Tejun Heo, May 2008

Note that we also need to check driver_status and sense_buffer to
detect situation when there is no medium. It's valid request to call
eject(8) for device with no medium.

References: https://bugzilla.novell.com/show_bug.cgi?id=358033
Signed-off-by: Anna Bernathova <anicka@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-06-18 12:24:28 +02:00
Aaron Lu 12272030e5 eject: unlock door before issuing CDROMEJECT command
If user has inserted a disc into the drive, the drive will normally be
locked. When using eject command to eject the drive, we need to unlock
the door first, or the CDROMEJECT command will fail.

Though the 2nd attmpt to eject the drive with eject_scsi will succeed,
it actually does two things: first to unlock the door and then to eject
the tray, both with the SG_IO ioctl. The problem is, Linux SCSI driver
keeps track of if a device is in locked state or not, if we go with
SG_IO to do the unlocking, the driver will not be aware of the unlocking
and would think the drive is locked while actually it has already been
unlocked by the first SG_IO command.

Fix this by issuing a unlock door command before the CDROMEJECT command
in cdrom_eject. Prior to this fix, the following output is expected when
there is a disc inside:

[aaron@aaronlu util-linux-2.22.2]$ eject -v /dev/sr0
eject: device name is `/dev/sr0'
eject: /dev/sr0: mounted on /run/media/aaron/CD_ROM
eject: /dev/sr0: is whole-disk device
eject: /dev/sr0: is removable device
eject: /run/media/aaron/CD_ROM: unmounting
eject: /dev/sr0: trying to eject using CD-ROM eject command
eject: CD-ROM eject command failed
eject: /dev/sr0: trying to eject using SCSI commands
eject: SCSI eject succeeded

After this fix, the following output is expected:
[aaron@aaronlu util-linux-2.22.2]$ ./eject -v /dev/sr0
lt-eject: device name is `/dev/sr0'
lt-eject: /dev/sr0: mounted on /run/media/aaron/CD_ROM
lt-eject: /dev/sr0: is whole-disk device
lt-eject: /dev/sr0: is removable device
lt-eject: /run/media/aaron/CD_ROM: unmounting
lt-eject: /dev/sr0: trying to eject using CD-ROM eject command
lt-eject: CD-ROM eject command succeeded

And the SCSI device's locked state is correct now.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
2013-06-13 13:28:04 +02:00
Sami Kerola 291af4bce1 eject: remove a duplicate command name from error message
Let the err() print the command name.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06 11:51:19 +01:00
Karel Zak 9f51089e7f misc: make readlink() usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-23 12:40:39 +02:00
Sami Kerola 913e43b8e2 libmount, eject: replace index() and rindex() with strrch() or strrchr()
Both index() and rindex() are legacy functions which may be withdrawn in
a future.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/index.html
Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/rindex.html
Acked-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-22 10:13:32 +02:00
Karel Zak 92fe6e9633 eject: robust strings usage [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-07 13:43:56 +02:00
Dave Reisner 3514cc3a8f eject: return proper 0/1 from eject_cdrom()
main() expects this method to return 0 for failure and 1 for success, as
the other eject_*() methods do. Add the missing comparison of ioctl() >= 0

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-13 15:45:47 +02:00
Sami Kerola 0c7fd6f8f9 eject: fix shadow declaration
sys-utils/eject.c:529:11: warning: declaration of 'str' shadows a previous local [-Wshadow]
sys-utils/eject.c:506:9: warning: shadowed declaration is here [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-26 13:35:59 +02:00
Karel Zak e5d262eec5 eject: fix compiler warning [-Wmissing-prototypes]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-16 18:55:39 +02:00
Sami Kerola 289dcc9023 translation: unify file open error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Karel Zak d5f9b6e5fb Merge branch '2012wk23' of git://github.com/kerolasa/lelux-utiliteetit
* '2012wk23' of git://github.com/kerolasa/lelux-utiliteetit:
  lsblk: use blkdev_scsi_type_to_name()
  blkdev: add blkdev_scsi_type_to_name()
  wipefs: use symbolic value for markup mode
  eject: inform if CD-ROM drive is not ready
  docs: clean up partx.8 manual
  include: fix void pointer arithmetics warnings
  sysfs: fix printf format warnings
  build: fix unused parameter warnings
  build: fix redundant redeclaration warnings
  include: fix spurious list.h warnings
  uuidd: use output redirection which works [checkbashisms]
  blkid: fix realloc memory leak [cppcheck]
  setarch: do not use -1 as array index [cppcheck]
2012-06-15 12:44:17 +02:00
Karel Zak 8cd48d67f4 eject: cleanup umount code
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-13 15:58:16 +02:00
Karel Zak 8388bbb3df eject: don't try to use non-device path
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-13 13:55:49 +02:00
Karel Zak 566cd92c9f eject: add --no-partitions-unmount
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-13 13:46:24 +02:00
Sami Kerola f31d041aaf eject: inform if CD-ROM drive is not ready
Include file (see linux/cdrom.h lines 395 and 398) suggests ioctl() can
return CDS_NO_INFO and CDS_DRIVE_NOT_READY, which where ignored.  This
commit will tell user what is going on.

The commit will also make eject to crash in ioctl() will return
unexpected value.

Reference: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/cdrom.h;h=dfd7f187c351440d2ffa81050e46ed2602877f73;hb=HEAD
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11 22:06:05 +02:00
Karel Zak 28094b1e3c eject: allow to address device by LABEL/UUID
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-18 12:01:10 +02:00
Sami Kerola 9146de0266 eject: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-23 12:02:07 +02:00
Sami Kerola 92091356f9 eject: close open file [cppcheck]
[eject.c:498]: (error) Resource leak: f

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-10 12:21:37 +02:00
Sami Kerola 38de283e35 eject: inform why open failed
Mostly to cover common case when user does not have permission to use
eject.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-10 12:21:33 +02:00
Mike Frysinger df3449d541 eject: use CDROM_DRIVE_STATUS if available for tray toggling
One some platforms, the -T option can be unreliable (see reference bug
report for some examples).  Instead, if the kernel supports the cdrom
status ioctl, use that to ask explicitly for the current tray status
and then open/close accordingly.

The eject_cdrom() func was reworked slightly, but none of the existing
callers care about the explicit normalization to [0,1] values, so have
it return the raw value so we can convert toggle_tray() over to using
that.

Finally, now that toggle_tray() uses a lot of helper functions, drop
the check on CDROMCLOSETRAY.  The sub-functions take care of that.

Reference: https://bugs.gentoo.org/261880
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-04-10 12:21:27 +02:00
Mike Frysinger e99f842daf eject: constify array
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-04-10 12:21:19 +02:00
Karel Zak 88a3f049ec eject: use BUILD_EJECT, move to sys-utils
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-05 15:51:30 +02:00