source: rtems/cpukit/libfs/src/imfs/imfs_symlink.c @ 24ec25d

4.115
Last change on this file since 24ec25d was 24ec25d, checked in by Sebastian Huber <sebastian.huber@…>, on 02/05/15 at 15:14:59

IMFS: Introduce IMFS_mknod_control

Drop IMFS_node_control::node_size field and add node_size parameter to
IMFS_allocate_node() and IMFS_create_node(). This reduces the size of
generic nodes.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief IMFS Create a New Symbolic Link Node
5 * @ingroup IMFS
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
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
23#include <stdlib.h>
24#include <string.h>
25
26static const IMFS_node_control IMFS_node_control_sym_link;
27
28int IMFS_symlink(
29  const rtems_filesystem_location_info_t *parentloc,
30  const char *name,
31  size_t namelen,
32  const char *target
33)
34{
35  char         *dup_target;
36  IMFS_jnode_t *new_node;
37
38  /*
39   * Duplicate link name
40   */
41  dup_target = strdup(target);
42  if (dup_target == NULL) {
43    rtems_set_errno_and_return_minus_one(ENOMEM);
44  }
45
46  /*
47   *  Create a new link node.
48   */
49  new_node = IMFS_create_node(
50    parentloc,
51    &IMFS_node_control_sym_link,
52    sizeof( IMFS_sym_link_t ),
53    name,
54    namelen,
55    ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )),
56    dup_target
57  );
58
59  if (new_node == NULL) {
60    free(dup_target);
61    rtems_set_errno_and_return_minus_one(ENOMEM);
62  }
63
64  return 0;
65}
66
67ssize_t IMFS_readlink(
68  const rtems_filesystem_location_info_t *loc,
69  char *buf,
70  size_t bufsize
71)
72{
73  IMFS_sym_link_t   *sym_link;
74  ssize_t            i;
75
76  sym_link = loc->node_access;
77
78  for( i=0; ((i<bufsize) && (sym_link->name[i] != '\0')); i++ )
79    buf[i] = sym_link->name[i];
80
81  return i;
82}
83
84static int IMFS_stat_sym_link(
85  const rtems_filesystem_location_info_t *loc,
86  struct stat *buf
87)
88{
89  const IMFS_sym_link_t *sym_link = loc->node_access;
90
91  buf->st_size = strlen( sym_link->name );
92
93  return IMFS_stat( loc, buf );
94}
95
96static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
97  .open_h = rtems_filesystem_default_open,
98  .close_h = rtems_filesystem_default_close,
99  .read_h = rtems_filesystem_default_read,
100  .write_h = rtems_filesystem_default_write,
101  .ioctl_h = rtems_filesystem_default_ioctl,
102  .lseek_h = rtems_filesystem_default_lseek,
103  .fstat_h = IMFS_stat_sym_link,
104  .ftruncate_h = rtems_filesystem_default_ftruncate,
105  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
106  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
107  .fcntl_h = rtems_filesystem_default_fcntl,
108  .kqfilter_h = rtems_filesystem_default_kqfilter,
109  .poll_h = rtems_filesystem_default_poll,
110  .readv_h = rtems_filesystem_default_readv,
111  .writev_h = rtems_filesystem_default_writev
112};
113
114static IMFS_jnode_t *IMFS_node_initialize_sym_link(
115  IMFS_jnode_t *node,
116  void *arg
117)
118{
119  IMFS_sym_link_t *sym_link = (IMFS_sym_link_t *) node;
120
121  sym_link->name = arg;
122
123  return node;
124}
125
126static void IMFS_node_destroy_sym_link( IMFS_jnode_t *node )
127{
128  IMFS_sym_link_t *sym_link = (IMFS_sym_link_t *) node;
129
130  free( sym_link->name );
131
132  IMFS_node_destroy_default( node );
133}
134
135static const IMFS_node_control IMFS_node_control_sym_link = {
136  .handlers = &IMFS_link_handlers,
137  .node_initialize = IMFS_node_initialize_sym_link,
138  .node_remove = IMFS_node_remove_default,
139  .node_destroy = IMFS_node_destroy_sym_link
140};
Note: See TracBrowser for help on using the repository browser.