Nut/OS  4.10.3
API Reference
Directory Support

Routines for reading and writing directories. More...

Collaboration diagram for Directory Support:

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.

Typedefs

typedef struct _PHATDIRENT PHATDIRENT
 Structure of a directory entry.
typedef struct _PHATXDIRENT PHATXDIRENT
 Structure of an extended directory entry.
typedef struct _PHATFIND PHATFIND

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.

Detailed Description

Routines for reading and writing directories.


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 136 of file phatdir.c.


Typedef Documentation

typedef struct _PHATDIRENT PHATDIRENT

Structure of a directory entry.

Once created, this structure will never change if it points to another directory. Except if the entry is removed.

typedef struct _PHATXDIRENT PHATXDIRENT

Structure of an extended directory entry.

Used for long filenames.

typedef struct _PHATFIND PHATFIND

Function Documentation

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

Create a new directory entry.

Parameters:
ndpHandle to the parent directory.
nameName of the new entry.
accAttributes of the new entry.
direntInformation structure of the new entry.
Returns:
0 on success. Otherwise -1 is returned.

Definition at line 475 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.

Referenced by PhatFileOpen().

Here is the call graph for this function:

int PhatDirEntryUpdate ( NUTFILE nfp)

Update directory entry of an opened file or directory.

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

Definition at line 499 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.

Here is the call graph for this function:

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

Find a directory entry with a specified name.

Parameters:
ndpPointer to a previously opened directory.
specName of the entry to retrieve.
attmskAttribute mask. Entries with attributes not specified in this mask will be ignored.
srchOptional pointer to a structure which receives the search result.
Returns:
0 if an entry was found, otherwise -1 is returned.

Definition at line 638 of file phatdir.c.

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

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

Here is the call graph for this function:

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

Open parent directory of a given path.

Parameters:
devSpecifies the file system device.
pathFull path.
basenamePoints 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 679 of file phatdir.c.

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

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

Here is the call graph for this function:

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

Rename file.

Parameters:
devSpecifies the file system device.
old_pathOld name and path of the file.
new_pathNew name and path of the file.
Returns:
0 on success, -1 otherwise.

Definition at line 700 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.

Here is the call graph for this function:

int PhatDirReleaseChain ( NUTDEVICE dev,
PHATDIRENT dent 
)

Release a cluster chain of a specified directory entry.

Parameters:
devSpecifies the file system device.
dentDirectory entry.
Returns:
0 on success or -1 on failure.

Definition at line 747 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.

Referenced by PhatDirDelEntry(), and PhatFileOpen().

Here is the call graph for this function:

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

Remove a directory entry.

Allocated clusters are released.

Parameters:
devSpecifies the file system device.
pathName of the entry to remove.
flagsAttributes of the entry to remove.
Returns:
0 if successful. Otherwise returns an error code.

Definition at line 791 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.

Referenced by PhatDirRemove().

Here is the call graph for this function:

NUTFILE* PhatDirOpen ( NUTDEVICE dev,
CONST char *  dpath 
)
int PhatDirRead ( DIR dir)

Read the next directory entry.

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

Definition at line 958 of file phatdir.c.

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

Here is the call graph for this function:

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:
devSpecifies the file system device.
pathFull path to the directory.
Returns:
0 on success. Otherwise -1 is returned.

Definition at line 997 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.

Here is the call graph for this function:

int PhatDirRemove ( NUTDEVICE dev,
char *  path 
)

Remove a specified subdirectory.

Parameters:
devSpecifies the file system device.
pathFull path to the directory.
Returns:
0 on success. Otherwise -1 is returned.

Definition at line 1084 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().

Here is the call graph for this function:

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

Retrieve status of a specified file.

Parameters:
devFile system device.
pathPath name to the file to query.
stpPointer to a structure which receives the result.

return 0 on success, -1 otherwise.

Definition at line 1155 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.

Here is the call graph for this function: