ReactOS  0.4.14-dev-49-gfb4591c
write.c File Reference
#include "ntifs.h"
#include "ffsdrv.h"
Include dependency graph for write.c:

Go to the source code of this file.

Classes

struct  _FFS_FLPFLUSH_CONTEXT
 

Typedefs

typedef struct _FFS_FLPFLUSH_CONTEXT FFS_FLPFLUSH_CONTEXT
 
typedef struct _FFS_FLPFLUSH_CONTEXTPFFS_FLPFLUSH_CONTEXT
 

Functions

__drv_mustHoldCriticalRegion VOID FFSFloppyFlush (IN PVOID Parameter)
 
VOID FFSFloppyFlushDpc (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
NTSTATUS FFSWriteComplete (IN PFFS_IRP_CONTEXT IrpContext)
 
__drv_mustHoldCriticalRegion NTSTATUS FFSWriteFile (IN PFFS_IRP_CONTEXT IrpContext)
 
__drv_mustHoldCriticalRegion NTSTATUS FFSWriteVolume (IN PFFS_IRP_CONTEXT IrpContext)
 
VOID FFSDeferWrite (IN PFFS_IRP_CONTEXT, PIRP Irp)
 
VOID FFSStartFloppyFlushDpc (PFFS_VCB Vcb, PFFS_FCB Fcb, PFILE_OBJECT FileObject)
 
BOOLEAN FFSZeroHoles (IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFILE_OBJECT FileObject, IN LONGLONG Offset, IN LONGLONG Count)
 
__drv_mustHoldCriticalRegion NTSTATUS FFSv1WriteInode (IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFSv1_INODE dinode1, IN ULONGLONG offset, IN PVOID Buffer, IN ULONG size, IN BOOLEAN bWriteToDisk, OUT PULONG dwRet)
 
__drv_mustHoldCriticalRegion NTSTATUS FFSv2WriteInode (IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFSv2_INODE dinode2, IN ULONGLONG offset, IN PVOID Buffer, IN ULONG size, IN BOOLEAN bWriteToDisk, OUT PULONG dwRet)
 
__drv_mustHoldCriticalRegion NTSTATUS FFSWrite (IN PFFS_IRP_CONTEXT IrpContext)
 

Variables

PFFS_GLOBAL FFSGlobal
 

Typedef Documentation

◆ FFS_FLPFLUSH_CONTEXT

◆ PFFS_FLPFLUSH_CONTEXT

Function Documentation

◆ FFSDeferWrite()

VOID FFSDeferWrite ( IN PFFS_IRP_CONTEXT  IrpContext,
PIRP  Irp 
)

Definition at line 234 of file write.c.

237 {
238  ASSERT(IrpContext->Irp == Irp);
239 
240  FFSQueueRequest(IrpContext);
241 }
NTSTATUS FFSQueueRequest(IN PFFS_IRP_CONTEXT IrpContext)
Definition: dispatch.c:33
_In_ PIRP Irp
Definition: csq.h:116
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by FFSWriteFile(), and FFSWriteVolume().

◆ FFSFloppyFlush()

__drv_mustHoldCriticalRegion VOID FFSFloppyFlush ( IN PVOID  Parameter)

Definition at line 93 of file write.c.

95 {
98  PFFS_FCB Fcb;
99  PFFS_VCB Vcb;
100 
101  PAGED_CODE();
102 
104  FileObject = Context->FileObject;
105  Fcb = Context->Fcb;
106  Vcb = Context->Vcb;
107 
108  FFSPrint((DBG_USER, "FFSFloppyFlushing ...\n"));
109 
111 
112  if (Vcb)
113  {
114  ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
115  ExReleaseResourceLite(&Vcb->PagingIoResource);
116 
117  CcFlushCache(&(Vcb->SectionObject), NULL, 0, NULL);
118  }
119 
120  if (FileObject)
121  {
122  ASSERT(Fcb == (PFFS_FCB)FileObject->FsContext);
123 
126 
127  CcFlushCache(&(Fcb->SectionObject), NULL, 0, NULL);
128 
130  }
131 
133 
135 }
#define TRUE
Definition: types.h:120
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
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define PAGED_CODE()
Definition: video.h:57
struct _FFS_FLPFLUSH_CONTEXT * PFFS_FLPFLUSH_CONTEXT
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define DBG_USER
Definition: ffsdrv.h:1032
#define Vcb
Definition: cdprocs.h:1425
#define FSRTL_FSP_TOP_LEVEL_IRP
Definition: fsrtltypes.h:59
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1063
struct tagContext Context
Definition: acpixf.h:1024
ERESOURCE PagingIoResource
Definition: ntfs.h:523
ExFreePool(ed)
_In_ PFCB Fcb
Definition: cdprocs.h:151

Referenced by FFSFloppyFlushDpc().

◆ FFSFloppyFlushDpc()

VOID FFSFloppyFlushDpc ( IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 139 of file write.c.

144 {
146 
148 
149  FFSPrint((DBG_USER, "FFSFloppyFlushDpc is to be started...\n"));
150 
153  Context);
154 
156 }
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
__drv_mustHoldCriticalRegion VOID FFSFloppyFlush(IN PVOID Parameter)
Definition: write.c:93
struct _FFS_FLPFLUSH_CONTEXT * PFFS_FLPFLUSH_CONTEXT
#define DBG_USER
Definition: ffsdrv.h:1032
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
struct tagContext Context
Definition: acpixf.h:1024
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

Referenced by FFSStartFloppyFlushDpc().

◆ FFSStartFloppyFlushDpc()

VOID FFSStartFloppyFlushDpc ( PFFS_VCB  Vcb,
PFFS_FCB  Fcb,
PFILE_OBJECT  FileObject 
)

Definition at line 160 of file write.c.

164 {
165  LARGE_INTEGER OneSecond;
167 
168  PAGED_CODE();
169 
171 
173 
174  if (!Context)
175  {
176  FFSBreakPoint();
177  return;
178  }
179 
180  KeInitializeTimer(&Context->Timer);
181 
182  KeInitializeDpc(&Context->Dpc,
184  Context);
185 
186  Context->Vcb = Vcb;
187  Context->Fcb = Fcb;
188  Context->FileObject = FileObject;
189 
190  if (FileObject)
191  {
193  }
194 
195  OneSecond.QuadPart = (LONGLONG) - 1 * 1000 * 1000 * 10;
196  KeSetTimer(&Context->Timer,
197  OneSecond,
198  &Context->Dpc);
199 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
#define PAGED_CODE()
Definition: video.h:57
#define FFSBreakPoint()
Definition: ffsdrv.h:43
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
int64_t LONGLONG
Definition: typedefs.h:66
#define Vcb
Definition: cdprocs.h:1425
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FFS_POOL_TAG
Definition: ffsdrv.h:817
VOID FFSFloppyFlushDpc(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: write.c:139
#define VCB_FLOPPY_DISK
Definition: ext2fs.h:797
#define ObReferenceObject
Definition: obfuncs.h:204
struct tagContext Context
Definition: acpixf.h:1024
_In_ PFCB Fcb
Definition: cdprocs.h:151
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by FFSSaveBlock(), FFSSaveSuper(), FFSv1SaveInode(), FFSv1WriteInode(), and FFSWriteFile().

◆ FFSv1WriteInode()

__drv_mustHoldCriticalRegion NTSTATUS FFSv1WriteInode ( IN PFFS_IRP_CONTEXT  IrpContext,
IN PFFS_VCB  Vcb,
IN PFFSv1_INODE  dinode1,
IN ULONGLONG  offset,
IN PVOID  Buffer,
IN ULONG  size,
IN BOOLEAN  bWriteToDisk,
OUT PULONG  dwRet 
)

Definition at line 798 of file write.c.

807 {
808  PFFS_BDL ffs_bdl = NULL;
809  ULONG blocks, i;
811  ULONG Totalblocks;
812  LONGLONG AllocSize;
813 
814  PAGED_CODE();
815 
816  if (dwRet)
817  {
818  *dwRet = 0;
819  }
820 
821  Totalblocks = (dinode1->di_blocks);
822  AllocSize = ((LONGLONG)(FFSDataBlocks(Vcb, Totalblocks)) << BLOCK_BITS);
823 
824  if ((LONGLONG)offset >= AllocSize)
825  {
826  FFSPrint((DBG_ERROR, "FFSv1WriteInode: beyond the file range.\n"));
827  return STATUS_SUCCESS;
828  }
829 
830  if ((LONGLONG)offset + size > AllocSize)
831  {
832  size = (ULONG)(AllocSize - offset);
833  }
834 
835  blocks = FFSv1BuildBDL(IrpContext, Vcb, dinode1, offset, size, &ffs_bdl);
836 
837  if (blocks <= 0)
838  {
839  return STATUS_SUCCESS;
840  }
841 
842 #if DBG
843  {
844  ULONG dwTotal = 0;
845  FFSPrint((DBG_INFO, "FFSv1WriteInode: BDLCount = %xh Size=%xh Off=%xh\n",
846  blocks, size, offset));
847  for(i = 0; i < blocks; i++)
848  {
849  FFSPrint((DBG_INFO, "FFSv1WriteInode: Lba=%I64xh Len=%xh Off=%xh\n",
850  ffs_bdl[i].Lba, ffs_bdl[i].Length, ffs_bdl[i].Offset));
851  dwTotal += ffs_bdl[i].Length;
852  }
853 
854  if (dwTotal != size)
855  {
856  FFSBreakPoint();
857  }
858 
859  FFSPrint((DBG_INFO, "FFSv1WriteInode: Total = %xh (WriteToDisk=%x)\n",
860  dwTotal, bWriteToDisk));
861  }
862 #endif
863 
864  if (bWriteToDisk)
865  {
866 
867 #if 0
868  for(i = 0; i < blocks; i++)
869  {
870  {
871  CcFlushCache(&(Vcb->SectionObject),
872  (PLARGE_INTEGER)&(ffs_bdl[i].Lba),
873  ffs_bdl[i].Length,
874  NULL);
875 
876  if (Vcb->SectionObject.DataSectionObject != NULL)
877  {
878  ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
879  ExReleaseResourceLite(&Vcb->PagingIoResource);
880 
881  CcPurgeCacheSection(&(Vcb->SectionObject),
882  (PLARGE_INTEGER)&(ffs_bdl[i].Lba),
883  ffs_bdl[i].Length,
884  FALSE);
885  }
886  }
887  }
888 #endif
889 
890  // assume offset is aligned.
891  Status = FFSReadWriteBlocks(IrpContext, Vcb, ffs_bdl, size, blocks, FALSE);
892  }
893  else
894  {
895  for(i = 0; i < blocks; i++)
896  {
897  if(!FFSSaveBuffer(IrpContext, Vcb, ffs_bdl[i].Lba, ffs_bdl[i].Length, (PVOID)((PUCHAR)Buffer + ffs_bdl[i].Offset)))
898  goto errorout;
899  }
900 
901  if (IsFlagOn(Vcb->Flags, VCB_FLOPPY_DISK))
902  {
903  FFSPrint((DBG_USER, "FFSv1WriteInode is starting FlushingDpc...\n"));
905  }
906 
908  }
909 
910 errorout:
911 
912  if (ffs_bdl)
913  ExFreePool(ffs_bdl);
914 
915  if (NT_SUCCESS(Status))
916  {
917  if (dwRet) *dwRet = size;
918  }
919 
920  return Status;
921 }
VOID FFSStartFloppyFlushDpc(PFFS_VCB Vcb, PFFS_FCB Fcb, PFILE_OBJECT FileObject)
Definition: write.c:160
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
#define TRUE
Definition: types.h:120
NTSTATUS Status
Definition: write.c:2817
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
__drv_mustHoldCriticalRegion BOOLEAN FFSSaveBuffer(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN LONGLONG Offset, IN ULONG Size, IN PVOID Buf)
Definition: ffs.c:552
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
GLintptr offset
Definition: glext.h:5920
#define PAGED_CODE()
Definition: video.h:57
#define FFSBreakPoint()
Definition: ffsdrv.h:43
ed2 size
Definition: write.c:2844
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
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
ULONG FFSDataBlocks(PFFS_VCB Vcb, ULONG TotalBlocks)
Definition: ffs.c:2930
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
#define BLOCK_BITS
Definition: stream.h:22
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static int blocks
Definition: mkdosfs.c:527
int64_t LONGLONG
Definition: typedefs.h:66
#define DBG_USER
Definition: ffsdrv.h:1032
NTSTATUS FFSReadWriteBlocks(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFS_BDL FFSBDL, IN ULONG Length, IN ULONG Count, IN BOOLEAN bVerify)
Definition: block.c:207
GLsizeiptr size
Definition: glext.h:5919
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1425
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG FFSv1BuildBDL(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFSv1_INODE dinode1, IN ULONGLONG Offset, IN ULONG Size, OUT PFFS_BDL *ffs_bdl)
Definition: ffs.c:817
#define DBG_ERROR
Definition: ffsdrv.h:1031
Status
Definition: gdiplustypes.h:24
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
ULONG Length
Definition: ffsdrv.h:801
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1063
#define VCB_FLOPPY_DISK
Definition: ext2fs.h:797
unsigned int ULONG
Definition: retypes.h:1
#define DBG_INFO
Definition: ffsdrv.h:1034
ExFreePool(ed)
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by FFSAddEntry(), FFSRemoveEntry(), FFSSetParentEntry(), and FFSWriteFile().

◆ FFSv2WriteInode()

__drv_mustHoldCriticalRegion NTSTATUS FFSv2WriteInode ( IN PFFS_IRP_CONTEXT  IrpContext,
IN PFFS_VCB  Vcb,
IN PFFSv2_INODE  dinode2,
IN ULONGLONG  offset,
IN PVOID  Buffer,
IN ULONG  size,
IN BOOLEAN  bWriteToDisk,
OUT PULONG  dwRet 
)

Definition at line 926 of file write.c.

935 {
936  return STATUS_UNSUCCESSFUL;
937 }
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

◆ FFSWrite()

Definition at line 1487 of file write.c.

1489 {
1490  NTSTATUS Status;
1491  PFFS_FCBVCB FcbOrVcb;
1494  PFFS_VCB Vcb;
1495  BOOLEAN bCompleteRequest = TRUE;
1496 
1497  PAGED_CODE();
1498 
1499  ASSERT(IrpContext);
1500 
1501  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
1502  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
1503 
1504  _SEH2_TRY
1505  {
1506  if (FlagOn(IrpContext->MinorFunction, IRP_MN_COMPLETE))
1507  {
1508  Status = FFSWriteComplete(IrpContext);
1509  bCompleteRequest = FALSE;
1510  }
1511  else
1512  {
1513  DeviceObject = IrpContext->DeviceObject;
1514 
1516  {
1518  _SEH2_LEAVE;
1519  }
1520 
1522 
1523  if (Vcb->Identifier.Type != FFSVCB ||
1524  Vcb->Identifier.Size != sizeof(FFS_VCB))
1525  {
1527  _SEH2_LEAVE;
1528  }
1529 
1530  ASSERT(IsMounted(Vcb));
1531 
1532  if (IsFlagOn(Vcb->Flags, VCB_DISMOUNT_PENDING))
1533  {
1535  _SEH2_LEAVE;
1536  }
1537 
1538  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY))
1539  {
1541  _SEH2_LEAVE;
1542  }
1543 
1544  FileObject = IrpContext->FileObject;
1545 
1546  FcbOrVcb = (PFFS_FCBVCB)FileObject->FsContext;
1547 
1548  if (FcbOrVcb->Identifier.Type == FFSVCB)
1549  {
1550  Status = FFSWriteVolume(IrpContext);
1551 
1552  if (!NT_SUCCESS(Status))
1553  {
1554  FFSBreakPoint();
1555  }
1556 
1557  bCompleteRequest = FALSE;
1558  }
1559  else if (FcbOrVcb->Identifier.Type == FFSFCB)
1560  {
1561  Status = FFSWriteFile(IrpContext);
1562 
1563  if (!NT_SUCCESS(Status))
1564  {
1565  FFSBreakPoint();
1566  }
1567 
1568  bCompleteRequest = FALSE;
1569  }
1570  else
1571  {
1573  }
1574  }
1575  }
1576 
1578  {
1579  if (bCompleteRequest)
1580  {
1581  FFSCompleteIrpContext(IrpContext, Status);
1582  }
1583  } _SEH2_END;
1584 
1585  return Status;
1586 }
NTSTATUS FFSWriteComplete(IN PFFS_IRP_CONTEXT IrpContext)
Definition: write.c:1444
Definition: ffsdrv.h:281
#define IsMounted(Vcb)
Definition: ext2fs.h:803
#define TRUE
Definition: types.h:120
NTSTATUS Status
Definition: write.c:2817
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
__drv_mustHoldCriticalRegion NTSTATUS FFSWriteVolume(IN PFFS_IRP_CONTEXT IrpContext)
Definition: write.c:246
Definition: ffsdrv.h:283
__drv_mustHoldCriticalRegion NTSTATUS FFSWriteFile(IN PFFS_IRP_CONTEXT IrpContext)
Definition: write.c:942
PDEVICE_OBJECT DeviceObject
Definition: ffsdrv.h:371
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define FFSBreakPoint()
Definition: ffsdrv.h:43
#define IRP_MN_COMPLETE
Definition: iotypes.h:4064
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
struct _FFS_VCB * PFFS_VCB
FFS_IDENTIFIER_TYPE Type
Definition: ffsdrv.h:294
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
struct _FFS_FCBVCB * PFFS_FCBVCB
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1425
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
FFS_IDENTIFIER Identifier
Definition: ffsdrv.h:426
#define VCB_DISMOUNT_PENDING
Definition: ext2fs.h:782
Definition: ffsdrv.h:280
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define VCB_READ_ONLY
Definition: ext2fs.h:795
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
_SEH2_END
Definition: create.c:4424
_SEH2_FINALLY
Definition: create.c:4395
if(!find_data_address_in_chunk(Vcb, c, length, &address)) return false
PFFS_GLOBAL FFSGlobal
Definition: init.c:22
#define _SEH2_LEAVE
Definition: filesup.c:20
#define STATUS_TOO_LATE
Definition: ntstatus.h:612

Referenced by FFSDispatchRequest().

◆ FFSWriteComplete()

__drv_mustHoldCriticalRegion NTSTATUS FFSWriteComplete ( IN PFFS_IRP_CONTEXT  IrpContext)

Definition at line 1444 of file write.c.

1446 {
1449  PIRP Irp;
1451 
1452  PAGED_CODE();
1453 
1454  _SEH2_TRY
1455  {
1456  ASSERT(IrpContext);
1457 
1458  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
1459  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
1460 
1461  FileObject = IrpContext->FileObject;
1462 
1463  Irp = IrpContext->Irp;
1465 
1466  CcMdlWriteComplete(FileObject, &(IrpSp->Parameters.Write.ByteOffset), Irp->MdlAddress);
1467 
1468  Irp->MdlAddress = NULL;
1469 
1471  }
1472 
1474  {
1475  if (!IrpContext->ExceptionInProgress)
1476  {
1477  FFSCompleteIrpContext(IrpContext, Status);
1478  }
1479  } _SEH2_END;
1480 
1481  return Status;
1482 }
NTSTATUS Status
Definition: write.c:2817
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Definition: ffsdrv.h:283
VOID NTAPI CcMdlWriteComplete(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PMDL MdlChain)
Definition: mdlsup.c:102
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP Irp
Definition: write.c:2814
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_SEH2_END
Definition: create.c:4424
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_SEH2_FINALLY
Definition: create.c:4395
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by FFSWrite().

◆ FFSWriteFile()

Definition at line 942 of file write.c.

944 {
946 
947  PFFS_VCB Vcb;
948  PFFS_FCB Fcb;
949  PFFS_CCB Ccb;
951  PFILE_OBJECT CacheObject;
952 
954 
955  PIRP Irp;
956  PIO_STACK_LOCATION IoStackLocation;
957 
958  ULONG Length;
961 
962  BOOLEAN PagingIo;
963  BOOLEAN Nocache;
964  BOOLEAN SynchronousIo;
965  BOOLEAN MainResourceAcquired = FALSE;
966  BOOLEAN PagingIoResourceAcquired = FALSE;
967 
968  BOOLEAN bNeedExtending = FALSE;
969  BOOLEAN bAppendFile = FALSE;
970 
971  BOOLEAN bDeferred = FALSE;
972 
973  PUCHAR Buffer;
974 
975  PAGED_CODE();
976 
977  _SEH2_TRY
978  {
979  ASSERT(IrpContext);
980 
981  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
982  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
983 
984  DeviceObject = IrpContext->DeviceObject;
985 
987 
988  ASSERT(Vcb != NULL);
989 
990  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
991  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
992 
993  FileObject = IrpContext->FileObject;
994 
995  Fcb = (PFFS_FCB)FileObject->FsContext;
996 
997  ASSERT(Fcb);
998 
999  ASSERT((Fcb->Identifier.Type == FFSFCB) &&
1000  (Fcb->Identifier.Size == sizeof(FFS_FCB)));
1001 
1002  Ccb = (PFFS_CCB)FileObject->FsContext2;
1003 
1004  Irp = IrpContext->Irp;
1005 
1006  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
1007 
1008  Length = IoStackLocation->Parameters.Write.Length;
1009  ByteOffset = IoStackLocation->Parameters.Write.ByteOffset;
1010 
1011  PagingIo = (Irp->Flags & IRP_PAGING_IO ? TRUE : FALSE);
1012  Nocache = (Irp->Flags & IRP_NOCACHE ? TRUE : FALSE);
1013  SynchronousIo = (FileObject->Flags & FO_SYNCHRONOUS_IO ? TRUE : FALSE);
1014 
1015  FFSPrint((DBG_INFO, "FFSWriteFile: Off=%I64xh Len=%xh Paging=%xh Nocache=%xh\n",
1016  ByteOffset.QuadPart, Length, PagingIo, Nocache));
1017 
1018  /*
1019  if (IsFlagOn(Fcb->Flags, FCB_FILE_DELETED))
1020  {
1021  Status = STATUS_FILE_DELETED;
1022  _SEH2_LEAVE;
1023  }
1024 
1025  if (IsFlagOn(Fcb->Flags, FCB_DELETE_PENDING))
1026  {
1027  Status = STATUS_DELETE_PENDING;
1028  _SEH2_LEAVE;
1029  }
1030  */
1031 
1032  if (Length == 0)
1033  {
1034  Irp->IoStatus.Information = 0;
1036  _SEH2_LEAVE;
1037  }
1038 
1039  if (Nocache &&
1040  (ByteOffset.LowPart & (SECTOR_SIZE - 1) ||
1041  Length & (SECTOR_SIZE - 1)))
1042  {
1044  _SEH2_LEAVE;
1045  }
1046 
1047  if (FlagOn(IrpContext->MinorFunction, IRP_MN_DPC))
1048  {
1049  ClearFlag(IrpContext->MinorFunction, IRP_MN_DPC);
1051  _SEH2_LEAVE;
1052  }
1053 
1054 #if FALSE
1055  if (!Nocache)
1056  {
1057  BOOLEAN bAgain = IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_DEFERRED);
1058  BOOLEAN bWait = IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT);
1059  BOOLEAN bQueue = IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_REQUEUED);
1060 
1061  if (!CcCanIWrite(
1062  FileObject,
1063  Length,
1064  (bWait && bQueue),
1065  bAgain))
1066  {
1067  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_DEFERRED);
1068 
1071  IrpContext,
1072  Irp,
1073  Length,
1074  bAgain);
1075 
1076  bDeferred = TRUE;
1077 
1078  FFSBreakPoint();
1079 
1081  _SEH2_LEAVE;
1082  }
1083  }
1084 
1085 #endif
1086 
1087  if (IsEndOfFile(ByteOffset))
1088  {
1089  bAppendFile = TRUE;
1090  ByteOffset.QuadPart = Fcb->Header.FileSize.QuadPart;
1091  }
1092 
1093  if (FlagOn(Fcb->FFSMcb->FileAttr, FILE_ATTRIBUTE_DIRECTORY) && !PagingIo)
1094  {
1096  _SEH2_LEAVE;
1097  }
1098 
1099  //
1100  // Do flushing for such cases
1101  //
1102  if (Nocache && !PagingIo && (Fcb->SectionObject.DataSectionObject != NULL))
1103  {
1104 #pragma prefast( suppress: 28137, "by design" )
1106  IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT));
1107 
1108  MainResourceAcquired = TRUE;
1109 
1112 
1113  CcFlushCache(&(Fcb->SectionObject),
1114  &ByteOffset,
1115  Length,
1116  &(Irp->IoStatus));
1118 
1119  if (!NT_SUCCESS(Irp->IoStatus.Status))
1120  {
1121  Status = Irp->IoStatus.Status;
1122  _SEH2_LEAVE;
1123  }
1124 
1127 
1128  CcPurgeCacheSection(&(Fcb->SectionObject),
1130  Length,
1131  FALSE);
1132 
1134  MainResourceAcquired = FALSE;
1135  }
1136 
1137  if (!PagingIo)
1138  {
1139 #pragma prefast( suppress: 28137, "by design" )
1141  &Fcb->MainResource,
1142  IrpContext->IsSynchronous))
1143  {
1145  _SEH2_LEAVE;
1146  }
1147 
1148  MainResourceAcquired = TRUE;
1149  }
1150  else
1151  {
1152  /*
1153  ULONG ResShCnt, ResExCnt;
1154  ResShCnt = ExIsResourceAcquiredSharedLite(&Fcb->PagingIoResource);
1155  ResExCnt = ExIsResourceAcquiredExclusiveLite(&Fcb->PagingIoResource);
1156 
1157  FFSPrint((DBG_USER, "FFSWriteFile: Inode=%xh %S PagingIo: %xh:%xh Synchronous=%xh\n",
1158  Fcb->FFSMcb->Inode, Fcb->FFSMcb->ShortName.Buffer, ResShCnt, ResExCnt, IrpContext->IsSynchronous));
1159  */
1162  IrpContext->IsSynchronous))
1163  {
1165  _SEH2_LEAVE;
1166  }
1167 
1168  PagingIoResourceAcquired = TRUE;
1169  }
1170 
1171  if (!PagingIo)
1172  {
1174  &Fcb->FileLockAnchor,
1175  Irp))
1176  {
1178  _SEH2_LEAVE;
1179  }
1180  }
1181 
1182  if (Nocache)
1183  {
1184  if ((ByteOffset.QuadPart + Length) >
1185  Fcb->Header.AllocationSize.QuadPart)
1186  {
1187  if (ByteOffset.QuadPart >=
1188  Fcb->Header.AllocationSize.QuadPart)
1189  {
1191  Irp->IoStatus.Information = 0;
1192  _SEH2_LEAVE;
1193  }
1194  else
1195  {
1196  if (Length > (ULONG)(Fcb->Header.AllocationSize.QuadPart
1197  - ByteOffset.QuadPart))
1198  {
1199  Length = (ULONG)(Fcb->Header.AllocationSize.QuadPart
1200  - ByteOffset.QuadPart);
1201  }
1202  }
1203  }
1204  }
1205 
1206  if (!Nocache)
1207  {
1208  if (FlagOn(Fcb->FFSMcb->FileAttr, FILE_ATTRIBUTE_DIRECTORY))
1209  {
1210  _SEH2_LEAVE;
1211  }
1212 
1213  if (FileObject->PrivateCacheMap == NULL)
1214  {
1216  FileObject,
1217  (PCC_FILE_SIZES)(&Fcb->Header.AllocationSize),
1218  FALSE,
1220  Fcb);
1221 
1223  FileObject,
1225 
1227  FileObject,
1228  (PCC_FILE_SIZES)(&(Fcb->Header.AllocationSize)));
1229  }
1230 
1231  CacheObject = FileObject;
1232 
1233  //
1234  // Need extending the size of inode ?
1235  //
1236  if ((bAppendFile) || ((ULONG)(ByteOffset.QuadPart + Length) >
1237  (ULONG)(Fcb->Header.FileSize.QuadPart)))
1238  {
1239 
1240  LARGE_INTEGER ExtendSize;
1242 
1243  bNeedExtending = TRUE;
1244  FileSize = Fcb->Header.FileSize;
1245  ExtendSize.QuadPart = (LONGLONG)(ByteOffset.QuadPart + Length);
1246 
1247  if (ExtendSize.QuadPart > Fcb->Header.AllocationSize.QuadPart)
1248  {
1249  if (!FFSExpandFile(IrpContext, Vcb, Fcb, &ExtendSize))
1250  {
1252  _SEH2_LEAVE;
1253  }
1254  }
1255 
1256  {
1257  Fcb->Header.FileSize.QuadPart = ExtendSize.QuadPart;
1258  Fcb->dinode1->di_size = (ULONG)ExtendSize.QuadPart;
1259  }
1260 
1261  if (FileObject->PrivateCacheMap)
1262  {
1263  CcSetFileSizes(FileObject, (PCC_FILE_SIZES)(&(Fcb->Header.AllocationSize)));
1264 
1265  if (ByteOffset.QuadPart > FileSize.QuadPart)
1266  {
1267  FFSZeroHoles(IrpContext, Vcb, FileObject, FileSize.QuadPart,
1268  ByteOffset.QuadPart - FileSize.QuadPart);
1269  }
1270 
1271  if (Fcb->Header.AllocationSize.QuadPart > ExtendSize.QuadPart)
1272  {
1273  FFSZeroHoles(IrpContext, Vcb, FileObject, ExtendSize.QuadPart,
1274  Fcb->Header.AllocationSize.QuadPart - ExtendSize.QuadPart);
1275  }
1276  }
1277 
1278  if (FFSv1SaveInode(IrpContext, Vcb, Fcb->FFSMcb->Inode, Fcb->dinode1))
1279  {
1281  }
1282 
1284  IrpContext,
1285  Vcb,
1286  Fcb,
1289  }
1290 
1291  if (FlagOn(IrpContext->MinorFunction, IRP_MN_MDL))
1292  {
1294  CacheObject,
1295  (&ByteOffset),
1296  Length,
1297  &Irp->MdlAddress,
1298  &Irp->IoStatus);
1299 
1300  Status = Irp->IoStatus.Status;
1301  }
1302  else
1303  {
1305 
1306  if (Buffer == NULL)
1307  {
1308  FFSBreakPoint();
1310  _SEH2_LEAVE;
1311  }
1312 
1313  if (!CcCopyWrite(
1314  CacheObject,
1316  Length,
1317  IrpContext->IsSynchronous,
1318  Buffer))
1319  {
1321  _SEH2_LEAVE;
1322  }
1323 
1324  Status = Irp->IoStatus.Status;
1325  }
1326 
1327  if (NT_SUCCESS(Status))
1328  {
1329  Irp->IoStatus.Information = Length;
1330 
1331  if (IsFlagOn(Vcb->Flags, VCB_FLOPPY_DISK))
1332  {
1333  FFSPrint((DBG_USER, "FFSWriteFile is starting FlushingDpc...\n"));
1335  }
1336  }
1337  }
1338  else
1339  {
1341 
1343  IrpContext->Irp,
1344  Length,
1345  IoReadAccess);
1346 
1347  if (!NT_SUCCESS(Status))
1348  {
1349  _SEH2_LEAVE;
1350  }
1351 
1352  Irp->IoStatus.Status = STATUS_SUCCESS;
1353  Irp->IoStatus.Information = Length;
1354 
1355  Status =
1357  IrpContext,
1358  Vcb,
1359  Fcb->dinode1,
1360  (ULONGLONG)(ByteOffset.QuadPart),
1361  NULL,
1362  Length,
1363  TRUE,
1364  &ReturnedLength);
1365 
1366  Irp = IrpContext->Irp;
1367 
1368  }
1369  }
1370 
1372  {
1373  if (PagingIoResourceAcquired)
1374  {
1378  }
1379 
1380  if (MainResourceAcquired)
1381  {
1383  &Fcb->MainResource,
1385  }
1386 
1387  if (!IrpContext->ExceptionInProgress)
1388  {
1389  if (Irp)
1390  {
1391  if (Status == STATUS_PENDING)
1392  {
1393  if (!bDeferred)
1394  {
1396  IrpContext->Irp,
1397  Length,
1398  IoReadAccess);
1399 
1400  if (NT_SUCCESS(Status))
1401  {
1402  Status = FFSQueueRequest(IrpContext);
1403  }
1404  else
1405  {
1406  FFSCompleteIrpContext(IrpContext, Status);
1407  }
1408  }
1409  }
1410  else
1411  {
1412  if (NT_SUCCESS(Status))
1413  {
1414  if (SynchronousIo && !PagingIo)
1415  {
1416  FileObject->CurrentByteOffset.QuadPart =
1417  ByteOffset.QuadPart + Irp->IoStatus.Information;
1418  }
1419 
1420  if (!PagingIo)
1421  {
1424  }
1425  }
1426 
1427  FFSCompleteIrpContext(IrpContext, Status);
1428  }
1429  }
1430  else
1431  {
1432  FFSFreeIrpContext(IrpContext);
1433  }
1434  }
1435  } _SEH2_END;
1436 
1437  return Status;
1438 
1439 }
#define READ_AHEAD_GRANULARITY
Definition: btrfs_drv.h:118
VOID FFSStartFloppyFlushDpc(PFFS_VCB Vcb, PFFS_FCB Fcb, PFILE_OBJECT FileObject)
Definition: write.c:160
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
NTSTATUS FFSQueueRequest(IN PFFS_IRP_CONTEXT IrpContext)
Definition: dispatch.c:33
Definition: ffsdrv.h:281
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
#define TRUE
Definition: types.h:120
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS Status
Definition: write.c:2817
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:931
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN NTAPI FsRtlCheckLockForWriteAccess(IN PFILE_LOCK FileLock, IN PIRP Irp)
Definition: filelock.c:714
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_CONTEXT_FLAG_DEFERRED
Definition: ext2fs.h:1082
#define IRP_NOCACHE
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
__drv_mustHoldCriticalRegion VOID FFSFreeIrpContext(IN PFFS_IRP_CONTEXT IrpContext)
Definition: memory.c:179
#define FILE_NOTIFY_CHANGE_SIZE
Definition: ffsdrv.h:283
NTSTATUS FFSLockUserBuffer(IN PIRP Irp, IN ULONG Length, IN LOCK_OPERATION Operation)
Definition: block.c:70
BOOLEAN FFSExpandFile(PFFS_IRP_CONTEXT IrpContext, PFFS_VCB Vcb, PFFS_FCB Fcb, PLARGE_INTEGER AllocationSize)
Definition: fileinfo.c:1156
struct _FFS_FCB * PFFS_FCB
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define FFSBreakPoint()
Definition: ffsdrv.h:43
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FO_FILE_MODIFIED
Definition: iotypes.h:1745
NTFSIDENTIFIER Identifier
Definition: ntfs.h:511
VOID NTAPI CcPrepareMdlWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, OUT PMDL *MdlChain, OUT PIO_STATUS_BLOCK IoStatus)
Definition: mdlsup.c:91
VOID(NTAPI * PCC_POST_DEFERRED_WRITE)(_In_ PVOID Context1, _In_ PVOID Context2)
Definition: cctypes.h:66
BOOLEAN FFSZeroHoles(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFILE_OBJECT FileObject, IN LONGLONG Offset, IN LONGLONG Count)
Definition: write.c:203
__drv_mustHoldCriticalRegion BOOLEAN FFSv1SaveInode(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN ULONG Inode, IN PFFSv1_INODE dinode1)
Definition: ffs.c:407
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
#define FILE_ACTION_MODIFIED
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166
PVOID FFSGetUserBuffer(IN PIRP Irp)
Definition: block.c:115
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
struct _FFS_VCB * PFFS_VCB
__drv_mustHoldCriticalRegion NTSTATUS FFSv1WriteInode(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFSv1_INODE dinode1, IN ULONGLONG offset, IN PVOID Buffer, IN ULONG size, IN BOOLEAN bWriteToDisk, OUT PULONG dwRet)
Definition: write.c:798
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define IsEndOfFile(Pos)
Definition: ffsdrv.h:157
int64_t LONGLONG
Definition: typedefs.h:66
#define DBG_USER
Definition: ffsdrv.h:1032
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
BOOLEAN NTAPI CcCanIWrite(IN PFILE_OBJECT FileObject, IN ULONG BytesToWrite, IN BOOLEAN Wait, IN UCHAR Retrying)
Definition: copysup.c:214
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:193
uint64_t ULONGLONG
Definition: typedefs.h:65
#define Vcb
Definition: cdprocs.h:1425
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: ntfs.h:532
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP Irp
Definition: write.c:2814
ULONG Type
Definition: ntfs.h:95
#define IRP_MN_MDL
Definition: iotypes.h:4063
#define FCB_FILE_MODIFIED
Definition: ext2fs.h:873
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187
Definition: ffsdrv.h:280
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
ERESOURCE MainResource
Definition: ntfs.h:524
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Status
Definition: gdiplustypes.h:24
#define IRP_MN_DPC
Definition: iotypes.h:4062
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
BOOLEAN NTAPI CcCopyWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN PVOID Buffer)
Definition: copysup.c:129
struct _FFS_CCB * PFFS_CCB
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1063
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
#define VCB_FLOPPY_DISK
Definition: ext2fs.h:797
VOID FFSDeferWrite(IN PFFS_IRP_CONTEXT, PIRP Irp)
Definition: write.c:234
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:354
_SEH2_FINALLY
Definition: create.c:4395
#define IRP_CONTEXT_FLAG_REQUEUED
Definition: ext2fs.h:1085
#define IRP_PAGING_IO
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
VOID FFSNotifyReportChange(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFS_FCB Fcb, IN ULONG Filter, IN ULONG Action)
Definition: dirctl.c:1201
#define STATUS_FILE_LOCK_CONFLICT
Definition: ntstatus.h:306
unsigned int ULONG
Definition: retypes.h:1
ERESOURCE PagingIoResource
Definition: ntfs.h:523
PFFS_GLOBAL FFSGlobal
Definition: init.c:22
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define DBG_INFO
Definition: ffsdrv.h:1034
#define SECTOR_SIZE
Definition: fs.h:22
#define _SEH2_LEAVE
Definition: filesup.c:20
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
ULONG Size
Definition: ntfs.h:96
VOID NTAPI CcDeferWrite(IN PFILE_OBJECT FileObject, IN PCC_POST_DEFERRED_WRITE PostRoutine, IN PVOID Context1, IN PVOID Context2, IN ULONG BytesToWrite, IN BOOLEAN Retrying)
Definition: copysup.c:225
CACHE_MANAGER_CALLBACKS CacheManagerCallbacks
Definition: ffsdrv.h:364
LONGLONG QuadPart
Definition: typedefs.h:112
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716
VOID NTAPI CcSetReadAheadGranularity(IN PFILE_OBJECT FileObject, IN ULONG Granularity)
Definition: cachesub.c:36

Referenced by FFSWrite().

◆ FFSWriteVolume()

__drv_mustHoldCriticalRegion NTSTATUS FFSWriteVolume ( IN PFFS_IRP_CONTEXT  IrpContext)

Definition at line 246 of file write.c.

248 {
250 
251  PFFS_VCB Vcb;
252  PFFS_CCB Ccb;
253  PFFS_FCBVCB FcbOrVcb;
255 
257 
258  PIRP Irp;
259  PIO_STACK_LOCATION IoStackLocation;
260 
261  ULONG Length;
263 
264  BOOLEAN PagingIo;
265  BOOLEAN Nocache;
266  BOOLEAN SynchronousIo;
267  BOOLEAN MainResourceAcquired = FALSE;
268  BOOLEAN PagingIoResourceAcquired = FALSE;
269 
270  BOOLEAN bDeferred = FALSE;
271 
272  PUCHAR Buffer;
273 
274  PAGED_CODE();
275 
276  _SEH2_TRY
277  {
278  ASSERT(IrpContext);
279 
280  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
281  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
282 
283  DeviceObject = IrpContext->DeviceObject;
284 
286 
287  ASSERT(Vcb != NULL);
288 
289  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
290  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
291 
292  FileObject = IrpContext->FileObject;
293 
294  FcbOrVcb = (PFFS_FCBVCB)FileObject->FsContext;
295 
296  ASSERT(FcbOrVcb);
297 
298  if (!(FcbOrVcb->Identifier.Type == FFSVCB && (PVOID)FcbOrVcb == (PVOID)Vcb))
299  {
301  _SEH2_LEAVE;
302  }
303 
304  Ccb = (PFFS_CCB)FileObject->FsContext2;
305 
306  Irp = IrpContext->Irp;
307 
308  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
309 
310  Length = IoStackLocation->Parameters.Write.Length;
311  ByteOffset = IoStackLocation->Parameters.Write.ByteOffset;
312 
313  PagingIo = (Irp->Flags & IRP_PAGING_IO ? TRUE : FALSE);
314  Nocache = (Irp->Flags & IRP_NOCACHE ? TRUE : FALSE);
315  SynchronousIo = (FileObject->Flags & FO_SYNCHRONOUS_IO ? TRUE : FALSE);
316 
317  FFSPrint((DBG_INFO, "FFSWriteVolume: Off=%I64xh Len=%xh Paging=%xh Nocache=%xh\n",
318  ByteOffset.QuadPart, Length, PagingIo, Nocache));
319 
320  if (Length == 0)
321  {
322  Irp->IoStatus.Information = 0;
324  _SEH2_LEAVE;
325  }
326 
327  // For the case of "Direct Access Storage Device", we
328  // need flush/purge the cache
329 
330  if (Ccb != NULL)
331  {
332  ExAcquireResourceExclusiveLite(&Vcb->MainResource, TRUE);
333  MainResourceAcquired = TRUE;
334 
336 
337  ExReleaseResourceLite(&Vcb->MainResource);
338  MainResourceAcquired = FALSE;
339 
341  {
342  if (ByteOffset.QuadPart + Length > Vcb->Header.FileSize.QuadPart)
343  {
344  Length = (ULONG)(Vcb->Header.FileSize.QuadPart - ByteOffset.QuadPart);
345  }
346  }
347 
348  {
349  FFS_BDL BlockArray;
350 
351  if ((ByteOffset.LowPart & (SECTOR_SIZE - 1)) ||
352  (Length & (SECTOR_SIZE - 1)))
353  {
355  _SEH2_LEAVE;
356  }
357 
359  IrpContext->Irp,
360  Length,
361  IoReadAccess);
362 
363  if (!NT_SUCCESS(Status))
364  {
365  _SEH2_LEAVE;
366  }
367 
368  BlockArray.Irp = NULL;
369  BlockArray.Lba = ByteOffset.QuadPart;;
370  BlockArray.Offset = 0;
371  BlockArray.Length = Length;
372 
373  Status = FFSReadWriteBlocks(IrpContext,
374  Vcb,
375  &BlockArray,
376  Length,
377  1,
378  FALSE);
379  Irp = IrpContext->Irp;
380 
381  _SEH2_LEAVE;
382  }
383  }
384 
385  if (Nocache &&
386  (ByteOffset.LowPart & (SECTOR_SIZE - 1) ||
387  Length & (SECTOR_SIZE - 1)))
388  {
390  _SEH2_LEAVE;
391  }
392 
393  if (FlagOn(IrpContext->MinorFunction, IRP_MN_DPC))
394  {
395  ClearFlag(IrpContext->MinorFunction, IRP_MN_DPC);
397  _SEH2_LEAVE;
398  }
399 
400  if (ByteOffset.QuadPart >=
401  Vcb->PartitionInformation.PartitionLength.QuadPart)
402  {
403  Irp->IoStatus.Information = 0;
405  _SEH2_LEAVE;
406  }
407 
408 #if FALSE
409 
410  if (!Nocache)
411  {
412  BOOLEAN bAgain = IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_DEFERRED);
413  BOOLEAN bWait = IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT);
414  BOOLEAN bQueue = IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_REQUEUED);
415 
416  if (!CcCanIWrite(
417  FileObject,
418  Length,
419  (bWait && bQueue),
420  bAgain))
421  {
422  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_DEFERRED);
423 
426  IrpContext,
427  Irp,
428  Length,
429  bAgain);
430 
431  bDeferred = TRUE;
432 
433  FFSBreakPoint();
434 
436 
437  _SEH2_LEAVE;
438  }
439  }
440 
441 #endif
442 
443  if (Nocache && !PagingIo && (Vcb->SectionObject.DataSectionObject != NULL))
444  {
445  ExAcquireResourceExclusiveLite(&Vcb->MainResource, TRUE);
446  MainResourceAcquired = TRUE;
447 
448  ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
449  ExReleaseResourceLite(&Vcb->PagingIoResource);
450 
451  CcFlushCache(&(Vcb->SectionObject),
452  &ByteOffset,
453  Length,
454  &(Irp->IoStatus));
455 
456  if (!NT_SUCCESS(Irp->IoStatus.Status))
457  {
458  Status = Irp->IoStatus.Status;
459  _SEH2_LEAVE;
460  }
461 
462  ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
463  ExReleaseResourceLite(&Vcb->PagingIoResource);
464 
465  CcPurgeCacheSection(&(Vcb->SectionObject),
467  Length,
468  FALSE);
469 
470  ExReleaseResourceLite(&Vcb->MainResource);
471  MainResourceAcquired = FALSE;
472  }
473 
474  if (!PagingIo)
475  {
476 #pragma prefast( suppress: 28137, "by design" )
478  &Vcb->MainResource,
479  IrpContext->IsSynchronous))
480  {
482  _SEH2_LEAVE;
483  }
484 
485  MainResourceAcquired = TRUE;
486  }
487  else
488  {
489  /*
490  ULONG ResShCnt, ResExCnt;
491  ResShCnt = ExIsResourceAcquiredSharedLite(&Vcb->PagingIoResource);
492  ResExCnt = ExIsResourceAcquiredExclusiveLite(&Vcb->PagingIoResource);
493 
494  FFSPrint((DBG_USER, "PagingIoRes: %xh:%xh Synchronous=%xh\n", ResShCnt, ResExCnt, IrpContext->IsSynchronous));
495  */
496 
497  if (Ccb)
498  {
500  &Vcb->PagingIoResource,
501  IrpContext->IsSynchronous))
502  {
504  _SEH2_LEAVE;
505  }
506 
507  PagingIoResourceAcquired = TRUE;
508  }
509  }
510 
511  if (!Nocache)
512  {
513  if ((ByteOffset.QuadPart + Length) >
514  Vcb->PartitionInformation.PartitionLength.QuadPart
515  )
516  {
517  Length = (ULONG) (
518  Vcb->PartitionInformation.PartitionLength.QuadPart -
519  ByteOffset.QuadPart);
520 
521  Length &= ~((ULONG)SECTOR_SIZE - 1);
522  }
523 
524  if (FlagOn(IrpContext->MinorFunction, IRP_MN_MDL))
525  {
526 
528  Vcb->StreamObj,
529  &ByteOffset,
530  Length,
531  &Irp->MdlAddress,
532  &Irp->IoStatus);
533 
534  Status = Irp->IoStatus.Status;
535  }
536  else
537  {
539 
540  if (Buffer == NULL)
541  {
542  FFSBreakPoint();
543 
545  _SEH2_LEAVE;
546  }
547 
548  if (!CcCopyWrite(Vcb->StreamObj,
550  Length,
551  TRUE,
552  Buffer))
553  {
555  _SEH2_LEAVE;
556  }
557 
558  Status = Irp->IoStatus.Status;
560  }
561 
562  if (NT_SUCCESS(Status))
563  {
564  Irp->IoStatus.Information = Length;
565  }
566  }
567  else
568  {
569  PFFS_BDL ffs_bdl = NULL;
570  ULONG Blocks = 0;
571 
572  LONGLONG DirtyStart;
573  LONGLONG DirtyLba;
574  LONGLONG DirtyLength;
575  LONGLONG RemainLength;
576 
577  if ((ByteOffset.QuadPart + Length) >
578  Vcb->PartitionInformation.PartitionLength.QuadPart)
579  {
580  Length = (ULONG)(
581  Vcb->PartitionInformation.PartitionLength.QuadPart -
582  ByteOffset.QuadPart);
583 
584  Length &= ~((ULONG)SECTOR_SIZE - 1);
585  }
586 
588  IrpContext->Irp,
589  Length,
590  IoReadAccess);
591 
592  if (!NT_SUCCESS(Status))
593  {
594  _SEH2_LEAVE;
595  }
596 
597  ffs_bdl = ExAllocatePoolWithTag(PagedPool,
598  (Length / Vcb->BlockSize) *
599  sizeof(FFS_BDL), FFS_POOL_TAG);
600 
601  if (!ffs_bdl)
602  {
604  _SEH2_LEAVE;
605  }
606 
607  DirtyLba = ByteOffset.QuadPart;
608  RemainLength = (LONGLONG)Length;
609 
610  while (RemainLength > 0)
611  {
612  DirtyStart = DirtyLba;
613 
614  if (FFSLookupMcbEntry(Vcb,
615  DirtyStart,
616  &DirtyLba,
617  &DirtyLength,
618  (PLONGLONG)NULL,
619  (PLONGLONG)NULL,
620  (PULONG)NULL))
621  {
622 
623  if (DirtyLba == -1)
624  {
625  DirtyLba = DirtyStart + DirtyLength;
626 
627  RemainLength = ByteOffset.QuadPart +
628  (LONGLONG)Length -
629  DirtyLba;
630  continue;
631  }
632 
633  ffs_bdl[Blocks].Irp = NULL;
634  ffs_bdl[Blocks].Lba = DirtyLba;
635  ffs_bdl[Blocks].Offset = (ULONG)((LONGLONG)Length +
636  DirtyStart -
637  RemainLength -
638  DirtyLba);
639 
640  if (DirtyLba + DirtyLength > DirtyStart + RemainLength)
641  {
642  ffs_bdl[Blocks].Length = (ULONG)(DirtyStart +
643  RemainLength -
644  DirtyLba);
645  RemainLength = 0;
646  }
647  else
648  {
649  ffs_bdl[Blocks].Length = (ULONG)DirtyLength;
650  RemainLength = (DirtyStart + RemainLength) -
651  (DirtyLba + DirtyLength);
652  }
653 
654  DirtyLba = DirtyStart + DirtyLength;
655  Blocks++;
656  }
657  else
658  {
659  if (Blocks == 0)
660  {
661  if (ffs_bdl)
662  ExFreePool(ffs_bdl);
663 
664  //
665  // Lookup fails at the first time, ie.
666  // no dirty blocks in the run
667  //
668 
669  FFSBreakPoint();
670 
671  if (RemainLength == (LONGLONG)Length)
673  else
675 
676  _SEH2_LEAVE;
677  }
678  else
679  {
680  break;
681  }
682  }
683  }
684 
685  if (Blocks > 0)
686  {
687  Status = FFSReadWriteBlocks(IrpContext,
688  Vcb,
689  ffs_bdl,
690  Length,
691  Blocks,
692  FALSE);
693  Irp = IrpContext->Irp;
694 
695  if (NT_SUCCESS(Status))
696  {
697  ULONG i;
698 
699  for (i = 0; i < Blocks; i++)
700  {
702  ffs_bdl[i].Lba,
703  ffs_bdl[i].Length);
704  }
705  }
706 
707  if (ffs_bdl)
708  ExFreePool(ffs_bdl);
709 
710  if (!Irp)
711  _SEH2_LEAVE;
712 
713  }
714  else
715  {
716  if (ffs_bdl)
717  ExFreePool(ffs_bdl);
718 
719  Irp->IoStatus.Information = Length;
720 
722  _SEH2_LEAVE;
723  }
724  }
725  }
726 
728  {
729  if (PagingIoResourceAcquired)
730  {
732  &Vcb->PagingIoResource,
734  }
735 
736  if (MainResourceAcquired)
737  {
739  &Vcb->MainResource,
741  }
742 
743  if (!IrpContext->ExceptionInProgress)
744  {
745  if (Irp)
746  {
747  if (Status == STATUS_PENDING)
748  {
749  if(!bDeferred)
750  {
752  IrpContext->Irp,
753  Length,
754  IoReadAccess);
755 
756  if (NT_SUCCESS(Status))
757  {
758  Status = FFSQueueRequest(IrpContext);
759  }
760  else
761  {
762  FFSCompleteIrpContext(IrpContext, Status);
763  }
764  }
765  }
766  else
767  {
768  if (NT_SUCCESS(Status))
769  {
770  if (SynchronousIo && !PagingIo)
771  {
772  FileObject->CurrentByteOffset.QuadPart =
773  ByteOffset.QuadPart + Irp->IoStatus.Information;
774  }
775 
776  if (!PagingIo)
777  {
779  }
780  }
781 
782  FFSCompleteIrpContext(IrpContext, Status);
783  }
784  }
785  else
786  {
787  FFSFreeIrpContext(IrpContext);
788  }
789  }
790  } _SEH2_END;
791 
792  return Status;
793 }
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
NTSTATUS FFSQueueRequest(IN PFFS_IRP_CONTEXT IrpContext)
Definition: dispatch.c:33
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
#define TRUE
Definition: types.h:120
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS Status
Definition: write.c:2817
ULONG Offset
Definition: ffsdrv.h:800
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
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_CONTEXT_FLAG_DEFERRED
Definition: ext2fs.h:1082
#define IRP_NOCACHE
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
__drv_mustHoldCriticalRegion VOID FFSFreeIrpContext(IN PFFS_IRP_CONTEXT IrpContext)
Definition: memory.c:179
__drv_mustHoldCriticalRegion BOOLEAN FFSLookupMcbEntry(IN PFFS_VCB Vcb, IN LONGLONG Lba, OUT PLONGLONG pLba, OUT PLONGLONG pLength, OUT PLONGLONG RunStart, OUT PLONGLONG RunLength, OUT PULONG Index)
Definition: ffs.c:2860
Definition: ffsdrv.h:283
NTSTATUS FFSLockUserBuffer(IN PIRP Irp, IN ULONG Length, IN LOCK_OPERATION Operation)
Definition: block.c:70
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define FFSBreakPoint()
Definition: ffsdrv.h:43
#define STATUS_END_OF_FILE
Definition: shellext.h:62
__drv_mustHoldCriticalRegion BOOLEAN FFSAddMcbEntry(IN PFFS_VCB Vcb, IN LONGLONG Lba, IN LONGLONG Length)
Definition: ffs.c:2673
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:389
#define FO_FILE_MODIFIED
Definition: iotypes.h:1745
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
#define CCB_ALLOW_EXTENDED_DASD_IO
Definition: ext2fs.h:1028
VOID NTAPI CcPrepareMdlWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, OUT PMDL *MdlChain, OUT PIO_STATUS_BLOCK IoStatus)
Definition: mdlsup.c:91
VOID(NTAPI * PCC_POST_DEFERRED_WRITE)(_In_ PVOID Context1, _In_ PVOID Context2)
Definition: cctypes.h:66
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166
PVOID FFSGetUserBuffer(IN PIRP Irp)
Definition: block.c:115
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
struct _FFS_VCB * PFFS_VCB
FFS_IDENTIFIER_TYPE Type
Definition: ffsdrv.h:294
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
struct _FFS_FCBVCB * PFFS_FCBVCB
int64_t LONGLONG
Definition: typedefs.h:66
NTSTATUS FFSReadWriteBlocks(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFS_BDL FFSBDL, IN ULONG Length, IN ULONG Count, IN BOOLEAN bVerify)
Definition: block.c:207
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
BOOLEAN NTAPI CcCanIWrite(IN PFILE_OBJECT FileObject, IN ULONG BytesToWrite, IN BOOLEAN Wait, IN UCHAR Retrying)
Definition: copysup.c:214
#define Vcb
Definition: cdprocs.h:1425
LONGLONG Lba
Definition: ffsdrv.h:799
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: ntfs.h:532
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
FFS_IDENTIFIER Identifier
Definition: ffsdrv.h:426
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP Irp
Definition: write.c:2814
#define IRP_MN_MDL
Definition: iotypes.h:4063
Definition: ffsdrv.h:280
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
__drv_mustHoldCriticalRegion VOID FFSRemoveMcbEntry(IN PFFS_VCB Vcb, IN LONGLONG Lba, IN LONGLONG Length)
Definition: ffs.c:2790
#define FFS_POOL_TAG
Definition: ffsdrv.h:817
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Status
Definition: gdiplustypes.h:24
#define IRP_MN_DPC
Definition: iotypes.h:4062
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
BOOLEAN NTAPI CcCopyWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN PVOID Buffer)
Definition: copysup.c:129
ULONG Length
Definition: ffsdrv.h:801
struct _FFS_CCB * PFFS_CCB
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1063
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
VOID FFSDeferWrite(IN PFFS_IRP_CONTEXT, PIRP Irp)
Definition: write.c:234
_SEH2_FINALLY
Definition: create.c:4395
unsigned int * PULONG
Definition: retypes.h:1
#define IRP_CONTEXT_FLAG_REQUEUED
Definition: ext2fs.h:1085
#define IRP_PAGING_IO
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define DBG_INFO
Definition: ffsdrv.h:1034
#define SECTOR_SIZE
Definition: fs.h:22
ExFreePool(ed)
#define _SEH2_LEAVE
Definition: filesup.c:20
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
__drv_mustHoldCriticalRegion NTSTATUS FFSPurgeVolume(IN PFFS_VCB Vcb, IN BOOLEAN FlushBeforePurge)
Definition: fsctl.c:1445
return STATUS_SUCCESS
Definition: btrfs.c:2966
VOID NTAPI CcDeferWrite(IN PFILE_OBJECT FileObject, IN PCC_POST_DEFERRED_WRITE PostRoutine, IN PVOID Context1, IN PVOID Context2, IN ULONG BytesToWrite, IN BOOLEAN Retrying)
Definition: copysup.c:225
PIRP Irp
Definition: ffsdrv.h:802
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716

Referenced by FFSWrite().

◆ FFSZeroHoles()

BOOLEAN FFSZeroHoles ( IN PFFS_IRP_CONTEXT  IrpContext,
IN PFFS_VCB  Vcb,
IN PFILE_OBJECT  FileObject,
IN LONGLONG  Offset,
IN LONGLONG  Count 
)

Definition at line 203 of file write.c.

209 {
210  LARGE_INTEGER StartAddr = {0, 0};
211  LARGE_INTEGER EndAddr = {0, 0};
212 
213  PAGED_CODE();
214 
215  StartAddr.QuadPart = (Offset + (SECTOR_SIZE - 1)) &
216  ~((LONGLONG)SECTOR_SIZE - 1);
217 
218  EndAddr.QuadPart = (Offset + Count + (SECTOR_SIZE - 1)) &
219  ~((LONGLONG)SECTOR_SIZE - 1);
220 
221  if (StartAddr.QuadPart < EndAddr.QuadPart)
222  {
223  return CcZeroData(FileObject,
224  &StartAddr,
225  &EndAddr,
226  IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT));
227  }
228 
229  return TRUE;
230 }
#define TRUE
Definition: types.h:120
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define PAGED_CODE()
Definition: video.h:57
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
BOOLEAN NTAPI CcZeroData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER StartOffset, IN PLARGE_INTEGER EndOffset, IN BOOLEAN Wait)
Definition: fssup.c:412
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
int64_t LONGLONG
Definition: typedefs.h:66
#define SECTOR_SIZE
Definition: fs.h:22
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by FFSSetInformation(), and FFSWriteFile().

Variable Documentation

◆ FFSGlobal

PFFS_GLOBAL FFSGlobal

Definition at line 22 of file init.c.

Referenced by DriverEntry(), FFSQueryParameters(), FFSWrite(), and FFSWriteFile().