source: rtems/c/src/exec/libcsupport/src/link.c @ d71fcab

4.104.114.84.95
Last change on this file since d71fcab was d71fcab, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/99 at 18:44:40

Added call to freenod to let each filesystem free its own internal
node used to manage file access.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  link() - POSIX 1003.1b - 5.3.4 - Create a new link
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems.h>
16#include <rtems/libio.h>
17#include <errno.h>
18
19#include "libio_.h"
20
21int link(
22  const char *existing,
23  const char *new
24)
25{
26  rtems_filesystem_location_info_t    existing_loc;
27  rtems_filesystem_location_info_t    parent_loc;
28  int                                 i;
29  int                                 result;
30  const char                         *name_start;
31
32  /*
33   * Get the node we are linking to.
34   */
35
36  result = rtems_filesystem_evaluate_path( existing, 0, &existing_loc, TRUE );
37  if ( result != 0 )
38     return -1;
39
40  /*
41   * Get the parent of the node we are creating.
42   */
43
44  rtems_filesystem_get_start_loc( new, &i, &parent_loc );
45  result = (*parent_loc.ops->evalformake)( &new[i], &parent_loc, &name_start );
46  if ( result != 0 ) {
47    if ( existing_loc.ops->freenod )
48      (*existing_loc.ops->freenod)( &parent_loc );
49    set_errno_and_return_minus_one( result );
50  }
51
52  /*
53   *  Check to see if the caller is trying to link across file system
54   *  boundaries.
55   */
56
57  if ( parent_loc.mt_entry != existing_loc.mt_entry ) {
58    if ( existing_loc.ops->freenod )
59      (*existing_loc.ops->freenod)( &existing_loc );
60
61    if ( parent_loc.ops->freenod )
62      (*parent_loc.ops->freenod)( &parent_loc );
63
64    set_errno_and_return_minus_one( EXDEV );
65  }
66
67  if ( !parent_loc.ops->link ) {
68
69    if ( existing_loc.ops->freenod )
70      (*existing_loc.ops->freenod)( &existing_loc );
71
72    if ( parent_loc.ops->freenod )
73      (*parent_loc.ops->freenod)( &parent_loc );
74
75    set_errno_and_return_minus_one( ENOTSUP );
76  }
77
78  result = (*parent_loc.ops->link)( &existing_loc, &parent_loc, name_start );
79 
80  if ( existing_loc.ops->freenod )
81    (*existing_loc.ops->freenod)( &existing_loc );
82
83  if ( parent_loc.ops->freenod )
84    (*parent_loc.ops->freenod)( &parent_loc );
85
86  return result;
87}
88
89/*
90 *  _link_r
91 *
92 *  This is the Newlib dependent reentrant version of link().
93 */
94
95#if defined(RTEMS_NEWLIB)
96
97#include <reent.h>
98
99int _link_r(
100  struct _reent *ptr,
101  const char    *existing,
102  const char    *new
103)
104{
105  return link( existing, new );
106}
107#endif
108
Note: See TracBrowser for help on using the repository browser.