1 /* 2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 6 #include "AllocationInfo.h" 7 #include "File.h" 8 #include "SizeIndex.h" 9 #include "Volume.h" 10 11 // constructor 12 File::File(Volume *volume) 13 : Node(volume, NODE_TYPE_FILE), 14 DataContainer(volume) 15 { 16 } 17 18 // destructor 19 File::~File() 20 { 21 } 22 23 // ReadAt 24 status_t 25 File::ReadAt(off_t offset, void *buffer, size_t size, size_t *bytesRead) 26 { 27 status_t error = DataContainer::ReadAt(offset, buffer, size, bytesRead); 28 // TODO: update access time? 29 return error; 30 } 31 32 // WriteAt 33 status_t 34 File::WriteAt(off_t offset, const void *buffer, size_t size, 35 size_t *bytesWritten) 36 { 37 off_t oldSize = DataContainer::GetSize(); 38 status_t error = DataContainer::WriteAt(offset, buffer, size, 39 bytesWritten); 40 MarkModified(B_STAT_MODIFICATION_TIME); 41 42 // update the size index, if our size has changed 43 if (oldSize != DataContainer::GetSize()) { 44 MarkModified(B_STAT_SIZE); 45 46 if (SizeIndex *index = GetVolume()->GetSizeIndex()) 47 index->Changed(this, oldSize); 48 } 49 return error; 50 } 51 52 // SetSize 53 status_t 54 File::SetSize(off_t newSize) 55 { 56 status_t error = B_OK; 57 off_t oldSize = DataContainer::GetSize(); 58 if (newSize != oldSize) { 59 error = DataContainer::Resize(newSize); 60 MarkModified(B_STAT_SIZE); 61 // update the size index 62 if (SizeIndex *index = GetVolume()->GetSizeIndex()) 63 index->Changed(this, oldSize); 64 } 65 return error; 66 } 67 68 // GetSize 69 off_t 70 File::GetSize() const 71 { 72 return DataContainer::GetSize(); 73 } 74 75 // GetAllocationInfo 76 void 77 File::GetAllocationInfo(AllocationInfo &info) 78 { 79 info.AddFileAllocation(GetSize()); 80 } 81 82