xref: /haiku/src/add-ons/kernel/file_systems/netfs/client/VolumeSupport.h (revision 20f046edb99c55b1af0a17340ff8a581d000bc5c)
15a1d355fSStephan Aßmus // VolumeSupport.h
25a1d355fSStephan Aßmus 
35a1d355fSStephan Aßmus #ifndef NET_FS_VOLUME_SUPPORT_H
45a1d355fSStephan Aßmus #define NET_FS_VOLUME_SUPPORT_H
55a1d355fSStephan Aßmus 
65a1d355fSStephan Aßmus #include <dirent.h>
75a1d355fSStephan Aßmus 
85a1d355fSStephan Aßmus #include "DebugSupport.h"
95a1d355fSStephan Aßmus 
105a1d355fSStephan Aßmus // set_dirent_name
115a1d355fSStephan Aßmus static inline
125a1d355fSStephan Aßmus status_t
set_dirent_name(struct dirent * buffer,size_t bufferSize,const char * name,int32 nameLen)135a1d355fSStephan Aßmus set_dirent_name(struct dirent* buffer, size_t bufferSize, const char* name,
145a1d355fSStephan Aßmus 	int32 nameLen)
155a1d355fSStephan Aßmus {
165a1d355fSStephan Aßmus 	size_t length = (buffer->d_name + nameLen + 1) - (char*)buffer;
175a1d355fSStephan Aßmus 	if (length <= bufferSize) {
185a1d355fSStephan Aßmus 		memcpy(buffer->d_name, name, nameLen);
195a1d355fSStephan Aßmus 		buffer->d_name[nameLen] = '\0';
205a1d355fSStephan Aßmus 		buffer->d_reclen = length;
215a1d355fSStephan Aßmus 		return B_OK;
225a1d355fSStephan Aßmus 	} else {
235a1d355fSStephan Aßmus 		RETURN_ERROR(B_BAD_VALUE);
245a1d355fSStephan Aßmus 	}
255a1d355fSStephan Aßmus }
265a1d355fSStephan Aßmus 
275a1d355fSStephan Aßmus // next_dirent
285a1d355fSStephan Aßmus static inline
295a1d355fSStephan Aßmus bool
next_dirent(struct dirent * & buffer,size_t & bufferSize)305a1d355fSStephan Aßmus next_dirent(struct dirent*& buffer, size_t& bufferSize)
315a1d355fSStephan Aßmus {
325a1d355fSStephan Aßmus 	// align
335a1d355fSStephan Aßmus 	char* nextBuffer = (char*)buffer + buffer->d_reclen;
34*20f046edSJérôme Duval 	nextBuffer = (char*)(((addr_t)nextBuffer + 3) & ~0x3);
355a1d355fSStephan Aßmus 
365a1d355fSStephan Aßmus 	// check, if the buffer is at least large enough to align the current entry
375a1d355fSStephan Aßmus 	int32 len = nextBuffer - (char*)buffer;
385a1d355fSStephan Aßmus 	if (len > (int32)bufferSize)
395a1d355fSStephan Aßmus 		return false;
405a1d355fSStephan Aßmus 
415a1d355fSStephan Aßmus 	buffer->d_reclen = len;
425a1d355fSStephan Aßmus 	buffer = (dirent*)nextBuffer;
435a1d355fSStephan Aßmus 	bufferSize -= len;
445a1d355fSStephan Aßmus 
455a1d355fSStephan Aßmus 	return true;
465a1d355fSStephan Aßmus }
475a1d355fSStephan Aßmus 
485a1d355fSStephan Aßmus #endif	// NET_FS_VOLUME_SUPPORT_H
49