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