source: rtems/cpukit/libfs/src/imfs/imfs_handlers_link.c @ 183af89

4.11
Last change on this file since 183af89 was e998c985, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 5, 2012 at 10:51:23 AM

IMFS: Node specific stat handlers

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