diff options
-rw-r--r-- | Makefile | 48 | ||||
-rw-r--r-- | extras/usb_id/Makefile | 2 | ||||
-rw-r--r-- | udev.c | 102 | ||||
-rw-r--r-- | udev.h | 7 | ||||
-rw-r--r-- | udev.spec | 7 | ||||
-rw-r--r-- | udev_add.c | 4 | ||||
-rw-r--r-- | udev_config.c | 4 | ||||
-rw-r--r-- | udev_db.c | 2 | ||||
-rw-r--r-- | udev_db.h | 4 | ||||
-rw-r--r-- | udev_device.c | 121 | ||||
-rw-r--r-- | udev_event.c | 141 | ||||
-rw-r--r-- | udev_remove.c | 4 | ||||
-rw-r--r-- | udev_rules.c | 56 | ||||
-rw-r--r-- | udev_rules.h | 8 | ||||
-rw-r--r-- | udev_rules_parse.c | 3 | ||||
-rw-r--r-- | udev_utils.c | 125 | ||||
-rw-r--r-- | udev_utils.h | 14 | ||||
-rw-r--r-- | udevcontrol.c | 3 | ||||
-rw-r--r-- | udevd.h | 5 | ||||
-rw-r--r-- | udeveventrecorder.c | 6 | ||||
-rw-r--r-- | udevinfo.c | 2 | ||||
-rw-r--r-- | udevinitsend.c | 6 | ||||
-rw-r--r-- | udevsend.c | 3 | ||||
-rw-r--r-- | udevstart.c | 10 | ||||
-rw-r--r-- | udevtest.c | 4 |
25 files changed, 380 insertions, 311 deletions
@@ -115,34 +115,36 @@ CFLAGS += -D_GNU_SOURCE OPTFLAGS := $(call cc-supports, -Os, -O2) HEADERS = \ - udev.h \ - udev_utils.h \ - udev_rules.h \ - udev_version.h \ - udev_db.h \ - udev_sysfs.h \ - logging.h \ - udev_libc_wrapper.h \ - udev_selinux.h \ + udev.h \ + udev_utils.h \ + udev_rules.h \ + udev_version.h \ + udev_db.h \ + udev_sysfs.h \ + logging.h \ + udev_libc_wrapper.h \ + udev_selinux.h \ list.h SYSFS_OBJS = \ - libsysfs/sysfs_class.o \ - libsysfs/sysfs_device.o \ - libsysfs/sysfs_dir.o \ - libsysfs/sysfs_driver.o \ - libsysfs/sysfs_utils.o \ + libsysfs/sysfs_class.o \ + libsysfs/sysfs_device.o \ + libsysfs/sysfs_dir.o \ + libsysfs/sysfs_driver.o \ + libsysfs/sysfs_utils.o \ libsysfs/dlist.o UDEV_OBJS = \ - udev_utils.o \ - udev_config.o \ - udev_add.o \ - udev_remove.o \ - udev_sysfs.o \ - udev_db.o \ - udev_rules.o \ - udev_rules_parse.o \ + udev_utils.o \ + udev_event.o \ + udev_device.o \ + udev_config.o \ + udev_add.o \ + udev_remove.o \ + udev_sysfs.o \ + udev_db.o \ + udev_rules.o \ + udev_rules_parse.o \ udev_libc_wrapper.o OBJS = \ @@ -151,7 +153,7 @@ OBJS = \ SYSFS = $(PWD)/libsysfs/sysfs.a -CFLAGS += -I$(PWD)/libsysfs/sysfs \ +CFLAGS += -I$(PWD)/libsysfs/sysfs \ -I$(PWD)/libsysfs ifeq ($(strip $(USE_LOG)),true) diff --git a/extras/usb_id/Makefile b/extras/usb_id/Makefile index 4324f95c76..e319a4fee8 100644 --- a/extras/usb_id/Makefile +++ b/extras/usb_id/Makefile @@ -28,7 +28,7 @@ INSTALL_PROGRAM = ${INSTALL} INSTALL_DATA = ${INSTALL} -m 644 INSTALL_SCRIPT = ${INSTALL_PROGRAM} -override CFLAGS+=-D_FILE_OFFSET_BITS=64 +CFLAGS+=-D_FILE_OFFSET_BITS=64 OBJS = $(PROG).o $(VOLUME_ID_OBJS) ../../udev.a ../../libsysfs/sysfs.a HEADERS = @@ -1,10 +1,8 @@ /* * udev.c * - * Userspace devfs - * - * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com> - * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> + * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com> + * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -69,8 +67,6 @@ int main(int argc, char *argv[], char *envp[]) { struct udevice udev; struct udev_rules rules; - char path[PATH_SIZE]; - const char *error; const char *action; const char *devpath; const char *subsystem; @@ -121,98 +117,9 @@ int main(int argc, char *argv[], char *envp[]) udev_init_device(&udev, devpath, subsystem, action); udev_rules_init(&rules, 0); - if (udev.type == DEV_BLOCK || udev.type == DEV_CLASS || udev.type == DEV_NET) { - /* handle device node */ - if (strcmp(action, "add") == 0) { - struct sysfs_class_device *class_dev; - - /* wait for sysfs of /sys/class /sys/block */ - dbg("node add"); - snprintf(path, sizeof(path), "%s%s", sysfs_path, udev.devpath); - path[sizeof(path)-1] = '\0'; - class_dev = wait_class_device_open(path); - if (class_dev == NULL) { - dbg("open class device failed"); - goto run; - } - dbg("opened class_dev->name='%s'", class_dev->name); - wait_for_class_device(class_dev, &error); - - /* get major/minor */ - if (udev.type == DEV_BLOCK || udev.type == DEV_CLASS) - udev.devt = get_devt(class_dev); - - if (udev.type == DEV_NET || udev.devt) { - /* name device */ - udev_rules_get_name(&rules, &udev, class_dev); - if (udev.ignore_device) { - info("device event will be ignored"); - sysfs_close_class_device(class_dev); - goto cleanup; - } - if (udev.name[0] == '\0') { - info("device node creation supressed"); - sysfs_close_class_device(class_dev); - goto cleanup; - } - /* create node, store in db */ - retval = udev_add_device(&udev, class_dev); - } else { - dbg("no dev-file found"); - udev_rules_get_run(&rules, &udev, class_dev, NULL); - if (udev.ignore_device) { - info("device event will be ignored"); - sysfs_close_class_device(class_dev); - goto cleanup; - } - } - sysfs_close_class_device(class_dev); - } else if (strcmp(action, "remove") == 0) { - dbg("node remove"); - udev_rules_get_run(&rules, &udev, NULL, NULL); - if (udev.ignore_device) { - dbg("device event will be ignored"); - goto cleanup; - } - - /* get name from db, remove db-entry, delete node */ - retval = udev_remove_device(&udev); - } - - /* export name of device node or netif */ - if (udev.devname[0] != '\0') - setenv("DEVNAME", udev.devname, 1); - } else if (udev.type == DEV_DEVICE && strcmp(action, "add") == 0) { - struct sysfs_device *devices_dev; - - /* wait for sysfs of /sys/devices/ */ - dbg("devices add"); - snprintf(path, sizeof(path), "%s%s", sysfs_path, devpath); - path[sizeof(path)-1] = '\0'; - devices_dev = wait_devices_device_open(path); - if (!devices_dev) { - dbg("devices device unavailable (probably remove has beaten us)"); - goto run; - } - dbg("devices device opened '%s'", path); - wait_for_devices_device(devices_dev, &error); - udev_rules_get_run(&rules, &udev, NULL, devices_dev); - sysfs_close_device(devices_dev); - if (udev.ignore_device) { - info("device event will be ignored"); - goto cleanup; - } - } else { - dbg("default handling"); - udev_rules_get_run(&rules, &udev, NULL, NULL); - if (udev.ignore_device) { - info("device event will be ignored"); - goto cleanup; - } - } + retval = udev_process_event(&rules, &udev); -run: - if (udev_run && !list_empty(&udev.run_list)) { + if (!retval && udev_run && !list_empty(&udev.run_list)) { struct name_entry *name_loop; dbg("executing run list"); @@ -220,7 +127,6 @@ run: execute_program(name_loop->name, udev.subsystem, NULL, 0, NULL); } -cleanup: udev_cleanup_device(&udev); exit: @@ -1,8 +1,6 @@ /* * udev.h * - * Userspace devfs - * * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org> * @@ -40,6 +38,8 @@ #define DEFAULT_PARTITIONS_COUNT 15 #define UDEV_ALARM_TIMEOUT 120 +struct udev_rules; + enum device_type { DEV_UNKNOWN, DEV_CLASS, @@ -82,6 +82,9 @@ struct udevice { int test_run; }; +extern int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action); +extern void udev_cleanup_device(struct udevice *udev); +extern int udev_process_event(struct udev_rules *rules, struct udevice *udev); extern int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev); extern int udev_remove_device(struct udevice *udev); extern void udev_init_config(void); @@ -27,7 +27,7 @@ # 1 - build it %define volume_id 1 -Summary: A userspace implementation of devfs +Summary: A userspace device manager providing devfs functionality Name: udev Version: 063 Release: 1 @@ -41,8 +41,9 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root Prereq: /bin/sh, fileutils, hotplug %description -udev is a implementation of devfs in userspace using sysfs and -/sbin/hotplug. It requires a 2.6 kernel to run properly. +udev is a userspace device manager, using sysfs and uevents +to provide a devfs-like device directory management and uevent +dispatching. %prep %setup -q diff --git a/udev_add.c b/udev_add.c index e9ae150180..9d872bf039 100644 --- a/udev_add.c +++ b/udev_add.c @@ -1,10 +1,8 @@ /* * udev-add.c * - * Userspace devfs - * * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> - * + * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/udev_config.c b/udev_config.c index 773ee67f9e..c57e36cd8c 100644 --- a/udev_config.c +++ b/udev_config.c @@ -1,10 +1,8 @@ /* * udev_config.c * - * Userspace devfs - * * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com> - * + * Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -1,8 +1,6 @@ /* * udev_db.c * - * Userspace devfs - * * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org> * @@ -1,10 +1,8 @@ /* * udev_db.h * - * Userspace devfs - * * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> - * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> + * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/udev_device.c b/udev_device.c new file mode 100644 index 0000000000..45bb6a2876 --- /dev/null +++ b/udev_device.c @@ -0,0 +1,121 @@ +/* + * udev_utils.c - generic stuff used by udev + * + * Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +#include <stdlib.h> +#include <stdio.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <ctype.h> +#include <dirent.h> +#include <syslog.h> +#include <sys/wait.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/utsname.h> + +#include "udev_libc_wrapper.h" +#include "udev.h" +#include "logging.h" +#include "udev_utils.h" +#include "udev_sysfs.h" +#include "list.h" + + +int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action) +{ + char *pos; + + memset(udev, 0x00, sizeof(struct udevice)); + INIT_LIST_HEAD(&udev->symlink_list); + INIT_LIST_HEAD(&udev->run_list); + INIT_LIST_HEAD(&udev->env_list); + + if (subsystem) + strlcpy(udev->subsystem, subsystem, sizeof(udev->subsystem)); + + if (action) + strlcpy(udev->action, action, sizeof(udev->action)); + + if (devpath) { + strlcpy(udev->devpath, devpath, sizeof(udev->devpath)); + remove_trailing_char(udev->devpath, '/'); + + if (strncmp(udev->devpath, "/block/", 7) == 0) + udev->type = DEV_BLOCK; + else if (strncmp(udev->devpath, "/class/net/", 11) == 0) + udev->type = DEV_NET; + else if (strncmp(udev->devpath, "/class/", 7) == 0) + udev->type = DEV_CLASS; + else if (strncmp(udev->devpath, "/devices/", 9) == 0) + udev->type = DEV_DEVICE; + + /* get kernel name */ + pos = strrchr(udev->devpath, '/'); + if (pos) { + strlcpy(udev->kernel_name, &pos[1], sizeof(udev->kernel_name)); + dbg("kernel_name='%s'", udev->kernel_name); + + /* Some block devices have '!' in their name, change that to '/' */ + pos = udev->kernel_name; + while (pos[0] != '\0') { + if (pos[0] == '!') + pos[0] = '/'; + pos++; + } + + /* get kernel number */ + pos = &udev->kernel_name[strlen(udev->kernel_name)]; + while (isdigit(pos[-1])) + pos--; + strlcpy(udev->kernel_number, pos, sizeof(udev->kernel_number)); + dbg("kernel_number='%s'", udev->kernel_number); + } + } + + if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS) { + udev->mode = 0660; + strcpy(udev->owner, "root"); + strcpy(udev->group, "root"); + } + + return 0; +} + +void udev_cleanup_device(struct udevice *udev) +{ + struct name_entry *name_loop; + struct name_entry *temp_loop; + + list_for_each_entry_safe(name_loop, temp_loop, &udev->symlink_list, node) { + list_del(&name_loop->node); + free(name_loop); + } + list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) { + list_del(&name_loop->node); + free(name_loop); + } + list_for_each_entry_safe(name_loop, temp_loop, &udev->env_list, node) { + list_del(&name_loop->node); + free(name_loop); + } +} diff --git a/udev_event.c b/udev_event.c new file mode 100644 index 0000000000..8a3ed29315 --- /dev/null +++ b/udev_event.c @@ -0,0 +1,141 @@ +/* + * udev_event.c - udev event process + * + * Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +#include <stdlib.h> +#include <stdio.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <ctype.h> +#include <dirent.h> +#include <syslog.h> +#include <sys/wait.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/utsname.h> + +#include "udev_libc_wrapper.h" +#include "udev.h" +#include "logging.h" +#include "udev_rules.h" +#include "udev_utils.h" +#include "udev_sysfs.h" +#include "list.h" + + +int udev_process_event(struct udev_rules *rules, struct udevice *udev) +{ + int retval; + char path[PATH_SIZE]; + const char *error; + + if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS || udev->type == DEV_NET) { + /* handle device node */ + if (strcmp(udev->action, "add") == 0) { + struct sysfs_class_device *class_dev; + + /* wait for sysfs of /sys/class /sys/block */ + dbg("node add"); + snprintf(path, sizeof(path), "%s%s", sysfs_path, udev->devpath); + path[sizeof(path)-1] = '\0'; + class_dev = wait_class_device_open(path); + if (class_dev == NULL) { + dbg("open class device failed"); + return 0; + } + dbg("opened class_dev->name='%s'", class_dev->name); + wait_for_class_device(class_dev, &error); + + /* get major/minor */ + if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS) + udev->devt = get_devt(class_dev); + + if (udev->type == DEV_NET || udev->devt) { + /* name device */ + udev_rules_get_name(rules, udev, class_dev); + if (udev->ignore_device) { + info("device event will be ignored"); + sysfs_close_class_device(class_dev); + return -1; + } + if (udev->name[0] == '\0') { + info("device node creation supressed"); + sysfs_close_class_device(class_dev); + return -1; + } + /* create node, store in db */ + retval = udev_add_device(udev, class_dev); + } else { + dbg("no dev-file found"); + udev_rules_get_run(rules, udev, class_dev, NULL); + if (udev->ignore_device) { + info("device event will be ignored"); + sysfs_close_class_device(class_dev); + return -1; + } + } + sysfs_close_class_device(class_dev); + } else if (strcmp(udev->action, "remove") == 0) { + dbg("node remove"); + udev_rules_get_run(rules, udev, NULL, NULL); + if (udev->ignore_device) { + dbg("device event will be ignored"); + return -1; + } + + /* get name from db, remove db-entry, delete node */ + retval = udev_remove_device(udev); + } + + /* export name of device node or netif */ + if (udev->devname[0] != '\0') + setenv("DEVNAME", udev->devname, 1); + } else if (udev->type == DEV_DEVICE && strcmp(udev->action, "add") == 0) { + struct sysfs_device *devices_dev; + + /* wait for sysfs of /sys/devices/ */ + dbg("devices add"); + snprintf(path, sizeof(path), "%s%s", sysfs_path, udev->devpath); + path[sizeof(path)-1] = '\0'; + devices_dev = wait_devices_device_open(path); + if (!devices_dev) { + dbg("devices device unavailable (probably remove has beaten us)"); + return 0; + } + dbg("devices device opened '%s'", path); + wait_for_devices_device(devices_dev, &error); + udev_rules_get_run(rules, udev, NULL, devices_dev); + sysfs_close_device(devices_dev); + if (udev->ignore_device) { + info("device event will be ignored"); + return -1; + } + } else { + dbg("default handling"); + udev_rules_get_run(rules, udev, NULL, NULL); + if (udev->ignore_device) { + info("device event will be ignored"); + return -1; + } + } + return 0; +} diff --git a/udev_remove.c b/udev_remove.c index b9a4384ee0..28885d4710 100644 --- a/udev_remove.c +++ b/udev_remove.c @@ -1,10 +1,8 @@ /* * udev-remove.c * - * Userspace devfs - * * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> - * + * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/udev_rules.c b/udev_rules.c index 6cbaa781f6..6a485f08af 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -1,12 +1,9 @@ /* * udev_rules.c * - * Userspace devfs - * * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org> * - * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2 of the License. @@ -44,59 +41,6 @@ #include "udev_db.h" -/* compare string with pattern (supports * ? [0-9] [!A-Z]) */ -static int strcmp_pattern(const char *p, const char *s) -{ - if (s[0] == '\0') { - while (p[0] == '*') - p++; - return (p[0] != '\0'); - } - switch (p[0]) { - case '[': - { - int not = 0; - p++; - if (p[0] == '!') { - not = 1; - p++; - } - while ((p[0] != '\0') && (p[0] != ']')) { - int match = 0; - if (p[1] == '-') { - if ((s[0] >= p[0]) && (s[0] <= p[2])) - match = 1; - p += 3; - } else { - match = (p[0] == s[0]); - p++; - } - if (match ^ not) { - while ((p[0] != '\0') && (p[0] != ']')) - p++; - if (p[0] == ']') - return strcmp_pattern(p+1, s+1); - } - } - } - break; - case '*': - if (strcmp_pattern(p, s+1)) - return strcmp_pattern(p+1, s); - return 0; - case '\0': - if (s[0] == '\0') { - return 0; - } - break; - default: - if ((p[0] == s[0]) || (p[0] == '?')) - return strcmp_pattern(p+1, s+1); - break; - } - return 1; -} - /* extract possible {attr} and move str behind it */ static char *get_format_attribute(char **str) { diff --git a/udev_rules.h b/udev_rules.h index bfcb3f23d5..9e3931129f 100644 --- a/udev_rules.h +++ b/udev_rules.h @@ -1,9 +1,8 @@ /* * udev_rules.h * - * Userspace devfs - * - * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com> + * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com> + * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -108,6 +107,9 @@ struct udev_rules { extern int udev_rules_init(struct udev_rules *rules, int resolve_names); extern void udev_rules_close(struct udev_rules *rules); +extern void udev_apply_format(struct udevice *udev, char *string, size_t maxsize, + struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device); + extern void udev_rules_iter_init(struct udev_rules *rules); extern struct udev_rule *udev_rules_iter_next(struct udev_rules *rules); extern struct udev_rule *udev_rules_iter_label(struct udev_rules *rules, const char *label); diff --git a/udev_rules_parse.c b/udev_rules_parse.c index e708f35558..be0757374e 100644 --- a/udev_rules_parse.c +++ b/udev_rules_parse.c @@ -1,12 +1,9 @@ /* * udev_rules_parse.c * - * Userspace devfs - * * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com> * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org> * - * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2 of the License. diff --git a/udev_utils.c b/udev_utils.c index 073cde1074..2524baf592 100644 --- a/udev_utils.c +++ b/udev_utils.c @@ -1,7 +1,7 @@ /* - * udev_lib - generic stuff used by udev + * udev_utils.c - generic stuff used by udev * - * Copyright (C) 2004 Kay Sievers <kay@vrfy.org> + * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -39,84 +39,57 @@ #include "udev_utils.h" #include "list.h" - -int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action) +/* compare string with pattern (supports * ? [0-9] [!A-Z]) */ +int strcmp_pattern(const char *p, const char *s) { - char *pos; - - memset(udev, 0x00, sizeof(struct udevice)); - INIT_LIST_HEAD(&udev->symlink_list); - INIT_LIST_HEAD(&udev->run_list); - INIT_LIST_HEAD(&udev->env_list); - - if (subsystem) - strlcpy(udev->subsystem, subsystem, sizeof(udev->subsystem)); - - if (action) - strlcpy(udev->action, action, sizeof(udev->action)); - - if (devpath) { - strlcpy(udev->devpath, devpath, sizeof(udev->devpath)); - remove_trailing_char(udev->devpath, '/'); - - if (strncmp(udev->devpath, "/block/", 7) == 0) - udev->type = DEV_BLOCK; - else if (strncmp(udev->devpath, "/class/net/", 11) == 0) - udev->type = DEV_NET; - else if (strncmp(udev->devpath, "/class/", 7) == 0) - udev->type = DEV_CLASS; - else if (strncmp(udev->devpath, "/devices/", 9) == 0) - udev->type = DEV_DEVICE; - - /* get kernel name */ - pos = strrchr(udev->devpath, '/'); - if (pos) { - strlcpy(udev->kernel_name, &pos[1], sizeof(udev->kernel_name)); - dbg("kernel_name='%s'", udev->kernel_name); - - /* Some block devices have '!' in their name, change that to '/' */ - pos = udev->kernel_name; - while (pos[0] != '\0') { - if (pos[0] == '!') - pos[0] = '/'; - pos++; + if (s[0] == '\0') { + while (p[0] == '*') + p++; + return (p[0] != '\0'); + } + switch (p[0]) { + case '[': + { + int not = 0; + p++; + if (p[0] == '!') { + not = 1; + p++; + } + while ((p[0] != '\0') && (p[0] != ']')) { + int match = 0; + if (p[1] == '-') { + if ((s[0] >= p[0]) && (s[0] <= p[2])) + match = 1; + p += 3; + } else { + match = (p[0] == s[0]); + p++; + } + if (match ^ not) { + while ((p[0] != '\0') && (p[0] != ']')) + p++; + if (p[0] == ']') + return strcmp_pattern(p+1, s+1); + } } - - /* get kernel number */ - pos = &udev->kernel_name[strlen(udev->kernel_name)]; - while (isdigit(pos[-1])) - pos--; - strlcpy(udev->kernel_number, pos, sizeof(udev->kernel_number)); - dbg("kernel_number='%s'", udev->kernel_number); } + break; + case '*': + if (strcmp_pattern(p, s+1)) + return strcmp_pattern(p+1, s); + return 0; + case '\0': + if (s[0] == '\0') { + return 0; + } + break; + default: + if ((p[0] == s[0]) || (p[0] == '?')) + return strcmp_pattern(p+1, s+1); + break; } - - if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS) { - udev->mode = 0660; - strcpy(udev->owner, "root"); - strcpy(udev->group, "root"); - } - - return 0; -} - -void udev_cleanup_device(struct udevice *udev) -{ - struct name_entry *name_loop; - struct name_entry *temp_loop; - - list_for_each_entry_safe(name_loop, temp_loop, &udev->symlink_list, node) { - list_del(&name_loop->node); - free(name_loop); - } - list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) { - list_del(&name_loop->node); - free(name_loop); - } - list_for_each_entry_safe(name_loop, temp_loop, &udev->env_list, node) { - list_del(&name_loop->node); - free(name_loop); - } + return 1; } int string_is_true(const char *str) diff --git a/udev_utils.h b/udev_utils.h index 655c764fc8..5f4152df82 100644 --- a/udev_utils.h +++ b/udev_utils.h @@ -1,8 +1,7 @@ /* - * udev_lib - generic stuff used by udev - * - * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> + * udev_utils.c - generic stuff used by udev * + * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -19,19 +18,18 @@ * */ -#ifndef _UDEV_LIB_H_ -#define _UDEV_LIB_H_ +#ifndef _UDEV_COMMON_H_ +#define _UDEV_COMMON_H_ #include "udev.h" +#include "list.h" struct name_entry { struct list_head node; char name[PATH_SIZE]; }; -extern int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action); -extern void udev_cleanup_device(struct udevice *udev); - +extern int strcmp_pattern(const char *p, const char *s); extern int kernel_release_satisfactory(unsigned int version, unsigned int patchlevel, unsigned int sublevel); extern int create_path(const char *path); extern int log_priority(const char *priority); diff --git a/udevcontrol.c b/udevcontrol.c index f19ae98fba..5d8fa77683 100644 --- a/udevcontrol.c +++ b/udevcontrol.c @@ -1,11 +1,8 @@ /* * udevcontrol.c * - * Userspace devfs - * * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org> * - * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2 of the License. @@ -1,11 +1,8 @@ /* * udevd.h * - * Userspace devfs - * * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com> - * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> - * + * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/udeveventrecorder.c b/udeveventrecorder.c index af7ea7c15c..711f467307 100644 --- a/udeveventrecorder.c +++ b/udeveventrecorder.c @@ -1,9 +1,9 @@ /* * udeveventrecorder.c * - * Userspace devfs - * - * Copyright (C) 2004, 2005 Olaf Hering <olh@suse.de> + * Copyright (C) 2004-2005 SuSE Linux Products GmbH + * Author: + * Olaf Hering <olh@suse.de> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/udevinfo.c b/udevinfo.c index db562eee49..d2c3e1ab7f 100644 --- a/udevinfo.c +++ b/udevinfo.c @@ -1,5 +1,5 @@ /* - * udevinfo - fetches attributes for a device + * udevinfo.c - fetches attributes for a device * * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> * diff --git a/udevinitsend.c b/udevinitsend.c index 204e9cecd5..5abf3d4bd3 100644 --- a/udevinitsend.c +++ b/udevinitsend.c @@ -1,9 +1,9 @@ /* * udevinitsend.c * - * Userspace devfs - * - * Copyright (C) 2004, 2005 Hannes Reinecke <hare@suse.de> + * Copyright (C) 2004, 2005 SuSE Linux Products GmbH + * Author: + * Hannes Reinecke <hare@suse.de> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/udevsend.c b/udevsend.c index bdc69d0508..94ab6ff625 100644 --- a/udevsend.c +++ b/udevsend.c @@ -1,12 +1,9 @@ /* * udevsend.c * - * Userspace devfs - * * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com> * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> * - * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2 of the License. diff --git a/udevstart.c b/udevstart.c index d9912466ca..0bcbc39737 100644 --- a/udevstart.c +++ b/udevstart.c @@ -2,10 +2,12 @@ * udevstart.c * * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com> - * + * Copyright (C) 2004 Kay Sievers <kay@vrfy.org> + * * Quick and dirty way to populate a /dev with udev if your system - * does not have access to a shell. Based originally on a patch to udev - * from Harald Hoyer <harald@redhat.com> + * does not have access to a shell. Based originally on a patch + * from: + * Harald Hoyer <harald@redhat.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -41,8 +43,8 @@ #include "udev.h" #include "udev_version.h" #include "logging.h" -#include "udev_rules.h" #include "udev_utils.h" +#include "udev_rules.h" #include "list.h" static const char *udev_run_str; diff --git a/udevtest.c b/udevtest.c index 3e17b94715..4890b6837c 100644 --- a/udevtest.c +++ b/udevtest.c @@ -1,9 +1,7 @@ /* * udevtest.c * - * Userspace devfs - * - * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com> + * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the |