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

4.104.115
Last change on this file since cb4e992 was cb4e992, checked in by Joel Sherrill <joel.sherrill@…>, on 01/19/10 at 19:31:00

2010-01-19 Joel Sherrill <joel.sherrill@…>

  • libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_link.c, libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c: Create special helper method for creating the j-node for the root directory. This lets us assume that every j-node created otherwise has a parent node.
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 *  IMFS_symlink
3 *
4 *  The following rouine creates a new symbolic link node under parent
5 *  with the name given in name.  The node is set to point to the node at
6 *  to_loc.
7 *
8 *  COPYRIGHT (c) 1989-2009.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <errno.h>
23#include <string.h>
24#include <stdlib.h>
25#include "imfs.h"
26#include <rtems/libio_.h>
27#include <rtems/seterr.h>
28
29int IMFS_symlink(
30  rtems_filesystem_location_info_t  *parent_loc,
31  const char                        *link_name,
32  const char                        *node_name
33)
34{
35  IMFS_types_union   info;
36  IMFS_jnode_t      *new_node;
37  char               new_name[ IMFS_NAME_MAX + 1 ];
38  int                i;
39
40  /*
41   * Remove any separators at the end of the string.
42   */
43  IMFS_get_token( node_name, strlen( node_name ), new_name, &i );
44
45  /*
46   * Duplicate link name
47   */
48  info.sym_link.name = strdup(link_name);
49  if (info.sym_link.name == NULL) {
50    rtems_set_errno_and_return_minus_one(ENOMEM);
51  }
52
53  /*
54   *  Create a new link node.
55   *
56   *  NOTE: Coverity CID 22 notes this as a resource leak.
57   *        While technically not a leak, it indicated that IMFS_create_node
58   *        was ONLY passed a NULL when we created the root node.  We
59   *        added a new IMFS_create_root_node() so this path no longer
60   *        existed.  The result was simpler code which should not have
61   *        this path.
62   */
63  new_node = IMFS_create_node(
64    parent_loc,
65    IMFS_SYM_LINK,
66    new_name,
67    ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )),
68    &info
69  );
70
71  if (new_node == NULL) {
72    free(info.sym_link.name);
73    rtems_set_errno_and_return_minus_one(ENOMEM);
74  }
75
76  return 0;
77}
Note: See TracBrowser for help on using the repository browser.