1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief IMFS Make a Generic Node |
---|
5 | * @ingroup IMFS |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
10 | * |
---|
11 | * embedded brains GmbH |
---|
12 | * Obere Lagerstr. 30 |
---|
13 | * 82178 Puchheim |
---|
14 | * Germany |
---|
15 | * <rtems@embedded-brains.de> |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * http://www.rtems.org/license/LICENSE. |
---|
20 | */ |
---|
21 | |
---|
22 | #if HAVE_CONFIG_H |
---|
23 | #include "config.h" |
---|
24 | #endif |
---|
25 | |
---|
26 | #include "imfs.h" |
---|
27 | |
---|
28 | #include <string.h> |
---|
29 | |
---|
30 | IMFS_jnode_t *IMFS_node_initialize_generic( |
---|
31 | IMFS_jnode_t *node, |
---|
32 | void *arg |
---|
33 | ) |
---|
34 | { |
---|
35 | IMFS_generic_t *generic = (IMFS_generic_t *) node; |
---|
36 | |
---|
37 | generic->context = arg; |
---|
38 | |
---|
39 | return node; |
---|
40 | } |
---|
41 | |
---|
42 | int IMFS_make_generic_node( |
---|
43 | const char *path, |
---|
44 | mode_t mode, |
---|
45 | const IMFS_node_control *node_control, |
---|
46 | void *context |
---|
47 | ) |
---|
48 | { |
---|
49 | int rv = 0; |
---|
50 | |
---|
51 | mode &= ~rtems_filesystem_umask; |
---|
52 | |
---|
53 | switch (mode & S_IFMT) { |
---|
54 | case S_IFBLK: |
---|
55 | case S_IFCHR: |
---|
56 | case S_IFIFO: |
---|
57 | case S_IFREG: |
---|
58 | case S_IFSOCK: |
---|
59 | break; |
---|
60 | default: |
---|
61 | errno = EINVAL; |
---|
62 | rv = -1; |
---|
63 | break; |
---|
64 | } |
---|
65 | |
---|
66 | if ( rv == 0 ) { |
---|
67 | rtems_filesystem_eval_path_context_t ctx; |
---|
68 | int eval_flags = RTEMS_FS_FOLLOW_LINK |
---|
69 | | RTEMS_FS_MAKE |
---|
70 | | RTEMS_FS_EXCLUSIVE; |
---|
71 | const rtems_filesystem_location_info_t *currentloc = |
---|
72 | rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); |
---|
73 | |
---|
74 | if ( IMFS_is_imfs_instance( currentloc ) ) { |
---|
75 | IMFS_jnode_t *new_node = IMFS_create_node( |
---|
76 | currentloc, |
---|
77 | node_control, |
---|
78 | sizeof( IMFS_generic_t ), |
---|
79 | rtems_filesystem_eval_path_get_token( &ctx ), |
---|
80 | rtems_filesystem_eval_path_get_tokenlen( &ctx ), |
---|
81 | mode, |
---|
82 | context |
---|
83 | ); |
---|
84 | |
---|
85 | if ( new_node != NULL ) { |
---|
86 | IMFS_jnode_t *parent = currentloc->node_access; |
---|
87 | |
---|
88 | IMFS_mtime_ctime_update( parent ); |
---|
89 | } else { |
---|
90 | rv = -1; |
---|
91 | } |
---|
92 | } else { |
---|
93 | rtems_filesystem_eval_path_error( &ctx, ENOTSUP ); |
---|
94 | rv = -1; |
---|
95 | } |
---|
96 | |
---|
97 | rtems_filesystem_eval_path_cleanup( &ctx ); |
---|
98 | } |
---|
99 | |
---|
100 | return rv; |
---|
101 | } |
---|