embkernel
 All Classes Functions Variables Typedefs Groups Pages
FsPartition.hpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #ifndef FS_PARTITION_HPP_
7 #define FS_PARTITION_HPP_
8 
9 #include <stdint.h>
10 #include "FsDefs.hpp"
11 
12 class FsPartition {
13  friend class Fs;
14  friend class FsDrive;
15  friend class FsDir;
16 public:
17  FsPartition(class FsDrive* drive, int indexOnDrive);
18 
19 private:
20  typedef enum {
21  UNKOWN = 0,
22  FAT12,
23  FAT16,
24  FAT32
25  } FAT_TYPE;
26 
27  class FsDrive* mDrive;
28  int mIndexOnDrive;
29  uint32_t mFatBeginLba;
30  uint32_t mClusterBeginLba;
31  uint32_t mRootDirFirstCluster;
32  uint32_t mInfoSectorLba;
33  uint32_t mBackupBootSectorLba;
34  uint32_t mInfoFreeClusterCount;
35  uint32_t mInfoNextFreeCluster;
36  uint32_t mClustersCount;
37  uint8_t mSectorsPerCluster;
38  uint8_t mNumFats;
39  FAT_TYPE mFatType;
40  bool mIsValid;
41 
42  uint32_t getRootClusterLba();
43  uint32_t getFatSectorLba(uint32_t cluster);
44  static uint32_t getFatSectorIndex(uint32_t cluster);
45  uint32_t getClusterBeginLba(uint32_t cluster);
46  uint32_t getClusterFromLba(uint32_t lba);
47  uint32_t getClusterFromFatIndex(uint32_t index);
48  uint32_t getFatIndexFromCluster(uint32_t cluster);
49 
50  FsDefs::RESULT initFromBootSector(FsDefs::BOOT_SECTOR* bootSector, uint32_t partitionBeginLba);
51  FsDefs::RESULT getNextBlockLba(FsDefs::SECTOR* sector, uint32_t* lba);
52  FsDefs::RESULT getNextFreeCluster(FsDefs::SECTOR* sector, uint32_t* cluster);
53  FsDefs::RESULT appendFreeCluster(FsDefs::SECTOR* sector, uint32_t* cluster);
54  FsDefs::RESULT setFatValue(FsDefs::SECTOR* sector, uint32_t cluster, uint32_t value);
55  FsDefs::RESULT writeFatSector(FsDefs::SECTOR* sector, uint32_t cluster);
56  FsDefs::RESULT freeClusterChain(FsDefs::SECTOR* sector, uint32_t cluster);
57  FsDefs::RESULT updateInfo(FsDefs::SECTOR* sector);
58 
59  bool readBlocks(FsDefs::SECTOR* buffer, unsigned int blockNumber, unsigned int blockCount);
60  bool writeBlocks(const FsDefs::SECTOR* buffer, unsigned int blockNumber, unsigned int blockCount);
61  void lock();
62  void unlock();
63 };
64 
65 #endif /* FS_PARTITION_HPP_ */