ReactOS  0.4.15-dev-3439-g2693a26
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 204 of file fcb.c.

206 {
207  KIRQL oldIrql;
208 
209  KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
210  Fcb->Vcb = Vcb;
211  InsertTailList(&Vcb->FcbListHead, &Fcb->FcbListEntry);
212  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
213 }
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 459 of file fcb.c.

462 {
463  PNTFS_CCB newCCB;
464 
466  if (newCCB == NULL)
467  {
469  }
470 
471  RtlZeroMemory(newCCB, sizeof(NTFS_CCB));
472 
473  newCCB->Identifier.Type = NTFS_TYPE_CCB;
474  newCCB->Identifier.Size = sizeof(NTFS_TYPE_CCB);
475 
476  FileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
477  FileObject->FsContext = Fcb;
478  FileObject->FsContext2 = newCCB;
479  newCCB->PtrFileObject = FileObject;
480  Fcb->Vcb = Vcb;
481 
482  if (!(Fcb->Flags & FCB_CACHE_INITIALIZED))
483  {
484  _SEH2_TRY
485  {
488  FALSE,
490  Fcb);
491  }
493  {
494  FileObject->FsContext2 = NULL;
495  ExFreePoolWithTag(newCCB, TAG_CCB);
496  return _SEH2_GetExceptionCode();
497  }
498  _SEH2_END;
499 
501  }
502 
503  //DPRINT("file open: fcb:%x file size: %d\n", Fcb, Fcb->Entry.DataLengthL);
504 
505  return STATUS_SUCCESS;
506 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:36
_SEH2_TRY
Definition: create.c:4226
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
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
#define FCB_CACHE_INITIALIZED
Definition: vfat.h:433
_SEH2_END
Definition: create.c:4400
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  RtlZeroMemory(Fcb, sizeof(NTFS_FCB));
78 
80  Fcb->Identifier.Size = sizeof(NTFS_TYPE_FCB);
81 
82  Fcb->Vcb = Vcb;
83 
84  if (FileName)
85  {
87  if (wcsrchr(Fcb->PathName, '\\') != 0)
88  {
89  Fcb->ObjectName = wcsrchr(Fcb->PathName, '\\');
90  }
91  else
92  {
94  }
95  }
96 
97  if (Stream)
98  {
100  }
101  else
102  {
103  Fcb->Stream[0] = UNICODE_NULL;
104  }
105 
107 
109 
110  return Fcb;
111 }
#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 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 115 of file fcb.c.

116 {
117  ASSERT(Fcb);
119 
121 
122  ExFreeToNPagedLookasideList(&NtfsGlobalData->FcbLookasideList, Fcb);
123 }
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 510 of file fcb.c.

515 {
517  ULONGLONG CurrentDir;
519  PFILE_RECORD_HEADER FileRecord;
520  ULONGLONG MFTIndex;
521  PWSTR Colon, OldColon;
522  PNTFS_ATTR_CONTEXT DataContext;
523  USHORT Length = 0;
524 
525  DPRINT("NtfsDirFindFile(%p, %p, %S, %s, %p)\n",
526  Vcb,
527  DirectoryFcb,
528  FileToFind,
529  CaseSensitive ? "TRUE" : "FALSE",
530  FoundFCB);
531 
532  *FoundFCB = NULL;
533  RtlInitUnicodeString(&File, FileToFind);
534  CurrentDir = DirectoryFcb->MFTIndex;
535 
536  Colon = wcsrchr(FileToFind, L':');
537  if (Colon != NULL)
538  {
539  Length = File.Length;
540  File.Length = (Colon - FileToFind) * sizeof(WCHAR);
541 
542  if (_wcsicmp(Colon + 1, L"$DATA") == 0)
543  {
544  OldColon = Colon;
545  Colon[0] = UNICODE_NULL;
546  Colon = wcsrchr(FileToFind, L':');
547  if (Colon != NULL)
548  {
549  Length = File.Length;
550  File.Length = (Colon - FileToFind) * sizeof(WCHAR);
551  }
552  else
553  {
554  Colon = OldColon;
555  Colon[0] = L':';
556  }
557  }
558 
559  /* Skip colon */
560  ++Colon;
561  DPRINT1("Will now look for file '%wZ' with stream '%S'\n", &File, Colon);
562  }
563 
564  Status = NtfsLookupFileAt(Vcb, &File, CaseSensitive, &FileRecord, &MFTIndex, CurrentDir);
565  if (!NT_SUCCESS(Status))
566  {
567  return Status;
568  }
569 
570  if (Length != 0)
571  {
572  File.Length = Length;
573  }
574 
575  if ((FileRecord->Flags & FRH_DIRECTORY) && Colon != 0)
576  {
577  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
579  }
580  else if (Colon != 0)
581  {
582  Status = FindAttribute(Vcb, FileRecord, AttributeData, Colon, wcslen(Colon), &DataContext, NULL);
583  if (!NT_SUCCESS(Status))
584  {
586  }
587  ReleaseAttributeContext(DataContext);
588  }
589 
590  Status = NtfsMakeFCBFromDirEntry(Vcb, DirectoryFcb, &File, Colon, FileRecord, MFTIndex, FoundFCB);
591  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
592 
593  return Status;
594 }
_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:384
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
#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 260 of file fcb.c.

262 {
265  PNTFS_CCB newCCB;
266 
267  FileObject = IoCreateStreamFileObject(NULL, Vcb->StorageDevice);
268 
270  if (newCCB == NULL)
271  {
273  }
274 
275  RtlZeroMemory(newCCB, sizeof(NTFS_CCB));
276 
277  newCCB->Identifier.Type = NTFS_TYPE_CCB;
278  newCCB->Identifier.Size = sizeof(NTFS_TYPE_CCB);
279 
280  FileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
281  FileObject->FsContext = Fcb;
282  FileObject->FsContext2 = newCCB;
283  newCCB->PtrFileObject = FileObject;
285  Fcb->Vcb = Vcb;
286 
288  _SEH2_TRY
289  {
292  FALSE,
294  Fcb);
295  }
297  {
298  FileObject->FsContext2 = NULL;
299  ExFreePoolWithTag(newCCB, TAG_CCB);
301  Fcb->FileObject = NULL;
302  return _SEH2_GetExceptionCode();
303  }
304  _SEH2_END;
305 
308 
309  return Status;
310 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PFILE_OBJECT FileObject
Definition: ntfs.h:520
LONG NTSTATUS
Definition: precomp.h:26
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:36
_SEH2_TRY
Definition: create.c:4226
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
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
#define FCB_CACHE_INITIALIZED
Definition: vfat.h:433
_SEH2_END
Definition: create.c:4400
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 141 of file fcb.c.

142 {
144 }
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 127 of file fcb.c.

128 {
130 }
#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 147 of file fcb.c.

148 {
150 }
#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 134 of file fcb.c.

135 {
137 }
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 153 of file fcb.c.

154 {
155  return (wcscmp(Fcb->PathName, L"\\") == 0);
156 }
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 598 of file fcb.c.

603 {
605  WCHAR pathName [MAX_PATH];
606  WCHAR elementName [MAX_PATH];
607  PCWSTR currentElement;
608  PNTFS_FCB FCB;
609  PNTFS_FCB parentFCB;
610 
611  DPRINT("NtfsGetFCBForFile(%p, %p, %p, '%S', %s)\n",
612  Vcb,
613  pParentFCB,
614  pFCB,
615  pFileName,
616  CaseSensitive ? "TRUE" : "FALSE");
617 
618  /* Dummy code */
619 // FCB = NtfsOpenRootFCB(Vcb);
620 // *pFCB = FCB;
621 // *pParentFCB = NULL;
622 
623 #if 1
624  /* Trivial case, open of the root directory on volume */
625  if (pFileName[0] == L'\0' || wcscmp(pFileName, L"\\") == 0)
626  {
627  DPRINT("returning root FCB\n");
628 
630  *pFCB = FCB;
631  *pParentFCB = NULL;
632 
634  }
635  else
636  {
637  currentElement = pFileName + 1;
638  wcscpy (pathName, L"\\");
639  FCB = NtfsOpenRootFCB (Vcb);
640  }
641 
642  parentFCB = NULL;
643 
644  /* Parse filename and check each path element for existence and access */
645  while (NtfsGetNextPathElement(currentElement) != 0)
646  {
647  /* Skip blank directory levels */
648  if ((NtfsGetNextPathElement(currentElement) - currentElement) == 0)
649  {
650  currentElement++;
651  continue;
652  }
653 
654  DPRINT("Parsing, currentElement:%S\n", currentElement);
655  DPRINT(" parentFCB:%p FCB:%p\n", parentFCB, FCB);
656 
657  /* Descend to next directory level */
658  if (parentFCB)
659  {
660  NtfsReleaseFCB(Vcb, parentFCB);
661  parentFCB = NULL;
662  }
663 
664  /* fail if element in FCB is not a directory */
665  if (!NtfsFCBIsDirectory(FCB))
666  {
667  DPRINT("Element in requested path is not a directory\n");
668 
670  FCB = 0;
671  *pParentFCB = NULL;
672  *pFCB = NULL;
673 
675  }
676 
677  parentFCB = FCB;
678 
679  /* Extract next directory level into dirName */
680  NtfsWSubString(pathName,
681  pFileName,
682  NtfsGetNextPathElement(currentElement) - pFileName);
683  DPRINT(" pathName:%S\n", pathName);
684 
685  FCB = NtfsGrabFCBFromTable(Vcb, pathName);
686  if (FCB == NULL)
687  {
688  NtfsWSubString(elementName,
689  currentElement,
690  NtfsGetNextPathElement(currentElement) - currentElement);
691  DPRINT(" elementName:%S\n", elementName);
692 
693  Status = NtfsDirFindFile(Vcb, parentFCB, elementName, CaseSensitive, &FCB);
695  {
696  *pParentFCB = parentFCB;
697  *pFCB = NULL;
698  currentElement = NtfsGetNextPathElement(currentElement);
699  if (*currentElement == L'\0' || NtfsGetNextPathElement(currentElement + 1) == 0)
700  {
702  }
703  else
704  {
706  }
707  }
708  else if (!NT_SUCCESS(Status))
709  {
710  NtfsReleaseFCB(Vcb, parentFCB);
711  *pParentFCB = NULL;
712  *pFCB = NULL;
713 
714  return Status;
715  }
716  }
717 
718  currentElement = NtfsGetNextPathElement(currentElement);
719  }
720 
721  *pParentFCB = parentFCB;
722  *pFCB = FCB;
723 #endif
724 
725  return STATUS_SUCCESS;
726 }
VOID NtfsReleaseFCB(PNTFS_VCB Vcb, PNTFS_FCB Fcb)
Definition: fcb.c:177
const uint16_t * PCWSTR
Definition: typedefs.h:57
PNTFS_FCB NtfsOpenRootFCB(PNTFS_VCB Vcb)
Definition: fcb.c:369
Definition: cdstruc.h:902
LONG NTSTATUS
Definition: precomp.h:26
PNTFS_FCB NtfsGrabFCBFromTable(PNTFS_VCB Vcb, PCWSTR FileName)
Definition: fcb.c:217
BOOLEAN NtfsFCBIsDirectory(PNTFS_FCB Fcb)
Definition: fcb.c:127
#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:510
#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 160 of file fcb.c.

162 {
163  KIRQL oldIrql;
164 
165  DPRINT("grabbing FCB at %p: %S, refCount:%d\n",
166  Fcb,
167  Fcb->PathName,
168  Fcb->RefCount);
169 
170  KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
171  Fcb->RefCount++;
172  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
173 }
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 217 of file fcb.c.

219 {
220  KIRQL oldIrql;
221  PNTFS_FCB Fcb;
222  PLIST_ENTRY current_entry;
223 
224  KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
225 
226  if (FileName == NULL || *FileName == 0)
227  {
228  DPRINT("Return FCB for stream file object\n");
229  Fcb = Vcb->StreamFileObject->FsContext;
230  Fcb->RefCount++;
231  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
232  return Fcb;
233  }
234 
235  current_entry = Vcb->FcbListHead.Flink;
236  while (current_entry != &Vcb->FcbListHead)
237  {
238  Fcb = CONTAINING_RECORD(current_entry, NTFS_FCB, FcbListEntry);
239 
240  DPRINT("Comparing '%S' and '%S'\n", FileName, Fcb->PathName);
241  if (_wcsicmp(FileName, Fcb->PathName) == 0)
242  {
243  Fcb->RefCount++;
244  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
245  return Fcb;
246  }
247 
248  //FIXME: need to compare against short name in FCB here
249 
250  current_entry = current_entry->Flink;
251  }
252 
253  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
254 
255  return NULL;
256 }
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 384 of file fcb.c.

391 {
392  WCHAR pathName[MAX_PATH];
394  PSTANDARD_INFORMATION StdInfo;
395  PNTFS_FCB rcFCB;
396  ULONGLONG Size, AllocatedSize;
397 
398  DPRINT("NtfsMakeFCBFromDirEntry(%p, %p, %wZ, %p, %p, %p)\n", Vcb, DirectoryFCB, Name, Stream, Record, fileFCB);
399 
401  if (!FileName)
402  {
403  return STATUS_OBJECT_NAME_NOT_FOUND; // Not sure that's the best here
404  }
405 
406  if (DirectoryFCB && Name)
407  {
408  if (Name->Buffer[0] != 0 && wcslen(DirectoryFCB->PathName) +
409  sizeof(WCHAR) + Name->Length / sizeof(WCHAR) > MAX_PATH)
410  {
412  }
413 
414  wcscpy(pathName, DirectoryFCB->PathName);
415  if (!NtfsFCBIsRoot(DirectoryFCB))
416  {
417  wcscat(pathName, L"\\");
418  }
419  wcscat(pathName, Name->Buffer);
420  }
421  else
422  {
423  RtlCopyMemory(pathName, FileName->Name, FileName->NameLength * sizeof (WCHAR));
424  pathName[FileName->NameLength] = UNICODE_NULL;
425  }
426 
427  Size = NtfsGetFileSize(Vcb, Record, (Stream ? Stream : L""), (Stream ? wcslen(Stream) : 0), &AllocatedSize);
428 
429  rcFCB = NtfsCreateFCB(pathName, Stream, Vcb);
430  if (!rcFCB)
431  {
433  }
434 
435  memcpy(&rcFCB->Entry, FileName, FIELD_OFFSET(FILENAME_ATTRIBUTE, NameLength));
436  rcFCB->Entry.NameType = FileName->NameType;
437  rcFCB->RFCB.FileSize.QuadPart = Size;
439  rcFCB->RFCB.AllocationSize.QuadPart = AllocatedSize;
440 
442  if (StdInfo != NULL)
443  {
444  rcFCB->Entry.FileAttributes |= StdInfo->FileAttribute;
445  }
446 
447  NtfsFCBInitializeCache(Vcb, rcFCB);
448  rcFCB->RefCount = 1;
449  rcFCB->MFTIndex = MFTIndex;
450  rcFCB->LinkCount = Record->LinkCount;
451  NtfsAddFCBToTable(Vcb, rcFCB);
452  *fileFCB = rcFCB;
453 
454  return STATUS_SUCCESS;
455 }
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:204
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:260
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:153
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 314 of file fcb.c.

315 {
316  PNTFS_FCB Fcb;
317  PFILE_RECORD_HEADER MftRecord;
319 
320  MftRecord = ExAllocateFromNPagedLookasideList(&Vcb->FileRecLookasideList);
321  if (MftRecord == NULL)
322  {
323  return NULL;
324  }
325 
326  if (!NT_SUCCESS(ReadFileRecord(Vcb, NTFS_FILE_ROOT, MftRecord)))
327  {
328  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, MftRecord);
329  return NULL;
330  }
331 
333  if (!FileName)
334  {
335  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, MftRecord);
336  return NULL;
337  }
338 
339  Fcb = NtfsCreateFCB(L"\\", NULL, Vcb);
340  if (!Fcb)
341  {
342  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, MftRecord);
343  return NULL;
344  }
345 
347  Fcb->Entry.NameType = FileName->NameType;
348  Fcb->Entry.NameLength = 0;
349  Fcb->Entry.Name[0] = UNICODE_NULL;
350  Fcb->RefCount = 1;
351  Fcb->DirIndex = 0;
352  Fcb->RFCB.FileSize.QuadPart = FileName->DataSize;
354  Fcb->RFCB.AllocationSize.QuadPart = FileName->AllocatedSize;
356  Fcb->LinkCount = MftRecord->LinkCount;
357 
360  NtfsGrabFCB(Vcb, Fcb);
361 
362  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, MftRecord);
363 
364  return Fcb;
365 }
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:204
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:260
#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:160
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 369 of file fcb.c.

370 {
371  PNTFS_FCB Fcb;
372 
373  Fcb = NtfsGrabFCBFromTable(Vcb, L"\\");
374  if (Fcb == NULL)
375  {
377  }
378 
379  return Fcb;
380 }
Definition: cdstruc.h:902
PNTFS_FCB NtfsGrabFCBFromTable(PNTFS_VCB Vcb, PCWSTR FileName)
Definition: fcb.c:217
PNTFS_FCB NtfsMakeRootFCB(PNTFS_VCB Vcb)
Definition: fcb.c:314
#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 730 of file fcb.c.

736 {
738  PFILE_RECORD_HEADER FileRecord;
739  PNTFS_ATTR_CONTEXT AttrCtxt;
740  ULONGLONG AttrLength;
741 
742  FileRecord = ExAllocateFromNPagedLookasideList(&Vcb->FileRecLookasideList);
743  if (FileRecord == NULL)
744  {
746  }
747 
748  Status = ReadFileRecord(Vcb, pFCB->MFTIndex, FileRecord);
749  if (!NT_SUCCESS(Status))
750  {
751  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
752  return Status;
753  }
754 
755  Status = FindAttribute(Vcb, FileRecord, Type, Name, NameLength, &AttrCtxt, NULL);
756  if (!NT_SUCCESS(Status))
757  {
758  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
759  return Status;
760  }
761 
762  AttrLength = AttributeDataLength(AttrCtxt->pRecord);
764  if (*Data == NULL)
765  {
766  ReleaseAttributeContext(AttrCtxt);
767  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
769  }
770 
771  ReadAttribute(Vcb, AttrCtxt, 0, *Data, AttrLength);
772 
773  ReleaseAttributeContext(AttrCtxt);
774  ExFreeToNPagedLookasideList(&Vcb->FileRecLookasideList, FileRecord);
775 
776  return STATUS_SUCCESS;
777 }
#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 177 of file fcb.c.

179 {
180  KIRQL oldIrql;
181 
182  DPRINT("releasing FCB at %p: %S, refCount:%d\n",
183  Fcb,
184  Fcb->PathName,
185  Fcb->RefCount);
186 
187  KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
188  Fcb->RefCount--;
189  if (Fcb->RefCount <= 0 && !NtfsFCBIsDirectory(Fcb))
190  {
192  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
195  }
196  else
197  {
198  KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
199  }
200 }
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:127
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:115
#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().