[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch] detect devices from /proc/partitions
From: |
Glenn McGrath |
Subject: |
[patch] detect devices from /proc/partitions |
Date: |
Sat, 18 Nov 2000 16:53:02 +1100 |
This patch makes parted probe whole disks as seen by /proc/partitions.
As far as i can tell its not possible to get a list of storage devices
from userland if /proc isnt compiled in, so it needs /proc which is
unfortunate.
Glenn
diff -U 3 -r ./parted-1.4.1.orig/libparted/device.c
./parted-1.4.1/libparted/device.c
--- ./parted-1.4.1.orig/libparted/device.c Tue Nov 14 19:50:50 2000
+++ ./parted-1.4.1/libparted/device.c Sat Nov 18 16:44:17 2000
@@ -45,6 +45,7 @@
#include <sys/sysmacros.h>
#include <sys/stat.h>
#include <scsi/scsi.h>
+#include <ctype.h>
#include <parted/parted.h>
@@ -1057,25 +1058,29 @@
ped_exception_leave_all ();
}
-/* FIXME */
+#define MAX_PARTNAME_LENGTH 80
void
ped_device_probe_all ()
{
- probe ("/dev/hdh");
- probe ("/dev/hdg");
- probe ("/dev/hdf");
- probe ("/dev/hde");
- probe ("/dev/hdd");
- probe ("/dev/hdc");
- probe ("/dev/hdb");
- probe ("/dev/hda");
-
- probe ("/dev/sdf");
- probe ("/dev/sde");
- probe ("/dev/sdd");
- probe ("/dev/sdc");
- probe ("/dev/sdb");
- probe ("/dev/sda");
+ FILE *proc_part;
+ char line[MAX_PARTNAME_LENGTH];
+ char name[MAX_PARTNAME_LENGTH - 22];
+
+ proc_part=fopen("/proc/partitions", "r");
+
+ /* the first two lines are headers, ignore them */
+ fgets(line, MAX_PARTNAME_LENGTH, proc_part);
+ fgets(line, MAX_PARTNAME_LENGTH, proc_part);
+
+ while( fgets(line, MAX_PARTNAME_LENGTH, proc_part) != NULL) {
+ if ( line[strlen(line)-1] = '\n' )
+ line[strlen(line)-1] = '\0';
+ if ( isalpha(line[strlen(line)-1]) ) {
+ strcpy(name, "/dev/");
+ strcat(name, rindex(line, ' ')+1);
+ probe(name);
+ }
+ }
}
void
- [patch] detect devices from /proc/partitions,
Glenn McGrath <=