]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/device.h
core: rework how device units get set up
[thirdparty/systemd.git] / src / core / device.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2010 Lennart Poettering
8 ***/
9
10 #include "unit.h"
11
12 typedef struct Device Device;
13
14 /* A mask specifying where we have seen the device currently. This is a bitmask because the device might show up
15 * asynchronously from each other at various places. For example, in very common case a device might already be mounted
16 * before udev finished probing it (think: a script setting up a loopback block device, formatting it and mounting it
17 * in quick succession). Hence we need to track precisely where it is already visible and where not. */
18 typedef enum DeviceFound {
19 DEVICE_NOT_FOUND = 0,
20 DEVICE_FOUND_UDEV = 1U << 1, /* The device has shown up in the udev database */
21 DEVICE_FOUND_MOUNT = 1U << 2, /* The device has shown up in /proc/self/mountinfo */
22 DEVICE_FOUND_SWAP = 1U << 3, /* The device has shown up in /proc/swaps */
23 DEVICE_FOUND_MASK = DEVICE_FOUND_UDEV|DEVICE_FOUND_MOUNT|DEVICE_FOUND_SWAP,
24 } DeviceFound;
25
26 struct Device {
27 Unit meta;
28
29 char *sysfs;
30
31 /* In order to be able to distinguish dependencies on different device nodes we might end up creating multiple
32 * devices for the same sysfs path. We chain them up here. */
33 LIST_FIELDS(struct Device, same_sysfs);
34
35 DeviceState state, deserialized_state;
36 DeviceFound found, deserialized_found, enumerated_found;
37
38 bool bind_mounts;
39 };
40
41 extern const UnitVTable device_vtable;
42
43 void device_found_node(Manager *m, const char *node, DeviceFound found, DeviceFound mask);
44 bool device_shall_be_bound_by(Unit *device, Unit *u);
45
46 DEFINE_CAST(DEVICE, Device);