fs.c File Reference

Filesystem OS layer. More...

Go to the source code of this file.

Functions

u32 FS_Mount (enum STORAGE_device device)
u32 FS_Unmount (enum STORAGE_device device)
u32 FS_OpenFile (PVOLINFO volinfo, u8 *path, u8 mode, PFILEINFO fileinfo)
u32 FS_ReadFile (PFILEINFO fileinfo, u8 *buffer, u32 *successcount, u32 len)
u32 FS_WriteFile (PFILEINFO fileinfo, u8 *buffer, u32 *successcount, u32 len)
u32 FS_Close (PFILEINFO fileinfo)
void FS_Seek (PFILEINFO fileinfo, u32 offset)
u32 FS_Delete (PVOLINFO volinfo, u8 *path)
u32 FS_GetNextEntry (PVOLINFO volinfo, PDIRINFO dirinfo, PDIRENT dirent)
u32 FS_OpenDirectory (PVOLINFO volinfo, u8 *dirname, PDIRINFO dirinfo)
u32 FS_GetVolumeInfo (u8 unit, u32 startsector, PVOLINFO volinfo)
enum MENU_code FS_Explorer_Ini (void)
s32 FS_Explorer (void)
u8 * FS_GetSDCardCurrentPath (void)
VOLINFOFS_GetSDCardVolInfo (void)
u8 * FS_GetPathFilter (void)
void FS_SetPathFilter (u8 *filter)

Detailed Description

Author:
S. S. Brandsma
Date:
23-01-2009
Version:
1.0
Author:
YRT
Date:
05/02/2009
Version:
1.1

Definition in file fs.c.


Function Documentation

u32 FS_Close ( PFILEINFO  fileinfo  ) 

Close file.

Parameters:
[in] fileinfo : structure populated by the DFS_OpenFile function.
Returns:
MENU_CONTINUE_COMMAND.
Warning:
Not yet implemented.

Definition at line 315 of file fs.c.

u32 FS_Delete ( PVOLINFO  volinfo,
u8 *  path 
)

Delete file or directory.

FS_Delete will delete a subdirectory (correctly) but will NOT first recurse the directory to delete the contents. So you will end up with lost clusters..

Parameters:
[in] volinfo : structure populated with information about filesystem.
[in] *path : string containing the path of the file to delete.
Returns:
MENU_CONTINUE_COMMAND.

Definition at line 361 of file fs.c.

s32 FS_Explorer ( void   ) 

Navigation into the SDCARD folders, through a list, and selection of a file.

Returns:
-1 if navigation not finished, 0 if Quit request, 1 if file selected : use FS_GetSDCardCurrentPath() to get the path.
Note:
This function has to be called periodically until it returns a value equal to -1.
Warning:
FS_Explorer_Ini() must be called before.

Definition at line 551 of file fs.c.

enum MENU_code FS_Explorer_Ini ( void   ) 

Checks the presence of the SDCARD, initializes various structures and lists the root directory.

Returns:
MENU_CONTINUE_COMMAND

Definition at line 469 of file fs.c.

u32 FS_GetNextEntry ( PVOLINFO  volinfo,
PDIRINFO  dirinfo,
PDIRENT  dirent 
)

Search next entry of the directory.

Call FS_GetNextEntry to receive the DIRENT contents for the next directory item. This function returns FS_OK for no error, and FS_EOF if there are no more entries in the directory being searched. Before using the DIRENT, check the first character of the name. If it is NULL, then this is an unusable entry - call DFS_GetNext again to keep searching. LFN directory entries are automatically tagged this way so your application will not be pestered by them.

Note:
A designed side-effect of this code is that when you locate the file of interest, the DIRINFO.currentcluster, DIRINFO.currentsector and DIRINFO.currententry-1 fields will identify the directory entry of.
Parameters:
[in] volinfo : structure populated with information about filesystem.
[in] dirinfo : .
[out] dirent : next directory entry.
Returns:
MENU_CONTINUE_COMMAND.

Definition at line 395 of file fs.c.

u8* FS_GetPathFilter ( void   ) 

Get the filter applied to the file type during exploring the SDCard

Returns:
FS_PathFilter.

Definition at line 728 of file fs.c.

u8* FS_GetSDCardCurrentPath ( void   ) 

Get the Currentpath of the SDCard, updated during navigation with the explorer.

Returns:
currentpath.
Warning:
FS_Explorer_Ini() must have been called before.

Definition at line 689 of file fs.c.

VOLINFO* FS_GetSDCardVolInfo ( void   ) 

Get the volume informations of the SDCard, structure populated by the FS_Explorer_Ini(). This structure is necessary for file access, (FS_OpenFile, FS_ReadFile, FS_Seek...).

Returns:
volume_info.
Warning:
FS_Explorer_Ini() must have been called before.

Definition at line 711 of file fs.c.

u32 FS_GetVolumeInfo ( u8  unit,
u32  startsector,
PVOLINFO  volinfo 
)

Gets the volume informations.

Call FS_GetVolInfo to read filesystem info into a VOLINFO structure. FS_GetVolInfo needs to know the unit number and partition starting sector (as returned by DFS_GetPtnStart, or 0 if this is a "floppy- format" volume without a MBR).

Parameters:
[in] unit : .
[in] startsector : .
[out] volinfo : structure populated with information about filesystem.
Returns:
MENU_CONTINUE_COMMAND.

Definition at line 451 of file fs.c.

u32 FS_Mount ( enum STORAGE_device  device  ) 

Initializes and connects selected device to file system.

Parameters:
[in] device (currently only supported: MMCSD_SDIO).
Returns:
MENU_CONTINUE_COMMAND.

Definition at line 163 of file fs.c.

u32 FS_OpenDirectory ( PVOLINFO  volinfo,
u8 *  dirname,
PDIRINFO  dirinfo 
)

Open directory.

Call FS_Opendir and supply a path, populated VOLINFO and a DIRINFO structure to receive the results. This buffer must remain unmolested while you have the directory open for searching.

Parameters:
[in] volinfo : structure populated with information about filesystem.
[in] *dirname : string containing the name of the directory.
[out] dirinfo : structure with infos about the directory.
Returns:
MENU_CONTINUE_COMMAND.

Definition at line 422 of file fs.c.

u32 FS_OpenFile ( PVOLINFO  volinfo,
u8 *  path,
u8  mode,
PFILEINFO  fileinfo 
)

Open file.

Call FS_OpenFile with mode = FS_READ and supply a path and the relevant VOLINFO structure. FS_OpenFile will populate a FILEINFO that can be used to refer to the file. Optionally call FS_Seek to set the file pointer. If you attempt to set the file pointer past the end of file, the file will NOT be extended. Check the FILEINFO.pointer value after FS_Seek to verify that the pointer is where you expect it to be. Observe that functionality similar to the "whence" parameter of fseek() can be obtained by using simple arithmetic on the FILEINFO.pointer and FILEINFO.filelen members. Call FS_ReadFile with the FILEINFO you obtained from OpenFile, and a pointer to a buffer plus the desired number of bytes to read, and a pointer to a sector-sized scratch buffer. The reason a scratch sector is required is because the underlying sector read function doesn't know about partial reads. Note that a file opened for reading cannot be written. If you need r/w access, open with mode = FS_WRITE (see below).

Parameters:
[in] volinfo : structure populated with information about filesystem.
[in] *path : string containing the path of the file to access.
[in] mode : access mode = FS_READ or FS_WRITE.
[out] fileinfo : empty structure filled by the function, for further access.
Returns:
MENU_CONTINUE_COMMAND.

Definition at line 227 of file fs.c.

u32 FS_ReadFile ( PFILEINFO  fileinfo,
u8 *  buffer,
u32 *  successcount,
u32  len 
)

Read file.

Parameters:
[in] fileinfo : structure populated by the DFS_OpenFile function.
[out] *buffer : buffer filled with the read result.
[out] *successcount : number of bytes really read.
[in] len : number of bytes to read.
Returns:
MENU_CONTINUE_COMMAND.

Definition at line 251 of file fs.c.

void FS_Seek ( PFILEINFO  fileinfo,
u32  offset 
)

Seek file pointer to a given position.

Parameters:
[in] fileinfo : structure populated by the DFS_OpenFile function.
[in] offset : position to reach.
Returns:
This function does not return status. Refer to the fileinfo->pointer value.

Definition at line 336 of file fs.c.

void FS_SetPathFilter ( u8 *  filter  ) 

Set the filter applied to the file type during exploring the SDCard. A null pointer indicates no filter

Parameters:
[in] filter : pointer on a string containing the filter.

Note : the string must contain 3 char.

Definition at line 748 of file fs.c.

u32 FS_Unmount ( enum STORAGE_device  device  ) 

Deinitializes and disconnects selected device to file system.

Parameters:
[in] device (currently only supported: MMCSD_SDIO).
Returns:
MENU_CONTINUE_COMMAND.
Warning:
Not yet implemented.

Definition at line 187 of file fs.c.

u32 FS_WriteFile ( PFILEINFO  fileinfo,
u8 *  buffer,
u32 *  successcount,
u32  len 
)

Write file.

Call DFS_OpenFile with mode = DFS_WRITE and supply a path and the relevant VOLINFO structure. DFS_OpenFile will populate a FILEINFO that can be used to refer to the file. Optionally call DFS_Seek to set the file pointer. Refer to the notes on this topic in the section on reading files, above. Call DFS_WriteFile with the FILEINFO you obtained from OpenFile, and a pointer to the source buffer, and a pointer to a sector-sized scratch buffer. Note that a file open for writing can also be read. Files are created automatically if they do not exist. Subdirectories are NOT automatically created. If you open an existing file for writing, the file pointer will start at the beginning of the data; if you want to append, seek to the end before writing new data. If you perform random-access writes to a file, the length will NOT change unless you exceed the file's original length. There is currently no function to truncate a file at the current pointer position. On-disk consistency is guaranteed when DFS_WriteFile exits, unless your physical layer has a writeback cache in it.

Parameters:
[in] fileinfo : structure populated by the DFS_OpenFile function.
[in] buffer : buffer to be written.
[out] *successcount : number of bytes really read.
[in] len : number of bytes to read.
Returns:
MENU_CONTINUE_COMMAND.

Definition at line 294 of file fs.c.