This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

d_ino bug in //


It looks like d_ino is not being correctly populated within //.
Running the program below on snapshot 20060220 produced:

$ ./foo
Searching for //eblake, inode 10556217422951964268
entry 553: name match only (inode 14394969718775064264)
2098 entries processed
$ cat foo.c
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

#define DEFAULT_SHARE "eblake"

int main(int argc, char**argv)
{
   ino_t ino;
   struct stat sb;
   DIR *dirp;
   int i = 0;

   switch (argc)
   {
   case 1:
      argv[1] = DEFAULT_SHARE;
      break;
   case 2:
      break;
   default:
      printf("Usage: foo [sharename]\n"
             "  Search // for sharename\n");
      return 1;
   }

   if (chdir("//") < 0)
   {
      printf("chdir failed: %d %s\n", errno, strerror(errno));
      return 1;
   }
   if (lstat(argv[1], &sb) < 0)
   {
      printf("lstat failed: %d %s\n", errno, strerror(errno));
      return 1;
   }
   ino = sb.st_ino;
   printf("Searching for //%s, inode %llu\n", argv[1], ino);
   if ((dirp = opendir ("..")) == NULL)
   {
      printf("opendir failed: %d %s\n", errno, strerror(errno));
      return 1;
   }
   while (1)
   {
      struct dirent *dp;

      errno = 0;
      i++;
      if ((dp = readdir (dirp)) == NULL)
      {
         if (errno)
         {
            printf("opendir failed: %d %s\n", errno, strerror(errno));
            return 2;
         }
         else
            break;
      }
      if (ino == dp->d_ino)
      {
         if (strcasecmp(argv[1], dp->d_name) == 0)
         {
            printf("match found at entry %d\n", i);
         }
         else
         {
            printf("entry %d: inode match only (name %s)\n", i, dp->d_name);
         }
      }
      else if (strcasecmp(argv[1], dp->d_name) == 0)
      {
         printf("entry %d: name match only (inode %llu)\n", i, dp->d_ino);
      }
   }
   printf("%d entries processed\n", i);
   if (closedir (dirp) < 0)
   {
      printf("closedir failed: %d %s\n", errno, strerror(errno));
      return 1;
   }
   return 0;
}

-- 
Eric Blake


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]