OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libfs/] [src/] [imfs/] [imfs_creat.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  IMFS_create_node()
3
 *
4
 *  Routine to create a new in memory file system node.
5
 *
6
 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
12
 *
13
 *  imfs_creat.c,v 1.8 2001/01/22 14:05:14 joel Exp
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
IMFS_jnode_t *IMFS_create_node(
27
  rtems_filesystem_location_info_t  *parent_loc,
28
  IMFS_jnode_types_t                 type,
29
  char                              *name,
30
  mode_t                             mode,
31
  IMFS_types_union                  *info
32
)
33
{
34
  IMFS_jnode_t        *node;
35
  struct timeval       tv;
36
  IMFS_jnode_t        *parent = NULL;
37
  IMFS_fs_info_t      *fs_info;
38
  char                *sym_name;
39
 
40
  if ( parent_loc != NULL )
41
    parent = parent_loc->node_access;
42
 
43
  /*
44
   *  Allocate an IMFS jnode
45
   */
46
 
47
  node = calloc( 1, sizeof( IMFS_jnode_t ) );
48
  if ( !node )
49
    return NULL;
50
 
51
  /*
52
   *  Fill in the basic information
53
   */
54
 
55
  node->st_nlink = 1;
56
  node->type     = type;
57
  strncpy( node->name, name, IMFS_NAME_MAX );
58
 
59
  /*
60
   *  Fill in the mode and permission information for the jnode structure.
61
   */
62
 
63
  node->st_mode = mode & ~rtems_filesystem_umask;
64
 
65
#if defined(RTEMS_POSIX_API)
66
  node->st_uid = geteuid();
67
  node->st_gid = getegid();
68
#else
69
  node->st_uid = 0;
70
  node->st_gid = 0;
71
#endif
72
 
73
  /*
74
   *  Now set all the times.
75
   */
76
 
77
  gettimeofday( &tv, 0 );
78
 
79
  node->stat_atime  = (time_t) tv.tv_sec;
80
  node->stat_mtime  = (time_t) tv.tv_sec;
81
  node->stat_ctime  = (time_t) tv.tv_sec;
82
 
83
  /*
84
   *  Set the type specific information
85
   */
86
 
87
  switch (type) {
88
    case IMFS_DIRECTORY:
89
      Chain_Initialize_empty(&node->info.directory.Entries);
90
      break;
91
 
92
    case IMFS_HARD_LINK:
93
      node->info.hard_link.link_node = info->hard_link.link_node;
94
      break;
95
 
96
    case IMFS_SYM_LINK:
97
      sym_name = calloc( 1, strlen( info->sym_link.name ) + 1 );
98
      strcpy( sym_name, info->sym_link.name );
99
      node->info.sym_link.name = sym_name;
100
      break;
101
 
102
    case IMFS_DEVICE:
103
      node->info.device.major = info->device.major;
104
      node->info.device.minor = info->device.minor;
105
      break;
106
 
107
    case IMFS_LINEAR_FILE:
108
      node->info.linearfile.size      = 0;
109
      node->info.linearfile.direct    = 0;
110
 
111
    case IMFS_MEMORY_FILE:
112
      node->info.file.size            = 0;
113
      node->info.file.indirect        = 0;
114
      node->info.file.doubly_indirect = 0;
115
      node->info.file.triply_indirect = 0;
116
      break;
117
 
118
    default:
119
      assert(0);
120
      break;
121
  }
122
 
123
  /*
124
   *  If this node has a parent, then put it in that directory list.
125
   */
126
 
127
  if ( parent ) {
128
    Chain_Append( &parent->info.directory.Entries, &node->Node );
129
    node->Parent = parent;
130
 
131
    fs_info = parent_loc->mt_entry->fs_info;
132
    node->st_ino = ++fs_info->ino_count;
133
  }
134
 
135
 
136
  return node;
137
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.