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