2 * udev_utils.c - generic stuff used by udev
4 * Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <sys/utsname.h>
36 #include "udev_libc_wrapper.h"
39 #include "udev_utils.h"
43 int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action)
47 memset(udev, 0x00, sizeof(struct udevice));
48 INIT_LIST_HEAD(&udev->symlink_list);
49 INIT_LIST_HEAD(&udev->run_list);
50 INIT_LIST_HEAD(&udev->env_list);
53 strlcpy(udev->subsystem, subsystem, sizeof(udev->subsystem));
56 strlcpy(udev->action, action, sizeof(udev->action));
59 strlcpy(udev->devpath, devpath, sizeof(udev->devpath));
60 remove_trailing_chars(udev->devpath, '/');
62 if (strncmp(udev->devpath, "/block/", 7) == 0)
63 udev->type = DEV_BLOCK;
64 else if (strncmp(udev->devpath, "/class/net/", 11) == 0)
66 else if (strncmp(udev->devpath, "/class/", 7) == 0)
67 udev->type = DEV_CLASS;
68 else if (strncmp(udev->devpath, "/devices/", 9) == 0)
69 udev->type = DEV_DEVICE;
72 pos = strrchr(udev->devpath, '/');
74 strlcpy(udev->kernel_name, &pos[1], sizeof(udev->kernel_name));
75 dbg("kernel_name='%s'", udev->kernel_name);
77 /* Some block devices have '!' in their name, change that to '/' */
78 pos = udev->kernel_name;
79 while (pos[0] != '\0') {
85 /* get kernel number */
86 pos = &udev->kernel_name[strlen(udev->kernel_name)];
87 while (isdigit(pos[-1]))
89 strlcpy(udev->kernel_number, pos, sizeof(udev->kernel_number));
90 dbg("kernel_number='%s'", udev->kernel_number);
94 if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS) {
96 strcpy(udev->owner, "root");
97 strcpy(udev->group, "root");
103 void udev_cleanup_device(struct udevice *udev)
105 name_list_cleanup(&udev->symlink_list);
106 name_list_cleanup(&udev->run_list);
107 name_list_cleanup(&udev->env_list);