-AddFileName() - Don't use dedicated buffer for FileNameNoPath, just point into FileObject->FileName's buffer. Don't use RtlCopyUnicodeString(), just update pointers.
-AddRun() - Fix an SEH2_YIELD with missing return statement.
-FreeClusters() - Use ULONG_MAX in place of 0xffffffff.
-NtfsDumpIndexRootAttribute() - Use consistent UpperCase naming convention. Use BooleanFlagOn() macro where appropriate. Replace magic 8 with sizeof(ULONGLONG).
-GetFileNameAttributeLength() - Add documentation.
svn path=/branches/GSoC_2016/NTFS/; revision=75279
/* INCLUDES *****************************************************************/
#include "ntfs.h"
/* INCLUDES *****************************************************************/
#include "ntfs.h"
#define NDEBUG
#include <debug.h>
#define NDEBUG
#include <debug.h>
UNICODE_STRING Current, Remaining, FilenameNoPath;
NTSTATUS Status = STATUS_SUCCESS;
ULONG FirstEntry;
UNICODE_STRING Current, Remaining, FilenameNoPath;
NTSTATUS Status = STATUS_SUCCESS;
ULONG FirstEntry;
- WCHAR Buffer[MAX_PATH];
if (AttributeAddress->Type != AttributeEnd)
{
if (AttributeAddress->Type != AttributeEnd)
{
// we need to extract the filename from the path
DPRINT1("Pathname: %wZ\n", &FileObject->FileName);
// we need to extract the filename from the path
DPRINT1("Pathname: %wZ\n", &FileObject->FileName);
- RtlInitEmptyUnicodeString(&FilenameNoPath, Buffer, MAX_PATH);
+ FilenameNoPath.Buffer = FileObject->FileName.Buffer;
+ FilenameNoPath.MaximumLength = FilenameNoPath.Length = FileObject->FileName.Length;
FsRtlDissectName(FileObject->FileName, &Current, &Remaining);
FsRtlDissectName(FileObject->FileName, &Current, &Remaining);
{
DPRINT1("Current: %wZ\n", &Current);
{
DPRINT1("Current: %wZ\n", &Current);
- if(Remaining.Length != 0)
- RtlCopyUnicodeString(&FilenameNoPath, &Remaining);
+ if (Remaining.Length != 0)
+ {
+ FilenameNoPath.Buffer = Remaining.Buffer;
+ FilenameNoPath.Length = FilenameNoPath.MaximumLength = Remaining.Length;
+ }
FirstEntry = 0;
Status = NtfsFindMftRecord(DeviceExt,
FirstEntry = 0;
Status = NtfsFindMftRecord(DeviceExt,
if (Remaining.Length == 0 )
{
if (Remaining.Length == 0 )
{
- if(Current.Length != 0)
- RtlCopyUnicodeString(&FilenameNoPath, &Current);
+ if (Current.Length != 0)
+ {
+ FilenameNoPath.Buffer = Current.Buffer;
+ FilenameNoPath.Length = FilenameNoPath.MaximumLength = Current.Length;
+ }
{
ExRaiseStatus(STATUS_UNSUCCESSFUL);
}
{
ExRaiseStatus(STATUS_UNSUCCESSFUL);
}
- } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
- _SEH2_YIELD(_SEH2_GetExceptionCode());
- } _SEH2_END;
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ DPRINT1("Failed to add LargeMcb Entry!\n");
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
+ }
+ _SEH2_END;
RunBuffer = ExAllocatePoolWithTag(NonPagedPool, Vcb->NtfsInfo.BytesPerFileRecord, TAG_NTFS);
if (!RunBuffer)
RunBuffer = ExAllocatePoolWithTag(NonPagedPool, Vcb->NtfsInfo.BytesPerFileRecord, TAG_NTFS);
if (!RunBuffer)
}
BitmapDataSize = AttributeDataLength(&DataContext->Record);
}
BitmapDataSize = AttributeDataLength(&DataContext->Record);
- BitmapDataSize = min(BitmapDataSize, 0xffffffff);
+ BitmapDataSize = min(BitmapDataSize, ULONG_MAX);
ASSERT((BitmapDataSize * 8) >= Vcb->NtfsInfo.ClusterCount);
BitmapData = ExAllocatePoolWithTag(NonPagedPool, ROUND_UP(BitmapDataSize, Vcb->NtfsInfo.BytesPerSector), TAG_NTFS);
if (BitmapData == NULL)
ASSERT((BitmapDataSize * 8) >= Vcb->NtfsInfo.ClusterCount);
BitmapData = ExAllocatePoolWithTag(NonPagedPool, ROUND_UP(BitmapDataSize, Vcb->NtfsInfo.BytesPerSector), TAG_NTFS);
if (BitmapData == NULL)
NtfsDumpIndexRootAttribute(PNTFS_ATTR_RECORD Attribute)
{
PINDEX_ROOT_ATTRIBUTE IndexRootAttr;
NtfsDumpIndexRootAttribute(PNTFS_ATTR_RECORD Attribute)
{
PINDEX_ROOT_ATTRIBUTE IndexRootAttr;
- ULONG currentOffset;
- ULONG currentNode;
+ ULONG CurrentOffset;
+ ULONG CurrentNode;
IndexRootAttr = (PINDEX_ROOT_ATTRIBUTE)((ULONG_PTR)Attribute + Attribute->Resident.ValueOffset);
IndexRootAttr = (PINDEX_ROOT_ATTRIBUTE)((ULONG_PTR)Attribute + Attribute->Resident.ValueOffset);
IndexRootAttr->Header.FirstEntryOffset,
IndexRootAttr->Header.TotalSizeOfEntries,
IndexRootAttr->Header.AllocatedSize);
IndexRootAttr->Header.FirstEntryOffset,
IndexRootAttr->Header.TotalSizeOfEntries,
IndexRootAttr->Header.AllocatedSize);
- currentOffset = IndexRootAttr->Header.FirstEntryOffset;
- currentNode = 0;
+ CurrentOffset = IndexRootAttr->Header.FirstEntryOffset;
+ CurrentNode = 0;
// print details of every node in the index
// print details of every node in the index
- while (currentOffset < IndexRootAttr->Header.TotalSizeOfEntries)
+ while (CurrentOffset < IndexRootAttr->Header.TotalSizeOfEntries)
- PINDEX_ENTRY_ATTRIBUTE currentIndexExtry = (PINDEX_ENTRY_ATTRIBUTE)((ULONG_PTR)IndexRootAttr + 0x10 + currentOffset);
- DbgPrint(" Index Node Entry %lu", currentNode++);
- if (currentIndexExtry->Flags & NTFS_INDEX_ENTRY_NODE)
+ PINDEX_ENTRY_ATTRIBUTE currentIndexExtry = (PINDEX_ENTRY_ATTRIBUTE)((ULONG_PTR)IndexRootAttr + 0x10 + CurrentOffset);
+ DbgPrint(" Index Node Entry %lu", CurrentNode++);
+ if (BooleanFlagOn(currentIndexExtry->Flags, NTFS_INDEX_ENTRY_NODE))
DbgPrint(" (Branch)");
else
DbgPrint(" (Leaf)");
DbgPrint(" (Branch)");
else
DbgPrint(" (Leaf)");
- if((currentIndexExtry->Flags & NTFS_INDEX_ENTRY_END))
+ if (BooleanFlagOn(currentIndexExtry->Flags, NTFS_INDEX_ENTRY_END))
{
DbgPrint(" (Dummy Key)");
}
{
DbgPrint(" (Dummy Key)");
}
if (currentIndexExtry->Flags & NTFS_INDEX_ENTRY_NODE)
{
// Print the VCN of the sub-node
if (currentIndexExtry->Flags & NTFS_INDEX_ENTRY_NODE)
{
// Print the VCN of the sub-node
- PULONGLONG SubNodeVCN = (PULONGLONG)((ULONG_PTR)currentIndexExtry + currentIndexExtry->Length - 8);
+ PULONGLONG SubNodeVCN = (PULONGLONG)((ULONG_PTR)currentIndexExtry + currentIndexExtry->Length - sizeof(ULONGLONG));
DbgPrint(" VCN of sub-node: 0x%llx\n", *SubNodeVCN);
}
DbgPrint(" VCN of sub-node: 0x%llx\n", *SubNodeVCN);
}
- currentOffset += currentIndexExtry->Length;
+ CurrentOffset += currentIndexExtry->Length;
ASSERT(currentIndexExtry->Length);
}
ASSERT(currentIndexExtry->Length);
}
+/**
+* @name GetFileNameAttributeLength
+* @implemented
+*
+* Returns the size of a given FILENAME_ATTRIBUTE, in bytes.
+*
+* @param FileNameAttribute
+* Pointer to a FILENAME_ATTRIBUTE to determine the size of.
+*
+* @remarks
+* The length of a FILENAME_ATTRIBUTE is variable and is dependent on the length of the file name stored at the end.
+* This function operates on the FILENAME_ATTRIBUTE proper, so don't try to pass it a PNTFS_ATTR_RECORD.
+*/
ULONG GetFileNameAttributeLength(PFILENAME_ATTRIBUTE FileNameAttribute)
{
ULONG Length = FIELD_OFFSET(FILENAME_ATTRIBUTE, Name) + (FileNameAttribute->NameLength * sizeof(WCHAR));
ULONG GetFileNameAttributeLength(PFILENAME_ATTRIBUTE FileNameAttribute)
{
ULONG Length = FIELD_OFFSET(FILENAME_ATTRIBUTE, Name) + (FileNameAttribute->NameLength * sizeof(WCHAR));