diff options
author | Patrick Georgi <patrick.georgi@coresystems.de> | 2009-09-14 13:29:27 +0000 |
---|---|---|
committer | Patrick Georgi <patrick.georgi@coresystems.de> | 2009-09-14 13:29:27 +0000 |
commit | b7b56dd8fbe123958e196f396dab5ff3000b68dd (patch) | |
tree | 19972cda7bd87504eeea26ed90535e4aa7585da4 /util/cbfstool/tools/lzma/C/7zip/Common | |
parent | c8d4a05f8f5df06bd98f8ee7d5ef46e61986e6b0 (diff) |
New cbfstool. Works without mmap or fork/exec and
supports fixed location files. Some parts are salvaged
from the pre-commit version (esp. stage and payload creation),
others are completely rewritten (eg. the main loop that handles
file addition)
Also adapt newconfig (we don't need cbfs/tools anymore) and fix
some minor issues in the cbfstool-README.
Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Stefan Reinauer <stepan@coresystems.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4630 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/cbfstool/tools/lzma/C/7zip/Common')
-rw-r--r-- | util/cbfstool/tools/lzma/C/7zip/Common/InBuffer.h | 76 | ||||
-rw-r--r-- | util/cbfstool/tools/lzma/C/7zip/Common/OutBuffer.cpp | 116 | ||||
-rw-r--r-- | util/cbfstool/tools/lzma/C/7zip/Common/OutBuffer.h | 64 | ||||
-rw-r--r-- | util/cbfstool/tools/lzma/C/7zip/Common/StdAfx.h | 9 | ||||
-rw-r--r-- | util/cbfstool/tools/lzma/C/7zip/Common/StreamUtils.cpp | 44 | ||||
-rw-r--r-- | util/cbfstool/tools/lzma/C/7zip/Common/StreamUtils.h | 11 |
6 files changed, 0 insertions, 320 deletions
diff --git a/util/cbfstool/tools/lzma/C/7zip/Common/InBuffer.h b/util/cbfstool/tools/lzma/C/7zip/Common/InBuffer.h deleted file mode 100644 index 057caa1659..0000000000 --- a/util/cbfstool/tools/lzma/C/7zip/Common/InBuffer.h +++ /dev/null @@ -1,76 +0,0 @@ -// InBuffer.h - -#ifndef __INBUFFER_H -#define __INBUFFER_H - -#include "../IStream.h" -#include "../../Common/MyCom.h" - -#ifndef _NO_EXCEPTIONS -class CInBufferException -{ -public: - HRESULT ErrorCode; - CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {} -}; -#endif - -class CInBuffer -{ - Byte *_buffer; - Byte *_bufferLimit; - Byte *_bufferBase; - CMyComPtr<ISequentialInStream> _stream; - UInt64 _processedSize; - UInt32 _bufferSize; - bool _wasFinished; - - bool ReadBlock(); - Byte ReadBlock2(); - -public: - #ifdef _NO_EXCEPTIONS - HRESULT ErrorCode; - #endif - - CInBuffer(); - ~CInBuffer() { Free(); } - - bool Create(UInt32 bufferSize); - void Free(); - - void SetStream(ISequentialInStream *stream); - void Init(); - void ReleaseStream() { _stream.Release(); } - - bool ReadByte(Byte &b) - { - if(_buffer >= _bufferLimit) - if(!ReadBlock()) - return false; - b = *_buffer++; - return true; - } - Byte ReadByte() - { - if(_buffer >= _bufferLimit) - return ReadBlock2(); - return *_buffer++; - } - void ReadBytes(void *data, UInt32 size, UInt32 &processedSize) - { - for(processedSize = 0; processedSize < size; processedSize++) - if (!ReadByte(((Byte *)data)[processedSize])) - return; - } - bool ReadBytes(void *data, UInt32 size) - { - UInt32 processedSize; - ReadBytes(data, size, processedSize); - return (processedSize == size); - } - UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); } - bool WasFinished() const { return _wasFinished; } -}; - -#endif diff --git a/util/cbfstool/tools/lzma/C/7zip/Common/OutBuffer.cpp b/util/cbfstool/tools/lzma/C/7zip/Common/OutBuffer.cpp deleted file mode 100644 index a73fa7c5b9..0000000000 --- a/util/cbfstool/tools/lzma/C/7zip/Common/OutBuffer.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// OutByte.cpp - -#include "StdAfx.h" - -#include "OutBuffer.h" - -#include "../../Common/Alloc.h" - -bool COutBuffer::Create(UInt32 bufferSize) -{ - const UInt32 kMinBlockSize = 1; - if (bufferSize < kMinBlockSize) - bufferSize = kMinBlockSize; - if (_buffer != 0 && _bufferSize == bufferSize) - return true; - Free(); - _bufferSize = bufferSize; - _buffer = (Byte *)::MidAlloc(bufferSize); - return (_buffer != 0); -} - -void COutBuffer::Free() -{ - ::MidFree(_buffer); - _buffer = 0; -} - -void COutBuffer::SetStream(ISequentialOutStream *stream) -{ - _stream = stream; -} - -void COutBuffer::Init() -{ - _streamPos = 0; - _limitPos = _bufferSize; - _pos = 0; - _processedSize = 0; - _overDict = false; - #ifdef _NO_EXCEPTIONS - ErrorCode = S_OK; - #endif -} - -UInt64 COutBuffer::GetProcessedSize() const -{ - UInt64 res = _processedSize + _pos - _streamPos; - if (_streamPos > _pos) - res += _bufferSize; - return res; -} - - -HRESULT COutBuffer::FlushPart() -{ - // _streamPos < _bufferSize - UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos); - HRESULT result = S_OK; - #ifdef _NO_EXCEPTIONS - result = ErrorCode; - #endif - if (_buffer2 != 0) - { - memmove(_buffer2, _buffer + _streamPos, size); - _buffer2 += size; - } - - if (_stream != 0 - #ifdef _NO_EXCEPTIONS - && (ErrorCode == S_OK) - #endif - ) - { - UInt32 processedSize = 0; - result = _stream->Write(_buffer + _streamPos, size, &processedSize); - size = processedSize; - } - _streamPos += size; - if (_streamPos == _bufferSize) - _streamPos = 0; - if (_pos == _bufferSize) - { - _overDict = true; - _pos = 0; - } - _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize; - _processedSize += size; - return result; -} - -HRESULT COutBuffer::Flush() -{ - #ifdef _NO_EXCEPTIONS - if (ErrorCode != S_OK) - return ErrorCode; - #endif - - while(_streamPos != _pos) - { - HRESULT result = FlushPart(); - if (result != S_OK) - return result; - } - return S_OK; -} - -void COutBuffer::FlushWithCheck() -{ - HRESULT result = FlushPart(); - #ifdef _NO_EXCEPTIONS - ErrorCode = result; - #else - if (result != S_OK) - throw COutBufferException(result); - #endif -} diff --git a/util/cbfstool/tools/lzma/C/7zip/Common/OutBuffer.h b/util/cbfstool/tools/lzma/C/7zip/Common/OutBuffer.h deleted file mode 100644 index 0ce54e21e6..0000000000 --- a/util/cbfstool/tools/lzma/C/7zip/Common/OutBuffer.h +++ /dev/null @@ -1,64 +0,0 @@ -// OutBuffer.h - -#ifndef __OUTBUFFER_H -#define __OUTBUFFER_H - -#include "../IStream.h" -#include "../../Common/MyCom.h" - -#ifndef _NO_EXCEPTIONS -struct COutBufferException -{ - HRESULT ErrorCode; - COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {} -}; -#endif - -class COutBuffer -{ -protected: - Byte *_buffer; - UInt32 _pos; - UInt32 _limitPos; - UInt32 _streamPos; - UInt32 _bufferSize; - CMyComPtr<ISequentialOutStream> _stream; - UInt64 _processedSize; - Byte *_buffer2; - bool _overDict; - - HRESULT FlushPart(); - void FlushWithCheck(); -public: - #ifdef _NO_EXCEPTIONS - HRESULT ErrorCode; - #endif - - COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {} - ~COutBuffer() { Free(); } - - bool Create(UInt32 bufferSize); - void Free(); - - void SetMemStream(Byte *buffer) { _buffer2 = buffer; } - void SetStream(ISequentialOutStream *stream); - void Init(); - HRESULT Flush(); - void ReleaseStream() { _stream.Release(); } - - void WriteByte(Byte b) - { - _buffer[_pos++] = b; - if(_pos == _limitPos) - FlushWithCheck(); - } - void WriteBytes(const void *data, size_t size) - { - for (size_t i = 0; i < size; i++) - WriteByte(((const Byte *)data)[i]); - } - - UInt64 GetProcessedSize() const; -}; - -#endif diff --git a/util/cbfstool/tools/lzma/C/7zip/Common/StdAfx.h b/util/cbfstool/tools/lzma/C/7zip/Common/StdAfx.h deleted file mode 100644 index 27a77b104b..0000000000 --- a/util/cbfstool/tools/lzma/C/7zip/Common/StdAfx.h +++ /dev/null @@ -1,9 +0,0 @@ -// StdAfx.h - -#ifndef __STDAFX_H -#define __STDAFX_H - -#include "../../Common/MyWindows.h" -#include "../../Common/NewHandler.h" - -#endif diff --git a/util/cbfstool/tools/lzma/C/7zip/Common/StreamUtils.cpp b/util/cbfstool/tools/lzma/C/7zip/Common/StreamUtils.cpp deleted file mode 100644 index a5d9ac0ef0..0000000000 --- a/util/cbfstool/tools/lzma/C/7zip/Common/StreamUtils.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// StreamUtils.cpp - -#include "StdAfx.h" - -#include "../../Common/MyCom.h" -#include "StreamUtils.h" - -HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize) -{ - if (processedSize != 0) - *processedSize = 0; - while(size != 0) - { - UInt32 processedSizeLoc; - HRESULT res = stream->Read(data, size, &processedSizeLoc); - if (processedSize != 0) - *processedSize += processedSizeLoc; - data = (Byte *)((Byte *)data + processedSizeLoc); - size -= processedSizeLoc; - RINOK(res); - if (processedSizeLoc == 0) - return S_OK; - } - return S_OK; -} - -HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize) -{ - if (processedSize != 0) - *processedSize = 0; - while(size != 0) - { - UInt32 processedSizeLoc; - HRESULT res = stream->Write(data, size, &processedSizeLoc); - if (processedSize != 0) - *processedSize += processedSizeLoc; - data = (const void *)((const Byte *)data + processedSizeLoc); - size -= processedSizeLoc; - RINOK(res); - if (processedSizeLoc == 0) - break; - } - return S_OK; -} diff --git a/util/cbfstool/tools/lzma/C/7zip/Common/StreamUtils.h b/util/cbfstool/tools/lzma/C/7zip/Common/StreamUtils.h deleted file mode 100644 index 59f88733f6..0000000000 --- a/util/cbfstool/tools/lzma/C/7zip/Common/StreamUtils.h +++ /dev/null @@ -1,11 +0,0 @@ -// StreamUtils.h - -#ifndef __STREAMUTILS_H -#define __STREAMUTILS_H - -#include "../IStream.h" - -HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize); -HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize); - -#endif |