]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 1998-2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ | |
5 | * | |
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 | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
29 | */ | |
30 | ||
31 | #include <sys/param.h> | |
32 | #include <sys/systm.h> | |
33 | #include <sys/namei.h> | |
34 | #include <sys/proc.h> | |
35 | #include <sys/kernel.h> | |
36 | #include <mach/machine/vm_types.h> | |
37 | #include <sys/vnode.h> | |
38 | #include <sys/socket.h> | |
39 | #include <sys/mount_internal.h> | |
40 | #include <sys/mbuf.h> | |
41 | #include <sys/file.h> | |
42 | #include <sys/disk.h> | |
43 | #include <sys/ioctl.h> | |
44 | #include <sys/errno.h> | |
45 | #include <sys/malloc.h> | |
46 | #include <dev/ldd.h> | |
47 | ||
48 | #include <miscfs/specfs/specdev.h> | |
49 | #include "volfs.h" | |
50 | ||
51 | static int volfs_mount(struct mount *, vnode_t , user_addr_t, vfs_context_t); | |
52 | static int volfs_start(struct mount *, int, vfs_context_t); | |
53 | static int volfs_unmount(struct mount *, int, vfs_context_t); | |
54 | static int volfs_root(struct mount *, struct vnode **, vfs_context_t); | |
55 | static int volfs_vfs_getattr(mount_t mp, struct vfs_attr *fsap, vfs_context_t context); | |
56 | static int volfs_sync(struct mount *, int, vfs_context_t); | |
57 | static int volfs_vget(struct mount *, ino64_t, struct vnode **, vfs_context_t); | |
58 | static int volfs_fhtovp(struct mount *, int, unsigned char *, struct vnode **, vfs_context_t); | |
59 | static int volfs_vptofh(struct vnode *, int *, unsigned char *, vfs_context_t); | |
60 | static int volfs_init(struct vfsconf *); | |
61 | static int volfs_sysctl(int *, u_int, user_addr_t, size_t *, user_addr_t, size_t, vfs_context_t); | |
62 | void volfs_load(int loadArgument); | |
63 | ||
64 | ||
65 | struct vfsops volfs_vfsops = { | |
66 | volfs_mount, | |
67 | volfs_start, | |
68 | volfs_unmount, | |
69 | volfs_root, | |
70 | NULL, /* quotactl */ | |
71 | volfs_vfs_getattr, | |
72 | volfs_sync, | |
73 | volfs_vget, | |
74 | volfs_fhtovp, | |
75 | volfs_vptofh, | |
76 | volfs_init, | |
77 | volfs_sysctl | |
78 | }; | |
79 | ||
80 | // static char volfs_fs_name[MFSNAMELEN] = "volfs"; | |
81 | extern struct vnodeopv_desc volfs_vnodeop_opv_desc; | |
82 | ||
83 | extern int (**volfs_vnodeop_p)(void *); | |
84 | ||
85 | /* The following refer to kernel global variables used in the loading/initialization: */ | |
86 | extern int vfs_opv_numops; /* The total number of defined vnode operations */ | |
87 | extern int kdp_flag; | |
88 | ||
89 | void | |
90 | volfs_load(__unused int loadArgument) | |
91 | { | |
92 | #if 0 | |
93 | struct vfsconf *vfsconflistentry; | |
94 | int entriesRemaining; | |
95 | struct vfsconf *newvfsconf = NULL; | |
96 | struct vfsconf *lastentry = NULL; | |
97 | int j; | |
98 | int (***opv_desc_vector_p)(); | |
99 | int (**opv_desc_vector)(); | |
100 | struct vnodeopv_entry_desc *opve_descp; | |
101 | ||
102 | /* | |
103 | * This routine is responsible for all the initialization that would | |
104 | * ordinarily be done as part of the system startup; it calls volfs_init | |
105 | * to do the initialization that is strictly volfs-specific. | |
106 | */ | |
107 | ||
108 | /* | |
109 | prevvfsconf is supposed to be the entry preceding the new entry. | |
110 | To make sure we can always get hooked in SOMEWHERE in the list, | |
111 | start it out at the first entry of the list. This assumes the | |
112 | first entry in the list will be non-empty and not volfs. | |
113 | ||
114 | This becomes irrelevant when volfs is compiled into the list. | |
115 | */ | |
116 | vfsconflistentry = vfsconf; | |
117 | for (entriesRemaining = maxvfsslots; entriesRemaining > 0; --entriesRemaining) { | |
118 | if (vfsconflistentry->vfc_vfsops != NULL) { | |
119 | /* | |
120 | * Check to see if we're reloading a new version of volfs during debugging | |
121 | * and overwrite the previously assigned entry if we find one: | |
122 | */ | |
123 | if (strcmp(vfsconflistentry->vfc_name, volfs_fs_name) == 0) { | |
124 | newvfsconf = vfsconflistentry; | |
125 | break; | |
126 | } else { | |
127 | lastentry = vfsconflistentry; | |
128 | }; | |
129 | } else { | |
130 | /* | |
131 | * This is at least a POSSIBLE place to insert the new entry... | |
132 | */ | |
133 | newvfsconf = vfsconflistentry; | |
134 | }; | |
135 | ++vfsconflistentry; | |
136 | }; | |
137 | ||
138 | if (newvfsconf) { | |
139 | newvfsconf->vfc_vfsops = &volfs_vfsops; | |
140 | strncpy(&newvfsconf->vfc_name[0], "volfs", MFSNAMELEN); | |
141 | newvfsconf->vfc_typenum = maxvfsconf++; | |
142 | newvfsconf->vfc_refcount = 0; | |
143 | newvfsconf->vfc_flags = 0; | |
144 | newvfsconf->vfc_mountroot = NULL; /* Can't mount root of file system [yet] */ | |
145 | ||
146 | /* Hook into the list: */ | |
147 | newvfsconf->vfc_next = NULL; | |
148 | if (lastentry) { | |
149 | newvfsconf->vfc_next = lastentry->vfc_next; | |
150 | lastentry->vfc_next = newvfsconf; | |
151 | }; | |
152 | ||
153 | /* Based on vfs_op_init and ... */ | |
154 | opv_desc_vector_p = volfs_vnodeop_opv_desc.opv_desc_vector_p; | |
155 | ||
156 | /* | |
157 | * Allocate and init the vector. | |
158 | * Also handle backwards compatibility. | |
159 | */ | |
160 | MALLOC(*opv_desc_vector_p, PFI *, vfs_opv_numops*sizeof(PFI), M_TEMP, M_WAITOK); | |
161 | ||
162 | bzero (*opv_desc_vector_p, vfs_opv_numops*sizeof(PFI)); | |
163 | ||
164 | opv_desc_vector = *opv_desc_vector_p; | |
165 | for (j=0; volfs_vnodeop_opv_desc.opv_desc_ops[j].opve_op; j++) { | |
166 | opve_descp = &(volfs_vnodeop_opv_desc.opv_desc_ops[j]); | |
167 | ||
168 | /* | |
169 | * Sanity check: is this operation listed | |
170 | * in the list of operations? We check this | |
171 | * by seeing if its offest is zero. Since | |
172 | * the default routine should always be listed | |
173 | * first, it should be the only one with a zero | |
174 | * offset. Any other operation with a zero | |
175 | * offset is probably not listed in | |
176 | * vfs_op_descs, and so is probably an error. | |
177 | * | |
178 | * A panic here means the layer programmer | |
179 | * has committed the all-too common bug | |
180 | * of adding a new operation to the layer's | |
181 | * list of vnode operations but | |
182 | * not adding the operation to the system-wide | |
183 | * list of supported operations. | |
184 | */ | |
185 | if (opve_descp->opve_op->vdesc_offset == 0 && | |
186 | opve_descp->opve_op->vdesc_offset != VOFFSET(vnop_default)) { | |
187 | panic ("load_volfs: bad operation"); | |
188 | } | |
189 | /* | |
190 | * Fill in this entry. | |
191 | */ | |
192 | opv_desc_vector[opve_descp->opve_op->vdesc_offset] = | |
193 | opve_descp->opve_impl; | |
194 | } | |
195 | ||
196 | /* | |
197 | * Finally, go back and replace unfilled routines | |
198 | * with their default. (Sigh, an O(n^3) algorithm. I | |
199 | * could make it better, but that'd be work, and n is small.) | |
200 | */ | |
201 | opv_desc_vector_p = volfs_vnodeop_opv_desc.opv_desc_vector_p; | |
202 | ||
203 | /* | |
204 | * Force every operations vector to have a default routine. | |
205 | */ | |
206 | opv_desc_vector = *opv_desc_vector_p; | |
207 | if (opv_desc_vector[VOFFSET(vnop_default)]==NULL) { | |
208 | panic("load_vp;fs: operation vector without default routine."); | |
209 | } | |
210 | for (j = 0;j<vfs_opv_numops; j++) | |
211 | if (opv_desc_vector[j] == NULL) | |
212 | opv_desc_vector[j] = | |
213 | opv_desc_vector[VOFFSET(vnop_default)]; | |
214 | ||
215 | volfs_init(newvfsconf); | |
216 | }; | |
217 | #else | |
218 | panic("volfs load not ported"); | |
219 | #endif | |
220 | } | |
221 | ||
222 | /* | |
223 | * VFS Operations. | |
224 | * | |
225 | * mount system call | |
226 | */ | |
227 | static int | |
228 | volfs_mount(struct mount *mp, __unused vnode_t devvp, __unused user_addr_t data, __unused vfs_context_t context) | |
229 | { | |
230 | struct volfs_mntdata *priv_mnt_data; | |
231 | struct vnode *root_vp; | |
232 | struct volfs_vndata *priv_vn_data; | |
233 | int error; | |
234 | struct vnode_fsparam vfsp; | |
235 | ||
236 | MALLOC(priv_mnt_data, struct volfs_mntdata *, sizeof(struct volfs_mntdata), | |
237 | M_VOLFSMNT, M_WAITOK); | |
238 | ||
239 | mp->mnt_data = (void *)priv_mnt_data; | |
240 | strcpy(mp->mnt_vfsstat.f_fstypename, "volfs"); | |
241 | strcpy(mp->mnt_vfsstat.f_mntfromname, "<volfs>"); | |
242 | ||
243 | /* Set up the root vnode for fast reference in the future. | |
244 | Note that the root is maintained unlocked but with a pos. ref count until unmount. */ | |
245 | ||
246 | MALLOC(priv_vn_data, struct volfs_vndata *, sizeof(struct volfs_vndata), M_VOLFSNODE, M_WAITOK); | |
247 | ||
248 | priv_vn_data->vnode_type = VOLFS_ROOT; | |
249 | priv_vn_data->nodeID = ROOT_DIRID; | |
250 | priv_vn_data->fs_mount = mp; | |
251 | priv_vn_data->fs_fsid = mp->mnt_vfsstat.f_fsid; | |
252 | ||
253 | vfsp.vnfs_mp = mp; | |
254 | vfsp.vnfs_vtype = VDIR; | |
255 | vfsp.vnfs_str = "volfs"; | |
256 | vfsp.vnfs_dvp = 0; | |
257 | vfsp.vnfs_fsnode = priv_vn_data; | |
258 | vfsp.vnfs_cnp = 0; | |
259 | vfsp.vnfs_vops = volfs_vnodeop_p; | |
260 | vfsp.vnfs_rdev = 0; | |
261 | vfsp.vnfs_filesize = 0; | |
262 | vfsp.vnfs_flags = VNFS_NOCACHE | VNFS_CANTCACHE; | |
263 | vfsp.vnfs_marksystem = 0; | |
264 | vfsp.vnfs_markroot = 1; | |
265 | ||
266 | error = vnode_create(VNCREATE_FLAVOR, VCREATESIZE, &vfsp, &root_vp); | |
267 | if (error != 0) { | |
268 | FREE(priv_mnt_data, M_VOLFSMNT); | |
269 | FREE(priv_vn_data, M_VOLFSNODE); | |
270 | return(error); | |
271 | } | |
272 | vnode_ref(root_vp); | |
273 | vnode_put(root_vp); | |
274 | ||
275 | /* obtain a new fsid for the mount point */ | |
276 | vfs_getnewfsid(mp); | |
277 | ||
278 | vnode_settag(root_vp, VT_VOLFS); | |
279 | ||
280 | priv_mnt_data->volfs_rootvp = root_vp; | |
281 | mp->mnt_flag &= ~MNT_RDONLY; | |
282 | ||
283 | mp->mnt_vtable->vfc_threadsafe = TRUE; | |
284 | ||
285 | return (0); | |
286 | } | |
287 | ||
288 | static int | |
289 | volfs_start(__unused struct mount * mp, __unused int flags, __unused vfs_context_t context) | |
290 | { | |
291 | return (0); | |
292 | } | |
293 | ||
294 | /* | |
295 | * Return the root of a filesystem. For volfs the root vnode is a directory | |
296 | * containing the list of all filesystems volfs can work with. | |
297 | */ | |
298 | static int | |
299 | volfs_root(struct mount *mp, struct vnode **vpp, __unused vfs_context_t context) | |
300 | { | |
301 | struct volfs_mntdata *priv_data; | |
302 | ||
303 | priv_data = (struct volfs_mntdata *)mp->mnt_data; | |
304 | ||
305 | if (priv_data->volfs_rootvp) { | |
306 | vnode_get(priv_data->volfs_rootvp); | |
307 | *vpp = priv_data->volfs_rootvp; | |
308 | } else { | |
309 | panic("volfs: root vnode missing!"); | |
310 | }; | |
311 | ||
312 | return(0); | |
313 | } | |
314 | ||
315 | /* | |
316 | * unmount system call | |
317 | */ | |
318 | static int | |
319 | volfs_unmount(struct mount *mp, __unused int mntflags, __unused vfs_context_t context) | |
320 | { | |
321 | struct volfs_mntdata *priv_data; | |
322 | struct vnode *root_vp; | |
323 | int retval; | |
324 | ||
325 | priv_data = (struct volfs_mntdata *)mp->mnt_data; | |
326 | ||
327 | root_vp = priv_data->volfs_rootvp; | |
328 | retval = vflush(mp, root_vp, 0); | |
329 | if (retval) goto Err_Exit; | |
330 | ||
331 | /* Free the root vnode. | |
332 | Note that there's no need to vget() or vref() it before locking it here: | |
333 | the ref. count has been maintained at +1 ever since mount time. */ | |
334 | if (root_vp) { | |
335 | if (vnode_isinuse(root_vp, 1)) { | |
336 | retval = EBUSY; | |
337 | goto Err_Exit; | |
338 | }; | |
339 | ||
340 | priv_data->volfs_rootvp = NULL; | |
341 | vnode_rele(root_vp); /* This drops volfs's own refcount */ | |
342 | vnode_reclaim(root_vp); | |
343 | }; | |
344 | ||
345 | /* All vnodes should be gone, and no errors, clean up the last */ | |
346 | ||
347 | mp->mnt_data = NULL; | |
348 | FREE(priv_data, M_VOLFSMNT); | |
349 | ||
350 | Err_Exit: | |
351 | ||
352 | return(retval); | |
353 | } | |
354 | ||
355 | /* | |
356 | * Get file system statistics. | |
357 | */ | |
358 | static int | |
359 | volfs_vfs_getattr(mount_t mp, struct vfs_attr *fsap, vfs_context_t context) | |
360 | { | |
361 | VFSATTR_RETURN(fsap, f_bsize, 512); | |
362 | VFSATTR_RETURN(fsap, f_iosize, 512); | |
363 | VFSATTR_RETURN(fsap, f_blocks, 1024); | |
364 | VFSATTR_RETURN(fsap, f_bfree, 0); | |
365 | VFSATTR_RETURN(fsap, f_bavail, 0); | |
366 | VFSATTR_RETURN(fsap, f_bused, 1024); | |
367 | VFSATTR_RETURN(fsap, f_files, 0); | |
368 | VFSATTR_RETURN(fsap, f_ffree, 0); | |
369 | VFSATTR_RETURN(fsap, f_fssubtype, 0); | |
370 | return 0; | |
371 | } | |
372 | ||
373 | /* | |
374 | * volfs doesn't have any data and you can't write into any of the volfs | |
375 | * structures, so don't do anything | |
376 | */ | |
377 | static int | |
378 | volfs_sync(__unused struct mount *mp, __unused int waitfor, __unused vfs_context_t context) | |
379 | { | |
380 | return 0; | |
381 | } | |
382 | ||
383 | /* | |
384 | * | |
385 | */ | |
386 | static int | |
387 | volfs_vget(__unused struct mount *mp, __unused ino64_t ino, | |
388 | __unused struct vnode **vpp, __unused vfs_context_t context) | |
389 | { | |
390 | return(ENOTSUP); | |
391 | } | |
392 | ||
393 | /* | |
394 | * File handle to vnode | |
395 | */ | |
396 | static int | |
397 | volfs_fhtovp(__unused struct mount *mp, __unused int fhlen, | |
398 | __unused unsigned char *fhp, __unused struct vnode **vpp, | |
399 | __unused vfs_context_t context) | |
400 | { | |
401 | return(ENOTSUP); | |
402 | } | |
403 | ||
404 | /* | |
405 | * Vnode pointer to File handle | |
406 | */ | |
407 | static int | |
408 | volfs_vptofh(__unused struct vnode *vp, __unused int *fhlenp, __unused unsigned char *fhp, __unused vfs_context_t context) | |
409 | { | |
410 | return(ENOTSUP); | |
411 | } | |
412 | ||
413 | /* | |
414 | * Initialize the filesystem | |
415 | */ | |
416 | static int | |
417 | volfs_init(__unused struct vfsconf *vfsp) | |
418 | { | |
419 | return (0); | |
420 | } | |
421 | ||
422 | /* | |
423 | * fast filesystem related variables. | |
424 | */ | |
425 | static int | |
426 | volfs_sysctl(__unused int *name, __unused u_int namelen, __unused user_addr_t oldp, | |
427 | __unused size_t *oldlenp, __unused user_addr_t newp, __unused size_t newlen, | |
428 | __unused vfs_context_t context) | |
429 | { | |
430 | return (ENOTSUP); | |
431 | } | |
432 |