source: rtems/cpukit/libcsupport/src/mount.c @ 3ba74c73

4.104.114.84.95
Last change on this file since 3ba74c73 was 3ba74c73, checked in by Joel Sherrill <joel.sherrill@…>, on 11/01/00 at 21:08:14

2000-11-01 Joel Sherrill <joel@…>

  • include/Makefile.am, include/rtems/libio_.h, libc/Makefile.am, libc/assoc.c, libc/assocnamebad.c, libc/base_fs.c, libc/cfsetispeed.c, libc/cfsetospeed.c, libc/chdir.c, libc/chmod.c, libc/chown.c, libc/close.c, libc/closedir.c, libc/dup2.c, libc/error.c, libc/eval.c, libc/fchdir.c, libc/fchmod.c, libc/fcntl.c, libc/fdatasync.c, libc/fpathconf.c, libc/fstat.c, libc/fsync.c, libc/ftruncate.c, libc/getdents.c, libc/ioctl.c, libc/libio.c, libc/libio_sockets.c, libc/link.c, libc/lseek.c, libc/malloc.c, libc/mallocfreespace.c, libc/mknod.c, libc/mount.c, libc/newlibc.c, libc/no_libc.c, libc/open.c, libc/read.c, libc/readlink.c, libc/rmdir.c, libc/stat.c, libc/symlink.c, libc/tcsetattr.c, libc/telldir.c, libc/ttyname.c, libc/ttyname_r.c, libc/umask.c, libc/unlink.c, libc/unmount.c, libc/utime.c, libc/write.c: assoc.h, error.h, libio_.h, libio.h, and libcsupport.h moved from libc to lib/include/rtems and now must be referenced as <rtems/XXX.h>.
  • include/rtems/Makefile.am, include/rtems/.cvsignore: New file.
  • include/rtems/assoc.h, include/rtems/error.h, include/rtems/libcsupport.h, include/rtems/libio.h, include/rtems/libio_.h: New/moved files.
  • Property mode set to 100644
File size: 6.5 KB
Line 
1/*
2 *  mount()
3 *
4 *  XXX
5 *
6 *  XXX make sure no required ops are NULL
7 *  XXX make sure no optional ops you are using are NULL
8 *  XXX unmount should be required.
9 *
10 *  COPYRIGHT (c) 1989-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  $Id$
18 */
19
20#include <sys/types.h>
21#include <sys/stat.h>
22#include <chain.h>
23#include <fcntl.h>
24#include <unistd.h>
25#include <errno.h>
26#include <stdlib.h>
27#include <string.h>
28#include <assert.h>
29
30#include <rtems/libio_.h>
31
32Chain_Control rtems_filesystem_mount_table_control;
33
34/*
35 *  Prototypes that probably should be somewhere else.
36 */
37
38int search_mt_for_mount_point(
39  rtems_filesystem_location_info_t *location_of_mount_point
40);
41
42int init_fs_mount_table( void );
43
44
45/*
46 *  XXX
47 */
48
49#define FOUND      0
50#define NOT_FOUND -1
51
52/*
53 *  mount
54 *
55 *  This routine will attempt to mount a new file system at the specified
56 *  mount point. A series of tests will be run to determine if any of the
57 *  following reasons exist to prevent the mount operation:
58 *
59 *      1) The file system type or options are not valid
60 *      2) No new file system root node is specified
61 *      3) The selected file system has already been mounted
62 *      4) The mount point exists with the proper permissions to allow mounting
63 *      5) The selected mount point already has a file system mounted to it
64 *
65 */
66
67int mount(
68  rtems_filesystem_mount_table_entry_t **mt_entry,
69  rtems_filesystem_operations_table    *fs_ops,
70  rtems_filesystem_options_t            options,
71  char                                 *device,
72  char                                 *mount_point
73)
74{
75  rtems_filesystem_location_info_t      loc;
76  rtems_filesystem_mount_table_entry_t *temp_mt_entry;
77  rtems_filesystem_location_info_t     *loc_to_free = NULL;
78
79/* XXX add code to check for required operations */
80
81  /*
82   *  Is there a file system operations table?
83   */
84
85  if ( fs_ops == NULL ) {
86    errno = EINVAL;
87    return -1;
88  }
89
90  /*
91   *  Are the file system options valid?
92   */
93
94  if ( options != RTEMS_FILESYSTEM_READ_ONLY &&
95       options != RTEMS_FILESYSTEM_READ_WRITE ) {
96    errno = EINVAL;
97    return -1;
98  }
99
100  /*
101   * Allocate a mount table entry
102   */
103
104   temp_mt_entry = malloc( sizeof(rtems_filesystem_mount_table_entry_t) );
105
106   if ( !temp_mt_entry ) {
107     errno = ENOMEM;
108     return -1;
109   }
110
111   temp_mt_entry->mt_fs_root.mt_entry = temp_mt_entry;
112   temp_mt_entry->options = options;
113   if ( device )
114     strcpy( temp_mt_entry->dev, device );
115   else
116     temp_mt_entry->dev = 0;
117
118  /*
119   *  The mount_point should be a directory with read/write/execute
120   *  permissions in the existing tree.
121   */
122
123  if ( mount_point ) {
124
125    if ( rtems_filesystem_evaluate_path(
126            mount_point, RTEMS_LIBIO_PERMS_RWX, &loc, TRUE ) == -1 )
127      goto cleanup_and_bail;
128
129    /*
130     *  Test to see if it is a directory
131     */
132
133    loc_to_free = &loc;
134    if ( loc.ops->node_type_h( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {
135      errno = ENOTDIR;
136      goto cleanup_and_bail;
137    }
138
139    /*
140     *  You can only mount one file system onto a single mount point.
141     */
142
143    if ( search_mt_for_mount_point( &loc ) == FOUND ) {
144      errno = EBUSY;
145      goto cleanup_and_bail;
146    }
147 
148    /*
149     *  This must be a good mount point, so move the location information
150     *  into the allocated mount entry.  Note:  the information that
151     *  may have been allocated in loc should not be sent to freenode
152     *  until the system is unmounted.  It may be needed to correctly
153     *  traverse the tree.
154     */
155
156    temp_mt_entry->mt_point_node.node_access = loc.node_access;
157    temp_mt_entry->mt_point_node.handlers = loc.handlers;
158    temp_mt_entry->mt_point_node.ops = loc.ops;
159    temp_mt_entry->mt_point_node.mt_entry = loc.mt_entry;
160
161    /*
162     *  This link to the parent is only done when we are dealing with system
163     *  below the base file system
164     */
165
166    if ( !loc.ops->mount_h ){
167      errno = ENOTSUP;
168      goto cleanup_and_bail;
169    }
170
171    if ( loc.ops->mount_h( temp_mt_entry ) ) {
172      goto cleanup_and_bail;
173    }
174  } else {
175
176    /*
177     *  This is a mount of the base file system --> The
178     *  mt_point_node.node_access will be set to null to indicate that this
179     *  is the root of the entire file system.
180     */
181
182    temp_mt_entry->mt_fs_root.node_access = NULL;
183    temp_mt_entry->mt_fs_root.handlers = NULL;
184    temp_mt_entry->mt_fs_root.ops = NULL;
185
186    temp_mt_entry->mt_point_node.node_access = NULL;
187    temp_mt_entry->mt_point_node.handlers = NULL;
188    temp_mt_entry->mt_point_node.ops = NULL;
189    temp_mt_entry->mt_point_node.mt_entry = NULL;
190  }
191
192  if ( !fs_ops->fsmount_me_h ) {
193    errno = ENOTSUP;
194    goto cleanup_and_bail;
195  }
196
197  if ( fs_ops->fsmount_me_h( temp_mt_entry ) )
198    goto cleanup_and_bail;
199
200  /*
201   *  Add the mount table entry to the mount table chain
202   */
203
204  Chain_Append( &rtems_filesystem_mount_table_control, &temp_mt_entry->Node );
205
206  *mt_entry = temp_mt_entry;
207
208  return 0;
209
210cleanup_and_bail:
211
212  free( temp_mt_entry );
213 
214  if ( loc_to_free )
215    rtems_filesystem_freenode( loc_to_free );
216
217  return -1;
218}
219
220
221
222/*
223 *  init_fs_mount_table
224 *
225 *  This routine will initialize the chain control element that manages the
226 *  mount table chain.
227 */
228
229int init_fs_mount_table()
230{
231  Chain_Initialize_empty ( &rtems_filesystem_mount_table_control );
232  return 0;
233}
234
235
236/*
237 *  search_mt_for_mount_point
238 *
239 *  This routine will run through the entries that currently exist in the
240 *  mount table chain. For each entry in the mount table chain it will
241 *  compare the mount tables mt_point_node to the node describing the selected
242 *  mount point.. If any of the mount table file system mount point nodes
243 *  match the new file system selected mount point node, we are attempting
244 *  to mount the new file system onto a node that already has a file system
245 *  mounted to it. This is not a permitted operation.
246 */
247
248int search_mt_for_mount_point(
249  rtems_filesystem_location_info_t *location_of_mount_point
250)
251{
252  Chain_Node                           *the_node;
253  rtems_filesystem_mount_table_entry_t *the_mount_entry;
254
255  for ( the_node = rtems_filesystem_mount_table_control.first;
256        !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node );
257        the_node = the_node->next ) {
258
259     the_mount_entry = (rtems_filesystem_mount_table_entry_t *) the_node;
260     if ( the_mount_entry->mt_point_node.node_access  ==
261             location_of_mount_point->node_access )
262        return FOUND;
263  }
264  return NOT_FOUND;
265}
266
Note: See TracBrowser for help on using the repository browser.