* Cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32281 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-08-12 14:39:37 +00:00
parent db341f3691
commit 30f4c392a4
@@ -1,6 +1,6 @@
/* /*
* Copyright 2005-2007, Ingo Weinhold, [email protected]. * Copyright 2005-2007, Ingo Weinhold, [email protected].
* Copyright 2005, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2005-2009, Axel Dörfler, [email protected].
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -33,7 +33,8 @@
#endif #endif
static const uint32 kFloppyArchiveOffset = BOOT_ARCHIVE_IMAGE_OFFSET * 1024; // initially at 192 kB, now defined at build time static const uint32 kFloppyArchiveOffset = BOOT_ARCHIVE_IMAGE_OFFSET * 1024;
// defined at build time, see build/jam/BuildSetup
static const size_t kTarRegionSize = 16 * 1024 * 1024; // 16 MB static const size_t kTarRegionSize = 16 * 1024 * 1024; // 16 MB
namespace TarFS { namespace TarFS {
@@ -47,8 +48,17 @@ struct RegionDelete {
}; };
struct RegionDeleter : BPrivate::AutoDeleter<void, RegionDelete> { struct RegionDeleter : BPrivate::AutoDeleter<void, RegionDelete> {
RegionDeleter() : BPrivate::AutoDeleter<void, RegionDelete>() {} RegionDeleter()
RegionDeleter(void *memory) : BPrivate::AutoDeleter<void, RegionDelete>(memory) {} :
BPrivate::AutoDeleter<void, RegionDelete>()
{
}
RegionDeleter(void* memory)
:
BPrivate::AutoDeleter<void, RegionDelete>(memory)
{
}
}; };
class Directory; class Directory;
@@ -77,10 +87,13 @@ class File : public ::Node, public Entry {
File(tar_header* header, const char* name); File(tar_header* header, const char* name);
virtual ~File(); virtual ~File();
virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); virtual ssize_t ReadAt(void* cookie, off_t pos, void* buffer,
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); size_t bufferSize);
virtual ssize_t WriteAt(void* cookie, off_t pos,
const void* buffer, size_t bufferSize);
virtual status_t GetName(char *nameBuffer, size_t bufferSize) const; virtual status_t GetName(char* nameBuffer,
size_t bufferSize) const;
virtual int32 Type() const; virtual int32 Type() const;
virtual off_t Size() const; virtual off_t Size() const;
@@ -102,12 +115,14 @@ class Directory : public ::Directory, public Entry {
virtual status_t Open(void** _cookie, int mode); virtual status_t Open(void** _cookie, int mode);
virtual status_t Close(void* cookie); virtual status_t Close(void* cookie);
virtual status_t GetName(char *nameBuffer, size_t bufferSize) const; virtual status_t GetName(char* nameBuffer,
size_t bufferSize) const;
virtual TarFS::Entry* LookupEntry(const char* name); virtual TarFS::Entry* LookupEntry(const char* name);
virtual ::Node* Lookup(const char* name, bool traverseLinks); virtual ::Node* Lookup(const char* name, bool traverseLinks);
virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize); virtual status_t GetNextEntry(void* cookie, char* nameBuffer,
size_t bufferSize);
virtual status_t GetNextNode(void* cookie, Node** _node); virtual status_t GetNextNode(void* cookie, Node** _node);
virtual status_t Rewind(void* cookie); virtual status_t Rewind(void* cookie);
virtual bool IsEmpty(); virtual bool IsEmpty();
@@ -117,7 +132,8 @@ class Directory : public ::Directory, public Entry {
virtual ::Node* ToNode() { return this; }; virtual ::Node* ToNode() { return this; };
virtual TarFS::Directory* ToTarDirectory() { return this; } virtual TarFS::Directory* ToTarDirectory() { return this; }
status_t AddDirectory(char *dirName, TarFS::Directory **_dir = NULL); status_t AddDirectory(char* dirName,
TarFS::Directory** _dir = NULL);
status_t AddFile(tar_header* header); status_t AddFile(tar_header* header);
private: private:
@@ -134,10 +150,11 @@ class Symlink : public ::Node, public Entry {
virtual ssize_t ReadAt(void* cookie, off_t pos, void* buffer, virtual ssize_t ReadAt(void* cookie, off_t pos, void* buffer,
size_t bufferSize); size_t bufferSize);
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, virtual ssize_t WriteAt(void* cookie, off_t pos,
size_t bufferSize); const void* buffer, size_t bufferSize);
virtual status_t GetName(char *nameBuffer, size_t bufferSize) const; virtual status_t GetName(char* nameBuffer,
size_t bufferSize) const;
virtual int32 Type() const; virtual int32 Type() const;
virtual off_t Size() const; virtual off_t Size() const;
@@ -163,8 +180,9 @@ class Volume : public TarFS::Directory {
TarFS::Directory* Root() { return this; } TarFS::Directory* Root() { return this; }
private: private:
status_t _Inflate(boot::Partition *partition, void* cookie, status_t _Inflate(boot::Partition* partition,
off_t offset, RegionDeleter& regionDeleter, void* cookie, off_t offset,
RegionDeleter& regionDeleter,
size_t* inflatedBytes); size_t* inflatedBytes);
}; };
@@ -251,7 +269,8 @@ TarFS::File::~File()
ssize_t ssize_t
TarFS::File::ReadAt(void* cookie, off_t pos, void* buffer, size_t bufferSize) TarFS::File::ReadAt(void* cookie, off_t pos, void* buffer, size_t bufferSize)
{ {
TRACE(("tarfs: read at %Ld, %lu bytes, fSize = %Ld\n", pos, bufferSize, fSize)); TRACE(("tarfs: read at %Ld, %lu bytes, fSize = %Ld\n", pos, bufferSize,
fSize));
if (pos < 0 || !buffer) if (pos < 0 || !buffer)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -270,7 +289,8 @@ TarFS::File::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
ssize_t ssize_t
TarFS::File::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) TarFS::File::WriteAt(void* cookie, off_t pos, const void* buffer,
size_t bufferSize)
{ {
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
} }
@@ -279,7 +299,8 @@ TarFS::File::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferS
status_t status_t
TarFS::File::GetName(char* nameBuffer, size_t bufferSize) const TarFS::File::GetName(char* nameBuffer, size_t bufferSize) const
{ {
return strlcpy(nameBuffer, Name(), bufferSize) >= bufferSize ? B_BUFFER_OVERFLOW : B_OK; return strlcpy(nameBuffer, Name(), bufferSize) >= bufferSize
? B_BUFFER_OVERFLOW : B_OK;
} }
@@ -326,7 +347,8 @@ TarFS::Directory::Open(void **_cookie, int mode)
{ {
_inherited::Open(_cookie, mode); _inherited::Open(_cookie, mode);
EntryIterator *iterator = new(nothrow) EntryIterator(fEntries.GetIterator()); EntryIterator* iterator
= new(std::nothrow) EntryIterator(fEntries.GetIterator());
if (iterator == NULL) if (iterator == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -349,7 +371,8 @@ TarFS::Directory::Close(void *cookie)
status_t status_t
TarFS::Directory::GetName(char* nameBuffer, size_t bufferSize) const TarFS::Directory::GetName(char* nameBuffer, size_t bufferSize) const
{ {
return strlcpy(nameBuffer, Name(), bufferSize) >= bufferSize ? B_BUFFER_OVERFLOW : B_OK; return strlcpy(nameBuffer, Name(), bufferSize) >= bufferSize
? B_BUFFER_OVERFLOW : B_OK;
} }
@@ -669,7 +692,8 @@ TarFS::Volume::Init(boot::Partition *partition)
TRACE(("tarfs: \"%s\", %Ld bytes\n", header->name, size)); TRACE(("tarfs: \"%s\", %Ld bytes\n", header->name, size));
// TODO: this is old-style GNU tar which probably won't work with newer ones... // TODO: this is old-style GNU tar which probably won't work with newer
// ones...
switch (header->type) { switch (header->type) {
case TAR_FILE: case TAR_FILE:
case TAR_FILE2: case TAR_FILE2:
@@ -685,7 +709,8 @@ TarFS::Volume::Init(boot::Partition *partition)
// this is a long file name // this is a long file name
// TODO: read long name // TODO: read long name
default: default:
dprintf("tarfs: unsupported file type: %d ('%c')\n", header->type, header->type); dprintf("tarfs: unsupported file type: %d ('%c')\n",
header->type, header->type);
// unsupported type // unsupported type
status = B_ERROR; status = B_ERROR;
break; break;