[07a3253d] | 1 | /* |
---|
| 2 | * rtems_filesystem_evaluate_path() |
---|
| 3 | * |
---|
| 4 | * Routine to seed the evaluate path routine. |
---|
| 5 | * |
---|
[08311cc3] | 6 | * COPYRIGHT (c) 1989-1999. |
---|
[07a3253d] | 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
| 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
[8638d32b] | 11 | * http://www.rtems.com/license/LICENSE. |
---|
[07a3253d] | 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
[9c49db4] | 16 | #if HAVE_CONFIG_H |
---|
| 17 | #include "config.h" |
---|
| 18 | #endif |
---|
| 19 | |
---|
[07a3253d] | 20 | #include <rtems.h> |
---|
[3ba74c73] | 21 | #include <rtems/libio_.h> |
---|
[a02224e] | 22 | #include <rtems/seterr.h> |
---|
[07a3253d] | 23 | |
---|
| 24 | int rtems_filesystem_evaluate_path( |
---|
| 25 | const char *pathname, |
---|
| 26 | int flags, |
---|
| 27 | rtems_filesystem_location_info_t *pathloc, |
---|
| 28 | int follow_link |
---|
| 29 | ) |
---|
| 30 | { |
---|
| 31 | int i; |
---|
| 32 | int result; |
---|
| 33 | rtems_filesystem_node_types_t type; |
---|
| 34 | |
---|
| 35 | /* |
---|
| 36 | * Verify Input parameters. |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | if ( !pathname ) |
---|
[a02224e] | 40 | rtems_set_errno_and_return_minus_one( EFAULT ); |
---|
[07a3253d] | 41 | |
---|
| 42 | if ( !pathloc ) |
---|
[a02224e] | 43 | rtems_set_errno_and_return_minus_one( EIO ); /* should never happen */ |
---|
[07a3253d] | 44 | |
---|
| 45 | /* |
---|
| 46 | * Evaluate the path using the optable evalpath. |
---|
| 47 | */ |
---|
| 48 | |
---|
| 49 | rtems_filesystem_get_start_loc( pathname, &i, pathloc ); |
---|
| 50 | |
---|
[9c3fa30] | 51 | if ( !pathloc->ops->evalpath_h ) |
---|
[a02224e] | 52 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
[dd19c0b] | 53 | |
---|
[9c3fa30] | 54 | result = (*pathloc->ops->evalpath_h)( &pathname[i], flags, pathloc ); |
---|
[07a3253d] | 55 | |
---|
| 56 | /* |
---|
| 57 | * Get the Node type and determine if you need to follow the link or |
---|
| 58 | * not. |
---|
| 59 | */ |
---|
| 60 | |
---|
[0139484] | 61 | if ( (result == 0) && follow_link ) { |
---|
[07a3253d] | 62 | |
---|
[1d66629] | 63 | if ( !pathloc->ops->node_type_h ){ |
---|
| 64 | rtems_filesystem_freenode( pathloc ); |
---|
[a02224e] | 65 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
[1d66629] | 66 | } |
---|
[07a3253d] | 67 | |
---|
[9c3fa30] | 68 | type = (*pathloc->ops->node_type_h)( pathloc ); |
---|
[07a3253d] | 69 | |
---|
| 70 | if ( ( type == RTEMS_FILESYSTEM_HARD_LINK ) || |
---|
| 71 | ( type == RTEMS_FILESYSTEM_SYM_LINK ) ) { |
---|
| 72 | |
---|
[1d66629] | 73 | if ( !pathloc->ops->eval_link_h ){ |
---|
| 74 | rtems_filesystem_freenode( pathloc ); |
---|
[a02224e] | 75 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
[1d66629] | 76 | } |
---|
| 77 | |
---|
| 78 | /* what to do with the valid node pathloc points to |
---|
| 79 | * if eval_link_h fails? |
---|
| 80 | * Let the FS implementation deal with this case. It |
---|
| 81 | * should probably free pathloc in either case: |
---|
| 82 | * - if the link evaluation fails, it must free the |
---|
| 83 | * original (valid) pathloc because we are going |
---|
| 84 | * to return -1 and hence the FS generics won't |
---|
| 85 | * cleanup pathloc. |
---|
| 86 | * - if the link evaluation is successful, the updated |
---|
| 87 | * pathloc will be passed up (and eventually released). |
---|
| 88 | * Hence, the (valid) originial node that we submit to |
---|
| 89 | * eval_link_h() should be released by the handler. |
---|
| 90 | */ |
---|
| 91 | |
---|
| 92 | result = (*pathloc->ops->eval_link_h)( pathloc, flags ); |
---|
[07a3253d] | 93 | |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | return result; |
---|
| 98 | } |
---|
| 99 | |
---|
[86042ae9] | 100 | |
---|
| 101 | int rtems_filesystem_evaluate_parent( |
---|
| 102 | int flags, |
---|
| 103 | rtems_filesystem_location_info_t *pathloc |
---|
| 104 | ) |
---|
| 105 | { |
---|
| 106 | rtems_filesystem_location_info_t parent; |
---|
| 107 | int result; |
---|
| 108 | |
---|
| 109 | if ( !pathloc ) |
---|
| 110 | rtems_set_errno_and_return_minus_one( EIO ); /* should never happen */ |
---|
| 111 | |
---|
| 112 | if ( !pathloc->ops->evalpath_h ) |
---|
| 113 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
| 114 | |
---|
| 115 | parent = *pathloc; |
---|
| 116 | result = (*pathloc->ops->evalpath_h)( "..", flags, &parent ); |
---|
| 117 | if (result != 0){ |
---|
| 118 | return -1; |
---|
| 119 | } |
---|
| 120 | rtems_filesystem_freenode( &parent ); |
---|
| 121 | return result; |
---|
| 122 | } |
---|
| 123 | |
---|