rpms/eject/F-8 eject-2.1.5-umount.patch, NONE, 1.1 eject.spec, 1.29, 1.30

Zdenek Prikryl (zprikryl) fedora-extras-commits at redhat.com
Wed Mar 12 12:16:43 UTC 2008


Author: zprikryl

Update of /cvs/extras/rpms/eject/F-8
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv23417

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 -a option */
 	if (a_option) {
 		if (v_option) {


Index: eject.spec
===================================================================
RCS file: /cvs/extras/rpms/eject/F-8/eject.spec,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- eject.spec	30 Oct 2006 14:53:46 -0000	1.29
+++ eject.spec	12 Mar 2008 12:16:00 -0000	1.30
@@ -1,7 +1,7 @@
 Summary: A program that ejects removable media using software control.
 Name: eject
 Version: 2.1.5
-Release: 5
+Release: 6
 License: GPL
 Group: System Environment/Base
 Source: http://metalab.unc.edu/pub/Linux/utils/disk-management/%{name}-%{version}.tar.gz
@@ -10,6 +10,7 @@
 Patch2: eject-timeout.patch
 Patch3: eject-2.1.5-opendevice.patch
 Patch4: eject-2.1.5-spaces.patch
+Patch5: eject-2.1.5-umount.patch
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
 URL: http://www.pobox.com/~tranter
 ExcludeArch: s390 s390x
@@ -33,6 +34,7 @@
 %patch2 -p1 -b .timeout
 %patch3 -p0 -b .opendevice
 %patch4 -p0 -b .spaces
+%patch5 -p1 -b .umount
 
 %build
 %configure
@@ -72,6 +74,10 @@
 %{_mandir}/man1/*
 
 %changelog
+* Wed Mar 12 2008 Zdenek Prikryl <zprikryl at redhat.com> 2.1.5-6
+- Added check for a removable flag
+- Resolves: #432187
+
 * Mon Oct 30 2006 Than Ngo <than at redhat.com> 2.1.5-5
 - apply upstream patch to fix #212467
 




More information about the fedora-extras-commits mailing list