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