direnum.h File Reference

Directory enumerator header file. More...

#include <dirent.h>
#include "global.h"
Include dependency graph for direnum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ESTIMATED_ENTRY_LENGTH   (15)
 How many bytes an average filename needs.

Functions

int dir__enumerator (struct estat *this, int est_count, int by_name)
 This function reads a directory into a self-allocated memory area.
int dir__sortbyname (struct estat *sts)
 Sorts the entries of the directory sts by name into the estat::by_name array, which is reallocated and NULL-terminated.
int dir__sortbyinode (struct estat *sts)
 Sorts the existing estat::by_inode array afresh, by device/inode.
int dir___f_sort_by_inode (struct estat **a, struct estat **b)
 Compares the data inside two struct estat pointers to pointers by device/inode.
int dir___f_sort_by_inodePP (struct estat *a, struct estat *b)
 Compares two struct estat pointers by device/inode.
int dir___f_sort_by_name (const void *a, const void *b)
 Compares the data inside two struct estat pointers to pointers by name.
int dir___f_sort_by_nameCC (const void *a, const void *b)
 Compares two names/strings.
int dir___f_sort_by_nameCS (const void *a, const void *b)
 Compares a pointer to name (string) with a struct estat pointer to pointer.

Detailed Description

Directory enumerator header file.

Definition in file direnum.h.


Define Documentation

#define ESTIMATED_ENTRY_LENGTH   (15)

How many bytes an average filename needs.

Measured on a debian system:

 find / -printf "%f\n" | wc

Definition at line 43 of file direnum.h.

Referenced by dir__enumerator().


Function Documentation

int dir___f_sort_by_inode ( struct estat **  a,
struct estat **  b 
)

Compares the data inside two struct estat pointers to pointers by device/inode.

Returns:
+2, +1, 0, -1, -2, suitable for qsort().

Definition at line 252 of file direnum.c.

References dir___f_sort_by_inodePP().

Referenced by dir__sortbyinode(), ops__find_entry_byinode(), waa___find_position(), and waa__output_tree().

Here is the call graph for this function:

Here is the caller graph for this function:

int dir___f_sort_by_inodePP ( struct estat a,
struct estat b 
)

Compares two struct estat pointers by device/inode.

Returns:
+2, +1, 0, -1, -2, suitable for qsort().

That is now an inline function; but without force gcc doesn't inline it on 32bit, because of the size (64bit compares, 0x6b bytes). [ __attribute__((always_inline)) in declaration].

Definition at line 235 of file direnum.c.

References sstat_t::dev, sstat_t::ino, and estat::st.

Referenced by dir___f_sort_by_inode(), and ign__is_ignore().

Here is the caller graph for this function:

int dir___f_sort_by_name ( const void *  a,
const void *  b 
)

Compares the data inside two struct estat pointers to pointers by name.

Returns:
+2, +1, 0, -1, -2, suitable for qsort().

Definition at line 271 of file direnum.c.

References dir___f_sort_by_nameCC().

Referenced by dir__sortbyname(), and ops__correlate_dirs().

Here is the call graph for this function:

Here is the caller graph for this function:

int dir___f_sort_by_nameCC ( const void *  a,
const void *  b 
) [inline]

Compares two names/strings.

Used for type checking cleanliness. 'C' as for 'Const'.

Returns:
+2, +1, 0, -1, -2, suitable for qsort().

Definition at line 262 of file direnum.c.

Referenced by dir___f_sort_by_name(), and dir___f_sort_by_nameCS().

Here is the caller graph for this function:

int dir___f_sort_by_nameCS ( const void *  a,
const void *  b 
)

Compares a pointer to name (string) with a struct estat pointer to pointer.

Returns:
+2, +1, 0, -1, -2, suitable for qsort().

Definition at line 283 of file direnum.c.

References dir___f_sort_by_nameCC().

Referenced by ops__find_entry_byname().

Here is the call graph for this function:

Here is the caller graph for this function:

int dir__enumerator ( struct estat this,
int  est_count,
int  give_by_name 
)

This function reads a directory into a self-allocated memory area.

This function reads a directory into a self-allocated memory area.

The entries are sorted by inode number and stat()ed.

Parameters:
this a pointer to this directory's stat - for estimating the number of entries. Only this->st.st_size is used for that - it may have to be zeroed before calling.
est_count is used to give an approximate number of entries, to avoid many realloc()s.
give_by_name simply tells whether the ->by_name array should be created, too.

The result is written back into the sub-entry array in this.

To avoid reallocating (and copying!) large amounts of memory, this function fills some arrays from the directory, then allocates the needed space, sorts the data (see note below) and adds all other data. See sts_array, names and inode_numbers.

Note:
Sorting by inode number brings about 30% faster lookup times on my test environment (8 to 5 seconds) on an empty cache. Once the cache is filled, it won't make a difference.
Returns:
0 for success, else an errorcode.

Definition at line 361 of file direnum.c.

References BUG_ON, estat::by_inode, estat::by_name, DEBUGP, dir__close(), dir__enum(), dir__get_dir_size(), dir__sortbyinode(), dir__sortbyname(), dir__start_enum(), estat::entry_count, ESTIMATED_ENTRY_LENGTH, FREE_SPACE, hlp__alloc(), hlp__lstat(), hlp__realloc(), IF_FREE, sstat_t::ino, estat::local_mode_packed, sstat_t::mode, MODE_T_to_PACKED, estat::name, estat::old_rev_mode_packed, ops__allocate(), estat::parent, estat::repos_rev, sstat_t::size, estat::st, STOPIF, STOPIF_CODE_ERR, estat::strings, and estat::to_be_ignored.

Referenced by waa__dir_enum().

Here is the call graph for this function:

Here is the caller graph for this function:

int dir__sortbyinode ( struct estat sts  ) 

Sorts the existing estat::by_inode array afresh, by device/inode.

Definition at line 322 of file direnum.c.

References BUG_ON, estat::by_inode, dir___f_sort_by_inode(), and estat::entry_count.

Referenced by dir__enumerator(), ops__find_entry_byinode(), and waa__output_tree().

Here is the call graph for this function:

Here is the caller graph for this function:

int dir__sortbyname ( struct estat sts  ) 

Sorts the entries of the directory sts by name into the estat::by_name array, which is reallocated and NULL-terminated.

Sorts the entries of the directory sts by name into the estat::by_name array, which is reallocated and NULL-terminated.

If it has no entries, an array with NULL is nonetheless allocated.

Definition at line 293 of file direnum.c.

References estat::by_inode, estat::by_name, dir___f_sort_by_name(), estat::entry_count, hlp__realloc(), and STOPIF.

Referenced by dir__enumerator(), ops__correlate_dirs(), ops__find_entry_byname(), and waa__do_sorted_tree().

Here is the call graph for this function:

Here is the caller graph for this function:


Generated for fsvs by  doxygen 1.6.1