21 #ifndef _RTEMS_RTEMS_LIBIO__H 22 #define _RTEMS_RTEMS_LIBIO__H 48 #define RTEMS_FILESYSTEM_SYMLOOP_MAX 32 61 extern const uint32_t rtems_libio_number_iops;
63 extern void *rtems_libio_iop_free_head;
64 extern void **rtems_libio_iop_free_tail;
95 static inline unsigned int rtems_libio_iop_flags_set(
100 return _Atomic_Fetch_or_uint( &iop->flags, set, ATOMIC_ORDER_RELAXED );
111 static inline unsigned int rtems_libio_iop_flags_clear(
116 return _Atomic_Fetch_and_uint( &iop->flags, ~clear, ATOMIC_ORDER_RELAXED );
130 return &rtems_libio_iops[ fd ];
140 static inline unsigned int rtems_libio_iop_hold(
rtems_libio_t *iop )
142 return _Atomic_Fetch_add_uint(
144 LIBIO_FLAGS_REFERENCE_INC,
154 static inline void rtems_libio_iop_drop(
rtems_libio_t *iop )
156 #if defined(RTEMS_DEBUG) 160 flags = _Atomic_Load_uint( &iop->flags, ATOMIC_ORDER_RELAXED );
163 unsigned int desired;
165 _Assert( flags >= LIBIO_FLAGS_REFERENCE_INC );
167 desired = flags - LIBIO_FLAGS_REFERENCE_INC;
168 success = _Atomic_Compare_exchange_uint(
172 ATOMIC_ORDER_RELEASE,
175 }
while ( !success );
177 _Atomic_Fetch_sub_uint(
179 LIBIO_FLAGS_REFERENCE_INC,
192 #define rtems_libio_iop_to_descriptor(_iop) \ 193 ((_iop) - &rtems_libio_iops[0]) 201 #define rtems_libio_check_is_open(_iop) \ 203 if ((rtems_libio_iop_flags(_iop) & LIBIO_FLAGS_OPEN) == 0) { \ 214 #define LIBIO_GET_IOP( _fd, _iop ) \ 216 unsigned int _flags; \ 217 if ( (uint32_t) ( _fd ) >= rtems_libio_number_iops ) { \ 218 rtems_set_errno_and_return_minus_one( EBADF ); \ 220 _iop = rtems_libio_iop( _fd ); \ 221 _flags = rtems_libio_iop_hold( _iop ); \ 222 if ( ( _flags & LIBIO_FLAGS_OPEN ) == 0 ) { \ 223 rtems_libio_iop_drop( _iop ); \ 224 rtems_set_errno_and_return_minus_one( EBADF ); \ 234 #define LIBIO_GET_IOP_WITH_ACCESS( _fd, _iop, _access_flags, _access_error ) \ 236 unsigned int _flags; \ 237 unsigned int _mandatory; \ 238 if ( (uint32_t) ( _fd ) >= rtems_libio_number_iops ) { \ 239 rtems_set_errno_and_return_minus_one( EBADF ); \ 241 _iop = rtems_libio_iop( _fd ); \ 242 _flags = rtems_libio_iop_hold( _iop ); \ 243 _mandatory = LIBIO_FLAGS_OPEN | ( _access_flags ); \ 244 if ( ( _flags & _mandatory ) != _mandatory ) { \ 246 rtems_libio_iop_drop( _iop ); \ 247 if ( ( _flags & LIBIO_FLAGS_OPEN ) == 0 ) { \ 250 _error = _access_error; \ 252 rtems_set_errno_and_return_minus_one( _error ); \ 262 #define rtems_libio_check_buffer(_buffer) \ 264 if ((_buffer) == 0) { \ 276 #define rtems_libio_check_count(_count) \ 278 if ((_count) == 0) { \ 317 void rtems_libio_lock(
void );
319 void rtems_libio_unlock(
void );
321 static inline void rtems_filesystem_mt_lock(
void )
326 static inline void rtems_filesystem_mt_unlock(
void )
328 rtems_libio_unlock();
333 #define rtems_filesystem_mt_entry_declare_lock_context( ctx ) \ 334 rtems_interrupt_lock_context ctx 336 #define rtems_filesystem_mt_entry_lock( ctx ) \ 337 rtems_interrupt_lock_acquire( &rtems_filesystem_mt_entry_lock_control, &ctx ) 339 #define rtems_filesystem_mt_entry_unlock( ctx ) \ 340 rtems_interrupt_lock_release( &rtems_filesystem_mt_entry_lock_control, &ctx ) 342 static inline void rtems_filesystem_instance_lock(
348 (*mt_entry->ops->lock_h)( mt_entry );
351 static inline void rtems_filesystem_instance_unlock(
357 (*mt_entry->ops->unlock_h)( mt_entry );
393 rtems_filesystem_eval_path_start(
400 rtems_filesystem_eval_path_start_with_parent(
405 int parent_eval_flags
409 rtems_filesystem_eval_path_start_with_root_and_current(
418 void rtems_filesystem_eval_path_continue(
422 void rtems_filesystem_eval_path_cleanup(
426 void rtems_filesystem_eval_path_recursive(
432 void rtems_filesystem_eval_path_cleanup_with_parent(
456 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE,
457 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE,
458 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY
459 } rtems_filesystem_eval_path_generic_status;
489 typedef rtems_filesystem_eval_path_generic_status
502 void rtems_filesystem_eval_path_generic(
529 rtems_filesystem_location_initialize_to_null(
540 rtems_filesystem_location_transform_to_global(
601 void rtems_filesystem_location_detach(
605 void rtems_filesystem_location_copy_and_detach(
611 rtems_filesystem_global_location_obtain_null(
void)
618 static inline bool rtems_filesystem_location_is_null(
622 return loc->handlers == &rtems_filesystem_null_handlers;
625 static inline bool rtems_filesystem_global_location_is_null(
629 return rtems_filesystem_location_is_null( &global_loc->location );
632 static inline void rtems_filesystem_location_error(
637 if ( !rtems_filesystem_location_is_null( loc ) ) {
642 int rtems_filesystem_mknod(
652 int rtems_filesystem_chmod(
657 int rtems_filesystem_chown(
663 static inline bool rtems_filesystem_is_ready_for_unmount(
667 bool ready = !mt_entry->mounted
669 && mt_entry->mt_fs_root->reference_count == 1;
678 static inline void rtems_filesystem_location_add_to_mt_entry(
682 rtems_filesystem_mt_entry_declare_lock_context( lock_context );
684 rtems_filesystem_mt_entry_lock( lock_context );
686 &loc->mt_entry->location_chain,
689 rtems_filesystem_mt_entry_unlock( lock_context );
692 void rtems_filesystem_location_remove_from_mt_entry(
696 void rtems_filesystem_do_unmount(
700 static inline bool rtems_filesystem_location_is_instance_root(
706 return (*mt_entry->ops->are_nodes_equal_h)(
708 &mt_entry->mt_fs_root->location
712 static inline const char *rtems_filesystem_eval_path_get_path(
719 static inline size_t rtems_filesystem_eval_path_get_pathlen(
726 static inline void rtems_filesystem_eval_path_set_path(
736 static inline void rtems_filesystem_eval_path_clear_path(
743 static inline const char *rtems_filesystem_eval_path_get_token(
750 static inline size_t rtems_filesystem_eval_path_get_tokenlen(
757 static inline void rtems_filesystem_eval_path_set_token(
767 static inline void rtems_filesystem_eval_path_clear_token(
774 static inline void rtems_filesystem_eval_path_put_back_token(
780 ctx->
path -= tokenlen;
785 void rtems_filesystem_eval_path_eat_delimiter(
789 void rtems_filesystem_eval_path_next_token(
793 static inline void rtems_filesystem_eval_path_get_next_token(
799 rtems_filesystem_eval_path_next_token(ctx);
805 rtems_filesystem_eval_path_get_currentloc(
812 static inline bool rtems_filesystem_eval_path_has_path(
819 static inline bool rtems_filesystem_eval_path_has_token(
826 static inline int rtems_filesystem_eval_path_get_flags(
833 static inline void rtems_filesystem_eval_path_set_flags(
841 static inline void rtems_filesystem_eval_path_clear_and_set_flags(
847 int flags = ctx->
flags;
855 static inline void rtems_filesystem_eval_path_extract_currentloc(
860 rtems_filesystem_location_copy_and_detach(
866 void rtems_filesystem_eval_path_error(
908 bool rtems_filesystem_eval_path_check_access(
916 static inline bool rtems_filesystem_is_delimiter(
char c)
918 return c ==
'/' || c ==
'\\';
921 static inline bool rtems_filesystem_is_current_directory(
926 return tokenlen == 1 && token [0] ==
'.';
929 static inline bool rtems_filesystem_is_parent_directory(
934 return tokenlen == 2 && token [0] ==
'.' && token [1] ==
'.';
937 typedef ssize_t ( *rtems_libio_iovec_adapter )(
939 const struct iovec *iov,
944 static inline ssize_t rtems_libio_iovec_eval(
946 const struct iovec *iov,
949 rtems_libio_iovec_adapter
adapter 965 if ( iovcnt > IOV_MAX )
974 for (
v = 0 ;
v < iovcnt ; ++
v ) {
975 size_t len = iov[
v ].iov_len;
977 if ( len > (
size_t ) ( SSIZE_MAX - total ) ) {
981 total += ( ssize_t ) len;
983 if ( iov[
v ].iov_base ==
NULL && len != 0 ) {
991 total = ( *adapter )( iop, iov, iovcnt, total );
994 rtems_libio_iop_drop( iop );
1006 static inline mode_t rtems_filesystem_location_type(
1013 (void) ( *loc->handlers->fstat_h )( loc, &st );
RTEMS_INLINE_ROUTINE bool rtems_chain_has_only_one_node(const rtems_chain_control *the_chain)
Does this chain have only one node.
Definition: chain.h:522
#define LIBIO_GET_IOP_WITH_ACCESS(_fd, _iop, _access_flags, _access_error)
Macro to get the iop for the specified file descriptor with access flags and error.
Definition: libio_.h:234
const char * token
Definition: libio.h:99
RTEMS_INLINE_ROUTINE void rtems_chain_initialize_empty(rtems_chain_control *the_chain)
Initialize this chain as empty.
Definition: chain.h:168
int rtems_filesystem_location_exists_in_same_instance_as(const rtems_filesystem_location_info_t *a, const rtems_filesystem_location_info_t *b)
Checks that the locations exist in the same file system instance.
Definition: sup_fs_exist_in_same_instance.c:28
Definition: deflate.c:115
void rtems_filesystem_global_location_release(rtems_filesystem_global_location_t *global_loc, bool deferred)
Releases a global file system location.
Definition: sup_fs_location.c:186
Data which Ease the Burden of Consistently Setting Errno.
User Environment Support.
int flags
Definition: libio.h:119
int rtems_libio_to_fcntl_flags(unsigned int flags)
Definition: libio.c:86
POSIX Threads Private Support.
rtems_filesystem_global_location_t rtems_filesystem_global_location_null
The global null location.
Definition: __usrenv.c:229
void rtems_libio_free(rtems_libio_t *iop)
Definition: libio.c:133
void rtems_filesystem_global_location_assign(rtems_filesystem_global_location_t **lhs_global_loc_ptr, rtems_filesystem_global_location_t *rhs_global_loc)
Assigns a global file system location.
Definition: sup_fs_location.c:96
size_t tokenlen
Definition: libio.h:105
ISR lock control.
Definition: isrlock.h:56
File system node operations table.
Definition: libio.h:1005
RTEMS_INLINE_ROUTINE void rtems_chain_append_unprotected(rtems_chain_control *the_chain, rtems_chain_node *the_node)
Append a node on the end of a chain (unprotected).
Definition: chain.h:679
Information for the Assert Handler.
void rtems_filesystem_location_clone(rtems_filesystem_location_info_t *clone, const rtems_filesystem_location_info_t *master)
Clones a node.
Definition: clonenode.c:28
bool(* rtems_filesystem_eval_path_is_directory)(rtems_filesystem_eval_path_context_t *ctx, void *arg)
Tests if the current location is a directory.
Definition: libio_.h:472
rtems_filesystem_location_info_t currentloc
Definition: libio.h:135
void rtems_filesystem_location_free(rtems_filesystem_location_info_t *loc)
Releases all resources of a location.
Definition: freenode.c:25
rtems_filesystem_eval_path_generic_status(* rtems_filesystem_eval_path_eval_token)(rtems_filesystem_eval_path_context_t *ctx, void *arg, const char *token, size_t tokenlen)
Evaluates a token.
Definition: libio_.h:490
Mount table entry.
Definition: libio.h:1604
Path evaluation context.
Definition: libio.h:84
unsigned int rtems_libio_fcntl_flags(int fcntl_flags)
Definition: libio.c:61
An open file data structure.
Definition: libio.h:1320
bool rtems_filesystem_check_access(int flags, mode_t object_mode, uid_t object_uid, gid_t object_gid)
Checks if access to an object is allowed for the current user.
Definition: sup_fs_check_permissions.c:89
const char * path
Definition: libio.h:88
rtems_libio_t * rtems_libio_allocate(void)
Definition: libio.c:109
rtems_filesystem_global_location_t * rtems_filesystem_global_location_obtain(rtems_filesystem_global_location_t *const *global_loc_ptr)
Obtains a global file system location.
Definition: sup_fs_location.c:163
#define rtems_set_errno_and_return_minus_one(_error)
Definition: seterr.h:48
size_t pathlen
Definition: libio.h:93
unsigned v
Definition: tte.h:73
void rtems_filesystem_eval_path_restart(rtems_filesystem_eval_path_context_t *ctx, rtems_filesystem_global_location_t **newstartloc_ptr)
Requests a path evaluation restart.
Definition: sup_fs_eval_path.c:317
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
rtems_filesystem_location_info_t * rtems_filesystem_location_copy(rtems_filesystem_location_info_t *dst, const rtems_filesystem_location_info_t *src)
Copies a location.
Global file system location.
Definition: fs.h:81
void rtems_filesystem_initialize(void)
Base File System Initialization.
Definition: base_fs.c:32
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
File system location.
Definition: fs.h:53