12cf4975bSFrançois Revol /* 22cf4975bSFrançois Revol ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3*b6f76ebeSAugustin Cavalier ** Distributed under the terms of the MIT License. 42cf4975bSFrançois Revol */ 52cf4975bSFrançois Revol #ifndef VOLUME_H 62cf4975bSFrançois Revol #define VOLUME_H 72cf4975bSFrançois Revol 82cf4975bSFrançois Revol 92cf4975bSFrançois Revol #include "fatfs.h" 102cf4975bSFrançois Revol 112cf4975bSFrançois Revol #include <SupportDefs.h> 122cf4975bSFrançois Revol 132cf4975bSFrançois Revol namespace boot { 142cf4975bSFrançois Revol class Partition; 152cf4975bSFrançois Revol } 162cf4975bSFrançois Revol 172cf4975bSFrançois Revol 182cf4975bSFrançois Revol namespace FATFS { 192cf4975bSFrançois Revol 202cf4975bSFrançois Revol class CachedBlock; 212cf4975bSFrançois Revol class Directory; 222cf4975bSFrançois Revol 232cf4975bSFrançois Revol class Volume { 242cf4975bSFrançois Revol public: 252cf4975bSFrançois Revol Volume(boot::Partition *partition); 262cf4975bSFrançois Revol ~Volume(); 272cf4975bSFrançois Revol 282cf4975bSFrançois Revol status_t InitCheck(); 292cf4975bSFrançois Revol status_t GetName(char *name, size_t size) const; 302cf4975bSFrançois Revol Device()312cf4975bSFrançois Revol int Device() const { return fDevice; } Root()322cf4975bSFrançois Revol Directory *Root() { return fRoot; } FatBits()332cf4975bSFrançois Revol int32 FatBits() const { return fFatBits; } DataStart()342cf4975bSFrançois Revol uint32 DataStart() const { return fDataStart; } 352cf4975bSFrançois Revol BlockSize()362cf4975bSFrançois Revol int32 BlockSize() const { return fBlockSize; } ClusterSize()372cf4975bSFrançois Revol int32 ClusterSize() const { return fSectorsPerCluster * fBytesPerSector; } 382cf4975bSFrançois Revol BlockShift()392cf4975bSFrançois Revol int32 BlockShift() const { return fBlockShift; } SectorShift()402cf4975bSFrançois Revol int32 SectorShift() const { return fSectorShift; } ClusterShift()412cf4975bSFrançois Revol int32 ClusterShift() const { return fClusterShift; } 422cf4975bSFrançois Revol NumBlocks()432cf4975bSFrançois Revol int32 NumBlocks() const { return (int32)((off_t)fTotalSectors * fBytesPerSector / fBlockSize); } NumSectors()442cf4975bSFrançois Revol int32 NumSectors() const { return fTotalSectors; } NumClusters()452cf4975bSFrançois Revol int32 NumClusters() const { return fTotalClusters; } 462cf4975bSFrançois Revol 472cf4975bSFrançois Revol uint32 NextCluster(uint32 cluster, uint32 skip=0); 482cf4975bSFrançois Revol bool IsValidCluster(uint32 cluster) const; 492cf4975bSFrançois Revol bool IsLastCluster(uint32 cluster) const; InvalidClusterID()502cf4975bSFrançois Revol uint32 InvalidClusterID() const { return (1 << fFatBits) - 1; } 512cf4975bSFrançois Revol 52085cf27bSIngo Weinhold status_t AllocateCluster(uint32 previousCluster, 53085cf27bSIngo Weinhold uint32& _newCluster); 54085cf27bSIngo Weinhold 55085cf27bSIngo Weinhold off_t ClusterToOffset(uint32 cluster) const; 562cf4975bSFrançois Revol // uint32 ToCluster(off_t offset) const { return offset >> ClusterShift(); } BlockToOffset(off_t block)57085cf27bSIngo Weinhold off_t BlockToOffset(off_t block) const 58085cf27bSIngo Weinhold { return block << BlockShift(); } ToBlock(off_t offset)592cf4975bSFrançois Revol uint32 ToBlock(off_t offset) const { return offset >> BlockShift(); } 602cf4975bSFrançois Revol 61085cf27bSIngo Weinhold private: 62085cf27bSIngo Weinhold status_t _UpdateCluster(uint32 cluster, uint32 value); 63085cf27bSIngo Weinhold status_t _ClusterAllocated(uint32 cluster); 642cf4975bSFrançois Revol 652cf4975bSFrançois Revol protected: 662cf4975bSFrançois Revol int fDevice; 672cf4975bSFrançois Revol int32 fBlockShift; 682cf4975bSFrançois Revol int32 fSectorShift; 692cf4975bSFrançois Revol int32 fClusterShift; 702cf4975bSFrançois Revol uint32 fBlockSize; 712cf4975bSFrançois Revol // from the boot/fsinfo sectors 722cf4975bSFrançois Revol uint32 fBytesPerSector; 732cf4975bSFrançois Revol uint32 fSectorsPerCluster; 742cf4975bSFrançois Revol uint32 fReservedSectors; 752cf4975bSFrançois Revol uint8 fMediaDesc; 762cf4975bSFrançois Revol uint32 fSectorsPerFat; 772cf4975bSFrançois Revol uint32 fTotalSectors; 782cf4975bSFrançois Revol uint8 fFatCount; 792cf4975bSFrançois Revol uint16 fMaxRootEntries; 802cf4975bSFrançois Revol uint8 fActiveFat; 812cf4975bSFrançois Revol uint8 fFatBits; 822cf4975bSFrançois Revol uint32 fDataStart; 832cf4975bSFrançois Revol uint32 fTotalClusters; 842cf4975bSFrançois Revol uint32 fRootDirCluster; 85085cf27bSIngo Weinhold uint16 fFSInfoSector; 862cf4975bSFrançois Revol 872cf4975bSFrançois Revol CachedBlock *fCachedBlock; 882cf4975bSFrançois Revol Directory *fRoot; 892cf4975bSFrançois Revol }; 902cf4975bSFrançois Revol 912cf4975bSFrançois Revol } // namespace FATFS 922cf4975bSFrançois Revol 932cf4975bSFrançois Revol #endif /* VOLUME_H */ 94