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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libc/] [imfs_creat.c] - Blame information for rev 228

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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