From c625a641218fbda23582354b3cfc7a7c7a4e4287 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Sun, 21 Dec 2014 20:12:28 +0100 Subject: Filesystem: Delete node type operation Use the fstat handler instead. --- cpukit/libcsupport/Makefile.am | 1 - cpukit/libcsupport/include/rtems/libio.h | 35 --------------------------- cpukit/libcsupport/include/rtems/libio_.h | 35 +++++++++++++++------------ cpukit/libcsupport/src/__usrenv.c | 1 - cpukit/libcsupport/src/chdir.c | 5 ++-- cpukit/libcsupport/src/chroot.c | 7 ++---- cpukit/libcsupport/src/getdents.c | 6 ++--- cpukit/libcsupport/src/open.c | 5 ++-- cpukit/libcsupport/src/readlink.c | 4 ++-- cpukit/libcsupport/src/rmdir.c | 4 ++-- cpukit/libcsupport/src/sup_fs_node_type.c | 39 ------------------------------- 11 files changed, 33 insertions(+), 109 deletions(-) delete mode 100644 cpukit/libcsupport/src/sup_fs_node_type.c (limited to 'cpukit/libcsupport') diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index 1486194aa7..77efdbbf14 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -139,7 +139,6 @@ libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \ src/sup_fs_next_token.c \ src/sup_fs_exist_in_same_instance.c \ src/sup_fs_mount_iterate.c \ - src/sup_fs_node_type.c \ src/sup_fs_deviceio.c \ src/clonenode.c \ src/freenode.c \ diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h index dabee60910..a4607de0e9 100644 --- a/cpukit/libcsupport/include/rtems/libio.h +++ b/cpukit/libcsupport/include/rtems/libio.h @@ -53,18 +53,6 @@ struct knote; */ /**@{**/ -/** - * @brief File system node types. - */ -typedef enum { - RTEMS_FILESYSTEM_DIRECTORY, - RTEMS_FILESYSTEM_DEVICE, - RTEMS_FILESYSTEM_HARD_LINK, - RTEMS_FILESYSTEM_SYM_LINK, - RTEMS_FILESYSTEM_MEMORY_FILE, - RTEMS_FILESYSTEM_INVALID_NODE_TYPE -} rtems_filesystem_node_types_t; - /** * @brief Locks a file system instance. * @@ -342,19 +330,6 @@ typedef bool (*rtems_filesystem_are_nodes_equal_t)( const rtems_filesystem_location_info_t *b ); -/** - * @brief Returns the node type. - * - * @param[in] loc The location of the node. - * - * @return Type of the node. - * - * @see rtems_filesystem_default_node_type(). - */ -typedef rtems_filesystem_node_types_t (*rtems_filesystem_node_type_t)( - const rtems_filesystem_location_info_t *loc -); - /** * @brief Creates a new node. * @@ -499,7 +474,6 @@ struct _rtems_filesystem_operations_table { rtems_filesystem_eval_path_t eval_path_h; rtems_filesystem_link_t link_h; rtems_filesystem_are_nodes_equal_t are_nodes_equal_h; - rtems_filesystem_node_type_t node_type_h; rtems_filesystem_mknod_t mknod_h; rtems_filesystem_rmnod_t rmnod_h; rtems_filesystem_fchmod_t fchmod_h; @@ -580,15 +554,6 @@ bool rtems_filesystem_default_are_nodes_equal( const rtems_filesystem_location_info_t *b ); -/** - * @retval RTEMS_FILESYSTEM_INVALID_NODE_TYPE Always. - * - * @see rtems_filesystem_node_type_t. - */ -rtems_filesystem_node_types_t rtems_filesystem_default_node_type( - const rtems_filesystem_location_info_t *pathloc -); - /** * @retval -1 Always. The errno is set to ENOTSUP. * diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h index 458201ea3f..e204508cf1 100644 --- a/cpukit/libcsupport/include/rtems/libio_.h +++ b/cpukit/libcsupport/include/rtems/libio_.h @@ -205,21 +205,6 @@ void rtems_filesystem_location_clone( const rtems_filesystem_location_info_t *master ); -/** - * @brief Returns the type of a node. - * - * This function obtains and releases the file system instance lock. - * - * @param[in] loc The location of the node. - * - * @retval type The node type. - * - * @see rtems_filesystem_instance_lock(). - */ -rtems_filesystem_node_types_t rtems_filesystem_node_type( - const rtems_filesystem_location_info_t *loc -); - /** * @brief Releases all resources of a location. * @@ -919,6 +904,26 @@ static inline ssize_t rtems_libio_iovec_eval( return total; } +/** + * @brief Returns the file type of the file referenced by the filesystem + * location. + * + * @brief[in] loc The filesystem location. + * + * @return The type of the file or an invalid file type in case of an error. + */ +static inline mode_t rtems_filesystem_location_type( + const rtems_filesystem_location_info_t *loc +) +{ + struct stat st; + + st.st_mode = 0; + (void) ( *loc->handlers->fstat_h )( loc, &st ); + + return st.st_mode; +} + /** @} */ #ifdef __cplusplus diff --git a/cpukit/libcsupport/src/__usrenv.c b/cpukit/libcsupport/src/__usrenv.c index d032aea4ab..8fd107e011 100644 --- a/cpukit/libcsupport/src/__usrenv.c +++ b/cpukit/libcsupport/src/__usrenv.c @@ -203,7 +203,6 @@ static const rtems_filesystem_operations_table null_ops = { .eval_path_h = rtems_filesystem_default_eval_path, .link_h = null_op_link, .are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal, - .node_type_h = rtems_filesystem_default_node_type, .mknod_h = null_op_mknod, .rmnod_h = null_op_rmnod, .fchmod_h = null_op_fchmod, diff --git a/cpukit/libcsupport/src/chdir.c b/cpukit/libcsupport/src/chdir.c index 2a1c3c4806..4bcb30075e 100644 --- a/cpukit/libcsupport/src/chdir.c +++ b/cpukit/libcsupport/src/chdir.c @@ -30,10 +30,9 @@ int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc ) 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 ); + mode_t type = rtems_filesystem_location_type( &global_loc->location ); - if ( type == RTEMS_FILESYSTEM_DIRECTORY ) { + if ( S_ISDIR( type ) ) { rtems_filesystem_global_location_assign( &rtems_filesystem_current, global_loc diff --git a/cpukit/libcsupport/src/chroot.c b/cpukit/libcsupport/src/chroot.c index e1f83d34ab..b7c2891f6a 100644 --- a/cpukit/libcsupport/src/chroot.c +++ b/cpukit/libcsupport/src/chroot.c @@ -54,12 +54,9 @@ int chroot( const char *path ) if ( !rtems_filesystem_global_location_is_null( new_current_loc ) ) { rtems_filesystem_global_location_t *new_root_loc = rtems_filesystem_global_location_obtain( &new_current_loc ); - rtems_filesystem_node_types_t type = - (*new_root_loc->location.mt_entry->ops->node_type_h)( - &new_root_loc->location - ); + mode_t type = rtems_filesystem_location_type( &new_root_loc->location ); - if ( type == RTEMS_FILESYSTEM_DIRECTORY ) { + if ( S_ISDIR( type ) ) { sc = rtems_libio_set_private_env(); if (sc == RTEMS_SUCCESSFUL) { rtems_filesystem_global_location_assign( diff --git a/cpukit/libcsupport/src/getdents.c b/cpukit/libcsupport/src/getdents.c index be1969faa4..7008def316 100644 --- a/cpukit/libcsupport/src/getdents.c +++ b/cpukit/libcsupport/src/getdents.c @@ -47,7 +47,7 @@ int getdents( ) { rtems_libio_t *iop; - rtems_filesystem_node_types_t type; + mode_t type; /* * Get the file control block structure associated with the file descriptor @@ -57,8 +57,8 @@ int getdents( /* * Make sure we are working on a directory */ - type = rtems_filesystem_node_type( &iop->pathinfo ); - if ( type != RTEMS_FILESYSTEM_DIRECTORY ) + type = rtems_filesystem_location_type( &iop->pathinfo ); + if ( !S_ISDIR( type ) ) rtems_set_errno_and_return_minus_one( ENOTDIR ); /* diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c index 042d405f1d..399b5a4eac 100644 --- a/cpukit/libcsupport/src/open.c +++ b/cpukit/libcsupport/src/open.c @@ -89,10 +89,9 @@ static int do_open( if ( write_access ) { const rtems_filesystem_location_info_t *currentloc = rtems_filesystem_eval_path_get_currentloc( &ctx ); - rtems_filesystem_node_types_t type = - (*currentloc->mt_entry->ops->node_type_h)( currentloc ); + mode_t type = rtems_filesystem_location_type( currentloc ); - if ( type == RTEMS_FILESYSTEM_DIRECTORY ) { + if ( S_ISDIR( type ) ) { rtems_filesystem_eval_path_error( &ctx, EISDIR ); } } diff --git a/cpukit/libcsupport/src/readlink.c b/cpukit/libcsupport/src/readlink.c index a43cb2cdf9..71a9d0d726 100644 --- a/cpukit/libcsupport/src/readlink.c +++ b/cpukit/libcsupport/src/readlink.c @@ -34,9 +34,9 @@ ssize_t readlink( const char *__restrict path, char *__restrict buf, const rtems_filesystem_location_info_t *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops; - rtems_filesystem_node_types_t type = (*ops->node_type_h)( currentloc ); + mode_t type = rtems_filesystem_location_type( currentloc ); - if ( type == RTEMS_FILESYSTEM_SYM_LINK ) { + if ( S_ISLNK( type ) ) { rv = (*ops->readlink_h)( currentloc, buf, bufsize ); } else { rtems_filesystem_eval_path_error( &ctx, EINVAL ); diff --git a/cpukit/libcsupport/src/rmdir.c b/cpukit/libcsupport/src/rmdir.c index 50c41d5f74..8aec6f784e 100644 --- a/cpukit/libcsupport/src/rmdir.c +++ b/cpukit/libcsupport/src/rmdir.c @@ -43,9 +43,9 @@ int rmdir( const char *path ) parent_eval_flags ); const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops; - rtems_filesystem_node_types_t type = (*ops->node_type_h)( currentloc ); + mode_t type = rtems_filesystem_location_type( currentloc ); - if ( type == RTEMS_FILESYSTEM_DIRECTORY ) { + if ( S_ISDIR( type ) ) { if ( !rtems_filesystem_location_is_instance_root( currentloc ) ) { rv = (*ops->rmnod_h)( &parentloc, currentloc ); } else { diff --git a/cpukit/libcsupport/src/sup_fs_node_type.c b/cpukit/libcsupport/src/sup_fs_node_type.c deleted file mode 100644 index a86d08e56d..0000000000 --- a/cpukit/libcsupport/src/sup_fs_node_type.c +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @file - * - * @brief Returns the Type of a Node - * @ingroup LibIOInternal - */ - -/* - * Copyright (c) 2012 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -#if HAVE_CONFIG_H - #include "config.h" -#endif - -#include - -rtems_filesystem_node_types_t rtems_filesystem_node_type( - const rtems_filesystem_location_info_t *loc -) -{ - rtems_filesystem_node_types_t type; - - rtems_filesystem_instance_lock(loc); - type = (*loc->mt_entry->ops->node_type_h)(loc); - rtems_filesystem_instance_unlock(loc); - - return type; -} -- cgit v1.2.3