OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libc/] [unmount.c] - Blame information for rev 481

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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: unmount.c,v 1.2 2001-09-27 12:01:15 chris Exp $
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
 
36
extern Chain_Control                    rtems_filesystem_mount_table_control;
37
extern rtems_filesystem_location_info_t rtems_filesystem_current;
38
 
39
int search_mt_for_mount_point(
40
  rtems_filesystem_location_info_t *location_of_mount_point
41
);
42
 
43
 
44
int 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
 
58
int 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
 
66
  /*
67
   *  Are there any file systems below the mount_path specified
68
   */
69
 
70
  status = file_systems_below_this_mountpoint(
71
    mount_path,
72
    &temp_loc,
73
    &temp_mt_entry
74
  );
75
 
76
  if ( status != 0 )
77
    return -1;
78
 
79
  /*
80
   *  Is the current node reference pointing to a node in the file system
81
   *  we are attempting to unmount ?
82
   */
83
 
84
  if ( rtems_filesystem_current.mt_entry == temp_loc.mt_entry ) {
85
    rtems_filesystem_freenode( &temp_loc );
86
    set_errno_and_return_minus_one( EBUSY );
87
  }
88
 
89
  /*
90
   *  Run the file descriptor table to determine if there are any file
91
   *  descriptors that are currently active and reference nodes in the
92
   *  file system that we are trying to unmount
93
   */
94
 
95
  if ( rtems_libio_is_open_files_in_fs( temp_loc.mt_entry ) == 1 ) {
96
    rtems_filesystem_freenode( &temp_loc );
97
    set_errno_and_return_minus_one( EBUSY );
98
  }
99
 
100
  /*
101
   * Allow the file system being mounted on to do its cleanup.
102
   * XXX - Did I change these correctly ??? It looks like either I did
103
   * XXX   this backwards or the IMFS_unmount and IMFS_fsumount are swapped.
104
   * XXX   Add to the mt_point_node unmount to set the mt_entry back to null
105
   * XXX   I will step off in space when evaluating past the end of the node.
106
   */
107
 
108
  if ((temp_mt_entry.mt_point_node.ops->unmount )( temp_loc.mt_entry ) != 0 ) {
109
    rtems_filesystem_freenode( &temp_loc );
110
    return -1;
111
  }
112
 
113
  /*
114
   * Run the unmount function for the subordinate file system.
115
   */
116
 
117
  if ((temp_mt_entry.mt_fs_root.ops->fsunmount_me )( temp_loc.mt_entry ) != 0){
118
    rtems_filesystem_freenode( &temp_loc );
119
    return -1;
120
  }
121
 
122
  /*
123
   *  Extract the mount table entry from the chain
124
   */
125
 
126
  Chain_Extract( ( Chain_Node * ) temp_loc.mt_entry );
127
 
128
  /*
129
   *  Free the memory associated with the extracted mount table entry.
130
   */
131
 
132
  rtems_filesystem_freenode( &temp_loc.mt_entry->mt_point_node );
133
  free( temp_loc.mt_entry );
134
  rtems_filesystem_freenode( &temp_loc );
135
 
136
  return 0;
137
}
138
 
139
 
140
/*
141
 *  file_systems_below_this_mountpoint
142
 *
143
 *  This routine will run through the entries that currently exist in the
144
 *  mount table chain. For each entry in the mount table chain it will
145
 *  compare the mount tables mt_fs_root to the new_fs_root_node. If any of the
146
 *  mount table file system root nodes matches the new file system root node
147
 *  this indicates that we are trying to mount a file system that has already
148
 *  been mounted. This is not a permitted operation. temp_loc is set to
149
 *  the root node of the file system being unmounted.
150
 */
151
 
152
int file_systems_below_this_mountpoint(
153
  const char                            *mount_path,
154
  rtems_filesystem_location_info_t      *temp_loc,
155
  rtems_filesystem_mount_table_entry_t  *temp_mt_entry
156
)
157
{
158
  Chain_Node                           *the_node;
159
  rtems_filesystem_mount_table_entry_t *the_mount_entry;
160
  rtems_filesystem_mount_table_entry_t *current_fs_mt_entry;
161
 
162
  /*
163
   *  Is the mount_path even a valid node name in the existing tree?
164
   */
165
 
166
  if ( rtems_filesystem_evaluate_path( mount_path, 0x0, temp_loc, TRUE ) )
167
    return -1;
168
 
169
  /*
170
   *  Look for the node defined in temp_loc as a mount point in the
171
   *  mount table chain.
172
   */
173
 
174
  for ( the_node = rtems_filesystem_mount_table_control.first;
175
        !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node );
176
        the_node = the_node->next ) {
177
 
178
     the_mount_entry = ( rtems_filesystem_mount_table_entry_t * )the_node;
179
     if  (the_mount_entry->mt_point_node.node_access  ==
180
          temp_loc->node_access ) {
181
        current_fs_mt_entry = the_mount_entry;
182
        *temp_loc = current_fs_mt_entry->mt_fs_root;
183
        goto after_real_mount_point_found;
184
     }
185
  }
186
  set_errno_and_return_minus_one( EACCES );
187
 
188
 
189
after_real_mount_point_found:
190
 
191
  for ( the_node = rtems_filesystem_mount_table_control.first;
192
        !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node );
193
        the_node = the_node->next ) {
194
 
195
     the_mount_entry = (  rtems_filesystem_mount_table_entry_t * )the_node;
196
 
197
     /*
198
      *  Exclude the current file systems mount table entry from the test
199
      */
200
 
201
     if ( current_fs_mt_entry != the_mount_entry ) {
202
       if ( the_mount_entry->mt_point_node.mt_entry  == current_fs_mt_entry ) {
203
 
204
          /*
205
           *  There is at least one fs below the fs on the mount_path.
206
           */
207
          set_errno_and_return_minus_one( EBUSY );
208
       }
209
     }
210
  }
211
 
212
  *temp_mt_entry = *current_fs_mt_entry;
213
 
214
  return 0;
215
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.