chiark / gitweb /
udev: hwdb - properly handle a missing database
[elogind.git] / src / libudev / libudev-device.c
index 98077e777de7c4787d4c5d1a47c45c30af17eaed..acf8e24d159abc42d0e9ab9db9d54b1f151921f7 100644 (file)
@@ -1,13 +1,21 @@
-/*
- * libudev - interface to udev device information
- *
- * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- */
+/***
+  This file is part of systemd.
+
+  Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -67,7 +75,7 @@ struct udev_device {
         struct udev_list sysattr_list;
         struct udev_list tags_list;
         unsigned long long int seqnum;
-        unsigned long long int usec_initialized;
+        usec_t usec_initialized;
         int devlink_priority;
         int refcount;
         dev_t devnum;
@@ -246,7 +254,7 @@ static int udev_device_set_devtype(struct udev_device *udev_device, const char *
         return 0;
 }
 
-static int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
+int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
 {
         free(udev_device->subsystem);
         udev_device->subsystem = strdup(subsystem);
@@ -378,12 +386,12 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device,
                 next = strchr(slink, ' ');
                 while (next != NULL) {
                         next[0] = '\0';
-                        udev_device_add_devlink(udev_device, slink, 0);
+                        udev_device_add_devlink(udev_device, slink);
                         slink = &next[1];
                         next = strchr(slink, ' ');
                 }
                 if (slink[0] != '\0')
-                        udev_device_add_devlink(udev_device, slink, 0);
+                        udev_device_add_devlink(udev_device, slink);
         } else if (startswith(property, "TAGS=")) {
                 char tags[UTIL_PATH_SIZE];
                 char *next;
@@ -503,7 +511,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile)
                 switch(line[0]) {
                 case 'S':
                         util_strscpyl(filename, sizeof(filename), "/dev/", val, NULL);
-                        udev_device_add_devlink(udev_device, filename, 0);
+                        udev_device_add_devlink(udev_device, filename);
                         break;
                 case 'L':
                         udev_device_set_devlink_priority(udev_device, atoi(val));
@@ -714,7 +722,25 @@ _public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char
         return udev_device_new_from_syspath(udev, path);
 }
 
-struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id)
+/**
+ * udev_device_new_from_device_id:
+ * @udev: udev library context
+ * @id: text string identifying a kernel device
+ *
+ * Create new udev device, and fill in information from the sys
+ * device and the udev database entry. The device is looked-up
+ * by a special string:
+ *   b8:2          - block device major:minor
+ *   c128:1        - char device major:minor
+ *   n3            - network device ifindex
+ *   +sound:card29 - kernel driver core subsystem:device name
+ *
+ * The initial refcount is 1, and needs to be decremented to
+ * release the resources of the udev device.
+ *
+ * Returns: a new udev device, or #NULL, if it does not exist
+ **/
+_public_ struct udev_device *udev_device_new_from_device_id(struct udev *udev, char *id)
 {
         char type;
         int maj, min;
@@ -1106,7 +1132,7 @@ _public_ const char *udev_device_get_sysname(struct udev_device *udev_device)
  *
  * Get the instance number of the device.
  *
- * Returns: the trailing number string of of the device name
+ * Returns: the trailing number string of the device name
  **/
 _public_ const char *udev_device_get_sysnum(struct udev_device *udev_device)
 {
@@ -1249,7 +1275,7 @@ _public_ const char *udev_device_get_action(struct udev_device *udev_device)
  **/
 _public_ unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device)
 {
-        unsigned long long now_ts;
+        usec_t now_ts;
 
         if (udev_device == NULL)
                 return 0;
@@ -1257,23 +1283,23 @@ _public_ unsigned long long int udev_device_get_usec_since_initialized(struct ud
                 udev_device_read_db(udev_device, NULL);
         if (udev_device->usec_initialized == 0)
                 return 0;
-        now_ts = now_usec();
+        now_ts = now(CLOCK_MONOTONIC);
         if (now_ts == 0)
                 return 0;
         return now_ts - udev_device->usec_initialized;
 }
 
-unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device)
+usec_t udev_device_get_usec_initialized(struct udev_device *udev_device)
 {
         return udev_device->usec_initialized;
 }
 
-void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized)
+void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized)
 {
         char num[32];
 
         udev_device->usec_initialized = usec_initialized;
-        snprintf(num, sizeof(num), "%llu", usec_initialized);
+        snprintf(num, sizeof(num), "%llu", (unsigned long long)usec_initialized);
         udev_device_add_property(udev_device, "USEC_INITIALIZED", num);
 }
 
@@ -1487,7 +1513,7 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode
         return 0;
 }
 
-int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink, int unique)
+int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink)
 {
         struct udev_list_entry *list_entry;
 
@@ -1495,8 +1521,6 @@ int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink
         list_entry = udev_list_entry_add(&udev_device->devlinks_list, devlink, NULL);
         if (list_entry == NULL)
                 return -ENOMEM;
-        if (unique)
-                udev_list_entry_set_num(list_entry, true);
         return 0;
 }