source: rtems/cpukit/libfs/src/devfs/devfs_eval.c @ 339069fc

5
Last change on this file since 339069fc was 339069fc, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 13, 2017 at 7:02:09 AM

devfs: Include <rtems/devfs.h>

Prepare for header file move to common include directory.

Update #3254.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Evaluate Patch
5 * @ingroup DevFsDeviceTable Define Device Table Type
6 */
7
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.org/license/LICENSE.
12 */
13
14#if HAVE_CONFIG_H
15  #include "config.h"
16#endif
17
18#include <string.h>
19
20#include <rtems/devfs.h>
21
22static devFS_node *devFS_search_node(
23  const devFS_data *data,
24  const char *path,
25  size_t pathlen,
26  devFS_node **free_node_ptr
27)
28{
29  size_t i = 0;
30  size_t n = data->count;
31  devFS_node *nodes = data->nodes;
32  devFS_node *node = NULL;
33  devFS_node *free_node = NULL;
34
35  for (i = 0; (free_node == NULL || node == NULL) && i < n; ++i) {
36    devFS_node *current = nodes + i;
37
38    if (current->name != NULL) {
39      if (
40        current->namelen == pathlen
41          && memcmp(current->name, path, pathlen) == 0
42      ) {
43        node = current;
44      }
45    } else {
46      free_node = current;
47    }
48  }
49
50  *free_node_ptr = free_node;
51
52  return node;
53}
54
55void devFS_eval_path(
56  rtems_filesystem_eval_path_context_t *ctx
57)
58{
59  rtems_filesystem_location_info_t *currentloc =
60    rtems_filesystem_eval_path_get_currentloc(ctx);
61  devFS_node *free_node;
62  devFS_node *node = devFS_search_node(
63    devFS_get_data(currentloc),
64    rtems_filesystem_eval_path_get_path(ctx),
65    rtems_filesystem_eval_path_get_pathlen(ctx),
66    &free_node
67  );
68  int eval_flags = rtems_filesystem_eval_path_get_flags(ctx);
69
70  if (node != NULL) {
71    if ((eval_flags & RTEMS_FS_EXCLUSIVE) == 0) {
72      currentloc->node_access = node;
73      rtems_filesystem_eval_path_clear_path(ctx);
74    } else {
75      rtems_filesystem_eval_path_error(ctx, EEXIST);
76    }
77  } else {
78    if ((eval_flags & RTEMS_FS_MAKE) != 0) {
79      if (free_node != NULL) {
80        free_node->mode = S_IRWXU | S_IRWXG | S_IRWXO;
81        currentloc->node_access = free_node;
82        rtems_filesystem_eval_path_set_token(
83          ctx,
84          rtems_filesystem_eval_path_get_path(ctx),
85          rtems_filesystem_eval_path_get_pathlen(ctx)
86        );
87        rtems_filesystem_eval_path_clear_path(ctx);
88      } else {
89        rtems_filesystem_eval_path_error(ctx, ENOSPC);
90      }
91    } else {
92      rtems_filesystem_eval_path_error(ctx, ENOENT);
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.