Debian Codegraph @

src/libsystemd/sd-id128/id128-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-id128.h"
5
6 #include "errno-util.h"
7 #include "sd-forward.h"
8
9 bool id128_is_valid(const char *s) _pure_;
10
11 typedef enum Id128Flag {
12 ID128_FORMAT_PLAIN = 1 << 0, /* formatted as 32 hex chars as-is */
13 ID128_FORMAT_UUID = 1 << 1, /* formatted as 36 character uuid string */
14 ID128_FORMAT_ANY = ID128_FORMAT_PLAIN | ID128_FORMAT_UUID,
15
16 ID128_SYNC_ON_WRITE = 1 << 2, /* Sync the file after write. Used only when writing an ID. */
17 ID128_REFUSE_NULL = 1 << 3, /* Refuse all zero ID with -ENOMEDIUM. */
18 } Id128Flag;
19
20 int id128_from_string_nonzero(const char *s, sd_id128_t *ret);
21
22 int id128_read_fd(int fd, Id128Flag f, sd_id128_t *ret);
23 int id128_read_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t *ret);
24 static inline int id128_read(const char *path, Id128Flag f, sd_id128_t *ret) {
25 return id128_read_at(AT_FDCWD, path, f, ret);
26 }
27
28 int id128_write_fd(int fd, Id128Flag f, sd_id128_t id);
29 int id128_write_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t id);
30 static inline int id128_write(const char *path, Id128Flag f, sd_id128_t id) {
31 return id128_write_at(AT_FDCWD, path, f, id);
32 }
33
34 int id128_get_machine(const char *root, sd_id128_t *ret);
35 int id128_get_machine_at(int rfd, sd_id128_t *ret);
36
37 void id128_hash_func(const sd_id128_t *p, struct siphash *state);
38 int id128_compare_func(const sd_id128_t *a, const sd_id128_t *b) _pure_;
39 extern const struct hash_ops id128_hash_ops;
40 extern const struct hash_ops id128_hash_ops_free;
41
42 sd_id128_t id128_make_v4_uuid(sd_id128_t id);
43
44 int id128_get_product(sd_id128_t *ret);
45
46 sd_id128_t id128_digest(const void *data, size_t size);
47
48 int id128_get_boot(sd_id128_t *ret);
49 int id128_get_boot_for_machine(const char *machine, sd_id128_t *ret);
50
51 /* A helper to check for the three relevant cases of "machine ID not initialized" */
52 #define ERRNO_IS_NEG_MACHINE_ID_UNSET(r) \
53 IN_SET(r, \
54 -ENOENT, \
55 -ENOMEDIUM, \
56 -ENOPKG)
57 _DEFINE_ABS_WRAPPER(MACHINE_ID_UNSET);