2012-03-27 13:35:06 +02:00
|
|
|
/*
|
2011-12-08 16:10:18 +01:00
|
|
|
* Copyright (C) 1994-2005 Jeff Tranter (tranter@pobox.com)
|
2012-03-27 13:35:06 +02:00
|
|
|
* Copyright (C) 2012 Karel Zak <kzak@redhat.com>
|
|
|
|
* Copyright (C) Michal Luscon <mluscon@redhat.com>
|
2011-12-08 16:10:18 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
2012-01-18 14:19:42 +01:00
|
|
|
#include <err.h>
|
2012-02-02 16:34:20 +01:00
|
|
|
#include <stdarg.h>
|
2012-01-17 18:23:40 +01:00
|
|
|
|
2011-12-08 16:10:18 +01:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/mtio.h>
|
|
|
|
#include <linux/cdrom.h>
|
|
|
|
#include <linux/fd.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/sg.h>
|
|
|
|
#include <scsi/scsi_ioctl.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2012-03-27 13:35:06 +02:00
|
|
|
#include "linux_version.h"
|
|
|
|
#include "c.h"
|
|
|
|
#include "nls.h"
|
|
|
|
#include "strutils.h"
|
|
|
|
#include "xalloc.h"
|
|
|
|
#include "canonicalize.h"
|
|
|
|
|
|
|
|
#define EJECT_DEFAULT_DEVICE "/dev/cdrom"
|
|
|
|
|
|
|
|
|
2012-02-08 18:19:35 +01:00
|
|
|
/* Used by the toggle_tray() function. If ejecting the tray takes this
|
2011-12-08 16:10:18 +01:00
|
|
|
* time or less, the tray was probably already ejected, so we close it
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
#define TRAY_WAS_ALREADY_OPEN_USECS 200000 /* about 0.2 seconds */
|
|
|
|
|
|
|
|
|
|
|
|
/* Global Variables */
|
2012-02-02 17:58:25 +01:00
|
|
|
static int a_option; /* command flags and arguments */
|
|
|
|
static int c_option;
|
|
|
|
static int d_option;
|
|
|
|
static int f_option;
|
|
|
|
static int n_option;
|
|
|
|
static int q_option;
|
|
|
|
static int r_option;
|
|
|
|
static int s_option;
|
|
|
|
static int t_option;
|
|
|
|
static int T_option;
|
|
|
|
static int v_option;
|
|
|
|
static int x_option;
|
|
|
|
static int p_option;
|
|
|
|
static int m_option;
|
|
|
|
static int a_arg;
|
|
|
|
static long int c_arg;
|
|
|
|
static long int x_arg;
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the basenames of devices which can have multiple
|
|
|
|
* partitions per device.
|
|
|
|
*/
|
2012-02-08 18:19:35 +01:00
|
|
|
const char *partition_device[] = {
|
|
|
|
"hd",
|
|
|
|
"sd",
|
|
|
|
"xd",
|
|
|
|
"dos_hd",
|
|
|
|
"mfm",
|
|
|
|
"ad",
|
|
|
|
"ed",
|
|
|
|
"ftl",
|
|
|
|
"pd",
|
|
|
|
0
|
|
|
|
};
|
2011-12-08 16:10:18 +01:00
|
|
|
|
2012-03-27 16:00:46 +02:00
|
|
|
static void vinfo(const char *fmt, va_list va)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "%s: ", program_invocation_short_name);
|
|
|
|
vprintf(fmt, va);
|
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void verbose(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
if (!v_option)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(va, fmt);
|
|
|
|
vinfo(fmt, va);
|
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void info(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
|
|
|
vinfo(fmt, va);
|
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
2012-03-27 13:44:09 +02:00
|
|
|
static void __attribute__ ((__noreturn__)) usage(FILE * out)
|
|
|
|
{
|
|
|
|
fputs(USAGE_HEADER, out);
|
|
|
|
|
|
|
|
fprintf(out,
|
|
|
|
_(" %s [options] [<device>|<mountpoint>]\n"), program_invocation_short_name);
|
|
|
|
|
|
|
|
fputs(USAGE_OPTIONS, out);
|
|
|
|
fputs(_(" -h, --help display command usage and exit\n"
|
|
|
|
" -V --version display program version and exit\n"
|
|
|
|
" -d, --default display default device\n"
|
|
|
|
" -a, --auto turn auto-eject feature on or off\n"
|
|
|
|
" -c, --changerslot switch discs on a CD-ROM changer\n"
|
|
|
|
" -t, --trayclose close tray\n"
|
|
|
|
" -T, --traytoggle toggle tray\n"
|
|
|
|
" -x, --cdspeed set CD-ROM max speed\n"
|
|
|
|
" -v, --verbose enable verbose output\n"
|
|
|
|
" -n, --noop don't eject, just show device found\n"
|
|
|
|
" -r, --cdrom eject CD-ROM\n"
|
|
|
|
" -s, --scsi eject SCSI device\n"
|
|
|
|
" -f, --loppy eject floppy\n"
|
|
|
|
" -q, --tape eject tape\n"
|
|
|
|
" -p, --proc use /proc/mounts instead of /etc/mtab\n"
|
|
|
|
" -m, --no-unmount do not unmount device even if it is mounted\n"),
|
|
|
|
out);
|
|
|
|
|
|
|
|
fputs(_("\nBy default tries -r, -s, -f, and -q in order until success.\n"), out);
|
|
|
|
fprintf(out, USAGE_MAN_TAIL("eject(1)"));
|
2011-12-08 16:10:18 +01:00
|
|
|
|
2012-03-27 13:44:09 +02:00
|
|
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle command line options. */
|
|
|
|
static void parse_args(int argc, char **argv, char **device)
|
|
|
|
{
|
2012-03-27 13:56:09 +02:00
|
|
|
static struct option long_opts[] =
|
2011-12-08 16:10:18 +01:00
|
|
|
{
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"verbose", no_argument, NULL, 'v'},
|
|
|
|
{"default", no_argument, NULL, 'd'},
|
|
|
|
{"auto", required_argument, NULL, 'a'},
|
|
|
|
{"changerslot", required_argument, NULL, 'c'},
|
|
|
|
{"trayclose", no_argument, NULL, 't'},
|
|
|
|
{"traytoggle", no_argument, NULL, 'T'},
|
|
|
|
{"cdspeed", required_argument, NULL, 'x'},
|
|
|
|
{"noop", no_argument, NULL, 'n'},
|
|
|
|
{"cdrom", no_argument, NULL, 'r'},
|
|
|
|
{"scsi", no_argument, NULL, 's'},
|
|
|
|
{"floppy", no_argument, NULL, 'f'},
|
|
|
|
{"tape", no_argument, NULL, 'q'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{"proc", no_argument, NULL, 'p'},
|
|
|
|
{"no-unmount", no_argument, NULL, 'm'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
int c;
|
|
|
|
|
2012-03-27 13:56:09 +02:00
|
|
|
while ((c = getopt_long(argc, argv,
|
|
|
|
"a:c:x:dfhnqrstTvVpm", long_opts, NULL)) != -1) {
|
2011-12-08 16:10:18 +01:00
|
|
|
switch (c) {
|
2012-03-27 13:56:09 +02:00
|
|
|
case 'a':
|
|
|
|
a_option = 1;
|
|
|
|
if (!strcmp(optarg, "0") || !strcmp(optarg, "off"))
|
|
|
|
a_arg = 0;
|
|
|
|
else if (!strcmp(optarg, "1") || !strcmp(optarg, "on"))
|
|
|
|
a_arg = 1;
|
|
|
|
else
|
|
|
|
errx(EXIT_FAILURE, _("invalid argument to --auto/-a option"));
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
c_option = 1;
|
|
|
|
c_arg = strtoul_or_err(optarg, _("invalid argument to --changerslot/-c option"));
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
x_option = 1;
|
|
|
|
x_arg = strtoul_or_err(optarg, _("invalid argument to --cdspeed/-x option"));
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
d_option = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
f_option = 1;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(stdout);
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
m_option = 1;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
n_option = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
p_option = 1;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
q_option = 1;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
r_option = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
s_option = 1;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
t_option = 1;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
T_option = 1;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
v_option = 1;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
printf(UTIL_LINUX_VERSION);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
2012-03-27 13:35:06 +02:00
|
|
|
default:
|
2012-03-27 13:56:09 +02:00
|
|
|
case '?':
|
|
|
|
usage(stderr);
|
|
|
|
break;
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-27 13:56:09 +02:00
|
|
|
|
2011-12-08 16:10:18 +01:00
|
|
|
/* check for a single additional argument */
|
2012-03-27 13:56:09 +02:00
|
|
|
if ((argc - optind) > 1)
|
|
|
|
errx(EXIT_FAILURE, _("too many arguments"));
|
|
|
|
|
|
|
|
if ((argc - optind) == 1)
|
2012-02-02 17:58:25 +01:00
|
|
|
*device = xstrdup(argv[optind]);
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given name, such as foo, see if any of the following exist:
|
|
|
|
*
|
|
|
|
* foo (if foo starts with '.' or '/')
|
|
|
|
* /dev/foo
|
|
|
|
*
|
|
|
|
* If found, return the full path. If not found, return 0.
|
|
|
|
* Returns pointer to dynamically allocated string.
|
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static char *find_device(const char *name)
|
|
|
|
{
|
|
|
|
if ((*name == '.' || *name == '/') && access(name, F_OK) == 0)
|
|
|
|
return xstrdup(name);
|
|
|
|
else {
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "/dev/%s", name);
|
|
|
|
if (access(name, F_OK) == 0)
|
|
|
|
return xstrdup(buf);
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
2012-03-27 14:24:42 +02:00
|
|
|
return NULL;
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set or clear auto-eject mode. */
|
2012-03-27 14:24:42 +02:00
|
|
|
static void auto_eject(int fd, int on)
|
|
|
|
{
|
|
|
|
if (ioctl(fd, CDROMEJECT_SW, on) != 0)
|
|
|
|
err(EXIT_FAILURE, _("CD-ROM auto-eject command failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changer select. CDROM_SELECT_DISC is preferred, older kernels used
|
|
|
|
* CDROMLOADFROMSLOT.
|
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static void changer_select(int fd, int slot)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
#ifdef CDROM_SELECT_DISC
|
2012-03-27 14:24:42 +02:00
|
|
|
if (ioctl(fd, CDROM_SELECT_DISC, slot) < 0)
|
|
|
|
err(EXIT_FAILURE, _("CD-ROM select disc command failed"));
|
|
|
|
|
2011-12-08 16:10:18 +01:00
|
|
|
#elif defined CDROMLOADFROMSLOT
|
2012-03-27 14:24:42 +02:00
|
|
|
if (ioctl(fd, CDROMLOADFROMSLOT, slot) != 0)
|
|
|
|
err(EXIT_FAILURE, _("CD-ROM load from slot command failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
#else
|
2012-03-27 14:24:42 +02:00
|
|
|
warnx(_("IDE/ATAPI CD-ROM changer not supported by this kernel\n") );
|
2011-12-08 16:10:18 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close tray. Not supported by older kernels.
|
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static void close_tray(int fd)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
#ifdef CDROMCLOSETRAY
|
2012-03-27 14:24:42 +02:00
|
|
|
if (ioctl(fd, CDROMCLOSETRAY) != 0)
|
|
|
|
err(EXIT_FAILURE, _("CD-ROM tray close command failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
#else
|
2012-03-27 14:24:42 +02:00
|
|
|
warnx(_("CD-ROM tray close command not supported by this kernel\n"));
|
2011-12-08 16:10:18 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Toggle tray.
|
|
|
|
*
|
|
|
|
* Written by Benjamin Schwenk <benjaminschwenk@yahoo.de> and
|
|
|
|
* Sybren Stuvel <sybren@thirdtower.com>
|
|
|
|
*
|
|
|
|
* Not supported by older kernels because it might use
|
|
|
|
* CloseTray().
|
|
|
|
*
|
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static void toggle_tray(int fd)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
struct timeval time_start, time_stop;
|
|
|
|
int time_elapsed;
|
|
|
|
|
|
|
|
#ifdef CDROMCLOSETRAY
|
|
|
|
/* Try to open the CDROM tray and measure the time therefor
|
|
|
|
* needed. In my experience the function needs less than 0.05
|
|
|
|
* seconds if the tray was already open, and at least 1.5 seconds
|
|
|
|
* if it was closed. */
|
|
|
|
gettimeofday(&time_start, NULL);
|
|
|
|
|
|
|
|
/* Send the CDROMEJECT command to the device. */
|
2012-03-27 14:24:42 +02:00
|
|
|
if (ioctl(fd, CDROMEJECT, 0) < 0)
|
|
|
|
err(EXIT_FAILURE, _("CD-ROM eject command failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* Get the second timestamp, to measure the time needed to open
|
|
|
|
* the tray. */
|
|
|
|
gettimeofday(&time_stop, NULL);
|
|
|
|
|
|
|
|
time_elapsed = (time_stop.tv_sec * 1000000 + time_stop.tv_usec) -
|
|
|
|
(time_start.tv_sec * 1000000 + time_start.tv_usec);
|
|
|
|
|
|
|
|
/* If the tray "opened" too fast, we can be nearly sure, that it
|
|
|
|
* was already open. In this case, close it now. Else the tray was
|
|
|
|
* closed before. This would mean that we are done. */
|
|
|
|
if (time_elapsed < TRAY_WAS_ALREADY_OPEN_USECS)
|
2012-02-08 18:19:35 +01:00
|
|
|
close_tray(fd);
|
2011-12-08 16:10:18 +01:00
|
|
|
#else
|
2012-03-27 14:24:42 +02:00
|
|
|
warnx(_("CD-ROM tray toggle command not supported by this kernel"));
|
2011-12-08 16:10:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Select Speed of CD-ROM drive.
|
|
|
|
* Thanks to Roland Krivanek (krivanek@fmph.uniba.sk)
|
|
|
|
* http://dmpc.dbp.fmph.uniba.sk/~krivanek/cdrom_speed/
|
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static void select_speed(int fd, int speed)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
#ifdef CDROM_SELECT_SPEED
|
2012-03-27 14:24:42 +02:00
|
|
|
if (ioctl(fd, CDROM_SELECT_SPEED, speed) != 0)
|
|
|
|
err(EXIT_FAILURE, _("CD-ROM select speed command failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
#else
|
2012-03-27 14:24:42 +02:00
|
|
|
warnx(_("CD-ROM select speed command not supported by this kernel"));
|
2011-12-08 16:10:18 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Eject using CDROMEJECT ioctl. Return 1 if successful, 0 otherwise.
|
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static int eject_cdrom(int fd)
|
|
|
|
{
|
|
|
|
return ioctl(fd, CDROMEJECT) == 0;
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Eject using SCSI commands. Return 1 if successful, 0 otherwise.
|
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static int eject_scsi(int fd)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
struct sdata {
|
|
|
|
int inlen;
|
|
|
|
int outlen;
|
|
|
|
char cmd[256];
|
|
|
|
} scsi_cmd;
|
|
|
|
|
|
|
|
scsi_cmd.inlen = 0;
|
|
|
|
scsi_cmd.outlen = 0;
|
|
|
|
scsi_cmd.cmd[0] = ALLOW_MEDIUM_REMOVAL;
|
|
|
|
scsi_cmd.cmd[1] = 0;
|
|
|
|
scsi_cmd.cmd[2] = 0;
|
|
|
|
scsi_cmd.cmd[3] = 0;
|
|
|
|
scsi_cmd.cmd[4] = 0;
|
|
|
|
scsi_cmd.cmd[5] = 0;
|
2012-03-27 14:24:42 +02:00
|
|
|
if (ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd) != 0)
|
2011-12-08 16:10:18 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
scsi_cmd.inlen = 0;
|
|
|
|
scsi_cmd.outlen = 0;
|
|
|
|
scsi_cmd.cmd[0] = START_STOP;
|
|
|
|
scsi_cmd.cmd[1] = 0;
|
|
|
|
scsi_cmd.cmd[2] = 0;
|
|
|
|
scsi_cmd.cmd[3] = 0;
|
|
|
|
scsi_cmd.cmd[4] = 1;
|
|
|
|
scsi_cmd.cmd[5] = 0;
|
2012-03-27 14:24:42 +02:00
|
|
|
if (ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd) != 0)
|
2011-12-08 16:10:18 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
scsi_cmd.inlen = 0;
|
|
|
|
scsi_cmd.outlen = 0;
|
|
|
|
scsi_cmd.cmd[0] = START_STOP;
|
|
|
|
scsi_cmd.cmd[1] = 0;
|
|
|
|
scsi_cmd.cmd[2] = 0;
|
|
|
|
scsi_cmd.cmd[3] = 0;
|
|
|
|
scsi_cmd.cmd[4] = 2;
|
|
|
|
scsi_cmd.cmd[5] = 0;
|
2012-03-27 14:24:42 +02:00
|
|
|
if (ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd) != 0)
|
2011-12-08 16:10:18 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* force kernel to reread partition table when new disc inserted */
|
2012-03-27 14:24:42 +02:00
|
|
|
return ioctl(fd, BLKRRPART) == 0;
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Eject using FDEJECT ioctl. Return 1 if successful, 0 otherwise.
|
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static int eject_floppy(int fd)
|
|
|
|
{
|
|
|
|
return ioctl(fd, FDEJECT) == 0;
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-27 14:24:42 +02:00
|
|
|
* Rewind and eject using tape ioctl. Return 1 if successful, 0 otherwise.
|
2011-12-08 16:10:18 +01:00
|
|
|
*/
|
2012-03-27 14:24:42 +02:00
|
|
|
static int eject_tape(int fd)
|
|
|
|
{
|
|
|
|
struct mtop op = { .mt_op = MTOFFL, .mt_count = 0 };
|
2011-12-08 16:10:18 +01:00
|
|
|
|
2012-03-27 14:24:42 +02:00
|
|
|
return ioctl(fd, MTIOCTOP, &op) == 0;
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Unmount a device. */
|
2012-03-27 14:41:18 +02:00
|
|
|
static void unmount_one(const char *name)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
int status;
|
|
|
|
|
|
|
|
switch (fork()) {
|
2012-03-27 14:41:18 +02:00
|
|
|
case 0: /* child */
|
|
|
|
if (setgid(getgid()) < 0)
|
|
|
|
err(EXIT_FAILURE, _("cannot set group id"));
|
|
|
|
|
|
|
|
if (setuid(getuid()) < 0)
|
|
|
|
err(EXIT_FAILURE, _("eject: cannot set user id"));
|
|
|
|
|
|
|
|
if (p_option)
|
|
|
|
execl("/bin/umount", "/bin/umount", name, "-n", NULL);
|
|
|
|
else
|
|
|
|
execl("/bin/umount", "/bin/umount", name, NULL);
|
|
|
|
|
|
|
|
errx(EXIT_FAILURE, _("unable to exec /bin/umount of `%s'"), name);
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
warn( _("unable to fork"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* parent */
|
|
|
|
wait(&status);
|
|
|
|
if (WIFEXITED(status) == 0)
|
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
_("unmount of `%s' did not exit normally"), name);
|
|
|
|
|
|
|
|
if (WEXITSTATUS(status) != 0)
|
|
|
|
errx(EXIT_FAILURE, _("unmount of `%s' failed\n"), name);
|
|
|
|
break;
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Open a device file. */
|
2012-03-27 14:41:18 +02:00
|
|
|
static int open_device(const char *name)
|
|
|
|
{
|
|
|
|
int fd = open(name, O_RDONLY|O_NONBLOCK);
|
|
|
|
if (fd == -1)
|
|
|
|
errx(EXIT_FAILURE, _("%s: open failed"), name);
|
2011-12-08 16:10:18 +01:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get major and minor device numbers for a device file name, so we
|
|
|
|
* can check for duplicate devices.
|
|
|
|
*/
|
2012-03-27 14:49:59 +02:00
|
|
|
static int get_major_minor(const char *name, int *maj, int *min)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
struct stat sstat;
|
2012-03-27 14:49:59 +02:00
|
|
|
|
2011-12-08 16:10:18 +01:00
|
|
|
*maj = *min = -1;
|
|
|
|
if (stat(name, &sstat) == -1)
|
|
|
|
return -1;
|
2012-03-27 14:49:59 +02:00
|
|
|
if (!S_ISBLK(sstat.st_mode))
|
2011-12-08 16:10:18 +01:00
|
|
|
return -1;
|
|
|
|
*maj = major(sstat.st_rdev);
|
|
|
|
*min = minor(sstat.st_rdev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if device has been mounted by looking in mount table. If so, set
|
|
|
|
* device name and mount point name, and return 1, otherwise return 0.
|
2012-03-27 14:49:59 +02:00
|
|
|
*
|
|
|
|
* TODO: use libmount here
|
2011-12-08 16:10:18 +01:00
|
|
|
*/
|
2012-03-27 14:49:59 +02:00
|
|
|
static int mounted_device(const char *name, char **mountName, char **deviceName)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
FILE *fp;
|
2012-03-27 14:49:59 +02:00
|
|
|
const char *fname;
|
2011-12-08 16:10:18 +01:00
|
|
|
char line[1024];
|
|
|
|
char s1[1024];
|
|
|
|
char s2[1024];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
int maj;
|
|
|
|
int min;
|
|
|
|
|
2012-02-08 18:19:35 +01:00
|
|
|
get_major_minor(name, &maj, &min);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
2012-03-27 14:49:59 +02:00
|
|
|
fname = p_option ? "/proc/mounts" : "/etc/mtab";
|
2012-03-27 14:41:18 +02:00
|
|
|
|
2012-03-27 14:49:59 +02:00
|
|
|
fp = fopen(fname, "r");
|
|
|
|
if (!fp)
|
|
|
|
err(EXIT_FAILURE, _("%s: open failed"), fname);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), fp) != 0) {
|
|
|
|
rc = sscanf(line, "%1023s %1023s", s1, s2);
|
|
|
|
if (rc >= 2) {
|
|
|
|
int mtabmaj, mtabmin;
|
2012-02-08 18:19:35 +01:00
|
|
|
get_major_minor(s1, &mtabmaj, &mtabmin);
|
2011-12-08 16:10:18 +01:00
|
|
|
if (((strcmp(s1, name) == 0) || (strcmp(s2, name) == 0)) ||
|
|
|
|
((maj != -1) && (maj == mtabmaj) && (min == mtabmin))) {
|
2012-03-27 14:05:56 +02:00
|
|
|
fclose(fp);
|
2012-03-27 14:49:59 +02:00
|
|
|
*deviceName = xstrdup(s1);
|
|
|
|
*mountName = xstrdup(s2);
|
2011-12-08 16:10:18 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*deviceName = 0;
|
|
|
|
*mountName = 0;
|
2012-03-27 14:05:56 +02:00
|
|
|
fclose(fp);
|
2011-12-08 16:10:18 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Step through mount table and unmount all devices that match a regular
|
|
|
|
* expression.
|
2012-03-27 14:49:59 +02:00
|
|
|
*
|
|
|
|
* TODO: replace obscure regex voodoo with /sys scan
|
2011-12-08 16:10:18 +01:00
|
|
|
*/
|
2012-03-27 14:49:59 +02:00
|
|
|
static void unmount_devices(const char *pattern)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
regex_t preg;
|
|
|
|
FILE *fp;
|
2012-03-27 14:49:59 +02:00
|
|
|
const char *fname;
|
2011-12-08 16:10:18 +01:00
|
|
|
char line[1024];
|
|
|
|
|
2012-03-27 14:49:59 +02:00
|
|
|
if (regcomp(&preg, pattern, REG_EXTENDED) != 0)
|
|
|
|
err(EXIT_FAILURE, _("regcomp failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
|
2012-03-27 14:49:59 +02:00
|
|
|
fname = p_option ? "/proc/mounts" : "/etc/mtab";
|
|
|
|
fp = fopen(fname, "r");
|
|
|
|
if (!fp)
|
|
|
|
err(EXIT_FAILURE, _("%s: open failed"), fname);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), fp) != 0) {
|
2012-03-27 14:49:59 +02:00
|
|
|
char s1[1024];
|
|
|
|
char s2[1024];
|
|
|
|
|
|
|
|
int status = sscanf(line, "%1023s %1023s", s1, s2);
|
2011-12-08 16:10:18 +01:00
|
|
|
if (status >= 2) {
|
|
|
|
status = regexec(&preg, s1, 0, 0, 0);
|
|
|
|
if (status == 0) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: unmounting"), s1);
|
2012-03-27 14:41:18 +02:00
|
|
|
unmount_one(s1);
|
2011-12-08 16:10:18 +01:00
|
|
|
regfree(&preg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-27 14:05:56 +02:00
|
|
|
fclose(fp);
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a name, see if it matches a pattern for a device that can have
|
|
|
|
* multiple partitions. If so, return a regular expression that matches
|
|
|
|
* partitions for that device, otherwise return 0.
|
|
|
|
*/
|
2012-03-27 14:53:37 +02:00
|
|
|
static char *multiple_partitions(const char *name)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
int i = 0;
|
|
|
|
int status;
|
|
|
|
regex_t preg;
|
|
|
|
char pattern[256];
|
|
|
|
char *result = 0;
|
|
|
|
|
2012-02-08 18:19:35 +01:00
|
|
|
for (i = 0; partition_device[i] != 0; i++) {
|
2011-12-08 16:10:18 +01:00
|
|
|
/* look for ^/dev/foo[a-z]([0-9]?[0-9])?$, e.g. /dev/hda1 */
|
|
|
|
strcpy(pattern, "^/dev/");
|
2012-02-08 18:19:35 +01:00
|
|
|
strcat(pattern, partition_device[i]);
|
2011-12-08 16:10:18 +01:00
|
|
|
strcat(pattern, "[a-z]([0-9]?[0-9])?$");
|
|
|
|
regcomp(&preg, pattern, REG_EXTENDED|REG_NOSUB);
|
|
|
|
status = regexec(&preg, name, 1, 0, 0);
|
|
|
|
regfree(&preg);
|
|
|
|
if (status == 0) {
|
2012-03-27 14:59:01 +02:00
|
|
|
result = xmalloc(strlen(name) + 25);
|
2011-12-08 16:10:18 +01:00
|
|
|
strcpy(result, name);
|
2012-02-08 18:19:35 +01:00
|
|
|
result[strlen(partition_device[i]) + 6] = 0;
|
2011-12-08 16:10:18 +01:00
|
|
|
strcat(result, "([0-9]?[0-9])?$");
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: multipartition device"), name);
|
2011-12-08 16:10:18 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: not a multipartition device"), name);
|
2011-12-08 16:10:18 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* handle -x option */
|
2012-03-27 14:53:37 +02:00
|
|
|
void set_device_speed(char *name)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2012-03-27 16:00:46 +02:00
|
|
|
if (!x_option)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x_arg == 0)
|
|
|
|
verbose(_("setting CD-ROM speed to auto"));
|
|
|
|
else
|
|
|
|
verbose(_("setting CD-ROM speed to %ldX"), x_arg);
|
|
|
|
|
|
|
|
fd = open_device(name);
|
|
|
|
select_speed(fd, x_arg);
|
|
|
|
exit(EXIT_SUCCESS);
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* main program */
|
2012-03-27 15:01:29 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2011-12-08 16:10:18 +01:00
|
|
|
int worked = 0; /* set to 1 when successfully ejected */
|
|
|
|
char *device = 0; /* name passed from user */
|
|
|
|
char *fullName; /* expanded name */
|
|
|
|
char *deviceName; /* name of device */
|
|
|
|
char *linkName; /* name of device's symbolic link */
|
|
|
|
char *mountName; /* name of device's mount point */
|
2012-01-18 14:19:42 +01:00
|
|
|
int fd; /* file descriptor for device */
|
2011-12-08 16:10:18 +01:00
|
|
|
int mounted = 0; /* true if device is mounted */
|
2012-01-18 14:19:42 +01:00
|
|
|
char *pattern; /* regex for device if multiple partitions */
|
|
|
|
int ld = 6; /* symbolic link max depth */
|
2011-12-08 16:10:18 +01:00
|
|
|
|
2012-01-17 18:23:40 +01:00
|
|
|
setlocale(LC_ALL,"");
|
2012-03-27 13:35:06 +02:00
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* parse the command line arguments */
|
|
|
|
parse_args(argc, argv, &device);
|
|
|
|
|
|
|
|
|
|
|
|
/* handle -d option */
|
|
|
|
if (d_option) {
|
2012-03-27 16:00:46 +02:00
|
|
|
info(_("default device: `%s'"), EJECT_DEFAULT_DEVICE);
|
2011-12-08 16:10:18 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no device, use default */
|
|
|
|
if (device == 0) {
|
2012-03-27 15:01:29 +02:00
|
|
|
device = xstrdup(EJECT_DEFAULT_DEVICE);
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("using default device `%s'"), device);
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Strip any trailing slash from name in case user used bash/tcsh
|
|
|
|
style filename completion (e.g. /mnt/cdrom/) */
|
|
|
|
if (device[strlen(device)-1] == '/')
|
|
|
|
device[strlen(device)-1] = 0;
|
|
|
|
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("device name is `%s'"), device);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* figure out full device or mount point name */
|
2012-02-08 13:33:57 +01:00
|
|
|
fullName = find_device(device);
|
2012-03-27 16:00:46 +02:00
|
|
|
if (fullName == 0)
|
|
|
|
errx(EXIT_FAILURE, _("%s: unable to find device"), device);
|
|
|
|
|
|
|
|
verbose(_("expanded name is `%s'"), fullName);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* check for a symbolic link */
|
2012-02-08 16:01:51 +01:00
|
|
|
while ((linkName = canonicalize_path(fullName)) && (ld > 0)) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("`%s' is a link to `%s'"), fullName, linkName);
|
2011-12-08 16:10:18 +01:00
|
|
|
free(fullName);
|
2012-03-27 14:59:01 +02:00
|
|
|
fullName = xstrdup(linkName);
|
2011-12-08 16:10:18 +01:00
|
|
|
free(linkName);
|
|
|
|
linkName = 0;
|
|
|
|
ld--;
|
|
|
|
}
|
|
|
|
/* handle max depth exceeded option */
|
2012-03-27 16:00:46 +02:00
|
|
|
if (ld <= 0)
|
|
|
|
errx(EXIT_FAILURE, _("maximum symbolic link depth exceeded: `%s'"), fullName);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* if mount point, get device name */
|
2012-02-08 18:19:35 +01:00
|
|
|
mounted = mounted_device(fullName, &mountName, &deviceName);
|
2012-03-27 16:00:46 +02:00
|
|
|
if (mounted)
|
|
|
|
verbose(_("`%s' is mounted at `%s'"), deviceName, mountName);
|
|
|
|
else
|
|
|
|
verbose(_("`%s' is not mounted\n"), fullName);
|
|
|
|
|
2011-12-08 16:10:18 +01:00
|
|
|
if (!mounted) {
|
2012-03-27 14:59:01 +02:00
|
|
|
deviceName = xstrdup(fullName);
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* handle -n option */
|
|
|
|
if (n_option) {
|
2012-03-27 16:00:46 +02:00
|
|
|
info(_("device is `%s'"), deviceName);
|
|
|
|
verbose(_("exiting due to -n/--noop option"));
|
2011-12-08 16:10:18 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle -a option */
|
|
|
|
if (a_option) {
|
2012-03-27 16:00:46 +02:00
|
|
|
if (a_arg)
|
|
|
|
verbose(_("%s: enabling auto-eject mode"), deviceName);
|
|
|
|
else
|
|
|
|
verbose(_("%s: disabling auto-eject mode"), deviceName);
|
2012-02-08 18:19:35 +01:00
|
|
|
fd = open_device(deviceName);
|
|
|
|
auto_eject(fd, a_arg);
|
2011-12-08 16:10:18 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle -t option */
|
|
|
|
if (t_option) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: closing tray"), deviceName);
|
2012-02-08 18:19:35 +01:00
|
|
|
fd = open_device(deviceName);
|
|
|
|
close_tray(fd);
|
2012-03-27 14:53:37 +02:00
|
|
|
set_device_speed(deviceName);
|
2011-12-08 16:10:18 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle -T option */
|
|
|
|
if (T_option) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: toggling tray"), deviceName);
|
2012-02-08 18:19:35 +01:00
|
|
|
fd = open_device(deviceName);
|
|
|
|
toggle_tray(fd);
|
2012-03-27 14:53:37 +02:00
|
|
|
set_device_speed(deviceName);
|
2011-12-08 16:10:18 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle -x option only */
|
2012-03-27 14:53:37 +02:00
|
|
|
if (!c_option)
|
|
|
|
set_device_speed(deviceName);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* unmount device if mounted */
|
|
|
|
if ((m_option != 1) && mounted) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: unmounting"), deviceName);
|
2012-03-27 14:41:18 +02:00
|
|
|
unmount_one(deviceName);
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if it is a multipartition device, unmount any other partitions on
|
|
|
|
the device */
|
2012-02-08 18:19:35 +01:00
|
|
|
pattern = multiple_partitions(deviceName);
|
2011-12-08 16:10:18 +01:00
|
|
|
if ((m_option != 1) && (pattern != 0))
|
2012-02-08 18:19:35 +01:00
|
|
|
unmount_devices(pattern);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* handle -c option */
|
|
|
|
if (c_option) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: selecting CD-ROM disc #%ld\n"), deviceName, c_arg);
|
2012-02-08 18:19:35 +01:00
|
|
|
fd = open_device(deviceName);
|
|
|
|
changer_select(fd, c_arg);
|
2012-03-27 14:53:37 +02:00
|
|
|
set_device_speed(deviceName);
|
2011-12-08 16:10:18 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if user did not specify type of eject, try all four methods */
|
|
|
|
if ((r_option + s_option + f_option + q_option) == 0) {
|
|
|
|
r_option = s_option = f_option = q_option = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open device */
|
2012-02-08 18:19:35 +01:00
|
|
|
fd = open_device(deviceName);
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* try various methods of ejecting until it works */
|
|
|
|
if (r_option) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: trying to eject using CD-ROM eject command"), deviceName);
|
2012-02-08 18:19:35 +01:00
|
|
|
worked = eject_cdrom(fd);
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(worked ? _("CD-ROM eject command succeeded") :
|
|
|
|
_("CD-ROM eject command failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s_option && !worked) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: trying to eject using SCSI commands"), deviceName);
|
2012-02-08 18:19:35 +01:00
|
|
|
worked = eject_scsi(fd);
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(worked ? _("SCSI eject succeeded") :
|
|
|
|
_("SCSI eject failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (f_option && !worked) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: trying to eject using floppy eject command"), deviceName);
|
2012-02-08 18:19:35 +01:00
|
|
|
worked = eject_floppy(fd);
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(worked ? _("floppy eject command succeeded") :
|
|
|
|
_("floppy eject command failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (q_option && !worked) {
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(_("%s: trying to eject using tape offline command"), deviceName);
|
2012-02-08 18:19:35 +01:00
|
|
|
worked = eject_tape(fd);
|
2012-03-27 16:00:46 +02:00
|
|
|
verbose(worked ? _("tape offline command succeeded") :
|
|
|
|
_("tape offline command failed"));
|
2011-12-08 16:10:18 +01:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:00:46 +02:00
|
|
|
if (!worked)
|
|
|
|
errx(EXIT_FAILURE, _("unable to eject"));
|
2011-12-08 16:10:18 +01:00
|
|
|
|
|
|
|
/* cleanup */
|
2012-03-27 14:05:56 +02:00
|
|
|
close(fd);
|
2011-12-08 16:10:18 +01:00
|
|
|
free(device);
|
|
|
|
free(deviceName);
|
|
|
|
free(fullName);
|
|
|
|
free(linkName);
|
|
|
|
free(mountName);
|
|
|
|
free(pattern);
|
|
|
|
exit(0);
|
|
|
|
}
|