00001
00032 #ifndef LL_LLVFS_H
00033 #define LL_LLVFS_H
00034
00035 #include <deque>
00036 #include "lluuid.h"
00037 #include "linked_lists.h"
00038 #include "llassettype.h"
00039 #include "llthread.h"
00040
00041 enum EVFSValid
00042 {
00043 VFSVALID_UNKNOWN = 0,
00044 VFSVALID_OK = 1,
00045 VFSVALID_BAD_CORRUPT = 2,
00046 VFSVALID_BAD_CANNOT_OPEN_READONLY = 3,
00047 VFSVALID_BAD_CANNOT_CREATE = 4
00048 };
00049
00050
00051
00052 enum EVFSLock
00053 {
00054 VFSLOCK_OPEN = 0,
00055 VFSLOCK_READ = 1,
00056 VFSLOCK_APPEND = 2,
00057
00058 VFSLOCK_COUNT = 3
00059 };
00060
00061
00062 class LLVFSBlock;
00063 class LLVFSFileBlock;
00064 class LLVFSFileSpecifier
00065 {
00066 public:
00067 LLVFSFileSpecifier();
00068 LLVFSFileSpecifier(const LLUUID &file_id, const LLAssetType::EType file_type);
00069 bool operator<(const LLVFSFileSpecifier &rhs) const;
00070 bool operator==(const LLVFSFileSpecifier &rhs) const;
00071
00072 public:
00073 LLUUID mFileID;
00074 LLAssetType::EType mFileType;
00075 };
00076
00077 class LLVFS
00078 {
00079 public:
00080
00081 LLVFS(const char *index_filename, const char *data_filename, const BOOL read_only, const U32 presize, const BOOL remove_after_crash);
00082 ~LLVFS();
00083
00084 BOOL isValid() const { return (VFSVALID_OK == mValid); }
00085 EVFSValid getValidState() const { return mValid; }
00086
00087
00088 BOOL getExists(const LLUUID &file_id, const LLAssetType::EType file_type);
00089 S32 getSize(const LLUUID &file_id, const LLAssetType::EType file_type);
00090
00091 BOOL checkAvailable(S32 max_size);
00092
00093 S32 getMaxSize(const LLUUID &file_id, const LLAssetType::EType file_type);
00094 BOOL setMaxSize(const LLUUID &file_id, const LLAssetType::EType file_type, S32 max_size);
00095
00096 void renameFile(const LLUUID &file_id, const LLAssetType::EType file_type,
00097 const LLUUID &new_id, const LLAssetType::EType &new_type);
00098 void removeFile(const LLUUID &file_id, const LLAssetType::EType file_type);
00099
00100 S32 getData(const LLUUID &file_id, const LLAssetType::EType file_type, U8 *buffer, S32 location, S32 length);
00101 S32 storeData(const LLUUID &file_id, const LLAssetType::EType file_type, const U8 *buffer, S32 location, S32 length);
00102
00103 void incLock(const LLUUID &file_id, const LLAssetType::EType file_type, EVFSLock lock);
00104 void decLock(const LLUUID &file_id, const LLAssetType::EType file_type, EVFSLock lock);
00105 BOOL isLocked(const LLUUID &file_id, const LLAssetType::EType file_type, EVFSLock lock);
00106
00107
00108
00109 void pokeFiles();
00110
00111
00112
00113 void audit();
00114
00115 void checkMem();
00116
00117 void dumpMap();
00118 void dumpLockCounts();
00119 void dumpStatistics();
00120 void listFiles();
00121 void dumpFiles();
00122
00123 protected:
00124 void removeFileBlock(LLVFSFileBlock *fileblock);
00125
00126 void eraseBlockLength(LLVFSBlock *block);
00127 void eraseBlock(LLVFSBlock *block);
00128 void addFreeBlock(LLVFSBlock *block);
00129
00130 void useFreeSpace(LLVFSBlock *free_block, S32 length);
00131 void sync(LLVFSFileBlock *block, BOOL remove = FALSE);
00132 void presizeDataFile(const U32 size);
00133
00134 static FILE *openAndLock(const char *filename, const char *mode, BOOL read_lock);
00135 static void unlockAndClose(FILE *fp);
00136
00137
00138
00139 LLVFSBlock *findFreeBlock(S32 size, LLVFSFileBlock *immune = NULL);
00140
00141
00142 void lockData() { mDataMutex->lock(); }
00143 void unlockData() { mDataMutex->unlock(); }
00144
00145 protected:
00146 LLMutex* mDataMutex;
00147
00148 typedef std::map<LLVFSFileSpecifier, LLVFSFileBlock*> fileblock_map;
00149 fileblock_map mFileBlocks;
00150
00151 typedef std::multimap<S32, LLVFSBlock*> blocks_length_map_t;
00152 blocks_length_map_t mFreeBlocksByLength;
00153 typedef std::multimap<U32, LLVFSBlock*> blocks_location_map_t;
00154 blocks_location_map_t mFreeBlocksByLocation;
00155
00156 FILE *mDataFP;
00157 FILE *mIndexFP;
00158
00159 std::deque<S32> mIndexHoles;
00160
00161 char *mIndexFilename;
00162 char *mDataFilename;
00163 BOOL mReadOnly;
00164
00165 EVFSValid mValid;
00166
00167 S32 mLockCounts[VFSLOCK_COUNT];
00168 BOOL mRemoveAfterCrash;
00169 };
00170
00171 extern LLVFS *gVFS;
00172
00173 #endif