ReactOS  0.4.15-dev-2522-g9e0a3cd
create.c File Reference
#include "rfsd.h"
Include dependency graph for create.c:

Go to the source code of this file.

Classes

struct  _RFSD_SCANDIR_CALLBACK_CONTEXT
 

Typedefs

typedef struct _RFSD_SCANDIR_CALLBACK_CONTEXT RFSD_SCANDIR_CALLBACK_CONTEXT
 
typedef struct _RFSD_SCANDIR_CALLBACK_CONTEXTPRFSD_SCANDIR_CALLBACK_CONTEXT
 

Functions

NTSTATUS RfsdScanDirCallback (ULONG BlockNumber, PVOID pContext)
 
NTSTATUS RfsdLookupFileName (IN PRFSD_VCB Vcb, IN PUNICODE_STRING FullFileName, IN PRFSD_MCB ParentMcb, OUT PRFSD_MCB *RfsdMcb, IN OUT PRFSD_INODE Inode)
 
NTSTATUS RfsdScanDir (IN PRFSD_VCB Vcb, IN PRFSD_MCB ParentMcb, IN PUNICODE_STRING FileName, IN OUT PULONG Index, IN OUT PRFSD_DENTRY_HEAD rfsd_dir)
 
__drv_mustHoldCriticalRegion NTSTATUS RfsdCreateFile (PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb)
 
__drv_mustHoldCriticalRegion NTSTATUS RfsdCreateVolume (PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb)
 
__drv_mustHoldCriticalRegion NTSTATUS RfsdCreate (IN PRFSD_IRP_CONTEXT IrpContext)
 
NTSTATUS RfsdCreateInode (PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, PRFSD_FCB ParentFcb, ULONG Type, ULONG FileAttr, PUNICODE_STRING FileName)
 
NTSTATUS RfsdSupersedeOrOverWriteFile (PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, PRFSD_FCB Fcb, ULONG Disposition)
 

Variables

PRFSD_GLOBAL RfsdGlobal
 

Typedef Documentation

◆ PRFSD_SCANDIR_CALLBACK_CONTEXT

◆ RFSD_SCANDIR_CALLBACK_CONTEXT

Function Documentation

◆ RfsdCreate()

Definition at line 1153 of file create.c.

1154 {
1156  PIRP Irp;
1158  PRFSD_VCB Vcb = 0;
1160  PRFSD_FCBVCB Xcb = NULL;
1161 
1162  PAGED_CODE();
1163 
1164  DeviceObject = IrpContext->DeviceObject;
1165 
1166  Vcb = (PRFSD_VCB) DeviceObject->DeviceExtension;
1167 
1168  ASSERT(IsMounted(Vcb));
1169 
1170  Irp = IrpContext->Irp;
1171 
1173 
1174  Xcb = (PRFSD_FCBVCB) (IrpSp->FileObject->FsContext);
1175 
1177  RfsdPrint((DBG_INFO, "RfsdCreate: Create on main device object.\n"));
1178 
1180 
1181  Irp->IoStatus.Information = FILE_OPENED;
1182 
1183  RfsdUnpinRepinnedBcbs(IrpContext);
1184 
1185  RfsdCompleteIrpContext(IrpContext, Status);
1186 
1187  return Status;
1188  }
1189 
1190  _SEH2_TRY {
1191 
1194 
1197  }
1198 
1199  _SEH2_LEAVE;
1200  }
1201 
1202  if ( ((IrpSp->FileObject->FileName.Length == 0) &&
1203  (IrpSp->FileObject->RelatedFileObject == NULL)) ||
1204  (Xcb && Xcb->Identifier.Type == RFSDVCB) ) {
1205  Status = RfsdCreateVolume(IrpContext, Vcb);
1206  } else {
1207  Status = RfsdCreateFile(IrpContext, Vcb);
1208  }
1209 
1210  } _SEH2_FINALLY {
1211 
1212  if (!IrpContext->ExceptionInProgress) {
1213  RfsdUnpinRepinnedBcbs(IrpContext);
1214 
1215  RfsdCompleteIrpContext(IrpContext, Status);
1216  }
1217  } _SEH2_END;
1218 
1219  return Status;
1220 }
#define IsMounted(Vcb)
Definition: ext2fs.h:803
NTSTATUS RfsdCompleteIrpContext(IN PRFSD_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: memory.c:160
Iosb Status
Definition: create.c:4287
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
Definition: rfsd.h:323
PDEVICE_OBJECT DeviceObject
Definition: rfsd.h:407
_SEH2_TRY
Definition: create.c:4226
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4137
_In_ PIRP Irp
Definition: csq.h:116
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
RFSD_IDENTIFIER_TYPE Type
Definition: rfsd.h:336
__drv_mustHoldCriticalRegion NTSTATUS RfsdCreateFile(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb)
Definition: create.c:304
PAGED_CODE()
VOID RfsdUnpinRepinnedBcbs(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: memory.c:286
struct _RFSD_VCB * PRFSD_VCB
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
struct _RFSD_FCBVCB * PRFSD_FCBVCB
#define VCB_DISMOUNT_PENDING
Definition: ext2fs.h:782
#define RfsdPrint(arg)
Definition: rfsd.h:1069
PRFSD_GLOBAL RfsdGlobal
Definition: init.c:17
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:3168
_SEH2_END
Definition: create.c:4400
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
_SEH2_FINALLY
Definition: create.c:4371
#define NULL
Definition: types.h:112
#define VCB_VOLUME_LOCKED
Definition: ext2fs.h:780
#define STATUS_VOLUME_DISMOUNTED
Definition: ntstatus.h:747
#define DBG_INFO
Definition: ffsdrv.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
RFSD_IDENTIFIER Identifier
Definition: rfsd.h:470
#define _SEH2_LEAVE
Definition: filesup.c:20
__drv_mustHoldCriticalRegion NTSTATUS RfsdCreateVolume(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb)
Definition: create.c:1057

Referenced by RfsdDispatchRequest().

◆ RfsdCreateFile()

__drv_mustHoldCriticalRegion NTSTATUS RfsdCreateFile ( PRFSD_IRP_CONTEXT  IrpContext,
PRFSD_VCB  Vcb 
)

Definition at line 304 of file create.c.

305 {
308  PRFSD_FCB Fcb = NULL;
309  PRFSD_MCB RfsdMcb = NULL;
310 
312  PRFSD_MCB ParentMcb = NULL;
313 
314  BOOLEAN bParentFcbCreated = FALSE;
315 
316  PRFSD_CCB Ccb = NULL;
317  PRFSD_INODE Inode = 0;
318  BOOLEAN VcbResourceAcquired = FALSE;
319 #if DISABLED
320  BOOLEAN bDir = FALSE;
321 #endif
322  BOOLEAN bFcbAllocated = FALSE;
323  BOOLEAN bCreated = FALSE;
325  PIRP Irp;
326 
327  ULONG Options;
329 
331  BOOLEAN OpenTargetDirectory;
333  BOOLEAN SequentialOnly;
334  BOOLEAN NoIntermediateBuffering;
335  BOOLEAN IsPagingFile;
337  BOOLEAN NonDirectoryFile;
340  BOOLEAN TemporaryFile;
341  BOOLEAN CaseSensitive;
342 
345 
346  PAGED_CODE();
347 
348  Irp = IrpContext->Irp;
350 
351  Options = IrpSp->Parameters.Create.Options;
352 
354  OpenTargetDirectory = IsFlagOn(IrpSp->Flags, SL_OPEN_TARGET_DIRECTORY);
355 
356  NonDirectoryFile = IsFlagOn(Options, FILE_NON_DIRECTORY_FILE);
357  SequentialOnly = IsFlagOn(Options, FILE_SEQUENTIAL_ONLY);
358  NoIntermediateBuffering = IsFlagOn( Options, FILE_NO_INTERMEDIATE_BUFFERING );
361 
362  CaseSensitive = IsFlagOn(IrpSp->Flags, SL_CASE_SENSITIVE);
363 
364  TemporaryFile = IsFlagOn(IrpSp->Parameters.Create.FileAttributes,
366 
367  CreateDisposition = (Options >> 24) & 0x000000ff;
368 
369  IsPagingFile = IsFlagOn(IrpSp->Flags, SL_OPEN_PAGING_FILE);
370 
374 
378 
379  DesiredAccess = IrpSp->Parameters.Create.SecurityContext->DesiredAccess;
380  ShareAccess = IrpSp->Parameters.Create.ShareAccess;
381 
382  FileName.Buffer = NULL;
383 
384  _SEH2_TRY {
385 
387  &Vcb->MainResource, TRUE );
388 
389  VcbResourceAcquired = TRUE;
390 
391  if (Irp->Overlay.AllocationSize.HighPart) {
393  _SEH2_LEAVE;
394  }
395 
396  if (!(Inode = ExAllocatePoolWithTag(
397  PagedPool, sizeof(RFSD_INODE), RFSD_POOL_TAG) )) {
398  _SEH2_LEAVE;
399  }
400 
401  RtlZeroMemory(Inode, sizeof(RFSD_INODE));
402 
403  FileName.MaximumLength = IrpSp->FileObject->FileName.MaximumLength;
404  FileName.Length = IrpSp->FileObject->FileName.Length;
405 
407  if (!FileName.Buffer) {
409  _SEH2_LEAVE;
410  }
411 
412  RtlZeroMemory(FileName.Buffer, FileName.MaximumLength);
413  RtlCopyMemory(FileName.Buffer, IrpSp->FileObject->FileName.Buffer, FileName.Length);
414 
415  if (IrpSp->FileObject->RelatedFileObject) {
416  ParentFcb = (PRFSD_FCB)(IrpSp->FileObject->RelatedFileObject->FsContext);
417  }
418 
419  if ((FileName.Length > sizeof(WCHAR)) &&
420  (FileName.Buffer[1] == L'\\') &&
421  (FileName.Buffer[0] == L'\\')) {
422 
423  FileName.Length -= sizeof(WCHAR);
424 
425  RtlMoveMemory( &FileName.Buffer[0],
426  &FileName.Buffer[1],
427  FileName.Length );
428 
429  //
430  // Bad Name if there are still beginning backslashes.
431  //
432 
433  if ((FileName.Length > sizeof(WCHAR)) &&
434  (FileName.Buffer[1] == L'\\') &&
435  (FileName.Buffer[0] == L'\\')) {
436 
438 
439  _SEH2_LEAVE;
440  }
441  }
442 
445  _SEH2_LEAVE;
446  }
447 
448  RfsdPrint((DBG_INFO, "RfsdCreateFile: %S (NameLen=%xh) Paging=%xh Option: %xh.\n",
449  FileName.Buffer, FileName.Length, IsPagingFile, IrpSp->Parameters.Create.Options));
450 
451  if (ParentFcb) {
452  ParentMcb = ParentFcb->RfsdMcb;
453  }
454 
456  Vcb,
457  &FileName,
458  ParentMcb,
459  &RfsdMcb,
460  Inode );
461 
462  if (!NT_SUCCESS(Status)) {
463  UNICODE_STRING PathName;
464  UNICODE_STRING RealName;
465  UNICODE_STRING RemainName;
466 
467 #if DISABLED
468  LONG i = 0;
469 #endif
470 
471  PathName = FileName;
472 
473  RfsdPrint((DBG_INFO, "RfsdCreateFile: File %S will be created.\n", PathName.Buffer));
474 
475  RfsdMcb = NULL;
476 
477  if (PathName.Buffer[PathName.Length/2 - 1] == L'\\') {
478  if (DirectoryFile) {
479  PathName.Length -=2;
480  PathName.Buffer[PathName.Length/2] = 0;
481  } else {
483  _SEH2_LEAVE;
484  }
485  }
486 
487  if (!ParentMcb) {
488  if (PathName.Buffer[0] != L'\\') {
490  _SEH2_LEAVE;
491  } else {
492  ParentMcb = Vcb->McbTree;
493  }
494  }
495 
496 Dissecting:
497 
498  FsRtlDissectName(PathName, &RealName, &RemainName);
499 
500  if (((RemainName.Length != 0) && (RemainName.Buffer[0] == L'\\')) ||
501  (RealName.Length >= 256*sizeof(WCHAR))) {
503  _SEH2_LEAVE;
504  }
505 
506  if (RemainName.Length != 0) {
507 
508  PRFSD_MCB RetMcb;
509 
511  Vcb,
512  &RealName,
513  ParentMcb,
514  &RetMcb,
515  Inode );
516 
517  if (!NT_SUCCESS(Status)) {
519  _SEH2_LEAVE;
520  }
521 
522  ParentMcb = RetMcb;
523  PathName = RemainName;
524 
525  goto Dissecting;
526  }
527 
528  if (FsRtlDoesNameContainWildCards(&RealName)) {
530  _SEH2_LEAVE;
531  }
532 
533  ParentFcb = ParentMcb->RfsdFcb;
534 
535  if (!ParentFcb) {
536 
538  sizeof(RFSD_INODE), RFSD_POOL_TAG);
539  if (!pTmpInode) {
541  _SEH2_LEAVE;
542  }
543 
544  if(!RfsdLoadInode(Vcb, &(ParentMcb->Key), pTmpInode)) {
545 #ifdef __REACTOS__
546  ExFreePool(pTmpInode);
547 #endif
549  _SEH2_LEAVE;
550  }
551 
552  ParentFcb = RfsdAllocateFcb(Vcb, ParentMcb, pTmpInode);
553 
554  if (!ParentFcb) {
555  ExFreePool(pTmpInode);
557  _SEH2_LEAVE;
558  }
559 
560  bParentFcbCreated = TRUE;
561  ParentFcb->ReferenceCount++;
562  }
563 
564  // We need to create a new one ?
565  if ((CreateDisposition == FILE_CREATE ) ||
568 
569  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) {
571  _SEH2_LEAVE;
572  }
573 
575  IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
576  Vcb->Vpb->RealDevice );
578 
580  }
581 
582  if (DirectoryFile) {
583  if (TemporaryFile) {
585  _SEH2_LEAVE;
586  }
587  }
588 
589  if (!ParentFcb) {
591  _SEH2_LEAVE;
592  }
593 
594  if (DirectoryFile) {
595  if ( RFSD_IS_ROOT_KEY(ParentFcb->RfsdMcb->Key) ) {
596  if ( (RealName.Length == 0x10) &&
597  memcmp(RealName.Buffer, L"Recycled\0", 0x10) == 0) {
598  SetFlag( IrpSp->Parameters.Create.FileAttributes,
600  }
601  }
602 
604 #if DISABLED
605  Status = RfsdCreateInode( IrpContext,
606  Vcb,
607  ParentFcb,
608  RFSD_FT_DIR,
609  IrpSp->Parameters.Create.FileAttributes,
610  &RealName);
611 #endif
612  } else {
614 #if DISABLED
615  Status = RfsdCreateInode( IrpContext,
616  Vcb,
617  ParentFcb,
618  RFSD_FT_REG_FILE,
619  IrpSp->Parameters.Create.FileAttributes,
620  &RealName);
621 #endif
622  }
623 
624  if (NT_SUCCESS(Status)) {
625 
626  bCreated = TRUE;
627 
628  Irp->IoStatus.Information = FILE_CREATED;
630  Vcb,
631  &RealName,
632  ParentMcb,
633  &RfsdMcb,
634  Inode );
635 
636  if (NT_SUCCESS(Status)) {
637 
638  if (DirectoryFile) {
639 DbgBreak();
640 #if DISABLED // dirctl.c [ see also in cleanup.c ]
642  IrpContext,
643  Vcb,
644  ParentFcb,
647  } else {
649  IrpContext,
650  Vcb,
651  ParentFcb,
654 #endif
655  }
656  } else {
657  DbgBreak();
658  }
659  } else {
660  DbgBreak();
661  }
662  } else if (OpenTargetDirectory) {
663  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) {
665  _SEH2_LEAVE;
666  }
667 
668  if (!ParentFcb) {
670  _SEH2_LEAVE;
671  }
672 
673  RtlZeroMemory( IrpSp->FileObject->FileName.Buffer,
674  IrpSp->FileObject->FileName.MaximumLength);
675  IrpSp->FileObject->FileName.Length = RealName.Length;
676 
677  RtlCopyMemory( IrpSp->FileObject->FileName.Buffer,
678  RealName.Buffer,
679  RealName.Length );
680 
681  Fcb = ParentFcb;
682 
683  Irp->IoStatus.Information = FILE_DOES_NOT_EXIST;
685  } else {
687  _SEH2_LEAVE;
688  }
689 
690  } else { // File / Dir already exists.
691 
692  if (OpenTargetDirectory) {
693 
694  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) {
696  _SEH2_LEAVE;
697  }
698 
699  Irp->IoStatus.Information = FILE_EXISTS;
701 
702  RtlZeroMemory( IrpSp->FileObject->FileName.Buffer,
703  IrpSp->FileObject->FileName.MaximumLength);
704  IrpSp->FileObject->FileName.Length = RfsdMcb->ShortName.Length;
705 
706  RtlCopyMemory( IrpSp->FileObject->FileName.Buffer,
707  RfsdMcb->ShortName.Buffer,
708  RfsdMcb->ShortName.Length );
709 
710  //Let Mcb pointer to it's parent
711  RfsdMcb = RfsdMcb->Parent;
712 
713  goto Openit;
714  }
715 
716  // We can not create if one exists
718  Irp->IoStatus.Information = FILE_EXISTS;
720  _SEH2_LEAVE;
721  }
722 
724 
725  if ((CreateDisposition != FILE_OPEN) &&
727 
729  _SEH2_LEAVE;
730  }
731 
732  if (NonDirectoryFile) {
734  _SEH2_LEAVE;
735  }
736 
737  if (RFSD_IS_ROOT_KEY(RfsdMcb->Key)) {
738 
739  if (DeleteOnClose) {
741  _SEH2_LEAVE;
742  }
743 
744  if (OpenTargetDirectory) {
746  _SEH2_LEAVE;
747  }
748  }
749  }
750 
751  Irp->IoStatus.Information = FILE_OPENED;
752  }
753 
754 Openit:
755 
756  if (RfsdMcb) {
757 
758  Fcb = RfsdMcb->RfsdFcb;
759 
760  if (!Fcb) {
761  Fcb = RfsdAllocateFcb (Vcb, RfsdMcb, Inode);
762  bFcbAllocated = TRUE;
763  }
764  }
765 
766  if (Fcb) {
767 
770  _SEH2_LEAVE;
771  }
772 
775  _SEH2_LEAVE;
776  }
777 
778  if (bCreated) {
779 DbgBreak();
780 #if DISABLED // ONLY FOR WRITE SUPPORT?
781 
782  //
783  // This file is just created.
784  //
785 
786  if (DirectoryFile) {
787  UNICODE_STRING EntryName;
788  USHORT NameBuf[6];
789 
790  RtlZeroMemory(&NameBuf, 6 * sizeof(USHORT));
791 
792  EntryName.Length = EntryName.MaximumLength = 2;
793  EntryName.Buffer = &NameBuf[0];
794  NameBuf[0] = (USHORT)'.';
795 
796  RfsdAddEntry( IrpContext, Vcb, Fcb,
797  RFSD_FT_DIR,
798  Fcb->RfsdMcb->Key,
799  &EntryName );
800 
801  RfsdSaveInode( IrpContext, Vcb,
802  Fcb->RfsdMcb->Key,
803  Fcb->Inode );
804 
805  EntryName.Length = EntryName.MaximumLength = 4;
806  EntryName.Buffer = &NameBuf[0];
807  NameBuf[0] = NameBuf[1] = (USHORT)'.';
808 
809  RfsdAddEntry( IrpContext, Vcb, Fcb,
810  RFSD_FT_DIR,
811  Fcb->RfsdMcb->Parent->Inode,
812  &EntryName );
813 
814  RfsdSaveInode( IrpContext, Vcb,
815  Fcb->RfsdMcb->Parent->Inode,
816  ParentFcb->Inode );
817  } else {
818 DbgBreak();
819 #if DISABLED
821  IrpContext, Vcb, Fcb,
822  &(Irp->Overlay.AllocationSize));
823 #endif
824 
825  if (!NT_SUCCESS(Status)) {
826 
827  DbgBreak();
828 
829  _SEH2_LEAVE;
830  }
831  }
832 #endif
833  } else {
834 
835  //
836  // This file alreayd exists.
837  //
838 
839  if (DeleteOnClose) {
840 
841  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) {
843  _SEH2_LEAVE;
844  }
845 
848 
849  IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
850  Vcb->Vpb->RealDevice );
851 
853 
855  }
856 
858 
859  } else {
860 
861  //
862  // Just to Open file (Open/OverWrite ...)
863  //
864 
865  if ((!IsDirectory(Fcb)) && (IsFlagOn(IrpSp->FileObject->Flags,
867  Fcb->Header.IsFastIoPossible = FastIoIsPossible;
868 
870  (Fcb->SectionObject.DataSectionObject != NULL)) {
871 
872  if (Fcb->NonCachedOpenCount == Fcb->OpenHandleCount) {
873  /* IsFlagOn(FileObject->Flags, FO_FILE_MODIFIED) */
874 
875  if(!IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) {
876  CcFlushCache(&Fcb->SectionObject, NULL, 0, NULL);
878  }
879 
880  CcPurgeCacheSection(&Fcb->SectionObject,
881  NULL,
882  0,
883  FALSE );
884  }
885  }
886  }
887  }
888  }
889 
890  if (!IsDirectory(Fcb)) {
891  if (!IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) {
892  if ((CreateDisposition == FILE_SUPERSEDE) && !IsPagingFile){
894  } else if (((CreateDisposition == FILE_OVERWRITE) ||
895  (CreateDisposition == FILE_OVERWRITE_IF)) && !IsPagingFile) {
898  }
899  }
900  }
901 
902  if (Fcb->OpenHandleCount > 0) {
904  ShareAccess,
905  IrpSp->FileObject,
906  &(Fcb->ShareAccess),
907  TRUE );
908 
909  if (!NT_SUCCESS(Status)) {
910  _SEH2_LEAVE;
911  }
912  } else {
914  ShareAccess,
915  IrpSp->FileObject,
916  &(Fcb->ShareAccess) );
917  }
918 
919  Ccb = RfsdAllocateCcb();
920 
921  Fcb->OpenHandleCount++;
922  Fcb->ReferenceCount++;
923 
925  Fcb->NonCachedOpenCount++;
926  }
927 
928  Vcb->OpenFileHandleCount++;
929  Vcb->ReferenceCount++;
930 
931  IrpSp->FileObject->FsContext = (void*)Fcb;
932  IrpSp->FileObject->FsContext2 = (void*) Ccb;
933  IrpSp->FileObject->PrivateCacheMap = NULL;
934  IrpSp->FileObject->SectionObjectPointer = &(Fcb->SectionObject);
935  IrpSp->FileObject->Vpb = Vcb->Vpb;
936 
938 
939  RfsdPrint((DBG_INFO, "RfsdCreateFile: %s OpenCount: %u ReferCount: %u\n",
940  Fcb->AnsiFileName.Buffer, Fcb->OpenHandleCount, Fcb->ReferenceCount));
941 
942  if (!IsDirectory(Fcb) && !NoIntermediateBuffering ) {
944  }
945 
946  if (!bCreated && !IsDirectory(Fcb)) {
947  if ( DeleteOnClose ||
951  if (!MmFlushImageSection( &Fcb->SectionObject,
952  MmFlushForWrite )) {
953 
956  _SEH2_LEAVE;
957  }
958  }
959 
963 
964 #if RFSD_READ_ONLY
966  _SEH2_LEAVE;
967 #endif
968 
969 
970 #if DISABLED
971  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) {
973  _SEH2_LEAVE;
974  }
975 
977 
978  IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
979  Vcb->Vpb->RealDevice );
981 
983  }
984 
985  Status = RfsdSupersedeOrOverWriteFile( IrpContext,
986  Vcb,
987  Fcb,
989 
990  if (NT_SUCCESS(Status)) {
991  _SEH2_LEAVE;
992  }
993 
994 DbgBreak();
995 #if DISABLED
997  IrpContext,
998  Vcb,
999  Fcb,
1000  &(Irp->Overlay.AllocationSize));
1001 #endif
1002 
1003  if (!(NT_SUCCESS(Status))) {
1004  _SEH2_LEAVE;
1005  }
1006 
1007 DbgBreak();
1008 #if DISABLED // dirctl.c
1010  IrpContext,
1011  Vcb,
1012  Fcb,
1017 #endif
1018 
1020  Irp->IoStatus.Information = FILE_SUPERSEDED;
1021  } else {
1022  Irp->IoStatus.Information = FILE_OVERWRITTEN;
1023  }
1024 #endif
1025  }
1026  }
1027  }
1028  } _SEH2_FINALLY {
1029 
1030  if (FileName.Buffer)
1031  ExFreePool(FileName.Buffer);
1032 
1033  if (bParentFcbCreated) {
1034  ParentFcb->ReferenceCount--;
1035  }
1036 
1037  if (VcbResourceAcquired) {
1039  &Vcb->MainResource,
1041  }
1042 
1043  if (!bFcbAllocated) {
1044  if (Inode)
1045  ExFreePool(Inode);
1046  } else {
1047  if (!Fcb && Inode)
1048  ExFreePool(Inode);
1049  }
1050  } _SEH2_END;
1051 
1052  return Status;
1053 }
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:386
#define FILE_WRITE_EA
Definition: nt_native.h:640
#define STATUS_DELETE_PENDING
Definition: ntstatus.h:322
NTSTATUS RfsdAddEntry(IN PRFSD_IRP_CONTEXT IrpContext, IN PRFSD_VCB Vcb, IN PRFSD_FCB Dcb, IN ULONG FileType, IN ULONG Inode, IN PUNICODE_STRING FileName)
#define FILE_EXISTS
Definition: nt_native.h:772
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
NTSTATUS RfsdExpandFile(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, PRFSD_FCB Fcb, PLARGE_INTEGER AllocationSize)
Definition: fileinfo.c:964
#define FILE_SEQUENTIAL_ONLY
Definition: from_kernel.h:27
#define STATUS_FILE_IS_A_DIRECTORY
Definition: udferr_usr.h:164
#define SL_CASE_SENSITIVE
Definition: iotypes.h:1820
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FILE_ATTRIBUTE_TEMPORARY
Definition: nt_native.h:708
#define FILE_OPEN_IF
Definition: from_kernel.h:56
#define FILE_OVERWRITTEN
Definition: nt_native.h:771
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
USHORT MaximumLength
Definition: env_spec_w32.h:370
Iosb Status
Definition: create.c:4287
#define SL_OPEN_PAGING_FILE
Definition: iotypes.h:1817
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4137
VOID RfsdNotifyReportChange(IN PRFSD_IRP_CONTEXT IrpContext, IN PRFSD_VCB Vcb, IN PRFSD_FCB Fcb, IN ULONG Filter, IN ULONG Action)
Definition: dirctl.c:745
PRFSD_MCB Parent
Definition: rfsd.h:684
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS RfsdSupersedeOrOverWriteFile(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, PRFSD_FCB Fcb, ULONG Disposition)
Definition: create.c:1307
#define FILE_CREATE
Definition: from_kernel.h:55
#define FILE_OPENED
Definition: nt_native.h:769
#define FILE_SUPERSEDED
Definition: nt_native.h:768
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
#define RFSD_IS_ROOT_KEY(x)
Definition: rfsd.h:52
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT _In_ ULONG CreateDisposition
Definition: create.c:4137
#define RFSD_POOL_TAG
Definition: rfsd.h:99
#define FILE_NOTIFY_CHANGE_SIZE
#define FILE_NOTIFY_CHANGE_LAST_WRITE
ULONG FileAttr
Definition: rfsd.h:703
#define FILE_OVERWRITE
Definition: from_kernel.h:57
#define FILE_NOTIFY_CHANGE_FILE_NAME
VOID NTAPI IoSetShareAccess(IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, OUT PSHARE_ACCESS ShareAccess)
Definition: file.c:3516
#define FO_NO_INTERMEDIATE_BUFFERING
Definition: iotypes.h:1778
#define FILE_NOTIFY_CHANGE_DIR_NAME
RFSD_KEY_IN_MEMORY Key
Definition: rfsd.h:697
BOOLEAN NTAPI FsRtlDoesNameContainWildCards(IN PUNICODE_STRING Name)
Definition: name.c:464
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT ShareAccess
Definition: create.c:4137
#define FCB_DELETE_PENDING
Definition: ext2fs.h:879
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
#define FILE_OPEN_BY_FILE_ID
Definition: from_kernel.h:41
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_SEH2_TRY
Definition: create.c:4226
#define FCB_DELETE_ON_CLOSE
Definition: ffsdrv.h:633
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
struct _RFSD_FCB * PRFSD_FCB
return STATUS_NOT_IMPLEMENTED
NTSTATUS RfsdLookupFileName(IN PRFSD_VCB Vcb, IN PUNICODE_STRING FullFileName, IN PRFSD_MCB ParentMcb, OUT PRFSD_MCB *RfsdMcb, IN OUT PRFSD_INODE Inode)
Definition: create.c:51
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4137
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define STATUS_NOT_A_DIRECTORY
Definition: udferr_usr.h:169
#define STATUS_SHARING_VIOLATION
Definition: udferr_usr.h:154
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
long LONG
Definition: pedump.c:60
#define FILE_NO_EA_KNOWLEDGE
Definition: from_kernel.h:36
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
#define FILE_ACTION_MODIFIED
unsigned char BOOLEAN
#define FILE_OVERWRITE_IF
Definition: from_kernel.h:58
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define STATUS_FILE_DELETED
Definition: udferr_usr.h:172
PAGED_CODE()
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
Status
Definition: gdiplustypes.h:24
ULONG OpenHandleCount
Definition: ntfs.h:533
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3531
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:112
SHARE_ACCESS ShareAccess
Definition: cdstruc.h:1009
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI FsRtlDissectName(IN UNICODE_STRING Name, OUT PUNICODE_STRING FirstPart, OUT PUNICODE_STRING RemainingPart)
Definition: name.c:398
BOOLEAN NTAPI MmFlushImageSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN MMFLUSH_TYPE FlushType)
Definition: section.c:4141
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:195
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
BOOLEAN RfsdSaveInode(IN PRFSD_IRP_CONTEXT IrpContext, IN PRFSD_VCB Vcb, IN ULONG inode, IN PRFSD_INODE Inode)
_In_ PFCB ParentFcb
Definition: cdprocs.h:736
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1781
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: ntfs.h:532
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FILE_DOES_NOT_EXIST
Definition: nt_native.h:773
#define STATUS_CANNOT_DELETE
Definition: shellext.h:71
static const WCHAR L[]
Definition: oid.c:1250
PRFSD_FCB RfsdFcb
Definition: rfsd.h:691
_Must_inspect_result_ _In_ PFLT_INSTANCE _Out_ PBOOLEAN IsDirectory
Definition: fltkernel.h:1139
#define RfsdPrint(arg)
Definition: rfsd.h:1069
#define FCB_FILE_MODIFIED
Definition: ext2fs.h:873
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:588
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define VCB_READ_ONLY
Definition: ext2fs.h:795
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
BOOLEAN RfsdLoadInode(IN PRFSD_VCB Vcb, IN PRFSD_KEY_IN_MEMORY pKey, IN OUT PRFSD_INODE Inode)
Definition: rfsd.c:253
#define FILE_OPEN
Definition: from_kernel.h:54
#define RfsdRaiseStatus(IRPCONTEXT, STATUS)
Definition: rfsd.h:177
NTSTATUS NTAPI IoCheckShareAccess(IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess, IN BOOLEAN Update)
Definition: file.c:3389
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
struct _FileName FileName
Definition: fatprocs.h:893
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:3168
_SEH2_END
Definition: create.c:4400
#define SL_OPEN_TARGET_DIRECTORY
Definition: iotypes.h:1818
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT _In_ ULONG _In_ BOOLEAN _In_ BOOLEAN DeleteOnClose
Definition: create.c:4137
#define FILE_NOTIFY_CHANGE_ATTRIBUTES
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
_SEH2_FINALLY
Definition: create.c:4371
#define NULL
Definition: types.h:112
#define FILE_CREATED
Definition: nt_native.h:770
NTSTATUS RfsdCreateInode(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, PRFSD_FCB ParentFcb, ULONG Type, ULONG FileAttr, PUNICODE_STRING FileName)
Definition: create.c:1225
#define FILE_ACTION_ADDED
#define FCB_FILE_DELETED
Definition: ffsdrv.h:635
UNICODE_STRING ShortName
Definition: rfsd.h:694
#define BOOLEAN
Definition: pedump.c:73
PRFSD_FCB RfsdAllocateFcb(IN PRFSD_VCB Vcb, IN PRFSD_MCB RfsdMcb, IN PRFSD_INODE Inode)
Definition: memory.c:383
unsigned int ULONG
Definition: retypes.h:1
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PRFSD_CCB RfsdAllocateCcb(VOID)
Definition: memory.c:617
#define DbgBreak()
Definition: ext2fs.h:46
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
VOID NTAPI IoSetHardErrorOrVerifyDevice(IN PIRP Irp, IN PDEVICE_OBJECT DeviceObject)
Definition: util.c:316
#define DBG_INFO
Definition: ffsdrv.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_LEAVE
Definition: filesup.c:20
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3127
_In_ PFCB Fcb
Definition: cdprocs.h:159
HRESULT Create([out]ITransactionReceiver **ppReceiver)
ULONG ACCESS_MASK
Definition: nt_native.h:40
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT _In_ ULONG _In_ BOOLEAN NoEaKnowledge
Definition: create.c:4137
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define DELETE
Definition: nt_native.h:57

Referenced by RfsdCreate().

◆ RfsdCreateInode()

NTSTATUS RfsdCreateInode ( PRFSD_IRP_CONTEXT  IrpContext,
PRFSD_VCB  Vcb,
PRFSD_FCB  ParentFcb,
ULONG  Type,
ULONG  FileAttr,
PUNICODE_STRING  FileName 
)

Definition at line 1225 of file create.c.

1232 {
1233  NTSTATUS Status;
1234  ULONG Inode;
1235  ULONG Group;
1236  RFSD_INODE RfsdIno;
1237 
1238  PAGED_CODE();
1239 #if 0
1240  RtlZeroMemory(&RfsdIno, sizeof(RFSD_INODE));
1241 
1242 DbgBreak();
1243 #if DISABLED
1244  Group = (ParentFcb->RfsdMcb->Inode - 1) / BLOCKS_PER_GROUP;
1245 #endif
1246 
1247  RfsdPrint(( DBG_INFO,
1248  "RfsdCreateInode: %S in %S(Key=%x,%xh)\n",
1249  FileName->Buffer,
1250  ParentFcb->RfsdMcb->ShortName.Buffer,
1251  ParentFcb->RfsdMcb->Key.k_dir_id, ParentFcb->RfsdMcb->Key.k_objectid));
1252 
1253  Status = RfsdNewInode(IrpContext, Vcb, Group,Type, &Inode);
1254 
1255  if (!NT_SUCCESS(Status)) {
1256  goto errorout;
1257  }
1258 
1259  Status = RfsdAddEntry(IrpContext, Vcb, ParentFcb, Type, Inode, FileName);
1260 
1261  if (!NT_SUCCESS(Status)) {
1262  DbgBreak();
1263  RfsdFreeInode(IrpContext, Vcb, Inode, Type);
1264 
1265  goto errorout;
1266  }
1267 
1268  RfsdSaveInode(IrpContext, Vcb, ParentFcb->RfsdMcb->Inode, ParentFcb->Inode);
1269 
1270  RfsdIno.i_ctime = ParentFcb->Inode->i_mtime;
1271  RfsdIno.i_mode = ( S_IPERMISSION_MASK &
1272  ParentFcb->Inode->i_mode );
1273  RfsdIno.i_uid = ParentFcb->Inode->i_uid;
1274  RfsdIno.i_gid = ParentFcb->Inode->i_gid;
1275 
1276  //~ RfsdIno.i_dir_acl = ParentFcb->Inode->i_dir_acl;
1277  //~ RfsdIno.i_file_acl = ParentFcb->Inode->i_file_acl;
1278  RfsdIno.u.i_generation = ParentFcb->Inode->u.i_generation;
1279 
1280  //~ RfsdIno.osd2 = ParentFcb->Inode->osd2;
1281 
1283  RfsdSetReadOnly(RfsdIno.i_mode);
1284  }
1285 
1286  if (Type == RFSD_FT_DIR) {
1287  RfsdIno.i_mode |= S_IFDIR;
1288  RfsdIno.i_links_count = 2;
1289  } else if (Type == RFSD_FT_REG_FILE) {
1290  RfsdIno.i_mode |= S_IFREG;
1291  RfsdIno.i_links_count = 1;
1292  } else {
1293  DbgBreak();
1294  RfsdIno.i_links_count = 1;
1295  }
1296 
1297  RfsdSaveInode(IrpContext, Vcb, Inode, &RfsdIno);
1298 
1299  RfsdPrint((DBG_INFO, "RfsdCreateInode: New Inode = %xh (Type=%xh)\n", Inode, Type));
1300 
1301 errorout:
1302 #endif // 0
1303  return 0;//Status;
1304 }
NTSTATUS RfsdAddEntry(IN PRFSD_IRP_CONTEXT IrpContext, IN PRFSD_VCB Vcb, IN PRFSD_FCB Dcb, IN ULONG FileType, IN ULONG Inode, IN PUNICODE_STRING FileName)
__u32 i_ctime
Definition: reiserfs.h:237
Iosb Status
Definition: create.c:4287
_In_opt_ PSID Group
Definition: rtlfuncs.h:1605
LONG NTSTATUS
Definition: precomp.h:26
__u32 i_generation
Definition: reiserfs.h:241
union stat_data::@761 u
#define S_IFREG
Definition: ext2fs.h:356
__u16 i_mode
Definition: reiserfs.h:229
__u32 i_links_count
Definition: reiserfs.h:231
NTSTATUS RfsdNewInode(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, ULONG GroupHint, ULONG mode, PULONG Inode)
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4137
#define RfsdSetReadOnly(m)
Definition: rfsd.h:294
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
PAGED_CODE()
#define S_IFDIR
Definition: acwin.h:115
__u32 i_gid
Definition: reiserfs.h:234
Status
Definition: gdiplustypes.h:24
__u32 i_uid
Definition: reiserfs.h:233
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
Type
Definition: Type.h:6
BOOLEAN RfsdSaveInode(IN PRFSD_IRP_CONTEXT IrpContext, IN PRFSD_VCB Vcb, IN ULONG inode, IN PRFSD_INODE Inode)
_In_ PFCB ParentFcb
Definition: cdprocs.h:736
#define RfsdPrint(arg)
Definition: rfsd.h:1069
#define S_IPERMISSION_MASK
Definition: ext2fs.h:375
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define DbgBreak()
Definition: ext2fs.h:46
#define DBG_INFO
Definition: ffsdrv.h:1034
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
#define BLOCKS_PER_GROUP
Definition: ext2fs.h:100
BOOLEAN RfsdFreeInode(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, ULONG Inode, ULONG Type)

Referenced by RfsdCreateFile().

◆ RfsdCreateVolume()

__drv_mustHoldCriticalRegion NTSTATUS RfsdCreateVolume ( PRFSD_IRP_CONTEXT  IrpContext,
PRFSD_VCB  Vcb 
)

Definition at line 1057 of file create.c.

1058 {
1060  PIRP Irp;
1061 
1062  NTSTATUS Status;
1063 
1066 
1067  ULONG Options;
1069  BOOLEAN OpenTargetDirectory;
1070 
1072 
1073  PAGED_CODE();
1074 
1075  RfsdPrint((DBG_FUNC, "Entering CreateVolume\n"));
1076 
1077  Irp = IrpContext->Irp;
1079 
1080  Options = IrpSp->Parameters.Create.Options;
1081 
1083  OpenTargetDirectory = IsFlagOn(IrpSp->Flags, SL_OPEN_TARGET_DIRECTORY);
1084 
1085  CreateDisposition = (Options >> 24) & 0x000000ff;
1086 
1087  DesiredAccess = IrpSp->Parameters.Create.SecurityContext->DesiredAccess;
1088  ShareAccess = IrpSp->Parameters.Create.ShareAccess;
1089 
1090  if (DirectoryFile) {
1091  return STATUS_NOT_A_DIRECTORY;
1092  }
1093 
1094  if (OpenTargetDirectory) {
1095  return STATUS_INVALID_PARAMETER;
1096  }
1097 
1098  if ( (CreateDisposition != FILE_OPEN) &&
1100  return STATUS_ACCESS_DENIED;
1101  }
1102 
1104 
1105  if (Vcb->OpenHandleCount > 0) {
1107  IrpSp->FileObject,
1108  &(Vcb->ShareAccess), TRUE);
1109 
1110  if (!NT_SUCCESS(Status)) {
1111  goto errorout;
1112  }
1113  } else {
1115  IrpSp->FileObject,
1116  &(Vcb->ShareAccess) );
1117  }
1118 
1120  ExAcquireResourceExclusiveLite(&Vcb->MainResource, TRUE);
1121 
1124 
1125  ExReleaseResourceLite(&Vcb->MainResource);
1126  }
1127 
1128  {
1130 
1131  if (Ccb == NULL) {
1133  goto errorout;
1134  }
1135 
1137  IrpSp->FileObject->FsContext = Vcb;
1138  IrpSp->FileObject->FsContext2 = Ccb;
1139 
1140  Vcb->ReferenceCount++;
1141  Vcb->OpenHandleCount++;
1142 
1143  Irp->IoStatus.Information = FILE_OPENED;
1144  }
1145 
1146 errorout:
1147 
1148  return Status;
1149 }
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FILE_OPEN_IF
Definition: from_kernel.h:56
Iosb Status
Definition: create.c:4287
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4137
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT _In_ ULONG CreateDisposition
Definition: create.c:4137
NTSTATUS RfsdFlushVolume(IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:97
NTSTATUS RfsdFlushFiles(IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:51
VOID NTAPI IoSetShareAccess(IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, OUT PSHARE_ACCESS ShareAccess)
Definition: file.c:3516
#define FO_NO_INTERMEDIATE_BUFFERING
Definition: iotypes.h:1778
#define FILE_APPEND_DATA
Definition: nt_native.h:634
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT ShareAccess
Definition: create.c:4137
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4137
#define STATUS_NOT_A_DIRECTORY
Definition: udferr_usr.h:169
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define FILE_READ_DATA
Definition: nt_native.h:628
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
unsigned char BOOLEAN
#define FILE_WRITE_DATA
Definition: nt_native.h:631
PAGED_CODE()
Status
Definition: gdiplustypes.h:24
#define DBG_FUNC
Definition: ffsdrv.h:1035
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3531
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define RfsdPrint(arg)
Definition: rfsd.h:1069
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:588
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
USHORT ShareAccess
Definition: iotypes.h:3119
#define FILE_OPEN
Definition: from_kernel.h:54
NTSTATUS NTAPI IoCheckShareAccess(IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess, IN BOOLEAN Update)
Definition: file.c:3389
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:3168
#define SL_OPEN_TARGET_DIRECTORY
Definition: iotypes.h:1818
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
PRFSD_CCB RfsdAllocateCcb(VOID)
Definition: memory.c:617
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3127
HRESULT Create([out]ITransactionReceiver **ppReceiver)
ULONG ACCESS_MASK
Definition: nt_native.h:40

Referenced by RfsdCreate().

◆ RfsdLookupFileName()

NTSTATUS RfsdLookupFileName ( IN PRFSD_VCB  Vcb,
IN PUNICODE_STRING  FullFileName,
IN PRFSD_MCB  ParentMcb,
OUT PRFSD_MCB RfsdMcb,
IN OUT PRFSD_INODE  Inode 
)

Definition at line 51 of file create.c.

56 {
59  PRFSD_MCB Mcb = 0;
60 
61  RFSD_DENTRY_HEAD DirectoryEntry;
62  int i = 0;
63  BOOLEAN bRun = TRUE;
64  BOOLEAN bParent = FALSE;
65  RFSD_INODE in;
66  ULONG off = 0;
67 
68  PAGED_CODE();
69 
71 
72  *RfsdMcb = NULL;
73 
74 
75  // Determine the parent node
76  if (ParentMcb) {
77  // Looking up a file in the tree, starting at an arbitrary parent node.
78  bParent = TRUE;
79  } else if (FullFileName->Buffer[0] == L'\\') {
80  // Looking up from the root (so there was no parent). Assign the root node parent from the VCB.
81  ParentMcb = Vcb->McbTree;
82  } else {
83  // Otherwise, fail attempt to lookup non-rooted filename
85  }
86 
87  RtlZeroMemory(&DirectoryEntry, sizeof(RFSD_DENTRY_HEAD));
88 
89  // Sanity check that the filename is valid
90  if (FullFileName->Length == 0) {
91  return Status;
92  }
93 
94  // Only if we're looking up *exactly* the root node, load it, and return it
95  if (FullFileName->Length == 2 && FullFileName->Buffer[0] == L'\\') {
96  if (!RfsdLoadInode(Vcb, &(ParentMcb->Key), Inode)) {
97  return Status;
98  }
99 
100  *RfsdMcb = Vcb->McbTree;
101 
102  return STATUS_SUCCESS;
103  }
104 
105  // Begin lookup from the parent node
106  while (bRun && i < FullFileName->Length/2) {
107  int Length;
109 
110  if (bParent) {
111  bParent = FALSE;
112  } else {
113  // Advance through the (potentially) consecutive '\' path seperators in the filename
114  while(i < FullFileName->Length/2 && FullFileName->Buffer[i] == L'\\') i++;
115  }
116 
117  Length = i;
118 
119  // Advance to the next '\' path seperator
120  while(i < FullFileName->Length/2 && (FullFileName->Buffer[i] != L'\\')) i++;
121 
122  if ( (i - Length) <= 0) {
123  // All of the tokens have been parsed...
124  break;
125  }
126  else {
127  // There remains a token between the path seperators...
128 
129  // FileName is a (non-null-terminated) view into the FullFileName structure
130  FileName = *FullFileName;
131  FileName.Buffer += Length;
132  FileName.Length = (USHORT)((i - Length) * 2);
133 
134  // Check to see if the parent MCB already contains a child MCB matching the target FileName
135  Mcb = RfsdSearchMcb(Vcb, ParentMcb, &FileName);
136 
137  if (Mcb) {
138  ParentMcb = Mcb;
139 
141 
142  if (!IsFlagOn(Mcb->FileAttr, FILE_ATTRIBUTE_DIRECTORY)) {
143  if (i < FullFileName->Length/2) {
145  }
146 
147  break;
148  }
149  } else {
150  // The parent has no child MCB, or there was no child MCB sibling named FileName. Check the disk using ScanDir...
151 
152  // Load the parent directory's inode / stat data structure
153  // For ReiserFS, I'd need the parent's key. This has to be a key leading to a directory... I'm just getting it to pass it to scan.
154  if (!RfsdLoadInode(Vcb, &(ParentMcb->Key), &in)) {
156  break;
157  }
158 
159  // Sanity check that we loaded a directory (unless we loaded the last token, in which case it's ok that we loaded something else??)
160  if (!S_ISDIR(in.i_mode)) {
161  if (i < FullFileName->Length/2) {
163  break;
164  }
165  }
166 
167 
168  Status = RfsdScanDir (
169  Vcb,
170  ParentMcb,
171  &FileName,
172  &off, // <
173  &(DirectoryEntry) ); // <
174 
175  if (!NT_SUCCESS(Status)) {
176  // No such file (or an error occurred), so drop out.
177  bRun = FALSE;
178 /*
179  if (i >= FullFileName->Length/2)
180  {
181  *RfsdMcb = ParentMcb;
182  }
183 */
184  } else {
185  // We've found what we were looking for...
186 #if 0 // disabled by ffs too
187  if (IsFlagOn( SUPER_BLOCK->s_feature_incompat,
188  RFSD_FEATURE_INCOMPAT_FILETYPE)) {
189  if (rfsd_dir.file_type == RFSD_FT_DIR)
191  } else
192 #endif
193  {
195  key.k_dir_id = DirectoryEntry.deh_dir_id;
196  key.k_objectid = DirectoryEntry.deh_objectid;
197 
198  if (!RfsdLoadInode(Vcb, &key, &in)) {
200  break;
201  }
202  if (S_ISDIR(in.i_mode)) {
204  }
205  }
206 
207  SetFlag(ParentMcb->Flags, MCB_IN_USE);
209  ClearFlag(ParentMcb->Flags, MCB_IN_USE);
210 
211  if (!Mcb) {
213  break;
214  }
215 
216  // NOTE: It should be OK to leave off the 3rd / 4th part of key, because (AFAIK) the only place this is used is ScanDir
217  Mcb->Key.k_dir_id = DirectoryEntry.deh_dir_id;
218  Mcb->Key.k_objectid = DirectoryEntry.deh_objectid;
219  Mcb->Key.k_offset = Mcb->Key.k_type = 0;
220 
221  Mcb->DeOffset = off;
222  RfsdAddMcbNode(Vcb, ParentMcb, Mcb);
223  ParentMcb = Mcb;
224  }
225  }
226  }
227  }
228 
229  if (NT_SUCCESS(Status)) {
230  // If the name has been found, load it according to the inode number in the MCB...
231  // The result will be returned to the caller via Inode
232  *RfsdMcb = Mcb;
233  if (Inode) {
234  if (!RfsdLoadInode(Vcb, &(Mcb->Key), Inode)) {
235  RfsdPrint((DBG_ERROR, "RfsdLookupFileName: error loading Inode %x,%xh\n",
236  Mcb->Key.k_dir_id, Mcb->Key.k_objectid));
238  }
239  }
240  }
241 
242  return Status;
243 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Iosb Status
Definition: create.c:4287
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4137
#define FALSE
Definition: types.h:117
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
unsigned char BOOLEAN
#define MCB_IN_USE
Definition: ffsdrv.h:680
#define SUPER_BLOCK
Definition: ext2fs.h:90
PAGED_CODE()
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
Status
Definition: gdiplustypes.h:24
PRFSD_MCB RfsdAllocateMcb(PRFSD_VCB, PUNICODE_STRING FileName, ULONG FileAttr)
Definition: memory.c:694
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define S_ISDIR(mode)
Definition: various.h:18
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
NTSTATUS RfsdScanDir(IN PRFSD_VCB Vcb, IN PRFSD_MCB ParentMcb, IN PUNICODE_STRING FileName, IN OUT PULONG Index, IN OUT PRFSD_DENTRY_HEAD rfsd_dir)
Definition: create.c:253
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
PRFSD_MCB RfsdSearchMcb(PRFSD_VCB Vcb, PRFSD_MCB Parent, PUNICODE_STRING FileName)
Definition: memory.c:987
static const WCHAR L[]
Definition: oid.c:1250
#define RfsdPrint(arg)
Definition: rfsd.h:1069
HKEY key
Definition: reg.c:42
#define DBG_ERROR
Definition: ffsdrv.h:1031
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
BOOLEAN RfsdLoadInode(IN PRFSD_VCB Vcb, IN PRFSD_KEY_IN_MEMORY pKey, IN OUT PRFSD_INODE Inode)
Definition: rfsd.c:253
struct _FileName FileName
Definition: fatprocs.h:893
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
GLuint in
Definition: glext.h:9616
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define NULL
Definition: types.h:112
VOID RfsdAddMcbNode(PRFSD_VCB Vcb, PRFSD_MCB Parent, PRFSD_MCB Child)
Definition: memory.c:1023
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: path.c:41

Referenced by RfsdCreateFile(), and RfsdSetRenameInfo().

◆ RfsdScanDir()

NTSTATUS RfsdScanDir ( IN PRFSD_VCB  Vcb,
IN PRFSD_MCB  ParentMcb,
IN PUNICODE_STRING  FileName,
IN OUT PULONG  Index,
IN OUT PRFSD_DENTRY_HEAD  rfsd_dir 
)

(This function is only called by LookupFileName.) NOTE: The offset and type of the key passed are irrelevant, as the function will always open a a directory for searching, and will search for the contents by file name – not key.

STATUS_INSUFFICIENT_RESOURCES if the filename or diskreading buffer could not be allocated STATUS_UNSUCCESSFUL if the buffer could not be read from disk STATUS_NO_SUCH_FILE if the FileName given was not found in the directory scanned

Definition at line 253 of file create.c.

258 {
261 
262  PAGED_CODE();
263 
264  // Construct the key (for the directory to be searched), by copying the structure
265  DirectoryKey = ParentMcb->Key;
266  DirectoryKey.k_offset = 0x1;
268 
269  // Request that the filesystem tree be parsed, looking for FileName in directory spans belonging to DirectoryKey
270  {
272 
273  CallbackContext.Vcb = Vcb;
274  CallbackContext.pDirectoryKey = &DirectoryKey;
275  CallbackContext.pTargetFilename = FileName;
276 
277  CallbackContext.idxCurrentDentry = 0;
278 
279  CallbackContext.pMatchingDentry = rfsd_dir;
280  CallbackContext.pMatchingIndex = Index;
281 
283 
284  if (Status == STATUS_EVENT_DONE)
285  {
287  }
288  else if (Status == STATUS_SUCCESS)
289  {
291  }
292  else
293  {
295  }
296  }
297 
298  RfsdPrint((DBG_TRACE, /*__FUNCTION__*/ " returning %s\n", RfsdNtStatusToString(Status)));
299  return Status;
300 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
NTSTATUS RfsdScanDirCallback(ULONG BlockNumber, PVOID pContext)
Definition: create.c:1381
Iosb Status
Definition: create.c:4287
#define STATUS_EVENT_DONE
Definition: ntstatus.h:132
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS RfsdParseFilesystemTree(IN PRFSD_VCB Vcb, IN PRFSD_KEY_IN_MEMORY Key, IN ULONG StartingBlockNumber, IN RFSD_CALLBACK(fpDirectoryCallback), IN PVOID Context)
Definition: rfsd.c:2909
PUCHAR RfsdNtStatusToString(IN NTSTATUS Status)
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4137
PAGED_CODE()
Status
Definition: gdiplustypes.h:24
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ ULONGLONG DirectoryKey
Definition: fsrtlfuncs.h:336
#define DBG_TRACE(fmt,...)
Definition: svchost.h:34
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define RfsdPrint(arg)
Definition: rfsd.h:1069
struct _FileName FileName
Definition: fatprocs.h:893
#define STATUS_NO_SUCH_FILE
Definition: udferr_usr.h:137
#define RFSD_KEY_TYPE_v2_DIRENTRY
Definition: reiserfs.h:285
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by RfsdLookupFileName().

◆ RfsdScanDirCallback()

NTSTATUS RfsdScanDirCallback ( ULONG  BlockNumber,
PVOID  pContext 
)

Searches to find if the name if is located in the dentry span within the block.

STATUS_SUCCESS if the name was not found, but processing should continue STATUS_EVENT_DONE if the name was found, and processing should stop

Definition at line 1381 of file create.c.

1384 {
1385  PRFSD_SCANDIR_CALLBACK_CONTEXT pCallbackContext = (PRFSD_SCANDIR_CALLBACK_CONTEXT) pContext;
1387  PUCHAR pBlockBuffer = NULL;
1388  PRFSD_ITEM_HEAD pDirectoryItemHeader = NULL;
1389  PUCHAR pDirectoryItemBuffer = NULL;
1390  NTSTATUS Status;
1391  BOOLEAN bFound = FALSE;
1392  PRFSD_DENTRY_HEAD pPrevDentry = NULL;
1393  ULONG idxDentryInSpan = 0;
1394  UNICODE_STRING InodeFileName;
1395  USHORT InodeFileNameLength;
1396 
1397  PAGED_CODE();
1398 
1399  InodeFileName.Buffer = NULL;
1400 
1401  RfsdPrint((DBG_FUNC, /*__FUNCTION__*/ " invoked on block %i\n", BlockNumber));
1402 
1403 
1404  _SEH2_TRY {
1405 
1406  // Load the block
1407  pBlockBuffer = RfsdAllocateAndLoadBlock(pCallbackContext->Vcb, BlockNumber);
1408  if (!pBlockBuffer) { Status = STATUS_INSUFFICIENT_RESOURCES; _SEH2_LEAVE; }
1409 
1410  // Construct the item key to search for
1411  DirectoryKey = *(pCallbackContext->pDirectoryKey);
1413 
1414  // Get the item header and its information
1416  pCallbackContext->Vcb, &DirectoryKey, pBlockBuffer,
1417  ( &pDirectoryItemHeader ), //<
1419  );
1420 
1421  // If this block doesn't happen to contain a directory item, skip it.
1422  if ( (Status == STATUS_NO_SUCH_MEMBER) || !pDirectoryItemHeader )
1423  {
1424  KdPrint(("Block %i did not contain the appropriate diritem header\n", BlockNumber));
1426  }
1427 
1428  // Setup the item buffer
1429  pDirectoryItemBuffer = (PUCHAR) pBlockBuffer + pDirectoryItemHeader->ih_item_location;
1430 
1431 
1432 
1433  // Allocate the unicode filename buffer
1434  InodeFileName.Buffer = ExAllocatePoolWithTag(PagedPool, (RFSD_NAME_LEN + 1) * 2, RFSD_POOL_TAG);
1435  if (!InodeFileName.Buffer) { Status = STATUS_INSUFFICIENT_RESOURCES; _SEH2_LEAVE; }
1436 
1437 
1438  while (!bFound && (idxDentryInSpan < pDirectoryItemHeader->u.ih_entry_count) ) {
1440 
1441  //
1442  // reading dir entries from Dcb
1443  //
1444 
1445  PRFSD_DENTRY_HEAD pCurrentDentry = (PRFSD_DENTRY_HEAD) (pDirectoryItemBuffer + (idxDentryInSpan * sizeof(RFSD_DENTRY_HEAD)));
1446 
1447  // Skip the directory entry for the parent of the root directory (because it should not be shown, and has no stat data)
1448  // (NOTE: Any change made here should also be mirrored in RfsdDirControlCallback)
1449  if (pCurrentDentry->deh_dir_id == 0 /*&& pCurrentDentry->deh_objectid == 1*/)
1450  { goto ProcessNextEntry; }
1451 
1452  // Retrieve the filename of the loaded directory entry from the buffer (encoded with the codepage)
1453  // NOTE: The filename is not gauranteed to be null-terminated, and so the end may implicitly be the start of the previous entry.
1454  OemName.Buffer = (PUCHAR) pDirectoryItemBuffer + pCurrentDentry->deh_location;
1455  OemName.MaximumLength = (pPrevDentry ? pPrevDentry->deh_location : // The end of this entry is the start of the previous
1456  pDirectoryItemHeader->ih_item_len // Otherwise this is the first entry, the end of which is the end of the item.
1457  ) - pCurrentDentry->deh_location;
1458  OemName.Length = RfsdStringLength(OemName.Buffer, OemName.MaximumLength);
1459 
1460 
1461 
1462  // Convert that name to unicode
1463  {
1464  InodeFileNameLength = (USHORT) RfsdOEMToUnicodeSize(&OemName) + 2;
1465 
1466  // If the unicode InodeFileName.Buffer is not large enough, expand it
1467  if (InodeFileName.MaximumLength < InodeFileNameLength)
1468  {
1469  // Free the existing buffer
1470  if (InodeFileName.Buffer) { ExFreePool(InodeFileName.Buffer); }
1471 
1472  // Allocate a new larger buffer
1473  InodeFileName.Buffer = ExAllocatePoolWithTag(PagedPool, InodeFileNameLength, RFSD_POOL_TAG);
1474  if (!InodeFileName.Buffer) { Status = STATUS_INSUFFICIENT_RESOURCES; _SEH2_LEAVE; }
1475  InodeFileName.MaximumLength = InodeFileNameLength;
1476  }
1477 
1478  InodeFileName.Length = 0;
1479 
1480  RtlZeroMemory( InodeFileName.Buffer, InodeFileNameLength);
1481 
1483  &InodeFileName,
1484  &OemName );
1485 
1486  if (!NT_SUCCESS(Status)) { _SEH2_LEAVE; }
1487  }
1488 
1489 
1490  // Compare it to the name we are searching for
1492  pCallbackContext->pTargetFilename,
1493  &InodeFileName,
1494  TRUE )) {
1495  // This entry MATCHED! Copy the matching dentry into the output field on the context
1496  bFound = TRUE;
1497 
1498  *(pCallbackContext->pMatchingIndex) = (pCallbackContext->idxCurrentDentry * sizeof(RFSD_DENTRY_HEAD));
1499  RtlCopyMemory(pCallbackContext->pMatchingDentry, pCurrentDentry, sizeof(RFSD_DENTRY_HEAD));
1500 
1501  RfsdPrint(( DBG_INFO, /*__FUNCTION__*/ ": Found: Name=%S Key=%xh,%xh\n",
1502  InodeFileName.Buffer, pCurrentDentry->deh_dir_id, pCurrentDentry->deh_objectid ));
1503 
1505  break;
1506  }
1507 
1508  ProcessNextEntry:
1509  // Advance to the next directory entry
1510  pPrevDentry = pCurrentDentry;
1511  ++idxDentryInSpan;
1512  ++(pCallbackContext->idxCurrentDentry);
1513  }
1514 
1515  if (!bFound) {
1516  // Indicate success, so that parsing will continue with subsequent blocks.
1518  }
1519  } _SEH2_FINALLY {
1520  if (pBlockBuffer) ExFreePool(pBlockBuffer);
1521  if (InodeFileName.Buffer) ExFreePool(InodeFileName.Buffer);
1522  } _SEH2_END;
1523 
1524 
1525  return Status;
1526 
1527 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define RFSD_NAME_LEN
Definition: rfsd.h:45
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_NO_SUCH_MEMBER
Definition: ntstatus.h:611
USHORT MaximumLength
Definition: env_spec_w32.h:370
OUT PRFSD_DENTRY_HEAD pMatchingDentry
Running count of the dentries processed, so that MatchingIndex will be relative to all dentry spans.
Definition: create.c:33
Iosb Status
Definition: create.c:4287
NTSTATUS RfsdFindItemHeaderInBlock(IN PRFSD_VCB Vcb, IN PRFSD_KEY_IN_MEMORY pKey, IN PUCHAR pBlockBuffer, OUT PRFSD_ITEM_HEAD *ppTargetItemHeader, IN RFSD_KEY_COMPARISON(*fpComparisonFunction)(PRFSD_KEY_IN_MEMORY, PRFSD_KEY_IN_MEMORY))
Definition: rfsdblock.c:61
#define TRUE
Definition: types.h:120
#define STATUS_EVENT_DONE
Definition: ntstatus.h:132
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
PUCHAR RfsdAllocateAndLoadBlock(IN PRFSD_VCB Vcb, IN ULONG BlockIndex)
Definition: rfsdblock.c:34
#define RFSD_POOL_TAG
Definition: rfsd.h:99
ULONG RfsdOEMToUnicodeSize(IN PANSI_STRING Oem)
Definition: misc.c:183
OUT PULONG pMatchingIndex
If a matching dentry is found, the callback will fill this structure with it.
Definition: create.c:34
STRING OEM_STRING
Definition: umtypes.h:203
IN PUNICODE_STRING pTargetFilename
Definition: create.c:29
_SEH2_TRY
Definition: create.c:4226
struct reiserfs_de_head * PRFSD_DENTRY_HEAD
Definition: rfsd.h:39
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
__u16 ih_item_location
Definition: reiserfs_fs.h:536
struct _RFSD_SCANDIR_CALLBACK_CONTEXT * PRFSD_SCANDIR_CALLBACK_CONTEXT
PAGED_CODE()
Status
Definition: gdiplustypes.h:24
#define DBG_FUNC
Definition: ffsdrv.h:1035
IN PRFSD_KEY_IN_MEMORY pDirectoryKey
Definition: create.c:28
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
__u16 ih_item_len
Definition: reiserfs_fs.h:535
_In_ ULONGLONG DirectoryKey
Definition: fsrtlfuncs.h:336
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#define RfsdPrint(arg)
Definition: rfsd.h:1069
_SEH2_END
Definition: create.c:4400
unsigned short USHORT
Definition: pedump.c:61
RFSD_KEY_COMPARISON CompareKeysWithoutOffset(IN PRFSD_KEY_IN_MEMORY a, IN PRFSD_KEY_IN_MEMORY b)
Definition: rfsd.c:2831
_SEH2_FINALLY
Definition: create.c:4371
NTSTATUS RfsdOEMToUnicode(IN OUT PUNICODE_STRING Oem, IN POEM_STRING Unicode)
Definition: misc.c:195
#define NULL
Definition: types.h:112
#define RFSD_KEY_TYPE_v2_DIRENTRY
Definition: reiserfs.h:285
static USHORT RfsdStringLength(PUCHAR buffer, USHORT MaximumLength)
Definition: rfsd.h:1943
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define DBG_INFO
Definition: ffsdrv.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_LEAVE
Definition: filesup.c:20
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1303
#define KdPrint(x)
Definition: env_spec_w32.h:288
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by RfsdScanDir().

◆ RfsdSupersedeOrOverWriteFile()

NTSTATUS RfsdSupersedeOrOverWriteFile ( PRFSD_IRP_CONTEXT  IrpContext,
PRFSD_VCB  Vcb,
PRFSD_FCB  Fcb,
ULONG  Disposition 
)

Definition at line 1307 of file create.c.

1312 {
1313  LARGE_INTEGER CurrentTime;
1316 
1317  PAGED_CODE();
1318 #if 0
1319  KeQuerySystemTime(&CurrentTime);
1320 
1321  AllocationSize.QuadPart = (LONGLONG)0;
1322 
1323  if (!MmCanFileBeTruncated(&(Fcb->SectionObject), &(AllocationSize))) {
1325  return Status;
1326  }
1327 
1328 DbgBreak();
1329 #if DISABLED
1330  Status = RfsdTruncateFile(IrpContext, Vcb, Fcb, &AllocationSize);
1331 #endif
1332 
1333  if (NT_SUCCESS(Status)) {
1334  Fcb->Header.AllocationSize.QuadPart =
1335  Fcb->Header.FileSize.QuadPart = (LONGLONG) 0;
1336 
1337  Fcb->Inode->i_size = 0;
1338 
1339  if (S_ISREG(Fcb->Inode->i_mode)) {
1340  KdPrint(("Reminder: Fcb->Inode->i_size_high = 0;\n"));
1341  //~Fcb->Inode->i_size_high = 0;
1342  }
1343 
1344  if (Disposition == FILE_SUPERSEDE)
1345  Fcb->Inode->i_ctime = RfsdInodeTime(CurrentTime);
1346 
1347  Fcb->Inode->i_atime =
1348  Fcb->Inode->i_mtime = RfsdInodeTime(CurrentTime);
1349  } else {
1350  LARGE_INTEGER iSize;
1351 
1352  iSize.QuadPart = (LONGLONG) Fcb->Inode->i_size;
1353 
1354  if (S_ISREG(Fcb->Inode->i_mode))
1355  KdPrint(("Reminder: Fcb->Inode->i_size_high = 0;\n"));
1356  //~ iSize.HighPart = (LONG)(Fcb->Inode->i_size_high);
1357 
1358  if (iSize.QuadPart > Fcb->Header.AllocationSize.QuadPart)
1359  iSize.QuadPart = Fcb->Header.AllocationSize.QuadPart;
1360 
1361  Fcb->Header.FileSize.QuadPart = iSize.QuadPart;
1362 
1363  Fcb->Inode->i_size = iSize.LowPart;
1364  //~ Fcb->Inode->i_size_high = (ULONG) iSize.HighPart;
1365  }
1366 
1367  RfsdSaveInode(IrpContext, Vcb, Fcb->RfsdMcb->Inode, Fcb->Inode);
1368 #endif // 0
1369  return Status;
1370 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
BOOLEAN NTAPI MmCanFileBeTruncated(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN PLARGE_INTEGER NewFileSize)
Definition: section.c:4091
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
Iosb Status
Definition: create.c:4287
if(OpenRequiringOplock &&(Iosb.Status==STATUS_SUCCESS))
Definition: create.c:4300
LONG NTSTATUS
Definition: precomp.h:26
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4137
#define STATUS_USER_MAPPED_FILE
Definition: ntstatus.h:711
PAGED_CODE()
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN RfsdSaveInode(IN PRFSD_IRP_CONTEXT IrpContext, IN PRFSD_VCB Vcb, IN ULONG inode, IN PRFSD_INODE Inode)
ULONG RfsdInodeTime(IN LARGE_INTEGER SysTime)
Definition: misc.c:59
ULONG LowPart
Definition: typedefs.h:106
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:319
NTSTATUS RfsdTruncateFile(PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb, PRFSD_FCB Fcb, PLARGE_INTEGER AllocationSize)
Definition: fileinfo.c:991
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
#define DbgBreak()
Definition: ext2fs.h:46
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define KdPrint(x)
Definition: env_spec_w32.h:288
#define S_ISREG(mode)
Definition: various.h:17
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by RfsdCreateFile().

Variable Documentation

◆ RfsdGlobal

PRFSD_GLOBAL RfsdGlobal

Definition at line 17 of file init.c.

Referenced by RfsdCreate().