source: rtems/c/src/libfs/src/imfs/imfs_creat.c @ 3cf8394

4.104.114.84.95
Last change on this file since 3cf8394 was 3cf8394, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 24, 1999 at 8:58:47 PM

Changed IMFS to use IMFS_NAME_MAX as the maximum length of a basename
rather then NAME_MAX. NAME_MAX is 255 and that lets IMFS chew up memory
too fast. Perhaps in the future, the places in IMFS that put a maximum
length name string on the stack and the jnode structure does not include
a maximu length name string can be fixed so this is not a problem.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  IMFS_create_node()
3 *
4 *  Routine to create a new in memory file system node.
5 *
6 *  COPYRIGHT (c) 1989-1998.
7 *  On-Line Applications Research Corporation (OAR).
8 *  Copyright assigned to U.S. Government, 1994.
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.OARcorp.com/rtems/license.html.
13 *
14 *  $Id$
15 */
16
17#include <assert.h>
18#include <stdlib.h>
19#include <string.h>
20#include "imfs.h"
21#include "libio_.h"
22
23IMFS_jnode_t *IMFS_create_node(
24  rtems_filesystem_location_info_t  *parent_loc,
25  IMFS_jnode_types_t                 type,
26  char                              *name,
27  mode_t                             mode,
28  IMFS_types_union                  *info
29)
30{
31  IMFS_jnode_t        *node;
32  struct timeval       tv;
33  IMFS_jnode_t        *parent = NULL;
34  IMFS_fs_info_t      *fs_info;
35  char                *sym_name;
36
37  if ( parent_loc != NULL )
38    parent = parent_loc->node_access;
39
40  /*
41   *  Allocate an IMFS jnode
42   */
43
44  node = calloc( 1, sizeof( IMFS_jnode_t ) );
45  if ( !node )
46    return NULL;
47
48  /*
49   *  Fill in the basic information
50   */
51
52  node->st_nlink = 1;
53  node->type     = type;
54  strncpy( node->name, name, IMFS_NAME_MAX );
55
56  /*
57   *  Fill in the mode and permission information for the jnode structure.
58   */
59
60  node->st_mode = mode & ~rtems_filesystem_umask;
61 
62#if defined(RTEMS_POSIX_API)
63  node->st_uid = geteuid();
64  node->st_gid = getegid();
65#else
66  node->st_uid = 0;
67  node->st_gid = 0;
68#endif
69
70  /*
71   *  Now set all the times.
72   */
73
74  gettimeofday( &tv, 0 );
75
76  node->st_atime  = (time_t) tv.tv_sec;
77  node->st_mtime  = (time_t) tv.tv_sec;
78  node->st_ctime  = (time_t) tv.tv_sec;
79
80  /*
81   *  Set the type specific information
82   */
83
84  switch (type) {
85    case IMFS_DIRECTORY:
86      Chain_Initialize_empty(&node->info.directory.Entries);
87      break;
88
89    case IMFS_HARD_LINK:
90      node->info.hard_link.link_node = info->hard_link.link_node;
91      break;
92
93    case IMFS_SYM_LINK:
94      sym_name = calloc( 1, strlen( info->sym_link.name ) + 1 );
95      strcpy( sym_name, info->sym_link.name );
96      node->info.sym_link.name = sym_name;
97      break;
98
99    case IMFS_DEVICE:
100      node->info.device.major = info->device.major;
101      node->info.device.minor = info->device.minor;
102      break;
103
104    case IMFS_MEMORY_FILE:
105      node->info.file.size            = 0;
106      node->info.file.indirect        = 0;
107      node->info.file.doubly_indirect = 0;
108      node->info.file.triply_indirect = 0;
109      break;
110
111    default:
112      assert(0);
113      break;
114  }
115
116  /*
117   *  If this node has a parent, then put it in that directory list.
118   */
119
120  if ( parent ) {
121    Chain_Append( &parent->info.directory.Entries, &node->Node );
122    node->Parent = parent;
123
124    fs_info = parent_loc->mt_entry->fs_info;
125    node->st_ino = ++fs_info->ino_count;
126  }
127
128
129  return node;
130}
Note: See TracBrowser for help on using the repository browser.