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

4.115
Last change on this file since cc43b364 was 0aea082, checked in by Joel Sherrill <joel.sherrill@…>, on 07/30/10 at 22:36:32

2010-07-30 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/fstat.c, libcsupport/src/rmdir.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_getchild.c, libfs/src/imfs/memfile.c: Add IMFS_assert. Clean up and remove all checks which are redundant with system call layer. Formatting.
  • Property mode set to 100644
File size: 4.0 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#include <stdlib.h>
21#include <string.h>
22#include "imfs.h"
23#include <rtems/libio_.h>
24
25/*
26 *  Create an IMFS filesystem node of an arbitrary type that is NOT
27 *  the root directory node.
28 */
29IMFS_jnode_t *IMFS_create_node(
30  rtems_filesystem_location_info_t *parent_loc,
31  IMFS_jnode_types_t                type,
32  const char                       *name,
33  mode_t                            mode,
34  const IMFS_types_union           *info
35)
36{
37  IMFS_jnode_t        *node;
38  IMFS_jnode_t        *parent;
39  IMFS_fs_info_t      *fs_info;
40
41  /*
42   *  MUST have a parent node to call this routine.
43   */
44  if ( parent_loc == NULL )
45    return NULL;
46
47  parent = parent_loc->node_access;
48  fs_info = parent_loc->mt_entry->fs_info;
49
50  /*
51   *  Reject creation of FIFOs if support is disabled.
52   */
53  if ( type == IMFS_FIFO &&
54       fs_info->fifo_handlers == &rtems_filesystem_handlers_default )
55    return NULL;
56
57  /*
58   *  Allocate filesystem node and fill in basic information
59   */
60  node  = IMFS_allocate_node( type, name, mode & ~rtems_filesystem_umask );
61  if ( !node )
62    return NULL;
63
64  /*
65   *  Set the type specific information
66   */
67  switch (type) {
68    case IMFS_DIRECTORY:
69      rtems_chain_initialize_empty(&node->info.directory.Entries);
70      break;
71
72    case IMFS_HARD_LINK:
73      node->info.hard_link.link_node = info->hard_link.link_node;
74      break;
75
76    case IMFS_SYM_LINK:
77      node->info.sym_link.name = info->sym_link.name;
78      break;
79
80    case IMFS_DEVICE:
81      node->info.device.major = info->device.major;
82      node->info.device.minor = info->device.minor;
83      break;
84
85    case IMFS_LINEAR_FILE:
86      node->info.linearfile.size      = 0;
87      node->info.linearfile.direct    = 0;
88
89    case IMFS_MEMORY_FILE:
90      node->info.file.size            = 0;
91      node->info.file.indirect        = 0;
92      node->info.file.doubly_indirect = 0;
93      node->info.file.triply_indirect = 0;
94      break;
95
96    case IMFS_FIFO:
97      node->info.fifo.pipe = NULL;
98      break;
99
100    default:
101      IMFS_assert(0);
102      break;
103  }
104
105  /*
106   *  This node MUST have a parent, so put it in that directory list.
107   */
108  node->Parent = parent;
109  node->st_ino = ++fs_info->ino_count;
110
111  rtems_chain_append( &parent->info.directory.Entries, &node->Node );
112
113  return node;
114}
115
116/*
117 *  Allocate filesystem node and fill in basic information
118 */
119IMFS_jnode_t *IMFS_allocate_node(
120  IMFS_jnode_types_t                type,
121  const char                       *name,
122  mode_t                            mode
123)
124{
125  IMFS_jnode_t        *node;
126  struct timeval       tv;
127
128  /*
129   *  Allocate an IMFS jnode
130   */
131  node = calloc( 1, sizeof( IMFS_jnode_t ) );
132  if ( !node )
133    return NULL;
134
135  /*
136   *  Fill in the basic information
137   */
138  node->st_nlink = 1;
139  node->type     = type;
140  strncpy( node->name, name, IMFS_NAME_MAX );
141
142  /*
143   *  Fill in the mode and permission information for the jnode structure.
144   */
145  node->st_mode = mode;
146  #if defined(RTEMS_POSIX_API)
147    node->st_uid = geteuid();
148    node->st_gid = getegid();
149  #else
150    node->st_uid = 0;
151    node->st_gid = 0;
152  #endif
153
154  /*
155   *  Now set all the times.
156   */
157  gettimeofday( &tv, 0 );
158
159  node->stat_atime  = (time_t) tv.tv_sec;
160  node->stat_mtime  = (time_t) tv.tv_sec;
161  node->stat_ctime  = (time_t) tv.tv_sec;
162
163  return node;
164}
165
166IMFS_jnode_t *IMFS_create_root_node(void)
167{
168  IMFS_jnode_t        *node;
169
170  /*
171   *  Allocate filesystem node and fill in basic information
172   */
173  node = IMFS_allocate_node( IMFS_DIRECTORY, "", (S_IFDIR | 0755) );
174  if ( !node )
175    return NULL;
176
177  /*
178   *  Set the type specific information
179   *
180   *  NOTE: Root node is always a directory.
181   */
182  rtems_chain_initialize_empty(&node->info.directory.Entries);
183
184  return node;
185}
Note: See TracBrowser for help on using the repository browser.