apfs::directory_entry

class directory_entry

Represents a filesystem entry.

A directory entry may represent a file, directory, symbolic link, or any other entry type described by directory_entry_type

Public Functions

std::vector<directory_entry> list_children() const

Lists the files in this entry iff it is a directory (DIRENT_DIR).

Throws:

If – this entry does not represent a directory, an error is thrown.

directory_entry resolve(const std::string &path, bool follow_last = true) const

Navigates to a given path relative to this directory entry.

Follows all symbolic links encountered in the path.

Parameters:
bool follow_last = true

If the path itself may refer to a symbolic link and you do not want to resolve the final entry, set follow_last to false.

void read_file(std::ostream &os, off_t offset = 0, apfs_ssize_t size = -1) const

Reads the file represented by this entry iff it is a file (DIRENT_FILE).

Throws:

If – this entry does not represent a regular file, an error is thrown.

std::string read_symlink() const

Gets the path pointed to by this entry iff it is a symbolic link (DIRENT_LINK).

Throws:

If – this entry does not represent a symbolic link, an error is thrown.

directory_entry follow_symlink(int level = -1) const

Resolves the symbolic link level times.

By default, level is -1, which repeatedly resolves symbolic links until the resulting entry is no longer a symbolic link.

Throws:
  • If – the path points outside the filesystem (e.g. /Volumes/VolName/file instead of /file).

  • Iflevel is -1 and the symbolic links form a cycle.

inode_t load_inode() const

Load the inode for the directory entry.

Public Members

std::string name

The name of this directory entry. Note that this is not the full path.

directory_entry_type type

The type of this directory entry.