source: rtems/cpukit/libfs/src/imfs/imfs_handlers_link.c @ 699ac7c

4.115
Last change on this file since 699ac7c was 699ac7c, checked in by Sebastian Huber <sebastian.huber@…>, on 02/24/12 at 16:08:06

IMFS: Add and use node control

Add and use structure IMFS_node_control with support functions. This
helps to make high level functions independent of the node type and
reduces the number of branches in the code.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  Link Operations Table for the IMFS
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15  #include "config.h"
16#endif
17
18#include "imfs.h"
19
20#include <stdlib.h>
21
22static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
23  rtems_filesystem_default_open,
24  rtems_filesystem_default_close,
25  rtems_filesystem_default_read,
26  rtems_filesystem_default_write,
27  rtems_filesystem_default_ioctl,
28  rtems_filesystem_default_lseek,
29  IMFS_stat,  /* stat */
30  rtems_filesystem_default_ftruncate,
31  rtems_filesystem_default_fsync_or_fdatasync,
32  rtems_filesystem_default_fsync_or_fdatasync,
33  rtems_filesystem_default_fcntl
34};
35
36static IMFS_jnode_t *IMFS_node_initialize_hard_link(
37  IMFS_jnode_t *node,
38  const IMFS_types_union *info
39)
40{
41  node->info.hard_link.link_node = info->hard_link.link_node;
42
43  return node;
44}
45
46static IMFS_jnode_t *IMFS_node_remove_hard_link(
47  IMFS_jnode_t *node,
48  const IMFS_jnode_t *root_node
49)
50{
51  IMFS_jnode_t *target = node->info.hard_link.link_node;
52
53  if ( target->st_nlink == 1) {
54    target = (*target->control->node_remove)( target, root_node );
55    if ( target == NULL ) {
56      node = NULL;
57    }
58  } else {
59    --target->st_nlink;
60    IMFS_update_ctime( target );
61  }
62
63  return node;
64}
65
66const IMFS_node_control IMFS_node_control_hard_link = {
67  .imfs_type = IMFS_HARD_LINK,
68  .handlers = &IMFS_link_handlers,
69  .node_initialize = IMFS_node_initialize_hard_link,
70  .node_remove = IMFS_node_remove_hard_link,
71  .node_destroy = IMFS_node_destroy_default
72};
73
74static IMFS_jnode_t *IMFS_node_initialize_sym_link(
75  IMFS_jnode_t *node,
76  const IMFS_types_union *info
77)
78{
79  node->info.sym_link.name = info->sym_link.name;
80
81  return node;
82}
83
84static IMFS_jnode_t *IMFS_node_destroy_sym_link( IMFS_jnode_t *node )
85{
86  free( node->info.sym_link.name );
87
88  return node;
89}
90
91const IMFS_node_control IMFS_node_control_sym_link = {
92  .imfs_type = IMFS_SYM_LINK,
93  .handlers = &IMFS_link_handlers,
94  .node_initialize = IMFS_node_initialize_sym_link,
95  .node_remove = IMFS_node_remove_default,
96  .node_destroy = IMFS_node_destroy_sym_link
97};
Note: See TracBrowser for help on using the repository browser.