source: rtems/cpukit/libfs/src/imfs/imfs_handlers_link.c @ 3c96bee

4.115
Last change on this file since 3c96bee was ef5e452, checked in by Alex Ivanov <alexivanov97@…>, on 12/20/12 at 15:45:31

libfs: Doxygen Enhancement Task #1

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Link Operations Table for the IMFS
5 * @ingroup IMFS
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
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.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include "imfs.h"
22
23#include <stdlib.h>
24#include <string.h>
25
26static int IMFS_stat_link(
27  const rtems_filesystem_location_info_t *loc,
28  struct stat *buf
29)
30{
31  const IMFS_jnode_t *node = loc->node_access;
32
33  if ( IMFS_type( node ) != IMFS_HARD_LINK ) {
34    buf->st_size = strlen( node->info.sym_link.name );
35
36    return IMFS_stat( loc, buf );
37  } else {
38    rtems_filesystem_location_info_t targetloc = *loc;
39
40    targetloc.node_access = node->info.hard_link.link_node;
41    IMFS_Set_handlers( &targetloc );
42
43    return (targetloc.handlers->fstat_h)( &targetloc, buf );
44  }
45}
46
47static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
48  rtems_filesystem_default_open,
49  rtems_filesystem_default_close,
50  rtems_filesystem_default_read,
51  rtems_filesystem_default_write,
52  rtems_filesystem_default_ioctl,
53  rtems_filesystem_default_lseek,
54  IMFS_stat_link,
55  rtems_filesystem_default_ftruncate,
56  rtems_filesystem_default_fsync_or_fdatasync,
57  rtems_filesystem_default_fsync_or_fdatasync,
58  rtems_filesystem_default_fcntl
59};
60
61static IMFS_jnode_t *IMFS_node_initialize_hard_link(
62  IMFS_jnode_t *node,
63  const IMFS_types_union *info
64)
65{
66  node->info.hard_link.link_node = info->hard_link.link_node;
67
68  return node;
69}
70
71static IMFS_jnode_t *IMFS_node_remove_hard_link(
72  IMFS_jnode_t *node
73)
74{
75  IMFS_jnode_t *target = node->info.hard_link.link_node;
76
77  if ( target->st_nlink == 1) {
78    target = (*target->control->node_remove)( target );
79    if ( target == NULL ) {
80      node = NULL;
81    }
82  } else {
83    --target->st_nlink;
84    IMFS_update_ctime( target );
85  }
86
87  return node;
88}
89
90const IMFS_node_control IMFS_node_control_hard_link = {
91  .imfs_type = IMFS_HARD_LINK,
92  .handlers = &IMFS_link_handlers,
93  .node_initialize = IMFS_node_initialize_hard_link,
94  .node_remove = IMFS_node_remove_hard_link,
95  .node_destroy = IMFS_node_destroy_default
96};
97
98static IMFS_jnode_t *IMFS_node_initialize_sym_link(
99  IMFS_jnode_t *node,
100  const IMFS_types_union *info
101)
102{
103  node->info.sym_link.name = info->sym_link.name;
104
105  return node;
106}
107
108static IMFS_jnode_t *IMFS_node_destroy_sym_link( IMFS_jnode_t *node )
109{
110  free( node->info.sym_link.name );
111
112  return node;
113}
114
115const IMFS_node_control IMFS_node_control_sym_link = {
116  .imfs_type = IMFS_SYM_LINK,
117  .handlers = &IMFS_link_handlers,
118  .node_initialize = IMFS_node_initialize_sym_link,
119  .node_remove = IMFS_node_remove_default,
120  .node_destroy = IMFS_node_destroy_sym_link
121};
Note: See TracBrowser for help on using the repository browser.