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

4.115
Last change on this file since 983bfad was 983bfad, checked in by Joel Sherrill <joel.sherrill@…>, on 06/24/10 at 21:31:22

2010-06-24 Joel Sherrill <joel.sherrilL@…>

  • libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_getchild.c, libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/ioman.c, libfs/src/imfs/memfile.c: Evaluate all assert calls in IMFS. Either made them conditional on RTEMS_DEBUG or eliminated them.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  IMFS_create_node()
3 *
4 *  Routine to create a new in memory file system node.
5 *
6 *  COPYRIGHT (c) 1989-2010.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#if defined(RTEMS_DEBUG)
21  #include <assert.h>
22#endif
23#include <stdlib.h>
24#include <string.h>
25#include "imfs.h"
26#include <rtems/libio_.h>
27
28/*
29 *  Create an IMFS filesystem node of an arbitrary type that is NOT
30 *  the root directory node.
31 */
32IMFS_jnode_t *IMFS_create_node(
33  rtems_filesystem_location_info_t *parent_loc,
34  IMFS_jnode_types_t                type,
35  const char                       *name,
36  mode_t                            mode,
37  const IMFS_types_union           *info
38)
39{
40  IMFS_jnode_t        *node;
41  IMFS_jnode_t        *parent;
42  IMFS_fs_info_t      *fs_info;
43
44  /*
45   *  MUST have a parent node to call this routine.
46   */
47  if ( parent_loc == NULL )
48    return NULL;
49
50  parent = parent_loc->node_access;
51  fs_info = parent_loc->mt_entry->fs_info;
52
53  /*
54   *  Reject creation of FIFOs if support is disabled.
55   */
56  if ( type == IMFS_FIFO &&
57       fs_info->fifo_handlers == &rtems_filesystem_null_handlers )
58    return NULL;
59
60  /*
61   *  Allocate filesystem node and fill in basic information
62   */
63  node  = IMFS_allocate_node( type, name, mode & ~rtems_filesystem_umask );
64  if ( !node )
65    return NULL;
66
67  /*
68   *  Set the type specific information
69   */
70  switch (type) {
71    case IMFS_DIRECTORY:
72      rtems_chain_initialize_empty(&node->info.directory.Entries);
73      break;
74
75    case IMFS_HARD_LINK:
76      node->info.hard_link.link_node = info->hard_link.link_node;
77      break;
78
79    case IMFS_SYM_LINK:
80      node->info.sym_link.name = info->sym_link.name;
81      break;
82
83    case IMFS_DEVICE:
84      node->info.device.major = info->device.major;
85      node->info.device.minor = info->device.minor;
86      break;
87
88    case IMFS_LINEAR_FILE:
89      node->info.linearfile.size      = 0;
90      node->info.linearfile.direct    = 0;
91
92    case IMFS_MEMORY_FILE:
93      node->info.file.size            = 0;
94      node->info.file.indirect        = 0;
95      node->info.file.doubly_indirect = 0;
96      node->info.file.triply_indirect = 0;
97      break;
98
99    case IMFS_FIFO:
100      node->info.fifo.pipe = NULL;
101      break;
102
103    default:
104      #if defined(RTEMS_DEBUG)
105        assert(0);
106      #endif
107      return;
108  }
109
110  /*
111   *  This node MUST have a parent, so put it in that directory list.
112   */
113
114  node->Parent = parent;
115  node->st_ino = ++fs_info->ino_count;
116
117  rtems_chain_append( &parent->info.directory.Entries, &node->Node );
118
119  return node;
120}
121
122/*
123 *  Allocate filesystem node and fill in basic information
124 */
125IMFS_jnode_t *IMFS_allocate_node(
126  IMFS_jnode_types_t                type,
127  const char                       *name,
128  mode_t                            mode
129)
130{
131  IMFS_jnode_t        *node;
132  struct timeval       tv;
133
134  /*
135   *  Allocate an IMFS jnode
136   */
137  node = calloc( 1, sizeof( IMFS_jnode_t ) );
138  if ( !node )
139    return NULL;
140
141  /*
142   *  Fill in the basic information
143   */
144  node->st_nlink = 1;
145  node->type     = type;
146  strncpy( node->name, name, IMFS_NAME_MAX );
147
148  /*
149   *  Fill in the mode and permission information for the jnode structure.
150   */
151  node->st_mode = mode;
152  #if defined(RTEMS_POSIX_API)
153    node->st_uid = geteuid();
154    node->st_gid = getegid();
155  #else
156    node->st_uid = 0;
157    node->st_gid = 0;
158  #endif
159
160  /*
161   *  Now set all the times.
162   */
163  gettimeofday( &tv, 0 );
164
165  node->stat_atime  = (time_t) tv.tv_sec;
166  node->stat_mtime  = (time_t) tv.tv_sec;
167  node->stat_ctime  = (time_t) tv.tv_sec;
168
169  return node;
170}
171
172IMFS_jnode_t *IMFS_create_root_node(void)
173{
174  IMFS_jnode_t        *node;
175
176  /*
177   *  Allocate filesystem node and fill in basic information
178   */
179  node = IMFS_allocate_node( IMFS_DIRECTORY, "", (S_IFDIR | 0755) );
180  if ( !node )
181    return NULL;
182
183  /*
184   *  Set the type specific information
185   *
186   *  NOTE: Root node is always a directory.
187   */
188  rtems_chain_initialize_empty(&node->info.directory.Entries);
189
190  return node;
191}
Note: See TracBrowser for help on using the repository browser.