wiki:TBR/UserManual/Using_the_RTEMS_DOS_File_System

Version 5 (modified by ChrisJohns, on Sep 12, 2008 at 12:19:10 PM) (diff)

/* ATA 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.

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;

}

return 0;