Directory Support
[PHAT File System]

Collaboration diagram for Directory Support:

Detailed Description

Routines for reading and writing directories.


Data Structures

struct  PHATDIRENT
 Structure of a directory entry. More...
struct  PHATXDIRENT
 Structure of an extended directory entry. More...
struct  PHATFIND

Defines

#define PHAT_MAX_NAMELEN   255
 Maximum length of a base file name.
#define PHAT_REM_DIRENT   0xE5
#define PHAT_REM_NAMENT   0x05
#define PHAT_MAXDIRENT   65536
 Maximum number of directory entries.

Functions

int PhatDirEntryCreate (NUTFILE *ndp, CONST char *name, int acc, PHATDIRENT *dirent)
 Create a new directory entry.
int PhatDirEntryUpdate (NUTFILE *nfp)
 Update directory entry of an opened file or directory.
int PhatDirEntryFind (NUTFILE *ndp, CONST char *spec, uint32_t attmsk, PHATFIND *srch)
 Find a directory entry with a specified name.
NUTFILEPhatDirOpenParent (NUTDEVICE *dev, CONST char *path, CONST char **basename)
 Open parent directory of a given path.
int PhatDirRenameEntry (NUTDEVICE *dev, CONST char *old_path, CONST char *new_path)
 Rename file.
int PhatDirReleaseChain (NUTDEVICE *dev, PHATDIRENT *dent)
 Release a cluster chain of a specified directory entry.
int PhatDirDelEntry (NUTDEVICE *dev, CONST char *path, uint32_t flags)
 Remove a directory entry.
NUTFILEPhatDirOpen (NUTDEVICE *dev, CONST char *dpath)
 Open a directory.
int PhatDirRead (DIR *dir)
 Read the next directory entry.
int PhatDirCreate (NUTDEVICE *dev, char *path)
 Create a new subdirectory.
int PhatDirRemove (NUTDEVICE *dev, char *path)
 Remove a specified subdirectory.
int PhatDirEntryStatus (NUTDEVICE *dev, CONST char *path, struct stat *stp)
 Retrieve status of a specified file.


Define Documentation

#define PHAT_MAX_NAMELEN   255

Maximum length of a base file name.

Definition at line 77 of file phatdir.h.

Referenced by PhatDirOpen().

#define PHAT_REM_DIRENT   0xE5

Definition at line 80 of file phatdir.h.

Referenced by MakePhatName(), MakeVisibleName(), and PhatDirRemove().

#define PHAT_REM_NAMENT   0x05

Definition at line 81 of file phatdir.h.

Referenced by MakePhatName(), and MakeVisibleName().

#define PHAT_MAXDIRENT   65536

Maximum number of directory entries.

Definition at line 128 of file phatdir.c.


Function Documentation

int PhatDirEntryCreate ( NUTFILE ndp,
CONST char *  name,
int  acc,
PHATDIRENT dirent 
)

Create a new directory entry.

Parameters:
ndp Handle to the parent directory.
name Name of the new entry.
acc Attributes of the new entry.
dirent Information structure of the new entry.
Returns:
0 on success. Otherwise -1 is returned.

Definition at line 467 of file phatdir.c.

References PHATDIRENT::dent_adate, PHATDIRENT::dent_attr, PHATDIRENT::dent_cdate, PHATDIRENT::dent_ctime, PHATDIRENT::dent_mdate, PHATDIRENT::dent_mtime, GetDosTimeStamp(), _NUTFILE::nf_fcb, PhatDbgFileInfo(), and stdout.

int PhatDirEntryUpdate ( NUTFILE nfp  ) 

Update directory entry of an opened file or directory.

Parameters:
nfp File of which the directory entry will be updated.
Returns:
0 on success. Otherwise -1 is returned.

Definition at line 491 of file phatdir.c.

References _NUTDEVICE::dev_dcb, memcpy(), _NUTFILE::nf_dev, _NUTFILE::nf_fcb, PhatDbgDirEntry(), PhatSectorLoad(), PHATSECTBUF::sect_data, PHATSECTBUF::sect_dirty, stdout, and PHATVOL::vol_buf.

int PhatDirEntryFind ( NUTFILE ndp,
CONST char *  spec,
uint32_t  attmsk,
PHATFIND srch 
)

Find a directory entry with a specified name.

Parameters:
ndp Pointer to a previously opened directory.
spec Name of the entry to retrieve.
attmsk Attribute mask. Entries with attributes not specified in this mask will be ignored.
srch Optional pointer to a structure which receives the search result.
Returns:
0 if an entry was found, otherwise -1 is returned.

Definition at line 630 of file phatdir.c.

References PHATDIRENT::dent_attr, free, malloc, _NUTFILE::nf_fcb, PhatFilePosRewind(), PHATFIND::phfind_ent, PHATFIND::phfind_name, and strcasecmp.

NUTFILE* PhatDirOpenParent ( NUTDEVICE dev,
CONST char *  path,
CONST char **  basename 
)

Open parent directory of a given path.

Parameters:
dev Specifies the file system device.
path Full path.
basename Points to a pointer which will be set to the last component within the full path.
Returns:
Pointer to a NUTFILE structure if successful or NUTFILE_EOF otherwise.

Definition at line 671 of file phatdir.c.

References free, GetParentPath(), NUTFILE_EOF, and PhatDirOpen().

int PhatDirRenameEntry ( NUTDEVICE dev,
CONST char *  old_path,
CONST char *  new_path 
)

Rename file.

Parameters:
dev Specifies the file system device.
old_path Old name and path of the file.
new_path New name and path of the file.
Returns:
0 on success, -1 otherwise.

Definition at line 692 of file phatdir.c.

References CONST, EEXIST, ENOENT, errno, free, malloc, NUTFILE_EOF, PHAT_FATTR_FILEMASK, PhatDirEntryFind(), PhatDirOpenParent(), PhatFileClose(), PHATFIND::phfind_ent, PHATFIND::phfind_pos, and PHATFIND::phfind_xcnt.

int PhatDirReleaseChain ( NUTDEVICE dev,
PHATDIRENT dent 
)

Release a cluster chain of a specified directory entry.

Parameters:
dev Specifies the file system device.
dent Directory entry.
Returns:
0 on success or -1 on failure.

Definition at line 739 of file phatdir.c.

References PHATDIRENT::dent_attr, PHATDIRENT::dent_clust, PHATDIRENT::dent_clusthi, _NUTDEVICE::dev_dcb, EACCES, errno, Phat12ReleaseChain(), Phat16ReleaseChain(), Phat32ReleaseChain(), PHAT_FATTR_RDONLY, and PHATVOL::vol_type.

int PhatDirDelEntry ( NUTDEVICE dev,
CONST char *  path,
uint32_t  flags 
)

Remove a directory entry.

Allocated clusters are released.

Parameters:
dev Specifies the file system device.
path Name of the entry to remove.
flags Attributes of the entry to remove.
Returns:
0 if successful. Otherwise returns an error code.

Definition at line 783 of file phatdir.c.

References CONST, ENOENT, errno, free, malloc, NUTFILE_EOF, PhatDirEntryFind(), PhatDirOpenParent(), PhatDirReleaseChain(), PhatFileClose(), PHATFIND::phfind_ent, PHATFIND::phfind_pos, and PHATFIND::phfind_xcnt.

NUTFILE* PhatDirOpen ( NUTDEVICE dev,
CONST char *  dpath 
)

Open a directory.

Parameters:
dev Specifies the file system device.
dpath Full absolute pathname of the directory to open.
Returns:
Pointer to a NUTFILE structure if successful or NUTFILE_EOF otherwise.

Definition at line 817 of file phatdir.c.

References _O_RDONLY, PHATDIRENT::dent_attr, PHATDIRENT::dent_clust, PHATDIRENT::dent_clusthi, _NUTDEVICE::dev_dcb, ENODEV, ENOENT, errno, PHATFILE::f_clust, PHATFILE::f_clust_pos, PHATFILE::f_clust_prv, 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, memset(), _NUTFILE::nf_dev, _NUTFILE::nf_fcb, _NUTFILE::nf_next, NUTFILE_EOF, PHAT_FATTR_DIR, PHAT_FATTR_FILEMASK, PHAT_MAX_NAMELEN, PhatClusterSector(), PhatDbgFileInfo(), PhatDirEntryFind(), PhatFilePosRewind(), PHATFIND::phfind_ent, stdout, PHATVOL::vol_root_clust, and PHATVOL::vol_type.

int PhatDirRead ( DIR dir  ) 

Read the next directory entry.

Parameters:
dir Pointer to the internal directory information structure.
Returns:
0 on success, -1 otherwise.

Definition at line 950 of file phatdir.c.

References dirent::d_name, dirent::d_namlen, dirent::d_type, DIR::dd_buf, DIR::dd_fd, PHATDIRENT::dent_attr, free, malloc, memset(), PHAT_FATTR_DIR, PhatDbgDirEntry(), PHATFIND::phfind_ent, PHATFIND::phfind_name, stdout, strcpy(), and strlen().

int PhatDirCreate ( NUTDEVICE dev,
char *  path 
)

Create a new subdirectory.

One cluster is allocated, initialized to zero and two directory entries are created, '.' and '..'.

Parameters:
dev Specifies the file system device.
path Full path to the directory.
Returns:
0 on success. Otherwise -1 is returned.

Definition at line 989 of file phatdir.c.

References _O_CREAT, _O_EXCL, _O_RDWR, AllocFirstCluster(), PHATDIRENT::dent_clust, PHATDIRENT::dent_clusthi, PHATDIRENT::dent_name, _NUTDEVICE::dev_dcb, PHATFILE::f_clust, PHATFILE::f_clust_prv, PHATFILE::f_dirent, PHATFILE::f_pde_clust, PHATFILE::f_pde_clusthi, free, malloc, memset(), _NUTFILE::nf_fcb, NUTFILE_EOF, PHAT_FATTR_DIR, PhatFileClose(), PhatFileOpen(), PhatFilePosRewind(), PhatFileWrite(), PHATVOL::vol_clustsz, PHATVOL::vol_root_clust, and PHATVOL::vol_sectsz.

int PhatDirRemove ( NUTDEVICE dev,
char *  path 
)

Remove a specified subdirectory.

Parameters:
dev Specifies the file system device.
path Full path to the directory.
Returns:
0 on success. Otherwise -1 is returned.

Definition at line 1076 of file phatdir.c.

References _O_RDONLY, PHATDIRENT::dent_attr, PHATDIRENT::dent_name, EBUSY, ENOTEMPTY, errno, free, malloc, memcmp(), NUTFILE_EOF, PHAT_FATTR_DIR, PHAT_FATTR_FILEMASK, PHAT_REM_DIRENT, PhatDirDelEntry(), PhatFileClose(), PhatFileOpen(), and PhatFileRead().

int PhatDirEntryStatus ( NUTDEVICE dev,
CONST char *  path,
struct stat stp 
)

Retrieve status of a specified file.

Parameters:
dev File system device.
path Path name to the file to query.
stp Pointer to a structure which receives the result.
return 0 on success, -1 otherwise.

Definition at line 1147 of file phatdir.c.

References _daylight, CONST, PHATDIRENT::dent_attr, PHATDIRENT::dent_fsize, PHATDIRENT::dent_mdate, PHATDIRENT::dent_mtime, free, malloc, memset(), mktime(), NUTFILE_EOF, PHAT_FATTR_DIR, PHAT_FATTR_FILEMASK, PhatDirEntryFind(), PhatDirOpenParent(), PhatFileClose(), PHATFIND::phfind_ent, stat::st_ino, stat::st_mode, stat::st_mtime, stat::st_nlink, stat::st_size, _tm::tm_hour, _tm::tm_isdst, _tm::tm_mday, _tm::tm_min, _tm::tm_mon, _tm::tm_sec, and _tm::tm_year.


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/