haiku/headers/private/kernel/fd.h
Axel Dörfler 8e5ca65bc9 Added a new write_stat() call to the file descriptor operations.
Renamed sys_read_stat() to sys_read_path_stat() - sys_read_stat() is now
the fd operation.
Removed the sys_write_attr_stat() call because it is no longer needed.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1554 a95241bf-73f2-0310-859d-f6bbb57e9c96
2002-10-17 03:04:19 +00:00

94 lines
2.2 KiB
C

/* 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;
struct fs_mount;
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 {
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);
off_t (*fd_seek)(struct file_descriptor *, off_t pos, int seekType);
status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer, size_t length);
// 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 *);
status_t (*fd_read_stat)(struct file_descriptor *, struct stat *);
status_t (*fd_write_stat)(struct file_descriptor *, const struct stat *, int statMask);
status_t (*fd_close)(struct file_descriptor *);
void (*fd_free)(struct file_descriptor *);
};
struct file_descriptor {
int32 type; /* descriptor type */
int32 ref_count;
struct fd_ops *ops;
union {
struct vnode *vnode;
struct fs_mount *mount;
} u;
void *cookie;
int32 open_mode;
off_t pos;
};
/* Types of file descriptors we can create */
enum fd_types {
FDTYPE_FILE = 1,
FDTYPE_ATTR,
FDTYPE_DIR,
FDTYPE_ATTR_DIR,
FDTYPE_INDEX,
FDTYPE_INDEX_DIR,
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);
/* The prototypes of the (sys|user)_ functions are currently defined in vfs.h */
/* Inlines */
static __inline struct io_context *get_current_io_context(bool kernel)
{
if (kernel)
return team_get_kernel_team()->ioctx;
return thread_get_current_thread()->team->ioctx;
}
#endif /* _FILE_H */