2009-03-11 03:57:17 +03:00
|
|
|
/*
|
2018-01-14 13:26:12 +03:00
|
|
|
* Copyright 2002-2018, Axel Dörfler, axeld@pinc-software.de.
|
2004-11-25 05:53:28 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-10-29 06:49:57 +03:00
|
|
|
#ifndef _FD_H
|
|
|
|
#define _FD_H
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-25 05:53:28 +03:00
|
|
|
|
2004-12-14 01:22:45 +03:00
|
|
|
#include <vfs.h>
|
2004-03-16 05:40:03 +03:00
|
|
|
#include <team.h>
|
2004-11-25 05:53:28 +03:00
|
|
|
#include <thread.h>
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-10-17 18:42:45 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2004-12-14 01:22:45 +03:00
|
|
|
struct file_descriptor;
|
2008-03-30 09:59:54 +04:00
|
|
|
struct io_context;
|
2008-04-11 07:33:59 +04:00
|
|
|
struct net_socket;
|
2007-10-01 05:37:28 +04:00
|
|
|
struct selectsync;
|
2007-10-02 23:47:31 +04:00
|
|
|
struct select_info;
|
2003-01-20 03:58:13 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
struct fd_ops {
|
2018-01-14 13:26:12 +03:00
|
|
|
status_t (*fd_read)(struct file_descriptor *, off_t pos, void *buffer,
|
|
|
|
size_t *length);
|
|
|
|
status_t (*fd_write)(struct file_descriptor *, off_t pos,
|
|
|
|
const void *buffer, size_t *length);
|
2002-07-17 12:01:40 +04:00
|
|
|
off_t (*fd_seek)(struct file_descriptor *, off_t pos, int seekType);
|
2018-01-14 13:26:12 +03:00
|
|
|
status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer,
|
|
|
|
size_t length);
|
2008-04-11 23:21:14 +04:00
|
|
|
status_t (*fd_set_flags)(struct file_descriptor *, int flags);
|
2007-10-02 23:47:31 +04:00
|
|
|
status_t (*fd_select)(struct file_descriptor *, uint8 event,
|
2007-10-01 05:37:28 +04:00
|
|
|
struct selectsync *sync);
|
|
|
|
status_t (*fd_deselect)(struct file_descriptor *, uint8 event,
|
|
|
|
struct selectsync *sync);
|
2008-03-30 09:59:54 +04:00
|
|
|
status_t (*fd_read_dir)(struct io_context* ioContext,
|
|
|
|
struct file_descriptor *, struct dirent *buffer,
|
|
|
|
size_t bufferSize, uint32 *_count);
|
2002-07-09 16:24:59 +04:00
|
|
|
status_t (*fd_rewind_dir)(struct file_descriptor *);
|
2002-10-17 07:04:19 +04:00
|
|
|
status_t (*fd_read_stat)(struct file_descriptor *, struct stat *);
|
2018-01-14 13:26:12 +03:00
|
|
|
status_t (*fd_write_stat)(struct file_descriptor *, const struct stat *,
|
|
|
|
int statMask);
|
2002-10-08 07:19:57 +04:00
|
|
|
status_t (*fd_close)(struct file_descriptor *);
|
2002-07-09 16:24:59 +04:00
|
|
|
void (*fd_free)(struct file_descriptor *);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct file_descriptor {
|
|
|
|
int32 type; /* descriptor type */
|
|
|
|
int32 ref_count;
|
2005-03-17 23:25:07 +03:00
|
|
|
int32 open_count;
|
2002-07-09 16:24:59 +04:00
|
|
|
struct fd_ops *ops;
|
2002-09-26 07:36:04 +04:00
|
|
|
union {
|
|
|
|
struct vnode *vnode;
|
|
|
|
struct fs_mount *mount;
|
2008-04-11 07:33:59 +04:00
|
|
|
struct net_socket *socket;
|
2002-09-26 07:36:04 +04:00
|
|
|
} u;
|
2002-07-09 16:24:59 +04:00
|
|
|
void *cookie;
|
2002-08-05 09:31:32 +04:00
|
|
|
int32 open_mode;
|
2002-10-08 04:11:10 +04:00
|
|
|
off_t pos;
|
2002-07-09 16:24:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Types of file descriptors we can create */
|
|
|
|
|
|
|
|
enum fd_types {
|
|
|
|
FDTYPE_FILE = 1,
|
|
|
|
FDTYPE_ATTR,
|
|
|
|
FDTYPE_DIR,
|
2002-09-26 07:36:04 +04:00
|
|
|
FDTYPE_ATTR_DIR,
|
2002-07-09 16:24:59 +04:00
|
|
|
FDTYPE_INDEX,
|
2002-09-26 07:36:04 +04:00
|
|
|
FDTYPE_INDEX_DIR,
|
2002-07-09 16:24:59 +04:00
|
|
|
FDTYPE_QUERY,
|
|
|
|
FDTYPE_SOCKET
|
|
|
|
};
|
|
|
|
|
2006-01-15 20:11:48 +03:00
|
|
|
// additional open mode - kernel special
|
|
|
|
#define O_DISCONNECTED 0x80000000
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/* Prototypes */
|
|
|
|
|
2002-10-29 06:49:57 +03:00
|
|
|
extern struct file_descriptor *alloc_fd(void);
|
2018-01-14 13:26:12 +03:00
|
|
|
extern int new_fd_etc(struct io_context *, struct file_descriptor *,
|
|
|
|
int firstIndex);
|
2002-10-29 06:49:57 +03:00
|
|
|
extern int new_fd(struct io_context *, struct file_descriptor *);
|
|
|
|
extern struct file_descriptor *get_fd(struct io_context *, int);
|
2008-05-05 04:24:14 +04:00
|
|
|
extern struct file_descriptor *get_open_fd(struct io_context *, int);
|
2018-01-14 13:26:12 +03:00
|
|
|
extern void close_fd(struct io_context *context,
|
|
|
|
struct file_descriptor *descriptor);
|
2008-04-12 12:32:29 +04:00
|
|
|
extern status_t close_fd_index(struct io_context *context, int fd);
|
2005-03-18 04:24:11 +03:00
|
|
|
extern void put_fd(struct file_descriptor *descriptor);
|
2006-01-15 20:11:48 +03:00
|
|
|
extern void disconnect_fd(struct file_descriptor *descriptor);
|
2006-01-15 22:26:42 +03:00
|
|
|
extern void inc_fd_ref_count(struct file_descriptor *descriptor);
|
2009-03-11 03:57:17 +03:00
|
|
|
extern int dup_foreign_fd(team_id fromTeam, int fd, bool kernel);
|
2007-10-02 23:47:31 +04:00
|
|
|
extern status_t select_fd(int32 fd, struct select_info *info, bool kernel);
|
|
|
|
extern status_t deselect_fd(int32 fd, struct select_info *info, bool kernel);
|
2002-10-29 06:49:57 +03:00
|
|
|
extern bool fd_is_valid(int fd, bool kernel);
|
2005-12-16 19:11:36 +03:00
|
|
|
extern struct vnode *fd_vnode(struct file_descriptor *descriptor);
|
2002-10-29 06:49:57 +03:00
|
|
|
|
2005-10-06 13:02:59 +04:00
|
|
|
extern bool fd_close_on_exec(struct io_context *context, int fd);
|
2018-01-14 13:26:12 +03:00
|
|
|
extern void fd_set_close_on_exec(struct io_context *context, int fd,
|
|
|
|
bool closeFD);
|
2005-10-06 13:02:59 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
static struct io_context *get_current_io_context(bool kernel);
|
|
|
|
|
2018-01-14 13:26:12 +03:00
|
|
|
extern status_t user_fd_kernel_ioctl(int fd, ulong op, void *buffer,
|
|
|
|
size_t length);
|
2007-05-23 23:56:40 +04:00
|
|
|
|
2002-07-11 01:46:34 +04:00
|
|
|
/* The prototypes of the (sys|user)_ functions are currently defined in vfs.h */
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/* Inlines */
|
|
|
|
|
2003-05-13 04:27:29 +04:00
|
|
|
static inline struct io_context *
|
|
|
|
get_current_io_context(bool kernel)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
if (kernel)
|
2003-05-13 04:27:29 +04:00
|
|
|
return (struct io_context *)team_get_kernel_team()->io_context;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-05-13 04:27:29 +04:00
|
|
|
return (struct io_context *)thread_get_current_thread()->team->io_context;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2003-10-17 18:42:45 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-29 06:49:57 +03:00
|
|
|
#endif /* _FD_H */
|