source: rtems/c/src/lib/libc/unmount.c @ 94a86c40

4.104.114.84.95
Last change on this file since 94a86c40 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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