Merge m-c to m-i
authorPhil Ringnalda <philringnalda@gmail.com>
Sun, 06 Jan 2013 09:38:33 -0800
changeset 126916 57e1f9c1910a43a6cbf9cebf67e1228a71422c67
parent 126915 ada416951818b6395c75cc49d1c395805e7e1bdf (current diff)
parent 126862 c4abfca219e5c438a69f65533dcb364ba9604c55 (diff)
child 126917 131e180f233e775ca474d6b56f2b027732e864c8
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge m-c to m-i
--- a/netwerk/cache/nsDiskCacheStreams.cpp
+++ b/netwerk/cache/nsDiskCacheStreams.cpp
@@ -11,16 +11,20 @@
 #include "nsDiskCacheStreams.h"
 #include "nsCacheService.h"
 #include "mozilla/FileUtils.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 
 
+// we pick 16k as the max buffer size because that is the threshold above which
+//      we are unable to store the data in the cache block files
+//      see nsDiskCacheMap.[cpp,h]
+#define kMaxBufferSize      (16 * 1024)
 
 // Assumptions:
 //      - cache descriptors live for life of streams
 //      - streams will only be used by FileTransport,
 //         they will not be directly accessible to clients
 //      - overlapped I/O is NOT supported
 
 
@@ -285,32 +289,23 @@ nsDiskCacheOutputStream::IsNonBlocking(b
 
 
 
 /******************************************************************************
  *  nsDiskCacheStreamIO
  *****************************************************************************/
 NS_IMPL_THREADSAFE_ISUPPORTS0(nsDiskCacheStreamIO)
 
-// we pick 16k as the max buffer size because that is the threshold above which
-//      we are unable to store the data in the cache block files
-//      see nsDiskCacheMap.[cpp,h]
-#define kMaxBufferSize      (16 * 1024)
-
 nsDiskCacheStreamIO::nsDiskCacheStreamIO(nsDiskCacheBinding *   binding)
     : mBinding(binding)
     , mOutStream(nullptr)
     , mInStreamCount(0)
     , mFD(nullptr)
-    , mStreamPos(0)
     , mStreamEnd(0)
-    , mBufPos(0)
-    , mBufEnd(0)
     , mBufSize(0)
-    , mBufDirty(false)
     , mBuffer(nullptr)
 {
     mDevice = (nsDiskCacheDevice *)mBinding->mCacheEntry->CacheDevice();
 
     // acquire "death grip" on cache service
     nsCacheService *service = nsCacheService::GlobalInstance();
     NS_ADDREF(service);
 }
@@ -367,17 +362,17 @@ nsDiskCacheStreamIO::GetInputStream(uint
     } else if (mBinding->mRecord.DataFile() == 0) {
         // open file desc for data
         rv = OpenCacheFile(PR_RDONLY, &fd);
         if (NS_FAILED(rv))  return rv;  // unable to open file        
         NS_ASSERTION(fd, "cache stream lacking open file.");
             
     } else if (!mBuffer) {
         // read block file for data
-        rv = ReadCacheBlocks();
+        rv = ReadCacheBlocks(mStreamEnd);
         if (NS_FAILED(rv))  return rv;
     }
     // else, mBuffer already contains all of the data (left over from a
     // previous block-file read or write).
 
     NS_ASSERTION(!(fd && mBuffer), "ambiguous data sources for input stream");
 
     // create a new input stream
@@ -397,28 +392,20 @@ nsDiskCacheStreamIO::GetOutputStream(uin
     *outputStream = nullptr;
 
     if (!mBinding)  return NS_ERROR_NOT_AVAILABLE;
         
     NS_ASSERTION(!mOutStream, "already have an output stream open");
     NS_ASSERTION(mInStreamCount == 0, "we already have input streams open");
     if (mOutStream || mInStreamCount)  return NS_ERROR_NOT_AVAILABLE;
     
-    // mBuffer lazily allocated, but might exist if a previous stream already
-    // created one.
-    mBufPos    = 0;
-    mStreamPos = 0;
     mStreamEnd = mBinding->mCacheEntry->DataSize();
 
-    nsresult rv;
-    if (offset) {
-        rv = Seek(PR_SEEK_SET, offset);
-        if (NS_FAILED(rv)) return rv;
-    }
-    rv = SetEOF();
+    // Inits file or buffer and truncate at the desired offset
+    nsresult rv = SeekAndTruncate(offset);
     if (NS_FAILED(rv)) return rv;
 
     // create a new output stream
     mOutStream = new nsDiskCacheOutputStream(this);
     if (!mOutStream)  return NS_ERROR_OUT_OF_MEMORY;
     
     NS_ADDREF(*outputStream = mOutStream);
     return NS_OK;
@@ -434,116 +421,99 @@ nsDiskCacheStreamIO::ClearBinding()
     return rv;
 }
 
 nsresult
 nsDiskCacheStreamIO::CloseOutputStream(nsDiskCacheOutputStream *  outputStream)
 {
     nsCacheServiceAutoLock lock(LOCK_TELEM(NSDISKCACHESTREAMIO_CLOSEOUTPUTSTREAM)); // grab service lock
 
-    nsresult   rv;
-
     if (outputStream != mOutStream) {
         NS_WARNING("mismatched output streams");
         return NS_ERROR_UNEXPECTED;
     }
 
     // output stream is closing
     if (!mBinding) {    // if we're severed, just clear member variables
-        NS_ASSERTION(!mBufDirty, "oops");
         mOutStream = nullptr;
         outputStream->ReleaseStreamIO();
         return NS_ERROR_NOT_AVAILABLE;
     }
 
-    rv = Flush();
+    nsresult rv = Flush();
     if (NS_FAILED(rv))
         NS_WARNING("Flush() failed");
 
     mOutStream = nullptr;
     return rv;
 }
 
 nsresult
 nsDiskCacheStreamIO::Flush()
 {
     NS_ASSERTION(mBinding, "oops");
 
     CACHE_LOG_DEBUG(("CACHE: Flush [%x doomed=%u]\n",
         mBinding->mRecord.HashNumber(), mBinding->mDoomed));
 
-    if (!mBufDirty) {
-        if (mFD) {
-            (void) PR_Close(mFD);
-            mFD = nullptr;
-        }
+    // When writing to a file, just close the file
+    if (mFD) {
+        (void) PR_Close(mFD);
+        mFD = nullptr;
         return NS_OK;
     }
 
     // write data to cache blocks, or flush mBuffer to file
     nsDiskCacheMap *cacheMap = mDevice->CacheMap();  // get map reference
     nsresult rv;
 
     bool written = false;
 
     if (mStreamEnd <= kMaxBufferSize) {
         // store data (if any) in cache block files
 
-        mBufDirty = false;
-
         // delete existing storage
         nsDiskCacheRecord * record = &mBinding->mRecord;
         if (record->DataLocationInitialized()) {
             rv = cacheMap->DeleteStorage(record, nsDiskCache::kData);
             if (NS_FAILED(rv)) {
                 NS_WARNING("cacheMap->DeleteStorage() failed.");
                 return rv;
             }
-            if (mFD) {
-                PR_Close(mFD);
-                mFD = nullptr;
-            }
         }
 
         // flush buffer to block files
         written = true;
         if (mStreamEnd > 0) {
-            rv = cacheMap->WriteDataCacheBlocks(mBinding, mBuffer, mBufEnd);
+            rv = cacheMap->WriteDataCacheBlocks(mBinding, mBuffer, mStreamEnd);
             if (NS_FAILED(rv)) {
                 NS_WARNING("WriteDataCacheBlocks() failed.");
                 written = false;
             }
         }
     }
 
     if (!written) {
-        // make sure we save as separate file
+        // failed to store in cacheblocks, save as separate file
         rv = FlushBufferToFile(); // initializes DataFileLocation() if necessary
 
         if (mFD) {
           // Update the file size of the disk file in the cache
           UpdateFileSize();
 
           // close file descriptor
           (void) PR_Close(mFD);
           mFD = nullptr;
         }
         else
           NS_WARNING("no file descriptor");
 
         // close mFD first if possible before returning if FlushBufferToFile
         // failed
         NS_ENSURE_SUCCESS(rv, rv);
-
-        // since the data location is on disk as a single file, the only value
-        // in keeping mBuffer around is to avoid an extra malloc the next time
-        // we need to write to this file.  reading will use a file descriptor.
-        // therefore, it's probably not worth optimizing for the subsequent
-        // write, so we unconditionally delete mBuffer here.
-        DeleteBuffer();
     }
     
     // XXX do we need this here?  WriteDataCacheBlocks() calls UpdateRecord()
     // update cache map if entry isn't doomed
     if (!mBinding->mDoomed) {
         rv = cacheMap->UpdateRecord(&mBinding->mRecord);
         if (NS_FAILED(rv)) {
             NS_WARNING("cacheMap->UpdateRecord() failed.");
@@ -560,84 +530,75 @@ nsDiskCacheStreamIO::Flush()
 //      never have both output and input streams open
 //      OnDataSizeChanged() will have already been called to update entry->DataSize()
 
 nsresult
 nsDiskCacheStreamIO::Write( const char * buffer,
                             uint32_t     count,
                             uint32_t *   bytesWritten)
 {
-    nsresult    rv = NS_OK;
-    nsCacheServiceAutoLock lock(LOCK_TELEM(NSDISKCACHESTREAMIO_WRITE)); // grab service lock
+    // grab service lock
+    nsCacheServiceAutoLock lock(LOCK_TELEM(NSDISKCACHESTREAMIO_WRITE));
     if (!mBinding)  return NS_ERROR_NOT_AVAILABLE;
 
     if (mInStreamCount) {
         // we have open input streams already
         // this is an error until we support overlapped I/O
         NS_WARNING("Attempting to write to cache entry with open input streams.\n");
         return NS_ERROR_NOT_AVAILABLE;
     }
 
     NS_ASSERTION(count, "Write called with count of zero");
-    NS_ASSERTION(mBufPos <= mBufEnd, "streamIO buffer corrupted");
 
-    uint32_t bytesLeft = count;
-    bool     flushed = false;
-    
-    while (bytesLeft) {
-        if (mBufPos == mBufSize) {
-            if (mBufSize < kMaxBufferSize) {
-                mBufSize = kMaxBufferSize;
-                char *buffer = mBuffer;
+    // Not writing to file, and it will fit in the cachedatablocks?
+    if (!mFD && (mStreamEnd + count <= kMaxBufferSize)) {
 
-                mBuffer  = (char *) realloc(mBuffer, mBufSize);
-                if (!mBuffer) {
-                    free(buffer);
-                    mBufSize = 0;
-                    break;
-                }
-            } else {
-                nsresult rv = FlushBufferToFile();
-                if (NS_FAILED(rv))  break;
-                flushed = true;
+        // We have more data than the current buffer size?
+        if ((mStreamEnd + count > mBufSize) && (mBufSize < kMaxBufferSize)) {
+            // Try to increase buffer to the max size, no problem if not 
+            // succesful, we just use what is available.
+            char *newbuf = (char *) realloc(mBuffer, kMaxBufferSize);
+            if (newbuf) {
+                // Use the new larger buffer
+                mBuffer = newbuf;
+                mBufSize = kMaxBufferSize;
             }
         }
-        
-        uint32_t chunkSize = bytesLeft;
-        if (chunkSize > (mBufSize - mBufPos))
-            chunkSize =  mBufSize - mBufPos;
-        
-        memcpy(mBuffer + mBufPos, buffer, chunkSize);
-        mBufDirty = true;
-        mBufPos += chunkSize;
-        bytesLeft -= chunkSize;
-        buffer += chunkSize;
-        
-        if (mBufEnd < mBufPos)
-            mBufEnd = mBufPos;
+
+        // Store in the buffer but only if it fits
+        if ((count > 0) && (mStreamEnd + count <= mBufSize)) {
+            memcpy(mBuffer + mStreamEnd, buffer, count);
+            mStreamEnd += count;
+            *bytesWritten = count;
+            return NS_OK;
+        }
     }
-    if (bytesLeft) {
+
+    // There are more bytes than fit in the buffer/cacheblocks, switch to file
+    if (!mFD) {
+        // Opens a cache file and write the buffer to it
+        nsresult rv = FlushBufferToFile();
+        if (NS_FAILED(rv)) {
+            *bytesWritten = 0;
+            return rv;
+        }
+    }
+    // Write directly to the file
+    if (PR_Write(mFD, buffer, count) != (int32_t)count) {
+        NS_WARNING("failed to write all data");
         *bytesWritten = 0;
-        return NS_ERROR_FAILURE;
+        return NS_ERROR_UNEXPECTED;     // NS_ErrorAccordingToNSPR()
     }
+    mStreamEnd += count;
     *bytesWritten = count;
 
-    // update mStreamPos, mStreamEnd
-    mStreamPos += count;
-    if (mStreamEnd < mStreamPos) {
-        mStreamEnd = mStreamPos;
-        NS_ASSERTION(mBinding->mCacheEntry->DataSize() == mStreamEnd, "bad stream");
+    UpdateFileSize();
+    NS_ASSERTION(mBinding->mCacheEntry->DataSize() == mStreamEnd, "bad stream");
 
-        // If we have flushed to a file, update the file size
-        if (flushed && mFD) {
-            UpdateFileSize();
-        }
-    }
-    
-    return rv;
+    return NS_OK;
 }
 
 
 void
 nsDiskCacheStreamIO::UpdateFileSize()
 {
     NS_ASSERTION(mFD, "nsDiskCacheStreamIO::UpdateFileSize should not have been called");
     
@@ -686,45 +647,39 @@ nsDiskCacheStreamIO::OpenCacheFile(int f
     if (NS_FAILED(rv))  return rv;
     
     // create PRFileDesc for input stream - the 00600 is just for consistency
     return localFile->OpenNSPRFileDesc(flags, 00600, fd);
 }
 
 
 nsresult
-nsDiskCacheStreamIO::ReadCacheBlocks()
+nsDiskCacheStreamIO::ReadCacheBlocks(uint32_t bufferSize)
 {
     NS_ASSERTION(mStreamEnd == mBinding->mCacheEntry->DataSize(), "bad stream");
-    NS_ASSERTION(mStreamEnd <= kMaxBufferSize, "data too large for buffer");
+    NS_ASSERTION(bufferSize <= kMaxBufferSize, "bufferSize too large for buffer");
+    NS_ASSERTION(mStreamEnd <= bufferSize, "data too large for buffer");
 
     nsDiskCacheRecord * record = &mBinding->mRecord;
     if (!record->DataLocationInitialized()) return NS_OK;
 
     NS_ASSERTION(record->DataFile() != kSeparateFile, "attempt to read cache blocks on separate file");
 
     if (!mBuffer) {
         // allocate buffer
-        mBuffer = (char *) malloc(mStreamEnd);
+        mBuffer = (char *) malloc(bufferSize);
         if (!mBuffer) {
             return NS_ERROR_OUT_OF_MEMORY;
         }
-        mBufSize = mStreamEnd;
+        mBufSize = bufferSize;
     }
     
     // read data stored in cache block files
     nsDiskCacheMap *map = mDevice->CacheMap();  // get map reference
-    nsresult rv = map->ReadDataCacheBlocks(mBinding, mBuffer, mStreamEnd);
-    if (NS_FAILED(rv)) return rv;
-
-    // update streamIO variables
-    mBufPos = 0;
-    mBufEnd = mStreamEnd;
-    
-    return NS_OK;
+    return map->ReadDataCacheBlocks(mBinding, mBuffer, mStreamEnd);
 }
 
 
 nsresult
 nsDiskCacheStreamIO::FlushBufferToFile()
 {
     nsresult  rv;
     nsDiskCacheRecord * record = &mBinding->mRecord;
@@ -742,202 +697,89 @@ nsDiskCacheStreamIO::FlushBufferToFile()
         rv = OpenCacheFile(PR_RDWR | PR_CREATE_FILE, &mFD);
         if (NS_FAILED(rv))  return rv;
 
         int64_t dataSize = mBinding->mCacheEntry->PredictedDataSize();
         if (dataSize != -1)
             mozilla::fallocate(mFD, NS_MIN<int64_t>(dataSize, kPreallocateLimit));
     }
     
-    // write buffer
-    int32_t bytesWritten = PR_Write(mFD, mBuffer, mBufEnd);
-    if (uint32_t(bytesWritten) != mBufEnd) {
+    // write buffer to the file
+    if (PR_Write(mFD, mBuffer, mStreamEnd) != (int32_t)mStreamEnd) {
         NS_WARNING("failed to flush all data");
         return NS_ERROR_UNEXPECTED;     // NS_ErrorAccordingToNSPR()
     }
-    mBufDirty = false;
-    
-    // reset buffer
-    mBufPos = 0;
-    mBufEnd = 0;
-    
+
+    // buffer is no longer valid
+    DeleteBuffer();
+   
     return NS_OK;
 }
 
 
 void
 nsDiskCacheStreamIO::DeleteBuffer()
 {
     if (mBuffer) {
-        NS_ASSERTION(!mBufDirty, "deleting dirty buffer");
         free(mBuffer);
         mBuffer = nullptr;
-        mBufPos = 0;
-        mBufEnd = 0;
         mBufSize = 0;
     }
 }
 
 size_t
 nsDiskCacheStreamIO::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
 {
     size_t usage = aMallocSizeOf(this);
 
     usage += aMallocSizeOf(mFD);
     usage += aMallocSizeOf(mBuffer);
 
     return usage;
 }
 
-// NOTE: called with service lock held
 nsresult
-nsDiskCacheStreamIO::Seek(int32_t whence, int32_t offset)
+nsDiskCacheStreamIO::SeekAndTruncate(uint32_t offset)
 {
-    int32_t  newPos;
     if (!mBinding)  return NS_ERROR_NOT_AVAILABLE;
     
     if (uint32_t(offset) > mStreamEnd)  return NS_ERROR_FAILURE;
     
-    if (mBinding->mRecord.DataLocationInitialized()) {
-        if (mBinding->mRecord.DataFile() == 0) {
-            if (!mFD) {
-                // we need an mFD, we better open it now
-                nsresult rv = OpenCacheFile(PR_RDWR | PR_CREATE_FILE, &mFD);
-                if (NS_FAILED(rv))  return rv;
-            }
-        }
-    }
-    
-    if (mFD) {
-        // do we have data in the buffer that needs to be flushed?
-        if (mBufDirty) {
-            // XXX optimization: are we just moving within the current buffer?
-            nsresult rv = FlushBufferToFile();
+    // Set the current end to the desired offset
+    mStreamEnd = offset;
+
+    // Currently stored in file?
+    if (mBinding->mRecord.DataLocationInitialized() && 
+        (mBinding->mRecord.DataFile() == 0)) {
+        if (!mFD) {
+            // we need an mFD, we better open it now
+            nsresult rv = OpenCacheFile(PR_RDWR | PR_CREATE_FILE, &mFD);
             if (NS_FAILED(rv))  return rv;
         }
-        
-        newPos = PR_Seek(mFD, offset, (PRSeekWhence)whence);
-        if (newPos == -1)
-            return NS_ErrorAccordingToNSPR();
-        
-        mStreamPos = (uint32_t) newPos;
-        mBufPos = 0;
-        mBufEnd = 0;
+        if (offset) {
+            if (PR_Seek(mFD, offset, PR_SEEK_SET) == -1)
+                return NS_ErrorAccordingToNSPR();
+        }
+        nsDiskCache::Truncate(mFD, offset);
+        UpdateFileSize();
+
+        // When we starting at zero again, close file and start with buffer.
+        // If offset is non-zero (and within buffer) an option would be
+        // to read the file into the buffer, but chance is high that it is 
+        // rewritten to the file anyway.
+        if (offset == 0) {
+            // close file descriptor
+            (void) PR_Close(mFD);
+            mFD = nullptr;
+        }
         return NS_OK;
     }
     
-    // else, seek in mBuffer
-    
-    switch(whence) {
-        case PR_SEEK_SET:
-            newPos = offset;
-            break;
-            
-        case PR_SEEK_CUR:   // relative from current posistion
-            newPos = offset + (uint32_t)mStreamPos;
-            break;
-            
-        case PR_SEEK_END:   // relative from end
-            newPos = offset + (uint32_t)mBufEnd;
-            break;
-            
-        default:
-            return NS_ERROR_INVALID_ARG;
-    }
-    
     // read data into mBuffer if not read yet.
-    if (mStreamEnd && !mBufEnd) {
-        if (newPos > 0) {
-            nsresult rv = ReadCacheBlocks();
-            if (NS_FAILED(rv))  return rv;
-        }
+    if (offset && !mBuffer) {
+        nsresult rv = ReadCacheBlocks(kMaxBufferSize);
+        if (NS_FAILED(rv))  return rv;
     }
-    
-    // stream buffer sanity checks
-    NS_ASSERTION(mBufEnd <= kMaxBufferSize, "bad stream");
-    NS_ASSERTION(mBufPos <= mBufEnd,     "bad stream");
-    NS_ASSERTION(mStreamPos == mBufPos,  "bad stream");
-    NS_ASSERTION(mStreamEnd == mBufEnd,  "bad stream");
-    
-    if ((newPos < 0) || (uint32_t(newPos) > mBufEnd)) {
-        NS_WARNING("seek offset out of range");
-        return NS_ERROR_INVALID_ARG;
-    }
-    
-    mStreamPos = newPos;
-    mBufPos    = newPos;
-    return NS_OK;
-}
 
-
-// called only from nsDiskCacheOutputStream::Tell
-nsresult
-nsDiskCacheStreamIO::Tell(uint32_t * result)
-{
-    NS_ENSURE_ARG_POINTER(result);
-    *result = mStreamPos;
+    // stream buffer sanity check
+    NS_ASSERTION(mStreamEnd <= kMaxBufferSize, "bad stream");
     return NS_OK;
 }
-
-
-// NOTE: called with service lock held
-nsresult
-nsDiskCacheStreamIO::SetEOF()
-{
-    nsresult    rv;
-    bool        needToCloseFD = false;
-    
-    NS_ASSERTION(mStreamPos <= mStreamEnd, "bad stream");
-    if (!mBinding)  return NS_ERROR_NOT_AVAILABLE;
-    
-    if (mBinding->mRecord.DataLocationInitialized()) {
-        if (mBinding->mRecord.DataFile() == 0) {
-            if (!mFD) {
-                // we need an mFD, we better open it now
-                rv = OpenCacheFile(PR_RDWR | PR_CREATE_FILE, &mFD);
-                if (NS_FAILED(rv))  return rv;
-                needToCloseFD = true;
-            }
-        } else {
-            // data in cache block files
-            if ((mStreamPos != 0) && (mStreamPos != mBufPos)) {
-                // only read data if there will be some left after truncation
-                rv = ReadCacheBlocks();
-                if (NS_FAILED(rv))  return rv;
-            }
-            
-            // We need to make sure we reflect this change in Flush().
-            // In particular, if mStreamPos is 0 and we never write to
-            // the buffer, we want the storage to be deleted.
-            mBufDirty = true;
-        }
-    }
-    
-    if (mFD) {
-        rv = nsDiskCache::Truncate(mFD, mStreamPos);
-#ifdef DEBUG
-        uint32_t oldSizeK = (mStreamEnd + 0x03FF) >> 10;
-        NS_ASSERTION(mBinding->mRecord.DataFileSize() == oldSizeK, "bad disk cache entry size");
-    } else {
-        // data stored in buffer.
-        NS_ASSERTION(mStreamEnd <= kMaxBufferSize, "buffer truncation inadequate");
-        NS_ASSERTION(mBufPos == mStreamPos, "bad stream");
-        NS_ASSERTION(mBuffer ? mBufEnd == mStreamEnd : true, "bad stream");
-#endif
-    }
-
-    NS_ASSERTION(mStreamEnd == mBinding->mCacheEntry->DataSize(), "cache entry not updated");
-    // we expect nsCacheEntryDescriptor::TransportWrapper::OpenOutputStream()
-    // to eventually update the cache entry
-
-    mStreamEnd  = mStreamPos;
-    mBufEnd     = mBufPos;
-
-    if (mFD) {
-        UpdateFileSize();
-        if (needToCloseFD) {
-            (void) PR_Close(mFD);
-            mFD = nullptr;
-        }
-    }
-
-    return  NS_OK;
-}
--- a/netwerk/cache/nsDiskCacheStreams.h
+++ b/netwerk/cache/nsDiskCacheStreams.h
@@ -32,54 +32,46 @@ public:
     nsresult    GetOutputStream(uint32_t offset, nsIOutputStream ** outputStream);
 
     nsresult    CloseOutputStream(nsDiskCacheOutputStream * outputStream);
 
     nsresult    Write( const char * buffer,
                        uint32_t     count,
                        uint32_t *   bytesWritten);
 
-    nsresult    Seek(int32_t whence, int32_t offset);
-    nsresult    Tell(uint32_t * position);    
-    nsresult    SetEOF();
-
     nsresult    ClearBinding();
     
     void        IncrementInputStreamCount() { PR_ATOMIC_INCREMENT(&mInStreamCount); }
     void        DecrementInputStreamCount()
                 {
                     PR_ATOMIC_DECREMENT(&mInStreamCount);
                     NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative");
                 }
 
     size_t     SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
 
     // GCC 2.95.2 requires this to be defined, although we never call it.
     // and OS/2 requires that it not be private
     nsDiskCacheStreamIO() { NS_NOTREACHED("oops"); }
+
 private:
 
-
     void        Close();
     nsresult    OpenCacheFile(int flags, PRFileDesc ** fd);
-    nsresult    ReadCacheBlocks();
+    nsresult    ReadCacheBlocks(uint32_t bufferSize);
     nsresult    FlushBufferToFile();
     void        UpdateFileSize();
     void        DeleteBuffer();
     nsresult    Flush();
+    nsresult    SeekAndTruncate(uint32_t offset);
 
     nsDiskCacheBinding *        mBinding;       // not an owning reference
     nsDiskCacheDevice *         mDevice;
     nsDiskCacheOutputStream *   mOutStream;     // not an owning reference
     int32_t                     mInStreamCount;
     PRFileDesc *                mFD;
 
-    uint32_t                    mStreamPos;     // for Output Streams
-    uint32_t                    mStreamEnd;
-    uint32_t                    mBufPos;        // current mark in buffer
-    uint32_t                    mBufEnd;        // current end of data in buffer
+    uint32_t                    mStreamEnd;     // current size of data
     uint32_t                    mBufSize;       // current end of buffer
-    bool                        mBufDirty;
     char *                      mBuffer;
-    
 };
 
 #endif // _nsDiskCacheStreams_h_