Add fseek that only supports SEEK_SET

This commit is contained in:
pjht 2019-09-10 19:15:02 -05:00
parent 43bd25506b
commit d81509d8e8
3 changed files with 52 additions and 2 deletions

View File

@ -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");
}

View File

@ -8,7 +8,8 @@ typedef enum {
VFS_CLOSE,
VFS_REGISTER_FS,
VFS_MOUNT,
VFS_UMOUNT
VFS_UMOUNT,
VFS_SEEK
} vfs_message_type;
typedef struct {

View File

@ -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);