mirror of
git://sourceware.org/git/glibc.git
synced 2026-09-08 23:58:31 +08:00
This patch synchronizes the glibc fts implementation with the latest version from gnulib (as of 2026-02-16). The primary motivation is to address limitations in the legacy glibc implementation, most notably BZ 22944, where fts fails with an ENAMETOOLONG error when traversing very long paths or deeply nested directory trees. The gnulib implementation dynamically reallocates path buffers and uses openat/fchdir optimizations, effectively lifting the MAXPATHLEN limitation. The gnulib implementation also added extra features, which are used by different GNU projects (coreutils, diffutils): * FTS_TIGHT_CYCLE_CHECK: used to enable a strict, immediate cycle-detection algorithm during a file system traversal. This is done internally using a hash table: every time the traversal enters a directory, it records the directory's device and inode (dev/ino) pair in the hash table, and before entering any directory, fts checks the hash table. * FTS_CWDFD: instead of actually changing the process's current working directory, it maintains a virtual current working directory using file descriptors. The file descriptor is store at the fts_cwd_fd field and all subsequent file operations are performed relative to this file descriptor using *at functions. * FTS_DEFER_STAT: performance-oriented flag that instructs the file tree traversal engine to delay fetching file metadata. When the flag is used, fts skips the immediate stat call. Instead, it marks the entry with a special internal state (FTS_NSOK and FTS_STAT_REQUIRED). The actual stat call is pushed down the line and executed by fts_read right before the application actually accesses the entry. * FTS_VERBATIM: fts_open accept and use the path strings exactly as they were provided in the arguments array without slash trimming. * FTS_MOUNT: it restrict the file tree walk to a single file system. Hopefully,it would allow some GNU projects to use the glibc implementation instead of pulling the gnulib one. It requires some changes to keep compatibility, compared to gnulib: * The new required fields are added at the end of FTS structure, and the new FTS flags are adjusted to avoid change FTS_NAMEONLY/FTS_STOP (even though they are marked as private). * The FTSENT uses a flexible array (fts_name), so two adjustments are required: the two new members (fts_fts and fts_dirp) are place *before* the struct and the fts_statp is now always allocated and accounted (the gnulib implementation uses an alwyas allocated member). Checked on x86_64-linux-gnu and i686-linux-gnu.
60 lines
1.2 KiB
C
60 lines
1.2 KiB
C
#ifndef _FTS_H
|
|
#include <io/fts.h>
|
|
|
|
#ifndef _ISOMAC
|
|
# if __TIMESIZE != 64
|
|
# include <sys/stat.h>
|
|
|
|
typedef struct
|
|
{
|
|
struct _ftsent64_time64 *fts_cur;
|
|
struct _ftsent64_time64 *fts_child;
|
|
struct _ftsent64_time64 **fts_array;
|
|
dev_t fts_dev;
|
|
char *fts_path;
|
|
int fts_rfd;
|
|
int fts_pathlen;
|
|
int fts_nitems;
|
|
int (*fts_compar) (const void *, const void *);
|
|
int fts_options;
|
|
int fts_cwd_fd;
|
|
struct hash_table *fts_leaf_optimization_works_ht;
|
|
union {
|
|
struct hash_table *ht;
|
|
struct cycle_check_state *state;
|
|
} fts_cycle;
|
|
__I_ring fts_fd_ring;
|
|
} FTS64_TIME64;
|
|
|
|
typedef struct _ftsent64_time64
|
|
{
|
|
struct _ftsent64_time64 *fts_cycle;
|
|
struct _ftsent64_time64 *fts_parent;
|
|
struct _ftsent64_time64 *fts_link;
|
|
long fts_number;
|
|
void *fts_pointer;
|
|
char *fts_accpath;
|
|
char *fts_path;
|
|
int fts_errno;
|
|
int fts_symfd;
|
|
unsigned short fts_pathlen;
|
|
unsigned short fts_namelen;
|
|
|
|
ino64_t fts_ino;
|
|
dev_t fts_dev;
|
|
nlink_t fts_nlink;
|
|
|
|
short fts_level;
|
|
unsigned short fts_info;
|
|
unsigned short fts_flags;
|
|
unsigned short fts_instr;
|
|
|
|
struct __stat64_t64 *fts_statp;
|
|
char fts_name[1];
|
|
} FSTENT64_TIME64;
|
|
|
|
# endif
|
|
#endif
|
|
|
|
#endif /* _FTS_H */
|