1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup IMFS |
---|
7 | * |
---|
8 | * @brief Create a IMFS Node |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * COPYRIGHT (c) 1989-2010. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * Modifications to support reference counting in the file system are |
---|
16 | * Copyright (c) 2012 embedded brains GmbH & Co. KG |
---|
17 | * |
---|
18 | * Redistribution and use in source and binary forms, with or without |
---|
19 | * modification, are permitted provided that the following conditions |
---|
20 | * are met: |
---|
21 | * 1. Redistributions of source code must retain the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer. |
---|
23 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
24 | * notice, this list of conditions and the following disclaimer in the |
---|
25 | * documentation and/or other materials provided with the distribution. |
---|
26 | * |
---|
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
31 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
37 | * POSSIBILITY OF SUCH DAMAGE. |
---|
38 | */ |
---|
39 | |
---|
40 | #ifdef HAVE_CONFIG_H |
---|
41 | #include "config.h" |
---|
42 | #endif |
---|
43 | |
---|
44 | #include <rtems/imfsimpl.h> |
---|
45 | |
---|
46 | static const IMFS_mknod_control *get_control( |
---|
47 | const IMFS_mknod_controls *controls, |
---|
48 | mode_t mode |
---|
49 | ) |
---|
50 | { |
---|
51 | if ( S_ISDIR( mode ) ) { |
---|
52 | return controls->directory; |
---|
53 | } else if ( S_ISBLK( mode ) || S_ISCHR( mode ) ) { |
---|
54 | return controls->device; |
---|
55 | } else if ( S_ISFIFO( mode ) ) { |
---|
56 | return controls->fifo; |
---|
57 | } else { |
---|
58 | IMFS_assert( S_ISREG( mode ) ); |
---|
59 | return controls->file; |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | int IMFS_mknod( |
---|
64 | const rtems_filesystem_location_info_t *parentloc, |
---|
65 | const char *name, |
---|
66 | size_t namelen, |
---|
67 | mode_t mode, |
---|
68 | dev_t dev |
---|
69 | ) |
---|
70 | { |
---|
71 | int rv = 0; |
---|
72 | const IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info; |
---|
73 | const IMFS_mknod_control *mknod_control = |
---|
74 | get_control( fs_info->mknod_controls, mode ); |
---|
75 | IMFS_jnode_t *new_node; |
---|
76 | |
---|
77 | new_node = IMFS_create_node( |
---|
78 | parentloc, |
---|
79 | &mknod_control->node_control, |
---|
80 | mknod_control->node_size, |
---|
81 | name, |
---|
82 | namelen, |
---|
83 | mode, |
---|
84 | &dev |
---|
85 | ); |
---|
86 | if ( new_node != NULL ) { |
---|
87 | IMFS_jnode_t *parent = parentloc->node_access; |
---|
88 | |
---|
89 | IMFS_mtime_ctime_update( parent ); |
---|
90 | } else { |
---|
91 | rv = -1; |
---|
92 | } |
---|
93 | |
---|
94 | return rv; |
---|
95 | } |
---|