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