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