Contiki-Inga 3.x
Files | Data Structures | Macros | Functions | Variables

Additional function for the FAT file system. More...

Files

file  cfs-fat.c
 
 FAT driver implementation

 
file  cfs-fat.h
 
    FAT driver definitions

 
file  fat_mkfs.c
 
 FAT driver mkfs implementation

 

Data Structures

struct  FAT_Info
 Holds boot sector information. More...
 
struct  dir_entry
 Fat table entry for file. More...
 

Macros

#define CFS_CONF_OFFSET_TYPE   uint32_t
 Seek type is 32 bit for FAT files. More...
 
#define FAT_SYNC   0
 Allows to enable synchronization of FATs when unmounting device. More...
 

Functions

void cfs_fat_print_file_info (int fd)
 
void cfs_fat_print_dir_entry (struct dir_entry *dir_entry)
 
void cfs_fat_get_fat_info (struct FAT_Info *info)
 Populates the given FAT_Info with the mounted FAT_Info. More...
 
uint16_t cfs_fat_get_last_date (int fd)
 Returns the date of last modification. More...
 
uint16_t cfs_fat_get_last_time (int fd)
 Returns the time of last modification. More...
 
uint16_t cfs_fat_get_create_date (int fd)
 Returns the date of creation. More...
 
uint16_t cfs_fat_get_create_time (int fd)
 Returns the time of creation. More...
 
void cfs_fat_flush ()
 Writes the current buffered block back to the disk if it was changed.
 
uint8_t cfs_fat_mount_device (struct diskio_device_info *dev)
 Tries to mount the defined device. More...
 
void cfs_fat_umount_device ()
 Umounts the mounted device. More...
 
int cfs_open (const char *name, int flags)
 Open a file. More...
 
void cfs_close (int fd)
 Close an open file. More...
 
int cfs_read (int fd, void *buf, unsigned int len)
 Read data from an open file. More...
 
int cfs_write (int fd, const void *buf, unsigned int len)
 Write data to an open file. More...
 
cfs_offset_t cfs_seek (int fd, cfs_offset_t offset, int whence)
 Seek to a specified position in an open file. More...
 
int cfs_remove (const char *name)
 Remove a file. More...
 
int cfs_opendir (struct cfs_dir *dirp, const char *name)
 Open a directory for reading directory entries. More...
 
int cfs_readdir (struct cfs_dir *dirp, struct cfs_dirent *dirent)
 Read a directory entry. More...
 
void cfs_closedir (struct cfs_dir *dirp)
 Close a directory opened with cfs_opendir(). More...
 
uint32_t cfs_fat_file_size (int fd)
 Returns the file size of the associated file. More...
 
void cfs_fat_sync_fats ()
 Syncs every FAT with the first. More...
 
uint8_t is_a_power_of_2 (uint32_t value)
 Tests if the given value is a power of 2. More...
 
uint32_t round_down_to_power_of_2 (uint32_t value)
 Rounds the value down to the next lower power of 2. More...
 
int cfs_fat_mkfs (struct diskio_device_info *dev)
 Formats the specified device as FAT16/32. More...
 
void cfs_fat_print_cluster_chain (int fd)
 

Variables

struct file_system mounted
 From fat.c.
 
struct file fat_file_pool [FAT_FD_POOL_SIZE]
 From fat.c.
 
struct file_desc fat_fd_pool [FAT_FD_POOL_SIZE]
 From fat.c.
 

Detailed Description

Additional function for the FAT file system.

Macro Definition Documentation

#define CFS_CONF_OFFSET_TYPE   uint32_t

Seek type is 32 bit for FAT files.

Definition at line 61 of file cfs-fat.h.

#define FAT_SYNC   0

Allows to enable synchronization of FATs when unmounting device.

This may allow to restore a corrupted primary FAT but note that this will lead to poor performance and decreases flash life because of a remarkable number of additional write cycles.

Definition at line 80 of file cfs-fat.h.

Function Documentation

void cfs_close ( int  fd)

Close an open file.

Parameters
fdThe file descriptor of the open file.
        This function closes a file that has previously been
        opened with cfs_open().

Definition at line 934 of file cfs-fat.c.

References cfs_fat_flush(), fat_fd_pool, and NULL.

void cfs_closedir ( struct cfs_dir *  dirp)

Close a directory opened with cfs_opendir().

Parameters
dirpA pointer to a struct cfs_dir that has been opened with cfs_opendir().
See Also
cfs_opendir()
cfs_readdir()

Definition at line 1136 of file cfs-fat.c.

uint32_t cfs_fat_file_size ( int  fd)

Returns the file size of the associated file.

Parameters
fd
Returns

Definition at line 1384 of file cfs-fat.c.

References fat_fd_pool, fat_file_pool, and NULL.

uint16_t cfs_fat_get_create_date ( int  fd)

Returns the date of creation.

Format: [15-9: year sine 1980, 8-5: month, 4-0: day]

Parameters
fdFile descriptor

Definition at line 424 of file cfs-fat.c.

References fat_file_pool.

uint16_t cfs_fat_get_create_time ( int  fd)

Returns the time of creation.

Format: [15-11: hours, 10-5: minutes, 4-0: seconds/2]

Parameters
fdFile descriptor

Definition at line 430 of file cfs-fat.c.

References fat_file_pool.

void cfs_fat_get_fat_info ( struct FAT_Info info)

Populates the given FAT_Info with the mounted FAT_Info.

Parameters
*infoThe FAT_Info struct which should be populated.

Definition at line 406 of file cfs-fat.c.

References mounted.

uint16_t cfs_fat_get_last_date ( int  fd)

Returns the date of last modification.

Format: [15-9: year sine 1980, 8-5: month, 4-0: day]

Parameters
fdFile descriptor

Definition at line 412 of file cfs-fat.c.

References fat_file_pool.

uint16_t cfs_fat_get_last_time ( int  fd)

Returns the time of last modification.

Format: [15-11: hours, 10-5: minutes, 4-0: seconds/2]

Parameters
fdFile descriptor

Definition at line 418 of file cfs-fat.c.

References fat_file_pool.

int cfs_fat_mkfs ( struct diskio_device_info dev)

Formats the specified device as FAT16/32.

Parameters
devdevice to format
Returns

Definition at line 74 of file fat_mkfs.c.

uint8_t cfs_fat_mount_device ( struct diskio_device_info dev)

Tries to mount the defined device.

Parameters
devThe device on which a FAT-FS should be mounted.
Returns
0 on success, 1 if the bootsector was not found or corrupted, 2 if the FAT-Type wasn't supported.

Definition at line 808 of file cfs-fat.c.

References cfs_fat_umount_device(), diskio_read_block(), and mounted.

void cfs_fat_print_cluster_chain ( int  fd)
Parameters
fd
void cfs_fat_print_dir_entry ( struct dir_entry dir_entry)
void cfs_fat_print_file_info ( int  fd)
void cfs_fat_sync_fats ( )

Syncs every FAT with the first.

Syncs every FAT with the first FAT.

Can take much time.

Definition at line 1401 of file cfs-fat.c.

References cfs_fat_flush(), diskio_read_block(), diskio_write_block(), and mounted.

Referenced by cfs_fat_umount_device().

void cfs_fat_umount_device ( )

Umounts the mounted device.

Invalidates all file descriptors. (Syncs all FATs (only if FAT_SYNC is set)) and flushes cached data.

Definition at line 843 of file cfs-fat.c.

References cfs_fat_flush(), cfs_fat_sync_fats(), fat_fd_pool, and mounted.

Referenced by cfs_fat_mount_device().

int cfs_open ( const char *  name,
int  flags 
)

Open a file.

Parameters
nameThe name of the file.
flagsCFS_READ, or CFS_WRITE/CFS_APPEND, or both.
Returns
A file descriptor, if the file could be opened, or -1 if the file could not be opened.

This function opens a file and returns a file descriptor for the opened file. If the file could not be opened, the function returns -1. The function can open a file for reading or writing, or both.

An opened file must be closed with cfs_close().

See Also
CFS_READ
CFS_WRITE
cfs_close()

Definition at line 867 of file cfs-fat.c.

References CFS_APPEND, cfs_remove(), cfs_seek(), CFS_SEEK_END, CFS_WRITE, fat_fd_pool, and fat_file_pool.

int cfs_opendir ( struct cfs_dir *  dirp,
const char *  name 
)

Open a directory for reading directory entries.

Parameters
dirpA pointer to a struct cfs_dir that is filled in by the function.
nameThe name of the directory.
Returns
0 or -1 if the directory could not be opened.
See Also
cfs_readdir()
cfs_closedir()

Definition at line 1089 of file cfs-fat.c.

int cfs_read ( int  fd,
void *  buf,
unsigned int  len 
)

Read data from an open file.

Parameters
fdThe file descriptor of the open file.
bufThe buffer in which data should be read from the file.
lenThe number of bytes that should be read.
Returns
The number of bytes that was actually read from the file.
        This function reads data from an open file into a
        buffer. The file must have first been opened with
        cfs_open() and the CFS_READ flag.

Definition at line 952 of file cfs-fat.c.

References CFS_READ, and fat_fd_pool.

int cfs_readdir ( struct cfs_dir *  dirp,
struct cfs_dirent *  dirent 
)

Read a directory entry.

Parameters
dirpA pointer to a struct cfs_dir that has been opened with cfs_opendir().
direntA pointer to a struct cfs_dirent that is filled in by cfs_readdir()
Return values
0If a directory entry was read.
-1If no more directory entries can be read.
See Also
cfs_opendir()
cfs_closedir()

Definition at line 1107 of file cfs-fat.c.

References dir_entry::DIR_FileSize, and mounted.

int cfs_remove ( const char *  name)

Remove a file.

Parameters
nameThe name of the file.
Return values
0If the file was removed.
Returns
-1 If the file could not be removed or if it doesn't exist.

Definition at line 1068 of file cfs-fat.c.

References cfs_fat_flush().

cfs_offset_t cfs_seek ( int  fd,
cfs_offset_t  offset,
int  whence 
)

Seek to a specified position in an open file.

Parameters
fdThe file descriptor of the open file.
offsetA position, either relative or absolute, in the file.
whenceDetermines how to interpret the offset parameter.
Returns
The new position in the file, or (cfs_offset_t)-1 if the seek failed.
        This function moves the file position to the specified
        position in the file. The next byte that is read from
        or written to the file will be at the position given 
        determined by the combination of the offset parameter 
        and the whence parameter.
See Also
CFS_SEEK_CUR
CFS_SEEK_END
CFS_SEEK_SET

Definition at line 1036 of file cfs-fat.c.

References CFS_SEEK_CUR, CFS_SEEK_END, CFS_SEEK_SET, dir_entry::DIR_FileSize, fat_fd_pool, and fat_file_pool.

int cfs_write ( int  fd,
const void *  buf,
unsigned int  len 
)

Write data to an open file.

Parameters
fdThe file descriptor of the open file.
bufThe buffer from which data should be written to the file.
lenThe number of bytes that should be written.
Returns
The number of bytes that was actually written to the file.
        This function reads writes data from a memory buffer to
        an open file. The file must have been opened with
        cfs_open() and the CFS_WRITE flag.

Definition at line 964 of file cfs-fat.c.

uint8_t is_a_power_of_2 ( uint32_t  value)

Tests if the given value is a power of 2.

Parameters
valueNumber which should be testet if it is a power of 2.
Returns
1 on failure and 0 if value is a power of 2.

Definition at line 1442 of file cfs-fat.c.

uint32_t round_down_to_power_of_2 ( uint32_t  value)

Rounds the value down to the next lower power of 2.

Parameters
valueThe number which should be rounded down.
Returns
the next lower number which is a power of 2

Definition at line 1468 of file cfs-fat.c.