summaryrefslogtreecommitdiffstats
path: root/sys-utils/eject.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-7/+5Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: fix typos [codespell]Sami Kerola2019-02-181-1/+1
| | | | | Reference: https://github.com/codespell-project/codespell Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* eject: use err() rather than abort()Karel Zak2018-11-051-1/+1
| | | | | Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1645920 Signed-off-by: Karel Zak <kzak@redhat.com>
* fstrim: use new ul_path_* APIKarel Zak2018-06-211-12/+15
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sys-utils: use errexec()Karel Zak2018-02-011-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* eject: remove list_speeds() #ifdef CDROM_SELECT_SPEED protectionSami Kerola2017-11-281-4/+0Star
| | | | | | | | The CDROM_SELECT_SPEED should be available practically everywhere. Where the define is missing an error message about path /proc/sys/dev/cdrom/info cannot be opened is better error than a warnx() about kernel support. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: cosmetics, remove argument from usage(FILE*)Ruediger Meier2017-06-261-3/+4
| | | | | | | | | | | | | | This patch is trivial and changes nothing, because we were always using usage(stdout) Now all our usage() functions look very similar. If wanted we could auto-generate another big cosmetical patch to remove all the useless "FILE *out" constants and use printf and puts rather than their f* friends. Such patch could be automatically synchronized with the translation project (newlines!) to not make the translators sick. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-2/+2
| | | | | | | | | | text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer Since many 'struct option' has used zero as NULL make them more readable in same go by reindenting, and using named argument requirements. Reference: https://lwn.net/Articles/93577/ Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-2/+1Star
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* eject: use parse_switch()Sami Kerola2015-02-241-12/+4Star
| | | | | | | [kzak@redhat.com: - use extended parse_switch()] Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* eject: add verbosity to cdrom door lock errorSami Kerola2015-01-071-8/+11
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-1/+3
| | | | | | | | | This adds a concise description of a tool to its usage text. A first form of this patch was proposed by Steven Honeyman (see http://www.spinics.net/lists/util-linux-ng/msg09994.html). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* eject: use sysfs API to detect hotplugKarel Zak2014-12-021-105/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: move all around clock_gettime() to monotonic.cKarel Zak2014-11-191-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: use monotonic time rater than gettimeofdayKarel Zak2014-11-181-2/+3
| | | | | | Based on patch Alexander Samilovskih <alexsamilovskih@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* eject: move unreachable code to preprocessor #else block [smatch scan]Sami Kerola2014-10-201-4/+4
| | | | | | eject.c:466 toggle_tray() info: ignoring unreachable code. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* eject: make open_device() and select_speed() to use struct eject_controlSami Kerola2014-09-191-29/+25Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* eject: add struct eject_control to remove global variablesSami Kerola2014-09-191-196/+198
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: use libmnt_table reference counterKarel Zak2013-08-211-5/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: use libmnt_cache reference countingKarel Zak2013-08-211-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* eject: assigned value is never read [clang-analyzer]Sami Kerola2013-07-091-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* eject: Check host_status and driver_status when using SG_IO.Karel Zak2013-06-181-3/+21
| | | | | | | | | | | | | | | | | 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>
* eject: unlock door before issuing CDROMEJECT commandAaron Lu2013-06-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* eject: remove a duplicate command name from error messageSami Kerola2013-02-061-1/+1
| | | | | | Let the err() print the command name. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: make readlink() usage more robustKarel Zak2012-10-231-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount, eject: replace index() and rindex() with strrch() or strrchr()Sami Kerola2012-10-221-1/+1
| | | | | | | | | | 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>
* eject: robust strings usage [coverity scan]Karel Zak2012-09-071-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* eject: return proper 0/1 from eject_cdrom()Dave Reisner2012-08-131-5/+5
| | | | | | | | 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>
* eject: fix shadow declarationSami Kerola2012-07-261-1/+0Star
| | | | | | | 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>
* eject: fix compiler warning [-Wmissing-prototypes]Karel Zak2012-07-161-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* translation: unify file open error messagesSami Kerola2012-07-161-2/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* Merge branch '2012wk23' of git://github.com/kerolasa/lelux-utiliteetitKarel Zak2012-06-151-0/+8
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * '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]
| * eject: inform if CD-ROM drive is not readySami Kerola2012-06-111-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* | eject: cleanup umount codeKarel Zak2012-06-131-19/+19
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | eject: don't try to use non-device pathKarel Zak2012-06-131-1/+8
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | eject: add --no-partitions-unmountKarel Zak2012-06-131-23/+41
|/ | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* eject: allow to address device by LABEL/UUIDKarel Zak2012-05-181-2/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* eject: verify writing to streams was successfulSami Kerola2012-04-231-0/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* eject: close open file [cppcheck]Sami Kerola2012-04-101-0/+1
| | | | | | [eject.c:498]: (error) Resource leak: f Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* eject: inform why open failedSami Kerola2012-04-101-1/+1
| | | | | | | Mostly to cover common case when user does not have permission to use eject. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* eject: use CDROM_DRIVE_STATUS if available for tray togglingMike Frysinger2012-04-101-20/+32
| | | | | | | | | | | | | | | | | | 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>
* eject: constify arrayMike Frysinger2012-04-101-1/+1
| | | | Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* eject: use BUILD_EJECT, move to sys-utilsKarel Zak2012-04-051-0/+1082
Signed-off-by: Karel Zak <kzak@redhat.com>