newlib-cygwin/winsup/cygwin/include/sys/dirent.h

126 lines
3.0 KiB
C
Raw Normal View History

/* Posix dirent.h for WIN32.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
/* Including this file should not require any Windows headers. */
2005-05-02 11:50:11 +08:00
#ifndef _SYS_DIRENT_H
#define _SYS_DIRENT_H
#include <sys/cdefs.h>
#include <sys/types.h>
#include <limits.h>
#define __DIRENT_VERSION 2
#ifdef __i386__
#pragma pack(push,4)
2013-04-23 17:44:36 +08:00
#endif
#define _DIRENT_HAVE_D_TYPE
struct dirent
{
2013-04-23 17:44:36 +08:00
uint32_t __d_version; /* Used internally */
ino_t d_ino;
unsigned char d_type;
unsigned char __d_unused1[3];
* autoload.cc (NtQueryDirectoryFile): Define. * dir.cc (__opendir_with_d_ino): Just call opendir. (opendir): Remove CYGWIN_VERSION_CHECK_FOR_NEEDS_D_INO handling. (readdir_worker): Only try generating d_ino if it's 0. Utilize namehash of directories fhandler. Call readdir_get_ino to generate d_ino for "..". (seekdir64): Keep dirent_set_d_ino flag. * fhandler.h (enum dirent_states): Add dirent_get_d_ino. (class fhandler_disk_file): Declare new private methods readdir_helper and readdir_9x. * fhandler_disk_file.cc (path_conv::hasgood_inode): New method to evaluate if a filesystem has reliable inode numbers. (fhandler_base::fstat_by_handle): Accomodate structure member name change from IndexNumber to FileId. (fhandler_base::fstat_helper): Call hasgood_inode here. (fhandler_disk_file::opendir): Call fhaccess only for real files. Don't append '*' to __d_dirname here, move to readdir_9x. On NT, open directory handle here. Set dirent_get_d_ino and dirent_set_d_ino flags according to wincap and filesystem. (fhandler_disk_file::readdir_helper): New method to implement readdir postprocessing only once. (readdir_get_ino_by_handle): New static function. (readdir_get_ino): New function to centralize inode number evaluation in case inode number hasn't been returned by NtQueryDirectoryFile. (fhandler_disk_file::readdir): Move old functionality to readdir_9x. Call readdir_9x when on 9x/Me. Implement NT specific readdir here. (fhandler_disk_file::readdir_9x): Move 9x specific readdir here. (fhandler_disk_file::seekdir): Accomodate new NT readdir method. (fhandler_disk_file::closedir): Ditto. (fhandler_cygdrive::fstat): Set d_ino to namehash. Add comment. (fhandler_cygdrive::opendir): Call get_namehash to prepare later correct evaluation of d_ino. (fhandler_cygdrive::readdir): Replace recursion with loop. Evaluate drive's d_ino by calling readdir_get_ino. * fhandler_proc.cc (fhandler_proc::readdir): Set dirent_saw_dot and dirent_saw_dot_dot to avoid seeing . and .. entries twice. * fhandler_process.cc (fhandler_process::readdir): Ditto. * fhandler_registry.cc (fhandler_registry::readdir): Ditto. * ntdll.h (STATUS_INVALID_PARAMETER): New define. (STATUS_INVALID_LEVEL): New define. (struct _FILE_INTERNAL_INFORMATION): Rename member IndexNumber to FileId (as in Nebbitt). * path.h (path_conv::hasgood_inode): Now implemented in fhandler_disk_file.cc. * wincap.h (wincaps::has_fileid_dirinfo): New element. * wincap.cc: Implement above element throughout. * winsup.h (readdir_get_ino): Add declaration. * include/sys/dirent.h (struct dirent): Slightly rename structure members to accomodate changes. Remove __USE_EXPENSIVE_CYGWIN_D_INO handling and declaration of __opendir_with_d_ino.
2006-01-28 05:50:42 +08:00
__uint32_t __d_internal1;
char d_name[NAME_MAX + 1];
};
#ifdef __i386__
#pragma pack(pop)
2013-04-23 17:44:36 +08:00
#endif
#define d_fileno d_ino /* BSD compatible definition */
2013-04-23 17:44:36 +08:00
#ifdef __x86_64__
#define __DIRENT_COOKIE 0xcdcd8484
#else
#define __DIRENT_COOKIE 0xdede4242
2013-04-23 17:44:36 +08:00
#endif
#ifdef __i386__
#pragma pack(push,4)
2013-04-23 17:44:36 +08:00
#endif
typedef struct __DIR
{
/* This is first to set alignment in non _COMPILING_NEWLIB case. */
unsigned long __d_cookie;
struct dirent *__d_dirent;
char *__d_dirname; /* directory name with trailing '*' */
2013-04-23 17:44:36 +08:00
__int32_t __d_position; /* used by telldir/seekdir */
int __d_fd;
2013-04-23 17:44:36 +08:00
uintptr_t __d_internal;
void *__handle;
void *__fh;
unsigned __flags;
} DIR;
#ifdef __i386__
#pragma pack(pop)
2013-04-23 17:44:36 +08:00
#endif
DIR *opendir (const char *);
DIR *fdopendir (int);
struct dirent *readdir (DIR *);
int readdir_r (DIR * __restrict, struct dirent * __restrict,
struct dirent ** __restrict);
void rewinddir (DIR *);
int closedir (DIR *);
int dirfd (DIR *);
#if __MISC_VISIBLE || __XSI_VISIBLE
#ifndef __INSIDE_CYGWIN__
long telldir (DIR *);
void seekdir (DIR *, long loc);
#endif
#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809
int scandir (const char *__dir,
struct dirent ***__namelist,
int (*select) (const struct dirent *),
int (*compar) (const struct dirent **, const struct dirent **));
int alphasort (const struct dirent **__a, const struct dirent **__b);
#endif
#if __GNU_VISIBLE
int scandirat (int __dirfd, const char *__dir, struct dirent ***__namelist,
int (*select) (const struct dirent *),
int (*compar) (const struct dirent **, const struct dirent **));
int versionsort (const struct dirent **__a, const struct dirent **__b);
#endif
#if __BSD_VISIBLE
#ifdef _DIRENT_HAVE_D_TYPE
/* File types for `d_type'. */
enum
2005-08-12 10:39:13 +08:00
{
DT_UNKNOWN = 0,
# define DT_UNKNOWN DT_UNKNOWN
2005-08-12 10:39:13 +08:00
DT_FIFO = 1,
# define DT_FIFO DT_FIFO
2005-08-12 10:39:13 +08:00
DT_CHR = 2,
# define DT_CHR DT_CHR
2005-08-12 10:39:13 +08:00
DT_DIR = 4,
# define DT_DIR DT_DIR
2005-08-12 10:39:13 +08:00
DT_BLK = 6,
# define DT_BLK DT_BLK
2005-08-12 10:39:13 +08:00
DT_REG = 8,
# define DT_REG DT_REG
2005-08-12 10:39:13 +08:00
DT_LNK = 10,
# define DT_LNK DT_LNK
2005-08-12 10:39:13 +08:00
DT_SOCK = 12,
# define DT_SOCK DT_SOCK
2005-08-12 10:39:13 +08:00
DT_WHT = 14
# define DT_WHT DT_WHT
2005-08-12 10:39:13 +08:00
};
/* Convert between stat structure types and directory types. */
2005-08-12 10:39:13 +08:00
# define IFTODT(mode) (((mode) & 0170000) >> 12)
# define DTTOIF(dirtype) ((dirtype) << 12)
#endif /* _DIRENT_HAVE_D_TYPE */
#endif /* __BSD_VISIBLE */
2005-08-12 10:39:13 +08:00
#endif /*_SYS_DIRENT_H*/