source: rtems/cpukit/libcsupport/src/unmount.c @ 955a34b5

4.10
Last change on this file since 955a34b5 was 955a34b5, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 1, 2010 at 3:18:06 PM

2010-07-01 Sebastian Huber <sebastian.huber@…>

  • libcsupport/include/rtems/libio_.h: Removed rtems_filesystem_mount_table_control.
  • libcsupport/include/rtems/libio.h, libcsupport/src/mount-mgr.c, libcsupport/src/mount.c libcsupport/src/statvfs.c, libcsupport/src/unmount.c, libmisc/shell/main_mount.c: Documentation. Removed rtems_filesystem_mounts_first() and rtems_filesystem_mounts_next(). Added rtems_filesystem_mount_iterate(). Changed return type of rtems_filesystem_iterate(). Removed rtems_filesystem_nodes_equal().

2010-07-01 Sebastian Huber <sebastian.huber@…>

  • libfs/src/nfsclient/src/nfs.c, libfs/src/nfsclient/src/nfs.c, libfs/src/nfsclient/src/librtemsNfs.h: Renamed rtems_nfsfs_initialize() in rtems_nfs_initialize().
  • sapi/include/confdefs.h: Reflect changes above. Renamed *_miniIMFS in *_MINIIMFS. Renamed *_NFSFS in *_NFS.
  • Property mode set to 100644
File size: 4.6 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.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <unistd.h>
27#include <errno.h>
28#include <stdlib.h>
29#include <string.h>
30#include <assert.h>
31
32#include <rtems/libio_.h>
33#include <rtems/seterr.h>
34#include <rtems/chain.h>
35
36static bool is_fs_below_mount_point(
37  const rtems_filesystem_mount_table_entry_t *mt_entry,
38  void *arg
39)
40{
41  return arg == mt_entry->mt_point_node.mt_entry;
42}
43
44/*
45 *  unmount
46 *
47 *  This routine will attempt to unmount the file system that has been
48 *  is mounted a path.  If the operation is successful, 0 will
49 *  be returned to the calling routine.  Otherwise, 1 will be returned.
50 */
51
52int unmount(
53  const char *path
54)
55{
56  rtems_filesystem_location_info_t      loc;
57  rtems_filesystem_location_info_t     *fs_root_loc;
58  rtems_filesystem_location_info_t     *fs_mount_loc;
59  rtems_filesystem_mount_table_entry_t *mt_entry;
60
61  /*
62   *  Get
63   *    The root node of the mounted filesytem.
64   *    The node for the directory that the fileystem is mounted on.
65   *    The mount entry that is being refered to.
66   */
67
68  if ( rtems_filesystem_evaluate_path( path, strlen( path ), 0x0, &loc, true ) )
69    return -1;
70
71  mt_entry     = loc.mt_entry;
72  fs_mount_loc = &mt_entry->mt_point_node;
73  fs_root_loc  = &mt_entry->mt_fs_root;
74
75  /*
76   * Verify this is the root node for the file system to be unmounted.
77   */
78
79  if ( fs_root_loc->node_access != loc.node_access ){
80    rtems_filesystem_freenode( &loc );
81    rtems_set_errno_and_return_minus_one( EACCES );
82  }
83
84  /*
85   * Free the loc node and just use the nodes from the mt_entry .
86   */
87
88  rtems_filesystem_freenode( &loc );
89
90  /*
91   * Verify Unmount is supported by both filesystems.
92   */
93
94  if ( !fs_mount_loc->ops->unmount_h )
95    rtems_set_errno_and_return_minus_one( ENOTSUP );
96
97  if ( !fs_root_loc->ops->fsunmount_me_h )
98    rtems_set_errno_and_return_minus_one( ENOTSUP );
99
100
101  /*
102   *  Verify the current node is not in this filesystem.
103   *  XXX - Joel I have a question here wasn't code added
104   *        that made the current node thread based instead
105   *        of system based?  I thought it was but it doesn't
106   *        look like it in this version.
107   */
108
109  if ( rtems_filesystem_current.mt_entry == mt_entry )
110    rtems_set_errno_and_return_minus_one( EBUSY );
111
112  /*
113   *  Verify there are no file systems below the path specified
114   */
115
116  if ( rtems_filesystem_mount_iterate( is_fs_below_mount_point,
117                                       fs_root_loc->mt_entry ) )
118    rtems_set_errno_and_return_minus_one( EBUSY );
119
120  /*
121   *  Run the file descriptor table to determine if there are any file
122   *  descriptors that are currently active and reference nodes in the
123   *  file system that we are trying to unmount
124   */
125
126  if ( rtems_libio_is_open_files_in_fs( mt_entry ) == 1 )
127    rtems_set_errno_and_return_minus_one( EBUSY );
128
129  /*
130   * Allow the file system being unmounted on to do its cleanup.
131   * If it fails it will set the errno to the approprate value
132   * and the fileystem will not be modified.
133   */
134
135  if (( fs_mount_loc->ops->unmount_h )( mt_entry ) != 0 )
136    return -1;
137
138  /*
139   *  Allow the mounted filesystem to unmark the use of the root node.
140   *
141   *  Run the unmount function for the subordinate file system.
142   *
143   *  If we fail to unmount the filesystem remount it on the base filesystems
144   *  directory node.
145   *
146   *  NOTE:  Fatal error is called in a case which should never happen
147   *         This was response was questionable but the best we could
148   *         come up with.
149   */
150
151  if ((fs_root_loc->ops->fsunmount_me_h )( mt_entry ) != 0){
152    if (( fs_mount_loc->ops->mount_h )( mt_entry ) != 0 )
153      rtems_fatal_error_occurred( 0 );
154    return -1;
155  }
156
157  /*
158   *  Extract the mount table entry from the chain
159   */
160
161  rtems_libio_lock();
162  rtems_chain_extract( &mt_entry->Node );
163  rtems_libio_unlock();
164
165  /*
166   *  Free the memory node that was allocated in mount
167   *  Free the memory associated with the extracted mount table entry.
168   */
169
170  rtems_filesystem_freenode( fs_mount_loc );
171  free( mt_entry );
172
173  return 0;
174}
Note: See TracBrowser for help on using the repository browser.