1 /* 2 * Copyright (C) 2017 THL A29 Limited, a Tencent company. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 */ 26 27 #ifndef _FSTACK_EVENT_H 28 #define _FSTACK_EVENT_H 29 30 #ifndef _KERNEL 31 32 #include <stdint.h> 33 #include <sys/queue.h> 34 35 #define EVFILT_READ (-1) 36 #define EVFILT_WRITE (-2) 37 #define EVFILT_AIO (-3) /* attached to aio requests */ 38 #define EVFILT_VNODE (-4) /* attached to vnodes */ 39 #define EVFILT_PROC (-5) /* attached to struct proc */ 40 #define EVFILT_SIGNAL (-6) /* attached to struct proc */ 41 #define EVFILT_TIMER (-7) /* timers */ 42 /* EVFILT_NETDEV (-8) no longer supported */ 43 #define EVFILT_FS (-9) /* filesystem events */ 44 #define EVFILT_LIO (-10) /* attached to lio requests */ 45 #define EVFILT_USER (-11) /* User events */ 46 #define EVFILT_SYSCOUNT 11 47 48 #define EV_SET(kevp_, a, b, c, d, e, f) do { \ 49 struct kevent *kevp = (kevp_); \ 50 (kevp)->ident = (a); \ 51 (kevp)->filter = (b); \ 52 (kevp)->flags = (c); \ 53 (kevp)->fflags = (d); \ 54 (kevp)->data = (e); \ 55 (kevp)->udata = (f); \ 56 } while(0) 57 58 struct kevent { 59 uintptr_t ident; /* identifier for this event */ 60 short filter; /* filter for event */ 61 u_short flags; 62 u_int fflags; 63 intptr_t data; 64 void *udata; /* opaque user data identifier */ 65 }; 66 67 /* actions */ 68 #define EV_ADD 0x0001 /* add event to kq (implies enable) */ 69 #define EV_DELETE 0x0002 /* delete event from kq */ 70 #define EV_ENABLE 0x0004 /* enable event */ 71 #define EV_DISABLE 0x0008 /* disable event (not reported) */ 72 73 /* flags */ 74 #define EV_ONESHOT 0x0010 /* only report one occurrence */ 75 #define EV_CLEAR 0x0020 /* clear event state after reporting */ 76 #define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data=0 */ 77 #define EV_DISPATCH 0x0080 /* disable event after reporting */ 78 79 #define EV_SYSFLAGS 0xF000 /* reserved by system */ 80 #define EV_DROP 0x1000 /* note should be dropped */ 81 #define EV_FLAG1 0x2000 /* filter-specific flag */ 82 83 /* returned values */ 84 #define EV_EOF 0x8000 /* EOF detected */ 85 #define EV_ERROR 0x4000 /* error, data contains errno */ 86 87 /* 88 * data/hint flags/masks for EVFILT_USER, shared with userspace 89 * 90 * On input, the top two bits of fflags specifies how the lower twenty four 91 * bits should be applied to the stored value of fflags. 92 * 93 * On output, the top two bits will always be set to NOTE_FFNOP and the 94 * remaining twenty four bits will contain the stored fflags value. 95 */ 96 #define NOTE_FFNOP 0x00000000 /* ignore input fflags */ 97 #define NOTE_FFAND 0x40000000 /* AND fflags */ 98 #define NOTE_FFOR 0x80000000 /* OR fflags */ 99 #define NOTE_FFCOPY 0xc0000000 /* copy fflags */ 100 #define NOTE_FFCTRLMASK 0xc0000000 /* masks for operations */ 101 #define NOTE_FFLAGSMASK 0x00ffffff 102 103 #define NOTE_TRIGGER 0x01000000 /* Cause the event to be 104 triggered for output. */ 105 106 /* 107 * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace 108 */ 109 #define NOTE_LOWAT 0x0001 /* low water mark */ 110 111 /* 112 * data/hint flags for EVFILT_VNODE, shared with userspace 113 */ 114 #define NOTE_DELETE 0x0001 /* vnode was removed */ 115 #define NOTE_WRITE 0x0002 /* data contents changed */ 116 #define NOTE_EXTEND 0x0004 /* size increased */ 117 #define NOTE_ATTRIB 0x0008 /* attributes changed */ 118 #define NOTE_LINK 0x0010 /* link count changed */ 119 #define NOTE_RENAME 0x0020 /* vnode was renamed */ 120 #define NOTE_REVOKE 0x0040 /* vnode access was revoked */ 121 122 /* 123 * data/hint flags for EVFILT_PROC, shared with userspace 124 */ 125 #define NOTE_EXIT 0x80000000 /* process exited */ 126 #define NOTE_FORK 0x40000000 /* process forked */ 127 #define NOTE_EXEC 0x20000000 /* process exec'd */ 128 #define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */ 129 #define NOTE_PDATAMASK 0x000fffff /* mask for pid */ 130 131 /* additional flags for EVFILT_PROC */ 132 #define NOTE_TRACK 0x00000001 /* follow across forks */ 133 #define NOTE_TRACKERR 0x00000002 /* could not track child */ 134 #define NOTE_CHILD 0x00000004 /* am a child process */ 135 136 struct knote; 137 SLIST_HEAD(klist, knote); 138 struct kqueue; 139 TAILQ_HEAD(kqlist, kqueue); 140 struct knlist { 141 struct klist kl_list; 142 void (*kl_lock)(void *); /* lock function */ 143 void (*kl_unlock)(void *); 144 void (*kl_assert_locked)(void *); 145 void (*kl_assert_unlocked)(void *); 146 void *kl_lockarg; /* argument passed to kl_lockf() */ 147 }; 148 149 #endif 150 #endif 151 152