vfs: check userland buffers before reading them.
[haiku.git] / src / system / boot / loader / file_systems / fat / Volume.h
blobb222069a13ddb6123743710f9f1ab7536e6d3a24
1 /*
2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
5 #ifndef VOLUME_H
6 #define VOLUME_H
9 #include "fatfs.h"
11 #include <SupportDefs.h>
13 namespace boot {
14 class Partition;
18 namespace FATFS {
20 class CachedBlock;
21 class Directory;
23 class Volume {
24 public:
25 Volume(boot::Partition *partition);
26 ~Volume();
28 status_t InitCheck();
29 status_t GetName(char *name, size_t size) const;
31 int Device() const { return fDevice; }
32 Directory *Root() { return fRoot; }
33 int32 FatBits() const { return fFatBits; }
34 uint32 DataStart() const { return fDataStart; }
36 int32 BlockSize() const { return fBlockSize; }
37 int32 ClusterSize() const { return fSectorsPerCluster * fBytesPerSector; }
39 int32 BlockShift() const { return fBlockShift; }
40 int32 SectorShift() const { return fSectorShift; }
41 int32 ClusterShift() const { return fClusterShift; }
43 int32 NumBlocks() const { return (int32)((off_t)fTotalSectors * fBytesPerSector / fBlockSize); }
44 int32 NumSectors() const { return fTotalSectors; }
45 int32 NumClusters() const { return fTotalClusters; }
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; }
52 status_t AllocateCluster(uint32 previousCluster,
53 uint32& _newCluster);
55 off_t ClusterToOffset(uint32 cluster) const;
56 // uint32 ToCluster(off_t offset) const { return offset >> ClusterShift(); }
57 off_t BlockToOffset(off_t block) const
58 { return block << BlockShift(); }
59 uint32 ToBlock(off_t offset) const { return offset >> BlockShift(); }
61 private:
62 status_t _UpdateCluster(uint32 cluster, uint32 value);
63 status_t _ClusterAllocated(uint32 cluster);
65 protected:
66 int fDevice;
67 int32 fBlockShift;
68 int32 fSectorShift;
69 int32 fClusterShift;
70 uint32 fBlockSize;
71 // from the boot/fsinfo sectors
72 uint32 fBytesPerSector;
73 uint32 fSectorsPerCluster;
74 uint32 fReservedSectors;
75 uint8 fMediaDesc;
76 uint32 fSectorsPerFat;
77 uint32 fTotalSectors;
78 uint8 fFatCount;
79 uint16 fMaxRootEntries;
80 uint8 fActiveFat;
81 uint8 fFatBits;
82 uint32 fDataStart;
83 uint32 fTotalClusters;
84 uint32 fRootDirCluster;
85 uint16 fFSInfoSector;
87 CachedBlock *fCachedBlock;
88 Directory *fRoot;
91 } // namespace FATFS
93 #endif /* VOLUME_H */