File indexing completed on 2025-05-11 08:24:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039
0040 #include <errno.h>
0041
0042 #include <rtems/libio_.h>
0043
0044 static bool contains_root_or_current_directory(
0045 const rtems_filesystem_mount_table_entry_t *mt_entry
0046 )
0047 {
0048 const rtems_filesystem_location_info_t *root =
0049 &rtems_filesystem_root->location;
0050 const rtems_filesystem_location_info_t *current =
0051 &rtems_filesystem_current->location;
0052
0053 return mt_entry == root->mt_entry || mt_entry == current->mt_entry;
0054 }
0055
0056
0057
0058
0059
0060
0061
0062 int unmount( const char *path )
0063 {
0064 int rv = 0;
0065 rtems_filesystem_eval_path_context_t ctx;
0066 int eval_flags = RTEMS_FS_FOLLOW_LINK;
0067 const rtems_filesystem_location_info_t *currentloc =
0068 rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
0069 rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry;
0070
0071 if ( rtems_filesystem_location_is_instance_root( currentloc ) ) {
0072 if ( !contains_root_or_current_directory( mt_entry ) ) {
0073 const rtems_filesystem_operations_table *mt_point_ops =
0074 mt_entry->mt_point_node->location.mt_entry->ops;
0075
0076 rv = (*mt_point_ops->unmount_h)( mt_entry );
0077 if ( rv == 0 ) {
0078 rtems_id self_task_id = rtems_task_self();
0079 rtems_filesystem_mt_entry_declare_lock_context( lock_context );
0080
0081 rtems_filesystem_mt_entry_lock( lock_context );
0082 mt_entry->unmount_task = self_task_id;
0083 mt_entry->mounted = false;
0084 rtems_filesystem_mt_entry_unlock( lock_context );
0085 }
0086 } else {
0087 errno = EBUSY;
0088 rv = -1;
0089 }
0090 } else {
0091 errno = EACCES;
0092 rv = -1;
0093 }
0094
0095 rtems_filesystem_eval_path_cleanup( &ctx );
0096
0097 if ( rv == 0 ) {
0098 rtems_status_code sc = rtems_event_transient_receive(
0099 RTEMS_WAIT,
0100 RTEMS_NO_TIMEOUT
0101 );
0102
0103 if ( sc != RTEMS_SUCCESSFUL ) {
0104 rtems_fatal_error_occurred( 0xdeadbeef );
0105 }
0106 }
0107
0108 return rv;
0109 }