21 #ifndef _RTEMS_RTEMS_LIBIO__H 22 #define _RTEMS_RTEMS_LIBIO__H 32 #include <rtems/score/assert.h> 46 #define RTEMS_FILESYSTEM_SYMLOOP_MAX 32 59 extern const uint32_t rtems_libio_number_iops;
61 extern void *rtems_libio_iop_free_head;
62 extern void **rtems_libio_iop_free_tail;
95 static inline void rtems_libio_iop_flags_initialize(
102 LIBIO_FLAGS_OPEN | flags,
115 static inline unsigned int rtems_libio_iop_flags_set(
120 return _Atomic_Fetch_or_uint( &iop->flags,
set, ATOMIC_ORDER_RELAXED );
131 static inline unsigned int rtems_libio_iop_flags_clear(
136 return _Atomic_Fetch_and_uint( &iop->flags, ~clear, ATOMIC_ORDER_RELAXED );
150 return &rtems_libio_iops[ fd ];
160 static inline unsigned int rtems_libio_iop_hold(
rtems_libio_t *iop )
162 return _Atomic_Fetch_add_uint(
164 LIBIO_FLAGS_REFERENCE_INC,
174 static inline void rtems_libio_iop_drop(
rtems_libio_t *iop )
176 #if defined(RTEMS_DEBUG) 180 flags = _Atomic_Load_uint( &iop->flags, ATOMIC_ORDER_RELAXED );
183 unsigned int desired;
185 _Assert( flags >= LIBIO_FLAGS_REFERENCE_INC );
187 desired = flags - LIBIO_FLAGS_REFERENCE_INC;
188 success = _Atomic_Compare_exchange_uint(
192 ATOMIC_ORDER_RELEASE,
195 }
while ( !success );
197 _Atomic_Fetch_sub_uint(
199 LIBIO_FLAGS_REFERENCE_INC,
212 #define rtems_libio_iop_to_descriptor(_iop) \ 213 ((_iop) - &rtems_libio_iops[0]) 221 #define rtems_libio_check_is_open(_iop) \ 223 if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \ 234 #define LIBIO_GET_IOP( _fd, _iop ) \ 236 unsigned int _flags; \ 237 if ( (uint32_t) ( _fd ) >= rtems_libio_number_iops ) { \ 238 rtems_set_errno_and_return_minus_one( EBADF ); \ 240 _iop = rtems_libio_iop( _fd ); \ 241 _flags = rtems_libio_iop_hold( _iop ); \ 242 if ( ( _flags & LIBIO_FLAGS_OPEN ) == 0 ) { \ 243 rtems_libio_iop_drop( _iop ); \ 244 rtems_set_errno_and_return_minus_one( EBADF ); \ 254 #define LIBIO_GET_IOP_WITH_ACCESS( _fd, _iop, _access_flags, _access_error ) \ 256 unsigned int _flags; \ 257 unsigned int _mandatory; \ 258 if ( (uint32_t) ( _fd ) >= rtems_libio_number_iops ) { \ 259 rtems_set_errno_and_return_minus_one( EBADF ); \ 261 _iop = rtems_libio_iop( _fd ); \ 262 _flags = rtems_libio_iop_hold( _iop ); \ 263 _mandatory = LIBIO_FLAGS_OPEN | ( _access_flags ); \ 264 if ( ( _flags & _mandatory ) != _mandatory ) { \ 266 rtems_libio_iop_drop( _iop ); \ 267 if ( ( _flags & LIBIO_FLAGS_OPEN ) == 0 ) { \ 270 _error = _access_error; \ 272 rtems_set_errno_and_return_minus_one( _error ); \ 282 #define rtems_libio_check_buffer(_buffer) \ 284 if ((_buffer) == 0) { \ 296 #define rtems_libio_check_count(_count) \ 298 if ((_count) == 0) { \ 337 void rtems_libio_free_user_env(
void *
env );
339 extern pthread_key_t rtems_current_user_env_key;
341 void rtems_libio_lock(
void );
343 void rtems_libio_unlock(
void );
345 static inline void rtems_filesystem_mt_lock(
void )
350 static inline void rtems_filesystem_mt_unlock(
void )
352 rtems_libio_unlock();
357 #define rtems_filesystem_mt_entry_declare_lock_context( ctx ) \ 358 rtems_interrupt_lock_context ctx 360 #define rtems_filesystem_mt_entry_lock( ctx ) \ 361 rtems_interrupt_lock_acquire( &rtems_filesystem_mt_entry_lock_control, &ctx ) 363 #define rtems_filesystem_mt_entry_unlock( ctx ) \ 364 rtems_interrupt_lock_release( &rtems_filesystem_mt_entry_lock_control, &ctx ) 366 static inline void rtems_filesystem_instance_lock(
372 (*mt_entry->ops->lock_h)( mt_entry );
375 static inline void rtems_filesystem_instance_unlock(
381 (*mt_entry->ops->unlock_h)( mt_entry );
417 rtems_filesystem_eval_path_start(
424 rtems_filesystem_eval_path_start_with_parent(
429 int parent_eval_flags
433 rtems_filesystem_eval_path_start_with_root_and_current(
442 void rtems_filesystem_eval_path_continue(
446 void rtems_filesystem_eval_path_cleanup(
450 void rtems_filesystem_eval_path_recursive(
456 void rtems_filesystem_eval_path_cleanup_with_parent(
480 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE,
481 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE,
482 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY
483 } rtems_filesystem_eval_path_generic_status;
513 typedef rtems_filesystem_eval_path_generic_status
526 void rtems_filesystem_eval_path_generic(
553 rtems_filesystem_location_initialize_to_null(
559 &rtems_filesystem_global_location_null.location
564 rtems_filesystem_location_transform_to_global(
625 void rtems_filesystem_location_detach(
629 void rtems_filesystem_location_copy_and_detach(
635 rtems_filesystem_global_location_obtain_null(
void)
642 static inline bool rtems_filesystem_location_is_null(
646 return loc->handlers == &rtems_filesystem_null_handlers;
649 static inline bool rtems_filesystem_global_location_is_null(
653 return rtems_filesystem_location_is_null( &global_loc->location );
656 static inline void rtems_filesystem_location_error(
661 if ( !rtems_filesystem_location_is_null( loc ) ) {
666 int rtems_filesystem_mknod(
676 int rtems_filesystem_chmod(
681 int rtems_filesystem_chown(
687 static inline bool rtems_filesystem_is_ready_for_unmount(
691 bool ready = !mt_entry->mounted
693 && mt_entry->mt_fs_root->reference_count == 1;
702 static inline void rtems_filesystem_location_add_to_mt_entry(
706 rtems_filesystem_mt_entry_declare_lock_context( lock_context );
708 rtems_filesystem_mt_entry_lock( lock_context );
710 &loc->mt_entry->location_chain,
713 rtems_filesystem_mt_entry_unlock( lock_context );
716 void rtems_filesystem_location_remove_from_mt_entry(
720 void rtems_filesystem_do_unmount(
724 static inline bool rtems_filesystem_location_is_instance_root(
730 return (*mt_entry->ops->are_nodes_equal_h)(
732 &mt_entry->mt_fs_root->location
736 static inline const char *rtems_filesystem_eval_path_get_path(
743 static inline size_t rtems_filesystem_eval_path_get_pathlen(
750 static inline void rtems_filesystem_eval_path_set_path(
760 static inline void rtems_filesystem_eval_path_clear_path(
767 static inline const char *rtems_filesystem_eval_path_get_token(
774 static inline size_t rtems_filesystem_eval_path_get_tokenlen(
781 static inline void rtems_filesystem_eval_path_set_token(
791 static inline void rtems_filesystem_eval_path_clear_token(
798 static inline void rtems_filesystem_eval_path_put_back_token(
804 ctx->
path -= tokenlen;
809 void rtems_filesystem_eval_path_eat_delimiter(
813 void rtems_filesystem_eval_path_next_token(
817 static inline void rtems_filesystem_eval_path_get_next_token(
823 rtems_filesystem_eval_path_next_token(ctx);
829 rtems_filesystem_eval_path_get_currentloc(
836 static inline bool rtems_filesystem_eval_path_has_path(
843 static inline bool rtems_filesystem_eval_path_has_token(
850 static inline int rtems_filesystem_eval_path_get_flags(
857 static inline void rtems_filesystem_eval_path_set_flags(
865 static inline void rtems_filesystem_eval_path_clear_and_set_flags(
871 int flags = ctx->
flags;
879 static inline void rtems_filesystem_eval_path_extract_currentloc(
884 rtems_filesystem_location_copy_and_detach(
890 void rtems_filesystem_eval_path_error(
932 bool rtems_filesystem_eval_path_check_access(
940 static inline bool rtems_filesystem_is_delimiter(
char c)
942 return c ==
'/' || c ==
'\\';
945 static inline bool rtems_filesystem_is_current_directory(
950 return tokenlen == 1 && token [0] ==
'.';
953 static inline bool rtems_filesystem_is_parent_directory(
958 return tokenlen == 2 && token [0] ==
'.' && token [1] ==
'.';
961 typedef ssize_t ( *rtems_libio_iovec_adapter )(
963 const struct iovec *iov,
968 static inline ssize_t rtems_libio_iovec_eval(
970 const struct iovec *iov,
973 rtems_libio_iovec_adapter
adapter 989 if ( iovcnt > IOV_MAX )
998 for ( v = 0 ; v < iovcnt ; ++
v ) {
999 size_t len = iov[
v ].iov_len;
1001 if ( len > (
size_t ) ( SSIZE_MAX - total ) ) {
1005 total += ( ssize_t ) len;
1007 if ( iov[ v ].iov_base ==
NULL && len != 0 ) {
1015 total = ( *adapter )( iop, iov, iovcnt, total );
1018 rtems_libio_iop_drop( iop );
1030 static inline mode_t rtems_filesystem_location_type(
1037 (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:254
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:227
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
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:496
#define rtems_set_errno_and_return_minus_one(_error)
Definition: seterr.h:48
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:514
Mount table entry.
Definition: libio.h:1606
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
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
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.
Definition: main_edit.c:207
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