summaryrefslogtreecommitdiff
path: root/kernel/fs/tmpfs.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-26 19:06:46 +0200
committerAnton Kling <anton@kling.gg>2024-04-26 19:06:46 +0200
commit7ab3153f92f38223157c4c1f4af1c30e33c94a76 (patch)
tree301f950cd6dc8fde244e9b5c1201ec01d964347b /kernel/fs/tmpfs.c
parent2e2805c88789c148cce0118d3a4ff0212458bb86 (diff)
Kernel/VFS: Change polling from variables to functions
Instead of having to store state in variables functions are called to check the object directly.
Diffstat (limited to 'kernel/fs/tmpfs.c')
-rw-r--r--kernel/fs/tmpfs.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/kernel/fs/tmpfs.c b/kernel/fs/tmpfs.c
index 3ef774c..eb6ae34 100644
--- a/kernel/fs/tmpfs.c
+++ b/kernel/fs/tmpfs.c
@@ -10,6 +10,16 @@ void tmp_close(vfs_fd_t *fd) {
((tmp_inode *)fd->inode->internal_object)->read_inode->is_open = 0;
}
+int tmp_has_data(vfs_inode_t *inode) {
+ tmp_inode *calling_file = inode->internal_object;
+ return calling_file->fifo->has_data;
+}
+
+int tmp_can_write(vfs_inode_t *inode) {
+ tmp_inode *child_file = inode->internal_object;
+ return child_file->fifo->can_write;
+}
+
int tmp_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
tmp_inode *calling_file = fd->inode->internal_object;
tmp_inode *child_file = calling_file->read_inode->internal_object;
@@ -17,23 +27,16 @@ int tmp_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
return -EPIPE;
}
- int rc = fifo_object_write(buffer, offset, len, child_file->fifo);
- calling_file->read_inode->has_data = child_file->fifo->has_data;
- fd->inode->can_write = child_file->fifo->can_write;
- return rc;
+ return fifo_object_write(buffer, offset, len, child_file->fifo);
}
int tmp_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
tmp_inode *calling_file = fd->inode->internal_object;
- tmp_inode *child_file = calling_file->read_inode->internal_object;
if (calling_file->is_closed) {
return -EPIPE;
}
- int rc = fifo_object_read(buffer, offset, len, calling_file->fifo);
- fd->inode->has_data = calling_file->fifo->has_data;
- calling_file->read_inode->can_write = child_file->fifo->can_write;
- return rc;
+ return fifo_object_read(buffer, offset, len, calling_file->fifo);
}
void dual_pipe(int fd[2]) {
@@ -42,12 +45,10 @@ void dual_pipe(int fd[2]) {
tmp_inode *pipe = kmalloc(sizeof(tmp_inode));
pipe->fifo = create_fifo_object();
- int has_data = 0;
- int can_write = 1;
int is_open = 1;
void *internal_object = pipe;
vfs_inode_t *inode = vfs_create_inode(
- 0 /*inode_num*/, 0 /*type*/, has_data, can_write, is_open,
+ 0 /*inode_num*/, 0 /*type*/, tmp_has_data, tmp_can_write, is_open,
internal_object, 0 /*file_size*/, NULL /*open*/, NULL /*create_file*/,
tmp_read, tmp_write, tmp_close, NULL /*create_directory*/,
NULL /*get_vm_object*/, NULL /*truncate*/, NULL /*stat*/,
@@ -77,12 +78,10 @@ void pipe(int fd[2]) {
tmp_inode *pipe = kmalloc(sizeof(tmp_inode));
pipe->fifo = create_fifo_object();
- int has_data = 0;
- int can_write = 1;
int is_open = 1;
void *internal_object = pipe;
vfs_inode_t *inode = vfs_create_inode(
- 0 /*inode_num*/, 0 /*type*/, has_data, can_write, is_open,
+ 0 /*inode_num*/, 0 /*type*/, tmp_has_data, tmp_can_write, is_open,
internal_object, 0 /*file_size*/, NULL /*open*/, NULL /*create_file*/,
tmp_read, tmp_write, tmp_close, NULL /*create_directory*/,
NULL /*get_vm_object*/, NULL /*truncate*/, NULL /*stat*/,