Whamcloud - gitweb
b=2979
authorzab <zab>
Mon, 22 Mar 2004 22:29:22 +0000 (22:29 +0000)
committerzab <zab>
Mon, 22 Mar 2004 22:29:22 +0000 (22:29 +0000)
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

index e4b7828..987550c 100644 (file)
@@ -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,