17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*da6c28aaSamw * Common Development and Distribution License (the "License"). 6*da6c28aaSamw * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*da6c28aaSamw * Copyright 2007 Sun Microsystems, Inc. 237c478bd9Sstevel@tonic-gate * All rights reserved. Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_FS_TMP_H 277c478bd9Sstevel@tonic-gate #define _SYS_FS_TMP_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate /* 367c478bd9Sstevel@tonic-gate * tmpfs per-mount data structure. 377c478bd9Sstevel@tonic-gate * 387c478bd9Sstevel@tonic-gate * All fields are protected by tm_contents. 397c478bd9Sstevel@tonic-gate * File renames on a particular file system are protected tm_renamelck. 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate struct tmount { 427c478bd9Sstevel@tonic-gate struct vfs *tm_vfsp; /* filesystem's vfs struct */ 437c478bd9Sstevel@tonic-gate struct tmpnode *tm_rootnode; /* root tmpnode */ 447c478bd9Sstevel@tonic-gate char *tm_mntpath; /* name of tmpfs mount point */ 457c478bd9Sstevel@tonic-gate ulong_t tm_anonmax; /* file system max anon reservation */ 467c478bd9Sstevel@tonic-gate pgcnt_t tm_anonmem; /* pages of reserved anon memory */ 477c478bd9Sstevel@tonic-gate dev_t tm_dev; /* unique dev # of mounted `device' */ 487c478bd9Sstevel@tonic-gate uint_t tm_gen; /* pseudo generation number for files */ 497c478bd9Sstevel@tonic-gate kmutex_t tm_contents; /* lock for tmount structure */ 507c478bd9Sstevel@tonic-gate kmutex_t tm_renamelck; /* rename lock for this mount */ 517c478bd9Sstevel@tonic-gate }; 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * File system independent to tmpfs conversion macros 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate #define VFSTOTM(vfsp) ((struct tmount *)(vfsp)->vfs_data) 577c478bd9Sstevel@tonic-gate #define VTOTM(vp) ((struct tmount *)(vp)->v_vfsp->vfs_data) 587c478bd9Sstevel@tonic-gate #define VTOTN(vp) ((struct tmpnode *)(vp)->v_data) 597c478bd9Sstevel@tonic-gate #define TNTOV(tp) ((tp)->tn_vnode) 607c478bd9Sstevel@tonic-gate #define tmpnode_hold(tp) VN_HOLD(TNTOV(tp)) 617c478bd9Sstevel@tonic-gate #define tmpnode_rele(tp) VN_RELE(TNTOV(tp)) 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * enums 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate enum de_op { DE_CREATE, DE_MKDIR, DE_LINK, DE_RENAME }; /* direnter ops */ 677c478bd9Sstevel@tonic-gate enum dr_op { DR_REMOVE, DR_RMDIR, DR_RENAME }; /* dirremove ops */ 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * tmpfs_minfree is the amount (in pages) of anonymous memory that tmpfs 717c478bd9Sstevel@tonic-gate * leaves free for the rest of the system. E.g. in a system with 32MB of 727c478bd9Sstevel@tonic-gate * configured swap space, if 16MB were reserved (leaving 16MB free), 737c478bd9Sstevel@tonic-gate * tmpfs could allocate up to 16MB - tmpfs_minfree. The default value 747c478bd9Sstevel@tonic-gate * for tmpfs_minfree is btopr(TMPMINFREE) but it can cautiously patched 757c478bd9Sstevel@tonic-gate * to a different number of pages. 767c478bd9Sstevel@tonic-gate * NB: If tmpfs allocates too much swap space, other processes will be 777c478bd9Sstevel@tonic-gate * unable to execute. 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate #define TMPMINFREE 2 * 1024 * 1024 /* 2 Megabytes */ 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate extern size_t tmpfs_minfree; /* Anonymous memory in pages */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * tmpfs can allocate only a certain percentage of kernel memory, 857c478bd9Sstevel@tonic-gate * which is used for tmpnodes, directories, file names, etc. 867c478bd9Sstevel@tonic-gate * This is statically set as TMPMAXFRACKMEM of physical memory. 877c478bd9Sstevel@tonic-gate * The actual number of allocatable bytes can be patched in tmpfs_maxkmem. 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate #define TMPMAXFRACKMEM 25 /* 1/25 of physical memory */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate extern size_t tmp_kmemspace; 927c478bd9Sstevel@tonic-gate extern size_t tmpfs_maxkmem; /* Allocatable kernel memory in bytes */ 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate extern void tmpnode_init(struct tmount *, struct tmpnode *, 957c478bd9Sstevel@tonic-gate struct vattr *, struct cred *); 967c478bd9Sstevel@tonic-gate extern int tmpnode_trunc(struct tmount *, struct tmpnode *, ulong_t); 977c478bd9Sstevel@tonic-gate extern void tmpnode_growmap(struct tmpnode *, ulong_t); 987c478bd9Sstevel@tonic-gate extern int tdirlookup(struct tmpnode *, char *, struct tmpnode **, 997c478bd9Sstevel@tonic-gate struct cred *); 1007c478bd9Sstevel@tonic-gate extern int tdirdelete(struct tmpnode *, struct tmpnode *, char *, 1017c478bd9Sstevel@tonic-gate enum dr_op, struct cred *); 1027c478bd9Sstevel@tonic-gate extern void tdirinit(struct tmpnode *, struct tmpnode *); 1037c478bd9Sstevel@tonic-gate extern void tdirtrunc(struct tmpnode *); 1047c478bd9Sstevel@tonic-gate extern void *tmp_memalloc(size_t, int); 1057c478bd9Sstevel@tonic-gate extern void tmp_memfree(void *, size_t); 1067c478bd9Sstevel@tonic-gate extern int tmp_resv(struct tmount *, struct tmpnode *, size_t, int); 1077c478bd9Sstevel@tonic-gate extern int tmp_taccess(void *, int, struct cred *); 1087c478bd9Sstevel@tonic-gate extern int tmp_sticky_remove_access(struct tmpnode *, struct tmpnode *, 1097c478bd9Sstevel@tonic-gate struct cred *); 1107c478bd9Sstevel@tonic-gate extern int tmp_convnum(char *, pgcnt_t *); 1117c478bd9Sstevel@tonic-gate extern int tdirenter(struct tmount *, struct tmpnode *, char *, 1127c478bd9Sstevel@tonic-gate enum de_op, struct tmpnode *, struct tmpnode *, struct vattr *, 113*da6c28aaSamw struct tmpnode **, struct cred *, caller_context_t *); 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #define TMP_MUSTHAVE 0x01 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate #endif 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #endif /* _SYS_FS_TMP_H */ 122