static NTSTATUS NtfsGetNameInformation(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PNTFS_ATTR_CONTEXT DataContext, PFILE_NAMES_INFORMATION Info, ULONG BufferLength) { ULONG Length; PFILENAME_ATTRIBUTE FileName; DPRINT("NtfsGetNameInformation() called\n"); FileName = GetBestFileNameFromRecord(FileRecord); ASSERT(FileName != NULL); Length = FileName->NameLength * sizeof (WCHAR); if ((sizeof(FILE_NAMES_INFORMATION) + Length) > BufferLength) return(STATUS_BUFFER_OVERFLOW); Info->FileNameLength = Length; Info->NextEntryOffset = ROUND_UP(sizeof(FILE_NAMES_INFORMATION) + Length, sizeof(ULONG)); RtlCopyMemory(Info->FileName, FileName->Name, Length); return(STATUS_SUCCESS); }
static NTSTATUS NtfsGetBothDirectoryInformation(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PNTFS_ATTR_CONTEXT DataContext, ULONGLONG MFTIndex, PFILE_BOTH_DIR_INFORMATION Info, ULONG BufferLength) { ULONG Length; PFILENAME_ATTRIBUTE FileName, ShortFileName; DPRINT("NtfsGetBothDirectoryInformation() called\n"); FileName = GetBestFileNameFromRecord(FileRecord); ASSERT(FileName != NULL); ShortFileName = GetFileNameFromRecord(FileRecord, NTFS_FILE_NAME_DOS); Length = FileName->NameLength * sizeof (WCHAR); if ((sizeof(FILE_BOTH_DIR_INFORMATION) + Length) > BufferLength) return(STATUS_BUFFER_OVERFLOW); Info->FileNameLength = Length; Info->NextEntryOffset = ROUND_UP(sizeof(FILE_BOTH_DIR_INFORMATION) + Length, sizeof(ULONG)); RtlCopyMemory(Info->FileName, FileName->Name, Length); if (ShortFileName) { /* Should we upcase the filename? */ ASSERT(ShortFileName->NameLength <= ARRAYSIZE(Info->ShortName)); Info->ShortNameLength = ShortFileName->NameLength * sizeof(WCHAR); RtlCopyMemory(Info->ShortName, ShortFileName->Name, Info->ShortNameLength); } else { Info->ShortName[0] = 0; Info->ShortNameLength = 0; } Info->CreationTime.QuadPart = FileName->CreationTime; Info->LastAccessTime.QuadPart = FileName->LastAccessTime; Info->LastWriteTime.QuadPart = FileName->LastWriteTime; Info->ChangeTime.QuadPart = FileName->ChangeTime; /* Convert file flags */ NtfsFileFlagsToAttributes(FileName->FileAttributes, &Info->FileAttributes); Info->EndOfFile.QuadPart = FileName->AllocatedSize; Info->AllocationSize.QuadPart = ROUND_UP(FileName->AllocatedSize, DeviceExt->NtfsInfo.BytesPerCluster); Info->FileIndex = MFTIndex; Info->EaSize = 0; return STATUS_SUCCESS; }
static NTSTATUS NtfsGetDirectoryInformation(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PNTFS_ATTR_CONTEXT DataContext, PFILE_DIRECTORY_INFORMATION Info, ULONG BufferLength) { ULONG Length; PFILENAME_ATTRIBUTE FileName; DPRINT("NtfsGetDirectoryInformation() called\n"); FileName = GetBestFileNameFromRecord(FileRecord); ASSERT(FileName != NULL); Length = FileName->NameLength * sizeof (WCHAR); if ((sizeof(FILE_DIRECTORY_INFORMATION) + Length) > BufferLength) return(STATUS_BUFFER_OVERFLOW); Info->FileNameLength = Length; Info->NextEntryOffset = ROUND_UP(sizeof(FILE_DIRECTORY_INFORMATION) + Length, sizeof(ULONG)); RtlCopyMemory(Info->FileName, FileName->Name, Length); Info->CreationTime.QuadPart = FileName->CreationTime; Info->LastAccessTime.QuadPart = FileName->LastAccessTime; Info->LastWriteTime.QuadPart = FileName->LastWriteTime; Info->ChangeTime.QuadPart = FileName->ChangeTime; /* Convert file flags */ NtfsFileFlagsToAttributes(FileName->FileAttributes, &Info->FileAttributes); Info->EndOfFile.QuadPart = FileName->AllocatedSize; Info->AllocationSize.QuadPart = ROUND_UP(FileName->AllocatedSize, DeviceExt->NtfsInfo.BytesPerCluster); // Info->FileIndex=; return STATUS_SUCCESS; }
NTSTATUS NtfsMakeFCBFromDirEntry(PNTFS_VCB Vcb, PNTFS_FCB DirectoryFCB, PUNICODE_STRING Name, PCWSTR Stream, PFILE_RECORD_HEADER Record, ULONGLONG MFTIndex, PNTFS_FCB * fileFCB) { WCHAR pathName[MAX_PATH]; 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); FileName = GetBestFileNameFromRecord(Vcb, Record); if (!FileName) { return STATUS_OBJECT_NAME_NOT_FOUND; // Not sure that's the best here } if (DirectoryFCB && Name) { if (Name->Buffer[0] != 0 && wcslen(DirectoryFCB->PathName) + sizeof(WCHAR) + Name->Length / sizeof(WCHAR) > MAX_PATH) { return STATUS_OBJECT_NAME_INVALID; } wcscpy(pathName, DirectoryFCB->PathName); if (!NtfsFCBIsRoot(DirectoryFCB)) { wcscat(pathName, L"\\"); } wcscat(pathName, Name->Buffer); } else { RtlCopyMemory(pathName, FileName->Name, FileName->NameLength * sizeof (WCHAR)); pathName[FileName->NameLength] = UNICODE_NULL; } Size = NtfsGetFileSize(Vcb, Record, (Stream ? Stream : L""), (Stream ? wcslen(Stream) : 0), &AllocatedSize); rcFCB = NtfsCreateFCB(pathName, Stream, Vcb); if (!rcFCB) { return STATUS_INSUFFICIENT_RESOURCES; } memcpy(&rcFCB->Entry, FileName, FIELD_OFFSET(FILENAME_ATTRIBUTE, NameLength)); rcFCB->Entry.NameType = FileName->NameType; rcFCB->RFCB.FileSize.QuadPart = Size; rcFCB->RFCB.ValidDataLength.QuadPart = Size; rcFCB->RFCB.AllocationSize.QuadPart = AllocatedSize; StdInfo = GetStandardInformationFromRecord(Vcb, Record); if (StdInfo != NULL) { rcFCB->Entry.FileAttributes |= StdInfo->FileAttribute; } NtfsFCBInitializeCache(Vcb, rcFCB); rcFCB->RefCount = 1; rcFCB->MFTIndex = MFTIndex; rcFCB->LinkCount = Record->LinkCount; NtfsAddFCBToTable(Vcb, rcFCB); *fileFCB = rcFCB; return STATUS_SUCCESS; }