source: rtems/cpukit/libcsupport/src/_rename_r.c @ da154e14

4.11
Last change on this file since da154e14 was da154e14, checked in by Sebastian Huber <sebastian.huber@…>, on May 14, 2012 at 2:55:41 PM

Filesystem: Move operations to mount table entry

The scope of the file system operations is the file system instance.
The scope of the file system node handlers is the file location. The
benefit of moving the operations to the mount table entry is a size
reduction of the file location (rtems_filesystem_location_info_t). The
code size is slightly increased due to additional load instructions.

Restructure rtems_filesystem_mount_table_entry_t to improve cache
efficiency.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 *  _rename_r() - POSIX 1003.1b - 5.3.4 - Rename a file
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  Modifications to support reference counting in the file system are
8 *  Copyright (c) 2012 embedded brains GmbH.
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#if defined(RTEMS_NEWLIB) && !defined(HAVE__RENAME_R)
20
21#include <stdio.h>
22
23#include <rtems/libio_.h>
24
25int _rename_r(
26  struct _reent *ptr __attribute__((unused)),
27  const char    *old,
28  const char    *new
29)
30{
31  int rv = 0;
32  rtems_filesystem_eval_path_context_t old_ctx;
33  int old_eval_flags = 0;
34  rtems_filesystem_location_info_t old_parentloc;
35  int old_parent_eval_flags = RTEMS_FS_PERMS_WRITE
36    | RTEMS_FS_FOLLOW_HARD_LINK;
37  const rtems_filesystem_location_info_t *old_currentloc =
38    rtems_filesystem_eval_path_start_with_parent(
39      &old_ctx,
40      old,
41      old_eval_flags,
42      &old_parentloc,
43      old_parent_eval_flags
44    );
45  rtems_filesystem_eval_path_context_t new_ctx;
46
47  /* FIXME: This is not POSIX conform */
48  int new_eval_flags = RTEMS_FS_FOLLOW_HARD_LINK
49    | RTEMS_FS_MAKE
50    | RTEMS_FS_EXCLUSIVE;
51
52  const rtems_filesystem_location_info_t *new_currentloc =
53    rtems_filesystem_eval_path_start( &new_ctx, new, new_eval_flags );
54
55  rv = rtems_filesystem_location_exists_in_same_fs_instance_as(
56    old_currentloc,
57    new_currentloc
58  );
59  if ( rv == 0 ) {
60    rv = (*new_currentloc->mt_entry->ops->rename_h)(
61      &old_parentloc,
62      old_currentloc,
63      new_currentloc,
64      rtems_filesystem_eval_path_get_token( &new_ctx ),
65      rtems_filesystem_eval_path_get_tokenlen( &new_ctx )
66    );
67  }
68
69  rtems_filesystem_eval_path_cleanup_with_parent( &old_ctx, &old_parentloc );
70  rtems_filesystem_eval_path_cleanup( &new_ctx );
71
72  return rv;
73}
74#endif
Note: See TracBrowser for help on using the repository browser.