1 // VolumeSupport.h 2 3 #ifndef NET_FS_VOLUME_SUPPORT_H 4 #define NET_FS_VOLUME_SUPPORT_H 5 6 #include <dirent.h> 7 8 #include "DebugSupport.h" 9 10 // set_dirent_name 11 static inline 12 status_t 13 set_dirent_name(struct dirent* buffer, size_t bufferSize, const char* name, 14 int32 nameLen) 15 { 16 size_t length = (buffer->d_name + nameLen + 1) - (char*)buffer; 17 if (length <= bufferSize) { 18 memcpy(buffer->d_name, name, nameLen); 19 buffer->d_name[nameLen] = '\0'; 20 buffer->d_reclen = length; 21 return B_OK; 22 } else { 23 RETURN_ERROR(B_BAD_VALUE); 24 } 25 } 26 27 // next_dirent 28 static inline 29 bool 30 next_dirent(struct dirent*& buffer, size_t& bufferSize) 31 { 32 // align 33 char* nextBuffer = (char*)buffer + buffer->d_reclen; 34 nextBuffer = (char*)(((uint32)nextBuffer + 3) & ~0x3); 35 36 // check, if the buffer is at least large enough to align the current entry 37 int32 len = nextBuffer - (char*)buffer; 38 if (len > (int32)bufferSize) 39 return false; 40 41 buffer->d_reclen = len; 42 buffer = (dirent*)nextBuffer; 43 bufferSize -= len; 44 45 return true; 46 } 47 48 #endif // NET_FS_VOLUME_SUPPORT_H 49