ReactOS  0.4.15-dev-5492-g47f3a4e
fcb.c File Reference
#include "ntfs.h"
#include <debug.h>
Include dependency graph for fcb.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static PCWSTR NtfsGetNextPathElement (PCWSTR FileName)
 
static VOID NtfsWSubString (PWCHAR pTarget, PCWSTR pSource, size_t pLength)
 
PNTFS_FCB NtfsCreateFCB (PCWSTR FileName, PCWSTR Stream, PNTFS_VCB Vcb)
 
VOID NtfsDestroyFCB (PNTFS_FCB Fcb)
 
BOOLEAN NtfsFCBIsDirectory (PNTFS_FCB Fcb)
 
BOOLEAN NtfsFCBIsReparsePoint (PNTFS_FCB Fcb)
 
BOOLEAN NtfsFCBIsCompressed (PNTFS_FCB Fcb)
 
BOOLEAN NtfsFCBIsEncrypted (PNTFS_FCB Fcb)
 
BOOLEAN NtfsFCBIsRoot (PNTFS_FCB Fcb)
 
VOID NtfsGrabFCB (PNTFS_VCB Vcb, PNTFS_FCB Fcb)
 
VOID NtfsReleaseFCB (PNTFS_VCB Vcb, PNTFS_FCB Fcb)
 
VOID NtfsAddFCBToTable (PNTFS_VCB Vcb, PNTFS_FCB Fcb)
 
PNTFS_FCB NtfsGrabFCBFromTable (PNTFS_VCB Vcb, PCWSTR FileName)
 
NTSTATUS NtfsFCBInitializeCache (PNTFS_VCB Vcb, PNTFS_FCB Fcb)
 
PNTFS_FCB NtfsMakeRootFCB (PNTFS_VCB Vcb)
 
PNTFS_FCB NtfsOpenRootFCB (PNTFS_VCB Vcb)
 
NTSTATUS NtfsMakeFCBFromDirEntry (PNTFS_VCB Vcb, PNTFS_FCB DirectoryFCB, PUNICODE_STRING Name, PCWSTR Stream, PFILE_RECORD_HEADER Record, ULONGLONG MFTIndex, PNTFS_FCB *fileFCB)
 
NTSTATUS NtfsAttachFCBToFileObject (PNTFS_VCB Vcb, PNTFS_FCB Fcb, PFILE_OBJECT FileObject)
 
static NTSTATUS NtfsDirFindFile (PNTFS_VCB Vcb, PNTFS_FCB DirectoryFcb, PWSTR FileToFind, BOOLEAN CaseSensitive, PNTFS_FCB *FoundFCB)
 
NTSTATUS NtfsGetFCBForFile (PNTFS_VCB Vcb, PNTFS_FCB *pParentFCB, PNTFS_FCB *pFCB, PCWSTR pFileName, BOOLEAN CaseSensitive)
 
NTSTATUS NtfsReadFCBAttribute (PNTFS_VCB Vcb, PNTFS_FCB pFCB, ULONG Type, PCWSTR Name, ULONG NameLength, PVOID *Data)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 32 of file fcb.c.

Function Documentation

◆ NtfsAddFCBToTable()

VOID NtfsAddFCBToTable ( PNTFS_VCB  Vcb,
PNTFS_FCB  Fcb 
)

Definition at line 209 of file fcb.c.

211 {
212  KIRQL oldIrql;
213 
214  KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
215  Fcb->Vcb = Vcb;
216  InsertTailList(&Vcb->FcbListHead, &Fcb->FcbListEntry);
217  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
218 }
LIST_ENTRY FcbListEntry
Definition: ntfs.h:530
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define Vcb
Definition: cdprocs.h:1415
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
PVCB Vcb
Definition: cdstruc.h:933
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by NtfsMakeFCBFromDirEntry(), and NtfsMakeRootFCB().

◆ NtfsAttachFCBToFileObject()

NTSTATUS NtfsAttachFCBToFileObject ( PNTFS_VCB  Vcb,
PNTFS_FCB  Fcb,
PFILE_OBJECT  FileObject 
)

Definition at line 464 of file fcb.c.

467 {
468  PNTFS_CCB newCCB;
469 
471  if (newCCB == NULL)
472  {
474  }
475 
476  RtlZeroMemory(newCCB, sizeof(NTFS_CCB));
477 
478  newCCB->Identifier.Type = NTFS_TYPE_CCB;
479  newCCB->Identifier.Size = sizeof(NTFS_TYPE_CCB);
480 
481  FileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
482  FileObject->FsContext = Fcb;
483  FileObject->FsContext2 = newCCB;
484  newCCB->PtrFileObject = FileObject;
485  Fcb->Vcb = Vcb;
486 
487  if (!(Fcb->Flags & FCB_CACHE_INITIALIZED))
488  {
489  _SEH2_TRY
490  {
493  FALSE,
495  Fcb);
496  }
498  {
499  FileObject->FsContext2 = NULL;
500  ExFreePoolWithTag(newCCB, TAG_CCB);
501  return _SEH2_GetExceptionCode();
502  }
503  _SEH2_END;
504 
506  }
507 
508  //DPRINT("file open: fcb:%x file size: %d\n", Fcb, Fcb->Entry.DataLengthL);
509 
510  return STATUS_SUCCESS;
511 }
_SEH2_TRY
Definition: create.c:4226
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_SEH2_END
Definition: create.c:4400
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:36
Definition: ntfs.h:129
#define FALSE
Definition: types.h:117
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
FSRTL_COMMON_FCB_HEADER RFCB
Definition: ntfs.h:517
PFILE_OBJECT PtrFileObject
Definition: ntfs.h:133
VOID NTAPI CcInitializeCacheMap(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes, IN BOOLEAN PinAccess, IN PCACHE_MANAGER_CALLBACKS Callbacks, IN PVOID LazyWriteContext)
Definition: fssup.c:195
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define Vcb
Definition: cdprocs.h:1415
#define TAG_CCB
Definition: cdprocs.h:85
#define FCB_CACHE_INITIALIZED
Definition: ntfs.h:508
ULONG Flags
Definition: ntfs.h:536
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG Type
Definition: ntfs.h:95
#define NTFS_TYPE_CCB
Definition: ntfs.h:87
LARGE_INTEGER AllocationSize
Definition: env_spec_w32.h:755
NTFSIDENTIFIER Identifier
Definition: ntfs.h:131
CACHE_MANAGER_CALLBACKS CacheMgrCallbacks
Definition: ntfs.h:149
#define NULL
Definition: types.h:112
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PVCB Vcb
Definition: cdstruc.h:933
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:518
ULONG Size
Definition: ntfs.h:96

Referenced by NtfsCreateFile(), NtfsOpenFile(), and NtfsOpenFileById().

◆ NtfsCreateFCB()

PNTFS_FCB NtfsCreateFCB ( PCWSTR  FileName,
PCWSTR  Stream,
PNTFS_VCB  Vcb 
)

Definition at line 67 of file fcb.c.

70 {
71  PNTFS_FCB Fcb;
72 
73  ASSERT(Vcb);
74  ASSERT(Vcb->Identifier.Type == NTFS_TYPE_VCB);
75 
76  Fcb = ExAllocateFromNPagedLookasideList(&NtfsGlobalData->FcbLookasideList);
77  if (Fcb == NULL)
78  {
79  return NULL;
80  }
81 
82  RtlZeroMemory(Fcb, sizeof(NTFS_FCB));
83 
85  Fcb->Identifier.Size = sizeof(NTFS_TYPE_FCB);
86 
87  Fcb->Vcb = Vcb;
88 
89  if (FileName)
90  {
92  if (wcsrchr(Fcb->PathName, '\\') != 0)
93  {
94  Fcb->ObjectName = wcsrchr(Fcb->PathName, '\\');
95  }
96  else
97  {
99  }
100  }
101 
102  if (Stream)
103  {
104  wcscpy(Fcb->Stream, Stream);
105  }
106  else
107  {
108  Fcb->Stream[0] = UNICODE_NULL;
109  }
110 
112 
114 
115  return Fcb;
116 }
#define NTFS_TYPE_VCB
Definition: ntfs.h:89
NPAGED_LOOKASIDE_LIST FcbLookasideList
Definition: ntfs.h:153
Definition: cdstruc.h:902
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
WCHAR PathName[MAX_PATH]
Definition: ntfs.h:525
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:36
NTFSIDENTIFIER Identifier
Definition: ntfs.h:515
#define UNICODE_NULL
WCHAR Stream[MAX_PATH]
Definition: ntfs.h:523
WCHAR * ObjectName
Definition: ntfs.h:524
FSRTL_COMMON_FCB_HEADER RFCB
Definition: ntfs.h:517
#define NTFS_TYPE_FCB
Definition: ntfs.h:88
#define ASSERT(a)
Definition: mode.c:44
#define Vcb
Definition: cdprocs.h:1415
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
ULONG Type
Definition: ntfs.h:95
#define wcsrchr
Definition: compat.h:16
ERESOURCE MainResource
Definition: ntfs.h:528
#define NULL
Definition: types.h:112
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PVCB Vcb
Definition: cdstruc.h:933
_In_ PFCB Fcb
Definition: cdprocs.h:159
ULONG Size
Definition: ntfs.h:96
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by NtfsGetVolumeData(), NtfsMakeFCBFromDirEntry(), NtfsMakeRootFCB(), and NtfsMountVolume().

◆ NtfsDestroyFCB()

VOID NtfsDestroyFCB ( PNTFS_FCB  Fcb)

Definition at line 120 of file fcb.c.

121 {
122  ASSERT(Fcb);
124 
126 
127  ExFreeToNPagedLookasideList(&NtfsGlobalData->FcbLookasideList, Fcb);
128 }
NPAGED_LOOKASIDE_LIST FcbLookasideList
Definition: ntfs.h:153
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:36
NTFSIDENTIFIER Identifier
Definition: ntfs.h:515
#define NTFS_TYPE_FCB
Definition: ntfs.h:88
#define ASSERT(a)
Definition: mode.c:44
ULONG Type
Definition: ntfs.h:95
ERESOURCE MainResource
Definition: ntfs.h:528
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by NtfsReleaseFCB().

◆ NtfsDirFindFile()

static NTSTATUS NtfsDirFindFile ( PNTFS_VCB  Vcb,
PNTFS_FCB  DirectoryFcb,
PWSTR  FileToFind,
BOOLEAN  CaseSensitive,
PNTFS_FCB FoundFCB 
)
static

Definition at line 515 of file fcb.c.

520 {
522  ULONGLONG CurrentDir;
524  PFILE_RECORD_HEADER FileRecord;
525  ULONGLONG MFTIndex;
526  PWSTR Colon, OldColon;
527  PNTFS_ATTR_CONTEXT DataContext;
528  USHORT Length = 0;
529 
530  DPRINT("NtfsDirFindFile(%p, %p, %S, %s, %p)\n",
531  Vcb,
532  DirectoryFcb,
533  FileToFind,
534  CaseSensitive ? "TRUE" : "FALSE",
535  FoundFCB);
536 
537  *FoundFCB = NULL;
538  RtlInitUnicodeString(&File, FileToFind);
539  CurrentDir = DirectoryFcb->MFTIndex;
540 
541  Colon = wcsrchr(FileToFind, L':');
542  if (Colon != NULL)
543  {
544  Length = File.Length;
545  File.Length = (Colon - FileToFind) * sizeof(WCHAR);
546 
547  if (_wcsicmp(Colon + 1, L"$DATA") == 0)
548  {
549  OldColon = Colon;
550  Colon[0] = UNICODE_NULL;
551  Colon = wcsrchr(FileToFind, L':');
552  if (Colon != NULL)
553  {
554  Length = File.Length;
555  File.Length = (Colon - FileToFind) * sizeof(WCHAR);
556  }
557  else
558  {
559  Colon = OldColon;
560  Colon[0] = L':';
561  }
562  }
563 
564  /* Skip colon */
565  ++Colon;
566  DPRINT1("Will now look for file '%wZ' with stream '%S'\n", &File, Colon);
567  }
568 
569  Status = NtfsLookupFileAt(Vcb, &File, CaseSensitive, &FileRecord, &MFTIndex, CurrentDir);
570  if (!NT_SUCCESS(Status))
571  {
572  return Status;
573  }
574 
575  if (Length != 0)
576  {
577  File.Length = Length;
578  }
579 
580  if ((FileRecord->Flags & FRH_DIRECTORY) && Colon != 0)
581  {
582  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
584  }
585  else if (Colon != 0)
586  {
587  Status = FindAttribute(Vcb, FileRecord, AttributeData, Colon, wcslen(Colon), &DataContext, NULL);
588  if (!NT_SUCCESS(Status))
589  {
591  }
592  ReleaseAttributeContext(DataContext);
593  }
594 
595  Status = NtfsMakeFCBFromDirEntry(Vcb, DirectoryFcb, &File, Colon, FileRecord, MFTIndex, FoundFCB);
596  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
597 
598  return Status;
599 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NtfsMakeFCBFromDirEntry(PNTFS_VCB Vcb, PNTFS_FCB DirectoryFCB, PUNICODE_STRING Name, PCWSTR Stream, PFILE_RECORD_HEADER Record, ULONGLONG MFTIndex, PNTFS_FCB *fileFCB)
Definition: fcb.c:389
NTSTATUS NtfsLookupFileAt(PDEVICE_EXTENSION Vcb, PUNICODE_STRING PathName, BOOLEAN CaseSensitive, PFILE_RECORD_HEADER *FileRecord, PULONGLONG MFTIndex, ULONGLONG CurrentMFTIndex)
Definition: mft.c:3229
NTSTATUS FindAttribute(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER MftRecord, ULONG Type, PCWSTR Name, ULONG NameLength, PNTFS_ATTR_CONTEXT *AttrCtx, PULONG Offset)
Definition: mft.c:131
ULONGLONG MFTIndex
Definition: ntfs.h:539
#define L(x)
Definition: ntvdm.h:50
#define UNICODE_NULL
#define FRH_DIRECTORY
Definition: ntfs.h:268
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
#define Vcb
Definition: cdprocs.h:1415
#define wcsrchr
Definition: compat.h:16
Definition: asmpp.cpp:43
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
VOID ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context)
Definition: mft.c:104
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
USHORT Flags
Definition: ntfs.h:256
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
Definition: File.h:15
#define DPRINT
Definition: sndvol32.h:71
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID _In_ LONG _In_z_ PCHAR File
Definition: wdfdevice.h:4061
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by NtfsGetFCBForFile().

◆ NtfsFCBInitializeCache()

NTSTATUS NtfsFCBInitializeCache ( PNTFS_VCB  Vcb,
PNTFS_FCB  Fcb 
)

Definition at line 265 of file fcb.c.

267 {
270  PNTFS_CCB newCCB;
271 
272  FileObject = IoCreateStreamFileObject(NULL, Vcb->StorageDevice);
273 
275  if (newCCB == NULL)
276  {
278  }
279 
280  RtlZeroMemory(newCCB, sizeof(NTFS_CCB));
281 
282  newCCB->Identifier.Type = NTFS_TYPE_CCB;
283  newCCB->Identifier.Size = sizeof(NTFS_TYPE_CCB);
284 
285  FileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
286  FileObject->FsContext = Fcb;
287  FileObject->FsContext2 = newCCB;
288  newCCB->PtrFileObject = FileObject;
290  Fcb->Vcb = Vcb;
291 
293  _SEH2_TRY
294  {
297  FALSE,
299  Fcb);
300  }
302  {
303  FileObject->FsContext2 = NULL;
304  ExFreePoolWithTag(newCCB, TAG_CCB);
306  Fcb->FileObject = NULL;
307  return _SEH2_GetExceptionCode();
308  }
309  _SEH2_END;
310 
313 
314  return Status;
315 }
_SEH2_TRY
Definition: create.c:4226
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PFILE_OBJECT FileObject
Definition: ntfs.h:520
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_END
Definition: create.c:4400
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:36
Definition: ntfs.h:129
#define FALSE
Definition: types.h:117
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
PFILE_OBJECT NTAPI IoCreateStreamFileObject(IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:3186
FSRTL_COMMON_FCB_HEADER RFCB
Definition: ntfs.h:517
Status
Definition: gdiplustypes.h:24
PFILE_OBJECT PtrFileObject
Definition: ntfs.h:133
VOID NTAPI CcInitializeCacheMap(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes, IN BOOLEAN PinAccess, IN PCACHE_MANAGER_CALLBACKS Callbacks, IN PVOID LazyWriteContext)
Definition: fssup.c:195
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define Vcb
Definition: cdprocs.h:1415
#define ObDereferenceObject
Definition: obfuncs.h:203
#define TAG_CCB
Definition: cdprocs.h:85
* PFILE_OBJECT
Definition: iotypes.h:1998
#define FCB_CACHE_INITIALIZED
Definition: ntfs.h:508
ULONG Flags
Definition: ntfs.h:536
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG Type
Definition: ntfs.h:95
#define NTFS_TYPE_CCB
Definition: ntfs.h:87
LARGE_INTEGER AllocationSize
Definition: env_spec_w32.h:755
NTFSIDENTIFIER Identifier
Definition: ntfs.h:131
CACHE_MANAGER_CALLBACKS CacheMgrCallbacks
Definition: ntfs.h:149
#define NULL
Definition: types.h:112
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PVCB Vcb
Definition: cdstruc.h:933
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:518
ULONG Size
Definition: ntfs.h:96

Referenced by NtfsMakeFCBFromDirEntry(), and NtfsMakeRootFCB().

◆ NtfsFCBIsCompressed()

BOOLEAN NtfsFCBIsCompressed ( PNTFS_FCB  Fcb)

Definition at line 146 of file fcb.c.

147 {
149 }
ULONG FileAttributes
Definition: ntfs.h:367
#define NTFS_FILE_TYPE_COMPRESSED
Definition: ntfs.h:229
_In_ PFCB Fcb
Definition: cdprocs.h:159
FILENAME_ATTRIBUTE Entry
Definition: ntfs.h:542

Referenced by NtfsQueryDirectory(), NtfsReadFile(), and NtfsWriteFile().

◆ NtfsFCBIsDirectory()

BOOLEAN NtfsFCBIsDirectory ( PNTFS_FCB  Fcb)

Definition at line 132 of file fcb.c.

133 {
135 }
#define NTFS_FILE_TYPE_DIRECTORY
Definition: ntfs.h:232
ULONG FileAttributes
Definition: ntfs.h:367
_In_ PFCB Fcb
Definition: cdprocs.h:159
FILENAME_ATTRIBUTE Entry
Definition: ntfs.h:542

Referenced by NtfsCreateFile(), NtfsGetFCBForFile(), NtfsGetStandardInformation(), NtfsMakeAbsoluteFilename(), and NtfsReleaseFCB().

◆ NtfsFCBIsEncrypted()

BOOLEAN NtfsFCBIsEncrypted ( PNTFS_FCB  Fcb)

Definition at line 152 of file fcb.c.

153 {
155 }
#define NTFS_FILE_TYPE_ENCRYPTED
Definition: ntfs.h:231
ULONG FileAttributes
Definition: ntfs.h:367
_In_ PFCB Fcb
Definition: cdprocs.h:159
FILENAME_ATTRIBUTE Entry
Definition: ntfs.h:542

Referenced by NtfsReadFile().

◆ NtfsFCBIsReparsePoint()

BOOLEAN NtfsFCBIsReparsePoint ( PNTFS_FCB  Fcb)

Definition at line 139 of file fcb.c.

140 {
142 }
ULONG FileAttributes
Definition: ntfs.h:367
#define NTFS_FILE_TYPE_REPARSE
Definition: ntfs.h:228
_In_ PFCB Fcb
Definition: cdprocs.h:159
FILENAME_ATTRIBUTE Entry
Definition: ntfs.h:542

Referenced by NtfsCreateFile().

◆ NtfsFCBIsRoot()

BOOLEAN NtfsFCBIsRoot ( PNTFS_FCB  Fcb)

Definition at line 158 of file fcb.c.

159 {
160  return (wcscmp(Fcb->PathName, L"\\") == 0);
161 }
WCHAR PathName[MAX_PATH]
Definition: ntfs.h:525
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by NtfsMakeAbsoluteFilename(), and NtfsMakeFCBFromDirEntry().

◆ NtfsGetFCBForFile()

NTSTATUS NtfsGetFCBForFile ( PNTFS_VCB  Vcb,
PNTFS_FCB pParentFCB,
PNTFS_FCB pFCB,
PCWSTR  pFileName,
BOOLEAN  CaseSensitive 
)

Definition at line 603 of file fcb.c.

608 {
610  WCHAR pathName [MAX_PATH];
611  WCHAR elementName [MAX_PATH];
612  PCWSTR currentElement;
613  PNTFS_FCB FCB;
614  PNTFS_FCB parentFCB;
615 
616  DPRINT("NtfsGetFCBForFile(%p, %p, %p, '%S', %s)\n",
617  Vcb,
618  pParentFCB,
619  pFCB,
620  pFileName,
621  CaseSensitive ? "TRUE" : "FALSE");
622 
623  /* Dummy code */
624 // FCB = NtfsOpenRootFCB(Vcb);
625 // *pFCB = FCB;
626 // *pParentFCB = NULL;
627 
628 #if 1
629  /* Trivial case, open of the root directory on volume */
630  if (pFileName[0] == L'\0' || wcscmp(pFileName, L"\\") == 0)
631  {
632  DPRINT("returning root FCB\n");
633 
635  *pFCB = FCB;
636  *pParentFCB = NULL;
637 
639  }
640  else
641  {
642  currentElement = pFileName + 1;
643  wcscpy (pathName, L"\\");
644  FCB = NtfsOpenRootFCB (Vcb);
645  }
646 
647  parentFCB = NULL;
648 
649  /* Parse filename and check each path element for existence and access */
650  while (NtfsGetNextPathElement(currentElement) != 0)
651  {
652  /* Skip blank directory levels */
653  if ((NtfsGetNextPathElement(currentElement) - currentElement) == 0)
654  {
655  currentElement++;
656  continue;
657  }
658 
659  DPRINT("Parsing, currentElement:%S\n", currentElement);
660  DPRINT(" parentFCB:%p FCB:%p\n", parentFCB, FCB);
661 
662  /* Descend to next directory level */
663  if (parentFCB)
664  {
665  NtfsReleaseFCB(Vcb, parentFCB);
666  parentFCB = NULL;
667  }
668 
669  /* fail if element in FCB is not a directory */
670  if (!NtfsFCBIsDirectory(FCB))
671  {
672  DPRINT("Element in requested path is not a directory\n");
673 
675  FCB = 0;
676  *pParentFCB = NULL;
677  *pFCB = NULL;
678 
680  }
681 
682  parentFCB = FCB;
683 
684  /* Extract next directory level into dirName */
685  NtfsWSubString(pathName,
686  pFileName,
687  NtfsGetNextPathElement(currentElement) - pFileName);
688  DPRINT(" pathName:%S\n", pathName);
689 
690  FCB = NtfsGrabFCBFromTable(Vcb, pathName);
691  if (FCB == NULL)
692  {
693  NtfsWSubString(elementName,
694  currentElement,
695  NtfsGetNextPathElement(currentElement) - currentElement);
696  DPRINT(" elementName:%S\n", elementName);
697 
698  Status = NtfsDirFindFile(Vcb, parentFCB, elementName, CaseSensitive, &FCB);
700  {
701  *pParentFCB = parentFCB;
702  *pFCB = NULL;
703  currentElement = NtfsGetNextPathElement(currentElement);
704  if (*currentElement == L'\0' || NtfsGetNextPathElement(currentElement + 1) == 0)
705  {
707  }
708  else
709  {
711  }
712  }
713  else if (!NT_SUCCESS(Status))
714  {
715  NtfsReleaseFCB(Vcb, parentFCB);
716  *pParentFCB = NULL;
717  *pFCB = NULL;
718 
719  return Status;
720  }
721  }
722 
723  currentElement = NtfsGetNextPathElement(currentElement);
724  }
725 
726  *pParentFCB = parentFCB;
727  *pFCB = FCB;
728 #endif
729 
730  return STATUS_SUCCESS;
731 }
VOID NtfsReleaseFCB(PNTFS_VCB Vcb, PNTFS_FCB Fcb)
Definition: fcb.c:182
const uint16_t * PCWSTR
Definition: typedefs.h:57
PNTFS_FCB NtfsOpenRootFCB(PNTFS_VCB Vcb)
Definition: fcb.c:374
Definition: cdstruc.h:902
LONG NTSTATUS
Definition: precomp.h:26
PNTFS_FCB NtfsGrabFCBFromTable(PNTFS_VCB Vcb, PCWSTR FileName)
Definition: fcb.c:222
BOOLEAN NtfsFCBIsDirectory(PNTFS_FCB Fcb)
Definition: fcb.c:132
#define L(x)
Definition: ntvdm.h:50
struct _FCB FCB
static PCWSTR NtfsGetNextPathElement(PCWSTR FileName)
Definition: fcb.c:39
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static NTSTATUS NtfsDirFindFile(PNTFS_VCB Vcb, PNTFS_FCB DirectoryFcb, PWSTR FileToFind, BOOLEAN CaseSensitive, PNTFS_FCB *FoundFCB)
Definition: fcb.c:515
#define Vcb
Definition: cdprocs.h:1415
#define MAX_PATH
Definition: compat.h:34
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
static VOID NtfsWSubString(PWCHAR pTarget, PCWSTR pSource, size_t pLength)
Definition: fcb.c:57
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by NtfsOpenFile().

◆ NtfsGetNextPathElement()

static PCWSTR NtfsGetNextPathElement ( PCWSTR  FileName)
static

Definition at line 39 of file fcb.c.

40 {
41  if (*FileName == L'\0')
42  {
43  return NULL;
44  }
45 
46  while (*FileName != L'\0' && *FileName != L'\\')
47  {
48  FileName++;
49  }
50 
51  return FileName;
52 }
#define L(x)
Definition: ntvdm.h:50
struct _FileName FileName
Definition: fatprocs.h:893
#define NULL
Definition: types.h:112

Referenced by NtfsGetFCBForFile().

◆ NtfsGrabFCB()

VOID NtfsGrabFCB ( PNTFS_VCB  Vcb,
PNTFS_FCB  Fcb 
)

Definition at line 165 of file fcb.c.

167 {
168  KIRQL oldIrql;
169 
170  DPRINT("grabbing FCB at %p: %S, refCount:%d\n",
171  Fcb,
172  Fcb->PathName,
173  Fcb->RefCount);
174 
175  KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
176  Fcb->RefCount++;
177  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
178 }
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
WCHAR PathName[MAX_PATH]
Definition: ntfs.h:525
UCHAR KIRQL
Definition: env_spec_w32.h:591
LONG RefCount
Definition: ntfs.h:535
#define Vcb
Definition: cdprocs.h:1415
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT
Definition: sndvol32.h:71
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by NtfsMakeRootFCB().

◆ NtfsGrabFCBFromTable()

PNTFS_FCB NtfsGrabFCBFromTable ( PNTFS_VCB  Vcb,
PCWSTR  FileName 
)

Definition at line 222 of file fcb.c.

224 {
225  KIRQL oldIrql;
226  PNTFS_FCB Fcb;
227  PLIST_ENTRY current_entry;
228 
229  KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
230 
231  if (FileName == NULL || *FileName == 0)
232  {
233  DPRINT("Return FCB for stream file object\n");
234  Fcb = Vcb->StreamFileObject->FsContext;
235  Fcb->RefCount++;
236  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
237  return Fcb;
238  }
239 
240  current_entry = Vcb->FcbListHead.Flink;
241  while (current_entry != &Vcb->FcbListHead)
242  {
243  Fcb = CONTAINING_RECORD(current_entry, NTFS_FCB, FcbListEntry);
244 
245  DPRINT("Comparing '%S' and '%S'\n", FileName, Fcb->PathName);
246  if (_wcsicmp(FileName, Fcb->PathName) == 0)
247  {
248  Fcb->RefCount++;
249  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
250  return Fcb;
251  }
252 
253  //FIXME: need to compare against short name in FCB here
254 
255  current_entry = current_entry->Flink;
256  }
257 
258  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
259 
260  return NULL;
261 }
Definition: cdstruc.h:902
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
WCHAR PathName[MAX_PATH]
Definition: ntfs.h:525
UCHAR KIRQL
Definition: env_spec_w32.h:591
LONG RefCount
Definition: ntfs.h:535
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define Vcb
Definition: cdprocs.h:1415
Definition: typedefs.h:119
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT
Definition: sndvol32.h:71
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by NtfsGetFCBForFile(), NtfsOpenFile(), NtfsOpenFileById(), and NtfsOpenRootFCB().

◆ NtfsMakeFCBFromDirEntry()

NTSTATUS NtfsMakeFCBFromDirEntry ( PNTFS_VCB  Vcb,
PNTFS_FCB  DirectoryFCB,
PUNICODE_STRING  Name,
PCWSTR  Stream,
PFILE_RECORD_HEADER  Record,
ULONGLONG  MFTIndex,
PNTFS_FCB fileFCB 
)

Definition at line 389 of file fcb.c.

396 {
397  WCHAR pathName[MAX_PATH];
399  PSTANDARD_INFORMATION StdInfo;
400  PNTFS_FCB rcFCB;
401  ULONGLONG Size, AllocatedSize;
402 
403  DPRINT("NtfsMakeFCBFromDirEntry(%p, %p, %wZ, %p, %p, %p)\n", Vcb, DirectoryFCB, Name, Stream, Record, fileFCB);
404 
406  if (!FileName)
407  {
408  return STATUS_OBJECT_NAME_NOT_FOUND; // Not sure that's the best here
409  }
410 
411  if (DirectoryFCB && Name)
412  {
413  if (Name->Buffer[0] != 0 && wcslen(DirectoryFCB->PathName) +
414  sizeof(WCHAR) + Name->Length / sizeof(WCHAR) > MAX_PATH)
415  {
417  }
418 
419  wcscpy(pathName, DirectoryFCB->PathName);
420  if (!NtfsFCBIsRoot(DirectoryFCB))
421  {
422  wcscat(pathName, L"\\");
423  }
424  wcscat(pathName, Name->Buffer);
425  }
426  else
427  {
428  RtlCopyMemory(pathName, FileName->Name, FileName->NameLength * sizeof (WCHAR));
429  pathName[FileName->NameLength] = UNICODE_NULL;
430  }
431 
432  Size = NtfsGetFileSize(Vcb, Record, (Stream ? Stream : L""), (Stream ? wcslen(Stream) : 0), &AllocatedSize);
433 
434  rcFCB = NtfsCreateFCB(pathName, Stream, Vcb);
435  if (!rcFCB)
436  {
438  }
439 
440  memcpy(&rcFCB->Entry, FileName, FIELD_OFFSET(FILENAME_ATTRIBUTE, NameLength));
441  rcFCB->Entry.NameType = FileName->NameType;
442  rcFCB->RFCB.FileSize.QuadPart = Size;
444  rcFCB->RFCB.AllocationSize.QuadPart = AllocatedSize;
445 
447  if (StdInfo != NULL)
448  {
449  rcFCB->Entry.FileAttributes |= StdInfo->FileAttribute;
450  }
451 
452  NtfsFCBInitializeCache(Vcb, rcFCB);
453  rcFCB->RefCount = 1;
454  rcFCB->MFTIndex = MFTIndex;
455  rcFCB->LinkCount = Record->LinkCount;
456  NtfsAddFCBToTable(Vcb, rcFCB);
457  *fileFCB = rcFCB;
458 
459  return STATUS_SUCCESS;
460 }
PFILENAME_ATTRIBUTE GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1985
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
Definition: cdstruc.h:902
ULONG FileAttribute
Definition: ntfs.h:334
VOID NtfsAddFCBToTable(PNTFS_VCB Vcb, PNTFS_FCB Fcb)
Definition: fcb.c:209
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PNTFS_FCB NtfsCreateFCB(PCWSTR FileName, PCWSTR Stream, PNTFS_VCB Vcb)
Definition: fcb.c:67
USHORT LinkCount
Definition: ntfs.h:540
WCHAR PathName[MAX_PATH]
Definition: ntfs.h:525
ULONGLONG MFTIndex
Definition: ntfs.h:539
NTSTATUS NtfsFCBInitializeCache(PNTFS_VCB Vcb, PNTFS_FCB Fcb)
Definition: fcb.c:265
PSTANDARD_INFORMATION GetStandardInformationFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1940
ULONG FileAttributes
Definition: ntfs.h:367
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD * Record
Definition: ketypes.h:256
#define L(x)
Definition: ntvdm.h:50
#define UNICODE_NULL
LONG RefCount
Definition: ntfs.h:535
FSRTL_COMMON_FCB_HEADER RFCB
Definition: ntfs.h:517
ULONGLONG NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PCWSTR Stream, ULONG StreamLength, PULONGLONG AllocatedSize)
Definition: dirctl.c:38
TCHAR Name[MAX_PATH]
Definition: filecomp.c:349
__wchar_t WCHAR
Definition: xmlstorage.h:180
uint64_t ULONGLONG
Definition: typedefs.h:67
#define Vcb
Definition: cdprocs.h:1415
#define MAX_PATH
Definition: compat.h:34
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LARGE_INTEGER AllocationSize
Definition: env_spec_w32.h:755
struct _FileName FileName
Definition: fatprocs.h:893
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
LARGE_INTEGER ValidDataLength
Definition: env_spec_w32.h:757
FILENAME_ATTRIBUTE Entry
Definition: ntfs.h:542
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
BOOLEAN NtfsFCBIsRoot(PNTFS_FCB Fcb)
Definition: fcb.c:158
LONGLONG QuadPart
Definition: typedefs.h:114
UCHAR NameType
Definition: ntfs.h:378

Referenced by NtfsDirFindFile(), and NtfsOpenFileById().

◆ NtfsMakeRootFCB()

PNTFS_FCB NtfsMakeRootFCB ( PNTFS_VCB  Vcb)

Definition at line 319 of file fcb.c.

320 {
321  PNTFS_FCB Fcb;
322  PFILE_RECORD_HEADER MftRecord;
324 
325  MftRecord = ExAllocateFromNPagedLookasideList(&Vcb->FileRecLookasideList);
326  if (MftRecord == NULL)
327  {
328  return NULL;
329  }
330 
331  if (!NT_SUCCESS(ReadFileRecord(Vcb, NTFS_FILE_ROOT, MftRecord)))
332  {
333  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, MftRecord);
334  return NULL;
335  }
336 
338  if (!FileName)
339  {
340  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, MftRecord);
341  return NULL;
342  }
343 
344  Fcb = NtfsCreateFCB(L"\\", NULL, Vcb);
345  if (!Fcb)
346  {
347  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, MftRecord);
348  return NULL;
349  }
350 
352  Fcb->Entry.NameType = FileName->NameType;
353  Fcb->Entry.NameLength = 0;
354  Fcb->Entry.Name[0] = UNICODE_NULL;
355  Fcb->RefCount = 1;
356  Fcb->DirIndex = 0;
357  Fcb->RFCB.FileSize.QuadPart = FileName->DataSize;
359  Fcb->RFCB.AllocationSize.QuadPart = FileName->AllocatedSize;
361  Fcb->LinkCount = MftRecord->LinkCount;
362 
365  NtfsGrabFCB(Vcb, Fcb);
366 
367  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, MftRecord);
368 
369  return Fcb;
370 }
WCHAR Name[1]
Definition: ntfs.h:379
Definition: cdstruc.h:902
PFILENAME_ATTRIBUTE GetFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord, UCHAR NameType)
Definition: attrib.c:1809
ULONG DirIndex
Definition: ntfs.h:533
VOID NtfsAddFCBToTable(PNTFS_VCB Vcb, PNTFS_FCB Fcb)
Definition: fcb.c:209
PNTFS_FCB NtfsCreateFCB(PCWSTR FileName, PCWSTR Stream, PNTFS_VCB Vcb)
Definition: fcb.c:67
USHORT LinkCount
Definition: ntfs.h:540
UCHAR NameLength
Definition: ntfs.h:377
ULONGLONG MFTIndex
Definition: ntfs.h:539
NTSTATUS NtfsFCBInitializeCache(PNTFS_VCB Vcb, PNTFS_FCB Fcb)
Definition: fcb.c:265
#define L(x)
Definition: ntvdm.h:50
#define UNICODE_NULL
LONG RefCount
Definition: ntfs.h:535
USHORT LinkCount
Definition: ntfs.h:254
FSRTL_COMMON_FCB_HEADER RFCB
Definition: ntfs.h:517
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1415
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LARGE_INTEGER AllocationSize
Definition: env_spec_w32.h:755
struct _FileName FileName
Definition: fatprocs.h:893
NTSTATUS ReadFileRecord(PDEVICE_EXTENSION Vcb, ULONGLONG index, PFILE_RECORD_HEADER file)
Definition: mft.c:1631
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
#define NTFS_FILE_NAME_WIN32
Definition: ntfs.h:64
_In_ PFCB Fcb
Definition: cdprocs.h:159
LARGE_INTEGER ValidDataLength
Definition: env_spec_w32.h:757
FILENAME_ATTRIBUTE Entry
Definition: ntfs.h:542
VOID NtfsGrabFCB(PNTFS_VCB Vcb, PNTFS_FCB Fcb)
Definition: fcb.c:165
LONGLONG QuadPart
Definition: typedefs.h:114
UCHAR NameType
Definition: ntfs.h:378
#define NTFS_FILE_ROOT
Definition: ntfs.h:28

Referenced by NtfsOpenRootFCB().

◆ NtfsOpenRootFCB()

PNTFS_FCB NtfsOpenRootFCB ( PNTFS_VCB  Vcb)

Definition at line 374 of file fcb.c.

375 {
376  PNTFS_FCB Fcb;
377 
378  Fcb = NtfsGrabFCBFromTable(Vcb, L"\\");
379  if (Fcb == NULL)
380  {
382  }
383 
384  return Fcb;
385 }
Definition: cdstruc.h:902
PNTFS_FCB NtfsGrabFCBFromTable(PNTFS_VCB Vcb, PCWSTR FileName)
Definition: fcb.c:222
PNTFS_FCB NtfsMakeRootFCB(PNTFS_VCB Vcb)
Definition: fcb.c:319
#define L(x)
Definition: ntvdm.h:50
#define Vcb
Definition: cdprocs.h:1415
#define NULL
Definition: types.h:112
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by NtfsGetFCBForFile().

◆ NtfsReadFCBAttribute()

NTSTATUS NtfsReadFCBAttribute ( PNTFS_VCB  Vcb,
PNTFS_FCB  pFCB,
ULONG  Type,
PCWSTR  Name,
ULONG  NameLength,
PVOID Data 
)

Definition at line 735 of file fcb.c.

741 {
743  PFILE_RECORD_HEADER FileRecord;
744  PNTFS_ATTR_CONTEXT AttrCtxt;
745  ULONGLONG AttrLength;
746 
747  FileRecord = ExAllocateFromNPagedLookasideList(&Vcb->FileRecLookasideList);
748  if (FileRecord == NULL)
749  {
751  }
752 
753  Status = ReadFileRecord(Vcb, pFCB->MFTIndex, FileRecord);
754  if (!NT_SUCCESS(Status))
755  {
756  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
757  return Status;
758  }
759 
760  Status = FindAttribute(Vcb, FileRecord, Type, Name, NameLength, &AttrCtxt, NULL);
761  if (!NT_SUCCESS(Status))
762  {
763  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
764  return Status;
765  }
766 
767  AttrLength = AttributeDataLength(AttrCtxt->pRecord);
769  if (*Data == NULL)
770  {
771  ReleaseAttributeContext(AttrCtxt);
772  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
774  }
775 
776  ReadAttribute(Vcb, AttrCtxt, 0, *Data, AttrLength);
777 
778  ReleaseAttributeContext(AttrCtxt);
779  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
780 
781  return STATUS_SUCCESS;
782 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS FindAttribute(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER MftRecord, ULONG Type, PCWSTR Name, ULONG NameLength, PNTFS_ATTR_CONTEXT *AttrCtx, PULONG Offset)
Definition: mft.c:131
ULONGLONG MFTIndex
Definition: ntfs.h:539
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
#define Vcb
Definition: cdprocs.h:1415
Type
Definition: Type.h:6
#define TAG_NTFS
Definition: ntfs.h:12
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS ReadFileRecord(PDEVICE_EXTENSION Vcb, ULONGLONG index, PFILE_RECORD_HEADER file)
Definition: mft.c:1631
VOID ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context)
Definition: mft.c:104
ULONG ReadAttribute(PDEVICE_EXTENSION Vcb, PNTFS_ATTR_CONTEXT Context, ULONGLONG Offset, PCHAR Buffer, ULONG Length)
Definition: mft.c:1065
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONGLONG AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord)
Definition: mft.c:259

Referenced by NtfsCreateFile().

◆ NtfsReleaseFCB()

VOID NtfsReleaseFCB ( PNTFS_VCB  Vcb,
PNTFS_FCB  Fcb 
)

Definition at line 182 of file fcb.c.

184 {
185  KIRQL oldIrql;
186 
187  DPRINT("releasing FCB at %p: %S, refCount:%d\n",
188  Fcb,
189  Fcb->PathName,
190  Fcb->RefCount);
191 
192  KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
193  Fcb->RefCount--;
194  if (Fcb->RefCount <= 0 && !NtfsFCBIsDirectory(Fcb))
195  {
197  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
200  }
201  else
202  {
203  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
204  }
205 }
LIST_ENTRY FcbListEntry
Definition: ntfs.h:530
PFILE_OBJECT FileObject
Definition: ntfs.h:520
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
WCHAR PathName[MAX_PATH]
Definition: ntfs.h:525
BOOLEAN NtfsFCBIsDirectory(PNTFS_FCB Fcb)
Definition: fcb.c:132
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
LONG RefCount
Definition: ntfs.h:535
VOID NtfsDestroyFCB(PNTFS_FCB Fcb)
Definition: fcb.c:120
#define Vcb
Definition: cdprocs.h:1415
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT
Definition: sndvol32.h:71
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by NtfsCloseFile(), NtfsGetFCBForFile(), and NtfsOpenFile().

◆ NtfsWSubString()

static VOID NtfsWSubString ( PWCHAR  pTarget,
PCWSTR  pSource,
size_t  pLength 
)
static

Definition at line 57 of file fcb.c.

60 {
61  wcsncpy(pTarget, pSource, pLength);
62  pTarget[pLength] = L'\0';
63 }
FxIoTarget * pTarget
Definition: fxdeviceapi.cpp:97
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)

Referenced by NtfsGetFCBForFile().