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

4.115
Last change on this file since cf36b70 was cf36b70, checked in by Sebastian Huber <sebastian.huber@…>, on 12/31/14 at 09:56:05

IMFS: Replace node union with individual struct

This reduces the average node size.

Add and use IMFS_GENERIC_INITIALIZER().

  • Property mode set to 100644
File size: 2.3 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 "imfs.h"
21
22#include <stdlib.h>
23#include <string.h>
24
25IMFS_jnode_t *IMFS_allocate_node(
26  IMFS_fs_info_t *fs_info,
27  const IMFS_node_control *node_control,
28  const char *name,
29  size_t namelen,
30  mode_t mode,
31  void *arg
32)
33{
34  IMFS_jnode_t        *node;
35  IMFS_jnode_t        *initialized_node;
36  struct timeval       tv;
37
38  if ( namelen > IMFS_NAME_MAX ) {
39    errno = ENAMETOOLONG;
40
41    return NULL;
42  }
43
44  gettimeofday( &tv, 0 );
45
46  /*
47   *  Allocate an IMFS jnode
48   */
49  node = calloc( 1, node_control->node_size );
50  if ( !node ) {
51    errno = ENOMEM;
52
53    return NULL;
54  }
55
56  /*
57   *  Fill in the basic information
58   */
59  node->reference_count = 1;
60  node->st_nlink = 1;
61  memcpy( node->name, name, namelen );
62  node->name [namelen] = '\0';
63  node->control = node_control;
64
65  /*
66   *  Fill in the mode and permission information for the jnode structure.
67   */
68  node->st_mode = mode;
69  node->st_uid = geteuid();
70  node->st_gid = getegid();
71
72  /*
73   *  Now set all the times.
74   */
75
76  node->stat_atime  = (time_t) tv.tv_sec;
77  node->stat_mtime  = (time_t) tv.tv_sec;
78  node->stat_ctime  = (time_t) tv.tv_sec;
79  node->st_ino = ++fs_info->ino_count;
80
81  initialized_node = (*node->control->node_initialize)( node, arg );
82  if ( initialized_node == NULL ) {
83    free( node );
84  }
85
86  return initialized_node;
87}
88
89IMFS_jnode_t *IMFS_create_node_with_control(
90  const rtems_filesystem_location_info_t *parentloc,
91  const IMFS_node_control *node_control,
92  const char *name,
93  size_t namelen,
94  mode_t mode,
95  void *arg
96)
97{
98  IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info;
99  IMFS_jnode_t *node = IMFS_allocate_node(
100    fs_info,
101    node_control,
102    name,
103    namelen,
104    mode,
105    arg
106  );
107
108  if ( node != NULL ) {
109    IMFS_jnode_t *parent = parentloc->node_access;
110
111    /*
112     *  This node MUST have a parent, so put it in that directory list.
113     */
114    IMFS_assert( parent != NULL );
115    IMFS_add_to_directory( parent, node );
116  }
117
118  return node;
119}
120
Note: See TracBrowser for help on using the repository browser.