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