libudev-device.c revision 37372bbc38d8542f482d90b26c90714429584421
afe3ab588a6b2992efe5a9b22ed038545ba3cdbfLennart Poettering/*
c343be283b7152554bac0c02493a4e1759c163f7Kay Sievers * libudev - interface to udev device information
b3ae710c251d0ce5cf2cef63208e325497b5e323Zbigniew Jędrzejewski-Szmek *
b3ae710c251d0ce5cf2cef63208e325497b5e323Zbigniew Jędrzejewski-Szmek * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers *
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * This program is free software: you can redistribute it and/or modify
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * it under the terms of the GNU General Public License as published by
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * the Free Software Foundation, either version 2 of the License, or
afe3ab588a6b2992efe5a9b22ed038545ba3cdbfLennart Poettering * (at your option) any later version.
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek *
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek * This program is distributed in the hope that it will be useful,
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek * but WITHOUT ANY WARRANTY; without even the implied warranty of
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek * GNU General Public License for more details.
3f85ef0f05ffc51e19f86fb83a1c51e8e3cd6817Harald Hoyer *
afe3ab588a6b2992efe5a9b22ed038545ba3cdbfLennart Poettering * You should have received a copy of the GNU General Public License
afe3ab588a6b2992efe5a9b22ed038545ba3cdbfLennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
afea8d3853d0f76b3845729ff00e75d281f43a1bZbigniew Jędrzejewski-Szmek */
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f85857df75cfedbc0d10b8ca2400188dc8f4c22eLennart Poettering#include "config.h"
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
bafb15bab99887d1b6b8a35136531bac6c3876a6Lennart Poettering#include <stdio.h>
81429136905a6204875174b60a179333b7f3c9e4Kay Sievers#include <stdlib.h>
e7b4d43ec3d5eb0099a3978f98a46f3c15443b23Lennart Poettering#include <stddef.h>
58f55364fa00a6a4706df2c4a01c6967f432e531Lennart Poettering#include <unistd.h>
58f55364fa00a6a4706df2c4a01c6967f432e531Lennart Poettering#include <errno.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include <string.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include <dirent.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include <sys/stat.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include "libudev.h"
81429136905a6204875174b60a179333b7f3c9e4Kay Sievers#include "libudev-private.h"
fbe1a1a94f19112d7e5d60c40d87487ad24e2ce4Lennart Poettering#include "../udev.h"
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poetteringstruct udev_device {
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering int refcount;
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering struct udev *udev;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering char *devpath;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering char *syspath;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering char *devname;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering char *subsystem;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering struct list_head link_list;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering struct list_head env_list;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering char *action;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering char *driver;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering char *devpath_old;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering char *physdevpath;
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering int timeout;
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering dev_t devnum;
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering long long int seqnum;
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering};
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poetteringstruct udev_device *device_init(struct udev *udev)
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering{
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering struct udev_device *udev_device;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering if (udev == NULL)
d2f81fb00cc3c49e21b31000ba7d37b81a260257Lennart Poettering return NULL;
d2f81fb00cc3c49e21b31000ba7d37b81a260257Lennart Poettering
98cd2651988619bf606f0b27825440c4638a7e0bLennart Poettering udev_device = malloc(sizeof(struct udev_device));
b7307642391c8ebb9724c99e6b33239e2c0ff944Lennart Poettering if (udev_device == NULL)
b7307642391c8ebb9724c99e6b33239e2c0ff944Lennart Poettering return NULL;
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poettering memset(udev_device, 0x00, sizeof(struct udev_device));
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poettering udev_device->refcount = 1;
bf27dcb613a3924b7f4ec74c2de29ace79d62b01Lennart Poettering udev_device->udev = udev;
bf27dcb613a3924b7f4ec74c2de29ace79d62b01Lennart Poettering INIT_LIST_HEAD(&udev_device->link_list);
bf27dcb613a3924b7f4ec74c2de29ace79d62b01Lennart Poettering INIT_LIST_HEAD(&udev_device->env_list);
bf27dcb613a3924b7f4ec74c2de29ace79d62b01Lennart Poettering info(udev_device->udev, "udev_device: %p created\n", udev_device);
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering return udev_device;
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering}
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering/**
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering * udev_device_new_from_devpath:
40ff4a4abd76d71408e598ed02d7860b8465fa9aLennart Poettering * @udev: udev library context
40ff4a4abd76d71408e598ed02d7860b8465fa9aLennart Poettering * @devpath: sys device path
40ff4a4abd76d71408e598ed02d7860b8465fa9aLennart Poettering *
40ff4a4abd76d71408e598ed02d7860b8465fa9aLennart Poettering * Create new udev device, and fill in information from the sysfs
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering * device and the udev database entry. The devpath must not contain
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering * the sysfs mount path, and must contain a leading '/'.
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering *
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering * The initial refcount is 1, and needs to be decremented to
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering * release the ressources of the udev device.
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering *
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering * Returns: a new udev device, or #NULL, if it does not exist
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering **/
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poetteringstruct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *devpath)
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering{
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering char path[PATH_SIZE];
41114e81b562bcee52be1ef94c684ace2362ca54Lennart Poettering struct stat statbuf;
41114e81b562bcee52be1ef94c684ace2362ca54Lennart Poettering struct udev_device *udev_device;
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering struct udevice *udevice;
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering struct name_entry *name_loop;
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering int err;
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering if (udev == NULL)
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering return NULL;
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering if (devpath == NULL)
a195cbad3796dfda3d1016e4819c612c859e3c7bLennart Poettering return NULL;
a195cbad3796dfda3d1016e4819c612c859e3c7bLennart Poettering
8514b67754c5ff7fa628929b3d27131010c21842Lennart Poettering strlcpy(path, udev_get_sys_path(udev), sizeof(path));
8514b67754c5ff7fa628929b3d27131010c21842Lennart Poettering strlcat(path, devpath, sizeof(path));
6c78f43c7b0e54e695af49917fda79b584f46830Lennart Poettering if (stat(path, &statbuf) != 0)
6c78f43c7b0e54e695af49917fda79b584f46830Lennart Poettering return NULL;
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering if (!S_ISDIR(statbuf.st_mode))
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering return NULL;
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering udev_device = device_init(udev);
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering if (udev_device == NULL)
b568ef14a75dffb7182e0acbdec743b31df2a597Lennart Poettering return NULL;
c2d5b3c94d0c082ef29597fb230f8b88b124bab8Lennart Poettering
264b8070715d2d19344c4991ace21147d998f56dLennart Poettering udevice = udev_device_init(udev);
264b8070715d2d19344c4991ace21147d998f56dLennart Poettering if (udevice == NULL) {
4ecd22142543aac55ddac1da3b7d6882c009d637Lennart Poettering free(udev_device);
4ecd22142543aac55ddac1da3b7d6882c009d637Lennart Poettering return NULL;
7e27f3121e5a10629302b5221eb21345f832724aLennart Poettering }
7e27f3121e5a10629302b5221eb21345f832724aLennart Poettering
f81e67f79fa856aa2ecffad4d014772ce981745cLennart Poettering /* resolve possible symlink to real path */
f81e67f79fa856aa2ecffad4d014772ce981745cLennart Poettering strlcpy(path, devpath, sizeof(path));
d48b7bd271b1e70924c8485d2f95c2f5a1ae77cbLennart Poettering sysfs_resolve_link(udev, path, sizeof(path));
d48b7bd271b1e70924c8485d2f95c2f5a1ae77cbLennart Poettering device_set_devpath(udev_device, devpath);
25e14499c4c5b02229d05a5bc26c3693ade5f987Lennart Poettering info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
25e14499c4c5b02229d05a5bc26c3693ade5f987Lennart Poettering
758c4d7a391c0e024737053c815bf3924653b8c5Lennart Poettering err = udev_db_get_device(udevice, path);
758c4d7a391c0e024737053c815bf3924653b8c5Lennart Poettering if (err >= 0)
821cc13ddae40fb7608458b44aaa7a3fd33d56d9Lennart Poettering info(udev, "device %p filled with udev database data\n", udev_device);
821cc13ddae40fb7608458b44aaa7a3fd33d56d9Lennart Poettering
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering if (udevice->name[0] != '\0')
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering asprintf(&udev_device->devname, "%s/%s", udev_get_dev_path(udev), udevice->name);
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering list_for_each_entry(name_loop, &udevice->symlink_list, node) {
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering char name[PATH_SIZE];
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering strlcpy(name, udev_get_dev_path(udev), sizeof(name));
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering strlcat(name, "/", sizeof(name));
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering strlcat(name, name_loop->name, sizeof(name));
25e773eeb4f853804e1bf0dbd9a184f23e9b2a97Kay Sievers name_list_add(udev, &udev_device->link_list, name, 0);
b857e042d621ffb98a652f33850b431fafbece43Lennart Poettering }
6dab5bb18151c80fc39bd51f03dcff40b920de3eLennart Poettering
6dab5bb18151c80fc39bd51f03dcff40b920de3eLennart Poettering list_for_each_entry(name_loop, &udevice->env_list, node)
384a4be2b00cb95ce215dd343cc9aa77adc9b1ecLennart Poettering name_list_add(udev_device->udev, &udev_device->env_list, name_loop->name, 0);
384a4be2b00cb95ce215dd343cc9aa77adc9b1ecLennart Poettering
706d97503df83d141d241b645d2c920d691b3d62Lennart Poettering udev_device_cleanup(udevice);
706d97503df83d141d241b645d2c920d691b3d62Lennart Poettering return udev_device;
3bcde97e8502c48b53f7420e2433ca68e601662dLennart Poettering}
3bcde97e8502c48b53f7420e2433ca68e601662dLennart Poettering
533bb267f13e2f7b4d7b78de30e821dc81c82335Lennart Poettering/**
533bb267f13e2f7b4d7b78de30e821dc81c82335Lennart Poettering * udev_device_get_udev:
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering * @udev_device: udev device
533bb267f13e2f7b4d7b78de30e821dc81c82335Lennart Poettering *
b42de08aa4c97636e42c28c7bce08f0d7c2a719aZbigniew Jędrzejewski-Szmek * Retrieve the udev library context the device was created with.
b42de08aa4c97636e42c28c7bce08f0d7c2a719aZbigniew Jędrzejewski-Szmek *
b42de08aa4c97636e42c28c7bce08f0d7c2a719aZbigniew Jędrzejewski-Szmek * Returns: the udev library context
b42de08aa4c97636e42c28c7bce08f0d7c2a719aZbigniew Jędrzejewski-Szmek **/
202aea456dfb279cd34da7bfd1880f6ac0fd849fLennart Poetteringstruct udev *udev_device_get_udev(struct udev_device *udev_device)
42aeb14a4a0fa7d43da96a8ed0fb0e180a2dd5c8Lennart Poettering{
42aeb14a4a0fa7d43da96a8ed0fb0e180a2dd5c8Lennart Poettering if (udev_device == NULL)
42aeb14a4a0fa7d43da96a8ed0fb0e180a2dd5c8Lennart Poettering return NULL;
42aeb14a4a0fa7d43da96a8ed0fb0e180a2dd5c8Lennart Poettering return udev_device->udev;
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering}
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering/**
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering * udev_device_ref:
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering * @udev_device: udev device
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering *
563b1bdc09efe0cf94dd3f514f30376ca854c1ceLennart Poettering * Take a reference of a udev device.
563b1bdc09efe0cf94dd3f514f30376ca854c1ceLennart Poettering *
5dcf983854c2e8314dbee239180255490ec8ae1cLennart Poettering * Returns: the passed udev device
5dcf983854c2e8314dbee239180255490ec8ae1cLennart Poettering **/
5dcf983854c2e8314dbee239180255490ec8ae1cLennart Poetteringstruct udev_device *udev_device_ref(struct udev_device *udev_device)
b873d33ec9583c92a0c2bc6807d010720fa31595Lennart Poettering{
d61bb44a89fde3042c7c15ea4975239f7dcb0cb0Lennart Poettering if (udev_device == NULL)
ed220efd6657822332b9563ec53c5ab9f3c33220Lennart Poettering return NULL;
ed220efd6657822332b9563ec53c5ab9f3c33220Lennart Poettering udev_device->refcount++;
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering return udev_device;
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering}
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering/**
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering * udev_device_unref:
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering * @udev_device: udev device
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering *
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering * Drop a reference of a udev device. If the refcount reaches zero,
ca70bec9261977336c94f44d5fcf37e1c495326aLennart Poettering * the ressources of the device will be released.
ca70bec9261977336c94f44d5fcf37e1c495326aLennart Poettering *
ca70bec9261977336c94f44d5fcf37e1c495326aLennart Poettering **/
1dbe0a6efda7b1d35957eab7e1d56a2c69d806d9Lennart Poetteringvoid udev_device_unref(struct udev_device *udev_device)
1dbe0a6efda7b1d35957eab7e1d56a2c69d806d9Lennart Poettering{
157a180e4fc827606833a6724834ba7b0246d650Tom Gundersen if (udev_device == NULL)
157a180e4fc827606833a6724834ba7b0246d650Tom Gundersen return;
b873d33ec9583c92a0c2bc6807d010720fa31595Lennart Poettering udev_device->refcount--;
9d6db739ce1eaa3eace21801fd606d523b73c8f4Lennart Poettering if (udev_device->refcount > 0)
1dbe0a6efda7b1d35957eab7e1d56a2c69d806d9Lennart Poettering return;
1dbe0a6efda7b1d35957eab7e1d56a2c69d806d9Lennart Poettering free(udev_device->syspath);
9d6db739ce1eaa3eace21801fd606d523b73c8f4Lennart Poettering free(udev_device->devname);
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek free(udev_device->subsystem);
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek name_list_cleanup(udev_device->udev, &udev_device->link_list);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek name_list_cleanup(udev_device->udev, &udev_device->env_list);
23c4091dc2b85d117512e89233fdeb47d1ff3d92Lennart Poettering info(udev_device->udev, "udev_device: %p released\n", udev_device);
23c4091dc2b85d117512e89233fdeb47d1ff3d92Lennart Poettering free(udev_device);
9d6db739ce1eaa3eace21801fd606d523b73c8f4Lennart Poettering}
0f47ed0a052c0da743404f23ac3532aaabd23655Lennart Poettering
9d6db739ce1eaa3eace21801fd606d523b73c8f4Lennart Poettering/**
bc07548926ec5ed7b13df8d3656654f238e0b9a7Lennart Poettering * udev_device_get_devpath:
bc07548926ec5ed7b13df8d3656654f238e0b9a7Lennart Poettering * @udev_device: udev device
b6b63571ae3eca1741d54172922961af972b8f20Lennart Poettering *
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering * Retrieve the kernel devpath value of the udev device. The path
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering * does not contain the sys mount point, and starts with a '/'.
3f77a1b19f5a8ce33566f7f6e28e94c08ea30841Kay Sievers *
e2a69298819b58f008be61d314f8ab95ccaec427Lennart Poettering * Returns: the devpath of the udev device
e2a69298819b58f008be61d314f8ab95ccaec427Lennart Poettering **/
2834ffe78d7fd8be118429aa1449ac72641638c2Lennart Poetteringconst char *udev_device_get_devpath(struct udev_device *udev_device)
2834ffe78d7fd8be118429aa1449ac72641638c2Lennart Poettering{
a940778fb1dd16479f455bab3ac6cbdbc5b06165Lennart Poettering if (udev_device == NULL)
a940778fb1dd16479f455bab3ac6cbdbc5b06165Lennart Poettering return NULL;
a01647e53727107d82382bc5c9d98c894e8f386cLennart Poettering return udev_device->devpath;
3c779fa59d1825d7db2a9516669d34ded7916913Lennart Poettering}
a940778fb1dd16479f455bab3ac6cbdbc5b06165Lennart Poettering
a01647e53727107d82382bc5c9d98c894e8f386cLennart Poettering/**
3de03738fc970496d2d3da668c72767a48ccc41bLennart Poettering * udev_device_get_syspath:
3de03738fc970496d2d3da668c72767a48ccc41bLennart Poettering * @udev_device: udev device
2b1c3767515672dfd0f5e0a9c9d7ac3a16a6a361Lennart Poettering *
2b1c3767515672dfd0f5e0a9c9d7ac3a16a6a361Lennart Poettering * Retrieve the sys path of the udev device. The path is an
37efac5ddb21fd91ed420c070ed07f375e78b3b9Lennart Poettering * absolute path and starts with the sys mount point.
37efac5ddb21fd91ed420c070ed07f375e78b3b9Lennart Poettering *
7348b3adb324614132cf376f478e883bd7de28f1Lennart Poettering * Returns: the sys path of the udev device
7348b3adb324614132cf376f478e883bd7de28f1Lennart Poettering **/
e107ed185ef08945102834234a05ec51bb438685Lennart Poetteringconst char *udev_device_get_syspath(struct udev_device *udev_device)
e107ed185ef08945102834234a05ec51bb438685Lennart Poettering{
81429136905a6204875174b60a179333b7f3c9e4Kay Sievers if (udev_device == NULL)
81429136905a6204875174b60a179333b7f3c9e4Kay Sievers return NULL;
e107ed185ef08945102834234a05ec51bb438685Lennart Poettering return udev_device->syspath;
f598ac3e28b729dd0b1d0a881df3e16465687a2bLennart Poettering}
11fb37f16ed99c1603c9d770b60ce4953b96a58dLennart Poettering
01083ad094664e5c685060f4fb35a05ea2f212edLennart Poettering/**
01083ad094664e5c685060f4fb35a05ea2f212edLennart Poettering * udev_device_get_devname:
edb2935c5c5b95c42b8679086f60da5eafad74cbLennart Poettering * @udev_device: udev device
edb2935c5c5b95c42b8679086f60da5eafad74cbLennart Poettering *
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering * Retrieve the device node file name belonging to the udev device.
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering * The path is an absolute path, and starts with the device directory.
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering *
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering * Returns: the device node file name of the udev device, or #NULL if no device node exists
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering **/
2a781fc9bd33982c81e5ff75974a442a33d4f167Lennart Poetteringconst char *udev_device_get_devname(struct udev_device *udev_device)
2a781fc9bd33982c81e5ff75974a442a33d4f167Lennart Poettering{
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering if (udev_device == NULL)
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering return NULL;
650264033f2f98f6319513958d94d59078654af8Lennart Poettering return udev_device->devname;
650264033f2f98f6319513958d94d59078654af8Lennart Poettering}
650264033f2f98f6319513958d94d59078654af8Lennart Poettering
f8901862b2b030921b3d5aba4157044ceab16451Lennart Poettering/**
eda8f06755bd98c4639293c26b856c225f0d1fe1Lennart Poettering * udev_device_get_subsystem:
eda8f06755bd98c4639293c26b856c225f0d1fe1Lennart Poettering * @udev_device: udev device
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering *
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering * Retrieve the subsystem string of the udev device. The string does not
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering * contain any "/".
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering *
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering * Returns: the subsystem name of the udev device, or #NULL if it can not be determined
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering **/
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poetteringconst char *udev_device_get_subsystem(struct udev_device *udev_device)
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering{
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering char subsystem[NAME_SIZE];
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering if (udev_device == NULL)
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering return NULL;
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering if (udev_device->subsystem != NULL)
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering return udev_device->subsystem;
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering if (util_get_sys_subsystem(udev_device->udev, udev_device->devpath, subsystem, sizeof(subsystem)) < 2)
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering return NULL;
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering udev_device->subsystem = strdup(subsystem);
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering return udev_device->subsystem;
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering}
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering/**
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering * udev_device_get_devlinks:
ef417cfd2211ae017a38b9796c6db29130133e63Zbigniew Jędrzejewski-Szmek * @udev_device: udev device
ef417cfd2211ae017a38b9796c6db29130133e63Zbigniew Jędrzejewski-Szmek * @cb: function to be called for every device link found
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmek * @data: data to be passed to the function
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering *
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering * Retrieve the device links pointing to the device file of the
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering * udev device. For every device link, the passed function will be
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering * called with the device link string.
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering * The path is an absolute path, and starts with the device directory.
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering * If the function returns 1, remaning device links will be ignored.
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering *
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering * Returns: the number of device links passed to the caller, or a negative value on error
0bee65f0622c4faa8ac8ae771cc0c8a936dfa284Lennart Poettering **/
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringint udev_device_get_devlinks(struct udev_device *udev_device,
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering int (*cb)(struct udev_device *udev_device, const char *value, void *data),
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering void *data)
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering{
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering struct name_entry *name_loop;
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering int count = 0;
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering
718db96199eb307751264e4163555662c9a389faLennart Poettering if (udev_device == NULL)
718db96199eb307751264e4163555662c9a389faLennart Poettering return -1;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering list_for_each_entry(name_loop, &udev_device->link_list, node) {
718db96199eb307751264e4163555662c9a389faLennart Poettering count++;
718db96199eb307751264e4163555662c9a389faLennart Poettering if (cb(udev_device, name_loop->name, data) != 0)
718db96199eb307751264e4163555662c9a389faLennart Poettering break;
966204e010ed432a1d7a0481d41a326d8ec7b0c8Lennart Poettering }
966204e010ed432a1d7a0481d41a326d8ec7b0c8Lennart Poettering return count;
94676f3e9352cbf1f72e0a512ee0d2ed83ff676dLennart Poettering}
6fd4d0209827e5c3e52fa8c7144852f550f8f95cLennart Poettering
416446221d905b6815175dc4d525d27f8ae43d1bLennart Poettering/**
416446221d905b6815175dc4d525d27f8ae43d1bLennart Poettering * udev_device_get_properties:
7f79cd7109a60810140a045cc725291fc5515264Lennart Poettering * @udev_device: udev device
0aafd43d235982510d1c40564079f7bcec0c7c19Lennart Poettering * @cb: function to be called for every property found
19aadacf92ad86967ffb678e37b2ff9e83cb9480Jan Engelhardt * @data: data to be passed to the function
19aadacf92ad86967ffb678e37b2ff9e83cb9480Jan Engelhardt *
df5f6971e6e15b4632884916c71daa076c8bae96Lennart Poettering * Retrieve the property key/value pairs belonging to the
df5f6971e6e15b4632884916c71daa076c8bae96Lennart Poettering * udev device. For every key/value pair, the passed function will be
fcba531ed4c6e6f8f21d8ca4e3a56e3162b1c578Lennart Poettering * called. If the function returns 1, remaning properties will be
fcba531ed4c6e6f8f21d8ca4e3a56e3162b1c578Lennart Poettering * ignored.
6aaa8c2f783cd1b3ac27c5ce40625d032e7e3d71Zbigniew Jędrzejewski-Szmek *
c3bb87dbab8b79bb9253407cb5b7f3e6fe8db395Lennart Poettering * Returns: the number of properties passed to the caller, or a negative value on error
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt **/
18d4e7c26e7806ac363d19989df7144d5058ce41Lennart Poetteringint udev_device_get_properties(struct udev_device *udev_device,
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poettering int (*cb)(struct udev_device *udev_device, const char *key, const char *value, void *data),
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poettering void *data)
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poettering{
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poettering struct name_entry *name_loop;
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poettering int count = 0;
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poettering
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poettering if (udev_device == NULL)
6bb648a16ae4a682ad4784412af706d2e6a3e4daTom Gundersen return -1;
d0928791499734e202460d5c027b5d3e0d28e7abLennart Poettering list_for_each_entry(name_loop, &udev_device->env_list, node) {
4a02e68602be9f6f3caac0f6195672490f715fe1Lennart Poettering char name[PATH_SIZE];
e7100587da6d147fa601c911122d13ad4257e963Lennart Poettering char *val;
bca3e263cfc68f506bfbafb11680f35aa13c38a5Lennart Poettering
e8bbb7c7e9163420cb1ba92f82dbc09aab577d1aLennart Poettering strncpy(name, name_loop->name, PATH_SIZE);
e8bbb7c7e9163420cb1ba92f82dbc09aab577d1aLennart Poettering name[PATH_SIZE-1] = '\0';
7212c6083a5577eabc96c35c9db4c19c113cae93Lennart Poettering val = strchr(name, '=');
7212c6083a5577eabc96c35c9db4c19c113cae93Lennart Poettering if (val == NULL)
7212c6083a5577eabc96c35c9db4c19c113cae93Lennart Poettering continue;
7212c6083a5577eabc96c35c9db4c19c113cae93Lennart Poettering val[0] = '\0';
1f140dd8b048c5f5599a886b8c4d20f3f1065774David Herrmann val = &val[1];
57f2a947270faf65e1876797b930e3f6d60ebd06Lennart Poettering count++;
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt if (cb(udev_device, name, val, data) != 0)
7973ca1927e1f3bac9438f3529458c9ff868905dLennart Poettering break;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering }
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering return count;
dc17bcef197a0d5ee798cce59c40e4f5e85c24f6Lennart Poettering}
80caea6cc72ebd311a311b1527cc6b87201c13bfLennart Poettering
ab9716c2489f9141ed13ec22dbb216b3e6fbd6b5Lennart Poetteringconst char *udev_device_get_driver(struct udev_device *udev_device)
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering{
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering if (udev_device == NULL)
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering return NULL;
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering return udev_device->driver;
2ecfc64e59b5e4e96bed6f68bd36b612ef77a146Lennart Poettering}
6a8b5fa4635ed858788fb10099ec9b62b3359a0aLennart Poettering
69727e6dc69ae5d9b5ae3681723778a3faa354e9Lennart Poetteringdev_t udev_device_get_devnum(struct udev_device *udev_device)
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering{
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering if (udev_device == NULL)
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return makedev(0, 0);
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return udev_device->devnum;
b568ef14a75dffb7182e0acbdec743b31df2a597Lennart Poettering}
0ad68f8743f3baaa7cd8ac7a2275459ae0f7b96aLennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringconst char *udev_device_get_action(struct udev_device *udev_device)
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering{
12179984a38fe74581333fbcdc11c822d81f505fLennart Poettering if (udev_device == NULL)
0536ce5d0ceaf87f3e81faaff41d69ffeed2186fZbigniew Jędrzejewski-Szmek return NULL;
eb01ba5de14859d7a94835ab9299de40132d549aLennart Poettering return udev_device->action;
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poettering}
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poettering
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poetteringunsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poettering{
69af45035913e7119cffd94c542bd3039600e45dZbigniew Jędrzejewski-Szmek if (udev_device == NULL)
e8a7a315391a6a07897122725cd707f4e9ce63d7Lennart Poettering return 0;
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering return udev_device->seqnum;
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering}
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poetteringint device_set_devpath(struct udev_device *udev_device, const char *devpath)
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering{
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering if (asprintf(&udev_device->syspath, "%s%s", udev_get_sys_path(udev_device->udev), devpath) < 0)
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering return -ENOMEM;
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering return 0;
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering}
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmekint device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek{
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek udev_device->subsystem = strdup(subsystem);
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering if (udev_device->subsystem == NULL)
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering return -1;
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt return 0;
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering}
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poetteringint device_set_devname(struct udev_device *udev_device, const char *devname)
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering{
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering udev_device->devname = strdup(devname);
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering if (udev_device->devname == NULL)
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering return -ENOMEM;
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering return 0;
09f727eebd87661f263d3c2c1e0de7b7771acd40Lennart Poettering}
09f727eebd87661f263d3c2c1e0de7b7771acd40Lennart Poettering
09f727eebd87661f263d3c2c1e0de7b7771acd40Lennart Poetteringint device_add_devlink(struct udev_device *udev_device, const char *devlink)
c144692179098c1861f2aeafc67689a74439cf4cLennart Poettering{
c144692179098c1861f2aeafc67689a74439cf4cLennart Poettering if (name_list_add(udev_device->udev, &udev_device->link_list, devlink, 0) == NULL)
c144692179098c1861f2aeafc67689a74439cf4cLennart Poettering return -ENOMEM;
c144692179098c1861f2aeafc67689a74439cf4cLennart Poettering return 0;
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering}
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poetteringint device_add_property(struct udev_device *udev_device, const char *property)
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering{
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering if (name_list_add(udev_device->udev, &udev_device->env_list, property, 0) == NULL)
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering return -ENOMEM;
e5ec62c56963d997edaffa904af5dc45dac23988Lennart Poettering return 0;
54c31a79f72ff57ac8eba089acacc4ab482b745dLennart Poettering}
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poettering
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poetteringint device_set_action(struct udev_device *udev_device, const char *action)
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt{
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poettering udev_device->action = strdup(action);
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering if (udev_device->action == NULL)
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering return -ENOMEM;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering return 0;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering}
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poetteringint device_set_driver(struct udev_device *udev_device, const char *driver)
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering{
490b7e47093d491a2bdb1084fe92b796f4e07eefLennart Poettering udev_device->driver = strdup(driver);
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering if (udev_device->driver == NULL)
490b7e47093d491a2bdb1084fe92b796f4e07eefLennart Poettering return -ENOMEM;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return 0;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering}
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
466784c8710e5cb0e0b86a16506d992d7ec5b619Kay Sieversconst char *device_get_devpath_old(struct udev_device *udev_device)
e41814846c19a48f4490169d82e359e005c4db45Lennart Poettering{
c0fe5db522b52f27e030655ce2c03e05cbbc1558Kay Sievers if (udev_device == NULL)
e9fd44b728ff1fc0d1f24fccb87a767f6865df27Lennart Poettering return NULL;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return udev_device->devpath_old;
e9fd44b728ff1fc0d1f24fccb87a767f6865df27Lennart Poettering}
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poetteringint device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
3040728b6691ea2e9df3a2060e2d49a792bbaedaLennart Poettering{
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering udev_device->devpath_old = strdup(devpath_old);
8ed206517c2be381324ac5832bf34cc14024270eLennart Poettering if (udev_device->devpath_old == NULL)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return -ENOMEM;
e6c6e7afffa80ad74efdb1ddfa815294624f1608Lennart Poettering return 0;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering}
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poetteringconst char *device_get_physdevpath(struct udev_device *udev_device)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering{
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering if (udev_device == NULL)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return NULL;
e5ec62c56963d997edaffa904af5dc45dac23988Lennart Poettering return udev_device->physdevpath;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering}
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringint device_set_physdevpath(struct udev_device *udev_device, const char *physdevpath)
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering{
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering udev_device->physdevpath = strdup(physdevpath);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering if (udev_device->physdevpath == NULL)
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return -ENOMEM;
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return 0;
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering}
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poetteringint device_get_timeout(struct udev_device *udev_device)
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering{
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering if (udev_device == NULL)
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return -1;
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return udev_device->timeout;
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering}
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poetteringint device_set_timeout(struct udev_device *udev_device, int timeout)
b568ef14a75dffb7182e0acbdec743b31df2a597Lennart Poettering{
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poettering udev_device->timeout = timeout;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return 0;
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poettering}
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poetteringint device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering{
57f2a947270faf65e1876797b930e3f6d60ebd06Lennart Poettering udev_device->seqnum = seqnum;
c06bf414042cd1bf94e0af63e9e2a0c291bfc546Kay Sievers return 0;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering}
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poetteringint device_set_devnum(struct udev_device *udev_device, dev_t devnum)
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt{
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering udev_device->devnum = devnum;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return 0;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering}
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering