Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup IMFS
0007  *
0008  * @brief IMFS Make a Generic Node
0009  */
0010 
0011 /*
0012  * Copyright (c) 2012 embedded brains GmbH & Co. KG
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039 
0040 #include <rtems/imfsimpl.h>
0041 
0042 #include <string.h>
0043 
0044 IMFS_jnode_t *IMFS_node_initialize_generic(
0045   IMFS_jnode_t *node,
0046   void *arg
0047 )
0048 {
0049   IMFS_generic_t *generic = (IMFS_generic_t *) node;
0050 
0051   generic->context = arg;
0052 
0053   return node;
0054 }
0055 
0056 int IMFS_make_generic_node(
0057   const char              *path,
0058   mode_t                   mode,
0059   const IMFS_node_control *node_control,
0060   void                    *context
0061 )
0062 {
0063   return IMFS_make_node(
0064     path,
0065     mode,
0066     node_control,
0067     sizeof( IMFS_generic_t ),
0068     context
0069   );
0070 }
0071 
0072 int IMFS_make_node(
0073   const char              *path,
0074   mode_t                   mode,
0075   const IMFS_node_control *node_control,
0076   size_t                   node_size,
0077   void                    *context
0078 )
0079 {
0080   int rv = 0;
0081 
0082   mode &= ~rtems_filesystem_umask;
0083 
0084   switch (mode & S_IFMT) {
0085     case S_IFBLK:
0086     case S_IFCHR:
0087     case S_IFIFO:
0088     case S_IFREG:
0089     case S_IFSOCK:
0090       break;
0091     default:
0092       errno = EINVAL;
0093       rv = -1;
0094       break;
0095   }
0096 
0097   if ( rv == 0 ) {
0098     rtems_filesystem_eval_path_context_t ctx;
0099     int eval_flags = RTEMS_FS_FOLLOW_LINK
0100       | RTEMS_FS_MAKE
0101       | RTEMS_FS_EXCLUSIVE;
0102     const rtems_filesystem_location_info_t *currentloc =
0103       rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
0104 
0105     if ( IMFS_is_imfs_instance( currentloc ) ) {
0106       IMFS_jnode_t *new_node = IMFS_create_node(
0107         currentloc,
0108         node_control,
0109         node_size,
0110         rtems_filesystem_eval_path_get_token( &ctx ),
0111         rtems_filesystem_eval_path_get_tokenlen( &ctx ),
0112         mode,
0113         context
0114       );
0115 
0116       if ( new_node != NULL ) {
0117         IMFS_jnode_t *parent = currentloc->node_access;
0118 
0119         IMFS_mtime_ctime_update( parent );
0120       } else {
0121         rv = -1;
0122       }
0123     } else {
0124       rtems_filesystem_eval_path_error( &ctx, ENOTSUP );
0125       rv = -1;
0126     }
0127 
0128     rtems_filesystem_eval_path_cleanup( &ctx );
0129   }
0130 
0131   return rv;
0132 }