libudev-device.c revision bc8184ede9cff156709fe053e3e02ef309cb2920
d4e7da6e9164ba18433755b68bbc8bc6354f0c04Eugen Kuksa * libudev - interface to udev device information
af313f59287bea73d6e453a1bdb397c3f68c3160Jonathan von Schroeder * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
167d70cbaefa2fcc045ffde6fb4b826524c1c7a9Christian Maeder * This program is free software: you can redistribute it and/or modify
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner * it under the terms of the GNU General Public License as published by
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner * the Free Software Foundation, either version 2 of the License, or
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner * (at your option) any later version.
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner * This program is distributed in the hope that it will be useful,
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner * but WITHOUT ANY WARRANTY; without even the implied warranty of
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner * GNU General Public License for more details.
6a6306c583c71d23b47101b59d7c9348d181ba57Eugen Kuksa * You should have received a copy of the GNU General Public License
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner * along with this program. If not, see <http://www.gnu.org/licenses/>.
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder unsigned long long int seqnum;
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederstatic size_t syspath_to_db_path(struct udev_device *udev_device, char *filename, size_t len)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder /* translate to location of db file */
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder util_strlcpy(filename, udev_get_dev_path(udev_device->udev), len);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder start = util_strlcat(filename, "/.udev/db/", len);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder util_strlcat(filename, udev_device->devpath, len);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder return util_path_encode(&filename[start], len - start);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederstatic int device_read_db(struct udev_device *udev_device)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder syspath_to_db_path(udev_device, filename, sizeof(filename));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder info(udev_device->udev, "no db file to read %s: %s\n", filename, strerror(errno));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if ((stats.st_mode & S_IFMT) == S_IFLNK) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder target_len = readlink(filename, target, sizeof(target));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder info(udev_device->udev, "error reading db link %s: %s\n", filename, strerror(errno));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if (asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), target) < 0)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder info(udev_device->udev, "device %p filled with db symlink data '%s'\n", udev_device, udev_device->devnode);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder info(udev_device->udev, "error reading db file %s: %s\n", filename, strerror(errno));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder while (fgets(line, sizeof(line), f)) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), val);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder util_strlcpy(filename, udev_get_dev_path(udev_device->udev), sizeof(filename));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder util_strlcat(filename, "/", sizeof(filename));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder util_strlcat(filename, val, sizeof(filename));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder device_add_devlink(udev_device, filename);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder device_set_devlink_priority(udev_device, atoi(val));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder device_set_event_timeout(udev_device, atoi(val));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder device_set_num_fake_partitions(udev_device, atoi(val));
8d632882ae6a59db929b7f87816da6c4d795594eJonathan von Schroeder device_set_ignore_remove(udev_device, atoi(val));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder device_add_property_from_string(udev_device, val);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder info(udev_device->udev, "device %p filled with db file data\n", udev_device);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederstatic int device_read_uevent_file(struct udev_device *udev_device)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder util_strlcpy(filename, udev_device->syspath, sizeof(filename));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder util_strlcat(filename, "/uevent", sizeof(filename));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder while (fgets(line, sizeof(line), f)) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder else if (strncmp(line, "MINOR=", 6) == 0)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder device_add_property_from_string(udev_device, line);
6aad75f5233b1f80eb84f53395f7bb44e9ed7b88Jonathan von Schroeder udev_device->devnum = makedev(maj, min);
5d8372f2459037830704c3f48d2b566ee1f35e31cmaederstatic void device_load_info(struct udev_device *device)
a389e88e0acb83d8489bdc5e55bc5522b152bbecEugen Kuksavoid device_set_info_loaded(struct udev_device *device)
return NULL;
return NULL;
return udev_device;
const char *subdir;
const char *pos;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return udev_device;
const char *type_str;
return NULL;
return NULL;
const char *subsystem;
return device;
const char *subdir;
return udev_device_parent;
char *pos;
return udev_device_parent;
return NULL;
return NULL;
return NULL;
return NULL;
return udev_device;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return makedev(0, 0);
return NULL;
int fd;
goto out;
int len;
char *pos;
if (len > 0) {
goto out;
goto out;
goto out;
if (fd < 0) {
goto out;
if (size < 0)
goto out;
goto out;
out:
return val;
const char *pos;
return -ENOMEM;
return -EINVAL;
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
char *val;
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;