diff options
Diffstat (limited to 'cpukit/include')
-rw-r--r-- | cpukit/include/rtems/fs.h | 59 | ||||
-rw-r--r-- | cpukit/include/rtems/userenv.h | 95 |
2 files changed, 119 insertions, 35 deletions
diff --git a/cpukit/include/rtems/fs.h b/cpukit/include/rtems/fs.h index 84b18370b5..bf5026f645 100644 --- a/cpukit/include/rtems/fs.h +++ b/cpukit/include/rtems/fs.h @@ -8,6 +8,9 @@ * COPYRIGHT (c) 1989-2011. * 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. @@ -18,6 +21,8 @@ #ifndef _RTEMS_FS_H #define _RTEMS_FS_H +#include <rtems/chain.h> + #ifdef __cplusplus extern "C" { #endif @@ -31,9 +36,6 @@ extern "C" { /* FIXME: shouldn't this better not be here? */ typedef struct rtems_libio_tt rtems_libio_t; -typedef struct rtems_filesystem_location_info_tt - rtems_filesystem_location_info_t; - struct rtems_filesystem_mount_table_entry_tt; typedef struct rtems_filesystem_mount_table_entry_tt rtems_filesystem_mount_table_entry_t; @@ -43,18 +45,57 @@ typedef struct _rtems_filesystem_file_handlers_r typedef struct _rtems_filesystem_operations_table rtems_filesystem_operations_table; -/* - * Structure used to determine a location/filesystem in the tree. +/** + * @brief File system location. + * + * @ingroup LibIO */ - -struct rtems_filesystem_location_info_tt -{ +typedef struct rtems_filesystem_location_info_tt { + rtems_chain_node mt_entry_node; void *node_access; void *node_access_2; const rtems_filesystem_file_handlers_r *handlers; const rtems_filesystem_operations_table *ops; rtems_filesystem_mount_table_entry_t *mt_entry; -}; +} rtems_filesystem_location_info_t; + +/** + * @brief Global file system location. + * + * @ingroup LibIO + * + * The global file system locations are used for + * - the mount point location in the mount table entry, + * - the file system root location in the mount table entry, + * - the root directory location in the user environment, and + * - the current directory location in the user environment. + * + * During the path evaluation global start locations are obtained to ensure + * that the current file system will be not unmounted in the meantime. + * + * To support a release within critical sections of the operating system a + * deferred release is supported. This is similar to malloc() and free(). + * + * @see rtems_filesystem_global_location_obtain() and + * rtems_filesystem_global_location_release(). + */ +typedef struct rtems_filesystem_global_location_t { + rtems_filesystem_location_info_t location; + int reference_count; + + /** + * A release within a critical section of the operating system will add this + * location to a list of deferred released locations. This list is processed + * in the next rtems_filesystem_global_location_obtain() in FIFO order. + */ + struct rtems_filesystem_global_location_t *deferred_released_next; + + /** + * A release within a critical section can happen multiple times. This field + * counts the deferred releases. + */ + int deferred_released_count; +} rtems_filesystem_global_location_t; /* * Return the mount table entry for a path location. diff --git a/cpukit/include/rtems/userenv.h b/cpukit/include/rtems/userenv.h index 28ac69ebd3..123da98af5 100644 --- a/cpukit/include/rtems/userenv.h +++ b/cpukit/include/rtems/userenv.h @@ -1,13 +1,16 @@ /** - * @file rtems/userenv.h + * @file * - * This file defines the interface for POSIX per-process environment. + * @ingroup LibIOEnv */ /* * COPYRIGHT (c) 1989-2011. * 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. @@ -18,6 +21,13 @@ #ifndef _RTEMS_USERENV_H #define _RTEMS_USERENV_H +/* + * According to IEEE Std 1003.1-2001, + * limits.h is supposed to provide _POSIX_LOGIN_NAME_MAX + * XXX: We do not rely on this. + */ +#include <limits.h> + #include <rtems.h> #include <rtems/fs.h> @@ -25,33 +35,30 @@ extern "C" { #endif -/* - * External structures - */ - -/* - * According to IEEE Std 1003.1-2001, - * limits.h is supposed to provide _POSIX_LOGIN_NAME_MAX - * FIXME: We should not rely on this. +/** + * @defgroup LibIOEnv User Environment + * + * @ingroup LibIO + * + * @brief Provides a POSIX like user environment for tasks. + * + * @{ */ -#include <limits.h> #ifndef LOGIN_NAME_MAX -#ifdef _POSIX_LOGIN_NAME_MAX -#define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX -#else -/* Fallback */ -#define LOGIN_NAME_MAX 9 -#endif + #ifdef _POSIX_LOGIN_NAME_MAX + #define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX + #else + /* Fallback */ + #define LOGIN_NAME_MAX 9 + #endif #endif typedef struct { - rtems_id task_id; - rtems_filesystem_location_info_t current_directory; - rtems_filesystem_location_info_t root_directory; + rtems_filesystem_global_location_t *current_directory; + rtems_filesystem_global_location_t *root_directory; /* Default mode for all files. */ mode_t umask; - nlink_t link_counts; /* _POSIX_types */ uid_t uid; gid_t gid; @@ -59,6 +66,9 @@ typedef struct { gid_t egid; char login_buffer[LOGIN_NAME_MAX]; pid_t pgrp; /* process group id */ + /* User environment maintenance */ + rtems_id task_id; + int reference_count; } rtems_user_env_t; extern rtems_user_env_t * rtems_current_user_env; @@ -66,7 +76,6 @@ extern rtems_user_env_t rtems_global_user_env; #define rtems_filesystem_current (rtems_current_user_env->current_directory) #define rtems_filesystem_root (rtems_current_user_env->root_directory) -#define rtems_filesystem_link_counts (rtems_current_user_env->link_counts) #define rtems_filesystem_umask (rtems_current_user_env->umask) #define _POSIX_types_Uid (rtems_current_user_env->uid) @@ -75,14 +84,48 @@ extern rtems_user_env_t rtems_global_user_env; #define _POSIX_types_Egid (rtems_current_user_env->egid) #define _POSIX_types_Getlogin_buffer (rtems_current_user_env->login_buffer) - -/* - * Instantiate a private copy of the per user information for the calling task. +/** + * @brief Creates a private environment. + * + * If the task has already a private environment nothing will be changed. This + * function must be called from normal thread context and may block on a mutex. + * Thread dispatching is disabled to protect some critical sections. + * + * @retval RTEMS_SUCCESSFUL Successful operation. + * @retval RTEMS_NO_MEMORY Not enough memory. + * @retval RTEMS_UNSATISFIED Cloning of the current environment failed. + * @retval RTEMS_TOO_MANY Cannot register the private environment. */ - rtems_status_code rtems_libio_set_private_env(void); + +/** + * @brief Creates a private environment shared with another task. + * + * An attempt to share the environment with itself has no effect. This + * function must be called from normal thread context and may block on a mutex. + * Thread dispatching is disabled to protect some critical sections. + * + * @param[in] task_id The private environment is shared with the task specified + * by this identifier. + * + * @retval RTEMS_SUCCESSFUL Successful operation. + * @retval RTEMS_UNSATISFIED No shared environment is available for this task + * @retval RTEMS_TOO_MANY Cannot register the shared environment. + * identifier. + */ rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ; +/** + * @brief Use the global environment. + * + * A private environment will be released. This function may be called from + * every thread context. Thread dispatching is disabled to protect the + * critical sections. + */ +void rtems_libio_use_global_env(void); + +/** @} */ + #ifdef __cplusplus } #endif |