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;
141static inline void rtems_libio_free(
156 const unsigned int flags = rtems_libio_iop_flags( iop );
157 if ( ( ( flags & LIBIO_FLAGS_OPEN ) == 0 )
158 && ( ( flags & LIBIO_FLAGS_REFERENCE_MASK ) == 0 ) ) {
171static inline unsigned int rtems_libio_iop_flags_set(
176 return _Atomic_Fetch_or_uint( &iop->flags, set, ATOMIC_ORDER_RELAXED );
187static inline unsigned int rtems_libio_iop_flags_clear(
192 return _Atomic_Fetch_and_uint( &iop->flags, ~clear, ATOMIC_ORDER_RELAXED );
206 return &rtems_libio_iops[ fd ];
216static inline unsigned int rtems_libio_iop_hold(
rtems_libio_t *iop )
218 return _Atomic_Fetch_add_uint(
220 LIBIO_FLAGS_REFERENCE_INC,
232#if defined(RTEMS_DEBUG)
236 flags = _Atomic_Load_uint( &iop->flags, ATOMIC_ORDER_RELAXED );
239 unsigned int desired;
241 _Assert( flags >= LIBIO_FLAGS_REFERENCE_INC );
243 desired = flags - LIBIO_FLAGS_REFERENCE_INC;
245 success = _Atomic_Compare_exchange_uint(
249 ATOMIC_ORDER_RELEASE,
252 }
while ( !success );
254 _Atomic_Fetch_sub_uint(
256 LIBIO_FLAGS_REFERENCE_INC,
261 rtems_libio_free( iop );
271#define rtems_libio_iop_to_descriptor(_iop) \
272 ((_iop) - &rtems_libio_iops[0])
280#define rtems_libio_check_is_open(_iop) \
282 if (rtems_libio_iop_is_open(_iop)) { \
293static inline int rtems_libio_get_iop(
int fd,
rtems_libio_t **iop )
296 if ( (uint32_t) ( fd ) >= rtems_libio_number_iops ) {
299 *iop = rtems_libio_iop( fd );
300 flags = rtems_libio_iop_hold( *iop );
301 if ( rtems_libio_iop_flags_bad_fd( flags ) ) {
302 rtems_libio_iop_drop( *iop );
311#define LIBIO_GET_IOP( _fd, _iop ) \
313 int _error = rtems_libio_get_iop( _fd, &_iop ); \
314 if ( _error != 0 ) { \
315 rtems_set_errno_and_return_minus_one( _error ); \
325static inline int rtems_libio_get_iop_with_access(
326 int fd,
rtems_libio_t **iop,
unsigned int access_flags,
int access_error
329 const unsigned int mandatory = LIBIO_FLAGS_OPEN | access_flags ;
331 if ( (uint32_t) ( fd ) >= rtems_libio_number_iops ) {
334 *iop = rtems_libio_iop( fd );
335 flags = rtems_libio_iop_hold( *iop );
336 if ( ( flags & mandatory ) != mandatory ) {
337 rtems_libio_iop_drop( *iop );
339 if ( ( flags & LIBIO_FLAGS_OPEN ) == 0 ) {
352#define LIBIO_GET_IOP_WITH_ACCESS( _fd, _iop, _access_flags, _access_error ) \
354 int _error = rtems_libio_get_iop_with_access( \
355 _fd, &_iop, _access_flags, _access_error \
357 if ( _error != 0 ) { \
358 rtems_set_errno_and_return_minus_one( _error ); \
368#define rtems_libio_check_buffer(_buffer) \
370 if ((_buffer) == 0) { \
382#define rtems_libio_check_count(_count) \
384 if ((_count) == 0) { \
423void rtems_libio_lock(
void );
425void rtems_libio_unlock(
void );
427static inline void rtems_filesystem_mt_lock(
void )
432static inline void rtems_filesystem_mt_unlock(
void )
434 rtems_libio_unlock();
439#define rtems_filesystem_mt_entry_declare_lock_context( ctx ) \
440 rtems_interrupt_lock_context ctx
442#define rtems_filesystem_mt_entry_lock( ctx ) \
443 rtems_interrupt_lock_acquire( &rtems_filesystem_mt_entry_lock_control, &ctx )
445#define rtems_filesystem_mt_entry_unlock( ctx ) \
446 rtems_interrupt_lock_release( &rtems_filesystem_mt_entry_lock_control, &ctx )
448static inline void rtems_filesystem_instance_lock(
454 (*mt_entry->ops->lock_h)( mt_entry );
457static inline void rtems_filesystem_instance_unlock(
463 (*mt_entry->ops->unlock_h)( mt_entry );
498 const struct timespec
times[2]
521 const struct timespec
times[2],
522 struct timespec new_times[2]
535rtems_filesystem_eval_path_start(
542rtems_filesystem_eval_path_start_with_parent(
547 int parent_eval_flags
551rtems_filesystem_eval_path_start_with_root_and_current(
560void rtems_filesystem_eval_path_continue(
564void rtems_filesystem_eval_path_cleanup(
568void rtems_filesystem_eval_path_recursive(
574void rtems_filesystem_eval_path_cleanup_with_parent(
598 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE,
599 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE,
600 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY
601} rtems_filesystem_eval_path_generic_status;
631typedef rtems_filesystem_eval_path_generic_status
644void rtems_filesystem_eval_path_generic(
671rtems_filesystem_location_initialize_to_null(
682rtems_filesystem_location_transform_to_global(
743void rtems_filesystem_location_detach(
747void rtems_filesystem_location_copy_and_detach(
753rtems_filesystem_global_location_obtain_null(
void)
760static inline bool rtems_filesystem_location_is_null(
764 return loc->handlers == &rtems_filesystem_null_handlers;
767static inline bool rtems_filesystem_global_location_is_null(
771 return rtems_filesystem_location_is_null( &global_loc->location );
774static inline void rtems_filesystem_location_error(
779 if ( !rtems_filesystem_location_is_null( loc ) ) {
784int rtems_filesystem_mknod(
794int rtems_filesystem_chmod(
799int rtems_filesystem_chown(
805static inline bool rtems_filesystem_is_ready_for_unmount(
809 bool ready = !mt_entry->mounted
810 && rtems_chain_has_only_one_node( &mt_entry->location_chain )
811 && mt_entry->mt_fs_root->reference_count == 1;
814 rtems_chain_initialize_empty( &mt_entry->location_chain );
820static inline void rtems_filesystem_location_add_to_mt_entry(
824 rtems_filesystem_mt_entry_declare_lock_context( lock_context );
826 rtems_filesystem_mt_entry_lock( lock_context );
827 rtems_chain_append_unprotected(
828 &loc->mt_entry->location_chain,
831 rtems_filesystem_mt_entry_unlock( lock_context );
834void rtems_filesystem_location_remove_from_mt_entry(
838void rtems_filesystem_do_unmount(
842static inline bool rtems_filesystem_location_is_instance_root(
848 return (*mt_entry->ops->are_nodes_equal_h)(
850 &mt_entry->mt_fs_root->location
854static inline const char *rtems_filesystem_eval_path_get_path(
861static inline size_t rtems_filesystem_eval_path_get_pathlen(
868static inline void rtems_filesystem_eval_path_set_path(
878static inline void rtems_filesystem_eval_path_clear_path(
885static inline const char *rtems_filesystem_eval_path_get_token(
892static inline size_t rtems_filesystem_eval_path_get_tokenlen(
899static inline void rtems_filesystem_eval_path_set_token(
909static inline void rtems_filesystem_eval_path_clear_token(
916static inline void rtems_filesystem_eval_path_put_back_token(
922 ctx->
path -= tokenlen;
927void rtems_filesystem_eval_path_eat_delimiter(
931void rtems_filesystem_eval_path_next_token(
935static inline void rtems_filesystem_eval_path_get_next_token(
941 rtems_filesystem_eval_path_next_token(ctx);
947rtems_filesystem_eval_path_get_currentloc(
954static inline bool rtems_filesystem_eval_path_has_path(
961static inline bool rtems_filesystem_eval_path_has_token(
968static inline int rtems_filesystem_eval_path_get_flags(
975static inline void rtems_filesystem_eval_path_set_flags(
983static inline void rtems_filesystem_eval_path_clear_and_set_flags(
989 int flags = ctx->
flags;
997static inline void rtems_filesystem_eval_path_extract_currentloc(
1002 rtems_filesystem_location_copy_and_detach(
1008void rtems_filesystem_eval_path_error(
1050bool rtems_filesystem_eval_path_check_access(
1058static inline bool rtems_filesystem_is_delimiter(
char c)
1060 return c ==
'/' || c ==
'\\';
1063static inline bool rtems_filesystem_is_current_directory(
1068 return tokenlen == 1 && token [0] ==
'.';
1071static inline bool rtems_filesystem_is_parent_directory(
1076 return tokenlen == 2 && token [0] ==
'.' && token [1] ==
'.';
1079typedef ssize_t ( *rtems_libio_iovec_adapter )(
1081 const struct iovec *iov,
1086static inline ssize_t rtems_libio_iovec_eval(
1088 const struct iovec *iov,
1091 rtems_libio_iovec_adapter adapter
1107 if ( iovcnt > IOV_MAX )
1116 for ( v = 0 ; v < iovcnt ; ++v ) {
1117 size_t len = iov[ v ].iov_len;
1119 if ( len > (
size_t ) ( SSIZE_MAX - total ) ) {
1123 total += ( ssize_t ) len;
1125 if ( iov[ v ].iov_base == NULL && len != 0 ) {
1133 total = ( *adapter )( iop, iov, iovcnt, total );
1136 rtems_libio_iop_drop( iop );
1148static inline mode_t rtems_filesystem_location_type(
1155 (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 wrap the function to allow returning the IOP and using the error set and return macro.
Definition: libio_.h:352
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
void rtems_libio_free_iop(rtems_libio_t *iop)
Definition: libio.c:154
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:614
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_count_open_iops(void)
Definition: libio.c:184
unsigned int rtems_libio_from_fcntl_flags(int fcntl_flags)
Definition: libio.c:80
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
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:632
char rtems_interrupt_lock
This structure represents an ISR lock.
Definition: intr.h:532
#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
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.
File system node operations table.
Definition: libio.h:1023
Definition: deflate.c:114
Path evaluation context.
Definition: libio.h:105
rtems_filesystem_location_info_t currentloc
Definition: libio.h:156
const char * path
Definition: libio.h:109
size_t pathlen
Definition: libio.h:114
size_t tokenlen
Definition: libio.h:126
const char * token
Definition: libio.h:120
int flags
Definition: libio.h:140
Global file system location.
Definition: fs.h:100
File system location.
Definition: fs.h:72
Mount table entry.
Definition: libio.h:1675
An open file data structure.
Definition: libio.h:1340
User Environment Support.