From 6865b783ccd4fbb8a0a8dadfb7ef7fb9b6cf8f28 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 12 Mar 2000 23:28:59 +0000 Subject: [PATCH] Fixed file creation date and time Implemented synchronization of all FATs (FAT16 only) Fixed bug in directory creation svn path=/trunk/; revision=1052 --- reactos/drivers/fs/vfat/dirwr.c | 77 +++++++++++++++++++++------------ reactos/drivers/fs/vfat/fat.c | 20 ++++++--- reactos/drivers/fs/vfat/rw.c | 53 +++++++++++++++-------- 3 files changed, 98 insertions(+), 52 deletions(-) diff --git a/reactos/drivers/fs/vfat/dirwr.c b/reactos/drivers/fs/vfat/dirwr.c index 19bd503783c..df1fef9f9f1 100644 --- a/reactos/drivers/fs/vfat/dirwr.c +++ b/reactos/drivers/fs/vfat/dirwr.c @@ -1,11 +1,11 @@ -/* $Id: dirwr.c,v 1.9 2000/03/01 23:41:35 ea Exp $ +/* $Id: dirwr.c,v 1.10 2000/03/12 23:28:59 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * FILE: services/fs/vfat/dirwr.c * PURPOSE: VFAT Filesystem : write in directory - -*/ + * + */ /* INCLUDES *****************************************************************/ @@ -72,28 +72,31 @@ DPRINT("open directory %S for update of entry %S\n",DirName,FileName); return status; } -NTSTATUS addEntry(PDEVICE_EXTENSION DeviceExt - ,PFILE_OBJECT pFileObject,ULONG RequestedOptions,UCHAR ReqAttr) +NTSTATUS addEntry(PDEVICE_EXTENSION DeviceExt, + PFILE_OBJECT pFileObject, + ULONG RequestedOptions, + UCHAR ReqAttr) /* create a new FAT entry */ { - WCHAR DirName[MAX_PATH],*FileName,*PathFileName; - VFATFCB DirFcb,FileFcb; - FATDirEntry FatEntry; - NTSTATUS status; - FILE_OBJECT FileObject; - FATDirEntry *pEntry; - slot *pSlots; - ULONG LengthRead,Offset; - short nbSlots=0,nbFree=0,i,j,posCar,NameLen; - PUCHAR Buffer,Buffer2; - BOOLEAN needTilde=FALSE,needLong=FALSE; - PVFATFCB newFCB; - PVFATCCB newCCB; - ULONG CurrentCluster; + WCHAR DirName[MAX_PATH],*FileName,*PathFileName; + VFATFCB DirFcb,FileFcb; + FATDirEntry FatEntry; + NTSTATUS status; + FILE_OBJECT FileObject; + FATDirEntry *pEntry; + slot *pSlots; + ULONG LengthRead,Offset; + short nbSlots=0,nbFree=0,i,j,posCar,NameLen; + PUCHAR Buffer,Buffer2; + BOOLEAN needTilde=FALSE,needLong=FALSE; + PVFATFCB newFCB; + PVFATCCB newCCB; + ULONG CurrentCluster; KIRQL oldIrql; - + LARGE_INTEGER SystemTime, LocalTime; + PathFileName=pFileObject->FileName.Buffer; DPRINT("addEntry: Pathname=%S\n",PathFileName); //find last \ in PathFileName @@ -226,13 +229,23 @@ DPRINT("i=%d,j=%d,%d,%d\n",i,j,pEntry->Filename[i],FileName[i]); DirName[NameLen]=0; } DPRINT("dos name=%11.11s\n",pEntry->Filename); - //FIXME : set attributes, dates, times - pEntry->Attrib=ReqAttr; + /* set attributes */ + pEntry->Attrib=ReqAttr; if(RequestedOptions&FILE_DIRECTORY_FILE) pEntry->Attrib |= FILE_ATTRIBUTE_DIRECTORY; - pEntry->CreationDate=0x21; - pEntry->UpdateDate=0x21; + + /* set dates and times */ + KeQuerySystemTime (&SystemTime); + ExSystemTimeToLocalTime (&SystemTime, + &LocalTime); + FsdFileTimeToDosDateTime ((TIME*)&LocalTime, + &pEntry->CreationDate, + &pEntry->CreationTime); + pEntry->UpdateDate = pEntry->CreationDate; + pEntry->UpdateTime = pEntry->CreationTime; + pEntry->AccessDate = pEntry->CreationDate; + // calculate checksum for 8.3 name for(pSlots[0].alias_checksum=i=0;i<11;i++) { @@ -258,6 +271,7 @@ DPRINT("i=%d,j=%d,%d,%d\n",i,j,pEntry->Filename[i],FileName[i]); memcpy(pSlots[i].name11_12,FileName+(nbSlots-i-2)*13+11 ,2*sizeof(WCHAR)); } + //try to find nbSlots contiguous entries frees in directory for(i=0,status=STATUS_SUCCESS;status==STATUS_SUCCESS;i++) { @@ -265,11 +279,17 @@ DPRINT("i=%d,j=%d,%d,%d\n",i,j,pEntry->Filename[i],FileName[i]); ,sizeof(FATDirEntry),i*sizeof(FATDirEntry),&LengthRead); if(IsLastEntry(&FatEntry,0)) break; - if(IsDeletedEntry(&FatEntry,0)) nbFree++; - else nbFree=0; - if (nbFree==nbSlots) break; + + if(IsDeletedEntry(&FatEntry,0)) + nbFree++; + else + nbFree=0; + + if (nbFree==nbSlots) + break; } - DPRINT("NbFree %d, entry number %d\n",nbFree,i); + DPRINT("nbSlots %d nbFree %d, entry number %d\n",nbSlots,nbFree,i); + if(RequestedOptions&FILE_DIRECTORY_FILE) { CurrentCluster=GetNextWriteCluster(DeviceExt,0); @@ -345,3 +365,4 @@ DPRINT("addentry ok\n"); return STATUS_SUCCESS; } +/* EOF */ diff --git a/reactos/drivers/fs/vfat/fat.c b/reactos/drivers/fs/vfat/fat.c index bf71f0fdbc5..395c2d7b89e 100644 --- a/reactos/drivers/fs/vfat/fat.c +++ b/reactos/drivers/fs/vfat/fat.c @@ -1,5 +1,5 @@ /* - * $Id: fat.c,v 1.3 2000/02/22 02:02:08 ekohl Exp $ + * $Id: fat.c,v 1.4 2000/03/12 23:28:59 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -339,6 +339,8 @@ void FAT16WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, { ULONG FATsector; PUSHORT Block; + ULONG Start; + int i; DbgPrint("FAT16WriteCluster %u : %u\n", ClusterToWrite, NewValue); @@ -347,11 +349,17 @@ void FAT16WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, /* Update the in-memory FAT */ Block[ClusterToWrite] = NewValue; - /* Write the changed FAT sector to disk */ - VFATWriteSectors(DeviceExt->StorageDevice, - DeviceExt->FATStart+FATsector, - 1, - (UCHAR *)Block); + + /* Write the changed FAT sector to disk (all FAT's) */ + Start = DeviceExt->FATStart + FATsector; + for (i = 0; i < DeviceExt->Boot->FATCount; i++) + { + VFATWriteSectors(DeviceExt->StorageDevice, + Start, + 1, + (UCHAR *)Block); + Start += DeviceExt->Boot->FATSectors; + } } void FAT32WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, diff --git a/reactos/drivers/fs/vfat/rw.c b/reactos/drivers/fs/vfat/rw.c index 3bd85cc1fc1..89b2836e6aa 100644 --- a/reactos/drivers/fs/vfat/rw.c +++ b/reactos/drivers/fs/vfat/rw.c @@ -1,4 +1,4 @@ -/* $Id: rw.c,v 1.3 2000/02/22 02:02:08 ekohl Exp $ +/* $Id: rw.c,v 1.4 2000/03/12 23:28:59 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -54,12 +54,7 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, CurrentCluster = Fcb->entry.FirstCluster; FirstCluster=CurrentCluster; DPRINT("DeviceExt->BytesPerCluster %x\n",DeviceExt->BytesPerCluster); - - if (Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY) - { - return(STATUS_FILE_IS_A_DIRECTORY); - } - + if (ReadOffset >= Fcb->entry.FileSize && !(Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY)) { @@ -167,6 +162,7 @@ NTSTATUS FsdWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, PVFATCCB pCcb; PVOID Temp; ULONG TempLength,Length2=Length; + LARGE_INTEGER SystemTime, LocalTime; DPRINT1("FsdWriteFile(FileObject %x, Buffer %x, Length %x, " "WriteOffset %x\n", FileObject, Buffer, Length, WriteOffset); @@ -243,7 +239,7 @@ NTSTATUS FsdWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, CurrentCluster, DeviceExt->Boot->SectorsPerCluster, Temp); - } + } else { VFATLoadCluster(DeviceExt,Temp,CurrentCluster); @@ -338,13 +334,20 @@ NTSTATUS FsdWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, VFATWriteCluster(DeviceExt,Temp,CurrentCluster); } } - CHECKPOINT; + CHECKPOINT; } - /* - * FIXME : set last write time and date - */ - if (Fcb->entry.FileSize < WriteOffset+Length + + /* set dates and times */ + KeQuerySystemTime (&SystemTime); + ExSystemTimeToLocalTime (&SystemTime, + &LocalTime); + FsdFileTimeToDosDateTime ((TIME*)&LocalTime, + &Fcb->entry.UpdateDate, + &Fcb->entry.UpdateTime); + Fcb->entry.AccessDate = Fcb->entry.UpdateDate; + + if (Fcb->entry.FileSize < WriteOffset+Length && !(Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY)) { Fcb->entry.FileSize = WriteOffset+Length; @@ -399,7 +402,8 @@ NTSTATUS FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp) PDEVICE_EXTENSION DeviceExt; NTSTATUS Status; ULONG LengthRead; - + PVFATFCB Fcb; + DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp); /* Precondition / Initialization */ @@ -414,10 +418,23 @@ NTSTATUS FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp) Length = Stack->Parameters.Read.Length; Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress); Offset = Stack->Parameters.Read.ByteOffset.u.LowPart; - - Status = FsdReadFile(DeviceExt,FileObject,Buffer,Length,Offset, - &LengthRead); - + + /* fail if file is a directory */ + Fcb = ((PVFATCCB)(FileObject->FsContext2))->pFcb; + if (Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY) + { + Status = STATUS_FILE_IS_A_DIRECTORY; + } + else + { + Status = FsdReadFile(DeviceExt, + FileObject, + Buffer, + Length, + Offset, + &LengthRead); + } + Irp->IoStatus.Status = Status; Irp->IoStatus.Information = LengthRead; IoCompleteRequest(Irp,IO_NO_INCREMENT);