]> git.saurik.com Git - apple/xnu.git/blame - bsd/miscfs/devfs/devfsdefs.h
xnu-792.6.56.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 *
ff6e181a
A
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
11 * file.
1c79356b 12 *
ff6e181a
A
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
1c79356b
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
ff6e181a
A
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.
1c79356b
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * Copyright 1997,1998 Julian Elischer. All rights reserved.
25 * julian@freebsd.org
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions are
29 * met:
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.
35 *
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
46 * SUCH DAMAGE.
47 *
48 * devfsdefs.h
49 */
50
51/*
52 * HISTORY
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.
57 */
58
9bccf70c
A
59#ifndef __DEVFS_DEVFSDEFS_H__
60#define __DEVFS_DEVFSDEFS_H__
1c79356b 61
9bccf70c
A
62#include <sys/appleapiopts.h>
63
64#ifdef __APPLE_API_PRIVATE
1c79356b
A
65#define DEVMAXNAMESIZE 32 /* XXX */
66#define DEVMAXPATHSIZE 128 /* XXX */
67
68typedef enum {
69 DEV_DIR,
70 DEV_BDEV,
71 DEV_CDEV,
55e303ae 72 DEV_SLNK
1c79356b
A
73} devfstype_t;
74
75extern int (**devfs_vnodeop_p)(void *); /* our own vector array for dirs */
76extern int (**devfs_spec_vnodeop_p)(void *); /* our own vector array for devs */
77extern struct vfsops devfs_vfsops;
78
79typedef struct devnode devnode_t;
80typedef struct devdirent devdirent_t;
81typedef union devnode_type devnode_type_t;
82
83struct devfs_stats {
84 int nodes;
85 int entries;
86 int mounts;
87 int stringspace;
88};
89
90union devnode_type {
91 dev_t dev;
92 struct {
93 devdirent_t * dirlist;
94 devdirent_t * * dirlast;
95 devnode_t * parent;
96 devdirent_t * myname; /* my entry in .. */
97 int entrycount;
98 }Dir;
99 struct {
100 char * name; /* must be allocated separately */
101 int namelen;
102 }Slnk;
103};
104
1c79356b
A
105struct devnode
106{
107 devfstype_t dn_type;
108 int dn_flags;
109 u_short dn_mode;
0b4e3aa0
A
110 uid_t dn_uid;
111 gid_t dn_gid;
1c79356b
A
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 */
1c79356b
A
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 */
91447636
A
125 int dn_change;
126 int dn_update;
127 int dn_access;
128 int dn_lflags;
1c79356b
A
129};
130
91447636
A
131#define DN_BUSY 0x01
132#define DN_DELETE 0x02
133#define DN_CREATE 0x04
134#define DN_CREATEWAIT 0x08
135
136
1c79356b
A
137struct devdirent
138{
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 */
147};
148
149extern devdirent_t * dev_root;
1c79356b 150extern struct devfs_stats devfs_stats;
91447636 151extern lck_mtx_t devfs_mutex;
1c79356b
A
152
153/*
154 * Rules for front nodes:
155 * Dirs hava a strict 1:1 relationship with their OWN devnode
156 * Symlinks similarly
157 * Device Nodes ALWAYS point to the devnode that is linked
158 * to the Backing node. (with a ref count)
159 */
160
161/*
162 * DEVFS specific per/mount information, used to link a monted fs to a
163 * particular 'plane' of front nodes.
164 */
165struct devfsmount
166{
167 struct mount * mount; /* vfs mount struct for this fs */
168 devdirent_t * plane_root;/* the root of this 'plane' */
169};
170
171/*
172 * Prototypes for DEVFS virtual filesystem operations
173 */
174#include <sys/lock.h>
175#include <miscfs/devfs/devfs_proto.h>
176
177//#define HIDDEN_MOUNTPOINT 1
178
179/* misc */
180#define M_DEVFSNAME M_DEVFS
181#define M_DEVFSNODE M_DEVFS
182#define M_DEVFSMNT M_DEVFS
183
1c79356b 184#define VTODN(vp) ((devnode_t *)(vp)->v_data)
1c79356b 185
91447636
A
186#define DEVFS_LOCK() lck_mtx_lock(&devfs_mutex)
187
188#define DEVFS_UNLOCK() lck_mtx_unlock(&devfs_mutex)
189
1c79356b 190
1c79356b
A
191
192static __inline__ void
193DEVFS_INCR_ENTRIES()
194{
91447636 195 OSAddAtomic(1, &devfs_stats.entries);
1c79356b
A
196}
197
198static __inline__ void
199DEVFS_DECR_ENTRIES()
200{
91447636 201 OSAddAtomic(-1, &devfs_stats.entries);
1c79356b
A
202}
203
204static __inline__ void
205DEVFS_INCR_NODES()
206{
91447636 207 OSAddAtomic(1, &devfs_stats.nodes);
1c79356b
A
208}
209
210static __inline__ void
211DEVFS_DECR_NODES()
212{
91447636 213 OSAddAtomic(-1, &devfs_stats.nodes);
1c79356b
A
214}
215
216static __inline__ void
217DEVFS_INCR_MOUNTS()
218{
91447636 219 OSAddAtomic(1, &devfs_stats.mounts);
1c79356b
A
220}
221
222static __inline__ void
223DEVFS_DECR_MOUNTS()
224{
91447636 225 OSAddAtomic(-1, &devfs_stats.mounts);
1c79356b
A
226}
227
228static __inline__ void
229DEVFS_INCR_STRINGSPACE(int space)
230{
91447636 231 OSAddAtomic(space, &devfs_stats.stringspace);
1c79356b
A
232}
233
234static __inline__ void
235DEVFS_DECR_STRINGSPACE(int space)
236{
91447636 237 OSAddAtomic(-space, &devfs_stats.stringspace);
1c79356b
A
238}
239
240static __inline__ void
91447636 241dn_times(devnode_t * dnp, struct timeval *t1, struct timeval *t2, struct timeval *t3)
1c79356b 242{
91447636
A
243 if (dnp->dn_access) {
244 dnp->dn_atime.tv_sec = t1->tv_sec;
245 dnp->dn_atime.tv_nsec = t1->tv_usec * 1000;
246 dnp->dn_access = 0;
1c79356b 247 }
91447636
A
248 if (dnp->dn_update) {
249 dnp->dn_mtime.tv_sec = t2->tv_sec;
250 dnp->dn_mtime.tv_nsec = t2->tv_usec * 1000;
251 dnp->dn_update = 0;
1c79356b 252 }
91447636
A
253 if (dnp->dn_change) {
254 dnp->dn_ctime.tv_sec = t3->tv_sec;
255 dnp->dn_ctime.tv_nsec = t3->tv_usec * 1000;
256 dnp->dn_change = 0;
1c79356b 257 }
91447636
A
258
259 return;
1c79356b
A
260}
261
262static __inline__ void
263dn_copy_times(devnode_t * target, devnode_t * source)
264{
265 target->dn_atime = source->dn_atime;
266 target->dn_mtime = source->dn_mtime;
267 target->dn_ctime = source->dn_ctime;
268 return;
269}
9bccf70c
A
270#endif /* __APPLE_API_PRIVATE */
271#endif /* __DEVFS_DEVFSDEFS_H__ */