1 /* 2 * Copyright 2008, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * François Revol <revol@free.fr> 7 */ 8 #ifndef CACHED_BLOCK_H 9 #define CACHED_BLOCK_H 10 11 12 #include <SupportDefs.h> 13 #include <sys/stat.h> 14 #include <stdlib.h> 15 #include <unistd.h> 16 17 #include "Volume.h" 18 19 20 namespace FATFS { 21 22 class CachedBlock { 23 public: 24 enum { 25 READ = 0x01, 26 CLEAR = 0x02, 27 FORCE = 0x04, 28 }; 29 30 public: 31 CachedBlock(Volume &volume); 32 CachedBlock(Volume &volume, off_t block); 33 ~CachedBlock(); 34 35 uint8 *SetTo(off_t block); 36 status_t SetTo(off_t blockNumber, uint32 flags); 37 status_t Flush(); 38 39 void Unset(); 40 41 uint8 *Block() const { return fBlock; } 42 off_t BlockNumber() const { return fBlockNumber; } 43 uint32 BlockSize() const { return fVolume.BlockSize(); } 44 uint32 BlockShift() const { return fVolume.BlockShift(); } 45 46 private: 47 Volume &fVolume; 48 off_t fBlockNumber; 49 uint8 *fBlock; 50 }; 51 52 53 inline void 54 CachedBlock::Unset() 55 { 56 fBlockNumber = -1; 57 } 58 59 60 } // namespace FATFS 61 62 63 #endif /* CACHED_BLOCK_H */ 64