2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright 1997,1998 Julian Elischer. All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions are
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright notice,
40 * this list of conditions and the following disclaimer in the documentation
41 * and/or other materials provided with the distribution.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
44 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
45 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46 * DISCLAIMED. IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
47 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
49 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * 8-April-1999 Dieter Siegmund (dieter@apple.com)
61 * Ported to from FreeBSD 3.1
62 * Removed unnecessary/unused defines
63 * Renamed structures/elements to clarify usage in code.
66 #ifndef __DEVFS_DEVFSDEFS_H__
67 #define __DEVFS_DEVFSDEFS_H__
69 #include <sys/appleapiopts.h>
71 #ifdef __APPLE_API_PRIVATE
72 #define DEVMAXNAMESIZE 32 /* XXX */
73 #define DEVMAXPATHSIZE 128 /* XXX */
82 extern int (**devfs_vnodeop_p
)(void *); /* our own vector array for dirs */
83 extern int (**devfs_spec_vnodeop_p
)(void *); /* our own vector array for devs */
84 extern struct vfsops devfs_vfsops
;
86 typedef struct devnode devnode_t
;
87 typedef struct devdirent devdirent_t
;
88 typedef union devnode_type devnode_type_t
;
100 devdirent_t
* dirlist
;
101 devdirent_t
* * dirlast
;
103 devdirent_t
* myname
; /* my entry in .. */
107 char * name
; /* must be allocated separately */
119 struct timespec dn_atime
;/* time of last access */
120 struct timespec dn_mtime
;/* time of last modification */
121 struct timespec dn_ctime
;/* time file changed */
122 int (***dn_ops
)(void *);/* yuk... pointer to pointer(s) to funcs */
123 int dn_links
;/* how many file links does this node have? */
124 struct devfsmount
* dn_dvm
; /* the mount structure for this 'plane' */
125 struct vnode
* dn_vn
; /* address of last vnode that represented us */
126 int dn_len
; /* of any associated info (e.g. dir data) */
127 devdirent_t
* dn_linklist
;/* circular list of hardlinks to this node */
128 devnode_t
* dn_nextsibling
; /* the list of equivalent nodes */
129 devnode_t
* * dn_prevsiblingp
;/* backpointer for the above */
130 devnode_type_t dn_typeinfo
;
131 int dn_delete
; /* mark for deletion */
139 #define DN_DELETE 0x02
140 #define DN_CREATE 0x04
141 #define DN_CREATEWAIT 0x08
146 /*-----------------------directory entry fields-------------*/
147 char de_name
[DEVMAXNAMESIZE
];
148 devnode_t
* de_dnp
; /* the "inode" (devnode) pointer */
149 devnode_t
* de_parent
; /* backpointer to the directory itself */
150 devdirent_t
* de_next
; /* next object in this directory */
151 devdirent_t
* *de_prevp
; /* previous pointer in directory linked list */
152 devdirent_t
* de_nextlink
; /* next hardlink to this node */
153 devdirent_t
* *de_prevlinkp
; /* previous hardlink pointer for this node */
156 extern devdirent_t
* dev_root
;
157 extern struct devfs_stats devfs_stats
;
158 extern lck_mtx_t devfs_mutex
;
161 * Rules for front nodes:
162 * Dirs hava a strict 1:1 relationship with their OWN devnode
164 * Device Nodes ALWAYS point to the devnode that is linked
165 * to the Backing node. (with a ref count)
169 * DEVFS specific per/mount information, used to link a monted fs to a
170 * particular 'plane' of front nodes.
174 struct mount
* mount
; /* vfs mount struct for this fs */
175 devdirent_t
* plane_root
;/* the root of this 'plane' */
179 * Prototypes for DEVFS virtual filesystem operations
181 #include <sys/lock.h>
182 #include <miscfs/devfs/devfs_proto.h>
184 //#define HIDDEN_MOUNTPOINT 1
187 #define M_DEVFSNAME M_DEVFS
188 #define M_DEVFSNODE M_DEVFS
189 #define M_DEVFSMNT M_DEVFS
191 #define VTODN(vp) ((devnode_t *)(vp)->v_data)
193 #define DEVFS_LOCK() lck_mtx_lock(&devfs_mutex)
195 #define DEVFS_UNLOCK() lck_mtx_unlock(&devfs_mutex)
199 static __inline__
void
202 OSAddAtomic(1, &devfs_stats
.entries
);
205 static __inline__
void
208 OSAddAtomic(-1, &devfs_stats
.entries
);
211 static __inline__
void
214 OSAddAtomic(1, &devfs_stats
.nodes
);
217 static __inline__
void
220 OSAddAtomic(-1, &devfs_stats
.nodes
);
223 static __inline__
void
226 OSAddAtomic(1, &devfs_stats
.mounts
);
229 static __inline__
void
232 OSAddAtomic(-1, &devfs_stats
.mounts
);
235 static __inline__
void
236 DEVFS_INCR_STRINGSPACE(int space
)
238 OSAddAtomic(space
, &devfs_stats
.stringspace
);
241 static __inline__
void
242 DEVFS_DECR_STRINGSPACE(int space
)
244 OSAddAtomic(-space
, &devfs_stats
.stringspace
);
247 static __inline__
void
248 dn_times(devnode_t
* dnp
, struct timeval
*t1
, struct timeval
*t2
, struct timeval
*t3
)
250 if (dnp
->dn_access
) {
251 dnp
->dn_atime
.tv_sec
= t1
->tv_sec
;
252 dnp
->dn_atime
.tv_nsec
= t1
->tv_usec
* 1000;
255 if (dnp
->dn_update
) {
256 dnp
->dn_mtime
.tv_sec
= t2
->tv_sec
;
257 dnp
->dn_mtime
.tv_nsec
= t2
->tv_usec
* 1000;
260 if (dnp
->dn_change
) {
261 dnp
->dn_ctime
.tv_sec
= t3
->tv_sec
;
262 dnp
->dn_ctime
.tv_nsec
= t3
->tv_usec
* 1000;
269 static __inline__
void
270 dn_copy_times(devnode_t
* target
, devnode_t
* source
)
272 target
->dn_atime
= source
->dn_atime
;
273 target
->dn_mtime
= source
->dn_mtime
;
274 target
->dn_ctime
= source
->dn_ctime
;
277 #endif /* __APPLE_API_PRIVATE */
278 #endif /* __DEVFS_DEVFSDEFS_H__ */