Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup rtems_rfs
0007  *
0008  * RTEMS File System RTEMS Header file.
0009  *
0010  * This file is not to be installed. It binds the RFS file system to RTEMS.
0011  */
0012 
0013 /*
0014  *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #if !defined(RTEMS_RFS_RTEMS_DEFINED)
0039 #define RTEMS_RFS_RTEMS_DEFINED
0040 
0041 #include <stdbool.h>
0042 #include <stdint.h>
0043 #include <errno.h>
0044 
0045 /**
0046  * RTEMS RFS RTEMS Error Enable. Set to 1 for printing of errors. Default is off.
0047  */
0048 #define RTEMS_RFS_RTEMS_ERROR 0
0049 
0050 /**
0051  * RTEMS RFS RTEMS Trace Enable. Set to 1 for printing of errors. Default is off.
0052  */
0053 #define RTEMS_RFS_RTEMS_TRACE 0
0054 
0055 /**
0056  * If we are not handling errors provide a define that removes the strings from
0057  * the code.
0058  */
0059 #if !RTEMS_RFS_RTEMS_ERROR
0060 #define rtems_rfs_rtems_error(_m, _e) \
0061   (((errno = (_e)) == 0) ? 0 : -1)
0062 #else
0063 /**
0064  * Take the result code and set errno with it and if non-zero return -1 else
0065  * return 0.
0066  *
0067  * @param[in] what is a pointer to the message to print if the error
0068  *            is not zero.
0069  * @param[in] error is the error code.
0070  *
0071  * @retval 0 Successful operation.
0072  * @retval -1 An error occurred.
0073  */
0074 int rtems_rfs_rtems_error (const char* mesg, int error);
0075 #endif
0076 
0077 /**
0078  * Trace message defines the RTEMS bindings of the RTEMS RFS. This is a
0079  * development tool where can edit the values below to control the various trace
0080  * output.
0081  */
0082 #define RTEMS_RFS_RTEMS_DEBUG_ALL           (0xffffffff)
0083 #define RTEMS_RFS_RTEMS_DEBUG_ERROR_MSGS    (1 << 0)
0084 #define RTEMS_RFS_RTEMS_DEBUG_EVAL_PATH     (1 << 1)
0085 #define RTEMS_RFS_RTEMS_DEBUG_EVAL_FOR_MAKE (1 << 2)
0086 #define RTEMS_RFS_RTEMS_DEBUG_EVAL_PERMS    (1 << 3)
0087 #define RTEMS_RFS_RTEMS_DEBUG_MKNOD         (1 << 4)
0088 #define RTEMS_RFS_RTEMS_DEBUG_RMNOD         (1 << 5)
0089 #define RTEMS_RFS_RTEMS_DEBUG_LINK          (1 << 6)
0090 #define RTEMS_RFS_RTEMS_DEBUG_UNLINK        (1 << 7)
0091 #define RTEMS_RFS_RTEMS_DEBUG_CHOWN         (1 << 8)
0092 #define RTEMS_RFS_RTEMS_DEBUG_READLINK      (1 << 9)
0093 #define RTEMS_RFS_RTEMS_DEBUG_FCHMOD        (1 << 10)
0094 #define RTEMS_RFS_RTEMS_DEBUG_STAT          (1 << 11)
0095 #define RTEMS_RFS_RTEMS_DEBUG_RENAME        (1 << 12)
0096 #define RTEMS_RFS_RTEMS_DEBUG_DIR_RMNOD     (1 << 13)
0097 #define RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN     (1 << 14)
0098 #define RTEMS_RFS_RTEMS_DEBUG_FILE_CLOSE    (1 << 15)
0099 #define RTEMS_RFS_RTEMS_DEBUG_FILE_READ     (1 << 16)
0100 #define RTEMS_RFS_RTEMS_DEBUG_FILE_WRITE    (1 << 17)
0101 #define RTEMS_RFS_RTEMS_DEBUG_FILE_LSEEK    (1 << 18)
0102 #define RTEMS_RFS_RTEMS_DEBUG_FILE_FTRUNC   (1 << 19)
0103 
0104 /**
0105  * Call to check if this part is bring traced. If RTEMS_RFS_RTEMS_TRACE is
0106  * defined to 0 the code is dead code elminiated when built with -Os, -O2, or
0107  * higher.
0108  *
0109  * @param[in] mask is the part of the API to trace.
0110  *
0111  * @retval true Tracing is active for the mask.
0112  * @retval false Do not trace.
0113  */
0114 #if RTEMS_RFS_RTEMS_TRACE
0115 bool rtems_rfs_rtems_trace (uint32_t mask);
0116 #else
0117 #define rtems_rfs_rtems_trace(_m) (0)
0118 #endif
0119 
0120 /**
0121  * Set the mask.
0122  *
0123  * @param[in] mask is the mask bits to set.
0124  *
0125  * @retval mask The previous mask.
0126  */
0127 #if RTEMS_RFS_RTEMS_TRACE
0128 void rtems_rfs_rtems_trace_set_mask (uint32_t mask);
0129 #else
0130 #define rtems_rfs_rtems_trace_set_mask(_m)
0131 #endif
0132 
0133 /**
0134  * Clear the mask.
0135  *
0136  * @param[in] mask is the mask bits to clear.
0137  *
0138  * @retval mask The previous mask.
0139  */
0140 #if RTEMS_RFS_RTEMS_TRACE
0141 void rtems_rfs_rtems_trace_clear_mask (uint32_t mask);
0142 #else
0143 #define rtems_rfs_rtems_trace_clear_mask(_m)
0144 #endif
0145 
0146 /**
0147  * Add shell trace shell command.
0148  */
0149 #if RTEMS_RFS_RTEMS_TRACE
0150 int rtems_rfs_rtems_trace_shell_command (int argc, char *argv[]);
0151 #endif
0152 
0153 #include <rtems/rfs/rtems-rfs-file-system.h>
0154 #include <rtems/rfs/rtems-rfs-inode.h>
0155 #include <rtems/rfs/rtems-rfs-mutex.h>
0156 #include <rtems/libio_.h>
0157 #include <rtems/fs.h>
0158 
0159 /**
0160  * Private RFS RTEMS Port data.
0161  */
0162 typedef struct rtems_rfs_rtems_private
0163 {
0164   /**
0165    * The access lock.
0166    */
0167   rtems_rfs_mutex access;
0168 } rtems_rfs_rtems_private;
0169 /**
0170  * Return the file system structure given a path location.
0171  *
0172  * @param[in] _loc is a pointer to the path location.
0173  * @return rtems_rfs_file_system*
0174  */
0175 #define rtems_rfs_rtems_pathloc_dev(_loc) \
0176   ((rtems_rfs_file_system*)((_loc)->mt_entry->fs_info))
0177 
0178 /**
0179  * Set the inode number (ino) into the path location.
0180  *
0181  * @param[in] _loc is a pointer to the path location.
0182  * @param[in] _ino is the ino to set in the path location.
0183  */
0184 #define rtems_rfs_rtems_set_pathloc_ino(_loc, _ino) \
0185   (_loc)->node_access = (void*)((intptr_t)(_ino))
0186 
0187 /**
0188  * Get the inode number (ino) given a path location.
0189  *
0190  * @param[in] _loc is a pointer to the path location.
0191  * @return rtems_rfs_ino The inode number in the path location.
0192  */
0193 #define rtems_rfs_rtems_get_pathloc_ino(_loc) \
0194   ((rtems_rfs_ino) (intptr_t)((_loc)->node_access))
0195 
0196 /**
0197  * Set the directory offset (doff) into the path location.
0198  *
0199  * @param[in] _loc is a pointer to the path location.
0200  * @param[in] _doff is the doff to set in the path location.
0201  */
0202 #define rtems_rfs_rtems_set_pathloc_doff(_loc, _doff) \
0203   (_loc)->node_access_2 = (void*)((intptr_t)(_doff))
0204 
0205 /**
0206  * Get the directory offset (doff) given a path location.
0207  *
0208  * @param[in] _loc is a pointer to the path location.
0209  * @return uin32_t The doff in the path location.
0210  */
0211 #define rtems_rfs_rtems_get_pathloc_doff(_loc) \
0212   ((uint32_t) (intptr_t)((_loc)->node_access_2))
0213 
0214 /**
0215  * Get the ino from the I/O pointer.
0216  *
0217  * @param[in] _iop is the I/O pointer.
0218  * @return ino
0219  */
0220 #define rtems_rfs_rtems_get_iop_ino(_iop) \
0221   ((intptr_t)(_iop)->pathinfo.node_access)
0222 
0223 /**
0224  * Get the file handle from the I/O pointer.
0225  *
0226  * @param _iop The I/O pointer.
0227  * @return filehandle The file handle
0228  */
0229 #define rtems_rfs_rtems_get_iop_file_handle(_iop) \
0230   ((rtems_rfs_file_handle*)(_iop)->pathinfo.node_access_2)
0231 
0232 /**
0233  * Set the file handle in the I/O pointer.
0234  *
0235  * @param[in] _iop is the I/O pointer.
0236  * @param[in] _fh is the file handle.
0237  */
0238 #define rtems_rfs_rtems_set_iop_file_handle(_iop, _fh) \
0239   (_iop)->pathinfo.node_access_2 = (_fh)
0240 
0241 /**
0242  * Create the name of the handler's table given the type of handlers.
0243  *
0244  * @param[in] _h is the name of the handlers.
0245  * @return label The name of the handler's table.
0246  */
0247 #define rtems_rfs_rtems_handlers(_h) \
0248   &rtems_rfs_rtems_ ## _h ## _handlers
0249 
0250 /**
0251  * Set the handlers in the path location based on the mode of the inode.
0252  *
0253  * @param[in] loc is a pointer to the path location to set the handlers in.
0254  * @param[in] inode is the inode handle to check the mode of for the
0255  *         type of handlers.
0256  *
0257  * @retval true The handlers have been set.
0258  * @retval false There are no handlers for the mode.
0259  */
0260 bool rtems_rfs_rtems_set_handlers (rtems_filesystem_location_info_t* pathloc,
0261                                    rtems_rfs_inode_handle*           inode);
0262 
0263 /**
0264  * Convert the system mode flags to inode mode flags.
0265  *
0266  * @param[in] mode is the system mode flags.
0267  * @return uint16_t The inode mode flags.
0268  */
0269 uint16_t rtems_rfs_rtems_imode (mode_t mode);
0270 
0271 /**
0272  * Convert the inode mode flags to system mode flags.
0273  *
0274  * @param[in] imode is the inode mode flags
0275  * @return mode_t The system mode flags.
0276  */
0277 mode_t rtems_rfs_rtems_mode (int imode);
0278 
0279 /**
0280  * Lock the RFS file system.
0281  */
0282 static inline void
0283  rtems_rfs_rtems_lock (rtems_rfs_file_system* fs)
0284 {
0285   rtems_rfs_rtems_private* rtems = rtems_rfs_fs_user (fs);
0286   rtems_rfs_mutex_lock (&rtems->access);
0287 }
0288 
0289 /**
0290  * Unlock the RFS file system.
0291  */
0292 static inline void
0293  rtems_rfs_rtems_unlock (rtems_rfs_file_system* fs)
0294 {
0295   rtems_rfs_rtems_private* rtems = rtems_rfs_fs_user (fs);
0296   rtems_rfs_buffers_release (fs);
0297   rtems_rfs_mutex_unlock (&rtems->access);
0298 }
0299 
0300 /**
0301  * The handlers.
0302  */
0303 extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_dir_handlers;
0304 extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_device_handlers;
0305 extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_link_handlers;
0306 extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_file_handlers;
0307 
0308 /**
0309  * The following routine does a stat on a node.
0310  */
0311 int rtems_rfs_rtems_fstat (const rtems_filesystem_location_info_t* pathloc,
0312                            struct stat*                            buf);
0313 
0314 /**
0315  * Routine to remove a node from the RFS file system.
0316  *
0317  * @param parent_pathloc
0318  * @param pathloc
0319  */
0320 int rtems_rfs_rtems_rmnod (const rtems_filesystem_location_info_t* parent_pathloc,
0321                            const rtems_filesystem_location_info_t* pathloc);
0322 
0323 /**
0324  * The following routine does a sync on an inode node. Currently it flushes
0325  * everything related to this device.
0326  *
0327  * @param iop
0328  */
0329 int rtems_rfs_rtems_fdatasync (rtems_libio_t* iop);
0330 
0331 #endif