# Petit FatFs Module Application Note

### Considerations on porting to various platform

The Petit FatFs module is assuming following terms on portability.

- ANSI C
  The Petit FatFs module is a middleware that written in ANSI C. There is no platform dependence, so long as the compiler is in compliance with ANSI C.
- Size of integer types
  The Petit FatFs module assumes that size of char/short/long are 8/16/32-bit and int is 16 or 32 bit. These correspondence are defined in integer.h. This will not be a problem on most compilers. When any conflict with existing definitions is occured, you must resolve it with care.

### Memory Usage (R0.02)

| AVR | x86
--- | --- | ---
Compiler | gcc(WinAVR) | VC6
_WORD_ACCESS | 1 | 1
ROM (default) | 2154 | 1698
ROM (!_USE_READ) | -456 | -268
ROM (_USE_DIR) | +974 | +426
ROM (_USE_LSEEK) | +512 | +241
ROM (_USE_WRITE) | +538 | +364
RAM (bss) | 2 | 4
RAM (work) | 44 | 48

This is the size of the Petit FatFs module itself. In addition to this, a low level disk I/O module will be required for a complete function. The size of MMC/SDC module on AVR becomes approximate 620 bytes without write function and 840 bytes with write function.

### Module Size Reduction

Follwing table shows which function is removed by configuration options for the module size reduction.

Function | _USE_READ | _USE_DIR | _USE_LSEEK | _USE_WRITE
0 | 0 | 0 | 0
pf_mount |  |  |  |
pf_open |  |  |  |
pf_read | x |  |  |
pf_lseek |  |  | x |
pf_opendir |  | x |  |
pf_readdir |  | x |  |
pf_write |  |  |  | x

### Performance effective file access

For good performance on reading a file on the small embedded system, application programmer should consider what process is done in the file system module.

The Petit FatFs reads the disk sectors without a sector buffer. This means the file system reads a part of the sector contains the required data every reference point even if they are in the same sector. However the generic storage device are not byte addressable so that the disk I/O layer will read the entire sector and pick up the data bytes from the read data steram.

When read 512 byte data from a file at a time, the data sector will be read only a time. When read that data in byte-by-byte, the data sector will be read 512 times. Therefore the byte-by-byte read request will drastically decrease the read performance. To avoid this stupid read controls, the file data should be read in long block as possible. Sector alignment access is not impotant on the Petit FatFs.

The tiny microcontrollers targeted by Petit FatFs has a limited size of RAM. It may not able to allocate a certain size of read buffer and most type of text processing will require byte-by-byte read operation. The Petit FatFs supports data forwarding feature for such purpose.

### About Petit FatFs License

This is a copy of the Petit FatFs license document that included in the source codes.

    /*----------------------------------------------------------------------------/
    /  Petit FatFs - FAT file system module  R0.02                 (C)ChaN, 2009
    /-----------------------------------------------------------------------------/
    / Petit FatFs module is an open source software to implement FAT file system to
    / small embedded systems. This is a free software and is opened for education,
    / research and commercial developments under license policy of following trems.
    /
    /  Copyright (C) 2009, ChaN, all right reserved.
    /
    / * The Petit FatFs module is a free software and there is NO WARRANTY.
    / * No restriction on use. You can use, modify and redistribute it for
    /   personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
    / * Redistributions of source code must retain the above copyright notice.
    /
    /-----------------------------------------------------------------------------/

Therefore Petit FatFs license is one of the BSD-style license but there is a big difference. Because Petit FatFs is for embedded projects, the conditions for redistributions in binary form, such as embedded code, hex file and binary library, are not specified to increase its usability. The documentation of the distributions need not include about Petit FatFs and its license document, and it may also. Of course Petit FatFs is compatible with the projects under GNU GPL.

Return