mirror of
https://github.com/reactos/reactos.git
synced 2025-06-16 05:48:31 +00:00
[FASTFAT] Allow partial returns on directory info query for first entry.
This mimics what MS FastFAT does and fixes (a bit) ntdll_winetest:directory. It still crashes, but go farther. CORE-13367
This commit is contained in:
parent
e15874b491
commit
52f0726817
1 changed files with 333 additions and 232 deletions
|
@ -91,20 +91,43 @@ NTSTATUS
|
||||||
VfatGetFileNameInformation(
|
VfatGetFileNameInformation(
|
||||||
PVFAT_DIRENTRY_CONTEXT DirContext,
|
PVFAT_DIRENTRY_CONTEXT DirContext,
|
||||||
PFILE_NAMES_INFORMATION pInfo,
|
PFILE_NAMES_INFORMATION pInfo,
|
||||||
ULONG BufferLength)
|
ULONG BufferLength,
|
||||||
|
PULONG Written,
|
||||||
|
BOOLEAN First)
|
||||||
{
|
{
|
||||||
if ((sizeof(FILE_DIRECTORY_INFORMATION) + DirContext->LongNameU.Length) > BufferLength)
|
NTSTATUS Status;
|
||||||
return STATUS_BUFFER_OVERFLOW;
|
ULONG BytesToCopy = 0;
|
||||||
|
|
||||||
|
*Written = 0;
|
||||||
|
Status = STATUS_BUFFER_OVERFLOW;
|
||||||
|
|
||||||
|
if (FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName) > BufferLength)
|
||||||
|
return Status;
|
||||||
|
|
||||||
|
if (First || (BufferLength >= FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName) + DirContext->LongNameU.Length))
|
||||||
|
{
|
||||||
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
||||||
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_DIRECTORY_INFORMATION) +
|
|
||||||
DirContext->LongNameU.Length);
|
|
||||||
|
|
||||||
|
*Written = FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName);
|
||||||
|
pInfo->NextEntryOffset = 0;
|
||||||
|
if (BufferLength > FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName))
|
||||||
|
{
|
||||||
|
BytesToCopy = min(DirContext->LongNameU.Length, BufferLength - FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName));
|
||||||
RtlCopyMemory(pInfo->FileName,
|
RtlCopyMemory(pInfo->FileName,
|
||||||
DirContext->LongNameU.Buffer,
|
DirContext->LongNameU.Buffer,
|
||||||
DirContext->LongNameU.Length);
|
BytesToCopy);
|
||||||
|
*Written += BytesToCopy;
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
if (BytesToCopy == DirContext->LongNameU.Length)
|
||||||
|
{
|
||||||
|
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_NAMES_INFORMATION) +
|
||||||
|
BytesToCopy);
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -113,19 +136,43 @@ VfatGetFileDirectoryInformation(
|
||||||
PVFAT_DIRENTRY_CONTEXT DirContext,
|
PVFAT_DIRENTRY_CONTEXT DirContext,
|
||||||
PDEVICE_EXTENSION DeviceExt,
|
PDEVICE_EXTENSION DeviceExt,
|
||||||
PFILE_DIRECTORY_INFORMATION pInfo,
|
PFILE_DIRECTORY_INFORMATION pInfo,
|
||||||
ULONG BufferLength)
|
ULONG BufferLength,
|
||||||
|
PULONG Written,
|
||||||
|
BOOLEAN First)
|
||||||
{
|
{
|
||||||
if ((sizeof(FILE_DIRECTORY_INFORMATION) + DirContext->LongNameU.Length) > BufferLength)
|
NTSTATUS Status;
|
||||||
return STATUS_BUFFER_OVERFLOW;
|
ULONG BytesToCopy = 0;
|
||||||
|
|
||||||
|
*Written = 0;
|
||||||
|
Status = STATUS_BUFFER_OVERFLOW;
|
||||||
|
|
||||||
|
if (FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName) > BufferLength)
|
||||||
|
return Status;
|
||||||
|
|
||||||
|
if (First || (BufferLength >= FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName) + DirContext->LongNameU.Length))
|
||||||
|
{
|
||||||
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
||||||
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_DIRECTORY_INFORMATION) +
|
|
||||||
DirContext->LongNameU.Length);
|
|
||||||
/* pInfo->FileIndex = ; */
|
/* pInfo->FileIndex = ; */
|
||||||
|
|
||||||
|
*Written = FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName);
|
||||||
|
pInfo->NextEntryOffset = 0;
|
||||||
|
if (BufferLength > FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName))
|
||||||
|
{
|
||||||
|
BytesToCopy = min(DirContext->LongNameU.Length, BufferLength - FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName));
|
||||||
RtlCopyMemory(pInfo->FileName,
|
RtlCopyMemory(pInfo->FileName,
|
||||||
DirContext->LongNameU.Buffer,
|
DirContext->LongNameU.Buffer,
|
||||||
DirContext->LongNameU.Length);
|
BytesToCopy);
|
||||||
|
*Written += BytesToCopy;
|
||||||
|
|
||||||
|
if (BytesToCopy == DirContext->LongNameU.Length)
|
||||||
|
{
|
||||||
|
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_DIRECTORY_INFORMATION) +
|
||||||
|
BytesToCopy);
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (vfatVolumeIsFatX(DeviceExt))
|
if (vfatVolumeIsFatX(DeviceExt))
|
||||||
{
|
{
|
||||||
|
@ -195,8 +242,9 @@ VfatGetFileDirectoryInformation(
|
||||||
|
|
||||||
pInfo->FileAttributes = DirContext->DirEntry.Fat.Attrib & 0x3f;
|
pInfo->FileAttributes = DirContext->DirEntry.Fat.Attrib & 0x3f;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -205,20 +253,42 @@ VfatGetFileFullDirectoryInformation(
|
||||||
PVFAT_DIRENTRY_CONTEXT DirContext,
|
PVFAT_DIRENTRY_CONTEXT DirContext,
|
||||||
PDEVICE_EXTENSION DeviceExt,
|
PDEVICE_EXTENSION DeviceExt,
|
||||||
PFILE_FULL_DIR_INFORMATION pInfo,
|
PFILE_FULL_DIR_INFORMATION pInfo,
|
||||||
ULONG BufferLength)
|
ULONG BufferLength,
|
||||||
|
PULONG Written,
|
||||||
|
BOOLEAN First)
|
||||||
{
|
{
|
||||||
if ((sizeof(FILE_FULL_DIR_INFORMATION) + DirContext->LongNameU.Length) > BufferLength)
|
NTSTATUS Status;
|
||||||
return STATUS_BUFFER_OVERFLOW;
|
ULONG BytesToCopy = 0;
|
||||||
|
|
||||||
|
*Written = 0;
|
||||||
|
Status = STATUS_BUFFER_OVERFLOW;
|
||||||
|
|
||||||
|
if (FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName) > BufferLength)
|
||||||
|
return Status;
|
||||||
|
|
||||||
|
if (First || (BufferLength >= FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName) + DirContext->LongNameU.Length))
|
||||||
|
{
|
||||||
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
||||||
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_FULL_DIR_INFORMATION) +
|
|
||||||
DirContext->LongNameU.Length);
|
|
||||||
/* pInfo->FileIndex = ; */
|
/* pInfo->FileIndex = ; */
|
||||||
/* pInfo->EaSize = ; */
|
pInfo->EaSize = 0;
|
||||||
|
|
||||||
|
*Written = FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName);
|
||||||
|
pInfo->NextEntryOffset = 0;
|
||||||
|
if (BufferLength > FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName))
|
||||||
|
{
|
||||||
|
BytesToCopy = min(DirContext->LongNameU.Length, BufferLength - FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName));
|
||||||
RtlCopyMemory(pInfo->FileName,
|
RtlCopyMemory(pInfo->FileName,
|
||||||
DirContext->LongNameU.Buffer,
|
DirContext->LongNameU.Buffer,
|
||||||
DirContext->LongNameU.Length);
|
BytesToCopy);
|
||||||
|
*Written += BytesToCopy;
|
||||||
|
|
||||||
|
if (BytesToCopy == DirContext->LongNameU.Length)
|
||||||
|
{
|
||||||
|
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_FULL_DIR_INFORMATION) +
|
||||||
|
BytesToCopy);
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (vfatVolumeIsFatX(DeviceExt))
|
if (vfatVolumeIsFatX(DeviceExt))
|
||||||
{
|
{
|
||||||
|
@ -268,8 +338,9 @@ VfatGetFileFullDirectoryInformation(
|
||||||
DeviceExt->FatInfo.BytesPerCluster);
|
DeviceExt->FatInfo.BytesPerCluster);
|
||||||
pInfo->FileAttributes = DirContext->DirEntry.Fat.Attrib & 0x3f;
|
pInfo->FileAttributes = DirContext->DirEntry.Fat.Attrib & 0x3f;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -278,23 +349,44 @@ VfatGetFileBothInformation(
|
||||||
PVFAT_DIRENTRY_CONTEXT DirContext,
|
PVFAT_DIRENTRY_CONTEXT DirContext,
|
||||||
PDEVICE_EXTENSION DeviceExt,
|
PDEVICE_EXTENSION DeviceExt,
|
||||||
PFILE_BOTH_DIR_INFORMATION pInfo,
|
PFILE_BOTH_DIR_INFORMATION pInfo,
|
||||||
ULONG BufferLength)
|
ULONG BufferLength,
|
||||||
|
PULONG Written,
|
||||||
|
BOOLEAN First)
|
||||||
{
|
{
|
||||||
if ((sizeof(FILE_BOTH_DIR_INFORMATION) + DirContext->LongNameU.Length) > BufferLength)
|
NTSTATUS Status;
|
||||||
return STATUS_BUFFER_OVERFLOW;
|
ULONG BytesToCopy = 0;
|
||||||
|
|
||||||
|
*Written = 0;
|
||||||
|
Status = STATUS_BUFFER_OVERFLOW;
|
||||||
|
|
||||||
|
if (FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName) > BufferLength)
|
||||||
|
return Status;
|
||||||
|
|
||||||
|
if (First || (BufferLength >= FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName) + DirContext->LongNameU.Length))
|
||||||
|
{
|
||||||
|
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
||||||
pInfo->EaSize = 0;
|
pInfo->EaSize = 0;
|
||||||
|
|
||||||
|
*Written = FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName);
|
||||||
|
pInfo->NextEntryOffset = 0;
|
||||||
|
if (BufferLength > FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName))
|
||||||
|
{
|
||||||
|
BytesToCopy = min(DirContext->LongNameU.Length, BufferLength - FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName));
|
||||||
|
RtlCopyMemory(pInfo->FileName,
|
||||||
|
DirContext->LongNameU.Buffer,
|
||||||
|
BytesToCopy);
|
||||||
|
*Written += BytesToCopy;
|
||||||
|
|
||||||
|
if (BytesToCopy == DirContext->LongNameU.Length)
|
||||||
|
{
|
||||||
|
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_BOTH_DIR_INFORMATION) +
|
||||||
|
BytesToCopy);
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (vfatVolumeIsFatX(DeviceExt))
|
if (vfatVolumeIsFatX(DeviceExt))
|
||||||
{
|
{
|
||||||
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
|
||||||
|
|
||||||
RtlCopyMemory(pInfo->FileName,
|
|
||||||
DirContext->LongNameU.Buffer,
|
|
||||||
DirContext->LongNameU.Length);
|
|
||||||
|
|
||||||
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_BOTH_DIR_INFORMATION) +
|
|
||||||
DirContext->LongNameU.Length);
|
|
||||||
pInfo->ShortName[0] = 0;
|
pInfo->ShortName[0] = 0;
|
||||||
pInfo->ShortNameLength = 0;
|
pInfo->ShortNameLength = 0;
|
||||||
/* pInfo->FileIndex = ; */
|
/* pInfo->FileIndex = ; */
|
||||||
|
@ -333,14 +425,6 @@ VfatGetFileBothInformation(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pInfo->FileNameLength = DirContext->LongNameU.Length;
|
|
||||||
pInfo->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_BOTH_DIR_INFORMATION) +
|
|
||||||
DirContext->LongNameU.Length);
|
|
||||||
|
|
||||||
RtlCopyMemory(pInfo->ShortName,
|
|
||||||
DirContext->ShortNameU.Buffer,
|
|
||||||
DirContext->ShortNameU.Length);
|
|
||||||
|
|
||||||
pInfo->ShortNameLength = (CCHAR)DirContext->ShortNameU.Length;
|
pInfo->ShortNameLength = (CCHAR)DirContext->ShortNameU.Length;
|
||||||
|
|
||||||
RtlCopyMemory(pInfo->FileName,
|
RtlCopyMemory(pInfo->FileName,
|
||||||
|
@ -380,8 +464,9 @@ VfatGetFileBothInformation(
|
||||||
|
|
||||||
pInfo->FileAttributes = DirContext->DirEntry.Fat.Attrib & 0x3f;
|
pInfo->FileAttributes = DirContext->DirEntry.Fat.Attrib & 0x3f;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -402,6 +487,7 @@ DoQuery(
|
||||||
VFAT_DIRENTRY_CONTEXT DirContext;
|
VFAT_DIRENTRY_CONTEXT DirContext;
|
||||||
WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH + 1];
|
WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH + 1];
|
||||||
WCHAR ShortNameBuffer[13];
|
WCHAR ShortNameBuffer[13];
|
||||||
|
ULONG Written;
|
||||||
|
|
||||||
PIO_STACK_LOCATION Stack = IrpContext->Stack;
|
PIO_STACK_LOCATION Stack = IrpContext->Stack;
|
||||||
|
|
||||||
|
@ -517,6 +603,7 @@ DoQuery(
|
||||||
DirContext.ShortNameU.Buffer = ShortNameBuffer;
|
DirContext.ShortNameU.Buffer = ShortNameBuffer;
|
||||||
DirContext.ShortNameU.MaximumLength = sizeof(ShortNameBuffer);
|
DirContext.ShortNameU.MaximumLength = sizeof(ShortNameBuffer);
|
||||||
|
|
||||||
|
Written = 0;
|
||||||
while ((Status == STATUS_SUCCESS) && (BufferLength > 0))
|
while ((Status == STATUS_SUCCESS) && (BufferLength > 0))
|
||||||
{
|
{
|
||||||
Status = FindFile(IrpContext->DeviceExt,
|
Status = FindFile(IrpContext->DeviceExt,
|
||||||
|
@ -536,28 +623,36 @@ DoQuery(
|
||||||
case FileNameInformation:
|
case FileNameInformation:
|
||||||
Status = VfatGetFileNameInformation(&DirContext,
|
Status = VfatGetFileNameInformation(&DirContext,
|
||||||
(PFILE_NAMES_INFORMATION)Buffer,
|
(PFILE_NAMES_INFORMATION)Buffer,
|
||||||
BufferLength);
|
BufferLength,
|
||||||
|
&Written,
|
||||||
|
Buffer0 == NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FileDirectoryInformation:
|
case FileDirectoryInformation:
|
||||||
Status = VfatGetFileDirectoryInformation(&DirContext,
|
Status = VfatGetFileDirectoryInformation(&DirContext,
|
||||||
IrpContext->DeviceExt,
|
IrpContext->DeviceExt,
|
||||||
(PFILE_DIRECTORY_INFORMATION)Buffer,
|
(PFILE_DIRECTORY_INFORMATION)Buffer,
|
||||||
BufferLength);
|
BufferLength,
|
||||||
|
&Written,
|
||||||
|
Buffer0 == NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FileFullDirectoryInformation:
|
case FileFullDirectoryInformation:
|
||||||
Status = VfatGetFileFullDirectoryInformation(&DirContext,
|
Status = VfatGetFileFullDirectoryInformation(&DirContext,
|
||||||
IrpContext->DeviceExt,
|
IrpContext->DeviceExt,
|
||||||
(PFILE_FULL_DIR_INFORMATION)Buffer,
|
(PFILE_FULL_DIR_INFORMATION)Buffer,
|
||||||
BufferLength);
|
BufferLength,
|
||||||
|
&Written,
|
||||||
|
Buffer0 == NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FileBothDirectoryInformation:
|
case FileBothDirectoryInformation:
|
||||||
Status = VfatGetFileBothInformation(&DirContext,
|
Status = VfatGetFileBothInformation(&DirContext,
|
||||||
IrpContext->DeviceExt,
|
IrpContext->DeviceExt,
|
||||||
(PFILE_BOTH_DIR_INFORMATION)Buffer,
|
(PFILE_BOTH_DIR_INFORMATION)Buffer,
|
||||||
BufferLength);
|
BufferLength,
|
||||||
|
&Written,
|
||||||
|
Buffer0 == NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -591,6 +686,12 @@ DoQuery(
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
IrpContext->Irp->IoStatus.Information = Stack->Parameters.QueryDirectory.Length - BufferLength;
|
IrpContext->Irp->IoStatus.Information = Stack->Parameters.QueryDirectory.Length - BufferLength;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ASSERT(Status != STATUS_SUCCESS || BufferLength == 0);
|
||||||
|
ASSERT(Written <= Stack->Parameters.QueryDirectory.Length);
|
||||||
|
IrpContext->Irp->IoStatus.Information = Written;
|
||||||
|
}
|
||||||
|
|
||||||
ExReleaseResourceLite(&pFcb->MainResource);
|
ExReleaseResourceLite(&pFcb->MainResource);
|
||||||
ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
|
ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue