source: rtems/cpukit/libfs/src/imfs/imfs_creat.c @ 13b71f8

5
Last change on this file since 13b71f8 was 13b71f8, checked in by Sebastian Huber <sebastian.huber@…>, on 02/29/20 at 10:43:42

imfs: Simplify IMFS_create_node()

Update #3894.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Create an IMFS Node
5 * @ingroup IMFS
6 */
7/*
8 *  COPYRIGHT (c) 1989-2010.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17  #include "config.h"
18#endif
19
20#include <rtems/imfs.h>
21
22#include <stdlib.h>
23#include <string.h>
24
25IMFS_jnode_t *IMFS_create_node(
26  const rtems_filesystem_location_info_t *parentloc,
27  const IMFS_node_control *node_control,
28  size_t node_size,
29  const char *name,
30  size_t namelen,
31  mode_t mode,
32  void *arg
33)
34{
35  IMFS_jnode_t *allocated_node;
36  char         *allocated_name;
37  IMFS_jnode_t *node;
38
39  allocated_node = calloc( 1, node_size + namelen );
40  if ( allocated_node == NULL ) {
41    errno = ENOMEM;
42
43    return NULL;
44  }
45
46  allocated_name = (char *) allocated_node + node_size;
47  allocated_name = memcpy( allocated_name, name, namelen );
48  node = IMFS_initialize_node(
49    allocated_node,
50    node_control,
51    allocated_name,
52    namelen,
53    mode,
54    arg
55  );
56  if ( node != NULL ) {
57    IMFS_jnode_t *parent = parentloc->node_access;
58
59    /*
60     *  This node MUST have a parent, so put it in that directory list.
61     */
62    IMFS_assert( parent != NULL );
63    IMFS_add_to_directory( parent, node );
64  } else {
65    free( allocated_node );
66  }
67
68  return node;
69}
70
Note: See TracBrowser for help on using the repository browser.