mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 21:42:57 +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)
|
DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||||
{
|
{
|
||||||
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
|
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
|
||||||
ULONGLONG SectorNumber;
|
LARGE_INTEGER NewPosition = *Position;
|
||||||
|
|
||||||
if (SeekMode != SeekAbsolute)
|
switch (SeekMode)
|
||||||
return EINVAL;
|
{
|
||||||
if (Position->LowPart & (Context->SectorSize - 1))
|
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;
|
return EINVAL;
|
||||||
|
|
||||||
SectorNumber = Position->QuadPart / Context->SectorSize;
|
/* Convert in number of sectors */
|
||||||
if (SectorNumber >= Context->SectorCount)
|
NewPosition.QuadPart /= Context->SectorSize;
|
||||||
|
if (NewPosition.QuadPart >= Context->SectorCount)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
Context->SectorNumber = SectorNumber;
|
Context->SectorNumber = NewPosition.QuadPart;
|
||||||
return ESUCCESS;
|
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)
|
static ARC_STATUS DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||||
{
|
{
|
||||||
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
|
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
|
||||||
ULONGLONG SectorNumber;
|
LARGE_INTEGER NewPosition = *Position;
|
||||||
|
|
||||||
if (SeekMode != SeekAbsolute)
|
switch (SeekMode)
|
||||||
return EINVAL;
|
{
|
||||||
if (Position->QuadPart & (Context->SectorSize - 1))
|
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;
|
return EINVAL;
|
||||||
|
|
||||||
SectorNumber = Position->QuadPart / Context->SectorSize;
|
/* Convert in number of sectors */
|
||||||
if (SectorNumber >= Context->SectorCount)
|
NewPosition.QuadPart /= Context->SectorSize;
|
||||||
|
if (NewPosition.QuadPart >= Context->SectorCount)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
Context->SectorNumber = SectorNumber;
|
Context->SectorNumber = NewPosition.QuadPart;
|
||||||
return ESUCCESS;
|
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)
|
ARC_STATUS BtrFsSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
|
||||||
{
|
{
|
||||||
pbtrfs_file_info phandle = FsGetDeviceSpecific(FileId);
|
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)
|
if (NewPosition.QuadPart >= phandle->inode.size)
|
||||||
return EINVAL;
|
|
||||||
if (Position->QuadPart >= phandle->inode.size)
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
phandle->position = Position->QuadPart;
|
phandle->position = NewPosition.QuadPart;
|
||||||
return ESUCCESS;
|
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)
|
ARC_STATUS Ext2Seek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||||
{
|
{
|
||||||
PEXT2_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
|
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)
|
if (NewPosition.QuadPart >= FileHandle->FileSize)
|
||||||
return EINVAL;
|
|
||||||
if (Position->HighPart != 0)
|
|
||||||
return EINVAL;
|
|
||||||
if (Position->LowPart >= FileHandle->FileSize)
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
FileHandle->FilePointer = Position->LowPart;
|
FileHandle->FilePointer = NewPosition.QuadPart;
|
||||||
return ESUCCESS;
|
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)
|
ARC_STATUS FatSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||||
{
|
{
|
||||||
PFAT_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
|
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;
|
return EINVAL;
|
||||||
if (Position->HighPart != 0)
|
if (NewPosition.LowPart >= FileHandle->FileSize)
|
||||||
return EINVAL;
|
|
||||||
if (Position->LowPart >= FileHandle->FileSize)
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
FileHandle->FilePointer = Position->LowPart;
|
FileHandle->FilePointer = NewPosition.LowPart;
|
||||||
return ESUCCESS;
|
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)
|
ARC_STATUS IsoSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||||
{
|
{
|
||||||
PISO_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
|
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;
|
return EINVAL;
|
||||||
if (Position->HighPart != 0)
|
if (NewPosition.LowPart >= FileHandle->FileSize)
|
||||||
return EINVAL;
|
|
||||||
if (Position->LowPart >= FileHandle->FileSize)
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
FileHandle->FilePointer = Position->LowPart;
|
FileHandle->FilePointer = NewPosition.LowPart;
|
||||||
return ESUCCESS;
|
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)
|
ARC_STATUS NtfsSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
|
||||||
{
|
{
|
||||||
PNTFS_FILE_HANDLE FileHandle = FsGetDeviceSpecific(FileId);
|
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)
|
if (NewPosition.QuadPart >= NtfsGetAttributeSize(&FileHandle->DataContext->Record))
|
||||||
return EINVAL;
|
|
||||||
if (Position->HighPart != 0)
|
|
||||||
return EINVAL;
|
|
||||||
if (Position->LowPart >= (ULONG)NtfsGetAttributeSize(&FileHandle->DataContext->Record))
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
FileHandle->Offset = Position->LowPart;
|
FileHandle->Offset = NewPosition.QuadPart;
|
||||||
return ESUCCESS;
|
return ESUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue