aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llvfs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llvfs/lldir.cpp78
-rw-r--r--linden/indra/llvfs/lldir.h4
-rw-r--r--linden/indra/llvfs/lldir_linux.cpp14
-rw-r--r--linden/indra/llvfs/lldir_mac.cpp2
-rw-r--r--linden/indra/llvfs/lldir_win32.cpp6
-rw-r--r--linden/indra/llvfs/lllfsthread.cpp235
-rw-r--r--linden/indra/llvfs/lllfsthread.h56
-rw-r--r--linden/indra/llvfs/llvfile.cpp16
-rw-r--r--linden/indra/llvfs/llvfile.h2
-rw-r--r--linden/indra/llvfs/llvfs.cpp177
-rw-r--r--linden/indra/llvfs/llvfs_vc8.vcproj292
-rw-r--r--linden/indra/llvfs/llvfsthread.cpp64
-rw-r--r--linden/indra/llvfs/llvfsthread.h25
13 files changed, 644 insertions, 327 deletions
diff --git a/linden/indra/llvfs/lldir.cpp b/linden/indra/llvfs/lldir.cpp
index b0d9d92..6d0e956 100644
--- a/linden/indra/llvfs/lldir.cpp
+++ b/linden/indra/llvfs/lldir.cpp
@@ -202,6 +202,27 @@ const std::string &LLDir::getTempDir() const
202 return mTempDir; 202 return mTempDir;
203} 203}
204 204
205const std::string LLDir::getCacheDir(bool get_default) const
206{
207 if (mCacheDir.empty() || get_default)
208 {
209 std::string res;
210 if (getOSUserAppDir().empty())
211 {
212 res = "data";
213 }
214 else
215 {
216 res = getOSUserAppDir() + mDirDelimiter + "cache";
217 }
218 return res;
219 }
220 else
221 {
222 return mCacheDir;
223 }
224}
225
205const std::string &LLDir::getCAFile() const 226const std::string &LLDir::getCAFile() const
206{ 227{
207 return mCAFile; 228 return mCAFile;
@@ -217,7 +238,12 @@ const std::string &LLDir::getSkinDir() const
217 return mSkinDir; 238 return mSkinDir;
218} 239}
219 240
220std::string LLDir::getExpandedFilename(ELLPath location, const std::string &filename) const 241std::string LLDir::getExpandedFilename(ELLPath location, const std::string& filename) const
242{
243 return getExpandedFilename(location, "", filename);
244}
245
246std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subdir, const std::string& in_filename) const
221{ 247{
222 std::string prefix; 248 std::string prefix;
223 switch (location) 249 switch (location)
@@ -249,16 +275,7 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string &file
249 break; 275 break;
250 276
251 case LL_PATH_CACHE: 277 case LL_PATH_CACHE:
252 if (getOSUserAppDir().empty()) 278 prefix = getCacheDir();
253 {
254 prefix = "data";
255 }
256 else
257 {
258 prefix = getOSUserAppDir();
259 prefix += mDirDelimiter;
260 prefix += "cache";
261 }
262 break; 279 break;
263 280
264 case LL_PATH_USER_SETTINGS: 281 case LL_PATH_USER_SETTINGS:
@@ -309,6 +326,16 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string &file
309 llassert(0); 326 llassert(0);
310 } 327 }
311 328
329 std::string filename = in_filename;
330 if (!subdir.empty())
331 {
332 filename = subdir + mDirDelimiter + in_filename;
333 }
334 else
335 {
336 filename = in_filename;
337 }
338
312 std::string expanded_filename; 339 std::string expanded_filename;
313 if (!filename.empty()) 340 if (!filename.empty())
314 { 341 {
@@ -323,8 +350,7 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string &file
323 expanded_filename = filename; 350 expanded_filename = filename;
324 } 351 }
325 } 352 }
326 else 353 else if (!prefix.empty())
327 if (!prefix.empty())
328 { 354 {
329 // Directory only, no file name. 355 // Directory only, no file name.
330 expanded_filename = prefix; 356 expanded_filename = prefix;
@@ -342,7 +368,7 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string &file
342std::string LLDir::getTempFilename() const 368std::string LLDir::getTempFilename() const
343{ 369{
344 LLUUID random_uuid; 370 LLUUID random_uuid;
345 char uuid_str[64]; 371 char uuid_str[64]; /* Flawfinder: ignore */
346 372
347 random_uuid.generate(); 373 random_uuid.generate();
348 random_uuid.toString(uuid_str); 374 random_uuid.toString(uuid_str);
@@ -424,6 +450,30 @@ void LLDir::setSkinFolder(const std::string &skin_folder)
424 mSkinDir += skin_folder; 450 mSkinDir += skin_folder;
425} 451}
426 452
453bool LLDir::setCacheDir(const std::string &path)
454{
455 if (path.empty() )
456 {
457 // reset to default
458 mCacheDir = "";
459 return true;
460 }
461 else
462 {
463 LLFile::mkdir(path.c_str());
464 std::string tempname = path + mDirDelimiter + "temp";
465 LLFILE* file = LLFile::fopen(tempname.c_str(),"wt");
466 if (file)
467 {
468 fclose(file);
469 LLFile::remove(tempname.c_str());
470 mCacheDir = path;
471 return true;
472 }
473 return false;
474 }
475}
476
427void LLDir::dumpCurrentDirectories() 477void LLDir::dumpCurrentDirectories()
428{ 478{
429 llinfos << "Current Directories:" << llendl; 479 llinfos << "Current Directories:" << llendl;
diff --git a/linden/indra/llvfs/lldir.h b/linden/indra/llvfs/lldir.h
index 2012f1b..60188f3 100644
--- a/linden/indra/llvfs/lldir.h
+++ b/linden/indra/llvfs/lldir.h
@@ -79,12 +79,14 @@ class LLDir
79 const std::string &getChatLogsDir() const; // Location of the chat logs dir. 79 const std::string &getChatLogsDir() const; // Location of the chat logs dir.
80 const std::string &getPerAccountChatLogsDir() const; // Location of the per account chat logs dir. 80 const std::string &getPerAccountChatLogsDir() const; // Location of the per account chat logs dir.
81 const std::string &getTempDir() const; // Common temporary directory 81 const std::string &getTempDir() const; // Common temporary directory
82 const std::string getCacheDir(bool get_default = false) const; // Location of the cache.
82 const std::string &getCAFile() const; // File containing TLS certificate authorities 83 const std::string &getCAFile() const; // File containing TLS certificate authorities
83 const std::string &getDirDelimiter() const; // directory separator for platform (ie. '\' or '/' or ':') 84 const std::string &getDirDelimiter() const; // directory separator for platform (ie. '\' or '/' or ':')
84 const std::string &getSkinDir() const; // User-specified skin folder. 85 const std::string &getSkinDir() const; // User-specified skin folder.
85 86
86 // Expanded filename 87 // Expanded filename
87 std::string getExpandedFilename(ELLPath location, const std::string &filename) const; 88 std::string getExpandedFilename(ELLPath location, const std::string &filename) const;
89 std::string getExpandedFilename(ELLPath location, const std::string &subdir, const std::string &filename) const;
88 90
89 // random filename in common temporary directory 91 // random filename in common temporary directory
90 std::string getTempFilename() const; 92 std::string getTempFilename() const;
@@ -93,6 +95,7 @@ class LLDir
93 virtual void setPerAccountChatLogsDir(const std::string &first, const std::string &last); // Set the per user chat log directory. 95 virtual void setPerAccountChatLogsDir(const std::string &first, const std::string &last); // Set the per user chat log directory.
94 virtual void setLindenUserDir(const std::string &first, const std::string &last); // Set the linden user dir to this user's dir 96 virtual void setLindenUserDir(const std::string &first, const std::string &last); // Set the linden user dir to this user's dir
95 virtual void setSkinFolder(const std::string &skin_folder); 97 virtual void setSkinFolder(const std::string &skin_folder);
98 virtual bool setCacheDir(const std::string &path);
96 99
97 virtual void dumpCurrentDirectories(); 100 virtual void dumpCurrentDirectories();
98 101
@@ -110,6 +113,7 @@ protected:
110 std::string mChatLogsDir; // Location for chat logs. 113 std::string mChatLogsDir; // Location for chat logs.
111 std::string mCAFile; // Location of the TLS certificate authority PEM file. 114 std::string mCAFile; // Location of the TLS certificate authority PEM file.
112 std::string mTempDir; 115 std::string mTempDir;
116 std::string mCacheDir;
113 std::string mDirDelimiter; 117 std::string mDirDelimiter;
114 std::string mSkinDir; // Location for u ser-specified skin info. 118 std::string mSkinDir; // Location for u ser-specified skin info.
115}; 119};
diff --git a/linden/indra/llvfs/lldir_linux.cpp b/linden/indra/llvfs/lldir_linux.cpp
index 780fbdb..f46ccf2 100644
--- a/linden/indra/llvfs/lldir_linux.cpp
+++ b/linden/indra/llvfs/lldir_linux.cpp
@@ -51,7 +51,7 @@ static std::string getCurrentUserHome(char* fallback)
51 else 51 else
52 { 52 {
53 llinfos << "Couldn't detect home directory from passwd - trying $HOME" << llendl; 53 llinfos << "Couldn't detect home directory from passwd - trying $HOME" << llendl;
54 const char *const home_env = getenv("HOME"); 54 const char *const home_env = getenv("HOME"); /* Flawfinder: ignore */
55 if (home_env) 55 if (home_env)
56 { 56 {
57 result_cstr = (char*) home_env; 57 result_cstr = (char*) home_env;
@@ -73,7 +73,7 @@ LLDir_Linux::LLDir_Linux()
73 mCurrentDirCount = -1; 73 mCurrentDirCount = -1;
74 mDirp = NULL; 74 mDirp = NULL;
75 75
76 char tmp_str[LL_MAX_PATH]; 76 char tmp_str[LL_MAX_PATH]; /* Flawfinder: ignore */
77 getcwd(tmp_str, LL_MAX_PATH); 77 getcwd(tmp_str, LL_MAX_PATH);
78 78
79 mExecutableFilename = ""; 79 mExecutableFilename = "";
@@ -85,13 +85,13 @@ LLDir_Linux::LLDir_Linux()
85 mOSUserAppDir = ""; 85 mOSUserAppDir = "";
86 mLindenUserDir = tmp_str; 86 mLindenUserDir = tmp_str;
87 87
88 char path [32]; 88 char path [32]; /* Flawfinder: ignore */
89 89
90 // *NOTE: /proc/%d/exe doesn't work on FreeBSD. But that's ok, 90 // *NOTE: /proc/%d/exe doesn't work on FreeBSD. But that's ok,
91 // because this is the linux implementation. 91 // because this is the linux implementation.
92 92
93 sprintf (path, "/proc/%d/exe", (int) getpid ()); 93 snprintf (path, sizeof(path), "/proc/%d/exe", (int) getpid ()); /* Flawfinder: ignore */
94 int rc = readlink (path, tmp_str, sizeof (tmp_str)-1); 94 int rc = readlink (path, tmp_str, sizeof (tmp_str)-1); /* Flawfinder: ignore */
95 if ( (rc != -1) && (rc <= ((int) sizeof (tmp_str)-1)) ) 95 if ( (rc != -1) && (rc <= ((int) sizeof (tmp_str)-1)) )
96 { 96 {
97 tmp_str[rc] = '\0'; //readlink() doesn't 0-terminate the buffer 97 tmp_str[rc] = '\0'; //readlink() doesn't 0-terminate the buffer
@@ -128,7 +128,7 @@ void LLDir_Linux::initAppDirs(const std::string &app_name)
128 LLString upper_app_name(app_name); 128 LLString upper_app_name(app_name);
129 LLString::toUpper(upper_app_name); 129 LLString::toUpper(upper_app_name);
130 130
131 char* app_home_env = getenv((upper_app_name + "_USER_DIR").c_str()); 131 char* app_home_env = getenv((upper_app_name + "_USER_DIR").c_str()); /* Flawfinder: ignore */
132 if (app_home_env) 132 if (app_home_env)
133 { 133 {
134 // user has specified own userappdir i.e. $SECONDLIFE_USER_DIR 134 // user has specified own userappdir i.e. $SECONDLIFE_USER_DIR
@@ -326,7 +326,7 @@ void LLDir_Linux::getRandomFileInDir(const std::string &dirname, const std::stri
326 326
327std::string LLDir_Linux::getCurPath() 327std::string LLDir_Linux::getCurPath()
328{ 328{
329 char tmp_str[LL_MAX_PATH]; 329 char tmp_str[LL_MAX_PATH]; /* Flawfinder: ignore */
330 getcwd(tmp_str, LL_MAX_PATH); 330 getcwd(tmp_str, LL_MAX_PATH);
331 return tmp_str; 331 return tmp_str;
332} 332}
diff --git a/linden/indra/llvfs/lldir_mac.cpp b/linden/indra/llvfs/lldir_mac.cpp
index 7f1d2ce..7ed7697 100644
--- a/linden/indra/llvfs/lldir_mac.cpp
+++ b/linden/indra/llvfs/lldir_mac.cpp
@@ -354,7 +354,7 @@ S32 LLDir_Mac::deleteFilesInDir(const std::string &dirname, const std::string &m
354 354
355std::string LLDir_Mac::getCurPath() 355std::string LLDir_Mac::getCurPath()
356{ 356{
357 char tmp_str[LL_MAX_PATH]; 357 char tmp_str[LL_MAX_PATH]; /* Flawfinder: ignore */
358 getcwd(tmp_str, LL_MAX_PATH); 358 getcwd(tmp_str, LL_MAX_PATH);
359 return tmp_str; 359 return tmp_str;
360} 360}
diff --git a/linden/indra/llvfs/lldir_win32.cpp b/linden/indra/llvfs/lldir_win32.cpp
index ad72752..fd264a7 100644
--- a/linden/indra/llvfs/lldir_win32.cpp
+++ b/linden/indra/llvfs/lldir_win32.cpp
@@ -64,9 +64,9 @@ LLDir_Win32::LLDir_Win32()
64 64
65 if (GetTempPath(MAX_PATH, w_str)) 65 if (GetTempPath(MAX_PATH, w_str))
66 { 66 {
67 if (wcslen(w_str)) 67 if (wcslen(w_str)) /* Flawfinder: ignore */
68 { 68 {
69 w_str[wcslen(w_str)-1] = '\0'; // remove trailing slash 69 w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash
70 } 70 }
71 mTempDir = utf16str_to_utf8str(llutf16string(w_str)); 71 mTempDir = utf16str_to_utf8str(llutf16string(w_str));
72 } 72 }
@@ -361,7 +361,7 @@ DWORD GetDllVersion(LPCTSTR lpszDllName)
361 HINSTANCE hinstDll; 361 HINSTANCE hinstDll;
362 DWORD dwVersion = 0; 362 DWORD dwVersion = 0;
363 363
364 hinstDll = LoadLibrary(lpszDllName); 364 hinstDll = LoadLibrary(lpszDllName); /* Flawfinder: ignore */
365 365
366 if(hinstDll) 366 if(hinstDll)
367 { 367 {
diff --git a/linden/indra/llvfs/lllfsthread.cpp b/linden/indra/llvfs/lllfsthread.cpp
index b7335e2..25edb52 100644
--- a/linden/indra/llvfs/lllfsthread.cpp
+++ b/linden/indra/llvfs/lllfsthread.cpp
@@ -38,10 +38,10 @@
38//============================================================================ 38//============================================================================
39// Run on MAIN thread 39// Run on MAIN thread
40//static 40//static
41void LLLFSThread::initClass(bool local_is_threaded, bool local_run_always) 41void LLLFSThread::initClass(bool local_is_threaded)
42{ 42{
43 llassert(sLocal == NULL); 43 llassert(sLocal == NULL);
44 sLocal = new LLLFSThread(local_is_threaded, local_run_always); 44 sLocal = new LLLFSThread(local_is_threaded);
45} 45}
46 46
47//static 47//static
@@ -65,8 +65,9 @@ void LLLFSThread::cleanupClass()
65 65
66//---------------------------------------------------------------------------- 66//----------------------------------------------------------------------------
67 67
68LLLFSThread::LLLFSThread(bool threaded, bool runalways) : 68LLLFSThread::LLLFSThread(bool threaded) :
69 LLQueuedThread("LFS", threaded, runalways) 69 LLQueuedThread("LFS", threaded),
70 mPriorityCounter(PRIORITY_LOWBITS)
70{ 71{
71} 72}
72 73
@@ -77,251 +78,165 @@ LLLFSThread::~LLLFSThread()
77 78
78//---------------------------------------------------------------------------- 79//----------------------------------------------------------------------------
79 80
80LLLFSThread::handle_t LLLFSThread::read(const LLString& filename, 81LLLFSThread::handle_t LLLFSThread::read(const LLString& filename, /* Flawfinder: ignore */
81 U8* buffer, S32 offset, S32 numbytes, U32 priority, U32 flags) 82 U8* buffer, S32 offset, S32 numbytes,
83 Responder* responder, U32 priority)
82{ 84{
83 handle_t handle = generateHandle(); 85 handle_t handle = generateHandle();
84 86
85 priority = llmax(priority, (U32)PRIORITY_LOW); // All reads are at least PRIORITY_LOW 87 if (priority == 0) priority = PRIORITY_NORMAL | priorityCounter();
86 Request* req = new Request(handle, priority, flags, 88 else if (priority < PRIORITY_LOW) priority |= PRIORITY_LOW; // All reads are at least PRIORITY_LOW
89
90 Request* req = new Request(this, handle, priority,
87 FILE_READ, filename, 91 FILE_READ, filename,
88 buffer, offset, numbytes); 92 buffer, offset, numbytes,
93 responder);
89 94
90 bool res = addRequest(req); 95 bool res = addRequest(req);
91 if (!res) 96 if (!res)
92 { 97 {
93 llerrs << "LLLFSThread::read called after LLLFSThread::cleanupClass()" << llendl; 98 llerrs << "LLLFSThread::read called after LLLFSThread::cleanupClass()" << llendl;
94 req->deleteRequest();
95 handle = nullHandle();
96 } 99 }
97 100
98 return handle; 101 return handle;
99} 102}
100 103
101S32 LLLFSThread::readImmediate(const LLString& filename,
102 U8* buffer, S32 offset, S32 numbytes)
103{
104 handle_t handle = generateHandle();
105
106 Request* req = new Request(handle, PRIORITY_IMMEDIATE, 0,
107 FILE_READ, filename,
108 buffer, offset, numbytes);
109
110 S32 res = addRequest(req) ? 1 : 0;
111 if (res == 0)
112 {
113 llerrs << "LLLFSThread::read called after LLLFSThread::cleanupClass()" << llendl;
114 req->deleteRequest();
115 }
116 else
117 {
118 llverify(waitForResult(handle, false) == true);
119 res = req->getBytesRead();
120 completeRequest(handle);
121 }
122 return res;
123}
124
125LLLFSThread::handle_t LLLFSThread::write(const LLString& filename, 104LLLFSThread::handle_t LLLFSThread::write(const LLString& filename,
126 U8* buffer, S32 offset, S32 numbytes, U32 flags) 105 U8* buffer, S32 offset, S32 numbytes,
106 Responder* responder, U32 priority)
127{ 107{
128 handle_t handle = generateHandle(); 108 handle_t handle = generateHandle();
129 109
130 Request* req = new Request(handle, 0, flags, 110 if (priority == 0) priority = PRIORITY_LOW | priorityCounter();
131 FILE_WRITE, filename,
132 buffer, offset, numbytes);
133
134 bool res = addRequest(req);
135 if (!res)
136 {
137 llerrs << "LLLFSThread::read called after LLLFSThread::cleanupClass()" << llendl;
138 req->deleteRequest();
139 handle = nullHandle();
140 }
141 111
142 return handle; 112 Request* req = new Request(this, handle, priority,
143}
144
145S32 LLLFSThread::writeImmediate(const LLString& filename,
146 U8* buffer, S32 offset, S32 numbytes)
147{
148 handle_t handle = generateHandle();
149
150 Request* req = new Request(handle, PRIORITY_IMMEDIATE, 0,
151 FILE_WRITE, filename, 113 FILE_WRITE, filename,
152 buffer, offset, numbytes); 114 buffer, offset, numbytes,
153 115 responder);
154 S32 res = addRequest(req) ? 1 : 0;
155 if (res == 0)
156 {
157 llerrs << "LLLFSThread::write called after LLLFSThread::cleanupClass()" << llendl;
158 req->deleteRequest();
159 }
160 else
161 {
162 llverify(waitForResult(handle, false) == true);
163 res = req->getBytesRead();
164 completeRequest(handle);
165 }
166 return res;
167}
168
169
170LLLFSThread::handle_t LLLFSThread::rename(const LLString& filename, const LLString& newname, U32 flags)
171{
172 handle_t handle = generateHandle();
173
174 LLString* new_name_str = new LLString(newname); // deleted with Request
175 Request* req = new Request(handle, 0, flags,
176 FILE_RENAME, filename,
177 (U8*)new_name_str, 0, 0);
178
179 bool res = addRequest(req);
180 if (!res)
181 {
182 llerrs << "LLLFSThread::rename called after LLLFSThread::cleanupClass()" << llendl;
183 req->deleteRequest();
184 handle = nullHandle();
185 }
186
187 return handle;
188}
189
190LLLFSThread::handle_t LLLFSThread::remove(const LLString& filename, U32 flags)
191{
192 handle_t handle = generateHandle();
193
194 Request* req = new Request(handle, 0, flags,
195 FILE_RENAME, filename,
196 NULL, 0, 0);
197 116
198 bool res = addRequest(req); 117 bool res = addRequest(req);
199 if (!res) 118 if (!res)
200 { 119 {
201 llerrs << "LLLFSThread::remove called after LLLFSThread::cleanupClass()" << llendl; 120 llerrs << "LLLFSThread::read called after LLLFSThread::cleanupClass()" << llendl;
202 req->deleteRequest();
203 handle = nullHandle();
204 } 121 }
205 122
206 return handle; 123 return handle;
207} 124}
208 125
209//============================================================================ 126//============================================================================
210// Runs on its OWN thread
211
212bool LLLFSThread::processRequest(QueuedRequest* qreq)
213{
214 Request *req = (Request*)qreq;
215
216 bool complete = req->processIO();
217
218 return complete;
219}
220
221//============================================================================
222 127
223LLLFSThread::Request::Request(handle_t handle, U32 priority, U32 flags, 128LLLFSThread::Request::Request(LLLFSThread* thread,
129 handle_t handle, U32 priority,
224 operation_t op, const LLString& filename, 130 operation_t op, const LLString& filename,
225 U8* buffer, S32 offset, S32 numbytes) : 131 U8* buffer, S32 offset, S32 numbytes,
226 QueuedRequest(handle, priority, flags), 132 Responder* responder) :
133 QueuedRequest(handle, priority, FLAG_AUTO_COMPLETE),
134 mThread(thread),
227 mOperation(op), 135 mOperation(op),
228 mFileName(filename), 136 mFileName(filename),
229 mBuffer(buffer), 137 mBuffer(buffer),
230 mOffset(offset), 138 mOffset(offset),
231 mBytes(numbytes), 139 mBytes(numbytes),
232 mBytesRead(0) 140 mBytesRead(0),
141 mResponder(responder)
233{ 142{
234 llassert(mBuffer); 143 if (numbytes <= 0)
235
236 if (numbytes <= 0 && mOperation != FILE_RENAME && mOperation != FILE_REMOVE)
237 { 144 {
238 llwarns << "LLLFSThread: Request with numbytes = " << numbytes << llendl; 145 llwarns << "LLLFSThread: Request with numbytes = " << numbytes << llendl;
239 } 146 }
240} 147}
241 148
242void LLLFSThread::Request::finishRequest() 149LLLFSThread::Request::~Request()
243{ 150{
244} 151}
245 152
153// virtual, called from own thread
154void LLLFSThread::Request::finishRequest(bool completed)
155{
156 if (mResponder.notNull())
157 {
158 mResponder->completed(completed ? mBytesRead : 0);
159 mResponder = NULL;
160 }
161}
162
246void LLLFSThread::Request::deleteRequest() 163void LLLFSThread::Request::deleteRequest()
247{ 164{
248 if (getStatus() == STATUS_QUEUED || getStatus() == STATUS_ABORT) 165 if (getStatus() == STATUS_QUEUED)
249 { 166 {
250 llerrs << "Attempt to delete a queued LLLFSThread::Request!" << llendl; 167 llerrs << "Attempt to delete a queued LLLFSThread::Request!" << llendl;
251 } 168 }
252 if (mOperation == FILE_WRITE) 169 if (mResponder.notNull())
253 {
254 if (mFlags & AUTO_DELETE)
255 {
256 delete mBuffer;
257 }
258 }
259 else if (mOperation == FILE_RENAME)
260 { 170 {
261 LLString* new_name = (LLString*)mBuffer; 171 mResponder->completed(0);
262 delete new_name; 172 mResponder = NULL;
263 } 173 }
264 LLQueuedThread::QueuedRequest::deleteRequest(); 174 LLQueuedThread::QueuedRequest::deleteRequest();
265} 175}
266 176
267bool LLLFSThread::Request::processIO() 177bool LLLFSThread::Request::processRequest()
268{ 178{
269 bool complete = false; 179 bool complete = false;
270 if (mOperation == FILE_READ) 180 if (mOperation == FILE_READ)
271 { 181 {
272 llassert(mOffset >= 0); 182 llassert(mOffset >= 0);
273 apr_file_t* filep = ll_apr_file_open(mFileName, LL_APR_RB); 183 apr_file_t* filep = ll_apr_file_open(mFileName, LL_APR_RB, mThread->mAPRPoolp);
274 if (!filep) 184 if (!filep)
275 { 185 {
276 llwarns << "LLLFS: Unable to read file: " << mFileName << llendl; 186 llwarns << "LLLFS: Unable to read file: " << mFileName << llendl;
277 mBytesRead = 0; // fail 187 mBytesRead = 0; // fail
278 return true; 188 return true;
279 } 189 }
190 S32 off;
280 if (mOffset < 0) 191 if (mOffset < 0)
281 ll_apr_file_seek(filep, APR_END, 0); 192 off = ll_apr_file_seek(filep, APR_END, 0);
282 else 193 else
283 ll_apr_file_seek(filep, APR_SET, mOffset); 194 off = ll_apr_file_seek(filep, APR_SET, mOffset);
195 llassert_always(off >= 0);
284 mBytesRead = ll_apr_file_read(filep, mBuffer, mBytes ); 196 mBytesRead = ll_apr_file_read(filep, mBuffer, mBytes );
285 apr_file_close(filep); 197 apr_file_close(filep);
286 complete = true; 198 complete = true;
287 //llinfos << llformat("LLLFSThread::READ '%s': %d bytes",mFileName.c_str(),mBytesRead) << llendl; 199// llinfos << "LLLFSThread::READ:" << mFileName << " Bytes: " << mBytesRead << llendl;
288 } 200 }
289 else if (mOperation == FILE_WRITE) 201 else if (mOperation == FILE_WRITE)
290 { 202 {
291 apr_file_t* filep = ll_apr_file_open(mFileName, LL_APR_WB); 203 apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY;
204 if (mOffset < 0)
205 flags |= APR_APPEND;
206 apr_file_t* filep = ll_apr_file_open(mFileName, flags, mThread->mAPRPoolp);
292 if (!filep) 207 if (!filep)
293 { 208 {
294 llwarns << "LLLFS: Unable to write file: " << mFileName << llendl; 209 llwarns << "LLLFS: Unable to write file: " << mFileName << llendl;
295 mBytesRead = 0; // fail 210 mBytesRead = 0; // fail
296 return true; 211 return true;
297 } 212 }
298 if (mOffset < 0) 213 if (mOffset >= 0)
299 ll_apr_file_seek(filep, APR_END, 0); 214 {
300 else 215 S32 seek = ll_apr_file_seek(filep, APR_SET, mOffset);
301 ll_apr_file_seek(filep, APR_SET, mOffset); 216 if (seek < 0)
217 {
218 apr_file_close(filep);
219 llwarns << "LLLFS: Unable to write file (seek failed): " << mFileName << llendl;
220 mBytesRead = 0; // fail
221 return true;
222 }
223 }
302 mBytesRead = ll_apr_file_write(filep, mBuffer, mBytes ); 224 mBytesRead = ll_apr_file_write(filep, mBuffer, mBytes );
303 complete = true; 225 complete = true;
304 apr_file_close(filep); 226 apr_file_close(filep);
305 //llinfos << llformat("LLLFSThread::WRITE '%s': %d bytes",mFileName.c_str(),mBytesRead) << llendl; 227// llinfos << "LLLFSThread::WRITE:" << mFileName << " Bytes: " << mBytesRead << "/" << mBytes << " Offset:" << mOffset << llendl;
306 }
307 else if (mOperation == FILE_RENAME)
308 {
309 LLString* new_name = (LLString*)mBuffer;
310 ll_apr_file_rename(mFileName, *new_name);
311 complete = true;
312 //llinfos << llformat("LLLFSThread::RENAME '%s': '%s'",mFileName.c_str(),new_name->c_str()) << llendl;
313 }
314 else if (mOperation == FILE_REMOVE)
315 {
316 ll_apr_file_remove(mFileName);
317 complete = true;
318 //llinfos << llformat("LLLFSThread::REMOVE '%s'",mFileName.c_str()) << llendl;
319 } 228 }
320 else 229 else
321 { 230 {
322 llerrs << llformat("LLLFSThread::unknown operation: %d", mOperation) << llendl; 231 llerrs << "LLLFSThread::unknown operation: " << (S32)mOperation << llendl;
323 } 232 }
324 return complete; 233 return complete;
325} 234}
326 235
327//============================================================================ 236//============================================================================
237
238LLLFSThread::Responder::~Responder()
239{
240}
241
242//============================================================================
diff --git a/linden/indra/llvfs/lllfsthread.h b/linden/indra/llvfs/lllfsthread.h
index 8af66b1..06c53aa 100644
--- a/linden/indra/llvfs/lllfsthread.h
+++ b/linden/indra/llvfs/lllfsthread.h
@@ -55,15 +55,24 @@ public:
55 //------------------------------------------------------------------------ 55 //------------------------------------------------------------------------
56public: 56public:
57 57
58 class Responder : public LLThreadSafeRefCount
59 {
60 public:
61 virtual ~Responder();
62 virtual void completed(S32 bytes) = 0;
63 };
64
58 class Request : public QueuedRequest 65 class Request : public QueuedRequest
59 { 66 {
60 protected: 67 protected:
61 ~Request() {}; // use deleteRequest() 68 virtual ~Request(); // use deleteRequest()
62 69
63 public: 70 public:
64 Request(handle_t handle, U32 priority, U32 flags, 71 Request(LLLFSThread* thread,
72 handle_t handle, U32 priority,
65 operation_t op, const LLString& filename, 73 operation_t op, const LLString& filename,
66 U8* buffer, S32 offset, S32 numbytes); 74 U8* buffer, S32 offset, S32 numbytes,
75 Responder* responder);
67 76
68 S32 getBytes() 77 S32 getBytes()
69 { 78 {
@@ -86,12 +95,12 @@ public:
86 return mFileName; 95 return mFileName;
87 } 96 }
88 97
89 /*virtual*/ void finishRequest(); 98 /*virtual*/ bool processRequest();
99 /*virtual*/ void finishRequest(bool completed);
90 /*virtual*/ void deleteRequest(); 100 /*virtual*/ void deleteRequest();
91
92 bool processIO();
93 101
94 private: 102 private:
103 LLLFSThread* mThread;
95 operation_t mOperation; 104 operation_t mOperation;
96 105
97 LLString mFileName; 106 LLString mFileName;
@@ -99,35 +108,36 @@ public:
99 U8* mBuffer; // dest for reads, source for writes, new UUID for rename 108 U8* mBuffer; // dest for reads, source for writes, new UUID for rename
100 S32 mOffset; // offset into file, -1 = append (WRITE only) 109 S32 mOffset; // offset into file, -1 = append (WRITE only)
101 S32 mBytes; // bytes to read from file, -1 = all 110 S32 mBytes; // bytes to read from file, -1 = all
102 S32 mBytesRead; // bytes read from file 111 S32 mBytesRead; // bytes read from file
112
113 LLPointer<Responder> mResponder;
103 }; 114 };
104 115
105 //------------------------------------------------------------------------ 116 //------------------------------------------------------------------------
106public: 117public:
107 LLLFSThread(bool threaded = TRUE, bool runalways = TRUE); 118 LLLFSThread(bool threaded = TRUE);
108 ~LLLFSThread(); 119 ~LLLFSThread();
109 120
110 // Return a Request handle 121 // Return a Request handle
111 handle_t read(const LLString& filename, 122 handle_t read(const LLString& filename, /* Flawfinder: ignore */
112 U8* buffer, S32 offset, S32 numbytes, U32 pri=PRIORITY_NORMAL, U32 flags = 0); 123 U8* buffer, S32 offset, S32 numbytes,
124 Responder* responder, U32 pri=0);
113 handle_t write(const LLString& filename, 125 handle_t write(const LLString& filename,
114 U8* buffer, S32 offset, S32 numbytes, U32 flags = 0); 126 U8* buffer, S32 offset, S32 numbytes,
115 handle_t rename(const LLString& filename, const LLString& newname, U32 flags = 0); 127 Responder* responder, U32 pri=0);
116 handle_t remove(const LLString& filename, U32 flags = 0);
117 128
118 // Return number of bytes read 129 // Misc
119 S32 readImmediate(const LLString& filename, 130 U32 priorityCounter() { return mPriorityCounter-- & PRIORITY_LOWBITS; } // Use to order IO operations
120 U8* buffer, S32 offset, S32 numbytes); 131
121 S32 writeImmediate(const LLString& filename, 132 // static initializers
122 U8* buffer, S32 offset, S32 numbytes); 133 static void initClass(bool local_is_threaded = TRUE); // Setup sLocal
123
124 static void initClass(bool local_is_threaded = TRUE, bool run_always = TRUE); // Setup sLocal
125 static S32 updateClass(U32 ms_elapsed); 134 static S32 updateClass(U32 ms_elapsed);
126 static void cleanupClass(); // Delete sLocal 135 static void cleanupClass(); // Delete sLocal
127 136
128protected: 137
129 /*virtual*/ bool processRequest(QueuedRequest* req); 138private:
130 139 U32 mPriorityCounter;
140
131public: 141public:
132 static LLLFSThread* sLocal; // Default local file thread 142 static LLLFSThread* sLocal; // Default local file thread
133}; 143};
diff --git a/linden/indra/llvfs/llvfile.cpp b/linden/indra/llvfs/llvfile.cpp
index 2faa5c3..e958b33 100644
--- a/linden/indra/llvfs/llvfile.cpp
+++ b/linden/indra/llvfs/llvfile.cpp
@@ -70,12 +70,12 @@ LLVFile::~LLVFile()
70 { 70 {
71 if (!(mMode & LLVFile::WRITE)) 71 if (!(mMode & LLVFile::WRITE))
72 { 72 {
73 // llwarns << "Destroying LLVFile with pending async read/write, aborting..." << llendl; 73 //llwarns << "Destroying LLVFile with pending async read/write, aborting..." << llendl;
74 sVFSThread->abortRequest(mHandle, LLVFSThread::AUTO_COMPLETE); 74 sVFSThread->setFlags(mHandle, LLVFSThread::FLAG_AUTO_COMPLETE | LLVFSThread::FLAG_ABORT);
75 } 75 }
76 else // WRITE 76 else // WRITE
77 { 77 {
78 sVFSThread->setFlags(mHandle, LLVFSThread::AUTO_COMPLETE); 78 sVFSThread->setFlags(mHandle, LLVFSThread::FLAG_AUTO_COMPLETE);
79 } 79 }
80 } 80 }
81 } 81 }
@@ -135,7 +135,7 @@ U8* LLVFile::readFile(LLVFS *vfs, const LLUUID &uuid, LLAssetType::EType type, S
135 else 135 else
136 { 136 {
137 data = new U8[file_size]; 137 data = new U8[file_size];
138 file.read(data, file_size); 138 file.read(data, file_size); /* Flawfinder: ignore */
139 139
140 if (file.getLastBytesRead() != (S32)file_size) 140 if (file.getLastBytesRead() != (S32)file_size)
141 { 141 {
@@ -213,8 +213,8 @@ BOOL LLVFile::write(const U8 *buffer, S32 bytes)
213 S32 offset = -1; 213 S32 offset = -1;
214 mHandle = sVFSThread->write(mVFS, mFileID, mFileType, 214 mHandle = sVFSThread->write(mVFS, mFileID, mFileType,
215 writebuf, offset, bytes, 215 writebuf, offset, bytes,
216 LLVFSThread::AUTO_COMPLETE | LLVFSThread::AUTO_DELETE); 216 LLVFSThread::FLAG_AUTO_COMPLETE | LLVFSThread::FLAG_AUTO_DELETE);
217 mHandle = LLVFSThread::nullHandle(); // AUTO_COMPLETE means we don't track this 217 mHandle = LLVFSThread::nullHandle(); // FLAG_AUTO_COMPLETE means we don't track this
218 } 218 }
219 else 219 else
220 { 220 {
@@ -323,7 +323,7 @@ BOOL LLVFile::setMaxSize(S32 size)
323 } 323 }
324 if (sVFSThread->isPaused()) 324 if (sVFSThread->isPaused())
325 { 325 {
326 sVFSThread->updateQueue(0); 326 sVFSThread->update(0);
327 } 327 }
328 ms_sleep(10); 328 ms_sleep(10);
329 } 329 }
@@ -427,7 +427,7 @@ void LLVFile::waitForLock(EVFSLock lock)
427 { 427 {
428 if (sVFSThread->isPaused()) 428 if (sVFSThread->isPaused())
429 { 429 {
430 sVFSThread->updateQueue(0); 430 sVFSThread->update(0);
431 } 431 }
432 ms_sleep(1); 432 ms_sleep(1);
433 } 433 }
diff --git a/linden/indra/llvfs/llvfile.h b/linden/indra/llvfs/llvfile.h
index dcc3cb5..c574cbc 100644
--- a/linden/indra/llvfs/llvfile.h
+++ b/linden/indra/llvfs/llvfile.h
@@ -39,7 +39,7 @@ public:
39 LLVFile(LLVFS *vfs, const LLUUID &file_id, const LLAssetType::EType file_type, S32 mode = LLVFile::READ); 39 LLVFile(LLVFS *vfs, const LLUUID &file_id, const LLAssetType::EType file_type, S32 mode = LLVFile::READ);
40 ~LLVFile(); 40 ~LLVFile();
41 41
42 BOOL read(U8 *buffer, S32 bytes, BOOL async = FALSE, F32 priority = 128.f); 42 BOOL read(U8 *buffer, S32 bytes, BOOL async = FALSE, F32 priority = 128.f); /* Flawfinder: ignore */
43 static U8* readFile(LLVFS *vfs, const LLUUID &uuid, LLAssetType::EType type, S32* bytes_read = 0); 43 static U8* readFile(LLVFS *vfs, const LLUUID &uuid, LLAssetType::EType type, S32* bytes_read = 0);
44 void setReadPriority(const F32 priority); 44 void setReadPriority(const F32 priority);
45 BOOL isReadComplete(); 45 BOOL isReadComplete();
diff --git a/linden/indra/llvfs/llvfs.cpp b/linden/indra/llvfs/llvfs.cpp
index bb211df..88476eb 100644
--- a/linden/indra/llvfs/llvfs.cpp
+++ b/linden/indra/llvfs/llvfs.cpp
@@ -63,12 +63,11 @@ public:
63 mLength = size; 63 mLength = size;
64 } 64 }
65 65
66 static BOOL insertFirstLL(LLVFSBlock *first, LLVFSBlock *second) 66 static bool locationSortPredicate(
67 const LLVFSBlock* lhs,
68 const LLVFSBlock* rhs)
67 { 69 {
68 return first->mLocation != second->mLocation 70 return lhs->mLocation < rhs->mLocation;
69 ? first->mLocation < second->mLocation
70 : first->mLength < second->mLength;
71
72 } 71 }
73 72
74public: 73public:
@@ -129,7 +128,7 @@ public:
129 } 128 }
130 129
131 #ifdef LL_LITTLE_ENDIAN 130 #ifdef LL_LITTLE_ENDIAN
132 inline void swizzleCopy(void *dst, void *src, int size) { memcpy(dst, src, size); } 131 inline void swizzleCopy(void *dst, void *src, int size) { memcpy(dst, src, size); /* Flawfinder: ignore */}
133 132
134 #else 133 #else
135 134
@@ -156,7 +155,7 @@ public:
156 else 155 else
157 { 156 {
158 // Perhaps this should assert... 157 // Perhaps this should assert...
159 memcpy(dst, src, size); 158 memcpy(dst, src, size); /* Flawfinder: ignore */
160 } 159 }
161 } 160 }
162 161
@@ -170,7 +169,7 @@ public:
170 buffer +=4; 169 buffer +=4;
171 swizzleCopy(buffer, &mAccessTime, 4); 170 swizzleCopy(buffer, &mAccessTime, 4);
172 buffer +=4; 171 buffer +=4;
173 memcpy(buffer, &mFileID.mData, 16); 172 memcpy(buffer, &mFileID.mData, 16); /* Flawfinder: ignore */
174 buffer += 16; 173 buffer += 16;
175 S16 temp_type = mFileType; 174 S16 temp_type = mFileType;
176 swizzleCopy(buffer, &temp_type, 2); 175 swizzleCopy(buffer, &temp_type, 2);
@@ -239,10 +238,15 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
239 } 238 }
240 mValid = VFSVALID_OK; 239 mValid = VFSVALID_OK;
241 mReadOnly = read_only; 240 mReadOnly = read_only;
242 mIndexFilename = new char[strlen(index_filename) + 1]; 241 mIndexFilename = new char[strlen(index_filename) + 1]; /* Flawfinder: ignore */
243 mDataFilename = new char[strlen(data_filename) + 1]; 242 mDataFilename = new char[strlen(data_filename) + 1]; /* Flawfinder: ignore */
244 strcpy(mIndexFilename, index_filename); 243 if (mIndexFilename == NULL || mDataFilename == NULL)
245 strcpy(mDataFilename, data_filename); 244 {
245 llerrs << "Memory Allocation Failure" << llendl;
246 return;
247 }
248 strcpy(mIndexFilename, index_filename); /* Flawfinder: ignore */
249 strcpy(mDataFilename, data_filename); /* Flawfinder: ignore */
246 250
247 const char *file_mode = mReadOnly ? "rb" : "r+b"; 251 const char *file_mode = mReadOnly ? "rb" : "r+b";
248 252
@@ -266,13 +270,23 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
266 { 270 {
267 llwarns << "Can't open VFS data file " << mDataFilename << " attempting to use alternate" << llendl; 271 llwarns << "Can't open VFS data file " << mDataFilename << " attempting to use alternate" << llendl;
268 272
269 char *temp_index = new char[strlen(mIndexFilename) + 10]; 273 char *temp_index = new char[strlen(mIndexFilename) + 10]; /* Flawfinder: ignore */
270 char *temp_data = new char[strlen(mDataFilename) + 10]; 274 if (!temp_index)
275 {
276 llerrs << "Out of the memory in LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL read_only, const U32 presize, const BOOL remove_after_crash)" << llendl;
277 return;
278 }
279 char *temp_data = new char[strlen(mDataFilename) + 10]; /* Flawfinder: ignore */
280 if (!temp_data)
281 {
282 llerrs << "Out of the memory in LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL read_only, const U32 presize, const BOOL remove_after_crash)" << llendl;
283 return;
284 }
271 285
272 for (U32 count = 0; count < 256; count++) 286 for (U32 count = 0; count < 256; count++)
273 { 287 {
274 sprintf(temp_index, "%s.%u", mIndexFilename, count); 288 sprintf(temp_index, "%s.%u", mIndexFilename, count); /* Flawfinder: ignore */
275 sprintf(temp_data, "%s.%u", mDataFilename, count); 289 sprintf(temp_data, "%s.%u", mDataFilename, count); /* Flawfinder: ignore */
276 290
277 // try just opening, then creating, each alternate 291 // try just opening, then creating, each alternate
278 if ((mDataFP = openAndLock(temp_data, "r+b", FALSE))) 292 if ((mDataFP = openAndLock(temp_data, "r+b", FALSE)))
@@ -313,8 +327,13 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
313 if (!mReadOnly && mRemoveAfterCrash) 327 if (!mReadOnly && mRemoveAfterCrash)
314 { 328 {
315 llstat marker_info; 329 llstat marker_info;
316 char* marker = new char[strlen(mDataFilename) + strlen(".open") + 1]; 330 char* marker = new char[strlen(mDataFilename) + strlen(".open") + 1]; /* Flawfinder: ignore */
317 sprintf(marker, "%s.open", mDataFilename); 331 if (!marker )
332 {
333 llerrs << "Out of memory in LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL read_only, const U32 presize, const BOOL remove_after_crash)" << llendl;
334 return;
335 }
336 sprintf(marker, "%s.open", mDataFilename); /* Flawfinder: ignore */
318 if (!LLFile::stat(marker, &marker_info)) 337 if (!LLFile::stat(marker, &marker_info))
319 { 338 {
320 // marker exists, kill the lock and the VFS files 339 // marker exists, kill the lock and the VFS files
@@ -361,9 +380,8 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
361 380
362 U8 *tmp_ptr = buffer; 381 U8 *tmp_ptr = buffer;
363 382
364 LLLinkedList<LLVFSBlock> files_by_loc; 383 std::vector<LLVFSFileBlock*> files_by_loc;
365 files_by_loc.setInsertBefore(LLVFSBlock::insertFirstLL); 384
366
367 while (tmp_ptr < buffer + fbuf.st_size) 385 while (tmp_ptr < buffer + fbuf.st_size)
368 { 386 {
369 LLVFSFileBlock *block = new LLVFSFileBlock(); 387 LLVFSFileBlock *block = new LLVFSFileBlock();
@@ -383,7 +401,7 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
383 block->mFileType < LLAssetType::AT_COUNT) 401 block->mFileType < LLAssetType::AT_COUNT)
384 { 402 {
385 mFileBlocks.insert(fileblock_map::value_type(*block, block)); 403 mFileBlocks.insert(fileblock_map::value_type(*block, block));
386 files_by_loc.addDataSorted(block); 404 files_by_loc.push_back(block);
387 } 405 }
388 else 406 else
389 if (block->mLength && block->mSize > 0) 407 if (block->mLength && block->mSize > 0)
@@ -419,22 +437,40 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
419 tmp_ptr += block->SERIAL_SIZE; 437 tmp_ptr += block->SERIAL_SIZE;
420 } 438 }
421 delete[] buffer; 439 delete[] buffer;
422 440
423 // discover all the free blocks 441 std::sort(
424 LLVFSFileBlock *last_file_block = (LLVFSFileBlock*)files_by_loc.getFirstData(); 442 files_by_loc.begin(),
425 443 files_by_loc.end(),
426 if (last_file_block) 444 LLVFSFileBlock::locationSortPredicate);
445
446 // There are 3 cases that have to be considered.
447 // 1. No blocks
448 // 2. One block.
449 // 3. Two or more blocks.
450 if (!files_by_loc.empty())
427 { 451 {
428 // check for empty space at the beginning 452 // cur walks through the list.
453 std::vector<LLVFSFileBlock*>::iterator cur = files_by_loc.begin();
454 std::vector<LLVFSFileBlock*>::iterator end = files_by_loc.end();
455 LLVFSFileBlock* last_file_block = *cur;
456
457 // Check to see if there is an empty space before the first file.
429 if (last_file_block->mLocation > 0) 458 if (last_file_block->mLocation > 0)
430 { 459 {
431 LLVFSBlock *block = new LLVFSBlock(0, last_file_block->mLocation); 460 // If so, create a free block.
432 addFreeBlock(block); 461 addFreeBlock(new LLVFSBlock(0, last_file_block->mLocation));
433 } 462 }
434 463
435 LLVFSFileBlock *cur_file_block; 464 // Walk through the 2nd+ block. If there is a free space
436 while ((cur_file_block = (LLVFSFileBlock*)files_by_loc.getNextData())) 465 // between cur_file_block and last_file_block, add it to
466 // the free space collection. This block will not need to
467 // run in the case there is only one entry in the VFS.
468 ++cur;
469 while( cur != end )
437 { 470 {
471 LLVFSFileBlock* cur_file_block = *cur;
472
473 // Dupe check on the block
438 if (cur_file_block->mLocation == last_file_block->mLocation 474 if (cur_file_block->mLocation == last_file_block->mLocation
439 && cur_file_block->mLength == last_file_block->mLength) 475 && cur_file_block->mLength == last_file_block->mLength)
440 { 476 {
@@ -451,21 +487,29 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
451 if (cur_file_block->mLength > 0) 487 if (cur_file_block->mLength > 0)
452 { 488 {
453 // convert to hole 489 // convert to hole
454 LLVFSBlock* block = new LLVFSBlock(cur_file_block->mLocation, 490 addFreeBlock(
455 cur_file_block->mLength); 491 new LLVFSBlock(
456 addFreeBlock(block); 492 cur_file_block->mLocation,
493 cur_file_block->mLength));
457 } 494 }
458 lockData(); // needed for sync() 495 lockData(); // needed for sync()
459 sync(cur_file_block, TRUE); // remove first on disk 496 sync(cur_file_block, TRUE); // remove first on disk
460 sync(last_file_block, TRUE); // remove last on disk 497 sync(last_file_block, TRUE); // remove last on disk
461 unlockData(); // needed for sync() 498 unlockData(); // needed for sync()
462 last_file_block = cur_file_block; 499 last_file_block = cur_file_block;
500 ++cur;
463 continue; 501 continue;
464 } 502 }
465 503
466 U32 loc = last_file_block->mLocation + last_file_block->mLength; 504 // Figure out where the last block ended.
505 U32 loc = last_file_block->mLocation+last_file_block->mLength;
506
507 // Figure out how much space there is between where
508 // the last block ended and this block begins.
467 S32 length = cur_file_block->mLocation - loc; 509 S32 length = cur_file_block->mLocation - loc;
468 510
511 // Check for more errors... Seeing if the current
512 // entry and the last entry make sense together.
469 if (length < 0 || loc < 0 || loc > data_size) 513 if (length < 0 || loc < 0 || loc > data_size)
470 { 514 {
471 // Invalid VFS 515 // Invalid VFS
@@ -487,27 +531,25 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
487 return; 531 return;
488 } 532 }
489 533
534 // we don't want to add empty blocks to the list...
490 if (length > 0) 535 if (length > 0)
491 { 536 {
492 LLVFSBlock *block = new LLVFSBlock(loc, length); 537 addFreeBlock(new LLVFSBlock(loc, length));
493 addFreeBlock(block);
494 } 538 }
495
496 last_file_block = cur_file_block; 539 last_file_block = cur_file_block;
540 ++cur;
497 } 541 }
498 542
499 // also note any empty space at the end 543 // also note any empty space at the end
500 U32 loc = last_file_block->mLocation + last_file_block->mLength; 544 U32 loc = last_file_block->mLocation + last_file_block->mLength;
501 if (loc < data_size) 545 if (loc < data_size)
502 { 546 {
503 LLVFSBlock *block = new LLVFSBlock(loc, data_size - loc); 547 addFreeBlock(new LLVFSBlock(loc, data_size - loc));
504 addFreeBlock(block);
505 } 548 }
506 } 549 }
507 else 550 else // There where no blocks in the file.
508 { 551 {
509 LLVFSBlock *first_block = new LLVFSBlock(0, data_size); 552 addFreeBlock(new LLVFSBlock(0, data_size));
510 addFreeBlock(first_block);
511 } 553 }
512 } 554 }
513 else 555 else
@@ -542,8 +584,13 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
542 if (!mReadOnly && mRemoveAfterCrash) 584 if (!mReadOnly && mRemoveAfterCrash)
543 { 585 {
544 char* marker = new char[strlen(mDataFilename) + strlen(".open") + 1]; 586 char* marker = new char[strlen(mDataFilename) + strlen(".open") + 1];
545 sprintf(marker, "%s.open", mDataFilename); 587 if (!marker)
546 FILE* marker_fp = LLFile::fopen(marker, "w"); 588 {
589 llerrs << "Out of memory in LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL read_only, const U32 presize, const BOOL remove_after_crash)" << llendl;
590 return;
591 }
592 sprintf(marker, "%s.open", mDataFilename); /* Flawfinder: ignore */
593 FILE* marker_fp = LLFile::fopen(marker, "w"); /* Flawfinder: ignore */
547 if (marker_fp) 594 if (marker_fp)
548 { 595 {
549 fclose(marker_fp); 596 fclose(marker_fp);
@@ -586,7 +633,12 @@ LLVFS::~LLVFS()
586 if (!mReadOnly && mRemoveAfterCrash) 633 if (!mReadOnly && mRemoveAfterCrash)
587 { 634 {
588 char* marker_file = new char[strlen(mDataFilename) + strlen(".open") + 1]; 635 char* marker_file = new char[strlen(mDataFilename) + strlen(".open") + 1];
589 sprintf(marker_file, "%s.open", mDataFilename); 636 if (marker_file == NULL)
637 {
638 llerrs << "Memory Allocation Failure" << llendl;
639 return;
640 }
641 sprintf(marker_file, "%s.open", mDataFilename); /* Flawfinder: ignore */
590 LLFile::remove(marker_file); 642 LLFile::remove(marker_file);
591 delete [] marker_file; 643 delete [] marker_file;
592 marker_file = NULL; 644 marker_file = NULL;
@@ -738,12 +790,17 @@ BOOL LLVFS::setMaxSize(const LLUUID &file_id, const LLAssetType::EType file_type
738 } 790 }
739 791
740 // round all sizes upward to KB increments 792 // round all sizes upward to KB increments
741 if (max_size & FILE_BLOCK_MASK) 793 // SJB: Need to not round for the new texture-pipeline code so we know the correct
794 // max file size. Need to investigate the potential problems with this...
795 if (file_type != LLAssetType::AT_TEXTURE)
742 { 796 {
743 max_size += FILE_BLOCK_MASK; 797 if (max_size & FILE_BLOCK_MASK)
744 max_size &= ~FILE_BLOCK_MASK; 798 {
745 } 799 max_size += FILE_BLOCK_MASK;
746 800 max_size &= ~FILE_BLOCK_MASK;
801 }
802 }
803
747 if (block && block->mLength > 0) 804 if (block && block->mLength > 0)
748 { 805 {
749 block->mAccessTime = (U32)time(NULL); 806 block->mAccessTime = (U32)time(NULL);
@@ -1230,6 +1287,7 @@ void LLVFS::eraseBlockLength(LLVFSBlock *block)
1230 S32 length = block->mLength; 1287 S32 length = block->mLength;
1231 blocks_length_map_t::iterator iter = mFreeBlocksByLength.lower_bound(length); 1288 blocks_length_map_t::iterator iter = mFreeBlocksByLength.lower_bound(length);
1232 blocks_length_map_t::iterator end = mFreeBlocksByLength.end(); 1289 blocks_length_map_t::iterator end = mFreeBlocksByLength.end();
1290 bool found_block = false;
1233 while(iter != end) 1291 while(iter != end)
1234 { 1292 {
1235 LLVFSBlock *tblock = iter->second; 1293 LLVFSBlock *tblock = iter->second;
@@ -1237,13 +1295,14 @@ void LLVFS::eraseBlockLength(LLVFSBlock *block)
1237 if (tblock == block) 1295 if (tblock == block)
1238 { 1296 {
1239 mFreeBlocksByLength.erase(iter); 1297 mFreeBlocksByLength.erase(iter);
1298 found_block = true;
1240 break; 1299 break;
1241 } 1300 }
1242 ++iter; 1301 ++iter;
1243 } 1302 }
1244 if (iter == end) 1303 if(!found_block)
1245 { 1304 {
1246 llerrs << "eraseBlock could not find block" << llendl; 1305 llwarns << "eraseBlock could not find block" << llendl;
1247 } 1306 }
1248} 1307}
1249 1308
@@ -1963,7 +2022,7 @@ LLString get_extension(LLAssetType::EType type)
1963 switch(type) 2022 switch(type)
1964 { 2023 {
1965 case LLAssetType::AT_TEXTURE: 2024 case LLAssetType::AT_TEXTURE:
1966 extension = ".jp2"; // ".j2c"; // IrfanView recognizes .jp2 -sjb 2025 extension = ".j2c";
1967 break; 2026 break;
1968 case LLAssetType::AT_SOUND: 2027 case LLAssetType::AT_SOUND:
1969 extension = ".ogg"; 2028 extension = ".ogg";
@@ -2033,7 +2092,7 @@ void LLVFS::dumpFiles()
2033 lockData(); 2092 lockData();
2034 2093
2035 LLString extension = get_extension(type); 2094 LLString extension = get_extension(type);
2036 LLString filename = id.getString() + extension; 2095 LLString filename = id.asString() + extension;
2037 llinfos << " Writing " << filename << llendl; 2096 llinfos << " Writing " << filename << llendl;
2038 apr_file_t* file = ll_apr_file_open(filename, LL_APR_WB); 2097 apr_file_t* file = ll_apr_file_open(filename, LL_APR_WB);
2039 ll_apr_file_write(file, buffer, size); 2098 ll_apr_file_write(file, buffer, size);
@@ -2064,7 +2123,7 @@ FILE *LLVFS::openAndLock(const char *filename, const char *mode, BOOL read_lock)
2064 // first test the lock in a non-destructive way 2123 // first test the lock in a non-destructive way
2065 if (strstr(mode, "w")) 2124 if (strstr(mode, "w"))
2066 { 2125 {
2067 fp = LLFile::fopen(filename, "rb"); 2126 fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */
2068 if (fp) 2127 if (fp)
2069 { 2128 {
2070 fd = fileno(fp); 2129 fd = fileno(fp);
@@ -2079,7 +2138,7 @@ FILE *LLVFS::openAndLock(const char *filename, const char *mode, BOOL read_lock)
2079 } 2138 }
2080 2139
2081 // now actually open the file for use 2140 // now actually open the file for use
2082 fp = LLFile::fopen(filename, mode); 2141 fp = LLFile::fopen(filename, mode); /* Flawfinder: ignore */
2083 if (fp) 2142 if (fp)
2084 { 2143 {
2085 fd = fileno(fp); 2144 fd = fileno(fp);
diff --git a/linden/indra/llvfs/llvfs_vc8.vcproj b/linden/indra/llvfs/llvfs_vc8.vcproj
new file mode 100644
index 0000000..7d4c0ae
--- /dev/null
+++ b/linden/indra/llvfs/llvfs_vc8.vcproj
@@ -0,0 +1,292 @@
1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="8.00"
5 Name="llvfs"
6 ProjectGUID="{D37774F4-253D-4760-BF64-372A943224A1}"
7 Keyword="Win32Proj"
8 >
9 <Platforms>
10 <Platform
11 Name="Win32"
12 />
13 </Platforms>
14 <ToolFiles>
15 </ToolFiles>
16 <Configurations>
17 <Configuration
18 Name="Debug|Win32"
19 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
20 IntermediateDirectory="Debug"
21 ConfigurationType="4"
22 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
23 CharacterSet="1"
24 >
25 <Tool
26 Name="VCPreBuildEventTool"
27 />
28 <Tool
29 Name="VCCustomBuildTool"
30 />
31 <Tool
32 Name="VCXMLDataGeneratorTool"
33 />
34 <Tool
35 Name="VCWebServiceProxyGeneratorTool"
36 />
37 <Tool
38 Name="VCMIDLTool"
39 />
40 <Tool
41 Name="VCCLCompilerTool"
42 Optimization="0"
43 AdditionalIncludeDirectories="..\..\libraries\i686-win32\include;..\..\libraries\include\;..\llcommon;..\llmath"
44 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_DEBUG"
45 MinimalRebuild="true"
46 BasicRuntimeChecks="3"
47 RuntimeLibrary="1"
48 StructMemberAlignment="4"
49 TreatWChar_tAsBuiltInType="false"
50 ForceConformanceInForLoopScope="true"
51 UsePrecompiledHeader="0"
52 WarningLevel="3"
53 WarnAsError="true"
54 Detect64BitPortabilityProblems="false"
55 DebugInformationFormat="4"
56 />
57 <Tool
58 Name="VCManagedResourceCompilerTool"
59 />
60 <Tool
61 Name="VCResourceCompilerTool"
62 />
63 <Tool
64 Name="VCPreLinkEventTool"
65 />
66 <Tool
67 Name="VCLibrarianTool"
68 OutputFile="$(OutDir)/llvfs.lib"
69 />
70 <Tool
71 Name="VCALinkTool"
72 />
73 <Tool
74 Name="VCXDCMakeTool"
75 />
76 <Tool
77 Name="VCBscMakeTool"
78 />
79 <Tool
80 Name="VCFxCopTool"
81 />
82 <Tool
83 Name="VCPostBuildEventTool"
84 />
85 </Configuration>
86 <Configuration
87 Name="Release|Win32"
88 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
89 IntermediateDirectory="Release"
90 ConfigurationType="4"
91 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
92 CharacterSet="1"
93 >
94 <Tool
95 Name="VCPreBuildEventTool"
96 />
97 <Tool
98 Name="VCCustomBuildTool"
99 />
100 <Tool
101 Name="VCXMLDataGeneratorTool"
102 />
103 <Tool
104 Name="VCWebServiceProxyGeneratorTool"
105 />
106 <Tool
107 Name="VCMIDLTool"
108 />
109 <Tool
110 Name="VCCLCompilerTool"
111 AdditionalIncludeDirectories="..\..\libraries\i686-win32\include;..\..\libraries\include\;..\llcommon;..\llmath"
112 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE"
113 RuntimeLibrary="0"
114 StructMemberAlignment="0"
115 TreatWChar_tAsBuiltInType="false"
116 ForceConformanceInForLoopScope="true"
117 UsePrecompiledHeader="0"
118 WarningLevel="3"
119 WarnAsError="true"
120 Detect64BitPortabilityProblems="false"
121 DebugInformationFormat="3"
122 />
123 <Tool
124 Name="VCManagedResourceCompilerTool"
125 />
126 <Tool
127 Name="VCResourceCompilerTool"
128 />
129 <Tool
130 Name="VCPreLinkEventTool"
131 />
132 <Tool
133 Name="VCLibrarianTool"
134 OutputFile="$(OutDir)/llvfs.lib"
135 />
136 <Tool
137 Name="VCALinkTool"
138 />
139 <Tool
140 Name="VCXDCMakeTool"
141 />
142 <Tool
143 Name="VCBscMakeTool"
144 />
145 <Tool
146 Name="VCFxCopTool"
147 />
148 <Tool
149 Name="VCPostBuildEventTool"
150 />
151 </Configuration>
152 <Configuration
153 Name="ReleaseNoOpt|Win32"
154 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
155 IntermediateDirectory="$(ConfigurationName)"
156 ConfigurationType="4"
157 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
158 CharacterSet="1"
159 >
160 <Tool
161 Name="VCPreBuildEventTool"
162 />
163 <Tool
164 Name="VCCustomBuildTool"
165 />
166 <Tool
167 Name="VCXMLDataGeneratorTool"
168 />
169 <Tool
170 Name="VCWebServiceProxyGeneratorTool"
171 />
172 <Tool
173 Name="VCMIDLTool"
174 />
175 <Tool
176 Name="VCCLCompilerTool"
177 Optimization="0"
178 AdditionalIncludeDirectories="..\..\libraries\i686-win32\include;..\..\libraries\include\;..\llcommon;..\llmath"
179 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE"
180 RuntimeLibrary="0"
181 StructMemberAlignment="0"
182 TreatWChar_tAsBuiltInType="false"
183 ForceConformanceInForLoopScope="true"
184 UsePrecompiledHeader="0"
185 WarningLevel="3"
186 WarnAsError="true"
187 Detect64BitPortabilityProblems="false"
188 DebugInformationFormat="3"
189 />
190 <Tool
191 Name="VCManagedResourceCompilerTool"
192 />
193 <Tool
194 Name="VCResourceCompilerTool"
195 />
196 <Tool
197 Name="VCPreLinkEventTool"
198 />
199 <Tool
200 Name="VCLibrarianTool"
201 OutputFile="$(OutDir)/llvfs.lib"
202 />
203 <Tool
204 Name="VCALinkTool"
205 />
206 <Tool
207 Name="VCXDCMakeTool"
208 />
209 <Tool
210 Name="VCBscMakeTool"
211 />
212 <Tool
213 Name="VCFxCopTool"
214 />
215 <Tool
216 Name="VCPostBuildEventTool"
217 />
218 </Configuration>
219 </Configurations>
220 <References>
221 </References>
222 <Files>
223 <Filter
224 Name="Source Files"
225 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
226 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
227 >
228 <File
229 RelativePath=".\lldir.cpp"
230 >
231 </File>
232 <File
233 RelativePath=".\lldir_win32.cpp"
234 >
235 </File>
236 <File
237 RelativePath=".\lllfsthread.cpp"
238 >
239 </File>
240 <File
241 RelativePath=".\llvfile.cpp"
242 >
243 </File>
244 <File
245 RelativePath=".\llvfs.cpp"
246 >
247 </File>
248 <File
249 RelativePath=".\llvfsthread.cpp"
250 >
251 </File>
252 </Filter>
253 <Filter
254 Name="Header Files"
255 Filter="h;hpp;hxx;hm;inl;inc;xsd"
256 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
257 >
258 <File
259 RelativePath=".\lldir.h"
260 >
261 </File>
262 <File
263 RelativePath=".\lldir_win32.h"
264 >
265 </File>
266 <File
267 RelativePath=".\lllfsthread.h"
268 >
269 </File>
270 <File
271 RelativePath=".\llvfile.h"
272 >
273 </File>
274 <File
275 RelativePath=".\llvfs.h"
276 >
277 </File>
278 <File
279 RelativePath=".\llvfsthread.h"
280 >
281 </File>
282 </Filter>
283 <Filter
284 Name="Resource Files"
285 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
286 UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
287 >
288 </Filter>
289 </Files>
290 <Globals>
291 </Globals>
292</VisualStudioProject>
diff --git a/linden/indra/llvfs/llvfsthread.cpp b/linden/indra/llvfs/llvfsthread.cpp
index be23bd5..9226230 100644
--- a/linden/indra/llvfs/llvfsthread.cpp
+++ b/linden/indra/llvfs/llvfsthread.cpp
@@ -39,10 +39,10 @@
39//============================================================================ 39//============================================================================
40// Run on MAIN thread 40// Run on MAIN thread
41//static 41//static
42void LLVFSThread::initClass(bool local_is_threaded, bool local_run_always) 42void LLVFSThread::initClass(bool local_is_threaded)
43{ 43{
44 llassert(sLocal == NULL); 44 llassert(sLocal == NULL);
45 sLocal = new LLVFSThread(local_is_threaded, local_run_always); 45 sLocal = new LLVFSThread(local_is_threaded);
46} 46}
47 47
48//static 48//static
@@ -66,8 +66,8 @@ void LLVFSThread::cleanupClass()
66 66
67//---------------------------------------------------------------------------- 67//----------------------------------------------------------------------------
68 68
69LLVFSThread::LLVFSThread(bool threaded, bool runalways) : 69LLVFSThread::LLVFSThread(bool threaded) :
70 LLQueuedThread("VFS", threaded, runalways) 70 LLQueuedThread("VFS", threaded)
71{ 71{
72} 72}
73 73
@@ -164,38 +164,26 @@ S32 LLVFSThread::writeImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAsset
164} 164}
165 165
166 166
167LLVFSThread::handle_t LLVFSThread::rename(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, 167// LLVFSThread::handle_t LLVFSThread::rename(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
168 const LLUUID &new_id, const LLAssetType::EType new_type, U32 flags) 168// const LLUUID &new_id, const LLAssetType::EType new_type, U32 flags)
169{ 169// {
170 handle_t handle = generateHandle(); 170// handle_t handle = generateHandle();
171 171
172 LLUUID* new_idp = new LLUUID(new_id); // deleted with Request 172// LLUUID* new_idp = new LLUUID(new_id); // deleted with Request
173 // new_type is passed as "numbytes" 173// // new_type is passed as "numbytes"
174 Request* req = new Request(handle, 0, flags, FILE_RENAME, vfs, file_id, file_type, 174// Request* req = new Request(handle, 0, flags, FILE_RENAME, vfs, file_id, file_type,
175 (U8*)new_idp, 0, (S32)new_type); 175// (U8*)new_idp, 0, (S32)new_type);
176 176
177 bool res = addRequest(req); 177// bool res = addRequest(req);
178 if (!res) 178// if (!res)
179 { 179// {
180 llerrs << "LLVFSThread::read called after LLVFSThread::cleanupClass()" << llendl; 180// llerrs << "LLVFSThread::read called after LLVFSThread::cleanupClass()" << llendl;
181 req->deleteRequest(); 181// req->deleteRequest();
182 handle = nullHandle(); 182// handle = nullHandle();
183 } 183// }
184 184
185 return handle; 185// return handle;
186} 186// }
187
188//============================================================================
189// Runs on its OWN thread
190
191bool LLVFSThread::processRequest(QueuedRequest* qreq)
192{
193 Request *req = (Request*)qreq;
194
195 bool complete = req->processIO();
196
197 return complete;
198}
199 187
200//============================================================================ 188//============================================================================
201 189
@@ -242,7 +230,7 @@ LLVFSThread::Request::Request(handle_t handle, U32 priority, U32 flags,
242} 230}
243 231
244// dec locks as soon as a request finishes 232// dec locks as soon as a request finishes
245void LLVFSThread::Request::finishRequest() 233void LLVFSThread::Request::finishRequest(bool completed)
246{ 234{
247 if (mOperation == FILE_WRITE) 235 if (mOperation == FILE_WRITE)
248 { 236 {
@@ -260,13 +248,13 @@ void LLVFSThread::Request::finishRequest()
260 248
261void LLVFSThread::Request::deleteRequest() 249void LLVFSThread::Request::deleteRequest()
262{ 250{
263 if (getStatus() == STATUS_QUEUED || getStatus() == STATUS_ABORT) 251 if (getStatus() == STATUS_QUEUED)
264 { 252 {
265 llerrs << "Attempt to delete a queued LLVFSThread::Request!" << llendl; 253 llerrs << "Attempt to delete a queued LLVFSThread::Request!" << llendl;
266 } 254 }
267 if (mOperation == FILE_WRITE) 255 if (mOperation == FILE_WRITE)
268 { 256 {
269 if (mFlags & AUTO_DELETE) 257 if (mFlags & FLAG_AUTO_DELETE)
270 { 258 {
271 delete [] mBuffer; 259 delete [] mBuffer;
272 } 260 }
@@ -279,7 +267,7 @@ void LLVFSThread::Request::deleteRequest()
279 LLQueuedThread::QueuedRequest::deleteRequest(); 267 LLQueuedThread::QueuedRequest::deleteRequest();
280} 268}
281 269
282bool LLVFSThread::Request::processIO() 270bool LLVFSThread::Request::processRequest()
283{ 271{
284 bool complete = false; 272 bool complete = false;
285 if (mOperation == FILE_READ) 273 if (mOperation == FILE_READ)
@@ -302,7 +290,7 @@ bool LLVFSThread::Request::processIO()
302 mVFS->renameFile(mFileID, mFileType, *new_idp, new_type); 290 mVFS->renameFile(mFileID, mFileType, *new_idp, new_type);
303 mFileID = *new_idp; 291 mFileID = *new_idp;
304 complete = true; 292 complete = true;
305 //llinfos << llformat("LLVFSThread::WRITE '%s': %d bytes arg:%d",getFilename(),mBytesRead) << llendl; 293 //llinfos << llformat("LLVFSThread::RENAME '%s': %d bytes arg:%d",getFilename(),mBytesRead) << llendl;
306 } 294 }
307 else 295 else
308 { 296 {
diff --git a/linden/indra/llvfs/llvfsthread.h b/linden/indra/llvfs/llvfsthread.h
index c3a5a55..3c90808 100644
--- a/linden/indra/llvfs/llvfsthread.h
+++ b/linden/indra/llvfs/llvfsthread.h
@@ -83,15 +83,14 @@ public:
83 } 83 }
84 std::string getFilename() 84 std::string getFilename()
85 { 85 {
86 char tbuf[40]; 86 char tbuf[40]; /* Flawfinder: ignore */
87 mFileID.toString(tbuf); 87 mFileID.toString(tbuf);
88 return std::string(tbuf); 88 return std::string(tbuf);
89 } 89 }
90 90
91 /*virtual*/ void finishRequest(); 91 /*virtual*/ bool processRequest();
92 /*virtual*/ void finishRequest(bool completed);
92 /*virtual*/ void deleteRequest(); 93 /*virtual*/ void deleteRequest();
93
94 bool processIO();
95 94
96 private: 95 private:
97 operation_t mOperation; 96 operation_t mOperation;
@@ -109,19 +108,20 @@ public:
109 //------------------------------------------------------------------------ 108 //------------------------------------------------------------------------
110public: 109public:
111 static std::string sDataPath; 110 static std::string sDataPath;
112 static void setDataPath(const std::string& path) { sDataPath = path; } 111 static LLVFSThread* sLocal; // Default worker thread
113 112
114public: 113public:
115 LLVFSThread(bool threaded = TRUE, bool runalways = TRUE); 114 LLVFSThread(bool threaded = TRUE);
116 ~LLVFSThread(); 115 ~LLVFSThread();
117 116
118 // Return a Request handle 117 // Return a Request handle
119 handle_t read(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, 118 handle_t read(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, /* Flawfinder: ignore */
120 U8* buffer, S32 offset, S32 numbytes, U32 pri=PRIORITY_NORMAL, U32 flags = 0); 119 U8* buffer, S32 offset, S32 numbytes, U32 pri=PRIORITY_NORMAL, U32 flags = 0);
121 handle_t write(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, 120 handle_t write(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
122 U8* buffer, S32 offset, S32 numbytes, U32 flags); 121 U8* buffer, S32 offset, S32 numbytes, U32 flags);
123 handle_t rename(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, 122 // SJB: rename seems to have issues, especially when threaded
124 const LLUUID &new_id, const LLAssetType::EType new_type, U32 flags); 123// handle_t rename(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
124// const LLUUID &new_id, const LLAssetType::EType new_type, U32 flags);
125 // Return number of bytes read 125 // Return number of bytes read
126 S32 readImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type, 126 S32 readImmediate(LLVFS* vfs, const LLUUID &file_id, const LLAssetType::EType file_type,
127 U8* buffer, S32 offset, S32 numbytes); 127 U8* buffer, S32 offset, S32 numbytes);
@@ -130,12 +130,11 @@ public:
130 130
131 /*virtual*/ bool processRequest(QueuedRequest* req); 131 /*virtual*/ bool processRequest(QueuedRequest* req);
132 132
133 static void initClass(bool local_is_threaded = TRUE, bool run_always = TRUE); // Setup sLocal 133public:
134 static void initClass(bool local_is_threaded = TRUE); // Setup sLocal
134 static S32 updateClass(U32 ms_elapsed); 135 static S32 updateClass(U32 ms_elapsed);
135 static void cleanupClass(); // Delete sLocal 136 static void cleanupClass(); // Delete sLocal
136 137 static void setDataPath(const std::string& path) { sDataPath = path; }
137public:
138 static LLVFSThread* sLocal; // Default worker thread
139}; 138};
140 139
141//============================================================================ 140//============================================================================