source: rtems/cpukit/libcsupport/src/mount.c @ d71fcab

4.104.114.84.95
Last change on this file since d71fcab was d71fcab, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/99 at 18:44:40

Added call to freenod to let each filesystem free its own internal
node used to manage file access.

  • Property mode set to 100644
File size: 6.8 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-1998.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <chain.h>
24#include <fcntl.h>
25#include <unistd.h>
26#include <errno.h>
27#include <stdlib.h>
28#include <string.h>
29#include <assert.h>
30
31#include "libio_.h"
32
33Chain_Control rtems_filesystem_mount_table_control;
34
35#include "imfs.h"
36
37/* XXX this structure should be in an IMFS specific file */
38/* XXX this structure should use real constants */
39
40rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS = {
41   5,   /* link_max */
42   6,   /* max_canon */
43   7,   /* max_input */
44   IMFS_NAME_MAX,       /* name_max */
45   255, /* path_max */
46   2,   /* pipe_buf */
47   1,   /* posix_async_io */
48   2,   /* posix_chown_restrictions */
49   3,   /* posix_no_trunc */
50   4,   /* posix_prio_io */
51   5,   /* posix_sync_io */
52   6    /* posix_vdisable */
53};
54
55/*
56 *  XXX
57 */
58
59int search_mt_for_mount_point(
60  rtems_filesystem_location_info_t *location_of_mount_point
61);
62
63int init_fs_mount_table( void );
64
65
66/*
67 *  XXX
68 */
69
70#define FOUND      0
71#define NOT_FOUND -1
72
73/*
74 *  mount
75 *
76 *  This routine will attempt to mount a new file system at the specified
77 *  mount point. A series of tests will be run to determine if any of the
78 *  following reasons exist to prevent the mount operation:
79 *
80 *      1) The file system type or options are not valid
81 *      2) No new file system root node is specified
82 *      3) The selected file system has already been mounted
83 *      4) The mount point exists with the proper permissions to allow mounting
84 *      5) The selected mount point already has a file system mounted to it
85 *
86 */
87
88int mount(
89  rtems_filesystem_mount_table_entry_t **mt_entry,
90  rtems_filesystem_operations_table    *fs_ops,
91  rtems_filesystem_options_t            options,
92  char                                 *device,
93  char                                 *mount_point
94)
95{
96  rtems_filesystem_location_info_t      loc;
97  rtems_filesystem_mount_table_entry_t *temp_mt_entry;
98
99/* XXX add code to check for required operations */
100
101  /*
102   *  Is there a file system operations table?
103   */
104
105  if ( fs_ops == NULL ) {
106    errno = EINVAL;
107    return -1;
108  }
109
110  /*
111   *  Are the file system options valid?
112   */
113
114  if ( options != RTEMS_FILESYSTEM_READ_ONLY &&
115       options != RTEMS_FILESYSTEM_READ_WRITE ) {
116    errno = EINVAL;
117    return -1;
118  }
119
120  /*
121   * Allocate a mount table entry
122   */
123
124   temp_mt_entry = malloc( sizeof(rtems_filesystem_mount_table_entry_t) );
125
126   if ( !temp_mt_entry ) {
127     errno = ENOMEM;
128     return -1;
129   }
130
131   temp_mt_entry->mt_fs_root.mt_entry = temp_mt_entry;
132   temp_mt_entry->options = options;
133   if ( device )
134     strcpy( temp_mt_entry->dev, device );
135   else
136     temp_mt_entry->dev = 0;
137
138  /*
139   *  The mount_point should be a directory with read/write/execute
140   *  permissions in the existing tree.
141   */
142
143  if ( mount_point ) {
144     if ( rtems_filesystem_evaluate_path(
145       mount_point,
146       RTEMS_LIBIO_PERMS_RWX,
147       &loc,
148       TRUE ) == -1 )
149       goto cleanup_and_bail;
150
151     /*
152      * Test to see if it is a directory
153      */
154
155     if ( loc.ops->node_type( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {
156       errno = ENOTDIR;
157       goto cleanup_and_bail;
158     }
159
160     /*
161      *  You can only mount one file system onto a single mount point.
162      */
163
164     if ( search_mt_for_mount_point( &loc ) == FOUND ) {
165       errno = EBUSY;
166       goto cleanup_and_bail;
167     }
168 
169     /*
170      * This must be a good mount point, so move the location information
171      * into the allocated mount entry
172      */
173
174     temp_mt_entry->mt_point_node.node_access = loc.node_access;
175     temp_mt_entry->mt_point_node.handlers = loc.handlers;
176     temp_mt_entry->mt_point_node.ops = loc.ops;
177     temp_mt_entry->mt_point_node.mt_entry = loc.mt_entry;
178
179     /*
180      * This link to the parent is only done when we are dealing with system
181      * below the base file system
182      */
183
184     if ( !loc.ops->mount ){
185       errno = ENOTSUP;
186       goto cleanup_and_bail;
187     }
188
189     if ( loc.ops->mount( temp_mt_entry ) ) {
190        goto cleanup_and_bail;
191     }
192  }
193  else {
194
195     /*
196      * This is a mount of the base file system --> The
197      * mt_point_node.node_access will be set to null to indicate that this
198      * is the root of the entire file system.
199      */
200
201      temp_mt_entry->mt_fs_root.node_access = NULL;
202      temp_mt_entry->mt_fs_root.handlers = NULL;
203      temp_mt_entry->mt_fs_root.ops = NULL;
204
205      temp_mt_entry->mt_point_node.node_access = NULL;
206      temp_mt_entry->mt_point_node.handlers = NULL;
207      temp_mt_entry->mt_point_node.ops = NULL;
208      temp_mt_entry->mt_point_node.mt_entry = NULL;
209  }
210
211  if ( !fs_ops->fsmount_me ){
212      errno = ENOTSUP;
213      goto cleanup_and_bail;
214  }
215
216  if ( fs_ops->fsmount_me( temp_mt_entry ) )
217      goto cleanup_and_bail;
218
219  /*
220   * Add the mount table entry to the mount table chain
221   */
222
223  Chain_Append( &rtems_filesystem_mount_table_control, &temp_mt_entry->Node );
224
225  *mt_entry = temp_mt_entry;
226
227  if ( loc.ops->freenod )
228    (*loc.ops->freenod)( &loc );
229 
230  return 0;
231
232cleanup_and_bail:
233
234  free( temp_mt_entry );
235
236  if ( loc.ops->freenod )
237    (*loc.ops->freenod)( &loc );
238 
239  return -1;
240}
241
242
243
244/*
245 *  init_fs_mount_table
246 *
247 *  This routine will initialize the chain control element that manages the
248 *  mount table chain.
249 */
250
251int init_fs_mount_table()
252{
253  Chain_Initialize_empty ( &rtems_filesystem_mount_table_control );
254  return 0;
255}
256
257
258/*
259 *  search_mt_for_mount_point
260 *
261 *  This routine will run through the entries that currently exist in the
262 *  mount table chain. For each entry in the mount table chain it will
263 *  compare the mount tables mt_point_node to the node describing the selected
264 *  mount point.. If any of the mount table file system mount point nodes
265 *  match the new file system selected mount point node, we are attempting
266 *  to mount the new file system onto a node that already has a file system
267 *  mounted to it. This is not a permitted operation.
268 */
269
270int search_mt_for_mount_point(
271  rtems_filesystem_location_info_t *location_of_mount_point
272)
273{
274  Chain_Node                           *the_node;
275  rtems_filesystem_mount_table_entry_t *the_mount_entry;
276
277  for ( the_node = rtems_filesystem_mount_table_control.first;
278        !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node );
279        the_node = the_node->next ) {
280
281     the_mount_entry = (rtems_filesystem_mount_table_entry_t *) the_node;
282     if ( the_mount_entry->mt_point_node.node_access  ==
283             location_of_mount_point->node_access )
284        return FOUND;
285  }
286  return NOT_FOUND;
287}
288
Note: See TracBrowser for help on using the repository browser.