libudev-device.c revision 88a6477ef32ac4c59111f7340525714a6e02e503
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * SECTION:libudev-device
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * @short_description: kernel sys devices
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * Representation of kernel sys devices. Devices are uniquely identified
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * by their syspath, every device has exactly one path in the kernel sys
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * filesystem. Devices usually belong to a kernel subsystem, and and have
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * a unique name inside that subsystem.
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * udev_device:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * Opaque object representing one kernel sys device.
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering unsigned long long int seqnum;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * udev_device_get_seqnum:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * @udev_device: udev device
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * This is only valid if the device was received through a monitor. Devices read from
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * sys do not have a sequence number.
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * Returns: the kernel event sequence number, or 0 if there is no sequence number available.
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering_public_ unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering snprintf(num, sizeof(num), "%llu", seqnum);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering udev_device_add_property(udev_device, "SEQNUM", num);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint udev_device_get_ifindex(struct udev_device *udev_device)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering udev_device_read_uevent_file(udev_device);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int udev_device_set_ifindex(struct udev_device *udev_device, int ifindex)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering snprintf(num, sizeof(num), "%u", ifindex);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering udev_device_add_property(udev_device, "IFINDEX", num);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering * udev_device_get_devnum:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering * @udev_device: udev device
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering * Get the device major/minor number.
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering * Returns: the dev_t number.
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering_public_ dev_t udev_device_get_devnum(struct udev_device *udev_device)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering udev_device_read_uevent_file(udev_device);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringstatic int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering snprintf(num, sizeof(num), "%u", major(devnum));
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device_add_property(udev_device, "MAJOR", num);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering snprintf(num, sizeof(num), "%u", minor(devnum));
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device_add_property(udev_device, "MINOR", num);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringconst char *udev_device_get_devpath_old(struct udev_device *udev_device)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringstatic int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device->devpath_old = strdup(devpath_old);
23432a1c249b9c513e438bffe9778a7ce2ee74feZbigniew Jędrzejewski-Szmek if (udev_device->devpath_old == NULL)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering pos = strrchr(udev_device->devpath_old, '/');
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * udev_device_get_driver:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @udev_device: udev device
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Get the kernel driver name.
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * Returns: the driver name string, or #NULL if there is no driver attached.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering_public_ const char *udev_device_get_driver(struct udev_device *udev_device)
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering if (util_get_sys_core_link_value(udev_device->udev, "driver", udev_device->syspath, driver, sizeof(driver)) > 0)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int udev_device_set_driver(struct udev_device *udev_device, const char *driver)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering udev_device_add_property(udev_device, "DRIVER", udev_device->driver);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * udev_device_get_devtype:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @udev_device: udev device
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Retrieve the devtype string of the udev device.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Returns: the devtype name of the udev device, or #NULL if it can not be determined
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering_public_ const char *udev_device_get_devtype(struct udev_device *udev_device)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering udev_device_read_uevent_file(udev_device);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic int udev_device_set_devtype(struct udev_device *udev_device, const char *devtype)
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek udev_device->devtype = strdup(devtype);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek udev_device->devtype_set = true;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering udev_device_add_property(udev_device, "DEVTYPE", udev_device->devtype);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmekint udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering udev_device->subsystem = strdup(subsystem);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek udev_device_add_property(udev_device, "SUBSYSTEM", udev_device->subsystem);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering * udev_device_get_subsystem:
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering * @udev_device: udev device
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek * Retrieve the subsystem string of the udev device. The string does not
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek * contain any "/".
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek * Returns: the subsystem name of the udev device, or #NULL if it can not be determined
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek_public_ const char *udev_device_get_subsystem(struct udev_device *udev_device)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* read "subsystem" link */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (util_get_sys_core_link_value(udev_device->udev, "subsystem", udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering udev_device_set_subsystem(udev_device, subsystem);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering /* implicit names */
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (startswith(udev_device->devpath, "/module/")) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering udev_device_set_subsystem(udev_device, "module");
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (strstr(udev_device->devpath, "/drivers/") != NULL) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering udev_device_set_subsystem(udev_device, "drivers");
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (startswith(udev_device->devpath, "/subsystem/") ||
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering startswith(udev_device->devpath, "/class/") ||
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering startswith(udev_device->devpath, "/bus/")) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering udev_device_set_subsystem(udev_device, "subsystem");
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringmode_t udev_device_get_devnode_mode(struct udev_device *udev_device)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering udev_device_read_uevent_file(udev_device);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringstatic int udev_device_set_devnode_mode(struct udev_device *udev_device, mode_t mode)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering udev_device_add_property(udev_device, "DEVMODE", num);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringstruct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering list_entry = udev_device_get_properties_list_entry(udev_device);
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering list_entry = udev_list_entry_get_by_name(list_entry, key);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return udev_list_entry_add(&udev_device->properties_list, key, value);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poetteringstatic struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering util_strscpy(name, sizeof(name), property);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return udev_device_add_property(udev_device, name, val);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek * parse property string, and if needed, update internal values accordingly
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek * udev_device_add_property_from_string_parse_finish() needs to be
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek * called after adding properties, and its return value checked
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek * udev_device_set_info_loaded() needs to be set, to avoid trying
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek * to use a device without a DEVPATH set
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmekvoid udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering util_strscpyl(path, sizeof(path), "/sys", &property[8], NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device_set_syspath(udev_device, path);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering } else if (startswith(property, "SUBSYSTEM=")) {
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering udev_device_set_subsystem(udev_device, &property[10]);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering } else if (startswith(property, "DEVTYPE=")) {
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering udev_device_set_devtype(udev_device, &property[8]);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering } else if (startswith(property, "DEVNAME=")) {
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering udev_device_set_devnode(udev_device, &property[8]);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering } else if (startswith(property, "DEVLINKS=")) {
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering util_strscpy(devlinks, sizeof(devlinks), &property[9]);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek udev_device_add_devlink(udev_device, slink);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_add_devlink(udev_device, slink);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "TAGS=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek util_strscpy(tags, sizeof(tags), &property[5]);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "USEC_INITIALIZED=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_usec_initialized(udev_device, strtoull(&property[19], NULL, 10));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "DRIVER=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_driver(udev_device, &property[7]);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "ACTION=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_action(udev_device, &property[7]);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "MAJOR=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device->maj = strtoull(&property[6], NULL, 10);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "MINOR=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device->min = strtoull(&property[6], NULL, 10);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "DEVPATH_OLD=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_devpath_old(udev_device, &property[12]);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "SEQNUM=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_seqnum(udev_device, strtoull(&property[7], NULL, 10));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "IFINDEX=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (startswith(property, "DEVMODE=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_devnode_mode(udev_device, strtoul(&property[8], NULL, 8));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_add_property_from_string(udev_device, property);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmekint udev_device_add_property_from_string_parse_finish(struct udev_device *udev_device)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_devnum(udev_device, makedev(udev_device->maj, udev_device->min));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (udev_device->devpath == NULL || udev_device->subsystem == NULL)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * udev_device_get_property_value:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering * @udev_device: udev device
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * @key: property name
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * Get the value of a given property.
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek * Returns: the property string, or #NULL if there is no such property.
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering_public_ const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering list_entry = udev_device_get_properties_list_entry(udev_device);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering list_entry = udev_list_entry_get_by_name(list_entry, key);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return udev_list_entry_get_value(list_entry);
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poetteringint udev_device_read_db(struct udev_device *udev_device, const char *dbfile)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* providing a database file will always force-load it */
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek id = udev_device_get_id_filename(udev_device);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek util_strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek udev_dbg(udev_device->udev, "no db file to read %s: %m\n", dbfile);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek udev_device->is_initialized = true;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering util_strscpyl(filename, sizeof(filename), "/dev/", val, NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device_add_devlink(udev_device, filename);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device_set_devlink_priority(udev_device, atoi(val));
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering entry = udev_device_add_property_from_string(udev_device, val);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device_set_watch_handle(udev_device, atoi(val));
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device_set_usec_initialized(udev_device, strtoull(val, NULL, 10));
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_dbg(udev_device->udev, "device %p filled with db file data\n", udev_device);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint udev_device_read_uevent_file(struct udev_device *udev_device)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek util_strscpyl(filename, sizeof(filename), udev_device->syspath, "/uevent", NULL);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device->uevent_loaded = true;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek while (fgets(line, sizeof(line), f)) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (startswith(line, "DEVTYPE=")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_device_set_devtype(udev_device, &line[8]);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (startswith(line, "IFINDEX=")) {
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10));
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering udev_device_set_devnode(udev_device, &line[8]);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering udev_device->devnode_mode = strtoul(&line[8], NULL, 8);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering udev_device_add_property_from_string(udev_device, line);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringvoid udev_device_set_info_loaded(struct udev_device *device)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringstruct udev_device *udev_device_new(struct udev *udev)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_device = calloc(1, sizeof(struct udev_device));
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_list_init(udev, &udev_device->devlinks_list, true);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_list_init(udev, &udev_device->properties_list, true);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_list_init(udev, &udev_device->sysattr_value_list, true);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering udev_list_init(udev, &udev_device->sysattr_list, false);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_list_init(udev, &udev_device->tags_list, true);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* copy global properties */
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * udev_device_new_from_syspath:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * @udev: udev library context
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering * @syspath: sys device path including sys directory
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * Create new udev device, and fill in information from the sys
const char *subdir;
char *pos;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return udev_device;
_public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
const char *type_str;
return NULL;
char type;
char *sysname;
switch(id[0]) {
return NULL;
int sk;
int ifindex;
if (ifindex <= 0)
return NULL;
if (sk < 0)
return NULL;
return NULL;
return NULL;
return dev;
return NULL;
return NULL;
return NULL;
_public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname)
goto found;
goto found;
goto found;
goto out;
goto found;
goto out;
char *driver;
goto found;
goto found;
goto out;
goto found;
goto found;
goto found;
out:
return NULL;
return NULL;
return udev_device;
const char *subdir;
char *pos;
return udev_device_parent;
return NULL;
return NULL;
_public_ struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype)
return NULL;
const char *parent_subsystem;
const char *parent_devtype;
return parent;
return NULL;
return NULL;
return udev_device;
return NULL;
return udev_device;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
_public_ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device)
return NULL;
_public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device)
return NULL;
size_t l;
s = symlinks;
size_t l;
s = tags;
return NULL;
_public_ unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device)
if (now_ts == 0)
_public_ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr)
int fd;
return NULL;
return NULL;
goto out;
return NULL;
goto out;
goto out;
goto out;
goto out;
if (fd < 0)
goto out;
if (size < 0)
goto out;
goto out;
out:
return val;
int num = 0;
if (!dir)
num++;
return num;
_public_ struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device)
int ret;
if (0 > ret)
return NULL;
const char *pos;
return -ENOMEM;
return -EINVAL;
return -ENOMEM;
len = 0;
len++;
if (len == 0)
return -ENOMEM;
return -ENOMEM;
return NULL;
const char *sysname;
return NULL;
if (asprintf(&udev_device->id_filename, "+%s:%s", udev_device_get_subsystem(udev_device), sysname) < 0)
return -EINVAL;
return -ENOMEM;
return NULL;
size_t l;
return -ENOMEM;
return -ENOMEM;
l = MONITOR_BUF_SIZE;
const char *key;
return -EINVAL;
return -EINVAL;
return NULL;
return -EINVAL;
return -ENOMEM;