kernel/fs: Reorder fd_ops and add readv/writev hooks.

* Put close/free at the beginning since all FDs must implement that.
   (Most of the function declarations inline were already in this order.)

 * Add readv/writev hooks. Not used yet, but this will allow for
   more than just files to implement them. All declarations updated
   to have NULL for the hooks for the moment.
This commit is contained in:
Augustin Cavalier
2024-07-23 16:55:30 -04:00
parent 65a86bce72
commit 22b7491d3c
4 changed files with 46 additions and 43 deletions
+11 -2
View File
@@ -21,27 +21,36 @@ struct selectsync;
struct select_info;
struct fd_ops {
status_t (*fd_close)(struct file_descriptor *);
void (*fd_free)(struct file_descriptor *);
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);
ssize_t (*fd_readv)(struct file_descriptor *, off_t pos,
const struct iovec *vecs, int count);
ssize_t (*fd_writev)(struct file_descriptor *, off_t pos,
const struct iovec *vecs, int count);
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);
status_t (*fd_set_flags)(struct file_descriptor *, int flags);
status_t (*fd_select)(struct file_descriptor *, uint8 event,
struct selectsync *sync);
status_t (*fd_deselect)(struct file_descriptor *, uint8 event,
struct selectsync *sync);
status_t (*fd_read_dir)(struct io_context* ioContext,
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 {
-11
View File
@@ -572,17 +572,6 @@ event_queue_free(file_descriptor* descriptor)
static struct fd_ops sEventQueueFDOps = {
NULL, // fd_read
NULL, // fd_write
NULL, // fd_seek
NULL, // fd_ioctl
NULL, // fd_set_flags
NULL, // fd_select
NULL, // fd_deselect
NULL, // fd_read_dir
NULL, // fd_rewind_dir
NULL, // fd_read_stat
NULL, // fd_write_stat
&event_queue_close,
&event_queue_free
};
+3 -2
View File
@@ -296,8 +296,11 @@ socket_free(struct file_descriptor *descriptor)
static struct fd_ops sSocketFDOps = {
&socket_close,
&socket_free,
&socket_read,
&socket_write,
NULL, NULL, // readv(), writev()
NULL, // fd_seek
&socket_ioctl,
&socket_set_flags,
@@ -307,8 +310,6 @@ static struct fd_ops sSocketFDOps = {
NULL, // fd_rewind_dir
&socket_read_stat,
NULL, // fd_write_stat
&socket_close,
&socket_free
};
+32 -28
View File
@@ -431,24 +431,28 @@ static int open_vnode(struct vnode* vnode, int openMode, bool kernel);
static struct fd_ops sFileOps = {
file_close,
file_free_fd,
file_read,
file_write,
NULL, // readv()
NULL, // writev()
file_seek,
common_ioctl,
NULL, // set_flags
NULL, // set_flags()
file_select,
file_deselect,
NULL, // read_dir()
NULL, // rewind_dir()
common_read_stat,
common_write_stat,
file_close,
file_free_fd
};
static struct fd_ops sDirectoryOps = {
NULL, // read()
NULL, // write()
dir_close,
dir_free_fd,
NULL, NULL, // read(), write()
NULL, NULL, // readv(), writev()
NULL, // seek()
common_ioctl,
NULL, // set_flags
@@ -458,13 +462,13 @@ static struct fd_ops sDirectoryOps = {
dir_rewind,
common_read_stat,
common_write_stat,
dir_close,
dir_free_fd
};
static struct fd_ops sAttributeDirectoryOps = {
NULL, // read()
NULL, // write()
attr_dir_close,
attr_dir_free_fd,
NULL, NULL, // read(), write()
NULL, NULL, // readv(), writev()
NULL, // seek()
common_ioctl,
NULL, // set_flags
@@ -474,46 +478,48 @@ static struct fd_ops sAttributeDirectoryOps = {
attr_dir_rewind,
common_read_stat,
common_write_stat,
attr_dir_close,
attr_dir_free_fd
};
static struct fd_ops sAttributeOps = {
attr_close,
attr_free_fd,
attr_read,
attr_write,
NULL, // readv()
NULL, // writev()
attr_seek,
common_ioctl,
NULL, // set_flags
NULL, // set_flags()
NULL, // select()
NULL, // deselect()
NULL, // read_dir()
NULL, // rewind_dir()
attr_read_stat,
attr_write_stat,
attr_close,
attr_free_fd
};
static struct fd_ops sIndexDirectoryOps = {
NULL, // read()
NULL, // write()
index_dir_close,
index_dir_free_fd,
NULL, NULL, // read(), write()
NULL, NULL, // readv(), writev()
NULL, // seek()
NULL, // ioctl()
NULL, // set_flags
NULL, // set_flags()
NULL, // select()
NULL, // deselect()
index_dir_read,
index_dir_rewind,
NULL, // read_stat()
NULL, // write_stat()
index_dir_close,
index_dir_free_fd
};
#if 0
static struct fd_ops sIndexOps = {
NULL, // read()
NULL, // write()
NULL, // dir_close()
NULL, // free_fd()
NULL, NULL, // read(), write()
NULL, NULL, // readv(), writev()
NULL, // seek()
NULL, // ioctl()
NULL, // set_flags
@@ -523,25 +529,23 @@ static struct fd_ops sIndexOps = {
NULL, // dir_rewind()
index_read_stat, // read_stat()
NULL, // write_stat()
NULL, // dir_close()
NULL // free_fd()
};
#endif
static struct fd_ops sQueryOps = {
NULL, // read()
NULL, // write()
query_close,
query_free_fd,
NULL, NULL, // read(), write()
NULL, NULL, // readv(), writev()
NULL, // seek()
NULL, // ioctl()
NULL, // set_flags
NULL, // set_flags()
NULL, // select()
NULL, // deselect()
query_read,
query_rewind,
NULL, // read_stat()
NULL, // write_stat()
query_close,
query_free_fd
};