Deleted Added
sdiff udiff text old ( 269164 ) new ( 269175 )
full compact
1/* $NetBSD: tmpfs_vfsops.c,v 1.10 2005/12/11 12:24:29 christos 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 * tmpfs is a file system that uses NetBSD's virtual memory sub-system
37 * (the well-known UVM) to store file data and metadata in an efficient
38 * way. This means that it does not follow the structure of an on-disk
39 * file system because it simply does not need to. Instead, it uses
40 * memory-specific data structures and algorithms to automatically
41 * allocate and release resources.
42 */
43#include <sys/cdefs.h>
44__FBSDID("$FreeBSD: stable/10/sys/fs/tmpfs/tmpfs_vfsops.c 269164 2014-07-28 00:43:42Z kib $");
45
46#include <sys/param.h>
47#include <sys/limits.h>
48#include <sys/lock.h>
49#include <sys/mutex.h>
50#include <sys/proc.h>
51#include <sys/jail.h>
52#include <sys/kernel.h>

--- 180 unchanged lines hidden (view full) ---

233 tmp->tm_node_pool = uma_zcreate("TMPFS node",
234 sizeof(struct tmpfs_node),
235 tmpfs_node_ctor, tmpfs_node_dtor,
236 tmpfs_node_init, tmpfs_node_fini,
237 UMA_ALIGN_PTR, 0);
238 tmp->tm_ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
239
240 /* Allocate the root node. */
241 error = tmpfs_alloc_node(tmp, VDIR, root_uid,
242 root_gid, root_mode & ALLPERMS, NULL, NULL,
243 VNOVAL, &root);
244
245 if (error != 0 || root == NULL) {
246 uma_zdestroy(tmp->tm_node_pool);
247 uma_zdestroy(tmp->tm_dirent_pool);
248 delete_unrhdr(tmp->tm_ino_unr);
249 free(tmp, M_TMPFSMNT);

--- 14 unchanged lines hidden (view full) ---

264
265 return 0;
266}
267
268/* ARGSUSED2 */
269static int
270tmpfs_unmount(struct mount *mp, int mntflags)
271{
272 int error;
273 int flags = 0;
274 struct tmpfs_mount *tmp;
275 struct tmpfs_node *node;
276
277 /* Handle forced unmounts. */
278 if (mntflags & MNT_FORCE)
279 flags |= FORCECLOSE;
280
281 /* Finalize all pending I/O. */
282 error = vflush(mp, 0, flags, curthread);
283 if (error != 0)
284 return error;
285
286 tmp = VFS_TO_TMPFS(mp);
287
288 /* Free all associated data. The loop iterates over the linked list
289 * we have containing all used nodes. For each of them that is
290 * a directory, we free all its directory entries. Note that after
291 * freeing a node, it will automatically go to the available list,
292 * so we will later have to iterate over it to release its items. */
293 node = LIST_FIRST(&tmp->tm_nodes_used);
294 while (node != NULL) {
295 struct tmpfs_node *next;
296
297 if (node->tn_type == VDIR)
298 tmpfs_dir_destroy(tmp, node);
299
300 next = LIST_NEXT(node, tn_entries);
301 tmpfs_free_node(tmp, node);
302 node = next;
303 }
304
305 uma_zdestroy(tmp->tm_dirent_pool);
306 uma_zdestroy(tmp->tm_node_pool);
307 delete_unrhdr(tmp->tm_ino_unr);
308
309 mtx_destroy(&tmp->allnode_lock);
310 MPASS(tmp->tm_pages_used == 0);
311 MPASS(tmp->tm_nodes_inuse == 0);
312
313 /* Throw away the tmpfs_mount structure. */
314 free(mp->mnt_data, M_TMPFSMNT);
315 mp->mnt_data = NULL;
316
317 MNT_ILOCK(mp);
318 mp->mnt_flag &= ~MNT_LOCAL;
319 MNT_IUNLOCK(mp);
320 return 0;
321}
322
323static int
324tmpfs_root(struct mount *mp, int flags, struct vnode **vpp)
325{
326 int error;
327 error = tmpfs_alloc_vp(mp, VFS_TO_TMPFS(mp)->tm_root, flags, vpp);
328

--- 67 unchanged lines hidden (view full) ---

396 sbp->f_ffree = 0;
397 else
398 sbp->f_ffree = sbp->f_files - used;
399 /* sbp->f_owner = tmp->tn_uid; */
400
401 return 0;
402}
403
404/*
405 * tmpfs vfs operations.
406 */
407
408struct vfsops tmpfs_vfsops = {
409 .vfs_mount = tmpfs_mount,
410 .vfs_unmount = tmpfs_unmount,
411 .vfs_root = tmpfs_root,
412 .vfs_statfs = tmpfs_statfs,
413 .vfs_fhtovp = tmpfs_fhtovp,
414};
415VFS_SET(tmpfs_vfsops, tmpfs, VFCF_JAIL);