source: rtems/cpukit/libfs/src/imfs/imfs_node.c @ 0ec9bbc

5
Last change on this file since 0ec9bbc was a397c7d8, checked in by Sebastian Huber <sebastian.huber@…>, on 12/13/17 at 07:00:02

IMFS: Include <rtems/imfs.h>

Prepare for header file move to common include directory.

Update #3254.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief IMFS Node Support
5 * @ingroup IMFS
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Modifications to support reference counting in the file system are
13 *  Copyright (c) 2012 embedded brains GmbH.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#if HAVE_CONFIG_H
21  #include "config.h"
22#endif
23
24#include <rtems/imfs.h>
25
26#include <stdlib.h>
27
28IMFS_jnode_t *IMFS_initialize_node(
29  IMFS_jnode_t *node,
30  const IMFS_node_control *node_control,
31  const char *name,
32  size_t namelen,
33  mode_t mode,
34  void *arg
35)
36{
37  struct timeval tv;
38
39  if ( namelen > IMFS_NAME_MAX ) {
40    errno = ENAMETOOLONG;
41
42    return NULL;
43  }
44
45  gettimeofday( &tv, 0 );
46
47  /*
48   *  Fill in the basic information
49   */
50  node->name = name;
51  node->namelen = namelen;
52  node->reference_count = 1;
53  node->st_nlink = 1;
54  node->control = node_control;
55
56  /*
57   *  Fill in the mode and permission information for the jnode structure.
58   */
59  node->st_mode = mode;
60  node->st_uid = geteuid();
61  node->st_gid = getegid();
62
63  /*
64   *  Now set all the times.
65   */
66
67  node->stat_atime  = (time_t) tv.tv_sec;
68  node->stat_mtime  = (time_t) tv.tv_sec;
69  node->stat_ctime  = (time_t) tv.tv_sec;
70
71  return (*node_control->node_initialize)( node, arg );
72}
73
74int IMFS_node_clone( rtems_filesystem_location_info_t *loc )
75{
76  IMFS_jnode_t *node = loc->node_access;
77
78  ++node->reference_count;
79
80  return 0;
81}
82
83void IMFS_node_destroy( IMFS_jnode_t *node )
84{
85  IMFS_assert( node->reference_count == 0 );
86
87  (*node->control->node_destroy)( node );
88}
89
90void IMFS_node_free( const rtems_filesystem_location_info_t *loc )
91{
92  IMFS_jnode_t *node = loc->node_access;
93
94  --node->reference_count;
95
96  if ( node->reference_count == 0 ) {
97    IMFS_node_destroy( node );
98  }
99}
100
101IMFS_jnode_t *IMFS_node_remove_default(
102  IMFS_jnode_t *node
103)
104{
105  return node;
106}
107
108void IMFS_node_destroy_default( IMFS_jnode_t *node )
109{
110  if ( ( node->flags & IMFS_NODE_FLAG_NAME_ALLOCATED ) != 0 ) {
111    free( RTEMS_DECONST( char *, node->name ) );
112  }
113
114  free( node );
115}
Note: See TracBrowser for help on using the repository browser.