1 /* 2 * Copyright 2022, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef FS_OPS_SUPPORT_H 6 #define FS_OPS_SUPPORT_H 7 8 #ifndef FS_SHELL 9 # include <kernel.h> 10 # include <kernel/debug.h> 11 # include <dirent.h> 12 #else 13 # include "fssh_kernel_priv.h" 14 #endif 15 16 17 static struct dirent* 18 next_dirent(struct dirent* dirent, size_t nameLength, size_t& bufferRemaining) 19 { 20 const size_t reclen = offsetof(struct dirent, d_name) + nameLength + 1; 21 ASSERT(reclen <= bufferRemaining); 22 dirent->d_reclen = reclen; 23 24 const size_t roundedReclen = ROUNDUP(reclen, alignof(struct dirent)); 25 if (roundedReclen >= bufferRemaining) { 26 bufferRemaining -= reclen; 27 return NULL; 28 } 29 dirent->d_reclen = roundedReclen; 30 bufferRemaining -= roundedReclen; 31 32 return (struct dirent*)((uint8*)dirent + roundedReclen); 33 } 34 35 36 #endif // FS_OPS_SUPPORT_H 37