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 | |
---|
27 | int 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->node_type_h)( &iop->pathinfo ) != |
---|
49 | RTEMS_FILESYSTEM_DIRECTORY ) { |
---|
50 | rtems_set_errno_and_return_minus_one( ENOTDIR ); |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | /* |
---|
55 | * FIXME : I feel there should be another call to |
---|
56 | * actually take into account the extra reference to |
---|
57 | * this node which we are making here. I can |
---|
58 | * see the freenode interface but do not see |
---|
59 | * allocnode node interface. It maybe node_type. |
---|
60 | * |
---|
61 | * FIXED: T.Straumann: it is evaluate_path() |
---|
62 | * but note the race condition. Threads who |
---|
63 | * share their rtems_filesystem_current better |
---|
64 | * be synchronized! |
---|
65 | */ |
---|
66 | |
---|
67 | saved = rtems_filesystem_current; |
---|
68 | rtems_filesystem_current = iop->pathinfo; |
---|
69 | |
---|
70 | /* clone the current node */ |
---|
71 | if (rtems_filesystem_evaluate_path(".", 1, 0, &loc, 0)) { |
---|
72 | /* cloning failed; restore original and bail out */ |
---|
73 | rtems_filesystem_current = saved; |
---|
74 | return -1; |
---|
75 | } |
---|
76 | /* release the old one */ |
---|
77 | rtems_filesystem_freenode( &saved ); |
---|
78 | |
---|
79 | rtems_filesystem_current = loc; |
---|
80 | |
---|
81 | return 0; |
---|
82 | } |
---|