21 #ifndef _RTEMS_RTEMS_LIBIO__H 22 #define _RTEMS_RTEMS_LIBIO__H 45 #define RTEMS_FILESYSTEM_SYMLOOP_MAX 32 58 #define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O') 59 #define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n) 61 extern rtems_id rtems_libio_semaphore;
67 extern const uint32_t rtems_libio_number_iops;
98 #define rtems_libio_iop(_fd) \ 99 ((((uint32_t)(_fd)) < rtems_libio_number_iops) ? \ 100 &rtems_libio_iops[_fd] : 0) 109 #define rtems_libio_iop_to_descriptor(_iop) \ 110 ((_iop) - &rtems_libio_iops[0]) 118 #define rtems_libio_check_is_open(_iop) \ 120 if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \ 132 #define rtems_libio_check_fd(_fd) \ 134 if ((uint32_t) (_fd) >= rtems_libio_number_iops) { \ 146 #define rtems_libio_check_buffer(_buffer) \ 148 if ((_buffer) == 0) { \ 160 #define rtems_libio_check_count(_count) \ 162 if ((_count) == 0) { \ 174 #define rtems_libio_check_permissions_with_error(_iop, _flag, _errno) \ 176 if (((_iop)->flags & (_flag)) == 0) { \ 177 rtems_set_errno_and_return_minus_one( _errno ); \ 189 #define rtems_libio_check_permissions(_iop, _flag) \ 190 rtems_libio_check_permissions_with_error(_iop, _flag, EINVAL ) 226 void rtems_libio_free_user_env(
void *
env );
228 extern pthread_key_t rtems_current_user_env_key;
230 static inline void rtems_libio_lock(
void )
235 static inline void rtems_libio_unlock(
void )
240 static inline void rtems_filesystem_mt_lock(
void )
245 static inline void rtems_filesystem_mt_unlock(
void )
247 rtems_libio_unlock();
252 #define rtems_filesystem_mt_entry_declare_lock_context( ctx ) \ 253 rtems_interrupt_lock_context ctx 255 #define rtems_filesystem_mt_entry_lock( ctx ) \ 256 rtems_interrupt_lock_acquire( &rtems_filesystem_mt_entry_lock_control, &ctx ) 258 #define rtems_filesystem_mt_entry_unlock( ctx ) \ 259 rtems_interrupt_lock_release( &rtems_filesystem_mt_entry_lock_control, &ctx ) 261 static inline void rtems_filesystem_instance_lock(
267 (*mt_entry->ops->lock_h)( mt_entry );
270 static inline void rtems_filesystem_instance_unlock(
276 (*mt_entry->ops->unlock_h)( mt_entry );
312 rtems_filesystem_eval_path_start(
319 rtems_filesystem_eval_path_start_with_parent(
324 int parent_eval_flags
328 rtems_filesystem_eval_path_start_with_root_and_current(
337 void rtems_filesystem_eval_path_continue(
341 void rtems_filesystem_eval_path_cleanup(
345 void rtems_filesystem_eval_path_recursive(
351 void rtems_filesystem_eval_path_cleanup_with_parent(
375 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE,
376 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE,
377 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY
378 } rtems_filesystem_eval_path_generic_status;
408 typedef rtems_filesystem_eval_path_generic_status
421 void rtems_filesystem_eval_path_generic(
448 rtems_filesystem_location_initialize_to_null(
454 &rtems_filesystem_global_location_null.location
459 rtems_filesystem_location_transform_to_global(
520 void rtems_filesystem_location_detach(
524 void rtems_filesystem_location_copy_and_detach(
530 rtems_filesystem_global_location_obtain_null(
void)
537 static inline bool rtems_filesystem_location_is_null(
541 return loc->handlers == &rtems_filesystem_null_handlers;
544 static inline bool rtems_filesystem_global_location_is_null(
548 return rtems_filesystem_location_is_null( &global_loc->location );
551 static inline void rtems_filesystem_location_error(
556 if ( !rtems_filesystem_location_is_null( loc ) ) {
561 int rtems_filesystem_mknod(
571 int rtems_filesystem_chmod(
576 int rtems_filesystem_chown(
582 static inline bool rtems_filesystem_is_ready_for_unmount(
586 bool ready = !mt_entry->mounted
588 && mt_entry->mt_fs_root->reference_count == 1;
597 static inline void rtems_filesystem_location_add_to_mt_entry(
601 rtems_filesystem_mt_entry_declare_lock_context( lock_context );
603 rtems_filesystem_mt_entry_lock( lock_context );
605 &loc->mt_entry->location_chain,
608 rtems_filesystem_mt_entry_unlock( lock_context );
611 void rtems_filesystem_location_remove_from_mt_entry(
615 void rtems_filesystem_do_unmount(
619 static inline bool rtems_filesystem_location_is_instance_root(
625 return (*mt_entry->ops->are_nodes_equal_h)(
627 &mt_entry->mt_fs_root->location
631 static inline const char *rtems_filesystem_eval_path_get_path(
638 static inline size_t rtems_filesystem_eval_path_get_pathlen(
645 static inline void rtems_filesystem_eval_path_set_path(
655 static inline void rtems_filesystem_eval_path_clear_path(
662 static inline const char *rtems_filesystem_eval_path_get_token(
669 static inline size_t rtems_filesystem_eval_path_get_tokenlen(
676 static inline void rtems_filesystem_eval_path_set_token(
686 static inline void rtems_filesystem_eval_path_clear_token(
693 static inline void rtems_filesystem_eval_path_put_back_token(
699 ctx->
path -= tokenlen;
704 void rtems_filesystem_eval_path_eat_delimiter(
708 void rtems_filesystem_eval_path_next_token(
712 static inline void rtems_filesystem_eval_path_get_next_token(
718 rtems_filesystem_eval_path_next_token(ctx);
724 rtems_filesystem_eval_path_get_currentloc(
731 static inline bool rtems_filesystem_eval_path_has_path(
738 static inline bool rtems_filesystem_eval_path_has_token(
745 static inline int rtems_filesystem_eval_path_get_flags(
752 static inline void rtems_filesystem_eval_path_set_flags(
760 static inline void rtems_filesystem_eval_path_clear_and_set_flags(
766 int flags = ctx->
flags;
774 static inline void rtems_filesystem_eval_path_extract_currentloc(
779 rtems_filesystem_location_copy_and_detach(
785 void rtems_filesystem_eval_path_error(
827 bool rtems_filesystem_eval_path_check_access(
835 static inline bool rtems_filesystem_is_delimiter(
char c)
837 return c ==
'/' || c ==
'\\';
840 static inline bool rtems_filesystem_is_current_directory(
845 return tokenlen == 1 && token [0] ==
'.';
848 static inline bool rtems_filesystem_is_parent_directory(
853 return tokenlen == 2 && token [0] ==
'.' && token [1] ==
'.';
856 static inline ssize_t rtems_libio_iovec_eval(
858 const struct iovec *iov,
868 rtems_libio_check_fd( fd );
869 iop = rtems_libio_iop( fd );
870 rtems_libio_check_is_open( iop );
871 rtems_libio_check_permissions_with_error( iop, flags, EBADF );
884 if ( iovcnt > IOV_MAX )
893 for ( v = 0 ; v < iovcnt ; ++v ) {
894 size_t len = iov[ v ].iov_len;
896 if ( len > (
size_t ) ( SSIZE_MAX - total ) ) {
900 total += ( ssize_t ) len;
902 if ( iov[ v ].iov_base == NULL && len != 0 ) {
918 static inline mode_t rtems_filesystem_location_type(
925 (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:507
const char * token
The contents of the token to be evaluated with respect to the current location.
Definition: libio.h:98
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:116
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:185
Data which Ease the Burden of Consistently Setting Errno.
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:80
User Environment Support.
int flags
The path evaluation is controlled by the following flags.
Definition: libio.h:118
POSIX Threads Private Support.
rtems_filesystem_global_location_t rtems_filesystem_global_location_null
The global null location.
Definition: __usrenv.c:226
void rtems_libio_free(rtems_libio_t *iop)
This routine frees the resources associated with an IOP (file descriptor) and clears the slot in the ...
Definition: libio.c:132
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:95
size_t tokenlen
The length of the token to be evaluated with respect to the current location.
Definition: libio.h:104
ISR lock control.
Definition: isrlock.h:56
File system node operations table.
Definition: libio.h:982
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:692
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:391
#define rtems_set_errno_and_return_minus_one(_error)
This is a helper macro which will set the variable errno and return -1 to the caller.
Definition: seterr.h:48
rtems_status_code rtems_semaphore_release(rtems_id id)
RTEMS Semaphore Release.
Definition: semrelease.c:56
rtems_filesystem_location_info_t currentloc
This is the current file system location of the evaluation process.
Definition: libio.h:134
rtems_status_code rtems_semaphore_obtain(rtems_id id, rtems_option option_set, rtems_interval timeout)
RTEMS Obtain Semaphore.
Definition: semobtain.c:34
void rtems_filesystem_location_free(rtems_filesystem_location_info_t *loc)
Releases all resources of a location.
Definition: freenode.c:25
uint32_t rtems_libio_fcntl_flags(int fcntl_flags)
Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand.
Definition: libio.c:62
#define RTEMS_NO_TIMEOUT
Constant for indefinite wait.
Definition: rtems.h:170
#define RTEMS_WAIT
This option constants indicates that the task is to wait on resource.
Definition: options.h:56
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:409
Mount table entry.
Definition: libio.h:1542
Path evaluation context.
Definition: libio.h:83
int rtems_libio_to_fcntl_flags(uint32_t flags)
Convert RTEMS internal flags to UNIX fnctl(2) flags.
Definition: libio.c:87
An open file data structure.
Definition: libio.h:1281
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
The contents of the remaining path to be evaluated.
Definition: libio.h:87
rtems_libio_t * rtems_libio_allocate(void)
This routine searches the IOP Table for an unused entry.
Definition: libio.c:114
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:162
size_t pathlen
The length of the remaining path to be evaluated.
Definition: libio.h:92
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:208
Global file system location.
Definition: fs.h:81
void rtems_filesystem_initialize(void)
Base File System Initialization.
Definition: base_fs.c:32
File system location.
Definition: fs.h:53