aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llvfs/llvfs.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llvfs/llvfs.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/llvfs/llvfs.h170
1 files changed, 170 insertions, 0 deletions
diff --git a/linden/indra/llvfs/llvfs.h b/linden/indra/llvfs/llvfs.h
new file mode 100644
index 0000000..f7affd4
--- /dev/null
+++ b/linden/indra/llvfs/llvfs.h
@@ -0,0 +1,170 @@
1/**
2 * @file llvfs.h
3 * @brief Definition of virtual file system
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLVFS_H
29#define LL_LLVFS_H
30
31#include <stdio.h>
32#include <map>
33#include <deque>
34#include "lluuid.h"
35#include "linked_lists.h"
36#include "llassettype.h"
37#include "llthread.h"
38
39enum EVFSValid
40{
41 VFSVALID_UNKNOWN = 0,
42 VFSVALID_OK = 1,
43 VFSVALID_BAD_CORRUPT = 2,
44 VFSVALID_BAD_CANNOT_OPEN_READONLY = 3,
45 VFSVALID_BAD_CANNOT_CREATE = 4
46};
47
48// Lock types for open vfiles, pending async reads, and pending async appends
49// (There are no async normal writes, currently)
50enum EVFSLock
51{
52 VFSLOCK_OPEN = 0,
53 VFSLOCK_READ = 1,
54 VFSLOCK_APPEND = 2,
55
56 VFSLOCK_COUNT = 3
57};
58
59// internal classes
60class LLVFSBlock;
61class LLVFSFileBlock;
62class LLVFSFileSpecifier
63{
64public:
65 LLVFSFileSpecifier();
66 LLVFSFileSpecifier(const LLUUID &file_id, const LLAssetType::EType file_type);
67 bool operator<(const LLVFSFileSpecifier &rhs) const;
68 bool operator==(const LLVFSFileSpecifier &rhs) const;
69
70public:
71 LLUUID mFileID;
72 LLAssetType::EType mFileType;
73};
74
75class LLVFS
76{
77public:
78 // Pass 0 to not presize
79 LLVFS(const char *index_filename, const char *data_filename, const BOOL read_only, const U32 presize, const BOOL remove_after_crash);
80 ~LLVFS();
81
82 BOOL isValid() const { return (VFSVALID_OK == mValid); }
83 EVFSValid getValidState() const { return mValid; }
84
85 // ---------- The following fucntions lock/unlock mDataMutex ----------
86 BOOL getExists(const LLUUID &file_id, const LLAssetType::EType file_type);
87 S32 getSize(const LLUUID &file_id, const LLAssetType::EType file_type);
88
89 BOOL checkAvailable(S32 max_size);
90
91 S32 getMaxSize(const LLUUID &file_id, const LLAssetType::EType file_type);
92 BOOL setMaxSize(const LLUUID &file_id, const LLAssetType::EType file_type, S32 max_size);
93
94 void renameFile(const LLUUID &file_id, const LLAssetType::EType file_type,
95 const LLUUID &new_id, const LLAssetType::EType &new_type);
96 void removeFile(const LLUUID &file_id, const LLAssetType::EType file_type);
97
98 S32 getData(const LLUUID &file_id, const LLAssetType::EType file_type, U8 *buffer, S32 location, S32 length);
99 S32 storeData(const LLUUID &file_id, const LLAssetType::EType file_type, const U8 *buffer, S32 location, S32 length);
100
101 void incLock(const LLUUID &file_id, const LLAssetType::EType file_type, EVFSLock lock);
102 void decLock(const LLUUID &file_id, const LLAssetType::EType file_type, EVFSLock lock);
103 BOOL isLocked(const LLUUID &file_id, const LLAssetType::EType file_type, EVFSLock lock);
104 // ----------------------------------------------------------------
105
106 // Used to trigger evil WinXP behavior of "preloading" entire file into memory.
107 void pokeFiles();
108
109 // Verify that the index file contents match the in-memory file structure
110 // Very slow, do not call routinely. JC
111 void audit();
112 // Check for uninitialized blocks. Slow, do not call in release. JC
113 void checkMem();
114 // for debugging, prints a map of the vfs
115 void dumpMap();
116 void dumpLockCounts();
117 void dumpStatistics();
118 void dumpFiles();
119
120protected:
121 void removeFileBlock(LLVFSFileBlock *fileblock);
122
123 void eraseBlockLength(LLVFSBlock *block);
124 void eraseBlock(LLVFSBlock *block);
125 void addFreeBlock(LLVFSBlock *block);
126 //void mergeFreeBlocks();
127 void useFreeSpace(LLVFSBlock *free_block, S32 length);
128 void sync(LLVFSFileBlock *block, BOOL remove = FALSE);
129 void presizeDataFile(const U32 size);
130
131 static FILE *openAndLock(const char *filename, const char *mode, BOOL read_lock);
132 static void unlockAndClose(FILE *fp);
133
134 // Can initiate LRU-based file removal to make space.
135 // The immune file block will not be removed.
136 LLVFSBlock *findFreeBlock(S32 size, LLVFSFileBlock *immune = NULL);
137
138 // lock/unlock data mutex (mDataMutex)
139 void lockData() { mDataMutex->lock(); }
140 void unlockData() { mDataMutex->unlock(); }
141
142protected:
143 LLMutex* mDataMutex;
144
145 typedef std::map<LLVFSFileSpecifier, LLVFSFileBlock*> fileblock_map;
146 fileblock_map mFileBlocks;
147
148 typedef std::multimap<S32, LLVFSBlock*> blocks_length_map_t;
149 blocks_length_map_t mFreeBlocksByLength;
150 typedef std::multimap<U32, LLVFSBlock*> blocks_location_map_t;
151 blocks_location_map_t mFreeBlocksByLocation;
152
153 FILE *mDataFP;
154 FILE *mIndexFP;
155
156 std::deque<S32> mIndexHoles;
157
158 char *mIndexFilename;
159 char *mDataFilename;
160 BOOL mReadOnly;
161
162 EVFSValid mValid;
163
164 S32 mLockCounts[VFSLOCK_COUNT];
165 BOOL mRemoveAfterCrash;
166};
167
168extern LLVFS *gVFS;
169
170#endif