branch update for HEAD-2003050101
[reactos.git] / drivers / fs / vfat / rw.c
index cd63a63..a28ca12 100644 (file)
@@ -290,7 +290,7 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
   *LengthRead = 0;
 
   Ccb = (PVFATCCB)IrpContext->FileObject->FsContext2;
-  Fcb = Ccb->pFcb;
+  Fcb = IrpContext->FileObject->FsContext;
   BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
   BytesPerCluster = DeviceExt->FatInfo.BytesPerCluster;
 
@@ -451,7 +451,7 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
    assert (IrpContext->FileObject->FsContext2 != NULL);
 
    Ccb = (PVFATCCB)IrpContext->FileObject->FsContext2;
-   Fcb = Ccb->pFcb;
+   Fcb = IrpContext->FileObject->FsContext;
    BytesPerCluster = DeviceExt->FatInfo.BytesPerCluster;
    BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
 
@@ -580,7 +580,6 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
 {
    NTSTATUS Status;
    PVFATFCB Fcb;
-   PVFATCCB Ccb;
    ULONG Length;
    ULONG ReturnedLength = 0;
    PERESOURCE Resource = NULL;
@@ -605,9 +604,7 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
 
    assert(IrpContext->DeviceExt);
    assert(IrpContext->FileObject);
-   Ccb = (PVFATCCB) IrpContext->FileObject->FsContext2;
-   assert(Ccb);
-   Fcb =  Ccb->pFcb;
+   Fcb = IrpContext->FileObject->FsContext;
    assert(Fcb);
 
    DPRINT("<%S>\n", Fcb->PathName);
@@ -672,6 +669,17 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
       Status = STATUS_PENDING;
       goto ByeBye;
    }
+
+   if (!(IrpContext->Irp->Flags & IRP_PAGING_IO) &&
+      FsRtlAreThereCurrentFileLocks(&Fcb->FileLock))
+   {
+      if (!FsRtlCheckLockForReadAccess(&Fcb->FileLock, IrpContext->Irp)) 
+      {
+         Status = STATUS_FILE_LOCK_CONFLICT;
+         goto ByeBye;
+      }
+   }
+
    if (!(IrpContext->Irp->Flags & (IRP_NOCACHE|IRP_PAGING_IO)) &&
      !(Fcb->Flags & (FCB_IS_PAGE_FILE|FCB_IS_VOLUME)))
    {
@@ -700,7 +708,7 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
          {
             CacheSize = PAGE_SIZE;
          }
-         CcRosInitializeFileCache(IrpContext->FileObject, &Fcb->RFCB.Bcb, CacheSize);
+         CcRosInitializeFileCache(IrpContext->FileObject, CacheSize);
       }
       if (!CcCopyRead(IrpContext->FileObject, &ByteOffset, Length,
                       IrpContext->Flags & IRPCONTEXT_CANWAIT, Buffer,
@@ -794,7 +802,6 @@ ByeBye:
 
 NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
 {
-   PVFATCCB Ccb;
    PVFATFCB Fcb;
    PERESOURCE Resource = NULL;
    LARGE_INTEGER ByteOffset;
@@ -821,9 +828,7 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
 
    assert(IrpContext->DeviceExt);
    assert(IrpContext->FileObject);
-   Ccb = (PVFATCCB) IrpContext->FileObject->FsContext2;
-   assert(Ccb);
-   Fcb =  Ccb->pFcb;
+   Fcb = IrpContext->FileObject->FsContext;
    assert(Fcb);
 
    DPRINT("<%S>\n", Fcb->PathName);
@@ -918,6 +923,16 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
       }
    }
 
+   if (!(IrpContext->Irp->Flags & IRP_PAGING_IO) &&
+      FsRtlAreThereCurrentFileLocks(&Fcb->FileLock))
+   {
+      if (!FsRtlCheckLockForWriteAccess(&Fcb->FileLock, IrpContext->Irp)) 
+      {
+         Status = STATUS_FILE_LOCK_CONFLICT;
+         goto ByeBye;
+       }
+    }
+
    if (!(IrpContext->Flags & IRPCONTEXT_CANWAIT) && !(Fcb->Flags & FCB_IS_VOLUME))
    {
       if (ByteOffset.u.LowPart + Length > Fcb->RFCB.AllocationSize.u.LowPart)
@@ -945,10 +960,6 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
       }
    }
 
-   if (ByteOffset.QuadPart > OldFileSize.QuadPart)
-   {
-      CcZeroData(IrpContext->FileObject, &OldFileSize, &ByteOffset, TRUE);
-   }
 
    if (!(IrpContext->Irp->Flags & (IRP_NOCACHE|IRP_PAGING_IO)) &&
       !(Fcb->Flags & (FCB_IS_PAGE_FILE|FCB_IS_VOLUME)))
@@ -971,7 +982,11 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
          {
             CacheSize = PAGE_SIZE;
          }
-         CcRosInitializeFileCache(IrpContext->FileObject, &Fcb->RFCB.Bcb, CacheSize);
+         CcRosInitializeFileCache(IrpContext->FileObject, CacheSize);
+      }
+      if (ByteOffset.QuadPart > OldFileSize.QuadPart)
+      {
+          CcZeroData(IrpContext->FileObject, &OldFileSize, &ByteOffset, TRUE);
       }
       if (CcCopyWrite(IrpContext->FileObject, &ByteOffset, Length,
                       1 /*IrpContext->Flags & IRPCONTEXT_CANWAIT*/, Buffer))
@@ -990,6 +1005,10 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
       // non cached write
       CHECKPOINT;
 
+      if (ByteOffset.QuadPart > OldFileSize.QuadPart)
+      {
+         CcZeroData(IrpContext->FileObject, &OldFileSize, &ByteOffset, TRUE);
+      }
       Buffer = VfatGetUserBuffer(IrpContext->Irp);
       if (!Buffer)
       {
@@ -1017,13 +1036,7 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
                                   &Fcb->entry.UpdateTime);
          Fcb->entry.AccessDate = Fcb->entry.UpdateDate;
          // update dates/times and length
-        if (OldAllocationSize != Fcb->RFCB.AllocationSize.u.LowPart)
-        {
-           VfatUpdateEntry (IrpContext->DeviceExt, IrpContext->FileObject);
-           Fcb->Flags &= ~FCB_UPDATE_DIRENTRY;
-        }
-        else
-           Fcb->Flags |= FCB_UPDATE_DIRENTRY;
+         VfatUpdateEntry (IrpContext->DeviceExt, IrpContext->FileObject);
       }
    }