https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e18e7b100c236835ffa6c…
commit e18e7b100c236835ffa6ca06114a5c8551becec5
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Wed Sep 18 02:42:56 2019 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Sep 18 02:42:56 2019 +0200
[FREELDR] Implement 'SeekRelative' mode for the *Seek() methods for disks
& filesystems.
---
boot/freeldr/freeldr/arch/i386/hwdisk.c | 25 ++++++++++++++++++-------
boot/freeldr/freeldr/disk/scsiport.c | 25 ++++++++++++++++++-------
boot/freeldr/freeldr/lib/fs/btrfs.c | 19 ++++++++++++++-----
boot/freeldr/freeldr/lib/fs/ext2.c | 21 ++++++++++++++-------
boot/freeldr/freeldr/lib/fs/fat.c | 21 +++++++++++++++------
boot/freeldr/freeldr/lib/fs/iso.c | 21 +++++++++++++++------
boot/freeldr/freeldr/lib/fs/ntfs.c | 21 ++++++++++++++-------
7 files changed, 108 insertions(+), 45 deletions(-)
diff --git a/boot/freeldr/freeldr/arch/i386/hwdisk.c
b/boot/freeldr/freeldr/arch/i386/hwdisk.c
index ef13c24bbe4..d67494d508d 100644
--- a/boot/freeldr/freeldr/arch/i386/hwdisk.c
+++ b/boot/freeldr/freeldr/arch/i386/hwdisk.c
@@ -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;
}
diff --git a/boot/freeldr/freeldr/disk/scsiport.c b/boot/freeldr/freeldr/disk/scsiport.c
index 92b032ea574..6cb204d4c31 100644
--- a/boot/freeldr/freeldr/disk/scsiport.c
+++ b/boot/freeldr/freeldr/disk/scsiport.c
@@ -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;
}
diff --git a/boot/freeldr/freeldr/lib/fs/btrfs.c b/boot/freeldr/freeldr/lib/fs/btrfs.c
index 6ba632e0a40..2b88d6f6b39 100644
--- a/boot/freeldr/freeldr/lib/fs/btrfs.c
+++ b/boot/freeldr/freeldr/lib/fs/btrfs.c
@@ -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;
}
diff --git a/boot/freeldr/freeldr/lib/fs/ext2.c b/boot/freeldr/freeldr/lib/fs/ext2.c
index d5a4d92b456..9d183488d68 100644
--- a/boot/freeldr/freeldr/lib/fs/ext2.c
+++ b/boot/freeldr/freeldr/lib/fs/ext2.c
@@ -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;
}
diff --git a/boot/freeldr/freeldr/lib/fs/fat.c b/boot/freeldr/freeldr/lib/fs/fat.c
index 7dad4f2f516..f16f03a57e1 100644
--- a/boot/freeldr/freeldr/lib/fs/fat.c
+++ b/boot/freeldr/freeldr/lib/fs/fat.c
@@ -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)
- return EINVAL;
- if (Position->HighPart != 0)
+ if (NewPosition.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;
}
diff --git a/boot/freeldr/freeldr/lib/fs/iso.c b/boot/freeldr/freeldr/lib/fs/iso.c
index 6e8d0df2a02..6c08d32a0e9 100644
--- a/boot/freeldr/freeldr/lib/fs/iso.c
+++ b/boot/freeldr/freeldr/lib/fs/iso.c
@@ -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)
- return EINVAL;
- if (Position->HighPart != 0)
+ if (NewPosition.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;
}
diff --git a/boot/freeldr/freeldr/lib/fs/ntfs.c b/boot/freeldr/freeldr/lib/fs/ntfs.c
index e6f7b2531b9..bc2e6bfee86 100644
--- a/boot/freeldr/freeldr/lib/fs/ntfs.c
+++ b/boot/freeldr/freeldr/lib/fs/ntfs.c
@@ -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;
}