mirror of
https://github.com/reactos/reactos.git
synced 2025-05-07 18:56:48 +00:00
[NTFS] - Add some fixes and improvements to finfo.c from CR-123:
NtfsSetEndOfFile() - Make fileNameAttribute and filename variables uppercase. Don't leak FileRecord if we can't truncate the file. Don't leak memory if there's no FileName attribute. svn path=/branches/GSoC_2016/NTFS/; revision=75283
This commit is contained in:
parent
39a06fae0d
commit
34696e49fc
1 changed files with 12 additions and 9 deletions
|
@ -449,9 +449,9 @@ NtfsSetEndOfFile(PNTFS_FCB Fcb,
|
||||||
ULONG AttributeOffset;
|
ULONG AttributeOffset;
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
ULONGLONG AllocationSize;
|
ULONGLONG AllocationSize;
|
||||||
PFILENAME_ATTRIBUTE fileNameAttribute;
|
PFILENAME_ATTRIBUTE FileNameAttribute;
|
||||||
ULONGLONG ParentMFTId;
|
ULONGLONG ParentMFTId;
|
||||||
UNICODE_STRING filename;
|
UNICODE_STRING FileName;
|
||||||
|
|
||||||
|
|
||||||
// Allocate non-paged memory for the file record
|
// Allocate non-paged memory for the file record
|
||||||
|
@ -485,6 +485,7 @@ NtfsSetEndOfFile(PNTFS_FCB Fcb,
|
||||||
NewFileSize))
|
NewFileSize))
|
||||||
{
|
{
|
||||||
DPRINT1("Couldn't decrease file size!\n");
|
DPRINT1("Couldn't decrease file size!\n");
|
||||||
|
ExFreePoolWithTag(FileRecord, TAG_NTFS);
|
||||||
return STATUS_USER_MAPPED_FILE;
|
return STATUS_USER_MAPPED_FILE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -535,24 +536,26 @@ NtfsSetEndOfFile(PNTFS_FCB Fcb,
|
||||||
|
|
||||||
// now we need to update this file's size in every directory index entry that references it
|
// now we need to update this file's size in every directory index entry that references it
|
||||||
// TODO: expand to work with every filename / hardlink stored in the file record.
|
// TODO: expand to work with every filename / hardlink stored in the file record.
|
||||||
fileNameAttribute = GetBestFileNameFromRecord(Fcb->Vcb, FileRecord);
|
FileNameAttribute = GetBestFileNameFromRecord(Fcb->Vcb, FileRecord);
|
||||||
if (fileNameAttribute == NULL)
|
if (FileNameAttribute == NULL)
|
||||||
{
|
{
|
||||||
DPRINT1("Unable to find FileName attribute associated with file!\n");
|
DPRINT1("Unable to find FileName attribute associated with file!\n");
|
||||||
|
ReleaseAttributeContext(DataContext);
|
||||||
|
ExFreePoolWithTag(FileRecord, TAG_NTFS);
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParentMFTId = fileNameAttribute->DirectoryFileReferenceNumber & NTFS_MFT_MASK;
|
ParentMFTId = FileNameAttribute->DirectoryFileReferenceNumber & NTFS_MFT_MASK;
|
||||||
|
|
||||||
filename.Buffer = fileNameAttribute->Name;
|
FileName.Buffer = FileNameAttribute->Name;
|
||||||
filename.Length = fileNameAttribute->NameLength * sizeof(WCHAR);
|
FileName.Length = FileNameAttribute->NameLength * sizeof(WCHAR);
|
||||||
filename.MaximumLength = filename.Length;
|
FileName.MaximumLength = FileName.Length;
|
||||||
|
|
||||||
AllocationSize = ROUND_UP(NewFileSize->QuadPart, Fcb->Vcb->NtfsInfo.BytesPerCluster);
|
AllocationSize = ROUND_UP(NewFileSize->QuadPart, Fcb->Vcb->NtfsInfo.BytesPerCluster);
|
||||||
|
|
||||||
Status = UpdateFileNameRecord(Fcb->Vcb,
|
Status = UpdateFileNameRecord(Fcb->Vcb,
|
||||||
ParentMFTId,
|
ParentMFTId,
|
||||||
&filename,
|
&FileName,
|
||||||
FALSE,
|
FALSE,
|
||||||
NewFileSize->QuadPart,
|
NewFileSize->QuadPart,
|
||||||
AllocationSize,
|
AllocationSize,
|
||||||
|
|
Loading…
Reference in a new issue