wiki:TBR/UserManual/Using_the_RTEMS_DOS_File_System

Version 8 (modified by ChrisJohns, on Sep 13, 2008 at 8:24:05 AM) (diff)

/* RAM Disk */

Using the RTEMS DOS File System

RTEMS provides an MS-DOS compatible file system. Currently the implementation provides support FAT12, FAT16 and FAT32 disks and short file-names. Long file-name support is being added. Contact for ChrisJohns? for details.

Configuration is based around the {{{confdefs.h</code> configuration file.

For details of the RTEMS File System see File Systems.

General Configuration

Your application needs a clock driver. The swap out task manages the block hold timers. You also need to use the IMFS as the base file system, configure the number of libio descriptors and indicate the application needs libblock:

/

  • Configure drivers. */

#define CONFIGURE_MAXIMUM_DRIVERS 10 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

/

  • Configure file system and libblock. */

#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20 #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK

The block cache requires configuration. You can configure:

  • CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS : Number of blocks to read ahead of the block read. Default is 32.
  • CONFIGURE_BDBUF_MAX_WRITE_BLOCKS : Number of blocks to pass to the driver when writing to a device. Default is 16.
  • CONFIGURE_SWAPOUT_TASK_PRIORITY : Priority of the swap out task. Default is 15.
  • CONFIGURE_SWAPOUT_SWAP_PERIOD : The period of time in milli-seconds the swap out sleeps for. This is the period of time the block hold timers are updated. Default is 250 msecs.
  • CONFIGURE_SWAPOUT_BLOCK_HOLD : The period of time in milli-seconds a block is held after being modified for the first time before being written to disk. Further updates to the block do not reset the timer. Default time is 1000 msecs.

An example that can be used with a 4.5G IDE disk on a PC with 1G of memory to get great performance coping 250M of files:

#define CONFIGURE_SWAPOUT_TASK_PRIORITY 10 #define CONFIGURE_BDBUF_BUFFER_COUNT 1024 #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 64 #define CONFIGURE_BDBUF_MAX_WRITE_BLOCKS 32

ATA Disk

The ATA driver is in libchip and requires a BSP driver. It is best to take an existing driver and modify it. YOu can locate the various drivers by searching the source tree for {{{IDE_Controller_Table</code>. There are drivers in :

c/src/lib/libbsp/arm/nds/block/block.c c/src/lib/libbsp/i386/pc386/ide/idecfg.c c/src/lib/libbsp/powerpc/gen5200/ide/idecfg.c c/src/lib/libbsp/powerpc/mbx8xx/ide/idecfg.c c/src/lib/libbsp/powerpc/mbx8xx/ide/pcmcia_ide.c

The {{{confdefs.h</code> configuration entry configures the IDE driver and the ATA driver:

#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER #define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 9

Note, the examples given the ATA driver is a higher priority than the cache swap out task. This will make the ATA more responsive to the low levels. It does not have to be configured this way.

Some where in the initialization phase of your application you need to read the IDE disk partition table. You need to provide the path to the IDE block driver. The code is:

extern rtems_status_code rtems_ide_part_table_initialize (const char* );

rtems_status_code sc;

/*

  • Register the IDE Disk driver. */

printf ("Read IDE Disk Partition Table: "); sc = rtems_ide_part_table_initialize ("/dev/ide0"); if (sc != RTEMS_SUCCESSFUL) {

printf ("error: ide partition table not found: %s\n",

rtems_status_text (sc));

return 1;

}

printf ("successful\n");

Once the partition table has been read you can mount partitions. The ATA code will create devices in the device tree for each MSDOS partition found. The first primary partition on a primary IDE disk is called {{{/dev/hda1</code>.

You can use the shell to mount the partition or you can code the mount call directly. Note, the shell can run scripts so you could embedded a simple initialization script that mounts the partition. The shell code to mount is in the function {{{rtems_shell_libc_mounter</code> and the shell command is:

mkdir c mount -t msdos /dev/hda1 /c

The code to mount the same partition to an existing {{{/c</code> directory is:

#include <rtems/dosfs.h> #include <rtems/fsmount.h>

rtems_filesystem_mount_table_entry_t* mt_entry;

if (mount (&mt_entry, &msdos_ops, options, "/dev/hda1", "/c") < 0) {

fprintf (stderr, "mount: mount failed: %s\n", strerror (errno)); return 1;

}

RAM Disk

The RAM disk driver supports a single continuous memory region as a disk. There is no partitions. You can specify the location of the memory to use or the driver can allocate the memory from the heap. The memory is not initialised so you need to format the disk once you have created it.

The RAM disk has a 1:1 block mapping. Block 0 is the first block in the memory region. There is not checking on blocks so a block of memory that survives reset and even power loss such as static RAM cannot be checked for a valid disk image. You should considering using the NV Disk driver in this case.

To configure a RAM disk add this following to a source file in your application. The configuration items are:

# Block size. This is normally 512 for the MSDOS file-system # Number of blocks in the disk drive. The memory size is the block size multiplied by the number of blocks # The location. If NULL the heap is used.

An example is:

/

  • The RAM Disk configuration. */

rtems_ramdisk_config rtems_ramdisk_configuration[] =

{

{

block_size: 512, block_num: 4000, location: NULL

}

};

/

  • The number of RAM Disk configurations. */

size_t rtems_ramdisk_configuration_size = 1;

To use the RAM disk you need to register the driver. For example:

rtems_driver_address_table rtems_flashdisk_io_ops =

RAMDISK_DRIVER_TABLE_ENTRY;

rtems_device_major_number major; rtems_status_code sc;

/*

  • Register the RAM Disk driver. */

printf ("Register RAM Disk Driver: "); sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,

&rtems_ramdisk_io_ops, &major);

if (sc != RTEMS_SUCCESSFUL) {

printf ("error: ramdisk driver not initialised: %s\n",

rtems_status_text (sc));

return 1;

}

printf ("successful\n");

Once the driver has been register you can mount the disk using the shell command of:

mkdir rd mount -t msdos /dev/ramdisk0 /rd

The code to mount the same device to an existing {{{/rd</code> directory is:

#include <rtems/dosfs.h> #include <rtems/fsmount.h>

rtems_filesystem_mount_table_entry_t* mt_entry;

if (mount (&mt_entry, &msdos_ops, options, "/dev/ramdisk0", "/rd") < 0) {

fprintf (stderr, "mount: mount failed: %s\n", strerror (errno)); return 1;

}

NV Disk