int msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc, const rtems_filesystem_location_info_t *pathloc) { int rc = RC_OK; fat_file_fd_t *fat_fd = pathloc->node_access; if (fat_fd->fat_file_type == MSDOS_DIRECTORY) { bool is_empty = false; /* * You cannot remove a node that still has children */ rc = msdos_dir_is_empty(pathloc->mt_entry, fat_fd, &is_empty); if (rc != RC_OK) { return rc; } if (!is_empty) { rtems_set_errno_and_return_minus_one(ENOTEMPTY); } /* * We deny attempts to delete open directory (if directory is current * directory we assume it is open one) */ if (fat_fd->links_num > 1) { rtems_set_errno_and_return_minus_one(EBUSY); } /* * You cannot remove the file system root node. */ if (rtems_filesystem_location_is_root(pathloc)) { rtems_set_errno_and_return_minus_one(EBUSY); } /* * You cannot remove a mountpoint. * not used - mount() not implemenetd yet. */ } /* mark file removed */ rc = msdos_set_first_char4file_name(pathloc->mt_entry, &fat_fd->dir_pos, MSDOS_THIS_DIR_ENTRY_EMPTY); if (rc != RC_OK) { return rc; } fat_file_mark_removed(pathloc->mt_entry, fat_fd); return rc; }
int unmount( const char *path ) { int rv = 0; rtems_filesystem_eval_path_context_t ctx; int eval_flags = RTEMS_FS_FOLLOW_LINK; const rtems_filesystem_location_info_t *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry; if ( rtems_filesystem_location_is_root( currentloc ) ) { if ( !contains_root_or_current_directory( mt_entry ) ) { const rtems_filesystem_operations_table *mt_point_ops = mt_entry->mt_point_node->location.mt_entry->ops; rv = (*mt_point_ops->unmount_h)( mt_entry ); if ( rv == 0 ) { rtems_id self_task_id = rtems_task_self(); rtems_filesystem_mt_entry_declare_lock_context( lock_context ); rtems_filesystem_mt_entry_lock( lock_context ); mt_entry->unmount_task = self_task_id; mt_entry->mounted = false; rtems_filesystem_mt_entry_unlock( lock_context ); } } else { errno = EBUSY; rv = -1; } } else { errno = EACCES; rv = -1; } rtems_filesystem_eval_path_cleanup( &ctx ); if ( rv == 0 ) { rtems_event_set out; rtems_status_code sc = rtems_event_receive( RTEMS_FILESYSTEM_UNMOUNT_EVENT, RTEMS_EVENT_ALL | RTEMS_WAIT, RTEMS_NO_TIMEOUT, &out ); if ( sc != RTEMS_SUCCESSFUL ) { rtems_fatal_error_occurred( 0xdeadbeef ); } } return rv; }