source: rtems/cpukit/libcsupport/src/fchdir.c @ 690861c

4.104.114.84.95
Last change on this file since 690861c was 0eae36c7, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:54:13

2003-09-04 Joel Sherrill <joel@…>

  • include/chain.h, include/clockdrv.h, include/console.h, include/iosupp.h, include/rtc.h, include/spurious.h, include/timerdrv.h, include/vmeintr.h, include/motorola/mc68230.h, include/rtems/libcsupport.h, include/rtems/libio.h, include/rtems/libio_.h, include/rtems/termiostypes.h, include/sys/termios.h, include/zilog/z8036.h, include/zilog/z8530.h, include/zilog/z8536.h, src/brk.c, src/gettod.c, src/sbrk.c, src/times.c, src/access.c, src/base_fs.c, src/cfgetispeed.c, src/cfgetospeed.c, src/cfsetispeed.c, src/cfsetospeed.c, src/chdir.c, src/chmod.c, src/chown.c, src/chroot.c, src/close.c, src/ctermid.c, src/dup.c, src/dup2.c, src/eval.c, src/fchdir.c, src/fchmod.c, src/fcntl.c, src/fdatasync.c, src/fpathconf.c, src/fs_null_handlers.c, src/fstat.c, src/fsync.c, src/ftruncate.c, src/getdents.c, src/getpwent.c, src/hosterr.c, src/ioctl.c, src/isatty.c, src/libio.c, src/libio_sockets.c, src/link.c, src/lseek.c, src/lstat.c, src/malloc.c, src/mallocfreespace.c, src/mkdir.c, src/mkfifo.c, src/mknod.c, src/mount.c, src/newlibc.c, src/no_libc.c, src/no_posix.c, src/open.c, src/pathconf.c, src/pipe.c, src/privateenv.c, src/read.c, src/readlink.c, src/rewinddir.c, src/rmdir.c, src/seekdir.c, src/stat.c, src/symlink.c, src/sync.c, src/tcdrain.c, src/tcflow.c, src/tcflush.c, src/tcgetattr.c, src/tcgetprgrp.c, src/tcsendbreak.c, src/tcsetattr.c, src/tcsetpgrp.c, src/telldir.c, src/termios.c, src/termiosinitialize.c, src/truncate.c, src/umask.c, src/unixlibc.c, src/unlink.c, src/unmount.c, src/utime.c, src/write.c: URL for license changed.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  fchdir() - compatible with SVr4, 4.4BSD and X/OPEN - Change Directory
3 *
4 *  COPYRIGHT (c) 1989-2000.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <unistd.h>
19#include <sys/stat.h>
20#include <errno.h>
21
22#include <rtems.h>
23#include <rtems/libio.h>
24#include <rtems/libio_.h>
25#include <rtems/seterr.h>
26
27int fchdir(
28  int       fd
29)
30{
31  rtems_libio_t *iop;
32  rtems_filesystem_location_info_t loc, saved;
33 
34  rtems_libio_check_fd( fd );
35  iop = rtems_libio_iop( fd );
36  rtems_libio_check_is_open(iop);
37
38  /*
39   *  Now process the fchmod().
40   */
41
42  rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
43
44  /*
45   * Verify you can change directory into this node.
46   */
47
48  if ( !iop->pathinfo.ops ) {
49    rtems_set_errno_and_return_minus_one( ENOTSUP );
50  }
51
52  if ( !iop->pathinfo.ops->node_type_h ) {
53    rtems_set_errno_and_return_minus_one( ENOTSUP );
54  }
55
56  if (  (*iop->pathinfo.ops->node_type_h)( &iop->pathinfo ) !=
57                                          RTEMS_FILESYSTEM_DIRECTORY ) {
58    rtems_set_errno_and_return_minus_one( ENOTDIR );
59  }
60 
61
62  /*
63   * FIXME : I feel there should be another call to
64   *         actually take into account the extra reference to
65   *         this node which we are making here. I can
66   *         see the freenode interface but do not see
67   *         allocnode node interface. It maybe node_type.
68   *
69   * FIXED:  T.Straumann: it is evaluate_path()
70   *         but note the race condition. Threads who
71   *         share their rtems_filesystem_current better
72   *         be synchronized!
73   */
74 
75  saved                    = rtems_filesystem_current;
76  rtems_filesystem_current = iop->pathinfo;
77 
78  /* clone the current node */
79  if (rtems_filesystem_evaluate_path(".", 0, &loc, 0)) {
80    /* cloning failed; restore original and bail out */
81    rtems_filesystem_current = saved;
82        return -1;
83  }
84  /* release the old one */
85  rtems_filesystem_freenode( &saved );
86
87  rtems_filesystem_current = loc;
88 
89  return 0;
90}
Note: See TracBrowser for help on using the repository browser.