1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief LibIO Internal Interface |
---|
5 | * |
---|
6 | * This file is the libio internal interface. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2011. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * Modifications to support reference counting in the file system are |
---|
14 | * Copyright (c) 2012 embedded brains GmbH. |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.com/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef _RTEMS_RTEMS_LIBIO__H |
---|
22 | #define _RTEMS_RTEMS_LIBIO__H |
---|
23 | |
---|
24 | #include <errno.h> |
---|
25 | |
---|
26 | #include <rtems.h> |
---|
27 | #include <rtems/libio.h> |
---|
28 | #include <rtems/seterr.h> |
---|
29 | |
---|
30 | #ifdef __cplusplus |
---|
31 | extern "C" { |
---|
32 | #endif |
---|
33 | |
---|
34 | /** |
---|
35 | * @defgroup LibIOInternal IO Internal Library |
---|
36 | * |
---|
37 | * @brief Internal IO library API and implementation. |
---|
38 | * |
---|
39 | */ |
---|
40 | /**@{**/ |
---|
41 | |
---|
42 | #define RTEMS_FILESYSTEM_SYMLOOP_MAX 32 |
---|
43 | |
---|
44 | /* |
---|
45 | * Semaphore to protect the io table |
---|
46 | */ |
---|
47 | |
---|
48 | #define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O') |
---|
49 | #define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n) |
---|
50 | |
---|
51 | extern rtems_id rtems_libio_semaphore; |
---|
52 | |
---|
53 | /* |
---|
54 | * File descriptor Table Information |
---|
55 | */ |
---|
56 | |
---|
57 | extern uint32_t rtems_libio_number_iops; |
---|
58 | extern rtems_libio_t *rtems_libio_iops; |
---|
59 | extern rtems_libio_t *rtems_libio_last_iop; |
---|
60 | extern rtems_libio_t *rtems_libio_iop_freelist; |
---|
61 | |
---|
62 | extern const rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers; |
---|
63 | |
---|
64 | extern rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry; |
---|
65 | |
---|
66 | /** |
---|
67 | * @brief The global null location. |
---|
68 | * |
---|
69 | * Every operation and the open and fstat handlers of this location returns an |
---|
70 | * error status. The errno is not touched by these operations and handlers. |
---|
71 | * The purpose of this location is to deliver the error return status for a |
---|
72 | * previous error condition which must set the errno accordingly. |
---|
73 | * |
---|
74 | * The usage of this null location instead of the NULL pointer eliminates |
---|
75 | * a lot of branches. |
---|
76 | * |
---|
77 | * The user environment root and current directory are statically initialized |
---|
78 | * with the null location. Due to that all file system services are in a |
---|
79 | * defined state even if no root file system was mounted. |
---|
80 | */ |
---|
81 | extern rtems_filesystem_global_location_t rtems_filesystem_global_location_null; |
---|
82 | |
---|
83 | /* |
---|
84 | * rtems_libio_iop |
---|
85 | * |
---|
86 | * Macro to return the file descriptor pointer. |
---|
87 | */ |
---|
88 | |
---|
89 | #define rtems_libio_iop(_fd) \ |
---|
90 | ((((uint32_t)(_fd)) < rtems_libio_number_iops) ? \ |
---|
91 | &rtems_libio_iops[_fd] : 0) |
---|
92 | |
---|
93 | /* |
---|
94 | * rtems_libio_iop_to_descriptor |
---|
95 | * |
---|
96 | * Macro to convert an internal file descriptor pointer (iop) into |
---|
97 | * the integer file descriptor used by the "section 2" system calls. |
---|
98 | */ |
---|
99 | |
---|
100 | #define rtems_libio_iop_to_descriptor(_iop) \ |
---|
101 | ((!(_iop)) ? -1 : (_iop - rtems_libio_iops)) |
---|
102 | |
---|
103 | /* |
---|
104 | * rtems_libio_check_is_open |
---|
105 | * |
---|
106 | * Macro to check if a file descriptor is actually open. |
---|
107 | */ |
---|
108 | |
---|
109 | #define rtems_libio_check_is_open(_iop) \ |
---|
110 | do { \ |
---|
111 | if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \ |
---|
112 | errno = EBADF; \ |
---|
113 | return -1; \ |
---|
114 | } \ |
---|
115 | } while (0) |
---|
116 | |
---|
117 | /* |
---|
118 | * rtems_libio_check_fd |
---|
119 | * |
---|
120 | * Macro to check if a file descriptor number is valid. |
---|
121 | */ |
---|
122 | |
---|
123 | #define rtems_libio_check_fd(_fd) \ |
---|
124 | do { \ |
---|
125 | if ((uint32_t) (_fd) >= rtems_libio_number_iops) { \ |
---|
126 | errno = EBADF; \ |
---|
127 | return -1; \ |
---|
128 | } \ |
---|
129 | } while (0) |
---|
130 | |
---|
131 | /* |
---|
132 | * rtems_libio_check_buffer |
---|
133 | * |
---|
134 | * Macro to check if a buffer pointer is valid. |
---|
135 | */ |
---|
136 | |
---|
137 | #define rtems_libio_check_buffer(_buffer) \ |
---|
138 | do { \ |
---|
139 | if ((_buffer) == 0) { \ |
---|
140 | errno = EINVAL; \ |
---|
141 | return -1; \ |
---|
142 | } \ |
---|
143 | } while (0) |
---|
144 | |
---|
145 | /* |
---|
146 | * rtems_libio_check_count |
---|
147 | * |
---|
148 | * Macro to check if a count or length is valid. |
---|
149 | */ |
---|
150 | |
---|
151 | #define rtems_libio_check_count(_count) \ |
---|
152 | do { \ |
---|
153 | if ((_count) == 0) { \ |
---|
154 | return 0; \ |
---|
155 | } \ |
---|
156 | } while (0) |
---|
157 | |
---|
158 | /* |
---|
159 | * rtems_libio_check_permissions_with_error |
---|
160 | * |
---|
161 | * Macro to check if a file descriptor is open for this operation. |
---|
162 | * On failure, return the user specified error. |
---|
163 | */ |
---|
164 | |
---|
165 | #define rtems_libio_check_permissions_with_error(_iop, _flag, _errno) \ |
---|
166 | do { \ |
---|
167 | if (((_iop)->flags & (_flag)) == 0) { \ |
---|
168 | rtems_set_errno_and_return_minus_one( _errno ); \ |
---|
169 | return -1; \ |
---|
170 | } \ |
---|
171 | } while (0) |
---|
172 | |
---|
173 | /* |
---|
174 | * rtems_libio_check_permissions |
---|
175 | * |
---|
176 | * Macro to check if a file descriptor is open for this operation. |
---|
177 | * On failure, return EINVAL |
---|
178 | */ |
---|
179 | |
---|
180 | #define rtems_libio_check_permissions(_iop, _flag) \ |
---|
181 | rtems_libio_check_permissions_with_error(_iop, _flag, EINVAL ) |
---|
182 | |
---|
183 | /** |
---|
184 | * @brief Clones a node. |
---|
185 | * |
---|
186 | * The caller must hold the file system instance lock. |
---|
187 | * |
---|
188 | * @param[out] clone The cloned location. |
---|
189 | * @param[in] master The master location. |
---|
190 | * |
---|
191 | * @see rtems_filesystem_instance_lock(). |
---|
192 | */ |
---|
193 | void rtems_filesystem_location_clone( |
---|
194 | rtems_filesystem_location_info_t *clone, |
---|
195 | const rtems_filesystem_location_info_t *master |
---|
196 | ); |
---|
197 | |
---|
198 | /** |
---|
199 | * @brief Returns the type of a node. |
---|
200 | * |
---|
201 | * This function obtains and releases the file system instance lock. |
---|
202 | * |
---|
203 | * @param[in] loc The location of the node. |
---|
204 | * |
---|
205 | * @retval type The node type. |
---|
206 | * |
---|
207 | * @see rtems_filesystem_instance_lock(). |
---|
208 | */ |
---|
209 | rtems_filesystem_node_types_t rtems_filesystem_node_type( |
---|
210 | const rtems_filesystem_location_info_t *loc |
---|
211 | ); |
---|
212 | |
---|
213 | /** |
---|
214 | * @brief Releases all resources of a location. |
---|
215 | * |
---|
216 | * This function may block on a mutex and may complete an unmount process. |
---|
217 | * |
---|
218 | * @param[in] loc The location to free. |
---|
219 | * |
---|
220 | * @note The file system root location is released by the file system |
---|
221 | * instance destruction handler (see @ref rtems_filesystem_fsunmount_me_t). |
---|
222 | * |
---|
223 | * @see rtems_filesystem_freenode_t. |
---|
224 | */ |
---|
225 | void rtems_filesystem_location_free( rtems_filesystem_location_info_t *loc ); |
---|
226 | |
---|
227 | /* |
---|
228 | * External structures |
---|
229 | */ |
---|
230 | #include <rtems/userenv.h> |
---|
231 | |
---|
232 | static inline void rtems_libio_lock( void ) |
---|
233 | { |
---|
234 | rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
---|
235 | } |
---|
236 | |
---|
237 | static inline void rtems_libio_unlock( void ) |
---|
238 | { |
---|
239 | rtems_semaphore_release( rtems_libio_semaphore ); |
---|
240 | } |
---|
241 | |
---|
242 | static inline void rtems_filesystem_mt_lock( void ) |
---|
243 | { |
---|
244 | rtems_libio_lock(); |
---|
245 | } |
---|
246 | |
---|
247 | static inline void rtems_filesystem_mt_unlock( void ) |
---|
248 | { |
---|
249 | rtems_libio_unlock(); |
---|
250 | } |
---|
251 | |
---|
252 | extern rtems_interrupt_lock rtems_filesystem_mt_entry_lock_control; |
---|
253 | |
---|
254 | #define rtems_filesystem_mt_entry_declare_lock_context( ctx ) \ |
---|
255 | rtems_interrupt_level ctx |
---|
256 | |
---|
257 | #define rtems_filesystem_mt_entry_lock( ctx ) \ |
---|
258 | rtems_interrupt_lock_acquire( &rtems_filesystem_mt_entry_lock_control, ctx ) |
---|
259 | |
---|
260 | #define rtems_filesystem_mt_entry_unlock( ctx ) \ |
---|
261 | rtems_interrupt_lock_release( &rtems_filesystem_mt_entry_lock_control, ctx ) |
---|
262 | |
---|
263 | static inline void rtems_filesystem_instance_lock( |
---|
264 | const rtems_filesystem_location_info_t *loc |
---|
265 | ) |
---|
266 | { |
---|
267 | const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry; |
---|
268 | |
---|
269 | (*mt_entry->ops->lock_h)( mt_entry ); |
---|
270 | } |
---|
271 | |
---|
272 | static inline void rtems_filesystem_instance_unlock( |
---|
273 | const rtems_filesystem_location_info_t *loc |
---|
274 | ) |
---|
275 | { |
---|
276 | const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry; |
---|
277 | |
---|
278 | (*mt_entry->ops->unlock_h)( mt_entry ); |
---|
279 | } |
---|
280 | |
---|
281 | /* |
---|
282 | * File Descriptor Routine Prototypes |
---|
283 | */ |
---|
284 | |
---|
285 | /** |
---|
286 | * This routine searches the IOP Table for an unused entry. If it |
---|
287 | * finds one, it returns it. Otherwise, it returns NULL. |
---|
288 | */ |
---|
289 | rtems_libio_t *rtems_libio_allocate(void); |
---|
290 | |
---|
291 | /** |
---|
292 | * Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand |
---|
293 | */ |
---|
294 | uint32_t rtems_libio_fcntl_flags( int fcntl_flags ); |
---|
295 | |
---|
296 | /** |
---|
297 | * Convert RTEMS internal flags to UNIX fnctl(2) flags |
---|
298 | */ |
---|
299 | int rtems_libio_to_fcntl_flags( uint32_t flags ); |
---|
300 | |
---|
301 | /** |
---|
302 | * This routine frees the resources associated with an IOP (file descriptor) |
---|
303 | * and clears the slot in the IOP Table. |
---|
304 | */ |
---|
305 | void rtems_libio_free( |
---|
306 | rtems_libio_t *iop |
---|
307 | ); |
---|
308 | |
---|
309 | /* |
---|
310 | * File System Routine Prototypes |
---|
311 | */ |
---|
312 | |
---|
313 | rtems_filesystem_location_info_t * |
---|
314 | rtems_filesystem_eval_path_start( |
---|
315 | rtems_filesystem_eval_path_context_t *ctx, |
---|
316 | const char *path, |
---|
317 | int eval_flags |
---|
318 | ); |
---|
319 | |
---|
320 | rtems_filesystem_location_info_t * |
---|
321 | rtems_filesystem_eval_path_start_with_parent( |
---|
322 | rtems_filesystem_eval_path_context_t *ctx, |
---|
323 | const char *path, |
---|
324 | int eval_flags, |
---|
325 | rtems_filesystem_location_info_t *parentloc, |
---|
326 | int parent_eval_flags |
---|
327 | ); |
---|
328 | |
---|
329 | rtems_filesystem_location_info_t * |
---|
330 | rtems_filesystem_eval_path_start_with_root_and_current( |
---|
331 | rtems_filesystem_eval_path_context_t *ctx, |
---|
332 | const char *path, |
---|
333 | int eval_flags, |
---|
334 | rtems_filesystem_global_location_t *const *global_root_ptr, |
---|
335 | rtems_filesystem_global_location_t *const *global_current_ptr |
---|
336 | ); |
---|
337 | |
---|
338 | void rtems_filesystem_eval_path_continue( |
---|
339 | rtems_filesystem_eval_path_context_t *ctx |
---|
340 | ); |
---|
341 | |
---|
342 | void rtems_filesystem_eval_path_cleanup( |
---|
343 | rtems_filesystem_eval_path_context_t *ctx |
---|
344 | ); |
---|
345 | |
---|
346 | void rtems_filesystem_eval_path_recursive( |
---|
347 | rtems_filesystem_eval_path_context_t *ctx, |
---|
348 | const char *path, |
---|
349 | size_t pathlen |
---|
350 | ); |
---|
351 | |
---|
352 | void rtems_filesystem_eval_path_cleanup_with_parent( |
---|
353 | rtems_filesystem_eval_path_context_t *ctx, |
---|
354 | rtems_filesystem_location_info_t *parentloc |
---|
355 | ); |
---|
356 | |
---|
357 | /** |
---|
358 | * @brief Requests a path evaluation restart. |
---|
359 | * |
---|
360 | * Sets the start and current location to the new start location. The caller |
---|
361 | * must terminate its current evaluation process. The path evaluation |
---|
362 | * continues in the next loop iteration within |
---|
363 | * rtems_filesystem_eval_path_continue(). This avoids recursive invokations. |
---|
364 | * The function obtains the new start location and clones it to set the new |
---|
365 | * current location. The previous start and current locations are released. |
---|
366 | * |
---|
367 | * @param[in, out] ctx The path evaluation context. |
---|
368 | * @param[in, out] newstartloc_ptr Pointer to the new start location. |
---|
369 | */ |
---|
370 | void rtems_filesystem_eval_path_restart( |
---|
371 | rtems_filesystem_eval_path_context_t *ctx, |
---|
372 | rtems_filesystem_global_location_t **newstartloc_ptr |
---|
373 | ); |
---|
374 | |
---|
375 | typedef enum { |
---|
376 | RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE, |
---|
377 | RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE, |
---|
378 | RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY |
---|
379 | } rtems_filesystem_eval_path_generic_status; |
---|
380 | |
---|
381 | /** |
---|
382 | * @brief Tests if the current location is a directory. |
---|
383 | * |
---|
384 | * @param[in, out] ctx The path evaluation context. |
---|
385 | * @param[in, out] arg The handler argument. |
---|
386 | * |
---|
387 | * @retval true The current location is a directory. |
---|
388 | * @retval false Otherwise. |
---|
389 | * |
---|
390 | * @see rtems_filesystem_eval_path_generic(). |
---|
391 | */ |
---|
392 | typedef bool (*rtems_filesystem_eval_path_is_directory)( |
---|
393 | rtems_filesystem_eval_path_context_t *ctx, |
---|
394 | void *arg |
---|
395 | ); |
---|
396 | |
---|
397 | /** |
---|
398 | * @brief Evaluates a token. |
---|
399 | * |
---|
400 | * @param[in, out] ctx The path evaluation context. |
---|
401 | * @param[in, out] arg The handler argument. |
---|
402 | * @param[in] token The token contents. |
---|
403 | * @param[in] tokenlen The token length in characters. |
---|
404 | * |
---|
405 | * @retval status The generic path evaluation status. |
---|
406 | * |
---|
407 | * @see rtems_filesystem_eval_path_generic(). |
---|
408 | */ |
---|
409 | typedef rtems_filesystem_eval_path_generic_status |
---|
410 | (*rtems_filesystem_eval_path_eval_token)( |
---|
411 | rtems_filesystem_eval_path_context_t *ctx, |
---|
412 | void *arg, |
---|
413 | const char *token, |
---|
414 | size_t tokenlen |
---|
415 | ); |
---|
416 | |
---|
417 | typedef struct { |
---|
418 | rtems_filesystem_eval_path_is_directory is_directory; |
---|
419 | rtems_filesystem_eval_path_eval_token eval_token; |
---|
420 | } rtems_filesystem_eval_path_generic_config; |
---|
421 | |
---|
422 | void rtems_filesystem_eval_path_generic( |
---|
423 | rtems_filesystem_eval_path_context_t *ctx, |
---|
424 | void *arg, |
---|
425 | const rtems_filesystem_eval_path_generic_config *config |
---|
426 | ); |
---|
427 | |
---|
428 | void rtems_filesystem_initialize(void); |
---|
429 | |
---|
430 | /** |
---|
431 | * @brief Copies a location. |
---|
432 | * |
---|
433 | * A bitwise copy is performed. The destination location will be added to the |
---|
434 | * corresponding mount entry. |
---|
435 | * |
---|
436 | * @param[out] dst The destination location. |
---|
437 | * @param[in] src The source location. |
---|
438 | * |
---|
439 | * @retval dst The destination location. |
---|
440 | * |
---|
441 | * @see rtems_filesystem_location_clone(). |
---|
442 | */ |
---|
443 | rtems_filesystem_location_info_t *rtems_filesystem_location_copy( |
---|
444 | rtems_filesystem_location_info_t *dst, |
---|
445 | const rtems_filesystem_location_info_t *src |
---|
446 | ); |
---|
447 | |
---|
448 | static inline rtems_filesystem_location_info_t * |
---|
449 | rtems_filesystem_location_initialize_to_null( |
---|
450 | rtems_filesystem_location_info_t *loc |
---|
451 | ) |
---|
452 | { |
---|
453 | return rtems_filesystem_location_copy( |
---|
454 | loc, |
---|
455 | &rtems_filesystem_global_location_null.location |
---|
456 | ); |
---|
457 | } |
---|
458 | |
---|
459 | rtems_filesystem_global_location_t * |
---|
460 | rtems_filesystem_location_transform_to_global( |
---|
461 | rtems_filesystem_location_info_t *loc |
---|
462 | ); |
---|
463 | |
---|
464 | /** |
---|
465 | * @brief Assigns a global file system location. |
---|
466 | * |
---|
467 | * @param[in, out] lhs_global_loc_ptr Pointer to the global left hand side file |
---|
468 | * system location. The current left hand side location will be released. |
---|
469 | * @param[in] rhs_global_loc The global right hand side file system location. |
---|
470 | */ |
---|
471 | void rtems_filesystem_global_location_assign( |
---|
472 | rtems_filesystem_global_location_t **lhs_global_loc_ptr, |
---|
473 | rtems_filesystem_global_location_t *rhs_global_loc |
---|
474 | ); |
---|
475 | |
---|
476 | /** |
---|
477 | * @brief Obtains a global file system location. |
---|
478 | * |
---|
479 | * Deferred releases will be processed in this function. |
---|
480 | * |
---|
481 | * This function must be called from normal thread context and may block on a |
---|
482 | * mutex. Thread dispatching is disabled to protect some critical sections. |
---|
483 | * |
---|
484 | * @param[in] global_loc_ptr Pointer to the global file system location. |
---|
485 | * |
---|
486 | * @return A global file system location. It returns always a valid object. |
---|
487 | * In case of an error, the global null location will be returned. Each |
---|
488 | * operation or handler of the null location returns an error status. The |
---|
489 | * errno indicates the error. The NULL pointer is never returned. |
---|
490 | * |
---|
491 | * @see rtems_filesystem_location_transform_to_global(), |
---|
492 | * rtems_filesystem_global_location_obtain_null(), and |
---|
493 | * rtems_filesystem_global_location_release(). |
---|
494 | */ |
---|
495 | rtems_filesystem_global_location_t *rtems_filesystem_global_location_obtain( |
---|
496 | rtems_filesystem_global_location_t *const *global_loc_ptr |
---|
497 | ); |
---|
498 | |
---|
499 | /** |
---|
500 | * @brief Releases a global file system location. |
---|
501 | * |
---|
502 | * In case the reference count reaches zero, all associated resources will be |
---|
503 | * released. This may include the complete unmount of the corresponding file |
---|
504 | * system instance. |
---|
505 | * |
---|
506 | * This function may block on a mutex. It may be called within critical |
---|
507 | * sections of the operating system. In this case the release will be |
---|
508 | * deferred. The next obtain call will do the actual release. |
---|
509 | * |
---|
510 | * @param[in] global_loc The global file system location. It must not be NULL. |
---|
511 | * |
---|
512 | * @see rtems_filesystem_global_location_obtain(). |
---|
513 | */ |
---|
514 | void rtems_filesystem_global_location_release( |
---|
515 | rtems_filesystem_global_location_t *global_loc |
---|
516 | ); |
---|
517 | |
---|
518 | void rtems_filesystem_location_detach( |
---|
519 | rtems_filesystem_location_info_t *detach |
---|
520 | ); |
---|
521 | |
---|
522 | void rtems_filesystem_location_copy_and_detach( |
---|
523 | rtems_filesystem_location_info_t *copy, |
---|
524 | rtems_filesystem_location_info_t *detach |
---|
525 | ); |
---|
526 | |
---|
527 | static inline rtems_filesystem_global_location_t * |
---|
528 | rtems_filesystem_global_location_obtain_null(void) |
---|
529 | { |
---|
530 | rtems_filesystem_global_location_t *global_loc = NULL; |
---|
531 | |
---|
532 | return rtems_filesystem_global_location_obtain( &global_loc ); |
---|
533 | } |
---|
534 | |
---|
535 | static inline bool rtems_filesystem_location_is_null( |
---|
536 | const rtems_filesystem_location_info_t *loc |
---|
537 | ) |
---|
538 | { |
---|
539 | return loc->handlers == &rtems_filesystem_null_handlers; |
---|
540 | } |
---|
541 | |
---|
542 | static inline bool rtems_filesystem_global_location_is_null( |
---|
543 | const rtems_filesystem_global_location_t *global_loc |
---|
544 | ) |
---|
545 | { |
---|
546 | return rtems_filesystem_location_is_null( &global_loc->location ); |
---|
547 | } |
---|
548 | |
---|
549 | static inline void rtems_filesystem_location_error( |
---|
550 | const rtems_filesystem_location_info_t *loc, |
---|
551 | int eno |
---|
552 | ) |
---|
553 | { |
---|
554 | if ( !rtems_filesystem_location_is_null( loc ) ) { |
---|
555 | errno = eno; |
---|
556 | } |
---|
557 | } |
---|
558 | |
---|
559 | int rtems_filesystem_mknod( |
---|
560 | const rtems_filesystem_location_info_t *parentloc, |
---|
561 | const char *name, |
---|
562 | size_t namelen, |
---|
563 | mode_t mode, |
---|
564 | dev_t dev |
---|
565 | ); |
---|
566 | |
---|
567 | int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc ); |
---|
568 | |
---|
569 | int rtems_filesystem_chown( |
---|
570 | const char *path, |
---|
571 | uid_t owner, |
---|
572 | gid_t group, |
---|
573 | int eval_follow_link |
---|
574 | ); |
---|
575 | |
---|
576 | static inline bool rtems_filesystem_is_ready_for_unmount( |
---|
577 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
578 | ) |
---|
579 | { |
---|
580 | bool ready = !mt_entry->mounted |
---|
581 | && rtems_chain_has_only_one_node( &mt_entry->location_chain ) |
---|
582 | && mt_entry->mt_fs_root->reference_count == 1; |
---|
583 | |
---|
584 | if ( ready ) { |
---|
585 | rtems_chain_initialize_empty( &mt_entry->location_chain ); |
---|
586 | } |
---|
587 | |
---|
588 | return ready; |
---|
589 | } |
---|
590 | |
---|
591 | static inline void rtems_filesystem_location_add_to_mt_entry( |
---|
592 | rtems_filesystem_location_info_t *loc |
---|
593 | ) |
---|
594 | { |
---|
595 | rtems_filesystem_mt_entry_declare_lock_context( lock_context ); |
---|
596 | |
---|
597 | rtems_filesystem_mt_entry_lock( lock_context ); |
---|
598 | rtems_chain_append_unprotected( |
---|
599 | &loc->mt_entry->location_chain, |
---|
600 | &loc->mt_entry_node |
---|
601 | ); |
---|
602 | rtems_filesystem_mt_entry_unlock( lock_context ); |
---|
603 | } |
---|
604 | |
---|
605 | void rtems_filesystem_location_remove_from_mt_entry( |
---|
606 | rtems_filesystem_location_info_t *loc |
---|
607 | ); |
---|
608 | |
---|
609 | void rtems_filesystem_do_unmount( |
---|
610 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
611 | ); |
---|
612 | |
---|
613 | static inline bool rtems_filesystem_location_is_instance_root( |
---|
614 | const rtems_filesystem_location_info_t *loc |
---|
615 | ) |
---|
616 | { |
---|
617 | const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry; |
---|
618 | |
---|
619 | return (*mt_entry->ops->are_nodes_equal_h)( |
---|
620 | loc, |
---|
621 | &mt_entry->mt_fs_root->location |
---|
622 | ); |
---|
623 | } |
---|
624 | |
---|
625 | static inline const char *rtems_filesystem_eval_path_get_path( |
---|
626 | rtems_filesystem_eval_path_context_t *ctx |
---|
627 | ) |
---|
628 | { |
---|
629 | return ctx->path; |
---|
630 | } |
---|
631 | |
---|
632 | static inline size_t rtems_filesystem_eval_path_get_pathlen( |
---|
633 | rtems_filesystem_eval_path_context_t *ctx |
---|
634 | ) |
---|
635 | { |
---|
636 | return ctx->pathlen; |
---|
637 | } |
---|
638 | |
---|
639 | static inline void rtems_filesystem_eval_path_set_path( |
---|
640 | rtems_filesystem_eval_path_context_t *ctx, |
---|
641 | const char *path, |
---|
642 | size_t pathlen |
---|
643 | ) |
---|
644 | { |
---|
645 | ctx->path = path; |
---|
646 | ctx->pathlen = pathlen; |
---|
647 | } |
---|
648 | |
---|
649 | static inline void rtems_filesystem_eval_path_clear_path( |
---|
650 | rtems_filesystem_eval_path_context_t *ctx |
---|
651 | ) |
---|
652 | { |
---|
653 | ctx->pathlen = 0; |
---|
654 | } |
---|
655 | |
---|
656 | static inline const char *rtems_filesystem_eval_path_get_token( |
---|
657 | rtems_filesystem_eval_path_context_t *ctx |
---|
658 | ) |
---|
659 | { |
---|
660 | return ctx->token; |
---|
661 | } |
---|
662 | |
---|
663 | static inline size_t rtems_filesystem_eval_path_get_tokenlen( |
---|
664 | rtems_filesystem_eval_path_context_t *ctx |
---|
665 | ) |
---|
666 | { |
---|
667 | return ctx->tokenlen; |
---|
668 | } |
---|
669 | |
---|
670 | static inline void rtems_filesystem_eval_path_set_token( |
---|
671 | rtems_filesystem_eval_path_context_t *ctx, |
---|
672 | const char *token, |
---|
673 | size_t tokenlen |
---|
674 | ) |
---|
675 | { |
---|
676 | ctx->token = token; |
---|
677 | ctx->tokenlen = tokenlen; |
---|
678 | } |
---|
679 | |
---|
680 | static inline void rtems_filesystem_eval_path_clear_token( |
---|
681 | rtems_filesystem_eval_path_context_t *ctx |
---|
682 | ) |
---|
683 | { |
---|
684 | ctx->tokenlen = 0; |
---|
685 | } |
---|
686 | |
---|
687 | static inline void rtems_filesystem_eval_path_put_back_token( |
---|
688 | rtems_filesystem_eval_path_context_t *ctx |
---|
689 | ) |
---|
690 | { |
---|
691 | size_t tokenlen = ctx->tokenlen; |
---|
692 | |
---|
693 | ctx->path -= tokenlen; |
---|
694 | ctx->pathlen += tokenlen; |
---|
695 | ctx->tokenlen = 0; |
---|
696 | } |
---|
697 | |
---|
698 | void rtems_filesystem_eval_path_eat_delimiter( |
---|
699 | rtems_filesystem_eval_path_context_t *ctx |
---|
700 | ); |
---|
701 | |
---|
702 | void rtems_filesystem_eval_path_next_token( |
---|
703 | rtems_filesystem_eval_path_context_t *ctx |
---|
704 | ); |
---|
705 | |
---|
706 | static inline void rtems_filesystem_eval_path_get_next_token( |
---|
707 | rtems_filesystem_eval_path_context_t *ctx, |
---|
708 | const char **token, |
---|
709 | size_t *tokenlen |
---|
710 | ) |
---|
711 | { |
---|
712 | rtems_filesystem_eval_path_next_token(ctx); |
---|
713 | *token = ctx->token; |
---|
714 | *tokenlen = ctx->tokenlen; |
---|
715 | } |
---|
716 | |
---|
717 | static inline rtems_filesystem_location_info_t * |
---|
718 | rtems_filesystem_eval_path_get_currentloc( |
---|
719 | rtems_filesystem_eval_path_context_t *ctx |
---|
720 | ) |
---|
721 | { |
---|
722 | return &ctx->currentloc; |
---|
723 | } |
---|
724 | |
---|
725 | static inline bool rtems_filesystem_eval_path_has_path( |
---|
726 | const rtems_filesystem_eval_path_context_t *ctx |
---|
727 | ) |
---|
728 | { |
---|
729 | return ctx->pathlen > 0; |
---|
730 | } |
---|
731 | |
---|
732 | static inline bool rtems_filesystem_eval_path_has_token( |
---|
733 | const rtems_filesystem_eval_path_context_t *ctx |
---|
734 | ) |
---|
735 | { |
---|
736 | return ctx->tokenlen > 0; |
---|
737 | } |
---|
738 | |
---|
739 | static inline int rtems_filesystem_eval_path_get_flags( |
---|
740 | const rtems_filesystem_eval_path_context_t *ctx |
---|
741 | ) |
---|
742 | { |
---|
743 | return ctx->flags; |
---|
744 | } |
---|
745 | |
---|
746 | static inline void rtems_filesystem_eval_path_set_flags( |
---|
747 | rtems_filesystem_eval_path_context_t *ctx, |
---|
748 | int flags |
---|
749 | ) |
---|
750 | { |
---|
751 | ctx->flags = flags; |
---|
752 | } |
---|
753 | |
---|
754 | static inline void rtems_filesystem_eval_path_clear_and_set_flags( |
---|
755 | rtems_filesystem_eval_path_context_t *ctx, |
---|
756 | int clear, |
---|
757 | int set |
---|
758 | ) |
---|
759 | { |
---|
760 | int flags = ctx->flags; |
---|
761 | |
---|
762 | flags &= ~clear; |
---|
763 | flags |= set; |
---|
764 | |
---|
765 | ctx->flags = flags; |
---|
766 | } |
---|
767 | |
---|
768 | static inline void rtems_filesystem_eval_path_extract_currentloc( |
---|
769 | rtems_filesystem_eval_path_context_t *ctx, |
---|
770 | rtems_filesystem_location_info_t *get |
---|
771 | ) |
---|
772 | { |
---|
773 | rtems_filesystem_location_copy_and_detach( |
---|
774 | get, |
---|
775 | &ctx->currentloc |
---|
776 | ); |
---|
777 | } |
---|
778 | |
---|
779 | void rtems_filesystem_eval_path_error( |
---|
780 | rtems_filesystem_eval_path_context_t *ctx, |
---|
781 | int eno |
---|
782 | ); |
---|
783 | |
---|
784 | /** |
---|
785 | * @brief Checks that the locations exist in the same file system instance. |
---|
786 | * |
---|
787 | * @retval 0 The locations exist and are in the same file system instance. |
---|
788 | * @retval -1 An error occurred. The @c errno indicates the error. |
---|
789 | */ |
---|
790 | int rtems_filesystem_location_exists_in_same_instance_as( |
---|
791 | const rtems_filesystem_location_info_t *a, |
---|
792 | const rtems_filesystem_location_info_t *b |
---|
793 | ); |
---|
794 | |
---|
795 | bool rtems_filesystem_check_access( |
---|
796 | int eval_flags, |
---|
797 | mode_t node_mode, |
---|
798 | uid_t node_uid, |
---|
799 | gid_t node_gid |
---|
800 | ); |
---|
801 | |
---|
802 | bool rtems_filesystem_eval_path_check_access( |
---|
803 | rtems_filesystem_eval_path_context_t *ctx, |
---|
804 | int eval_flags, |
---|
805 | mode_t node_mode, |
---|
806 | uid_t node_uid, |
---|
807 | gid_t node_gid |
---|
808 | ); |
---|
809 | |
---|
810 | static inline bool rtems_filesystem_is_delimiter(char c) |
---|
811 | { |
---|
812 | return c == '/' || c == '\\'; |
---|
813 | } |
---|
814 | |
---|
815 | static inline bool rtems_filesystem_is_current_directory( |
---|
816 | const char *token, |
---|
817 | size_t tokenlen |
---|
818 | ) |
---|
819 | { |
---|
820 | return tokenlen == 1 && token [0] == '.'; |
---|
821 | } |
---|
822 | |
---|
823 | static inline bool rtems_filesystem_is_parent_directory( |
---|
824 | const char *token, |
---|
825 | size_t tokenlen |
---|
826 | ) |
---|
827 | { |
---|
828 | return tokenlen == 2 && token [0] == '.' && token [1] == '.'; |
---|
829 | } |
---|
830 | |
---|
831 | /** @} */ |
---|
832 | |
---|
833 | #ifdef __cplusplus |
---|
834 | } |
---|
835 | #endif |
---|
836 | |
---|
837 | #endif |
---|
838 | /* end of include file */ |
---|