PowerFile overview








Introduction

The PowerFile code provides a filing system for embedded applications. It can be used in conjunction with the PowerNet TCP/IP stack and web server, and with the PowerView embedded GUI. PowerFile was originally developed by CEM Systems Ltd. for use in networked access control systems. This release of PowerFile is distributed under license by MicroProcessor Engineering.

PowerFile is written for the MPE Forth cross compilers, and takes full advantage of the VFX code generator. The use of a 32 bit Forth is assumed. PowerFile provides:

  • Simple configuration. Different applications can use different configurations held in a separate configuration file.
  • Files wih the standard ANS Forth interface for code compatibility with other applications.
  • Directories are nestable to a configured level.
  • Command line tools
  • Diagnostics
  • Easy interface to a range of mass storage media, including USB memory sticks, CompactFlash, IDE/ATAPI drives and serial EEPROM or DataFlash.



  • Disk structure

    The PowerFile data structures are loosely based on the pSOS pHILE system. All data items except for strings are 32 bit items known as elements.

    The media surface is divided into blocks, which usually correspond to disk sectors. The size of these blocks vary depending on the media. Normally each block is 512 bytes long.

    Disk blocks are allocated from a volume bitmap, which indicates whether or not the block is available for use. The bitmap is contained in a special file called bitmap.sys.

    Each file on the disc is controlled by a File List Descriptor (FLDs). When these entries are read into RAM they are referred to as File Control Blocks (FCBs). All the FLDs are contained in a special file called flist.sys. Each FLD contains data that describes the file's location on the disk

    Directories are files which contain records consisting of the file name and a record number in flist.sys. The current directory is called '.' and the next directory level down (closer to the root) is called '..'. The directory separator character is '/' by default. File and directory names have a maximum length of 12 characters including a count byte. A subdirectory is just a special file in a directory.

    When the disc is initialised (formatted), the first few blocks are set up and a root directory and the special files are created. The special files are of fixed length.

    
    Number     Item            Comment
    0               Boot load 1     Not used
    1          Boot load 2     Not used
    2          Root block      Defines volume
    3          Root Directory
    4          Usage bit map   Defines used blocks on media
    4 + X      File list descriptors  File layouts
    4 + X + Y  Data area

    Root Block

    
    Element Item               Comment
    0       Bit map address    Location block of usage bit map
    1       File list address  Location block of file lists
    2       Data address       Location block of data.
    3       Creation time      Date and time when created
    4       Volume name
    7       Volume size        Number of blocks
    8       File list size     Number of file list descriptors
    9       Validation key

    Directories

    Each entry has a size of 16 bytes, so each block of 512 bytes will hold 32 file names.

    
    Item         Size (bytes)       Comment
    File number  4             Index to record in FLD blocks
    Name         12            Count byte + 11 chars max.

    Volume bit map

    This table is a binary representation of the blocks on the media surface. When a block is defined as used, its state will be changed from a 0 to a 1. This has the file name of bitmap.sys and its size is fixed when the media is initialised, based on the size of the media device in use.

    File list descriptor

    Every file has a file list descriptor record associated with it. They are contained in the special file flist.sys whose size is fixed when the media is initialised. This size is determined by data in the configuration file FSconfig.fth from the maximum number of files and directories that can be held on the media. Each entry is 128 bytes long, and is copied into RAM when the file is opened.

    
    Element  Item                  Description
    0        Next FCB              RAM FCB only
    1        File size (bytes)
    2        File size (blocks)
    3        File type             System, data, directory file
    4        Modification time
    5        Expansion size        Minimum size increment
    6        Open occurrences      RAM FCB only
    7        File list descriptor  Index in FLIST.SYS
    8        Extent start 0        Block number of first data block
    9        Extent size 0         Number of contiguous blocks used
    10..27   Extents 1..9          For a total of 10 extents
    28       Indirect block
    29       Not used
    30       Not used
    31       Not used



    Software data structures

    Only the two most important structures are described here. All the others can be found in the source code file STRUCTS.FTH.

    Open file table

    Every task has a series of Open File Tables, one for every open file it is using. There is a limit to the number of files that a task may have open at the same time.

    
    Element  Item
    0        Read/write pointer
    1        File control block pointer
    2        File FLD number

    File control block

    Every open file has a File Control Block (FCB) associated with it. More than one task can have access to the same FCB. The system has a fixed number of FCBs, created at startup of the system. These contain a copy of the FLD for the particular open file to permit access to the data.