xref: /xnu-11215.41.3/bsd/sys/fsevents.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1 /*
2  * Copyright (c) 2000-2021 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 #ifndef FSEVENT_H
29 #define FSEVENT_H 1
30 
31 #include <stdint.h>
32 #include <sys/types.h>
33 
34 // Event types that you can ask to listen for
35 #define FSE_INVALID             -1
36 #define FSE_CREATE_FILE          0
37 #define FSE_DELETE               1
38 #define FSE_STAT_CHANGED         2
39 #define FSE_RENAME               3
40 #define FSE_CONTENT_MODIFIED     4
41 #define FSE_EXCHANGE             5
42 #define FSE_FINDER_INFO_CHANGED  6
43 #define FSE_CREATE_DIR           7
44 #define FSE_CHOWN                8
45 #define FSE_XATTR_MODIFIED       9
46 #define FSE_XATTR_REMOVED       10
47 #define FSE_DOCID_CREATED       11
48 #define FSE_DOCID_CHANGED       12
49 #define FSE_UNMOUNT_PENDING     13 // iOS-only: client must respond via FSEVENTS_UNMOUNT_PENDING_ACK
50 #define FSE_CLONE               14
51 
52 #define FSE_ACTIVITY            15
53 #define FSE_ACTIVITY_VERSION_1  1
54 
55 #define FSE_ACTIVITY_ATTR_DEV            0x00000001
56 #define FSE_ACTIVITY_ATTR_INO            0x00000002
57 #define FSE_ACTIVITY_ATTR_ORIGIN_ID      0x00000004
58 #define FSE_ACTIVITY_ATTR_AGE            0x00000008
59 #define FSE_ACTIVITY_ATTR_USE_STATE      0x00000010
60 #define FSE_ACTIVITY_ATTR_URGENCY        0x00000020
61 #define FSE_ACTIVITY_ATTR_SIZE           0x00000040
62 
63 #define FSE_MAX_EVENTS          16
64 #define FSE_ACCESS_GRANTED      FSE_INVALID
65 #ifdef BSD_KERNEL_PRIVATE
66 #define FSE_CONTENT_MODIFIED_NO_HLINK  997
67 #endif /* BSD_KERNEL_PRIVATE */
68 #define FSE_ALL_EVENTS         998
69 
70 #define FSE_EVENTS_DROPPED     999
71 
72 //
73 // These defines only apply if you've asked for extended
74 // type info.  In that case the type field's low 12-bits
75 // contain the basic types defined above and the top 4
76 // bits contain flags that indicate if an event had other
77 // events combined with it or if it represents a directory
78 // that has dropped events below it.
79 //
80 #define FSE_TYPE_MASK          0x0fff
81 #define FSE_FLAG_MASK          0xf000
82 #define FSE_FLAG_SHIFT         12
83 #define FSE_GET_FLAGS(type)    (((type) >> 12) & 0x000f)
84 
85 #define FSE_COMBINED_EVENTS          0x0001
86 #define FSE_CONTAINS_DROPPED_EVENTS  0x0002
87 
88 
89 // Actions for each event type
90 #define FSE_IGNORE    0
91 #define FSE_REPORT    1
92 #define FSE_ASK       2    // Not implemented yet
93 
94 // The default disposition is to not report FSE_ACCESS_GRANTED
95 // events.  (They are not useful to the vast majority of
96 // /dev/fsevents clients.)
97 #define FSE_REPORT_DEFAULT(e) \
98     ((e) == FSE_ACCESS_GRANTED ? FSE_IGNORE : FSE_REPORT)
99 
100 // The types of each of the arguments for an event
101 // Each type is followed by the size and then the
102 // data.  FSE_ARG_VNODE is just a path string
103 // FSE_ARG_AUDIT_TOKEN is only delivered on FSE_ACCESS_GRANTED
104 // events.
105 #define FSE_ARG_VNODE    0x0001   // next arg is a vnode pointer
106 #define FSE_ARG_STRING   0x0002   // next arg is length followed by string ptr
107 #define FSE_ARG_PATH     0x0003   // next arg is a full path
108 #define FSE_ARG_INT32    0x0004   // next arg is a 32-bit int
109 #define FSE_ARG_INT64    0x0005   // next arg is a 64-bit int
110 #define FSE_ARG_RAW      0x0006   // next arg is a length followed by a void ptr
111 #define FSE_ARG_INO      0x0007   // next arg is the inode number (ino_t)
112 #define FSE_ARG_UID      0x0008   // next arg is the file's uid (uid_t)
113 #define FSE_ARG_DEV      0x0009   // next arg is the file's dev_t
114 #define FSE_ARG_MODE     0x000a   // next arg is the file's mode (as an int32, file type only)
115 #define FSE_ARG_GID      0x000b   // next arg is the file's gid (gid_t)
116 #define FSE_ARG_FINFO    0x000c   // next arg is a packed finfo (dev, ino, mode, uid, gid)
117 #define FSE_ARG_AUDIT_TOKEN 0x000d // next arg is an audit_token_t ptr
118 #define FSE_ARG_DONE     0xb33f   // no more arguments
119 
120 #define FSE_MAX_ARGS     13
121 
122 //
123 // These are special bits that be set in the 32-bit mode
124 // field that /dev/fsevents provides.
125 //
126 #define FSE_MODE_HLINK         (1U << 31)    // notification is for a hard-link
127 #define FSE_MODE_LAST_HLINK    (1U << 30)    // link count == 0 on a hard-link delete
128 #define FSE_REMOTE_DIR_EVENT   (1U << 29)    // this is a remotely generated directory-level granularity event
129 #define FSE_TRUNCATED_PATH     (1U << 28)    // the path for this item had to be truncated
130 #define FSE_MODE_CLONE         (1U << 27)    // notification is for a clone
131 
132 // ioctl's on /dev/fsevents
133 typedef struct fsevent_clone_args {
134 	int8_t  *event_list;
135 	int32_t  num_events;
136 	int32_t  event_queue_depth;
137 	int32_t *fd;
138 } fsevent_clone_args;
139 
140 #define FSEVENTS_CLONE          _IOW('s', 1, fsevent_clone_args)
141 
142 
143 // ioctl's on the cloned fd
144 #pragma pack(push, 4)
145 typedef struct fsevent_dev_filter_args {
146 	uint32_t  num_devices;
147 	dev_t    *devices;
148 } fsevent_dev_filter_args;
149 #pragma pack(pop)
150 
151 #define FSEVENTS_DEVICE_FILTER          _IOW('s', 100, fsevent_dev_filter_args)
152 #define FSEVENTS_WANT_COMPACT_EVENTS    _IO('s', 101)
153 #define FSEVENTS_WANT_EXTENDED_INFO     _IO('s', 102)
154 #define FSEVENTS_GET_CURRENT_ID         _IOR('s', 103, uint64_t)
155 #define FSEVENTS_UNMOUNT_PENDING_ACK    _IOW('s', 104, dev_t)
156 
157 
158 #ifdef BSD_KERNEL_PRIVATE
159 
160 void fsevents_init(void);
161 void fsevent_unmount(struct mount *mp, vfs_context_t ctx);
162 struct vnode_attr;
163 void create_fsevent_from_kevent(vnode_t vp, uint32_t kevents, struct vnode_attr *vap);
164 
165 // misc utility functions for fsevent info and pathbuffers...
166 typedef struct fse_info {
167 	ino64_t    ino;
168 	dev_t      dev;
169 	int32_t    mode;// note: this is not a mode_t (it's 32-bits, not 16)
170 	uid_t      uid;
171 	uint32_t   document_id;
172 	uint64_t   nlink;// only filled in if the vnode is marked as a hardlink
173 } fse_info;
174 
175 int   get_fse_info(struct vnode *vp, fse_info *fse, vfs_context_t ctx);
176 int   vnode_get_fse_info_from_vap(vnode_t vp, fse_info *fse, struct vnode_attr *vap);
177 
178 char *get_pathbuff(void);
179 void  release_pathbuff(char *path);
180 
181 #endif /* BSD_KERNEL_PRIVATE */
182 
183 #ifdef KERNEL_PRIVATE
184 
185 int  need_fsevent(int type, vnode_t vp);
186 int  add_fsevent(int type, vfs_context_t, ...);
187 int  test_fse_access_granted(vnode_t vp, unsigned long type, vfs_context_t);
188 
189 #endif /* KERNEL_PRIVATE */
190 
191 #endif /* FSEVENT_H */
192