From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Thu, 24 Feb 2005 21:52:36 +0000 Subject: Re: replace dev.d/ with a rule based program execution Message-Id: <1109281956.7242.30.camel@localhost.localdomain> MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-+5JqlgYiwi1eRNoe0Q60" List-Id: References: <20050221181242.GA22891@vrfy.org> In-Reply-To: <20050221181242.GA22891@vrfy.org> To: linux-hotplug@vger.kernel.org --=-+5JqlgYiwi1eRNoe0Q60 Content-Type: text/plain Content-Transfer-Encoding: 7bit On Thu, 2005-02-24 at 22:04 +0100, Kay Sievers wrote: >On Thu, 2005-02-24 at 15:45 -0500, David Zeuthen wrote: >>On Thu, 2005-02-24 at 21:34 +0100, Kay Sievers wrote: >>>HAL needs this only in the coldplug case, so what about letting udevinfo >>>dumping a list of _all_ devpath -> node matches with a single call and >>>HAL can merge all the names in one go into the device objects? >> >>That would work, yeah. > >So we should go for it? What format? Any options needed? > > $ udevinfo -d > /block/fd0:/dev/fd0 > /block/hda:/dev/hda > /class/input/mice:/dev/input/mice > /class/mem/null:/dev/null > ... Something stupid like this? It dumps all my ~700 devices in 0.02 seconds. :) Kay --=-+5JqlgYiwi1eRNoe0Q60 Content-Disposition: attachment; filename=udev-dump-db-01.patch Content-Type: text/x-patch; name=udev-dump-db-01.patch; charset=utf-8 Content-Transfer-Encoding: 7bit ===== udev_db.c 1.45 vs edited ===== --- 1.45/udev_db.c 2005-02-24 12:13:24 +01:00 +++ edited/udev_db.c 2005-02-24 22:26:41 +01:00 @@ -239,3 +239,38 @@ return 0; } + +int udev_db_call_foreach(int (*handler_function)(struct udevice *udev)) +{ + struct dirent *ent; + DIR *dir; + char filename[NAME_SIZE]; + struct udevice db_udev; + + dir = opendir(udev_db_path); + if (dir == NULL) { + dbg("unable to udev db '%s'", udev_db_path); + return -1; + } + + while (1) { + ent = readdir(dir); + if (ent == NULL || ent->d_name[0] == '\0') + break; + + if (ent->d_name[0] == '.') + continue; + + snprintf(filename, NAME_SIZE, "%s/%s", udev_db_path, ent->d_name); + filename[NAME_SIZE-1] = '\0'; + + memset(&db_udev, 0x00, sizeof(struct udevice)); + if (parse_db_file(&db_udev, filename) == 0) { + if (handler_function(&db_udev) != 0) + break; + } + } + + closedir(dir); + return 0; +} ===== udev_db.h 1.20 vs edited ===== --- 1.20/udev_db.h 2005-02-24 12:13:24 +01:00 +++ edited/udev_db.h 2005-02-24 22:26:10 +01:00 @@ -30,5 +30,6 @@ extern int udev_db_get_device_by_devpath(struct udevice *dev, const char *devpath); extern int udev_db_get_device_by_name(struct udevice *udev, const char *name); +extern int udev_db_call_foreach(int (*handler_function)(struct udevice *udev)); #endif /* _UDEV_DB_H_ */ ===== udevinfo.8 1.16 vs edited ===== --- 1.16/udevinfo.8 2005-02-23 04:21:38 +01:00 +++ edited/udevinfo.8 2005-02-24 22:44:05 +01:00 @@ -47,6 +47,10 @@ unique attributes to compose a rule. .RB Needs " \-p " specified. .TP +.B \-d +Print the relationship between the devpath and the node name for all devices +currently available in the database. +.TP .B \-h Print help text. .SH "FILES" ===== udevinfo.c 1.44 vs edited ===== --- 1.44/udevinfo.c 2005-02-24 12:13:24 +01:00 +++ edited/udevinfo.c 2005-02-24 22:43:27 +01:00 @@ -178,9 +178,14 @@ return retval; } +static int print_dump(struct udevice *udev) { + printf("%s:%s/%s\n", udev->devpath, udev_root, udev->name); + return 0; +} + static int process_options(int argc, char *argv[]) { - static const char short_options[] = "an:p:q:rVh"; + static const char short_options[] = "adn:p:q:rVh"; int option; int retval = 1; struct udevice udev; @@ -245,6 +250,10 @@ attributes = 1; break; + case 'd': + udev_db_call_foreach(print_dump); + exit(0); + case 'V': printf("udevinfo, version %s\n", UDEV_VERSION); exit(0); @@ -384,7 +393,8 @@ "\n" " -r print udev root\n" " -a print all SYSFS_attributes along the device chain\n" - " -s print all sysfs devices with major/minor, physical device and bus\n" + " -d print the relationship of devpath and the node name for all\n" + " devices available in the database\n" " -V print udev version\n" " -h print this help text\n" "\n"); --=-+5JqlgYiwi1eRNoe0Q60-- ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel