Date: Sun, 14 May 2006 19:47:18 +0200 From: Ulrich Spoerlein <spoerlein@informatik.uni-wuerzburg.de> To: current@freebsd.org Subject: cdcontrol -f /cdrom eject Message-ID: <20060514174718.GA4496@roadrunner.informatik.uni-wuerzburg.de>
next in thread | raw e-mail | index | archive | help
--BwCQnh7xodEAoBMC Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello everybody, I tried to make 'cdcontrol -f /mountpoint eject' work, but I found something strange while implementing it. First of all, cdcontrol will eject the media, even if it is currently mounted. Shouldn't mount lock the media, and only unmount unlock it? To reproduce % mount /cdrom % mount|grep acd0 % cdcontrol -f /dev/acd0 eject # works % mount|grep acd0 # still mounted Attached is a patch that will umount the given mount-point first, then eject the media. I wonder why the CDIOCALLOW is necessary even if the media was not previously mounted. It only seems to make a difference with cd(4), acd(4) will eject the media even without the CDIOCALLOW call. Very strange (at least to me), or it might be bad atapicam-mojo that's interfering. Anyway, comments are appreciated! Ulrich Spoerlein --=20 PGP Key ID: 20FEE9DD Encrypted mail welcome! Fingerprint: AEC9 AF5E 01AC 4EE1 8F70 6CBD E76E 2227 20FE E9DD Which is worse: ignorance or apathy? Don't know. Don't care. --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=patch Content-Transfer-Encoding: quoted-printable --- cdcontrol.c.orig Sun May 14 19:46:39 2006 +++ cdcontrol.c Sun May 14 19:46:24 2006 @@ -26,10 +26,14 @@ #include <sys/file.h> #include <sys/ioctl.h> #include <sys/param.h> +#include <sys/mount.h> +#include <sys/stat.h> +#include <sys/types.h> #include <arpa/inet.h> #include <ctype.h> #include <err.h> #include <errno.h> +#include <fcntl.h> #include <histedit.h> #include <limits.h> #include <paths.h> @@ -167,7 +171,7 @@ =20 void usage () { - fprintf (stderr, "usage: cdcontrol [-sv] [-f device] [command ...]\n"); + fprintf (stderr, "usage: cdcontrol [-sv] [-f device|mountpoint] [command = =2E..]\n"); exit (1); } =20 @@ -271,6 +275,8 @@ { long speed; int l, r, rc; + struct stat sb; + struct statfs sfsb; =20 switch (cmd) { =20 @@ -353,6 +359,23 @@ return (0); =20 case CMD_EJECT: + if (stat(cdname, &sb) !=3D 0) + warn("stat failed, %s", cdname); + /* Unmount first, if directory */ + else if (S_ISDIR(sb.st_mode)) { + if (statfs(cdname, &sfsb) !=3D 0) + warn("statfs failed, %s", cdname); + else { + if (strncmp(cdname, sfsb.f_mntonname, MAXPATHLEN) !=3D 0) + warnx("device %s and mountpoint %s differ", + cdname, sfsb.f_mntonname); + if (unmount(cdname, 0) !=3D 0) + warn("umount of %s failed", cdname); + else + cdname =3D sfsb.f_mntfromname; + } + } + if (fd < 0 && ! open_cd ()) return (0); =20 --LQksG6bCIzRHxTLp-- --BwCQnh7xodEAoBMC Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (FreeBSD) iD8DBQFEZ20l524iJyD+6d0RAnc5AJwJ8K6xh/LyOnrvC+gHw2oY/Vy+2QCdH98i xdhNTbklg3DgJDmDJDRJfsw= =X/yA -----END PGP SIGNATURE----- --BwCQnh7xodEAoBMC--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060514174718.GA4496>