10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*9694SScott.Rotondo@Sun.COM * Common Development and Distribution License (the "License"). 6*9694SScott.Rotondo@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*9694SScott.Rotondo@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_FS_TMPNODE_H 270Sstevel@tonic-gate #define _SYS_FS_TMPNODE_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/t_lock.h> 300Sstevel@tonic-gate #include <vm/seg.h> 310Sstevel@tonic-gate #include <vm/seg_vn.h> 32*9694SScott.Rotondo@Sun.COM #include <sys/vfs_opreg.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate #ifdef __cplusplus 350Sstevel@tonic-gate extern "C" { 360Sstevel@tonic-gate #endif 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* 390Sstevel@tonic-gate * tmpnode is the file system dependent node for tmpfs. 400Sstevel@tonic-gate * 410Sstevel@tonic-gate * tn_rwlock protects access of the directory list at tn_dir 420Sstevel@tonic-gate * as well as syncronizing read and writes to the tmpnode 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * tn_contents protects growing, shrinking, reading and writing 450Sstevel@tonic-gate * the file along with tn_rwlock (see below). 460Sstevel@tonic-gate * 470Sstevel@tonic-gate * tn_tlock protects updates to tn_mode and tn_nlink 480Sstevel@tonic-gate * 490Sstevel@tonic-gate * tm_contents in the tmount filesystem data structure protects 500Sstevel@tonic-gate * tn_forw and tn_back which are used to maintain a linked 510Sstevel@tonic-gate * list of all tmpfs files associated with that file system 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * The anon array represents the secondary store for tmpfs. 540Sstevel@tonic-gate * To grow or shrink the file or fill in holes requires 550Sstevel@tonic-gate * manipulation of the anon array. These operations are protected 560Sstevel@tonic-gate * by a combination of tn_rwlock and tn_contents. Growing or shrinking 570Sstevel@tonic-gate * the array requires the write lock on tn_rwlock and tn_contents. 580Sstevel@tonic-gate * Filling in a slot in the array requires the write lock on tn_contents. 590Sstevel@tonic-gate * Reading the array requires the read lock on tn_contents. 600Sstevel@tonic-gate * 610Sstevel@tonic-gate * The ordering of the locking is: 620Sstevel@tonic-gate * tn_rwlock -> tn_contents -> page locks on pages in file 630Sstevel@tonic-gate * 640Sstevel@tonic-gate * tn_tlock doesn't require any tmpnode locks 650Sstevel@tonic-gate */ 660Sstevel@tonic-gate 670Sstevel@tonic-gate struct tmpnode { 680Sstevel@tonic-gate struct tmpnode *tn_back; /* linked list of tmpnodes */ 690Sstevel@tonic-gate struct tmpnode *tn_forw; /* linked list of tmpnodes */ 700Sstevel@tonic-gate union { 710Sstevel@tonic-gate struct { 720Sstevel@tonic-gate struct tdirent *un_dirlist; /* dirent list */ 730Sstevel@tonic-gate uint_t un_dirents; /* number of dirents */ 740Sstevel@tonic-gate } un_dirstruct; 750Sstevel@tonic-gate char *un_symlink; /* pointer to symlink */ 760Sstevel@tonic-gate struct { 770Sstevel@tonic-gate struct anon_hdr *un_anon; /* anon backing for file */ 780Sstevel@tonic-gate pgcnt_t un_size; /* size repres. by array */ 790Sstevel@tonic-gate } un_anonstruct; 800Sstevel@tonic-gate } un_tmpnode; 810Sstevel@tonic-gate struct vnode *tn_vnode; /* vnode for this tmpnode */ 820Sstevel@tonic-gate int tn_gen; /* pseudo gen number for tfid */ 830Sstevel@tonic-gate struct vattr tn_attr; /* attributes */ 840Sstevel@tonic-gate krwlock_t tn_contents; /* vm side -serialize mods */ 850Sstevel@tonic-gate krwlock_t tn_rwlock; /* rw,trunc size - serialize */ 860Sstevel@tonic-gate /* mods and directory updates */ 870Sstevel@tonic-gate kmutex_t tn_tlock; /* time, flag, and nlink lock */ 880Sstevel@tonic-gate struct tmpnode *tn_xattrdp; /* ext. attribute directory */ 890Sstevel@tonic-gate uint_t tn_flags; /* tmpnode specific flags */ 900Sstevel@tonic-gate }; 910Sstevel@tonic-gate 920Sstevel@tonic-gate #define tn_dir un_tmpnode.un_dirstruct.un_dirlist 930Sstevel@tonic-gate #define tn_dirents un_tmpnode.un_dirstruct.un_dirents 940Sstevel@tonic-gate #define tn_symlink un_tmpnode.un_symlink 950Sstevel@tonic-gate #define tn_anon un_tmpnode.un_anonstruct.un_anon 960Sstevel@tonic-gate #define tn_asize un_tmpnode.un_anonstruct.un_size 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * tmnode flag values. 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate #define ISXATTR 0x1 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* 1040Sstevel@tonic-gate * Attributes 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate #define tn_mask tn_attr.va_mask 1070Sstevel@tonic-gate #define tn_type tn_attr.va_type 1080Sstevel@tonic-gate #define tn_mode tn_attr.va_mode 1090Sstevel@tonic-gate #define tn_uid tn_attr.va_uid 1100Sstevel@tonic-gate #define tn_gid tn_attr.va_gid 1110Sstevel@tonic-gate #define tn_fsid tn_attr.va_fsid 1120Sstevel@tonic-gate #define tn_nodeid tn_attr.va_nodeid 1130Sstevel@tonic-gate #define tn_nlink tn_attr.va_nlink 1140Sstevel@tonic-gate #define tn_size tn_attr.va_size 1150Sstevel@tonic-gate #define tn_atime tn_attr.va_atime 1160Sstevel@tonic-gate #define tn_mtime tn_attr.va_mtime 1170Sstevel@tonic-gate #define tn_ctime tn_attr.va_ctime 1180Sstevel@tonic-gate #define tn_rdev tn_attr.va_rdev 1190Sstevel@tonic-gate #define tn_blksize tn_attr.va_blksize 1200Sstevel@tonic-gate #define tn_nblocks tn_attr.va_nblocks 1210Sstevel@tonic-gate #define tn_seq tn_attr.va_seq 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /* 1240Sstevel@tonic-gate * tmpfs directories are made up of a linked list of tdirent structures 1250Sstevel@tonic-gate * hanging off directory tmpnodes. File names are not fixed length, 1260Sstevel@tonic-gate * but are null terminated. 1270Sstevel@tonic-gate */ 1280Sstevel@tonic-gate struct tdirent { 1290Sstevel@tonic-gate struct tmpnode *td_tmpnode; /* tnode for this file */ 1300Sstevel@tonic-gate struct tdirent *td_next; /* next directory entry */ 1310Sstevel@tonic-gate struct tdirent *td_prev; /* prev directory entry */ 1320Sstevel@tonic-gate uint_t td_offset; /* "offset" of dir entry */ 1330Sstevel@tonic-gate uint_t td_hash; /* a hash of td_name */ 1340Sstevel@tonic-gate struct tdirent *td_link; /* linked via the hash table */ 1350Sstevel@tonic-gate struct tmpnode *td_parent; /* parent, dir we are in */ 1360Sstevel@tonic-gate char *td_name; /* must be null terminated */ 1370Sstevel@tonic-gate /* max length is MAXNAMELEN */ 1380Sstevel@tonic-gate }; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * tfid overlays the fid structure (for VFS_VGET) 1420Sstevel@tonic-gate */ 1430Sstevel@tonic-gate struct tfid { 1440Sstevel@tonic-gate uint16_t tfid_len; 1450Sstevel@tonic-gate ino32_t tfid_ino; 1460Sstevel@tonic-gate int32_t tfid_gen; 1470Sstevel@tonic-gate }; 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate #define ESAME (-1) /* trying to rename linked files (special) */ 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate extern struct vnodeops *tmp_vnodeops; 1520Sstevel@tonic-gate extern const struct fs_operation_def tmp_vnodeops_template[]; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate #ifdef __cplusplus 1550Sstevel@tonic-gate } 1560Sstevel@tonic-gate #endif 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate #endif /* _SYS_FS_TMPNODE_H */ 159