151 | | = RFS Programable Configuration = |
| 151 | = RFS Programmable Configuration = |
| 152 | |
| 153 | |
| 154 | The RFS can be configured and manage directly from your software. To format a disk include <tt>rtems-rfs-format.h</tt> in your application code then create a variable of type <tt>rtems_rfs_format_config</tt> and initialise it to 0: |
| 155 | |
| 156 | #include <rtems-rfs-format.h> |
| 157 | |
| 158 | rtems_rfs_format_config config; |
| 159 | memset (&config, 0, sizeof (rtems_rfs_format_config)); |
| 160 | |
| 161 | The <tt>rtems_rfs_format_config</tt> structure has the following fields: |
| 162 | |
| 163 | <blockquote> |
| 164 | ;<tt>block_size</tt> : The size of a block. If 0 the formatter will determine an optimal block by looking at the size of the disk. |
| 165 | ;<tt>group_blocks</tt> : The number of blocks in a group. If 0 the formatter will attempt to make a group have as many blocks as bit fit in a block. This minimises the number of groups. |
| 166 | ;<tt>group_inodes</tt> : Number of inodes in a group. If 0 the formatter will use the percentage configuration field to determine the number of inodes. |
| 167 | ;<tt>inode_overhead</tt> : The percentage overhead inodes consume. The percentage value, eg 1 for 1% means 1% of the total blocks will be used by inodes. If 0 the formatter will assume a value of 1%. If you know you will have only a few files you can limit the amount by using the group_inodes field. |
| 168 | ;<tt>initialise_inodes</tt> : Initialise the inodes. By default the formatter will only initialise the superblock and the group allocator block and inode bit maps. An unallocated block or inode will not be referenced by the file system therefore its contents are not important. If you set this field to <tt>true</tt> the formatter will initialise all inodes to a know state. |
| 169 | ;<tt>verbose</tt> : If set to <tt>true</tt> the formatter will output various configuration settings as well as the format progress. |
| 170 | </blockquote> |
| 171 | |
| 172 | When the configuration has been set call the format routine. In this example the RAM disk is being formatted: |
| 173 | |
| 174 | const char* driver = "/dev/rda"; |
| 175 | if (rtems_rfs_format (driver, &config) < 0) |
| 176 | printf ("error: format of %s failed: %s\n", driver, strerror (errno)); |
| 177 | |
| 178 | With a formatted disk you can mount it using the standard <tt>mount</tt> call: |
| 179 | |
| 180 | #include <rtems-rfs.h> |
| 181 | |
| 182 | rtems_filesystem_mount_table_entry_t* mt_entry; |
| 183 | char* driver = "/dev/rda"; |
| 184 | char* path = "/rd"; |
| 185 | if (mount (&mt_entry, &rtems_rfs_ops, 0, driver, path)) |
| 186 | printf ("error: mount of %s to %s failed: %s\n, |
| 187 | driver, path, strerror (errno)); |