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