MityDSP Documentation Index

e:/hudson/workspace/MityDSP MDK Release/trunk/sw/src/fatfs/fatfs_int.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <file.h>
#include <assert.h>
#include <std.h>
#include <clk.h>
#include <errno.h>
#include "fatfs.h"
#include "private/fatfs_int.h"

Defines

#define MAX_FILENO   21
 hardcoded max 21 FDS. TODO - make dynamic...
#define SEC_PER_MIN   60
#define MIN_PER_HOUR   60
#define HOURS_PER_DAY   24
#define DAYS_PER_YEAR   365

Functions

int FAT_Get83Extension (char *apBuffer, char *apBasename, char *apExtension)
 Utility to strip 8.3 file name into basename and extension.
int FAT_finddirent (const char *apPath, tsFATDevData *apDevData, uint32_t *apDirStartCluster, uint32_t *apDirEntryCluster, uint32_t *apDirEntryInCluster, tsDirEntry *apFileEntry)
 Given a path, locates parent directory cluster information and directory entry information.
int FAT_createdirent (const char *apNewPath, tsFATDevData *apDevData)
 Given a path to a non-existent entry in a directory, this function creates a new subdirectory at the provided path.
int FAT_GetNextCluster (tsFATDevData *apDevData, int anCluster)
 Find the Next Cluster In the Chain.
int FAT_UpdateDirEntry (tsFATFileData *apFileData)
 Updates Directory Data based on current file structure (cached) information.
int FAT_CountFreeClusters (tsFATDevData *apDevData)
 Count free clusters on the FAT Table.
int FAT_TruncateCluster (tsFATDevData *apDevData, int anCluster)
 Mark the current cluster as the end of chain, and free all following clusters.
int FAT_FreeCluster (tsFATDevData *apDevData, int anCluster)
 Free a chain of clusters in the FAT Table.
int FAT_GetFreeCluster (tsFATDevData *apDevData, int anChainedCluster)
 Find a free cluster on the FAT Table and Mark it used with EOC.
int FAT_open (const char *apPath, unsigned int anFlags, int anFileno, tsFATDevData *apDevData)
 Attempt to open an existing file or create a new file at the given path.
int FAT_close (int anFileno)
 Close a file descriptor assocaited with a FAT device.
int FAT_read (int anFileno, char *apBuffer, unsigned int anCount)
 Read implementation for a FAT filesystem.
int FAT_write (int anFileno, const char *apBuffer, unsigned int anCount)
 Write implementation for a FAT filesystem.
off_t FAT_lseek (int anFileno, off_t anOffset, int aeOrigin)
 FAT driver lseek implementation.
int FAT_unlink (const char *apPath, tsFATDevData *apDevData)
 Delete a file.
int FAT_rename (const char *apOldPath, const char *apNewPath, tsFATDevData *apDevData)
 Rename a file on a FAT device.
int FAT_gettime (unsigned int *apYear, unsigned int *apMonth, unsigned int *apDay, unsigned int *apHours, unsigned int *apMinutes, unsigned int *apSeconds, unsigned int *apHundredths)
 Default time callback, used when access to a RTC device is not provided to the FAT filesystem driver.

Variables

tsFATFileData gpFileData [MAX_FILENO]
 data needed for each file descriptor
static char FAT_valid_chars [128]

Define Documentation

#define MAX_FILENO   21

hardcoded max 21 FDS. TODO - make dynamic...

#define SEC_PER_MIN   60
#define MIN_PER_HOUR   60
#define HOURS_PER_DAY   24
#define DAYS_PER_YEAR   365

Function Documentation

int FAT_Get83Extension ( char *  apBuffer,
char *  apBasename,
char *  apExtension 
)

Utility to strip 8.3 file name into basename and extension.

Parameters:
[in] apBuffer Name to parse.
[out] apBasename Storage for base name
[out] apExtension Storage for file extension
Note:
apBasename is assumed to be at least 9 characters long and apExtension is assumed to be at least 4 characters long.
Returns:
Zero for success, or FATFS_INVALID_PATH for invalid 8.3 name.
int FAT_finddirent ( const char *  apPath,
tsFATDevData apDevData,
uint32_t *  apDirStartCluster,
uint32_t *  apDirEntryCluster,
uint32_t *  apDirEntryInCluster,
tsDirEntry apFileEntry 
)

Given a path, locates parent directory cluster information and directory entry information.

Parameters:
[in] apPath pointer to null terminated path to file
[in] apDevData FAT interface device data structure
[out] apDirStartCluster holder for found parent directory starting cluster. This value is set 0xFFFFFFFF if the path was not found. For FAT16 the dir_start_cluster will be 0x00000000 if the path points to the root directory (which is not in the FAT Data Area).
[out] apDirEntryCluster holder for found parent directory cluster containing the entry of the file specified in the path. If the file was not found, then this value is set to 0xFFFFFFF.
[out] apDirEntryInCluster the 32 byte index in the dir_entry_cluster containing the location of the file specified. If the file was not found, then this value is set to 0xFFFFFFFF.
[out] apFileEntry a copy of the file entry infromation from the parent directory file, this information is not modified if the file is not found.
Returns:
0 on success, FATFS_INVALID_PATH if parent path was invalid, FATFS_FAT_TYPE_NOT_SUPPORTED if an unsupported FAT type was found, FATFS_DEVICE_READ_FAILED is a device read failure occurs, FATFS_DIR_NOT_FOUND if a subdirectory was not found, and FATFS_FILE_NOT_FOUND if file was not located but parent path was OK.
int FAT_createdirent ( const char *  apNewPath,
tsFATDevData apDevData 
)

Given a path to a non-existent entry in a directory, this function creates a new subdirectory at the provided path.

Parameters:
[in] apNewPath pointer to null terminated path to the directory
[in] apDevData FAT interface device data structure
Returns:
0 on success, FATFS_INVALID_PATH if parent path was invalid, FATFS_FAT_TYPE_NOT_SUPPORTED if an unsupported FAT type was found, FATFS_DEVICE_READ_FAILED if a device read failure occurs, FATFS_DEVICE_WRITE_FAILED if a device write failure occurs, FATFS_DIR_NOT_FOUND if a subdirectory was not found, or FATFS_FILE_ALREADY_EXISTS if the path points to an existing file.
int FAT_GetNextCluster ( tsFATDevData apDevData,
int  anCluster 
)

Find the Next Cluster In the Chain.

Parameters:
[in] apDevData FAT interface device data structure
[in] anCluster Current cluster number
Returns:
0 if no available cluster, FATFS_FAT_TYPE_NOT_SUPPORTED if an unsupported FAT type was found, FATFS_DEVICE_READ_FAILED if a device read failure occurs, otherwise cluster number.
int FAT_UpdateDirEntry ( tsFATFileData apFileData  ) 

Updates Directory Data based on current file structure (cached) information.

Parameters:
[in] apFileData Pointer to file data
Returns:
FATFS_OK on success, FATFS_FAT_TYPE_NOT_SUPPORTED if an unsupported FAT type was found, or FATFS_DEVICE_WRITE_FAILED if a device write failure occurs,
int FAT_CountFreeClusters ( tsFATDevData apDevData  ) 

Count free clusters on the FAT Table.

Parameters:
[in] apDevData Pointer to file system driver
Returns:
The free cluster count, or FATFS_FAT_TYPE_NOT_SUPPORTED if an unsupported FAT type was found, or FATFS_DEVICE_READ_FAILED if a device read failure occurs.
int FAT_TruncateCluster ( tsFATDevData apDevData,
int  anCluster 
)

Mark the current cluster as the end of chain, and free all following clusters.

Parameters:
[in] apDevData Pointer to file system driver
[in] anCluster The head of the chain of clusters to truncate.
Returns:
FATFS_OK (0) if successful, or FATFS_FAT_TYPE_NOT_SUPPORTED if an unsupported FAT type was found, or FATFS_DEVICE_READ_FAILED if a device read failure occurs, or FATFS_DEVICE_WRITE_FAILED if a device write failure occurs.
int FAT_FreeCluster ( tsFATDevData apDevData,
int  anCluster 
)

Free a chain of clusters in the FAT Table.

Parameters:
[in] apDevData Pointer to file system driver
[in] anCluster The head of the chain of clusters to free.
Returns:
FATFS_OK (0) if successful, or FATFS_FAT_TYPE_NOT_SUPPORTED if an unsupported FAT type was found, or FATFS_DEVICE_READ_FAILED if a device read failure occurs, or FATFS_DEVICE_WRITE_FAILED if a device write failure occurs.
int FAT_GetFreeCluster ( tsFATDevData apDevData,
int  anChainedCluster 
)

Find a free cluster on the FAT Table and Mark it used with EOC.

Parameters:
[in] apDevData Pointer to file system driver
[in] anChainedCluster If non-zero, the cluster entry provided will be linked to the newly found free cluster (for file growth)
Returns:
Cluster number allocated (0 if no available cluster), or FATFS_FAT_TYPE_NOT_SUPPORTED if an unsupported FAT type was found, or FATFS_DEVICE_READ_FAILED if a device read failure occurs, or FATFS_DEVICE_WRITE_FAILED if a device write failure occurs.
int FAT_open ( const char *  apPath,
unsigned int  anFlags,
int  anFileno,
tsFATDevData apDevData 
)

Attempt to open an existing file or create a new file at the given path.

Flags indicate actions to be taken.

Parameters:
[in] apPath The complete file path.
[in] anFlags Flags to control actions (O_WRONLY | O_CREAT | O_TRUNC | O_APPEND)
[in] anFileno Internal file descriptor for opened file.
[in] apDevData Pointer to file system driver
Returns:
File number if open succeeded, otherwise a negative value to indicate the type of failure.
int FAT_close ( int  anFileno  ) 

Close a file descriptor assocaited with a FAT device.

Parameters:
[in] anFileno Internal file descriptor for opened file.
Returns:
FATFS_OK on success, negative value on error.
int FAT_read ( int  anFileno,
char *  apBuffer,
unsigned int  anCount 
)

Read implementation for a FAT filesystem.

This routine will up to the specified byte count to the provided buffer from the file referenced by the anFileno file descriptor.

Parameters:
[in] anFileno Internal file descriptor for opened file.
[in] apBuffer Pointer to data to store read data
[in] anCount Number of bytes to read from device
Returns:
Number of bytes read, or a negative number on error.
int FAT_write ( int  anFileno,
const char *  apBuffer,
unsigned int  anCount 
)

Write implementation for a FAT filesystem.

This routine will write count bytes in buffer to the file reference by the anFileno file descriptor.

Parameters:
[in] anFileno Internal file descriptor for opened file.
[in] apBuffer Pointer to data to write.
[in] anCount Number of bytes to write to device
Returns:
Number of bytes written, or a negative number on error.
off_t FAT_lseek ( int  anFileno,
off_t  anOffset,
int  aeOrigin 
)

FAT driver lseek implementation.

Parameters:
[in] anFileno Internal file descriptor for opened file.
[in] anOffset Byte offset from provided origin.
[in] aeOrigin SEEK_SET, SEEK_CUR, or SEEK_END.
Returns:
New file offset, or a negative number on error.
int FAT_unlink ( const char *  apPath,
tsFATDevData apDevData 
)

Delete a file.

Parameters:
[in] apPath Pointer to null terminated path to file
[in] apDevData FAT interface device data structure
Returns:
Zero if successful, or a negative number on error.
int FAT_rename ( const char *  apOldPath,
const char *  apNewPath,
tsFATDevData apDevData 
)

Rename a file on a FAT device.

Parameters:
[in] apOldPath Pointer to null terminated path to current file
[in] apNewPath Pointer to null terminated new path for file
[in] apDevData FAT interface device data structure
Returns:
Zero if successful, or a negative number on error.
int FAT_gettime ( unsigned int *  apYear,
unsigned int *  apMonth,
unsigned int *  apDay,
unsigned int *  apHours,
unsigned int *  apMinutes,
unsigned int *  apSeconds,
unsigned int *  apHundredths 
)

Default time callback, used when access to a RTC device is not provided to the FAT filesystem driver.

It uses the system tick timer to compute a date based on the tick count, offset from midnight on January 1, 2000.

Parameters:
[out] apYear Location to store RTC year (1980-20??)
[out] apMonth Location to store RTC month (1-12)
[out] apDay Location to store RTC day (1-31)
[out] apHours Location to store RTC hour (0-23)
[out] apMinutes Location to store RTC minutes (0-59)
[out] apSeconds Location to store RTC seconds (0-59)
[out] apHundredths Location to store RTC 1/100's seconds (0-99)
Returns:
Zero for success, -1 for failure.

Variable Documentation

data needed for each file descriptor

char FAT_valid_chars[128] [static]
Initial value:
{
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0, '!',   0, '#', '$', '%', '&','\'', '(', ')',   0,   0,   0, '-',   0,   0,
  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',   0,   0,   0,   0,   0,   0,
  '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',   0,   0,   0, '^', '_',
  '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{',   0, '}', '~',   0
}

  
Generated on Wed Mar 28 15:13:58 2012 for FAT File System Library by  Doxygen Version 1.6.1
Copyright © 2009, Critical Link LLC, All rights reserved.