source: rtems/c/src/lib/libc/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 Dec 6, 2000 at 3:45:37 PM

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
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 <rtems/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                            *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 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 *path
59)
60{
61  int                                   status;
62  rtems_filesystem_location_info_t      fs_root_loc;
63  rtems_filesystem_mount_table_entry_t  temp_mt_entry;
64
65  /*
66   *  Are there any file systems below the path specified
67   */
68
69  status = file_systems_below_this_mountpoint( 
70    path, 
71    &fs_root_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 == fs_root_loc.mt_entry ) {
84    rtems_filesystem_freenode( &fs_root_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( fs_root_loc.mt_entry ) == 1 ) {
95    rtems_filesystem_freenode( &fs_root_loc );
96    set_errno_and_return_minus_one( EBUSY );
97  }
98 
99  /*
100   * Allow the file system being unmounted on to do its cleanup.
101   */
102
103  if ((temp_mt_entry.mt_point_node.ops->unmount_h )( fs_root_loc.mt_entry ) != 0 ) {
104    rtems_filesystem_freenode( &fs_root_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 )( fs_root_loc.mt_entry ) != 0){
113    rtems_filesystem_freenode( &fs_root_loc );
114    return -1;
115  }
116
117  /*
118   *  Extract the mount table entry from the chain
119   */
120
121  Chain_Extract( ( Chain_Node * ) fs_root_loc.mt_entry );
122
123  /*
124   *  Free the memory associated with the extracted mount table entry.
125   */
126
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 );
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                            *path,
149  rtems_filesystem_location_info_t      *fs_root_loc,
150  rtems_filesystem_mount_table_entry_t  *fs_to_unmount
151)
152{
153  Chain_Node                           *the_node;
154  rtems_filesystem_mount_table_entry_t *the_mount_entry;
155
156  /*
157   *  Is the path even a valid node name in the existing tree?
158   */
159
160  if ( rtems_filesystem_evaluate_path( path, 0x0, fs_root_loc, TRUE ) )
161    return -1;
162 
163  /*
164   * Verify this is the root node for the file system to be unmounted.
165   */
166
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 );
170
171  /*
172   * Search the mount table for any mount entries referencing this
173   * mount entry.
174   */
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 ) {
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 ) {
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.