Directory enumerator functions. More...
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "est_ops.h"
#include "direnum.h"
#include "warnings.h"
#include "global.h"
#include "helper.h"
#include <linux/types.h>
#include <linux/unistd.h>
Go to the source code of this file.
Defines | |
#define | HAVE_GETDENTS64 1 |
If the system fulfills all necessary checks to use getdents(), this macro is set. | |
#define | FREE_SPACE (4096) |
The amount of memory that should be allocated for directory reading. | |
Typedefs | |
typedef int | dir__handle |
The type of handle. | |
typedef struct dirent64 | fsvs_dirent |
A compatibility structure. | |
Functions | |
int | dir__start_enum (dir__handle *dh, char *path) |
Starts enumeration of the given path. | |
int | dir__enum (dir__handle dh, fsvs_dirent *dirp, unsigned int count) |
The enumeration function. | |
int | dir__close (dir__handle dh) |
Simply closes the handle dh. | |
int | dir__get_dir_size (dir__handle dh, struct sstat_t *st) |
How to get the length of a directory (in bytes), from a handle dh, into st->size. | |
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_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_nameCC (const void *a, const void *b) |
Compares two names/strings. | |
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_nameCS (const void *a, const void *b) |
Compares a pointer to name (string) with a struct estat pointer to pointer. | |
int | dir__sortbyname (struct estat *sts) |
-. | |
int | dir__sortbyinode (struct estat *sts) |
-. | |
int | dir__enumerator (struct estat *this, int est_count, int give_by_name) |
-. |
Directory enumerator functions.
Definition in file direnum.c.
#define FREE_SPACE (4096) |
The amount of memory that should be allocated for directory reading.
This value should be bigger (or at least equal) than the number of bytes returned by getdents(). For the compatibility layer it's more or less the maximum filename length plus the inode and record length lengths.
This many bytes more will also be allocated for the filenames in a directory; if we get this close to the end of the buffer, the memory area will be reallocated.
Definition at line 226 of file direnum.c.
Referenced by dir__enumerator().
Compares the data inside two struct estat pointers to pointers by device/inode.
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().
Compares two struct estat pointers by device/inode.
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().
int dir___f_sort_by_name | ( | const void * | a, | |
const void * | b | |||
) |
Compares the data inside two struct estat pointers to pointers by name.
Definition at line 271 of file direnum.c.
References dir___f_sort_by_nameCC().
Referenced by dir__sortbyname(), and ops__correlate_dirs().
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'.
Definition at line 262 of file direnum.c.
Referenced by dir___f_sort_by_name(), and dir___f_sort_by_nameCS().
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.
Definition at line 283 of file direnum.c.
References dir___f_sort_by_nameCC().
Referenced by ops__find_entry_byname().
int dir__enumerator | ( | struct estat * | this, | |
int | est_count, | |||
int | give_by_name | |||
) |
-.
This function reads a directory into a self-allocated memory area.
The entries are sorted by inode number and stat()ed.
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.
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().
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().
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.
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().