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

4.104.11
Last change on this file since cb4e992 was cb4e992, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 19, 2010 at 7:31:00 PM

2010-01-19 Joel Sherrill <joel.sherrill@…>

  • libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_link.c, libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c: Create special helper method for creating the j-node for the root directory. This lets us assume that every j-node created otherwise has a parent node.
  • Property mode set to 100644
File size: 3.9 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  /*
49   *  Allocate filesystem node and fill in basic information
50   */
51  node  = IMFS_allocate_node( type, name, mode & ~rtems_filesystem_umask );
52  if ( !node )
53    return NULL;
54
55  /*
56   *  Set the type specific information
57   */
58  switch (type) {
59    case IMFS_DIRECTORY:
60      rtems_chain_initialize_empty(&node->info.directory.Entries);
61      break;
62
63    case IMFS_HARD_LINK:
64      node->info.hard_link.link_node = info->hard_link.link_node;
65      break;
66
67    case IMFS_SYM_LINK:
68      node->info.sym_link.name = info->sym_link.name;
69      break;
70
71    case IMFS_DEVICE:
72      node->info.device.major = info->device.major;
73      node->info.device.minor = info->device.minor;
74      break;
75
76    case IMFS_LINEAR_FILE:
77      node->info.linearfile.size      = 0;
78      node->info.linearfile.direct    = 0;
79
80    case IMFS_MEMORY_FILE:
81      node->info.file.size            = 0;
82      node->info.file.indirect        = 0;
83      node->info.file.doubly_indirect = 0;
84      node->info.file.triply_indirect = 0;
85      break;
86
87    case IMFS_FIFO:
88      node->info.fifo.pipe = NULL;
89      break;
90
91    default:
92      assert(0);
93      break;
94  }
95
96  /*
97   *  This node MUST have a parent, so put it in that directory list.
98   */
99  parent       = parent_loc->node_access;
100  fs_info      = parent_loc->mt_entry->fs_info;
101
102  node->Parent = parent;
103  node->st_ino = ++fs_info->ino_count;
104
105  rtems_chain_append( &parent->info.directory.Entries, &node->Node );
106
107  return node;
108}
109
110/*
111 *  Allocate filesystem node and fill in basic information
112 */
113IMFS_jnode_t *IMFS_allocate_node(
114  IMFS_jnode_types_t                type,
115  const char                       *name,
116  mode_t                            mode
117)
118{
119  IMFS_jnode_t        *node;
120  struct timeval       tv;
121
122  /*
123   *  Allocate an IMFS jnode
124   */
125  node = calloc( 1, sizeof( IMFS_jnode_t ) );
126  if ( !node )
127    return NULL;
128
129  /*
130   *  Fill in the basic information
131   */
132  node->st_nlink = 1;
133  node->type     = type;
134  strncpy( node->name, name, IMFS_NAME_MAX );
135
136  /*
137   *  Fill in the mode and permission information for the jnode structure.
138   */
139  node->st_mode = mode;
140  #if defined(RTEMS_POSIX_API)
141    node->st_uid = geteuid();
142    node->st_gid = getegid();
143  #else
144    node->st_uid = 0;
145    node->st_gid = 0;
146  #endif
147
148  /*
149   *  Now set all the times.
150   */
151  gettimeofday( &tv, 0 );
152
153  node->stat_atime  = (time_t) tv.tv_sec;
154  node->stat_mtime  = (time_t) tv.tv_sec;
155  node->stat_ctime  = (time_t) tv.tv_sec;
156
157  return node;
158}
159
160IMFS_jnode_t *IMFS_create_root_node(void)
161{
162  IMFS_jnode_t        *node;
163
164  /*
165   *  Allocate filesystem node and fill in basic information
166   */
167  node = IMFS_allocate_node( IMFS_DIRECTORY, "", (S_IFDIR | 0755) );
168  if ( !node )
169    return NULL;
170
171  /*
172   *  Set the type specific information
173   *
174   *  NOTE: Root node is always a directory.
175   */
176  rtems_chain_initialize_empty(&node->info.directory.Entries);
177
178  return node;
179}
Note: See TracBrowser for help on using the repository browser.