]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. |
3 | * | |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 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. 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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright 1997,1998 Julian Elischer. All rights reserved. | |
30 | * julian@freebsd.org | |
31 | * | |
32 | * Redistribution and use in source and binary forms, with or without | |
33 | * modification, are permitted provided that the following conditions are | |
34 | * met: | |
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. | |
40 | * | |
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 | |
51 | * SUCH DAMAGE. | |
52 | * | |
53 | * devfsdefs.h | |
54 | */ | |
2d21ac55 A |
55 | /* |
56 | * NOTICE: This file was modified by McAfee Research in 2004 to introduce | |
57 | * support for mandatory and extensible security protections. This notice | |
58 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
59 | * Version 2.0. | |
60 | */ | |
1c79356b A |
61 | |
62 | /* | |
63 | * HISTORY | |
64 | * 8-April-1999 Dieter Siegmund (dieter@apple.com) | |
65 | * Ported to from FreeBSD 3.1 | |
66 | * Removed unnecessary/unused defines | |
67 | * Renamed structures/elements to clarify usage in code. | |
68 | */ | |
69 | ||
9bccf70c A |
70 | #ifndef __DEVFS_DEVFSDEFS_H__ |
71 | #define __DEVFS_DEVFSDEFS_H__ | |
1c79356b | 72 | |
9bccf70c A |
73 | #include <sys/appleapiopts.h> |
74 | ||
2d21ac55 A |
75 | #include <security/mac.h> |
76 | ||
9bccf70c | 77 | #ifdef __APPLE_API_PRIVATE |
1c79356b A |
78 | #define DEVMAXNAMESIZE 32 /* XXX */ |
79 | #define DEVMAXPATHSIZE 128 /* XXX */ | |
80 | ||
81 | typedef enum { | |
82 | DEV_DIR, | |
83 | DEV_BDEV, | |
84 | DEV_CDEV, | |
55e303ae | 85 | DEV_SLNK |
1c79356b A |
86 | } devfstype_t; |
87 | ||
88 | extern int (**devfs_vnodeop_p)(void *); /* our own vector array for dirs */ | |
89 | extern int (**devfs_spec_vnodeop_p)(void *); /* our own vector array for devs */ | |
90 | extern struct vfsops devfs_vfsops; | |
91 | ||
92 | typedef struct devnode devnode_t; | |
93 | typedef struct devdirent devdirent_t; | |
94 | typedef union devnode_type devnode_type_t; | |
95 | ||
96 | struct devfs_stats { | |
97 | int nodes; | |
98 | int entries; | |
99 | int mounts; | |
100 | int stringspace; | |
101 | }; | |
102 | ||
103 | union devnode_type { | |
104 | dev_t dev; | |
105 | struct { | |
106 | devdirent_t * dirlist; | |
107 | devdirent_t * * dirlast; | |
108 | devnode_t * parent; | |
109 | devdirent_t * myname; /* my entry in .. */ | |
110 | int entrycount; | |
111 | }Dir; | |
112 | struct { | |
113 | char * name; /* must be allocated separately */ | |
114 | int namelen; | |
115 | }Slnk; | |
116 | }; | |
117 | ||
1c79356b A |
118 | struct devnode |
119 | { | |
120 | devfstype_t dn_type; | |
121 | int dn_flags; | |
122 | u_short dn_mode; | |
0b4e3aa0 A |
123 | uid_t dn_uid; |
124 | gid_t dn_gid; | |
1c79356b A |
125 | struct timespec dn_atime;/* time of last access */ |
126 | struct timespec dn_mtime;/* time of last modification */ | |
127 | struct timespec dn_ctime;/* time file changed */ | |
128 | int (***dn_ops)(void *);/* yuk... pointer to pointer(s) to funcs */ | |
129 | int dn_links;/* how many file links does this node have? */ | |
130 | struct devfsmount * dn_dvm; /* the mount structure for this 'plane' */ | |
131 | struct vnode * dn_vn; /* address of last vnode that represented us */ | |
132 | int dn_len; /* of any associated info (e.g. dir data) */ | |
133 | devdirent_t * dn_linklist;/* circular list of hardlinks to this node */ | |
1c79356b A |
134 | devnode_t * dn_nextsibling; /* the list of equivalent nodes */ |
135 | devnode_t * * dn_prevsiblingp;/* backpointer for the above */ | |
136 | devnode_type_t dn_typeinfo; | |
137 | int dn_delete; /* mark for deletion */ | |
91447636 A |
138 | int dn_change; |
139 | int dn_update; | |
140 | int dn_access; | |
141 | int dn_lflags; | |
2d21ac55 A |
142 | int (*dn_clone)(dev_t dev, int action); /* get minor # */ |
143 | struct label * dn_label; /* security label */ | |
1c79356b A |
144 | }; |
145 | ||
91447636 A |
146 | #define DN_BUSY 0x01 |
147 | #define DN_DELETE 0x02 | |
148 | #define DN_CREATE 0x04 | |
149 | #define DN_CREATEWAIT 0x08 | |
150 | ||
151 | ||
1c79356b A |
152 | struct devdirent |
153 | { | |
154 | /*-----------------------directory entry fields-------------*/ | |
155 | char de_name[DEVMAXNAMESIZE]; | |
156 | devnode_t * de_dnp; /* the "inode" (devnode) pointer */ | |
157 | devnode_t * de_parent; /* backpointer to the directory itself */ | |
158 | devdirent_t * de_next; /* next object in this directory */ | |
159 | devdirent_t * *de_prevp; /* previous pointer in directory linked list */ | |
160 | devdirent_t * de_nextlink; /* next hardlink to this node */ | |
161 | devdirent_t * *de_prevlinkp; /* previous hardlink pointer for this node */ | |
162 | }; | |
163 | ||
164 | extern devdirent_t * dev_root; | |
1c79356b | 165 | extern struct devfs_stats devfs_stats; |
91447636 | 166 | extern lck_mtx_t devfs_mutex; |
1c79356b A |
167 | |
168 | /* | |
169 | * Rules for front nodes: | |
170 | * Dirs hava a strict 1:1 relationship with their OWN devnode | |
171 | * Symlinks similarly | |
172 | * Device Nodes ALWAYS point to the devnode that is linked | |
173 | * to the Backing node. (with a ref count) | |
174 | */ | |
175 | ||
176 | /* | |
177 | * DEVFS specific per/mount information, used to link a monted fs to a | |
178 | * particular 'plane' of front nodes. | |
179 | */ | |
180 | struct devfsmount | |
181 | { | |
182 | struct mount * mount; /* vfs mount struct for this fs */ | |
183 | devdirent_t * plane_root;/* the root of this 'plane' */ | |
184 | }; | |
185 | ||
186 | /* | |
187 | * Prototypes for DEVFS virtual filesystem operations | |
188 | */ | |
189 | #include <sys/lock.h> | |
190 | #include <miscfs/devfs/devfs_proto.h> | |
2d21ac55 | 191 | #include <libkern/OSAtomic.h> /* required for OSAddAtomic() */ |
1c79356b A |
192 | |
193 | //#define HIDDEN_MOUNTPOINT 1 | |
194 | ||
195 | /* misc */ | |
196 | #define M_DEVFSNAME M_DEVFS | |
197 | #define M_DEVFSNODE M_DEVFS | |
198 | #define M_DEVFSMNT M_DEVFS | |
199 | ||
1c79356b | 200 | #define VTODN(vp) ((devnode_t *)(vp)->v_data) |
1c79356b | 201 | |
91447636 A |
202 | #define DEVFS_LOCK() lck_mtx_lock(&devfs_mutex) |
203 | ||
204 | #define DEVFS_UNLOCK() lck_mtx_unlock(&devfs_mutex) | |
205 | ||
1c79356b | 206 | |
2d21ac55 A |
207 | /* |
208 | * XXX all the (SInt32 *) casts below assume sizeof(int) == sizeof(long) | |
209 | */ | |
1c79356b | 210 | static __inline__ void |
2d21ac55 | 211 | DEVFS_INCR_ENTRIES(void) |
1c79356b | 212 | { |
2d21ac55 | 213 | OSAddAtomic(1, (SInt32 *)&devfs_stats.entries); |
1c79356b A |
214 | } |
215 | ||
216 | static __inline__ void | |
2d21ac55 | 217 | DEVFS_DECR_ENTRIES(void) |
1c79356b | 218 | { |
2d21ac55 | 219 | OSAddAtomic(-1, (SInt32 *)&devfs_stats.entries); |
1c79356b A |
220 | } |
221 | ||
222 | static __inline__ void | |
2d21ac55 | 223 | DEVFS_INCR_NODES(void) |
1c79356b | 224 | { |
2d21ac55 | 225 | OSAddAtomic(1, (SInt32 *)&devfs_stats.nodes); |
1c79356b A |
226 | } |
227 | ||
228 | static __inline__ void | |
2d21ac55 | 229 | DEVFS_DECR_NODES(void) |
1c79356b | 230 | { |
2d21ac55 | 231 | OSAddAtomic(-1, (SInt32 *)&devfs_stats.nodes); |
1c79356b A |
232 | } |
233 | ||
234 | static __inline__ void | |
2d21ac55 | 235 | DEVFS_INCR_MOUNTS(void) |
1c79356b | 236 | { |
2d21ac55 | 237 | OSAddAtomic(1, (SInt32 *)&devfs_stats.mounts); |
1c79356b A |
238 | } |
239 | ||
240 | static __inline__ void | |
2d21ac55 | 241 | DEVFS_DECR_MOUNTS(void) |
1c79356b | 242 | { |
2d21ac55 | 243 | OSAddAtomic(-1, (SInt32 *)&devfs_stats.mounts); |
1c79356b A |
244 | } |
245 | ||
246 | static __inline__ void | |
247 | DEVFS_INCR_STRINGSPACE(int space) | |
248 | { | |
2d21ac55 | 249 | OSAddAtomic(space, (SInt32 *)&devfs_stats.stringspace); |
1c79356b A |
250 | } |
251 | ||
252 | static __inline__ void | |
253 | DEVFS_DECR_STRINGSPACE(int space) | |
254 | { | |
2d21ac55 | 255 | OSAddAtomic(-space, (SInt32 *)&devfs_stats.stringspace); |
1c79356b A |
256 | } |
257 | ||
258 | static __inline__ void | |
91447636 | 259 | dn_times(devnode_t * dnp, struct timeval *t1, struct timeval *t2, struct timeval *t3) |
1c79356b | 260 | { |
91447636 A |
261 | if (dnp->dn_access) { |
262 | dnp->dn_atime.tv_sec = t1->tv_sec; | |
263 | dnp->dn_atime.tv_nsec = t1->tv_usec * 1000; | |
264 | dnp->dn_access = 0; | |
1c79356b | 265 | } |
91447636 A |
266 | if (dnp->dn_update) { |
267 | dnp->dn_mtime.tv_sec = t2->tv_sec; | |
268 | dnp->dn_mtime.tv_nsec = t2->tv_usec * 1000; | |
269 | dnp->dn_update = 0; | |
1c79356b | 270 | } |
91447636 A |
271 | if (dnp->dn_change) { |
272 | dnp->dn_ctime.tv_sec = t3->tv_sec; | |
273 | dnp->dn_ctime.tv_nsec = t3->tv_usec * 1000; | |
274 | dnp->dn_change = 0; | |
1c79356b | 275 | } |
91447636 A |
276 | |
277 | return; | |
1c79356b A |
278 | } |
279 | ||
280 | static __inline__ void | |
281 | dn_copy_times(devnode_t * target, devnode_t * source) | |
282 | { | |
283 | target->dn_atime = source->dn_atime; | |
284 | target->dn_mtime = source->dn_mtime; | |
285 | target->dn_ctime = source->dn_ctime; | |
286 | return; | |
287 | } | |
9bccf70c A |
288 | #endif /* __APPLE_API_PRIVATE */ |
289 | #endif /* __DEVFS_DEVFSDEFS_H__ */ |