file_systems/fs_ops_support: Add open_mode_to_access.
This is duplicated across multiple filesystems, and could probably be used in more still. Adjusted only BFS, EXT2, and NTFS in this commit, as they are the ones which make use of fs_ops_support.h already and thus need to be modified to avoid duplicate-definition errors. Also tweak next_dirent to support being built under fs_shell. (Possibly we should define ASSERT there, though?)
This commit is contained in:
@@ -14,6 +14,22 @@
|
||||
#endif
|
||||
|
||||
|
||||
/*! Converts a given open mode (e.g. O_RDONLY) into access modes (e.g. R_OK).
|
||||
*/
|
||||
static inline int
|
||||
open_mode_to_access(int openMode)
|
||||
{
|
||||
openMode &= O_RWMASK;
|
||||
if (openMode == O_RDONLY)
|
||||
return R_OK;
|
||||
if (openMode == O_WRONLY)
|
||||
return W_OK;
|
||||
if (openMode == O_RDWR)
|
||||
return R_OK | W_OK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! Computes and assigns `dirent->d_reclen`, adjusts `bufferRemaining` accordingly,
|
||||
* and either advances to the next buffer, or returns NULL if no space remains.
|
||||
*/
|
||||
@@ -21,7 +37,9 @@ static inline struct dirent*
|
||||
next_dirent(struct dirent* dirent, size_t nameLength, size_t& bufferRemaining)
|
||||
{
|
||||
const size_t reclen = offsetof(struct dirent, d_name) + nameLength + 1;
|
||||
#ifdef ASSERT
|
||||
ASSERT(reclen <= bufferRemaining);
|
||||
#endif
|
||||
dirent->d_reclen = reclen;
|
||||
|
||||
const size_t roundedReclen = ROUNDUP(reclen, alignof(struct dirent));
|
||||
|
||||
Reference in New Issue
Block a user