source: rtems/c/src/lib/libc/unmount.c @ 7b0001f7

4.104.114.84.95
Last change on this file since 7b0001f7 was 7b0001f7, checked in by Joel Sherrill <joel.sherrill@…>, on 10/25/00 at 16:56:11

2000-10-24 Joel Sherrill <joel@…>

  • libc/ioman.c: Moved to libfs.
  • libc/Makefile.am: Removed ioman.c as part of moving it to libfs.
  • libc/base_fs.c: Removed include of imfs.h and reworded comment to avoid being IMFS specific.
  • libc/libio.h: Removed prototype of IMFS_ops since it should not be in this file.
  • libc/mount.c: Removed IMFS specific configuration information.
  • libc/unmount.c: Removed include of imfs.h and reworded comment to avoid being IMFS specific.
  • Property mode set to 100644
File size: 5.7 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 "libio_.h"
30
31/*
32 *  Data structures and routines private to mount/unmount pair.
33 */
34
35extern Chain_Control                    rtems_filesystem_mount_table_control;
36extern rtems_filesystem_location_info_t rtems_filesystem_current;
37
38int search_mt_for_mount_point(
39  rtems_filesystem_location_info_t *location_of_mount_point
40);
41
42
43int file_systems_below_this_mountpoint(
44  const char                            *mount_path,
45  rtems_filesystem_location_info_t      *temp_loc,
46  rtems_filesystem_mount_table_entry_t  *temp_mt_entry
47);
48
49/*
50 *  unmount
51 *
52 *  This routine will attempt to unmount the file system that has been
53 *  is mounted a mount_path.  If the operation is successful, 0 will
54 *  be returned to the calling routine.  Otherwise, 1 will be returned.
55 */
56
57int unmount(
58  const char *mount_path
59)
60{
61  int                                   status;
62  rtems_filesystem_location_info_t      temp_loc;
63  rtems_filesystem_mount_table_entry_t  temp_mt_entry;
64
65  /*
66   *  Are there any file systems below the mount_path specified
67   */
68
69  status = file_systems_below_this_mountpoint(
70    mount_path,
71    &temp_loc,
72    &temp_mt_entry
73  );
74
75  if ( status != 0 )
76    return -1;
77
78  /*
79   *  Is the current node reference pointing to a node in the file system
80   *  we are attempting to unmount ?
81   */
82
83  if ( rtems_filesystem_current.mt_entry == temp_loc.mt_entry ) {
84    rtems_filesystem_freenode( &temp_loc );
85    set_errno_and_return_minus_one( EBUSY );
86  }
87
88  /*
89   *  Run the file descriptor table to determine if there are any file
90   *  descriptors that are currently active and reference nodes in the
91   *  file system that we are trying to unmount
92   */
93
94  if ( rtems_libio_is_open_files_in_fs( temp_loc.mt_entry ) == 1 ) {
95    rtems_filesystem_freenode( &temp_loc );
96    set_errno_and_return_minus_one( EBUSY );
97  }
98 
99  /*
100   * Allow the file system being mounted on to do its cleanup.
101   */
102
103  if ((temp_mt_entry.mt_point_node.ops->unmount_h )( temp_loc.mt_entry ) != 0 ) {
104    rtems_filesystem_freenode( &temp_loc );
105    return -1;
106  }
107
108  /*
109   * Run the unmount function for the subordinate file system.
110   */
111
112  if ((temp_mt_entry.mt_fs_root.ops->fsunmount_me_h )( temp_loc.mt_entry ) != 0){
113    rtems_filesystem_freenode( &temp_loc );
114    return -1;
115  }
116
117  /*
118   *  Extract the mount table entry from the chain
119   */
120
121  Chain_Extract( ( Chain_Node * ) temp_loc.mt_entry );
122
123  /*
124   *  Free the memory associated with the extracted mount table entry.
125   */
126
127  rtems_filesystem_freenode( &temp_loc.mt_entry->mt_point_node );
128  free( temp_loc.mt_entry );
129  rtems_filesystem_freenode( &temp_loc );
130
131  return 0;
132}
133
134
135/*
136 *  file_systems_below_this_mountpoint
137 *
138 *  This routine will run through the entries that currently exist in the
139 *  mount table chain. For each entry in the mount table chain it will
140 *  compare the mount tables mt_fs_root to the new_fs_root_node. If any of the
141 *  mount table file system root nodes matches the new file system root node
142 *  this indicates that we are trying to mount a file system that has already
143 *  been mounted. This is not a permitted operation. temp_loc is set to
144 *  the root node of the file system being unmounted.
145 */
146
147int file_systems_below_this_mountpoint(
148  const char                            *mount_path,
149  rtems_filesystem_location_info_t      *temp_loc,
150  rtems_filesystem_mount_table_entry_t  *temp_mt_entry
151)
152{
153  Chain_Node                           *the_node;
154  rtems_filesystem_mount_table_entry_t *the_mount_entry;
155  rtems_filesystem_mount_table_entry_t *current_fs_mt_entry;
156
157  /*
158   *  Is the mount_path even a valid node name in the existing tree?
159   */
160
161  if ( rtems_filesystem_evaluate_path( mount_path, 0x0, temp_loc, TRUE ) )
162    return -1;
163 
164  /*
165   *  Look for the node defined in temp_loc as a mount point in the
166   *  mount table chain.
167   */
168
169  for ( the_node = rtems_filesystem_mount_table_control.first;
170        !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node );
171        the_node = the_node->next ) {
172
173     the_mount_entry = ( rtems_filesystem_mount_table_entry_t * )the_node;
174     if  (the_mount_entry->mt_point_node.node_access  ==
175          temp_loc->node_access ) {
176        current_fs_mt_entry = the_mount_entry;
177        *temp_loc = current_fs_mt_entry->mt_fs_root;
178        goto after_real_mount_point_found;
179     }
180  }
181  set_errno_and_return_minus_one( EACCES );
182
183
184after_real_mount_point_found:
185
186  for ( the_node = rtems_filesystem_mount_table_control.first;
187        !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node );
188        the_node = the_node->next ) {
189
190     the_mount_entry = (  rtems_filesystem_mount_table_entry_t * )the_node;
191
192     /*
193      *  Exclude the current file systems mount table entry from the test
194      */
195
196     if ( current_fs_mt_entry != the_mount_entry ) {
197       if ( the_mount_entry->mt_point_node.mt_entry  == current_fs_mt_entry ) {
198
199          /*
200           *  There is at least one fs below the fs on the mount_path.
201           */
202          set_errno_and_return_minus_one( EBUSY );
203       }
204     }
205  }
206
207  *temp_mt_entry = *current_fs_mt_entry;
208
209  return 0;
210}
Note: See TracBrowser for help on using the repository browser.