1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-10-18 19:49:40 +00:00

- Fix eject when media is mounted (unmount it)

- Add eject by mount point
- Add -t flag for closing tray
- While here, portlint, DOCSDIR, PLIST_FILES

PR:		ports/62201
Submitted by:	Przemek Laczynski <torindel@wp.pl>
This commit is contained in:
Pav Lucistnik 2004-02-01 17:02:40 +00:00
parent 0ad06bd111
commit c3ab96401b
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=99718
4 changed files with 127 additions and 24 deletions

View File

@ -16,18 +16,18 @@ MASTER_SITES= ftp://ports.jp.FreeBSD.org/pub/FreeBSD-jp/OD/ \
MAINTAINER= ports@FreeBSD.org
COMMENT= Utility for ejecting media from CD or optical disk drive
DOCDIR= share/doc/eject
PLIST_SUB= DOCDIR=${DOCDIR}
PLIST_FILES= sbin/eject
PORTDOCS= README README-J
MAN1= eject.1
MANCOMPRESSED= yes
post-install:
@if [ ! -d ${PREFIX}/${DOCDIR} ] ; then \
${MKDIR} ${PREFIX}/${DOCDIR} ; \
fi
@for i in README README-J ; do \
${INSTALL_DATA} ${WRKSRC}/$${i} ${PREFIX}/${DOCDIR} ; \
done
.if !defined(NOPORTDOCS)
${MKDIR} ${DOCSDIR}
.for i in ${PORTDOCS}
${INSTALL_DATA} ${WRKSRC}/${i} ${DOCSDIR}
.endfor
.endif
.include <bsd.port.mk>

View File

@ -1,5 +1,5 @@
--- eject.c.orig Tue Jan 4 09:42:12 2000
+++ eject.c Wed Dec 24 01:11:34 2003
--- eject.c.orig Tue Jan 4 15:42:12 2000
+++ eject.c Sun Feb 1 17:59:10 2004
@@ -43,8 +43,8 @@
extern int optind;
@ -11,7 +11,15 @@
int eject(char *, char *);
char *program = "eject";
@@ -65,8 +65,8 @@
@@ -52,6 +52,7 @@
int fflag; /* force unmount filesystem */
int nflag; /* not execute operation */
int vflag; /* verbose operation */
+int tflag; /* tray close */
/*
* simple eject program
@@ -65,14 +66,14 @@
{
int ch;
int sts;
@ -21,8 +29,26 @@
+ char *err;
char *defdev;
fflag = nflag = vflag = 0;
@@ -95,18 +95,28 @@
- fflag = nflag = vflag = 0;
+ fflag = nflag = vflag = tflag = 0;
defdev = getenv("EJECT");
- while ((ch = getopt(argc, argv, "fnv?")) != EOF) {
+ while ((ch = getopt(argc, argv, "fnvt?")) != EOF) {
switch (ch) {
case 'f' :
fflag = 1;
@@ -83,6 +84,9 @@
case 'v' :
vflag = 1;
break;
+ case 't' :
+ tflag = 1;
+ break;
case '?' :
default :
usage();
@@ -95,18 +99,51 @@
if (argc == 0) {
usage();
}
@ -41,12 +67,35 @@
+ } else {
+ int c;
+ char *dev_bak = malloc(MAXPATHLEN);
+ if ((c = readlink(device, dev_bak, MAXPATHLEN-1)) != -1) {
+ free(name);
+ if ((c = readlink(device, dev_bak, MAXPATHLEN))>0) {
+ dev_bak[c] = '\0';
+ free(name);
+ name = dev_bak;
+ } else {
+ free(dev_bak);
+ name = device;
+ }
+ if (strncmp(device, "/dev/", 5) != 0)
+ {
+ int mnts;
+ struct statfs *mntbuf;
+ mnts = getmntinfo(&mntbuf, MNT_NOWAIT);
+ if (mnts == 0) {
+ perror(program);
+ exit(1);
+ }
+ for (ch = 0; ch < mnts; ch++) {
+ if (strcmp(mntbuf[ch].f_mntonname, name) == 0) {
+ device = strdup(mntbuf[ch].f_mntfromname);
+ name = strdup(mntbuf[ch].f_mntfromname);
+ break;
+ }
+ }
+ if (strncmp(device, "/dev/", 5) != 0)
+ {
+ perror(program);
+ exit(1);
+ }
+ }
}
@ -55,7 +104,7 @@
if (sts < 0) {
perror(err);
exit(1);
@@ -128,16 +138,26 @@
@@ -128,16 +165,26 @@
int
check_device(name, device)
char *name;
@ -69,8 +118,8 @@
- sprintf(device, "/dev/r%sc", name);
- if (vflag || nflag) {
- printf("%s: using device %s\n", program, device);
+ const char* dev_list[] = { "/dev/%sc", "/dev/%s", "%s", NULL };
+ for (i = 0; dev_list[i]; i++) {
+ const char* dev_list[] = { "/dev/%sc", "/dev/%s", "%s" };
+ for (i = 0; i < 3; i++) {
+ if ((sts = asprintf(device, dev_list[i], name)) == -1)
+ return sts;
+ if (vflag || nflag) {
@ -88,7 +137,7 @@
return sts;
}
@@ -155,7 +175,7 @@
@@ -155,7 +202,7 @@
int
unmount_fs(name, err)
char *name;
@ -97,7 +146,16 @@
{
int mnts;
struct statfs *mntbuf;
@@ -221,7 +241,7 @@
@@ -173,7 +220,7 @@
/* get proper mount information into the list */
len = strlen(name);
for (n = 0; n < mnts; n++) {
- p = rindex(mntbuf[n].f_mntfromname, '/');
+ p = mntbuf[n].f_mntfromname - 1;
if (p == NULL) {
continue;
}
@@ -221,7 +268,7 @@
sts = 0;
}
if (sts < 0 && fflag == 0) {
@ -106,3 +164,41 @@
return sts;
}
nextp = mp->next;
@@ -255,14 +302,26 @@
}
if (!nflag) {
if (vflag) {
- printf("%s: ejecting media from %s\n", program, name);
+ if (tflag) {
+ printf("%s: tray close on %s\n", program, name);
+ } else {
+ printf("%s: ejecting media from %s\n", program, name);
+ }
}
sts = ioctl(fd, CDIOCALLOW);
if (sts >= 0) {
- sts = ioctl(fd, CDIOCEJECT);
+ if (tflag) {
+ sts = ioctl(fd, CDIOCCLOSE);
+ } else {
+ sts = ioctl(fd, CDIOCEJECT);
+ }
}
} else {
- printf("%s: ejecting media from %s\n", program, name);
+ if (tflag) {
+ printf("%s: tray close on %s\n", program, name);
+ } else {
+ printf("%s: ejecting media from %s\n", program, name);
+ }
sts = 0;
}
close(fd);
@@ -277,6 +336,6 @@
void
usage(void)
{
- fprintf(stderr, "usage: %s [-fnv] device\n", program);
+ fprintf(stderr, "usage: %s [-fnvt] device\n", program);
exit(1);
}

View File

@ -0,0 +1,11 @@
--- eject.1.orig Tue Jan 4 14:49:41 2000
+++ eject.1 Sun Feb 1 00:49:17 2004
@@ -53,6 +53,8 @@
Not execute operation but print it.
.It Fl v
Verbose mode.
+.It Fl t
+Give drive tray close command.
.Sh ENVIRONMENT
If the following environment variable exists, it is used by
.Nm eject :

View File

@ -1,4 +0,0 @@
sbin/eject
%%DOCDIR%%/README
%%DOCDIR%%/README-J
@dirrm %%DOCDIR%%