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

4.11
Last change on this file since 68cd765 was 68cd765, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 8, 2010 at 3:15:31 PM

2010-06-08 Sebastian Huber <sebastian.huber@…>

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