Implement file seek

This commit is contained in:
Alex
2023-05-05 19:19:05 +03:00
parent b0e0415b3e
commit 50a0857524
5 changed files with 92 additions and 4 deletions

View File

@ -36,9 +36,44 @@ namespace VirtualFileSystem
return Size;
}
SeekFSFunction(USTAR_Seek)
{
long NewOffset;
if (Whence == SEEK_SET)
{
if (Offset > node->Length)
return -1;
node->Offset = Offset;
NewOffset = node->Offset;
}
else if (Whence == SEEK_CUR)
{
NewOffset = node->Offset + Offset;
if (NewOffset > node->Length || NewOffset < 0)
return -1;
node->Offset = NewOffset;
}
else if (Whence == SEEK_END)
{
NewOffset = node->Length + Offset;
if (NewOffset < 0)
return -1;
node->Offset = NewOffset;
}
else
{
error("Invalid whence!");
return -1;
}
return NewOffset;
}
FileSystemOperations ustar_op = {
.Name = "ustar",
.Read = USTAR_Read,
.Seek = USTAR_Seek,
};
USTAR::USTAR(uintptr_t Address, Virtual *vfs_ctx)