tmpfs_subr.c (171068) | tmpfs_subr.c (171070) |
---|---|
1/* $NetBSD: tmpfs_subr.c,v 1.21 2006/06/07 22:33:39 kardel Exp $ */ 2 3/* 4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code --- 27 unchanged lines hidden (view full) --- 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40/* 41 * Efficient memory file system supporting functions. 42 */ 43#include <sys/cdefs.h> | 1/* $NetBSD: tmpfs_subr.c,v 1.21 2006/06/07 22:33:39 kardel Exp $ */ 2 3/* 4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code --- 27 unchanged lines hidden (view full) --- 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40/* 41 * Efficient memory file system supporting functions. 42 */ 43#include <sys/cdefs.h> |
44__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_subr.c 171068 2007-06-28 02:34:32Z delphij $"); | 44__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_subr.c 171070 2007-06-28 02:39:31Z delphij $"); |
45 46#include <sys/param.h> 47#include <sys/namei.h> 48#include <sys/priv.h> 49#include <sys/proc.h> 50#include <sys/stat.h> 51#include <sys/systm.h> 52#include <sys/vnode.h> --- 58 unchanged lines hidden (view full) --- 111 /* Generic initialization. */ 112 nnode->tn_type = type; 113 vfs_timestamp(&nnode->tn_atime); 114 nnode->tn_birthtime = nnode->tn_ctime = nnode->tn_mtime = 115 nnode->tn_atime; 116 nnode->tn_uid = uid; 117 nnode->tn_gid = gid; 118 nnode->tn_mode = mode; | 45 46#include <sys/param.h> 47#include <sys/namei.h> 48#include <sys/priv.h> 49#include <sys/proc.h> 50#include <sys/stat.h> 51#include <sys/systm.h> 52#include <sys/vnode.h> --- 58 unchanged lines hidden (view full) --- 111 /* Generic initialization. */ 112 nnode->tn_type = type; 113 vfs_timestamp(&nnode->tn_atime); 114 nnode->tn_birthtime = nnode->tn_ctime = nnode->tn_mtime = 115 nnode->tn_atime; 116 nnode->tn_uid = uid; 117 nnode->tn_gid = gid; 118 nnode->tn_mode = mode; |
119 | 119 |
120 /* Type-specific initialization. */ 121 switch (nnode->tn_type) { 122 case VBLK: 123 case VCHR: 124 nnode->tn_rdev = rdev; 125 break; 126 127 case VDIR: --- 19 unchanged lines hidden (view full) --- 147 nnode->tn_type = VNON; 148 uma_zfree(tmp->tm_node_pool, nnode); 149 return ENOSPC; 150 } 151 memcpy(nnode->tn_link, target, nnode->tn_size); 152 break; 153 154 case VREG: | 120 /* Type-specific initialization. */ 121 switch (nnode->tn_type) { 122 case VBLK: 123 case VCHR: 124 nnode->tn_rdev = rdev; 125 break; 126 127 case VDIR: --- 19 unchanged lines hidden (view full) --- 147 nnode->tn_type = VNON; 148 uma_zfree(tmp->tm_node_pool, nnode); 149 return ENOSPC; 150 } 151 memcpy(nnode->tn_link, target, nnode->tn_size); 152 break; 153 154 case VREG: |
155 nnode->tn_reg.tn_aobj = | 155 nnode->tn_reg.tn_aobj = |
156 vm_pager_allocate(OBJT_SWAP, NULL, 0, VM_PROT_DEFAULT, 0); 157 nnode->tn_reg.tn_aobj_pages = 0; 158 break; 159 160 default: 161 MPASS(0); 162 } 163 --- 159 unchanged lines hidden (view full) --- 323 struct vnode *vp; 324 325 vp = NULL; 326 327loop: 328 if (node->tn_vnode != NULL) { 329 vp = node->tn_vnode; 330 vget(vp, LK_EXCLUSIVE | LK_RETRY, td); | 156 vm_pager_allocate(OBJT_SWAP, NULL, 0, VM_PROT_DEFAULT, 0); 157 nnode->tn_reg.tn_aobj_pages = 0; 158 break; 159 160 default: 161 MPASS(0); 162 } 163 --- 159 unchanged lines hidden (view full) --- 323 struct vnode *vp; 324 325 vp = NULL; 326 327loop: 328 if (node->tn_vnode != NULL) { 329 vp = node->tn_vnode; 330 vget(vp, LK_EXCLUSIVE | LK_RETRY, td); |
331 | 331 |
332 /* 333 * Make sure the vnode is still there after 334 * getting the interlock to avoid racing a free. 335 */ 336 if (node->tn_vnode == NULL || node->tn_vnode != vp) { 337 vput(vp); 338 goto loop; 339 } --- 64 unchanged lines hidden (view full) --- 404 405 error = 0; 406 node->tn_vnode = vp; 407 408unlock: 409 MPASS(node->tn_vpstate & TMPFS_VNODE_ALLOCATING); 410 TMPFS_NODE_LOCK(node); 411 node->tn_vpstate &= ~TMPFS_VNODE_ALLOCATING; | 332 /* 333 * Make sure the vnode is still there after 334 * getting the interlock to avoid racing a free. 335 */ 336 if (node->tn_vnode == NULL || node->tn_vnode != vp) { 337 vput(vp); 338 goto loop; 339 } --- 64 unchanged lines hidden (view full) --- 404 405 error = 0; 406 node->tn_vnode = vp; 407 408unlock: 409 MPASS(node->tn_vpstate & TMPFS_VNODE_ALLOCATING); 410 TMPFS_NODE_LOCK(node); 411 node->tn_vpstate &= ~TMPFS_VNODE_ALLOCATING; |
412 | 412 |
413 if (node->tn_vpstate & TMPFS_VNODE_WANT) { 414 node->tn_vpstate &= ~TMPFS_VNODE_WANT; 415 TMPFS_NODE_UNLOCK(node); 416 wakeup((caddr_t) &node->tn_vpstate); 417 } else 418 TMPFS_NODE_UNLOCK(node); | 413 if (node->tn_vpstate & TMPFS_VNODE_WANT) { 414 node->tn_vpstate &= ~TMPFS_VNODE_WANT; 415 TMPFS_NODE_UNLOCK(node); 416 wakeup((caddr_t) &node->tn_vpstate); 417 } else 418 TMPFS_NODE_UNLOCK(node); |
419 | 419 |
420out: 421 *vpp = vp; 422 423 MPASS(IFF(error == 0, *vpp != NULL && VOP_ISLOCKED(*vpp, td))); 424 MPASS(*vpp == node->tn_vnode); 425 426 return error; 427} --- 164 unchanged lines hidden (view full) --- 592 MPASS(cnp->cn_namelen < 0xffff); 593 if (de->td_namelen == (uint16_t)cnp->cn_namelen && 594 memcmp(de->td_name, cnp->cn_nameptr, de->td_namelen) == 0) { 595 found = 1; 596 break; 597 } 598 } 599 node->tn_status |= TMPFS_NODE_ACCESSED; | 420out: 421 *vpp = vp; 422 423 MPASS(IFF(error == 0, *vpp != NULL && VOP_ISLOCKED(*vpp, td))); 424 MPASS(*vpp == node->tn_vnode); 425 426 return error; 427} --- 164 unchanged lines hidden (view full) --- 592 MPASS(cnp->cn_namelen < 0xffff); 593 if (de->td_namelen == (uint16_t)cnp->cn_namelen && 594 memcmp(de->td_name, cnp->cn_nameptr, de->td_namelen) == 0) { 595 found = 1; 596 break; 597 } 598 } 599 node->tn_status |= TMPFS_NODE_ACCESSED; |
600 | 600 |
601 return found ? de : NULL; 602} 603 604/* --------------------------------------------------------------------- */ 605 606/* 607 * Helper function for tmpfs_readdir. Creates a '.' entry for the given 608 * directory and returns it in the uio space. The function returns 0 --- 261 unchanged lines hidden (view full) --- 870 vm_page_t m; 871 872 /* 873 * free "backing store" 874 */ 875 876 if (newpages < oldpages) { 877 VM_OBJECT_LOCK(uobj); | 601 return found ? de : NULL; 602} 603 604/* --------------------------------------------------------------------- */ 605 606/* 607 * Helper function for tmpfs_readdir. Creates a '.' entry for the given 608 * directory and returns it in the uio space. The function returns 0 --- 261 unchanged lines hidden (view full) --- 870 vm_page_t m; 871 872 /* 873 * free "backing store" 874 */ 875 876 if (newpages < oldpages) { 877 VM_OBJECT_LOCK(uobj); |
878 swap_pager_freespace(uobj, | 878 swap_pager_freespace(uobj, |
879 newpages, oldpages - newpages); 880 VM_OBJECT_UNLOCK(uobj); 881 } 882 883 /* 884 * zero out the truncated part of the last page. 885 */ 886 887 if (zerolen > 0) { | 879 newpages, oldpages - newpages); 880 VM_OBJECT_UNLOCK(uobj); 881 } 882 883 /* 884 * zero out the truncated part of the last page. 885 */ 886 887 if (zerolen > 0) { |
888 m = vm_page_grab(uobj, OFF_TO_IDX(newsize), | 888 m = vm_page_grab(uobj, OFF_TO_IDX(newsize), |
889 VM_ALLOC_NORMAL | VM_ALLOC_RETRY); | 889 VM_ALLOC_NORMAL | VM_ALLOC_RETRY); |
890 pmap_zero_page_area(m, PAGE_SIZE - zerolen, | 890 pmap_zero_page_area(m, PAGE_SIZE - zerolen, |
891 zerolen); 892 vm_page_wakeup(m); 893 } 894 895 } 896 897 error = 0; 898 --- 164 unchanged lines hidden (view full) --- 1063 if ((error = VOP_ACCESS(vp, VADMIN, cred, p))) 1064 return (error); 1065 1066 /* 1067 * To change the owner of a file, or change the group of a file to a 1068 * group of which we are not a member, the caller must have 1069 * privilege. 1070 */ | 891 zerolen); 892 vm_page_wakeup(m); 893 } 894 895 } 896 897 error = 0; 898 --- 164 unchanged lines hidden (view full) --- 1063 if ((error = VOP_ACCESS(vp, VADMIN, cred, p))) 1064 return (error); 1065 1066 /* 1067 * To change the owner of a file, or change the group of a file to a 1068 * group of which we are not a member, the caller must have 1069 * privilege. 1070 */ |
1071 if ((uid != node->tn_uid || | 1071 if ((uid != node->tn_uid || |
1072 (gid != node->tn_gid && !groupmember(gid, cred))) && 1073 (error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0))) 1074 return (error); 1075 1076 ogid = node->tn_gid; 1077 ouid = node->tn_uid; 1078 1079 node->tn_uid = uid; --- 93 unchanged lines hidden (view full) --- 1173 /* Immutable or append-only files cannot be modified, either. */ 1174 if (node->tn_flags & (IMMUTABLE | APPEND)) 1175 return EPERM; 1176 1177 /* XXX: The following comes from UFS code, and can be found in 1178 * several other file systems. Shouldn't this be centralized 1179 * somewhere? */ 1180 if (cred->cr_uid != node->tn_uid && | 1072 (gid != node->tn_gid && !groupmember(gid, cred))) && 1073 (error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0))) 1074 return (error); 1075 1076 ogid = node->tn_gid; 1077 ouid = node->tn_uid; 1078 1079 node->tn_uid = uid; --- 93 unchanged lines hidden (view full) --- 1173 /* Immutable or append-only files cannot be modified, either. */ 1174 if (node->tn_flags & (IMMUTABLE | APPEND)) 1175 return EPERM; 1176 1177 /* XXX: The following comes from UFS code, and can be found in 1178 * several other file systems. Shouldn't this be centralized 1179 * somewhere? */ 1180 if (cred->cr_uid != node->tn_uid && |
1181 (error = suser_cred(cred, 0)) && | 1181 (error = suser_cred(cred, 0)) && |
1182 ((vaflags & VA_UTIMES_NULL) == 0 || 1183 (error = VOP_ACCESS(vp, VWRITE, cred, l)))) 1184 return error; 1185 1186 if (atime->tv_sec != VNOVAL && atime->tv_nsec != VNOVAL) 1187 node->tn_status |= TMPFS_NODE_ACCESSED; 1188 1189 if (mtime->tv_sec != VNOVAL && mtime->tv_nsec != VNOVAL) 1190 node->tn_status |= TMPFS_NODE_MODIFIED; 1191 1192 if (birthtime->tv_nsec != VNOVAL && birthtime->tv_nsec != VNOVAL) 1193 node->tn_status |= TMPFS_NODE_MODIFIED; | 1182 ((vaflags & VA_UTIMES_NULL) == 0 || 1183 (error = VOP_ACCESS(vp, VWRITE, cred, l)))) 1184 return error; 1185 1186 if (atime->tv_sec != VNOVAL && atime->tv_nsec != VNOVAL) 1187 node->tn_status |= TMPFS_NODE_ACCESSED; 1188 1189 if (mtime->tv_sec != VNOVAL && mtime->tv_nsec != VNOVAL) 1190 node->tn_status |= TMPFS_NODE_MODIFIED; 1191 1192 if (birthtime->tv_nsec != VNOVAL && birthtime->tv_nsec != VNOVAL) 1193 node->tn_status |= TMPFS_NODE_MODIFIED; |
1194 | 1194 |
1195 tmpfs_itimes(vp, atime, mtime); | 1195 tmpfs_itimes(vp, atime, mtime); |
1196 | 1196 |
1197 if (birthtime->tv_nsec != VNOVAL && birthtime->tv_nsec != VNOVAL) 1198 node->tn_birthtime = *birthtime; 1199 MPASS(VOP_ISLOCKED(vp, l)); 1200 1201 return 0; 1202} 1203 1204/* --------------------------------------------------------------------- */ --- 80 unchanged lines hidden --- | 1197 if (birthtime->tv_nsec != VNOVAL && birthtime->tv_nsec != VNOVAL) 1198 node->tn_birthtime = *birthtime; 1199 MPASS(VOP_ISLOCKED(vp, l)); 1200 1201 return 0; 1202} 1203 1204/* --------------------------------------------------------------------- */ --- 80 unchanged lines hidden --- |