Nut/OS  5.0.5
API Reference
PHAT File System

FAT12/16/32 compatible file system. More...

Collaboration diagram for PHAT File System:

Data Structures

struct  _PHATFILE
 PHAT file descriptor structure. More...

Modules

 Volume Support
 

Dealing with volumes.


 Directory Support
 

Routines for reading and writing directories.


 PHAT12 Support
 

PHAT12 specific routines.


 PHAT16 Support
 

PHAT16 specific routines.


 PHAT32 Support
 

PHAT32 specific routines.


 PHAT Block I/O
 

Reading and writing data blocks.


 PHAT Utilities
 

General utility routines used by the PHAT file system.


 PHAT Debugging Support
 

Listing various PHAT structures.


Defines

#define PHATEOC   0x0FFFFFF8
 Marks end of cluster chain.

Typedefs

typedef struct _PHATFILE PHATFILE
 PHAT file descriptor structure.

Functions

uint32_t AllocFirstCluster (NUTFILE *nfp)
 Allocate the first cluster of a file.
int PhatFileClose (NUTFILE *nfp)
 Close a file.
NUTFILEPhatFileOpen (NUTDEVICE *dev, const char *path, int mode, int acc)
 Open a file.
int PhatFileWrite (NUTFILE *nfp, const void *buffer, int len)
 Write data to a file.
int PhatFileWrite_P (NUTFILE *nfp, PGM_P buffer, int len)
 Write data from program space to a file.
int PhatFileRead (NUTFILE *nfp, void *buffer, int size)
 Read data from a file.

Variables

NUTDEVICE devPhat0
 PHAT file system driver information structure.
NUTDEVICE devPhat1

File attributes.

#define PHAT_FATTR_RDONLY   0x01
#define PHAT_FATTR_HIDDEN   0x02
#define PHAT_FATTR_SYSTEM   0x04
#define PHAT_FATTR_VOLID   0x08
#define PHAT_FATTR_DIR   0x10
#define PHAT_FATTR_ARCHIV   0x20
#define PHAT_FATTR_LFN   (PHAT_FATTR_RDONLY | PHAT_FATTR_HIDDEN | PHAT_FATTR_SYSTEM | PHAT_FATTR_VOLID)
#define PHAT_FATTR_FILEMASK   0x37

Detailed Description

FAT12/16/32 compatible file system.

Note:
This is alpha code and may contain severe bugs.

Define Documentation

#define PHAT_FATTR_RDONLY   0x01

Read only file.

Referenced by PhatDbgAttrList(), PhatDirReleaseChain(), and PhatFileWrite().

#define PHAT_FATTR_HIDDEN   0x02

Hidden file.

Referenced by PhatDbgAttrList().

#define PHAT_FATTR_SYSTEM   0x04

System file.

Referenced by PhatDbgAttrList().

#define PHAT_FATTR_VOLID   0x08

No file, but a volume label.

Referenced by PhatDbgAttrList().

#define PHAT_FATTR_DIR   0x10
#define PHAT_FATTR_ARCHIV   0x20

File is not archived. This flag will be set when the file is created or modified.

Referenced by PhatDbgAttrList(), and PhatFileWrite().

#define PHAT_FATTR_LFN   (PHAT_FATTR_RDONLY | PHAT_FATTR_HIDDEN | PHAT_FATTR_SYSTEM | PHAT_FATTR_VOLID)

Long filename entry.

#define PHAT_FATTR_FILEMASK   0x37

Only these flags are allowed for files and directories.

Referenced by PhatDirEntryStatus(), PhatDirOpen(), PhatDirRemove(), PhatDirRenameEntry(), and PhatFileOpen().


Typedef Documentation

typedef struct _PHATFILE PHATFILE

PHAT file descriptor structure.


Function Documentation

uint32_t AllocFirstCluster ( NUTFILE nfp)

Allocate the first cluster of a file.

Parameters:
nfpThe file for which a cluster is allocated.
Returns:
Number of the allocated cluster, which is not lower than 2. Any value lower than 2 indicates an error.

References _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, PHAT12CMASK, Phat12SetClusterLink(), PHAT16CMASK, Phat16SetClusterLink(), PHAT32CMASK, Phat32SetClusterLink(), _PHATVOL::vol_numfree, and _PHATVOL::vol_type.

Referenced by PhatDirCreate(), and PhatFileWrite().

Here is the call graph for this function:

int PhatFileClose ( NUTFILE nfp)

Close a file.

Parameters:
nfpFile descriptor.
Returns:
0 on success, -1 otherwise.

References EBADF, errno, free(), _NUTFILE::nf_fcb, NULL, NUTFILE_EOF, PhatDbgFileInfo(), rc, and stdout.

Referenced by PhatDirCreate(), PhatDirDelEntry(), PhatDirEntryStatus(), PhatDirRemove(), PhatDirRenameEntry(), and PhatFileOpen().

Here is the call graph for this function:

NUTFILE* PhatFileOpen ( NUTDEVICE dev,
const char *  path,
int  mode,
int  acc 
)

Open a file.

This function is called by the low level open routine of the C runtime library, using the _NUTDEVICE::dev_open entry.

Parameters:
devSpecifies the file system device.
pathPathname of the file to open. If the last character is a slash, then a directory will be opened.
modeOperation mode.
accFile attribute.
Returns:
Pointer to a NUTFILE structure if successful or NUTFILE_EOF otherwise.
Bug:
Append mode not working as expected.

References _O_APPEND, _O_CREAT, _O_EXCL, _O_TRUNC, _PHATDIRENT::dent_attr, _PHATDIRENT::dent_cdate, _PHATDIRENT::dent_clust, _PHATDIRENT::dent_clusthi, _PHATDIRENT::dent_ctime, _PHATDIRENT::dent_ctsecs, _PHATDIRENT::dent_fsize, _PHATDIRENT::dent_name, _PHATDIRENT::dent_rsvdnt, EEXIST, ENOENT, errno, _PHATFILE::f_clust, _PHATFILE::f_clust_pos, _PHATFILE::f_de_dirty, _PHATFILE::f_de_offs, _PHATFILE::f_de_sect, _PHATFILE::f_dirent, _PHATFILE::f_mode, _PHATFILE::f_pde_clust, _PHATFILE::f_pde_clusthi, _PHATFILE::f_sect_pos, free(), malloc(), memcpy(), memset(), _NUTFILE::nf_dev, _NUTFILE::nf_fcb, _NUTFILE::nf_next, NULL, NUTFILE_EOF, PHAT_FATTR_FILEMASK, PhatClusterSector(), PhatDbgFileInfo(), PhatDirEntryCreate(), PhatDirEntryFind(), PhatDirOpenParent(), PhatDirReleaseChain(), PhatFileClose(), PhatFilePosSet(), _PHATFIND::phfind_ent, and stdout.

Referenced by PhatDirCreate(), and PhatDirRemove().

Here is the call graph for this function:

int PhatFileWrite ( NUTFILE nfp,
const void *  buffer,
int  len 
)

Write data to a file.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to PnutFileOpen().
bufferPointer to the data to be written. If zero, then the output buffer will be flushed.
lenNumber of bytes to write.
Returns:
The number of bytes written. A return value of -1 indicates an error.

References AllocFirstCluster(), _PHATDIRENT::dent_adate, _PHATDIRENT::dent_attr, _PHATDIRENT::dent_fsize, _PHATDIRENT::dent_mdate, _PHATDIRENT::dent_mtime, _NUTDEVICE::dev_dcb, EACCES, ENOSPC, errno, _PHATFILE::f_clust, _PHATFILE::f_clust_pos, _PHATFILE::f_clust_prv, _PHATFILE::f_de_dirty, _PHATFILE::f_dirent, _PHATFILE::f_pos, _PHATFILE::f_sect_pos, GetDosTimeStamp(), IsFixedRootDir(), memcpy(), _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NULL, PHAT12CMASK, Phat12GetClusterLink(), PHAT16CMASK, Phat16GetClusterLink(), PHAT32CMASK, Phat32GetClusterLink(), PHAT_FATTR_ARCHIV, PHAT_FATTR_DIR, PHAT_FATTR_RDONLY, PhatClusterSector(), PHATEOC, PhatSectorBufferRelease(), PhatSectorLoad(), PhatSectorWrite(), rc, _PHATSECTBUF::sect_data, _PHATSECTBUF::sect_dirty, _PHATVOL::vol_buf, _PHATVOL::vol_clustsz, _PHATVOL::vol_numfree, _PHATVOL::vol_rootsz, _PHATVOL::vol_sectsz, and _PHATVOL::vol_type.

Referenced by PhatDirCreate().

Here is the call graph for this function:

int PhatFileWrite_P ( NUTFILE nfp,
PGM_P  buffer,
int  len 
)

Write data from program space to a file.

This function is not yet implemented and will always return -1.

Similar to PhatFileWrite() except that the data is located in program memory.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to PnutFileOpen().
bufferPointer to the data in program space. If zero, then the output buffer will be flushed.
lenNumber of bytes to write.
Returns:
The number of bytes written. A return value of -1 indicates an error.
int PhatFileRead ( NUTFILE nfp,
void *  buffer,
int  size 
)

Read data from a file.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to PnutFileOpen().
bufferPointer to the data buffer to fill.
sizeMaximum number of bytes to read.
Returns:
The number of bytes actually read. A return value of -1 indicates an error.

References _PHATDIRENT::dent_attr, _PHATDIRENT::dent_fsize, _NUTDEVICE::dev_dcb, _PHATFILE::f_clust, _PHATFILE::f_clust_pos, _PHATFILE::f_clust_prv, _PHATFILE::f_dirent, _PHATFILE::f_pos, _PHATFILE::f_sect_pos, IsFixedRootDir(), memcpy(), _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NULL, PHAT12CMASK, Phat12GetClusterLink(), PHAT16CMASK, Phat16GetClusterLink(), PHAT32CMASK, Phat32GetClusterLink(), PHAT_FATTR_DIR, PhatClusterSector(), PHATEOC, PhatSectorBufferRelease(), PhatSectorLoad(), rc, _PHATSECTBUF::sect_data, _PHATVOL::vol_buf, _PHATVOL::vol_clustsz, _PHATVOL::vol_rootsz, _PHATVOL::vol_sectsz, and _PHATVOL::vol_type.

Referenced by PhatDirRemove().

Here is the call graph for this function:


Variable Documentation

Initial value:
 {
    0,                          
    {'P', 'H', 'A', 'T', '0', 0, 0, 0, 0}
    ,                           
    IFTYP_FS,                   
    0,                          
    0,                          
    0,                          
    0,                          
    PhatInit,                   
    PhatApiIOCtl,               
    PhatApiFileRead,            
    PhatApiFileWrite,           

    PhatApiFileWrite_P,         

    PhatApiFileOpen,            
    PhatApiFileClose,           
    PhatFileSize                
}

PHAT file system driver information structure.

A pointer to this structure must be passed to NutRegisterDevice() to bind this file system driver to the Nut/OS kernel. An application may then call /verbatim _open("MMC0:1/PHAT0", _O_RDWR | _O_BINARY); /endverbatim to mount partition 1 on the previously registered block device (devMmc0 in this example).

Initial value:
 {
    0,                          
    {'P', 'H', 'A', 'T', '1', 0, 0, 0, 0}
    ,                           
    IFTYP_FS,                   
    0,                          
    0,                          
    0,                          
    0,                          
    PhatInit,                   
    PhatApiIOCtl,               
    PhatApiFileRead,            
    PhatApiFileWrite,           

    PhatApiFileWrite_P,         

    PhatApiFileOpen,            
    PhatApiFileClose,           
    PhatFileSize                
}