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