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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 30 unneback
/*
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: mount.c,v 1.2 2001-09-27 12:01:15 chris Exp $
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 "libio_.h"
31
 
32
Chain_Control rtems_filesystem_mount_table_control;
33
 
34
#include "imfs.h"
35
 
36
/* XXX this structure should be in an IMFS specific file */
37
/* XXX this structure should use real constants */
38
 
39
rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS = {
40
   5,   /* link_max */
41
   6,   /* max_canon */
42
   7,   /* max_input */
43
   IMFS_NAME_MAX,       /* name_max */
44
   255, /* path_max */
45
   2,   /* pipe_buf */
46
   1,   /* posix_async_io */
47
   2,   /* posix_chown_restrictions */
48
   3,   /* posix_no_trunc */
49
   4,   /* posix_prio_io */
50
   5,   /* posix_sync_io */
51
   6    /* posix_vdisable */
52
};
53
 
54
/*
55
 *  XXX
56
 */
57
 
58
int search_mt_for_mount_point(
59
  rtems_filesystem_location_info_t *location_of_mount_point
60
);
61
 
62
int init_fs_mount_table( void );
63
 
64
 
65
/*
66
 *  XXX
67
 */
68
 
69
#define FOUND      0
70
#define NOT_FOUND -1
71
 
72
/*
73
 *  mount
74
 *
75
 *  This routine will attempt to mount a new file system at the specified
76
 *  mount point. A series of tests will be run to determine if any of the
77
 *  following reasons exist to prevent the mount operation:
78
 *
79
 *      1) The file system type or options are not valid
80
 *      2) No new file system root node is specified
81
 *      3) The selected file system has already been mounted
82
 *      4) The mount point exists with the proper permissions to allow mounting
83
 *      5) The selected mount point already has a file system mounted to it
84
 *
85
 */
86
 
87
int mount(
88
  rtems_filesystem_mount_table_entry_t **mt_entry,
89
  rtems_filesystem_operations_table    *fs_ops,
90
  rtems_filesystem_options_t            options,
91
  char                                 *device,
92
  char                                 *mount_point
93
)
94
{
95
  rtems_filesystem_location_info_t      loc;
96
  rtems_filesystem_mount_table_entry_t *temp_mt_entry;
97
  rtems_filesystem_location_info_t     *loc_to_free = NULL;
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
 
145
    if ( rtems_filesystem_evaluate_path(
146
            mount_point, RTEMS_LIBIO_PERMS_RWX, &loc, TRUE ) == -1 )
147
      goto cleanup_and_bail;
148
 
149
    /*
150
     *  Test to see if it is a directory
151
     */
152
 
153
    loc_to_free = &loc;
154
    if ( loc.ops->node_type( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {
155
      errno = ENOTDIR;
156
      goto cleanup_and_bail;
157
    }
158
 
159
    /*
160
     *  You can only mount one file system onto a single mount point.
161
     */
162
 
163
    if ( search_mt_for_mount_point( &loc ) == FOUND ) {
164
      errno = EBUSY;
165
      goto cleanup_and_bail;
166
    }
167
 
168
    /*
169
     *  This must be a good mount point, so move the location information
170
     *  into the allocated mount entry.  Note:  the information that
171
     *  may have been allocated in loc should not be sent to freenode
172
     *  until the system is unmounted.  It may be needed to correctly
173
     *  traverse the tree.
174
     */
175
 
176
    temp_mt_entry->mt_point_node.node_access = loc.node_access;
177
    temp_mt_entry->mt_point_node.handlers = loc.handlers;
178
    temp_mt_entry->mt_point_node.ops = loc.ops;
179
    temp_mt_entry->mt_point_node.mt_entry = loc.mt_entry;
180
 
181
    /*
182
     *  This link to the parent is only done when we are dealing with system
183
     *  below the base file system
184
     */
185
 
186
    if ( !loc.ops->mount ){
187
      errno = ENOTSUP;
188
      goto cleanup_and_bail;
189
    }
190
 
191
    if ( loc.ops->mount( temp_mt_entry ) ) {
192
      goto cleanup_and_bail;
193
    }
194
  } else {
195
 
196
    /*
197
     *  This is a mount of the base file system --> The
198
     *  mt_point_node.node_access will be set to null to indicate that this
199
     *  is the root of the entire file system.
200
     */
201
 
202
    temp_mt_entry->mt_fs_root.node_access = NULL;
203
    temp_mt_entry->mt_fs_root.handlers = NULL;
204
    temp_mt_entry->mt_fs_root.ops = NULL;
205
 
206
    temp_mt_entry->mt_point_node.node_access = NULL;
207
    temp_mt_entry->mt_point_node.handlers = NULL;
208
    temp_mt_entry->mt_point_node.ops = NULL;
209
    temp_mt_entry->mt_point_node.mt_entry = NULL;
210
  }
211
 
212
  if ( !fs_ops->fsmount_me ) {
213
    errno = ENOTSUP;
214
    goto cleanup_and_bail;
215
  }
216
 
217
  if ( fs_ops->fsmount_me( temp_mt_entry ) )
218
    goto cleanup_and_bail;
219
 
220
  /*
221
   *  Add the mount table entry to the mount table chain
222
   */
223
 
224
  Chain_Append( &rtems_filesystem_mount_table_control, &temp_mt_entry->Node );
225
 
226
  *mt_entry = temp_mt_entry;
227
 
228
  return 0;
229
 
230
cleanup_and_bail:
231
 
232
  free( temp_mt_entry );
233
 
234
  if ( loc_to_free )
235
    rtems_filesystem_freenode( loc_to_free );
236
 
237
  return -1;
238
}
239
 
240
 
241
 
242
/*
243
 *  init_fs_mount_table
244
 *
245
 *  This routine will initialize the chain control element that manages the
246
 *  mount table chain.
247
 */
248
 
249
int init_fs_mount_table()
250
{
251
  Chain_Initialize_empty ( &rtems_filesystem_mount_table_control );
252
  return 0;
253
}
254
 
255
 
256
/*
257
 *  search_mt_for_mount_point
258
 *
259
 *  This routine will run through the entries that currently exist in the
260
 *  mount table chain. For each entry in the mount table chain it will
261
 *  compare the mount tables mt_point_node to the node describing the selected
262
 *  mount point.. If any of the mount table file system mount point nodes
263
 *  match the new file system selected mount point node, we are attempting
264
 *  to mount the new file system onto a node that already has a file system
265
 *  mounted to it. This is not a permitted operation.
266
 */
267
 
268
int search_mt_for_mount_point(
269
  rtems_filesystem_location_info_t *location_of_mount_point
270
)
271
{
272
  Chain_Node                           *the_node;
273
  rtems_filesystem_mount_table_entry_t *the_mount_entry;
274
 
275
  for ( the_node = rtems_filesystem_mount_table_control.first;
276
        !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node );
277
        the_node = the_node->next ) {
278
 
279
     the_mount_entry = (rtems_filesystem_mount_table_entry_t *) the_node;
280
     if ( the_mount_entry->mt_point_node.node_access  ==
281
             location_of_mount_point->node_access )
282
        return FOUND;
283
  }
284
  return NOT_FOUND;
285
}
286
 

powered by: WebSVN 2.1.0

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