Continue streams integration:
- NtfsGetFileSize() will now return the file size depending on the open data stream
- NtfsGetFileSize() will also optionally return allocated size
- In NtfsMakeFCBFromDirEntry(), when initializing FSRTL_COMMON_FCB_HEADER entry, use data stream sizes

svn path=/trunk/; revision=68348
This commit is contained in:
Pierre Schweitzer 2015-07-05 19:04:05 +00:00
parent 83159263f9
commit 53bbe9ea86
3 changed files with 27 additions and 12 deletions

View file

@ -35,23 +35,28 @@
/* FUNCTIONS ****************************************************************/
static ULONGLONG
ULONGLONG
NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt,
PFILE_RECORD_HEADER FileRecord,
PFILENAME_ATTRIBUTE FileName)
PCWSTR Stream,
ULONG StreamLength,
PULONGLONG AllocatedSize)
{
ULONGLONG Size;
ULONGLONG Size = 0ULL;
ULONGLONG Allocated = 0ULL;
NTSTATUS Status;
PNTFS_ATTR_CONTEXT DataContext;
Size = FileName->AllocatedSize;
Status = FindAttribute(DeviceExt, FileRecord, AttributeData, L"", 0, &DataContext);
Status = FindAttribute(DeviceExt, FileRecord, AttributeData, Stream, StreamLength, &DataContext);
if (NT_SUCCESS(Status))
{
Size = AttributeDataLength(&DataContext->Record);
Allocated = AttributeAllocatedLength(&DataContext->Record);
ReleaseAttributeContext(DataContext);
}
if (AllocatedSize != NULL) *AllocatedSize = Allocated;
return Size;
}
@ -130,7 +135,7 @@ NtfsGetDirectoryInformation(PDEVICE_EXTENSION DeviceExt,
/* Convert file flags */
NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, FileName);
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, NULL);
Info->AllocationSize.QuadPart = ROUND_UP(Info->EndOfFile.QuadPart, DeviceExt->NtfsInfo.BytesPerCluster);
Info->FileIndex = MFTIndex;
@ -180,7 +185,7 @@ NtfsGetFullDirectoryInformation(PDEVICE_EXTENSION DeviceExt,
/* Convert file flags */
NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, FileName);
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, NULL);
Info->AllocationSize.QuadPart = ROUND_UP(Info->EndOfFile.QuadPart, DeviceExt->NtfsInfo.BytesPerCluster);
Info->FileIndex = MFTIndex;
@ -245,7 +250,7 @@ NtfsGetBothDirectoryInformation(PDEVICE_EXTENSION DeviceExt,
/* Convert file flags */
NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, FileName);
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, NULL);
Info->AllocationSize.QuadPart = ROUND_UP(Info->EndOfFile.QuadPart, DeviceExt->NtfsInfo.BytesPerCluster);
Info->FileIndex = MFTIndex;
@ -362,7 +367,7 @@ NtfsQueryDirectory(PNTFS_IRP_CONTEXT IrpContext)
*/
if (MFTRecord == OldMFTRecord)
{
DPRINT("Ignoring duplicate MFT entry 0x%x\n", MFTRecord);
DPRINT1("Ignoring duplicate MFT entry 0x%x\n", MFTRecord);
Ccb->Entry++;
ExFreePoolWithTag(FileRecord, TAG_NTFS);
continue;

View file

@ -421,6 +421,7 @@ NtfsMakeFCBFromDirEntry(PNTFS_VCB Vcb,
PFILENAME_ATTRIBUTE FileName;
PSTANDARD_INFORMATION StdInfo;
PNTFS_FCB rcFCB;
ULONGLONG Size, AllocatedSize;
DPRINT1("NtfsMakeFCBFromDirEntry(%p, %p, %wZ, %p, %p, %p)\n", Vcb, DirectoryFCB, Name, Stream, Record, fileFCB);
@ -451,6 +452,8 @@ NtfsMakeFCBFromDirEntry(PNTFS_VCB Vcb,
pathName[FileName->NameLength] = UNICODE_NULL;
}
Size = NtfsGetFileSize(Vcb, Record, Stream, wcslen(Stream), &AllocatedSize);
rcFCB = NtfsCreateFCB(pathName, Stream, Vcb);
if (!rcFCB)
{
@ -459,9 +462,9 @@ NtfsMakeFCBFromDirEntry(PNTFS_VCB Vcb,
memcpy(&rcFCB->Entry, FileName, FIELD_OFFSET(FILENAME_ATTRIBUTE, NameLength));
rcFCB->Entry.NameType = FileName->NameType;
rcFCB->RFCB.FileSize.QuadPart = FileName->DataSize;
rcFCB->RFCB.ValidDataLength.QuadPart = FileName->DataSize;
rcFCB->RFCB.AllocationSize.QuadPart = FileName->AllocatedSize;
rcFCB->RFCB.FileSize.QuadPart = Size;
rcFCB->RFCB.ValidDataLength.QuadPart = Size;
rcFCB->RFCB.AllocationSize.QuadPart = AllocatedSize;
StdInfo = GetStandardInformationFromRecord(Record);
if (StdInfo != NULL)

View file

@ -550,6 +550,13 @@ NtfsDeviceControl(PNTFS_IRP_CONTEXT IrpContext);
/* dirctl.c */
ULONGLONG
NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt,
PFILE_RECORD_HEADER FileRecord,
PCWSTR Stream,
ULONG StreamLength,
PULONGLONG AllocatedSize);
NTSTATUS
NtfsDirectoryControl(PNTFS_IRP_CONTEXT IrpContext);