Home | History | Annotate | Line # | Download | only in tmpfs
tmpfs_args.h revision 1.2
      1  1.2  pooka /*	$NetBSD: tmpfs_args.h,v 1.2 2008/07/28 18:00:20 pooka Exp $	*/
      2  1.1  pooka 
      3  1.1  pooka /*
      4  1.1  pooka  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
      5  1.1  pooka  * All rights reserved.
      6  1.1  pooka  *
      7  1.1  pooka  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  pooka  * by Julio M. Merino Vidal, developed as part of Google's Summer of Code
      9  1.1  pooka  * 2005 program.
     10  1.1  pooka  *
     11  1.1  pooka  * Redistribution and use in source and binary forms, with or without
     12  1.1  pooka  * modification, are permitted provided that the following conditions
     13  1.1  pooka  * are met:
     14  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     15  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     16  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     19  1.1  pooka  *
     20  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.1  pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1  pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1  pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.1  pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1  pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1  pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1  pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1  pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1  pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1  pooka  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1  pooka  */
     32  1.1  pooka 
     33  1.2  pooka #ifndef _FS_TMPFS_TMPFS_ARGS_H_
     34  1.2  pooka #define _FS_TMPFS_TMPFS_ARGS_H_
     35  1.2  pooka 
     36  1.2  pooka #include <sys/vnode.h>
     37  1.2  pooka 
     38  1.2  pooka /*
     39  1.2  pooka  * Internal representation of a tmpfs directory entry.
     40  1.2  pooka  */
     41  1.2  pooka struct tmpfs_dirent {
     42  1.2  pooka 	TAILQ_ENTRY(tmpfs_dirent)	td_entries;
     43  1.2  pooka 
     44  1.2  pooka 	/* Length of the name stored in this directory entry.  This avoids
     45  1.2  pooka 	 * the need to recalculate it every time the name is used. */
     46  1.2  pooka 	uint16_t			td_namelen;
     47  1.2  pooka 
     48  1.2  pooka 	/* The name of the entry, allocated from a string pool.  This
     49  1.2  pooka 	* string is not required to be zero-terminated; therefore, the
     50  1.2  pooka 	* td_namelen field must always be used when accessing its value. */
     51  1.2  pooka 	char *				td_name;
     52  1.2  pooka 
     53  1.2  pooka 	/* Pointer to the node this entry refers to. */
     54  1.2  pooka 	struct tmpfs_node *		td_node;
     55  1.2  pooka };
     56  1.2  pooka 
     57  1.2  pooka /* A directory in tmpfs holds a sorted list of directory entries, which in
     58  1.2  pooka  * turn point to other files (which can be directories themselves).
     59  1.2  pooka  *
     60  1.2  pooka  * In tmpfs, this list is managed by a tail queue, whose head is defined by
     61  1.2  pooka  * the struct tmpfs_dir type.
     62  1.2  pooka  *
     63  1.2  pooka  * It is imporant to notice that directories do not have entries for . and
     64  1.2  pooka  * .. as other file systems do.  These can be generated when requested
     65  1.2  pooka  * based on information available by other means, such as the pointer to
     66  1.2  pooka  * the node itself in the former case or the pointer to the parent directory
     67  1.2  pooka  * in the latter case.  This is done to simplify tmpfs's code and, more
     68  1.2  pooka  * importantly, to remove redundancy. */
     69  1.2  pooka TAILQ_HEAD(tmpfs_dir, tmpfs_dirent);
     70  1.2  pooka 
     71  1.2  pooka /*
     72  1.2  pooka  * Internal representation of a tmpfs file system node.
     73  1.2  pooka  *
     74  1.2  pooka  * This structure is splitted in two parts: one holds attributes common
     75  1.2  pooka  * to all file types and the other holds data that is only applicable to
     76  1.2  pooka  * a particular type.  The code must be careful to only access those
     77  1.2  pooka  * attributes that are actually allowed by the node's type.
     78  1.2  pooka  */
     79  1.2  pooka struct tmpfs_node {
     80  1.2  pooka 	/* Doubly-linked list entry which links all existing nodes for a
     81  1.2  pooka 	 * single file system.  This is provided to ease the removal of
     82  1.2  pooka 	 * all nodes during the unmount operation. */
     83  1.2  pooka 	LIST_ENTRY(tmpfs_node)	tn_entries;
     84  1.2  pooka 
     85  1.2  pooka 	/* The node's type.  Any of 'VBLK', 'VCHR', 'VDIR', 'VFIFO',
     86  1.2  pooka 	 * 'VLNK', 'VREG' and 'VSOCK' is allowed.  The usage of vnode
     87  1.2  pooka 	 * types instead of a custom enumeration is to make things simpler
     88  1.2  pooka 	 * and faster, as we do not need to convert between two types. */
     89  1.2  pooka 	enum vtype		tn_type;
     90  1.2  pooka 
     91  1.2  pooka 	/* Node identifier. */
     92  1.2  pooka 	ino_t			tn_id;
     93  1.2  pooka 
     94  1.2  pooka 	/* Node's internal status.  This is used by several file system
     95  1.2  pooka 	 * operations to do modifications to the node in a delayed
     96  1.2  pooka 	 * fashion. */
     97  1.2  pooka 	int			tn_status;
     98  1.2  pooka #define	TMPFS_NODE_ACCESSED	(1 << 1)
     99  1.2  pooka #define	TMPFS_NODE_MODIFIED	(1 << 2)
    100  1.2  pooka #define	TMPFS_NODE_CHANGED	(1 << 3)
    101  1.2  pooka 
    102  1.2  pooka 	/* The node size.  It does not necessarily match the real amount
    103  1.2  pooka 	 * of memory consumed by it. */
    104  1.2  pooka 	off_t			tn_size;
    105  1.2  pooka 
    106  1.2  pooka 	/* Generic node attributes. */
    107  1.2  pooka 	uid_t			tn_uid;
    108  1.2  pooka 	gid_t			tn_gid;
    109  1.2  pooka 	mode_t			tn_mode;
    110  1.2  pooka 	int			tn_flags;
    111  1.2  pooka 	nlink_t			tn_links;
    112  1.2  pooka 	struct timespec		tn_atime;
    113  1.2  pooka 	struct timespec		tn_mtime;
    114  1.2  pooka 	struct timespec		tn_ctime;
    115  1.2  pooka 	struct timespec		tn_birthtime;
    116  1.2  pooka 	unsigned long		tn_gen;
    117  1.2  pooka 
    118  1.2  pooka 	/* Head of byte-level lock list (used by tmpfs_advlock). */
    119  1.2  pooka 	struct lockf *		tn_lockf;
    120  1.2  pooka 
    121  1.2  pooka 	/* As there is a single vnode for each active file within the
    122  1.2  pooka 	 * system, care has to be taken to avoid allocating more than one
    123  1.2  pooka 	 * vnode per file.  In order to do this, a bidirectional association
    124  1.2  pooka 	 * is kept between vnodes and nodes.
    125  1.2  pooka 	 *
    126  1.2  pooka 	 * Whenever a vnode is allocated, its v_data field is updated to
    127  1.2  pooka 	 * point to the node it references.  At the same time, the node's
    128  1.2  pooka 	 * tn_vnode field is modified to point to the new vnode representing
    129  1.2  pooka 	 * it.  Further attempts to allocate a vnode for this same node will
    130  1.2  pooka 	 * result in returning a new reference to the value stored in
    131  1.2  pooka 	 * tn_vnode.
    132  1.2  pooka 	 *
    133  1.2  pooka 	 * May be NULL when the node is unused (that is, no vnode has been
    134  1.2  pooka 	 * allocated for it or it has been reclaimed). */
    135  1.2  pooka 	kmutex_t		tn_vlock;
    136  1.2  pooka 	struct vnode *		tn_vnode;
    137  1.2  pooka 
    138  1.2  pooka 	union {
    139  1.2  pooka 		/* Valid when tn_type == VBLK || tn_type == VCHR. */
    140  1.2  pooka 		struct {
    141  1.2  pooka 			dev_t			tn_rdev;
    142  1.2  pooka 		} tn_dev;
    143  1.2  pooka 
    144  1.2  pooka 		/* Valid when tn_type == VDIR. */
    145  1.2  pooka 		struct {
    146  1.2  pooka 			/* Pointer to the parent directory.  The root
    147  1.2  pooka 			 * directory has a pointer to itself in this field;
    148  1.2  pooka 			 * this property identifies the root node. */
    149  1.2  pooka 			struct tmpfs_node *	tn_parent;
    150  1.2  pooka 
    151  1.2  pooka 			/* Head of a tail-queue that links the contents of
    152  1.2  pooka 			 * the directory together.  See above for a
    153  1.2  pooka 			 * description of its contents. */
    154  1.2  pooka 			struct tmpfs_dir	tn_dir;
    155  1.2  pooka 
    156  1.2  pooka 			/* Number and pointer of the first directory entry
    157  1.2  pooka 			 * returned by the readdir operation if it were
    158  1.2  pooka 			 * called again to continue reading data from the
    159  1.2  pooka 			 * same directory as before.  This is used to speed
    160  1.2  pooka 			 * up reads of long directories, assuming that no
    161  1.2  pooka 			 * more than one read is in progress at a given time.
    162  1.2  pooka 			 * Otherwise, these values are discarded and a linear
    163  1.2  pooka 			 * scan is performed from the beginning up to the
    164  1.2  pooka 			 * point where readdir starts returning values. */
    165  1.2  pooka 			off_t			tn_readdir_lastn;
    166  1.2  pooka 			struct tmpfs_dirent *	tn_readdir_lastp;
    167  1.2  pooka 		} tn_dir;
    168  1.2  pooka 
    169  1.2  pooka 		/* Valid when tn_type == VLNK. */
    170  1.2  pooka 		struct tn_lnk {
    171  1.2  pooka 			/* The link's target, allocated from a string pool. */
    172  1.2  pooka 			char *			tn_link;
    173  1.2  pooka 		} tn_lnk;
    174  1.2  pooka 
    175  1.2  pooka 		/* Valid when tn_type == VREG. */
    176  1.2  pooka 		struct tn_reg {
    177  1.2  pooka 			/* The contents of regular files stored in a tmpfs
    178  1.2  pooka 			 * file system are represented by a single anonymous
    179  1.2  pooka 			 * memory object (aobj, for short).  The aobj provides
    180  1.2  pooka 			 * direct access to any position within the file,
    181  1.2  pooka 			 * because its contents are always mapped in a
    182  1.2  pooka 			 * contiguous region of virtual memory.  It is a task
    183  1.2  pooka 			 * of the memory management subsystem (see uvm(9)) to
    184  1.2  pooka 			 * issue the required page ins or page outs whenever
    185  1.2  pooka 			 * a position within the file is accessed. */
    186  1.2  pooka 			struct uvm_object *	tn_aobj;
    187  1.2  pooka 			size_t			tn_aobj_pages;
    188  1.2  pooka 		} tn_reg;
    189  1.2  pooka 	} tn_spec;
    190  1.2  pooka };
    191  1.2  pooka 
    192  1.2  pooka static __inline
    193  1.2  pooka struct tmpfs_node *
    194  1.2  pooka VP_TO_TMPFS_NODE(struct vnode *vp)
    195  1.2  pooka {
    196  1.2  pooka 	struct tmpfs_node *node;
    197  1.2  pooka 
    198  1.2  pooka #ifdef KASSERT
    199  1.2  pooka 	KASSERT((vp) != NULL && (vp)->v_data != NULL);
    200  1.2  pooka #endif
    201  1.2  pooka 	node = (struct tmpfs_node *)vp->v_data;
    202  1.2  pooka 	return node;
    203  1.2  pooka }
    204  1.1  pooka 
    205  1.1  pooka /*
    206  1.1  pooka  * This structure is used to communicate mount parameters between userland
    207  1.1  pooka  * and kernel space.
    208  1.1  pooka  */
    209  1.1  pooka #define TMPFS_ARGS_VERSION	1
    210  1.1  pooka struct tmpfs_args {
    211  1.1  pooka 	int			ta_version;
    212  1.1  pooka 
    213  1.1  pooka 	/* Size counters. */
    214  1.1  pooka 	ino_t			ta_nodes_max;
    215  1.1  pooka 	off_t			ta_size_max;
    216  1.1  pooka 
    217  1.1  pooka 	/* Root node attributes. */
    218  1.1  pooka 	uid_t			ta_root_uid;
    219  1.1  pooka 	gid_t			ta_root_gid;
    220  1.1  pooka 	mode_t			ta_root_mode;
    221  1.1  pooka };
    222  1.1  pooka 
    223  1.2  pooka #endif /* _FS_TMPFS_TMPFS_ARGS_H_ */
    224