Based on a patch by Herve Poussineau <poussine@freesurf.fr>:

- Compile using W32API.
- Use documented structures names instead of ReactOS equivalent.
- Get rid of MAX_PATH constant (only valid in user mode).

svn path=/trunk/; revision=12957
This commit is contained in:
Filip Navara 2005-01-12 12:06:15 +00:00
parent fb6e28b8a0
commit 5a27206097
9 changed files with 132 additions and 58 deletions

View file

@ -41,7 +41,7 @@
void vfat8Dot3ToString (PFAT_DIR_ENTRY pEntry, PUNICODE_STRING NameU)
{
OEM_STRING StringA;
ULONG Length;
USHORT Length;
CHAR cString[12];
RtlCopyMemory(cString, pEntry->Filename, 11);
@ -191,22 +191,39 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
* FUNCTION: Find a file
*/
{
WCHAR PathNameBuffer[MAX_PATH];
PWCHAR PathNameBuffer;
ULONG PathNameBufferLength;
NTSTATUS Status;
PVOID Context = NULL;
PVOID Page;
PVFATFCB rcFcb;
BOOLEAN Found;
UNICODE_STRING PathNameU;
UNICODE_STRING FileToFindUpcase;
BOOLEAN WildCard;
DPRINT ("FindFile(Parent %x, FileToFind '%wZ', DirIndex: %d)\n",
Parent, FileToFindU, DirContext->DirIndex);
DPRINT ("FindFile: Path %wZ)\n",&Parent->PathNameU);
PathNameBufferLength = Parent->PathNameU.Length + LONGNAME_MAX_LENGTH + 2 * sizeof(WCHAR);
if (PathNameBufferLength > (USHRT_MAX - 2) * sizeof(WCHAR))
{
/* A valid filename can't be so long. Do as if the file doesn't exist. */
CHECKPOINT;
return STATUS_NO_SUCH_FILE;
}
PathNameBuffer = ExAllocatePool(NonPagedPool, PathNameBufferLength);
if (!PathNameBuffer)
{
CHECKPOINT1;
return STATUS_INSUFFICIENT_RESOURCES;
}
PathNameU.Buffer = PathNameBuffer;
PathNameU.Length = 0;
PathNameU.MaximumLength = sizeof(PathNameBuffer);
PathNameU.MaximumLength = PathNameBufferLength;
DirContext->LongNameU.Length = 0;
DirContext->ShortNameU.Length = 0;
@ -244,10 +261,21 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
Status = STATUS_UNSUCCESSFUL;
}
vfatReleaseFCB(DeviceExt, rcFcb);
ExFreePool(PathNameBuffer);
return Status;
}
}
/* FsRtlIsNameInExpression need the searched string to be upcase,
* even if IgnoreCase is specified */
Status = RtlUpcaseUnicodeString(&FileToFindUpcase, FileToFindU, TRUE);
if (!NT_SUCCESS(Status))
{
CHECKPOINT;
ExFreePool(PathNameBuffer);
return Status;
}
while(TRUE)
{
Status = DeviceExt->GetNextDirEntry(&Context, &Page, Parent, DirContext, First);
@ -263,14 +291,13 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
}
if (WildCard)
{
Found = FsRtlIsNameInExpression(FileToFindU, &DirContext->LongNameU, TRUE, NULL) ||
FsRtlIsNameInExpression(FileToFindU, &DirContext->ShortNameU, TRUE, NULL);
Found = FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->LongNameU, TRUE, NULL) ||
FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->ShortNameU, TRUE, NULL);
}
else
{
/* FIXME: Use FsRtlAreNamesEqual */
Found = RtlEqualUnicodeString(&DirContext->LongNameU, FileToFindU, TRUE) ||
RtlEqualUnicodeString(&DirContext->ShortNameU, FileToFindU, TRUE);
Found = FsRtlAreNamesEqual(&DirContext->LongNameU, FileToFindU, TRUE, NULL) ||
FsRtlAreNamesEqual(&DirContext->ShortNameU, FileToFindU, TRUE, NULL);
}
if (Found)
@ -300,6 +327,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
{
CcUnpinData(Context);
}
RtlFreeUnicodeString(&FileToFindUpcase);
ExFreePool(PathNameBuffer);
return STATUS_SUCCESS;
}
DirContext->DirIndex++;
@ -310,6 +339,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
CcUnpinData(Context);
}
RtlFreeUnicodeString(&FileToFindUpcase);
ExFreePool(PathNameBuffer);
return Status;
}

View file

@ -311,7 +311,7 @@ NTSTATUS DoQuery (PVFAT_IRP_CONTEXT IrpContext)
BOOLEAN First = FALSE;
BOOLEAN FirstCall;
VFAT_DIRENTRY_CONTEXT DirContext;
WCHAR LongNameBuffer[MAX_PATH];
WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH];
WCHAR ShortNameBuffer[13];
PIO_STACK_LOCATION Stack = IrpContext->Stack;
@ -344,7 +344,13 @@ NTSTATUS DoQuery (PVFAT_IRP_CONTEXT IrpContext)
}
/* Obtain the callers parameters */
#ifdef _MSC_VER
/* HACKHACK: Bug in the MS ntifs.h header:
* FileName is really a PUNICODE_STRING, not a PSTRING */
pSearchPattern = (PUNICODE_STRING)Stack->Parameters.QueryDirectory.FileName;
#else
pSearchPattern = Stack->Parameters.QueryDirectory.FileName;
#endif
FileInformationClass =
Stack->Parameters.QueryDirectory.FileInformationClass;
FileIndex = Stack->Parameters.QueryDirectory.FileIndex;

View file

@ -211,7 +211,7 @@ FATAddEntry (PDEVICE_EXTENSION DeviceExt,
BOOLEAN SpacesFound;
VFAT_DIRENTRY_CONTEXT DirContext;
WCHAR LongNameBuffer[MAX_PATH];
WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH];
WCHAR ShortNameBuffer[13];
DPRINT ("addEntry: Name='%wZ', Dir='%wZ'\n", NameU, &ParentFcb->PathNameU);
@ -370,16 +370,6 @@ FATAddEntry (PDEVICE_EXTENSION DeviceExt,
}
/* set dates and times */
KeQuerySystemTime (&SystemTime);
#if 0
{
TIME_FIELDS tf;
RtlTimeToTimeFields (&SystemTime, &tf);
DPRINT1("%d.%d.%d %02d:%02d:%02d.%03d '%wZ'\n",
tf.Day, tf.Month, tf.Year, tf.Hour,
tf.Minute, tf.Second, tf.Milliseconds,
NameU);
}
#endif
FsdSystemTimeToDosDateTime (DeviceExt, &SystemTime, &DirContext.DirEntry.Fat.CreationDate,
&DirContext.DirEntry.Fat.CreationTime);
DirContext.DirEntry.Fat.UpdateDate = DirContext.DirEntry.Fat.CreationDate;
@ -566,7 +556,7 @@ FATXAddEntry (PDEVICE_EXTENSION DeviceExt,
NameA.Length = 0;
NameA.MaximumLength = 42;
RtlUnicodeStringToOemString(&NameA, &DirContext.LongNameU, FALSE);
DirContext.DirEntry.FatX.FilenameLength = NameA.Length;
DirContext.DirEntry.FatX.FilenameLength = (unsigned char)NameA.Length;
/* set attributes */
DirContext.DirEntry.FatX.Attrib = ReqAttr;

View file

@ -14,7 +14,6 @@
/* ------------------------------------------------------- INCLUDES */
#include <ddk/ntddk.h>
#include <ntos/kefuncs.h>
#include <wchar.h>
#include <limits.h>
#include <rosrtl/string.h>
@ -26,7 +25,6 @@
/* -------------------------------------------------------- DEFINES */
#define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
#define TAG_FCB TAG('V', 'F', 'C', 'B')
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
@ -55,7 +53,7 @@ VOID
vfatSplitPathName(PUNICODE_STRING PathNameU, PUNICODE_STRING DirNameU, PUNICODE_STRING FileNameU)
{
PWCHAR pName;
ULONG Length = 0;
USHORT Length = 0;
pName = PathNameU->Buffer + PathNameU->Length / sizeof(WCHAR) - 1;
while (*pName != L'\\' && pName >= PathNameU->Buffer)
{
@ -79,9 +77,24 @@ vfatSplitPathName(PUNICODE_STRING PathNameU, PUNICODE_STRING DirNameU, PUNICODE_
VOID
vfatInitFcb(PVFATFCB Fcb, PUNICODE_STRING NameU)
{
ULONG PathNameBufferLength;
if (NameU)
PathNameBufferLength = NameU->Length + sizeof(WCHAR);
else
PathNameBufferLength = 0;
Fcb->PathNameBuffer = ExAllocatePool(NonPagedPool, PathNameBufferLength);
if (!Fcb->PathNameBuffer)
{
/* FIXME: what to do if no more memory? */
DPRINT1("Unable to initialize FCB for filename '%wZ'\n", NameU);
KEBUGCHECKEX(0, (ULONG_PTR)Fcb, (ULONG_PTR)NameU, 0, 0);
}
Fcb->PathNameU.Length = 0;
Fcb->PathNameU.Buffer = Fcb->PathNameBuffer;
Fcb->PathNameU.MaximumLength = sizeof(Fcb->PathNameBuffer);
Fcb->PathNameU.MaximumLength = PathNameBufferLength;
Fcb->ShortNameU.Length = 0;
Fcb->ShortNameU.Buffer = Fcb->ShortNameBuffer;
Fcb->ShortNameU.MaximumLength = sizeof(Fcb->ShortNameBuffer);
@ -146,6 +159,7 @@ VOID
vfatDestroyFCB(PVFATFCB pFCB)
{
FsRtlUninitializeFileLock(&pFCB->FileLock);
ExFreePool(pFCB->PathNameBuffer);
ExDeleteResourceLite(&pFCB->PagingIoResource);
ExDeleteResourceLite(&pFCB->MainResource);
ExFreeToNPagedLookasideList(&VfatGlobalData->FcbLookasideList, pFCB);
@ -431,20 +445,28 @@ vfatMakeFCBFromDirEntry(PVCB vcb,
PVFATFCB* fileFCB)
{
PVFATFCB rcFCB;
WCHAR pathName [MAX_PATH];
PWCHAR PathNameBuffer;
ULONG PathNameLength;
ULONG Size;
ULONG hash;
UNICODE_STRING NameU;
if (directoryFCB->PathNameU.Length + 2 * sizeof(WCHAR) +
+ DirContext->LongNameU.Length > MAX_PATH * sizeof(WCHAR))
PathNameLength = (directoryFCB->PathNameU.Length + 2 * sizeof(WCHAR)
+ DirContext->LongNameU.Length) * sizeof(WCHAR);
if (PathNameLength > (USHRT_MAX - 2) * sizeof(WCHAR))
{
return STATUS_OBJECT_NAME_INVALID;
}
NameU.Buffer = pathName;
PathNameBuffer = ExAllocatePool(NonPagedPool, PathNameLength);
if (!PathNameBuffer)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
NameU.Buffer = PathNameBuffer;
NameU.Length = 0;
NameU.MaximumLength = sizeof(pathName);
NameU.MaximumLength = PathNameLength;
RtlCopyUnicodeString(&NameU, &directoryFCB->PathNameU);
if (!vfatFCBIsRoot (directoryFCB))
@ -516,6 +538,7 @@ vfatMakeFCBFromDirEntry(PVCB vcb,
vfatAddFCBToTable (vcb, rcFCB);
*fileFCB = rcFCB;
ExFreePool(PathNameBuffer);
return STATUS_SUCCESS;
}
@ -553,7 +576,7 @@ vfatDirFindFile (PDEVICE_EXTENSION pDeviceExt,
PVOID Page = NULL;
BOOLEAN First = TRUE;
VFAT_DIRENTRY_CONTEXT DirContext;
WCHAR LongNameBuffer[MAX_PATH];
WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH];
WCHAR ShortNameBuffer[13];
BOOLEAN FoundLong = FALSE;
BOOLEAN FoundShort = FALSE;
@ -690,9 +713,9 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
vfatReleaseFCB (pVCB, FCB);
return STATUS_OBJECT_NAME_INVALID;
}
memmove(pFileNameU->Buffer + FCB->PathNameU.Length / sizeof(WCHAR),
RtlMoveMemory(pFileNameU->Buffer + FCB->PathNameU.Length / sizeof(WCHAR),
curr, pFileNameU->Length - Length);
pFileNameU->Length += FCB->PathNameU.Length - Length;
pFileNameU->Length += (USHORT)(FCB->PathNameU.Length - Length);
curr = pFileNameU->Buffer + FCB->PathNameU.Length / sizeof(WCHAR);
last = pFileNameU->Buffer + pFileNameU->Length / sizeof(WCHAR) - 1;
}
@ -751,9 +774,9 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
vfatReleaseFCB (pVCB, parentFCB);
return STATUS_OBJECT_NAME_INVALID;
}
memmove(prev + parentFCB->LongNameU.Length / sizeof(WCHAR), curr,
RtlMoveMemory(prev + parentFCB->LongNameU.Length / sizeof(WCHAR), curr,
pFileNameU->Length - (curr - pFileNameU->Buffer) * sizeof(WCHAR));
pFileNameU->Length += parentFCB->LongNameU.Length - Length;
pFileNameU->Length += (USHORT)(parentFCB->LongNameU.Length - Length);
curr = prev + parentFCB->LongNameU.Length / sizeof(WCHAR);
last = pFileNameU->Buffer + pFileNameU->Length / sizeof(WCHAR) - 1;
}

View file

@ -226,8 +226,9 @@ VfatSetDispositionInformation(PFILE_OBJECT FileObject,
PFILE_DISPOSITION_INFORMATION DispositionInfo)
{
NTSTATUS Status = STATUS_SUCCESS;
#ifdef DBG
PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
#endif
DPRINT ("FsdSetDispositionInformation()\n");
@ -248,7 +249,7 @@ VfatSetDispositionInformation(PFILE_OBJECT FileObject,
return STATUS_ACCESS_DENIED;
}
if (DispositionInfo->DoDeleteFile)
if (DispositionInfo->DeleteFile)
{
if (MmFlushImageSection (FileObject->SectionObjectPointer, MmFlushForDelete))
{

View file

@ -27,7 +27,6 @@
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <ntos/kefuncs.h>
#include <rosrtl/string.h>
#include <wchar.h>
@ -654,9 +653,9 @@ VfatGetVolumeBitmap(PVFAT_IRP_CONTEXT IrpContext)
static NTSTATUS
VfatGetRetrievalPointers(PVFAT_IRP_CONTEXT IrpContext)
{
PIO_STACK_LOCATION Stack;
PIO_STACK_LOCATION Stack;
LARGE_INTEGER Vcn;
PGET_RETRIEVAL_DESCRIPTOR RetrievalPointers;
PRETRIEVAL_POINTERS_BUFFER RetrievalPointers;
PFILE_OBJECT FileObject;
ULONG MaxExtentCount;
PVFATFCB Fcb;
@ -677,7 +676,7 @@ VfatGetRetrievalPointers(PVFAT_IRP_CONTEXT IrpContext)
return STATUS_INVALID_PARAMETER;
}
if (IrpContext->Irp->UserBuffer == NULL ||
Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(GET_RETRIEVAL_DESCRIPTOR) + sizeof(MAPPING_PAIR))
Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(RETRIEVAL_POINTERS_BUFFER))
{
return STATUS_BUFFER_TOO_SMALL;
}
@ -689,7 +688,7 @@ VfatGetRetrievalPointers(PVFAT_IRP_CONTEXT IrpContext)
Vcn = *(PLARGE_INTEGER)Stack->Parameters.DeviceIoControl.Type3InputBuffer;
RetrievalPointers = IrpContext->Irp->UserBuffer;
MaxExtentCount = ((Stack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(GET_RETRIEVAL_DESCRIPTOR)) / sizeof(MAPPING_PAIR));
MaxExtentCount = ((Stack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(RetrievalPointers->ExtentCount) - sizeof(RetrievalPointers->StartingVcn)) / sizeof(RetrievalPointers->Extents[0]));
if (Vcn.QuadPart >= Fcb->RFCB.AllocationSize.QuadPart / DeviceExt->FatInfo.BytesPerCluster)
@ -707,11 +706,12 @@ VfatGetRetrievalPointers(PVFAT_IRP_CONTEXT IrpContext)
goto ByeBye;
}
RetrievalPointers->StartVcn = Vcn.QuadPart;
RetrievalPointers->NumberOfPairs = 0;
RetrievalPointers->Pair[0].Lcn = CurrentCluster - 2;
RetrievalPointers->StartingVcn = Vcn;
RetrievalPointers->ExtentCount = 0;
RetrievalPointers->Extents[0].Lcn.u.HighPart = 0;
RetrievalPointers->Extents[0].Lcn.u.LowPart = CurrentCluster - 2;
LastCluster = 0;
while (CurrentCluster != 0xffffffff && RetrievalPointers->NumberOfPairs < MaxExtentCount)
while (CurrentCluster != 0xffffffff && RetrievalPointers->ExtentCount < MaxExtentCount)
{
LastCluster = CurrentCluster;
@ -724,16 +724,17 @@ VfatGetRetrievalPointers(PVFAT_IRP_CONTEXT IrpContext)
if (LastCluster + 1 != CurrentCluster)
{
RetrievalPointers->Pair[RetrievalPointers->NumberOfPairs].Vcn = Vcn.QuadPart;
RetrievalPointers->NumberOfPairs++;
if (RetrievalPointers->NumberOfPairs < MaxExtentCount)
RetrievalPointers->Extents[RetrievalPointers->ExtentCount].NextVcn = Vcn;
RetrievalPointers->ExtentCount++;
if (RetrievalPointers->ExtentCount < MaxExtentCount)
{
RetrievalPointers->Pair[RetrievalPointers->NumberOfPairs].Lcn = CurrentCluster - 2;
RetrievalPointers->Extents[RetrievalPointers->ExtentCount].Lcn.u.HighPart = 0;
RetrievalPointers->Extents[RetrievalPointers->ExtentCount].Lcn.u.LowPart = CurrentCluster - 2;
}
}
}
IrpContext->Irp->IoStatus.Information = sizeof(GET_RETRIEVAL_DESCRIPTOR) + sizeof(MAPPING_PAIR) * RetrievalPointers->NumberOfPairs;
IrpContext->Irp->IoStatus.Information = sizeof(RETRIEVAL_POINTERS_BUFFER) + (sizeof(RetrievalPointers->Extents[0]) * (RetrievalPointers->ExtentCount - 1));
Status = STATUS_SUCCESS;
ByeBye:
@ -757,7 +758,7 @@ VfatRosQueryLcnMapping(PVFAT_IRP_CONTEXT IrpContext)
PROS_QUERY_LCN_MAPPING LcnQuery;
PIO_STACK_LOCATION Stack;
DPRINT("VfatGetRetrievalPointers(IrpContext %x)\n", IrpContext);
DPRINT("VfatRosQueryLcnMapping(IrpContext %x)\n", IrpContext);
DeviceExt = IrpContext->DeviceExt;
Stack = IrpContext->Stack;

View file

@ -38,9 +38,9 @@ TARGET_CLEAN = $(DEP_FILES) *.o *.sys *.sym
include $(PATH_TO_TOP)/config
ifeq ($(DBG), 1)
TARGET_CFLAGS = -Wall -Werror -g
TARGET_CFLAGS = -D__USE_W32API -Wall -Werror -g
else
TARGET_CFLAGS = -Wall -Werror -O3 -fno-strict-aliasing
TARGET_CFLAGS = -D__USE_W32API -Wall -Werror -O3 -fno-strict-aliasing
endif
include $(PATH_TO_TOP)/rules.mak

View file

@ -13,7 +13,6 @@
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <ntos/kefuncs.h>
#include <wchar.h>
#include <ntos/minmax.h>

View file

@ -1,6 +1,27 @@
/* $Id$ */
#include <ddk/ntifs.h>
#include <ddk/ntdddisk.h>
#undef DeleteFile /* FIXME */
#define USE_ROS_CC_AND_FS
/* FIXME */
#ifdef __USE_W32API
NTSTATUS NTAPI RtlOemStringToUnicodeString(PUNICODE_STRING, CONST STRING *, BOOLEAN);
NTSTATUS NTAPI RtlDowncaseUnicodeString(PUNICODE_STRING, PCUNICODE_STRING, BOOLEAN);
NTSTATUS NTAPI RtlUnicodeStringToOemString(POEM_STRING, PCUNICODE_STRING, BOOLEAN);
#endif
#ifdef USE_ROS_CC_AND_FS
NTSTATUS STDCALL CcRosInitializeFileCache(PFILE_OBJECT, ULONG);
NTSTATUS STDCALL CcRosReleaseFileCache(PFILE_OBJECT);
#define FSCTL_ROS_QUERY_LCN_MAPPING CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 63, METHOD_BUFFERED, FILE_ANY_ACCESS)
typedef struct _ROS_QUERY_LCN_MAPPING { LARGE_INTEGER LcnDiskOffset; } ROS_QUERY_LCN_MAPPING, *PROS_QUERY_LCN_MAPPING;
#endif
#define KEBUGCHECK(a) DbgPrint("KeBugCheck at %s:%i\n",__FILE__,__LINE__), KeBugCheck(a)
#define KEBUGCHECKEX(a,b,c,d,e) DbgPrint("KeBugCheckEx at %s:%i\n",__FILE__,__LINE__), KeBugCheckEx(a,b,c,d,e)
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
@ -75,8 +96,10 @@ struct _FsInfoSector
typedef struct _BootSector BootSector;
#define VFAT_CASE_LOWER_BASE 8 // base is lower case
#define VFAT_CASE_LOWER_EXT 16 // extension is lower case
#define VFAT_CASE_LOWER_BASE 8 // base is lower case
#define VFAT_CASE_LOWER_EXT 16 // extension is lower case
#define LONGNAME_MAX_LENGTH 256 // max length for a long filename
#define ENTRY_DELETED(DeviceExt, DirEntry) ((DeviceExt)->Flags & VCB_IS_FATX ? FATX_ENTRY_DELETED(&((DirEntry)->FatX)) : FAT_ENTRY_DELETED(&((DirEntry)->Fat)))
#define ENTRY_VOLUME(DeviceExt, DirEntry) ((DeviceExt)->Flags & VCB_IS_FATX ? FATX_ENTRY_VOLUME(&((DirEntry)->FatX)) : FAT_ENTRY_VOLUME(&((DirEntry)->Fat)))
@ -284,7 +307,7 @@ typedef struct _VFATFCB
UNICODE_STRING PathNameU;
/* buffer for PathNameU */
WCHAR PathNameBuffer[MAX_PATH];
PWCHAR PathNameBuffer;
/* buffer for ShortNameU */
WCHAR ShortNameBuffer[13];