tmpfs_subr.c (171070) | tmpfs_subr.c (171087) |
---|---|
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 171070 2007-06-28 02:39:31Z delphij $"); | 44__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_subr.c 171087 2007-06-29 05:23:15Z 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> --- 47 unchanged lines hidden (view full) --- 100 MPASS(IFF(type == VLNK, target != NULL)); 101 MPASS(IFF(type == VBLK || type == VCHR, rdev != VNOVAL)); 102 103 if (tmp->tm_nodes_inuse > tmp->tm_nodes_max) 104 return (ENOSPC); 105 106 nnode = (struct tmpfs_node *)uma_zalloc_arg( 107 tmp->tm_node_pool, tmp, M_WAITOK); | 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> --- 47 unchanged lines hidden (view full) --- 100 MPASS(IFF(type == VLNK, target != NULL)); 101 MPASS(IFF(type == VBLK || type == VCHR, rdev != VNOVAL)); 102 103 if (tmp->tm_nodes_inuse > tmp->tm_nodes_max) 104 return (ENOSPC); 105 106 nnode = (struct tmpfs_node *)uma_zalloc_arg( 107 tmp->tm_node_pool, tmp, M_WAITOK); |
108 if (nnode == NULL) 109 return (ENOSPC); | |
110 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; --- 18 unchanged lines hidden (view full) --- 136 case VFIFO: 137 /* FALLTHROUGH */ 138 case VSOCK: 139 break; 140 141 case VLNK: 142 MPASS(strlen(target) < MAXPATHLEN); 143 nnode->tn_size = strlen(target); | 108 109 /* Generic initialization. */ 110 nnode->tn_type = type; 111 vfs_timestamp(&nnode->tn_atime); 112 nnode->tn_birthtime = nnode->tn_ctime = nnode->tn_mtime = 113 nnode->tn_atime; 114 nnode->tn_uid = uid; 115 nnode->tn_gid = gid; --- 18 unchanged lines hidden (view full) --- 134 case VFIFO: 135 /* FALLTHROUGH */ 136 case VSOCK: 137 break; 138 139 case VLNK: 140 MPASS(strlen(target) < MAXPATHLEN); 141 nnode->tn_size = strlen(target); |
144 nnode->tn_link = tmpfs_str_zone_alloc(&tmp->tm_str_pool, 145 M_WAITOK, nnode->tn_size); 146 if (nnode->tn_link == NULL) { 147 nnode->tn_type = VNON; 148 uma_zfree(tmp->tm_node_pool, nnode); 149 return ENOSPC; 150 } | 142 nnode->tn_link = malloc(nnode->tn_size, M_TMPFSNAME, 143 M_WAITOK); |
151 memcpy(nnode->tn_link, target, nnode->tn_size); 152 break; 153 154 case VREG: 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; --- 53 unchanged lines hidden (view full) --- 212 case VDIR: 213 /* FALLTHROUGH */ 214 case VFIFO: 215 /* FALLTHROUGH */ 216 case VSOCK: 217 break; 218 219 case VLNK: | 144 memcpy(nnode->tn_link, target, nnode->tn_size); 145 break; 146 147 case VREG: 148 nnode->tn_reg.tn_aobj = 149 vm_pager_allocate(OBJT_SWAP, NULL, 0, VM_PROT_DEFAULT, 0); 150 nnode->tn_reg.tn_aobj_pages = 0; 151 break; --- 53 unchanged lines hidden (view full) --- 205 case VDIR: 206 /* FALLTHROUGH */ 207 case VFIFO: 208 /* FALLTHROUGH */ 209 case VSOCK: 210 break; 211 212 case VLNK: |
220 tmpfs_str_zone_free(&tmp->tm_str_pool, node->tn_link, 221 node->tn_size); | 213 free(node->tn_link, M_TMPFSNAME); |
222 break; 223 224 case VREG: 225 if (node->tn_reg.tn_aobj != NULL) { 226 vm_object_deallocate(node->tn_reg.tn_aobj); 227 } 228 pages = node->tn_reg.tn_aobj_pages; 229 break; --- 24 unchanged lines hidden (view full) --- 254int 255tmpfs_alloc_dirent(struct tmpfs_mount *tmp, struct tmpfs_node *node, 256 const char *name, uint16_t len, struct tmpfs_dirent **de) 257{ 258 struct tmpfs_dirent *nde; 259 260 nde = (struct tmpfs_dirent *)uma_zalloc( 261 tmp->tm_dirent_pool, M_WAITOK); | 214 break; 215 216 case VREG: 217 if (node->tn_reg.tn_aobj != NULL) { 218 vm_object_deallocate(node->tn_reg.tn_aobj); 219 } 220 pages = node->tn_reg.tn_aobj_pages; 221 break; --- 24 unchanged lines hidden (view full) --- 246int 247tmpfs_alloc_dirent(struct tmpfs_mount *tmp, struct tmpfs_node *node, 248 const char *name, uint16_t len, struct tmpfs_dirent **de) 249{ 250 struct tmpfs_dirent *nde; 251 252 nde = (struct tmpfs_dirent *)uma_zalloc( 253 tmp->tm_dirent_pool, M_WAITOK); |
262 if (nde == NULL) 263 return ENOSPC; 264 265 nde->td_name = tmpfs_str_zone_alloc(&tmp->tm_str_pool, M_WAITOK, len); 266 if (nde->td_name == NULL) { 267 uma_zfree(tmp->tm_dirent_pool, nde); 268 return ENOSPC; 269 } | 254 nde->td_name = malloc(len, M_TMPFSNAME, M_WAITOK); |
270 nde->td_namelen = len; 271 memcpy(nde->td_name, name, len); 272 273 nde->td_node = node; 274 node->tn_links++; 275 276 *de = nde; 277 --- 19 unchanged lines hidden (view full) --- 297 struct tmpfs_node *node; 298 299 node = de->td_node; 300 301 MPASS(node->tn_links > 0); 302 node->tn_links--; 303 } 304 | 255 nde->td_namelen = len; 256 memcpy(nde->td_name, name, len); 257 258 nde->td_node = node; 259 node->tn_links++; 260 261 *de = nde; 262 --- 19 unchanged lines hidden (view full) --- 282 struct tmpfs_node *node; 283 284 node = de->td_node; 285 286 MPASS(node->tn_links > 0); 287 node->tn_links--; 288 } 289 |
305 tmpfs_str_zone_free(&tmp->tm_str_pool, de->td_name, de->td_namelen); | 290 free(de->td_name, M_TMPFSNAME); |
306 uma_zfree(tmp->tm_dirent_pool, de); 307} 308 309/* --------------------------------------------------------------------- */ 310 311/* 312 * Allocates a new vnode for the node node or returns a new reference to 313 * an existing one if the node had already a vnode referencing it. The --- 855 unchanged lines hidden (view full) --- 1169 /* Disallow this operation if the file system is mounted read-only. */ 1170 if (vp->v_mount->mnt_flag & MNT_RDONLY) 1171 return EROFS; 1172 1173 /* Immutable or append-only files cannot be modified, either. */ 1174 if (node->tn_flags & (IMMUTABLE | APPEND)) 1175 return EPERM; 1176 | 291 uma_zfree(tmp->tm_dirent_pool, de); 292} 293 294/* --------------------------------------------------------------------- */ 295 296/* 297 * Allocates a new vnode for the node node or returns a new reference to 298 * an existing one if the node had already a vnode referencing it. The --- 855 unchanged lines hidden (view full) --- 1154 /* Disallow this operation if the file system is mounted read-only. */ 1155 if (vp->v_mount->mnt_flag & MNT_RDONLY) 1156 return EROFS; 1157 1158 /* Immutable or append-only files cannot be modified, either. */ 1159 if (node->tn_flags & (IMMUTABLE | APPEND)) 1160 return EPERM; 1161 |
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)) && 1182 ((vaflags & VA_UTIMES_NULL) == 0 || 1183 (error = VOP_ACCESS(vp, VWRITE, cred, l)))) 1184 return error; | 1162 /* Determine if the user have proper privilege to update time. */ 1163 if (vaflags & VA_UTIMES_NULL) { 1164 error = VOP_ACCESS(vp, VADMIN, cred, l); 1165 if (error) 1166 error = VOP_ACCESS(vp, VWRITE, cred, l); 1167 } else 1168 error = VOP_ACCESS(vp, VADMIN, cred, l); 1169 if (error) 1170 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) --- 92 unchanged lines hidden --- | 1171 1172 if (atime->tv_sec != VNOVAL && atime->tv_nsec != VNOVAL) 1173 node->tn_status |= TMPFS_NODE_ACCESSED; 1174 1175 if (mtime->tv_sec != VNOVAL && mtime->tv_nsec != VNOVAL) 1176 node->tn_status |= TMPFS_NODE_MODIFIED; 1177 1178 if (birthtime->tv_nsec != VNOVAL && birthtime->tv_nsec != VNOVAL) --- 92 unchanged lines hidden --- |