]> git.saurik.com Git - apple/xnu.git/blame - bsd/miscfs/devfs/devfsdefs.h
xnu-201.42.3.tar.gz
[apple/xnu.git] / bsd / miscfs / devfs / devfsdefs.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright 1997,1998 Julian Elischer. All rights reserved.
24 * julian@freebsd.org
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions are
28 * met:
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright notice,
32 * this list of conditions and the following disclaimer in the documentation
33 * and/or other materials provided with the distribution.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
36 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
37 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
39 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
41 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
42 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 * devfsdefs.h
48 */
49
50/*
51 * HISTORY
52 * 8-April-1999 Dieter Siegmund (dieter@apple.com)
53 * Ported to from FreeBSD 3.1
54 * Removed unnecessary/unused defines
55 * Renamed structures/elements to clarify usage in code.
56 */
57
58
59#define DEVMAXNAMESIZE 32 /* XXX */
60#define DEVMAXPATHSIZE 128 /* XXX */
61
62typedef enum {
63 DEV_DIR,
64 DEV_BDEV,
65 DEV_CDEV,
66 DEV_SLNK,
67} devfstype_t;
68
69extern int (**devfs_vnodeop_p)(void *); /* our own vector array for dirs */
70extern int (**devfs_spec_vnodeop_p)(void *); /* our own vector array for devs */
71extern struct vfsops devfs_vfsops;
72
73typedef struct devnode devnode_t;
74typedef struct devdirent devdirent_t;
75typedef union devnode_type devnode_type_t;
76
77struct devfs_stats {
78 int nodes;
79 int entries;
80 int mounts;
81 int stringspace;
82};
83
84union devnode_type {
85 dev_t dev;
86 struct {
87 devdirent_t * dirlist;
88 devdirent_t * * dirlast;
89 devnode_t * parent;
90 devdirent_t * myname; /* my entry in .. */
91 int entrycount;
92 }Dir;
93 struct {
94 char * name; /* must be allocated separately */
95 int namelen;
96 }Slnk;
97};
98
99#define DN_ACCESS 0x0001 /* Access time update request. */
100#define DN_CHANGE 0x0002 /* Inode change time update request. */
101#define DN_UPDATE 0x0004 /* Modification time update request. */
102#define DN_MODIFIED 0x0008 /* Inode has been modified. */
103#define DN_RENAME 0x0010 /* Inode is being renamed. */
104
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 */
121 devdirent_t * dn_last_lookup; /* name I was last looked up from */
122 devnode_t * dn_nextsibling; /* the list of equivalent nodes */
123 devnode_t * * dn_prevsiblingp;/* backpointer for the above */
124 devnode_type_t dn_typeinfo;
125 int dn_delete; /* mark for deletion */
126};
127
128struct devdirent
129{
130 /*-----------------------directory entry fields-------------*/
131 char de_name[DEVMAXNAMESIZE];
132 devnode_t * de_dnp; /* the "inode" (devnode) pointer */
133 devnode_t * de_parent; /* backpointer to the directory itself */
134 devdirent_t * de_next; /* next object in this directory */
135 devdirent_t * *de_prevp; /* previous pointer in directory linked list */
136 devdirent_t * de_nextlink; /* next hardlink to this node */
137 devdirent_t * *de_prevlinkp; /* previous hardlink pointer for this node */
138};
139
140extern devdirent_t * dev_root;
141extern struct lock__bsd__ devfs_lock;
142extern struct devfs_stats devfs_stats;
143
144/*
145 * Rules for front nodes:
146 * Dirs hava a strict 1:1 relationship with their OWN devnode
147 * Symlinks similarly
148 * Device Nodes ALWAYS point to the devnode that is linked
149 * to the Backing node. (with a ref count)
150 */
151
152/*
153 * DEVFS specific per/mount information, used to link a monted fs to a
154 * particular 'plane' of front nodes.
155 */
156struct devfsmount
157{
158 struct mount * mount; /* vfs mount struct for this fs */
159 devdirent_t * plane_root;/* the root of this 'plane' */
160};
161
162/*
163 * Prototypes for DEVFS virtual filesystem operations
164 */
165#include <sys/lock.h>
166#include <miscfs/devfs/devfs_proto.h>
167
168//#define HIDDEN_MOUNTPOINT 1
169
170/* misc */
171#define M_DEVFSNAME M_DEVFS
172#define M_DEVFSNODE M_DEVFS
173#define M_DEVFSMNT M_DEVFS
174
175static __inline__ void
176getnanotime(struct timespec * t_p)
177{
178 struct timeval tv;
179
180 microtime(&tv);
181 t_p->tv_sec = tv.tv_sec;
182 t_p->tv_nsec = tv.tv_usec * 1000;
183 return;
184}
185
186#define VTODN(vp) ((devnode_t *)(vp)->v_data)
187extern void cache_purge(struct vnode *vp); /* vfs_cache.c */
188
189static __inline__ int
190DEVFS_LOCK(struct proc * p)
191{
192 return (lockmgr(&devfs_lock, LK_EXCLUSIVE, NULL, p));
193}
194
195static __inline__ int
196DEVFS_UNLOCK(struct proc * p)
197{
198 return (lockmgr(&devfs_lock, LK_RELEASE, NULL, p));
199}
200
201static __inline__ void
202DEVFS_INCR_ENTRIES()
203{
204 devfs_stats.entries++;
205}
206
207static __inline__ void
208DEVFS_DECR_ENTRIES()
209{
210 devfs_stats.entries--;
211}
212
213static __inline__ void
214DEVFS_INCR_NODES()
215{
216 devfs_stats.nodes++;
217}
218
219static __inline__ void
220DEVFS_DECR_NODES()
221{
222 devfs_stats.nodes--;
223}
224
225static __inline__ void
226DEVFS_INCR_MOUNTS()
227{
228 devfs_stats.mounts++;
229}
230
231static __inline__ void
232DEVFS_DECR_MOUNTS()
233{
234 devfs_stats.mounts--;
235}
236
237static __inline__ void
238DEVFS_INCR_STRINGSPACE(int space)
239{
240 devfs_stats.stringspace += space;
241}
242
243static __inline__ void
244DEVFS_DECR_STRINGSPACE(int space)
245{
246 devfs_stats.stringspace -= space;
247 if (devfs_stats.stringspace < 0) {
248 printf("DEVFS_DECR_STRINGSPACE: (%d - %d < 0)\n",
249 devfs_stats.stringspace + space, space);
250 devfs_stats.stringspace = 0;
251 }
252}
253
254static __inline__ void
255dn_times(devnode_t * dnp, struct timeval t1, struct timeval t2)
256{
257 if (dnp->dn_flags & (DN_ACCESS | DN_CHANGE | DN_UPDATE)) {
258 if (dnp->dn_flags & DN_ACCESS) {
259 dnp->dn_atime.tv_sec = t1.tv_sec;
260 dnp->dn_atime.tv_nsec = t1.tv_usec * 1000;
261 }
262 if (dnp->dn_flags & DN_UPDATE) {
263 dnp->dn_mtime.tv_sec = t2.tv_sec;
264 dnp->dn_mtime.tv_nsec = t2.tv_usec * 1000;
265 }
266 if (dnp->dn_flags & DN_CHANGE) {
267 dnp->dn_ctime.tv_sec = time.tv_sec;
268 dnp->dn_ctime.tv_nsec = time.tv_usec * 1000;
269 }
270 dnp->dn_flags &= ~(DN_ACCESS | DN_CHANGE | DN_UPDATE);
271 }
272 return;
273}
274
275static __inline__ void
276dn_copy_times(devnode_t * target, devnode_t * source)
277{
278 target->dn_atime = source->dn_atime;
279 target->dn_mtime = source->dn_mtime;
280 target->dn_ctime = source->dn_ctime;
281 return;
282}