* Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "AllocationInfo.h"
#include "File.h"
#include "SizeIndex.h"
#include "Volume.h"
File::File(Volume *volume)
: Node(volume, NODE_TYPE_FILE),
DataContainer(volume)
{
}
File::~File()
{
}
status_t
File::ReadAt(off_t offset, void *buffer, size_t size, size_t *bytesRead)
{
status_t error = DataContainer::ReadAt(offset, buffer, size, bytesRead);
return error;
}
status_t
File::WriteAt(off_t offset, const void *buffer, size_t size,
size_t *bytesWritten)
{
off_t oldSize = DataContainer::GetSize();
status_t error = DataContainer::WriteAt(offset, buffer, size,
bytesWritten);
MarkModified(B_STAT_MODIFICATION_TIME);
if (oldSize != DataContainer::GetSize()) {
MarkModified(B_STAT_SIZE);
if (SizeIndex *index = GetVolume()->GetSizeIndex())
index->Changed(this, oldSize);
}
return error;
}
status_t
File::SetSize(off_t newSize)
{
status_t error = B_OK;
off_t oldSize = DataContainer::GetSize();
if (newSize != oldSize) {
error = DataContainer::Resize(newSize);
MarkModified(B_STAT_SIZE);
if (SizeIndex *index = GetVolume()->GetSizeIndex())
index->Changed(this, oldSize);
}
return error;
}
off_t
File::GetSize() const
{
return DataContainer::GetSize();
}
void
File::GetAllocationInfo(AllocationInfo &info)
{
info.AddFileAllocation(GetSize());
}