39#ifndef _RTEMS_RTEMS_LIBIO__H
40#define _RTEMS_RTEMS_LIBIO__H
67#define RTEMS_FILESYSTEM_SYMLOOP_MAX 32
80extern const uint32_t rtems_libio_number_iops;
82extern void *rtems_libio_iop_free_head;
83extern void **rtems_libio_iop_free_tail;
114static inline unsigned int rtems_libio_iop_flags_set(
119 return _Atomic_Fetch_or_uint( &iop->flags, set, ATOMIC_ORDER_RELAXED );
130static inline unsigned int rtems_libio_iop_flags_clear(
135 return _Atomic_Fetch_and_uint( &iop->flags, ~clear, ATOMIC_ORDER_RELAXED );
149 return &rtems_libio_iops[ fd ];
159static inline unsigned int rtems_libio_iop_hold(
rtems_libio_t *iop )
161 return _Atomic_Fetch_add_uint(
163 LIBIO_FLAGS_REFERENCE_INC,
175#if defined(RTEMS_DEBUG)
179 flags = _Atomic_Load_uint( &iop->flags, ATOMIC_ORDER_RELAXED );
182 unsigned int desired;
184 _Assert( flags >= LIBIO_FLAGS_REFERENCE_INC );
186 desired = flags - LIBIO_FLAGS_REFERENCE_INC;
187 success = _Atomic_Compare_exchange_uint(
191 ATOMIC_ORDER_RELEASE,
194 }
while ( !success );
196 _Atomic_Fetch_sub_uint(
198 LIBIO_FLAGS_REFERENCE_INC,
211#define rtems_libio_iop_to_descriptor(_iop) \
212 ((_iop) - &rtems_libio_iops[0])
220#define rtems_libio_check_is_open(_iop) \
222 if ((rtems_libio_iop_flags(_iop) & LIBIO_FLAGS_OPEN) == 0) { \
233#define LIBIO_GET_IOP( _fd, _iop ) \
235 unsigned int _flags; \
236 if ( (uint32_t) ( _fd ) >= rtems_libio_number_iops ) { \
237 rtems_set_errno_and_return_minus_one( EBADF ); \
239 _iop = rtems_libio_iop( _fd ); \
240 _flags = rtems_libio_iop_hold( _iop ); \
241 if ( ( _flags & LIBIO_FLAGS_OPEN ) == 0 ) { \
242 rtems_libio_iop_drop( _iop ); \
243 rtems_set_errno_and_return_minus_one( EBADF ); \
253#define LIBIO_GET_IOP_WITH_ACCESS( _fd, _iop, _access_flags, _access_error ) \
255 unsigned int _flags; \
256 unsigned int _mandatory; \
257 if ( (uint32_t) ( _fd ) >= rtems_libio_number_iops ) { \
258 rtems_set_errno_and_return_minus_one( EBADF ); \
260 _iop = rtems_libio_iop( _fd ); \
261 _flags = rtems_libio_iop_hold( _iop ); \
262 _mandatory = LIBIO_FLAGS_OPEN | ( _access_flags ); \
263 if ( ( _flags & _mandatory ) != _mandatory ) { \
265 rtems_libio_iop_drop( _iop ); \
266 if ( ( _flags & LIBIO_FLAGS_OPEN ) == 0 ) { \
269 _error = _access_error; \
271 rtems_set_errno_and_return_minus_one( _error ); \
281#define rtems_libio_check_buffer(_buffer) \
283 if ((_buffer) == 0) { \
295#define rtems_libio_check_count(_count) \
297 if ((_count) == 0) { \
336void rtems_libio_lock(
void );
338void rtems_libio_unlock(
void );
340static inline void rtems_filesystem_mt_lock(
void )
345static inline void rtems_filesystem_mt_unlock(
void )
347 rtems_libio_unlock();
352#define rtems_filesystem_mt_entry_declare_lock_context( ctx ) \
353 rtems_interrupt_lock_context ctx
355#define rtems_filesystem_mt_entry_lock( ctx ) \
356 rtems_interrupt_lock_acquire( &rtems_filesystem_mt_entry_lock_control, &ctx )
358#define rtems_filesystem_mt_entry_unlock( ctx ) \
359 rtems_interrupt_lock_release( &rtems_filesystem_mt_entry_lock_control, &ctx )
361static inline void rtems_filesystem_instance_lock(
367 (*mt_entry->ops->lock_h)( mt_entry );
370static inline void rtems_filesystem_instance_unlock(
376 (*mt_entry->ops->unlock_h)( mt_entry );
411 const struct timespec
times[2]
434 const struct timespec
times[2],
435 struct timespec new_times[2]
471rtems_filesystem_eval_path_start(
478rtems_filesystem_eval_path_start_with_parent(
483 int parent_eval_flags
487rtems_filesystem_eval_path_start_with_root_and_current(
496void rtems_filesystem_eval_path_continue(
500void rtems_filesystem_eval_path_cleanup(
504void rtems_filesystem_eval_path_recursive(
510void rtems_filesystem_eval_path_cleanup_with_parent(
534 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE,
535 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE,
536 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY
537} rtems_filesystem_eval_path_generic_status;
567typedef rtems_filesystem_eval_path_generic_status
580void rtems_filesystem_eval_path_generic(
607rtems_filesystem_location_initialize_to_null(
618rtems_filesystem_location_transform_to_global(
679void rtems_filesystem_location_detach(
683void rtems_filesystem_location_copy_and_detach(
689rtems_filesystem_global_location_obtain_null(
void)
696static inline bool rtems_filesystem_location_is_null(
700 return loc->handlers == &rtems_filesystem_null_handlers;
703static inline bool rtems_filesystem_global_location_is_null(
707 return rtems_filesystem_location_is_null( &global_loc->location );
710static inline void rtems_filesystem_location_error(
715 if ( !rtems_filesystem_location_is_null( loc ) ) {
720int rtems_filesystem_mknod(
730int rtems_filesystem_chmod(
735int rtems_filesystem_chown(
741static inline bool rtems_filesystem_is_ready_for_unmount(
745 bool ready = !mt_entry->mounted
746 && rtems_chain_has_only_one_node( &mt_entry->location_chain )
747 && mt_entry->mt_fs_root->reference_count == 1;
750 rtems_chain_initialize_empty( &mt_entry->location_chain );
756static inline void rtems_filesystem_location_add_to_mt_entry(
760 rtems_filesystem_mt_entry_declare_lock_context( lock_context );
762 rtems_filesystem_mt_entry_lock( lock_context );
763 rtems_chain_append_unprotected(
764 &loc->mt_entry->location_chain,
767 rtems_filesystem_mt_entry_unlock( lock_context );
770void rtems_filesystem_location_remove_from_mt_entry(
774void rtems_filesystem_do_unmount(
778static inline bool rtems_filesystem_location_is_instance_root(
784 return (*mt_entry->ops->are_nodes_equal_h)(
786 &mt_entry->mt_fs_root->location
790static inline const char *rtems_filesystem_eval_path_get_path(
797static inline size_t rtems_filesystem_eval_path_get_pathlen(
804static inline void rtems_filesystem_eval_path_set_path(
814static inline void rtems_filesystem_eval_path_clear_path(
821static inline const char *rtems_filesystem_eval_path_get_token(
828static inline size_t rtems_filesystem_eval_path_get_tokenlen(
835static inline void rtems_filesystem_eval_path_set_token(
845static inline void rtems_filesystem_eval_path_clear_token(
852static inline void rtems_filesystem_eval_path_put_back_token(
858 ctx->
path -= tokenlen;
863void rtems_filesystem_eval_path_eat_delimiter(
867void rtems_filesystem_eval_path_next_token(
871static inline void rtems_filesystem_eval_path_get_next_token(
877 rtems_filesystem_eval_path_next_token(ctx);
883rtems_filesystem_eval_path_get_currentloc(
890static inline bool rtems_filesystem_eval_path_has_path(
897static inline bool rtems_filesystem_eval_path_has_token(
904static inline int rtems_filesystem_eval_path_get_flags(
911static inline void rtems_filesystem_eval_path_set_flags(
919static inline void rtems_filesystem_eval_path_clear_and_set_flags(
925 int flags = ctx->
flags;
933static inline void rtems_filesystem_eval_path_extract_currentloc(
938 rtems_filesystem_location_copy_and_detach(
944void rtems_filesystem_eval_path_error(
986bool rtems_filesystem_eval_path_check_access(
994static inline bool rtems_filesystem_is_delimiter(
char c)
996 return c ==
'/' || c ==
'\\';
999static inline bool rtems_filesystem_is_current_directory(
1004 return tokenlen == 1 && token [0] ==
'.';
1007static inline bool rtems_filesystem_is_parent_directory(
1012 return tokenlen == 2 && token [0] ==
'.' && token [1] ==
'.';
1015typedef ssize_t ( *rtems_libio_iovec_adapter )(
1017 const struct iovec *iov,
1022static inline ssize_t rtems_libio_iovec_eval(
1024 const struct iovec *iov,
1027 rtems_libio_iovec_adapter adapter
1043 if ( iovcnt > IOV_MAX )
1052 for ( v = 0 ; v < iovcnt ; ++v ) {
1053 size_t len = iov[ v ].iov_len;
1055 if ( len > (
size_t ) ( SSIZE_MAX - total ) ) {
1059 total += ( ssize_t ) len;
1061 if ( iov[ v ].iov_base ==
NULL && len != 0 ) {
1069 total = ( *adapter )( iop, iov, iovcnt, total );
1072 rtems_libio_iop_drop( iop );
1084static inline mode_t rtems_filesystem_location_type(
1091 (void) ( *loc->handlers->fstat_h )( loc, &st );
clock_t times(struct tms *ptms)
Definition: __times.c:97
This header file provides the interfaces of the Assert Handler.
#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:253
int rtems_filesystem_utime_check_permissions(const rtems_filesystem_location_info_t *currentloc, const struct timespec times[2])
Checks for errors and if the process has write permissions to the file.
Definition: utimensat.c:75
unsigned int rtems_libio_fcntl_flags(int fcntl_flags)
Definition: libio.c:80
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:550
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:108
rtems_filesystem_global_location_t rtems_filesystem_global_location_null
The global null location.
Definition: __usrenv.c:246
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:330
bool rtems_filesystem_utime_tv_nsec_valid(struct timespec time)
Checks the tv_nsec member of a timespec struct.
Definition: utimensat.c:53
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:102
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:175
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:198
int rtems_libio_to_fcntl_flags(unsigned int flags)
Definition: libio.c:105
rtems_libio_t * rtems_libio_allocate(void)
Definition: libio.c:128
void rtems_filesystem_location_free(rtems_filesystem_location_info_t *loc)
Releases all resources of a location.
Definition: freenode.c:44
void rtems_filesystem_location_clone(rtems_filesystem_location_info_t *clone, const rtems_filesystem_location_info_t *master)
Clones a node.
Definition: clonenode.c:41
void rtems_libio_free(rtems_libio_t *iop)
Definition: libio.c:152
int rtems_filesystem_utime_update(const struct timespec times[2], struct timespec new_times[2])
Checks times and fills new_times with the time to be written.
Definition: utimensat.c:120
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:41
void rtems_filesystem_initialize(void)
Base File System Initialization.
Definition: base_fs.c:51
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:568
#define rtems_set_errno_and_return_minus_one(_error)
Definition: seterr.h:67
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
POSIX Threads Private Support.
This header file defines the RTEMS Classic API.
This header file provides the interfaces of the Timespec Helpers.
This header file defines macros to set errno and return minus one.
ISR lock control.
Definition: isrlock.h:72
File system node operations table.
Definition: libio.h:1021
Definition: deflate.c:114
Path evaluation context.
Definition: libio.h:103
rtems_filesystem_location_info_t currentloc
Definition: libio.h:154
const char * path
Definition: libio.h:107
size_t pathlen
Definition: libio.h:112
size_t tokenlen
Definition: libio.h:124
const char * token
Definition: libio.h:118
int flags
Definition: libio.h:138
Global file system location.
Definition: fs.h:100
File system location.
Definition: fs.h:72
Mount table entry.
Definition: libio.h:1622
An open file data structure.
Definition: libio.h:1338
User Environment Support.