]> git.ipfire.org Git - thirdparty/systemd.git/blame - udev/udev_device.c
update file headers
[thirdparty/systemd.git] / udev / udev_device.c
CommitLineData
e8d569b4 1/*
55e9959b 2 * Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
e8d569b4 3 *
55e9959b
KS
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.
e8d569b4 8 *
55e9959b
KS
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.
13 *
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/>.
e8d569b4
KS
16 */
17
e8d569b4
KS
18#include <stdlib.h>
19#include <stdio.h>
20#include <stddef.h>
21#include <unistd.h>
22#include <fcntl.h>
23#include <errno.h>
24#include <ctype.h>
01618658 25#include <string.h>
5fc32819
KS
26#include <sys/ioctl.h>
27#include <sys/socket.h>
a4d5ca64
KS
28#include <net/if.h>
29#include <linux/sockios.h>
1aa1e248 30
e8d569b4 31#include "udev.h"
1aa1e248 32#include "udev_rules.h"
e8d569b4
KS
33
34
7d563a17 35struct udevice *udev_device_init(struct udev *udev)
e8d569b4 36{
7d563a17 37 struct udevice *udevice;
44aff4cd 38
7d563a17
KS
39 udevice = malloc(sizeof(struct udevice));
40 if (udevice == NULL)
1aa1e248 41 return NULL;
7d563a17 42 memset(udevice, 0x00, sizeof(struct udevice));
1aa1e248 43
7d563a17
KS
44 udevice->udev = udev;
45
46 INIT_LIST_HEAD(&udevice->symlink_list);
47 INIT_LIST_HEAD(&udevice->run_list);
48 INIT_LIST_HEAD(&udevice->env_list);
e8d569b4 49
1aa1e248 50 /* set sysfs device to local storage, can be overridden if needed */
7d563a17 51 udevice->dev = &udevice->dev_local;
e8d569b4 52
1aa1e248 53 /* default node permissions */
7d563a17
KS
54 udevice->mode = 0660;
55 strcpy(udevice->owner, "root");
56 strcpy(udevice->group, "root");
e8d569b4 57
7d563a17
KS
58 udevice->event_timeout = -1;
59 return udevice;
e8d569b4
KS
60}
61
7d563a17 62void udev_device_cleanup(struct udevice *udevice)
e8d569b4 63{
7d563a17 64 if (udevice == NULL)
44aff4cd 65 return;
7d563a17
KS
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);
69 free(udevice);
1aa1e248
KS
70}
71
7d563a17 72dev_t udev_device_get_devt(struct udevice *udevice)
1aa1e248
KS
73{
74 const char *attr;
5780be9e 75 unsigned int maj, min;
1aa1e248
KS
76
77 /* read it from sysfs */
7d563a17 78 attr = sysfs_attr_get_value(udevice->udev, udevice->dev->devpath, "dev");
1aa1e248 79 if (attr != NULL) {
5780be9e
KS
80 if (sscanf(attr, "%u:%u", &maj, &min) == 2)
81 return makedev(maj, min);
1aa1e248
KS
82 }
83 return makedev(0, 0);
84}