PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/headers/private/kernel/fs/fd.h

https://bitbucket.org/ddevine/haiku
C Header | 119 lines | 87 code | 23 blank | 9 comment | 1 complexity | 3473efab0bafda7b26f0a5b5d2d0cdc7 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, MIT, ISC, BSD-3-Clause, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-3.0
  1. /*
  2. * Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de.
  3. * Distributed under the terms of the MIT License.
  4. */
  5. #ifndef _FD_H
  6. #define _FD_H
  7. #include <vfs.h>
  8. #include <team.h>
  9. #include <thread.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. struct file_descriptor;
  14. struct io_context;
  15. struct net_socket;
  16. struct selectsync;
  17. struct select_info;
  18. struct fd_ops {
  19. status_t (*fd_read)(struct file_descriptor *, off_t pos, void *buffer, size_t *length);
  20. status_t (*fd_write)(struct file_descriptor *, off_t pos, const void *buffer, size_t *length);
  21. off_t (*fd_seek)(struct file_descriptor *, off_t pos, int seekType);
  22. status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer, size_t length);
  23. status_t (*fd_set_flags)(struct file_descriptor *, int flags);
  24. status_t (*fd_select)(struct file_descriptor *, uint8 event,
  25. struct selectsync *sync);
  26. status_t (*fd_deselect)(struct file_descriptor *, uint8 event,
  27. struct selectsync *sync);
  28. status_t (*fd_read_dir)(struct io_context* ioContext,
  29. struct file_descriptor *, struct dirent *buffer,
  30. size_t bufferSize, uint32 *_count);
  31. status_t (*fd_rewind_dir)(struct file_descriptor *);
  32. status_t (*fd_read_stat)(struct file_descriptor *, struct stat *);
  33. status_t (*fd_write_stat)(struct file_descriptor *, const struct stat *, int statMask);
  34. status_t (*fd_close)(struct file_descriptor *);
  35. void (*fd_free)(struct file_descriptor *);
  36. };
  37. struct file_descriptor {
  38. int32 type; /* descriptor type */
  39. int32 ref_count;
  40. int32 open_count;
  41. struct fd_ops *ops;
  42. union {
  43. struct vnode *vnode;
  44. struct fs_mount *mount;
  45. struct net_socket *socket;
  46. } u;
  47. void *cookie;
  48. int32 open_mode;
  49. off_t pos;
  50. };
  51. /* Types of file descriptors we can create */
  52. enum fd_types {
  53. FDTYPE_FILE = 1,
  54. FDTYPE_ATTR,
  55. FDTYPE_DIR,
  56. FDTYPE_ATTR_DIR,
  57. FDTYPE_INDEX,
  58. FDTYPE_INDEX_DIR,
  59. FDTYPE_QUERY,
  60. FDTYPE_SOCKET
  61. };
  62. // additional open mode - kernel special
  63. #define O_DISCONNECTED 0x80000000
  64. /* Prototypes */
  65. extern struct file_descriptor *alloc_fd(void);
  66. extern int new_fd_etc(struct io_context *, struct file_descriptor *, int firstIndex);
  67. extern int new_fd(struct io_context *, struct file_descriptor *);
  68. extern struct file_descriptor *get_fd(struct io_context *, int);
  69. extern struct file_descriptor *get_open_fd(struct io_context *, int);
  70. extern void close_fd(struct file_descriptor *descriptor);
  71. extern status_t close_fd_index(struct io_context *context, int fd);
  72. extern void put_fd(struct file_descriptor *descriptor);
  73. extern void disconnect_fd(struct file_descriptor *descriptor);
  74. extern void inc_fd_ref_count(struct file_descriptor *descriptor);
  75. extern int dup_foreign_fd(team_id fromTeam, int fd, bool kernel);
  76. extern status_t select_fd(int32 fd, struct select_info *info, bool kernel);
  77. extern status_t deselect_fd(int32 fd, struct select_info *info, bool kernel);
  78. extern bool fd_is_valid(int fd, bool kernel);
  79. extern struct vnode *fd_vnode(struct file_descriptor *descriptor);
  80. extern bool fd_close_on_exec(struct io_context *context, int fd);
  81. extern void fd_set_close_on_exec(struct io_context *context, int fd, bool closeFD);
  82. static struct io_context *get_current_io_context(bool kernel);
  83. extern status_t user_fd_kernel_ioctl(int fd, ulong op, void *buffer, size_t length);
  84. /* The prototypes of the (sys|user)_ functions are currently defined in vfs.h */
  85. /* Inlines */
  86. static inline struct io_context *
  87. get_current_io_context(bool kernel)
  88. {
  89. if (kernel)
  90. return (struct io_context *)team_get_kernel_team()->io_context;
  91. return (struct io_context *)thread_get_current_thread()->team->io_context;
  92. }
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* _FD_H */