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