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 1989-1991, 1996-1999, 2001-2003 Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _SYS_FS_TMP_H 28*0Sstevel@tonic-gate #define _SYS_FS_TMP_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #ifdef __cplusplus 33*0Sstevel@tonic-gate extern "C" { 34*0Sstevel@tonic-gate #endif 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate /* 37*0Sstevel@tonic-gate * tmpfs per-mount data structure. 38*0Sstevel@tonic-gate * 39*0Sstevel@tonic-gate * All fields are protected by tm_contents. 40*0Sstevel@tonic-gate * File renames on a particular file system are protected tm_renamelck. 41*0Sstevel@tonic-gate */ 42*0Sstevel@tonic-gate struct tmount { 43*0Sstevel@tonic-gate struct vfs *tm_vfsp; /* filesystem's vfs struct */ 44*0Sstevel@tonic-gate struct tmpnode *tm_rootnode; /* root tmpnode */ 45*0Sstevel@tonic-gate char *tm_mntpath; /* name of tmpfs mount point */ 46*0Sstevel@tonic-gate ulong_t tm_anonmax; /* file system max anon reservation */ 47*0Sstevel@tonic-gate pgcnt_t tm_anonmem; /* pages of reserved anon memory */ 48*0Sstevel@tonic-gate dev_t tm_dev; /* unique dev # of mounted `device' */ 49*0Sstevel@tonic-gate uint_t tm_gen; /* pseudo generation number for files */ 50*0Sstevel@tonic-gate kmutex_t tm_contents; /* lock for tmount structure */ 51*0Sstevel@tonic-gate kmutex_t tm_renamelck; /* rename lock for this mount */ 52*0Sstevel@tonic-gate }; 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate /* 55*0Sstevel@tonic-gate * File system independent to tmpfs conversion macros 56*0Sstevel@tonic-gate */ 57*0Sstevel@tonic-gate #define VFSTOTM(vfsp) ((struct tmount *)(vfsp)->vfs_data) 58*0Sstevel@tonic-gate #define VTOTM(vp) ((struct tmount *)(vp)->v_vfsp->vfs_data) 59*0Sstevel@tonic-gate #define VTOTN(vp) ((struct tmpnode *)(vp)->v_data) 60*0Sstevel@tonic-gate #define TNTOV(tp) ((tp)->tn_vnode) 61*0Sstevel@tonic-gate #define tmpnode_hold(tp) VN_HOLD(TNTOV(tp)) 62*0Sstevel@tonic-gate #define tmpnode_rele(tp) VN_RELE(TNTOV(tp)) 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate /* 65*0Sstevel@tonic-gate * enums 66*0Sstevel@tonic-gate */ 67*0Sstevel@tonic-gate enum de_op { DE_CREATE, DE_MKDIR, DE_LINK, DE_RENAME }; /* direnter ops */ 68*0Sstevel@tonic-gate enum dr_op { DR_REMOVE, DR_RMDIR, DR_RENAME }; /* dirremove ops */ 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate /* 71*0Sstevel@tonic-gate * tmpfs_minfree is the amount (in pages) of anonymous memory that tmpfs 72*0Sstevel@tonic-gate * leaves free for the rest of the system. E.g. in a system with 32MB of 73*0Sstevel@tonic-gate * configured swap space, if 16MB were reserved (leaving 16MB free), 74*0Sstevel@tonic-gate * tmpfs could allocate up to 16MB - tmpfs_minfree. The default value 75*0Sstevel@tonic-gate * for tmpfs_minfree is btopr(TMPMINFREE) but it can cautiously patched 76*0Sstevel@tonic-gate * to a different number of pages. 77*0Sstevel@tonic-gate * NB: If tmpfs allocates too much swap space, other processes will be 78*0Sstevel@tonic-gate * unable to execute. 79*0Sstevel@tonic-gate */ 80*0Sstevel@tonic-gate #define TMPMINFREE 2 * 1024 * 1024 /* 2 Megabytes */ 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate extern size_t tmpfs_minfree; /* Anonymous memory in pages */ 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate /* 85*0Sstevel@tonic-gate * tmpfs can allocate only a certain percentage of kernel memory, 86*0Sstevel@tonic-gate * which is used for tmpnodes, directories, file names, etc. 87*0Sstevel@tonic-gate * This is statically set as TMPMAXFRACKMEM of physical memory. 88*0Sstevel@tonic-gate * The actual number of allocatable bytes can be patched in tmpfs_maxkmem. 89*0Sstevel@tonic-gate */ 90*0Sstevel@tonic-gate #define TMPMAXFRACKMEM 25 /* 1/25 of physical memory */ 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate extern size_t tmp_kmemspace; 93*0Sstevel@tonic-gate extern size_t tmpfs_maxkmem; /* Allocatable kernel memory in bytes */ 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate extern void tmpnode_init(struct tmount *, struct tmpnode *, 96*0Sstevel@tonic-gate struct vattr *, struct cred *); 97*0Sstevel@tonic-gate extern int tmpnode_trunc(struct tmount *, struct tmpnode *, ulong_t); 98*0Sstevel@tonic-gate extern void tmpnode_growmap(struct tmpnode *, ulong_t); 99*0Sstevel@tonic-gate extern int tdirlookup(struct tmpnode *, char *, struct tmpnode **, 100*0Sstevel@tonic-gate struct cred *); 101*0Sstevel@tonic-gate extern int tdirdelete(struct tmpnode *, struct tmpnode *, char *, 102*0Sstevel@tonic-gate enum dr_op, struct cred *); 103*0Sstevel@tonic-gate extern void tdirinit(struct tmpnode *, struct tmpnode *); 104*0Sstevel@tonic-gate extern void tdirtrunc(struct tmpnode *); 105*0Sstevel@tonic-gate extern void *tmp_memalloc(size_t, int); 106*0Sstevel@tonic-gate extern void tmp_memfree(void *, size_t); 107*0Sstevel@tonic-gate extern int tmp_resv(struct tmount *, struct tmpnode *, size_t, int); 108*0Sstevel@tonic-gate extern int tmp_taccess(void *, int, struct cred *); 109*0Sstevel@tonic-gate extern int tmp_sticky_remove_access(struct tmpnode *, struct tmpnode *, 110*0Sstevel@tonic-gate struct cred *); 111*0Sstevel@tonic-gate extern int tmp_convnum(char *, pgcnt_t *); 112*0Sstevel@tonic-gate extern int tdirenter(struct tmount *, struct tmpnode *, char *, 113*0Sstevel@tonic-gate enum de_op, struct tmpnode *, struct tmpnode *, struct vattr *, 114*0Sstevel@tonic-gate struct tmpnode **, struct cred *); 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate #define TMP_MUSTHAVE 0x01 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate #ifdef __cplusplus 119*0Sstevel@tonic-gate } 120*0Sstevel@tonic-gate #endif 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate #endif /* _SYS_FS_TMP_H */ 123