2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1998-1999 Apple Computer, Inc. All Rights Reserved.
33 * Modification History:
35 * 02-Feb-2000 Clark Warner Added copyfile to table
36 * 17-Aug-1999 Pat Dirks New today.
39 #include <mach/mach_types.h>
40 #include <mach/machine/boolean.h>
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
47 #include <sys/kauth.h>
49 #include <sys/mount_internal.h>
50 #include <sys/vnode_internal.h>
51 #include <sys/malloc.h>
52 #include <sys/dirent.h>
53 #include <sys/namei.h>
55 #include <sys/uio_internal.h>
58 #include <sys/errno.h>
59 #include <vfs/vfs_support.h>
66 #error NOT PORTED FOR UBC
70 static int synthfs_remove_internal(struct vnode
*dvp
, struct vnode
*vp
,
71 struct componentname
*cnp
, vfs_context_t context
);
74 #define VOPFUNC int (*)(void *)
76 /* Global vfs data structures for synthfs. */
77 int (**synthfs_vnodeop_p
) (void *);
78 struct vnodeopv_entry_desc synthfs_vnodeop_entries
[] = {
79 {&vnop_default_desc
, (VOPFUNC
)vn_default_error
},
80 {&vnop_strategy_desc
, (VOPFUNC
)err_strategy
}, /* strategy - not supported */
81 {&vnop_bwrite_desc
, (VOPFUNC
)err_bwrite
}, /* bwrite - not supported */
82 {&vnop_lookup_desc
, (VOPFUNC
)synthfs_cached_lookup
}, /* cached lookup */
83 {&vnop_create_desc
, (VOPFUNC
)synthfs_create
}, /* create - DEBUGGER */
84 {&vnop_whiteout_desc
, (VOPFUNC
)err_whiteout
}, /* whiteout - not supported */
85 {&vnop_mknod_desc
, (VOPFUNC
)err_mknod
}, /* mknod - not supported */
86 {&vnop_open_desc
, (VOPFUNC
)synthfs_open
}, /* open - DEBUGGER */
87 {&vnop_close_desc
, (VOPFUNC
)nop_close
}, /* close - NOP */
88 {&vnop_getattr_desc
, (VOPFUNC
)synthfs_getattr
}, /* getattr */
89 {&vnop_setattr_desc
, (VOPFUNC
)synthfs_setattr
}, /* setattr */
90 {&vnop_getattrlist_desc
, (VOPFUNC
)err_getattrlist
}, /* getattrlist - not supported */
91 {&vnop_setattrlist_desc
, (VOPFUNC
)err_setattrlist
}, /* setattrlist - not supported */
92 {&vnop_read_desc
, (VOPFUNC
)err_read
}, /* read - not supported */
93 {&vnop_write_desc
, (VOPFUNC
)err_write
}, /* write - not supported */
94 {&vnop_ioctl_desc
, (VOPFUNC
)err_ioctl
}, /* ioctl - not supported */
95 {&vnop_select_desc
, (VOPFUNC
)synthfs_select
}, /* select */
96 {&vnop_exchange_desc
, (VOPFUNC
)err_exchange
}, /* exchange - not supported */
97 {&vnop_revoke_desc
, (VOPFUNC
)nop_revoke
}, /* revoke - NOP */
98 {&vnop_mmap_desc
, (VOPFUNC
)synthfs_mmap
}, /* mmap - DEBUGGER */
99 {&vnop_fsync_desc
, (VOPFUNC
)nop_fsync
}, /* fsync - NOP */
100 {&vnop_remove_desc
, (VOPFUNC
)synthfs_remove
}, /* remove */
101 {&vnop_link_desc
, (VOPFUNC
)err_link
}, /* link - not supported */
102 {&vnop_rename_desc
, (VOPFUNC
)synthfs_rename
}, /* rename */
103 {&vnop_mkdir_desc
, (VOPFUNC
)synthfs_mkdir
}, /* mkdir */
104 {&vnop_rmdir_desc
, (VOPFUNC
)synthfs_rmdir
}, /* rmdir */
105 {&vnop_symlink_desc
, (VOPFUNC
)synthfs_symlink
}, /* symlink */
106 {&vnop_readdir_desc
, (VOPFUNC
)synthfs_readdir
}, /* readdir */
107 {&vnop_readdirattr_desc
, (VOPFUNC
)err_readdirattr
}, /* readdirattr - not supported */
108 {&vnop_readlink_desc
, (VOPFUNC
)synthfs_readlink
}, /* readlink */
109 {&vnop_inactive_desc
, (VOPFUNC
)synthfs_inactive
}, /* inactive */
110 {&vnop_reclaim_desc
, (VOPFUNC
)synthfs_reclaim
}, /* reclaim */
111 {&vnop_pathconf_desc
, (VOPFUNC
)synthfs_pathconf
}, /* pathconf */
112 {&vnop_advlock_desc
, (VOPFUNC
)err_advlock
}, /* advlock - not supported */
113 {&vnop_allocate_desc
, (VOPFUNC
)err_allocate
}, /* allocate - not supported */
114 {&vnop_pagein_desc
, (VOPFUNC
)err_pagein
}, /* pagein - not supported */
115 {&vnop_pageout_desc
, (VOPFUNC
)err_pageout
}, /* pageout - not supported */
116 {&vnop_devblocksize_desc
, (VOPFUNC
)err_devblocksize
}, /* devblocksize - not supported */
117 {&vnop_searchfs_desc
, (VOPFUNC
)err_searchfs
}, /* searchfs - not supported */
118 {&vnop_copyfile_desc
, (VOPFUNC
)err_copyfile
}, /* copyfile - not supported */
119 { &vnop_blktooff_desc
, (VOPFUNC
)err_blktooff
}, /* blktooff not supported */
120 { &vnop_offtoblk_desc
, (VOPFUNC
)err_offtoblk
}, /* offtoblk not supported */
121 { &vnop_blockmap_desc
, (VOPFUNC
)err_blockmap
}, /* blockmap not supported */
122 {(struct vnodeop_desc
*) NULL
, (int (*) ()) NULL
}
126 * Oh what a tangled web we weave. This structure will be used by
127 * bsd/vfs/vfs_conf.c to actually do the initialization of synthfs_vnodeop_p
129 struct vnodeopv_desc synthfs_vnodeop_opv_desc
=
130 {&synthfs_vnodeop_p
, synthfs_vnodeop_entries
};
135 * Create a regular file
140 IN WILLRELE struct vnode *dvp;
141 OUT struct vnode **vpp;
142 IN struct componentname *cnp;
143 IN struct vnode_attr *vap;
145 We are responsible for freeing the namei buffer, it is done in hfs_makenode(), unless there is
152 struct vnop_create_args
/* {
154 struct vnode **a_vpp;
155 struct componentname *a_cnp;
156 struct vnode_attr *a_vap;
157 vfs_context_t a_context;
161 struct vnode
*dvp
= ap
->a_dvp
;
164 sprintf(debugmsg
, "synthfs_create: attempt to create '%s' in '%s' ?!", ap
->a_cnp
->cn_nameptr
, VTOS(dvp
)->s_name
);
168 return err_create(ap
);
180 IN vfs_context_t a_context;
185 struct vnop_open_args
/* {
188 vfs_context_t a_context;
191 struct vnode
*vp
= ap
->a_vp
;
193 if (vp
->v_type
== VDIR
) {
197 struct synthfsnode
*sp
= VTOS(vp
);
200 sprintf(debugmsg
, "synthfs_open: attempt to open '/%s' ?!", sp
->s_name
);
213 * NB Currently unsupported.
219 IN kauth_cred_t cred;
227 synthfs_mmap(__unused
struct vnop_mmap_args
*ap
)
239 IN struct vnode_attr *vap;
240 IN vfs_context_t context;
245 struct vnop_getattr_args
/* {
247 struct vnode_attr *a_vap;
248 vfs_context_t a_context;
251 struct vnode
*vp
= ap
->a_vp
;
252 struct vnode_attr
*vap
= ap
->a_vap
;
253 struct synthfsnode
*sp
= VTOS(vp
);
255 VATTR_RETURN(vap
, va_type
, vp
->v_type
);
256 VATTR_RETURN(vap
, va_mode
, sp
->s_mode
);
257 VATTR_RETURN(vap
, va_nlink
, sp
->s_linkcount
);
258 VATTR_RETURN(vap
, va_uid
, sp
->s_uid
);
259 VATTR_RETURN(vap
, va_gid
, sp
->s_gid
);
260 VATTR_RETURN(vap
, va_fsid
, VTOVFS(vp
)->mnt_vfsstat
.f_fsid
.val
[0]);
261 VATTR_RETURN(vap
, va_fileid
, sp
->s_nodeid
);
262 switch (vp
->v_type
) {
264 VATTR_RETURN(vap
, va_data_size
, (sp
->s_u
.d
.d_entrycount
+ 2) * sizeof(struct dirent
));
268 VATTR_RETURN(vap
, va_data_size
, sp
->s_u
.f
.f_size
);
272 VATTR_RETURN(vap
, va_data_size
, sp
->s_u
.s
.s_length
);
276 VATTR_RETURN(vap
, va_data_size
, 0);
278 VATTR_RETURN(vap
, va_iosize
, 512);
279 vap
->va_access_time
.tv_sec
= sp
->s_accesstime
.tv_sec
;
280 vap
->va_access_time
.tv_nsec
= sp
->s_accesstime
.tv_usec
* 1000;
281 VATTR_SET_SUPPORTED(vap
, va_access_time
);
282 vap
->va_modify_time
.tv_sec
= sp
->s_modificationtime
.tv_sec
;
283 vap
->va_modify_time
.tv_nsec
= sp
->s_modificationtime
.tv_usec
* 1000;
284 VATTR_SET_SUPPORTED(vap
, va_modify_time
);
285 vap
->va_change_time
.tv_sec
= sp
->s_changetime
.tv_sec
;
286 vap
->va_change_time
.tv_nsec
= sp
->s_changetime
.tv_usec
* 1000;
287 VATTR_SET_SUPPORTED(vap
, va_change_time
);
288 VATTR_RETURN(vap
, va_gen
, sp
->s_generation
);
289 VATTR_RETURN(vap
, va_flags
, sp
->s_flags
);
290 VATTR_RETURN(vap
, va_rdev
, sp
->s_rdev
);
291 VATTR_RETURN(vap
, va_filerev
, 0);
292 VATTR_RETURN(vap
, va_acl
, NULL
);
300 * Change the mode on a file or directory.
301 * vnode vp must be locked on entry.
303 int synthfs_chmod(struct vnode
*vp
, int mode
, kauth_cred_t cred
, struct proc
*p
)
305 struct synthfsnode
*sp
= VTOS(vp
);
308 sp
->s_mode
&= ~ALLPERMS
;
309 sp
->s_mode
|= (mode
& ALLPERMS
);
310 sp
->s_nodeflags
|= IN_CHANGE
;
312 if ((vp
->v_flag
& VTEXT
) && (sp
->s_mode
& S_ISTXT
) == 0) (void) vnode_uncache(vp
);
321 * Change the flags on a file or directory.
322 * vnode vp must be locked on entry.
324 int synthfs_chflags(struct vnode
*vp
, u_long flags
, kauth_cred_t cred
, struct proc
*p
)
326 struct synthfsnode
*sp
= VTOS(vp
);
329 sp
->s_nodeflags
|= IN_CHANGE
;
337 * Perform chown operation on vnode vp;
338 * vnode vp must be locked on entry.
340 int synthfs_chown(struct vnode
*vp
, uid_t uid
, gid_t gid
, kauth_cred_t cred
, struct proc
*p
)
342 struct synthfsnode
*sp
= VTOS(vp
);
348 if (uid
== (uid_t
)VNOVAL
) uid
= sp
->s_uid
;
349 if (gid
== (gid_t
)VNOVAL
) gid
= sp
->s_gid
;
357 if (ouid
!= uid
|| ogid
!= gid
) sp
->s_nodeflags
|= IN_CHANGE
;
358 if (ouid
!= uid
&& suser(cred
, NULL
)) sp
->s_mode
&= ~S_ISUID
;
359 if (ogid
!= gid
&& suser(cred
, NULL
)) sp
->s_mode
&= ~S_ISGID
;
367 * Set attribute vnode op. called from several syscalls
372 IN struct vnode_attr *vap;
373 IN vfs_context_t context;
378 struct vnop_setattr_args
/* {
380 struct vnode_attr *a_vap;
381 vfs_context_t a_context;
384 struct vnode
*vp
= ap
->a_vp
;
385 struct synthfsnode
*sp
= VTOS(vp
);
386 struct vnode_attr
*vap
= ap
->a_vap
;
387 kauth_cred_t cred
= vfs_context_ucred(ap
->a_context
);
388 struct proc
*p
= vfs_context_proc(ap
->a_context
);
389 struct timeval atimeval
, mtimeval
;
396 if (VATTR_IS_ACTIVE(vap
, va_flags
)) {
397 if ((result
= synthfs_chflags(vp
, vap
->va_flags
, cred
, p
))) {
401 VATTR_SET_SUPPORTED(vap
, va_flags
);
403 nuid
= (uid_t
)ngid
= (gid_t
)VNOVAL
;
404 if (VATTR_IS_ACTIVE(vap
, va_uid
))
406 if (VATTR_IS_ACTIVE(vap
, va_gid
))
408 if (nuid
!= (uid_t
)VNOVAL
|| ngid
!= (gid_t
)VNOVAL
) {
409 if ((result
= synthfs_chown(vp
, nuid
, ngid
, cred
, p
))) {
413 VATTR_SET_SUPPORTED(vap
, va_uid
);
414 VATTR_SET_SUPPORTED(vap
, va_gid
);
416 if (VATTR_IS_ACTIVE(vap
, va_data_size
)) {
418 if ((result
= vnode_setsize(vp
, vap
->va_data_size
, 0, ap
->a_context
))) {
421 VATTR_SET_SUPPORTED(vap
, va_data_size
);
429 if (VATTR_IS_ACTIVE(vap
, va_access_time
) || VATTR_IS_ACTIVE(vap
, va_modify_time
)) {
430 if (VATTR_IS_ACTIVE(vap
, va_access_time
)) {
431 sp
->s_nodeflags
|= IN_ACCESS
;
432 atimeval
.tv_sec
= vap
->va_access_time
.tv_sec
;
433 atimeval
.tv_usec
= vap
->va_access_time
.tv_nsec
/ 1000;
435 if (VATTR_IS_ACTIVE(vap
, va_modify_time
)) {
436 sp
->s_nodeflags
|= IN_CHANGE
| IN_UPDATE
;
437 mtimeval
.tv_sec
= vap
->va_modify_time
.tv_sec
;
438 mtimeval
.tv_usec
= vap
->va_modify_time
.tv_nsec
/ 1000;
440 if ((result
= synthfs_update(vp
, &atimeval
, &mtimeval
, 1))) {
444 VATTR_SET_SUPPORTED(vap
, va_access_time
);
445 VATTR_SET_SUPPORTED(vap
, va_modify_time
);
447 if (VATTR_IS_ACTIVE(vap
, va_mode
))
448 result
= synthfs_chmod(vp
, (int)vap
->va_mode
, cred
, p
);
449 VATTR_SET_SUPPORTED(vap
, va_mode
);
453 DBG_VOP(("synthfs_setattr: returning %d...\n", result
));
462 #% rename sourcePar_vp U U U
463 #% rename source_vp U U U
464 #% rename targetPar_vp L U U
465 #% rename target_vp X U U
468 IN WILLRELE struct vnode *sourcePar_vp;
469 IN WILLRELE struct vnode *source_vp;
470 IN struct componentname *source_cnp;
471 IN WILLRELE struct vnode *targetPar_vp;
472 IN WILLRELE struct vnode *target_vp;
473 IN struct componentname *target_cnp;
480 * source's parent directory is unlocked
481 * source file or directory is unlocked
482 * destination's parent directory is locked
483 * destination file or directory is locked if it exists
486 * all denodes should be released
492 struct vnop_rename_args
/* {
493 struct vnode *a_fdvp;
495 struct componentname *a_fcnp;
496 struct vnode *a_tdvp;
498 struct componentname *a_tcnp;
499 vfs_context_t a_context;
502 struct vnode
*target_vp
= ap
->a_tvp
;
503 struct vnode
*targetPar_vp
= ap
->a_tdvp
;
504 struct vnode
*source_vp
= ap
->a_fvp
;
505 struct vnode
*sourcePar_vp
= ap
->a_fdvp
;
506 struct componentname
*target_cnp
= ap
->a_tcnp
;
507 struct componentname
*source_cnp
= ap
->a_fcnp
;
508 struct synthfsnode
*target_sp
, *targetPar_sp
, *source_sp
, *sourcePar_sp
;
509 u_short doingdirectory
= 0, oldparent
= 0, newparent
= 0;
513 #if SYNTHFS_DIAGNOSTIC
514 if ((target_cnp
->cn_flags
& HASBUF
) == 0 ||
515 (source_cnp
->cn_flags
& HASBUF
) == 0)
516 panic("synthfs_rename: no name");
519 DBG_ASSERT((ap
->a_fdvp
->v_type
== VDIR
) && (ap
->a_tdvp
->v_type
== VDIR
));
520 target_sp
= targetPar_sp
= source_sp
= sourcePar_sp
= NULL
;
523 sourcePar_sp
= VTOS(sourcePar_vp
);
524 source_sp
= VTOS(source_vp
);
525 oldparent
= sourcePar_sp
->s_nodeid
;
528 * Be sure we are not renaming ".", "..", or an alias of ".". This
529 * leads to a crippled directory tree. It's pretty tough to do a
530 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
531 * doesn't work if the ".." entry is missing.
533 if (source_sp
->s_type
== SYNTHFS_DIRECTORY
) {
534 if ((source_cnp
->cn_namelen
== 1 && source_cnp
->cn_nameptr
[0] == '.')
535 || sourcePar_sp
== source_sp
536 || (source_cnp
->cn_flags
& ISDOTDOT
)
537 || (source_sp
->s_nodeflags
& IN_RENAME
)) {
541 source_sp
->s_nodeflags
|= IN_RENAME
;
542 doingdirectory
= TRUE
;
545 /* Transit between abort and bad */
547 targetPar_sp
= VTOS(targetPar_vp
);
548 target_sp
= target_vp
? VTOS(target_vp
) : NULL
;
549 newparent
= targetPar_sp
->s_nodeid
;
553 * If the destination exists, then be sure its type (file or dir)
554 * matches that of the source. And, if it is a directory make sure
555 * it is empty. Then delete the destination.
560 if (target_vp
->v_type
== VREG
) {
561 (void) vnode_uncache(target_vp
);
564 cache_purge(target_vp
);
566 retval
= synthfs_remove_internal(targetPar_vp
, target_vp
, target_cnp
, ap
->a_context
);
571 if (retval
) goto bad
;
575 /* remove the existing entry from the namei cache: */
576 if (source_vp
->v_type
== VREG
) cache_purge(source_vp
);
578 retval
= synthfs_move_rename_entry( source_vp
, targetPar_vp
, target_cnp
->cn_nameptr
);
580 if (retval
) goto bad
;
582 source_sp
->s_nodeflags
&= ~IN_RENAME
;
585 * Timestamp both parent directories.
586 * Note that if this is a rename within the same directory,
587 * (where targetPar_hp == sourcePar_hp)
588 * the code below is still safe and correct.
590 targetPar_sp
->s_nodeflags
|= IN_UPDATE
;
591 sourcePar_sp
->s_nodeflags
|= IN_UPDATE
;
594 SYNTHFSTIMES(targetPar_sp
, &tv
, &tv
);
595 SYNTHFSTIMES(sourcePar_sp
, &tv
, &tv
);
600 if (retval
&& doingdirectory
)
601 source_sp
->s_nodeflags
&= ~IN_RENAME
;
618 IN WILLRELE struct vnode *dvp;
619 OUT struct vnode **vpp;
620 IN struct componentname *cnp;
621 IN struct vnode_attr *vap;
622 IN vfs_context_t context;
624 We are responsible for freeing the namei buffer, it is done in synthfs_makenode(), unless there is
631 struct vnop_mkdir_args
/* {
633 struct vnode **a_vpp;
634 struct componentname *a_cnp;
635 struct vnode_attr *a_vap;
636 vfs_context_t a_context;
640 struct vnode
*dvp
= ap
->a_dvp
;
641 struct componentname
*cnp
= ap
->a_cnp
;
642 int mode
= MAKEIMODE(ap
->a_vap
->va_type
, ap
->a_vap
->va_mode
);
643 struct vnode
*vp
= NULL
;
647 retval
= synthfs_new_directory(VTOVFS(dvp
), dvp
, cnp
->cn_nameptr
, VTOSFS(dvp
)->synthfs_nextid
++, mode
, vfs_context_proc(cnp
->cn_context
), &vp
);
648 if (retval
) goto Error_Exit
;
652 retval
= vnode_setattr(vp
, ap
->a_vap
, ap
->a_context
);
653 if (retval
!= 0) goto Error_Exit
;
657 if (vp
) synthfs_remove_directory(vp
);
671 IN WILLRELE struct vnode *dvp;
672 IN WILLRELE struct vnode *vp;
673 IN struct componentname *cnp;
674 IN vfs_context_t context;
680 struct vnop_remove_args
/* {
683 struct componentname *a_cnp;
684 vfs_context_t a_context;
687 return synthfs_remove_internal(ap
->a_dvp
, ap
->a_vp
, ap
->a_cnp
, ap
->a_context
);
691 synthfs_remove_internal(struct vnode
*dvp
, struct vnode
*vp
,
692 __unused
struct componentname
*cnp
,
693 __unused vfs_context_t context
)
695 struct synthfsnode
*sp
= VTOS(vp
);
699 /* This is sort of silly right now but someday it may make sense... */
700 if (sp
->s_nodeflags
& IN_MODIFIED
) {
702 synthfs_update(vp
, &tv
, &tv
, 0);
705 /* remove the entry from the namei cache: */
708 /* remove entry from tree and reclaim any resources consumed: */
709 switch (sp
->s_type
) {
710 case SYNTHFS_DIRECTORY
:
711 synthfs_remove_directory(vp
);
715 case SYNTHFS_SYMLINK
:
716 synthfs_remove_symlink(vp
);
720 /* Fall through to default case */
723 synthfs_remove_entry(vp
);
729 VTOS(dvp
)->s_nodeflags
|= IN_CHANGE
| IN_UPDATE
;
741 IN WILLRELE struct vnode *dvp;
742 IN WILLRELE struct vnode *vp;
743 IN struct componentname *cnp;
744 IN vfs_context_t context;
750 struct vnop_rmdir_args
/* {
753 struct componentname *a_cnp;
754 vfs_context_t a_context;
757 return synthfs_remove((struct vnop_remove_args
*)ap
);
763 * synthfs_select - just say OK. Only possible op is readdir
765 * Locking policy: ignore
768 synthfs_select(__unused
769 struct vnop_select_args
/* {
778 DBG_VOP(("synthfs_select called\n"));
788 # XXX - note that the return vnode has already been vnode_put'ed
789 # by the filesystem layer. To use it you must use vnode_get,
790 # possibly with a further namei.
793 IN WILLRELE struct vnode *dvp;
794 OUT WILLRELE struct vnode **vpp;
795 IN struct componentname *cnp;
796 IN struct vnode_attr *vap;
799 We are responsible for freeing the namei buffer, it is done in synthfs_makenode(), unless there is
807 struct vnop_symlink_args
/* {
809 struct vnode **a_vpp;
810 struct componentname *a_cnp;
811 struct vnode_attr *a_vap;
813 vfs_context_t a_context;
816 struct vnode
*dvp
= ap
->a_dvp
;
817 struct vnode
**vpp
= ap
->a_vpp
;
818 struct componentname
*cnp
= ap
->a_cnp
;
823 retval
= synthfs_new_symlink(VTOVFS(dvp
), dvp
, cnp
->cn_nameptr
, VTOSFS(dvp
)->synthfs_nextid
++, ap
->a_target
, vfs_context_proc(cnp
->cn_context
), vpp
);
836 INOUT struct uio *uio;
837 IN kauth_cred_t cred;
842 struct vnop_readlink_args
/* {
845 vfs_context_t a_context;
848 struct vnode
*vp
= ap
->a_vp
;
849 struct synthfsnode
*sp
= VTOS(vp
);
850 struct uio
*uio
= ap
->a_uio
;
854 if (ap
->a_uio
->uio_offset
> sp
->s_u
.s
.s_length
) {
858 // LP64todo - fix this!
859 if (uio
->uio_offset
+ uio_resid(uio
) <= sp
->s_u
.s
.s_length
) {
860 count
= uio_resid(uio
);
862 count
= sp
->s_u
.s
.s_length
- uio
->uio_offset
;
864 retval
= uiomove((void *)((unsigned char *)sp
->s_u
.s
.s_symlinktarget
+ uio
->uio_offset
), count
, uio
);
875 * Read directory entries.
879 struct vnop_readdir_args
/* {
885 vfs_context_t a_context;
888 struct synthfsnode
*sp
= VTOS(ap
->a_vp
);
889 register struct uio
*uio
= ap
->a_uio
;
890 off_t diroffset
; /* Offset into simulated directory file */
891 struct synthfsnode
*entry
;
893 DBG_VOP(("\tuio_offset = %d, uio_resid = %lld\n", (int) uio
->uio_offset
, uio_resid(uio
)));
895 if (ap
->a_flags
& (VNODE_READDIR_EXTENDED
| VNODE_READDIR_REQSEEKOFF
))
898 /* We assume it's all one big buffer... */
899 if (uio
->uio_iovcnt
> 1) {
900 DBG_VOP(("\tuio->uio_iovcnt = %d?\n", uio
->uio_iovcnt
));
907 * We must synthesize . and ..
909 DBG_VOP(("\tstarting ... uio_offset = %d, uio_resid = %lld\n", (int) uio
->uio_offset
, uio_resid(uio
)));
910 if (uio
->uio_offset
== diroffset
)
912 DBG_VOP(("\tAdding .\n"));
913 diroffset
+= synthfs_adddirentry(sp
->s_nodeid
, DT_DIR
, ".", uio
);
914 DBG_VOP(("\t after adding ., uio_offset = %d, uio_resid = %lld\n", (int) uio
->uio_offset
, uio_resid(uio
)));
916 if ((uio_resid(uio
) > 0) && (diroffset
> uio
->uio_offset
)) {
917 /* Oops - we skipped over a partial entry: at best, diroffset should've just matched uio->uio_offset */
921 if (uio
->uio_offset
== diroffset
)
923 DBG_VOP(("\tAdding ..\n"));
924 if (sp
->s_parent
!= NULL
) {
925 diroffset
+= synthfs_adddirentry(sp
->s_parent
->s_nodeid
, DT_DIR
, "..", uio
);
927 diroffset
+= synthfs_adddirentry(sp
->s_nodeid
, DT_DIR
, "..", uio
);
929 DBG_VOP(("\t after adding .., uio_offset = %d, uio_resid = %lld\n", (int) uio
->uio_offset
, uio_resid(uio
)));
931 if ((uio_resid(uio
) > 0) && (diroffset
> uio
->uio_offset
)) {
932 /* Oops - we skipped over a partial entry: at best, diroffset should've just matched uio->uio_offset */
936 /* OK, so much for the fakes. Now for the "real thing": */
937 TAILQ_FOREACH(entry
, &sp
->s_u
.d
.d_subnodes
, s_sibling
) {
938 if (diroffset
== uio
->uio_offset
) {
939 /* Return this entry */
940 diroffset
+= synthfs_adddirentry(entry
->s_nodeid
, VTTOIF(STOV(entry
)->v_type
), entry
->s_name
, uio
);
942 if ((uio_resid(uio
) > 0) && (diroffset
> uio
->uio_offset
)) {
943 /* Oops - we skipped over a partial entry: at best, diroffset should've just matched uio->uio_offset */
949 *ap
->a_eofflag
= (entry
== NULL
); /* If we ran all the way through the list, there is no more */
964 synthfs_cached_lookup(ap
)
965 struct vnop_lookup_args
/* {
967 struct vnode **a_vpp;
968 struct componentname *a_cnp;
971 struct vnode
*dp
= ap
->a_dvp
;
972 struct componentname
*cnp
= ap
->a_cnp
;
973 u_long nameiop
= cnp
->cn_nameiop
;
974 u_long flags
= cnp
->cn_flags
;
975 struct vnode
**vpp
= ap
->a_vpp
;
978 DBG_VOP(("synthfs_cached_lookup called, name = %s, namelen = %ld\n", ap
->a_cnp
->cn_nameptr
, ap
->a_cnp
->cn_namelen
));
980 if (flags
& ISLASTCN
) DBG_VOP(("\tISLASTCN is set\n"));
986 * Look up an entry in the namei cache
989 result
= cache_lookup(dp
, vpp
, cnp
);
991 /* There was no entry in the cache for this parent vnode/name pair:
992 do the full-blown pathname lookup
994 return synthfs_lookup(ap
);
996 if (result
== ENOENT
) return result
;
998 /* An entry matching the parent vnode/name was found in the cache: */
1010 struct vnop_lookup_args
/* {
1011 struct vnode *a_dvp;
1012 struct vnode **a_vpp;
1013 struct componentname *a_cnp;
1014 vfs_context_t a_context;
1017 struct vnode
*dp
= ap
->a_dvp
;
1018 struct synthfsnode
*dsp
= VTOS(dp
);
1019 struct componentname
*cnp
= ap
->a_cnp
;
1020 u_long nameiop
= cnp
->cn_nameiop
;
1021 // char *nameptr = cnp->cn_nameptr;
1022 u_long flags
= cnp
->cn_flags
;
1023 long namelen
= cnp
->cn_namelen
;
1024 // struct proc *p = cnp->cn_proc;
1025 vfs_context_t ctx
= cnp
->cn_context
;
1026 kauth_cred_t cred
= vfs_context_ucred(ctx
);
1027 struct synthfsnode
*entry
;
1028 struct vnode
*target_vp
= NULL
;
1030 boolean_t found
= FALSE
;
1031 boolean_t isDot
= FALSE
;
1032 boolean_t isDotDot
= FALSE
;
1033 struct vnode
*starting_parent
= dp
;
1035 DBG_VOP(("synthfs_lookup called, name = %s, namelen = %ld\n", ap
->a_cnp
->cn_nameptr
, ap
->a_cnp
->cn_namelen
));
1037 if (flags
& LOCKPARENT
) DBG_VOP(("\tLOCKPARENT is set\n"));
1038 if (flags
& ISLASTCN
) DBG_VOP(("\tISLASTCN is set\n"));
1043 /* first check for "." and ".." */
1044 if (cnp
->cn_nameptr
[0] == '.') {
1053 vnode_get(target_vp
);
1058 } else if ((namelen
== 2) && (cnp
->cn_nameptr
[1] == '.')) {
1065 if ((dsp
->s_parent
!= NULL
) && (dsp
->s_parent
!= VTOS(dp
))) {
1066 target_vp
= STOV(dsp
->s_parent
);
1068 * Special case for ".." to prevent deadlock:
1069 * always release the parent vnode BEFORE trying to acquire
1070 * ITS parent. This avoids deadlocking with another lookup
1071 * starting from the target_vp trying to vnode_get() this directory.
1073 result
= vnode_get(target_vp
);
1077 /* dp is alread locked and ref'ed */
1085 /* finally, just look for entries by name (making sure the entry's length
1086 matches the cnp's namelen... */
1087 TAILQ_FOREACH(entry
, &dsp
->s_u
.d
.d_subnodes
, s_sibling
) {
1088 if ((bcmp(cnp
->cn_nameptr
, entry
->s_name
, (unsigned)namelen
) == 0) &&
1089 (*(entry
->s_name
+ namelen
) == (char)0)) {
1091 target_vp
= STOV(entry
);
1092 result
= vnode_getwithref(target_vp
); /* refcount is always > 0 for any vnode in this list... */
1097 /* The specified entry was found and successfully acquired: */
1106 if ((nameiop
== DELETE
) && (flags
& ISLASTCN
)) {
1109 * If the parent directory is "sticky" then the user must own
1110 * the directory, or the file in it, in order to be allowed to
1111 * delete it (unless the user is root). This implements
1112 * append-only directories
1114 if ((dsp
->s_mode
& S_ISVTX
) &&
1115 suser(cred
, NULL
) &&
1116 (kauth_cred_getuid(cred
) != dsp
->s_uid
) &&
1117 (target_vp
!= NULL
) &&
1118 (target_vp
->v_type
!= VLNK
) &&
1119 (VTOS(target_vp
)->s_uid
!= kauth_cred_getuid(cred
))) {
1120 vnode_put(target_vp
);
1126 if ((nameiop
== RENAME
) && (flags
& WANTPARENT
) && (flags
* ISLASTCN
)) {
1129 vnode_put(target_vp
);
1135 /* The specified entry wasn't found: */
1138 if ((flags
& ISLASTCN
) &&
1139 ((nameiop
== CREATE
) ||
1140 (nameiop
== RENAME
) ||
1141 ((nameiop
== DELETE
) && (flags
& DOWHITEOUT
) && (flags
& ISWHITEOUT
)))) {
1142 /* create a new entry */
1143 result
= EJUSTRETURN
;
1147 *ap
->a_vpp
= target_vp
;
1150 DBG_VOP(("synthfs_lookup: result = %d.\n", result
));
1153 DBG_VOP(("synthfs_lookup: target_vp = 0x%08X \n", (u_long
)target_vp
));
1155 DBG_VOP(("synthfs_lookup: found = true but target_vp = NULL?\n"));
1158 DBG_VOP(("synthf_lookup: target not found.\n"));
1160 DBG_VOP(("synthfs_lookup: dp = %08X; starting_parent = 0x%08X .\n", (u_long
)dp
, (u_long
)starting_parent
));
1169 #% pathconf vp L L L
1172 IN struct vnode *vp;
1174 OUT register_t *retval;
1177 synthfs_pathconf(ap
)
1178 struct vnop_pathconf_args
/* {
1182 vfs_context_t a_context;
1185 DBG_VOP(("synthfs_pathconf called\n"));
1190 *ap
->a_retval
= LINK_MAX
;
1193 *ap
->a_retval
= NAME_MAX
;
1196 *ap
->a_retval
= PATH_MAX
;
1199 *ap
->a_retval
= PIPE_BUF
;
1201 case _PC_CHOWN_RESTRICTED
:
1215 * Update the access, modified, and node change times as specified by the
1216 * IACCESS, IUPDATE, and ICHANGE flags respectively. The IMODIFIED flag is
1217 * used to specify that the node needs to be updated but that the times have
1218 * already been set. The access and modified times are taken from the second
1219 * and third parameters; the node change time is always taken from the current
1220 * time. If waitfor is set, then wait for the disk write of the node to
1225 synthfs_update(struct vnode
*vp
, struct timeval
*access
, struct timeval
*modify
, __unused
int waitfor
)
1227 struct synthfsnode
*sp
= VTOS(vp
);
1230 DBG_ASSERT(sp
!= NULL
);
1232 if (((sp
->s_nodeflags
& (IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
)) != 0) &&
1233 !(VTOVFS(vp
)->mnt_flag
& MNT_RDONLY
)) {
1234 if (sp
->s_nodeflags
& IN_ACCESS
) sp
->s_accesstime
= *access
;
1235 if (sp
->s_nodeflags
& IN_UPDATE
) sp
->s_modificationtime
= *modify
;
1236 if (sp
->s_nodeflags
& IN_CHANGE
) {
1239 sp
->s_changetime
= tv
;
1243 /* After the updates are finished, clear the flags */
1244 sp
->s_nodeflags
&= ~(IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
);
1251 /*******************************************************************************************
1253 Utility/housekeeping vnode operations:
1255 ******************************************************************************************/
1260 #% inactive vp L U U
1263 IN struct vnode *vp;
1269 synthfs_inactive(ap
)
1270 struct vnop_inactive_args
/* {
1272 vfs_context_t a_context;
1275 struct vnode
*vp
= ap
->a_vp
;
1276 struct synthfsnode
*sp
= VTOS(vp
);
1280 if (vp
->v_usecount
!= 0)
1281 DBG_VOP(("synthfs_inactive: bad usecount = %d\n", vp
->v_usecount
));
1285 * Ignore nodes related to stale file handles.
1287 if (vp
->v_type
== VNON
)
1290 /* This is sort of silly but might make sense in the future: */
1291 if (sp
->s_nodeflags
& (IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
)) {
1293 synthfs_update(vp
, &tv
, &tv
, 0);
1298 * If we are done with the inode, reclaim it
1299 * so that it can be reused immediately.
1301 if (vp
->v_type
== VNON
) {
1311 * synthfs_reclaim - Reclaim a vnode so that it can be used for other purposes.
1313 * Locking policy: ignored
1317 struct vnop_reclaim_args
/* { struct vnode *a_vp; struct proc *a_p; } */ *ap
;
1319 struct vnode
*vp
= ap
->a_vp
;
1320 struct synthfsnode
*sp
= VTOS(vp
);
1321 void *name
= sp
->s_name
;
1327 FREE((void *)sp
, M_SYNTHFS
);