1 /* 2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 ** Distributed under the terms of the OpenBeOS License. 4 */ 5 #ifndef VOLUME_H 6 #define VOLUME_H 7 8 9 #include "fatfs.h" 10 11 #include <SupportDefs.h> 12 13 namespace boot { 14 class Partition; 15 } 16 17 18 namespace FATFS { 19 20 class CachedBlock; 21 class Directory; 22 23 class Volume { 24 public: 25 Volume(boot::Partition *partition); 26 ~Volume(); 27 28 status_t InitCheck(); 29 status_t GetName(char *name, size_t size) const; 30 31 int Device() const { return fDevice; } 32 Directory *Root() { return fRoot; } 33 int32 FatBits() const { return fFatBits; } 34 uint32 DataStart() const { return fDataStart; } 35 36 int32 BlockSize() const { return fBlockSize; } 37 int32 ClusterSize() const { return fSectorsPerCluster * fBytesPerSector; } 38 39 int32 BlockShift() const { return fBlockShift; } 40 int32 SectorShift() const { return fSectorShift; } 41 int32 ClusterShift() const { return fClusterShift; } 42 43 int32 NumBlocks() const { return (int32)((off_t)fTotalSectors * fBytesPerSector / fBlockSize); } 44 int32 NumSectors() const { return fTotalSectors; } 45 int32 NumClusters() const { return fTotalClusters; } 46 47 uint32 NextCluster(uint32 cluster, uint32 skip=0); 48 bool IsValidCluster(uint32 cluster) const; 49 bool IsLastCluster(uint32 cluster) const; 50 uint32 InvalidClusterID() const { return (1 << fFatBits) - 1; } 51 52 off_t ToOffset(uint32 cluster) const; 53 // uint32 ToCluster(off_t offset) const { return offset >> ClusterShift(); } 54 off_t ToOffset(off_t block) const { return block << BlockShift(); } 55 uint32 ToBlock(off_t offset) const { return offset >> BlockShift(); } 56 57 58 protected: 59 int fDevice; 60 int32 fBlockShift; 61 int32 fSectorShift; 62 int32 fClusterShift; 63 uint32 fBlockSize; 64 // from the boot/fsinfo sectors 65 uint32 fBytesPerSector; 66 uint32 fSectorsPerCluster; 67 uint32 fReservedSectors; 68 uint8 fMediaDesc; 69 uint32 fSectorsPerFat; 70 uint32 fTotalSectors; 71 uint8 fFatCount; 72 uint16 fMaxRootEntries; 73 uint8 fActiveFat; 74 uint8 fFatBits; 75 uint32 fDataStart; 76 uint32 fTotalClusters; 77 uint32 fRootDirCluster; 78 79 CachedBlock *fCachedBlock; 80 Directory *fRoot; 81 }; 82 83 } // namespace FATFS 84 85 #endif /* VOLUME_H */ 86