2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright 1997,1998 Julian Elischer. All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions are
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.
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
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.
61 #ifndef __DEVFS_DEVFSDEFS_H__
62 #define __DEVFS_DEVFSDEFS_H__
64 #include <sys/appleapiopts.h>
66 #ifdef __APPLE_API_PRIVATE
67 #define DEVMAXNAMESIZE 32 /* XXX */
68 #define DEVMAXPATHSIZE 128 /* XXX */
77 extern int (**devfs_vnodeop_p
)(void *); /* our own vector array for dirs */
78 extern int (**devfs_spec_vnodeop_p
)(void *); /* our own vector array for devs */
79 extern struct vfsops devfs_vfsops
;
81 typedef struct devnode devnode_t
;
82 typedef struct devdirent devdirent_t
;
83 typedef union devnode_type devnode_type_t
;
95 devdirent_t
* dirlist
;
96 devdirent_t
* * dirlast
;
98 devdirent_t
* myname
; /* my entry in .. */
102 char * name
; /* must be allocated separately */
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. */
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 */
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 */
148 extern devdirent_t
* dev_root
;
149 extern struct lock__bsd__ devfs_lock
;
150 extern struct devfs_stats devfs_stats
;
153 * Rules for front nodes:
154 * Dirs hava a strict 1:1 relationship with their OWN devnode
156 * Device Nodes ALWAYS point to the devnode that is linked
157 * to the Backing node. (with a ref count)
161 * DEVFS specific per/mount information, used to link a monted fs to a
162 * particular 'plane' of front nodes.
166 struct mount
* mount
; /* vfs mount struct for this fs */
167 devdirent_t
* plane_root
;/* the root of this 'plane' */
171 * Prototypes for DEVFS virtual filesystem operations
173 #include <sys/lock.h>
174 #include <miscfs/devfs/devfs_proto.h>
176 //#define HIDDEN_MOUNTPOINT 1
179 #define M_DEVFSNAME M_DEVFS
180 #define M_DEVFSNODE M_DEVFS
181 #define M_DEVFSMNT M_DEVFS
183 #define VTODN(vp) ((devnode_t *)(vp)->v_data)
185 static __inline__
int
186 DEVFS_LOCK(struct proc
* p
)
188 return (lockmgr(&devfs_lock
, LK_EXCLUSIVE
, NULL
, p
));
191 static __inline__
int
192 DEVFS_UNLOCK(struct proc
* p
)
194 return (lockmgr(&devfs_lock
, LK_RELEASE
, NULL
, p
));
197 static __inline__
void
200 devfs_stats
.entries
++;
203 static __inline__
void
206 devfs_stats
.entries
--;
209 static __inline__
void
215 static __inline__
void
221 static __inline__
void
224 devfs_stats
.mounts
++;
227 static __inline__
void
230 devfs_stats
.mounts
--;
233 static __inline__
void
234 DEVFS_INCR_STRINGSPACE(int space
)
236 devfs_stats
.stringspace
+= space
;
239 static __inline__
void
240 DEVFS_DECR_STRINGSPACE(int space
)
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;
250 static __inline__
void
251 dn_times(devnode_t
* dnp
, struct timeval t1
, struct timeval t2
)
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;
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;
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;
266 dnp
->dn_flags
&= ~(DN_ACCESS
| DN_CHANGE
| DN_UPDATE
);
271 static __inline__
void
272 dn_copy_times(devnode_t
* target
, devnode_t
* source
)
274 target
->dn_atime
= source
->dn_atime
;
275 target
->dn_mtime
= source
->dn_mtime
;
276 target
->dn_ctime
= source
->dn_ctime
;
279 #endif /* __APPLE_API_PRIVATE */
280 #endif /* __DEVFS_DEVFSDEFS_H__ */