2002-07-09 16:24:59 +04:00
|
|
|
/* file.h
|
|
|
|
*
|
|
|
|
* File Descriptors
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _FILE_H
|
|
|
|
#define _FILE_H
|
|
|
|
|
|
|
|
#include <sem.h>
|
|
|
|
#include <lock.h>
|
|
|
|
#include <atomic.h>
|
|
|
|
#include <memheap.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct file_descriptor;
|
2002-09-26 07:36:04 +04:00
|
|
|
struct fs_mount;
|
2002-07-09 16:24:59 +04:00
|
|
|
struct vnode;
|
|
|
|
|
|
|
|
/** The I/O context of a process/team, holds the fd array */
|
|
|
|
struct io_context {
|
|
|
|
struct vnode *cwd;
|
|
|
|
mutex io_mutex;
|
|
|
|
int table_size;
|
|
|
|
int num_used_fds;
|
|
|
|
struct file_descriptor **fds;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fd_ops {
|
2002-08-09 20:57:25 +04:00
|
|
|
ssize_t (*fd_read) (struct file_descriptor *, off_t pos, void *buffer, size_t *length);
|
|
|
|
ssize_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);
|
2002-10-08 07:19:57 +04:00
|
|
|
status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer, size_t length);
|
2002-07-09 16:24:59 +04:00
|
|
|
// int (*fd_poll)(struct file_descriptor *, int);
|
|
|
|
status_t (*fd_read_dir)(struct file_descriptor *,struct dirent *buffer,size_t bufferSize,uint32 *_count);
|
|
|
|
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 *);
|
|
|
|
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;
|
|
|
|
struct fd_ops *ops;
|
2002-09-26 07:36:04 +04:00
|
|
|
union {
|
|
|
|
struct vnode *vnode;
|
|
|
|
struct fs_mount *mount;
|
|
|
|
} 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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Prototypes */
|
|
|
|
|
|
|
|
struct file_descriptor *alloc_fd(void);
|
|
|
|
int new_fd(struct io_context *, struct file_descriptor *);
|
|
|
|
struct file_descriptor *get_fd(struct io_context *, int);
|
|
|
|
void put_fd(struct file_descriptor *);
|
|
|
|
void free_fd(struct file_descriptor *);
|
|
|
|
static struct io_context *get_current_io_context(bool kernel);
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
static __inline struct io_context *get_current_io_context(bool kernel)
|
|
|
|
{
|
|
|
|
if (kernel)
|
2002-08-03 04:41:27 +04:00
|
|
|
return team_get_kernel_team()->ioctx;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-08-03 04:41:27 +04:00
|
|
|
return thread_get_current_thread()->team->ioctx;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _FILE_H */
|