source: rtems/cpukit/libcsupport/src/sup_fs_eval_path_generic.c @ 2563410

4.115
Last change on this file since 2563410 was 2563410, checked in by Sebastian Huber <sebastian.huber@…>, on 03/13/12 at 08:22:11

Filesystem: Rename defines

o Removed RTEMS_LIBIO_PERMS_SEARCH.
o Renamed RTEMS_LIBIO_PERMS_READ in RTEMS_FS_PERMS_READ.
o Renamed RTEMS_LIBIO_PERMS_WRITE in RTEMS_FS_PERMS_WRITE.
o Renamed RTEMS_LIBIO_PERMS_EXEC in RTEMS_FS_PERMS_EXEC.
o Renamed RTEMS_LIBIO_FOLLOW_HARD_LINK in RTEMS_FS_FOLLOW_HARD_LINK.
o Renamed RTEMS_LIBIO_FOLLOW_SYM_LINK in RTEMS_FS_FOLLOW_SYM_LINK.
o Renamed RTEMS_LIBIO_MAKE in RTEMS_FS_MAKE.
o Renamed RTEMS_LIBIO_EXCLUSIVE in RTEMS_FS_EXCLUSIVE.
o Renamed RTEMS_LIBIO_ACCEPT_RESIDUAL_DELIMITERS in

RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS.

o Renamed RTEMS_LIBIO_REJECT_TERMINAL_DOT in
RTEMS_FS_REJECT_TERMINAL_DOT.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/libio_.h>
20
21static bool is_fs_root( const rtems_filesystem_location_info_t *loc )
22{
23  const rtems_filesystem_location_info_t *mt_fs_root =
24    &loc->mt_entry->mt_fs_root->location;
25
26  return (*loc->ops->are_nodes_equal_h)( loc, mt_fs_root );
27}
28
29static bool is_eval_path_root(
30  const rtems_filesystem_eval_path_context_t *ctx,
31  const rtems_filesystem_location_info_t *loc
32)
33{
34  const rtems_filesystem_location_info_t *rootloc = &ctx->rootloc->location;
35
36  return loc->mt_entry == rootloc->mt_entry
37    && (*loc->ops->are_nodes_equal_h)( loc, rootloc );
38}
39
40void rtems_filesystem_eval_path_generic(
41  rtems_filesystem_eval_path_context_t *ctx,
42  void *arg,
43  const rtems_filesystem_eval_path_generic_config *config
44)
45{
46  rtems_filesystem_eval_path_generic_status status =
47    RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE;
48
49  while (status == RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE) {
50    const char *token;
51    size_t tokenlen;
52
53    rtems_filesystem_eval_path_get_next_token(ctx, &token, &tokenlen);
54
55    if (tokenlen > 0) {
56      if ((*config->is_directory)(ctx, arg)) {
57        if (rtems_filesystem_is_current_directory(token, tokenlen)) {
58          if (rtems_filesystem_eval_path_has_path(ctx)) {
59            status = (*config->eval_token)(ctx, arg, ".", 1);
60          } else {
61            int eval_flags = rtems_filesystem_eval_path_get_flags(ctx);
62
63            if ((eval_flags & RTEMS_FS_REJECT_TERMINAL_DOT) == 0) {
64              status = (*config->eval_token)(ctx, arg, ".", 1);
65            } else {
66              rtems_filesystem_eval_path_error(ctx, EINVAL);
67              status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE;
68            }
69          }
70        } else if (rtems_filesystem_is_parent_directory(token, tokenlen)) {
71          rtems_filesystem_location_info_t *currentloc =
72            rtems_filesystem_eval_path_get_currentloc( ctx );
73
74          if (is_eval_path_root(ctx, currentloc)) {
75            /* This prevents the escape from a chroot() environment */
76            status = (*config->eval_token)(ctx, arg, ".", 1);
77          } else if (is_fs_root(currentloc)) {
78            if (currentloc->mt_entry->mt_point_node != NULL) {
79              rtems_filesystem_eval_path_put_back_token(ctx);
80              rtems_filesystem_eval_path_restart(
81                ctx,
82                &currentloc->mt_entry->mt_point_node
83              );
84              status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE;
85            } else {
86              /* This is the root file system */
87              status = (*config->eval_token)(ctx, arg, ".", 1);
88            }
89          } else {
90            status = (*config->eval_token)(ctx, arg, "..", 2);
91          }
92        } else {
93          status = (*config->eval_token)(ctx, arg, token, tokenlen);
94        }
95
96        if (status == RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY) {
97          if (rtems_filesystem_eval_path_has_path(ctx)) {
98            int eval_flags;
99
100            rtems_filesystem_eval_path_eat_delimiter(ctx);
101            eval_flags = rtems_filesystem_eval_path_get_flags(ctx);
102            if (
103              (eval_flags & RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS) == 0
104                || rtems_filesystem_eval_path_has_path(ctx)
105            ) {
106              rtems_filesystem_eval_path_error(ctx, ENOENT);
107            }
108          }
109        }
110      } else {
111        rtems_filesystem_eval_path_error(ctx, ENOTDIR);
112        status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE;
113      }
114    } else {
115      status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE;
116    }
117  }
118}
Note: See TracBrowser for help on using the repository browser.