summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/include/rtems
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-03-13 11:33:51 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-03-13 12:23:37 +0100
commit3b7c123c8d910eb60ab3b38dec6224e2de9847c9 (patch)
treea67335010c15af5efb5e27224ae9204883c2b5b8 /cpukit/libcsupport/include/rtems
parentAdd missing BSD sections. (diff)
downloadrtems-3b7c123c8d910eb60ab3b38dec6224e2de9847c9.tar.bz2
Filesystem: Reference counting for locations
o A new data structure rtems_filesystem_global_location_t was introduced to be used for o the mount point location in the mount table entry, o the file system root location in the mount table entry, o the root directory location in the user environment, and o the current directory location in the user environment. During the path evaluation global start locations are obtained to ensure that the current file system instance will be not unmounted in the meantime. o The user environment uses now reference counting and is protected from concurrent access. o The path evaluation process was completely rewritten and simplified. The IMFS, RFS, NFS, and DOSFS use now a generic path evaluation method. Recursive calls in the path evaluation have been replaced with iteration to avoid stack overflows. Only the evaluation of symbolic links is recursive. No dynamic memory allocations and intermediate buffers are used in the high level path evaluation. No global locks are held during the file system instance specific path evaluation process. o Recursive symbolic link evaluation is now limited by RTEMS_FILESYSTEM_SYMLOOP_MAX. Applications can retrieve this value via sysconf(). o The device file system (devFS) uses now no global variables and allocation from the workspace. Node names are allocated from the heap. o The upper layer lseek() performs now some parameter checks. o The upper layer ftruncate() performs now some parameter checks. o unmask() is now restricted to the RWX flags and protected from concurrent access. o The fchmod_h and rmnod_h file system node handlers are now a file system operation. o The unlink_h operation has been removed. All nodes are now destroyed with the rmnod_h operation. o New lock_h, unlock_h, clonenod_h, and are_nodes_equal_h file system operations. o The path evaluation and file system operations are now protected by per file system instance lock and unlock operations. o Fix and test file descriptor duplicate in fcntl(). o New test fstests/fsnofs01.
Diffstat (limited to 'cpukit/libcsupport/include/rtems')
-rw-r--r--cpukit/libcsupport/include/rtems/libio.h1623
-rw-r--r--cpukit/libcsupport/include/rtems/libio_.h658
2 files changed, 1442 insertions, 839 deletions
diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h
index 661fe0bc33..4a09e0c18b 100644
--- a/cpukit/libcsupport/include/rtems/libio.h
+++ b/cpukit/libcsupport/include/rtems/libio.h
@@ -10,6 +10,9 @@
* COPYRIGHT (c) 1989-2008.
* 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.
@@ -37,20 +40,15 @@ extern "C" {
#endif
/**
- * @defgroup LibIO IO Library
+ * @defgroup LibIOFSOps File System Operations
*
- * @brief Provides system call and file system interface definitions.
+ * @ingroup LibIO
*
- * General purpose communication channel for RTEMS to allow UNIX/POSIX
- * system call behavior under RTEMS. Initially this supported only
- * IO to devices but has since been enhanced to support networking
- * and support for mounted file systems.
+ * @brief File system operations.
*
* @{
*/
-typedef off_t rtems_off64_t __attribute__((deprecated));
-
/**
* @brief File system node types.
*/
@@ -64,974 +62,1044 @@ typedef enum {
} rtems_filesystem_node_types_t;
/**
- * @name File System Node Operations
+ * @brief Locks a file system instance.
*
- * @{
+ * This lock must allow nesting.
+ *
+ * @param[in, out] mt_entry The mount table entry of the file system instance.
+ *
+ * @see rtems_filesystem_default_lock().
*/
+typedef void (*rtems_filesystem_mt_entry_lock_t)(
+ rtems_filesystem_mount_table_entry_t *mt_entry
+);
/**
- * This type defines the interface to the open(2) system call
- * support which is provided by a file system implementation.
+ * @brief Unlocks a file system instance.
+ *
+ * @param[in, out] mt_entry The mount table entry of the file system instance.
+ *
+ * @see rtems_filesystem_default_unlock().
*/
-typedef int (*rtems_filesystem_open_t)(
- rtems_libio_t *iop,
- const char *pathname,
- uint32_t flag,
- uint32_t mode
+typedef void (*rtems_filesystem_mt_entry_unlock_t)(
+ rtems_filesystem_mount_table_entry_t *mt_entry
);
/**
- * This type defines the interface to the close(2) system call
- * support which is provided by a file system implementation.
+ * @brief Path evaluation context.
*/
-typedef int (*rtems_filesystem_close_t)(
- rtems_libio_t *iop
-);
+typedef struct {
+ /**
+ * The contents of the remaining path to be evaluated.
+ */
+ const char *path;
+
+ /**
+ * The length of the remaining path to be evaluated.
+ */
+ size_t pathlen;
+
+ /**
+ * The contents of the token to be evaluated with respect to the current
+ * location.
+ */
+ const char *token;
+
+ /**
+ * The length of the token to be evaluated with respect to the current
+ * location.
+ */
+ size_t tokenlen;
+
+ /**
+ * The path evaluation is controlled by the following flags
+ * - RTEMS_LIBIO_PERMS_READ,
+ * - RTEMS_LIBIO_PERMS_WRITE,
+ * - RTEMS_LIBIO_PERMS_EXEC,
+ * - RTEMS_LIBIO_PERMS_SEARCH,
+ * - RTEMS_LIBIO_FOLLOW_HARD_LINK,
+ * - RTEMS_LIBIO_FOLLOW_SYM_LINK,
+ * - RTEMS_LIBIO_MAKE,
+ * - RTEMS_LIBIO_EXCLUSIVE,
+ * - RTEMS_LIBIO_ACCEPT_RESIDUAL_DELIMITERS, and
+ * - RTEMS_LIBIO_REJECT_TERMINAL_DOT.
+ */
+ int flags;
+
+ /**
+ * Symbolic link evaluation is a recursive operation. This field helps to
+ * limit the recursion level and thus prevents a stack overflow. The
+ * recursion level is limited by RTEMS_FILESYSTEM_SYMLOOP_MAX.
+ */
+ int recursionlevel;
+
+ /**
+ * This is the current file system location of the evaluation process.
+ * Tokens are evaluated with respect to the current location. The token
+ * interpretation may change the current location. The purpose of the path
+ * evaluation is to change the start location into a final current location
+ * according to the path.
+ */
+ rtems_filesystem_location_info_t currentloc;
+
+ /**
+ * The location of the root directory of the user environment during the
+ * evaluation start.
+ */
+ rtems_filesystem_global_location_t *rootloc;
+
+ /**
+ * The start location of the evaluation process. The start location my
+ * change during symbolic link evaluation.
+ */
+ rtems_filesystem_global_location_t *startloc;
+} rtems_filesystem_eval_path_context_t;
/**
- * This type defines the interface to the read(2) system call
- * support which is provided by a file system implementation.
+ * @brief Path evaluation.
+ *
+ * @param[in, out] ctx The path evaluation context.
+ *
+ * @see rtems_filesystem_default_eval_path().
*/
-typedef ssize_t (*rtems_filesystem_read_t)(
- rtems_libio_t *iop,
- void *buffer,
- size_t count
+typedef void (*rtems_filesystem_eval_path_t)(
+ rtems_filesystem_eval_path_context_t *ctx
);
/**
- * This type defines the interface to the write(2) system call
- * support which is provided by a file system implementation.
+ * @brief Creates a new link for the existing file.
+ *
+ * @param[in] parentloc The location of the parent of the new link.
+ * @param[in] targetloc The location of the target file.
+ * @param[in] name Name for the new link.
+ * @param[in] namelen Length of the name for the new link in characters.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_link().
*/
-typedef ssize_t (*rtems_filesystem_write_t)(
- rtems_libio_t *iop,
- const void *buffer,
- size_t count
+typedef int (*rtems_filesystem_link_t)(
+ const rtems_filesystem_location_info_t *parentloc,
+ const rtems_filesystem_location_info_t *targetloc,
+ const char *name,
+ size_t namelen
);
/**
- * This type defines the interface to the ioctl(2) system call
- * support which is provided by a file system implementation.
+ * @brief Changes the mode of a node.
+ *
+ * @param[in] loc The location of the node.
+ * @param[in] mode The new mode of the node
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_fchmod().
*/
-typedef int (*rtems_filesystem_ioctl_t)(
- rtems_libio_t *iop,
- uint32_t command,
- void *buffer
+typedef int (*rtems_filesystem_fchmod_t)(
+ const rtems_filesystem_location_info_t *loc,
+ mode_t mode
);
/**
- * This type defines the interface to the lseek(2) system call
- * support which is provided by a file system implementation.
+ * @brief Changes owner and group of a node.
+ *
+ * @param[in] loc The location of the node.
+ * @param[in] owner User ID for the node.
+ * @param[in] group Group ID for the node.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_chown().
*/
-typedef off_t (*rtems_filesystem_lseek_t)(
- rtems_libio_t *iop,
- off_t length,
- int whence
+typedef int (*rtems_filesystem_chown_t)(
+ const rtems_filesystem_location_info_t *loc,
+ uid_t owner,
+ gid_t group
);
/**
- * This type defines the interface to the fstat(2) system call
- * support which is provided by a file system implementation.
+ * @brief Clones a location.
+ *
+ * The location is initialized with a bitwise copy of an existing location.
+ * The caller must ensure that this location is protected from a release during
+ * the clone operation. After a successful clone operation the clone will be
+ * added to the location chain of the corresponding mount table entry.
+ *
+ * @param[in, out] loc Location to clone.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_clonenode().
*/
-typedef int (*rtems_filesystem_fstat_t)(
- rtems_filesystem_location_info_t *loc,
- struct stat *buf
+typedef int (*rtems_filesystem_clonenode_t)(
+ rtems_filesystem_location_info_t *loc
);
/**
- * This type defines the interface to the fchmod(2) system call
- * support which is provided by a file system implementation.
+ * @brief Frees the location of a node.
+ *
+ * @param[in] loc The location of the node.
+ *
+ * @see rtems_filesystem_default_freenode().
*/
-typedef int (*rtems_filesystem_fchmod_t)(
- rtems_filesystem_location_info_t *loc,
- mode_t mode
+typedef void (*rtems_filesystem_freenode_t)(
+ const rtems_filesystem_location_info_t *loc
);
/**
- * This type defines the interface to the ftruncate(2) system call
- * support which is provided by a file system implementation.
+ * @brief Mounts a file system instance in a mount point (directory).
+ *
+ * The mount point belongs to the file system instance of the handler and is
+ * specified by a field of the mount table entry. The handler must check that
+ * the mount point is capable of mounting a file system instance. This is the
+ * last step during the mount process. The file system instance is fully
+ * initialized at this point.
+ *
+ * @param[in] mt_entry The mount table entry.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_mount().
*/
-typedef int (*rtems_filesystem_ftruncate_t)(
- rtems_libio_t *iop,
- off_t length
+typedef int (*rtems_filesystem_mount_t) (
+ rtems_filesystem_mount_table_entry_t *mt_entry
);
/**
- * This type defines the interface to the fsync(2) system call
- * support which is provided by a file system implementation.
+ * @brief Initializes a file system instance.
+ *
+ * This function must initialize the file system root node in the mount table
+ * entry.
+ *
+ * @param[in] mt_entry The mount table entry.
+ * @param[in] data The data provided by the user.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
*/
-typedef int (*rtems_filesystem_fsync_t)(
- rtems_libio_t *iop
+typedef int (*rtems_filesystem_fsmount_me_t)(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
);
/**
- * This type defines the interface to the fdatasync(2) system call
- * support which is provided by a file system implementation.
+ * @brief Unmounts a file system instance in a mount point (directory).
+ *
+ * In case this function is successful the file system instance will be marked
+ * as unmounted. The file system instance will be destroyed when the last
+ * reference to it vanishes.
+ *
+ * @param[in] mt_entry The mount table entry.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_unmount().
*/
-typedef int (*rtems_filesystem_fdatasync_t)(
- rtems_libio_t *iop
+typedef int (*rtems_filesystem_unmount_t) (
+ rtems_filesystem_mount_table_entry_t *mt_entry
);
/**
- * This type defines the interface to the fnctl(2) system call
- * support which is provided by a file system implementation.
+ * @brief Destroys a file system instance.
+ *
+ * The mount point node location of the mount table entry is invalid. This
+ * handler must free the file system root location and all remaining resources
+ * of the file system instance.
+ *
+ * @param[in] mt_entry The mount table entry.
+ *
+ * @see rtems_filesystem_default_fsunmount().
*/
-typedef int (*rtems_filesystem_fcntl_t)(
- int cmd,
- rtems_libio_t *iop
+typedef void (*rtems_filesystem_fsunmount_me_t)(
+ rtems_filesystem_mount_table_entry_t *mt_entry
);
-typedef int (*rtems_filesystem_rmnod_t)(
- rtems_filesystem_location_info_t *parent_loc, /* IN */
- rtems_filesystem_location_info_t *pathloc /* IN */
+/**
+ * @brief Tests if the node of one location is equal to the node of the other
+ * location.
+ *
+ * The caller ensures that both nodes are within the same file system instance.
+ *
+ * @param[in] a The one location.
+ * @param[in] b The other location.
+ *
+ * @retval true The nodes of the locations are equal.
+ * @retval false Otherwise.
+ *
+ * @see rtems_filesystem_default_are_nodes_equal().
+ */
+typedef bool (*rtems_filesystem_are_nodes_equal_t)(
+ const rtems_filesystem_location_info_t *a,
+ const rtems_filesystem_location_info_t *b
);
-/** @} */
-
/**
- * @brief File system node operations table.
+ * @brief Returns the node type.
+ *
+ * @param[in] loc The location of the node.
+ *
+ * @return Type of the node.
+ *
+ * @see rtems_filesystem_default_node_type().
*/
-struct _rtems_filesystem_file_handlers_r {
- /**
- * This field points to the file system specific implementation
- * of the support routine for the open(2) system call
- *
- * @note This method must have a filesystem specific implementation.
- *
- * @note There is no default implementation.
- */
- rtems_filesystem_open_t open_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the close(2) system call
- *
- * @note This method is REQUIRED by all file systems.
- *
- * @note There is no default implementation.
- */
- rtems_filesystem_close_t close_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the read(2) system call
- *
- * @note This method must have a filesystem specific implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_read_t read_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the write(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_write_t write_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the ioctl(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_ioctl_t ioctl_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the lseek(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_lseek_t lseek_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the fstat(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_fstat_t fstat_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the fchmod(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_fchmod_t fchmod_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the ftruncate(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_ftruncate_t ftruncate_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the fsync(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_fsync_t fsync_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the fdatasync(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_fdatasync_t fdatasync_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the fcntl(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_fcntl_t fcntl_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the rmnod(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_rmnod_t rmnod_h;
-};
-
-extern const rtems_filesystem_file_handlers_r
-rtems_filesystem_handlers_default;
+typedef rtems_filesystem_node_types_t (*rtems_filesystem_node_type_t)(
+ const rtems_filesystem_location_info_t *loc
+);
/**
- * This method defines the interface to the default open(2)
- * system call support which is provided by a file system
- * implementation.
+ * @brief Creates a new node.
+ *
+ * This handler should create a new node according to the parameters.
+ *
+ * @param[in] parentloc The location of the parent of the new node.
+ * @param[in] name Name for the new node.
+ * @param[in] namelen Length of the name for the new node in characters.
+ * @param[in] mode Mode for the new node.
+ * @param[in] dev Optional device identifier for the new node.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_mknod().
*/
-int rtems_filesystem_default_open(
- rtems_libio_t *iop,
- const char *pathname,
- uint32_t flag,
- uint32_t mode
+typedef int (*rtems_filesystem_mknod_t)(
+ const rtems_filesystem_location_info_t *parentloc,
+ const char *name,
+ size_t namelen,
+ mode_t mode,
+ dev_t dev
);
/**
- * This method defines the interface to the default close(2)
- * system call support which is provided by a file system
- * implementation.
+ * @brief Removes a node.
+ *
+ * @param[in] parentloc The location of the parent of the node.
+ * @param[in] loc The location of the node.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_rmnod().
*/
-int rtems_filesystem_default_close(
- rtems_libio_t *iop
+typedef int (*rtems_filesystem_rmnod_t)(
+ const rtems_filesystem_location_info_t *parentloc,
+ const rtems_filesystem_location_info_t *loc
);
-
/**
- * This method defines the interface to the default read(2)
- * system call support which is provided by a file system
- * implementation.
+ * @brief Set node access and modification times.
+ *
+ * @param[in] loc The location of the node.
+ * @param[in] actime Access time for the node.
+ * @param[in] modtime Modification for the node.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_utime().
*/
-ssize_t rtems_filesystem_default_read(
- rtems_libio_t *iop,
- void *buffer,
- size_t count
+typedef int (*rtems_filesystem_utime_t)(
+ const rtems_filesystem_location_info_t *loc,
+ time_t actime,
+ time_t modtime
);
/**
- * This method defines the interface to the default write(2) system call
- * support which is provided by a file system implementation.
+ * @brief Makes a symbolic link to a node.
+ *
+ * @param[in] parentloc The location of the parent of the new symbolic link.
+ * @param[in] name Name for the new symbolic link.
+ * @param[in] namelen Length of the name for the new symbolic link in
+ * characters.
+ * @param[in] target Contents for the symbolic link.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_symlink().
*/
-ssize_t rtems_filesystem_default_write(
- rtems_libio_t *iop,
- const void *buffer,
- size_t count
+typedef int (*rtems_filesystem_symlink_t)(
+ const rtems_filesystem_location_info_t *parentloc,
+ const char *name,
+ size_t namelen,
+ const char *target
);
/**
- * This method defines the interface to the default ioctl(2) system call
- * support which is provided by a file system implementation.
+ * @brief Reads the contents of a symbolic link.
+ *
+ * @param[in] loc The location of the symbolic link.
+ * @param[out] buf The buffer for the contents.
+ * @param[in] bufsize The size of the buffer in characters.
+ *
+ * @retval non-negative Size of the actual contents in characters.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_readlink().
*/
-int rtems_filesystem_default_ioctl(
- rtems_libio_t *iop,
- uint32_t command,
- void *buffer
+typedef ssize_t (*rtems_filesystem_readlink_t)(
+ const rtems_filesystem_location_info_t *loc,
+ char *buf,
+ size_t bufsize
);
/**
- * This method defines the interface to the default lseek(2) system call
- * support which is provided by a file system implementation.
+ * @brief Renames a node.
+ *
+ * @param[in] oldparentloc The location of the parent of the old node.
+ * @param[in] oldloc The location of the old node.
+ * @param[in] newparentloc The location of the parent of the new node.
+ * @param[in] name Name for the new node.
+ * @param[in] namelen Length of the name for the new node in characters.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_rename().
*/
-off_t rtems_filesystem_default_lseek(
- rtems_libio_t *iop,
- off_t length,
- int whence
+typedef int (*rtems_filesystem_rename_t)(
+ const rtems_filesystem_location_info_t *oldparentloc,
+ const rtems_filesystem_location_info_t *oldloc,
+ const rtems_filesystem_location_info_t *newparentloc,
+ const char *name,
+ size_t namelen
);
/**
- * This method defines the interface to the default fstat(2) system call
- * support which is provided by a file system implementation.
+ * @brief Gets file system information.
+ *
+ * @param[in] loc The location of a node.
+ * @param[out] buf Buffer for file system information.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_statvfs().
*/
-int rtems_filesystem_default_fstat(
- rtems_filesystem_location_info_t *loc,
- struct stat *buf
+typedef int (*rtems_filesystem_statvfs_t)(
+ const rtems_filesystem_location_info_t *loc,
+ struct statvfs *buf
);
/**
- * This method defines the interface to the default fchmod(2) system call
- * support which is provided by a file system implementation.
+ * @brief File system operations table.
*/
-int rtems_filesystem_default_fchmod(
- rtems_filesystem_location_info_t *loc,
- mode_t mode
-);
+struct _rtems_filesystem_operations_table {
+ rtems_filesystem_mt_entry_lock_t lock_h;
+ rtems_filesystem_mt_entry_unlock_t unlock_h;
+ 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;
+ rtems_filesystem_chown_t chown_h;
+ rtems_filesystem_clonenode_t clonenod_h;
+ rtems_filesystem_freenode_t freenod_h;
+ rtems_filesystem_mount_t mount_h;
+ rtems_filesystem_fsmount_me_t fsmount_me_h;
+ rtems_filesystem_unmount_t unmount_h;
+ rtems_filesystem_fsunmount_me_t fsunmount_me_h;
+ rtems_filesystem_utime_t utime_h;
+ rtems_filesystem_symlink_t symlink_h;
+ rtems_filesystem_readlink_t readlink_h;
+ rtems_filesystem_rename_t rename_h;
+ rtems_filesystem_statvfs_t statvfs_h;
+};
/**
- * This method defines the interface to the default ftruncate(2) system call
- * support which is provided by a file system implementation.
+ * @brief File system operations table with default operations.
*/
-int rtems_filesystem_default_ftruncate(
- rtems_libio_t *iop,
- off_t length
-);
+extern const rtems_filesystem_operations_table
+ rtems_filesystem_operations_default;
/**
- * This method defines the interface to the default fsync(2) system call
- * support which is provided by a file system implementation.
+ * @brief Obtains the IO library mutex.
+ *
+ * @see rtems_filesystem_mt_entry_lock_t.
*/
-int rtems_filesystem_default_fsync(
- rtems_libio_t *iop
+void rtems_filesystem_default_lock(
+ rtems_filesystem_mount_table_entry_t *mt_entry
);
/**
- * This method defines the interface to the default fdatasync(2) system call
- * support which is provided by a file system implementation.
+ * @brief Releases the IO library mutex.
+ *
+ * @see rtems_filesystem_mt_entry_unlock_t.
*/
-int rtems_filesystem_default_fdatasync(
- rtems_libio_t *iop
+void rtems_filesystem_default_unlock(
+ rtems_filesystem_mount_table_entry_t *mt_entry
);
/**
- * This method defines the interface to the default fnctl(2) system call
- * support which is provided by a file system implementation.
+ * @brief Terminates the path evaluation and replaces the current location with
+ * the null location.
+ *
+ * @see rtems_filesystem_eval_path_t.
*/
-int rtems_filesystem_default_fcntl(
- int cmd,
- rtems_libio_t *iop
+void rtems_filesystem_default_eval_path(
+ rtems_filesystem_eval_path_context_t *ctx
);
/**
- * This method defines the interface to the default rmnod(2) system call
- * support which is provided by a file system implementation.
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_link_t.
*/
-int rtems_filesystem_default_rmnod(
- rtems_filesystem_location_info_t *parent_loc, /* IN */
- rtems_filesystem_location_info_t *pathloc /* IN */
+int rtems_filesystem_default_link(
+ const rtems_filesystem_location_info_t *parentloc,
+ const rtems_filesystem_location_info_t *targetloc,
+ const char *name,
+ size_t namelen
);
/**
- * @name File System Operations
+ * @brief Tests if the node access pointer of one location is equal to
+ * the node access pointer of the other location.
*
- * @{
+ * @param[in] a The one location.
+ * @param[in] b The other location.
+ *
+ * @retval true The node access pointers of the locations are equal.
+ * @retval false Otherwise.
+ *
+ * @see rtems_filesystem_are_nodes_equal_t.
*/
+bool rtems_filesystem_default_are_nodes_equal(
+ const rtems_filesystem_location_info_t *a,
+ const rtems_filesystem_location_info_t *b
+);
/**
- * This type defines the interface to the mknod(2) system call
- * support which is provided by a file system implementation.
- *
- * @note This routine does not allocate any space and
- * rtems_filesystem_freenode_t is not called by the generic
- * after calling this routine. ie. node_access does not have
- * to contain valid data when the routine returns.
+ * @retval RTEMS_FILESYSTEM_INVALID_NODE_TYPE Always.
+ *
+ * @see rtems_filesystem_node_type_t.
*/
-typedef int (*rtems_filesystem_mknod_t)(
- const char *path, /* IN */
- mode_t mode, /* IN */
- dev_t dev, /* IN */
- rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+rtems_filesystem_node_types_t rtems_filesystem_default_node_type(
+ const rtems_filesystem_location_info_t *pathloc
);
/**
- * This type defines the interface that allows the
- * file system implementation to parse a path and
- * allocate any memory necessary for tracking purposes.
+ * @retval -1 Always. The errno is set to ENOTSUP.
*
- * @note rtems_filesystem_freenode_t must be called by
- * the generic after calling this routine
+ * @see rtems_filesystem_mknod_t.
*/
-typedef int (*rtems_filesystem_evalpath_t)(
- const char *pathname, /* IN */
- size_t pathnamelen, /* IN */
- int flags, /* IN */
- rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+int rtems_filesystem_default_mknod(
+ const rtems_filesystem_location_info_t *parentloc,
+ const char *name,
+ size_t namelen,
+ mode_t mode,
+ dev_t dev
);
/**
- * This type defines the interface that allows the
- * file system implementation to parse a path with the
- * intent of creating a new node and to
- * allocate any memory necessary for tracking purposes.
+ * @retval -1 Always. The errno is set to ENOTSUP.
*
- * @note rtems_filesystem_freenode_t must be called by
- * the generic after calling this routine
+ * @see rtems_filesystem_rmnod_t.
*/
-typedef int (*rtems_filesystem_evalmake_t)(
- const char *path, /* IN */
- rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
- const char **name /* OUT */
+int rtems_filesystem_default_rmnod(
+ const rtems_filesystem_location_info_t *parentloc,
+ const rtems_filesystem_location_info_t *loc
);
/**
- * This type defines the interface to the link(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (*rtems_filesystem_link_t)(
- rtems_filesystem_location_info_t *to_loc, /* IN */
- rtems_filesystem_location_info_t *parent_loc, /* IN */
- const char *name /* IN */
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_fchmod_t.
+ */
+int rtems_filesystem_default_fchmod(
+ const rtems_filesystem_location_info_t *loc,
+ mode_t mode
);
/**
- * This type defines the interface to the unlink(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (*rtems_filesystem_unlink_t)(
- rtems_filesystem_location_info_t *parent_pathloc, /* IN */
- rtems_filesystem_location_info_t *pathloc /* IN */
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_chown_t.
+ */
+int rtems_filesystem_default_chown(
+ const rtems_filesystem_location_info_t *loc,
+ uid_t owner,
+ gid_t group
);
/**
- * This type defines the interface to the chown(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (*rtems_filesystem_chown_t)(
- rtems_filesystem_location_info_t *pathloc, /* IN */
- uid_t owner, /* IN */
- gid_t group /* IN */
+ * @retval 0 Always.
+ *
+ * @see rtems_filesystem_clonenode_t.
+ */
+int rtems_filesystem_default_clonenode(
+ rtems_filesystem_location_info_t *loc
);
/**
- * This type defines the interface to the freenod(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (*rtems_filesystem_freenode_t)(
- rtems_filesystem_location_info_t *pathloc /* IN */
+ * @see rtems_filesystem_freenode_t.
+ */
+void rtems_filesystem_default_freenode(
+ const rtems_filesystem_location_info_t *loc
);
/**
- * This type defines the interface that allows the implemented
- * filesystem ot mount another filesystem at the given location.
- */
-typedef int (* rtems_filesystem_mount_t ) (
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_mount_t.
+ */
+int rtems_filesystem_default_mount (
rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
);
/**
- * This type defines the interface that allows a file system
- * implementation to do any necessary work that is needed when
- * it is being mounted.
- */
-typedef int (* rtems_filesystem_fsmount_me_t )(
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_fsmount_me_t.
+ */
+int rtems_filesystem_default_fsmount(
rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */
const void *data /* IN */
);
/**
- * This type defines the interface allow the filesystem to
- * unmount a filesystem that was mounted at one of its node
- * locations.
- */
-typedef int (* rtems_filesystem_unmount_t ) (
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_unmount_t.
+ */
+int rtems_filesystem_default_unmount(
rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
);
/**
- * This type defines the interface that allows a file system
- * implementation to do any necessary work that is needed when
- * it is being unmounted.
- */
-typedef int (* rtems_filesystem_fsunmount_me_t ) (
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_fsunmount_me_t.
+ */
+void rtems_filesystem_default_fsunmount(
rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
);
/**
- * This type defines the interface that will return the
- * type of a filesystem implementations node.
- */
-typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) (
- rtems_filesystem_location_info_t *pathloc /* IN */
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_utime_t.
+ */
+int rtems_filesystem_default_utime(
+ const rtems_filesystem_location_info_t *loc,
+ time_t actime,
+ time_t modtime
);
/**
- * This type defines the interface to the time(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (* rtems_filesystem_utime_t)(
- rtems_filesystem_location_info_t *pathloc, /* IN */
- time_t actime, /* IN */
- time_t modtime /* IN */
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_symlink_t.
+ */
+int rtems_filesystem_default_symlink(
+ const rtems_filesystem_location_info_t *parentloc,
+ const char *name,
+ size_t namelen,
+ const char *target
);
/**
- * This type defines the interface to the link(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (*rtems_filesystem_evaluate_link_t)(
- rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
- int flags /* IN */
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_readlink_t.
+ */
+ssize_t rtems_filesystem_default_readlink(
+ const rtems_filesystem_location_info_t *loc,
+ char *buf,
+ size_t bufsize
);
/**
- * This type defines the interface to the symlink(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (*rtems_filesystem_symlink_t)(
- rtems_filesystem_location_info_t *loc, /* IN */
- const char *link_name, /* IN */
- const char *node_name
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_rename_t.
+ */
+int rtems_filesystem_default_rename(
+ const rtems_filesystem_location_info_t *oldparentloc,
+ const rtems_filesystem_location_info_t *oldloc,
+ const rtems_filesystem_location_info_t *newparentloc,
+ const char *name,
+ size_t namelen
);
/**
- * This type defines the interface to the readlink(2) system call
- * support which is provided by a file system implementation.
- */
-typedef ssize_t (*rtems_filesystem_readlink_t)(
- rtems_filesystem_location_info_t *loc, /* IN */
- char *buf, /* OUT */
- size_t bufsize
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_statvfs_t.
+ */
+int rtems_filesystem_default_statvfs(
+ const rtems_filesystem_location_info_t *loc,
+ struct statvfs *buf
);
+/** @} */
+
/**
- * This type defines the interface to the name(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (*rtems_filesystem_rename_t)(
- rtems_filesystem_location_info_t *old_parent_loc, /* IN */
- rtems_filesystem_location_info_t *old_loc, /* IN */
- rtems_filesystem_location_info_t *new_parent_loc, /* IN */
- const char *name /* IN */
-);
+ * @defgroup LibIOFSHandler File System Node Handler
+ *
+ * @ingroup LibIO
+ *
+ * @brief File system node handler.
+ *
+ * @{
+ */
/**
- * This type defines the interface to the statvfs(2) system call
- * support which is provided by a file system implementation.
- */
-typedef int (*rtems_filesystem_statvfs_t)(
- rtems_filesystem_location_info_t *loc, /* IN */
- struct statvfs *buf /* OUT */
+ * @brief Opens a node.
+ *
+ * @param[in, out] iop The IO pointer.
+ * @param[in] path The path.
+ * @param[in] oflag The open flags.
+ * @param[in] mode Optional mode for node creation.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_open().
+ */
+typedef int (*rtems_filesystem_open_t)(
+ rtems_libio_t *iop,
+ const char *path,
+ int oflag,
+ mode_t mode
);
-/** @} */
-
/**
- * @brief File system operations table.
+ * @brief Closes a node.
+ *
+ * @param[in, out] iop The IO pointer.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_close().
*/
-struct _rtems_filesystem_operations_table {
+typedef int (*rtems_filesystem_close_t)(
+ rtems_libio_t *iop
+);
- /**
- * This field points to the file system specific implementation
- * of the support routine that evaluates a character path and
- * returns the node assocated with the last node in the path.
- *
- * @note This method must have a filesystem specific implementation.
- *
- * @note There is no default implementation.
- */
- rtems_filesystem_evalpath_t evalpath_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine that evaluates a character path and
- * returns the node assocated with next to the last node in
- * the path. The last node will be the new node to be created.
- *
- * @note This method must have a filesystem specific implementation.
- *
- * @note There is no default implementation.
- */
- rtems_filesystem_evalmake_t evalformake_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the link(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_link_t link_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the unlink(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_unlink_t unlink_h;
-
- /**
- * This field points to the file system specific implementation
- * of a method that returns the node type of the given node.
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_node_type_t node_type_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the link(2) system call
- *
- * @note This method may use a mknod implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_mknod_t mknod_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the link(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_chown_t chown_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the freenod(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_freenode_t freenod_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the mount(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_mount_t mount_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the fsmount(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_fsmount_me_t fsmount_me_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the unmount(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_unmount_t unmount_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the fsunmount(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_fsunmount_me_t fsunmount_me_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the utime(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_utime_t utime_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the eval_link(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_evaluate_link_t eval_link_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the sumlink(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_symlink_t symlink_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the readlink(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_readlink_t readlink_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the rename(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_rename_t rename_h;
-
- /**
- * This field points to the file system specific implementation
- * of the support routine for the statvfs(2) system call
- *
- * @note This method may use a default implementation.
- *
- * @note The default implementation returns -1 and sets
- * errno to ENOTSUP.
- */
- rtems_filesystem_statvfs_t statvfs_h;
-};
+/**
+ * @brief Reads from a node.
+ *
+ * @param[in, out] iop The IO pointer.
+ * @param[out] buffer The buffer for read data.
+ * @param[in] count The size of the buffer in characters.
+ *
+ * @retval non-negative Count of read characters.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_read().
+ */
+typedef ssize_t (*rtems_filesystem_read_t)(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+);
-extern const rtems_filesystem_operations_table
-rtems_filesystem_operations_default;
+/**
+ * @brief Writes to a node.
+ *
+ * @param[in, out] iop The IO pointer.
+ * @param[out] buffer The buffer for write data.
+ * @param[in] count The size of the buffer in characters.
+ *
+ * @retval non-negative Count of written characters.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_write().
+ */
+typedef ssize_t (*rtems_filesystem_write_t)(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of path evaluation.
+ * @brief IO control of a node.
+ *
+ * @param[in, out] iop The IO pointer.
+ * @param[in] request The IO control request.
+ * @param[in, out] buffer The buffer for IO control request data.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_ioctl().
*/
-int rtems_filesystem_default_evalpath(
- const char *pathname,
- size_t pathnamelen,
- int flags,
- rtems_filesystem_location_info_t *pathloc
+typedef int (*rtems_filesystem_ioctl_t)(
+ rtems_libio_t *iop,
+ uint32_t request,
+ void *buffer
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of path evaluation for make.
+ * @brief Moves the read/write file offset.
+ *
+ * @param[in, out] iop The IO pointer.
+ * @param[in] offset The new offset.
+ * @param[in] whence The reference position of the new offset.
+ *
+ * @retval non-negative The new offset from the beginning of the file.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_lseek().
*/
-int rtems_filesystem_default_evalformake(
- const char *path,
- rtems_filesystem_location_info_t *pathloc,
- const char **name
+typedef off_t (*rtems_filesystem_lseek_t)(
+ rtems_libio_t *iop,
+ off_t offset,
+ int whence
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a link command.
+ * @brief Gets a node status.
+ *
+ * @param[in, out] iop The IO pointer.
+ * @param[out] stat The buffer to status information.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_fstat().
*/
-int rtems_filesystem_default_link(
- rtems_filesystem_location_info_t *to_loc, /* IN */
- rtems_filesystem_location_info_t *parent_loc, /* IN */
- const char *name /* IN */
+typedef int (*rtems_filesystem_fstat_t)(
+ const rtems_filesystem_location_info_t *loc,
+ struct stat *buf
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a unlink command.
+ * @brief Truncates a file to a specified length.
+ *
+ * @param[in, out] iop The IO pointer.
+ * @param[in] length The new length in characters.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_ftruncate() and
+ * rtems_filesystem_default_ftruncate_directory().
*/
-int rtems_filesystem_default_unlink(
- rtems_filesystem_location_info_t *parent_pathloc, /* IN */
- rtems_filesystem_location_info_t *pathloc /* IN */
+typedef int (*rtems_filesystem_ftruncate_t)(
+ rtems_libio_t *iop,
+ off_t length
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation to determine the node type.
+ * @brief Synchronizes changes to a file.
+ *
+ * @param[in, out] iop The IO pointer.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_fsync().
*/
-rtems_filesystem_node_types_t rtems_filesystem_default_node_type(
- rtems_filesystem_location_info_t *pathloc
+typedef int (*rtems_filesystem_fsync_t)(
+ rtems_libio_t *iop
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation to create a new node.
+ * @brief Synchronizes the data of a file.
+ *
+ * @param[in, out] iop The IO pointer.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The errno is set to indicate the error.
+ *
+ * @see rtems_filesystem_default_fdatasync().
*/
-int rtems_filesystem_default_mknod(
- const char *path, /* IN */
- mode_t mode, /* IN */
- dev_t dev, /* IN */
- rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+typedef int (*rtems_filesystem_fdatasync_t)(
+ rtems_libio_t *iop
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a chown command.
+ * @brief File control.
+ *
+ * @param[in, out] iop The IO pointer.
+ * @param[in] cmd Control command.
+ *
+ * @retval 0 Successful operation.
+ * @retval errno An error occured. This value is assigned to errno.
+ *
+ * @see rtems_filesystem_default_fcntl().
*/
-int rtems_filesystem_default_chown(
- rtems_filesystem_location_info_t *pathloc, /* IN */
- uid_t owner, /* IN */
- gid_t group /* IN */
+typedef int (*rtems_filesystem_fcntl_t)(
+ rtems_libio_t *iop,
+ int cmd
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a freenode command.
+ * @brief File system node operations table.
+ */
+struct _rtems_filesystem_file_handlers_r {
+ rtems_filesystem_open_t open_h;
+ rtems_filesystem_close_t close_h;
+ rtems_filesystem_read_t read_h;
+ rtems_filesystem_write_t write_h;
+ rtems_filesystem_ioctl_t ioctl_h;
+ rtems_filesystem_lseek_t lseek_h;
+ rtems_filesystem_fstat_t fstat_h;
+ rtems_filesystem_ftruncate_t ftruncate_h;
+ rtems_filesystem_fsync_t fsync_h;
+ rtems_filesystem_fdatasync_t fdatasync_h;
+ rtems_filesystem_fcntl_t fcntl_h;
+};
+
+/**
+ * @brief File system node handler table with default node handlers.
+ */
+extern const rtems_filesystem_file_handlers_r
+ rtems_filesystem_handlers_default;
+
+/**
+ * @retval 0 Always.
+ *
+ * @see rtems_filesystem_open_t.
*/
-int rtems_filesystem_default_freenode(
- rtems_filesystem_location_info_t *pathloc /* IN */
+int rtems_filesystem_default_open(
+ rtems_libio_t *iop,
+ const char *path,
+ int oflag,
+ mode_t mode
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a mount command.
+ * @retval 0 Always.
+ *
+ * @see rtems_filesystem_close_t.
*/
-int rtems_filesystem_default_mount (
- rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+int rtems_filesystem_default_close(
+ rtems_libio_t *iop
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a fsmount command.
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_read_t.
*/
-int rtems_filesystem_default_fsmount(
- rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */
- const void *data /* IN */
+ssize_t rtems_filesystem_default_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a unmount command.
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_write_t.
*/
-int rtems_filesystem_default_unmount(
- rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+ssize_t rtems_filesystem_default_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a fsunmount command.
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_ioctl_t.
*/
-int rtems_filesystem_default_fsunmount(
- rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+int rtems_filesystem_default_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
);
+/**
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_lseek_t.
+ */
+off_t rtems_filesystem_default_lseek(
+ rtems_libio_t *iop,
+ off_t length,
+ int whence
+);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a utime command.
+ * @brief Sets the mode to S_IRWXU | S_IRWXG | S_IRWXO.
+ *
+ * @retval 0 Always.
+ *
+ * @see rtems_filesystem_fstat_t.
*/
-int rtems_filesystem_default_utime(
- rtems_filesystem_location_info_t *pathloc, /* IN */
- time_t actime, /* IN */
- time_t modtime /* IN */
+int rtems_filesystem_default_fstat(
+ const rtems_filesystem_location_info_t *loc,
+ struct stat *buf
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a link command.
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_ftruncate_t.
*/
-int rtems_filesystem_default_evaluate_link(
- rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
- int flags /* IN */
+int rtems_filesystem_default_ftruncate(
+ rtems_libio_t *iop,
+ off_t length
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a symlink command.
+ * @retval -1 Always. The errno is set to EISDIR.
+ *
+ * @see rtems_filesystem_ftruncate_t.
*/
-int rtems_filesystem_default_symlink(
- rtems_filesystem_location_info_t *loc, /* IN */
- const char *link_name, /* IN */
- const char *node_name
+int rtems_filesystem_default_ftruncate_directory(
+ rtems_libio_t *iop,
+ off_t length
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a readlink command.
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_fsync_t.
*/
-ssize_t rtems_filesystem_default_readlink(
- rtems_filesystem_location_info_t *loc, /* IN */
- char *buf, /* OUT */
- size_t bufsize
+int rtems_filesystem_default_fsync(
+ rtems_libio_t *iop
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a rename command.
+ * @retval -1 Always. The errno is set to ENOTSUP.
+ *
+ * @see rtems_filesystem_fdatasync_t.
*/
-int rtems_filesystem_default_rename(
- rtems_filesystem_location_info_t *old_parent_loc, /* IN */
- rtems_filesystem_location_info_t *old_loc, /* IN */
- rtems_filesystem_location_info_t *new_parent_loc, /* IN */
- const char *name /* IN */
+int rtems_filesystem_default_fdatasync(
+ rtems_libio_t *iop
);
/**
- * @brief Provides a defualt routine for filesystem
- * implementation of a statvfs command.
+ * @retval 0 Always.
+ *
+ * @see rtems_filesystem_fcntl_t.
*/
-int rtems_filesystem_default_statvfs(
- rtems_filesystem_location_info_t *loc, /* IN */
- struct statvfs *buf /* OUT */
+int rtems_filesystem_default_fcntl(
+ rtems_libio_t *iop,
+ int cmd
);
+/** @} */
+
+/**
+ * @defgroup LibIO IO Library
+ *
+ * @brief Provides system call and file system interface definitions.
+ *
+ * General purpose communication channel for RTEMS to allow UNIX/POSIX
+ * system call behavior under RTEMS. Initially this supported only
+ * IO to devices but has since been enhanced to support networking
+ * and support for mounted file systems.
+ *
+ * @{
+ */
+
+typedef off_t rtems_off64_t __attribute__((deprecated));
+
/**
* @brief Gets the mount handler for the file system @a type.
*
@@ -1067,7 +1135,8 @@ typedef struct {
*
* Override in a filesystem.
*/
-extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf;
+extern const rtems_filesystem_limits_and_options_t
+ rtems_filesystem_default_pathconf;
/**
* @brief An open file data structure.
@@ -1194,12 +1263,22 @@ typedef off_t (*rtems_libio_lseek_t)(
* used to check permissions. These are similar in style to the
* mode_t bits and should stay compatible with them.
*/
-#define RTEMS_LIBIO_PERMS_READ S_IROTH
-#define RTEMS_LIBIO_PERMS_WRITE S_IWOTH
-#define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH)
-#define RTEMS_LIBIO_PERMS_EXEC S_IXOTH
+#define RTEMS_LIBIO_PERMS_READ 0x4
+#define RTEMS_LIBIO_PERMS_WRITE 0x2
+#define RTEMS_LIBIO_PERMS_EXEC 0x1
#define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC
-#define RTEMS_LIBIO_PERMS_RWX S_IRWXO
+#define RTEMS_LIBIO_PERMS_RDWR \
+ (RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE)
+#define RTEMS_LIBIO_PERMS_RWX \
+ (RTEMS_LIBIO_PERMS_RDWR | RTEMS_LIBIO_PERMS_EXEC)
+#define RTEMS_LIBIO_FOLLOW_HARD_LINK 0x8
+#define RTEMS_LIBIO_FOLLOW_SYM_LINK 0x10
+#define RTEMS_LIBIO_FOLLOW_LINK \
+ (RTEMS_LIBIO_FOLLOW_HARD_LINK | RTEMS_LIBIO_FOLLOW_SYM_LINK)
+#define RTEMS_LIBIO_MAKE 0x20
+#define RTEMS_LIBIO_EXCLUSIVE 0x40
+#define RTEMS_LIBIO_ACCEPT_RESIDUAL_DELIMITERS 0x80
+#define RTEMS_LIBIO_REJECT_TERMINAL_DOT 0x100
/** @} */
@@ -1251,12 +1330,6 @@ static inline rtems_device_minor_number rtems_filesystem_dev_minor_t(
} while(0)
/*
- * Verifies that the permission flag is valid.
- */
-#define rtems_libio_is_valid_perms( _perm ) \
- (((~RTEMS_LIBIO_PERMS_RWX) & _perm ) == 0)
-
-/*
* Prototypes for filesystem
*/
@@ -1317,12 +1390,14 @@ extern int rtems_mkdir(const char *path, mode_t mode);
* @brief Mount table entry.
*/
struct rtems_filesystem_mount_table_entry_tt {
- rtems_chain_node Node;
- rtems_filesystem_location_info_t mt_point_node;
- rtems_filesystem_location_info_t mt_fs_root;
- int options;
+ rtems_chain_node mt_node;
+ rtems_chain_control location_chain;
+ rtems_filesystem_global_location_t *mt_point_node;
+ rtems_filesystem_global_location_t *mt_fs_root;
+ bool mounted;
+ bool writeable;
void *fs_info;
-
+ const void *immutable_fs_info;
rtems_filesystem_limits_and_options_t pathconf_limits_and_options;
/*
@@ -1369,6 +1444,8 @@ typedef struct rtems_filesystem_table_t {
*/
extern const rtems_filesystem_table_t rtems_filesystem_table [];
+extern rtems_chain_control rtems_filesystem_mount_table;
+
/**
* @brief Registers a file system @a type.
*
@@ -1498,60 +1575,46 @@ bool rtems_filesystem_iterate(
);
/**
- * @brief Per file system mount routine.
- *
- * @see rtems_filesystem_mount_iterate().
+ * @brief Mount table entry visitor.
*
* @retval true Stop the iteration.
* @retval false Continue the iteration.
+ *
+ * @see rtems_filesystem_mount_iterate().
*/
-typedef bool (*rtems_per_filesystem_mount_routine)(
+typedef bool (*rtems_filesystem_mt_entry_visitor)(
const rtems_filesystem_mount_table_entry_t *mt_entry,
void *arg
);
/**
- * @brief Iterates over all file system mounts.
- *
- * For each file system mount the @a routine will be called with the entry and
- * the @a routine_arg parameter.
+ * @brief Iterates over all file system mount entries.
*
- * Do not mount or unmount file systems in @a routine.
+ * The iteration is protected by the IO library mutex. Do not mount or unmount
+ * file systems in the visitor function.
*
- * The iteration is protected by the IO library mutex.
+ * @param[in] visitor For each file system mount entry the visitor function
+ * will be called with the entry and the visitor argument as parameters.
+ * @param[in] visitor_arg The second parameter for the visitor function.
*
- * @retval true Iteration stopped due to @a routine return status.
+ * @retval true Iteration stopped due to visitor function return status.
* @retval false Iteration through all entries.
*/
-bool
-rtems_filesystem_mount_iterate(
- rtems_per_filesystem_mount_routine routine,
- void *routine_arg
+bool rtems_filesystem_mount_iterate(
+ rtems_filesystem_mt_entry_visitor visitor,
+ void *visitor_arg
);
-/**
- * @brief Boot time mount table entry.
- */
typedef struct {
- const char *type;
- rtems_filesystem_options_t fsoptions;
- const char *device;
- const char *mount_point;
-} rtems_filesystem_mount_table_t;
-
-/**
- * @brief Boot time mount table.
- *
- * @todo Only the first entry will be evaluated. Why do we need a table?
- */
-extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
-
-/**
- * @brief Boot time mount table entry count.
- *
- * @todo Only the first entry will be evaluated. Why do we need a table?
- */
-extern const int rtems_filesystem_mount_table_size;
+ const char *source;
+ const char *target;
+ const char *filesystemtype;
+ rtems_filesystem_options_t options;
+ const void *data;
+} rtems_filesystem_mount_configuration;
+
+extern const rtems_filesystem_mount_configuration
+ rtems_filesystem_root_configuration;
/** @} */
diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index e0396daa24..84882908fb 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.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,17 +21,18 @@
#ifndef _RTEMS_RTEMS_LIBIO__H
#define _RTEMS_RTEMS_LIBIO__H
-#include <rtems.h>
-#include <rtems/libio.h> /* include before standard IO */
-
-#include <sys/types.h>
-
#include <errno.h>
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/seterr.h>
+
#ifdef __cplusplus
extern "C" {
#endif
+#define RTEMS_FILESYSTEM_SYMLOOP_MAX 32
+
/*
* Semaphore to protect the io table
*/
@@ -47,6 +51,27 @@ extern rtems_libio_t *rtems_libio_iops;
extern rtems_libio_t *rtems_libio_last_iop;
extern rtems_libio_t *rtems_libio_iop_freelist;
+extern const rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers;
+
+extern rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry;
+
+/**
+ * @brief The global null location.
+ *
+ * Every operation and the open and fstat handlers of this location returns an
+ * error status. The errno is not touched by these operations and handlers.
+ * The purpose of this location is to deliver the error return status for a
+ * previous error condition which must set the errno accordingly.
+ *
+ * The usage of this null location instead of the NULL pointer eliminates a lot
+ * of branches.
+ *
+ * The user environment root and current directory are statically initialized
+ * with the null location. Due to that all file system services are in a
+ * defined state even if no root file system was mounted.
+ */
+extern rtems_filesystem_global_location_t rtems_filesystem_global_location_null;
+
/*
* rtems_libio_iop
*
@@ -147,28 +172,54 @@ extern rtems_libio_t *rtems_libio_iop_freelist;
#define rtems_libio_check_permissions(_iop, _flag) \
rtems_libio_check_permissions_with_error(_iop, _flag, EINVAL )
-/*
- * rtems_filesystem_freenode
+/**
+ * @brief Clones a node.
*
- * Macro to free a node.
+ * The caller must hold the file system instance lock.
+ *
+ * @param[out] clone The cloned location.
+ * @param[in] master The master location.
+ *
+ * @see rtems_filesystem_instance_lock().
*/
+void rtems_filesystem_location_clone(
+ rtems_filesystem_location_info_t *clone,
+ const rtems_filesystem_location_info_t *master
+);
-void rtems_filesystem_freenode( rtems_filesystem_location_info_t* node );
-
-/*
- * External structures
+/**
+ * @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.
+ *
+ * @return The node type.
+ *
+ * @see rtems_filesystem_instance_lock().
*/
-#include <rtems/userenv.h>
+rtems_filesystem_node_types_t rtems_filesystem_node_type(
+ const rtems_filesystem_location_info_t *loc
+);
-extern rtems_user_env_t * rtems_current_user_env;
-extern rtems_user_env_t rtems_global_user_env;
+/**
+ * @brief Releases all resources of a location.
+ *
+ * This function may block on a mutex and may complete an unmount process.
+ *
+ * @param[in] loc The location to free.
+ *
+ * @note The file system root location is released by the file system instance
+ * destruction handler (see @ref rtems_filesystem_fsunmount_me_t).
+ *
+ * @see rtems_filesystem_freenode_t.
+ */
+void rtems_filesystem_location_free( rtems_filesystem_location_info_t *loc );
/*
- * Instantiate a private copy of the per user information for the calling task.
+ * External structures
*/
-
-rtems_status_code rtems_libio_set_private_env(void);
-rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
+#include <rtems/userenv.h>
static inline void rtems_libio_lock( void )
{
@@ -180,80 +231,569 @@ static inline void rtems_libio_unlock( void )
rtems_semaphore_release( rtems_libio_semaphore );
}
+static inline void rtems_filesystem_mt_lock( void )
+{
+ rtems_libio_lock();
+}
+
+static inline void rtems_filesystem_mt_unlock( void )
+{
+ rtems_libio_unlock();
+}
+
+#define rtems_filesystem_mt_entry_declare_lock_context( ctx ) \
+ rtems_interrupt_level ctx
+
+#define rtems_filesystem_mt_entry_lock( ctx ) rtems_interrupt_disable( ctx )
+
+#define rtems_filesystem_mt_entry_unlock( ctx ) rtems_interrupt_enable( ctx )
+
+static inline void rtems_filesystem_instance_lock(
+ const rtems_filesystem_location_info_t *loc
+)
+{
+ (*loc->ops->lock_h)( loc->mt_entry );
+}
+
+static inline void rtems_filesystem_instance_unlock(
+ const rtems_filesystem_location_info_t *loc
+)
+{
+ (*loc->ops->unlock_h)( loc->mt_entry );
+}
+
/*
* File Descriptor Routine Prototypes
*/
rtems_libio_t *rtems_libio_allocate(void);
-uint32_t rtems_libio_fcntl_flags(
- uint32_t fcntl_flags
-);
+uint32_t rtems_libio_fcntl_flags( int fcntl_flags );
-uint32_t rtems_libio_to_fcntl_flags(
- uint32_t flags
-);
+int rtems_libio_to_fcntl_flags( uint32_t flags );
void rtems_libio_free(
rtems_libio_t *iop
);
-int rtems_libio_is_open_files_in_fs(
- rtems_filesystem_mount_table_entry_t *mt_entry
+/*
+ * File System Routine Prototypes
+ */
+
+rtems_filesystem_location_info_t *
+rtems_filesystem_eval_path_start(
+ rtems_filesystem_eval_path_context_t *ctx,
+ const char *path,
+ int eval_flags
);
-int rtems_libio_is_file_open(
- void *node_access
+rtems_filesystem_location_info_t *
+rtems_filesystem_eval_path_start_with_parent(
+ rtems_filesystem_eval_path_context_t *ctx,
+ const char *path,
+ int eval_flags,
+ rtems_filesystem_location_info_t *parentloc,
+ int parent_eval_flags
);
-/*
- * File System Routine Prototypes
- */
+rtems_filesystem_location_info_t *
+rtems_filesystem_eval_path_start_with_root_and_current(
+ rtems_filesystem_eval_path_context_t *ctx,
+ const char *path,
+ int eval_flags,
+ rtems_filesystem_global_location_t *const *global_root_ptr,
+ rtems_filesystem_global_location_t *const *global_current_ptr
+);
+
+void rtems_filesystem_eval_path_continue(
+ rtems_filesystem_eval_path_context_t *ctx
+);
-int rtems_filesystem_evaluate_relative_path(
- const char *pathname,
- size_t pathnamelen,
- int flags,
- rtems_filesystem_location_info_t *pathloc,
- int follow_link
+void rtems_filesystem_eval_path_cleanup(
+ rtems_filesystem_eval_path_context_t *ctx
);
-int rtems_filesystem_evaluate_path(
- const char *pathname,
- size_t pathnamelen,
- int flags,
- rtems_filesystem_location_info_t *pathloc,
- int follow_link
+void rtems_filesystem_eval_path_recursive(
+ rtems_filesystem_eval_path_context_t *ctx,
+ const char *path,
+ size_t pathlen
);
-int rtems_filesystem_dirname(
- const char *pathname
+void rtems_filesystem_eval_path_cleanup_with_parent(
+ rtems_filesystem_eval_path_context_t *ctx,
+ rtems_filesystem_location_info_t *parentloc
);
-int rtems_filesystem_prefix_separators(
- const char *pathname,
- int pathnamelen
+/**
+ * @brief Requests a path evaluation restart.
+ *
+ * Sets the start and current location to the new start location. The caller
+ * must terminate its current evaluation process. The path evaluation
+ * continues in the next loop iteration within
+ * rtems_filesystem_eval_path_continue(). This avoids recursive invokations.
+ * The function obtains the new start location and clones it to set the new
+ * current location. The previous start and current locations are released.
+ *
+ * @param[in, out] ctx The path evaluation context.
+ * @param[in, out] newstartloc_ptr Pointer to new start location.
+ */
+void rtems_filesystem_eval_path_restart(
+ rtems_filesystem_eval_path_context_t *ctx,
+ rtems_filesystem_global_location_t **newstartloc_ptr
+);
+
+typedef enum {
+ RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE,
+ RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE,
+ RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY
+} rtems_filesystem_eval_path_generic_status;
+
+/**
+ * @brief Tests if the current location is a directory.
+ *
+ * @param[in, out] ctx The path evaluation context.
+ * @param[in, out] arg The handler argument.
+ *
+ * @retval true The current location is a directory.
+ * @retval false Otherwise.
+ *
+ * @see rtems_filesystem_eval_path_generic().
+ */
+typedef bool (*rtems_filesystem_eval_path_is_directory)(
+ rtems_filesystem_eval_path_context_t *ctx,
+ void *arg
+);
+
+/**
+ * @brief Evaluates a token.
+ *
+ * @param[in, out] ctx The path evaluation context.
+ * @param[in, out] arg The handler argument.
+ * @param[in] token The token contents.
+ * @param[in] tokenlen The token length in characters.
+ *
+ * @retval status The generic path evaluation status.
+ *
+ * @see rtems_filesystem_eval_path_generic().
+ */
+typedef rtems_filesystem_eval_path_generic_status
+(*rtems_filesystem_eval_path_eval_token)(
+ rtems_filesystem_eval_path_context_t *ctx,
+ void *arg,
+ const char *token,
+ size_t tokenlen
+);
+
+typedef struct {
+ rtems_filesystem_eval_path_is_directory is_directory;
+ rtems_filesystem_eval_path_eval_token eval_token;
+} rtems_filesystem_eval_path_generic_config;
+
+void rtems_filesystem_eval_path_generic(
+ rtems_filesystem_eval_path_context_t *ctx,
+ void *arg,
+ const rtems_filesystem_eval_path_generic_config *config
);
void rtems_filesystem_initialize(void);
-int init_fs_mount_table(void);
+/**
+ * @brief Copies a location.
+ *
+ * A bitwise copy is performed. The destination location will be added to the
+ * corresponding mount entry.
+ *
+ * @param[out] dst The destination location.
+ * @param[in] src The source location.
+ *
+ * @retval dst The destination location.
+ *
+ * @see rtems_filesystem_location_clone().
+ */
+rtems_filesystem_location_info_t *rtems_filesystem_location_copy(
+ rtems_filesystem_location_info_t *dst,
+ const rtems_filesystem_location_info_t *src
+);
+
+static inline rtems_filesystem_location_info_t *
+rtems_filesystem_location_initialize_to_null(
+ rtems_filesystem_location_info_t *loc
+)
+{
+ return rtems_filesystem_location_copy(
+ loc,
+ &rtems_filesystem_global_location_null.location
+ );
+}
-int rtems_filesystem_is_separator(char ch);
+rtems_filesystem_global_location_t *
+rtems_filesystem_location_transform_to_global(
+ rtems_filesystem_location_info_t *loc
+);
-void rtems_filesystem_get_start_loc(const char *path,
- int *index,
- rtems_filesystem_location_info_t *loc);
+/**
+ * @brief Assigns a global file system location.
+ *
+ * @param[in, out] lhs_global_loc_ptr Pointer to the global left hand side file
+ * system location. The current left hand side location will be released.
+ * @param[in] rhs_global_loc The global right hand side file system location.
+ */
+void rtems_filesystem_global_location_assign(
+ rtems_filesystem_global_location_t **lhs_global_loc_ptr,
+ rtems_filesystem_global_location_t *rhs_global_loc
+);
-void rtems_filesystem_get_sym_start_loc(const char *path,
- int *index,
- rtems_filesystem_location_info_t *loc);
+/**
+ * @brief Obtains a global file system location.
+ *
+ * Deferred releases will be processed in this function.
+ *
+ * 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] global_loc_ptr Pointer to the global file system location.
+ *
+ * @return A global file system location. It returns always a valid object.
+ * In case of an error, the global null location will be returned. Each
+ * operation or handler of the null location returns an error status. The
+ * errno indicates the error. The NULL pointer is never returned.
+ *
+ * @see rtems_filesystem_location_transform_to_global(),
+ * rtems_filesystem_global_location_obtain_null(), and
+ * rtems_filesystem_global_location_release().
+ */
+rtems_filesystem_global_location_t *rtems_filesystem_global_location_obtain(
+ rtems_filesystem_global_location_t *const *global_loc_ptr
+);
+
+/**
+ * @brief Releases a global file system location.
+ *
+ * In case the reference count reaches zero, all associated resources will be
+ * released. This may include the complete unmount of the corresponding file
+ * system instance.
+ *
+ * This function may block on a mutex. It may be called within critical
+ * sections of the operating system. In this case the release will be
+ * deferred. The next obtain call will do the actual release.
+ *
+ * @param[in] global_loc The global file system location. It must not be NULL.
+ *
+ * @see rtems_filesystem_global_location_obtain().
+ */
+void rtems_filesystem_global_location_release(
+ rtems_filesystem_global_location_t *global_loc
+);
+
+void rtems_filesystem_location_detach(
+ rtems_filesystem_location_info_t *detach
+);
+
+void rtems_filesystem_location_copy_and_detach(
+ rtems_filesystem_location_info_t *copy,
+ rtems_filesystem_location_info_t *detach
+);
+
+static inline rtems_filesystem_global_location_t *
+rtems_filesystem_global_location_obtain_null(void)
+{
+ rtems_filesystem_global_location_t *global_loc = NULL;
-static inline bool rtems_filesystem_is_root_location(
+ return rtems_filesystem_global_location_obtain( &global_loc );
+}
+
+static inline bool rtems_filesystem_location_is_null(
+ const rtems_filesystem_location_info_t *loc
+)
+{
+ return loc->handlers == &rtems_filesystem_null_handlers;
+}
+
+static inline bool rtems_filesystem_global_location_is_null(
+ const rtems_filesystem_global_location_t *global_loc
+)
+{
+ return rtems_filesystem_location_is_null( &global_loc->location );
+}
+
+static inline void rtems_filesystem_location_error(
+ const rtems_filesystem_location_info_t *loc,
+ int eno
+)
+{
+ if ( !rtems_filesystem_location_is_null( loc ) ) {
+ errno = eno;
+ }
+}
+
+int rtems_filesystem_mknod(
+ const rtems_filesystem_location_info_t *parentloc,
+ const char *name,
+ size_t namelen,
+ mode_t mode,
+ dev_t dev
+);
+
+int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc );
+
+int rtems_filesystem_chown(
+ const char *path,
+ uid_t owner,
+ gid_t group,
+ int eval_follow_link
+);
+
+static inline bool rtems_filesystem_is_ready_for_unmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry
+)
+{
+ bool ready = !mt_entry->mounted
+ && rtems_chain_has_only_one_node( &mt_entry->location_chain )
+ && mt_entry->mt_fs_root->reference_count == 1;
+
+ if ( ready ) {
+ rtems_chain_initialize_empty( &mt_entry->location_chain );
+ }
+
+ return ready;
+}
+
+static inline void rtems_filesystem_location_add_to_mt_entry(
+ rtems_filesystem_location_info_t *loc
+)
+{
+ rtems_filesystem_mt_entry_declare_lock_context( lock_context );
+
+ rtems_filesystem_mt_entry_lock( lock_context );
+ rtems_chain_append_unprotected(
+ &loc->mt_entry->location_chain,
+ &loc->mt_entry_node
+ );
+ rtems_filesystem_mt_entry_unlock( lock_context );
+}
+
+void rtems_filesystem_location_remove_from_mt_entry(
+ rtems_filesystem_location_info_t *loc
+);
+
+void rtems_filesystem_do_unmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry
+);
+
+static inline bool rtems_filesystem_location_is_root(
const rtems_filesystem_location_info_t *loc
)
{
- return loc->mt_entry->mt_fs_root.node_access == loc->node_access;
+ return (*loc->ops->are_nodes_equal_h)(
+ loc,
+ &loc->mt_entry->mt_fs_root->location
+ );
+}
+
+static inline const char *rtems_filesystem_eval_path_get_path(
+ rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ return ctx->path;
+}
+
+static inline size_t rtems_filesystem_eval_path_get_pathlen(
+ rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ return ctx->pathlen;
+}
+
+static inline void rtems_filesystem_eval_path_set_path(
+ rtems_filesystem_eval_path_context_t *ctx,
+ const char *path,
+ size_t pathlen
+)
+{
+ ctx->path = path;
+ ctx->pathlen = pathlen;
+}
+
+static inline void rtems_filesystem_eval_path_clear_path(
+ rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ ctx->pathlen = 0;
+}
+
+static inline const char *rtems_filesystem_eval_path_get_token(
+ rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ return ctx->token;
+}
+
+static inline size_t rtems_filesystem_eval_path_get_tokenlen(
+ rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ return ctx->tokenlen;
+}
+
+static inline void rtems_filesystem_eval_path_set_token(
+ rtems_filesystem_eval_path_context_t *ctx,
+ const char *token,
+ size_t tokenlen
+)
+{
+ ctx->token = token;
+ ctx->tokenlen = tokenlen;
+}
+
+static inline void rtems_filesystem_eval_path_clear_token(
+ rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ ctx->tokenlen = 0;
+}
+
+static inline void rtems_filesystem_eval_path_put_back_token(
+ rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ size_t tokenlen = ctx->tokenlen;
+
+ ctx->path -= tokenlen;
+ ctx->pathlen += tokenlen;
+ ctx->tokenlen = 0;
+}
+
+void rtems_filesystem_eval_path_eat_delimiter(
+ rtems_filesystem_eval_path_context_t *ctx
+);
+
+void rtems_filesystem_eval_path_next_token(
+ rtems_filesystem_eval_path_context_t *ctx
+);
+
+static inline void rtems_filesystem_eval_path_get_next_token(
+ rtems_filesystem_eval_path_context_t *ctx,
+ const char **token,
+ size_t *tokenlen
+)
+{
+ rtems_filesystem_eval_path_next_token(ctx);
+ *token = ctx->token;
+ *tokenlen = ctx->tokenlen;
+}
+
+static inline rtems_filesystem_location_info_t *
+rtems_filesystem_eval_path_get_currentloc(
+ rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ return &ctx->currentloc;
+}
+
+static inline bool rtems_filesystem_eval_path_has_path(
+ const rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ return ctx->pathlen > 0;
+}
+
+static inline bool rtems_filesystem_eval_path_has_token(
+ const rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ return ctx->tokenlen > 0;
+}
+
+static inline int rtems_filesystem_eval_path_get_flags(
+ const rtems_filesystem_eval_path_context_t *ctx
+)
+{
+ return ctx->flags;
+}
+
+static inline void rtems_filesystem_eval_path_set_flags(
+ rtems_filesystem_eval_path_context_t *ctx,
+ int flags
+)
+{
+ ctx->flags = flags;
+}
+
+static inline void rtems_filesystem_eval_path_clear_and_set_flags(
+ rtems_filesystem_eval_path_context_t *ctx,
+ int clear,
+ int set
+)
+{
+ int flags = ctx->flags;
+
+ flags &= ~clear;
+ flags |= set;
+
+ ctx->flags = flags;
+}
+
+static inline void rtems_filesystem_eval_path_extract_currentloc(
+ rtems_filesystem_eval_path_context_t *ctx,
+ rtems_filesystem_location_info_t *get
+)
+{
+ rtems_filesystem_location_copy_and_detach(
+ get,
+ &ctx->currentloc
+ );
+}
+
+void rtems_filesystem_eval_path_error(
+ rtems_filesystem_eval_path_context_t *ctx,
+ int eno
+);
+
+/**
+ * @brief Checks that the locations exist in the same file system instance.
+ *
+ * @retval 0 The locations exist and are in the same file system instance.
+ * @retval -1 An error occured. The @c errno indicates the error.
+ */
+int rtems_filesystem_location_exists_in_same_fs_instance_as(
+ const rtems_filesystem_location_info_t *a,
+ const rtems_filesystem_location_info_t *b
+);
+
+bool rtems_filesystem_check_access(
+ int eval_flags,
+ mode_t node_mode,
+ uid_t node_uid,
+ gid_t node_gid
+);
+
+bool rtems_filesystem_eval_path_check_access(
+ rtems_filesystem_eval_path_context_t *ctx,
+ int eval_flags,
+ mode_t node_mode,
+ uid_t node_uid,
+ gid_t node_gid
+);
+
+static inline bool rtems_filesystem_is_delimiter(char c)
+{
+ return c == '/' || c == '\\';
+}
+
+static inline bool rtems_filesystem_is_current_directory(
+ const char *token,
+ size_t tokenlen
+)
+{
+ return tokenlen == 1 && token [0] == '.';
+}
+
+static inline bool rtems_filesystem_is_parent_directory(
+ const char *token,
+ size_t tokenlen
+)
+{
+ return tokenlen == 2 && token [0] == '.' && token [1] == '.';
}
#ifdef __cplusplus