Author: pschweitzer Date: Wed Aug 3 12:54:46 2016 New Revision: 72096
URL: http://svn.reactos.org/svn/reactos?rev=72096&view=rev Log: [FASTFAT] Fixes suggested by Thomas: - Don't dereference cached data after unpinning - Pin big enough data to read direntries
CORE-11377
Modified: trunk/reactos/drivers/filesystems/fastfat/dirwr.c
Modified: trunk/reactos/drivers/filesystems/fastfat/dirwr.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fastfat... ============================================================================== --- trunk/reactos/drivers/filesystems/fastfat/dirwr.c [iso-8859-1] (original) +++ trunk/reactos/drivers/filesystems/fastfat/dirwr.c [iso-8859-1] Wed Aug 3 12:54:46 2016 @@ -100,7 +100,7 @@ Offset.u.LowPart = (StartIndex * sizeof(FATX_DIR_ENTRY) / PAGE_SIZE) * PAGE_SIZE; _SEH2_TRY { - CcPinRead(pFcb->parentFcb->FileObject, &Offset, sizeof(FATX_DIR_ENTRY), PIN_WAIT, &Context, (PVOID*)&pDirEntry); + CcPinRead(pFcb->parentFcb->FileObject, &Offset, PAGE_SIZE, PIN_WAIT, &Context, (PVOID*)&pDirEntry); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -118,15 +118,16 @@ RtlUnicodeStringToOemString(&NameA, FileName, FALSE); pDirEntry->FilenameLength = (unsigned char)NameA.Length;
- CcSetDirtyPinnedData(Context, NULL); - CcUnpinData(Context); - /* Update FCB */ DirContext.ShortNameU.Length = 0; DirContext.ShortNameU.MaximumLength = 0; DirContext.ShortNameU.Buffer = NULL; DirContext.LongNameU = *FileName; DirContext.DirEntry.FatX = *pDirEntry; + + CcSetDirtyPinnedData(Context, NULL); + CcUnpinData(Context); + Status = vfatUpdateFCB(DeviceExt, pFcb, &DirContext, pFcb->parentFcb); if (NT_SUCCESS(Status)) { @@ -862,7 +863,7 @@ Offset.u.LowPart = (i * sizeof(FAT_DIR_ENTRY) / PAGE_SIZE) * PAGE_SIZE; _SEH2_TRY { - CcPinRead(pFcb->parentFcb->FileObject, &Offset, sizeof(FAT_DIR_ENTRY), PIN_WAIT, &Context, (PVOID*)&pDirEntry); + CcPinRead(pFcb->parentFcb->FileObject, &Offset, PAGE_SIZE, PIN_WAIT, &Context, (PVOID*)&pDirEntry); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -878,13 +879,8 @@ (PDIR_ENTRY)&pDirEntry[i % (PAGE_SIZE / sizeof(FAT_DIR_ENTRY))]); } } - if (Context) - { - CcSetDirtyPinnedData(Context, NULL); - CcUnpinData(Context); - } - - /* In case of moving, don't delete data */ + + /* In case of moving, save properties */ if (MoveContext != NULL) { pDirEntry = &pDirEntry[pFcb->dirIndex % (PAGE_SIZE / sizeof(FAT_DIR_ENTRY))]; @@ -893,7 +889,15 @@ MoveContext->CreationTime = pDirEntry->CreationTime; MoveContext->CreationDate = pDirEntry->CreationDate; } - else + + if (Context) + { + CcSetDirtyPinnedData(Context, NULL); + CcUnpinData(Context); + } + + /* In case of moving, don't delete data */ + if (MoveContext == NULL) { while (CurrentCluster && CurrentCluster != 0xffffffff) { @@ -934,7 +938,7 @@ Offset.u.LowPart = (StartIndex * sizeof(FATX_DIR_ENTRY) / PAGE_SIZE) * PAGE_SIZE; _SEH2_TRY { - CcPinRead(pFcb->parentFcb->FileObject, &Offset, sizeof(FATX_DIR_ENTRY), PIN_WAIT, &Context, (PVOID*)&pDirEntry); + CcPinRead(pFcb->parentFcb->FileObject, &Offset, PAGE_SIZE, PIN_WAIT, &Context, (PVOID*)&pDirEntry); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -946,10 +950,8 @@ pDirEntry->FilenameLength = 0xe5; CurrentCluster = vfatDirEntryGetFirstCluster(DeviceExt, (PDIR_ENTRY)pDirEntry); - CcSetDirtyPinnedData(Context, NULL); - CcUnpinData(Context); - - /* In case of moving, don't delete data */ + + /* In case of moving, save properties */ if (MoveContext != NULL) { MoveContext->FirstCluster = CurrentCluster; @@ -957,7 +959,12 @@ MoveContext->CreationTime = pDirEntry->CreationTime; MoveContext->CreationDate = pDirEntry->CreationDate; } - else + + CcSetDirtyPinnedData(Context, NULL); + CcUnpinData(Context); + + /* In case of moving, don't delete data */ + if (MoveContext == NULL) { while (CurrentCluster && CurrentCluster != 0xffffffff) {