2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright 1997,1998 Julian Elischer. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions are
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.
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
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.
59 #ifndef __DEVFS_DEVFSDEFS_H__
60 #define __DEVFS_DEVFSDEFS_H__
62 #include <sys/appleapiopts.h>
64 #ifdef __APPLE_API_PRIVATE
65 #define DEVMAXNAMESIZE 32 /* XXX */
66 #define DEVMAXPATHSIZE 128 /* XXX */
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
;
79 typedef struct devnode devnode_t
;
80 typedef struct devdirent devdirent_t
;
81 typedef union devnode_type devnode_type_t
;
93 devdirent_t
* dirlist
;
94 devdirent_t
* * dirlast
;
96 devdirent_t
* myname
; /* my entry in .. */
100 char * name
; /* must be allocated separately */
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 */
132 #define DN_DELETE 0x02
133 #define DN_CREATE 0x04
134 #define DN_CREATEWAIT 0x08
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 */
149 extern devdirent_t
* dev_root
;
150 extern struct devfs_stats devfs_stats
;
151 extern lck_mtx_t devfs_mutex
;
154 * Rules for front nodes:
155 * Dirs hava a strict 1:1 relationship with their OWN devnode
157 * Device Nodes ALWAYS point to the devnode that is linked
158 * to the Backing node. (with a ref count)
162 * DEVFS specific per/mount information, used to link a monted fs to a
163 * particular 'plane' of front nodes.
167 struct mount
* mount
; /* vfs mount struct for this fs */
168 devdirent_t
* plane_root
;/* the root of this 'plane' */
172 * Prototypes for DEVFS virtual filesystem operations
174 #include <sys/lock.h>
175 #include <miscfs/devfs/devfs_proto.h>
177 //#define HIDDEN_MOUNTPOINT 1
180 #define M_DEVFSNAME M_DEVFS
181 #define M_DEVFSNODE M_DEVFS
182 #define M_DEVFSMNT M_DEVFS
184 #define VTODN(vp) ((devnode_t *)(vp)->v_data)
186 #define DEVFS_LOCK() lck_mtx_lock(&devfs_mutex)
188 #define DEVFS_UNLOCK() lck_mtx_unlock(&devfs_mutex)
192 static __inline__
void
195 OSAddAtomic(1, &devfs_stats
.entries
);
198 static __inline__
void
201 OSAddAtomic(-1, &devfs_stats
.entries
);
204 static __inline__
void
207 OSAddAtomic(1, &devfs_stats
.nodes
);
210 static __inline__
void
213 OSAddAtomic(-1, &devfs_stats
.nodes
);
216 static __inline__
void
219 OSAddAtomic(1, &devfs_stats
.mounts
);
222 static __inline__
void
225 OSAddAtomic(-1, &devfs_stats
.mounts
);
228 static __inline__
void
229 DEVFS_INCR_STRINGSPACE(int space
)
231 OSAddAtomic(space
, &devfs_stats
.stringspace
);
234 static __inline__
void
235 DEVFS_DECR_STRINGSPACE(int space
)
237 OSAddAtomic(-space
, &devfs_stats
.stringspace
);
240 static __inline__
void
241 dn_times(devnode_t
* dnp
, struct timeval
*t1
, struct timeval
*t2
, struct timeval
*t3
)
243 if (dnp
->dn_access
) {
244 dnp
->dn_atime
.tv_sec
= t1
->tv_sec
;
245 dnp
->dn_atime
.tv_nsec
= t1
->tv_usec
* 1000;
248 if (dnp
->dn_update
) {
249 dnp
->dn_mtime
.tv_sec
= t2
->tv_sec
;
250 dnp
->dn_mtime
.tv_nsec
= t2
->tv_usec
* 1000;
253 if (dnp
->dn_change
) {
254 dnp
->dn_ctime
.tv_sec
= t3
->tv_sec
;
255 dnp
->dn_ctime
.tv_nsec
= t3
->tv_usec
* 1000;
262 static __inline__
void
263 dn_copy_times(devnode_t
* target
, devnode_t
* source
)
265 target
->dn_atime
= source
->dn_atime
;
266 target
->dn_mtime
= source
->dn_mtime
;
267 target
->dn_ctime
= source
->dn_ctime
;
270 #endif /* __APPLE_API_PRIVATE */
271 #endif /* __DEVFS_DEVFSDEFS_H__ */