Make the remaning code match the current formatting instead of being really ugly, and make some changes to IoCreateFileStreamObject (which is wrong anyways, since it's doing what *Lite should do)

svn path=/trunk/; revision=15178
This commit is contained in:
Alex Ionescu 2005-05-09 04:31:04 +00:00
parent 834acf81da
commit 37707ad1a6

View file

@ -4,7 +4,8 @@
* FILE: ntoskrnl/io/file.c * FILE: ntoskrnl/io/file.c
* PURPOSE: I/O File Object & NT File Handle Access/Managment of Files. * PURPOSE: I/O File Object & NT File Handle Access/Managment of Files.
* *
* PROGRAMMERS: David Welch (welch@mcmail.com) * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
* David Welch (welch@mcmail.com)
*/ */
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
@ -767,6 +768,7 @@ IoCreateFile(OUT PHANDLE FileHandle,
ObDereferenceObject (DeviceObject); ObDereferenceObject (DeviceObject);
return STATUS_OBJECT_NAME_COLLISION; return STATUS_OBJECT_NAME_COLLISION;
} }
/* FIXME: wt... */
FileObject = IoCreateStreamFileObject(NULL, DeviceObject); FileObject = IoCreateStreamFileObject(NULL, DeviceObject);
ObDereferenceObject (DeviceObject); ObDereferenceObject (DeviceObject);
} }
@ -997,55 +999,50 @@ STDCALL
IoCreateStreamFileObject(PFILE_OBJECT FileObject, IoCreateStreamFileObject(PFILE_OBJECT FileObject,
PDEVICE_OBJECT DeviceObject) PDEVICE_OBJECT DeviceObject)
{ {
PFILE_OBJECT CreatedFileObject; PFILE_OBJECT CreatedFileObject;
NTSTATUS Status; NTSTATUS Status;
/* FIXME: This function should call ObInsertObject. The "Lite" version
doesnt. This function is also called from IoCreateFile for some
reason. These hacks need to be removed.
*/
DPRINT("IoCreateStreamFileObject(FileObject %x, DeviceObject %x)\n", DPRINT("IoCreateStreamFileObject(FileObject %x, DeviceObject %x)\n",
FileObject, DeviceObject); FileObject, DeviceObject);
PAGED_CODE();
ASSERT_IRQL(PASSIVE_LEVEL); /* Create the File Object */
Status = ObCreateObject(KernelMode,
Status = ObCreateObject(KernelMode, IoFileObjectType,
IoFileObjectType, NULL,
NULL, KernelMode,
KernelMode, NULL,
NULL, sizeof(FILE_OBJECT),
sizeof(FILE_OBJECT), 0,
0, 0,
0, (PVOID*)&CreatedFileObject);
(PVOID*)&CreatedFileObject); if (!NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{ {
DPRINT("Could not create FileObject\n"); DPRINT1("Could not create FileObject\n");
return (NULL); return (NULL);
} }
if (FileObject != NULL) /* Choose Device Object */
{ if (FileObject) DeviceObject = FileObject->DeviceObject;
DeviceObject = FileObject->DeviceObject; DPRINT("DeviceObject %x\n", DeviceObject);
}
DeviceObject = IoGetAttachedDevice(DeviceObject); /* Set File Object Data */
CreatedFileObject->DeviceObject = DeviceObject;
CreatedFileObject->Vpb = DeviceObject->Vpb;
CreatedFileObject->Type = IO_TYPE_FILE;
CreatedFileObject->Flags = FO_STREAM_FILE;
DPRINT("DeviceObject %x\n", DeviceObject); /* Initialize Lock and Event */
KeInitializeEvent(&CreatedFileObject->Event, NotificationEvent, FALSE);
KeInitializeEvent(&CreatedFileObject->Lock, SynchronizationEvent, TRUE);
if (DeviceObject->Vpb && /* Return file */
DeviceObject->Vpb->DeviceObject) return CreatedFileObject;
{
CreatedFileObject->DeviceObject = DeviceObject->Vpb->DeviceObject;
}
else
{
CreatedFileObject->DeviceObject = DeviceObject;
}
CreatedFileObject->Vpb = DeviceObject->Vpb;
CreatedFileObject->Type = IO_TYPE_FILE;
CreatedFileObject->Flags |= FO_DIRECT_DEVICE_OPEN;
// shouldn't we initialize the lock event, and several other things here too?
KeInitializeEvent(&CreatedFileObject->Event, NotificationEvent, FALSE);
KeInitializeEvent(&CreatedFileObject->Lock, SynchronizationEvent, TRUE);
return CreatedFileObject;
} }
/* /*
@ -1390,41 +1387,48 @@ NtCreateMailslotFile(OUT PHANDLE FileHandle,
IN ULONG MaxMessageSize, IN ULONG MaxMessageSize,
IN PLARGE_INTEGER TimeOut) IN PLARGE_INTEGER TimeOut)
{ {
MAILSLOT_CREATE_PARAMETERS Buffer; MAILSLOT_CREATE_PARAMETERS Buffer;
DPRINT("NtCreateMailslotFile(FileHandle %x, DesiredAccess %x, " DPRINT("NtCreateMailslotFile(FileHandle %x, DesiredAccess %x, "
"ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %S)\n", "ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %S)\n",
FileHandle,DesiredAccess,ObjectAttributes, FileHandle,DesiredAccess,ObjectAttributes,
ObjectAttributes->ObjectName->Buffer); ObjectAttributes->ObjectName->Buffer);
PAGED_CODE();
ASSERT_IRQL(PASSIVE_LEVEL); /* Check for Timeout */
if (TimeOut)
if (TimeOut != NULL) {
{ /* Enable it */
Buffer.ReadTimeout.QuadPart = TimeOut->QuadPart; Buffer.TimeoutSpecified = TRUE;
Buffer.TimeoutSpecified = TRUE;
} /* FIXME: Add SEH */
else Buffer.ReadTimeout = *TimeOut;
{ }
Buffer.TimeoutSpecified = FALSE; else
} {
Buffer.MailslotQuota = MailslotQuota; /* No timeout */
Buffer.MaximumMessageSize = MaxMessageSize; Buffer.TimeoutSpecified = FALSE;
}
/* Set Settings */
Buffer.MailslotQuota = MailslotQuota;
Buffer.MaximumMessageSize = MaxMessageSize;
return IoCreateFile(FileHandle, /* Call I/O */
DesiredAccess, return IoCreateFile(FileHandle,
ObjectAttributes, DesiredAccess,
IoStatusBlock, ObjectAttributes,
NULL, IoStatusBlock,
FILE_ATTRIBUTE_NORMAL, NULL,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_ATTRIBUTE_NORMAL,
FILE_CREATE, FILE_SHARE_READ | FILE_SHARE_WRITE,
CreateOptions, FILE_CREATE,
NULL, CreateOptions,
0, NULL,
CreateFileTypeMailslot, 0,
(PVOID)&Buffer, CreateFileTypeMailslot,
0); (PVOID)&Buffer,
0);
} }
NTSTATUS NTSTATUS
@ -1444,45 +1448,52 @@ NtCreateNamedPipeFile(PHANDLE FileHandle,
ULONG OutboundQuota, ULONG OutboundQuota,
PLARGE_INTEGER DefaultTimeout) PLARGE_INTEGER DefaultTimeout)
{ {
NAMED_PIPE_CREATE_PARAMETERS Buffer; NAMED_PIPE_CREATE_PARAMETERS Buffer;
DPRINT("NtCreateNamedPipeFile(FileHandle %x, DesiredAccess %x, " DPRINT("NtCreateNamedPipeFile(FileHandle %x, DesiredAccess %x, "
"ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %S)\n", "ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %S)\n",
FileHandle,DesiredAccess,ObjectAttributes, FileHandle,DesiredAccess,ObjectAttributes,
ObjectAttributes->ObjectName->Buffer); ObjectAttributes->ObjectName->Buffer);
PAGED_CODE();
ASSERT_IRQL(PASSIVE_LEVEL); /* Check for Timeout */
if (DefaultTimeout)
if (DefaultTimeout != NULL)
{ {
Buffer.DefaultTimeout.QuadPart = DefaultTimeout->QuadPart; /* Enable it */
Buffer.TimeoutSpecified = TRUE; Buffer.TimeoutSpecified = TRUE;
/* FIXME: Add SEH */
Buffer.DefaultTimeout = *DefaultTimeout;
} }
else else
{ {
Buffer.TimeoutSpecified = FALSE; /* No timeout */
Buffer.TimeoutSpecified = FALSE;
} }
Buffer.NamedPipeType = NamedPipeType;
Buffer.ReadMode = ReadMode; /* Set Settings */
Buffer.CompletionMode = CompletionMode; Buffer.NamedPipeType = NamedPipeType;
Buffer.MaximumInstances = MaximumInstances; Buffer.ReadMode = ReadMode;
Buffer.InboundQuota = InboundQuota; Buffer.CompletionMode = CompletionMode;
Buffer.OutboundQuota = OutboundQuota; Buffer.MaximumInstances = MaximumInstances;
Buffer.InboundQuota = InboundQuota;
Buffer.OutboundQuota = OutboundQuota;
return IoCreateFile(FileHandle, /* Call I/O */
DesiredAccess, return IoCreateFile(FileHandle,
ObjectAttributes, DesiredAccess,
IoStatusBlock, ObjectAttributes,
NULL, IoStatusBlock,
FILE_ATTRIBUTE_NORMAL, NULL,
ShareAccess, FILE_ATTRIBUTE_NORMAL,
CreateDisposition, ShareAccess,
CreateOptions, CreateDisposition,
NULL, CreateOptions,
0, NULL,
CreateFileTypeNamedPipe, 0,
(PVOID)&Buffer, CreateFileTypeNamedPipe,
0); (PVOID)&Buffer,
0);
} }
/* /*
@ -1513,8 +1524,8 @@ NTSTATUS
STDCALL STDCALL
NtFlushWriteBuffer(VOID) NtFlushWriteBuffer(VOID)
{ {
KeFlushWriteBuffer(); KeFlushWriteBuffer();
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/* /*
@ -1960,36 +1971,36 @@ STDCALL
NtQueryAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes, NtQueryAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes,
OUT PFILE_BASIC_INFORMATION FileInformation) OUT PFILE_BASIC_INFORMATION FileInformation)
{ {
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
HANDLE FileHandle; HANDLE FileHandle;
NTSTATUS Status; NTSTATUS Status;
/* Open the file */ /* Open the file */
Status = ZwOpenFile (&FileHandle, Status = ZwOpenFile(&FileHandle,
SYNCHRONIZE | FILE_READ_ATTRIBUTES, SYNCHRONIZE | FILE_READ_ATTRIBUTES,
ObjectAttributes, ObjectAttributes,
&IoStatusBlock, &IoStatusBlock,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_SYNCHRONOUS_IO_NONALERT); FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS (Status)) if (!NT_SUCCESS (Status))
{ {
DPRINT ("ZwOpenFile() failed (Status %lx)\n", Status); DPRINT ("ZwOpenFile() failed (Status %lx)\n", Status);
return Status; return Status;
} }
/* Get file attributes */ /* Get file attributes */
Status = ZwQueryInformationFile (FileHandle, Status = ZwQueryInformationFile(FileHandle,
&IoStatusBlock, &IoStatusBlock,
FileInformation, FileInformation,
sizeof(FILE_BASIC_INFORMATION), sizeof(FILE_BASIC_INFORMATION),
FileBasicInformation); FileBasicInformation);
ZwClose (FileHandle); if (!NT_SUCCESS (Status))
if (!NT_SUCCESS (Status))
{ {
DPRINT ("ZwQueryInformationFile() failed (Status %lx)\n", Status); DPRINT ("ZwQueryInformationFile() failed (Status %lx)\n", Status);
} }
return Status; ZwClose(FileHandle);
return Status;
} }
/* /*
@ -2184,36 +2195,36 @@ STDCALL
NtQueryFullAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes, NtQueryFullAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes,
OUT PFILE_NETWORK_OPEN_INFORMATION FileInformation) OUT PFILE_NETWORK_OPEN_INFORMATION FileInformation)
{ {
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
HANDLE FileHandle; HANDLE FileHandle;
NTSTATUS Status; NTSTATUS Status;
/* Open the file */ /* Open the file */
Status = ZwOpenFile (&FileHandle, Status = ZwOpenFile(&FileHandle,
SYNCHRONIZE | FILE_READ_ATTRIBUTES, SYNCHRONIZE | FILE_READ_ATTRIBUTES,
ObjectAttributes, ObjectAttributes,
&IoStatusBlock, &IoStatusBlock,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_SYNCHRONOUS_IO_NONALERT); FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS (Status)) if (!NT_SUCCESS (Status))
{ {
DPRINT ("ZwOpenFile() failed (Status %lx)\n", Status); DPRINT ("ZwOpenFile() failed (Status %lx)\n", Status);
return Status; return Status;
} }
/* Get file attributes */ /* Get file attributes */
Status = ZwQueryInformationFile (FileHandle, Status = ZwQueryInformationFile(FileHandle,
&IoStatusBlock, &IoStatusBlock,
FileInformation, FileInformation,
sizeof(FILE_NETWORK_OPEN_INFORMATION), sizeof(FILE_NETWORK_OPEN_INFORMATION),
FileNetworkOpenInformation); FileNetworkOpenInformation);
ZwClose (FileHandle); if (!NT_SUCCESS (Status))
if (!NT_SUCCESS (Status))
{ {
DPRINT ("ZwQueryInformationFile() failed (Status %lx)\n", Status); DPRINT ("ZwQueryInformationFile() failed (Status %lx)\n", Status);
} }
return Status; ZwClose (FileHandle);
return Status;
} }
/* /*