device-private.c revision 401cb61499f446c7c1579a160eeef435afd525fd
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2014 Tom Gundersen <teg@jklm.no>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint device_add_property(sd_device *device, const char *key, const char *value) {
d3e84ddb885e9d5f0ae9930eb905910e3a81f157Lennart Poettering r = device_add_property_aux(device, key, value, false);
afc6adb5ec7e73bc13156c43f52fb015cd80cc68Lennart Poettering r = device_add_property_aux(device, key, value, true);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int device_add_property_internal_from_string(sd_device *device, const char *str) {
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering return device_add_property_internal(device, key, value);
d04c1fb8e215600b4950c6778c6c16ddafc14024Lennart Poetteringstatic int handle_db_line(sd_device *device, char key, const char *value) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = safe_atoi(value, &device->devlink_priority);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = device_add_property_internal_from_string(device, value);
b87633c4b20e3221748d6c98336cf6c85123cd66Lennart Poettering r = safe_atoi(value, &device->watch_handle);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = device_set_usec_initialized(device, value);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_debug("device db: unknown key '%c'", key);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringvoid device_set_devlink_priority(sd_device *device, int priority) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringvoid device_set_is_initialized(sd_device *device) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint device_ensure_usec_initialized(sd_device *device, sd_device *device_old) {
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt if (device_old && device_old->usec_initialized > 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering usec_initialized = device_old->usec_initialized;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = snprintf(num, sizeof(num), USEC_FMT, usec_initialized);
ebeccf9eecf5939a2ef772c3160e89efcad96194Lennart Poettering r = device_set_usec_initialized(device, num);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poetteringstatic int device_read_db(sd_device *device) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_debug("sd-device: failed to read db '%s': %s", path, strerror(-r));
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering /* devices with a database entry are initialized */
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering for (i = 0; i < db_len; i++) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering log_debug("sd-device: ignoring invalid db entry with key '%c'", key);
49f3fffd94591bdf2bd6c2233a9300daeab79566Lennart Poettering log_debug("sd-device: failed to handle db entry '%c:%s': %s", key, value, strerror(-r));
49f3fffd94591bdf2bd6c2233a9300daeab79566Lennart Poettering assert_not_reached("invalid state when parsing db");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringuint64_t device_get_properties_generation(sd_device *device) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringuint64_t device_get_tags_generation(sd_device *device) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringuint64_t device_get_devlinks_generation(sd_device *device) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint device_get_devnode_mode(sd_device *device, mode_t *mode) {
d9e34bfda3d34dcde00a876cb052e7de0655e1cbLennart Poetteringint device_get_devnode_uid(sd_device *device, uid_t *uid) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int device_set_devuid(sd_device *device, const char *uid) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = device_add_property_internal(device, "DEVUID", uid);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poetteringint device_get_devnode_gid(sd_device *device, gid_t *gid) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int device_set_devgid(sd_device *device, const char *gid) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = device_add_property_internal(device, "DEVGID", gid);
char *path;
size_t l;
char *devlink;
size_t l;
char *tag;
static int device_append(sd_device *device, char *key, const char **_major, const char **_minor, uint64_t *_seqnum,
char *value;
if (!value) {
return -EINVAL;
value++;
return -EINVAL;
else if (seqnum == 0)
return -EINVAL;
if (major != 0)
if (minor != 0)
if (seqnum > 0)
return -EINVAL;
char **key;
if (major) {
while (i < len) {
char *key;
const char *end;
if (!end) {
return -EINVAL;
if (major) {
if (!buf_nulstr)
return -ENOMEM;
if (!buf_strv)
return -ENOMEM;
char *new_syspath;
const char *interface;
if (!dirname)
return -ENOMEM;
/* like DEVPATH_OLD, INTERFACE_OLD is not saved to the db, but only stays around for the current event */
} else if (r != -ENOENT)
int device_new_from_synthetic_event(sd_device **new_device, const char *syspath, const char *action) {
const char *id;
char *path;
if (add) {
return -errno;
const char *tag;
const char *id;
char *path;
bool has_info;
return -errno;
r = -errno;
goto fail;
r = -errno;
goto fail;
if (has_info) {
Iterator i;
const char *devlink;
r = fflush_and_check(f);
goto fail;
r = -errno;
goto fail;
fail:
const char *id;
char *path;
return -errno;