[FORMATTING] - Fix formatting in IoCreateFile

svn path=/trunk/; revision=22868
This commit is contained in:
Alex Ionescu 2006-07-05 19:55:25 +00:00
parent 284101e016
commit 54c6ba2513

View file

@ -795,76 +795,10 @@ IoCheckQuotaBufferValidity(IN PFILE_QUOTA_INFORMATION QuotaBuffer,
} }
/* /*
* NAME EXPORTED
* IoCreateFile@56
*
* DESCRIPTION
* Either causes a new file or directory to be created, or it
* opens an existing file, device, directory or volume, giving
* the caller a handle for the file object. This handle can be
* used by subsequent calls to manipulate data within the file
* or the file object's state of attributes.
*
* ARGUMENTS
* FileHandle (OUT)
* Points to a variable which receives the file handle
* on return;
*
* DesiredAccess
* Desired access to the file;
*
* ObjectAttributes
* Structure describing the file;
*
* IoStatusBlock (OUT)
* Receives information about the operation on return;
*
* AllocationSize [OPTIONAL]
* Initial size of the file in bytes;
*
* FileAttributes
* Attributes to create the file with;
*
* ShareAccess
* Type of shared access the caller would like to the
* file;
*
* CreateDisposition
* Specifies what to do, depending on whether the
* file already exists;
*
* CreateOptions
* Options for creating a new file;
*
* EaBuffer [OPTIONAL]
* Undocumented;
*
* EaLength
* Undocumented;
*
* CreateFileType
* Type of file (normal, named pipe, mailslot) to create;
*
* ExtraCreateParameters [OPTIONAL]
* Additional creation data for named pipe and mailsots;
*
* Options
* Undocumented.
*
* RETURN VALUE
* Status
*
* NOTE
* Prototype taken from Bo Branten's ntifs.h v15.
* Description taken from old NtCreateFile's which is
* now a wrapper of this call.
*
* REVISIONS
*
* @implemented * @implemented
*/ */
NTSTATUS NTSTATUS
STDCALL NTAPI
IoCreateFile(OUT PHANDLE FileHandle, IoCreateFile(OUT PHANDLE FileHandle,
IN ACCESS_MASK DesiredAccess, IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_ATTRIBUTES ObjectAttributes,
@ -881,12 +815,11 @@ IoCreateFile(OUT PHANDLE FileHandle,
IN ULONG Options) IN ULONG Options)
{ {
PFILE_OBJECT FileObject = NULL; PFILE_OBJECT FileObject = NULL;
//PDEVICE_OBJECT DeviceObject;
PIRP Irp; PIRP Irp;
PEXTENDED_IO_STACK_LOCATION StackLoc; PEXTENDED_IO_STACK_LOCATION StackLoc;
IO_SECURITY_CONTEXT SecurityContext; IO_SECURITY_CONTEXT SecurityContext;
KPROCESSOR_MODE AccessMode; KPROCESSOR_MODE AccessMode;
HANDLE LocalHandle; HANDLE LocalHandle = 0;
LARGE_INTEGER SafeAllocationSize; LARGE_INTEGER SafeAllocationSize;
PVOID SystemEaBuffer = NULL; PVOID SystemEaBuffer = NULL;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
@ -895,23 +828,16 @@ IoCreateFile(OUT PHANDLE FileHandle,
KIRQL OldIrql; KIRQL OldIrql;
PKNORMAL_ROUTINE NormalRoutine; PKNORMAL_ROUTINE NormalRoutine;
PVOID NormalContext; PVOID NormalContext;
PAGED_CODE();
DPRINT("IoCreateFile(FileHandle 0x%p, DesiredAccess %x, "
"ObjectAttributes 0x%p ObjectAttributes->ObjectName->Buffer %S)\n",
FileHandle,DesiredAccess,ObjectAttributes,
ObjectAttributes->ObjectName->Buffer);
ASSERT_IRQL(PASSIVE_LEVEL);
if (IoStatusBlock == NULL || FileHandle == NULL)
return STATUS_ACCESS_VIOLATION;
LocalHandle = 0;
if(Options & IO_NO_PARAMETER_CHECKING) if(Options & IO_NO_PARAMETER_CHECKING)
{
AccessMode = KernelMode; AccessMode = KernelMode;
}
else else
{
AccessMode = ExGetPreviousMode(); AccessMode = ExGetPreviousMode();
}
if(AccessMode != KernelMode) if(AccessMode != KernelMode)
{ {
@ -921,31 +847,30 @@ IoCreateFile(OUT PHANDLE FileHandle,
ProbeForWrite(IoStatusBlock, ProbeForWrite(IoStatusBlock,
sizeof(IO_STATUS_BLOCK), sizeof(IO_STATUS_BLOCK),
sizeof(ULONG)); sizeof(ULONG));
if(AllocationSize != NULL) if (AllocationSize)
{ {
SafeAllocationSize = ProbeForReadLargeInteger(AllocationSize); SafeAllocationSize = ProbeForReadLargeInteger(AllocationSize);
} }
else else
{
SafeAllocationSize.QuadPart = 0; SafeAllocationSize.QuadPart = 0;
}
if(EaBuffer != NULL && EaLength > 0) if ((EaBuffer) && (EaLength))
{ {
ProbeForRead(EaBuffer, ProbeForRead(EaBuffer,
EaLength, EaLength,
sizeof(ULONG)); sizeof(ULONG));
/* marshal EaBuffer */ /* marshal EaBuffer */
SystemEaBuffer = ExAllocatePool(NonPagedPool, SystemEaBuffer = ExAllocatePool(NonPagedPool, EaLength);
EaLength); if(!SystemEaBuffer)
if(SystemEaBuffer == NULL)
{ {
Status = STATUS_INSUFFICIENT_RESOURCES; Status = STATUS_INSUFFICIENT_RESOURCES;
_SEH_LEAVE; _SEH_LEAVE;
} }
RtlCopyMemory(SystemEaBuffer, RtlCopyMemory(SystemEaBuffer, EaBuffer, EaLength);
EaBuffer,
EaLength);
} }
} }
_SEH_HANDLE _SEH_HANDLE
@ -954,22 +879,20 @@ IoCreateFile(OUT PHANDLE FileHandle,
} }
_SEH_END; _SEH_END;
if(!NT_SUCCESS(Status)) if(!NT_SUCCESS(Status)) return Status;
{
return Status;
}
} }
else else
{ {
if(AllocationSize != NULL) if (AllocationSize)
{
SafeAllocationSize = *AllocationSize; SafeAllocationSize = *AllocationSize;
else
SafeAllocationSize.QuadPart = 0;
if(EaBuffer != NULL && EaLength > 0)
{
SystemEaBuffer = EaBuffer;
} }
else
{
SafeAllocationSize.QuadPart = 0;
}
if ((EaBuffer) && (EaLength)) SystemEaBuffer = EaBuffer;
} }
if(Options & IO_CHECK_CREATE_PARAMETERS) if(Options & IO_CHECK_CREATE_PARAMETERS)
@ -987,7 +910,6 @@ IoCreateFile(OUT PHANDLE FileHandle,
DesiredAccess, DesiredAccess,
NULL, NULL,
&LocalHandle); &LocalHandle);
ObReferenceObjectByHandle(LocalHandle, ObReferenceObjectByHandle(LocalHandle,
DesiredAccess, DesiredAccess,
NULL, NULL,
@ -999,10 +921,6 @@ IoCreateFile(OUT PHANDLE FileHandle,
FileObject->Type = IO_TYPE_FILE; FileObject->Type = IO_TYPE_FILE;
FileObject->Size = sizeof(FILE_OBJECT); FileObject->Size = sizeof(FILE_OBJECT);
//
// stop stuff that should be in IopParseDevice
//
if (CreateOptions & if (CreateOptions &
(FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)) (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT))
{ {
@ -1034,12 +952,8 @@ IoCreateFile(OUT PHANDLE FileHandle,
{ {
FileObject->Flags |= FO_OPENED_CASE_SENSITIVE; FileObject->Flags |= FO_OPENED_CASE_SENSITIVE;
} }
/*
* FIXME: We should get the access state from Ob once this function becomes
* a parse routine once the Ob is refactored.
*/
SeCreateAccessState(&AccessState, &AuxData, FILE_ALL_ACCESS, NULL);
SeCreateAccessState(&AccessState, &AuxData, FILE_ALL_ACCESS, NULL);
SecurityContext.SecurityQos = NULL; /* ?? */ SecurityContext.SecurityQos = NULL; /* ?? */
SecurityContext.AccessState = &AccessState; SecurityContext.AccessState = &AccessState;
SecurityContext.DesiredAccess = DesiredAccess; SecurityContext.DesiredAccess = DesiredAccess;
@ -1048,15 +962,8 @@ IoCreateFile(OUT PHANDLE FileHandle,
KeInitializeEvent(&FileObject->Lock, SynchronizationEvent, TRUE); KeInitializeEvent(&FileObject->Lock, SynchronizationEvent, TRUE);
KeInitializeEvent(&FileObject->Event, NotificationEvent, FALSE); KeInitializeEvent(&FileObject->Event, NotificationEvent, FALSE);
DPRINT("FileObject 0x%p\n", FileObject);
DPRINT("FileObject->DeviceObject 0x%p\n", FileObject->DeviceObject);
/*
* Create a new IRP to hand to
* the FS driver: this may fail
* due to resource shortage.
*/
Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize, FALSE); Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize, FALSE);
if (Irp == NULL) if (!Irp)
{ {
ZwClose(LocalHandle); ZwClose(LocalHandle);
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
@ -1078,10 +985,6 @@ IoCreateFile(OUT PHANDLE FileHandle,
Irp->CancelRoutine = NULL; Irp->CancelRoutine = NULL;
Irp->Tail.Overlay.AuxiliaryBuffer = NULL; Irp->Tail.Overlay.AuxiliaryBuffer = NULL;
/*
* Get the stack location for the new
* IRP and prepare it.
*/
StackLoc = (PEXTENDED_IO_STACK_LOCATION)IoGetNextIrpStackLocation(Irp); StackLoc = (PEXTENDED_IO_STACK_LOCATION)IoGetNextIrpStackLocation(Irp);
StackLoc->Control = 0; StackLoc->Control = 0;
StackLoc->FileObject = FileObject; StackLoc->FileObject = FileObject;
@ -1115,15 +1018,7 @@ IoCreateFile(OUT PHANDLE FileHandle,
StackLoc->Parameters.Create.ShareAccess = ShareAccess; StackLoc->Parameters.Create.ShareAccess = ShareAccess;
StackLoc->Parameters.Create.SecurityContext = &SecurityContext; StackLoc->Parameters.Create.SecurityContext = &SecurityContext;
/*
* Now call the driver and
* possibly wait if it can
* not complete the request
* immediately.
*/
Status = IofCallDriver(FileObject->DeviceObject, Irp ); Status = IofCallDriver(FileObject->DeviceObject, Irp );
DPRINT("Status :%x\n", Status);
if (Status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
KeWaitForSingleObject(&FileObject->Event, KeWaitForSingleObject(&FileObject->Event,
@ -1145,9 +1040,9 @@ IoCreateFile(OUT PHANDLE FileHandle,
&NormalContext); &NormalContext);
KeLowerIrql(OldIrql); KeLowerIrql(OldIrql);
} }
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("Failing create request with status %x\n", Status);
FileObject->DeviceObject = NULL; FileObject->DeviceObject = NULL;
FileObject->Vpb = NULL; FileObject->Vpb = NULL;
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
@ -1166,15 +1061,11 @@ IoCreateFile(OUT PHANDLE FileHandle,
} }
/* cleanup EABuffer if captured */ /* cleanup EABuffer if captured */
if(AccessMode != KernelMode && SystemEaBuffer != NULL) if (AccessMode != KernelMode && (SystemEaBuffer))
{ {
ExFreePool(SystemEaBuffer); ExFreePool(SystemEaBuffer);
} }
ASSERT_IRQL(PASSIVE_LEVEL);
DPRINT("Finished IoCreateFile() (*FileHandle) 0x%p\n", (*FileHandle));
return Status; return Status;
} }