1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _SYS_FS_TMPNODE_H
28*0Sstevel@tonic-gate #define	_SYS_FS_TMPNODE_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/t_lock.h>
33*0Sstevel@tonic-gate #include <vm/seg.h>
34*0Sstevel@tonic-gate #include <vm/seg_vn.h>
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #ifdef	__cplusplus
37*0Sstevel@tonic-gate extern "C" {
38*0Sstevel@tonic-gate #endif
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate /*
41*0Sstevel@tonic-gate  * tmpnode is the file system dependent node for tmpfs.
42*0Sstevel@tonic-gate  *
43*0Sstevel@tonic-gate  *	tn_rwlock protects access of the directory list at tn_dir
44*0Sstevel@tonic-gate  *	as well as syncronizing read and writes to the tmpnode
45*0Sstevel@tonic-gate  *
46*0Sstevel@tonic-gate  *	tn_contents protects growing, shrinking, reading and writing
47*0Sstevel@tonic-gate  *	the file along with tn_rwlock (see below).
48*0Sstevel@tonic-gate  *
49*0Sstevel@tonic-gate  *	tn_tlock protects updates to tn_mode and tn_nlink
50*0Sstevel@tonic-gate  *
51*0Sstevel@tonic-gate  *	tm_contents in the tmount filesystem data structure protects
52*0Sstevel@tonic-gate  *	tn_forw and tn_back which are used to maintain a linked
53*0Sstevel@tonic-gate  *	list of all tmpfs files associated with that file system
54*0Sstevel@tonic-gate  *
55*0Sstevel@tonic-gate  *	The anon array represents the secondary store for tmpfs.
56*0Sstevel@tonic-gate  * 	To grow or shrink the file or fill in holes requires
57*0Sstevel@tonic-gate  *	manipulation of the anon array. These operations are protected
58*0Sstevel@tonic-gate  *	by a combination of tn_rwlock and tn_contents. Growing or shrinking
59*0Sstevel@tonic-gate  * 	the array requires the write lock on tn_rwlock and tn_contents.
60*0Sstevel@tonic-gate  *	Filling in a slot in the array requires the write lock on tn_contents.
61*0Sstevel@tonic-gate  *	Reading the array requires the read lock on tn_contents.
62*0Sstevel@tonic-gate  *
63*0Sstevel@tonic-gate  *	The ordering of the locking is:
64*0Sstevel@tonic-gate  *	tn_rwlock -> tn_contents -> page locks on pages in file
65*0Sstevel@tonic-gate  *
66*0Sstevel@tonic-gate  *	tn_tlock doesn't require any tmpnode locks
67*0Sstevel@tonic-gate  */
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate struct tmpnode {
70*0Sstevel@tonic-gate 	struct tmpnode	*tn_back;		/* linked list of tmpnodes */
71*0Sstevel@tonic-gate 	struct tmpnode	*tn_forw;		/* linked list of tmpnodes */
72*0Sstevel@tonic-gate 	union {
73*0Sstevel@tonic-gate 		struct {
74*0Sstevel@tonic-gate 			struct tdirent	*un_dirlist; /* dirent list */
75*0Sstevel@tonic-gate 			uint_t	un_dirents;	/* number of dirents */
76*0Sstevel@tonic-gate 		} un_dirstruct;
77*0Sstevel@tonic-gate 		char 		*un_symlink;	/* pointer to symlink */
78*0Sstevel@tonic-gate 		struct {
79*0Sstevel@tonic-gate 			struct anon_hdr	*un_anon; /* anon backing for file */
80*0Sstevel@tonic-gate 			pgcnt_t	un_size;	/* size repres. by array */
81*0Sstevel@tonic-gate 		} un_anonstruct;
82*0Sstevel@tonic-gate 	} un_tmpnode;
83*0Sstevel@tonic-gate 	struct vnode 	*tn_vnode;		/* vnode for this tmpnode */
84*0Sstevel@tonic-gate 	int 		tn_gen;			/* pseudo gen number for tfid */
85*0Sstevel@tonic-gate 	struct vattr	tn_attr;		/* attributes */
86*0Sstevel@tonic-gate 	krwlock_t	tn_contents;		/* vm side -serialize mods */
87*0Sstevel@tonic-gate 	krwlock_t	tn_rwlock;		/* rw,trunc size - serialize */
88*0Sstevel@tonic-gate 						/* mods and directory updates */
89*0Sstevel@tonic-gate 	kmutex_t	tn_tlock;		/* time, flag, and nlink lock */
90*0Sstevel@tonic-gate 	struct tmpnode *tn_xattrdp;		/* ext. attribute directory */
91*0Sstevel@tonic-gate 	uint_t		tn_flags;		/* tmpnode specific flags */
92*0Sstevel@tonic-gate };
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate #define	tn_dir		un_tmpnode.un_dirstruct.un_dirlist
95*0Sstevel@tonic-gate #define	tn_dirents	un_tmpnode.un_dirstruct.un_dirents
96*0Sstevel@tonic-gate #define	tn_symlink	un_tmpnode.un_symlink
97*0Sstevel@tonic-gate #define	tn_anon		un_tmpnode.un_anonstruct.un_anon
98*0Sstevel@tonic-gate #define	tn_asize	un_tmpnode.un_anonstruct.un_size
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate /*
101*0Sstevel@tonic-gate  * tmnode flag values.
102*0Sstevel@tonic-gate  */
103*0Sstevel@tonic-gate #define	ISXATTR		0x1
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate /*
106*0Sstevel@tonic-gate  * Attributes
107*0Sstevel@tonic-gate  */
108*0Sstevel@tonic-gate #define	tn_mask		tn_attr.va_mask
109*0Sstevel@tonic-gate #define	tn_type		tn_attr.va_type
110*0Sstevel@tonic-gate #define	tn_mode		tn_attr.va_mode
111*0Sstevel@tonic-gate #define	tn_uid		tn_attr.va_uid
112*0Sstevel@tonic-gate #define	tn_gid		tn_attr.va_gid
113*0Sstevel@tonic-gate #define	tn_fsid		tn_attr.va_fsid
114*0Sstevel@tonic-gate #define	tn_nodeid	tn_attr.va_nodeid
115*0Sstevel@tonic-gate #define	tn_nlink	tn_attr.va_nlink
116*0Sstevel@tonic-gate #define	tn_size		tn_attr.va_size
117*0Sstevel@tonic-gate #define	tn_atime	tn_attr.va_atime
118*0Sstevel@tonic-gate #define	tn_mtime	tn_attr.va_mtime
119*0Sstevel@tonic-gate #define	tn_ctime	tn_attr.va_ctime
120*0Sstevel@tonic-gate #define	tn_rdev		tn_attr.va_rdev
121*0Sstevel@tonic-gate #define	tn_blksize	tn_attr.va_blksize
122*0Sstevel@tonic-gate #define	tn_nblocks	tn_attr.va_nblocks
123*0Sstevel@tonic-gate #define	tn_seq		tn_attr.va_seq
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate /*
126*0Sstevel@tonic-gate  * tmpfs directories are made up of a linked list of tdirent structures
127*0Sstevel@tonic-gate  * hanging off directory tmpnodes.  File names are not fixed length,
128*0Sstevel@tonic-gate  * but are null terminated.
129*0Sstevel@tonic-gate  */
130*0Sstevel@tonic-gate struct tdirent {
131*0Sstevel@tonic-gate 	struct tmpnode	*td_tmpnode;		/* tnode for this file */
132*0Sstevel@tonic-gate 	struct tdirent	*td_next;		/* next directory entry */
133*0Sstevel@tonic-gate 	struct tdirent	*td_prev;		/* prev directory entry */
134*0Sstevel@tonic-gate 	uint_t		td_offset;		/* "offset" of dir entry */
135*0Sstevel@tonic-gate 	uint_t		td_hash;		/* a hash of td_name */
136*0Sstevel@tonic-gate 	struct tdirent	*td_link;		/* linked via the hash table */
137*0Sstevel@tonic-gate 	struct tmpnode	*td_parent;		/* parent, dir we are in */
138*0Sstevel@tonic-gate 	char		*td_name;		/* must be null terminated */
139*0Sstevel@tonic-gate 						/* max length is MAXNAMELEN */
140*0Sstevel@tonic-gate };
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate /*
143*0Sstevel@tonic-gate  * tfid overlays the fid structure (for VFS_VGET)
144*0Sstevel@tonic-gate  */
145*0Sstevel@tonic-gate struct tfid {
146*0Sstevel@tonic-gate 	uint16_t tfid_len;
147*0Sstevel@tonic-gate 	ino32_t	tfid_ino;
148*0Sstevel@tonic-gate 	int32_t	tfid_gen;
149*0Sstevel@tonic-gate };
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate #define	ESAME	(-1)		/* trying to rename linked files (special) */
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate extern struct vnodeops *tmp_vnodeops;
154*0Sstevel@tonic-gate extern const struct fs_operation_def tmp_vnodeops_template[];
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate #ifdef	__cplusplus
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate #endif
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate #endif	/* _SYS_FS_TMPNODE_H */
161