X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=drivers%2Ffs%2Fvfat%2Ffat.c;h=7b57bf889092071f5355654b4ba4aa8b2eb25e7f;hb=HEAD;hp=499f1a3d09a88c2ae0dfd9a59183421f8fb7cd6b;hpb=1334f77b1ecef00ac31076ce6bf22bdfeb82d347;p=reactos.git diff --git a/drivers/fs/vfat/fat.c b/drivers/fs/vfat/fat.c index 499f1a3..7b57bf8 100644 --- a/drivers/fs/vfat/fat.c +++ b/drivers/fs/vfat/fat.c @@ -39,7 +39,6 @@ Fat32GetNextCluster(PDEVICE_EXTENSION DeviceExt, */ { PVOID BaseAddress; - NTSTATUS Status; ULONG FATOffset; ULONG ChunkSize; PVOID Context; @@ -52,7 +51,7 @@ Fat32GetNextCluster(PDEVICE_EXTENSION DeviceExt, { return STATUS_UNSUCCESSFUL; } - CurrentCluster = (*(PULONG)(BaseAddress + (FATOffset % ChunkSize))) & 0x0fffffff; + CurrentCluster = (*(PULONG)((char*)BaseAddress + (FATOffset % ChunkSize))) & 0x0fffffff; if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff) CurrentCluster = 0xffffffff; CcUnpinData(Context); @@ -69,7 +68,6 @@ Fat16GetNextCluster(PDEVICE_EXTENSION DeviceExt, */ { PVOID BaseAddress; - NTSTATUS Status; ULONG FATOffset; ULONG ChunkSize; PVOID Context; @@ -82,7 +80,7 @@ Fat16GetNextCluster(PDEVICE_EXTENSION DeviceExt, { return STATUS_UNSUCCESSFUL; } - CurrentCluster = *((PUSHORT)(BaseAddress + (FATOffset % ChunkSize))); + CurrentCluster = *((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize))); if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff) CurrentCluster = 0xffffffff; CcUnpinData(Context); @@ -99,9 +97,7 @@ Fat12GetNextCluster(PDEVICE_EXTENSION DeviceExt, */ { PUSHORT CBlock; - ULONG FATOffset; ULONG Entry; - NTSTATUS Status; PVOID BaseAddress; PVOID Context; LARGE_INTEGER Offset; @@ -114,7 +110,7 @@ Fat12GetNextCluster(PDEVICE_EXTENSION DeviceExt, { return STATUS_UNSUCCESSFUL; } - CBlock = (PUSHORT)(BaseAddress + (CurrentCluster * 12) / 8); + CBlock = (PUSHORT)((char*)BaseAddress + (CurrentCluster * 12) / 8); if ((CurrentCluster % 2) == 0) { Entry = *CBlock & 0x0fff; @@ -143,7 +139,6 @@ FAT16FindAvailableCluster(PDEVICE_EXTENSION DeviceExt, ULONG FatLength; ULONG StartCluster; ULONG i, j; - NTSTATUS Status; PVOID BaseAddress; ULONG ChunkSize; PVOID Context = 0; @@ -173,7 +168,7 @@ FAT16FindAvailableCluster(PDEVICE_EXTENSION DeviceExt, return STATUS_UNSUCCESSFUL; } CHECKPOINT; - Block = (PUSHORT)(BaseAddress + i % ChunkSize); + Block = (PUSHORT)((char*)BaseAddress + i % ChunkSize); } if (*Block == 0) @@ -202,13 +197,11 @@ FAT12FindAvailableCluster(PDEVICE_EXTENSION DeviceExt, PULONG Cluster) */ { ULONG FatLength; - ULONG FATOffset; ULONG StartCluster; ULONG Entry; PUSHORT CBlock; ULONG i, j; PVOID BaseAddress; - NTSTATUS Status; PVOID Context; LARGE_INTEGER Offset; @@ -226,7 +219,7 @@ FAT12FindAvailableCluster(PDEVICE_EXTENSION DeviceExt, PULONG Cluster) { for (i = StartCluster; i < FatLength; i++) { - CBlock = (PUSHORT)(BaseAddress + (i * 12) / 8); + CBlock = (PUSHORT)((char*)BaseAddress + (i * 12) / 8); if ((i % 2) == 0) { Entry = *CBlock & 0xfff; @@ -259,7 +252,6 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster) ULONG FatLength; ULONG StartCluster; ULONG i, j; - NTSTATUS Status; PVOID BaseAddress; ULONG ChunkSize; PVOID Context = 0; @@ -287,7 +279,7 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster) DPRINT1("CcMapData(Offset %x, Length %d) failed\n", (ULONG)Offset.QuadPart, ChunkSize); return STATUS_UNSUCCESSFUL; } - Block = (PULONG)(BaseAddress + i % ChunkSize); + Block = (PULONG)((char*)BaseAddress + i % ChunkSize); } if ((*Block & 0x0fffffff) == 0) @@ -316,12 +308,10 @@ FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt) * FUNCTION: Counts free cluster in a FAT12 table */ { - ULONG FATOffset; ULONG Entry; PVOID BaseAddress; ULONG ulCount = 0; ULONG i; - NTSTATUS Status; ULONG numberofclusters; LARGE_INTEGER Offset; PVOID Context; @@ -337,7 +327,7 @@ FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt) for (i = 2; i < numberofclusters; i++) { - CBlock = (PUSHORT)(BaseAddress + (i * 12) / 8); + CBlock = (PUSHORT)((char*)BaseAddress + (i * 12) / 8); if ((i % 2) == 0) { Entry = *CBlock & 0x0fff; @@ -369,7 +359,6 @@ FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt) ULONG ulCount = 0; ULONG i; ULONG ChunkSize; - NTSTATUS Status; PVOID Context = NULL; LARGE_INTEGER Offset; ULONG FatLength; @@ -391,7 +380,7 @@ FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt) { return STATUS_UNSUCCESSFUL; } - Block = (PUSHORT)(BaseAddress + i % ChunkSize); + Block = (PUSHORT)((char*)BaseAddress + i % ChunkSize); } if (*Block == 0) ulCount++; @@ -416,7 +405,6 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt) ULONG ulCount = 0; ULONG i; ULONG ChunkSize; - NTSTATUS Status; PVOID Context = NULL; LARGE_INTEGER Offset; ULONG FatLength; @@ -437,7 +425,7 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt) { return STATUS_UNSUCCESSFUL; } - Block = (PULONG)(BaseAddress + i % ChunkSize); + Block = (PULONG)((char*)BaseAddress + i % ChunkSize); } if ((*Block & 0x0fffffff) == 0) ulCount++; @@ -487,8 +475,6 @@ FAT12WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG FATsector; ULONG FATOffset; PUCHAR CBlock; - int i; - NTSTATUS Status; PVOID BaseAddress; PVOID Context; LARGE_INTEGER Offset; @@ -506,7 +492,7 @@ FAT12WriteCluster(PDEVICE_EXTENSION DeviceExt, if ((ClusterToWrite % 2) == 0) { *OldValue = CBlock[FATOffset] + ((CBlock[FATOffset + 1] & 0x0f) << 8); - CBlock[FATOffset] = NewValue; + CBlock[FATOffset] = (UCHAR)NewValue; CBlock[FATOffset + 1] &= 0xf0; CBlock[FATOffset + 1] |= (NewValue & 0xf00) >> 8; } @@ -515,7 +501,7 @@ FAT12WriteCluster(PDEVICE_EXTENSION DeviceExt, *OldValue = (CBlock[FATOffset] >> 4) + (CBlock[FATOffset + 1] << 4); CBlock[FATOffset] &= 0x0f; CBlock[FATOffset] |= (NewValue & 0xf) << 4; - CBlock[FATOffset + 1] = NewValue >> 4; + CBlock[FATOffset + 1] = (UCHAR)(NewValue >> 4); } /* Write the changed FAT sector(s) to disk */ FATsector = FATOffset / DeviceExt->FatInfo.BytesPerSector; @@ -534,9 +520,7 @@ FAT16WriteCluster(PDEVICE_EXTENSION DeviceExt, */ { PVOID BaseAddress; - NTSTATUS Status; ULONG FATOffset; - ULONG i; ULONG ChunkSize; PVOID Context; LARGE_INTEGER Offset; @@ -551,9 +535,9 @@ FAT16WriteCluster(PDEVICE_EXTENSION DeviceExt, } DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset, ClusterToWrite); - Cluster = ((PUSHORT)(BaseAddress + (FATOffset % ChunkSize))); + Cluster = ((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize))); *OldValue = *Cluster; - *Cluster = NewValue; + *Cluster = (USHORT)NewValue; CcSetDirtyPinnedData(Context, NULL); CcUnpinData(Context); return(STATUS_SUCCESS); @@ -569,9 +553,7 @@ FAT32WriteCluster(PDEVICE_EXTENSION DeviceExt, */ { PVOID BaseAddress; - NTSTATUS Status; ULONG FATOffset; - ULONG i; ULONG ChunkSize; PVOID Context; LARGE_INTEGER Offset; @@ -587,7 +569,7 @@ FAT32WriteCluster(PDEVICE_EXTENSION DeviceExt, } DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset, ClusterToWrite); - Cluster = ((PULONG)(BaseAddress + (FATOffset % ChunkSize))); + Cluster = ((PULONG)((char*)BaseAddress + (FATOffset % ChunkSize))); *OldValue = *Cluster & 0x0fffffff; *Cluster = (*Cluster & 0xf0000000) | (NewValue & 0x0fffffff); @@ -632,7 +614,7 @@ WriteCluster(PDEVICE_EXTENSION DeviceExt, return(Status); } -ULONG +ULONGLONG ClusterToSector(PDEVICE_EXTENSION DeviceExt, ULONG Cluster) /* @@ -641,7 +623,8 @@ ClusterToSector(PDEVICE_EXTENSION DeviceExt, */ { return DeviceExt->FatInfo.dataStart + - ((Cluster - 2) * DeviceExt->FatInfo.SectorsPerCluster); + ((ULONGLONG)(Cluster - 2) * DeviceExt->FatInfo.SectorsPerCluster); + } NTSTATUS @@ -774,44 +757,4 @@ 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 (CurrentSectorFatInfo.dataStart || ((CurrentSector - DeviceExt->FatInfo.dataStart + 1) % DeviceExt->FatInfo.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->FatInfo.dataStart) / DeviceExt->FatInfo.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); - } -} - /* EOF */