Package: eject
Version: 2.0.13deb-13
Severity: important
Tags: patch
The attached patch allows eject to build (and work) on GNU/kFreeBSD.
Please could you forward it to upstream?
-- System Information:
Debian Release: testing/unstable
Architecture: kfreebsd-i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: GNU/kFreeBSD 5.3-1
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ANSI_X3.4-1968) (ignored: LC_ALL
set to C)
Versions of packages eject depends on:
ii libc0.1 2.3-1+kbsd.11 GNU C Library: Shared libraries an
eject recommends no packages.
-- no debconf information
diff -u eject-2.0.13deb/eject.c eject-2.0.13deb/eject.c
--- eject-2.0.13deb/eject.c
+++ eject-2.0.13deb/eject.c
@@ -36,12 +36,6 @@
#error DEFAULTDEVICE not set, check Makefile
#endif
-#include <linux/version.h>
-/* handy macro found in 2.1 kernels, but not in older ones */
-#ifndef KERNEL_VERSION
-#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
-#endif
-
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
@@ -59,17 +53,33 @@
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sys/mtio.h>
+#include <sys/mount.h>
+
+#if defined(__linux__)
+#include <linux/version.h>
+/* handy macro found in 2.1 kernels, but not in older ones */
+#ifndef KERNEL_VERSION
+#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
+#endif
#include <linux/types.h>
#include <linux/cdrom.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
#include <linux/ucdrom.h>
#endif
#include <linux/fd.h>
-#include <sys/mount.h>
#include <scsi/scsi.h>
#include <scsi/sg.h>
#include <scsi/scsi_ioctl.h>
+#define HAVE_EJECT_SCSI
+#define HAVE_EJECT_FLOPPY
+#define HAVE_EJECT_TAPE
+
+#elif defined(__FreeBSD_kernel__)
+#include <sys/cdio.h>
+#endif
+
+
#define CLOSE(fd) if (close(fd)==-1) { \
perror(programName); \
exit(1); \
@@ -137,9 +147,15 @@
" -v\t-- enable verbose output\n"
" -n\t-- don't eject, just show device found\n"
" -r\t-- eject CD-ROM\n"
+#ifdef HAVE_EJECT_SCSI
" -s\t-- eject SCSI device\n"
+#endif
+#ifdef HAVE_EJECT_FLOPPY
" -f\t-- eject floppy\n"
+#endif
+#ifdef HAVE_EJECT_TAPE
" -q\t-- eject tape\n"
+#endif
" -p\t-- use /proc/mounts instead of /etc/mtab\n"
" -m\t-- do not unmount device even if it is mounted\n"
)
@@ -149,8 +165,18 @@
"Long options:\n"
" -h --help -v --verbose -d --default\n"
" -a --auto -c --changerslot -t --trayclose -x --cdspeed\n"
-" -r --cdrom -s --scsi -f --floppy\n"
-" -q --tape -n --noop -V --version\n"
+" -r --cdrom"
+#ifdef HAVE_EJECT_SCSI
+" -s --scsi"
+#endif
+#ifdef HAVE_EJECT_FLOPPY
+" -f --floppy"
+#endif
+#ifdef HAVE_EJECT_TAPE
+" -q --tape"
+#endif
+"\n"
+"-n --noop -V --version\n"
" -p --proc -m --no-unmount\n"));
#endif /* GETOPTLONG */
fprintf(stderr,_(
@@ -404,9 +430,13 @@
/* Set or clear auto-eject mode. */
static void AutoEject(int fd, int onOff)
{
- int status;
+ int status = -1;
+#ifdef CDROMEJECT_SW
status = ioctl(fd, CDROMEJECT_SW, onOff);
+#else
+ errno = ENOSYS;
+#endif
if (status != 0) {
fprintf(stderr, _("%s: CD-ROM auto-eject command failed: %s\n"), programName, strerror(errno));
exit(1);
@@ -447,8 +477,12 @@
{
int status;
-#ifdef CDROMCLOSETRAY
+#if defined(CDROMCLOSETRAY) || defined(CDIOCCLOSE)
+#if defined(CDROMCLOSETRAY)
status = ioctl(fd, CDROMCLOSETRAY);
+#elif defined(CDIOCCLOSE)
+ status = ioctl(fd, CDIOCCLOSE);
+#endif
if (status != 0) {
fprintf(stderr, _("%s: CD-ROM tray close command failed: %s\n"), programName, strerror(errno));
exit(1);
@@ -485,12 +519,21 @@
*/
static int EjectCdrom(int fd)
{
- int status;
+ int status = -1;
+#if defined(CDROMEJECT)
status = ioctl(fd, CDROMEJECT);
+#elif defined(CDIOCEJECT)
+ status = ioctl(fd, CDIOCEJECT);
+#else
+/* Some kernels implement cdrom-eject only, but I don't think any kernel in the
+ world would implement eject only for non-cdrom drives. Let's die. */
+# error
+#endif
return (status == 0);
}
+#ifdef HAVE_EJECT_SCSI
/*
* Eject using SCSI SG_IO commands. Return 1 if successful, 0 otherwise.
*/
@@ -538,8 +581,10 @@
status = ioctl(fd, BLKRRPART);
return 1;
}
+#endif
+#ifdef HAVE_EJECT_FLOPPY
/*
* Eject using FDEJECT ioctl. Return 1 if successful, 0 otherwise.
*/
@@ -550,8 +595,10 @@
status = ioctl(fd, FDEJECT);
return (status >= 0);
}
+#endif
+#ifdef HAVE_EJECT_TAPE
/*
* Eject using tape ioctl. Return 1 if successful, 0 otherwise.
*/
@@ -565,6 +612,7 @@
status = ioctl(fd, MTIOCTOP, &op);
return (status >= 0);
}
+#endif
/* Unmount a device. */
@@ -576,10 +624,10 @@
case 0: /* child */
setuid(getuid()); /* reduce likelyhood of security holes when running setuid */
if(p_option)
- execl("/bin/umount", "/bin/umount", fullName, "-n", NULL);
+ execlp("umount", "umount", fullName, "-n", NULL);
else
- execl("/bin/umount", "/bin/umount", fullName, NULL);
- fprintf(stderr, _("%s: unable to exec /bin/umount of `%s': %s\n"),
+ execlp("umount", "umount", fullName, NULL);
+ fprintf(stderr, _("%s: unable to exec umount of `%s': %s\n"),
programName, fullName, strerror(errno));
exit(1);
break;
@@ -624,7 +672,7 @@
if (min) *min = -1;
if (stat(name, &sstat) == -1)
return -1;
- if (! S_ISBLK(sstat.st_mode))
+ if (! S_ISBLK(sstat.st_mode) && ! S_ISCHR(sstat.st_mode))
return -1;
if (maj) *maj = major(sstat.st_rdev);
if (min) *min = minor(sstat.st_rdev);
@@ -1042,6 +1090,7 @@
}
}
+#ifdef HAVE_EJECT_SCSI
if (s_option && !worked) {
if (v_option)
printf(_("%s: trying to eject `%s' using SCSI commands\n"), programName, deviceName);
@@ -1053,7 +1102,9 @@
printf(_("%s: SCSI eject failed\n"), programName);
}
}
+#endif
+#ifdef HAVE_EJECT_FLOPPY
if (f_option && !worked) {
if (v_option)
printf(_("%s: trying to eject `%s' using floppy eject command\n"), programName, deviceName);
@@ -1065,7 +1116,9 @@
printf(_("%s: floppy eject command failed\n"), programName);
}
}
+#endif
+#ifdef HAVE_EJECT_TAPE
if (q_option && !worked) {
if (v_option)
printf(_("%s: trying to eject `%s' using tape offline command\n"), programName, deviceName);
@@ -1077,6 +1130,7 @@
printf(_("%s: tape offline command failed\n"), programName);
}
}
+#endif
if (!worked) {
fprintf(stderr, _("%s: unable to eject, last error: %s\n"), programName, strerror(errno));
diff -u eject-2.0.13deb/debian/rules eject-2.0.13deb/debian/rules
--- eject-2.0.13deb/debian/rules
+++ eject-2.0.13deb/debian/rules
@@ -17,13 +17,21 @@
CFLAGS += -Os -fomit-frame-pointer
endif
+DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
+DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+ifeq ($(DEB_HOST_ARCH_OS), kfreebsd)
+cdrom = --enable-default-device=acd0
+endif
+
deb_dir = debian/eject
udeb_dir = debian/eject-udeb
build_dirs = $(deb_dir) $(udeb_dir)
build:
dh_testdir
- ./configure --prefix=/usr
+ ./configure --prefix=/usr --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) $(cdrom)
$(MAKE) AM_CFLAGS= CFLAGS="$(CFLAGS)"
touch build