Hi,
I noticed that a simple
# parted -s /dev/ide/host0/bus0/target0/lun0/disc print
takes on my machine 1.5 seconds to complete.
I made a strace and I did see that parted does try to open
part1, part2, ... part15, in that directory, which in turn triggers
devfs module probing.
With the following simple patch, the time required is down to 0.05
seconds. Is this a good thing or am I going to destroy my disks?
Cheers
David
--- linux.c.orig 2002-12-14 11:29:29.000000000 +0100
+++ linux.c 2002-12-14 11:58:28.000000000 +0100
@@ -24,8 +24,10 @@
#include <parted/linux.h>
#include <ctype.h>
+#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <libgen.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@@ -881,6 +883,33 @@
return 0;
}
+static int
+_direntry_exists (const char *name)
+{
+ DIR *dp;
+ struct dirent *ep;
+ char *dir_str = strdup(name);
+ char *base_str = strdup(name);
+ char *dir = dirname(dir_str);
+ char *base = basename(base_str);
+
+ dp = opendir (dir);
+ if (dp != NULL) {
+ while ((ep = readdir (dp))) {
+ if (strcmp(base, ep->d_name)==0) {
+ closedir(dp);
+ free(dir_str);
+ free(base_str);
+ return 1;
+ }
+ }
+ closedir (dp);
+ }
+ free(dir_str);
+ free(base_str);
+ return 0;
+}
+
/* we need to flush the master device, and all the partition devices,
* because there is no coherency between the caches.
* We should only flush unmounted partition devices, because:
@@ -908,10 +937,16 @@
if (!name)
break;
if (!_partition_is_mounted_by_path (name)) {
- fd = open (name, O_WRONLY, 0);
- if (fd > 0) {
- ioctl (fd, BLKFLSBUF);
- close (fd);
+ /* opening all devices makes devfs probe modules
+ thus only open if the directory entry exists.
+ parted startup down from 1.1 seconds to 0 for me
+ with this... address@hidden, 2002-12-14 */
+ if(!_have_devfs() || _direntry_exists(name)) {
+ fd = open (name, O_WRONLY, 0);
+ if (fd > 0) {
+ ioctl (fd, BLKFLSBUF);
+ close (fd);
+ }
}
}
ped_free (name);