2002-04-15 20:39:49 +00:00
|
|
|
/*
|
2013-03-16 19:49:08 +00:00
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2002, 2003, 2004 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
2015-06-17 20:27:52 +00:00
|
|
|
* FILE: drivers/filesystems/cdfs/cdfs.c
|
2013-03-16 19:49:08 +00:00
|
|
|
* PURPOSE: CDROM (ISO 9660) filesystem driver
|
|
|
|
* PROGRAMMER: Art Yerkes
|
|
|
|
* Eric Kohl
|
|
|
|
*/
|
2002-04-15 20:39:49 +00:00
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2005-07-20 02:52:52 +00:00
|
|
|
#include "cdfs.h"
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2002-05-01 13:15:42 +00:00
|
|
|
#define NDEBUG
|
2002-04-15 20:39:49 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2002-05-01 13:15:42 +00:00
|
|
|
static NTSTATUS
|
2004-09-14 21:46:39 +00:00
|
|
|
CdfsMakeAbsoluteFilename(PFILE_OBJECT FileObject,
|
2009-02-03 14:50:50 +00:00
|
|
|
PUNICODE_STRING RelativeFileName,
|
|
|
|
PUNICODE_STRING AbsoluteFileName)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2011-07-05 13:55:39 +00:00
|
|
|
USHORT Length;
|
2009-02-03 14:50:50 +00:00
|
|
|
PFCB Fcb;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
DPRINT("try related for %wZ\n", RelativeFileName);
|
|
|
|
Fcb = FileObject->FsContext;
|
|
|
|
ASSERT(Fcb);
|
|
|
|
|
|
|
|
/* verify related object is a directory and target name
|
|
|
|
don't start with \. */
|
|
|
|
if ((Fcb->Entry.FileFlags & FILE_FLAG_DIRECTORY) == 0 ||
|
2015-11-16 11:01:36 +00:00
|
|
|
(RelativeFileName->Length >= sizeof(WCHAR) &&
|
|
|
|
RelativeFileName->Buffer[0] == L'\\'))
|
2002-05-01 13:15:42 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2002-05-01 13:15:42 +00:00
|
|
|
}
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
/* construct absolute path name */
|
2014-04-18 21:40:02 +00:00
|
|
|
Length = Fcb->PathName.Length +
|
2009-02-03 14:50:50 +00:00
|
|
|
sizeof(WCHAR) +
|
|
|
|
RelativeFileName->Length +
|
|
|
|
sizeof(WCHAR);
|
|
|
|
AbsoluteFileName->Length = 0;
|
|
|
|
AbsoluteFileName->MaximumLength = Length;
|
2015-03-27 18:03:39 +00:00
|
|
|
AbsoluteFileName->Buffer = ExAllocatePoolWithTag(NonPagedPool, Length, CDFS_FILENAME_TAG);
|
2009-02-03 14:50:50 +00:00
|
|
|
if (AbsoluteFileName->Buffer == NULL)
|
2002-05-01 13:15:42 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2004-09-14 21:46:39 +00:00
|
|
|
}
|
|
|
|
|
2014-04-18 21:40:02 +00:00
|
|
|
Status = RtlAppendUnicodeStringToString(AbsoluteFileName,
|
|
|
|
&Fcb->PathName);
|
2009-02-03 14:50:50 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2004-09-14 21:46:39 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
RtlFreeUnicodeString(AbsoluteFileName);
|
|
|
|
return Status;
|
2002-05-01 13:15:42 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
if (!CdfsFCBIsRoot(Fcb))
|
2004-09-14 21:46:39 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
Status = RtlAppendUnicodeToString(AbsoluteFileName,
|
|
|
|
L"\\");
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
RtlFreeUnicodeString(AbsoluteFileName);
|
|
|
|
return Status;
|
|
|
|
}
|
2004-09-14 21:46:39 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
Status = RtlAppendUnicodeStringToString(AbsoluteFileName,
|
|
|
|
RelativeFileName);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2004-09-14 21:46:39 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
RtlFreeUnicodeString(AbsoluteFileName);
|
|
|
|
return Status;
|
2004-09-14 21:46:39 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
return STATUS_SUCCESS;
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-02-03 14:50:50 +00:00
|
|
|
* FUNCTION: Opens a file
|
|
|
|
*/
|
2004-09-14 21:46:39 +00:00
|
|
|
static NTSTATUS
|
|
|
|
CdfsOpenFile(PDEVICE_EXTENSION DeviceExt,
|
2009-02-03 14:50:50 +00:00
|
|
|
PFILE_OBJECT FileObject,
|
|
|
|
PUNICODE_STRING FileName)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
PFCB ParentFcb;
|
|
|
|
PFCB Fcb;
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING AbsFileName;
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2013-05-11 09:24:31 +00:00
|
|
|
DPRINT("CdfsOpenFile(%p, %p, %wZ)\n", DeviceExt, FileObject, FileName);
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
if (FileObject->RelatedFileObject)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
DPRINT("Converting relative filename to absolute filename\n");
|
2002-05-01 13:15:42 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
Status = CdfsMakeAbsoluteFilename(FileObject->RelatedFileObject,
|
|
|
|
FileName,
|
|
|
|
&AbsFileName);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
2003-11-10 11:32:08 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
FileName = &AbsFileName;
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
Status = CdfsDeviceIoControl (DeviceExt->StorageDevice,
|
|
|
|
IOCTL_CDROM_CHECK_VERIFY,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
FALSE);
|
|
|
|
DPRINT ("Status %lx\n", Status);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-11-09 11:20:28 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
DPRINT1 ("Status %lx\n", Status);
|
|
|
|
return Status;
|
2003-11-09 11:20:28 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
DPRINT("PathName to open: %wZ\n", FileName);
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
/* try first to find an existing FCB in memory */
|
|
|
|
DPRINT("Checking for existing FCB in memory\n");
|
|
|
|
Fcb = CdfsGrabFCBFromTable(DeviceExt,
|
|
|
|
FileName);
|
|
|
|
if (Fcb == NULL)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
DPRINT("No existing FCB found, making a new one if file exists.\n");
|
|
|
|
Status = CdfsGetFCBForFile(DeviceExt,
|
|
|
|
&ParentFcb,
|
|
|
|
&Fcb,
|
|
|
|
FileName);
|
|
|
|
if (ParentFcb != NULL)
|
|
|
|
{
|
|
|
|
CdfsReleaseFCB(DeviceExt,
|
|
|
|
ParentFcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NT_SUCCESS (Status))
|
|
|
|
{
|
|
|
|
DPRINT("Could not make a new FCB, status: %x\n", Status);
|
|
|
|
|
|
|
|
if (FileName == &AbsFileName)
|
|
|
|
RtlFreeUnicodeString(&AbsFileName);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
DPRINT("Attaching FCB to fileObject\n");
|
|
|
|
Status = CdfsAttachFCBToFileObject(DeviceExt,
|
|
|
|
Fcb,
|
|
|
|
FileObject);
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
if ((FileName == &AbsFileName) && AbsFileName.Buffer)
|
2015-03-27 18:03:39 +00:00
|
|
|
ExFreePoolWithTag(AbsFileName.Buffer, CDFS_FILENAME_TAG);
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
return Status;
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-02-03 14:50:50 +00:00
|
|
|
* FUNCTION: Opens a file
|
|
|
|
*/
|
2004-09-14 21:46:39 +00:00
|
|
|
static NTSTATUS
|
|
|
|
CdfsCreateFile(PDEVICE_OBJECT DeviceObject,
|
2009-02-03 14:50:50 +00:00
|
|
|
PIRP Irp)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
ULONG RequestedDisposition;
|
|
|
|
ULONG RequestedOptions;
|
|
|
|
PFCB Fcb;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
DPRINT("CdfsCreateFile() called\n");
|
|
|
|
|
|
|
|
DeviceExt = DeviceObject->DeviceExtension;
|
|
|
|
ASSERT(DeviceExt);
|
|
|
|
Stack = IoGetCurrentIrpStackLocation (Irp);
|
|
|
|
ASSERT(Stack);
|
|
|
|
|
|
|
|
RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff);
|
|
|
|
RequestedOptions = Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
|
|
|
|
DPRINT("RequestedDisposition %x, RequestedOptions %x\n",
|
|
|
|
RequestedDisposition, RequestedOptions);
|
|
|
|
|
|
|
|
FileObject = Stack->FileObject;
|
|
|
|
|
|
|
|
if (RequestedDisposition == FILE_CREATE ||
|
|
|
|
RequestedDisposition == FILE_OVERWRITE_IF ||
|
|
|
|
RequestedDisposition == FILE_SUPERSEDE)
|
2002-05-09 15:53:02 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
return STATUS_ACCESS_DENIED;
|
2002-05-09 15:53:02 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
Status = CdfsOpenFile(DeviceExt,
|
|
|
|
FileObject,
|
|
|
|
&FileObject->FileName);
|
|
|
|
if (NT_SUCCESS(Status))
|
2002-09-15 22:21:40 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
Fcb = FileObject->FsContext;
|
|
|
|
|
|
|
|
/* Check whether the file has the requested attributes */
|
|
|
|
if (RequestedOptions & FILE_NON_DIRECTORY_FILE && CdfsFCBIsDirectory(Fcb))
|
|
|
|
{
|
|
|
|
CdfsCloseFile (DeviceExt, FileObject);
|
|
|
|
return STATUS_FILE_IS_A_DIRECTORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RequestedOptions & FILE_DIRECTORY_FILE && !CdfsFCBIsDirectory(Fcb))
|
|
|
|
{
|
|
|
|
CdfsCloseFile (DeviceExt, FileObject);
|
|
|
|
return STATUS_NOT_A_DIRECTORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the directory containing the file to open doesn't exist then
|
|
|
|
* fail immediately
|
|
|
|
*/
|
|
|
|
Irp->IoStatus.Information = (NT_SUCCESS(Status)) ? FILE_OPENED : 0;
|
|
|
|
|
|
|
|
return Status;
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-29 20:14:45 +00:00
|
|
|
NTSTATUS NTAPI
|
2015-06-01 19:22:42 +00:00
|
|
|
CdfsCreate(
|
|
|
|
PCDFS_IRP_CONTEXT IrpContext)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2015-06-01 19:22:42 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2009-02-03 14:50:50 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
NTSTATUS Status;
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2015-06-01 19:22:42 +00:00
|
|
|
DPRINT("CdfsCreate()\n");
|
|
|
|
|
|
|
|
ASSERT(IrpContext);
|
|
|
|
|
|
|
|
DeviceObject = IrpContext->DeviceObject;
|
2017-08-16 20:04:55 +00:00
|
|
|
if (DeviceObject == CdfsGlobalData->CdFsDeviceObject || DeviceObject == CdfsGlobalData->HddFsDeviceObject)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
/* DeviceObject represents FileSystem instead of logical volume */
|
|
|
|
DPRINT("Opening file system\n");
|
2015-06-01 19:22:42 +00:00
|
|
|
IrpContext->Irp->IoStatus.Information = FILE_OPENED;
|
|
|
|
return STATUS_SUCCESS;
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
DeviceExt = DeviceObject->DeviceExtension;
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2008-04-22 20:44:34 +00:00
|
|
|
KeEnterCriticalRegion();
|
2009-02-03 14:50:50 +00:00
|
|
|
ExAcquireResourceExclusiveLite(&DeviceExt->DirResource,
|
|
|
|
TRUE);
|
|
|
|
Status = CdfsCreateFile(DeviceObject,
|
2015-06-01 19:22:42 +00:00
|
|
|
IrpContext->Irp);
|
2009-02-03 14:50:50 +00:00
|
|
|
ExReleaseResourceLite(&DeviceExt->DirResource);
|
2008-04-22 20:44:34 +00:00
|
|
|
KeLeaveCriticalRegion();
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
return Status;
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
2002-09-15 22:21:40 +00:00
|
|
|
/* EOF */
|