Latest available version: IDA and decompilers v8.4.240320sp1 see all releases
Hex-Rays logo State-of-the-art binary code analysis tools
email icon

Directory tree. More...

#include <dirtree.hpp>

Public Member Functions

 dirtree_t (dirspec_t *ds)
 
bool is_orderable () const
 Is dirtree orderable? More...
 
dterr_t chdir (const char *path)
 Change current directory. More...
 
qstring getcwd () const
 Get current directory. More...
 
qstring get_abspath (const dirtree_cursor_t &cursor, uint32 name_flags=DTN_FULL_NAME) const
 Get absolute path pointed by the cursor. More...
 
qstring get_abspath (const char *relpath) const
 Construct an absolute path from the specified relative path. More...
 
direntry_t resolve_cursor (const dirtree_cursor_t &cursor) const
 Resolve cursor. More...
 
direntry_t resolve_path (const char *path) const
 Resolve path. More...
 
bool isdir (const char *path) const
 Is a directory? More...
 
bool isfile (const char *path) const
 Is a file? More...
 
qstring get_entry_name (const direntry_t &de, uint32 name_flags=DTN_FULL_NAME) const
 Get entry name. More...
 
bool is_dir_ordered (diridx_t diridx) const
 Is dir ordered? More...
 
bool set_natural_order (diridx_t diridx, bool enable) const
 Enable/disable natural inode order in a directory. More...
 
ssize_t get_dir_size (diridx_t diridx) const
 Get dir size. More...
 
qstring get_entry_attrs (const direntry_t &de) const
 Get entry attributes. More...
 
bool findfirst (dirtree_iterator_t *ff, const char *pattern) const
 Start iterating over files in a directory. More...
 
bool findnext (dirtree_iterator_t *ff) const
 Continue iterating over files in a directory. More...
 
dterr_t mkdir (const char *path)
 Create a directory. More...
 
dterr_t rmdir (const char *path)
 Remove a directory. More...
 
dterr_t link (const char *path)
 Add a file item into a directory. More...
 
dterr_t unlink (const char *path)
 Remove a file item from a directory. More...
 
dterr_t link (inode_t inode)
 Add an inode into the current directory. More...
 
dterr_t unlink (inode_t inode)
 Remove an inode from the current directory. More...
 
dterr_t rename (const char *from, const char *to)
 Rename a directory entry. More...
 
ssize_t get_rank (diridx_t diridx, const direntry_t &de) const
 Get ordering rank of an item. More...
 
dterr_t change_rank (const char *path, ssize_t rank_delta)
 Change ordering rank of an item. More...
 
dirtree_cursor_t get_parent_cursor (const dirtree_cursor_t &cursor) const
 Get parent cursor. More...
 
bool load ()
 Load the tree structure from the netnode. More...
 
bool save () const
 Save the tree structure to the netnode. More...
 
const char * get_id () const
 netnode name
 
void set_id (const char *nm)
 
void notify_dirtree (bool added, inode_t inode)
 Notify dirtree about a change of an inode. More...
 
ssize_t traverse (dirtree_visitor_t &v) const
 Traverse dirtree, and be notified at each entry If the the visitor returns anything other than 0, iteration will stop, and that value returned. More...
 
dirtree_cursor_t find_entry (const direntry_t &de) const
 Find the cursor corresponding to an entry of a directory. More...
 

Static Public Member Functions

static const char * errstr (dterr_t err)
 Get textual representation of the error code.
 
static bool isdir (const direntry_t &de)
 
static bool isfile (const direntry_t &de)
 

Detailed Description

Directory tree.

This class organizes a virtual directory tree over items that are represented by dirspec_t.

Member Function Documentation

◆ is_orderable()

bool dirtree_t::is_orderable ( ) const
inline

Is dirtree orderable?

Returns
true if the dirtree is orderable

◆ chdir()

dterr_t dirtree_t::chdir ( const char *  path)
inline

Change current directory.

Parameters
pathnew current directory
Returns
dterr_t error code

◆ getcwd()

qstring dirtree_t::getcwd ( ) const
inline

Get current directory.

Returns
the current working directory

◆ get_abspath() [1/2]

qstring dirtree_t::get_abspath ( const dirtree_cursor_t cursor,
uint32  name_flags = DTN_FULL_NAME 
) const
inline

Get absolute path pointed by the cursor.

Parameters
cursor
name_flagshow exactly the name should be retrieved. combination of bits for get_...name() methods bits
Returns
path; empty string if error
Note
see also resolve_cursor()

◆ get_abspath() [2/2]

qstring dirtree_t::get_abspath ( const char *  relpath) const
inline

Construct an absolute path from the specified relative path.

This function verifies the directory part of the specified path. The last component of the specified path is not verified.

Parameters
relpathrelative path
Returns
path. empty path means wrong directory part of RELPATH

◆ resolve_cursor()

direntry_t dirtree_t::resolve_cursor ( const dirtree_cursor_t cursor) const
inline

Resolve cursor.

Parameters
cursorto analyze
Returns
directory entry; if the cursor is bad, the resolved entry will be invalid.
Note
see also get_abspath()

◆ resolve_path()

direntry_t dirtree_t::resolve_path ( const char *  path) const
inline

Resolve path.

Parameters
pathto analyze
Returns
directory entry

◆ isdir()

bool dirtree_t::isdir ( const char *  path) const
inline

Is a directory?

Parameters
pathto analyze
Returns
true if the specified path is a directory

◆ isfile()

bool dirtree_t::isfile ( const char *  path) const
inline

Is a file?

Parameters
pathto analyze
Returns
true if the specified path is a file

◆ get_entry_name()

qstring dirtree_t::get_entry_name ( const direntry_t de,
uint32  name_flags = DTN_FULL_NAME 
) const
inline

Get entry name.

Parameters
dedirectory entry
name_flagshow exactly the name should be retrieved. combination of bits for get_...name() methods bits
Returns
name

◆ is_dir_ordered()

bool dirtree_t::is_dir_ordered ( diridx_t  diridx) const
inline

Is dir ordered?

Returns
true if the dirtree has natural ordering

◆ set_natural_order()

bool dirtree_t::set_natural_order ( diridx_t  diridx,
bool  enable 
) const
inline

Enable/disable natural inode order in a directory.

Parameters
diridxdirectory index
enableaction to do TRUE - enable ordering: re-order existing entries so that all subdirs are at the to beginning of the list, file entries are sorted and placed after the subdirs FALSE - disable ordering, no changes to existing entries
Returns
SUCCESS

◆ get_dir_size()

ssize_t dirtree_t::get_dir_size ( diridx_t  diridx) const
inline

Get dir size.

Parameters
diridxdirectory index
Returns
number of entries under this directory; if error, return -1

◆ get_entry_attrs()

qstring dirtree_t::get_entry_attrs ( const direntry_t de) const
inline

Get entry attributes.

Parameters
dedirectory entry
Returns
name

◆ findfirst()

bool dirtree_t::findfirst ( dirtree_iterator_t ff,
const char *  pattern 
) const
inline

Start iterating over files in a directory.

Parameters
ffdirectory iterator. it will be initialized by the function
patternpattern to search for
Returns
success

◆ findnext()

bool dirtree_t::findnext ( dirtree_iterator_t ff) const
inline

Continue iterating over files in a directory.

Parameters
ffdirectory iterator
Returns
success

◆ mkdir()

dterr_t dirtree_t::mkdir ( const char *  path)
inline

Create a directory.

Parameters
pathdirectory to create
Returns
dterr_t error code

◆ rmdir()

dterr_t dirtree_t::rmdir ( const char *  path)
inline

Remove a directory.

Parameters
pathdirectory to delete
Returns
dterr_t error code

◆ link() [1/2]

dterr_t dirtree_t::link ( const char *  path)
inline

Add a file item into a directory.

Parameters
pathpath to item to add to a directory
Returns
dterr_t error code

◆ unlink() [1/2]

dterr_t dirtree_t::unlink ( const char *  path)
inline

Remove a file item from a directory.

Parameters
pathpath to item remove from a directory
Returns
dterr_t error code

◆ link() [2/2]

dterr_t dirtree_t::link ( inode_t  inode)
inline

Add an inode into the current directory.

Parameters
inode
Returns
dterr_t error code

◆ unlink() [2/2]

dterr_t dirtree_t::unlink ( inode_t  inode)
inline

Remove an inode from the current directory.

Parameters
inode
Returns
dterr_t error code

◆ rename()

dterr_t dirtree_t::rename ( const char *  from,
const char *  to 
)
inline

Rename a directory entry.

Parameters
fromsource path
todestination path
Returns
dterr_t error code
Note
This function can also rename the item

◆ get_rank()

ssize_t dirtree_t::get_rank ( diridx_t  diridx,
const direntry_t de 
) const
inline

Get ordering rank of an item.

Parameters
diridxindex of the parent directory
dedirectory entry
Returns
number in a range of [0..n) where n is the number of entries in the parent directory. -1 if error

◆ change_rank()

dterr_t dirtree_t::change_rank ( const char *  path,
ssize_t  rank_delta 
)
inline

Change ordering rank of an item.

Parameters
pathpath to the item
rank_deltathe amount of the change. positive numbers mean to move down in the list; negative numbers mean to move up.
Returns
dterr_t error code
Note
this function may disable natural ordering of the parent folder
See also
set_natural_order()

◆ get_parent_cursor()

dirtree_cursor_t dirtree_t::get_parent_cursor ( const dirtree_cursor_t cursor) const
inline

Get parent cursor.

Parameters
cursora valid ditree cursor
Returns
cursor's parent

◆ load()

bool dirtree_t::load ( )
inline

Load the tree structure from the netnode.

If dirspec_t::id is empty, the operation will be considered a success. In addition, calling load() more than once will not do anything, and will be considered a success.

Returns
success
See also
dirspec_t::id.

◆ save()

bool dirtree_t::save ( ) const
inline

Save the tree structure to the netnode.

Returns
success
See also
dirspec_t::id.

◆ notify_dirtree()

void dirtree_t::notify_dirtree ( bool  added,
inode_t  inode 
)
inline

Notify dirtree about a change of an inode.

Parameters
addedare we adding or deleting an inode?
inodeinode in question

◆ traverse()

ssize_t dirtree_t::traverse ( dirtree_visitor_t v) const
inline

Traverse dirtree, and be notified at each entry If the the visitor returns anything other than 0, iteration will stop, and that value returned.

The tree is traversed using a depth-first algorithm. It is forbidden to modify the dirtree_t during traversal; doing so will result in undefined behavior.

Parameters
vthe callback
Returns
0, or whatever the visitor returned

◆ find_entry()

dirtree_cursor_t dirtree_t::find_entry ( const direntry_t de) const
inline

Find the cursor corresponding to an entry of a directory.

Parameters
dedirectory entry
Returns
cursor corresponding to the directory entry

The documentation for this class was generated from the following file: