1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/**
* @file
*
* @brief Create an IMFS Node
* @ingroup IMFS
*/
/*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include "imfs.h"
#include <stdlib.h>
#include <string.h>
IMFS_jnode_t *IMFS_allocate_node(
IMFS_fs_info_t *fs_info,
const IMFS_node_control *node_control,
const char *name,
size_t namelen,
mode_t mode,
void *arg
)
{
IMFS_jnode_t *node;
IMFS_jnode_t *initialized_node;
struct timeval tv;
if ( namelen > IMFS_NAME_MAX ) {
errno = ENAMETOOLONG;
return NULL;
}
gettimeofday( &tv, 0 );
/*
* Allocate an IMFS jnode
*/
node = calloc( 1, node_control->node_size );
if ( !node ) {
errno = ENOMEM;
return NULL;
}
/*
* Fill in the basic information
*/
node->reference_count = 1;
node->st_nlink = 1;
memcpy( node->name, name, namelen );
node->name [namelen] = '\0';
node->control = node_control;
/*
* Fill in the mode and permission information for the jnode structure.
*/
node->st_mode = mode;
node->st_uid = geteuid();
node->st_gid = getegid();
/*
* Now set all the times.
*/
node->stat_atime = (time_t) tv.tv_sec;
node->stat_mtime = (time_t) tv.tv_sec;
node->stat_ctime = (time_t) tv.tv_sec;
node->st_ino = ++fs_info->ino_count;
initialized_node = (*node->control->node_initialize)( node, arg );
if ( initialized_node == NULL ) {
free( node );
}
return initialized_node;
}
IMFS_jnode_t *IMFS_create_node_with_control(
const rtems_filesystem_location_info_t *parentloc,
const IMFS_node_control *node_control,
const char *name,
size_t namelen,
mode_t mode,
void *arg
)
{
IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info;
IMFS_jnode_t *node = IMFS_allocate_node(
fs_info,
node_control,
name,
namelen,
mode,
arg
);
if ( node != NULL ) {
IMFS_jnode_t *parent = parentloc->node_access;
/*
* This node MUST have a parent, so put it in that directory list.
*/
IMFS_assert( parent != NULL );
IMFS_add_to_directory( parent, node );
}
return node;
}
|