mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
[FREELDR] Implement 'SeekRelative' mode for the *Seek() methods for disks & filesystems.
This commit is contained in:
parent
dd46d40fd2
commit
e18e7b100c
7 changed files with 108 additions and 45 deletions
|
@ -206,18 +206,29 @@ static ARC_STATUS
|
|||
DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||
{
|
||||
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
|
||||
ULONGLONG SectorNumber;
|
||||
LARGE_INTEGER NewPosition = *Position;
|
||||
|
||||
if (SeekMode != SeekAbsolute)
|
||||
return EINVAL;
|
||||
if (Position->LowPart & (Context->SectorSize - 1))
|
||||
switch (SeekMode)
|
||||
{
|
||||
case SeekAbsolute:
|
||||
break;
|
||||
case SeekRelative:
|
||||
NewPosition.QuadPart += (Context->SectorNumber * Context->SectorSize);
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (NewPosition.QuadPart & (Context->SectorSize - 1))
|
||||
return EINVAL;
|
||||
|
||||
SectorNumber = Position->QuadPart / Context->SectorSize;
|
||||
if (SectorNumber >= Context->SectorCount)
|
||||
/* Convert in number of sectors */
|
||||
NewPosition.QuadPart /= Context->SectorSize;
|
||||
if (NewPosition.QuadPart >= Context->SectorCount)
|
||||
return EINVAL;
|
||||
|
||||
Context->SectorNumber = SectorNumber;
|
||||
Context->SectorNumber = NewPosition.QuadPart;
|
||||
return ESUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -373,18 +373,29 @@ static ARC_STATUS DiskRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
|
|||
static ARC_STATUS DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||
{
|
||||
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
|
||||
ULONGLONG SectorNumber;
|
||||
LARGE_INTEGER NewPosition = *Position;
|
||||
|
||||
if (SeekMode != SeekAbsolute)
|
||||
return EINVAL;
|
||||
if (Position->QuadPart & (Context->SectorSize - 1))
|
||||
switch (SeekMode)
|
||||
{
|
||||
case SeekAbsolute:
|
||||
break;
|
||||
case SeekRelative:
|
||||
NewPosition.QuadPart += (Context->SectorNumber * Context->SectorSize);
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (NewPosition.QuadPart & (Context->SectorSize - 1))
|
||||
return EINVAL;
|
||||
|
||||
SectorNumber = Position->QuadPart / Context->SectorSize;
|
||||
if (SectorNumber >= Context->SectorCount)
|
||||
/* Convert in number of sectors */
|
||||
NewPosition.QuadPart /= Context->SectorSize;
|
||||
if (NewPosition.QuadPart >= Context->SectorCount)
|
||||
return EINVAL;
|
||||
|
||||
Context->SectorNumber = SectorNumber;
|
||||
Context->SectorNumber = NewPosition.QuadPart;
|
||||
return ESUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -1201,15 +1201,24 @@ ARC_STATUS BtrFsRead(ULONG FileId, VOID *Buffer, ULONG Size, ULONG *BytesRead)
|
|||
ARC_STATUS BtrFsSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
|
||||
{
|
||||
pbtrfs_file_info phandle = FsGetDeviceSpecific(FileId);
|
||||
LARGE_INTEGER NewPosition = *Position;
|
||||
|
||||
TRACE("BtrFsSeek %lu NewFilePointer = %llu\n", FileId, Position->QuadPart);
|
||||
switch (SeekMode)
|
||||
{
|
||||
case SeekAbsolute:
|
||||
break;
|
||||
case SeekRelative:
|
||||
NewPosition.QuadPart += phandle->position;
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (SeekMode != SeekAbsolute)
|
||||
return EINVAL;
|
||||
if (Position->QuadPart >= phandle->inode.size)
|
||||
if (NewPosition.QuadPart >= phandle->inode.size)
|
||||
return EINVAL;
|
||||
|
||||
phandle->position = Position->QuadPart;
|
||||
phandle->position = NewPosition.QuadPart;
|
||||
return ESUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -1263,17 +1263,24 @@ ARC_STATUS Ext2Read(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
|
|||
ARC_STATUS Ext2Seek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||
{
|
||||
PEXT2_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
|
||||
LARGE_INTEGER NewPosition = *Position;
|
||||
|
||||
TRACE("Ext2Seek() NewFilePointer = %lu\n", Position->LowPart);
|
||||
switch (SeekMode)
|
||||
{
|
||||
case SeekAbsolute:
|
||||
break;
|
||||
case SeekRelative:
|
||||
NewPosition.QuadPart += FileHandle->FilePointer;
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (SeekMode != SeekAbsolute)
|
||||
return EINVAL;
|
||||
if (Position->HighPart != 0)
|
||||
return EINVAL;
|
||||
if (Position->LowPart >= FileHandle->FileSize)
|
||||
if (NewPosition.QuadPart >= FileHandle->FileSize)
|
||||
return EINVAL;
|
||||
|
||||
FileHandle->FilePointer = Position->LowPart;
|
||||
FileHandle->FilePointer = NewPosition.QuadPart;
|
||||
return ESUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -1485,17 +1485,26 @@ ARC_STATUS FatRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
|
|||
ARC_STATUS FatSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||
{
|
||||
PFAT_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
|
||||
LARGE_INTEGER NewPosition = *Position;
|
||||
|
||||
TRACE("FatSeek() NewFilePointer = %lu\n", Position->LowPart);
|
||||
switch (SeekMode)
|
||||
{
|
||||
case SeekAbsolute:
|
||||
break;
|
||||
case SeekRelative:
|
||||
NewPosition.QuadPart += (ULONGLONG)FileHandle->FilePointer;
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (SeekMode != SeekAbsolute)
|
||||
if (NewPosition.HighPart != 0)
|
||||
return EINVAL;
|
||||
if (Position->HighPart != 0)
|
||||
return EINVAL;
|
||||
if (Position->LowPart >= FileHandle->FileSize)
|
||||
if (NewPosition.LowPart >= FileHandle->FileSize)
|
||||
return EINVAL;
|
||||
|
||||
FileHandle->FilePointer = Position->LowPart;
|
||||
FileHandle->FilePointer = NewPosition.LowPart;
|
||||
return ESUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -462,17 +462,26 @@ ARC_STATUS IsoRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
|
|||
ARC_STATUS IsoSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||
{
|
||||
PISO_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
|
||||
LARGE_INTEGER NewPosition = *Position;
|
||||
|
||||
TRACE("IsoSeek() NewFilePointer = %lu\n", Position->LowPart);
|
||||
switch (SeekMode)
|
||||
{
|
||||
case SeekAbsolute:
|
||||
break;
|
||||
case SeekRelative:
|
||||
NewPosition.QuadPart += (ULONGLONG)FileHandle->FilePointer;
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (SeekMode != SeekAbsolute)
|
||||
if (NewPosition.HighPart != 0)
|
||||
return EINVAL;
|
||||
if (Position->HighPart != 0)
|
||||
return EINVAL;
|
||||
if (Position->LowPart >= FileHandle->FileSize)
|
||||
if (NewPosition.LowPart >= FileHandle->FileSize)
|
||||
return EINVAL;
|
||||
|
||||
FileHandle->FilePointer = Position->LowPart;
|
||||
FileHandle->FilePointer = NewPosition.LowPart;
|
||||
return ESUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -846,17 +846,24 @@ ARC_STATUS NtfsRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
|
|||
ARC_STATUS NtfsSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||
{
|
||||
PNTFS_FILE_HANDLE FileHandle = FsGetDeviceSpecific(FileId);
|
||||
LARGE_INTEGER NewPosition = *Position;
|
||||
|
||||
TRACE("NtfsSeek() NewFilePointer = %lu\n", Position->LowPart);
|
||||
switch (SeekMode)
|
||||
{
|
||||
case SeekAbsolute:
|
||||
break;
|
||||
case SeekRelative:
|
||||
NewPosition.QuadPart += FileHandle->Offset;
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (SeekMode != SeekAbsolute)
|
||||
return EINVAL;
|
||||
if (Position->HighPart != 0)
|
||||
return EINVAL;
|
||||
if (Position->LowPart >= (ULONG)NtfsGetAttributeSize(&FileHandle->DataContext->Record))
|
||||
if (NewPosition.QuadPart >= NtfsGetAttributeSize(&FileHandle->DataContext->Record))
|
||||
return EINVAL;
|
||||
|
||||
FileHandle->Offset = Position->LowPart;
|
||||
FileHandle->Offset = NewPosition.QuadPart;
|
||||
return ESUCCESS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue