2005-08-24 18:29:45 +00:00
|
|
|
/*
|
1999-12-11 21:14:49 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
2003-10-11 17:51:56 +00:00
|
|
|
* FILE: drivers/fs/vfat/finfo.c
|
1999-12-11 21:14:49 +00:00
|
|
|
* PURPOSE: VFAT Filesystem
|
|
|
|
* PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
|
2004-12-05 16:31:51 +00:00
|
|
|
* Herve Poussineau (reactos@poussine.freesurf.fr)
|
1999-12-11 21:14:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include "vfat.h"
|
|
|
|
|
2005-01-25 21:10:42 +00:00
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
2005-05-08 02:16:32 +00:00
|
|
|
const char* FileInformationClassNames[] =
|
2005-01-25 21:10:42 +00:00
|
|
|
{
|
|
|
|
"??????",
|
|
|
|
"FileDirectoryInformation",
|
|
|
|
"FileFullDirectoryInformation",
|
|
|
|
"FileBothDirectoryInformation",
|
|
|
|
"FileBasicInformation",
|
|
|
|
"FileStandardInformation",
|
|
|
|
"FileInternalInformation",
|
|
|
|
"FileEaInformation",
|
|
|
|
"FileAccessInformation",
|
|
|
|
"FileNameInformation",
|
|
|
|
"FileRenameInformation",
|
|
|
|
"FileLinkInformation",
|
|
|
|
"FileNamesInformation",
|
|
|
|
"FileDispositionInformation",
|
|
|
|
"FilePositionInformation",
|
|
|
|
"FileFullEaInformation",
|
|
|
|
"FileModeInformation",
|
|
|
|
"FileAlignmentInformation",
|
|
|
|
"FileAllInformation",
|
|
|
|
"FileAllocationInformation",
|
|
|
|
"FileEndOfFileInformation",
|
|
|
|
"FileAlternateNameInformation",
|
|
|
|
"FileStreamInformation",
|
|
|
|
"FilePipeInformation",
|
|
|
|
"FilePipeLocalInformation",
|
|
|
|
"FilePipeRemoteInformation",
|
|
|
|
"FileMailslotQueryInformation",
|
|
|
|
"FileMailslotSetInformation",
|
|
|
|
"FileCompressionInformation",
|
|
|
|
"FileObjectIdInformation",
|
|
|
|
"FileCompletionInformation",
|
|
|
|
"FileMoveClusterInformation",
|
|
|
|
"FileQuotaInformation",
|
|
|
|
"FileReparsePointInformation",
|
|
|
|
"FileNetworkOpenInformation",
|
|
|
|
"FileAttributeTagInformation",
|
|
|
|
"FileTrackingInformation",
|
|
|
|
"FileIdBothDirectoryInformation",
|
|
|
|
"FileIdFullDirectoryInformation",
|
|
|
|
"FileValidDataLengthInformation",
|
|
|
|
"FileShortNameInformation",
|
|
|
|
"FileMaximumInformation"
|
|
|
|
};
|
|
|
|
|
1999-12-11 21:14:49 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2001-03-07 13:44:41 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatGetStandardInformation(PVFATFCB FCB,
|
2001-06-12 12:35:42 +00:00
|
|
|
PFILE_STANDARD_INFORMATION StandardInfo,
|
|
|
|
PULONG BufferLength)
|
1999-12-11 21:14:49 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the standard file information
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_STANDARD_INFORMATION))
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
|
1999-12-11 21:14:49 +00:00
|
|
|
/* PRECONDITION */
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(StandardInfo != NULL);
|
|
|
|
ASSERT(FCB != NULL);
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2004-05-23 13:34:32 +00:00
|
|
|
if (vfatFCBIsDirectory(FCB))
|
|
|
|
{
|
2005-08-24 18:29:45 +00:00
|
|
|
StandardInfo->AllocationSize.QuadPart = 0;
|
|
|
|
StandardInfo->EndOfFile.QuadPart = 0;
|
2004-05-23 13:34:32 +00:00
|
|
|
StandardInfo->Directory = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StandardInfo->AllocationSize = FCB->RFCB.AllocationSize;
|
|
|
|
StandardInfo->EndOfFile = FCB->RFCB.FileSize;
|
|
|
|
StandardInfo->Directory = FALSE;
|
|
|
|
}
|
2008-10-19 13:23:00 +00:00
|
|
|
StandardInfo->NumberOfLinks = 1;
|
2001-11-01 10:44:11 +00:00
|
|
|
StandardInfo->DeletePending = FCB->Flags & FCB_DELETE_PENDING ? TRUE : FALSE;
|
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
*BufferLength -= sizeof(FILE_STANDARD_INFORMATION);
|
|
|
|
return(STATUS_SUCCESS);
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 13:44:41 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatSetPositionInformation(PFILE_OBJECT FileObject,
|
2000-12-29 23:17:12 +00:00
|
|
|
PFILE_POSITION_INFORMATION PositionInfo)
|
1999-12-11 21:14:49 +00:00
|
|
|
{
|
2000-12-29 23:17:12 +00:00
|
|
|
DPRINT ("FsdSetPositionInformation()\n");
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2007-11-21 16:50:07 +00:00
|
|
|
DPRINT ("PositionInfo %p\n", PositionInfo);
|
2000-12-29 23:17:12 +00:00
|
|
|
DPRINT ("Setting position %d\n", PositionInfo->CurrentByteOffset.u.LowPart);
|
2004-11-06 13:44:57 +00:00
|
|
|
|
|
|
|
FileObject->CurrentByteOffset.QuadPart =
|
|
|
|
PositionInfo->CurrentByteOffset.QuadPart;
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
return (STATUS_SUCCESS);
|
|
|
|
}
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2001-03-07 13:44:41 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatGetPositionInformation(PFILE_OBJECT FileObject,
|
2000-12-29 23:17:12 +00:00
|
|
|
PVFATFCB FCB,
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
PFILE_POSITION_INFORMATION PositionInfo,
|
|
|
|
PULONG BufferLength)
|
2000-12-29 23:17:12 +00:00
|
|
|
{
|
2009-06-19 00:21:21 +00:00
|
|
|
UNREFERENCED_PARAMETER(FileObject);
|
|
|
|
UNREFERENCED_PARAMETER(FCB);
|
|
|
|
UNREFERENCED_PARAMETER(DeviceObject);
|
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
DPRINT ("VfatGetPositionInformation()\n");
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_POSITION_INFORMATION))
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
|
|
|
|
PositionInfo->CurrentByteOffset.QuadPart =
|
|
|
|
FileObject->CurrentByteOffset.QuadPart;
|
|
|
|
|
|
|
|
DPRINT("Getting position %I64x\n",
|
|
|
|
PositionInfo->CurrentByteOffset.QuadPart);
|
|
|
|
|
|
|
|
*BufferLength -= sizeof(FILE_POSITION_INFORMATION);
|
|
|
|
return(STATUS_SUCCESS);
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-12-27 23:50:21 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatSetBasicInformation(PFILE_OBJECT FileObject,
|
|
|
|
PVFATFCB FCB,
|
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_BASIC_INFORMATION BasicInfo)
|
|
|
|
{
|
|
|
|
DPRINT("VfatSetBasicInformation()\n");
|
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(NULL != FileObject);
|
|
|
|
ASSERT(NULL != FCB);
|
|
|
|
ASSERT(NULL != DeviceExt);
|
|
|
|
ASSERT(NULL != BasicInfo);
|
2002-12-27 23:50:21 +00:00
|
|
|
/* Check volume label bit */
|
2010-12-27 18:11:35 +00:00
|
|
|
ASSERT(0 == (*FCB->Attributes & _A_VOLID));
|
2004-11-06 13:44:57 +00:00
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
if (FCB->Flags & FCB_IS_FATX_ENTRY)
|
|
|
|
{
|
2011-03-07 20:28:42 +00:00
|
|
|
if (BasicInfo->CreationTime.QuadPart != 0 && BasicInfo->CreationTime.QuadPart != -1)
|
|
|
|
{
|
|
|
|
FsdSystemTimeToDosDateTime(DeviceExt,
|
|
|
|
&BasicInfo->CreationTime,
|
|
|
|
&FCB->entry.FatX.CreationDate,
|
|
|
|
&FCB->entry.FatX.CreationTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BasicInfo->LastAccessTime.QuadPart != 0 && BasicInfo->LastAccessTime.QuadPart != -1)
|
|
|
|
{
|
|
|
|
FsdSystemTimeToDosDateTime(DeviceExt,
|
|
|
|
&BasicInfo->LastAccessTime,
|
|
|
|
&FCB->entry.FatX.AccessDate,
|
|
|
|
&FCB->entry.FatX.AccessTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BasicInfo->LastWriteTime.QuadPart != 0 && BasicInfo->LastWriteTime.QuadPart != -1)
|
|
|
|
{
|
|
|
|
FsdSystemTimeToDosDateTime(DeviceExt,
|
|
|
|
&BasicInfo->LastWriteTime,
|
|
|
|
&FCB->entry.FatX.UpdateDate,
|
|
|
|
&FCB->entry.FatX.UpdateTime);
|
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-07 20:28:42 +00:00
|
|
|
if (BasicInfo->CreationTime.QuadPart != 0 && BasicInfo->CreationTime.QuadPart != -1)
|
|
|
|
{
|
|
|
|
FsdSystemTimeToDosDateTime(DeviceExt,
|
|
|
|
&BasicInfo->CreationTime,
|
|
|
|
&FCB->entry.Fat.CreationDate,
|
|
|
|
&FCB->entry.Fat.CreationTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BasicInfo->LastAccessTime.QuadPart != 0 && BasicInfo->LastAccessTime.QuadPart != -1)
|
|
|
|
{
|
|
|
|
FsdSystemTimeToDosDateTime(DeviceExt,
|
|
|
|
&BasicInfo->LastAccessTime,
|
|
|
|
&FCB->entry.Fat.AccessDate,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BasicInfo->LastWriteTime.QuadPart != 0 && BasicInfo->LastWriteTime.QuadPart != -1)
|
|
|
|
{
|
|
|
|
FsdSystemTimeToDosDateTime(DeviceExt,
|
|
|
|
&BasicInfo->LastWriteTime,
|
|
|
|
&FCB->entry.Fat.UpdateDate,
|
|
|
|
&FCB->entry.Fat.UpdateTime);
|
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|
2002-12-27 23:50:21 +00:00
|
|
|
|
2011-03-07 20:28:42 +00:00
|
|
|
if (BasicInfo->FileAttributes)
|
|
|
|
{
|
|
|
|
*FCB->Attributes = (unsigned char)((*FCB->Attributes &
|
|
|
|
(FILE_ATTRIBUTE_DIRECTORY | 0x48)) |
|
|
|
|
(BasicInfo->FileAttributes &
|
|
|
|
(FILE_ATTRIBUTE_ARCHIVE |
|
|
|
|
FILE_ATTRIBUTE_SYSTEM |
|
|
|
|
FILE_ATTRIBUTE_HIDDEN |
|
|
|
|
FILE_ATTRIBUTE_READONLY)));
|
|
|
|
DPRINT("Setting attributes 0x%02x\n", *FCB->Attributes);
|
|
|
|
}
|
2002-12-27 23:50:21 +00:00
|
|
|
|
2003-10-11 17:51:56 +00:00
|
|
|
VfatUpdateEntry(FCB);
|
2002-12-27 23:50:21 +00:00
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2001-03-07 13:44:41 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatGetBasicInformation(PFILE_OBJECT FileObject,
|
2000-12-29 23:17:12 +00:00
|
|
|
PVFATFCB FCB,
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
PFILE_BASIC_INFORMATION BasicInfo,
|
|
|
|
PULONG BufferLength)
|
2000-12-29 23:17:12 +00:00
|
|
|
{
|
2004-12-05 16:31:51 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
2009-06-19 00:21:21 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(FileObject);
|
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
DPRINT("VfatGetBasicInformation()\n");
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
DeviceExt = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2001-06-12 12:35:42 +00:00
|
|
|
|
|
|
|
if (*BufferLength < sizeof(FILE_BASIC_INFORMATION))
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
if (FCB->Flags & FCB_IS_FATX_ENTRY)
|
|
|
|
{
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
FCB->entry.FatX.CreationDate,
|
|
|
|
FCB->entry.FatX.CreationTime,
|
2004-11-06 13:44:57 +00:00
|
|
|
&BasicInfo->CreationTime);
|
2004-12-05 16:31:51 +00:00
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
FCB->entry.FatX.AccessDate,
|
|
|
|
FCB->entry.FatX.AccessTime,
|
|
|
|
&BasicInfo->LastAccessTime);
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
FCB->entry.FatX.UpdateDate,
|
|
|
|
FCB->entry.FatX.UpdateTime,
|
|
|
|
&BasicInfo->LastWriteTime);
|
|
|
|
BasicInfo->ChangeTime = BasicInfo->LastWriteTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
FCB->entry.Fat.CreationDate,
|
|
|
|
FCB->entry.Fat.CreationTime,
|
|
|
|
&BasicInfo->CreationTime);
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
FCB->entry.Fat.AccessDate,
|
2004-11-06 13:44:57 +00:00
|
|
|
0,
|
|
|
|
&BasicInfo->LastAccessTime);
|
2004-12-05 16:31:51 +00:00
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
FCB->entry.Fat.UpdateDate,
|
|
|
|
FCB->entry.Fat.UpdateTime,
|
2004-11-06 13:44:57 +00:00
|
|
|
&BasicInfo->LastWriteTime);
|
2004-12-05 16:31:51 +00:00
|
|
|
BasicInfo->ChangeTime = BasicInfo->LastWriteTime;
|
|
|
|
}
|
2000-12-29 23:17:12 +00:00
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
BasicInfo->FileAttributes = *FCB->Attributes & 0x3f;
|
2002-12-27 23:50:21 +00:00
|
|
|
/* Synthesize FILE_ATTRIBUTE_NORMAL */
|
|
|
|
if (0 == (BasicInfo->FileAttributes & (FILE_ATTRIBUTE_DIRECTORY |
|
|
|
|
FILE_ATTRIBUTE_ARCHIVE |
|
|
|
|
FILE_ATTRIBUTE_SYSTEM |
|
|
|
|
FILE_ATTRIBUTE_HIDDEN |
|
|
|
|
FILE_ATTRIBUTE_READONLY)))
|
|
|
|
{
|
2005-12-09 13:23:33 +00:00
|
|
|
DPRINT("Synthesizing FILE_ATTRIBUTE_NORMAL\n");
|
2002-12-27 23:50:21 +00:00
|
|
|
BasicInfo->FileAttributes |= FILE_ATTRIBUTE_NORMAL;
|
|
|
|
}
|
|
|
|
DPRINT("Getting attributes 0x%02x\n", BasicInfo->FileAttributes);
|
2000-12-29 23:17:12 +00:00
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
*BufferLength -= sizeof(FILE_BASIC_INFORMATION);
|
|
|
|
return(STATUS_SUCCESS);
|
2000-12-29 23:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-07 13:44:41 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatSetDispositionInformation(PFILE_OBJECT FileObject,
|
2000-12-29 23:17:12 +00:00
|
|
|
PVFATFCB FCB,
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_DISPOSITION_INFORMATION DispositionInfo)
|
1999-12-11 21:14:49 +00:00
|
|
|
{
|
2009-06-17 12:44:05 +00:00
|
|
|
#if DBG
|
2005-03-18 19:36:36 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
|
2005-01-12 12:06:15 +00:00
|
|
|
#endif
|
2001-08-14 20:47:30 +00:00
|
|
|
|
2008-10-19 13:23:00 +00:00
|
|
|
DPRINT ("FsdSetDispositionInformation(<%wZ>, Delete %d)\n", &FCB->PathNameU, DispositionInfo->DeleteFile);
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2005-03-18 19:36:36 +00:00
|
|
|
ASSERT(DeviceExt != NULL);
|
|
|
|
ASSERT(DeviceExt->FatInfo.BytesPerCluster != 0);
|
|
|
|
ASSERT(FCB != NULL);
|
2000-12-29 23:17:12 +00:00
|
|
|
|
2005-03-18 19:36:36 +00:00
|
|
|
if (!DispositionInfo->DeleteFile)
|
|
|
|
{
|
|
|
|
/* undelete the file */
|
|
|
|
FCB->Flags &= ~FCB_DELETE_PENDING;
|
|
|
|
FileObject->DeletePending = FALSE;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2005-03-18 19:36:36 +00:00
|
|
|
if (FCB->Flags & FCB_DELETE_PENDING)
|
|
|
|
{
|
|
|
|
/* stream already marked for deletion. just update the file object */
|
|
|
|
FileObject->DeletePending = TRUE;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
|
|
if (*FCB->Attributes & FILE_ATTRIBUTE_READONLY)
|
2005-03-18 19:36:36 +00:00
|
|
|
{
|
2004-08-28 22:19:12 +00:00
|
|
|
return STATUS_CANNOT_DELETE;
|
2005-03-18 19:36:36 +00:00
|
|
|
}
|
2004-08-28 22:19:12 +00:00
|
|
|
|
2005-05-08 02:16:32 +00:00
|
|
|
if (vfatFCBIsRoot(FCB) ||
|
2003-10-11 17:51:56 +00:00
|
|
|
(FCB->LongNameU.Length == sizeof(WCHAR) && FCB->LongNameU.Buffer[0] == L'.') ||
|
|
|
|
(FCB->LongNameU.Length == 2 * sizeof(WCHAR) && FCB->LongNameU.Buffer[0] == L'.' && FCB->LongNameU.Buffer[1] == L'.'))
|
2005-03-18 19:36:36 +00:00
|
|
|
{
|
2003-10-11 17:51:56 +00:00
|
|
|
// we cannot delete a '.', '..' or the root directory
|
|
|
|
return STATUS_ACCESS_DENIED;
|
2005-03-18 19:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!MmFlushImageSection (FileObject->SectionObjectPointer, MmFlushForDelete))
|
|
|
|
{
|
|
|
|
/* can't delete a file if its mapped into a process */
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2005-03-18 19:36:36 +00:00
|
|
|
DPRINT("MmFlushImageSection returned FALSE\n");
|
2005-05-08 02:16:32 +00:00
|
|
|
return STATUS_CANNOT_DELETE;
|
2005-03-18 19:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vfatFCBIsDirectory(FCB) && !VfatIsDirectoryEmpty(FCB))
|
|
|
|
{
|
|
|
|
/* can't delete a non-empty directory */
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2005-03-18 19:36:36 +00:00
|
|
|
return STATUS_DIRECTORY_NOT_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* all good */
|
|
|
|
FCB->Flags |= FCB_DELETE_PENDING;
|
|
|
|
FileObject->DeletePending = TRUE;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2005-03-18 19:36:36 +00:00
|
|
|
return STATUS_SUCCESS;
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatGetNameInformation(PFILE_OBJECT FileObject,
|
|
|
|
PVFATFCB FCB,
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_NAME_INFORMATION NameInfo,
|
|
|
|
PULONG BufferLength)
|
2001-03-06 23:36:35 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the file name information
|
|
|
|
*/
|
|
|
|
{
|
2008-11-17 11:25:36 +00:00
|
|
|
ULONG BytesToCopy;
|
2009-06-19 00:21:21 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(FileObject);
|
|
|
|
UNREFERENCED_PARAMETER(DeviceObject);
|
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(NameInfo != NULL);
|
|
|
|
ASSERT(FCB != NULL);
|
2001-03-06 23:36:35 +00:00
|
|
|
|
2008-11-17 11:25:36 +00:00
|
|
|
/* If buffer can't hold at least the file name length, bail out */
|
2011-07-05 13:55:39 +00:00
|
|
|
if (*BufferLength < (ULONG)FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
|
2001-06-12 12:35:42 +00:00
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
|
2008-11-17 11:25:36 +00:00
|
|
|
/* Save file name length, and as much file len, as buffer length allows */
|
|
|
|
NameInfo->FileNameLength = FCB->PathNameU.Length;
|
|
|
|
|
|
|
|
/* Calculate amount of bytes to copy not to overflow the buffer */
|
|
|
|
BytesToCopy = min(FCB->PathNameU.Length,
|
|
|
|
*BufferLength - FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]));
|
2001-06-12 12:35:42 +00:00
|
|
|
|
2008-11-17 11:25:36 +00:00
|
|
|
/* Fill in the bytes */
|
|
|
|
RtlCopyMemory(NameInfo->FileName, FCB->PathNameU.Buffer, BytesToCopy);
|
|
|
|
|
|
|
|
/* Check if we could write more but are not able to */
|
2008-12-07 21:52:22 +00:00
|
|
|
if (*BufferLength < FCB->PathNameU.Length + (ULONG)FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
|
2008-11-17 11:25:36 +00:00
|
|
|
{
|
|
|
|
/* Return number of bytes written */
|
|
|
|
*BufferLength -= FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]) + BytesToCopy;
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We filled up as many bytes, as needed */
|
2006-07-27 00:13:14 +00:00
|
|
|
*BufferLength -= (FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]) + FCB->PathNameU.Length);
|
2001-03-06 23:36:35 +00:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2001-11-01 10:44:11 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatGetInternalInformation(PVFATFCB Fcb,
|
2001-11-02 22:47:36 +00:00
|
|
|
PFILE_INTERNAL_INFORMATION InternalInfo,
|
|
|
|
PULONG BufferLength)
|
2001-11-01 10:44:11 +00:00
|
|
|
{
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(InternalInfo);
|
|
|
|
ASSERT(Fcb);
|
2001-03-06 23:36:35 +00:00
|
|
|
|
2001-11-01 10:44:11 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_INTERNAL_INFORMATION))
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
// FIXME: get a real index, that can be used in a create operation
|
|
|
|
InternalInfo->IndexNumber.QuadPart = 0;
|
|
|
|
*BufferLength -= sizeof(FILE_INTERNAL_INFORMATION);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2002-07-20 00:57:36 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatGetNetworkOpenInformation(PVFATFCB Fcb,
|
2004-12-05 16:31:51 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
2002-07-20 00:57:36 +00:00
|
|
|
PFILE_NETWORK_OPEN_INFORMATION NetworkInfo,
|
|
|
|
PULONG BufferLength)
|
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the file network open information
|
|
|
|
*/
|
|
|
|
{
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(NetworkInfo);
|
|
|
|
ASSERT(Fcb);
|
2002-07-20 00:57:36 +00:00
|
|
|
|
|
|
|
if (*BufferLength < sizeof(FILE_NETWORK_OPEN_INFORMATION))
|
|
|
|
return(STATUS_BUFFER_OVERFLOW);
|
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_FATX_ENTRY)
|
|
|
|
{
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
Fcb->entry.FatX.CreationDate,
|
|
|
|
Fcb->entry.FatX.CreationTime,
|
|
|
|
&NetworkInfo->CreationTime);
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
Fcb->entry.FatX.AccessDate,
|
|
|
|
Fcb->entry.FatX.AccessTime,
|
|
|
|
&NetworkInfo->LastAccessTime);
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
Fcb->entry.FatX.UpdateDate,
|
|
|
|
Fcb->entry.FatX.UpdateTime,
|
|
|
|
&NetworkInfo->LastWriteTime);
|
|
|
|
NetworkInfo->ChangeTime.QuadPart = NetworkInfo->LastWriteTime.QuadPart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
Fcb->entry.Fat.CreationDate,
|
|
|
|
Fcb->entry.Fat.CreationTime,
|
2004-11-06 13:44:57 +00:00
|
|
|
&NetworkInfo->CreationTime);
|
2004-12-05 16:31:51 +00:00
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
Fcb->entry.Fat.AccessDate,
|
2004-11-06 13:44:57 +00:00
|
|
|
0,
|
|
|
|
&NetworkInfo->LastAccessTime);
|
2004-12-05 16:31:51 +00:00
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
Fcb->entry.Fat.UpdateDate,
|
|
|
|
Fcb->entry.Fat.UpdateTime,
|
2004-11-06 13:44:57 +00:00
|
|
|
&NetworkInfo->LastWriteTime);
|
2004-12-05 16:31:51 +00:00
|
|
|
NetworkInfo->ChangeTime.QuadPart = NetworkInfo->LastWriteTime.QuadPart;
|
|
|
|
}
|
2004-05-23 13:34:32 +00:00
|
|
|
if (vfatFCBIsDirectory(Fcb))
|
|
|
|
{
|
|
|
|
NetworkInfo->EndOfFile.QuadPart = 0L;
|
|
|
|
NetworkInfo->AllocationSize.QuadPart = 0L;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NetworkInfo->AllocationSize = Fcb->RFCB.AllocationSize;
|
|
|
|
NetworkInfo->EndOfFile = Fcb->RFCB.FileSize;
|
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
NetworkInfo->FileAttributes = *Fcb->Attributes & 0x3f;
|
2005-12-09 13:23:33 +00:00
|
|
|
/* Synthesize FILE_ATTRIBUTE_NORMAL */
|
|
|
|
if (0 == (NetworkInfo->FileAttributes & (FILE_ATTRIBUTE_DIRECTORY |
|
|
|
|
FILE_ATTRIBUTE_ARCHIVE |
|
|
|
|
FILE_ATTRIBUTE_SYSTEM |
|
|
|
|
FILE_ATTRIBUTE_HIDDEN |
|
|
|
|
FILE_ATTRIBUTE_READONLY)))
|
|
|
|
{
|
|
|
|
DPRINT("Synthesizing FILE_ATTRIBUTE_NORMAL\n");
|
|
|
|
NetworkInfo->FileAttributes |= FILE_ATTRIBUTE_NORMAL;
|
|
|
|
}
|
2002-07-20 00:57:36 +00:00
|
|
|
|
|
|
|
*BufferLength -= sizeof(FILE_NETWORK_OPEN_INFORMATION);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2006-05-07 18:50:18 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatGetEaInformation(PFILE_OBJECT FileObject,
|
|
|
|
PVFATFCB Fcb,
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_EA_INFORMATION Info,
|
|
|
|
PULONG BufferLength)
|
|
|
|
{
|
|
|
|
PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
|
|
|
|
|
2009-06-19 00:21:21 +00:00
|
|
|
UNREFERENCED_PARAMETER(FileObject);
|
|
|
|
UNREFERENCED_PARAMETER(Fcb);
|
|
|
|
|
2006-05-07 18:50:18 +00:00
|
|
|
/* FIXME - use SEH to access the buffer! */
|
|
|
|
Info->EaSize = 0;
|
|
|
|
*BufferLength -= sizeof(*Info);
|
|
|
|
if (DeviceExt->FatInfo.FatType == FAT12 ||
|
|
|
|
DeviceExt->FatInfo.FatType == FAT16)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
DPRINT1("VFAT: FileEaInformation not implemented!\n");
|
|
|
|
}
|
2012-01-01 17:15:25 +00:00
|
|
|
return STATUS_SUCCESS;
|
2006-05-07 18:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-20 11:44:37 +00:00
|
|
|
static NTSTATUS
|
|
|
|
VfatGetAllInformation(PFILE_OBJECT FileObject,
|
|
|
|
PVFATFCB Fcb,
|
2004-12-05 16:31:51 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject,
|
2002-07-20 11:44:37 +00:00
|
|
|
PFILE_ALL_INFORMATION Info,
|
|
|
|
PULONG BufferLength)
|
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the all file information
|
|
|
|
*/
|
|
|
|
{
|
2004-12-05 16:31:51 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG InitialBufferLength = *BufferLength;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(Info);
|
|
|
|
ASSERT(Fcb);
|
2002-07-20 11:44:37 +00:00
|
|
|
|
2003-10-11 17:51:56 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_ALL_INFORMATION) + Fcb->PathNameU.Length + sizeof(WCHAR))
|
2002-07-20 11:44:37 +00:00
|
|
|
return(STATUS_BUFFER_OVERFLOW);
|
|
|
|
|
|
|
|
/* Basic Information */
|
2004-12-05 16:31:51 +00:00
|
|
|
Status = VfatGetBasicInformation(FileObject, Fcb, DeviceObject, &Info->BasicInformation, BufferLength);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2002-07-20 11:44:37 +00:00
|
|
|
/* Standard Information */
|
2004-12-05 16:31:51 +00:00
|
|
|
Status = VfatGetStandardInformation(Fcb, &Info->StandardInformation, BufferLength);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2002-07-20 11:44:37 +00:00
|
|
|
/* Internal Information */
|
2004-12-05 16:31:51 +00:00
|
|
|
Status = VfatGetInternalInformation(Fcb, &Info->InternalInformation, BufferLength);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2002-07-20 11:44:37 +00:00
|
|
|
/* EA Information */
|
|
|
|
Info->EaInformation.EaSize = 0;
|
2004-12-05 16:31:51 +00:00
|
|
|
/* Access Information: The IO-Manager adds this information */
|
2002-07-20 11:44:37 +00:00
|
|
|
/* Position Information */
|
2004-12-05 16:31:51 +00:00
|
|
|
Status = VfatGetPositionInformation(FileObject, Fcb, DeviceObject, &Info->PositionInformation, BufferLength);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
/* Mode Information: The IO-Manager adds this information */
|
|
|
|
/* Alignment Information: The IO-Manager adds this information */
|
2002-07-20 11:44:37 +00:00
|
|
|
/* Name Information */
|
2004-12-05 16:31:51 +00:00
|
|
|
Status = VfatGetNameInformation(FileObject, Fcb, DeviceObject, &Info->NameInformation, BufferLength);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
*BufferLength = InitialBufferLength - (sizeof(FILE_ALL_INFORMATION) + Fcb->PathNameU.Length + sizeof(WCHAR));
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2002-07-20 11:44:37 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-06 21:39:18 +00:00
|
|
|
static VOID UpdateFileSize(PFILE_OBJECT FileObject, PVFATFCB Fcb, ULONG Size, ULONG ClusterSize)
|
2003-01-28 16:48:03 +00:00
|
|
|
{
|
|
|
|
if (Size > 0)
|
|
|
|
{
|
|
|
|
Fcb->RFCB.AllocationSize.QuadPart = ROUND_UP(Size, ClusterSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-24 19:00:42 +00:00
|
|
|
Fcb->RFCB.AllocationSize.QuadPart = (LONGLONG)0;
|
2003-01-28 16:48:03 +00:00
|
|
|
}
|
|
|
|
if (!vfatFCBIsDirectory(Fcb))
|
|
|
|
{
|
2004-12-05 16:31:51 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_FATX_ENTRY)
|
2005-05-08 02:16:32 +00:00
|
|
|
Fcb->entry.FatX.FileSize = Size;
|
2004-12-05 16:31:51 +00:00
|
|
|
else
|
2005-05-08 02:16:32 +00:00
|
|
|
Fcb->entry.Fat.FileSize = Size;
|
2003-01-28 16:48:03 +00:00
|
|
|
}
|
|
|
|
Fcb->RFCB.FileSize.QuadPart = Size;
|
|
|
|
Fcb->RFCB.ValidDataLength.QuadPart = Size;
|
|
|
|
|
2009-02-03 12:39:55 +00:00
|
|
|
CcSetFileSizes(FileObject, (PCC_FILE_SIZES)&Fcb->RFCB.AllocationSize);
|
2003-01-28 16:48:03 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:58:39 +00:00
|
|
|
NTSTATUS
|
2005-05-08 02:16:32 +00:00
|
|
|
VfatSetAllocationSizeInformation(PFILE_OBJECT FileObject,
|
2002-08-14 20:58:39 +00:00
|
|
|
PVFATFCB Fcb,
|
2002-08-17 15:15:50 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
2002-08-14 20:58:39 +00:00
|
|
|
PLARGE_INTEGER AllocationSize)
|
|
|
|
{
|
|
|
|
ULONG OldSize;
|
2002-09-30 20:47:28 +00:00
|
|
|
ULONG Cluster, FirstCluster;
|
2002-08-14 20:58:39 +00:00
|
|
|
NTSTATUS Status;
|
2002-08-17 15:15:50 +00:00
|
|
|
|
2002-08-14 20:58:39 +00:00
|
|
|
ULONG ClusterSize = DeviceExt->FatInfo.BytesPerCluster;
|
|
|
|
ULONG NewSize = AllocationSize->u.LowPart;
|
2002-08-17 15:15:50 +00:00
|
|
|
ULONG NCluster;
|
2005-01-12 10:46:13 +00:00
|
|
|
BOOLEAN AllocSizeChanged = FALSE;
|
2002-08-17 15:15:50 +00:00
|
|
|
|
2008-10-19 13:23:00 +00:00
|
|
|
DPRINT("VfatSetAllocationSizeInformation(File <%wZ>, AllocationSize %d %d)\n", &Fcb->PathNameU,
|
|
|
|
AllocationSize->HighPart, AllocationSize->LowPart);
|
2002-08-14 20:58:39 +00:00
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_FATX_ENTRY)
|
|
|
|
OldSize = Fcb->entry.FatX.FileSize;
|
|
|
|
else
|
|
|
|
OldSize = Fcb->entry.Fat.FileSize;
|
2002-08-17 15:15:50 +00:00
|
|
|
if (AllocationSize->u.HighPart > 0)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
if (OldSize == NewSize)
|
2002-08-14 20:58:39 +00:00
|
|
|
{
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
2002-09-30 20:47:28 +00:00
|
|
|
|
|
|
|
FirstCluster = vfatDirEntryGetFirstCluster (DeviceExt, &Fcb->entry);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2002-08-17 15:15:50 +00:00
|
|
|
if (NewSize > Fcb->RFCB.AllocationSize.u.LowPart)
|
|
|
|
{
|
2003-10-11 17:51:56 +00:00
|
|
|
AllocSizeChanged = TRUE;
|
2002-09-30 20:47:28 +00:00
|
|
|
if (FirstCluster == 0)
|
2002-08-14 20:58:39 +00:00
|
|
|
{
|
2004-08-01 21:57:18 +00:00
|
|
|
Fcb->LastCluster = Fcb->LastOffset = 0;
|
2003-05-11 09:51:26 +00:00
|
|
|
Status = NextCluster (DeviceExt, FirstCluster, &FirstCluster, TRUE);
|
2002-08-17 15:15:50 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2003-01-28 16:48:03 +00:00
|
|
|
DPRINT1("NextCluster failed. Status = %x\n", Status);
|
2002-08-17 15:15:50 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2002-09-30 20:47:28 +00:00
|
|
|
if (FirstCluster == 0xffffffff)
|
2002-08-17 15:15:50 +00:00
|
|
|
{
|
|
|
|
return STATUS_DISK_FULL;
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
Status = OffsetToCluster(DeviceExt, FirstCluster,
|
2004-08-01 21:57:18 +00:00
|
|
|
ROUND_DOWN(NewSize - 1, ClusterSize),
|
|
|
|
&NCluster, TRUE);
|
2003-01-28 16:48:03 +00:00
|
|
|
if (NCluster == 0xffffffff || !NT_SUCCESS(Status))
|
2002-08-17 15:15:50 +00:00
|
|
|
{
|
2004-08-01 21:57:18 +00:00
|
|
|
/* disk is full */
|
2002-09-30 20:47:28 +00:00
|
|
|
NCluster = Cluster = FirstCluster;
|
2004-08-01 21:57:18 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2003-01-28 16:48:03 +00:00
|
|
|
while (NT_SUCCESS(Status) && Cluster != 0xffffffff && Cluster > 1)
|
2004-08-01 21:57:18 +00:00
|
|
|
{
|
|
|
|
Status = NextCluster (DeviceExt, FirstCluster, &NCluster, FALSE);
|
2002-08-17 15:15:50 +00:00
|
|
|
WriteCluster (DeviceExt, Cluster, 0);
|
2004-08-01 21:57:18 +00:00
|
|
|
Cluster = NCluster;
|
|
|
|
}
|
|
|
|
return STATUS_DISK_FULL;
|
2002-08-17 15:15:50 +00:00
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_FATX_ENTRY)
|
|
|
|
{
|
|
|
|
Fcb->entry.FatX.FirstCluster = FirstCluster;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-07 18:50:18 +00:00
|
|
|
if (DeviceExt->FatInfo.FatType == FAT32)
|
|
|
|
{
|
|
|
|
Fcb->entry.Fat.FirstCluster = (unsigned short)(FirstCluster & 0x0000FFFF);
|
|
|
|
Fcb->entry.Fat.FirstClusterHigh = FirstCluster >> 16;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT((FirstCluster >> 16) == 0);
|
|
|
|
Fcb->entry.Fat.FirstCluster = (unsigned short)(FirstCluster & 0x0000FFFF);
|
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|
2002-08-14 20:58:39 +00:00
|
|
|
}
|
2002-08-17 15:15:50 +00:00
|
|
|
else
|
2002-08-14 20:58:39 +00:00
|
|
|
{
|
2005-11-27 15:53:46 +00:00
|
|
|
if (Fcb->LastCluster > 0)
|
2004-08-01 21:57:18 +00:00
|
|
|
{
|
2005-11-27 15:53:46 +00:00
|
|
|
if (Fcb->RFCB.AllocationSize.u.LowPart - ClusterSize == Fcb->LastOffset)
|
|
|
|
{
|
|
|
|
Cluster = Fcb->LastCluster;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = OffsetToCluster(DeviceExt, Fcb->LastCluster,
|
|
|
|
Fcb->RFCB.AllocationSize.u.LowPart - ClusterSize - Fcb->LastOffset,
|
|
|
|
&Cluster, FALSE);
|
|
|
|
}
|
2004-08-01 21:57:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-08 02:16:32 +00:00
|
|
|
Status = OffsetToCluster(DeviceExt, FirstCluster,
|
2004-08-01 21:57:18 +00:00
|
|
|
Fcb->RFCB.AllocationSize.u.LowPart - ClusterSize,
|
|
|
|
&Cluster, FALSE);
|
|
|
|
}
|
2005-11-27 15:53:46 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
2004-08-01 21:57:18 +00:00
|
|
|
|
2008-12-18 20:47:20 +00:00
|
|
|
Fcb->LastCluster = Cluster;
|
|
|
|
Fcb->LastOffset = Fcb->RFCB.AllocationSize.u.LowPart - ClusterSize;
|
2004-08-01 21:57:18 +00:00
|
|
|
|
2003-01-28 16:48:03 +00:00
|
|
|
/* FIXME: Check status */
|
2002-08-17 15:15:50 +00:00
|
|
|
/* Cluster points now to the last cluster within the chain */
|
2005-11-27 15:53:46 +00:00
|
|
|
Status = OffsetToCluster(DeviceExt, Cluster,
|
|
|
|
ROUND_DOWN(NewSize - 1, ClusterSize) - Fcb->LastOffset,
|
|
|
|
&NCluster, TRUE);
|
2003-01-28 16:48:03 +00:00
|
|
|
if (NCluster == 0xffffffff || !NT_SUCCESS(Status))
|
2002-08-17 15:15:50 +00:00
|
|
|
{
|
|
|
|
/* disk is full */
|
2005-05-08 02:16:32 +00:00
|
|
|
NCluster = Cluster;
|
2003-05-11 09:51:26 +00:00
|
|
|
Status = NextCluster (DeviceExt, FirstCluster, &NCluster, FALSE);
|
2002-08-17 15:15:50 +00:00
|
|
|
WriteCluster(DeviceExt, Cluster, 0xffffffff);
|
|
|
|
Cluster = NCluster;
|
2003-01-28 16:48:03 +00:00
|
|
|
while (NT_SUCCESS(Status) && Cluster != 0xffffffff && Cluster > 1)
|
2002-08-17 15:15:50 +00:00
|
|
|
{
|
2003-05-11 09:51:26 +00:00
|
|
|
Status = NextCluster (DeviceExt, FirstCluster, &NCluster, FALSE);
|
2003-01-28 16:48:03 +00:00
|
|
|
WriteCluster (DeviceExt, Cluster, 0);
|
|
|
|
Cluster = NCluster;
|
2002-08-17 15:15:50 +00:00
|
|
|
}
|
|
|
|
return STATUS_DISK_FULL;
|
|
|
|
}
|
2002-08-14 20:58:39 +00:00
|
|
|
}
|
2003-01-28 16:48:03 +00:00
|
|
|
UpdateFileSize(FileObject, Fcb, NewSize, ClusterSize);
|
2002-08-17 15:15:50 +00:00
|
|
|
}
|
2003-01-19 01:06:09 +00:00
|
|
|
else if (NewSize + ClusterSize <= Fcb->RFCB.AllocationSize.u.LowPart)
|
2002-08-17 15:15:50 +00:00
|
|
|
{
|
2009-02-03 12:39:55 +00:00
|
|
|
|
|
|
|
DPRINT("Check for the ability to set file size\n");
|
|
|
|
if (!MmCanFileBeTruncated
|
|
|
|
(FileObject->SectionObjectPointer,
|
|
|
|
(PLARGE_INTEGER)AllocationSize))
|
|
|
|
{
|
|
|
|
DPRINT("Couldn't set file size!\n");
|
|
|
|
return STATUS_USER_MAPPED_FILE;
|
|
|
|
}
|
|
|
|
DPRINT("Can set file size\n");
|
|
|
|
|
2003-10-11 17:51:56 +00:00
|
|
|
AllocSizeChanged = TRUE;
|
2004-08-01 21:57:18 +00:00
|
|
|
/* FIXME: Use the cached cluster/offset better way. */
|
2007-03-10 11:06:02 +00:00
|
|
|
Fcb->LastCluster = Fcb->LastOffset = 0;
|
2003-01-28 16:48:03 +00:00
|
|
|
UpdateFileSize(FileObject, Fcb, NewSize, ClusterSize);
|
2003-01-19 01:06:09 +00:00
|
|
|
if (NewSize > 0)
|
|
|
|
{
|
2005-05-08 02:16:32 +00:00
|
|
|
Status = OffsetToCluster(DeviceExt, FirstCluster,
|
2002-08-17 15:15:50 +00:00
|
|
|
ROUND_DOWN(NewSize - 1, ClusterSize),
|
|
|
|
&Cluster, FALSE);
|
2002-09-30 20:47:28 +00:00
|
|
|
|
2003-01-19 01:06:09 +00:00
|
|
|
NCluster = Cluster;
|
2003-05-11 09:51:26 +00:00
|
|
|
Status = NextCluster (DeviceExt, FirstCluster, &NCluster, FALSE);
|
2003-01-19 01:06:09 +00:00
|
|
|
WriteCluster(DeviceExt, Cluster, 0xffffffff);
|
|
|
|
Cluster = NCluster;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-05 16:31:51 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_FATX_ENTRY)
|
|
|
|
{
|
|
|
|
Fcb->entry.FatX.FirstCluster = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-07 18:50:18 +00:00
|
|
|
if (DeviceExt->FatInfo.FatType == FAT32)
|
|
|
|
{
|
|
|
|
Fcb->entry.Fat.FirstCluster = 0;
|
|
|
|
Fcb->entry.Fat.FirstClusterHigh = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Fcb->entry.Fat.FirstCluster = 0;
|
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|
2003-01-28 16:48:03 +00:00
|
|
|
|
|
|
|
NCluster = Cluster = FirstCluster;
|
|
|
|
Status = STATUS_SUCCESS;
|
2003-01-19 01:06:09 +00:00
|
|
|
}
|
2003-01-28 16:48:03 +00:00
|
|
|
while (NT_SUCCESS(Status) && 0xffffffff != Cluster && Cluster > 1)
|
2003-01-19 01:06:09 +00:00
|
|
|
{
|
2003-05-11 09:51:26 +00:00
|
|
|
Status = NextCluster (DeviceExt, FirstCluster, &NCluster, FALSE);
|
2003-01-19 01:06:09 +00:00
|
|
|
WriteCluster (DeviceExt, Cluster, 0);
|
|
|
|
Cluster = NCluster;
|
|
|
|
}
|
2002-08-17 15:15:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-01-28 16:48:03 +00:00
|
|
|
UpdateFileSize(FileObject, Fcb, NewSize, ClusterSize);
|
2002-08-17 15:15:50 +00:00
|
|
|
}
|
2002-08-14 20:58:39 +00:00
|
|
|
/* Update the on-disk directory entry */
|
2003-10-11 17:51:56 +00:00
|
|
|
Fcb->Flags |= FCB_IS_DIRTY;
|
|
|
|
if (AllocSizeChanged)
|
|
|
|
{
|
|
|
|
VfatUpdateEntry(Fcb);
|
|
|
|
}
|
2002-08-17 15:15:50 +00:00
|
|
|
return STATUS_SUCCESS;
|
2002-08-14 20:58:39 +00:00
|
|
|
}
|
2002-07-20 11:44:37 +00:00
|
|
|
|
2001-11-02 22:47:36 +00:00
|
|
|
NTSTATUS VfatQueryInformation(PVFAT_IRP_CONTEXT IrpContext)
|
1999-12-11 21:14:49 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the specified file information
|
|
|
|
*/
|
|
|
|
{
|
2001-06-12 12:35:42 +00:00
|
|
|
FILE_INFORMATION_CLASS FileInformationClass;
|
2000-12-29 23:17:12 +00:00
|
|
|
PVFATFCB FCB = NULL;
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2008-11-17 11:25:36 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2001-06-12 12:35:42 +00:00
|
|
|
PVOID SystemBuffer;
|
|
|
|
ULONG BufferLength;
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
/* PRECONDITION */
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext);
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
/* INITIALIZATION */
|
2001-11-02 22:47:36 +00:00
|
|
|
FileInformationClass = IrpContext->Stack->Parameters.QueryFile.FileInformationClass;
|
2003-02-13 22:24:19 +00:00
|
|
|
FCB = (PVFATFCB) IrpContext->FileObject->FsContext;
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2005-05-08 02:16:32 +00:00
|
|
|
DPRINT("VfatQueryInformation is called for '%s'\n",
|
2005-01-25 21:10:42 +00:00
|
|
|
FileInformationClass >= FileMaximumInformation - 1 ? "????" : FileInformationClassNames[FileInformationClass]);
|
|
|
|
|
|
|
|
|
2001-11-02 22:47:36 +00:00
|
|
|
SystemBuffer = IrpContext->Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
BufferLength = IrpContext->Stack->Parameters.QueryFile.Length;
|
|
|
|
|
|
|
|
if (!(FCB->Flags & FCB_IS_PAGE_FILE))
|
|
|
|
{
|
2003-07-24 19:00:42 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(&FCB->MainResource,
|
|
|
|
(BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
|
|
|
return VfatQueueRequest (IrpContext);
|
|
|
|
}
|
|
|
|
}
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2001-11-01 10:44:11 +00:00
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
switch (FileInformationClass)
|
|
|
|
{
|
|
|
|
case FileStandardInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = VfatGetStandardInformation(FCB,
|
2001-06-12 12:35:42 +00:00
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
1999-12-11 21:14:49 +00:00
|
|
|
break;
|
2000-12-29 23:17:12 +00:00
|
|
|
case FilePositionInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = VfatGetPositionInformation(IrpContext->FileObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
FCB,
|
2001-11-02 22:47:36 +00:00
|
|
|
IrpContext->DeviceObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
1999-12-11 21:14:49 +00:00
|
|
|
break;
|
2000-12-29 23:17:12 +00:00
|
|
|
case FileBasicInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = VfatGetBasicInformation(IrpContext->FileObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
FCB,
|
2001-11-02 22:47:36 +00:00
|
|
|
IrpContext->DeviceObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
1999-12-11 21:14:49 +00:00
|
|
|
break;
|
2001-03-06 23:36:35 +00:00
|
|
|
case FileNameInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = VfatGetNameInformation(IrpContext->FileObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
FCB,
|
2001-11-02 22:47:36 +00:00
|
|
|
IrpContext->DeviceObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
2001-03-06 23:36:35 +00:00
|
|
|
break;
|
2001-06-12 12:35:42 +00:00
|
|
|
case FileInternalInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = VfatGetInternalInformation(FCB,
|
2001-11-02 22:47:36 +00:00
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
2001-11-01 10:44:11 +00:00
|
|
|
break;
|
2002-07-20 00:57:36 +00:00
|
|
|
case FileNetworkOpenInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = VfatGetNetworkOpenInformation(FCB,
|
2004-12-05 16:31:51 +00:00
|
|
|
IrpContext->DeviceExt,
|
2002-07-20 00:57:36 +00:00
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
2002-07-20 11:44:37 +00:00
|
|
|
case FileAllInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = VfatGetAllInformation(IrpContext->FileObject,
|
2002-07-20 11:44:37 +00:00
|
|
|
FCB,
|
2004-12-05 16:31:51 +00:00
|
|
|
IrpContext->DeviceObject,
|
2002-07-20 11:44:37 +00:00
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
2002-07-20 00:57:36 +00:00
|
|
|
|
2006-05-07 18:50:18 +00:00
|
|
|
case FileEaInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = VfatGetEaInformation(IrpContext->FileObject,
|
2006-05-07 18:50:18 +00:00
|
|
|
FCB,
|
|
|
|
IrpContext->DeviceObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
case FileAlternateNameInformation:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
2001-06-12 12:35:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-11-17 11:25:36 +00:00
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
2000-12-29 23:17:12 +00:00
|
|
|
}
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2001-11-02 22:47:36 +00:00
|
|
|
if (!(FCB->Flags & FCB_IS_PAGE_FILE))
|
|
|
|
{
|
|
|
|
ExReleaseResourceLite(&FCB->MainResource);
|
|
|
|
}
|
2008-11-17 11:25:36 +00:00
|
|
|
IrpContext->Irp->IoStatus.Status = Status;
|
|
|
|
if (NT_SUCCESS(Status) || Status == STATUS_BUFFER_OVERFLOW)
|
2001-11-02 22:47:36 +00:00
|
|
|
IrpContext->Irp->IoStatus.Information =
|
|
|
|
IrpContext->Stack->Parameters.QueryFile.Length - BufferLength;
|
2001-06-12 12:35:42 +00:00
|
|
|
else
|
2001-11-02 22:47:36 +00:00
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(IrpContext->Irp, IO_NO_INCREMENT);
|
|
|
|
VfatFreeIrpContext(IrpContext);
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2008-11-17 11:25:36 +00:00
|
|
|
return Status;
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
2001-11-02 22:47:36 +00:00
|
|
|
NTSTATUS VfatSetInformation(PVFAT_IRP_CONTEXT IrpContext)
|
1999-12-11 21:14:49 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the specified file information
|
|
|
|
*/
|
|
|
|
{
|
2000-12-29 23:17:12 +00:00
|
|
|
FILE_INFORMATION_CLASS FileInformationClass;
|
|
|
|
PVFATFCB FCB = NULL;
|
|
|
|
NTSTATUS RC = STATUS_SUCCESS;
|
|
|
|
PVOID SystemBuffer;
|
2005-01-12 10:46:13 +00:00
|
|
|
BOOLEAN CanWait = (IrpContext->Flags & IRPCONTEXT_CANWAIT) != 0;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
/* PRECONDITION */
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2007-11-21 16:50:07 +00:00
|
|
|
DPRINT("VfatSetInformation(IrpContext %p)\n", IrpContext);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
/* INITIALIZATION */
|
2005-05-08 02:16:32 +00:00
|
|
|
FileInformationClass =
|
2002-08-14 20:58:39 +00:00
|
|
|
IrpContext->Stack->Parameters.SetFile.FileInformationClass;
|
2003-02-13 22:24:19 +00:00
|
|
|
FCB = (PVFATFCB) IrpContext->FileObject->FsContext;
|
2001-11-02 22:47:36 +00:00
|
|
|
SystemBuffer = IrpContext->Irp->AssociatedIrp.SystemBuffer;
|
2005-01-25 21:10:42 +00:00
|
|
|
|
2005-05-08 02:16:32 +00:00
|
|
|
DPRINT("VfatSetInformation is called for '%s'\n",
|
2005-01-25 21:10:42 +00:00
|
|
|
FileInformationClass >= FileMaximumInformation - 1 ? "????" : FileInformationClassNames[ FileInformationClass]);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
DPRINT("FileInformationClass %d\n", FileInformationClass);
|
2007-11-21 16:50:07 +00:00
|
|
|
DPRINT("SystemBuffer %p\n", SystemBuffer);
|
2003-10-11 17:51:56 +00:00
|
|
|
|
2009-02-03 12:39:55 +00:00
|
|
|
/* Special: We should call MmCanFileBeTruncated here to determine if changing
|
|
|
|
the file size would be allowed. If not, we bail with the right error.
|
|
|
|
We must do this before acquiring the lock. */
|
|
|
|
if (FileInformationClass == FileEndOfFileInformation)
|
|
|
|
{
|
|
|
|
DPRINT("Check for the ability to set file size\n");
|
|
|
|
if (!MmCanFileBeTruncated
|
|
|
|
(IrpContext->FileObject->SectionObjectPointer,
|
|
|
|
(PLARGE_INTEGER)SystemBuffer))
|
|
|
|
{
|
|
|
|
DPRINT("Couldn't set file size!\n");
|
|
|
|
IrpContext->Irp->IoStatus.Status = STATUS_USER_MAPPED_FILE;
|
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(IrpContext->Irp, IO_NO_INCREMENT);
|
|
|
|
VfatFreeIrpContext(IrpContext);
|
|
|
|
return STATUS_USER_MAPPED_FILE;
|
|
|
|
}
|
|
|
|
DPRINT("Can set file size\n");
|
|
|
|
}
|
|
|
|
|
2003-05-11 09:51:26 +00:00
|
|
|
if (!(FCB->Flags & FCB_IS_PAGE_FILE))
|
2002-08-14 20:58:39 +00:00
|
|
|
{
|
2003-07-24 19:00:42 +00:00
|
|
|
if (!ExAcquireResourceExclusiveLite(&FCB->MainResource,
|
|
|
|
(BOOLEAN)CanWait))
|
2002-08-14 20:58:39 +00:00
|
|
|
{
|
|
|
|
return(VfatQueueRequest (IrpContext));
|
|
|
|
}
|
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
switch (FileInformationClass)
|
|
|
|
{
|
|
|
|
case FilePositionInformation:
|
2001-11-02 22:47:36 +00:00
|
|
|
RC = VfatSetPositionInformation(IrpContext->FileObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
SystemBuffer);
|
2000-12-29 23:17:12 +00:00
|
|
|
break;
|
|
|
|
case FileDispositionInformation:
|
2001-11-02 22:47:36 +00:00
|
|
|
RC = VfatSetDispositionInformation(IrpContext->FileObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
FCB,
|
2001-11-02 22:47:36 +00:00
|
|
|
IrpContext->DeviceObject,
|
2001-06-12 12:35:42 +00:00
|
|
|
SystemBuffer);
|
2000-12-29 23:17:12 +00:00
|
|
|
break;
|
2005-05-08 02:16:32 +00:00
|
|
|
case FileAllocationInformation:
|
2001-06-12 12:35:42 +00:00
|
|
|
case FileEndOfFileInformation:
|
2002-08-14 20:58:39 +00:00
|
|
|
RC = VfatSetAllocationSizeInformation(IrpContext->FileObject,
|
|
|
|
FCB,
|
2002-08-17 15:15:50 +00:00
|
|
|
IrpContext->DeviceExt,
|
2002-08-14 20:58:39 +00:00
|
|
|
(PLARGE_INTEGER)SystemBuffer);
|
2005-05-08 02:16:32 +00:00
|
|
|
break;
|
2002-08-14 20:58:39 +00:00
|
|
|
case FileBasicInformation:
|
2002-12-27 23:50:21 +00:00
|
|
|
RC = VfatSetBasicInformation(IrpContext->FileObject,
|
|
|
|
FCB,
|
|
|
|
IrpContext->DeviceExt,
|
|
|
|
SystemBuffer);
|
|
|
|
break;
|
2001-06-12 12:35:42 +00:00
|
|
|
case FileRenameInformation:
|
2000-12-29 23:17:12 +00:00
|
|
|
RC = STATUS_NOT_IMPLEMENTED;
|
2001-06-12 12:35:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RC = STATUS_NOT_SUPPORTED;
|
2000-12-29 23:17:12 +00:00
|
|
|
}
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2003-05-11 09:51:26 +00:00
|
|
|
if (!(FCB->Flags & FCB_IS_PAGE_FILE))
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
|
|
|
ExReleaseResourceLite(&FCB->MainResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
IrpContext->Irp->IoStatus.Status = RC;
|
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(IrpContext->Irp, IO_NO_INCREMENT);
|
|
|
|
VfatFreeIrpContext(IrpContext);
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2000-12-29 23:17:12 +00:00
|
|
|
return RC;
|
|
|
|
}
|
2001-06-12 12:35:42 +00:00
|
|
|
|
|
|
|
/* EOF */
|