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 STREAM_H 9 #define STREAM_H 10 11 #include "fatfs.h" 12 #include "Volume.h" 13 14 #include <sys/stat.h> 15 16 #define CLUSTER_MAP_CACHE_SIZE 50 17 18 class Node; 19 20 struct file_map_run; 21 22 namespace FATFS { 23 24 class Stream { 25 public: 26 Stream(Volume &volume, uint32 chain, off_t size, const char *name); 27 ~Stream(); 28 29 status_t InitCheck(); 30 Volume &GetVolume() const { return fVolume; } 31 32 status_t GetName(char *nameBuffer, size_t bufferSize) const; 33 status_t GetFileMap(struct file_map_run *runs, int32 *count); 34 off_t Size() const { return fSize; } 35 uint32 FirstCluster() const { return fFirstCluster; } 36 37 status_t ReadAt(off_t pos, uint8 *buffer, size_t *length); 38 39 private: 40 status_t BuildClusterList(); 41 status_t FindBlock(off_t pos, off_t &block, off_t &offset); 42 Volume &fVolume; 43 uint32 fFirstCluster; 44 uint32 fClusterCount; 45 //uint32 *fClusters; // [fClusterCount] 46 struct { 47 off_t block; 48 uint32 cluster; 49 } fClusterMapCache[CLUSTER_MAP_CACHE_SIZE]; 50 int fClusterMapCacheLast; 51 off_t fSize; 52 // we cache the name here, since FAT doesn't have inodes, 53 // let alone names inside. 54 char fName[FATFS_NAME_LENGTH+1]; 55 }; 56 57 } // namespace FATFS 58 59 #endif /* STREAM_H */ 60