1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Create a IMFS Node |
---|
5 | * @ingroup IMFS |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2010. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * Modifications to support reference counting in the file system are |
---|
13 | * Copyright (c) 2012 embedded brains GmbH. |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <rtems/imfs.h> |
---|
25 | |
---|
26 | static const IMFS_mknod_control *get_control( |
---|
27 | const IMFS_mknod_controls *controls, |
---|
28 | mode_t mode |
---|
29 | ) |
---|
30 | { |
---|
31 | if ( S_ISDIR( mode ) ) { |
---|
32 | return controls->directory; |
---|
33 | } else if ( S_ISBLK( mode ) || S_ISCHR( mode ) ) { |
---|
34 | return controls->device; |
---|
35 | } else if ( S_ISFIFO( mode ) ) { |
---|
36 | return controls->fifo; |
---|
37 | } else { |
---|
38 | IMFS_assert( S_ISREG( mode ) ); |
---|
39 | return controls->file; |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | int IMFS_mknod( |
---|
44 | const rtems_filesystem_location_info_t *parentloc, |
---|
45 | const char *name, |
---|
46 | size_t namelen, |
---|
47 | mode_t mode, |
---|
48 | dev_t dev |
---|
49 | ) |
---|
50 | { |
---|
51 | int rv = 0; |
---|
52 | const IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info; |
---|
53 | const IMFS_mknod_control *mknod_control = |
---|
54 | get_control( fs_info->mknod_controls, mode ); |
---|
55 | IMFS_jnode_t *new_node; |
---|
56 | |
---|
57 | new_node = IMFS_create_node( |
---|
58 | parentloc, |
---|
59 | &mknod_control->node_control, |
---|
60 | mknod_control->node_size, |
---|
61 | name, |
---|
62 | namelen, |
---|
63 | mode, |
---|
64 | &dev |
---|
65 | ); |
---|
66 | if ( new_node != NULL ) { |
---|
67 | IMFS_jnode_t *parent = parentloc->node_access; |
---|
68 | |
---|
69 | IMFS_mtime_ctime_update( parent ); |
---|
70 | } else { |
---|
71 | rv = -1; |
---|
72 | } |
---|
73 | |
---|
74 | return rv; |
---|
75 | } |
---|