xref: /freebsd/sys/fs/tmpfs/tmpfs.h (revision c07d6445eb89d9dd3950361b065b7bd110e3a043)
1 /*	$NetBSD: tmpfs.h,v 1.26 2007/02/22 06:37:00 thorpej Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
5  *
6  * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Julio M. Merino Vidal, developed as part of Google's Summer of Code
11  * 2005 program.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $FreeBSD$
35  */
36 
37 #ifndef _FS_TMPFS_TMPFS_H_
38 #define _FS_TMPFS_TMPFS_H_
39 
40 #include <sys/cdefs.h>
41 #include <sys/queue.h>
42 #include <sys/tree.h>
43 
44 #ifdef	_SYS_MALLOC_H_
45 MALLOC_DECLARE(M_TMPFSNAME);
46 #endif
47 
48 #define	OBJ_TMPFS	OBJ_PAGERPRIV1	/* has tmpfs vnode allocated */
49 #define	OBJ_TMPFS_VREF	OBJ_PAGERPRIV2	/* vnode is referenced */
50 
51 /*
52  * Internal representation of a tmpfs directory entry.
53  */
54 
55 LIST_HEAD(tmpfs_dir_duphead, tmpfs_dirent);
56 
57 struct tmpfs_dirent {
58 	/*
59 	 * Depending on td_cookie flag entry can be of 3 types:
60 	 * - regular -- no hash collisions, stored in RB-Tree
61 	 * - duphead -- synthetic linked list head for dup entries
62 	 * - dup -- stored in linked list instead of RB-Tree
63 	 */
64 	union {
65 		/* regular and duphead entry types */
66 		RB_ENTRY(tmpfs_dirent)		td_entries;
67 
68 		/* dup entry type */
69 		struct {
70 			LIST_ENTRY(tmpfs_dirent) entries;
71 			LIST_ENTRY(tmpfs_dirent) index_entries;
72 		} td_dup;
73 	} uh;
74 
75 	uint32_t			td_cookie;
76 	uint32_t			td_hash;
77 	u_int				td_namelen;
78 
79 	/*
80 	 * Pointer to the node this entry refers to.  In case this field
81 	 * is NULL, the node is a whiteout.
82 	 */
83 	struct tmpfs_node *		td_node;
84 
85 	union {
86 		/*
87 		 * The name of the entry, allocated from a string pool.  This
88 		 * string is not required to be zero-terminated.
89 		 */
90 		char *			td_name;	/* regular, dup */
91 		struct tmpfs_dir_duphead td_duphead;	/* duphead */
92 	} ud;
93 };
94 
95 /*
96  * A directory in tmpfs holds a collection of directory entries, which
97  * in turn point to other files (which can be directories themselves).
98  *
99  * In tmpfs, this collection is managed by a RB-Tree, whose head is
100  * defined by the struct tmpfs_dir type.
101  *
102  * It is important to notice that directories do not have entries for . and
103  * .. as other file systems do.  These can be generated when requested
104  * based on information available by other means, such as the pointer to
105  * the node itself in the former case or the pointer to the parent directory
106  * in the latter case.  This is done to simplify tmpfs's code and, more
107  * importantly, to remove redundancy.
108  */
109 RB_HEAD(tmpfs_dir, tmpfs_dirent);
110 
111 /*
112  * Each entry in a directory has a cookie that identifies it.  Cookies
113  * supersede offsets within directories because, given how tmpfs stores
114  * directories in memory, there is no such thing as an offset.
115  *
116  * The '.', '..' and the end of directory markers have fixed cookies which
117  * cannot collide with the cookies generated by other entries.  The cookies
118  * for the other entries are generated based on the file name hash value or
119  * unique number in case of name hash collision.
120  *
121  * To preserve compatibility cookies are limited to 31 bits.
122  */
123 
124 #define	TMPFS_DIRCOOKIE_DOT		0
125 #define	TMPFS_DIRCOOKIE_DOTDOT		1
126 #define	TMPFS_DIRCOOKIE_EOF		2
127 #define	TMPFS_DIRCOOKIE_MASK		((off_t)0x3fffffffU)
128 #define	TMPFS_DIRCOOKIE_MIN		((off_t)0x00000004U)
129 #define	TMPFS_DIRCOOKIE_DUP		((off_t)0x40000000U)
130 #define	TMPFS_DIRCOOKIE_DUPHEAD		((off_t)0x80000000U)
131 #define	TMPFS_DIRCOOKIE_DUP_MIN		TMPFS_DIRCOOKIE_DUP
132 #define	TMPFS_DIRCOOKIE_DUP_MAX		\
133 	(TMPFS_DIRCOOKIE_DUP | TMPFS_DIRCOOKIE_MASK)
134 
135 /*
136  * Internal representation of a tmpfs file system node.
137  *
138  * This structure is splitted in two parts: one holds attributes common
139  * to all file types and the other holds data that is only applicable to
140  * a particular type.  The code must be careful to only access those
141  * attributes that are actually allowed by the node's type.
142  *
143  * Below is the key of locks used to protected the fields in the following
144  * structures.
145  * (v)  vnode lock in exclusive mode
146  * (vi) vnode lock in exclusive mode, or vnode lock in shared vnode and
147  *	tn_interlock
148  * (i)  tn_interlock
149  * (m)  tmpfs_mount tm_allnode_lock
150  * (c)  stable after creation
151  * (v)  tn_reg.tn_aobj vm_object lock
152  */
153 struct tmpfs_node {
154 	/*
155 	 * Doubly-linked list entry which links all existing nodes for
156 	 * a single file system.  This is provided to ease the removal
157 	 * of all nodes during the unmount operation, and to support
158 	 * the implementation of VOP_VNTOCNP().  tn_attached is false
159 	 * when the node is removed from list and unlocked.
160 	 */
161 	LIST_ENTRY(tmpfs_node)	tn_entries;	/* (m) */
162 
163 	/* Node identifier. */
164 	ino_t			tn_id;		/* (c) */
165 
166 	/*
167 	 * The node's type.  Any of 'VBLK', 'VCHR', 'VDIR', 'VFIFO',
168 	 * 'VLNK', 'VREG' and 'VSOCK' is allowed.  The usage of vnode
169 	 * types instead of a custom enumeration is to make things simpler
170 	 * and faster, as we do not need to convert between two types.
171 	 */
172 	enum vtype		tn_type;	/* (c) */
173 
174 	/*
175 	 * See the top comment. Reordered here to fill LP64 hole.
176 	 */
177 	bool			tn_attached;	/* (m) */
178 
179 	/*
180 	 * Node's internal status.  This is used by several file system
181 	 * operations to do modifications to the node in a delayed
182 	 * fashion.
183 	 *
184 	 * tn_accessed has a dedicated byte to allow update by store without
185 	 * using atomics.  This provides a micro-optimization to e.g.
186 	 * tmpfs_read_pgcache().
187 	 */
188 	uint8_t			tn_status;	/* (vi) */
189 	uint8_t			tn_accessed;	/* unlocked */
190 
191 	/*
192 	 * The node size.  It does not necessarily match the real amount
193 	 * of memory consumed by it.
194 	 */
195 	off_t			tn_size;	/* (v) */
196 
197 	/* Generic node attributes. */
198 	uid_t			tn_uid;		/* (v) */
199 	gid_t			tn_gid;		/* (v) */
200 	mode_t			tn_mode;	/* (v) */
201 	int			tn_links;	/* (v) */
202 	u_long			tn_flags;	/* (v) */
203 	struct timespec		tn_atime;	/* (vi) */
204 	struct timespec		tn_mtime;	/* (vi) */
205 	struct timespec		tn_ctime;	/* (vi) */
206 	struct timespec		tn_birthtime;	/* (v) */
207 	unsigned long		tn_gen;		/* (c) */
208 
209 	/*
210 	 * As there is a single vnode for each active file within the
211 	 * system, care has to be taken to avoid allocating more than one
212 	 * vnode per file.  In order to do this, a bidirectional association
213 	 * is kept between vnodes and nodes.
214 	 *
215 	 * Whenever a vnode is allocated, its v_data field is updated to
216 	 * point to the node it references.  At the same time, the node's
217 	 * tn_vnode field is modified to point to the new vnode representing
218 	 * it.  Further attempts to allocate a vnode for this same node will
219 	 * result in returning a new reference to the value stored in
220 	 * tn_vnode.
221 	 *
222 	 * May be NULL when the node is unused (that is, no vnode has been
223 	 * allocated for it or it has been reclaimed).
224 	 */
225 	struct vnode *		tn_vnode;	/* (i) */
226 
227 	/*
228 	 * Interlock to protect tn_vpstate, and tn_status under shared
229 	 * vnode lock.
230 	 */
231 	struct mtx	tn_interlock;
232 
233 	/*
234 	 * Identify if current node has vnode assiocate with
235 	 * or allocating vnode.
236 	 */
237 	int		tn_vpstate;		/* (i) */
238 
239 	/* Transient refcounter on this node. */
240 	u_int		tn_refcount;		/* 0<->1 (m) + (i) */
241 
242 	/* misc data field for different tn_type node */
243 	union {
244 		/* Valid when tn_type == VBLK || tn_type == VCHR. */
245 		dev_t			tn_rdev;	/* (c) */
246 
247 		/* Valid when tn_type == VDIR. */
248 		struct tn_dir {
249 			/*
250 			 * Pointer to the parent directory.  The root
251 			 * directory has a pointer to itself in this field;
252 			 * this property identifies the root node.
253 			 */
254 			struct tmpfs_node *	tn_parent;
255 
256 			/*
257 			 * Head of a tree that links the contents of
258 			 * the directory together.
259 			 */
260 			struct tmpfs_dir	tn_dirhead;
261 
262 			/*
263 			 * Head of a list the contains fake directory entries
264 			 * heads, i.e. entries with TMPFS_DIRCOOKIE_DUPHEAD
265 			 * flag.
266 			 */
267 			struct tmpfs_dir_duphead tn_dupindex;
268 
269 			/*
270 			 * Number and pointer of the first directory entry
271 			 * returned by the readdir operation if it were
272 			 * called again to continue reading data from the
273 			 * same directory as before.  This is used to speed
274 			 * up reads of long directories, assuming that no
275 			 * more than one read is in progress at a given time.
276 			 * Otherwise, these values are discarded.
277 			 */
278 			off_t			tn_readdir_lastn;
279 			struct tmpfs_dirent *	tn_readdir_lastp;
280 		} tn_dir;
281 
282 		/* Valid when tn_type == VLNK. */
283 		/* The link's target, allocated from a string pool. */
284 		struct tn_link {
285 			char *			tn_link_target;	/* (c) */
286 			char 			tn_link_smr;	/* (c) */
287 		} tn_link;
288 
289 		/* Valid when tn_type == VREG. */
290 		struct tn_reg {
291 			/*
292 			 * The contents of regular files stored in a
293 			 * tmpfs file system are represented by a
294 			 * single anonymous memory object (aobj, for
295 			 * short).  The aobj provides direct access to
296 			 * any position within the file.  It is a task
297 			 * of the memory management subsystem to issue
298 			 * the required page ins or page outs whenever
299 			 * a position within the file is accessed.
300 			 */
301 			vm_object_t		tn_aobj;	/* (c) */
302 			struct tmpfs_mount	*tn_tmp;	/* (c) */
303 			vm_pindex_t		tn_pages;	/* (v) */
304 		} tn_reg;
305 	} tn_spec;	/* (v) */
306 };
307 LIST_HEAD(tmpfs_node_list, tmpfs_node);
308 
309 #define tn_rdev tn_spec.tn_rdev
310 #define tn_dir tn_spec.tn_dir
311 #define tn_link_target tn_spec.tn_link.tn_link_target
312 #define tn_link_smr tn_spec.tn_link.tn_link_smr
313 #define tn_reg tn_spec.tn_reg
314 #define tn_fifo tn_spec.tn_fifo
315 
316 #define	TMPFS_LINK_MAX INT_MAX
317 
318 #define TMPFS_NODE_LOCK(node) mtx_lock(&(node)->tn_interlock)
319 #define TMPFS_NODE_UNLOCK(node) mtx_unlock(&(node)->tn_interlock)
320 #define TMPFS_NODE_MTX(node) (&(node)->tn_interlock)
321 #define	TMPFS_NODE_ASSERT_LOCKED(node) mtx_assert(TMPFS_NODE_MTX(node), \
322     MA_OWNED)
323 
324 #ifdef INVARIANTS
325 #define TMPFS_ASSERT_LOCKED(node) do {					\
326 		MPASS((node) != NULL);					\
327 		MPASS((node)->tn_vnode != NULL);			\
328 		ASSERT_VOP_LOCKED((node)->tn_vnode, "tmpfs assert");	\
329 	} while (0)
330 #else
331 #define TMPFS_ASSERT_LOCKED(node) (void)0
332 #endif
333 
334 /* tn_vpstate */
335 #define TMPFS_VNODE_ALLOCATING	1
336 #define TMPFS_VNODE_WANT	2
337 #define TMPFS_VNODE_DOOMED	4
338 #define	TMPFS_VNODE_WRECLAIM	8
339 
340 /* tn_status */
341 #define	TMPFS_NODE_MODIFIED	0x01
342 #define	TMPFS_NODE_CHANGED	0x02
343 
344 /*
345  * Internal representation of a tmpfs mount point.
346  */
347 struct tmpfs_mount {
348 	/*
349 	 * Original value of the "size" parameter, for reference purposes,
350 	 * mostly.
351 	 */
352 	off_t			tm_size_max;
353 	/*
354 	 * Maximum number of memory pages available for use by the file
355 	 * system, set during mount time.  This variable must never be
356 	 * used directly as it may be bigger than the current amount of
357 	 * free memory; in the extreme case, it will hold the ULONG_MAX
358 	 * value.
359 	 */
360 	u_long			tm_pages_max;
361 
362 	/* Number of pages in use by the file system. */
363 	u_long			tm_pages_used;
364 
365 	/*
366 	 * Pointer to the node representing the root directory of this
367 	 * file system.
368 	 */
369 	struct tmpfs_node *	tm_root;
370 
371 	/*
372 	 * Maximum number of possible nodes for this file system; set
373 	 * during mount time.  We need a hard limit on the maximum number
374 	 * of nodes to avoid allocating too much of them; their objects
375 	 * cannot be released until the file system is unmounted.
376 	 * Otherwise, we could easily run out of memory by creating lots
377 	 * of empty files and then simply removing them.
378 	 */
379 	ino_t			tm_nodes_max;
380 
381 	/* unrhdr used to allocate inode numbers */
382 	struct unrhdr64		tm_ino_unr;
383 
384 	/* Number of nodes currently that are in use. */
385 	ino_t			tm_nodes_inuse;
386 
387 	/* Refcounter on this struct tmpfs_mount. */
388 	uint64_t		tm_refcount;
389 
390 	/* maximum representable file size */
391 	u_int64_t		tm_maxfilesize;
392 
393 	/*
394 	 * The used list contains all nodes that are currently used by
395 	 * the file system; i.e., they refer to existing files.
396 	 */
397 	struct tmpfs_node_list	tm_nodes_used;
398 
399 	/* All node lock to protect the node list and tmp_pages_used. */
400 	struct mtx		tm_allnode_lock;
401 
402 	/* Read-only status. */
403 	bool			tm_ronly;
404 	/* Do not use namecache. */
405 	bool			tm_nonc;
406 	/* Do not update mtime on writes through mmaped areas. */
407 	bool			tm_nomtime;
408 };
409 #define	TMPFS_LOCK(tm) mtx_lock(&(tm)->tm_allnode_lock)
410 #define	TMPFS_UNLOCK(tm) mtx_unlock(&(tm)->tm_allnode_lock)
411 #define	TMPFS_MP_ASSERT_LOCKED(tm) mtx_assert(&(tm)->tm_allnode_lock, MA_OWNED)
412 
413 /*
414  * This structure maps a file identifier to a tmpfs node.  Used by the
415  * NFS code.
416  */
417 struct tmpfs_fid_data {
418 	ino_t			tfd_id;
419 	unsigned long		tfd_gen;
420 };
421 _Static_assert(sizeof(struct tmpfs_fid_data) <= MAXFIDSZ,
422     "(struct tmpfs_fid_data) is larger than (struct fid).fid_data");
423 
424 struct tmpfs_dir_cursor {
425 	struct tmpfs_dirent	*tdc_current;
426 	struct tmpfs_dirent	*tdc_tree;
427 };
428 
429 #ifdef _KERNEL
430 /*
431  * Prototypes for tmpfs_subr.c.
432  */
433 
434 void	tmpfs_ref_node(struct tmpfs_node *node);
435 int	tmpfs_alloc_node(struct mount *mp, struct tmpfs_mount *, enum vtype,
436 	    uid_t uid, gid_t gid, mode_t mode, struct tmpfs_node *,
437 	    const char *, dev_t, struct tmpfs_node **);
438 int	tmpfs_fo_close(struct file *fp, struct thread *td);
439 void	tmpfs_free_node(struct tmpfs_mount *, struct tmpfs_node *);
440 bool	tmpfs_free_node_locked(struct tmpfs_mount *, struct tmpfs_node *, bool);
441 void	tmpfs_free_tmp(struct tmpfs_mount *);
442 int	tmpfs_alloc_dirent(struct tmpfs_mount *, struct tmpfs_node *,
443 	    const char *, u_int, struct tmpfs_dirent **);
444 void	tmpfs_free_dirent(struct tmpfs_mount *, struct tmpfs_dirent *);
445 void	tmpfs_dirent_init(struct tmpfs_dirent *, const char *, u_int);
446 void	tmpfs_destroy_vobject(struct vnode *vp, vm_object_t obj);
447 int	tmpfs_alloc_vp(struct mount *, struct tmpfs_node *, int,
448 	    struct vnode **);
449 void	tmpfs_free_vp(struct vnode *);
450 int	tmpfs_alloc_file(struct vnode *, struct vnode **, struct vattr *,
451 	    struct componentname *, const char *);
452 void	tmpfs_check_mtime(struct vnode *);
453 void	tmpfs_dir_attach(struct vnode *, struct tmpfs_dirent *);
454 void	tmpfs_dir_detach(struct vnode *, struct tmpfs_dirent *);
455 void	tmpfs_dir_destroy(struct tmpfs_mount *, struct tmpfs_node *);
456 struct tmpfs_dirent *	tmpfs_dir_lookup(struct tmpfs_node *node,
457 			    struct tmpfs_node *f,
458 			    struct componentname *cnp);
459 int	tmpfs_dir_getdents(struct tmpfs_mount *, struct tmpfs_node *,
460 	    struct uio *, int, uint64_t *, int *);
461 int	tmpfs_dir_whiteout_add(struct vnode *, struct componentname *);
462 void	tmpfs_dir_whiteout_remove(struct vnode *, struct componentname *);
463 int	tmpfs_reg_resize(struct vnode *, off_t, boolean_t);
464 int	tmpfs_reg_punch_hole(struct vnode *vp, off_t *, off_t *);
465 int	tmpfs_chflags(struct vnode *, u_long, struct ucred *, struct thread *);
466 int	tmpfs_chmod(struct vnode *, mode_t, struct ucred *, struct thread *);
467 int	tmpfs_chown(struct vnode *, uid_t, gid_t, struct ucred *,
468 	    struct thread *);
469 int	tmpfs_chsize(struct vnode *, u_quad_t, struct ucred *, struct thread *);
470 int	tmpfs_chtimes(struct vnode *, struct vattr *, struct ucred *cred,
471 	    struct thread *);
472 void	tmpfs_itimes(struct vnode *, const struct timespec *,
473 	    const struct timespec *);
474 
475 void	tmpfs_set_accessed(struct tmpfs_mount *tm, struct tmpfs_node *node);
476 void	tmpfs_set_status(struct tmpfs_mount *tm, struct tmpfs_node *node,
477 	    int status);
478 int	tmpfs_truncate(struct vnode *, off_t);
479 struct tmpfs_dirent *tmpfs_dir_first(struct tmpfs_node *dnode,
480 	    struct tmpfs_dir_cursor *dc);
481 struct tmpfs_dirent *tmpfs_dir_next(struct tmpfs_node *dnode,
482 	    struct tmpfs_dir_cursor *dc);
483 static __inline void
484 tmpfs_update(struct vnode *vp)
485 {
486 
487 	tmpfs_itimes(vp, NULL, NULL);
488 }
489 
490 /*
491  * Convenience macros to simplify some logical expressions.
492  */
493 #define IMPLIES(a, b) (!(a) || (b))
494 #define IFF(a, b) (IMPLIES(a, b) && IMPLIES(b, a))
495 
496 /*
497  * Checks that the directory entry pointed by 'de' matches the name 'name'
498  * with a length of 'len'.
499  */
500 #define TMPFS_DIRENT_MATCHES(de, name, len) \
501     (de->td_namelen == len && \
502     bcmp((de)->ud.td_name, (name), (de)->td_namelen) == 0)
503 
504 /*
505  * Ensures that the node pointed by 'node' is a directory and that its
506  * contents are consistent with respect to directories.
507  */
508 #define TMPFS_VALIDATE_DIR(node) do { \
509 	MPASS((node)->tn_type == VDIR); \
510 	MPASS((node)->tn_size % sizeof(struct tmpfs_dirent) == 0); \
511 } while (0)
512 
513 /*
514  * Amount of memory pages to reserve for the system (e.g., to not use by
515  * tmpfs).
516  */
517 #if !defined(TMPFS_PAGES_MINRESERVED)
518 #define TMPFS_PAGES_MINRESERVED		(4 * 1024 * 1024 / PAGE_SIZE)
519 #endif
520 
521 size_t tmpfs_mem_avail(void);
522 size_t tmpfs_pages_used(struct tmpfs_mount *tmp);
523 int tmpfs_subr_init(void);
524 void tmpfs_subr_uninit(void);
525 
526 extern int tmpfs_pager_type;
527 
528 /*
529  * Macros/functions to convert from generic data structures to tmpfs
530  * specific ones.
531  */
532 
533 static inline struct vnode *
534 VM_TO_TMPFS_VP(vm_object_t obj)
535 {
536 	struct tmpfs_node *node;
537 
538 	if ((obj->flags & OBJ_TMPFS) == 0)
539 		return (NULL);
540 
541 	/*
542 	 * swp_priv is the back-pointer to the tmpfs node, if any,
543 	 * which uses the vm object as backing store.  The object
544 	 * handle is not used to avoid locking sw_alloc_sx on tmpfs
545 	 * node instantiation/destroy.
546 	 */
547 	node = obj->un_pager.swp.swp_priv;
548 	return (node->tn_vnode);
549 }
550 
551 static inline struct tmpfs_mount *
552 VM_TO_TMPFS_MP(vm_object_t obj)
553 {
554 	struct tmpfs_node *node;
555 
556 	if ((obj->flags & OBJ_TMPFS) == 0)
557 		return (NULL);
558 
559 	node = obj->un_pager.swp.swp_priv;
560 	MPASS(node->tn_type == VREG);
561 	return (node->tn_reg.tn_tmp);
562 }
563 
564 static inline struct tmpfs_mount *
565 VFS_TO_TMPFS(struct mount *mp)
566 {
567 	struct tmpfs_mount *tmp;
568 
569 	MPASS(mp != NULL && mp->mnt_data != NULL);
570 	tmp = (struct tmpfs_mount *)mp->mnt_data;
571 	return (tmp);
572 }
573 
574 static inline struct tmpfs_node *
575 VP_TO_TMPFS_NODE(struct vnode *vp)
576 {
577 	struct tmpfs_node *node;
578 
579 	MPASS(vp != NULL && vp->v_data != NULL);
580 	node = (struct tmpfs_node *)vp->v_data;
581 	return (node);
582 }
583 
584 #define	VP_TO_TMPFS_NODE_SMR(vp)	\
585 	((struct tmpfs_node *)vn_load_v_data_smr(vp))
586 
587 static inline struct tmpfs_node *
588 VP_TO_TMPFS_DIR(struct vnode *vp)
589 {
590 	struct tmpfs_node *node;
591 
592 	node = VP_TO_TMPFS_NODE(vp);
593 	TMPFS_VALIDATE_DIR(node);
594 	return (node);
595 }
596 
597 static inline bool
598 tmpfs_use_nc(struct vnode *vp)
599 {
600 
601 	return (!(VFS_TO_TMPFS(vp->v_mount)->tm_nonc));
602 }
603 
604 static inline void
605 tmpfs_update_getattr(struct vnode *vp)
606 {
607 	struct tmpfs_node *node;
608 
609 	node = VP_TO_TMPFS_NODE(vp);
610 	if (__predict_false((node->tn_status & (TMPFS_NODE_MODIFIED |
611 	    TMPFS_NODE_CHANGED)) != 0 || node->tn_accessed))
612 		tmpfs_update(vp);
613 }
614 
615 extern struct fileops tmpfs_fnops;
616 
617 #endif /* _KERNEL */
618 
619 #endif /* _FS_TMPFS_TMPFS_H_ */
620