]> git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/devfs/devfsdefs.h
d7496d1e8ad49106f831c62d12388f382e938939
[apple/xnu.git] / bsd / miscfs / devfs / devfsdefs.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright 1997,1998 Julian Elischer. All rights reserved.
32 * julian@freebsd.org
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions are
36 * met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright notice,
40 * this list of conditions and the following disclaimer in the documentation
41 * and/or other materials provided with the distribution.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
44 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
45 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46 * DISCLAIMED. IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
47 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
49 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * devfsdefs.h
56 */
57
58 /*
59 * HISTORY
60 * 8-April-1999 Dieter Siegmund (dieter@apple.com)
61 * Ported to from FreeBSD 3.1
62 * Removed unnecessary/unused defines
63 * Renamed structures/elements to clarify usage in code.
64 */
65
66 #ifndef __DEVFS_DEVFSDEFS_H__
67 #define __DEVFS_DEVFSDEFS_H__
68
69 #include <sys/appleapiopts.h>
70
71 #ifdef __APPLE_API_PRIVATE
72 #define DEVMAXNAMESIZE 32 /* XXX */
73 #define DEVMAXPATHSIZE 128 /* XXX */
74
75 typedef enum {
76 DEV_DIR,
77 DEV_BDEV,
78 DEV_CDEV,
79 DEV_SLNK
80 } devfstype_t;
81
82 extern int (**devfs_vnodeop_p)(void *); /* our own vector array for dirs */
83 extern int (**devfs_spec_vnodeop_p)(void *); /* our own vector array for devs */
84 extern struct vfsops devfs_vfsops;
85
86 typedef struct devnode devnode_t;
87 typedef struct devdirent devdirent_t;
88 typedef union devnode_type devnode_type_t;
89
90 struct devfs_stats {
91 int nodes;
92 int entries;
93 int mounts;
94 int stringspace;
95 };
96
97 union devnode_type {
98 dev_t dev;
99 struct {
100 devdirent_t * dirlist;
101 devdirent_t * * dirlast;
102 devnode_t * parent;
103 devdirent_t * myname; /* my entry in .. */
104 int entrycount;
105 }Dir;
106 struct {
107 char * name; /* must be allocated separately */
108 int namelen;
109 }Slnk;
110 };
111
112 struct devnode
113 {
114 devfstype_t dn_type;
115 int dn_flags;
116 u_short dn_mode;
117 uid_t dn_uid;
118 gid_t dn_gid;
119 struct timespec dn_atime;/* time of last access */
120 struct timespec dn_mtime;/* time of last modification */
121 struct timespec dn_ctime;/* time file changed */
122 int (***dn_ops)(void *);/* yuk... pointer to pointer(s) to funcs */
123 int dn_links;/* how many file links does this node have? */
124 struct devfsmount * dn_dvm; /* the mount structure for this 'plane' */
125 struct vnode * dn_vn; /* address of last vnode that represented us */
126 int dn_len; /* of any associated info (e.g. dir data) */
127 devdirent_t * dn_linklist;/* circular list of hardlinks to this node */
128 devnode_t * dn_nextsibling; /* the list of equivalent nodes */
129 devnode_t * * dn_prevsiblingp;/* backpointer for the above */
130 devnode_type_t dn_typeinfo;
131 int dn_delete; /* mark for deletion */
132 int dn_change;
133 int dn_update;
134 int dn_access;
135 int dn_lflags;
136 };
137
138 #define DN_BUSY 0x01
139 #define DN_DELETE 0x02
140 #define DN_CREATE 0x04
141 #define DN_CREATEWAIT 0x08
142
143
144 struct devdirent
145 {
146 /*-----------------------directory entry fields-------------*/
147 char de_name[DEVMAXNAMESIZE];
148 devnode_t * de_dnp; /* the "inode" (devnode) pointer */
149 devnode_t * de_parent; /* backpointer to the directory itself */
150 devdirent_t * de_next; /* next object in this directory */
151 devdirent_t * *de_prevp; /* previous pointer in directory linked list */
152 devdirent_t * de_nextlink; /* next hardlink to this node */
153 devdirent_t * *de_prevlinkp; /* previous hardlink pointer for this node */
154 };
155
156 extern devdirent_t * dev_root;
157 extern struct devfs_stats devfs_stats;
158 extern lck_mtx_t devfs_mutex;
159
160 /*
161 * Rules for front nodes:
162 * Dirs hava a strict 1:1 relationship with their OWN devnode
163 * Symlinks similarly
164 * Device Nodes ALWAYS point to the devnode that is linked
165 * to the Backing node. (with a ref count)
166 */
167
168 /*
169 * DEVFS specific per/mount information, used to link a monted fs to a
170 * particular 'plane' of front nodes.
171 */
172 struct devfsmount
173 {
174 struct mount * mount; /* vfs mount struct for this fs */
175 devdirent_t * plane_root;/* the root of this 'plane' */
176 };
177
178 /*
179 * Prototypes for DEVFS virtual filesystem operations
180 */
181 #include <sys/lock.h>
182 #include <miscfs/devfs/devfs_proto.h>
183
184 //#define HIDDEN_MOUNTPOINT 1
185
186 /* misc */
187 #define M_DEVFSNAME M_DEVFS
188 #define M_DEVFSNODE M_DEVFS
189 #define M_DEVFSMNT M_DEVFS
190
191 #define VTODN(vp) ((devnode_t *)(vp)->v_data)
192
193 #define DEVFS_LOCK() lck_mtx_lock(&devfs_mutex)
194
195 #define DEVFS_UNLOCK() lck_mtx_unlock(&devfs_mutex)
196
197
198
199 static __inline__ void
200 DEVFS_INCR_ENTRIES()
201 {
202 OSAddAtomic(1, &devfs_stats.entries);
203 }
204
205 static __inline__ void
206 DEVFS_DECR_ENTRIES()
207 {
208 OSAddAtomic(-1, &devfs_stats.entries);
209 }
210
211 static __inline__ void
212 DEVFS_INCR_NODES()
213 {
214 OSAddAtomic(1, &devfs_stats.nodes);
215 }
216
217 static __inline__ void
218 DEVFS_DECR_NODES()
219 {
220 OSAddAtomic(-1, &devfs_stats.nodes);
221 }
222
223 static __inline__ void
224 DEVFS_INCR_MOUNTS()
225 {
226 OSAddAtomic(1, &devfs_stats.mounts);
227 }
228
229 static __inline__ void
230 DEVFS_DECR_MOUNTS()
231 {
232 OSAddAtomic(-1, &devfs_stats.mounts);
233 }
234
235 static __inline__ void
236 DEVFS_INCR_STRINGSPACE(int space)
237 {
238 OSAddAtomic(space, &devfs_stats.stringspace);
239 }
240
241 static __inline__ void
242 DEVFS_DECR_STRINGSPACE(int space)
243 {
244 OSAddAtomic(-space, &devfs_stats.stringspace);
245 }
246
247 static __inline__ void
248 dn_times(devnode_t * dnp, struct timeval *t1, struct timeval *t2, struct timeval *t3)
249 {
250 if (dnp->dn_access) {
251 dnp->dn_atime.tv_sec = t1->tv_sec;
252 dnp->dn_atime.tv_nsec = t1->tv_usec * 1000;
253 dnp->dn_access = 0;
254 }
255 if (dnp->dn_update) {
256 dnp->dn_mtime.tv_sec = t2->tv_sec;
257 dnp->dn_mtime.tv_nsec = t2->tv_usec * 1000;
258 dnp->dn_update = 0;
259 }
260 if (dnp->dn_change) {
261 dnp->dn_ctime.tv_sec = t3->tv_sec;
262 dnp->dn_ctime.tv_nsec = t3->tv_usec * 1000;
263 dnp->dn_change = 0;
264 }
265
266 return;
267 }
268
269 static __inline__ void
270 dn_copy_times(devnode_t * target, devnode_t * source)
271 {
272 target->dn_atime = source->dn_atime;
273 target->dn_mtime = source->dn_mtime;
274 target->dn_ctime = source->dn_ctime;
275 return;
276 }
277 #endif /* __APPLE_API_PRIVATE */
278 #endif /* __DEVFS_DEVFSDEFS_H__ */