2 * Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/ioctl.h>
27 #include <sys/socket.h>
29 #include <linux/sockios.h>
32 #include "udev_rules.h"
35 struct udevice *udev_device_init(struct udev *udev)
37 struct udevice *udevice;
39 udevice = malloc(sizeof(struct udevice));
42 memset(udevice, 0x00, sizeof(struct udevice));
46 INIT_LIST_HEAD(&udevice->symlink_list);
47 INIT_LIST_HEAD(&udevice->run_list);
48 INIT_LIST_HEAD(&udevice->env_list);
50 /* set sysfs device to local storage, can be overridden if needed */
51 udevice->dev = &udevice->dev_local;
53 /* default node permissions */
55 strcpy(udevice->owner, "root");
56 strcpy(udevice->group, "root");
58 udevice->event_timeout = -1;
62 void udev_device_cleanup(struct udevice *udevice)
66 name_list_cleanup(udevice->udev, &udevice->symlink_list);
67 name_list_cleanup(udevice->udev, &udevice->run_list);
68 name_list_cleanup(udevice->udev, &udevice->env_list);
72 dev_t udev_device_get_devt(struct udevice *udevice)
75 unsigned int maj, min;
77 /* read it from sysfs */
78 attr = sysfs_attr_get_value(udevice->udev, udevice->dev->devpath, "dev");
80 if (sscanf(attr, "%u:%u", &maj, &min) == 2)
81 return makedev(maj, min);