57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/***
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen This file is part of systemd.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Copyright 2014 Tom Gundersen <teg@jklm.no>
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen systemd is free software; you can redistribute it and/or modify it
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen under the terms of the GNU Lesser General Public License as published by
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen (at your option) any later version.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen systemd is distributed in the hope that it will be useful, but
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Lesser General Public License for more details.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen You should have received a copy of the GNU Lesser General Public License
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen***/
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#pragma once
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#include "hashmap.h"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#include "set.h"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstruct sd_device {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t n_ref;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen sd_device *parent;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool parent_set; /* no need to try to reload parent */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen OrderedHashmap *properties;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Iterator properties_iterator;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t properties_generation; /* changes whenever the properties are changed */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t properties_iterator_generation; /* generation when iteration was started */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* the subset of the properties that should be written to the db*/
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen OrderedHashmap *properties_db;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Hashmap *sysattr_values; /* cached sysattr values */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Set *sysattrs; /* names of sysattrs */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Iterator sysattrs_iterator;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool sysattrs_read; /* don't try to re-read sysattrs once read */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Set *tags;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Iterator tags_iterator;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t tags_generation; /* changes whenever the tags are changed */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t tags_iterator_generation; /* generation when iteration was started */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool property_tags_outdated; /* need to update TAGS= property */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Set *devlinks;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Iterator devlinks_iterator;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t devlinks_generation; /* changes whenever the devlinks are changed */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t devlinks_iterator_generation; /* generation when iteration was started */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool property_devlinks_outdated; /* need to update DEVLINKS= property */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen int devlink_priority;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char **properties_strv; /* the properties hashmap as a strv */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint8_t *properties_nulstr; /* the same as a nulstr */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen size_t properties_nulstr_len;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool properties_buf_outdated; /* need to reread hashmap */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen int watch_handle;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *syspath;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen const char *devpath;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen const char *sysnum;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *sysname;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool sysname_set; /* don't reread sysname */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *devtype;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen int ifindex;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *devname;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dev_t devnum;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *subsystem;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool subsystem_set; /* don't reread subsystem */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *driver;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool driver_set; /* don't reread driver */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *id_filename;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool is_initialized;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t usec_initialized;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mode_t devmode;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uid_t devuid;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen gid_t devgid;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool uevent_loaded; /* don't reread uevent */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool db_loaded; /* don't reread db */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool sealed; /* don't read more information from uevent/db */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool db_persist; /* don't clean up the db when switching from initrd to real root */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen};
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentypedef enum DeviceAction {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen DEVICE_ACTION_ADD,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen DEVICE_ACTION_REMOVE,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen DEVICE_ACTION_CHANGE,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen DEVICE_ACTION_MOVE,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen DEVICE_ACTION_ONLINE,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen DEVICE_ACTION_OFFLINE,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen _DEVICE_ACTION_MAX,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen _DEVICE_ACTION_INVALID = -1,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen} DeviceAction;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_new_aux(sd_device **ret);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_add_property_aux(sd_device *device, const char *key, const char *value, bool db);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_add_property_internal(sd_device *device, const char *key, const char *value);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_read_uevent_file(sd_device *device);
107f2e2526d476c6cc9b81a690391c111027d641Tom Gundersenint device_read_db_aux(sd_device *device, bool force);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_syspath(sd_device *device, const char *_syspath, bool verify);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_ifindex(sd_device *device, const char *ifindex);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_devmode(sd_device *device, const char *devmode);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_devname(sd_device *device, const char *_devname);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_devtype(sd_device *device, const char *_devtype);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_devnum(sd_device *device, const char *major, const char *minor);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_subsystem(sd_device *device, const char *_subsystem);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_driver(sd_device *device, const char *_driver);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint device_set_usec_initialized(sd_device *device, const char *initialized);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenDeviceAction device_action_from_string(const char *s) _pure_;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenconst char *device_action_to_string(DeviceAction a) _const_;