21#ifndef _RTEMS_RTEMS_LIBIO__H
22#define _RTEMS_RTEMS_LIBIO__H
48#define RTEMS_FILESYSTEM_SYMLOOP_MAX 32
61extern const uint32_t rtems_libio_number_iops;
63extern void *rtems_libio_iop_free_head;
64extern void **rtems_libio_iop_free_tail;
95static inline unsigned int rtems_libio_iop_flags_set(
100 return _Atomic_Fetch_or_uint( &iop->flags, set, ATOMIC_ORDER_RELAXED );
111static 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 ];
140static inline unsigned int rtems_libio_iop_hold(
rtems_libio_t *iop )
142 return _Atomic_Fetch_add_uint(
144 LIBIO_FLAGS_REFERENCE_INC,
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) { \
317void rtems_libio_lock(
void );
319void rtems_libio_unlock(
void );
321static inline void rtems_filesystem_mt_lock(
void )
326static 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 )
342static inline void rtems_filesystem_instance_lock(
348 (*mt_entry->ops->lock_h)( mt_entry );
351static inline void rtems_filesystem_instance_unlock(
357 (*mt_entry->ops->unlock_h)( mt_entry );
393rtems_filesystem_eval_path_start(
400rtems_filesystem_eval_path_start_with_parent(
405 int parent_eval_flags
409rtems_filesystem_eval_path_start_with_root_and_current(
418void rtems_filesystem_eval_path_continue(
422void rtems_filesystem_eval_path_cleanup(
426void rtems_filesystem_eval_path_recursive(
432void 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;
489typedef rtems_filesystem_eval_path_generic_status
502void rtems_filesystem_eval_path_generic(
529rtems_filesystem_location_initialize_to_null(
540rtems_filesystem_location_transform_to_global(
601void rtems_filesystem_location_detach(
605void rtems_filesystem_location_copy_and_detach(
611rtems_filesystem_global_location_obtain_null(
void)
618static inline bool rtems_filesystem_location_is_null(
622 return loc->handlers == &rtems_filesystem_null_handlers;
625static inline bool rtems_filesystem_global_location_is_null(
629 return rtems_filesystem_location_is_null( &global_loc->location );
632static inline void rtems_filesystem_location_error(
637 if ( !rtems_filesystem_location_is_null( loc ) ) {
642int rtems_filesystem_mknod(
652int rtems_filesystem_chmod(
657int rtems_filesystem_chown(
663static inline bool rtems_filesystem_is_ready_for_unmount(
667 bool ready = !mt_entry->mounted
669 && mt_entry->mt_fs_root->reference_count == 1;
678static 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 );
692void rtems_filesystem_location_remove_from_mt_entry(
696void rtems_filesystem_do_unmount(
700static inline bool rtems_filesystem_location_is_instance_root(
706 return (*mt_entry->ops->are_nodes_equal_h)(
708 &mt_entry->mt_fs_root->location
712static inline const char *rtems_filesystem_eval_path_get_path(
719static inline size_t rtems_filesystem_eval_path_get_pathlen(
726static inline void rtems_filesystem_eval_path_set_path(
736static inline void rtems_filesystem_eval_path_clear_path(
743static inline const char *rtems_filesystem_eval_path_get_token(
750static inline size_t rtems_filesystem_eval_path_get_tokenlen(
757static inline void rtems_filesystem_eval_path_set_token(
767static inline void rtems_filesystem_eval_path_clear_token(
774static inline void rtems_filesystem_eval_path_put_back_token(
780 ctx->
path -= tokenlen;
785void rtems_filesystem_eval_path_eat_delimiter(
789void rtems_filesystem_eval_path_next_token(
793static inline void rtems_filesystem_eval_path_get_next_token(
799 rtems_filesystem_eval_path_next_token(ctx);
805rtems_filesystem_eval_path_get_currentloc(
812static inline bool rtems_filesystem_eval_path_has_path(
819static inline bool rtems_filesystem_eval_path_has_token(
826static inline int rtems_filesystem_eval_path_get_flags(
833static inline void rtems_filesystem_eval_path_set_flags(
841static inline void rtems_filesystem_eval_path_clear_and_set_flags(
847 int flags = ctx->
flags;
855static inline void rtems_filesystem_eval_path_extract_currentloc(
860 rtems_filesystem_location_copy_and_detach(
866void rtems_filesystem_eval_path_error(
908bool rtems_filesystem_eval_path_check_access(
916static inline bool rtems_filesystem_is_delimiter(
char c)
918 return c ==
'/' || c ==
'\\';
921static inline bool rtems_filesystem_is_current_directory(
926 return tokenlen == 1 && token [0] ==
'.';
929static inline bool rtems_filesystem_is_parent_directory(
934 return tokenlen == 2 && token [0] ==
'.' && token [1] ==
'.';
937typedef ssize_t ( *rtems_libio_iovec_adapter )(
939 const struct iovec *iov,
944static 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 );
1006static inline mode_t rtems_filesystem_location_type(
1013 (void) ( *loc->handlers->fstat_h )( loc, &st );
Information for the Assert Handler.
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
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
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
RTEMS_INLINE_ROUTINE void rtems_chain_initialize_empty(rtems_chain_control *the_chain)
Initialize this chain as empty.
Definition: chain.h:168
#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
unsigned int rtems_libio_fcntl_flags(int fcntl_flags)
Definition: libio.c:61
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
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
rtems_filesystem_global_location_t rtems_filesystem_global_location_null
The global null location.
Definition: __usrenv.c:229
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
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
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
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
int rtems_libio_to_fcntl_flags(unsigned int flags)
Definition: libio.c:86
rtems_libio_t * rtems_libio_allocate(void)
Definition: libio.c:109
void rtems_filesystem_location_free(rtems_filesystem_location_info_t *loc)
Releases all resources of a location.
Definition: freenode.c:25
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
void rtems_libio_free(rtems_libio_t *iop)
Definition: libio.c:133
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
void rtems_filesystem_initialize(void)
Base File System Initialization.
Definition: base_fs.c:32
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.
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
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
#define rtems_set_errno_and_return_minus_one(_error)
Definition: seterr.h:48
POSIX Threads Private Support.
Data which Ease the Burden of Consistently Setting Errno.
ISR lock control.
Definition: isrlock.h:56
File system node operations table.
Definition: libio.h:1005
Definition: deflate.c:115
Path evaluation context.
Definition: libio.h:84
rtems_filesystem_location_info_t currentloc
Definition: libio.h:135
const char * path
Definition: libio.h:88
size_t pathlen
Definition: libio.h:93
size_t tokenlen
Definition: libio.h:105
const char * token
Definition: libio.h:99
int flags
Definition: libio.h:119
Global file system location.
Definition: fs.h:81
File system location.
Definition: fs.h:53
Mount table entry.
Definition: libio.h:1604
An open file data structure.
Definition: libio.h:1320
unsigned v
Definition: tte.h:0
User Environment Support.