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