Routines for reading and writing directories. More...
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. | |
| NUTFILE * | PhatDirOpenParent (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. | |
| NUTFILE * | PhatDirOpen (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. | |
Routines for reading and writing directories.
| #define PHAT_MAX_NAMELEN 255 |
Maximum length of a base file name.
Referenced by PhatDirOpen().
| #define PHAT_REM_DIRENT 0xE5 |
Referenced by MakePhatName(), MakeVisibleName(), and PhatDirRemove().
| #define PHAT_REM_NAMENT 0x05 |
Referenced by MakePhatName(), and MakeVisibleName().
| #define PHAT_MAXDIRENT 65536 |
Maximum number of directory entries.
| 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.
| int PhatDirEntryCreate | ( | NUTFILE * | ndp, |
| const char * | name, | ||
| int | acc, | ||
| PHATDIRENT * | dirent | ||
| ) |
Create a new directory entry.
| 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. |
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().
| int PhatDirEntryUpdate | ( | NUTFILE * | nfp | ) |
Update directory entry of an opened file or directory.
| nfp | File of which the directory entry will be updated. |
References _NUTDEVICE::dev_dcb, memcpy(), _NUTFILE::nf_dev, _NUTFILE::nf_fcb, PhatDbgDirEntry(), PhatSectorBufferRelease(), PhatSectorLoad(), _PHATSECTBUF::sect_data, _PHATSECTBUF::sect_dirty, stdout, and _PHATVOL::vol_buf.
Find a directory entry with a specified name.
| 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. |
References _PHATDIRENT::dent_attr, free(), malloc(), _NUTFILE::nf_fcb, NULL, PhatFilePosRewind(), _PHATFIND::phfind_ent, _PHATFIND::phfind_name, rc, and strcasecmp.
Referenced by PhatDirDelEntry(), PhatDirEntryStatus(), PhatDirOpen(), PhatDirRenameEntry(), and PhatFileOpen().
Open parent directory of a given path.
| 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. |
References free(), GetParentPath(), NULL, NUTFILE_EOF, PhatDirOpen(), and rc.
Referenced by PhatDirDelEntry(), PhatDirEntryStatus(), PhatDirRenameEntry(), and PhatFileOpen().
| int PhatDirRenameEntry | ( | NUTDEVICE * | dev, |
| const char * | old_path, | ||
| const char * | new_path | ||
| ) |
Rename file.
| dev | Specifies the file system device. |
| old_path | Old name and path of the file. |
| new_path | New name and path of the file. |
References EEXIST, ENOENT, errno, free(), malloc(), NULL, NUTFILE_EOF, PHAT_FATTR_FILEMASK, PhatDirEntryFind(), PhatDirOpenParent(), PhatFileClose(), _PHATFIND::phfind_ent, _PHATFIND::phfind_pos, _PHATFIND::phfind_xcnt, and rc.
| int PhatDirReleaseChain | ( | NUTDEVICE * | dev, |
| PHATDIRENT * | dent | ||
| ) |
Release a cluster chain of a specified directory entry.
| dev | Specifies the file system device. |
| dent | Directory entry. |
References _PHATDIRENT::dent_attr, _PHATDIRENT::dent_clust, _PHATDIRENT::dent_clusthi, _NUTDEVICE::dev_dcb, EACCES, errno, Phat12ReleaseChain(), Phat16ReleaseChain(), Phat32ReleaseChain(), PHAT_FATTR_RDONLY, rc, and _PHATVOL::vol_type.
Referenced by PhatDirDelEntry(), and PhatFileOpen().
Remove a directory entry.
Allocated clusters are released.
| dev | Specifies the file system device. |
| path | Name of the entry to remove. |
| flags | Attributes of the entry to remove. |
References ENOENT, errno, free(), malloc(), NULL, NUTFILE_EOF, PhatDirEntryFind(), PhatDirOpenParent(), PhatDirReleaseChain(), PhatFileClose(), _PHATFIND::phfind_ent, _PHATFIND::phfind_pos, _PHATFIND::phfind_xcnt, and rc.
Referenced by PhatDirRemove().
Open a directory.
| dev | Specifies the file system device. |
| dpath | Full absolute pathname of the directory to open. |
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, NULL, 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.
Referenced by PhatDirOpenParent().
| int PhatDirRead | ( | DIR * | dir | ) |
Read the next directory entry.
| dir | Pointer to the internal directory information structure. |
References dirent::d_name, dirent::d_namlen, dirent::d_type, _dirdesc::dd_buf, _dirdesc::dd_fd, _PHATDIRENT::dent_attr, free(), malloc(), memset(), NULL, 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 '..'.
| dev | Specifies the file system device. |
| path | Full path to the directory. |
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, NULL, 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.
| dev | Specifies the file system device. |
| path | Full path to the directory. |
References _O_RDONLY, _PHATDIRENT::dent_attr, _PHATDIRENT::dent_name, EBUSY, ENOTEMPTY, errno, free(), malloc(), memcmp(), NULL, NUTFILE_EOF, PHAT_FATTR_DIR, PHAT_FATTR_FILEMASK, PHAT_REM_DIRENT, PhatDirDelEntry(), PhatFileClose(), PhatFileOpen(), PhatFileRead(), and rc.
Retrieve status of a specified file.
| 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.
References _daylight, _PHATDIRENT::dent_attr, _PHATDIRENT::dent_fsize, _PHATDIRENT::dent_mdate, _PHATDIRENT::dent_mtime, free(), malloc(), memset(), mktime(), NULL, NUTFILE_EOF, PHAT_FATTR_DIR, PHAT_FATTR_FILEMASK, PhatDirEntryFind(), PhatDirOpenParent(), PhatFileClose(), _PHATFIND::phfind_ent, rc, 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.