source: rtems/cpukit/libfs/src/imfs/imfs_symlink.c @ 9247d3f

4.115
Last change on this file since 9247d3f was 9247d3f, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 5, 2015 at 3:58:09 PM

IMFS: Simplify IMFS_symlink()

  • Property mode set to 100644
File size: 2.8 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 <string.h>
24
25static const IMFS_node_control IMFS_node_control_sym_link;
26
27int IMFS_symlink(
28  const rtems_filesystem_location_info_t *parentloc,
29  const char *name,
30  size_t namelen,
31  const char *target
32)
33{
34  IMFS_jnode_t *new_node;
35
36  /*
37   *  Create a new link node.
38   */
39  new_node = IMFS_create_node(
40    parentloc,
41    &IMFS_node_control_sym_link,
42    sizeof( IMFS_sym_link_t ) + strlen( target ) + 1,
43    name,
44    namelen,
45    ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )),
46    RTEMS_DECONST( char *, target )
47  );
48
49  if ( new_node == NULL ) {
50    rtems_set_errno_and_return_minus_one( ENOMEM );
51  }
52
53  return 0;
54}
55
56ssize_t IMFS_readlink(
57  const rtems_filesystem_location_info_t *loc,
58  char *buf,
59  size_t bufsize
60)
61{
62  IMFS_sym_link_t   *sym_link;
63  ssize_t            i;
64
65  sym_link = loc->node_access;
66
67  for( i=0; ((i<bufsize) && (sym_link->name[i] != '\0')); i++ )
68    buf[i] = sym_link->name[i];
69
70  return i;
71}
72
73static int IMFS_stat_sym_link(
74  const rtems_filesystem_location_info_t *loc,
75  struct stat *buf
76)
77{
78  const IMFS_sym_link_t *sym_link = loc->node_access;
79
80  buf->st_size = strlen( sym_link->name );
81
82  return IMFS_stat( loc, buf );
83}
84
85static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
86  .open_h = rtems_filesystem_default_open,
87  .close_h = rtems_filesystem_default_close,
88  .read_h = rtems_filesystem_default_read,
89  .write_h = rtems_filesystem_default_write,
90  .ioctl_h = rtems_filesystem_default_ioctl,
91  .lseek_h = rtems_filesystem_default_lseek,
92  .fstat_h = IMFS_stat_sym_link,
93  .ftruncate_h = rtems_filesystem_default_ftruncate,
94  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
95  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
96  .fcntl_h = rtems_filesystem_default_fcntl,
97  .kqfilter_h = rtems_filesystem_default_kqfilter,
98  .poll_h = rtems_filesystem_default_poll,
99  .readv_h = rtems_filesystem_default_readv,
100  .writev_h = rtems_filesystem_default_writev
101};
102
103static IMFS_jnode_t *IMFS_node_initialize_sym_link(
104  IMFS_jnode_t *node,
105  void *arg
106)
107{
108  IMFS_sym_link_t *sym_link = (IMFS_sym_link_t *) node;
109
110  sym_link->name = (char *) sym_link + sizeof( *sym_link );
111  strcpy( sym_link->name, arg );
112
113  return node;
114}
115
116static const IMFS_node_control IMFS_node_control_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_default
121};
Note: See TracBrowser for help on using the repository browser.