Fat16 Class Reference

Fat16 implements a minimal Arduino FAT16 Library. More...

#include <Fat16.h>

Inheritance diagram for Fat16:

Inheritance graph
[legend]
Collaboration diagram for Fat16:

Collaboration graph
[legend]

List of all members.

Public Member Functions

uint8_t close (void)
uint8_t create (char *fileName)
uint32_t fileSize (void)
uint8_t isOpen (void)
uint8_t open (char *fileName)
uint8_t open (uint16_t entry)
int16_t read (void)
int16_t read (uint8_t *dst, uint16_t count)
uint32_t readPos (void)
uint8_t seek (uint32_t pos)
uint8_t sync (void)
void write (uint8_t b)
int16_t write (uint8_t *src, uint16_t count)

Static Public Member Functions

static uint8_t init (BlockDevice &dev, uint8_t part)
static dir_treadDir (uint16_t &entry, uint8_t skip=(DIR_ATT_VOLUME_ID|DIR_ATT_DIRECTORY))
static uint16_t rootDirEntryCount (void)
static void dbgSetDev (BlockDevice &dev)
static uint8_t * dbgCacheBlock (uint32_t blockNumber)
static dir_tdbgCacheDir (uint16_t index)
static uint16_t * dbgCacheFat (uint16_t cluster)


Detailed Description

Fat16 implements a minimal Arduino FAT16 Library.

Fat16 does not support subdirectories or long file names.


Member Function Documentation

uint8_t Fat16::init ( BlockDevice dev,
uint8_t  part 
) [static]

Initialize a FAT16 volume.

Parameters:
[in] dev The BlockDevice where the volume is located.
[in] part The partition to be used. Legal values for part are 1-4 to use the corresponding partition on a device formatted with a MBR, Master Boot Record, or zero if the device is formatted as a super floppy with the FAT boot sector in block zero.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure. reasons for failure include not finding a valid FAT16 file system in the specified partition, a call to init() after a volume has been successful initialized or an I/O error.

static dir_t* Fat16::readDir ( uint16_t &  entry,
uint8_t  skip = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY) 
) [inline, static]

Read the next short, 8.3, directory entry into the cache buffer.

Unused entries and entries for long names are skipped.

The directory entry must not be modified since the cached block containing the entry may be written back to the storage device.

Parameters:
[in,out] entry The search starts at entry and entry is updated with the root directory index of the found directory entry. If the entry is a file, it may be opened by calling open(entry).
[in] skip Skip entries that have these attributes. If skip is not specified, the default is to skip the volume label and directories.
Returns:
A pointer to a dir_t structure for the found directory entry, or NULL if an error occurs or the end of the root directory is reached. On success, entry is set to the index of the found directory entry.

static uint16_t Fat16::rootDirEntryCount ( void   )  [inline, static]

Returns:
The number of entries in the root directory.

uint8_t Fat16::close ( void   ) 

Closes a file and forces cached data and directory information to be written to the storage device.

Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include no file is open or an I/O error.

uint8_t Fat16::create ( char *  fileName  ) 

Create and open a new file.

Note:
This function only creates files in the root directory and only supports short DOS 8.3 names. See open() for more information.
Parameters:
[in] fileName a valid DOS 8.3 file name.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include fileName contains an invalid DOS 8.3 file name, the FAT volume has not been initialized, a file is already open, the file already exists, the root directory is full or an I/O error.

uint32_t Fat16::fileSize ( void   )  [inline]

Returns:
The file's size in bytes. This is also the write position for the file.

uint8_t Fat16::isOpen ( void   )  [inline]

Checks the file's open/closed status for this instance of Fat16.

Returns:
The value true if a file is open otherwise false;

uint8_t Fat16::open ( char *  fileName  ) 

Open a file for read and write by file name. Two file positions are maintained. The write position is at the end of the file. Data is appended to the file. The read position starts at the beginning of the file.

Note:
The file must be in the root directory and must have a DOS 8.3 name.
Parameters:
[in] fileName A valid 8.3 DOS name for a file in the root directory.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the FAT volume has not been initialized, a file is already open, fileName is invalid, the file does not exist or it is a directory.

uint8_t Fat16::open ( uint16_t  index  ) 

Open a file for read and write by file index. Two file positions are maintained. The write position is at the end of the file. Data is appended to the file. The read position starts at the beginning of the file.

Parameters:
[in] index The root directory index of the file to be opened. See readDir().
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the FAT volume has not been initialized, a file is already open, index is invalid or is not the index of a file.

int16_t Fat16::read ( void   ) 

Read the next byte from a file.

Returns:
For success read returns the next byte in the file as an int. If an error occurs or end of file is reached -1 is returned.

int16_t Fat16::read ( uint8_t *  dst,
uint16_t  count 
)

Read data from a file at starting at the current read position.

Parameters:
[out] dst Pointer to the location that will receive the data.
[in] count Maximum number of bytes to read.
Returns:
For success read returns the number of bytes read. A value less than count, including zero, may be returned if end of file is reached. If an error occurs, read returns -1. Possible errors include read called before a file has been opened, corrupt file system or I/O error.

uint32_t Fat16::readPos ( void   )  [inline]

Returns:
The read position in bytes.

uint8_t Fat16::seek ( uint32_t  pos  ) 

Sets the file's read position.

Parameters:
[in] pos The new read position in bytes from the beginning of the file.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure.

uint8_t Fat16::sync ( void   ) 

The sync() call causes all modified data and directory fields to be written to the storage device.

Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include a call to sync() before a file has been opened or an I/O error.

void Fat16::write ( uint8_t  b  )  [virtual]

Append one byte to a file. This function is called by Arduino's Print class.

Note:
The byte is moved to the cache but may not be written to the storage device until sync() is called.
Parameters:
[in] b The byte to be written.

Reimplemented from Print.

int16_t Fat16::write ( uint8_t *  src,
uint16_t  count 
)

Write data at the end of an open file.

Note:
Data is moved to the cache but may not be written to the storage device until sync() is called.
Parameters:
[in] src Pointer to the location of the data to be written.
[in] count Number of bytes to write.
Returns:
For success write() returns the number of bytes written, always count. If an error occurs, write() returns -1. Possible errors include write() is called before a file has been opened, write is called for a read-only file, device is full, a corrupt file system or an I/O error.

static void Fat16::dbgSetDev ( BlockDevice dev  )  [inline, static]

For debug only. Do not use in applications.

static uint8_t* Fat16::dbgCacheBlock ( uint32_t  blockNumber  )  [inline, static]

For debug only. Do not use in applications.

static dir_t* Fat16::dbgCacheDir ( uint16_t  index  )  [inline, static]

For debug only. Do not use in applications.

static uint16_t* Fat16::dbgCacheFat ( uint16_t  cluster  )  [inline, static]

For debug only. Do not use in applications.


The documentation for this class was generated from the following files:

Generated on Thu Oct 9 08:22:19 2008 for Fat16 by  doxygen 1.5.6