2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1998-1999 Apple Computer, Inc. All Rights Reserved.
25 * Modification History:
27 * 02-Feb-2000 Clark Warner Added copyfile to table
28 * 17-Aug-1999 Pat Dirks New today.
31 #include <mach/mach_types.h>
32 #include <mach/machine/boolean.h>
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
39 #include <sys/kauth.h>
41 #include <sys/mount_internal.h>
42 #include <sys/vnode_internal.h>
43 #include <sys/malloc.h>
44 #include <sys/dirent.h>
45 #include <sys/namei.h>
47 #include <sys/uio_internal.h>
50 #include <sys/errno.h>
51 #include <vfs/vfs_support.h>
58 #error NOT PORTED FOR UBC
62 static int synthfs_remove_internal(struct vnode
*dvp
, struct vnode
*vp
,
63 struct componentname
*cnp
, vfs_context_t context
);
66 #define VOPFUNC int (*)(void *)
68 /* Global vfs data structures for synthfs. */
69 int (**synthfs_vnodeop_p
) (void *);
70 struct vnodeopv_entry_desc synthfs_vnodeop_entries
[] = {
71 {&vnop_default_desc
, (VOPFUNC
)vn_default_error
},
72 {&vnop_strategy_desc
, (VOPFUNC
)err_strategy
}, /* strategy - not supported */
73 {&vnop_bwrite_desc
, (VOPFUNC
)err_bwrite
}, /* bwrite - not supported */
74 {&vnop_lookup_desc
, (VOPFUNC
)synthfs_cached_lookup
}, /* cached lookup */
75 {&vnop_create_desc
, (VOPFUNC
)synthfs_create
}, /* create - DEBUGGER */
76 {&vnop_whiteout_desc
, (VOPFUNC
)err_whiteout
}, /* whiteout - not supported */
77 {&vnop_mknod_desc
, (VOPFUNC
)err_mknod
}, /* mknod - not supported */
78 {&vnop_open_desc
, (VOPFUNC
)synthfs_open
}, /* open - DEBUGGER */
79 {&vnop_close_desc
, (VOPFUNC
)nop_close
}, /* close - NOP */
80 {&vnop_getattr_desc
, (VOPFUNC
)synthfs_getattr
}, /* getattr */
81 {&vnop_setattr_desc
, (VOPFUNC
)synthfs_setattr
}, /* setattr */
82 {&vnop_getattrlist_desc
, (VOPFUNC
)err_getattrlist
}, /* getattrlist - not supported */
83 {&vnop_setattrlist_desc
, (VOPFUNC
)err_setattrlist
}, /* setattrlist - not supported */
84 {&vnop_read_desc
, (VOPFUNC
)err_read
}, /* read - not supported */
85 {&vnop_write_desc
, (VOPFUNC
)err_write
}, /* write - not supported */
86 {&vnop_ioctl_desc
, (VOPFUNC
)err_ioctl
}, /* ioctl - not supported */
87 {&vnop_select_desc
, (VOPFUNC
)synthfs_select
}, /* select */
88 {&vnop_exchange_desc
, (VOPFUNC
)err_exchange
}, /* exchange - not supported */
89 {&vnop_revoke_desc
, (VOPFUNC
)nop_revoke
}, /* revoke - NOP */
90 {&vnop_mmap_desc
, (VOPFUNC
)synthfs_mmap
}, /* mmap - DEBUGGER */
91 {&vnop_fsync_desc
, (VOPFUNC
)nop_fsync
}, /* fsync - NOP */
92 {&vnop_remove_desc
, (VOPFUNC
)synthfs_remove
}, /* remove */
93 {&vnop_link_desc
, (VOPFUNC
)err_link
}, /* link - not supported */
94 {&vnop_rename_desc
, (VOPFUNC
)synthfs_rename
}, /* rename */
95 {&vnop_mkdir_desc
, (VOPFUNC
)synthfs_mkdir
}, /* mkdir */
96 {&vnop_rmdir_desc
, (VOPFUNC
)synthfs_rmdir
}, /* rmdir */
97 {&vnop_symlink_desc
, (VOPFUNC
)synthfs_symlink
}, /* symlink */
98 {&vnop_readdir_desc
, (VOPFUNC
)synthfs_readdir
}, /* readdir */
99 {&vnop_readdirattr_desc
, (VOPFUNC
)err_readdirattr
}, /* readdirattr - not supported */
100 {&vnop_readlink_desc
, (VOPFUNC
)synthfs_readlink
}, /* readlink */
101 {&vnop_inactive_desc
, (VOPFUNC
)synthfs_inactive
}, /* inactive */
102 {&vnop_reclaim_desc
, (VOPFUNC
)synthfs_reclaim
}, /* reclaim */
103 {&vnop_pathconf_desc
, (VOPFUNC
)synthfs_pathconf
}, /* pathconf */
104 {&vnop_advlock_desc
, (VOPFUNC
)err_advlock
}, /* advlock - not supported */
105 {&vnop_allocate_desc
, (VOPFUNC
)err_allocate
}, /* allocate - not supported */
106 {&vnop_pagein_desc
, (VOPFUNC
)err_pagein
}, /* pagein - not supported */
107 {&vnop_pageout_desc
, (VOPFUNC
)err_pageout
}, /* pageout - not supported */
108 {&vnop_searchfs_desc
, (VOPFUNC
)err_searchfs
}, /* searchfs - not supported */
109 {&vnop_copyfile_desc
, (VOPFUNC
)err_copyfile
}, /* copyfile - not supported */
110 { &vnop_blktooff_desc
, (VOPFUNC
)err_blktooff
}, /* blktooff not supported */
111 { &vnop_offtoblk_desc
, (VOPFUNC
)err_offtoblk
}, /* offtoblk not supported */
112 { &vnop_blockmap_desc
, (VOPFUNC
)err_blockmap
}, /* blockmap not supported */
113 {(struct vnodeop_desc
*) NULL
, (int (*) ()) NULL
}
117 * Oh what a tangled web we weave. This structure will be used by
118 * bsd/vfs/vfs_conf.c to actually do the initialization of synthfs_vnodeop_p
120 struct vnodeopv_desc synthfs_vnodeop_opv_desc
=
121 {&synthfs_vnodeop_p
, synthfs_vnodeop_entries
};
126 * Create a regular file
131 IN WILLRELE struct vnode *dvp;
132 OUT struct vnode **vpp;
133 IN struct componentname *cnp;
134 IN struct vnode_attr *vap;
136 We are responsible for freeing the namei buffer, it is done in hfs_makenode(), unless there is
143 struct vnop_create_args
/* {
145 struct vnode **a_vpp;
146 struct componentname *a_cnp;
147 struct vnode_attr *a_vap;
148 vfs_context_t a_context;
152 struct vnode
*dvp
= ap
->a_dvp
;
155 sprintf(debugmsg
, "synthfs_create: attempt to create '%s' in '%s' ?!", ap
->a_cnp
->cn_nameptr
, VTOS(dvp
)->s_name
);
159 return err_create(ap
);
171 IN vfs_context_t a_context;
176 struct vnop_open_args
/* {
179 vfs_context_t a_context;
182 struct vnode
*vp
= ap
->a_vp
;
184 if (vp
->v_type
== VDIR
) {
188 struct synthfsnode
*sp
= VTOS(vp
);
191 sprintf(debugmsg
, "synthfs_open: attempt to open '/%s' ?!", sp
->s_name
);
204 * NB Currently unsupported.
210 IN kauth_cred_t cred;
218 synthfs_mmap(__unused
struct vnop_mmap_args
*ap
)
230 IN struct vnode_attr *vap;
231 IN vfs_context_t context;
236 struct vnop_getattr_args
/* {
238 struct vnode_attr *a_vap;
239 vfs_context_t a_context;
242 struct vnode
*vp
= ap
->a_vp
;
243 struct vnode_attr
*vap
= ap
->a_vap
;
244 struct synthfsnode
*sp
= VTOS(vp
);
246 VATTR_RETURN(vap
, va_type
, vp
->v_type
);
247 VATTR_RETURN(vap
, va_mode
, sp
->s_mode
);
248 VATTR_RETURN(vap
, va_nlink
, sp
->s_linkcount
);
249 VATTR_RETURN(vap
, va_uid
, sp
->s_uid
);
250 VATTR_RETURN(vap
, va_gid
, sp
->s_gid
);
251 VATTR_RETURN(vap
, va_fsid
, VTOVFS(vp
)->mnt_vfsstat
.f_fsid
.val
[0]);
252 VATTR_RETURN(vap
, va_fileid
, sp
->s_nodeid
);
253 switch (vp
->v_type
) {
255 VATTR_RETURN(vap
, va_data_size
, (sp
->s_u
.d
.d_entrycount
+ 2) * sizeof(struct dirent
));
259 VATTR_RETURN(vap
, va_data_size
, sp
->s_u
.f
.f_size
);
263 VATTR_RETURN(vap
, va_data_size
, sp
->s_u
.s
.s_length
);
267 VATTR_RETURN(vap
, va_data_size
, 0);
269 VATTR_RETURN(vap
, va_iosize
, 512);
270 vap
->va_access_time
.tv_sec
= sp
->s_accesstime
.tv_sec
;
271 vap
->va_access_time
.tv_nsec
= sp
->s_accesstime
.tv_usec
* 1000;
272 VATTR_SET_SUPPORTED(vap
, va_access_time
);
273 vap
->va_modify_time
.tv_sec
= sp
->s_modificationtime
.tv_sec
;
274 vap
->va_modify_time
.tv_nsec
= sp
->s_modificationtime
.tv_usec
* 1000;
275 VATTR_SET_SUPPORTED(vap
, va_modify_time
);
276 vap
->va_change_time
.tv_sec
= sp
->s_changetime
.tv_sec
;
277 vap
->va_change_time
.tv_nsec
= sp
->s_changetime
.tv_usec
* 1000;
278 VATTR_SET_SUPPORTED(vap
, va_change_time
);
279 VATTR_RETURN(vap
, va_gen
, sp
->s_generation
);
280 VATTR_RETURN(vap
, va_flags
, sp
->s_flags
);
281 VATTR_RETURN(vap
, va_rdev
, sp
->s_rdev
);
282 VATTR_RETURN(vap
, va_filerev
, 0);
283 VATTR_RETURN(vap
, va_acl
, NULL
);
291 * Change the mode on a file or directory.
292 * vnode vp must be locked on entry.
294 int synthfs_chmod(struct vnode
*vp
, int mode
, kauth_cred_t cred
, struct proc
*p
)
296 struct synthfsnode
*sp
= VTOS(vp
);
299 sp
->s_mode
&= ~ALLPERMS
;
300 sp
->s_mode
|= (mode
& ALLPERMS
);
301 sp
->s_nodeflags
|= IN_CHANGE
;
303 if ((vp
->v_flag
& VTEXT
) && (sp
->s_mode
& S_ISTXT
) == 0) (void) vnode_uncache(vp
);
312 * Change the flags on a file or directory.
313 * vnode vp must be locked on entry.
315 int synthfs_chflags(struct vnode
*vp
, u_long flags
, kauth_cred_t cred
, struct proc
*p
)
317 struct synthfsnode
*sp
= VTOS(vp
);
320 sp
->s_nodeflags
|= IN_CHANGE
;
328 * Perform chown operation on vnode vp;
329 * vnode vp must be locked on entry.
331 int synthfs_chown(struct vnode
*vp
, uid_t uid
, gid_t gid
, kauth_cred_t cred
, struct proc
*p
)
333 struct synthfsnode
*sp
= VTOS(vp
);
339 if (uid
== (uid_t
)VNOVAL
) uid
= sp
->s_uid
;
340 if (gid
== (gid_t
)VNOVAL
) gid
= sp
->s_gid
;
348 if (ouid
!= uid
|| ogid
!= gid
) sp
->s_nodeflags
|= IN_CHANGE
;
349 if (ouid
!= uid
&& suser(cred
, NULL
)) sp
->s_mode
&= ~S_ISUID
;
350 if (ogid
!= gid
&& suser(cred
, NULL
)) sp
->s_mode
&= ~S_ISGID
;
358 * Set attribute vnode op. called from several syscalls
363 IN struct vnode_attr *vap;
364 IN vfs_context_t context;
369 struct vnop_setattr_args
/* {
371 struct vnode_attr *a_vap;
372 vfs_context_t a_context;
375 struct vnode
*vp
= ap
->a_vp
;
376 struct synthfsnode
*sp
= VTOS(vp
);
377 struct vnode_attr
*vap
= ap
->a_vap
;
378 kauth_cred_t cred
= vfs_context_ucred(ap
->a_context
);
379 struct proc
*p
= vfs_context_proc(ap
->a_context
);
380 struct timeval atimeval
, mtimeval
;
387 if (VATTR_IS_ACTIVE(vap
, va_flags
)) {
388 if ((result
= synthfs_chflags(vp
, vap
->va_flags
, cred
, p
))) {
392 VATTR_SET_SUPPORTED(vap
, va_flags
);
394 nuid
= (uid_t
)ngid
= (gid_t
)VNOVAL
;
395 if (VATTR_IS_ACTIVE(vap
, va_uid
))
397 if (VATTR_IS_ACTIVE(vap
, va_gid
))
399 if (nuid
!= (uid_t
)VNOVAL
|| ngid
!= (gid_t
)VNOVAL
) {
400 if ((result
= synthfs_chown(vp
, nuid
, ngid
, cred
, p
))) {
404 VATTR_SET_SUPPORTED(vap
, va_uid
);
405 VATTR_SET_SUPPORTED(vap
, va_gid
);
407 if (VATTR_IS_ACTIVE(vap
, va_data_size
)) {
409 if ((result
= vnode_setsize(vp
, vap
->va_data_size
, 0, ap
->a_context
))) {
412 VATTR_SET_SUPPORTED(vap
, va_data_size
);
420 if (VATTR_IS_ACTIVE(vap
, va_access_time
) || VATTR_IS_ACTIVE(vap
, va_modify_time
)) {
421 if (VATTR_IS_ACTIVE(vap
, va_access_time
)) {
422 sp
->s_nodeflags
|= IN_ACCESS
;
423 atimeval
.tv_sec
= vap
->va_access_time
.tv_sec
;
424 atimeval
.tv_usec
= vap
->va_access_time
.tv_nsec
/ 1000;
426 if (VATTR_IS_ACTIVE(vap
, va_modify_time
)) {
427 sp
->s_nodeflags
|= IN_CHANGE
| IN_UPDATE
;
428 mtimeval
.tv_sec
= vap
->va_modify_time
.tv_sec
;
429 mtimeval
.tv_usec
= vap
->va_modify_time
.tv_nsec
/ 1000;
431 if ((result
= synthfs_update(vp
, &atimeval
, &mtimeval
, 1))) {
435 VATTR_SET_SUPPORTED(vap
, va_access_time
);
436 VATTR_SET_SUPPORTED(vap
, va_modify_time
);
438 if (VATTR_IS_ACTIVE(vap
, va_mode
))
439 result
= synthfs_chmod(vp
, (int)vap
->va_mode
, cred
, p
);
440 VATTR_SET_SUPPORTED(vap
, va_mode
);
444 DBG_VOP(("synthfs_setattr: returning %d...\n", result
));
453 #% rename sourcePar_vp U U U
454 #% rename source_vp U U U
455 #% rename targetPar_vp L U U
456 #% rename target_vp X U U
459 IN WILLRELE struct vnode *sourcePar_vp;
460 IN WILLRELE struct vnode *source_vp;
461 IN struct componentname *source_cnp;
462 IN WILLRELE struct vnode *targetPar_vp;
463 IN WILLRELE struct vnode *target_vp;
464 IN struct componentname *target_cnp;
471 * source's parent directory is unlocked
472 * source file or directory is unlocked
473 * destination's parent directory is locked
474 * destination file or directory is locked if it exists
477 * all denodes should be released
483 struct vnop_rename_args
/* {
484 struct vnode *a_fdvp;
486 struct componentname *a_fcnp;
487 struct vnode *a_tdvp;
489 struct componentname *a_tcnp;
490 vfs_context_t a_context;
493 struct vnode
*target_vp
= ap
->a_tvp
;
494 struct vnode
*targetPar_vp
= ap
->a_tdvp
;
495 struct vnode
*source_vp
= ap
->a_fvp
;
496 struct vnode
*sourcePar_vp
= ap
->a_fdvp
;
497 struct componentname
*target_cnp
= ap
->a_tcnp
;
498 struct componentname
*source_cnp
= ap
->a_fcnp
;
499 struct synthfsnode
*target_sp
, *targetPar_sp
, *source_sp
, *sourcePar_sp
;
500 u_short doingdirectory
= 0, oldparent
= 0, newparent
= 0;
504 #if SYNTHFS_DIAGNOSTIC
505 if ((target_cnp
->cn_flags
& HASBUF
) == 0 ||
506 (source_cnp
->cn_flags
& HASBUF
) == 0)
507 panic("synthfs_rename: no name");
510 DBG_ASSERT((ap
->a_fdvp
->v_type
== VDIR
) && (ap
->a_tdvp
->v_type
== VDIR
));
511 target_sp
= targetPar_sp
= source_sp
= sourcePar_sp
= NULL
;
514 sourcePar_sp
= VTOS(sourcePar_vp
);
515 source_sp
= VTOS(source_vp
);
516 oldparent
= sourcePar_sp
->s_nodeid
;
519 * Be sure we are not renaming ".", "..", or an alias of ".". This
520 * leads to a crippled directory tree. It's pretty tough to do a
521 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
522 * doesn't work if the ".." entry is missing.
524 if (source_sp
->s_type
== SYNTHFS_DIRECTORY
) {
525 if ((source_cnp
->cn_namelen
== 1 && source_cnp
->cn_nameptr
[0] == '.')
526 || sourcePar_sp
== source_sp
527 || (source_cnp
->cn_flags
& ISDOTDOT
)
528 || (source_sp
->s_nodeflags
& IN_RENAME
)) {
532 source_sp
->s_nodeflags
|= IN_RENAME
;
533 doingdirectory
= TRUE
;
536 /* Transit between abort and bad */
538 targetPar_sp
= VTOS(targetPar_vp
);
539 target_sp
= target_vp
? VTOS(target_vp
) : NULL
;
540 newparent
= targetPar_sp
->s_nodeid
;
544 * If the destination exists, then be sure its type (file or dir)
545 * matches that of the source. And, if it is a directory make sure
546 * it is empty. Then delete the destination.
551 if (target_vp
->v_type
== VREG
) {
552 (void) vnode_uncache(target_vp
);
555 cache_purge(target_vp
);
557 retval
= synthfs_remove_internal(targetPar_vp
, target_vp
, target_cnp
, ap
->a_context
);
562 if (retval
) goto bad
;
566 /* remove the existing entry from the namei cache: */
567 if (source_vp
->v_type
== VREG
) cache_purge(source_vp
);
569 retval
= synthfs_move_rename_entry( source_vp
, targetPar_vp
, target_cnp
->cn_nameptr
);
571 if (retval
) goto bad
;
573 source_sp
->s_nodeflags
&= ~IN_RENAME
;
576 * Timestamp both parent directories.
577 * Note that if this is a rename within the same directory,
578 * (where targetPar_hp == sourcePar_hp)
579 * the code below is still safe and correct.
581 targetPar_sp
->s_nodeflags
|= IN_UPDATE
;
582 sourcePar_sp
->s_nodeflags
|= IN_UPDATE
;
585 SYNTHFSTIMES(targetPar_sp
, &tv
, &tv
);
586 SYNTHFSTIMES(sourcePar_sp
, &tv
, &tv
);
591 if (retval
&& doingdirectory
)
592 source_sp
->s_nodeflags
&= ~IN_RENAME
;
609 IN WILLRELE struct vnode *dvp;
610 OUT struct vnode **vpp;
611 IN struct componentname *cnp;
612 IN struct vnode_attr *vap;
613 IN vfs_context_t context;
615 We are responsible for freeing the namei buffer, it is done in synthfs_makenode(), unless there is
622 struct vnop_mkdir_args
/* {
624 struct vnode **a_vpp;
625 struct componentname *a_cnp;
626 struct vnode_attr *a_vap;
627 vfs_context_t a_context;
631 struct vnode
*dvp
= ap
->a_dvp
;
632 struct componentname
*cnp
= ap
->a_cnp
;
633 int mode
= MAKEIMODE(ap
->a_vap
->va_type
, ap
->a_vap
->va_mode
);
634 struct vnode
*vp
= NULL
;
638 retval
= synthfs_new_directory(VTOVFS(dvp
), dvp
, cnp
->cn_nameptr
, VTOSFS(dvp
)->synthfs_nextid
++, mode
, vfs_context_proc(cnp
->cn_context
), &vp
);
639 if (retval
) goto Error_Exit
;
643 retval
= vnode_setattr(vp
, ap
->a_vap
, ap
->a_context
);
644 if (retval
!= 0) goto Error_Exit
;
648 if (vp
) synthfs_remove_directory(vp
);
662 IN WILLRELE struct vnode *dvp;
663 IN WILLRELE struct vnode *vp;
664 IN struct componentname *cnp;
665 IN vfs_context_t context;
671 struct vnop_remove_args
/* {
674 struct componentname *a_cnp;
675 vfs_context_t a_context;
678 return synthfs_remove_internal(ap
->a_dvp
, ap
->a_vp
, ap
->a_cnp
, ap
->a_context
);
682 synthfs_remove_internal(struct vnode
*dvp
, struct vnode
*vp
,
683 __unused
struct componentname
*cnp
,
684 __unused vfs_context_t context
)
686 struct synthfsnode
*sp
= VTOS(vp
);
690 /* This is sort of silly right now but someday it may make sense... */
691 if (sp
->s_nodeflags
& IN_MODIFIED
) {
693 synthfs_update(vp
, &tv
, &tv
, 0);
696 /* remove the entry from the namei cache: */
699 /* remove entry from tree and reclaim any resources consumed: */
700 switch (sp
->s_type
) {
701 case SYNTHFS_DIRECTORY
:
702 synthfs_remove_directory(vp
);
706 case SYNTHFS_SYMLINK
:
707 synthfs_remove_symlink(vp
);
711 /* Fall through to default case */
714 synthfs_remove_entry(vp
);
720 VTOS(dvp
)->s_nodeflags
|= IN_CHANGE
| IN_UPDATE
;
732 IN WILLRELE struct vnode *dvp;
733 IN WILLRELE struct vnode *vp;
734 IN struct componentname *cnp;
735 IN vfs_context_t context;
741 struct vnop_rmdir_args
/* {
744 struct componentname *a_cnp;
745 vfs_context_t a_context;
748 return synthfs_remove((struct vnop_remove_args
*)ap
);
754 * synthfs_select - just say OK. Only possible op is readdir
756 * Locking policy: ignore
759 synthfs_select(__unused
760 struct vnop_select_args
/* {
769 DBG_VOP(("synthfs_select called\n"));
779 # XXX - note that the return vnode has already been vnode_put'ed
780 # by the filesystem layer. To use it you must use vnode_get,
781 # possibly with a further namei.
784 IN WILLRELE struct vnode *dvp;
785 OUT WILLRELE struct vnode **vpp;
786 IN struct componentname *cnp;
787 IN struct vnode_attr *vap;
790 We are responsible for freeing the namei buffer, it is done in synthfs_makenode(), unless there is
798 struct vnop_symlink_args
/* {
800 struct vnode **a_vpp;
801 struct componentname *a_cnp;
802 struct vnode_attr *a_vap;
804 vfs_context_t a_context;
807 struct vnode
*dvp
= ap
->a_dvp
;
808 struct vnode
**vpp
= ap
->a_vpp
;
809 struct componentname
*cnp
= ap
->a_cnp
;
814 retval
= synthfs_new_symlink(VTOVFS(dvp
), dvp
, cnp
->cn_nameptr
, VTOSFS(dvp
)->synthfs_nextid
++, ap
->a_target
, vfs_context_proc(cnp
->cn_context
), vpp
);
827 INOUT struct uio *uio;
828 IN kauth_cred_t cred;
833 struct vnop_readlink_args
/* {
836 vfs_context_t a_context;
839 struct vnode
*vp
= ap
->a_vp
;
840 struct synthfsnode
*sp
= VTOS(vp
);
841 struct uio
*uio
= ap
->a_uio
;
845 if (ap
->a_uio
->uio_offset
> sp
->s_u
.s
.s_length
) {
849 // LP64todo - fix this!
850 if (uio
->uio_offset
+ uio_resid(uio
) <= sp
->s_u
.s
.s_length
) {
851 count
= uio_resid(uio
);
853 count
= sp
->s_u
.s
.s_length
- uio
->uio_offset
;
855 retval
= uiomove((void *)((unsigned char *)sp
->s_u
.s
.s_symlinktarget
+ uio
->uio_offset
), count
, uio
);
866 * Read directory entries.
870 struct vnop_readdir_args
/* {
876 vfs_context_t a_context;
879 struct synthfsnode
*sp
= VTOS(ap
->a_vp
);
880 register struct uio
*uio
= ap
->a_uio
;
881 off_t diroffset
; /* Offset into simulated directory file */
882 struct synthfsnode
*entry
;
884 DBG_VOP(("\tuio_offset = %d, uio_resid = %lld\n", (int) uio
->uio_offset
, uio_resid(uio
)));
886 if (ap
->a_flags
& (VNODE_READDIR_EXTENDED
| VNODE_READDIR_REQSEEKOFF
))
889 /* We assume it's all one big buffer... */
890 if (uio
->uio_iovcnt
> 1) {
891 DBG_VOP(("\tuio->uio_iovcnt = %d?\n", uio
->uio_iovcnt
));
898 * We must synthesize . and ..
900 DBG_VOP(("\tstarting ... uio_offset = %d, uio_resid = %lld\n", (int) uio
->uio_offset
, uio_resid(uio
)));
901 if (uio
->uio_offset
== diroffset
)
903 DBG_VOP(("\tAdding .\n"));
904 diroffset
+= synthfs_adddirentry(sp
->s_nodeid
, DT_DIR
, ".", uio
);
905 DBG_VOP(("\t after adding ., uio_offset = %d, uio_resid = %lld\n", (int) uio
->uio_offset
, uio_resid(uio
)));
907 if ((uio_resid(uio
) > 0) && (diroffset
> uio
->uio_offset
)) {
908 /* Oops - we skipped over a partial entry: at best, diroffset should've just matched uio->uio_offset */
912 if (uio
->uio_offset
== diroffset
)
914 DBG_VOP(("\tAdding ..\n"));
915 if (sp
->s_parent
!= NULL
) {
916 diroffset
+= synthfs_adddirentry(sp
->s_parent
->s_nodeid
, DT_DIR
, "..", uio
);
918 diroffset
+= synthfs_adddirentry(sp
->s_nodeid
, DT_DIR
, "..", uio
);
920 DBG_VOP(("\t after adding .., uio_offset = %d, uio_resid = %lld\n", (int) uio
->uio_offset
, uio_resid(uio
)));
922 if ((uio_resid(uio
) > 0) && (diroffset
> uio
->uio_offset
)) {
923 /* Oops - we skipped over a partial entry: at best, diroffset should've just matched uio->uio_offset */
927 /* OK, so much for the fakes. Now for the "real thing": */
928 TAILQ_FOREACH(entry
, &sp
->s_u
.d
.d_subnodes
, s_sibling
) {
929 if (diroffset
== uio
->uio_offset
) {
930 /* Return this entry */
931 diroffset
+= synthfs_adddirentry(entry
->s_nodeid
, VTTOIF(STOV(entry
)->v_type
), entry
->s_name
, uio
);
933 if ((uio_resid(uio
) > 0) && (diroffset
> uio
->uio_offset
)) {
934 /* Oops - we skipped over a partial entry: at best, diroffset should've just matched uio->uio_offset */
940 *ap
->a_eofflag
= (entry
== NULL
); /* If we ran all the way through the list, there is no more */
955 synthfs_cached_lookup(ap
)
956 struct vnop_lookup_args
/* {
958 struct vnode **a_vpp;
959 struct componentname *a_cnp;
962 struct vnode
*dp
= ap
->a_dvp
;
963 struct componentname
*cnp
= ap
->a_cnp
;
964 u_long nameiop
= cnp
->cn_nameiop
;
965 u_long flags
= cnp
->cn_flags
;
966 struct vnode
**vpp
= ap
->a_vpp
;
969 DBG_VOP(("synthfs_cached_lookup called, name = %s, namelen = %ld\n", ap
->a_cnp
->cn_nameptr
, ap
->a_cnp
->cn_namelen
));
971 if (flags
& ISLASTCN
) DBG_VOP(("\tISLASTCN is set\n"));
977 * Look up an entry in the namei cache
980 result
= cache_lookup(dp
, vpp
, cnp
);
982 /* There was no entry in the cache for this parent vnode/name pair:
983 do the full-blown pathname lookup
985 return synthfs_lookup(ap
);
987 if (result
== ENOENT
) return result
;
989 /* An entry matching the parent vnode/name was found in the cache: */
1001 struct vnop_lookup_args
/* {
1002 struct vnode *a_dvp;
1003 struct vnode **a_vpp;
1004 struct componentname *a_cnp;
1005 vfs_context_t a_context;
1008 struct vnode
*dp
= ap
->a_dvp
;
1009 struct synthfsnode
*dsp
= VTOS(dp
);
1010 struct componentname
*cnp
= ap
->a_cnp
;
1011 u_long nameiop
= cnp
->cn_nameiop
;
1012 // char *nameptr = cnp->cn_nameptr;
1013 u_long flags
= cnp
->cn_flags
;
1014 long namelen
= cnp
->cn_namelen
;
1015 // struct proc *p = cnp->cn_proc;
1016 vfs_context_t ctx
= cnp
->cn_context
;
1017 kauth_cred_t cred
= vfs_context_ucred(ctx
);
1018 struct synthfsnode
*entry
;
1019 struct vnode
*target_vp
= NULL
;
1021 boolean_t found
= FALSE
;
1022 boolean_t isDot
= FALSE
;
1023 boolean_t isDotDot
= FALSE
;
1024 struct vnode
*starting_parent
= dp
;
1026 DBG_VOP(("synthfs_lookup called, name = %s, namelen = %ld\n", ap
->a_cnp
->cn_nameptr
, ap
->a_cnp
->cn_namelen
));
1028 if (flags
& LOCKPARENT
) DBG_VOP(("\tLOCKPARENT is set\n"));
1029 if (flags
& ISLASTCN
) DBG_VOP(("\tISLASTCN is set\n"));
1034 /* first check for "." and ".." */
1035 if (cnp
->cn_nameptr
[0] == '.') {
1044 vnode_get(target_vp
);
1049 } else if ((namelen
== 2) && (cnp
->cn_nameptr
[1] == '.')) {
1056 if ((dsp
->s_parent
!= NULL
) && (dsp
->s_parent
!= VTOS(dp
))) {
1057 target_vp
= STOV(dsp
->s_parent
);
1059 * Special case for ".." to prevent deadlock:
1060 * always release the parent vnode BEFORE trying to acquire
1061 * ITS parent. This avoids deadlocking with another lookup
1062 * starting from the target_vp trying to vnode_get() this directory.
1064 result
= vnode_get(target_vp
);
1068 /* dp is alread locked and ref'ed */
1076 /* finally, just look for entries by name (making sure the entry's length
1077 matches the cnp's namelen... */
1078 TAILQ_FOREACH(entry
, &dsp
->s_u
.d
.d_subnodes
, s_sibling
) {
1079 if ((bcmp(cnp
->cn_nameptr
, entry
->s_name
, (unsigned)namelen
) == 0) &&
1080 (*(entry
->s_name
+ namelen
) == (char)0)) {
1082 target_vp
= STOV(entry
);
1083 result
= vnode_getwithref(target_vp
); /* refcount is always > 0 for any vnode in this list... */
1088 /* The specified entry was found and successfully acquired: */
1097 if ((nameiop
== DELETE
) && (flags
& ISLASTCN
)) {
1100 * If the parent directory is "sticky" then the user must own
1101 * the directory, or the file in it, in order to be allowed to
1102 * delete it (unless the user is root). This implements
1103 * append-only directories
1105 if ((dsp
->s_mode
& S_ISVTX
) &&
1106 suser(cred
, NULL
) &&
1107 (kauth_cred_getuid(cred
) != dsp
->s_uid
) &&
1108 (target_vp
!= NULL
) &&
1109 (target_vp
->v_type
!= VLNK
) &&
1110 (VTOS(target_vp
)->s_uid
!= kauth_cred_getuid(cred
))) {
1111 vnode_put(target_vp
);
1117 if ((nameiop
== RENAME
) && (flags
& WANTPARENT
) && (flags
* ISLASTCN
)) {
1120 vnode_put(target_vp
);
1126 /* The specified entry wasn't found: */
1129 if ((flags
& ISLASTCN
) &&
1130 ((nameiop
== CREATE
) ||
1131 (nameiop
== RENAME
) ||
1132 ((nameiop
== DELETE
) && (flags
& DOWHITEOUT
) && (flags
& ISWHITEOUT
)))) {
1133 /* create a new entry */
1134 result
= EJUSTRETURN
;
1138 *ap
->a_vpp
= target_vp
;
1141 DBG_VOP(("synthfs_lookup: result = %d.\n", result
));
1144 DBG_VOP(("synthfs_lookup: target_vp = 0x%08X \n", (u_long
)target_vp
));
1146 DBG_VOP(("synthfs_lookup: found = true but target_vp = NULL?\n"));
1149 DBG_VOP(("synthf_lookup: target not found.\n"));
1151 DBG_VOP(("synthfs_lookup: dp = %08X; starting_parent = 0x%08X .\n", (u_long
)dp
, (u_long
)starting_parent
));
1160 #% pathconf vp L L L
1163 IN struct vnode *vp;
1165 OUT register_t *retval;
1168 synthfs_pathconf(ap
)
1169 struct vnop_pathconf_args
/* {
1173 vfs_context_t a_context;
1176 DBG_VOP(("synthfs_pathconf called\n"));
1181 *ap
->a_retval
= LINK_MAX
;
1184 *ap
->a_retval
= NAME_MAX
;
1187 *ap
->a_retval
= PATH_MAX
;
1190 *ap
->a_retval
= PIPE_BUF
;
1192 case _PC_CHOWN_RESTRICTED
:
1206 * Update the access, modified, and node change times as specified by the
1207 * IACCESS, IUPDATE, and ICHANGE flags respectively. The IMODIFIED flag is
1208 * used to specify that the node needs to be updated but that the times have
1209 * already been set. The access and modified times are taken from the second
1210 * and third parameters; the node change time is always taken from the current
1211 * time. If waitfor is set, then wait for the disk write of the node to
1216 synthfs_update(struct vnode
*vp
, struct timeval
*access
, struct timeval
*modify
, __unused
int waitfor
)
1218 struct synthfsnode
*sp
= VTOS(vp
);
1221 DBG_ASSERT(sp
!= NULL
);
1223 if (((sp
->s_nodeflags
& (IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
)) != 0) &&
1224 !(VTOVFS(vp
)->mnt_flag
& MNT_RDONLY
)) {
1225 if (sp
->s_nodeflags
& IN_ACCESS
) sp
->s_accesstime
= *access
;
1226 if (sp
->s_nodeflags
& IN_UPDATE
) sp
->s_modificationtime
= *modify
;
1227 if (sp
->s_nodeflags
& IN_CHANGE
) {
1230 sp
->s_changetime
= tv
;
1234 /* After the updates are finished, clear the flags */
1235 sp
->s_nodeflags
&= ~(IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
);
1242 /*******************************************************************************************
1244 Utility/housekeeping vnode operations:
1246 ******************************************************************************************/
1251 #% inactive vp L U U
1254 IN struct vnode *vp;
1260 synthfs_inactive(ap
)
1261 struct vnop_inactive_args
/* {
1263 vfs_context_t a_context;
1266 struct vnode
*vp
= ap
->a_vp
;
1267 struct synthfsnode
*sp
= VTOS(vp
);
1271 if (vp
->v_usecount
!= 0)
1272 DBG_VOP(("synthfs_inactive: bad usecount = %d\n", vp
->v_usecount
));
1276 * Ignore nodes related to stale file handles.
1278 if (vp
->v_type
== VNON
)
1281 /* This is sort of silly but might make sense in the future: */
1282 if (sp
->s_nodeflags
& (IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
)) {
1284 synthfs_update(vp
, &tv
, &tv
, 0);
1289 * If we are done with the inode, reclaim it
1290 * so that it can be reused immediately.
1292 if (vp
->v_type
== VNON
) {
1302 * synthfs_reclaim - Reclaim a vnode so that it can be used for other purposes.
1304 * Locking policy: ignored
1308 struct vnop_reclaim_args
/* { struct vnode *a_vp; struct proc *a_p; } */ *ap
;
1310 struct vnode
*vp
= ap
->a_vp
;
1311 struct synthfsnode
*sp
= VTOS(vp
);
1312 void *name
= sp
->s_name
;
1318 FREE((void *)sp
, M_SYNTHFS
);