File indexing completed on 2025-05-11 08:24:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039
0040 #include <rtems/imfsimpl.h>
0041
0042 int IMFS_add_node( const char *path, IMFS_jnode_t *node, void *arg )
0043 {
0044 mode_t mode;
0045 rtems_filesystem_eval_path_context_t ctx;
0046 const rtems_filesystem_location_info_t *currentloc;
0047 int eval_flags;
0048 int rv;
0049
0050 mode = node->st_mode;
0051 mode &= ~rtems_filesystem_umask;
0052
0053 switch (mode & S_IFMT) {
0054 case S_IFBLK:
0055 case S_IFCHR:
0056 case S_IFIFO:
0057 case S_IFREG:
0058 case S_IFSOCK:
0059 break;
0060 default:
0061 errno = EINVAL;
0062 return -1;
0063 }
0064
0065 eval_flags = RTEMS_FS_FOLLOW_LINK;
0066 currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
0067
0068 if ( IMFS_is_imfs_instance( currentloc ) ) {
0069 eval_flags = RTEMS_FS_MAKE | RTEMS_FS_EXCLUSIVE;
0070 rtems_filesystem_eval_path_set_flags( &ctx, eval_flags );
0071 rtems_filesystem_eval_path_set_path( &ctx, node->name, node->namelen );
0072 rtems_filesystem_eval_path_continue( &ctx );
0073
0074 if ( rtems_filesystem_eval_path_get_token( &ctx ) == node->name ) {
0075 IMFS_assert(
0076 rtems_filesystem_eval_path_get_tokenlen( &ctx ) == node->namelen
0077 );
0078 node = IMFS_initialize_node(
0079 node,
0080 node->control,
0081 node->name,
0082 node->namelen,
0083 mode,
0084 arg
0085 );
0086 if ( node != NULL ) {
0087 IMFS_jnode_t *parent;
0088
0089 currentloc = rtems_filesystem_eval_path_get_currentloc( &ctx );
0090 parent = currentloc->node_access;
0091 IMFS_assert( parent != NULL );
0092 IMFS_add_to_directory( parent, node );
0093 IMFS_mtime_ctime_update( parent );
0094 rv = 0;
0095 } else {
0096 rv = -1;
0097 }
0098 } else {
0099 if ( rtems_filesystem_eval_path_get_token( &ctx ) != NULL ) {
0100 rtems_filesystem_eval_path_error( &ctx, EINVAL );
0101 }
0102
0103 rv = -1;
0104 }
0105 } else {
0106 rtems_filesystem_eval_path_error( &ctx, ENOTSUP );
0107 rv = -1;
0108 }
0109
0110 rtems_filesystem_eval_path_cleanup( &ctx );
0111 return rv;
0112 }