]> git.saurik.com Git - apple/xnu.git/blame - bsd/miscfs/devfs/devfsdefs.h
xnu-517.tar.gz
[apple/xnu.git] / bsd / miscfs / devfs / devfsdefs.h
CommitLineData
1c79356b 1/*
9bccf70c 2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright 1997,1998 Julian Elischer. All rights reserved.
27 * julian@freebsd.org
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions are
31 * met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright notice,
35 * this list of conditions and the following disclaimer in the documentation
36 * and/or other materials provided with the distribution.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
39 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
40 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED. IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
42 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 *
50 * devfsdefs.h
51 */
52
53/*
54 * HISTORY
55 * 8-April-1999 Dieter Siegmund (dieter@apple.com)
56 * Ported to from FreeBSD 3.1
57 * Removed unnecessary/unused defines
58 * Renamed structures/elements to clarify usage in code.
59 */
60
9bccf70c
A
61#ifndef __DEVFS_DEVFSDEFS_H__
62#define __DEVFS_DEVFSDEFS_H__
1c79356b 63
9bccf70c
A
64#include <sys/appleapiopts.h>
65
66#ifdef __APPLE_API_PRIVATE
1c79356b
A
67#define DEVMAXNAMESIZE 32 /* XXX */
68#define DEVMAXPATHSIZE 128 /* XXX */
69
70typedef enum {
71 DEV_DIR,
72 DEV_BDEV,
73 DEV_CDEV,
55e303ae 74 DEV_SLNK
1c79356b
A
75} devfstype_t;
76
77extern int (**devfs_vnodeop_p)(void *); /* our own vector array for dirs */
78extern int (**devfs_spec_vnodeop_p)(void *); /* our own vector array for devs */
79extern struct vfsops devfs_vfsops;
80
81typedef struct devnode devnode_t;
82typedef struct devdirent devdirent_t;
83typedef union devnode_type devnode_type_t;
84
85struct devfs_stats {
86 int nodes;
87 int entries;
88 int mounts;
89 int stringspace;
90};
91
92union devnode_type {
93 dev_t dev;
94 struct {
95 devdirent_t * dirlist;
96 devdirent_t * * dirlast;
97 devnode_t * parent;
98 devdirent_t * myname; /* my entry in .. */
99 int entrycount;
100 }Dir;
101 struct {
102 char * name; /* must be allocated separately */
103 int namelen;
104 }Slnk;
105};
106
107#define DN_ACCESS 0x0001 /* Access time update request. */
108#define DN_CHANGE 0x0002 /* Inode change time update request. */
109#define DN_UPDATE 0x0004 /* Modification time update request. */
110#define DN_MODIFIED 0x0008 /* Inode has been modified. */
111#define DN_RENAME 0x0010 /* Inode is being renamed. */
112
113struct devnode
114{
115 devfstype_t dn_type;
116 int dn_flags;
117 u_short dn_mode;
0b4e3aa0
A
118 uid_t dn_uid;
119 gid_t dn_gid;
1c79356b
A
120 struct timespec dn_atime;/* time of last access */
121 struct timespec dn_mtime;/* time of last modification */
122 struct timespec dn_ctime;/* time file changed */
123 int (***dn_ops)(void *);/* yuk... pointer to pointer(s) to funcs */
124 int dn_links;/* how many file links does this node have? */
125 struct devfsmount * dn_dvm; /* the mount structure for this 'plane' */
126 struct vnode * dn_vn; /* address of last vnode that represented us */
127 int dn_len; /* of any associated info (e.g. dir data) */
128 devdirent_t * dn_linklist;/* circular list of hardlinks to this node */
129 devdirent_t * dn_last_lookup; /* name I was last looked up from */
130 devnode_t * dn_nextsibling; /* the list of equivalent nodes */
131 devnode_t * * dn_prevsiblingp;/* backpointer for the above */
132 devnode_type_t dn_typeinfo;
133 int dn_delete; /* mark for deletion */
134};
135
136struct 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
148extern devdirent_t * dev_root;
149extern struct lock__bsd__ devfs_lock;
150extern struct devfs_stats devfs_stats;
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 */
164struct 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
1c79356b 183#define VTODN(vp) ((devnode_t *)(vp)->v_data)
1c79356b
A
184
185static __inline__ int
186DEVFS_LOCK(struct proc * p)
187{
188 return (lockmgr(&devfs_lock, LK_EXCLUSIVE, NULL, p));
189}
190
191static __inline__ int
192DEVFS_UNLOCK(struct proc * p)
193{
194 return (lockmgr(&devfs_lock, LK_RELEASE, NULL, p));
195}
196
197static __inline__ void
198DEVFS_INCR_ENTRIES()
199{
200 devfs_stats.entries++;
201}
202
203static __inline__ void
204DEVFS_DECR_ENTRIES()
205{
206 devfs_stats.entries--;
207}
208
209static __inline__ void
210DEVFS_INCR_NODES()
211{
212 devfs_stats.nodes++;
213}
214
215static __inline__ void
216DEVFS_DECR_NODES()
217{
218 devfs_stats.nodes--;
219}
220
221static __inline__ void
222DEVFS_INCR_MOUNTS()
223{
224 devfs_stats.mounts++;
225}
226
227static __inline__ void
228DEVFS_DECR_MOUNTS()
229{
230 devfs_stats.mounts--;
231}
232
233static __inline__ void
234DEVFS_INCR_STRINGSPACE(int space)
235{
236 devfs_stats.stringspace += space;
237}
238
239static __inline__ void
240DEVFS_DECR_STRINGSPACE(int space)
241{
242 devfs_stats.stringspace -= space;
243 if (devfs_stats.stringspace < 0) {
244 printf("DEVFS_DECR_STRINGSPACE: (%d - %d < 0)\n",
245 devfs_stats.stringspace + space, space);
246 devfs_stats.stringspace = 0;
247 }
248}
249
250static __inline__ void
251dn_times(devnode_t * dnp, struct timeval t1, struct timeval t2)
252{
253 if (dnp->dn_flags & (DN_ACCESS | DN_CHANGE | DN_UPDATE)) {
254 if (dnp->dn_flags & DN_ACCESS) {
255 dnp->dn_atime.tv_sec = t1.tv_sec;
256 dnp->dn_atime.tv_nsec = t1.tv_usec * 1000;
257 }
258 if (dnp->dn_flags & DN_UPDATE) {
259 dnp->dn_mtime.tv_sec = t2.tv_sec;
260 dnp->dn_mtime.tv_nsec = t2.tv_usec * 1000;
261 }
262 if (dnp->dn_flags & DN_CHANGE) {
263 dnp->dn_ctime.tv_sec = time.tv_sec;
264 dnp->dn_ctime.tv_nsec = time.tv_usec * 1000;
265 }
266 dnp->dn_flags &= ~(DN_ACCESS | DN_CHANGE | DN_UPDATE);
267 }
268 return;
269}
270
271static __inline__ void
272dn_copy_times(devnode_t * target, devnode_t * source)
273{
274 target->dn_atime = source->dn_atime;
275 target->dn_mtime = source->dn_mtime;
276 target->dn_ctime = source->dn_ctime;
277 return;
278}
9bccf70c
A
279#endif /* __APPLE_API_PRIVATE */
280#endif /* __DEVFS_DEVFSDEFS_H__ */