1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> 4 * 5 * This file is created to resolve conflicts between user space and kernel 6 * space fctnl.h declaration. linux/watch_queue.h is not handled, since 7 * user space fcntl.h redefines kernel space structures. 8 */ 9 10 #ifndef LAPI_WATCH_QUEUE_H__ 11 #define LAPI_WATCH_QUEUE_H__ 12 13 #include <stdint.h> 14 #include "lapi/ioctl.h" 15 #include "lapi/fcntl.h" 16 17 #define O_NOTIFICATION_PIPE O_EXCL /* Parameter to pipe2() selecting notification pipe */ 18 19 #define IOC_WATCH_QUEUE_SET_SIZE _IO('W', 0x60) /* Set the size in pages */ 20 #define IOC_WATCH_QUEUE_SET_FILTER _IO('W', 0x61) /* Set the filter */ 21 22 enum watch_notification_type { 23 WATCH_TYPE_META = 0, /* Special record */ 24 WATCH_TYPE_KEY_NOTIFY = 1, /* Key change event notification */ 25 WATCH_TYPE__NR = 2 26 }; 27 28 enum watch_meta_notification_subtype { 29 WATCH_META_REMOVAL_NOTIFICATION = 0, /* Watched object was removed */ 30 WATCH_META_LOSS_NOTIFICATION = 1, /* Data loss occurred */ 31 }; 32 33 /* 34 * Notification record header. This is aligned to 64-bits so that subclasses 35 * can contain __u64 fields. 36 */ 37 struct watch_notification { 38 uint32_t type:24; /* enum watch_notification_type */ 39 uint32_t subtype:8; /* Type-specific subtype (filterable) */ 40 uint32_t info; 41 #define WATCH_INFO_LENGTH 0x0000007f /* Length of record */ 42 #define WATCH_INFO_LENGTH__SHIFT 0 43 #define WATCH_INFO_ID 0x0000ff00 /* ID of watchpoint */ 44 #define WATCH_INFO_ID__SHIFT 8 45 #define WATCH_INFO_TYPE_INFO 0xffff0000 /* Type-specific info */ 46 #define WATCH_INFO_TYPE_INFO__SHIFT 16 47 #define WATCH_INFO_FLAG_0 0x00010000 /* Type-specific info, flag bit 0 */ 48 #define WATCH_INFO_FLAG_1 0x00020000 /* ... */ 49 #define WATCH_INFO_FLAG_2 0x00040000 50 #define WATCH_INFO_FLAG_3 0x00080000 51 #define WATCH_INFO_FLAG_4 0x00100000 52 #define WATCH_INFO_FLAG_5 0x00200000 53 #define WATCH_INFO_FLAG_6 0x00400000 54 #define WATCH_INFO_FLAG_7 0x00800000 55 }; 56 57 /* 58 * Notification filtering rules (IOC_WATCH_QUEUE_SET_FILTER). 59 */ 60 struct watch_notification_type_filter { 61 uint32_t type; /* Type to apply filter to */ 62 uint32_t info_filter; /* Filter on watch_notification::info */ 63 uint32_t info_mask; /* Mask of relevant bits in info_filter */ 64 uint32_t subtype_filter[8]; /* Bitmask of subtypes to filter on */ 65 }; 66 67 struct watch_notification_filter { 68 uint32_t nr_filters; /* Number of filters */ 69 uint32_t __reserved; /* Must be 0 */ 70 struct watch_notification_type_filter filters[]; 71 }; 72 73 74 /* 75 * Extended watch removal notification. This is used optionally if the type 76 * wants to indicate an identifier for the object being watched, if there is 77 * such. This can be distinguished by the length. 78 * 79 * type -> WATCH_TYPE_META 80 * subtype -> WATCH_META_REMOVAL_NOTIFICATION 81 */ 82 struct watch_notification_removal { 83 struct watch_notification watch; 84 uint64_t id; /* Type-dependent identifier */ 85 }; 86 87 /* 88 * Type of key/keyring change notification. 89 */ 90 enum key_notification_subtype { 91 NOTIFY_KEY_INSTANTIATED = 0, /* Key was instantiated (aux is error code) */ 92 NOTIFY_KEY_UPDATED = 1, /* Key was updated */ 93 NOTIFY_KEY_LINKED = 2, /* Key (aux) was added to watched keyring */ 94 NOTIFY_KEY_UNLINKED = 3, /* Key (aux) was removed from watched keyring */ 95 NOTIFY_KEY_CLEARED = 4, /* Keyring was cleared */ 96 NOTIFY_KEY_REVOKED = 5, /* Key was revoked */ 97 NOTIFY_KEY_INVALIDATED = 6, /* Key was invalidated */ 98 NOTIFY_KEY_SETATTR = 7, /* Key's attributes got changed */ 99 }; 100 101 /* 102 * Key/keyring notification record. 103 * - watch.type = WATCH_TYPE_KEY_NOTIFY 104 * - watch.subtype = enum key_notification_type 105 */ 106 struct key_notification { 107 struct watch_notification watch; 108 uint32_t key_id; /* The key/keyring affected */ 109 uint32_t aux; /* Per-type auxiliary data */ 110 }; 111 112 #endif /* LAPI_WATCH_QUEUE_H__ */ 113