[07a3253d] | 1 | /* |
---|
| 2 | * unmount() - Unmount a File System |
---|
| 3 | * |
---|
| 4 | * This routine is not defined in the POSIX 1003.1b standard but |
---|
| 5 | * in some form is supported on most UNIX and POSIX systems. This |
---|
| 6 | * routine is necessary to mount instantiations of a file system |
---|
| 7 | * into the file system name space. |
---|
| 8 | * |
---|
| 9 | * COPYRIGHT (c) 1989-1998. |
---|
| 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * Copyright assigned to U.S. Government, 1994. |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
| 15 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include <sys/types.h> |
---|
| 21 | #include <sys/stat.h> |
---|
| 22 | #include <chain.h> |
---|
| 23 | #include <fcntl.h> |
---|
| 24 | #include <unistd.h> |
---|
| 25 | #include <errno.h> |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include <assert.h> |
---|
| 29 | |
---|
| 30 | #include "imfs.h" |
---|
| 31 | #include "libio_.h" |
---|
| 32 | |
---|
| 33 | /* |
---|
| 34 | * Data structures and routines private to mount/unmount pair. |
---|
| 35 | */ |
---|
| 36 | |
---|
| 37 | extern Chain_Control rtems_filesystem_mount_table_control; |
---|
| 38 | extern rtems_filesystem_location_info_t rtems_filesystem_current; |
---|
| 39 | |
---|
| 40 | int search_mt_for_mount_point( |
---|
| 41 | rtems_filesystem_location_info_t *location_of_mount_point |
---|
| 42 | ); |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | int file_systems_below_this_mountpoint( |
---|
| 46 | const char *mount_path, |
---|
| 47 | rtems_filesystem_location_info_t *temp_loc, |
---|
| 48 | rtems_filesystem_mount_table_entry_t *temp_mt_entry |
---|
| 49 | ); |
---|
| 50 | |
---|
| 51 | /* |
---|
| 52 | * unmount |
---|
| 53 | * |
---|
| 54 | * This routine will attempt to unmount the file system that has been |
---|
| 55 | * is mounted a mount_path. If the operation is successful, 0 will |
---|
| 56 | * be returned to the calling routine. Otherwise, 1 will be returned. |
---|
| 57 | */ |
---|
| 58 | |
---|
| 59 | int unmount( |
---|
| 60 | const char *mount_path |
---|
| 61 | ) |
---|
| 62 | { |
---|
| 63 | int status; |
---|
| 64 | rtems_filesystem_location_info_t temp_loc; |
---|
| 65 | rtems_filesystem_mount_table_entry_t temp_mt_entry; |
---|
| 66 | int result; |
---|
| 67 | |
---|
| 68 | /* |
---|
| 69 | * Are there any file systems below the mount_path specified |
---|
| 70 | */ |
---|
| 71 | |
---|
| 72 | status = file_systems_below_this_mountpoint( |
---|
| 73 | mount_path, |
---|
| 74 | &temp_loc, |
---|
| 75 | &temp_mt_entry |
---|
| 76 | ); |
---|
| 77 | |
---|
| 78 | if ( status != 0 ) |
---|
| 79 | return -1; |
---|
| 80 | |
---|
| 81 | /* |
---|
| 82 | * Is the current node reference pointing to a node in the file system |
---|
| 83 | * we are attempting to unmount ? |
---|
| 84 | */ |
---|
| 85 | |
---|
| 86 | if ( rtems_filesystem_current.mt_entry == temp_loc.mt_entry ) |
---|
| 87 | set_errno_and_return_minus_one( EBUSY ); |
---|
| 88 | |
---|
| 89 | /* |
---|
| 90 | * Run the file descriptor table to determine if there are any file |
---|
| 91 | * descriptors that are currently active and reference nodes in the |
---|
| 92 | * file system that we are trying to unmount |
---|
| 93 | */ |
---|
| 94 | |
---|
| 95 | if ( rtems_libio_is_open_files_in_fs( temp_loc.mt_entry ) == 1 ) |
---|
| 96 | set_errno_and_return_minus_one( EBUSY ); |
---|
| 97 | |
---|
| 98 | /* |
---|
| 99 | * Allow the file system being mounted on to do its cleanup. |
---|
| 100 | * XXX - Did I change these correctly ??? It looks like either I did |
---|
| 101 | * XXX this backwards or the IMFS_unmount and IMFS_fsumount are swaped. |
---|
| 102 | * XXX Add to the mt_point_node unmount to set the mt_entry back to null |
---|
| 103 | * XXX I will step off in space when evaluating past the end of the node. |
---|
| 104 | */ |
---|
| 105 | |
---|
| 106 | if ( ( temp_mt_entry.mt_point_node.ops->unmount )( temp_loc.mt_entry ) != 0 ) |
---|
| 107 | return -1; |
---|
| 108 | |
---|
| 109 | /* |
---|
| 110 | * Run the unmount function for the subordinate file system. |
---|
| 111 | */ |
---|
| 112 | |
---|
| 113 | if ( ( temp_mt_entry.mt_fs_root.ops->fsunmount_me )( temp_loc.mt_entry ) != 0 ) |
---|
| 114 | return -1; |
---|
| 115 | |
---|
| 116 | /* |
---|
| 117 | * Allow the file system to clean up. |
---|
| 118 | */ |
---|
| 119 | |
---|
| 120 | result = (*temp_loc.ops->fsunmount_me)( temp_loc.mt_entry ); |
---|
| 121 | |
---|
| 122 | /* |
---|
| 123 | * Extract the mount table entry from the chain |
---|
| 124 | */ |
---|
| 125 | |
---|
| 126 | Chain_Extract( ( Chain_Node * ) temp_loc.mt_entry ); |
---|
| 127 | |
---|
| 128 | /* |
---|
| 129 | * Free the memory associated with the extracted mount table entry. |
---|
| 130 | */ |
---|
| 131 | |
---|
| 132 | free( temp_loc.mt_entry ); |
---|
| 133 | |
---|
| 134 | return result; |
---|
| 135 | |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | /* |
---|
| 140 | * file_systems_below_this_mountpoint |
---|
| 141 | * |
---|
| 142 | * This routine will run through the entries that currently exist in the |
---|
| 143 | * mount table chain. For each entry in the mount table chain it will |
---|
| 144 | * compare the mount tables mt_fs_root to the new_fs_root_node. If any of the |
---|
| 145 | * mount table file system root nodes matches the new file system root node |
---|
| 146 | * this indicates that we are trying to mount a file system that has already |
---|
| 147 | * been mounted. This is not a permitted operation. temp_loc is set to |
---|
| 148 | * the root node of the file system being unmounted. |
---|
| 149 | */ |
---|
| 150 | |
---|
| 151 | int file_systems_below_this_mountpoint( |
---|
| 152 | const char *mount_path, |
---|
| 153 | rtems_filesystem_location_info_t *temp_loc, |
---|
| 154 | rtems_filesystem_mount_table_entry_t *temp_mt_entry |
---|
| 155 | ) |
---|
| 156 | { |
---|
| 157 | Chain_Node *the_node; |
---|
| 158 | rtems_filesystem_mount_table_entry_t *the_mount_entry; |
---|
| 159 | rtems_filesystem_mount_table_entry_t *current_fs_mt_entry; |
---|
| 160 | |
---|
| 161 | /* |
---|
| 162 | * Is the mount_path even a valid node name in the existing tree? |
---|
| 163 | */ |
---|
| 164 | |
---|
| 165 | if ( rtems_filesystem_evaluate_path( mount_path, 0x0, temp_loc, TRUE ) ) |
---|
| 166 | return -1; |
---|
| 167 | |
---|
| 168 | /* |
---|
| 169 | * Look for the node defined in temp_loc as a mount point in the |
---|
| 170 | * mount table chain. |
---|
| 171 | */ |
---|
| 172 | |
---|
| 173 | for ( the_node = rtems_filesystem_mount_table_control.first; |
---|
| 174 | !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node ); |
---|
| 175 | the_node = the_node->next ) { |
---|
| 176 | |
---|
| 177 | the_mount_entry = ( rtems_filesystem_mount_table_entry_t * )the_node; |
---|
| 178 | if (the_mount_entry->mt_point_node.node_access == |
---|
| 179 | temp_loc->node_access ) { |
---|
| 180 | current_fs_mt_entry = the_mount_entry; |
---|
| 181 | *temp_loc = current_fs_mt_entry->mt_fs_root; |
---|
| 182 | goto after_real_mount_point_found; |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | set_errno_and_return_minus_one( EACCES ); |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | after_real_mount_point_found: |
---|
| 189 | |
---|
| 190 | for ( the_node = rtems_filesystem_mount_table_control.first; |
---|
| 191 | !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node ); |
---|
| 192 | the_node = the_node->next ) { |
---|
| 193 | |
---|
| 194 | the_mount_entry = ( rtems_filesystem_mount_table_entry_t * )the_node; |
---|
| 195 | |
---|
| 196 | /* |
---|
| 197 | * Exclude the current file systems mount table entry from the test |
---|
| 198 | */ |
---|
| 199 | |
---|
| 200 | if ( current_fs_mt_entry != the_mount_entry ) { |
---|
| 201 | if ( the_mount_entry->mt_point_node.mt_entry == current_fs_mt_entry ) { |
---|
| 202 | |
---|
| 203 | /* |
---|
| 204 | * There is at least one fs below the fs on the mount_path. |
---|
| 205 | */ |
---|
| 206 | set_errno_and_return_minus_one( EBUSY ); |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | *temp_mt_entry = *current_fs_mt_entry; |
---|
| 212 | |
---|
| 213 | return 0; |
---|
| 214 | } |
---|