]> git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/devfs/devfsdefs.h
e6f299f3d9114212b5fa66eb3a89785774887123
[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 #define DN_ACCESS 0x0001 /* Access time update request. */
105 #define DN_CHANGE 0x0002 /* Inode change time update request. */
106 #define DN_UPDATE 0x0004 /* Modification time update request. */
107 #define DN_MODIFIED 0x0008 /* Inode has been modified. */
108 #define DN_RENAME 0x0010 /* Inode is being renamed. */
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 devdirent_t * dn_last_lookup; /* name I was last looked up from */
127 devnode_t * dn_nextsibling; /* the list of equivalent nodes */
128 devnode_t * * dn_prevsiblingp;/* backpointer for the above */
129 devnode_type_t dn_typeinfo;
130 int dn_delete; /* mark for deletion */
131 };
132
133 struct devdirent
134 {
135 /*-----------------------directory entry fields-------------*/
136 char de_name[DEVMAXNAMESIZE];
137 devnode_t * de_dnp; /* the "inode" (devnode) pointer */
138 devnode_t * de_parent; /* backpointer to the directory itself */
139 devdirent_t * de_next; /* next object in this directory */
140 devdirent_t * *de_prevp; /* previous pointer in directory linked list */
141 devdirent_t * de_nextlink; /* next hardlink to this node */
142 devdirent_t * *de_prevlinkp; /* previous hardlink pointer for this node */
143 };
144
145 extern devdirent_t * dev_root;
146 extern struct lock__bsd__ devfs_lock;
147 extern struct devfs_stats devfs_stats;
148
149 /*
150 * Rules for front nodes:
151 * Dirs hava a strict 1:1 relationship with their OWN devnode
152 * Symlinks similarly
153 * Device Nodes ALWAYS point to the devnode that is linked
154 * to the Backing node. (with a ref count)
155 */
156
157 /*
158 * DEVFS specific per/mount information, used to link a monted fs to a
159 * particular 'plane' of front nodes.
160 */
161 struct devfsmount
162 {
163 struct mount * mount; /* vfs mount struct for this fs */
164 devdirent_t * plane_root;/* the root of this 'plane' */
165 };
166
167 /*
168 * Prototypes for DEVFS virtual filesystem operations
169 */
170 #include <sys/lock.h>
171 #include <miscfs/devfs/devfs_proto.h>
172
173 //#define HIDDEN_MOUNTPOINT 1
174
175 /* misc */
176 #define M_DEVFSNAME M_DEVFS
177 #define M_DEVFSNODE M_DEVFS
178 #define M_DEVFSMNT M_DEVFS
179
180 static __inline__ void
181 getnanotime(struct timespec * t_p)
182 {
183 struct timeval tv;
184
185 microtime(&tv);
186 t_p->tv_sec = tv.tv_sec;
187 t_p->tv_nsec = tv.tv_usec * 1000;
188 return;
189 }
190
191 #define VTODN(vp) ((devnode_t *)(vp)->v_data)
192 extern void cache_purge(struct vnode *vp); /* vfs_cache.c */
193
194 static __inline__ int
195 DEVFS_LOCK(struct proc * p)
196 {
197 return (lockmgr(&devfs_lock, LK_EXCLUSIVE, NULL, p));
198 }
199
200 static __inline__ int
201 DEVFS_UNLOCK(struct proc * p)
202 {
203 return (lockmgr(&devfs_lock, LK_RELEASE, NULL, p));
204 }
205
206 static __inline__ void
207 DEVFS_INCR_ENTRIES()
208 {
209 devfs_stats.entries++;
210 }
211
212 static __inline__ void
213 DEVFS_DECR_ENTRIES()
214 {
215 devfs_stats.entries--;
216 }
217
218 static __inline__ void
219 DEVFS_INCR_NODES()
220 {
221 devfs_stats.nodes++;
222 }
223
224 static __inline__ void
225 DEVFS_DECR_NODES()
226 {
227 devfs_stats.nodes--;
228 }
229
230 static __inline__ void
231 DEVFS_INCR_MOUNTS()
232 {
233 devfs_stats.mounts++;
234 }
235
236 static __inline__ void
237 DEVFS_DECR_MOUNTS()
238 {
239 devfs_stats.mounts--;
240 }
241
242 static __inline__ void
243 DEVFS_INCR_STRINGSPACE(int space)
244 {
245 devfs_stats.stringspace += space;
246 }
247
248 static __inline__ void
249 DEVFS_DECR_STRINGSPACE(int space)
250 {
251 devfs_stats.stringspace -= space;
252 if (devfs_stats.stringspace < 0) {
253 printf("DEVFS_DECR_STRINGSPACE: (%d - %d < 0)\n",
254 devfs_stats.stringspace + space, space);
255 devfs_stats.stringspace = 0;
256 }
257 }
258
259 static __inline__ void
260 dn_times(devnode_t * dnp, struct timeval t1, struct timeval t2)
261 {
262 if (dnp->dn_flags & (DN_ACCESS | DN_CHANGE | DN_UPDATE)) {
263 if (dnp->dn_flags & DN_ACCESS) {
264 dnp->dn_atime.tv_sec = t1.tv_sec;
265 dnp->dn_atime.tv_nsec = t1.tv_usec * 1000;
266 }
267 if (dnp->dn_flags & DN_UPDATE) {
268 dnp->dn_mtime.tv_sec = t2.tv_sec;
269 dnp->dn_mtime.tv_nsec = t2.tv_usec * 1000;
270 }
271 if (dnp->dn_flags & DN_CHANGE) {
272 dnp->dn_ctime.tv_sec = time.tv_sec;
273 dnp->dn_ctime.tv_nsec = time.tv_usec * 1000;
274 }
275 dnp->dn_flags &= ~(DN_ACCESS | DN_CHANGE | DN_UPDATE);
276 }
277 return;
278 }
279
280 static __inline__ void
281 dn_copy_times(devnode_t * target, devnode_t * source)
282 {
283 target->dn_atime = source->dn_atime;
284 target->dn_mtime = source->dn_mtime;
285 target->dn_ctime = source->dn_ctime;
286 return;
287 }
288 #endif /* __APPLE_API_PRIVATE */
289 #endif /* __DEVFS_DEVFSDEFS_H__ */