1 // SymLink.cpp 2 3 #include <limits.h> 4 5 #include "AllocationInfo.h" 6 #include "Debug.h" 7 #include "SizeIndex.h" 8 #include "SymLink.h" 9 #include "Volume.h" 10 11 // constructor 12 SymLink::SymLink(Volume *volume) 13 : Node(volume, NODE_TYPE_SYMLINK), 14 fLinkedPath() 15 { 16 } 17 18 // destructor 19 SymLink::~SymLink() 20 { 21 } 22 23 // SetSize 24 status_t 25 SymLink::SetSize(off_t newSize) 26 { 27 status_t error = (newSize >= 0 && newSize < PATH_MAX ? B_OK : B_BAD_VALUE); 28 int32 oldSize = GetLinkedPathLength(); 29 if (error == B_OK && newSize < oldSize) { 30 fLinkedPath.Truncate(newSize); 31 MarkModified(B_STAT_SIZE); 32 // update the size index 33 if (SizeIndex *index = GetVolume()->GetSizeIndex()) 34 index->Changed(this, oldSize); 35 } 36 return error; 37 } 38 39 // GetSize 40 off_t 41 SymLink::GetSize() const 42 { 43 return GetLinkedPathLength(); 44 } 45 46 // SetLinkedPath 47 status_t 48 SymLink::SetLinkedPath(const char *path) 49 { 50 int32 oldLen = GetLinkedPathLength(); 51 int32 len = strnlen(path, PATH_MAX - 1); 52 if (fLinkedPath.SetTo(path, len)) { 53 MarkModified(B_STAT_MODIFICATION_TIME); 54 // update the size index, if necessary 55 if (len != oldLen) { 56 MarkModified(B_STAT_SIZE); 57 58 if (SizeIndex *index = GetVolume()->GetSizeIndex()) 59 index->Changed(this, oldLen); 60 } 61 return B_OK; 62 } 63 RETURN_ERROR(B_NO_MEMORY); 64 } 65 66 // GetAllocationInfo 67 void 68 SymLink::GetAllocationInfo(AllocationInfo &info) 69 { 70 info.AddSymLinkAllocation(GetSize()); 71 } 72 73