2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright 1997,1998 Julian Elischer. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions are
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright notice,
38 * this list of conditions and the following disclaimer in the documentation
39 * and/or other materials provided with the distribution.
41 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
42 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 * DISCLAIMED. IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
45 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * 8-April-1999 Dieter Siegmund (dieter@apple.com)
59 * Ported to from FreeBSD 3.1
60 * Removed unnecessary/unused defines
61 * Renamed structures/elements to clarify usage in code.
64 #ifndef __DEVFS_DEVFSDEFS_H__
65 #define __DEVFS_DEVFSDEFS_H__
67 #include <sys/appleapiopts.h>
69 #ifdef __APPLE_API_PRIVATE
70 #define DEVMAXNAMESIZE 32 /* XXX */
71 #define DEVMAXPATHSIZE 128 /* XXX */
80 extern int (**devfs_vnodeop_p
)(void *); /* our own vector array for dirs */
81 extern int (**devfs_spec_vnodeop_p
)(void *); /* our own vector array for devs */
82 extern struct vfsops devfs_vfsops
;
84 typedef struct devnode devnode_t
;
85 typedef struct devdirent devdirent_t
;
86 typedef union devnode_type devnode_type_t
;
98 devdirent_t
* dirlist
;
99 devdirent_t
* * dirlast
;
101 devdirent_t
* myname
; /* my entry in .. */
105 char * name
; /* must be allocated separately */
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 devnode_t
* dn_nextsibling
; /* the list of equivalent nodes */
127 devnode_t
* * dn_prevsiblingp
;/* backpointer for the above */
128 devnode_type_t dn_typeinfo
;
129 int dn_delete
; /* mark for deletion */
137 #define DN_DELETE 0x02
138 #define DN_CREATE 0x04
139 #define DN_CREATEWAIT 0x08
144 /*-----------------------directory entry fields-------------*/
145 char de_name
[DEVMAXNAMESIZE
];
146 devnode_t
* de_dnp
; /* the "inode" (devnode) pointer */
147 devnode_t
* de_parent
; /* backpointer to the directory itself */
148 devdirent_t
* de_next
; /* next object in this directory */
149 devdirent_t
* *de_prevp
; /* previous pointer in directory linked list */
150 devdirent_t
* de_nextlink
; /* next hardlink to this node */
151 devdirent_t
* *de_prevlinkp
; /* previous hardlink pointer for this node */
154 extern devdirent_t
* dev_root
;
155 extern struct devfs_stats devfs_stats
;
156 extern lck_mtx_t devfs_mutex
;
159 * Rules for front nodes:
160 * Dirs hava a strict 1:1 relationship with their OWN devnode
162 * Device Nodes ALWAYS point to the devnode that is linked
163 * to the Backing node. (with a ref count)
167 * DEVFS specific per/mount information, used to link a monted fs to a
168 * particular 'plane' of front nodes.
172 struct mount
* mount
; /* vfs mount struct for this fs */
173 devdirent_t
* plane_root
;/* the root of this 'plane' */
177 * Prototypes for DEVFS virtual filesystem operations
179 #include <sys/lock.h>
180 #include <miscfs/devfs/devfs_proto.h>
182 //#define HIDDEN_MOUNTPOINT 1
185 #define M_DEVFSNAME M_DEVFS
186 #define M_DEVFSNODE M_DEVFS
187 #define M_DEVFSMNT M_DEVFS
189 #define VTODN(vp) ((devnode_t *)(vp)->v_data)
191 #define DEVFS_LOCK() lck_mtx_lock(&devfs_mutex)
193 #define DEVFS_UNLOCK() lck_mtx_unlock(&devfs_mutex)
197 static __inline__
void
200 OSAddAtomic(1, &devfs_stats
.entries
);
203 static __inline__
void
206 OSAddAtomic(-1, &devfs_stats
.entries
);
209 static __inline__
void
212 OSAddAtomic(1, &devfs_stats
.nodes
);
215 static __inline__
void
218 OSAddAtomic(-1, &devfs_stats
.nodes
);
221 static __inline__
void
224 OSAddAtomic(1, &devfs_stats
.mounts
);
227 static __inline__
void
230 OSAddAtomic(-1, &devfs_stats
.mounts
);
233 static __inline__
void
234 DEVFS_INCR_STRINGSPACE(int space
)
236 OSAddAtomic(space
, &devfs_stats
.stringspace
);
239 static __inline__
void
240 DEVFS_DECR_STRINGSPACE(int space
)
242 OSAddAtomic(-space
, &devfs_stats
.stringspace
);
245 static __inline__
void
246 dn_times(devnode_t
* dnp
, struct timeval
*t1
, struct timeval
*t2
, struct timeval
*t3
)
248 if (dnp
->dn_access
) {
249 dnp
->dn_atime
.tv_sec
= t1
->tv_sec
;
250 dnp
->dn_atime
.tv_nsec
= t1
->tv_usec
* 1000;
253 if (dnp
->dn_update
) {
254 dnp
->dn_mtime
.tv_sec
= t2
->tv_sec
;
255 dnp
->dn_mtime
.tv_nsec
= t2
->tv_usec
* 1000;
258 if (dnp
->dn_change
) {
259 dnp
->dn_ctime
.tv_sec
= t3
->tv_sec
;
260 dnp
->dn_ctime
.tv_nsec
= t3
->tv_usec
* 1000;
267 static __inline__
void
268 dn_copy_times(devnode_t
* target
, devnode_t
* source
)
270 target
->dn_atime
= source
->dn_atime
;
271 target
->dn_mtime
= source
->dn_mtime
;
272 target
->dn_ctime
= source
->dn_ctime
;
275 #endif /* __APPLE_API_PRIVATE */
276 #endif /* __DEVFS_DEVFSDEFS_H__ */