source: rtems/cpukit/libcsupport/src/eval.c @ 72755421

4.104.115
Last change on this file since 72755421 was 72755421, checked in by Chris Johns <chrisj@…>, on 06/12/09 at 02:59:18

2009-06-12 Chris Johns <chrisj@…>

  • libblock/include/rtems/flashdisk.h, libblock/include/rtems/nvdisk.h, libblock/src/flashdisk.c, libblock/src/nvdisk.c: Change names to match the RAM disk change.
  • libcsupport/src/eval.c: Remove some warnings.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  rtems_filesystem_evaluate_path()
3 *
4 *  Routine to seed the evaluate path routine.
5 *
6 *  COPYRIGHT (c) 1989-1999.
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
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems.h>
21#include <rtems/libio_.h>
22#include <rtems/seterr.h>
23
24int rtems_filesystem_evaluate_relative_path(
25  const char                        *pathname,
26  int                                pathnamelen,
27  int                                flags,
28  rtems_filesystem_location_info_t  *pathloc,
29  int                                follow_link
30)
31{
32  //int                           i;
33  int                           result;
34  rtems_filesystem_node_types_t type;
35
36  /*
37   * Verify Input parameters.
38   */
39
40  if ( !pathname )
41    rtems_set_errno_and_return_minus_one( EFAULT );
42
43  if ( !pathloc )
44    rtems_set_errno_and_return_minus_one( EIO );       /* should never happen */
45
46  if ( !pathloc->ops->evalpath_h )
47    rtems_set_errno_and_return_minus_one( ENOTSUP );
48
49  result = (*pathloc->ops->evalpath_h)( pathname, pathnamelen, flags, pathloc );
50
51  /*
52   * Get the Node type and determine if you need to follow the link or
53   * not.
54   */
55
56  if ( (result == 0) && follow_link ) {
57
58    if ( !pathloc->ops->node_type_h ){
59      rtems_filesystem_freenode( pathloc );
60      rtems_set_errno_and_return_minus_one( ENOTSUP );
61    }
62
63    type = (*pathloc->ops->node_type_h)( pathloc );
64
65    if ( ( type == RTEMS_FILESYSTEM_HARD_LINK ) ||
66         ( type == RTEMS_FILESYSTEM_SYM_LINK ) ) {
67
68        if ( !pathloc->ops->eval_link_h ){
69          rtems_filesystem_freenode( pathloc );
70          rtems_set_errno_and_return_minus_one( ENOTSUP );
71        }
72
73        /* what to do with the valid node pathloc points to
74         * if eval_link_h fails?
75         * Let the FS implementation deal with this case.  It
76         * should probably free pathloc in either case:
77         *  - if the link evaluation fails, it must free the
78         *    original (valid) pathloc because we are going
79         *    to return -1 and hence the FS generics won't
80         *    cleanup pathloc.
81         *  - if the link evaluation is successful, the updated
82         *    pathloc will be passed up (and eventually released).
83         *    Hence, the (valid) originial node that we submit to
84         *    eval_link_h() should be released by the handler.
85         */
86
87        result =  (*pathloc->ops->eval_link_h)( pathloc, flags );
88    }
89  }
90
91  return result;
92}
93
94int rtems_filesystem_evaluate_path(
95  const char                        *pathname,
96  int                                pathnamelen,
97  int                                flags,
98  rtems_filesystem_location_info_t  *pathloc,
99  int                                follow_link
100)
101{
102  int                           i = 0;
103
104  /*
105   * Verify Input parameters.
106   */
107
108  if ( !pathname )
109    rtems_set_errno_and_return_minus_one( EFAULT );
110
111  if ( !pathloc )
112    rtems_set_errno_and_return_minus_one( EIO );       /* should never happen */
113
114  /*
115   * Evaluate the path using the optable evalpath.
116   */
117
118  rtems_filesystem_get_start_loc( pathname, &i, pathloc );
119
120  /*
121   * We evaluation the path relative to the start location we get got.
122   */
123  return rtems_filesystem_evaluate_relative_path( &pathname[i],
124                                                  pathnamelen - i,
125                                                  flags,
126                                                  pathloc,
127                                                  follow_link );
128}
129
130int rtems_filesystem_dirname(
131  const char  *pathname
132)
133{
134  int len = strlen( pathname );
135
136  while ( len ) {
137    len--;
138    if ( rtems_filesystem_is_separator( pathname[len] ) )
139      break;
140  }
141
142  return len;
143}
144
145int rtems_filesystem_prefix_separators(
146  const char  *pathname,
147  int          pathnamelen
148)
149{
150  /*
151   * Eat any separators at start of the path.
152   */
153  int stripped = 0;
154  while ( *pathname && pathnamelen && rtems_filesystem_is_separator( *pathname ) )
155  {
156    pathname++;
157    pathnamelen--;
158    stripped++;
159  }
160  return stripped;
161}
Note: See TracBrowser for help on using the repository browser.