]> git.sesse.net Git - bcachefs-tools-debian/blob - c_src/include/linux/key.h
rust: bump rpassword to v7.x
[bcachefs-tools-debian] / c_src / include / linux / key.h
1 #ifndef _LINUX_KEY_H
2 #define _LINUX_KEY_H
3
4 #include <linux/types.h>
5 #include <linux/atomic.h>
6 #include <keyutils.h>
7
8 struct user_key_payload {
9         size_t          datalen;        /* length of this data */
10         char            data[0];        /* actual data */
11 };
12
13 struct key {
14         atomic_t                usage;          /* number of references */
15         key_serial_t            serial;         /* key serial number */
16         struct rw_semaphore     sem;            /* change vs change sem */
17         struct user_key_payload payload;
18 };
19
20 static inline const struct user_key_payload *user_key_payload(const struct key *key)
21 {
22         return &key->payload;
23 }
24
25 static inline void key_put(struct key *key)
26 {
27         if (atomic_dec_and_test(&key->usage))
28                 free(key);
29 }
30
31 static inline struct key *__key_get(struct key *key)
32 {
33         atomic_inc(&key->usage);
34         return key;
35 }
36
37 static inline struct key *key_get(struct key *key)
38 {
39         return key ? __key_get(key) : key;
40 }
41
42 #endif /* _LINUX_KEY_H */