2007-08-10 11:00:30 +00:00
|
|
|
/* $NetBSD: tmpfs.h,v 1.26 2007/02/22 06:37:00 thorpej Exp $ */
|
2007-06-16 01:56:05 +00:00
|
|
|
|
2008-09-03 18:53:48 +00:00
|
|
|
/*-
|
2007-08-10 11:00:30 +00:00
|
|
|
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
|
2007-06-16 01:56:05 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Julio M. Merino Vidal, developed as part of Google's Summer of Code
|
|
|
|
* 2005 program.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _FS_TMPFS_TMPFS_H_
|
|
|
|
#define _FS_TMPFS_TMPFS_H_
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------
|
|
|
|
* KERNEL-SPECIFIC DEFINITIONS
|
|
|
|
* --------------------------------------------------------------------- */
|
|
|
|
#include <sys/dirent.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/systm.h>
|
2013-01-06 22:15:44 +00:00
|
|
|
#include <sys/tree.h>
|
2007-06-16 01:56:05 +00:00
|
|
|
#include <sys/vmmeter.h>
|
|
|
|
#include <vm/swap_pager.h>
|
|
|
|
|
|
|
|
MALLOC_DECLARE(M_TMPFSMNT);
|
2007-06-29 05:23:15 +00:00
|
|
|
MALLOC_DECLARE(M_TMPFSNAME);
|
2007-06-16 01:56:05 +00:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal representation of a tmpfs directory entry.
|
|
|
|
*/
|
2013-01-06 22:15:44 +00:00
|
|
|
|
|
|
|
LIST_HEAD(tmpfs_dir_duphead, tmpfs_dirent);
|
|
|
|
|
2007-06-16 01:56:05 +00:00
|
|
|
struct tmpfs_dirent {
|
2013-01-06 22:15:44 +00:00
|
|
|
/*
|
|
|
|
* Depending on td_cookie flag entry can be of 3 types:
|
|
|
|
* - regular -- no hash collisions, stored in RB-Tree
|
|
|
|
* - duphead -- synthetic linked list head for dup entries
|
|
|
|
* - dup -- stored in linked list instead of RB-Tree
|
|
|
|
*/
|
|
|
|
union {
|
|
|
|
/* regular and duphead entry types */
|
|
|
|
RB_ENTRY(tmpfs_dirent) td_entries;
|
2007-06-16 01:56:05 +00:00
|
|
|
|
2013-01-06 22:15:44 +00:00
|
|
|
/* dup entry type */
|
|
|
|
struct {
|
|
|
|
LIST_ENTRY(tmpfs_dirent) entries;
|
|
|
|
LIST_ENTRY(tmpfs_dirent) index_entries;
|
|
|
|
} td_dup;
|
|
|
|
} uh;
|
2007-06-16 01:56:05 +00:00
|
|
|
|
2013-01-06 22:15:44 +00:00
|
|
|
uint32_t td_cookie;
|
|
|
|
uint32_t td_hash;
|
|
|
|
u_int td_namelen;
|
2007-06-16 01:56:05 +00:00
|
|
|
|
2010-08-22 05:36:06 +00:00
|
|
|
/* Pointer to the node this entry refers to. In case this field
|
|
|
|
* is NULL, the node is a whiteout. */
|
2007-06-16 01:56:05 +00:00
|
|
|
struct tmpfs_node * td_node;
|
2013-01-06 22:15:44 +00:00
|
|
|
|
|
|
|
union {
|
|
|
|
/*
|
|
|
|
* The name of the entry, allocated from a string pool. This
|
|
|
|
* string is not required to be zero-terminated.
|
|
|
|
*/
|
|
|
|
char * td_name; /* regular, dup */
|
|
|
|
struct tmpfs_dir_duphead td_duphead; /* duphead */
|
|
|
|
} ud;
|
2007-06-16 01:56:05 +00:00
|
|
|
};
|
|
|
|
|
2013-01-06 22:15:44 +00:00
|
|
|
/* A directory in tmpfs holds a list of directory entries, which in
|
2007-06-16 01:56:05 +00:00
|
|
|
* turn point to other files (which can be directories themselves).
|
|
|
|
*
|
2013-01-06 22:15:44 +00:00
|
|
|
* In tmpfs, this list is managed by a RB-Tree, whose head is defined by
|
2007-06-16 01:56:05 +00:00
|
|
|
* the struct tmpfs_dir type.
|
|
|
|
*
|
2013-01-06 22:15:44 +00:00
|
|
|
* It is important to notice that directories do not have entries for . and
|
2007-06-16 01:56:05 +00:00
|
|
|
* .. as other file systems do. These can be generated when requested
|
|
|
|
* based on information available by other means, such as the pointer to
|
|
|
|
* the node itself in the former case or the pointer to the parent directory
|
|
|
|
* in the latter case. This is done to simplify tmpfs's code and, more
|
|
|
|
* importantly, to remove redundancy. */
|
2013-01-06 22:15:44 +00:00
|
|
|
RB_HEAD(tmpfs_dir, tmpfs_dirent);
|
2007-06-16 01:56:05 +00:00
|
|
|
|
2007-08-10 11:00:30 +00:00
|
|
|
/* Each entry in a directory has a cookie that identifies it. Cookies
|
|
|
|
* supersede offsets within directories because, given how tmpfs stores
|
2013-01-06 22:15:44 +00:00
|
|
|
* directories in memory, there is no such thing as an offset.
|
|
|
|
*
|
2007-08-10 11:00:30 +00:00
|
|
|
* The '.', '..' and the end of directory markers have fixed cookies which
|
|
|
|
* cannot collide with the cookies generated by other entries. The cookies
|
2013-01-06 22:15:44 +00:00
|
|
|
* for the other entries are generated based on the file name hash value or
|
|
|
|
* unique number in case of name hash collision.
|
2007-08-10 11:00:30 +00:00
|
|
|
*
|
2013-01-06 22:15:44 +00:00
|
|
|
* To preserve compatibility cookies are limited to 31 bits.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TMPFS_DIRCOOKIE_DOT 0
|
|
|
|
#define TMPFS_DIRCOOKIE_DOTDOT 1
|
|
|
|
#define TMPFS_DIRCOOKIE_EOF 2
|
|
|
|
#define TMPFS_DIRCOOKIE_MASK ((off_t)0x3fffffffU)
|
|
|
|
#define TMPFS_DIRCOOKIE_MIN ((off_t)0x00000004U)
|
|
|
|
#define TMPFS_DIRCOOKIE_DUP ((off_t)0x40000000U)
|
|
|
|
#define TMPFS_DIRCOOKIE_DUPHEAD ((off_t)0x80000000U)
|
|
|
|
#define TMPFS_DIRCOOKIE_DUP_MIN TMPFS_DIRCOOKIE_DUP
|
|
|
|
#define TMPFS_DIRCOOKIE_DUP_MAX \
|
|
|
|
(TMPFS_DIRCOOKIE_DUP | TMPFS_DIRCOOKIE_MASK)
|
2007-06-16 01:56:05 +00:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal representation of a tmpfs file system node.
|
|
|
|
*
|
|
|
|
* This structure is splitted in two parts: one holds attributes common
|
|
|
|
* to all file types and the other holds data that is only applicable to
|
|
|
|
* a particular type. The code must be careful to only access those
|
|
|
|
* attributes that are actually allowed by the node's type.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Below is the key of locks used to protected the fields in the following
|
|
|
|
* structures.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct tmpfs_node {
|
|
|
|
/* Doubly-linked list entry which links all existing nodes for a
|
|
|
|
* single file system. This is provided to ease the removal of
|
|
|
|
* all nodes during the unmount operation. */
|
|
|
|
LIST_ENTRY(tmpfs_node) tn_entries;
|
|
|
|
|
|
|
|
/* The node's type. Any of 'VBLK', 'VCHR', 'VDIR', 'VFIFO',
|
|
|
|
* 'VLNK', 'VREG' and 'VSOCK' is allowed. The usage of vnode
|
|
|
|
* types instead of a custom enumeration is to make things simpler
|
|
|
|
* and faster, as we do not need to convert between two types. */
|
|
|
|
enum vtype tn_type;
|
|
|
|
|
|
|
|
/* Node identifier. */
|
|
|
|
ino_t tn_id;
|
|
|
|
|
|
|
|
/* Node's internal status. This is used by several file system
|
|
|
|
* operations to do modifications to the node in a delayed
|
|
|
|
* fashion. */
|
|
|
|
int tn_status;
|
|
|
|
#define TMPFS_NODE_ACCESSED (1 << 1)
|
|
|
|
#define TMPFS_NODE_MODIFIED (1 << 2)
|
|
|
|
#define TMPFS_NODE_CHANGED (1 << 3)
|
|
|
|
|
|
|
|
/* The node size. It does not necessarily match the real amount
|
|
|
|
* of memory consumed by it. */
|
|
|
|
off_t tn_size;
|
|
|
|
|
|
|
|
/* Generic node attributes. */
|
|
|
|
uid_t tn_uid;
|
|
|
|
gid_t tn_gid;
|
|
|
|
mode_t tn_mode;
|
2013-03-21 22:44:33 +00:00
|
|
|
u_long tn_flags;
|
2007-06-16 01:56:05 +00:00
|
|
|
nlink_t tn_links;
|
|
|
|
struct timespec tn_atime;
|
|
|
|
struct timespec tn_mtime;
|
|
|
|
struct timespec tn_ctime;
|
|
|
|
struct timespec tn_birthtime;
|
|
|
|
unsigned long tn_gen;
|
|
|
|
|
|
|
|
/* As there is a single vnode for each active file within the
|
|
|
|
* system, care has to be taken to avoid allocating more than one
|
|
|
|
* vnode per file. In order to do this, a bidirectional association
|
|
|
|
* is kept between vnodes and nodes.
|
|
|
|
*
|
|
|
|
* Whenever a vnode is allocated, its v_data field is updated to
|
|
|
|
* point to the node it references. At the same time, the node's
|
|
|
|
* tn_vnode field is modified to point to the new vnode representing
|
|
|
|
* it. Further attempts to allocate a vnode for this same node will
|
|
|
|
* result in returning a new reference to the value stored in
|
|
|
|
* tn_vnode.
|
|
|
|
*
|
|
|
|
* May be NULL when the node is unused (that is, no vnode has been
|
|
|
|
* allocated for it or it has been reclaimed). */
|
|
|
|
struct vnode * tn_vnode;
|
|
|
|
|
|
|
|
/* interlock to protect tn_vpstate */
|
|
|
|
struct mtx tn_interlock;
|
|
|
|
|
|
|
|
/* Identify if current node has vnode assiocate with
|
|
|
|
* or allocating vnode.
|
|
|
|
*/
|
|
|
|
int tn_vpstate;
|
|
|
|
|
|
|
|
/* misc data field for different tn_type node */
|
|
|
|
union {
|
|
|
|
/* Valid when tn_type == VBLK || tn_type == VCHR. */
|
|
|
|
dev_t tn_rdev;
|
|
|
|
|
|
|
|
/* Valid when tn_type == VDIR. */
|
2013-01-06 22:15:44 +00:00
|
|
|
struct tn_dir {
|
2007-06-16 01:56:05 +00:00
|
|
|
/* Pointer to the parent directory. The root
|
|
|
|
* directory has a pointer to itself in this field;
|
|
|
|
* this property identifies the root node. */
|
|
|
|
struct tmpfs_node * tn_parent;
|
|
|
|
|
2013-01-06 22:15:44 +00:00
|
|
|
/* Head of a tree that links the contents of
|
|
|
|
* the directory together. */
|
2007-06-16 01:56:05 +00:00
|
|
|
struct tmpfs_dir tn_dirhead;
|
|
|
|
|
2013-01-06 22:15:44 +00:00
|
|
|
/* Head of a list the contains fake directory entries
|
|
|
|
* heads, i.e. entries with TMPFS_DIRCOOKIE_DUPHEAD
|
|
|
|
* flag. */
|
|
|
|
struct tmpfs_dir_duphead tn_dupindex;
|
|
|
|
|
2007-06-16 01:56:05 +00:00
|
|
|
/* Number and pointer of the first directory entry
|
|
|
|
* returned by the readdir operation if it were
|
|
|
|
* called again to continue reading data from the
|
|
|
|
* same directory as before. This is used to speed
|
|
|
|
* up reads of long directories, assuming that no
|
|
|
|
* more than one read is in progress at a given time.
|
2013-01-06 22:15:44 +00:00
|
|
|
* Otherwise, these values are discarded. */
|
2007-06-16 01:56:05 +00:00
|
|
|
off_t tn_readdir_lastn;
|
|
|
|
struct tmpfs_dirent * tn_readdir_lastp;
|
2013-01-06 22:15:44 +00:00
|
|
|
} tn_dir;
|
2007-06-16 01:56:05 +00:00
|
|
|
|
|
|
|
/* Valid when tn_type == VLNK. */
|
|
|
|
/* The link's target, allocated from a string pool. */
|
|
|
|
char * tn_link;
|
|
|
|
|
|
|
|
/* Valid when tn_type == VREG. */
|
|
|
|
struct tn_reg {
|
|
|
|
/* The contents of regular files stored in a tmpfs
|
|
|
|
* file system are represented by a single anonymous
|
|
|
|
* memory object (aobj, for short). The aobj provides
|
|
|
|
* direct access to any position within the file,
|
|
|
|
* because its contents are always mapped in a
|
|
|
|
* contiguous region of virtual memory. It is a task
|
|
|
|
* of the memory management subsystem (see uvm(9)) to
|
|
|
|
* issue the required page ins or page outs whenever
|
|
|
|
* a position within the file is accessed. */
|
|
|
|
vm_object_t tn_aobj;
|
|
|
|
|
|
|
|
}tn_reg;
|
|
|
|
|
|
|
|
/* Valid when tn_type = VFIFO */
|
|
|
|
struct tn_fifo {
|
|
|
|
fo_rdwr_t *tn_fo_read;
|
|
|
|
fo_rdwr_t *tn_fo_write;
|
|
|
|
}tn_fifo;
|
|
|
|
}tn_spec;
|
|
|
|
};
|
|
|
|
LIST_HEAD(tmpfs_node_list, tmpfs_node);
|
|
|
|
|
|
|
|
#define tn_rdev tn_spec.tn_rdev
|
|
|
|
#define tn_dir tn_spec.tn_dir
|
|
|
|
#define tn_link tn_spec.tn_link
|
|
|
|
#define tn_reg tn_spec.tn_reg
|
|
|
|
#define tn_fifo tn_spec.tn_fifo
|
|
|
|
|
|
|
|
#define TMPFS_NODE_LOCK(node) mtx_lock(&(node)->tn_interlock)
|
|
|
|
#define TMPFS_NODE_UNLOCK(node) mtx_unlock(&(node)->tn_interlock)
|
2009-10-11 07:03:56 +00:00
|
|
|
#define TMPFS_NODE_MTX(node) (&(node)->tn_interlock)
|
|
|
|
|
|
|
|
#ifdef INVARIANTS
|
|
|
|
#define TMPFS_ASSERT_LOCKED(node) do { \
|
|
|
|
MPASS(node != NULL); \
|
|
|
|
MPASS(node->tn_vnode != NULL); \
|
|
|
|
if (!VOP_ISLOCKED(node->tn_vnode) && \
|
|
|
|
!mtx_owned(TMPFS_NODE_MTX(node))) \
|
|
|
|
panic("tmpfs: node is not locked: %p", node); \
|
|
|
|
} while (0)
|
|
|
|
#define TMPFS_ASSERT_ELOCKED(node) do { \
|
|
|
|
MPASS((node) != NULL); \
|
|
|
|
MPASS((node)->tn_vnode != NULL); \
|
|
|
|
mtx_assert(TMPFS_NODE_MTX(node), MA_OWNED); \
|
|
|
|
ASSERT_VOP_LOCKED((node)->tn_vnode, "tmpfs"); \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define TMPFS_ASSERT_LOCKED(node) (void)0
|
|
|
|
#define TMPFS_ASSERT_ELOCKED(node) (void)0
|
|
|
|
#endif
|
2007-06-16 01:56:05 +00:00
|
|
|
|
|
|
|
#define TMPFS_VNODE_ALLOCATING 1
|
|
|
|
#define TMPFS_VNODE_WANT 2
|
2009-10-11 07:03:56 +00:00
|
|
|
#define TMPFS_VNODE_DOOMED 4
|
2013-08-05 18:53:59 +00:00
|
|
|
#define TMPFS_VNODE_WRECLAIM 8
|
2007-06-16 01:56:05 +00:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal representation of a tmpfs mount point.
|
|
|
|
*/
|
|
|
|
struct tmpfs_mount {
|
|
|
|
/* Maximum number of memory pages available for use by the file
|
|
|
|
* system, set during mount time. This variable must never be
|
2007-06-26 02:07:08 +00:00
|
|
|
* used directly as it may be bigger than the current amount of
|
2007-06-16 01:56:05 +00:00
|
|
|
* free memory; in the extreme case, it will hold the SIZE_MAX
|
2012-04-07 15:23:51 +00:00
|
|
|
* value. */
|
2007-06-16 01:56:05 +00:00
|
|
|
size_t tm_pages_max;
|
|
|
|
|
2012-04-07 15:23:51 +00:00
|
|
|
/* Number of pages in use by the file system. */
|
2007-06-16 01:56:05 +00:00
|
|
|
size_t tm_pages_used;
|
|
|
|
|
|
|
|
/* Pointer to the node representing the root directory of this
|
|
|
|
* file system. */
|
|
|
|
struct tmpfs_node * tm_root;
|
|
|
|
|
|
|
|
/* Maximum number of possible nodes for this file system; set
|
|
|
|
* during mount time. We need a hard limit on the maximum number
|
|
|
|
* of nodes to avoid allocating too much of them; their objects
|
|
|
|
* cannot be released until the file system is unmounted.
|
|
|
|
* Otherwise, we could easily run out of memory by creating lots
|
|
|
|
* of empty files and then simply removing them. */
|
|
|
|
ino_t tm_nodes_max;
|
|
|
|
|
2007-07-11 14:26:27 +00:00
|
|
|
/* unrhdr used to allocate inode numbers */
|
|
|
|
struct unrhdr * tm_ino_unr;
|
2007-06-16 01:56:05 +00:00
|
|
|
|
|
|
|
/* Number of nodes currently that are in use. */
|
|
|
|
ino_t tm_nodes_inuse;
|
|
|
|
|
|
|
|
/* maximum representable file size */
|
|
|
|
u_int64_t tm_maxfilesize;
|
2007-06-28 02:39:31 +00:00
|
|
|
|
2007-06-16 01:56:05 +00:00
|
|
|
/* Nodes are organized in two different lists. The used list
|
|
|
|
* contains all nodes that are currently used by the file system;
|
|
|
|
* i.e., they refer to existing files. The available list contains
|
|
|
|
* all nodes that are currently available for use by new files.
|
|
|
|
* Nodes must be kept in this list (instead of deleting them)
|
|
|
|
* because we need to keep track of their generation number (tn_gen
|
|
|
|
* field).
|
|
|
|
*
|
|
|
|
* Note that nodes are lazily allocated: if the available list is
|
|
|
|
* empty and we have enough space to create more nodes, they will be
|
|
|
|
* created and inserted in the used list. Once these are released,
|
|
|
|
* they will go into the available list, remaining alive until the
|
|
|
|
* file system is unmounted. */
|
|
|
|
struct tmpfs_node_list tm_nodes_used;
|
|
|
|
|
|
|
|
/* All node lock to protect the node list and tmp_pages_used */
|
|
|
|
struct mtx allnode_lock;
|
|
|
|
|
|
|
|
/* Pools used to store file system meta data. These are not shared
|
|
|
|
* across several instances of tmpfs for the reasons described in
|
|
|
|
* tmpfs_pool.c. */
|
|
|
|
uma_zone_t tm_dirent_pool;
|
|
|
|
uma_zone_t tm_node_pool;
|
2012-04-16 18:07:42 +00:00
|
|
|
|
|
|
|
/* Read-only status. */
|
|
|
|
int tm_ronly;
|
2007-06-16 01:56:05 +00:00
|
|
|
};
|
|
|
|
#define TMPFS_LOCK(tm) mtx_lock(&(tm)->allnode_lock)
|
|
|
|
#define TMPFS_UNLOCK(tm) mtx_unlock(&(tm)->allnode_lock)
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure maps a file identifier to a tmpfs node. Used by the
|
|
|
|
* NFS code.
|
|
|
|
*/
|
|
|
|
struct tmpfs_fid {
|
|
|
|
uint16_t tf_len;
|
|
|
|
uint16_t tf_pad;
|
|
|
|
ino_t tf_id;
|
2007-06-28 02:32:44 +00:00
|
|
|
unsigned long tf_gen;
|
2007-06-16 01:56:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
/*
|
|
|
|
* Prototypes for tmpfs_subr.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int tmpfs_alloc_node(struct tmpfs_mount *, enum vtype,
|
|
|
|
uid_t uid, gid_t gid, mode_t mode, struct tmpfs_node *,
|
2009-05-11 15:33:26 +00:00
|
|
|
char *, dev_t, struct tmpfs_node **);
|
2007-06-16 01:56:05 +00:00
|
|
|
void tmpfs_free_node(struct tmpfs_mount *, struct tmpfs_node *);
|
|
|
|
int tmpfs_alloc_dirent(struct tmpfs_mount *, struct tmpfs_node *,
|
2013-01-06 22:15:44 +00:00
|
|
|
const char *, u_int, struct tmpfs_dirent **);
|
|
|
|
void tmpfs_free_dirent(struct tmpfs_mount *, struct tmpfs_dirent *);
|
|
|
|
void tmpfs_dirent_init(struct tmpfs_dirent *, const char *, u_int);
|
2013-05-02 18:44:31 +00:00
|
|
|
void tmpfs_destroy_vobject(struct vnode *vp, vm_object_t obj);
|
2007-08-10 05:24:49 +00:00
|
|
|
int tmpfs_alloc_vp(struct mount *, struct tmpfs_node *, int,
|
2009-05-11 15:33:26 +00:00
|
|
|
struct vnode **);
|
2007-06-16 01:56:05 +00:00
|
|
|
void tmpfs_free_vp(struct vnode *);
|
|
|
|
int tmpfs_alloc_file(struct vnode *, struct vnode **, struct vattr *,
|
|
|
|
struct componentname *, char *);
|
|
|
|
void tmpfs_dir_attach(struct vnode *, struct tmpfs_dirent *);
|
|
|
|
void tmpfs_dir_detach(struct vnode *, struct tmpfs_dirent *);
|
2013-01-06 22:15:44 +00:00
|
|
|
void tmpfs_dir_destroy(struct tmpfs_mount *, struct tmpfs_node *);
|
2007-06-16 01:56:05 +00:00
|
|
|
struct tmpfs_dirent * tmpfs_dir_lookup(struct tmpfs_node *node,
|
2009-02-08 19:18:33 +00:00
|
|
|
struct tmpfs_node *f,
|
2007-06-16 01:56:05 +00:00
|
|
|
struct componentname *cnp);
|
2013-01-06 22:15:44 +00:00
|
|
|
int tmpfs_dir_getdents(struct tmpfs_node *, struct uio *, int,
|
|
|
|
u_long *, int *);
|
2010-08-22 05:36:06 +00:00
|
|
|
int tmpfs_dir_whiteout_add(struct vnode *, struct componentname *);
|
|
|
|
void tmpfs_dir_whiteout_remove(struct vnode *, struct componentname *);
|
2012-01-16 00:26:49 +00:00
|
|
|
int tmpfs_reg_resize(struct vnode *, off_t, boolean_t);
|
2013-03-21 22:44:33 +00:00
|
|
|
int tmpfs_chflags(struct vnode *, u_long, struct ucred *, struct thread *);
|
2007-06-16 01:56:05 +00:00
|
|
|
int tmpfs_chmod(struct vnode *, mode_t, struct ucred *, struct thread *);
|
|
|
|
int tmpfs_chown(struct vnode *, uid_t, gid_t, struct ucred *,
|
|
|
|
struct thread *);
|
|
|
|
int tmpfs_chsize(struct vnode *, u_quad_t, struct ucred *, struct thread *);
|
2007-06-28 02:39:31 +00:00
|
|
|
int tmpfs_chtimes(struct vnode *, struct timespec *, struct timespec *,
|
2007-06-16 01:56:05 +00:00
|
|
|
struct timespec *, int, struct ucred *, struct thread *);
|
|
|
|
void tmpfs_itimes(struct vnode *, const struct timespec *,
|
|
|
|
const struct timespec *);
|
|
|
|
|
|
|
|
void tmpfs_update(struct vnode *);
|
|
|
|
int tmpfs_truncate(struct vnode *, off_t);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience macros to simplify some logical expressions.
|
|
|
|
*/
|
|
|
|
#define IMPLIES(a, b) (!(a) || (b))
|
|
|
|
#define IFF(a, b) (IMPLIES(a, b) && IMPLIES(b, a))
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks that the directory entry pointed by 'de' matches the name 'name'
|
|
|
|
* with a length of 'len'.
|
|
|
|
*/
|
|
|
|
#define TMPFS_DIRENT_MATCHES(de, name, len) \
|
2013-01-06 22:15:44 +00:00
|
|
|
(de->td_namelen == len && \
|
|
|
|
bcmp((de)->ud.td_name, (name), (de)->td_namelen) == 0)
|
2007-06-16 01:56:05 +00:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensures that the node pointed by 'node' is a directory and that its
|
|
|
|
* contents are consistent with respect to directories.
|
|
|
|
*/
|
2013-01-06 22:15:44 +00:00
|
|
|
#define TMPFS_VALIDATE_DIR(node) do { \
|
|
|
|
MPASS((node)->tn_type == VDIR); \
|
|
|
|
MPASS((node)->tn_size % sizeof(struct tmpfs_dirent) == 0); \
|
|
|
|
} while (0)
|
2007-06-16 01:56:05 +00:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory management stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2012-04-07 15:23:51 +00:00
|
|
|
* Amount of memory pages to reserve for the system (e.g., to not use by
|
|
|
|
* tmpfs).
|
2007-06-16 01:56:05 +00:00
|
|
|
*/
|
2012-04-07 15:23:51 +00:00
|
|
|
#define TMPFS_PAGES_MINRESERVED (4 * 1024 * 1024 / PAGE_SIZE)
|
2007-06-16 01:56:05 +00:00
|
|
|
|
2012-04-07 15:23:51 +00:00
|
|
|
size_t tmpfs_mem_avail(void);
|
2007-06-25 18:46:13 +00:00
|
|
|
|
2012-04-07 15:23:51 +00:00
|
|
|
size_t tmpfs_pages_used(struct tmpfs_mount *tmp);
|
2007-06-16 01:56:05 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros/functions to convert from generic data structures to tmpfs
|
|
|
|
* specific ones.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline
|
|
|
|
struct tmpfs_mount *
|
|
|
|
VFS_TO_TMPFS(struct mount *mp)
|
|
|
|
{
|
|
|
|
struct tmpfs_mount *tmp;
|
|
|
|
|
|
|
|
MPASS((mp) != NULL && (mp)->mnt_data != NULL);
|
|
|
|
tmp = (struct tmpfs_mount *)(mp)->mnt_data;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
struct tmpfs_node *
|
|
|
|
VP_TO_TMPFS_NODE(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
MPASS((vp) != NULL && (vp)->v_data != NULL);
|
|
|
|
node = (struct tmpfs_node *)vp->v_data;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
struct tmpfs_node *
|
|
|
|
VP_TO_TMPFS_DIR(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
TMPFS_VALIDATE_DIR(node);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _FS_TMPFS_TMPFS_H_ */
|