Cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17981 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+97
-123
@@ -1,165 +1,139 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
* Copyright 2005-2006, Haiku.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
* Authors:
|
||||||
// to deal in the Software without restriction, including without limitation
|
* Ingo Weinhold, [email protected]
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
*/
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
|
||||||
// File Name: DataIO.cpp
|
|
||||||
// Author(s): Ingo Weinhold ([email protected])
|
|
||||||
// Stefano Ceccherini ([email protected])
|
|
||||||
// The Storage Team
|
|
||||||
// Description: Pure virtual BDataIO and BPositionIO classes provide
|
|
||||||
// the protocol for Read()/Write()/Seek().
|
|
||||||
//
|
|
||||||
// BMallocIO and BMemoryIO classes implement the protocol,
|
|
||||||
// as does BFile in the Storage Kit.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#ifndef _DATA_IO_H
|
#ifndef _DATA_IO_H
|
||||||
#define _DATA_IO_H
|
#define _DATA_IO_H
|
||||||
|
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
// DataIO
|
|
||||||
class BDataIO {
|
class BDataIO {
|
||||||
public:
|
public:
|
||||||
BDataIO();
|
BDataIO();
|
||||||
virtual ~BDataIO();
|
virtual ~BDataIO();
|
||||||
|
|
||||||
virtual ssize_t Read(void *buffer, size_t size) = 0;
|
virtual ssize_t Read(void *buffer, size_t size) = 0;
|
||||||
virtual ssize_t Write(const void *buffer, size_t size) = 0;
|
virtual ssize_t Write(const void *buffer, size_t size) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BDataIO(const BDataIO &);
|
BDataIO(const BDataIO &);
|
||||||
BDataIO &operator=(const BDataIO &);
|
BDataIO &operator=(const BDataIO &);
|
||||||
|
|
||||||
virtual void _ReservedDataIO1();
|
virtual void _ReservedDataIO1();
|
||||||
virtual void _ReservedDataIO2();
|
virtual void _ReservedDataIO2();
|
||||||
virtual void _ReservedDataIO3();
|
virtual void _ReservedDataIO3();
|
||||||
virtual void _ReservedDataIO4();
|
virtual void _ReservedDataIO4();
|
||||||
virtual void _ReservedDataIO5();
|
virtual void _ReservedDataIO5();
|
||||||
virtual void _ReservedDataIO6();
|
virtual void _ReservedDataIO6();
|
||||||
virtual void _ReservedDataIO7();
|
virtual void _ReservedDataIO7();
|
||||||
virtual void _ReservedDataIO8();
|
virtual void _ReservedDataIO8();
|
||||||
virtual void _ReservedDataIO9();
|
virtual void _ReservedDataIO9();
|
||||||
virtual void _ReservedDataIO10();
|
virtual void _ReservedDataIO10();
|
||||||
virtual void _ReservedDataIO11();
|
virtual void _ReservedDataIO11();
|
||||||
virtual void _ReservedDataIO12();
|
virtual void _ReservedDataIO12();
|
||||||
|
|
||||||
uint32 _reserved[2];
|
uint32 _reserved[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
// BPositionIO
|
|
||||||
class BPositionIO : public BDataIO {
|
class BPositionIO : public BDataIO {
|
||||||
public:
|
public:
|
||||||
BPositionIO();
|
BPositionIO();
|
||||||
virtual ~BPositionIO();
|
virtual ~BPositionIO();
|
||||||
|
|
||||||
virtual ssize_t Read(void *buffer, size_t size);
|
virtual ssize_t Read(void *buffer, size_t size);
|
||||||
virtual ssize_t Write(const void *buffer, size_t size);
|
virtual ssize_t Write(const void *buffer, size_t size);
|
||||||
|
|
||||||
virtual ssize_t ReadAt(off_t position, void *buffer, size_t size) = 0;
|
virtual ssize_t ReadAt(off_t position, void *buffer, size_t size) = 0;
|
||||||
virtual ssize_t WriteAt(off_t position, const void *buffer,
|
virtual ssize_t WriteAt(off_t position, const void *buffer,
|
||||||
size_t size) = 0;
|
size_t size) = 0;
|
||||||
|
|
||||||
virtual off_t Seek(off_t position, uint32 seekMode) = 0;
|
virtual off_t Seek(off_t position, uint32 seekMode) = 0;
|
||||||
virtual off_t Position() const = 0;
|
virtual off_t Position() const = 0;
|
||||||
|
|
||||||
virtual status_t SetSize(off_t size);
|
virtual status_t SetSize(off_t size);
|
||||||
virtual status_t GetSize(off_t* size) const;
|
virtual status_t GetSize(off_t* size) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void _ReservedPositionIO2();
|
virtual void _ReservedPositionIO2();
|
||||||
virtual void _ReservedPositionIO3();
|
virtual void _ReservedPositionIO3();
|
||||||
virtual void _ReservedPositionIO4();
|
virtual void _ReservedPositionIO4();
|
||||||
virtual void _ReservedPositionIO5();
|
virtual void _ReservedPositionIO5();
|
||||||
virtual void _ReservedPositionIO6();
|
virtual void _ReservedPositionIO6();
|
||||||
virtual void _ReservedPositionIO7();
|
virtual void _ReservedPositionIO7();
|
||||||
virtual void _ReservedPositionIO8();
|
virtual void _ReservedPositionIO8();
|
||||||
virtual void _ReservedPositionIO9();
|
virtual void _ReservedPositionIO9();
|
||||||
virtual void _ReservedPositionIO10();
|
virtual void _ReservedPositionIO10();
|
||||||
virtual void _ReservedPositionIO11();
|
virtual void _ReservedPositionIO11();
|
||||||
virtual void _ReservedPositionIO12();
|
virtual void _ReservedPositionIO12();
|
||||||
|
|
||||||
uint32 _reserved[2];
|
uint32 _reserved[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
// BMemoryIO
|
|
||||||
class BMemoryIO : public BPositionIO {
|
class BMemoryIO : public BPositionIO {
|
||||||
public:
|
public:
|
||||||
BMemoryIO(void *data, size_t len);
|
BMemoryIO(void *data, size_t length);
|
||||||
BMemoryIO(const void *data, size_t len);
|
BMemoryIO(const void *data, size_t length);
|
||||||
virtual ~BMemoryIO();
|
virtual ~BMemoryIO();
|
||||||
|
|
||||||
virtual ssize_t ReadAt(off_t position, void *buffer, size_t size);
|
virtual ssize_t ReadAt(off_t position, void *buffer, size_t size);
|
||||||
virtual ssize_t WriteAt(off_t position, const void *buffer, size_t size);
|
virtual ssize_t WriteAt(off_t position, const void *buffer, size_t size);
|
||||||
|
|
||||||
virtual off_t Seek(off_t position, uint32 seekMode);
|
virtual off_t Seek(off_t position, uint32 seekMode);
|
||||||
virtual off_t Position() const;
|
virtual off_t Position() const;
|
||||||
|
|
||||||
virtual status_t SetSize(off_t size);
|
virtual status_t SetSize(off_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMemoryIO(const BMemoryIO &);
|
BMemoryIO(const BMemoryIO &);
|
||||||
BMemoryIO &operator=(const BMemoryIO &);
|
BMemoryIO &operator=(const BMemoryIO &);
|
||||||
|
|
||||||
virtual void _ReservedMemoryIO1();
|
virtual void _ReservedMemoryIO1();
|
||||||
virtual void _ReservedMemoryIO2();
|
virtual void _ReservedMemoryIO2();
|
||||||
|
|
||||||
bool fReadOnly;
|
bool fReadOnly;
|
||||||
char *fBuf;
|
char *fBuffer;
|
||||||
size_t fLen;
|
size_t fLength;
|
||||||
size_t fPhys;
|
size_t fBufferSize;
|
||||||
size_t fPos;
|
size_t fPosition;
|
||||||
uint32 _reserved[1];
|
uint32 _reserved[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
// BMallocIO
|
|
||||||
class BMallocIO : public BPositionIO {
|
class BMallocIO : public BPositionIO {
|
||||||
public:
|
public:
|
||||||
BMallocIO();
|
BMallocIO();
|
||||||
virtual ~BMallocIO();
|
virtual ~BMallocIO();
|
||||||
|
|
||||||
virtual ssize_t ReadAt(off_t position, void *buffer, size_t size);
|
virtual ssize_t ReadAt(off_t position, void *buffer, size_t size);
|
||||||
virtual ssize_t WriteAt(off_t position, const void *buffer, size_t size);
|
virtual ssize_t WriteAt(off_t position, const void *buffer, size_t size);
|
||||||
|
|
||||||
virtual off_t Seek(off_t position, uint32 seekMode);
|
virtual off_t Seek(off_t position, uint32 seekMode);
|
||||||
virtual off_t Position() const;
|
virtual off_t Position() const;
|
||||||
|
|
||||||
virtual status_t SetSize(off_t size);
|
virtual status_t SetSize(off_t size);
|
||||||
|
|
||||||
void SetBlockSize(size_t blockSize);
|
void SetBlockSize(size_t blockSize);
|
||||||
|
|
||||||
const void *Buffer() const;
|
const void *Buffer() const;
|
||||||
size_t BufferLength() const;
|
size_t BufferLength() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMallocIO(const BMallocIO &);
|
BMallocIO(const BMallocIO &);
|
||||||
BMallocIO &operator=(const BMallocIO &);
|
BMallocIO &operator=(const BMallocIO &);
|
||||||
|
|
||||||
virtual void _ReservedMallocIO1();
|
virtual void _ReservedMallocIO1();
|
||||||
virtual void _ReservedMallocIO2();
|
virtual void _ReservedMallocIO2();
|
||||||
|
|
||||||
size_t fBlockSize;
|
size_t fBlockSize;
|
||||||
size_t fMallocSize;
|
size_t fMallocSize;
|
||||||
size_t fLength;
|
size_t fLength;
|
||||||
char *fData;
|
char *fData;
|
||||||
off_t fPosition;
|
off_t fPosition;
|
||||||
uint32 _reserved[1];
|
uint32 _reserved[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // _DATA_IO_H
|
||||||
|
|||||||
+79
-126
@@ -1,65 +1,48 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2005, Haiku, Inc.
|
* Copyright 2005-2006, Haiku.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
* Authors:
|
||||||
// to deal in the Software without restriction, including without limitation
|
* Stefano Ceccherini ([email protected])
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
*/
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
/*!
|
||||||
//
|
Pure virtual BDataIO and BPositioIO classes provide
|
||||||
// The above copyright notice and this permission notice shall be included in
|
the protocol for Read()/Write()/Seek().
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
BMallocIO and BMemoryIO classes implement the protocol,
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
as does BFile in the Storage Kit.
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
*/
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
#include <DataIO.h>
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
|
||||||
// File Name: DataIO.cpp
|
|
||||||
// Author(s): Stefano Ceccherini ([email protected])
|
|
||||||
// The Storage Team
|
|
||||||
// Description: Pure virtual BDataIO and BPositioIO classes provide
|
|
||||||
// the protocol for Read()/Write()/Seek().
|
|
||||||
//
|
|
||||||
// BMallocIO and BMemoryIO classes implement the protocol,
|
|
||||||
// as does BFile in the Storage Kit.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <DataIO.h>
|
|
||||||
|
|
||||||
|
|
||||||
// *** BDataIO ***
|
|
||||||
|
|
||||||
// Construction
|
|
||||||
BDataIO::BDataIO()
|
BDataIO::BDataIO()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Destruction
|
|
||||||
BDataIO::~BDataIO()
|
BDataIO::~BDataIO()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Private or Reserved
|
// Private or Reserved
|
||||||
|
|
||||||
BDataIO::BDataIO(const BDataIO &)
|
BDataIO::BDataIO(const BDataIO &)
|
||||||
{
|
{
|
||||||
//Copying not allowed
|
// Copying not allowed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BDataIO &
|
BDataIO &
|
||||||
BDataIO::operator=(const BDataIO &)
|
BDataIO::operator=(const BDataIO &)
|
||||||
{
|
{
|
||||||
//Copying not allowed
|
// Copying not allowed
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,8 +52,6 @@ void BDataIO::_ReservedDataIO1(){}
|
|||||||
void BDataIO::_ReservedDataIO2(){}
|
void BDataIO::_ReservedDataIO2(){}
|
||||||
void BDataIO::_ReservedDataIO3(){}
|
void BDataIO::_ReservedDataIO3(){}
|
||||||
void BDataIO::_ReservedDataIO4(){}
|
void BDataIO::_ReservedDataIO4(){}
|
||||||
|
|
||||||
#if !_PR3_COMPATIBLE_
|
|
||||||
void BDataIO::_ReservedDataIO5(){}
|
void BDataIO::_ReservedDataIO5(){}
|
||||||
void BDataIO::_ReservedDataIO6(){}
|
void BDataIO::_ReservedDataIO6(){}
|
||||||
void BDataIO::_ReservedDataIO7(){}
|
void BDataIO::_ReservedDataIO7(){}
|
||||||
@@ -79,24 +60,21 @@ void BDataIO::_ReservedDataIO9(){}
|
|||||||
void BDataIO::_ReservedDataIO10(){}
|
void BDataIO::_ReservedDataIO10(){}
|
||||||
void BDataIO::_ReservedDataIO11(){}
|
void BDataIO::_ReservedDataIO11(){}
|
||||||
void BDataIO::_ReservedDataIO12(){}
|
void BDataIO::_ReservedDataIO12(){}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// *** BPositionIO ***
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// Construction
|
|
||||||
BPositionIO::BPositionIO()
|
BPositionIO::BPositionIO()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Destruction
|
|
||||||
BPositionIO::~BPositionIO()
|
BPositionIO::~BPositionIO()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Read
|
|
||||||
ssize_t
|
ssize_t
|
||||||
BPositionIO::Read(void *buffer, size_t size)
|
BPositionIO::Read(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
@@ -104,12 +82,11 @@ BPositionIO::Read(void *buffer, size_t size)
|
|||||||
ssize_t result = ReadAt(curPos, buffer, size);
|
ssize_t result = ReadAt(curPos, buffer, size);
|
||||||
if (result > 0)
|
if (result > 0)
|
||||||
Seek(result, SEEK_CUR);
|
Seek(result, SEEK_CUR);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Write
|
|
||||||
ssize_t
|
ssize_t
|
||||||
BPositionIO::Write(const void *buffer, size_t size)
|
BPositionIO::Write(const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
@@ -117,19 +94,18 @@ BPositionIO::Write(const void *buffer, size_t size)
|
|||||||
ssize_t result = WriteAt(curPos, buffer, size);
|
ssize_t result = WriteAt(curPos, buffer, size);
|
||||||
if (result > 0)
|
if (result > 0)
|
||||||
Seek(result, SEEK_CUR);
|
Seek(result, SEEK_CUR);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetSize
|
|
||||||
status_t
|
status_t
|
||||||
BPositionIO::SetSize(off_t size)
|
BPositionIO::SetSize(off_t size)
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSize
|
|
||||||
status_t
|
status_t
|
||||||
BPositionIO::GetSize(off_t* size) const
|
BPositionIO::GetSize(off_t* size) const
|
||||||
{
|
{
|
||||||
@@ -158,8 +134,6 @@ extern "C" void _ReservedPositionIO1__11BPositionIO() {}
|
|||||||
void BPositionIO::_ReservedPositionIO2(){}
|
void BPositionIO::_ReservedPositionIO2(){}
|
||||||
void BPositionIO::_ReservedPositionIO3(){}
|
void BPositionIO::_ReservedPositionIO3(){}
|
||||||
void BPositionIO::_ReservedPositionIO4(){}
|
void BPositionIO::_ReservedPositionIO4(){}
|
||||||
|
|
||||||
#if !_PR3_COMPATIBLE_
|
|
||||||
void BPositionIO::_ReservedPositionIO5(){}
|
void BPositionIO::_ReservedPositionIO5(){}
|
||||||
void BPositionIO::_ReservedPositionIO6(){}
|
void BPositionIO::_ReservedPositionIO6(){}
|
||||||
void BPositionIO::_ReservedPositionIO7(){}
|
void BPositionIO::_ReservedPositionIO7(){}
|
||||||
@@ -168,124 +142,118 @@ void BPositionIO::_ReservedPositionIO9(){}
|
|||||||
void BPositionIO::_ReservedPositionIO10(){}
|
void BPositionIO::_ReservedPositionIO10(){}
|
||||||
void BPositionIO::_ReservedPositionIO11(){}
|
void BPositionIO::_ReservedPositionIO11(){}
|
||||||
void BPositionIO::_ReservedPositionIO12(){}
|
void BPositionIO::_ReservedPositionIO12(){}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// *** BMemoryIO ***
|
// #pragma mark -
|
||||||
|
|
||||||
// Construction
|
|
||||||
BMemoryIO::BMemoryIO(void *p, size_t len)
|
BMemoryIO::BMemoryIO(void *buffer, size_t length)
|
||||||
:fReadOnly(false),
|
:
|
||||||
fBuf(static_cast<char*>(p)),
|
fReadOnly(false),
|
||||||
fLen(len),
|
fBuffer(static_cast<char*>(buffer)),
|
||||||
fPhys(len),
|
fLength(length),
|
||||||
fPos(0)
|
fBufferSize(length),
|
||||||
|
fPosition(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMemoryIO::BMemoryIO(const void *p, size_t len)
|
BMemoryIO::BMemoryIO(const void *buffer, size_t length)
|
||||||
:fReadOnly(true),
|
:
|
||||||
fBuf(const_cast<char*>(static_cast<const char*>(p))),
|
fReadOnly(true),
|
||||||
fLen(len),
|
fBuffer(const_cast<char*>(static_cast<const char*>(buffer))),
|
||||||
fPhys(len),
|
fLength(length),
|
||||||
fPos(0)
|
fBufferSize(length),
|
||||||
|
fPosition(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Destruction
|
|
||||||
BMemoryIO::~BMemoryIO()
|
BMemoryIO::~BMemoryIO()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ReadAt
|
|
||||||
ssize_t
|
ssize_t
|
||||||
BMemoryIO::ReadAt(off_t pos, void *buffer, size_t size)
|
BMemoryIO::ReadAt(off_t pos, void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || pos < 0)
|
if (buffer == NULL || pos < 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
ssize_t sizeRead = 0;
|
ssize_t sizeRead = 0;
|
||||||
if (pos < fLen) {
|
if (pos < fLength) {
|
||||||
sizeRead = min_c(static_cast<off_t>(size), fLen - pos);
|
sizeRead = min_c(static_cast<off_t>(size), fLength - pos);
|
||||||
memcpy(buffer, fBuf + pos, sizeRead);
|
memcpy(buffer, fBuffer + pos, sizeRead);
|
||||||
}
|
}
|
||||||
return sizeRead;
|
return sizeRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// WriteAt
|
|
||||||
ssize_t
|
ssize_t
|
||||||
BMemoryIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
BMemoryIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (fReadOnly)
|
if (fReadOnly)
|
||||||
return B_NOT_ALLOWED;
|
return B_NOT_ALLOWED;
|
||||||
|
|
||||||
if (buffer == NULL || pos < 0)
|
if (buffer == NULL || pos < 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
ssize_t sizeWritten = 0;
|
ssize_t sizeWritten = 0;
|
||||||
if (pos < fPhys) {
|
if (pos < fBufferSize) {
|
||||||
sizeWritten = min_c(static_cast<off_t>(size), fPhys - pos);
|
sizeWritten = min_c(static_cast<off_t>(size), fBufferSize - pos);
|
||||||
memcpy(fBuf + pos, buffer, sizeWritten);
|
memcpy(fBuffer + pos, buffer, sizeWritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos + sizeWritten > fLen)
|
if (pos + sizeWritten > fLength)
|
||||||
fLen = pos + sizeWritten;
|
fLength = pos + sizeWritten;
|
||||||
|
|
||||||
return sizeWritten;
|
return sizeWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Seek
|
|
||||||
off_t
|
off_t
|
||||||
BMemoryIO::Seek(off_t position, uint32 seek_mode)
|
BMemoryIO::Seek(off_t position, uint32 seek_mode)
|
||||||
{
|
{
|
||||||
switch (seek_mode) {
|
switch (seek_mode) {
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
fPos = position;
|
fPosition = position;
|
||||||
break;
|
break;
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
fPos += position;
|
fPosition += position;
|
||||||
break;
|
break;
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
fPos = fLen + position;
|
fPosition = fLength + position;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return fPos;
|
return fPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Position
|
|
||||||
off_t
|
off_t
|
||||||
BMemoryIO::Position() const
|
BMemoryIO::Position() const
|
||||||
{
|
{
|
||||||
return fPos;
|
return fPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetSize
|
|
||||||
status_t
|
status_t
|
||||||
BMemoryIO::SetSize(off_t size)
|
BMemoryIO::SetSize(off_t size)
|
||||||
{
|
{
|
||||||
if (fReadOnly)
|
if (fReadOnly)
|
||||||
return B_NOT_ALLOWED;
|
return B_NOT_ALLOWED;
|
||||||
|
|
||||||
if (size > fPhys)
|
if (size > fBufferSize)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
fLen = size;
|
fLength = size;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Private or Reserved
|
// Private or Reserved
|
||||||
|
|
||||||
BMemoryIO::BMemoryIO(const BMemoryIO &)
|
BMemoryIO::BMemoryIO(const BMemoryIO &)
|
||||||
{
|
{
|
||||||
//Copying not allowed
|
//Copying not allowed
|
||||||
@@ -305,33 +273,32 @@ void BMemoryIO::_ReservedMemoryIO1(){}
|
|||||||
void BMemoryIO::_ReservedMemoryIO2(){}
|
void BMemoryIO::_ReservedMemoryIO2(){}
|
||||||
|
|
||||||
|
|
||||||
// *** BMallocIO ***
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// Construction
|
|
||||||
BMallocIO::BMallocIO()
|
BMallocIO::BMallocIO()
|
||||||
: fBlockSize(256),
|
:
|
||||||
fMallocSize(0),
|
fBlockSize(256),
|
||||||
fLength(0),
|
fMallocSize(0),
|
||||||
fData(NULL),
|
fLength(0),
|
||||||
fPosition(0)
|
fData(NULL),
|
||||||
|
fPosition(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Destruction
|
|
||||||
BMallocIO::~BMallocIO()
|
BMallocIO::~BMallocIO()
|
||||||
{
|
{
|
||||||
free(fData);
|
free(fData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ReadAt
|
|
||||||
ssize_t
|
ssize_t
|
||||||
BMallocIO::ReadAt(off_t pos, void *buffer, size_t size)
|
BMallocIO::ReadAt(off_t pos, void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
ssize_t sizeRead = 0;
|
ssize_t sizeRead = 0;
|
||||||
if (pos < fLength) {
|
if (pos < fLength) {
|
||||||
sizeRead = min_c(static_cast<off_t>(size), fLength - pos);
|
sizeRead = min_c(static_cast<off_t>(size), fLength - pos);
|
||||||
@@ -341,20 +308,18 @@ BMallocIO::ReadAt(off_t pos, void *buffer, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// WriteAt
|
|
||||||
ssize_t
|
ssize_t
|
||||||
BMallocIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
BMallocIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
size_t newSize = max_c(pos + size, static_cast<off_t>(fLength));
|
size_t newSize = max_c(pos + size, static_cast<off_t>(fLength));
|
||||||
|
|
||||||
status_t error = B_OK;
|
status_t error = B_OK;
|
||||||
|
|
||||||
if (newSize > fMallocSize)
|
if (newSize > fMallocSize)
|
||||||
error = SetSize(newSize);
|
error = SetSize(newSize);
|
||||||
|
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
memcpy(fData + pos, buffer, size);
|
memcpy(fData + pos, buffer, size);
|
||||||
if (pos + size > fLength)
|
if (pos + size > fLength)
|
||||||
@@ -364,7 +329,6 @@ BMallocIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Seek
|
|
||||||
off_t
|
off_t
|
||||||
BMallocIO::Seek(off_t position, uint32 seekMode)
|
BMallocIO::Seek(off_t position, uint32 seekMode)
|
||||||
{
|
{
|
||||||
@@ -385,7 +349,6 @@ BMallocIO::Seek(off_t position, uint32 seekMode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Position
|
|
||||||
off_t
|
off_t
|
||||||
BMallocIO::Position() const
|
BMallocIO::Position() const
|
||||||
{
|
{
|
||||||
@@ -393,7 +356,6 @@ BMallocIO::Position() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetSize
|
|
||||||
status_t
|
status_t
|
||||||
BMallocIO::SetSize(off_t size)
|
BMallocIO::SetSize(off_t size)
|
||||||
{
|
{
|
||||||
@@ -418,15 +380,14 @@ BMallocIO::SetSize(off_t size)
|
|||||||
error = B_NO_MEMORY;
|
error = B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error == B_OK)
|
if (error == B_OK)
|
||||||
fLength = size;
|
fLength = size;
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetBlockSize
|
|
||||||
void
|
void
|
||||||
BMallocIO::SetBlockSize(size_t blockSize)
|
BMallocIO::SetBlockSize(size_t blockSize)
|
||||||
{
|
{
|
||||||
@@ -437,7 +398,6 @@ BMallocIO::SetBlockSize(size_t blockSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Buffer
|
|
||||||
const void *
|
const void *
|
||||||
BMallocIO::Buffer() const
|
BMallocIO::Buffer() const
|
||||||
{
|
{
|
||||||
@@ -445,7 +405,6 @@ BMallocIO::Buffer() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// BufferLength
|
|
||||||
size_t
|
size_t
|
||||||
BMallocIO::BufferLength() const
|
BMallocIO::BufferLength() const
|
||||||
{
|
{
|
||||||
@@ -454,6 +413,7 @@ BMallocIO::BufferLength() const
|
|||||||
|
|
||||||
|
|
||||||
// Private or Reserved
|
// Private or Reserved
|
||||||
|
|
||||||
BMallocIO::BMallocIO(const BMallocIO &)
|
BMallocIO::BMallocIO(const BMallocIO &)
|
||||||
{
|
{
|
||||||
// copying not allowed...
|
// copying not allowed...
|
||||||
@@ -472,10 +432,3 @@ BMallocIO::operator=(const BMallocIO &)
|
|||||||
void BMallocIO::_ReservedMallocIO1() {}
|
void BMallocIO::_ReservedMallocIO1() {}
|
||||||
void BMallocIO::_ReservedMallocIO2() {}
|
void BMallocIO::_ReservedMallocIO2() {}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* $Log $
|
|
||||||
*
|
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user