diff --git a/libc/stdio.c b/libc/stdio.c index e732c04..08e850d 100644 --- a/libc/stdio.c +++ b/libc/stdio.c @@ -419,6 +419,35 @@ int printf(const char* format,...) { } } +int fseek(FILE* stream,long offset,int origin) { + if (vfs_box==0) { + serial_print("The VFS box has not been found\n"); + return -1; + } + vfs_message* msg_data=make_msg(VFS_SEEK,NULL,NULL,*stream,origin); + msg_data->pos=offset; + Message msg; + msg.from=box; + msg.to=vfs_box; + msg.msg=msg_data; + msg.size=sizeof(vfs_message); + mailbox_send_msg(&msg); + yieldToPID(VFS_PID); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + while (msg.from==0) { + yieldToPID(VFS_PID); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + } + vfs_message* vfs_msg=(vfs_message*)msg.msg; + if (vfs_msg->flags) { + free(vfs_msg); + return -1; + } else { + free(vfs_msg); + return 0; + } +} + void rescan_vfs() { vfs_box=mailbox_find_by_name("vfs"); } diff --git a/sysroot/usr/include/ipc/vfs.h b/sysroot/usr/include/ipc/vfs.h index 1254143..3a88182 100644 --- a/sysroot/usr/include/ipc/vfs.h +++ b/sysroot/usr/include/ipc/vfs.h @@ -8,7 +8,8 @@ typedef enum { VFS_CLOSE, VFS_REGISTER_FS, VFS_MOUNT, - VFS_UMOUNT + VFS_UMOUNT, + VFS_SEEK } vfs_message_type; typedef struct { diff --git a/vfs/main.c b/vfs/main.c index b164a52..9c7dd43 100644 --- a/vfs/main.c +++ b/vfs/main.c @@ -332,6 +332,23 @@ void vfs_mount_abort(vfs_message* vfs_msg,uint32_t from) { free(data); } +void vfs_seek(vfs_message* vfs_msg,uint32_t from) { + char str[256]; + int_to_ascii(fd_tables[vfs_msg->orig_mbox][vfs_msg->fd].pos,str); + serial_print("Prev pos:"); + serial_print(str); + serial_print("\n"); + int_to_ascii(vfs_msg->pos,str); + serial_print("New in vfs msg:"); + serial_print(str); + serial_print("\n"); + fd_tables[vfs_msg->orig_mbox][vfs_msg->fd].pos=vfs_msg->pos; + int_to_ascii(fd_tables[vfs_msg->orig_mbox][vfs_msg->fd].pos,str); + serial_print("New in fd table:"); + serial_print(str); + serial_print("\n"); + vfs_msg->flags=0; +} int main() { init_vfs(); @@ -414,11 +431,14 @@ int main() { vfs_register_fs(vfs_msg,msg.from); serial_print("REGISTER_FS DONE\n"); break; + case VFS_SEEK: + vfs_seek(vfs_msg,msg.from); + break; default: vfs_msg->flags=1; break; } - if (vfs_msg->flags || vfs_msg->type==VFS_REGISTER_FS) { + if (vfs_msg->flags || vfs_msg->type==VFS_REGISTER_FS || vfs_msg->type==VFS_SEEK) { msg.from=box; msg.to=sender; mailbox_send_msg(&msg);