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;
DPRINT("IoCreateStreamFileObject(FileObject %x, DeviceObject %x)\n", /* FIXME: This function should call ObInsertObject. The "Lite" version
FileObject, DeviceObject); doesnt. This function is also called from IoCreateFile for some
reason. These hacks need to be removed.
*/
ASSERT_IRQL(PASSIVE_LEVEL); DPRINT("IoCreateStreamFileObject(FileObject %x, DeviceObject %x)\n",
FileObject, DeviceObject);
PAGED_CODE();
Status = ObCreateObject(KernelMode, /* Create the File Object */
IoFileObjectType, Status = ObCreateObject(KernelMode,
NULL, IoFileObjectType,
KernelMode, NULL,
NULL, KernelMode,
sizeof(FILE_OBJECT), NULL,
0, sizeof(FILE_OBJECT),
0, 0,
(PVOID*)&CreatedFileObject); 0,
if (!NT_SUCCESS(Status)) (PVOID*)&CreatedFileObject);
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);
DPRINT("DeviceObject %x\n", DeviceObject); /* Set File Object Data */
CreatedFileObject->DeviceObject = DeviceObject;
CreatedFileObject->Vpb = DeviceObject->Vpb;
CreatedFileObject->Type = IO_TYPE_FILE;
CreatedFileObject->Flags = FO_STREAM_FILE;
if (DeviceObject->Vpb && /* Initialize Lock and Event */
DeviceObject->Vpb->DeviceObject) KeInitializeEvent(&CreatedFileObject->Event, NotificationEvent, FALSE);
{ KeInitializeEvent(&CreatedFileObject->Lock, SynchronizationEvent, TRUE);
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? /* Return file */
KeInitializeEvent(&CreatedFileObject->Event, NotificationEvent, FALSE); return CreatedFileObject;
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)
{
/* Enable it */
Buffer.TimeoutSpecified = TRUE;
if (TimeOut != NULL) /* FIXME: Add SEH */
{ Buffer.ReadTimeout = *TimeOut;
Buffer.ReadTimeout.QuadPart = TimeOut->QuadPart; }
Buffer.TimeoutSpecified = TRUE; else
} {
else /* No timeout */
{ Buffer.TimeoutSpecified = FALSE;
Buffer.TimeoutSpecified = FALSE; }
}
Buffer.MailslotQuota = MailslotQuota;
Buffer.MaximumMessageSize = MaxMessageSize;
return IoCreateFile(FileHandle, /* Set Settings */
DesiredAccess, Buffer.MailslotQuota = MailslotQuota;
ObjectAttributes, Buffer.MaximumMessageSize = MaxMessageSize;
IoStatusBlock,
NULL, /* Call I/O */
FILE_ATTRIBUTE_NORMAL, return IoCreateFile(FileHandle,
FILE_SHARE_READ | FILE_SHARE_WRITE, DesiredAccess,
FILE_CREATE, ObjectAttributes,
CreateOptions, IoStatusBlock,
NULL, NULL,
0, FILE_ATTRIBUTE_NORMAL,
CreateFileTypeMailslot, FILE_SHARE_READ | FILE_SHARE_WRITE,
(PVOID)&Buffer, FILE_CREATE,
0); CreateOptions,
NULL,
0,
CreateFileTypeMailslot,
(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;
}
else
{
Buffer.TimeoutSpecified = FALSE;
}
Buffer.NamedPipeType = NamedPipeType;
Buffer.ReadMode = ReadMode;
Buffer.CompletionMode = CompletionMode;
Buffer.MaximumInstances = MaximumInstances;
Buffer.InboundQuota = InboundQuota;
Buffer.OutboundQuota = OutboundQuota;
return IoCreateFile(FileHandle, /* FIXME: Add SEH */
DesiredAccess, Buffer.DefaultTimeout = *DefaultTimeout;
ObjectAttributes, }
IoStatusBlock, else
NULL, {
FILE_ATTRIBUTE_NORMAL, /* No timeout */
ShareAccess, Buffer.TimeoutSpecified = FALSE;
CreateDisposition, }
CreateOptions,
NULL, /* Set Settings */
0, Buffer.NamedPipeType = NamedPipeType;
CreateFileTypeNamedPipe, Buffer.ReadMode = ReadMode;
(PVOID)&Buffer, Buffer.CompletionMode = CompletionMode;
0); Buffer.MaximumInstances = MaximumInstances;
Buffer.InboundQuota = InboundQuota;
Buffer.OutboundQuota = OutboundQuota;
/* Call I/O */
return IoCreateFile(FileHandle,
DesiredAccess,
ObjectAttributes,
IoStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
ShareAccess,
CreateDisposition,
CreateOptions,
NULL,
0,
CreateFileTypeNamedPipe,
(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;
} }
/* /*