Esempio n. 1
0
IMFS_jnode_t *IMFS_create_node_with_control(
  const rtems_filesystem_location_info_t *parentloc,
  const IMFS_node_control *node_control,
  const char *name,
  size_t namelen,
  mode_t mode,
  const IMFS_types_union *info
)
{
  IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info;
  IMFS_jnode_t *node = IMFS_allocate_node(
    fs_info,
    node_control,
    name,
    namelen,
    mode,
    info
  );

  if ( node != NULL ) {
    IMFS_jnode_t *parent = parentloc->node_access;

    /*
     *  This node MUST have a parent, so put it in that directory list.
     */
    IMFS_assert( parent != NULL );
    IMFS_add_to_directory( parent, node );
  }

  return node;
}
Esempio n. 2
0
int IMFS_initialize_support(
  rtems_filesystem_mount_table_entry_t *mt_entry,
  const rtems_filesystem_operations_table *op_table,
  const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT]
)
{
  static int imfs_instance;

  int rv = 0;
  IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );

  if ( fs_info != NULL ) {
    IMFS_jnode_t *root_node;

    fs_info->instance = imfs_instance++;
    memcpy(
      fs_info->node_controls,
      node_controls,
      sizeof( fs_info->node_controls )
    );

    root_node = IMFS_allocate_node(
      fs_info,
      fs_info->node_controls [IMFS_DIRECTORY],
      "",
      0,
      (S_IFDIR | 0755),
      NULL
    );
    if ( root_node != NULL ) {
      mt_entry->fs_info = fs_info;
      mt_entry->ops = op_table;
      mt_entry->pathconf_limits_and_options = &IMFS_LIMITS_AND_OPTIONS;
      mt_entry->mt_fs_root->location.node_access = root_node;
      IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
    } else {
      errno = ENOMEM;
      rv = -1;
    }
  } else {
    errno = ENOMEM;
    rv = -1;
  }

  if ( rv == 0 ) {
    IMFS_determine_bytes_per_block(
      &imfs_memfile_bytes_per_block,
      imfs_rq_memfile_bytes_per_block,
      IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
    );
  }

  return rv;
}
IMFS_jnode_t *IMFS_create_root_node(void)
{
  IMFS_jnode_t        *node;

  /*
   *  Allocate filesystem node and fill in basic information
   */
  node = IMFS_allocate_node( IMFS_DIRECTORY, "", (S_IFDIR | 0755) );
  if ( !node )
    return NULL;

  /*
   *  Set the type specific information
   *
   *  NOTE: Root node is always a directory.
   */
  rtems_chain_initialize_empty(&node->info.directory.Entries);

  return node;
}
/*
 *  Create an IMFS filesystem node of an arbitrary type that is NOT
 *  the root directory node.
 */
IMFS_jnode_t *IMFS_create_node(
  rtems_filesystem_location_info_t *parent_loc,
  IMFS_jnode_types_t                type,
  const char                       *name,
  mode_t                            mode,
  const IMFS_types_union           *info
)
{
  IMFS_jnode_t        *node;
  IMFS_jnode_t        *parent;
  IMFS_fs_info_t      *fs_info;

  /*
   *  MUST have a parent node to call this routine.
   */
  if ( parent_loc == NULL )
    return NULL;

  /*
   *  Allocate filesystem node and fill in basic information
   */
  node  = IMFS_allocate_node( type, name, mode & ~rtems_filesystem_umask );
  if ( !node )
    return NULL;

  /*
   *  Set the type specific information
   */
  switch (type) {
    case IMFS_DIRECTORY:
      rtems_chain_initialize_empty(&node->info.directory.Entries);
      break;

    case IMFS_HARD_LINK:
      node->info.hard_link.link_node = info->hard_link.link_node;
      break;

    case IMFS_SYM_LINK:
      node->info.sym_link.name = info->sym_link.name;
      break;

    case IMFS_DEVICE:
      node->info.device.major = info->device.major;
      node->info.device.minor = info->device.minor;
      break;

    case IMFS_LINEAR_FILE:
      node->info.linearfile.size      = 0;
      node->info.linearfile.direct    = 0;

    case IMFS_MEMORY_FILE:
      node->info.file.size            = 0;
      node->info.file.indirect        = 0;
      node->info.file.doubly_indirect = 0;
      node->info.file.triply_indirect = 0;
      break;

    case IMFS_FIFO:
      node->info.fifo.pipe = NULL;
      break;

    default:
      assert(0);
      break;
  }

  /*
   *  This node MUST have a parent, so put it in that directory list.
   */
  parent       = parent_loc->node_access;
  fs_info      = parent_loc->mt_entry->fs_info;

  node->Parent = parent;
  node->st_ino = ++fs_info->ino_count;

  rtems_chain_append( &parent->info.directory.Entries, &node->Node );

  return node;
}