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