rpms/eject/devel eject-2.1.5-umount.patch, NONE, 1.1 eject.spec, 1.32, 1.33
Zdenek Prikryl (zprikryl)
fedora-extras-commits at redhat.com
Wed Mar 12 11:57:44 UTC 2008
Author: zprikryl
Update of /cvs/extras/rpms/eject/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv16900
Modified Files:
eject.spec
Added Files:
eject-2.1.5-umount.patch
Log Message:
Added check for a removable flag
Resolves: #432187
eject-2.1.5-umount.patch:
--- NEW FILE eject-2.1.5-umount.patch ---
--- eject/eject.c.umount 2008-03-12 11:25:55.000000000 +0100
+++ eject/eject.c 2008-03-12 11:47:24.000000000 +0100
@@ -30,6 +30,8 @@
*
*/
+#define _ATFILE_SOURCE
+
#include "i18n.h"
#ifndef DEFAULTDEVICE
@@ -42,6 +44,7 @@
#include <string.h>
#include <fcntl.h>
#include <limits.h>
+#include <dirent.h>
#ifdef GETOPTLONG
#include <getopt.h>
@@ -1127,6 +1130,69 @@ static char *MultiplePartitions(const ch
return 0;
}
+/*
+ * Find device name with the given major and minor number. Returns NULL if not
+ * found. The returned pointer must be free()'d.
+ */
+static char* FindDeviceMajorMinor(int maj, int min)
+{
+ DIR *dir = opendir("/dev");
+ struct dirent *d;
+ int dfd = dirfd(dir);
+ struct stat st;
+ char *device;
+
+ if (!dir || dfd == -1) {
+ perror("/dev");
+ return NULL;
+ }
+ while ((d = readdir(dir)) != NULL) {
+ if (d->d_type == DT_DIR || d->d_type == DT_UNKNOWN || d->d_type == DT_LNK)
+ continue;
+ if (fstatat(dfd, d->d_name, &st, O_RDONLY) != 0)
+ continue;
+ if (major(st.st_rdev) == maj && minor(st.st_rdev) == min) {
+ device = strdup(d->d_name);
+ closedir(dir);
+ return device;
+ }
+ }
+ closedir(dir);
+ return NULL;
+}
+
+/*
+ * Check content of /sys/block/<dev>/removable. Returns 1 if the file
+ * contains '1' otherwise returns 0.
+ */
+static int CheckRemovable(const char* deviceName)
+{
+ FILE *fp;
+ int removable = 0;
+ char *device;
+ char path[PATH_MAX];
+ int maj, min;
+
+ GetMajorMinor(deviceName, &maj, &min);
+ if ((device = FindDeviceMajorMinor(maj, 0)) == NULL) {
+ fprintf(stderr,
+ _("%s: did not find a device with %d-0 major-minor numbers\n"),
+ programName, maj);
+ exit(1);
+ }
+ snprintf(path, sizeof(path), "/sys/block/%s/removable", device);
+ free(device);
+ if((fp = fopen(path, "r")) == NULL) {
+ perror(path);
+ exit(1);
+ }
+
+ if (fgetc(fp) == '1')
+ removable = 1;
+
+ fclose(fp);
+ return removable;
+}
/* handle -x option */
static void HandleXOption(char *deviceName)
@@ -1270,6 +1336,15 @@ int main(int argc, char **argv)
exit(0);
}
+ /* Check if device has removable flag*/
+ if (v_option)
+ printf(_("%s: checking if device \"%s\" has a removable flag\n"), programName, deviceName);
+ if (!CheckRemovable(deviceName))
+ {
+ fprintf(stderr, _("%s: device \"%s\" doesn't have a removable flag\n"), programName, deviceName);
+ exit(1);
+ }
+
/* handle -i option */
if (i_option) {
fd = OpenDevice(deviceName);
Index: eject.spec
===================================================================
RCS file: /cvs/extras/rpms/eject/devel/eject.spec,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- eject.spec 28 Feb 2008 12:33:47 -0000 1.32
+++ eject.spec 12 Mar 2008 11:57:01 -0000 1.33
@@ -1,7 +1,7 @@
Summary: A program that ejects removable media using software control.
Name: eject
Version: 2.1.5
-Release: 7
+Release: 8
License: GPL
Group: System Environment/Base
Source: http://metalab.unc.edu/pub/Linux/utils/disk-management/%{name}-%{version}.tar.gz
@@ -11,6 +11,7 @@
Patch3: eject-2.1.5-opendevice.patch
Patch4: eject-2.1.5-spaces.patch
Patch5: eject-2.1.5-lock.patch
+Patch6: eject-2.1.5-umount.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
URL: http://www.pobox.com/~tranter
ExcludeArch: s390 s390x
@@ -35,6 +36,7 @@
%patch3 -p0 -b .opendevice
%patch4 -p0 -b .spaces
%patch5 -p0 -b .lock
+%patch6 -p1 -b .umount
%build
%configure
@@ -74,6 +76,10 @@
%{_mandir}/man1/*
%changelog
+* Wed Mar 12 2008 Zdenek Prikryl <zprikryl at redhat.com> 2.1.5-8
+- Added check for a removable flag
+- Resolves: #432187
+
* Thu Feb 28 2008 Zdenek Prikryl <zprikryl at redhat.com> 2.1.5-7
- Added lock functionality, patch from upstream.
- Resolves: #145843
More information about the fedora-extras-commits
mailing list