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