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*5331Samw * Common Development and Distribution License (the "License"). 6*5331Samw * 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*5331Samw * Copyright 2007 Sun Microsystems, Inc. 230Sstevel@tonic-gate * All rights reserved. Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_FS_TMP_H 270Sstevel@tonic-gate #define _SYS_FS_TMP_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate /* 360Sstevel@tonic-gate * tmpfs per-mount data structure. 370Sstevel@tonic-gate * 380Sstevel@tonic-gate * All fields are protected by tm_contents. 390Sstevel@tonic-gate * File renames on a particular file system are protected tm_renamelck. 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate struct tmount { 420Sstevel@tonic-gate struct vfs *tm_vfsp; /* filesystem's vfs struct */ 430Sstevel@tonic-gate struct tmpnode *tm_rootnode; /* root tmpnode */ 440Sstevel@tonic-gate char *tm_mntpath; /* name of tmpfs mount point */ 450Sstevel@tonic-gate ulong_t tm_anonmax; /* file system max anon reservation */ 460Sstevel@tonic-gate pgcnt_t tm_anonmem; /* pages of reserved anon memory */ 470Sstevel@tonic-gate dev_t tm_dev; /* unique dev # of mounted `device' */ 480Sstevel@tonic-gate uint_t tm_gen; /* pseudo generation number for files */ 490Sstevel@tonic-gate kmutex_t tm_contents; /* lock for tmount structure */ 500Sstevel@tonic-gate kmutex_t tm_renamelck; /* rename lock for this mount */ 510Sstevel@tonic-gate }; 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* 540Sstevel@tonic-gate * File system independent to tmpfs conversion macros 550Sstevel@tonic-gate */ 560Sstevel@tonic-gate #define VFSTOTM(vfsp) ((struct tmount *)(vfsp)->vfs_data) 570Sstevel@tonic-gate #define VTOTM(vp) ((struct tmount *)(vp)->v_vfsp->vfs_data) 580Sstevel@tonic-gate #define VTOTN(vp) ((struct tmpnode *)(vp)->v_data) 590Sstevel@tonic-gate #define TNTOV(tp) ((tp)->tn_vnode) 600Sstevel@tonic-gate #define tmpnode_hold(tp) VN_HOLD(TNTOV(tp)) 610Sstevel@tonic-gate #define tmpnode_rele(tp) VN_RELE(TNTOV(tp)) 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* 640Sstevel@tonic-gate * enums 650Sstevel@tonic-gate */ 660Sstevel@tonic-gate enum de_op { DE_CREATE, DE_MKDIR, DE_LINK, DE_RENAME }; /* direnter ops */ 670Sstevel@tonic-gate enum dr_op { DR_REMOVE, DR_RMDIR, DR_RENAME }; /* dirremove ops */ 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * tmpfs_minfree is the amount (in pages) of anonymous memory that tmpfs 710Sstevel@tonic-gate * leaves free for the rest of the system. E.g. in a system with 32MB of 720Sstevel@tonic-gate * configured swap space, if 16MB were reserved (leaving 16MB free), 730Sstevel@tonic-gate * tmpfs could allocate up to 16MB - tmpfs_minfree. The default value 740Sstevel@tonic-gate * for tmpfs_minfree is btopr(TMPMINFREE) but it can cautiously patched 750Sstevel@tonic-gate * to a different number of pages. 760Sstevel@tonic-gate * NB: If tmpfs allocates too much swap space, other processes will be 770Sstevel@tonic-gate * unable to execute. 780Sstevel@tonic-gate */ 790Sstevel@tonic-gate #define TMPMINFREE 2 * 1024 * 1024 /* 2 Megabytes */ 800Sstevel@tonic-gate 810Sstevel@tonic-gate extern size_t tmpfs_minfree; /* Anonymous memory in pages */ 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* 840Sstevel@tonic-gate * tmpfs can allocate only a certain percentage of kernel memory, 850Sstevel@tonic-gate * which is used for tmpnodes, directories, file names, etc. 860Sstevel@tonic-gate * This is statically set as TMPMAXFRACKMEM of physical memory. 870Sstevel@tonic-gate * The actual number of allocatable bytes can be patched in tmpfs_maxkmem. 880Sstevel@tonic-gate */ 890Sstevel@tonic-gate #define TMPMAXFRACKMEM 25 /* 1/25 of physical memory */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate extern size_t tmp_kmemspace; 920Sstevel@tonic-gate extern size_t tmpfs_maxkmem; /* Allocatable kernel memory in bytes */ 930Sstevel@tonic-gate 940Sstevel@tonic-gate extern void tmpnode_init(struct tmount *, struct tmpnode *, 950Sstevel@tonic-gate struct vattr *, struct cred *); 960Sstevel@tonic-gate extern int tmpnode_trunc(struct tmount *, struct tmpnode *, ulong_t); 970Sstevel@tonic-gate extern void tmpnode_growmap(struct tmpnode *, ulong_t); 980Sstevel@tonic-gate extern int tdirlookup(struct tmpnode *, char *, struct tmpnode **, 990Sstevel@tonic-gate struct cred *); 1000Sstevel@tonic-gate extern int tdirdelete(struct tmpnode *, struct tmpnode *, char *, 1010Sstevel@tonic-gate enum dr_op, struct cred *); 1020Sstevel@tonic-gate extern void tdirinit(struct tmpnode *, struct tmpnode *); 1030Sstevel@tonic-gate extern void tdirtrunc(struct tmpnode *); 1040Sstevel@tonic-gate extern void *tmp_memalloc(size_t, int); 1050Sstevel@tonic-gate extern void tmp_memfree(void *, size_t); 1060Sstevel@tonic-gate extern int tmp_resv(struct tmount *, struct tmpnode *, size_t, int); 1070Sstevel@tonic-gate extern int tmp_taccess(void *, int, struct cred *); 1080Sstevel@tonic-gate extern int tmp_sticky_remove_access(struct tmpnode *, struct tmpnode *, 1090Sstevel@tonic-gate struct cred *); 1100Sstevel@tonic-gate extern int tmp_convnum(char *, pgcnt_t *); 1110Sstevel@tonic-gate extern int tdirenter(struct tmount *, struct tmpnode *, char *, 1120Sstevel@tonic-gate enum de_op, struct tmpnode *, struct tmpnode *, struct vattr *, 113*5331Samw struct tmpnode **, struct cred *, caller_context_t *); 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate #define TMP_MUSTHAVE 0x01 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate #ifdef __cplusplus 1180Sstevel@tonic-gate } 1190Sstevel@tonic-gate #endif 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate #endif /* _SYS_FS_TMP_H */ 122