source: rtems/cpukit/libfs/src/imfs/imfs_link.c @ 40d062f5

4.115
Last change on this file since 40d062f5 was 40d062f5, checked in by Sebastian Huber <sebastian.huber@…>, on 01/28/15 at 17:47:19

IMFS: Reduce IMFS node types

Provide only types used by IMFS_mknod().

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief IMFS Create a New Link Node
5 * @ingroup IMFS
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2010.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include "imfs.h"
22
23static const IMFS_node_control IMFS_node_control_hard_link;
24
25int IMFS_link(
26  const rtems_filesystem_location_info_t *parentloc,
27  const rtems_filesystem_location_info_t *targetloc,
28  const char *name,
29  size_t namelen
30)
31{
32  IMFS_jnode_t *new_node;
33  IMFS_jnode_t *target;
34
35  target = targetloc->node_access;
36
37  /*
38   *  Verify this node can be linked to.
39   */
40  if ( target->st_nlink >= LINK_MAX )
41    rtems_set_errno_and_return_minus_one( EMLINK );
42
43  /*
44   *  Create a new link node.
45   */
46  new_node = IMFS_create_node(
47    parentloc,
48    &IMFS_node_control_hard_link,
49    name,
50    namelen,
51    IMFS_STAT_FMT_HARD_LINK | ( S_IRWXU | S_IRWXG | S_IRWXO ),
52    target
53  );
54
55  if ( !new_node )
56    rtems_set_errno_and_return_minus_one( ENOMEM );
57
58  /*
59   * Increment the link count of the node being pointed to.
60   */
61  target->reference_count++;
62  target->st_nlink++;
63  IMFS_update_ctime( target );
64
65  return 0;
66}
67
68static int IMFS_stat_hard_link(
69  const rtems_filesystem_location_info_t *loc,
70  struct stat *buf
71)
72{
73  const IMFS_link_t *hard_link = loc->node_access;
74  rtems_filesystem_location_info_t targetloc = *loc;
75
76  targetloc.node_access = hard_link->link_node;
77  IMFS_Set_handlers( &targetloc );
78
79  return (targetloc.handlers->fstat_h)( &targetloc, buf );
80}
81
82static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
83  .open_h = rtems_filesystem_default_open,
84  .close_h = rtems_filesystem_default_close,
85  .read_h = rtems_filesystem_default_read,
86  .write_h = rtems_filesystem_default_write,
87  .ioctl_h = rtems_filesystem_default_ioctl,
88  .lseek_h = rtems_filesystem_default_lseek,
89  .fstat_h = IMFS_stat_hard_link,
90  .ftruncate_h = rtems_filesystem_default_ftruncate,
91  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
92  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
93  .fcntl_h = rtems_filesystem_default_fcntl,
94  .kqfilter_h = rtems_filesystem_default_kqfilter,
95  .poll_h = rtems_filesystem_default_poll,
96  .readv_h = rtems_filesystem_default_readv,
97  .writev_h = rtems_filesystem_default_writev
98};
99
100static IMFS_jnode_t *IMFS_node_initialize_hard_link(
101  IMFS_jnode_t *node,
102  void *arg
103)
104{
105  IMFS_link_t *hard_link = (IMFS_link_t *) node;
106
107  hard_link->link_node = arg;
108
109  return node;
110}
111
112static IMFS_jnode_t *IMFS_node_remove_hard_link(
113  IMFS_jnode_t *node
114)
115{
116  IMFS_link_t *hard_link = (IMFS_link_t *) node;
117  IMFS_jnode_t *target = hard_link->link_node;
118
119  _Assert( target != NULL );
120
121  if ( target->st_nlink == 1) {
122    target = (*target->control->node_remove)( target );
123    if ( target == NULL ) {
124      node = NULL;
125    }
126  } else {
127    --target->st_nlink;
128    IMFS_update_ctime( target );
129  }
130
131  return node;
132}
133
134static const IMFS_node_control IMFS_node_control_hard_link = {
135  .handlers = &IMFS_link_handlers,
136  .node_size = sizeof(IMFS_link_t),
137  .node_initialize = IMFS_node_initialize_hard_link,
138  .node_remove = IMFS_node_remove_hard_link,
139  .node_destroy = IMFS_node_destroy_default
140};
Note: See TracBrowser for help on using the repository browser.