Changeset a2f5c7e1 in rtems


Ignore:
Timestamp:
Feb 8, 2015, 3:09:27 PM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
a9df916
Parents:
11026956
git-author:
Sebastian Huber <sebastian.huber@…> (02/08/15 15:09:27)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/12/15 19:53:35)
Message:

IMFS: Allow static initialization of FS info

Location:
cpukit/libfs/src/imfs
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/imfs/fifoimfs_init.c

    r11026956 ra2f5c7e1  
    2626#include "imfs.h"
    2727
     28#include <stdlib.h>
     29
     30#include <rtems/seterr.h>
     31
    2832const rtems_filesystem_operations_table fifoIMFS_ops = {
    2933  .lock_h = rtems_filesystem_default_lock,
     
    4852};
    4953
    50 static const IMFS_mknod_control *const
    51   IMFS_fifo_mknod_controls[IMFS_TYPE_COUNT] = {
    52   [IMFS_DIRECTORY] = &IMFS_mknod_control_directory,
    53   [IMFS_DEVICE] = &IMFS_mknod_control_device,
    54   [IMFS_MEMORY_FILE] = &IMFS_mknod_control_memfile,
    55   [IMFS_FIFO] = &IMFS_mknod_control_fifo
     54static const IMFS_mknod_controls IMFS_fifo_mknod_controls = {
     55  .directory = &IMFS_mknod_control_directory,
     56  .device = &IMFS_mknod_control_device,
     57  .file = &IMFS_mknod_control_memfile,
     58  .fifo = &IMFS_mknod_control_fifo
    5659};
    5760
     
    6164)
    6265{
    63   return IMFS_initialize_support(
    64     mt_entry,
    65     &fifoIMFS_ops,
    66     IMFS_fifo_mknod_controls
    67   );
     66  IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
     67  IMFS_mount_data mount_data = {
     68    .fs_info = fs_info,
     69    .ops = &fifoIMFS_ops,
     70    .mknod_controls = &IMFS_fifo_mknod_controls
     71  };
     72
     73  if ( fs_info == NULL ) {
     74    rtems_set_errno_and_return_minus_one( ENOMEM );
     75  }
     76
     77  return IMFS_initialize_support( mt_entry, &mount_data );
    6878}
  • cpukit/libfs/src/imfs/imfs.h

    r11026956 ra2f5c7e1  
    9595  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
    9696
    97 /*
    98  *  What types of IMFS file systems entities there can be.
    99  */
    100 typedef enum {
    101   IMFS_DIRECTORY,
    102   IMFS_DEVICE,
    103   IMFS_MEMORY_FILE,
    104   IMFS_FIFO
    105 } IMFS_jnode_types_t;
    106 
    107 #define IMFS_TYPE_COUNT (IMFS_FIFO + 1)
    108 
    10997/** @} */
    11098
     
    376364
    377365typedef struct {
     366  const IMFS_mknod_control *directory;
     367  const IMFS_mknod_control *device;
     368  const IMFS_mknod_control *file;
     369  const IMFS_mknod_control *fifo;
     370} IMFS_mknod_controls;
     371
     372typedef struct {
    378373  IMFS_directory_t Root_directory;
    379   const IMFS_mknod_control *mknod_controls[ IMFS_TYPE_COUNT ];
     374  const IMFS_mknod_controls *mknod_controls;
    380375} IMFS_fs_info_t;
     376
     377typedef struct {
     378  IMFS_fs_info_t *fs_info;
     379  const rtems_filesystem_operations_table *ops;
     380  const IMFS_mknod_controls *mknod_controls;
     381} IMFS_mount_data;
    381382
    382383/*
     
    416417);
    417418
    418 /**
    419  * @brief IMFS initialization support.
    420  */
    421419extern int IMFS_initialize_support(
    422420  rtems_filesystem_mount_table_entry_t *mt_entry,
    423   const rtems_filesystem_operations_table *op_table,
    424   const IMFS_mknod_control *const mknod_controls[ IMFS_TYPE_COUNT ]
    425 );
     421  const void                           *data
     422);
     423
    426424/**
    427425 * @brief Unmount this instance of IMFS.
  • cpukit/libfs/src/imfs/imfs_init.c

    r11026956 ra2f5c7e1  
    2222#include "imfs.h"
    2323
     24#include <stdlib.h>
     25
     26#include <rtems/seterr.h>
     27
    2428const rtems_filesystem_operations_table IMFS_ops = {
    2529  .lock_h = rtems_filesystem_default_lock,
     
    4448};
    4549
    46 static const IMFS_mknod_control *const
    47   IMFS_mknod_controls[ IMFS_TYPE_COUNT ] = {
    48   [IMFS_DIRECTORY] = &IMFS_mknod_control_directory,
    49   [IMFS_DEVICE] = &IMFS_mknod_control_device,
    50   [IMFS_MEMORY_FILE] = &IMFS_mknod_control_memfile,
    51   [IMFS_FIFO] = &IMFS_mknod_control_enosys
     50static const IMFS_mknod_controls IMFS_default_mknod_controls = {
     51  .directory = &IMFS_mknod_control_directory,
     52  .device = &IMFS_mknod_control_device,
     53  .file = &IMFS_mknod_control_memfile,
     54  .fifo = &IMFS_mknod_control_enosys
    5255};
    5356
     
    5760)
    5861{
    59   return IMFS_initialize_support(
    60     mt_entry,
    61     &IMFS_ops,
    62     IMFS_mknod_controls
    63   );
     62  IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
     63  IMFS_mount_data mount_data = {
     64    .fs_info = fs_info,
     65    .ops = &IMFS_ops,
     66    .mknod_controls = &IMFS_default_mknod_controls
     67  };
     68
     69  if ( fs_info == NULL ) {
     70    rtems_set_errno_and_return_minus_one( ENOMEM );
     71  }
     72
     73  return IMFS_initialize_support( mt_entry, &mount_data );
    6474}
  • cpukit/libfs/src/imfs/imfs_initsupp.c

    r11026956 ra2f5c7e1  
    105105int IMFS_initialize_support(
    106106  rtems_filesystem_mount_table_entry_t *mt_entry,
    107   const rtems_filesystem_operations_table *op_table,
    108   const IMFS_mknod_control *const mknod_controls[ IMFS_TYPE_COUNT ]
    109 )
    110 {
    111   int rv = 0;
    112   IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
    113 
    114   if ( fs_info != NULL ) {
    115     IMFS_jnode_t *root_node;
    116 
    117     memcpy(
    118       fs_info->mknod_controls,
    119       mknod_controls,
    120       sizeof( fs_info->mknod_controls )
    121     );
    122 
    123     root_node = IMFS_initialize_node(
    124       &fs_info->Root_directory.Node,
    125       &fs_info->mknod_controls[ IMFS_DIRECTORY ]->node_control,
    126       "",
    127       0,
    128       (S_IFDIR | 0755),
    129       NULL
    130     );
    131     IMFS_assert( root_node != NULL );
    132 
    133     mt_entry->fs_info = fs_info;
    134     mt_entry->ops = op_table;
    135     mt_entry->pathconf_limits_and_options = &IMFS_LIMITS_AND_OPTIONS;
    136     mt_entry->mt_fs_root->location.node_access = root_node;
    137     IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
    138   } else {
    139     errno = ENOMEM;
    140     rv = -1;
    141   }
    142 
    143   if ( rv == 0 ) {
    144     IMFS_determine_bytes_per_block(
    145       &imfs_memfile_bytes_per_block,
    146       imfs_rq_memfile_bytes_per_block,
    147       IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
    148     );
    149   }
    150 
    151   return rv;
     107  const void                           *data
     108)
     109{
     110  const IMFS_mount_data *mount_data = data;
     111  IMFS_fs_info_t *fs_info = mount_data->fs_info;
     112  IMFS_jnode_t *root_node;
     113
     114  fs_info->mknod_controls = mount_data->mknod_controls;
     115
     116  root_node = IMFS_initialize_node(
     117    &fs_info->Root_directory.Node,
     118    &fs_info->mknod_controls->directory->node_control,
     119    "",
     120    0,
     121    (S_IFDIR | 0755),
     122    NULL
     123  );
     124  IMFS_assert( root_node != NULL );
     125
     126  mt_entry->fs_info = fs_info;
     127  mt_entry->ops = mount_data->ops;
     128  mt_entry->pathconf_limits_and_options = &IMFS_LIMITS_AND_OPTIONS;
     129  mt_entry->mt_fs_root->location.node_access = root_node;
     130  IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
     131
     132  IMFS_determine_bytes_per_block(
     133    &imfs_memfile_bytes_per_block,
     134    imfs_rq_memfile_bytes_per_block,
     135    IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
     136  );
     137
     138  return 0;
    152139}
    153140
  • cpukit/libfs/src/imfs/imfs_mknod.c

    r11026956 ra2f5c7e1  
    2424#include "imfs.h"
    2525
    26 static IMFS_jnode_types_t get_type( mode_t mode )
     26static const IMFS_mknod_control *get_control(
     27  const IMFS_mknod_controls *controls,
     28  mode_t mode
     29)
    2730{
    2831  if ( S_ISDIR( mode ) ) {
    29     return IMFS_DIRECTORY;
     32    return controls->directory;
    3033  } else if ( S_ISBLK( mode ) || S_ISCHR( mode ) ) {
    31     return IMFS_DEVICE;
    32   } else if (S_ISFIFO( mode )) {
    33     return IMFS_FIFO;
     34    return controls->device;
     35  } else if ( S_ISFIFO( mode ) ) {
     36    return controls->fifo;
    3437  } else {
    3538    IMFS_assert( S_ISREG( mode ) );
    36     return IMFS_MEMORY_FILE;
     39    return controls->file;
    3740  }
    3841}
     
    4952  const IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info;
    5053  const IMFS_mknod_control *mknod_control =
    51     fs_info->mknod_controls[ get_type( mode ) ];
     54    get_control( fs_info->mknod_controls, mode );
    5255  IMFS_jnode_t *new_node;
    5356
  • cpukit/libfs/src/imfs/miniimfs_init.c

    r11026956 ra2f5c7e1  
    2222#include "imfs.h"
    2323
     24#include <stdlib.h>
     25
     26#include <rtems/seterr.h>
     27
    2428const rtems_filesystem_operations_table miniIMFS_ops = {
    2529  .lock_h = rtems_filesystem_default_lock,
     
    4448};
    4549
    46 static const IMFS_mknod_control *const
    47   IMFS_mini_mknod_controls[ IMFS_TYPE_COUNT ] = {
    48   [IMFS_DIRECTORY] = &IMFS_mknod_control_directory,
    49   [IMFS_DEVICE] = &IMFS_mknod_control_device,
    50   [IMFS_MEMORY_FILE] = &IMFS_mknod_control_memfile,
    51   [IMFS_FIFO] = &IMFS_mknod_control_enosys
     50static const IMFS_mknod_controls IMFS_mini_mknod_controls = {
     51  .directory = &IMFS_mknod_control_directory,
     52  .device = &IMFS_mknod_control_device,
     53  .file = &IMFS_mknod_control_memfile,
     54  .fifo = &IMFS_mknod_control_enosys
    5255};
    5356
     
    5760)
    5861{
    59   return IMFS_initialize_support(
    60     mt_entry,
    61     &miniIMFS_ops,
    62     IMFS_mini_mknod_controls
    63   );
     62  IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
     63  IMFS_mount_data mount_data = {
     64    .fs_info = fs_info,
     65    .ops = &miniIMFS_ops,
     66    .mknod_controls = &IMFS_mini_mknod_controls
     67  };
     68
     69  if ( fs_info == NULL ) {
     70    rtems_set_errno_and_return_minus_one( ENOMEM );
     71  }
     72
     73  return IMFS_initialize_support( mt_entry, &mount_data );
    6474}
Note: See TracChangeset for help on using the changeset viewer.