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