source: rtems/cpukit/libfs/src/imfs/imfs_initsupp.c @ c9b005a9

4.104.114.84.95
Last change on this file since c9b005a9 was c9b005a9, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/09/06 at 10:05:27

applied patches for PR1117/1118/1119/1120

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  IMFS Initialization
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <sys/types.h>         /* for mkdir */
19#include <fcntl.h>
20#include <unistd.h>
21#include <stdlib.h>
22
23#include <assert.h>
24
25#include "imfs.h"
26#include <rtems/libio_.h>
27#include <rtems/seterr.h>
28
29#if defined(IMFS_DEBUG)
30#include <stdio.h>
31#endif
32
33/*
34 *  IMFS_determine_bytes_per_block
35 */
36int imfs_memfile_bytes_per_block = 0;
37
38static int IMFS_determine_bytes_per_block(
39  int *dest_bytes_per_block,
40  int requested_bytes_per_block,
41  int default_bytes_per_block
42)
43{
44  rtems_boolean is_valid = FALSE;
45  int bit_mask;
46  /*
47   * check, whether requested bytes per block is valid
48   */
49  for (bit_mask = 16;
50       !is_valid && (bit_mask <= 512);
51       bit_mask <<= 1) {
52    if (bit_mask == requested_bytes_per_block) {
53      is_valid = TRUE;
54    }
55  }
56  *dest_bytes_per_block = ((is_valid)
57                           ? requested_bytes_per_block
58                           : default_bytes_per_block);
59  return 0;
60   
61}
62
63
64/*
65 *  IMFS_initialize
66 */
67
68int IMFS_initialize_support(
69  rtems_filesystem_mount_table_entry_t *temp_mt_entry,
70   rtems_filesystem_operations_table    *op_table,
71   rtems_filesystem_file_handlers_r     *memfile_handlers,
72   rtems_filesystem_file_handlers_r     *directory_handlers
73)
74{
75  IMFS_fs_info_t                        *fs_info;
76  IMFS_jnode_t                          *jnode;
77
78  /*
79   * determine/check value for imfs_memfile_bytes_per_block
80   */
81  IMFS_determine_bytes_per_block(&imfs_memfile_bytes_per_block,
82                                 imfs_rq_memfile_bytes_per_block,
83                                 IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK);
84 
85  /*
86   *  Create the root node
87   *
88   *  NOTE: UNIX root is 755 and owned by root/root (0/0).
89   */
90
91  temp_mt_entry->mt_fs_root.node_access = IMFS_create_node(
92    NULL,
93    IMFS_DIRECTORY,
94    "",
95    ( S_IFDIR | 0755 ),
96    NULL
97  );
98
99  temp_mt_entry->mt_fs_root.handlers         = directory_handlers;
100  temp_mt_entry->mt_fs_root.ops              = op_table;
101  temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
102
103  /*
104   * Create custom file system data.
105   */
106  fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) );
107  if ( !fs_info ){
108    free(temp_mt_entry->mt_fs_root.node_access);
109    rtems_set_errno_and_return_minus_one(ENOMEM);
110  }
111  temp_mt_entry->fs_info = fs_info;
112
113  /*
114   * Set st_ino for the root to 1.
115   */
116
117  fs_info->ino_count             = 1;
118  fs_info->memfile_handlers      = memfile_handlers;
119  fs_info->directory_handlers    = directory_handlers;
120
121  jnode = temp_mt_entry->mt_fs_root.node_access;
122  jnode->st_ino = fs_info->ino_count;
123
124  return 0;
125}
Note: See TracBrowser for help on using the repository browser.