source: rtems/cpukit/libcsupport/src/unmount.c @ 922a723

4.104.114.84.95
Last change on this file since 922a723 was 922a723, checked in by Joel Sherrill <joel.sherrill@…>, on 12/06/00 at 15:45:37

2000-12-06 Joel Sherrill <joel@…>

  • libc/mallocfreespace.c: Name of routine is rtems_region_get_information() NOT region_get_information().
  • libc/unmount.c: Removed unused variable.
  • Property mode set to 100644
File size: 5.1 KB
RevLine 
[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 *
[08311cc3]9 *  COPYRIGHT (c) 1989-1999.
[07a3253d]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
[3ba74c73]29#include <rtems/libio_.h>
[07a3253d]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(
[4b0d1ab]44  const char                            *path,
[07a3253d]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
[4b0d1ab]53 *  is mounted a path.  If the operation is successful, 0 will
[07a3253d]54 *  be returned to the calling routine.  Otherwise, 1 will be returned.
55 */
56
57int unmount(
[4b0d1ab]58  const char *path
[07a3253d]59)
60{
61  int                                   status;
[4b0d1ab]62  rtems_filesystem_location_info_t      fs_root_loc;
[07a3253d]63  rtems_filesystem_mount_table_entry_t  temp_mt_entry;
64
65  /*
[4b0d1ab]66   *  Are there any file systems below the path specified
[07a3253d]67   */
68
69  status = file_systems_below_this_mountpoint(
[4b0d1ab]70    path,
71    &fs_root_loc,
[07a3253d]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
[4b0d1ab]83  if ( rtems_filesystem_current.mt_entry == fs_root_loc.mt_entry ) {
84    rtems_filesystem_freenode( &fs_root_loc );
[07a3253d]85    set_errno_and_return_minus_one( EBUSY );
[d71fcab]86  }
[07a3253d]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
[4b0d1ab]94  if ( rtems_libio_is_open_files_in_fs( fs_root_loc.mt_entry ) == 1 ) {
95    rtems_filesystem_freenode( &fs_root_loc );
[07a3253d]96    set_errno_and_return_minus_one( EBUSY );
[d71fcab]97  }
[07a3253d]98 
99  /*
[4b0d1ab]100   * Allow the file system being unmounted on to do its cleanup.
[07a3253d]101   */
102
[4b0d1ab]103  if ((temp_mt_entry.mt_point_node.ops->unmount_h )( fs_root_loc.mt_entry ) != 0 ) {
104    rtems_filesystem_freenode( &fs_root_loc );
[d71fcab]105    return -1;
106  }
[07a3253d]107
108  /*
109   * Run the unmount function for the subordinate file system.
110   */
111
[4b0d1ab]112  if ((temp_mt_entry.mt_fs_root.ops->fsunmount_me_h )( fs_root_loc.mt_entry ) != 0){
113    rtems_filesystem_freenode( &fs_root_loc );
[dd0f326]114    return -1;
[d71fcab]115  }
[07a3253d]116
117  /*
118   *  Extract the mount table entry from the chain
119   */
120
[4b0d1ab]121  Chain_Extract( ( Chain_Node * ) fs_root_loc.mt_entry );
[07a3253d]122
123  /*
124   *  Free the memory associated with the extracted mount table entry.
125   */
126
[4b0d1ab]127  rtems_filesystem_freenode( &fs_root_loc.mt_entry->mt_point_node );
128  free( fs_root_loc.mt_entry );
129  rtems_filesystem_freenode( &fs_root_loc );
[07a3253d]130
[df49c60]131  return 0;
[07a3253d]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(
[4b0d1ab]148  const char                            *path,
149  rtems_filesystem_location_info_t      *fs_root_loc,
150  rtems_filesystem_mount_table_entry_t  *fs_to_unmount
[07a3253d]151)
152{
153  Chain_Node                           *the_node;
154  rtems_filesystem_mount_table_entry_t *the_mount_entry;
155
156  /*
[4b0d1ab]157   *  Is the path even a valid node name in the existing tree?
[07a3253d]158   */
159
[4b0d1ab]160  if ( rtems_filesystem_evaluate_path( path, 0x0, fs_root_loc, TRUE ) )
[07a3253d]161    return -1;
162 
163  /*
[4b0d1ab]164   * Verify this is the root node for the file system to be unmounted.
[07a3253d]165   */
166
[4b0d1ab]167  *fs_to_unmount = *fs_root_loc->mt_entry;
168  if ( fs_to_unmount->mt_fs_root.node_access != fs_root_loc->node_access )
169    set_errno_and_return_minus_one( EACCES );
[07a3253d]170
[4b0d1ab]171  /*
172   * Search the mount table for any mount entries referencing this
173   * mount entry.
174   */
[07a3253d]175
176  for ( the_node = rtems_filesystem_mount_table_control.first;
177        !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node );
178        the_node = the_node->next ) {
[4b0d1ab]179     the_mount_entry = ( rtems_filesystem_mount_table_entry_t * )the_node;
180     if (the_mount_entry->mt_point_node.mt_entry  == fs_root_loc->mt_entry ) {
[07a3253d]181          set_errno_and_return_minus_one( EBUSY );
182     }
183  }
184
185  return 0;
186}
Note: See TracBrowser for help on using the repository browser.