From a8f99c578c89cf1164f6c4c7fa7eb136b3a28587 Mon Sep 17 00:00:00 2001 From: zab Date: Mon, 22 Mar 2004 22:29:22 +0000 Subject: [PATCH] b=2979 r=adilger Tweak lfs a little so that lfs find can use open(O_DIRECTORY) to detect directories when libc doesn't implement readdir64() in a way that returns d_type. This lets sanity hobble along on some x86-64 installations. --- lustre/utils/liblustreapi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index e4b7828..987550c 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -380,6 +380,26 @@ static int process_file(DIR *dir, char *dname, char *fname, return 0; } +/* some 64bit libcs implement readdir64() by calling sys_getdents(). the + * kernel's sys_getdents() doesn't return d_type. */ +unsigned char handle_dt_unknown(char *parent, char *entry) +{ + char path[PATH_MAX + 1]; + int fd, ret; + + ret = snprintf(path, PATH_MAX, "%s/%s", parent, entry); + if (ret >= PATH_MAX) + return DT_UNKNOWN; + + fd = open(path, O_DIRECTORY|O_RDONLY); + if (fd < 0) { + if (errno == ENOTDIR) + return DT_REG; /* kind of a lie */ + return DT_UNKNOWN; + } + close(fd); + return DT_DIR; +} static int process_dir(DIR *dir, char *dname, struct find_param *param) { @@ -416,6 +436,9 @@ static int process_dir(DIR *dir, char *dname, struct find_param *param) if (!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, "..")) continue; + if (dirp->d_type == DT_UNKNOWN) + dirp->d_type = handle_dt_unknown(dname, dirp->d_name); + switch (dirp->d_type) { case DT_UNKNOWN: err_msg("\"%s\" is UNKNOWN type %d", dirp->d_name, -- 1.8.3.1