MityDSP Documentation Index

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

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <file.h>
#include <ctype.h>
#include "fatfs.h"
#include "private/fatfs_int.h"
#include "version.h"
#include "string_extras.h"

Classes

struct  FAT_DIR_int
 This structure is used to keep track of a directory structure used by FAT_readdir(), FAT_opendir(), etc. More...

Defines

#define MAX_NUM_DRIVERS   3
#define FAT_OPEN_DEF(X, Y)
 The following compiler gymnastics is due to the fact that the TI file system hooks strip the device name off of the path prior to calling the specified function, so there is no way the support multiple FAT devices using the same functions unless you slip in an argument telling the real functions what device they are using.
#define FAT_RENAME_DEF(X, Y)
#define FAT_UNLINK_DEF(X, Y)

Typedefs

typedef int(* fat_open )(const char *, unsigned int, int)
typedef int(* fat_rename )(const char *, const char *)
typedef int(* fat_unlink )(const char *)

Functions

int remove_device (char *name)
int RegisterFATDriver (RAWREAD apRawReadFunc, RAWWRITE apRawWriteFunc, GETTIME apGetTimeFunc, tsDevInfo *apRawInfo, char *apDeviceName, void *apDriverData)
 Register a FAT device/driver with BIOS CIO utilities.
int RemoveFATDriver (char *apDeviceName)
 REMOVE a FAT device/driver with BIOS CIO utilities.
int FAT_format (tsDevInfo *apRawInfo, RAWWRITE apRawWriteFunc, char *apFATType, void *apDriverData)
 FORMAT a device with a FAT filesystem.
int FAT_mkdir (const char *apPath)
 Create directory on a FAT FileSystem.
int FAT_rmdir (const char *apPath)
 Remove an empty directory on a FAT FileSystem.
FAT_DIRFAT_opendir (const char *apDirName)
 Open directory for reading (listing).
int FAT_closedir (FAT_DIR *ahDir)
 Close / Free resources associated with FAT_DIR structure initialized with FAT_opendir().
int FAT_readdir (FAT_DIR *ahDir, FAT_dirent *apDirent)
 Read next directory entry of FAT directory structure.
int FAT_rewinddir (FAT_DIR *ahDir)
 Resets directory listing pointer to beginning of list for a valid FAT_DIR entry as initalized by FAT_opendir.
double FAT_getdiskfree (const char *apDrive)
 Computes the free space on a device based upon the free cluster count.
int FAT_ioctl (const char *apDevName, int cmd, void *argp)
 IOCTL for FAT filasystem Supported IOCTLs are

  • FATIONOATIME - set arg to a uint32 pointer.

Variables

tsFATDevData gpFATDevData [MAX_NUM_DRIVERS]
int gnNUMFATDevs = 0
fat_open FAT_OPEN_ARRAY [MAX_NUM_DRIVERS]
fat_rename FAT_RENAME_ARRAY [MAX_NUM_DRIVERS]
fat_unlink FAT_UNLINK_ARRAY [MAX_NUM_DRIVERS]

Define Documentation

#define MAX_NUM_DRIVERS   3
#define FAT_OPEN_DEF ( X,
 ) 
Value:
int X(const char *path, unsigned int flags, int fno)      \
    {                                                         \
        return(FAT_open(path, flags, fno, &gpFATDevData[Y])); \
    }

The following compiler gymnastics is due to the fact that the TI file system hooks strip the device name off of the path prior to calling the specified function, so there is no way the support multiple FAT devices using the same functions unless you slip in an argument telling the real functions what device they are using.

..

#define FAT_RENAME_DEF ( X,
 ) 
Value:
int X(const char *old_name, const char *new_name)             \
    {                                                             \
        return(FAT_rename(old_name, new_name, &gpFATDevData[Y])); \
    }
#define FAT_UNLINK_DEF ( X,
 ) 
Value:
int X(const char* name)                          \
    {                                                \
        return(FAT_unlink(name, &gpFATDevData[Y]));  \
    }

Typedef Documentation

typedef int(* fat_open)(const char *, unsigned int, int)
typedef int(* fat_rename)(const char *, const char *)
typedef int(* fat_unlink)(const char *)

Function Documentation

int remove_device ( char *  name  ) 
int RegisterFATDriver ( RAWREAD  apRawReadFunc,
RAWWRITE  apRawWriteFunc,
GETTIME  apGetTimeFunc,
tsDevInfo apRawInfo,
char *  apDeviceName,
void *  apDriverData 
)

Register a FAT device/driver with BIOS CIO utilities.

This routine will load/interrogate the FAT tables on the provided device and register the device driver with the TI stdio lookup table.

Note:
the current implementation supports up to 5 separate FAT devices to be "mounted" or configured on the MityDSP platform at any one time.
Once a system is registered, files may be accessed using fopen, etc., with "apDeviceName:" (minus the quotes) prepended to the path. There is no notion of a "current working directory" other than the "root" directory. So paths must always be fully qualified to open files in subdirectories.
A maximum of 5 FAT devices is currently supported.
Parameters:
[in] apRawReadFunc Pointer to RawRead Function used by Driver.
[in] apRawWriteFunc Pointer to RawWrite function used by Driver.
[in] apGetTimeFunc Pointer to RTC function used by Driver (if no RTC available, should be NULL to use tick timer).
[in] apRawInfo Raw Device Info, required by FAT Driver.
[in] apDeviceName Name of device, e.g. "RAMDISK". Must be less than 32 characters. This name is used to specify a path to fopen() from BIOS, e.g., "RAMDISK:\my\home\directory".
[in] apDriverData Driver Data passed to RawRead and RawWrite Routines.
Returns:
FATFS_OK (0) on success, else an error occurred.
int RemoveFATDriver ( char *  apDeviceName  ) 

REMOVE a FAT device/driver with BIOS CIO utilities.

This routine will remove a FAT device.

Parameters:
[in] apDeviceName Name of device, e.g. "RAMDISK". Must be less than 32 characters. This name is used to specify a path to fopen() from BIOS, e.g., "RAMDISK:\my\home\directory".
Returns:
FATFS_OK (0) on success, else an error occurred.
int FAT_format ( tsDevInfo apRawInfo,
RAWWRITE  apRawWriteFunc,
char *  apFATType,
void *  apDriverData 
)

FORMAT a device with a FAT filesystem.

This routine is useful for non-volatile devices requiring a FAT filesystem.

Note:
Currently, this routine will only support devices with 512 byte sector sizes.
Parameters:
[in] apRawInfo Device Info Structure required by FAT formatting logic.
[in] apRawWriteFunc Raw Write routine called during format operation.
[in] apFATType "FAT16" (FAT32 and FAT 12 are currently not supported)
[in] apDriverData device drive info passwd to apRawWriteFunc.
Returns:
FATFS_OK (0) on success, or non-zero on error.
int FAT_mkdir ( const char *  apPath  ) 

Create directory on a FAT FileSystem.

Parameters:
[in] apPath Fully qualified path of directory to create
Returns:
FATFS_OK (0) on success, FATFS_INVALID_PATH (-1) if the path was not valid, or another negative number upon error.
int FAT_rmdir ( const char *  apPath  ) 

Remove an empty directory on a FAT FileSystem.

Parameters:
[in] apPath Fully qualified path of directory to create
Returns:
FATFS_OK (0) on success, FATFS_INVALID_PATH (-1) if the path was not valid, FATFS_DIRECTORY_NOT_EMPTY if the directory still has files in it, FATFS_FILE_NOT_FOUND if the path does not point to a valid file, or another negative number upon error.
FAT_DIR* FAT_opendir ( const char *  apDirName  ) 

Open directory for reading (listing).

Use this call in combination with FAT_readdir, FAT_closedir, and FAT_rewinddir in order to gather contents of a specified directory.

Parameters:
[in] apDirName Fully qualified path of interest
Returns:
Pointer to FAT directory control structure, if the path was not found, NULL is returned.
int FAT_closedir ( FAT_DIR ahDir  ) 

Close / Free resources associated with FAT_DIR structure initialized with FAT_opendir().

Parameters:
[in] ahDir Pointer to successfully opened FAT_DIR structure
Returns:
FATFS_OK on success.
int FAT_readdir ( FAT_DIR ahDir,
FAT_dirent apDirent 
)

Read next directory entry of FAT directory structure.

Parameters:
[in] ahDir Pointer to a valid FAT_DIR from FAT_opendir
[out] apDirent Pointer to a valid buffer to populate with listing contents.
Returns:
FATFS_OK (0) on success, FATFS_FILE_NOT_FOUND (-2) at end of directory, or another negative number upon error.
int FAT_rewinddir ( FAT_DIR ahDir  ) 

Resets directory listing pointer to beginning of list for a valid FAT_DIR entry as initalized by FAT_opendir.

Parameters:
[in] ahDir Pointer to a valid FAT_DIR from FAT_opendir
Returns:
FATFS_OK (0) on success, negative number upon failure.
double FAT_getdiskfree ( const char *  apDrive  ) 

Computes the free space on a device based upon the free cluster count.

Parameters:
[in] apDrive Path name (including at least the device identifier) of the device to compute free space for.
Returns:
Free space remaining, in bytes (double precision).
int FAT_ioctl ( const char *  apDevName,
int  cmd,
void *  argp 
)

IOCTL for FAT filasystem Supported IOCTLs are

  • FATIONOATIME - set arg to a uint32 pointer.

Value of 1 to disable accesstime on readonly files

Parameters:
[in] apDevName - Device name to perform IOCTL on
[in] cmd - IOCTL command to implement
[in] argp - cmd specific data
Returns:
Zero on success, -1 if an error occurred.

Variable Documentation

tsFATDevData gpFATDevData[MAX_NUM_DRIVERS]
int gnNUMFATDevs = 0
fat_open FAT_OPEN_ARRAY[MAX_NUM_DRIVERS]
Initial value:
{
    FAT_open_0,
    FAT_open_1,
    FAT_open_2,
}
fat_rename FAT_RENAME_ARRAY[MAX_NUM_DRIVERS]
Initial value:
{
    FAT_rename_0,
    FAT_rename_1,
    FAT_rename_2,
}
fat_unlink FAT_UNLINK_ARRAY[MAX_NUM_DRIVERS]
Initial value:
{
    FAT_unlink_0,
    FAT_unlink_1,
    FAT_unlink_2,
}

  
Generated on Wed Mar 17 18:24:35 2010 for FAT File System Library by  Doxygen Version 1.6.1
Copyright © 2009, Critical Link LLC, All rights reserved.