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

4.104.115
Last change on this file since a794000d was a794000d, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/27/10 at 16:29:37

2010-05-27 Ralf Corsépius <ralf.corsepius@…>

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