PageRenderTime 46ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

include/sys/file.h

http://www.minix3.org/
C Header | 169 lines | 83 code | 16 blank | 70 comment | 0 complexity | b44ce288fa4674253b8e65e32b077f7c MD5 | raw file
Possible License(s): MIT, WTFPL, AGPL-1.0, BSD-3-Clause, GPL-3.0, LGPL-2.0, JSON, 0BSD
  1. /* $NetBSD: file.h,v 1.71 2009/12/24 19:01:12 elad Exp $ */
  2. /*-
  3. * Copyright (c) 2009 The NetBSD Foundation, Inc.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to The NetBSD Foundation
  7. * by Andrew Doran.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  20. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  22. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /*
  31. * Copyright (c) 1982, 1986, 1989, 1993
  32. * The Regents of the University of California. All rights reserved.
  33. *
  34. * Redistribution and use in source and binary forms, with or without
  35. * modification, are permitted provided that the following conditions
  36. * are met:
  37. * 1. Redistributions of source code must retain the above copyright
  38. * notice, this list of conditions and the following disclaimer.
  39. * 2. Redistributions in binary form must reproduce the above copyright
  40. * notice, this list of conditions and the following disclaimer in the
  41. * documentation and/or other materials provided with the distribution.
  42. * 3. Neither the name of the University nor the names of its contributors
  43. * may be used to endorse or promote products derived from this software
  44. * without specific prior written permission.
  45. *
  46. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  47. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  48. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  49. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  50. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  51. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  52. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  53. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  56. * SUCH DAMAGE.
  57. *
  58. * @(#)file.h 8.3 (Berkeley) 1/9/95
  59. */
  60. #ifndef _SYS_FILE_H_
  61. #define _SYS_FILE_H_
  62. #include <sys/fcntl.h>
  63. #include <sys/unistd.h>
  64. #ifdef _KERNEL
  65. #include <sys/mallocvar.h>
  66. #include <sys/queue.h>
  67. #include <sys/mutex.h>
  68. #include <sys/condvar.h>
  69. struct proc;
  70. struct lwp;
  71. struct uio;
  72. struct iovec;
  73. struct stat;
  74. struct knote;
  75. /*
  76. * Kernel file descriptor. One entry for each open kernel vnode and
  77. * socket.
  78. *
  79. * This structure is exported via the KERN_FILE and KERN_FILE2 sysctl
  80. * calls. Only add members to the end, do not delete them.
  81. */
  82. struct file {
  83. off_t f_offset; /* first, is 64-bit */
  84. kauth_cred_t f_cred; /* creds associated with descriptor */
  85. const struct fileops {
  86. int (*fo_read) (struct file *, off_t *, struct uio *,
  87. kauth_cred_t, int);
  88. int (*fo_write) (struct file *, off_t *, struct uio *,
  89. kauth_cred_t, int);
  90. int (*fo_ioctl) (struct file *, u_long, void *);
  91. int (*fo_fcntl) (struct file *, u_int, void *);
  92. int (*fo_poll) (struct file *, int);
  93. int (*fo_stat) (struct file *, struct stat *);
  94. int (*fo_close) (struct file *);
  95. int (*fo_kqfilter) (struct file *, struct knote *);
  96. void (*fo_restart) (struct file *);
  97. void (*fo_spare1) (void);
  98. void (*fo_spare2) (void);
  99. } *f_ops;
  100. void *f_data; /* descriptor data, e.g. vnode/socket */
  101. LIST_ENTRY(file) f_list; /* list of active files */
  102. kmutex_t f_lock; /* lock on structure */
  103. int f_flag; /* see fcntl.h */
  104. u_int f_marker; /* traversal marker (sysctl) */
  105. #define DTYPE_VNODE 1 /* file */
  106. #define DTYPE_SOCKET 2 /* communications endpoint */
  107. #define DTYPE_PIPE 3 /* pipe */
  108. #define DTYPE_KQUEUE 4 /* event queue */
  109. #define DTYPE_MISC 5 /* misc file descriptor type */
  110. #define DTYPE_CRYPTO 6 /* crypto */
  111. #define DTYPE_MQUEUE 7 /* message queue */
  112. #define DTYPE_NAMES \
  113. "0", "file", "socket", "pipe", "kqueue", "misc", "crypto", "mqueue"
  114. u_int f_type; /* descriptor type */
  115. u_int f_advice; /* access pattern hint; UVM_ADV_* */
  116. u_int f_count; /* reference count */
  117. u_int f_msgcount; /* references from message queue */
  118. u_int f_unpcount; /* deferred close: see uipc_usrreq.c */
  119. SLIST_ENTRY(file) f_unplist; /* deferred close: see uipc_usrreq.c */
  120. };
  121. /*
  122. * Flags for fo_read and fo_write and do_fileread/write/v
  123. */
  124. #define FOF_UPDATE_OFFSET 0x0001 /* update the file offset */
  125. #define FOF_IOV_SYSSPACE 0x0100 /* iov structure in kernel memory */
  126. LIST_HEAD(filelist, file);
  127. extern struct filelist filehead; /* head of list of open files */
  128. extern u_int maxfiles; /* kernel limit on # of open files */
  129. extern u_int nfiles; /* actual number of open files */
  130. extern const struct fileops vnops; /* vnode operations for files */
  131. int dofileread(int, struct file *, void *, size_t,
  132. off_t *, int, register_t *);
  133. int dofilewrite(int, struct file *, const void *,
  134. size_t, off_t *, int, register_t *);
  135. int do_filereadv(int, const struct iovec *, int, off_t *,
  136. int, register_t *);
  137. int do_filewritev(int, const struct iovec *, int, off_t *,
  138. int, register_t *);
  139. int fsetown(pid_t *, u_long, const void *);
  140. int fgetown(pid_t, u_long, void *);
  141. void fownsignal(pid_t, int, int, int, void *);
  142. /* Commonly used fileops */
  143. int fnullop_fcntl(struct file *, u_int, void *);
  144. int fnullop_poll(struct file *, int);
  145. int fnullop_kqfilter(struct file *, struct knote *);
  146. int fbadop_read(struct file *, off_t *, struct uio *, kauth_cred_t, int);
  147. int fbadop_write(struct file *, off_t *, struct uio *, kauth_cred_t, int);
  148. int fbadop_ioctl(struct file *, u_long, void *);
  149. int fbadop_close(struct file *);
  150. int fbadop_stat(struct file *, struct stat *);
  151. void fnullop_restart(struct file *);
  152. #endif /* _KERNEL */
  153. #endif /* _SYS_FILE_H_ */