1/*
2 * Copyright (c) 2009-2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef _PATHWATCH_H_
25#define _PATHWATCH_H_
26
27#include <dispatch/dispatch.h>
28/*
29 * types for virtual path nodes (path_node_t)
30 */
31#define PATH_NODE_TYPE_GHOST 0
32#define PATH_NODE_TYPE_FILE  1
33#define PATH_NODE_TYPE_LINK  2
34#define PATH_NODE_TYPE_DIR   3
35#define PATH_NODE_TYPE_OTHER 4
36
37
38enum
39{
40	PATH_NODE_DELETE = 0x0001, /* node or path deleted */
41	PATH_NODE_WRITE  = 0x0002, /* node written */
42	PATH_NODE_EXTEND = 0x0004, /* node extended */
43	PATH_NODE_ATTRIB = 0x0008, /* node attributes changed (mtime or ctime) */
44	PATH_NODE_LINK	 = 0x0010, /* node link count changed */
45	PATH_NODE_RENAME = 0x0020, /* node renamed, always accompanied by PATH_NODE_DELETE */
46	PATH_NODE_REVOKE = 0x0040, /* access revoked, always accompanied by PATH_NODE_DELETE */
47	PATH_NODE_CREATE = 0x0080, /* path created or access re-acquired */
48	PATH_NODE_MTIME  = 0x0100, /* path mtime changed, always accompanied by PATH_NODE_ATTRIB */
49	PATH_NODE_CTIME  = 0x0200  /* path ctime changed, always accompanied by PATH_NODE_ATTRIB */
50};
51
52/* all bits mask */
53#define PATH_NODE_ALL 0x000003ff
54/* src is suspended */
55#define PATH_SRC_SUSPENDED 0x10000000
56
57/* Path changes coalesce for 100 milliseconds */
58#define PNODE_COALESCE_TIME 100000000
59
60/*
61 * path_node_t represents a virtual path
62 */
63typedef struct
64{
65	char *path;
66	size_t plen;
67	uid_t uid;
68	gid_t gid;
69	uint32_t pname_count;
70	char **pname;
71	uint32_t type;
72	uint32_t flags;
73	dispatch_source_t src;
74	dispatch_queue_t src_queue;
75	void *contextp;
76	uint32_t context32;
77	uint64_t context64;
78	uint32_t refcount;
79} path_node_t;
80
81path_node_t *path_node_create(const char *path, uid_t uid, gid_t gid, uint32_t mask, dispatch_queue_t queue);
82void path_node_close(path_node_t *pnode);
83
84#endif /* _PATHWATCH_H_ */
85