Author: zooey Date: 2011-01-30 16:05:38 +0100 (Sun, 30 Jan 2011) New Revision: 40320 Changeset: http://dev.haiku-os.org/changeset/40320 Added: haiku/trunk/headers/os/package/hpkg/ haiku/trunk/headers/os/package/hpkg/BlockBufferCache.h haiku/trunk/headers/os/package/hpkg/BufferCache.h haiku/trunk/headers/os/package/hpkg/DataOutput.h haiku/trunk/headers/os/package/hpkg/DataReader.h haiku/trunk/headers/os/package/hpkg/ErrorOutput.h haiku/trunk/headers/os/package/hpkg/HPKGDefs.h haiku/trunk/headers/os/package/hpkg/PackageAttributeValue.h haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h haiku/trunk/headers/os/package/hpkg/PackageData.h haiku/trunk/headers/os/package/hpkg/PackageDataReader.h haiku/trunk/headers/os/package/hpkg/PackageEntry.h haiku/trunk/headers/os/package/hpkg/PackageEntryAttribute.h haiku/trunk/headers/os/package/hpkg/PackageReader.h haiku/trunk/headers/os/package/hpkg/PackageWriter.h haiku/trunk/headers/private/package/hpkg/BlockBufferCacheImpl.h haiku/trunk/headers/private/package/hpkg/CachedBuffer.h haiku/trunk/headers/private/package/hpkg/FDCloser.h haiku/trunk/headers/private/package/hpkg/PackageReaderImpl.h haiku/trunk/headers/private/package/hpkg/PackageWriterImpl.h haiku/trunk/src/bin/package/BlockBufferCacheNoLock.cpp haiku/trunk/src/bin/package/BlockBufferCacheNoLock.h haiku/trunk/src/kits/package/hpkg/BlockBufferCacheImpl.cpp haiku/trunk/src/kits/package/hpkg/CachedBuffer.cpp haiku/trunk/src/kits/package/hpkg/ErrorOutput.cpp haiku/trunk/src/kits/package/hpkg/PackageContentHandler.cpp haiku/trunk/src/kits/package/hpkg/PackageReaderImpl.cpp haiku/trunk/src/kits/package/hpkg/PackageWriterImpl.cpp Removed: haiku/trunk/headers/private/package/hpkg/BlockBufferCache.h haiku/trunk/headers/private/package/hpkg/BufferCache.h haiku/trunk/headers/private/package/hpkg/DataOutput.h haiku/trunk/headers/private/package/hpkg/DataReader.h haiku/trunk/headers/private/package/hpkg/ErrorOutput.h haiku/trunk/headers/private/package/hpkg/FDCloser.h haiku/trunk/headers/private/package/hpkg/PackageAttributeValue.h haiku/trunk/headers/private/package/hpkg/PackageData.h haiku/trunk/headers/private/package/hpkg/PackageDataReader.h haiku/trunk/headers/private/package/hpkg/PackageEntry.h haiku/trunk/headers/private/package/hpkg/PackageEntryAttribute.h haiku/trunk/headers/private/package/hpkg/PackageReader.h haiku/trunk/headers/private/package/hpkg/PackageWriter.h haiku/trunk/src/kits/package/hpkg/ErrorOutput.cpp Modified: haiku/trunk/headers/private/package/hpkg/Stacker.h haiku/trunk/headers/private/package/hpkg/Strings.h haiku/trunk/headers/private/package/hpkg/ZlibCompressionBase.h haiku/trunk/headers/private/package/hpkg/ZlibCompressor.h haiku/trunk/headers/private/package/hpkg/ZlibDecompressor.h haiku/trunk/headers/private/package/hpkg/haiku_package.h haiku/trunk/src/add-ons/kernel/file_systems/packagefs/BlockBufferCacheKernel.cpp haiku/trunk/src/add-ons/kernel/file_systems/packagefs/BlockBufferCacheKernel.h haiku/trunk/src/add-ons/kernel/file_systems/packagefs/GlobalFactory.cpp haiku/trunk/src/add-ons/kernel/file_systems/packagefs/GlobalFactory.h haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Jamfile haiku/trunk/src/add-ons/kernel/file_systems/packagefs/PackageFile.cpp haiku/trunk/src/add-ons/kernel/file_systems/packagefs/PackageFile.h haiku/trunk/src/add-ons/kernel/file_systems/packagefs/PackageLeafNode.h haiku/trunk/src/add-ons/kernel/file_systems/packagefs/PackageNodeAttribute.cpp haiku/trunk/src/add-ons/kernel/file_systems/packagefs/PackageNodeAttribute.h haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/packagefs/kernel_interface.cpp haiku/trunk/src/bin/package/Jamfile haiku/trunk/src/bin/package/StandardErrorOutput.h haiku/trunk/src/bin/package/command_create.cpp haiku/trunk/src/bin/package/command_dump.cpp haiku/trunk/src/bin/package/command_extract.cpp haiku/trunk/src/bin/package/command_list.cpp haiku/trunk/src/kits/package/Jamfile haiku/trunk/src/kits/package/hpkg/BlockBufferCache.cpp haiku/trunk/src/kits/package/hpkg/BufferCache.cpp haiku/trunk/src/kits/package/hpkg/DataOutput.cpp haiku/trunk/src/kits/package/hpkg/DataReader.cpp haiku/trunk/src/kits/package/hpkg/PackageData.cpp haiku/trunk/src/kits/package/hpkg/PackageDataReader.cpp haiku/trunk/src/kits/package/hpkg/PackageEntry.cpp haiku/trunk/src/kits/package/hpkg/PackageEntryAttribute.cpp haiku/trunk/src/kits/package/hpkg/PackageReader.cpp haiku/trunk/src/kits/package/hpkg/PackageWriter.cpp haiku/trunk/src/kits/package/hpkg/Strings.cpp haiku/trunk/src/kits/package/hpkg/ZlibCompressionBase.cpp haiku/trunk/src/kits/package/hpkg/ZlibCompressor.cpp haiku/trunk/src/kits/package/hpkg/ZlibDecompressor.cpp Log: Refactored hpkg implementation to provide some separation between public and private API (still far from ideal, but a start): * moved several HPKG-classes into the public namespace BPackageKit::HPKG * added fImpl-wrappers around PackageReader and PackageWriter to hide most of the gory details * adjusted 'package'-binary and packagefs accordingly Copied: haiku/trunk/headers/os/package/hpkg/BlockBufferCache.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/BlockBufferCache.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/BlockBufferCache.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/BlockBufferCache.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,49 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_ +#define _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_ + + +#include <SupportDefs.h> + +#include <package/hpkg/BufferCache.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +namespace BPrivate { + class BlockBufferCacheImpl; +} +using BPrivate::BlockBufferCacheImpl; + + +class BBlockBufferCache : public BBufferCache, public BBufferCacheLockable { +public: + BBlockBufferCache(size_t blockSize, + uint32 maxCachedBlocks); + virtual ~BBlockBufferCache(); + + virtual status_t Init(); + + virtual CachedBuffer* GetBuffer(size_t size, + CachedBuffer** owner = NULL, + bool* _newBuffer = NULL); + virtual void PutBufferAndCache(CachedBuffer** owner); + virtual void PutBuffer(CachedBuffer** owner); + +private: + BlockBufferCacheImpl* fImpl; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_ Copied: haiku/trunk/headers/os/package/hpkg/BufferCache.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/BufferCache.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/BufferCache.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/BufferCache.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,54 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__BUFFER_CACHE_H_ +#define _PACKAGE__HPKG__BUFFER_CACHE_H_ + + +#include <stddef.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +namespace BPrivate { + class CachedBuffer; +} +using BPrivate::CachedBuffer; + + +class BBufferCache { +public: + virtual ~BBufferCache(); + + virtual CachedBuffer* GetBuffer(size_t size, + CachedBuffer** owner = NULL, + bool* _newBuffer = NULL) = 0; + virtual void PutBufferAndCache(CachedBuffer** owner) = 0; + // caller is buffer owner and wants the + // buffer cached, if possible + virtual void PutBuffer(CachedBuffer** owner) = 0; + // puts the buffer for good, owner might + // have called PutBufferAndCache() before + // and might not own a buffer anymore +}; + + +class BBufferCacheLockable { +public: + virtual ~BBufferCacheLockable(); + + virtual bool Lock() = 0; + virtual void Unlock() = 0; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__BUFFER_CACHE_H_ Copied: haiku/trunk/headers/os/package/hpkg/DataOutput.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/DataOutput.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/DataOutput.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/DataOutput.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,45 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__DATA_OUTPUT_H_ +#define _PACKAGE__HPKG__DATA_OUTPUT_H_ + + +#include <SupportDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +class BDataOutput { +public: + virtual ~BDataOutput(); + + virtual status_t WriteData(const void* buffer, size_t size) = 0; +}; + + +class BBufferDataOutput : public BDataOutput { +public: + BBufferDataOutput(void* buffer, size_t size); + + size_t BytesWritten() const { return fBytesWritten; } + + virtual status_t WriteData(const void* buffer, size_t size); + +private: + void* fBuffer; + size_t fSize; + size_t fBytesWritten; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__DATA_OUTPUT_H_ Copied: haiku/trunk/headers/os/package/hpkg/DataReader.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/DataReader.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/DataReader.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/DataReader.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,71 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__DATA_READER_H_ +#define _PACKAGE__HPKG__DATA_READER_H_ + + +#include <SupportDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +class BDataReader { +public: + virtual ~BDataReader(); + + virtual status_t ReadData(off_t offset, void* buffer, + size_t size) = 0; +}; + + +class BFDDataReader : public BDataReader { +public: + BFDDataReader(int fd); + + virtual status_t ReadData(off_t offset, void* buffer, + size_t size); + +private: + int fFD; +}; + + +class BAttributeDataReader : public BDataReader { +public: + BAttributeDataReader(int fd, + const char* attribute, uint32 type); + + virtual status_t ReadData(off_t offset, void* buffer, + size_t size); + +private: + int fFD; + uint32 fType; + const char* fAttribute; +}; + + +class BBufferDataReader : public BDataReader { +public: + BBufferDataReader(const void* data, size_t size); + + virtual status_t ReadData(off_t offset, void* buffer, + size_t size); + +private: + const void* fData; + size_t fSize; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__DATA_READER_H_ Copied: haiku/trunk/headers/os/package/hpkg/ErrorOutput.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/ErrorOutput.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/ErrorOutput.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/ErrorOutput.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,34 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__ERROR_OUTPUT_H_ +#define _PACKAGE__HPKG__ERROR_OUTPUT_H_ + + +#include <stdarg.h> + +#include <SupportDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +class BErrorOutput { +public: + virtual ~BErrorOutput(); + + virtual void PrintErrorVarArgs(const char* format, + va_list args) = 0; + void PrintError(const char* format, ...); +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PACKAGE_OUTPUT_H_ Added: haiku/trunk/headers/os/package/hpkg/HPKGDefs.h =================================================================== --- haiku/trunk/headers/os/package/hpkg/HPKGDefs.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/HPKGDefs.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,77 @@ +/* + * Copyright 2011, Haiku, Inc. + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__HPKG_DEFS_H_ +#define _PACKAGE__HPKG__HPKG_DEFS_H_ + + +#include <SupportDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +// magic, version +enum { + B_HPKG_MAGIC = 'hpkg', + B_HPKG_VERSION = 1 +}; + + +// attribute types +enum { + // types + B_HPKG_ATTRIBUTE_TYPE_INVALID = 0, + B_HPKG_ATTRIBUTE_TYPE_INT = 1, + B_HPKG_ATTRIBUTE_TYPE_UINT = 2, + B_HPKG_ATTRIBUTE_TYPE_STRING = 3, + B_HPKG_ATTRIBUTE_TYPE_RAW = 4 +}; + + +// attribute encodings +enum { + // signed/unsigned int encodings + B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT = 0, + B_HPKG_ATTRIBUTE_ENCODING_INT_16_BIT = 1, + B_HPKG_ATTRIBUTE_ENCODING_INT_32_BIT = 2, + B_HPKG_ATTRIBUTE_ENCODING_INT_64_BIT = 3, + + // string encodings + B_HPKG_ATTRIBUTE_ENCODING_STRING_INLINE = 0, + // null-terminated string + B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE = 1, + // unsigned LEB128 index into string table + + // raw data encodings + B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE = 0, + // unsigned LEB128 size, raw bytes + B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP = 1 + // unsigned LEB128 size, unsigned LEB128 offset into the heap +}; + + +// maximum number of bytes of data to be encoded inline; more will be allocated +// on the heap +#define B_HPKG_MAX_INLINE_DATA_SIZE 8 + + +// name of file containing package information (in package's root folder) +#define B_HPKG_PACKAGE_INFO_FILE_NAME ".PackageInfo" + + +// default values +enum { + B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB = 64 * 1024 +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__HPKG_DEFS_H_ Copied: haiku/trunk/headers/os/package/hpkg/PackageAttributeValue.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/PackageAttributeValue.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageAttributeValue.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/PackageAttributeValue.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,157 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_ +#define _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_ + + +#include <string.h> + +#include <package/hpkg/HPKGDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +struct BPackageAttributeValue { + union { + int64 signedInt; + uint64 unsignedInt; + const char* string; + struct { + uint64 size; + union { + uint64 offset; + uint8 raw[B_HPKG_MAX_INLINE_DATA_SIZE]; + }; + } data; + }; + uint8 type; + uint8 encoding; + +public: + inline BPackageAttributeValue(); + + inline void SetTo(int8 value); + inline void SetTo(uint8 value); + inline void SetTo(int16 value); + inline void SetTo(uint16 value); + inline void SetTo(int32 value); + inline void SetTo(uint32 value); + inline void SetTo(int64 value); + inline void SetTo(uint64 value); + inline void SetTo(const char* value); + inline void SetToData(uint64 size, uint64 offset); + inline void SetToData(uint64 size, const void* rawData); +}; + + +BPackageAttributeValue::BPackageAttributeValue() + : + type(B_HPKG_ATTRIBUTE_TYPE_INVALID) +{ +} + + +void +BPackageAttributeValue::SetTo(int8 value) +{ + signedInt = value; + type = B_HPKG_ATTRIBUTE_TYPE_INT; +} + + +void +BPackageAttributeValue::SetTo(uint8 value) +{ + unsignedInt = value; + type = B_HPKG_ATTRIBUTE_TYPE_UINT; +} + + +void +BPackageAttributeValue::SetTo(int16 value) +{ + signedInt = value; + type = B_HPKG_ATTRIBUTE_TYPE_INT; +} + + +void +BPackageAttributeValue::SetTo(uint16 value) +{ + unsignedInt = value; + type = B_HPKG_ATTRIBUTE_TYPE_UINT; +} + + +void +BPackageAttributeValue::SetTo(int32 value) +{ + signedInt = value; + type = B_HPKG_ATTRIBUTE_TYPE_INT; +} + + +void +BPackageAttributeValue::SetTo(uint32 value) +{ + unsignedInt = value; + type = B_HPKG_ATTRIBUTE_TYPE_UINT; +} + + +void +BPackageAttributeValue::SetTo(int64 value) +{ + signedInt = value; + type = B_HPKG_ATTRIBUTE_TYPE_INT; +} + + +void +BPackageAttributeValue::SetTo(uint64 value) +{ + unsignedInt = value; + type = B_HPKG_ATTRIBUTE_TYPE_UINT; +} + + +void +BPackageAttributeValue::SetTo(const char* value) +{ + string = value; + type = B_HPKG_ATTRIBUTE_TYPE_STRING; +} + + +void +BPackageAttributeValue::SetToData(uint64 size, uint64 offset) +{ + data.size = size; + data.offset = offset; + type = B_HPKG_ATTRIBUTE_TYPE_RAW; + encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP; +} + + +void +BPackageAttributeValue::SetToData(uint64 size, const void* rawData) +{ + data.size = size; + if (size > 0) + memcpy(data.raw, rawData, size); + type = B_HPKG_ATTRIBUTE_TYPE_RAW; + encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE; +} + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_ Added: haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,55 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_ +#define _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_ + + +#include <SupportDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +class BPackageAttributeValue; +class BPackageEntry; +class BPackageEntryAttribute; + + +class BLowLevelPackageContentHandler { +public: + virtual ~BLowLevelPackageContentHandler(); + + virtual status_t HandleAttribute(const char* attributeName, + const BPackageAttributeValue& value, + void* parentToken, void*& _token) = 0; + virtual status_t HandleAttributeDone(const char* attributeName, + const BPackageAttributeValue& value, + void* token) = 0; + + virtual void HandleErrorOccurred() = 0; +}; + + +class BPackageContentHandler { +public: + virtual ~BPackageContentHandler(); + + virtual status_t HandleEntry(BPackageEntry* entry) = 0; + virtual status_t HandleEntryAttribute(BPackageEntry* entry, + BPackageEntryAttribute* attribute) = 0; + virtual status_t HandleEntryDone(BPackageEntry* entry) = 0; + + virtual void HandleErrorOccurred() = 0; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_ Copied: haiku/trunk/headers/os/package/hpkg/PackageData.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/PackageData.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageData.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/PackageData.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,62 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PACKAGE_DATA_H_ +#define _PACKAGE__HPKG__PACKAGE_DATA_H_ + + +#include <package/hpkg/HPKGDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +class BPackageData { +public: + BPackageData(); + + uint64 CompressedSize() const + { return fCompressedSize; } + uint64 UncompressedSize() const + { return fUncompressedSize; } + uint64 Offset() const + { return fEncodedInline ? 0 : fOffset; } + uint32 Compression() const { return fCompression; } + uint32 ChunkSize() const { return fChunkSize; } + + bool IsEncodedInline() const + { return fEncodedInline; } + const uint8* InlineData() const { return fInlineData; } + + void SetData(uint64 size, uint64 offset); + void SetData(uint8 size, const void* data); + + void SetCompression(uint32 compression) + { fCompression = compression; } + void SetUncompressedSize(uint64 size) + { fUncompressedSize = size; } + void SetChunkSize(uint32 size) + { fChunkSize = size; } + +private: + uint64 fCompressedSize; + uint64 fUncompressedSize; + union { + uint64 fOffset; + uint8 fInlineData[B_HPKG_MAX_INLINE_DATA_SIZE]; + }; + uint32 fChunkSize; + uint32 fCompression; + bool fEncodedInline; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PACKAGE_DATA_H_ Copied: haiku/trunk/headers/os/package/hpkg/PackageDataReader.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/PackageDataReader.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageDataReader.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/PackageDataReader.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,61 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PACKAGE_DATA_READER_H_ +#define _PACKAGE__HPKG__PACKAGE_DATA_READER_H_ + + +#include <package/hpkg/DataReader.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +class BBufferCache; +class BDataOutput; +class BPackageData; + + +class BPackageDataReader : public BDataReader { +public: + BPackageDataReader(BDataReader* dataReader); + virtual ~BPackageDataReader(); + + virtual status_t Init(const BPackageData& data) = 0; + + virtual status_t ReadData(off_t offset, void* buffer, + size_t size); + virtual status_t ReadDataToOutput(off_t offset, size_t size, + BDataOutput* output) = 0; + + virtual uint64 Size() const = 0; + virtual size_t BlockSize() const = 0; + +protected: + BDataReader* fDataReader; +}; + + +class BPackageDataReaderFactory { +public: + BPackageDataReaderFactory( + BBufferCache* bufferCache); + + status_t CreatePackageDataReader(BDataReader* dataReader, + const BPackageData& data, + BPackageDataReader*& _reader); + +private: + BBufferCache* fBufferCache; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PACKAGE_DATA_READER_H_ Copied: haiku/trunk/headers/os/package/hpkg/PackageEntry.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/PackageEntry.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageEntry.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/PackageEntry.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,94 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PACKAGE_ENTRY_H_ +#define _PACKAGE__HPKG__PACKAGE_ENTRY_H_ + + +#include <sys/stat.h> + +#include <package/hpkg/PackageData.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +class BPackageEntry { +public: + BPackageEntry(BPackageEntry* parent, + const char* name); + + const BPackageEntry* Parent() const { return fParent; } + const char* Name() const { return fName; } + void* UserToken() const { return fUserToken; } + + mode_t Mode() const { return fMode; } + + const timespec& AccessTime() const + { return fAccessTime; } + const timespec& ModifiedTime() const + { return fModifiedTime; } + const timespec& CreationTime() const + { return fCreationTime; } + + BPackageData& Data() { return fData; } + + const char* SymlinkPath() const { return fSymlinkPath; } + + void SetUserToken(void* token) + { fUserToken = token; } + + void SetType(uint32 type); + void SetPermissions(uint32 permissions); + + void SetAccessTime(uint32 seconds) + { fAccessTime.tv_sec = seconds; } + void SetAccessTimeNanos(uint32 nanos) + { fAccessTime.tv_nsec = nanos; } + void SetModifiedTime(uint32 seconds) + { fModifiedTime.tv_sec = seconds; } + void SetModifiedTimeNanos(uint32 nanos) + { fModifiedTime.tv_nsec = nanos; } + void SetCreationTime(uint32 seconds) + { fCreationTime.tv_sec = seconds; } + void SetCreationTimeNanos(uint32 nanos) + { fCreationTime.tv_nsec = nanos; } + + void SetSymlinkPath(const char* path) + { fSymlinkPath = path; } +private: + BPackageEntry* fParent; + const char* fName; + void* fUserToken; + mode_t fMode; + timespec fAccessTime; + timespec fModifiedTime; + timespec fCreationTime; + BPackageData fData; + const char* fSymlinkPath; +}; + + +inline void +BPackageEntry::SetType(uint32 type) +{ + fMode = (fMode & ~(uint32)S_IFMT) | (type & S_IFMT); +} + + +inline void +BPackageEntry::SetPermissions(uint32 permissions) +{ + fMode = (fMode & ~(uint32)ALLPERMS) | (permissions & ALLPERMS); +} + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PACKAGE_ENTRY_H_ Copied: haiku/trunk/headers/os/package/hpkg/PackageEntryAttribute.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/PackageEntryAttribute.h) =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageEntryAttribute.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/PackageEntryAttribute.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,40 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_ +#define _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_ + + +#include <package/hpkg/PackageData.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +class BPackageEntryAttribute { +public: + BPackageEntryAttribute(const char* name); + + const char* Name() const { return fName; } + uint32 Type() const { return fType; } + + BPackageData& Data() { return fData; } + + void SetType(uint32 type) { fType = type; } + +private: + const char* fName; + uint32 fType; + BPackageData fData; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_ Added: haiku/trunk/headers/os/package/hpkg/PackageReader.h =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageReader.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/PackageReader.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,51 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PACKAGE_READER_H_ +#define _PACKAGE__HPKG__PACKAGE_READER_H_ + + +#include <SupportDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +namespace BPrivate { + class PackageReaderImpl; +} +using BPrivate::PackageReaderImpl; + +class BErrorOutput; +class BLowLevelPackageContentHandler; +class BPackageContentHandler; + + +class BPackageReader { +public: + BPackageReader( + BErrorOutput* errorOutput); + ~BPackageReader(); + + status_t Init(const char* fileName); + status_t Init(int fd, bool keepFD); + status_t ParseContent( + BPackageContentHandler* contentHandler); + status_t ParseContent(BLowLevelPackageContentHandler* + contentHandler); + + int PackageFileFD(); +private: + PackageReaderImpl* fImpl; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_H_ Added: haiku/trunk/headers/os/package/hpkg/PackageWriter.h =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageWriter.h (rev 0) +++ haiku/trunk/headers/os/package/hpkg/PackageWriter.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,42 @@ +/* + * Copyright 2011, Haiku, Inc. + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PACKAGE_WRITER_H_ +#define _PACKAGE__HPKG__PACKAGE_WRITER_H_ + + +#include <SupportDefs.h> + + +namespace BPackageKit { + +namespace BHPKG { + + +namespace BPrivate { + class PackageWriterImpl; +} +using BPrivate::PackageWriterImpl; + + +class BPackageWriter { +public: + BPackageWriter(); + ~BPackageWriter(); + + status_t Init(const char* fileName); + status_t AddEntry(const char* fileName); + status_t Finish(); + +private: + PackageWriterImpl* fImpl; +}; + + +} // namespace BHPKG + +} // namespace BPackageKit + + +#endif // _PACKAGE__HPKG__PACKAGE_WRITER_H_ Copied: haiku/trunk/headers/private/package/hpkg/BlockBufferCacheImpl.h (from rev 40315, haiku/trunk/headers/private/package/hpkg/BlockBufferCache.h) =================================================================== --- haiku/trunk/headers/private/package/hpkg/BlockBufferCacheImpl.h (rev 0) +++ haiku/trunk/headers/private/package/hpkg/BlockBufferCacheImpl.h 2011-01-30 15:05:38 UTC (rev 40320) @@ -0,0 +1,66 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_CACHE_H_ +#define _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_CACHE_H_ + + +#include <SupportDefs.h> + +#include <util/DoublyLinkedList.h> + +#include <package/hpkg/BufferCache.h> + + +namespace BPackageKit { + +namespace BHPKG { + [... truncated: 8760 lines follow ...]