docs/how-to-build.md: use proper markup for directory names
[unleashed/tickless.git] / include / sys / file.h
blobc2c75434093b8fbeca08f310296dd31566161f61
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
29 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
30 /* Copyright 2015 Joyent, Inc. */
32 #ifndef _SYS_FILE_H
33 #define _SYS_FILE_H
35 #include <sys/t_lock.h>
36 #include <sys/fcntl.h>
37 #ifdef _KERNEL
38 #include <sys/model.h>
39 #include <sys/user.h>
40 #endif
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
47 * fio locking:
48 * f_rwlock protects f_vnode and f_cred
49 * f_tlock protects the rest
51 * The purpose of locking in this layer is to keep the kernel
52 * from panicing if, for example, a thread calls close() while
53 * another thread is doing a read(). It is up to higher levels
54 * to make sure 2 threads doing I/O to the same file don't
55 * screw each other up.
58 * One file structure is allocated for each open/creat/pipe call.
59 * Main use is to hold the read/write pointer (and OFD locks) associated with
60 * each open file.
62 typedef struct file {
63 kmutex_t f_tlock; /* short term lock */
64 uint32_t f_flag;
65 struct vnode *f_vnode; /* pointer to vnode structure */
66 offset_t f_offset; /* read/write character pointer */
67 struct cred *f_cred; /* credentials of user who opened it */
68 struct f_audit_data *f_audit_data; /* file audit data */
69 int f_count; /* reference count */
70 struct filock *f_filock; /* ptr to single lock_descriptor_t */
71 } file_t;
74 * fpollinfo struct - used by poll caching to track who has polled the fd
76 typedef struct fpollinfo {
77 struct _kthread *fp_thread; /* thread caching poll info */
78 struct fpollinfo *fp_next;
79 } fpollinfo_t;
82 #ifdef _KERNEL
85 * Fake flags for driver ioctl calls to inform them of the originating
86 * process' model. See <sys/model.h>
88 * Part of the Solaris 2.6+ DDI/DKI
90 #define FMODELS DATAMODEL_MASK /* Note: 0x0ff00000 */
91 #define FILP32 DATAMODEL_ILP32
92 #define FLP64 DATAMODEL_LP64
93 #define FNATIVE DATAMODEL_NATIVE
96 * Large Files: The macro gets the offset maximum (refer to LFS API doc)
97 * corresponding to a file descriptor. We had the choice of storing
98 * this value in file descriptor. Right now we only have two
99 * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is
100 * inefficient to store these two values in a separate member in
101 * file descriptor. To avoid wasting spaces we define this macro.
102 * The day there are more than two offset maximum we may want to
103 * rewrite this macro.
106 #define OFFSET_MAX(fd) ((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T)
109 * Fake flag => internal ioctl call for layered drivers.
110 * Note that this flag deliberately *won't* fit into
111 * the f_flag field of a file_t.
113 * Part of the Solaris 2.x DDI/DKI.
115 #define FKIOCTL 0x80000000 /* ioctl addresses are from kernel */
118 * Fake flag => this time to specify that the open(9E)
119 * comes from another part of the kernel, not userland.
121 * Part of the Solaris 2.x DDI/DKI.
123 #define FKLYR 0x40000000 /* layered driver call */
125 #endif /* _KERNEL */
127 /* miscellaneous defines */
129 #ifndef L_SET
130 #define L_SET 0 /* for lseek */
131 #endif /* L_SET */
134 * For flock(3C). These really don't belong here but for historical reasons
135 * the interface defines them to be here.
137 #define LOCK_SH 1
138 #define LOCK_EX 2
139 #define LOCK_NB 4
140 #define LOCK_UN 8
142 #if !defined(_STRICT_SYMBOLS)
143 extern int flock(int, int);
144 #endif
146 #if defined(_KERNEL)
149 * Routines dealing with user per-open file flags and
150 * user open files.
152 struct proc; /* forward reference for function prototype */
153 struct vnodeops;
154 struct vattr;
156 extern file_t *getf(int);
157 extern void releasef(int);
158 extern void areleasef(int, uf_info_t *);
159 #ifndef _BOOT
160 extern void closeall(uf_info_t *);
161 #endif
162 extern void flist_fork(uf_info_t *, uf_info_t *);
163 extern int closef(file_t *);
164 extern int closeandsetf(int, file_t *);
165 extern int ufalloc_file(int, file_t *);
166 extern int ufalloc(int);
167 extern int ufcanalloc(struct proc *, uint_t);
168 extern int falloc(struct vnode *, int, file_t **, int *);
169 extern void finit(void);
170 extern void unfalloc(file_t *);
171 extern void setf(int, file_t *);
172 extern int f_getfd_error(int, int *);
173 extern char f_getfd(int);
174 extern int f_setfd_error(int, int);
175 extern void f_setfd(int, char);
176 extern int f_getfl(int, int *);
177 extern int f_badfd(int, int *, int);
178 extern int fassign(struct vnode **, int, int *);
179 extern void fcnt_add(uf_info_t *, int);
180 extern void close_exec(uf_info_t *);
181 extern void clear_stale_fd(void);
182 extern void clear_active_fd(int);
183 extern void free_afd(afd_t *afd);
184 extern int fgetstartvp(int, char *, struct vnode **);
185 extern int fsetattrat(int, char *, int, struct vattr *);
186 extern int fisopen(struct vnode *);
187 extern void delfpollinfo(int);
188 extern void addfpollinfo(int);
189 extern int sock_getfasync(struct vnode *);
190 extern int files_can_change_zones(void);
191 #ifdef DEBUG
192 /* The following functions are only used in ASSERT()s */
193 extern void checkwfdlist(struct vnode *, fpollinfo_t *);
194 extern void checkfpollinfo(void);
195 extern int infpollinfo(int);
196 #endif /* DEBUG */
198 #endif /* defined(_KERNEL) */
200 #ifdef __cplusplus
202 #endif
204 #endif /* _SYS_FILE_H */