diff options
Diffstat (limited to 'cpukit/libcsupport/src/chdir.c')
-rw-r--r-- | cpukit/libcsupport/src/chdir.c | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/cpukit/libcsupport/src/chdir.c b/cpukit/libcsupport/src/chdir.c index c9d05f0bef..df65170936 100644 --- a/cpukit/libcsupport/src/chdir.c +++ b/cpukit/libcsupport/src/chdir.c @@ -4,6 +4,9 @@ * COPYRIGHT (c) 1989-2010. * On-Line Applications Research Corporation (OAR). * + * Modifications to support reference counting in the file system are + * Copyright (c) 2012 embedded brains GmbH. + * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.com/license/LICENSE. @@ -12,46 +15,47 @@ */ #if HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif -#include <rtems.h> - #include <unistd.h> -#include <errno.h> #include <rtems/libio_.h> -#include <rtems/seterr.h> -int chdir( - const char *pathname -) +int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc ) { - rtems_filesystem_location_info_t loc; - int result; - - if ( !pathname ) - rtems_set_errno_and_return_minus_one( EFAULT ); - - /* - * Get the node where we wish to go. - */ - result = rtems_filesystem_evaluate_path( - pathname, strlen( pathname ), RTEMS_LIBIO_PERMS_SEARCH, &loc, true ); - if ( result != 0 ) - return -1; - - /* - * Verify you can change directory into this node. - */ - if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) { - rtems_filesystem_freenode( &loc ); - rtems_set_errno_and_return_minus_one( ENOTDIR ); + int rv = 0; + rtems_filesystem_global_location_t *global_loc = + rtems_filesystem_location_transform_to_global( loc ); + rtems_filesystem_node_types_t type = + rtems_filesystem_node_type( &global_loc->location ); + + if ( type == RTEMS_FILESYSTEM_DIRECTORY ) { + rtems_filesystem_global_location_assign( + &rtems_filesystem_current, + global_loc + ); + } else { + rtems_filesystem_location_error( &global_loc->location, ENOTDIR ); + rtems_filesystem_global_location_release( global_loc ); + rv = -1; } - rtems_filesystem_freenode( &rtems_filesystem_current ); - - rtems_filesystem_current = loc; + return rv; +} - return 0; +int chdir( const char *path ) +{ + int rv = 0; + rtems_filesystem_eval_path_context_t ctx; + int eval_flags = RTEMS_LIBIO_PERMS_EXEC + | RTEMS_LIBIO_FOLLOW_LINK; + rtems_filesystem_location_info_t pathloc; + + rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + rtems_filesystem_eval_path_extract_currentloc( &ctx, &pathloc ); + rv = rtems_filesystem_chdir( &pathloc ); + rtems_filesystem_eval_path_cleanup( &ctx ); + + return rv; } |