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 | |
---|
33 | Chain_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 | |
---|
40 | rtems_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 | |
---|
59 | int search_mt_for_mount_point( |
---|
60 | rtems_filesystem_location_info_t *location_of_mount_point |
---|
61 | ); |
---|
62 | |
---|
63 | int 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 | |
---|
88 | int mount( |
---|
89 | rtems_filesystem_mount_table_entry_t **mt_entry, |
---|
90 | rtems_filesystem_operations_table *fs_ops, |
---|
91 | rtems_filesystem_options_t fsoptions, |
---|
92 | char *device, |
---|
93 | char *mount_point |
---|
94 | ) |
---|
95 | { |
---|
96 | rtems_filesystem_location_info_t temp_loc; |
---|
97 | rtems_filesystem_options_t options; |
---|
98 | rtems_filesystem_mount_table_entry_t *temp_mt_entry; |
---|
99 | |
---|
100 | /* XXX add code to check for required operations */ |
---|
101 | |
---|
102 | /* |
---|
103 | * Is there a file system operations table? |
---|
104 | */ |
---|
105 | |
---|
106 | if ( fs_ops == NULL ) { |
---|
107 | errno = EINVAL; |
---|
108 | return -1; |
---|
109 | } |
---|
110 | |
---|
111 | /* |
---|
112 | * Are the file system options valid? |
---|
113 | */ |
---|
114 | |
---|
115 | if ( fsoptions != RTEMS_FILESYSTEM_READ_ONLY && |
---|
116 | fsoptions != RTEMS_FILESYSTEM_READ_WRITE ) { |
---|
117 | errno = EINVAL; |
---|
118 | return -1; |
---|
119 | } |
---|
120 | |
---|
121 | /* |
---|
122 | * Allocate a mount table entry |
---|
123 | */ |
---|
124 | |
---|
125 | temp_mt_entry = malloc( sizeof(rtems_filesystem_mount_table_entry_t) ); |
---|
126 | |
---|
127 | if ( !temp_mt_entry ) { |
---|
128 | errno = ENOMEM; |
---|
129 | return -1; |
---|
130 | } |
---|
131 | |
---|
132 | temp_mt_entry->mt_fs_root.mt_entry = temp_mt_entry; |
---|
133 | temp_mt_entry->options = options; |
---|
134 | if ( device ) |
---|
135 | strcpy( temp_mt_entry->dev, device ); |
---|
136 | else |
---|
137 | temp_mt_entry->dev = 0; |
---|
138 | |
---|
139 | /* |
---|
140 | * The mount_point should be a directory with read/write/execute |
---|
141 | * permissions in the existing tree. |
---|
142 | */ |
---|
143 | |
---|
144 | if ( mount_point ) { |
---|
145 | if ( rtems_filesystem_evaluate_path( |
---|
146 | mount_point, |
---|
147 | RTEMS_LIBIO_PERMS_RWX, |
---|
148 | &temp_loc , |
---|
149 | TRUE ) == -1 ) |
---|
150 | goto cleanup_and_bail; |
---|
151 | |
---|
152 | /* |
---|
153 | * Test to see if it is a directory |
---|
154 | */ |
---|
155 | |
---|
156 | if ( temp_loc.ops->node_type( &temp_loc ) != RTEMS_FILESYSTEM_DIRECTORY ) { |
---|
157 | errno = ENOTDIR; |
---|
158 | goto cleanup_and_bail; |
---|
159 | } |
---|
160 | |
---|
161 | /* |
---|
162 | * You can only mount one file system onto a single mount point. |
---|
163 | */ |
---|
164 | |
---|
165 | if ( search_mt_for_mount_point( &temp_loc ) == FOUND ) { |
---|
166 | errno = EBUSY; |
---|
167 | goto cleanup_and_bail; |
---|
168 | } |
---|
169 | |
---|
170 | /* |
---|
171 | * This must be a good mount point, so move the location information |
---|
172 | * into the allocated mount entry |
---|
173 | */ |
---|
174 | |
---|
175 | temp_mt_entry->mt_point_node.node_access = temp_loc.node_access; |
---|
176 | temp_mt_entry->mt_point_node.handlers = temp_loc.handlers; |
---|
177 | temp_mt_entry->mt_point_node.ops = temp_loc.ops; |
---|
178 | temp_mt_entry->mt_point_node.mt_entry = temp_loc.mt_entry; |
---|
179 | |
---|
180 | /* |
---|
181 | * This link to the parent is only done when we are dealing with system |
---|
182 | * below the base file system |
---|
183 | */ |
---|
184 | |
---|
185 | if ( !temp_loc.ops->mount ){ |
---|
186 | errno = ENOTSUP; |
---|
187 | goto cleanup_and_bail; |
---|
188 | } |
---|
189 | |
---|
190 | if ( temp_loc.ops->mount( temp_mt_entry ) ) { |
---|
191 | goto cleanup_and_bail; |
---|
192 | } |
---|
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 | return 0; |
---|
228 | |
---|
229 | cleanup_and_bail: |
---|
230 | |
---|
231 | free( temp_mt_entry ); |
---|
232 | return -1; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | |
---|
237 | /* |
---|
238 | * init_fs_mount_table |
---|
239 | * |
---|
240 | * This routine will initialize the chain control element that manages the |
---|
241 | * mount table chain. |
---|
242 | */ |
---|
243 | |
---|
244 | int init_fs_mount_table() |
---|
245 | { |
---|
246 | Chain_Initialize_empty ( &rtems_filesystem_mount_table_control ); |
---|
247 | return 0; |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | /* |
---|
252 | * search_mt_for_mount_point |
---|
253 | * |
---|
254 | * This routine will run through the entries that currently exist in the |
---|
255 | * mount table chain. For each entry in the mount table chain it will |
---|
256 | * compare the mount tables mt_point_node to the node describing the selected |
---|
257 | * mount point.. If any of the mount table file system mount point nodes |
---|
258 | * match the new file system selected mount point node, we are attempting |
---|
259 | * to mount the new file system onto a node that already has a file system |
---|
260 | * mounted to it. This is not a permitted operation. |
---|
261 | */ |
---|
262 | |
---|
263 | int search_mt_for_mount_point( |
---|
264 | rtems_filesystem_location_info_t *location_of_mount_point |
---|
265 | ) |
---|
266 | { |
---|
267 | Chain_Node *the_node; |
---|
268 | rtems_filesystem_mount_table_entry_t *the_mount_entry; |
---|
269 | |
---|
270 | for ( the_node = rtems_filesystem_mount_table_control.first; |
---|
271 | !Chain_Is_tail( &rtems_filesystem_mount_table_control, the_node ); |
---|
272 | the_node = the_node->next ) { |
---|
273 | |
---|
274 | the_mount_entry = (rtems_filesystem_mount_table_entry_t *) the_node; |
---|
275 | if ( the_mount_entry->mt_point_node.node_access == |
---|
276 | location_of_mount_point->node_access ) |
---|
277 | return FOUND; |
---|
278 | } |
---|
279 | return NOT_FOUND; |
---|
280 | } |
---|
281 | |
---|