FATDirectoryEntry¶
Directory entry operations with PyFAT.
- class pyfatfs.FATDirectoryEntry.FATDirectoryEntry(DIR_Name: EightDotThree, DIR_Attr: int, DIR_NTRes: int, DIR_CrtTimeTenth: int, DIR_CrtTime: int, DIR_CrtDate: int, DIR_LstAccessDate: int, DIR_FstClusHI: int, DIR_WrtTime: int, DIR_WrtDate: int, DIR_FstClusLO: int, DIR_FileSize: int, encoding: str = 'ibm437', fs: pyfatfs.PyFat.PyFat = None, lazy_load: bool = False, lfn_entry=None)¶
Bases:
object
Represents directory entries in FAT (files & directories).
FAT directory entry constructor.
- Parameters:
DIR_Name – EightDotThree class instance
DIR_Attr – Attributes of directory
DIR_NTRes – Reserved attributes of directory entry
DIR_CrtTimeTenth – Milliseconds at file creation
DIR_CrtTime – Creation timestamp of entry
DIR_CrtDate – Creation date of entry
DIR_LstAccessDate – Last access date of entry
DIR_FstClusHI – High cluster value of entry data
DIR_WrtTime – Modification timestamp of entry
DIR_WrtDate – Modification date of entry
DIR_FstClusLO – Low cluster value of entry data
DIR_FileSize – File size in bytes
encoding – Encoding of filename
lfn_entry – FATLongDirectoryEntry instance or None
- ATTR_ARCHIVE = 32¶
Bit set in DIR_Attr if entry is an archive
- ATTR_DIRECTORY = 16¶
Bit set in DIR_Attr if entry is a directory
- ATTR_HIDDEN = 2¶
Bit set in DIR_Attr if entry is hidden
- ATTR_LONG_NAME = 15¶
Bits set in DIR_Attr if entry is an LFN entry
- ATTR_LONG_NAME_MASK = 63¶
Bitmask to check if entry is an LFN entry
- ATTR_READ_ONLY = 1¶
Bit set in DIR_Attr if entry is read-only
- ATTR_SYSTEM = 4¶
Bit set in DIR_Attr if entry is a system file
- ATTR_VOLUME_ID = 8¶
Bit set in DIR_Attr if entry is a volume id descriptor
- FAT_DIRECTORY_HEADER_SIZE = 32¶
Size of a directory entry header in bytes
- FAT_DIRECTORY_LAYOUT = '<11sBBBHHHHHHHL'¶
Directory entry header layout in struct formatted string
- FAT_DIRECTORY_VARS = ['DIR_Name', 'DIR_Attr', 'DIR_NTRes', 'DIR_CrtTimeTenth', 'DIR_CrtTime', 'DIR_CrtDate', 'DIR_LstAccessDate', 'DIR_FstClusHI', 'DIR_WrtTime', 'DIR_WrtDate', 'DIR_FstClusLO', 'DIR_FileSize']¶
Directory entry headers
- FREE_DIR_ENTRY_MARK = 229¶
Marks a directory entry as empty
- LAST_DIR_ENTRY_MARK = 0¶
Marks all directory entries after this one as empty
- MAX_FILE_SIZE = 4294967295¶
Maximum allowed file size, dictated by size of DIR_FileSize
- add_subdirectory(dir_entry, recursive: bool = True)¶
Register a subdirectory in current directory entry.
- Parameters:
dir_entry – FATDirectoryEntry
- Raises:
PyFATException: If current entry is not a directory or given directory entry already has a parent directory set
- property filesize¶
Size of the file in bytes.
- Getter:
Get the currently set filesize in bytes
- Setter:
Set new filesize. FAT chain must be extended separately. Raises PyFATException with errno=E2BIG if filesize is larger than FATDirectoryEntry.MAX_FILE_SIZE.
- Type:
int
- get_atime() DosDateTime ¶
Get dentry access time.
- get_checksum() int ¶
Get calculated checksum of this directory entry.
- Returns:
Checksum as int
- get_cluster()¶
Get cluster address of directory entry.
- Returns:
Cluster address of entry
- get_ctime() DosDateTime ¶
Get dentry creation time.
- get_entries()¶
Get entries of directory.
- Raises:
PyFatException: If entry is not a directory
- Returns:
tuple: root (current path, full), dirs (all dirs), files (all files)
- get_entry(path: str)¶
Get sub-entry if current entry is a directory.
- Parameters:
path – Relative path of entry to get
- Raises:
PyFATException: If entry cannot be found
- Returns:
FATDirectoryEntry: Found entry
- get_entry_size()¶
Get size of directory entry.
- Returns:
Entry size in bytes as int
- get_full_path()¶
Iterate all parents up and join them by “/”.
- get_long_name()¶
Get long name of directory entry.
- Raises:
NotAnLFNEntryException: If entry has no long file name
- Returns:
str: Long file name of directory entry
- get_mtime() DosDateTime ¶
Get dentry modification time.
- get_parent_dir()¶
Get the parent directory entry.
- get_short_name()¶
Get short name of directory entry.
- Returns:
str: Name of directory entry
- get_size()¶
Get filesize or directory entry size.
- Returns:
Filesize or directory entry size in bytes as int
- is_archive()¶
Determine if dir entry has archive attribute set.
- Returns:
Boolean value indicating archive attribute is set
- is_directory()¶
Determine if dir entry has directory attribute set.
- Returns:
Boolean value indicating directory attribute is set
- is_empty()¶
Determine if directory does not contain any directories.
Determine if dir entry has the hidden attribute set.
- Returns:
Boolean value indicating hidden attribute is set
- is_read_only()¶
Determine if dir entry has read-only attribute set.
- Returns:
Boolean value indicating read-only attribute is set
- is_special()¶
Determine if dir entry is a dot or dotdot entry.
- Returns:
Boolean value whether or not entry is a dot or dotdot entry
- is_system()¶
Determine if dir entry has the system file attribute set.
- Returns:
Boolean value indicating system attribute is set
- is_volume_id()¶
Determine if dir entry has the volume ID attribute set.
- Returns:
Boolean value indicating volume ID attribute is set
- mark_empty()¶
Mark this directory entry as empty.
- static new(name: EightDotThree, tz: 0, encoding: str, attr: int = 0, ntres: int = 0, cluster: int = 0, filesize: int = 0) FATDirectoryEntry ¶
Create a new directory entry with sane defaults.
- Parameters:
name –
EightDotThree
: SFN of new dentrytz –
timezone
: Timezone value to use for new timestampencoding –
str
: Encoding for SFNattr –
int
: Directory attributesntres –
int
: Reserved NT directory attributescluster –
int
: Cluster number of dentryfilesize –
int
: Size of file referenced by dentry
- Returns:
FATDirectoryEntry
instance
- remove_dir_entry(name)¶
Remove given dir_entry from dir list.
NOTE: This will also remove special entries such as ».«, »..« and volume labels!
- set_cluster(first_cluster)¶
Set low and high cluster address in directory headers.
- set_lfn_entry(lfn_entry)¶
Set LFN entry for current directory entry.
- Param:
lfn_entry: Can be either of type FATLongDirectoryEntry or None.
- set_size(size: int)¶
Set filesize.
- Parameters:
size – int: File size in bytes
- walk()¶
Walk all directory entries recursively.
- Returns:
tuple: root (current path, full), dirs (all dirs), files (all files)
- class pyfatfs.FATDirectoryEntry.FATLongDirectoryEntry¶
Bases:
object
Represents long file name (LFN) entries.
Initialize empty LFN directory entry object.
- FAT_LONG_DIRECTORY_LAYOUT = '<B10sBBB12sH4s'¶
LFN entry header layout in struct formatted string
- FAT_LONG_DIRECTORY_VARS = ['LDIR_Ord', 'LDIR_Name1', 'LDIR_Attr', 'LDIR_Type', 'LDIR_Chksum', 'LDIR_Name2', 'LDIR_FstClusLO', 'LDIR_Name3']¶
LFN header fields when extracted with FAT_LONG_DIRECTORY_LAYOUT
- LAST_LONG_ENTRY = 64¶
Ordinance of last LFN entry in a chain
- LFN_ENTRY_LENGTH = 26¶
Length for long file name in bytes per entry
- add_lfn_entry(LDIR_Ord, LDIR_Name1, LDIR_Attr, LDIR_Type, LDIR_Chksum, LDIR_Name2, LDIR_FstClusLO, LDIR_Name3)¶
Add LFN entry to this instances chain.
- Parameters:
LDIR_Ord – Ordinance of LFN entry
LDIR_Name1 – First name field of LFN entry
LDIR_Attr – Attributes of LFN entry
LDIR_Type – Type of LFN entry
LDIR_Chksum – Checksum value of following 8dot3 entry
LDIR_Name2 – Second name field of LFN entry
LDIR_FstClusLO – Cluster address of LFN entry. Always zero.
LDIR_Name3 – Third name field of LFN entry
- get_entries(reverse: bool = False)¶
Get LFS entries in correct order (based on LDIR_Ord).
- Parameters:
reverse – bool: Returns LFN entries in reversed order. This is required for byte representation.
- static is_lfn_entry(LDIR_Ord, LDIR_Attr)¶
Verify that entry is an LFN entry.
- Parameters:
LDIR_Ord – First byte of the directory header, ordinance
LDIR_Attr – Attributes segment of directory header
- Returns:
True if entry is a valid LFN entry
- is_lfn_entry_complete()¶
Verify that LFN object forms a complete chain.
- Returns:
True if LAST_LONG_ENTRY is found
- mark_empty()¶
Mark LFN entry as empty.
- pyfatfs.FATDirectoryEntry.make_lfn_entry(dir_name: str, short_name: EightDotThree)¶
Generate a FATLongDirectoryEntry instance from directory name.
- Parameters:
dir_name – Long name of directory
short_name – EightDotThree class instance
- Raises:
PyFATException if entry name does not require an LFN entry or the name exceeds the FAT limitation of 255 characters