summaryrefslogtreecommitdiff
path: root/fs/shm.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/shm.c')
-rw-r--r--fs/shm.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/fs/shm.c b/fs/shm.c
index 8668c9a..4d5f2ab 100644
--- a/fs/shm.c
+++ b/fs/shm.c
@@ -47,6 +47,19 @@ vfs_vm_object_t *shm_get_vm_object(uint64_t length, uint64_t offset,
return p;
}
+int shm_ftruncate(vfs_fd_t *fd, size_t length) {
+ vfs_vm_object_t *p = fd->inode->internal_object;
+ p->size = length;
+ p->virtual_object = ksbrk(length);
+ int n = (uintptr_t)align_page((void *)(uint32_t)length) / 0x1000;
+ p->object = kmalloc(sizeof(void *) * n);
+ for (int i = 0; i < n; i++)
+ p->object[i] =
+ (void *)(get_page(p->virtual_object + (i * 0x1000), NULL, 0, 0)->frame *
+ 0x1000);
+ return 0;
+}
+
int shm_open(const char *name, int oflag, mode_t mode) {
// Try to find or create a new shared memory object.
vfs_vm_object_t *internal_object =
@@ -60,11 +73,11 @@ int shm_open(const char *name, int oflag, mode_t mode) {
hashmap_add_entry(shared_memory_objects, name, internal_object, NULL, 0);
}
- vfs_inode_t *inode =
- vfs_create_inode(0 /*inode_num*/, 0 /*type*/, 1 /*has_data*/,
- 1 /*can_write*/, 1 /*is_open*/, internal_object,
- 0 /*file_size*/, NULL /*open*/, NULL /*create_file*/,
- shm_read, shm_write, NULL /*close*/, NULL/*create_directory*/, shm_get_vm_object);
+ vfs_inode_t *inode = vfs_create_inode(
+ 0 /*inode_num*/, 0 /*type*/, 1 /*has_data*/, 1 /*can_write*/,
+ 1 /*is_open*/, internal_object, 0 /*file_size*/, NULL /*open*/,
+ NULL /*create_file*/, shm_read, shm_write, NULL /*close*/,
+ NULL /*create_directory*/, shm_get_vm_object, shm_ftruncate);
vfs_fd_t *fd_ptr;
int fd = vfs_create_fd(oflag, mode, inode, &fd_ptr);
@@ -79,20 +92,3 @@ int shm_unlink(const char *name) {
(void)name;
return 0;
}
-
-int ftruncate(int fildes, uint64_t length) {
- kprintf("ftruncate: %d\n", length);
- vfs_fd_t *fd = get_current_task()->file_descriptors[fildes];
- if (!fd)
- return -EBADF;
- vfs_vm_object_t *p = fd->inode->internal_object;
- p->size = length;
- p->virtual_object = ksbrk(length);
- int n = (uintptr_t)align_page((void *)(uint32_t)length) / 0x1000;
- p->object = kmalloc(sizeof(void *) * n);
- for (int i = 0; i < n; i++)
- p->object[i] =
- (void *)(get_page(p->virtual_object + (i * 0x1000), NULL, 0, 0)->frame *
- 0x1000);
- return 0;
-}