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

4.115
Last change on this file since c17d0b3 was c17d0b3, checked in by Sebastian Huber <sebastian.huber@…>, on 10/02/12 at 13:44:59

Filesystem: Reject removal of root nodes

Reject the removal of file system instance root nodes in rmdir() and
unlink() and return the EBUSY error status. File system instances can
be removed with unmount(). Remove root node special cases in IMFS,
DOSFS, and RFS.

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