Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:12

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief RTEMS File System Link Support
0007  *
0008  * @ingroup rtems_rfs
0009  *
0010  * RTEMS File System Link Support
0011  *
0012  * This file provides the link support functions.
0013  */
0014 
0015 /*
0016  *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
0017  *
0018  * Redistribution and use in source and binary forms, with or without
0019  * modification, are permitted provided that the following conditions
0020  * are met:
0021  * 1. Redistributions of source code must retain the above copyright
0022  *    notice, this list of conditions and the following disclaimer.
0023  * 2. Redistributions in binary form must reproduce the above copyright
0024  *    notice, this list of conditions and the following disclaimer in the
0025  *    documentation and/or other materials provided with the distribution.
0026  *
0027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0037  * POSSIBILITY OF SUCH DAMAGE.
0038  */
0039 
0040 
0041 #if !defined (_RTEMS_RFS_LINK_H_)
0042 #define _RTEMS_RFS_LINK_H_
0043 
0044 #include <dirent.h>
0045 
0046 #include <rtems/rfs/rtems-rfs-file-system.h>
0047 #include <rtems/rfs/rtems-rfs-inode.h>
0048 
0049 /**
0050  * Directory unlink modes.
0051  */
0052 typedef enum rtems_rfs_unlink_dir_e
0053 {
0054   rtems_rfs_unlink_dir_denied,   /**< Not allowed to unlink a directory. */
0055   rtems_rfs_unlink_dir_if_empty, /**< Unlink if the directory is empty. */
0056   rtems_rfs_unlink_dir_allowed   /**< Unlinking of directories is allowed. */
0057 } rtems_rfs_unlink_dir;
0058 
0059 /**
0060  * Create a link. Do not link directories unless renaming or you will create
0061  * loops in the file system.
0062  *
0063  * @param[in] fs is the file system.
0064  * @param[in] name is a pointer to the name of the link.
0065  * @param[in] length is the length of the name.
0066  * @param[in] parent is the inode number of the parent directory.
0067  * @param[in] target is the inode of the target.
0068  * @param[in] link_dir If true directories can be linked. Useful when
0069  *                renaming.
0070  *
0071  * @retval 0 Successful operation.
0072  * @retval error_code An error occurred.
0073  */
0074 int rtems_rfs_link (rtems_rfs_file_system* fs,
0075                     const char*            name,
0076                     int                    length,
0077                     rtems_rfs_ino          parent,
0078                     rtems_rfs_ino          target,
0079                     bool                   link_dir);
0080 
0081 /**
0082  * Unlink the node from the parent directory. A directory offset for the
0083  * target entry is required because links cause a number of inode numbers to
0084  * appear in a single directory so scanning does not work.
0085  *
0086  * @param[in] fs is the file system.
0087  * @param[in] parent is the inode number of the parent directory.
0088  * @param[in] target is the inode of the target.
0089  * @param[in] doff is the parent directory entry offset for the target entry.
0090  * @param[in] dir_mode is the directory unlink mode.
0091  *
0092  * @retval 0 Successful operation.
0093  * @retval error_code An error occurred.
0094  */
0095 int rtems_rfs_unlink (rtems_rfs_file_system* fs,
0096                       rtems_rfs_ino          parent,
0097                       rtems_rfs_ino          target,
0098                       uint32_t               doff,
0099                       rtems_rfs_unlink_dir   dir_mode);
0100 
0101 /**
0102  * Symbolic link is an inode that has a path attached.
0103  *
0104  * @param[in] fs is the file system data.
0105  * @param[in] name is a pointer to the name of the node.
0106  * @param[in] length is the length of the name of the node.
0107  * @param[in] link is a pointer to the link path attached to the
0108  *             symlink inode.
0109  * @param[in] link_length is the length of the link path.
0110  * @param[in] parent is the parent inode number.
0111  *
0112  * @retval 0 Successful operation.
0113  * @retval error_code An error occurred.
0114  */
0115 int rtems_rfs_symlink (rtems_rfs_file_system* fs,
0116                        const char*            name,
0117                        int                    length,
0118                        const char*            link,
0119                        int                    link_length,
0120                        uid_t                  uid,
0121                        gid_t                  gid,
0122                        rtems_rfs_ino          parent);
0123 
0124 /**
0125  * Read a symbolic link into the provided buffer returning the link of link
0126  * name.
0127  *
0128  * @param[in] fs is the file system data.
0129  * @param[in] link is the link inode number to read.
0130  * @param[in] path is a pointer to the buffer to write the link path into.
0131  * @param[in] size is the size of the buffer.
0132  * @param[out] length will contain the length of the link path.
0133  *
0134  * @retval 0 Successful operation.
0135  * @retval error_code An error occurred.
0136  */
0137 int rtems_rfs_symlink_read (rtems_rfs_file_system* fs,
0138                             rtems_rfs_ino          link,
0139                             char*                  path,
0140                             size_t                 size,
0141                             size_t*                length);
0142 
0143 #endif