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