diff --git a/reactos/drivers/fs/vfat/create.c b/reactos/drivers/fs/vfat/create.c index 02f1885ba70..fd08de707c1 100644 --- a/reactos/drivers/fs/vfat/create.c +++ b/reactos/drivers/fs/vfat/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.16 2001/02/14 02:53:54 dwelch Exp $ +/* $Id: create.c,v 1.17 2001/03/02 15:59:16 cnettel Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -93,7 +93,8 @@ GetEntryName (PVOID Block, PULONG _Offset, PWSTR Name, PULONG _jloop, if (Offset == ENTRIES_PER_SECTOR) { Offset = 0; - StartingSector++; //FIXME : nor always the next sector + /* FIXME: Check status */ + GetNextSector (DeviceExt, StartingSector, &StartingSector, FALSE); jloop++; /* FIXME: Check status */ VfatReadSectors (DeviceExt->StorageDevice, @@ -186,8 +187,9 @@ ReadVolumeLabel (PDEVICE_EXTENSION DeviceExt, PVPB Vpb) /* not found in this sector, try next : */ /* directory can be fragmented although it is best to keep them - unfragmented */ + unfragmented.*/ StartingSector++; + if (DeviceExt->FatType == FAT32) { if (StartingSector == ClusterToSector (DeviceExt, NextCluster + 1)) @@ -313,9 +315,9 @@ FindFile (PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb, i++; if (i == (ENTRIES_PER_SECTOR)) { - /* entry is in next sector */ - StartingSector++; - /* FIXME : treat case of next sector fragmented */ + /* FIXME: Check status */ + GetNextSector (DeviceExt, StartingSector, &StartingSector, FALSE); + /* FIXME: Check status */ VfatReadSectors (DeviceExt->StorageDevice, StartingSector, 1, block); @@ -336,7 +338,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb, /* not found in this sector, try next : */ /* directory can be fragmented although it is best to keep them - unfragmented */ + unfragmented. Should we change this to also use GetNextSector? + GetNextSector was originally implemented to handle the case above */ if (Entry) *Entry = 0; StartingSector++; diff --git a/reactos/drivers/fs/vfat/fat.c b/reactos/drivers/fs/vfat/fat.c index 1f5fdf67471..436962a4b33 100644 --- a/reactos/drivers/fs/vfat/fat.c +++ b/reactos/drivers/fs/vfat/fat.c @@ -1,5 +1,5 @@ /* - * $Id: fat.c,v 1.19 2001/03/01 07:48:17 dwelch Exp $ + * $Id: fat.c,v 1.20 2001/03/02 15:59:16 cnettel Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -786,6 +786,7 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt, { NTSTATUS Status; + // DPRINT ("GetNextCluster(DeviceExt %x, CurrentCluster %x)\n", // DeviceExt, CurrentCluster); @@ -897,3 +898,39 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt, return (Status); } +NTSTATUS +GetNextSector (PDEVICE_EXTENSION DeviceExt, + ULONG CurrentSector, + PULONG NextSector, + BOOLEAN Extend) +/* Some functions don't have access to the cluster they're really reading from. + Maybe this is a dirty solution, but it will allow them to handle fragmentation. */ +{ + NTSTATUS Status; + + DPRINT ("GetNextSector(DeviceExt %x, CurrentSector %x)\n",DeviceExt, CurrentSector); + if (CurrentSectordataStart || ((CurrentSector - DeviceExt->dataStart + 1) % DeviceExt -> Boot -> SectorsPerCluster)) + /* Basically, if the next sequential sector would be on a cluster border, then we'll need to check in the FAT */ + { + (*NextSector)=CurrentSector+1; + return (STATUS_SUCCESS); + } + else + { + CurrentSector = (CurrentSector - DeviceExt->dataStart) / DeviceExt -> Boot -> SectorsPerCluster + 2; + + Status = GetNextCluster(DeviceExt, CurrentSector, NextSector, Extend); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + if ((*NextSector) == 0 || (*NextSector) == 0xffffffff) + { + /* The caller wants to know a sector. These FAT codes don't correspond to any sector. */ + return (STATUS_UNSUCCESSFUL); + } + + (*NextSector)=ClusterToSector(DeviceExt,(*NextSector)); + return (STATUS_SUCCESS); + } +} \ No newline at end of file diff --git a/reactos/drivers/fs/vfat/rw.c b/reactos/drivers/fs/vfat/rw.c index bb33a38f645..59a0d906399 100644 --- a/reactos/drivers/fs/vfat/rw.c +++ b/reactos/drivers/fs/vfat/rw.c @@ -1,5 +1,5 @@ -/* $Id: rw.c,v 1.20 2001/01/16 15:43:42 dwelch Exp $ +/* $Id: rw.c,v 1.21 2001/03/02 15:59:16 cnettel Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -42,6 +42,16 @@ NextCluster(PDEVICE_EXTENSION DeviceExt, (*CurrentCluster) += DeviceExt->Boot->SectorsPerCluster; return(STATUS_SUCCESS); } + else + /* CN: FIXME: Real bug here or in dirwr, where CurrentCluster isn't initialized when 0*/ + if (FirstCluster == 0) + { + NTSTATUS Status; + + Status = GetNextCluster(DeviceExt, 0, CurrentCluster, + Extend); + return(Status); + } else { NTSTATUS Status; diff --git a/reactos/drivers/fs/vfat/vfat.h b/reactos/drivers/fs/vfat/vfat.h index fa1bf78d2de..51bf24d7a43 100644 --- a/reactos/drivers/fs/vfat/vfat.h +++ b/reactos/drivers/fs/vfat/vfat.h @@ -1,4 +1,4 @@ -/* $Id: vfat.h,v 1.25 2001/02/10 22:51:11 dwelch Exp $ */ +/* $Id: vfat.h,v 1.26 2001/03/02 15:59:16 cnettel Exp $ */ #include @@ -251,6 +251,11 @@ GetNextCluster(PDEVICE_EXTENSION DeviceExt, PULONG NextCluster, BOOLEAN Extend); NTSTATUS +GetNextSector (PDEVICE_EXTENSION DeviceExt, + ULONG CurrentSector, + PULONG NextSector, + BOOLEAN Extend); +NTSTATUS VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PVOID Buffer,