Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *
0006  *  @brief RTEMS File System Location Support
0007  *  @ingroup LibIOInternal
0008  */
0009 
0010 /*
0011  * COPYRIGHT (C) 2021 On-Line Applications Research Corporation (OAR).
0012  *
0013  * Modifications to support reference counting in the file system are
0014  * Copyright (c) 2012 embedded brains GmbH & Co. KG
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 #ifdef HAVE_CONFIG_H
0039 #include "config.h"
0040 #endif
0041 
0042 #include <sys/stat.h>
0043 
0044 #include <rtems/libio_.h>
0045 #include <rtems/score/percpu.h>
0046 #include <rtems/score/thread.h>
0047 
0048 static int null_handler_open(
0049   rtems_libio_t *iop,
0050   const char *path,
0051   int oflag,
0052   mode_t mode
0053 )
0054 {
0055   return -1;
0056 }
0057 
0058 static int null_handler_fstat(
0059   const rtems_filesystem_location_info_t *pathloc,
0060   struct stat *buf
0061 )
0062 {
0063   return -1;
0064 }
0065 
0066 const rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers = {
0067   .open_h = null_handler_open,
0068   .close_h = rtems_filesystem_default_close,
0069   .read_h = rtems_filesystem_default_read,
0070   .write_h = rtems_filesystem_default_write,
0071   .ioctl_h = rtems_filesystem_default_ioctl,
0072   .lseek_h = rtems_filesystem_default_lseek,
0073   .fstat_h = null_handler_fstat,
0074   .ftruncate_h = rtems_filesystem_default_ftruncate,
0075   .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
0076   .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
0077   .fcntl_h = rtems_filesystem_default_fcntl,
0078   .kqfilter_h = rtems_filesystem_default_kqfilter,
0079   .mmap_h = rtems_filesystem_default_mmap,
0080   .poll_h = rtems_filesystem_default_poll,
0081   .readv_h = rtems_filesystem_default_readv,
0082   .writev_h = rtems_filesystem_default_writev
0083 };
0084 
0085 static void null_op_lock_or_unlock(
0086   const rtems_filesystem_mount_table_entry_t *mt_entry
0087 )
0088 {
0089   /* Do nothing */
0090 }
0091 
0092 static int null_op_mknod(
0093   const rtems_filesystem_location_info_t *parentloc,
0094   const char *name,
0095   size_t namelen,
0096   mode_t mode,
0097   dev_t dev
0098 )
0099 {
0100   return -1;
0101 }
0102 
0103 static int null_op_rmnod(
0104   const rtems_filesystem_location_info_t *parentloc,
0105   const rtems_filesystem_location_info_t *loc
0106 )
0107 {
0108   return -1;
0109 }
0110 
0111 static int null_op_link(
0112   const rtems_filesystem_location_info_t *parentloc,
0113   const rtems_filesystem_location_info_t *targetloc,
0114   const char *name,
0115   size_t namelen
0116 )
0117 {
0118   return -1;
0119 }
0120 
0121 static int null_op_fchmod(
0122   const rtems_filesystem_location_info_t *pathloc,
0123   mode_t mode
0124 )
0125 {
0126   return -1;
0127 }
0128 
0129 static int null_op_chown(
0130   const rtems_filesystem_location_info_t *loc,
0131   uid_t owner,
0132   gid_t group
0133 )
0134 {
0135   return -1;
0136 }
0137 
0138 static int null_op_clonenode(
0139   rtems_filesystem_location_info_t *loc
0140 )
0141 {
0142   return -1;
0143 }
0144 
0145 static int null_op_mount(
0146   rtems_filesystem_mount_table_entry_t *mt_entry
0147 )
0148 {
0149   return -1;
0150 }
0151 
0152 static int null_op_unmount(
0153   rtems_filesystem_mount_table_entry_t *mt_entry
0154 )
0155 {
0156   return -1;
0157 }
0158 
0159 static void null_op_fsunmount_me(
0160   rtems_filesystem_mount_table_entry_t *mt_entry
0161 )
0162 {
0163   /* Do nothing */
0164 }
0165 
0166 static int null_op_utimens(
0167   const rtems_filesystem_location_info_t *loc,
0168   struct timespec times[2]
0169 )
0170 {
0171   return -1;
0172 }
0173 
0174 static int null_op_symlink(
0175   const rtems_filesystem_location_info_t *parentloc,
0176   const char *name,
0177   size_t namelen,
0178   const char *target
0179 )
0180 {
0181   return -1;
0182 }
0183 
0184 static ssize_t null_op_readlink(
0185   const rtems_filesystem_location_info_t *loc,
0186   char *buf,
0187   size_t bufsize
0188 )
0189 {
0190   return -1;
0191 }
0192 
0193 static int null_op_rename(
0194   const rtems_filesystem_location_info_t *oldparentloc,
0195   const rtems_filesystem_location_info_t *oldloc,
0196   const rtems_filesystem_location_info_t *newparentloc,
0197   const char *name,
0198   size_t namelen
0199 )
0200 {
0201   return -1;
0202 }
0203 
0204 static int null_op_statvfs(
0205   const rtems_filesystem_location_info_t *__restrict loc,
0206   struct statvfs *__restrict buf
0207 )
0208 {
0209   return -1;
0210 }
0211 
0212 static const rtems_filesystem_operations_table null_ops = {
0213   .lock_h = null_op_lock_or_unlock,
0214   .unlock_h = null_op_lock_or_unlock,
0215   .eval_path_h = rtems_filesystem_default_eval_path,
0216   .link_h = null_op_link,
0217   .are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal,
0218   .mknod_h = null_op_mknod,
0219   .rmnod_h = null_op_rmnod,
0220   .fchmod_h = null_op_fchmod,
0221   .chown_h = null_op_chown,
0222   .clonenod_h = null_op_clonenode,
0223   .freenod_h = rtems_filesystem_default_freenode,
0224   .mount_h = null_op_mount,
0225   .unmount_h = null_op_unmount,
0226   .fsunmount_me_h = null_op_fsunmount_me,
0227   .utimens_h = null_op_utimens,
0228   .symlink_h = null_op_symlink,
0229   .readlink_h = null_op_readlink,
0230   .rename_h = null_op_rename,
0231   .statvfs_h = null_op_statvfs
0232 };
0233 
0234 rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = {
0235   .location_chain = RTEMS_CHAIN_INITIALIZER_ONE_NODE(
0236     &rtems_filesystem_global_location_null.location.mt_entry_node
0237   ),
0238   .ops = &null_ops,
0239   .mt_point_node = &rtems_filesystem_global_location_null,
0240   .mt_fs_root = &rtems_filesystem_global_location_null,
0241   .mounted = false,
0242   .writeable = false,
0243   .type = ""
0244 };
0245 
0246 rtems_filesystem_global_location_t rtems_filesystem_global_location_null = {
0247   .location = {
0248     .mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(
0249       &rtems_filesystem_null_mt_entry.location_chain
0250     ),
0251     .handlers = &rtems_filesystem_null_handlers,
0252     .mt_entry = &rtems_filesystem_null_mt_entry
0253   },
0254 
0255   /*
0256    * The initial reference count accounts for the following references
0257    *  o the root directory of the user environment,
0258    *  o the current directory of the user environment,
0259    *  o the root node of the null file system instance, and
0260    *  o the mount point node of the null file system instance.
0261    */
0262   .reference_count = 4
0263 };
0264 
0265 rtems_user_env_t rtems_global_user_env = {
0266   .current_directory = &rtems_filesystem_global_location_null,
0267   .root_directory = &rtems_filesystem_global_location_null,
0268   .umask = S_IWGRP | S_IWOTH
0269 };
0270 
0271 rtems_user_env_t *rtems_current_user_env_get(void)
0272 {
0273   Thread_Control *executing = _Thread_Get_executing();
0274   rtems_user_env_t *env = executing->user_environment;
0275 
0276   if (env == NULL) {
0277     return &rtems_global_user_env;
0278   }
0279 
0280   return env;
0281 }