]> sourceware.org Git - newlib-cygwin.git/commitdiff
* fhandler.h (fhandler_base::set_ino_and_dev): Declare.
authorCorinna Vinschen <corinna@vinschen.de>
Mon, 2 Apr 2012 11:18:45 +0000 (11:18 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Mon, 2 Apr 2012 11:18:45 +0000 (11:18 +0000)
* syscalls.cc (fhandler_base::set_ino_and_dev): New method to set
st_ino, st_dev, and st_rdev for devices in a single spot.
(fstat64): Call fhandler_base::set_ino_and_dev instead of setting
st_ino, st_dev, and st_rdev here.
(stat_worker): Ditto.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler.h
winsup/cygwin/syscalls.cc

index d054118a9c11b5764ca9cdbe60878aa347fe3491..56fea6bcfaaa567573bf578c02f67d80f1b81ae9 100644 (file)
@@ -1,3 +1,12 @@
+2012-04-02  Corinna Vinschen  <corinna@vinschen.de>
+
+       * fhandler.h (fhandler_base::set_ino_and_dev): Declare.
+       * syscalls.cc (fhandler_base::set_ino_and_dev): New method to set
+       st_ino, st_dev, and st_rdev for devices in a single spot.
+       (fstat64): Call fhandler_base::set_ino_and_dev instead of setting
+       st_ino, st_dev, and st_rdev here.
+       (stat_worker): Ditto.
+
 2012-04-02  Corinna Vinschen  <corinna@vinschen.de>
 
        * fhandler.h (fhandler_dev::open): Declare.
index 7fb374aa113a80a9c9651d0c9966525f57d87537..683c45dbd7ac1a61b85f0a6b06ce6e2bb04de463 100644 (file)
@@ -328,6 +328,7 @@ class fhandler_base
 # define archetype_usecount(n) _archetype_usecount (__PRETTY_FUNCTION__, __LINE__, (n))
   int close_fs () { return fhandler_base::close (); }
   virtual int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
+  void set_ino_and_dev (struct __stat64 *buf) __attribute__ ((regparm (2)));
   int __stdcall fstat_fs (struct __stat64 *buf) __attribute__ ((regparm (2)));
 private:
   int __stdcall fstat_helper (struct __stat64 *buf,
index 80d22b2326d4f0d1fbf6efa6c927e15fe9ca0c68..2ef94dae625e5e9a01c5d99fc5d86fe7002c82cd 100644 (file)
@@ -1585,6 +1585,38 @@ stat64_to_stat32 (struct __stat64 *src, struct __stat32 *dst)
   dst->st_blocks = src->st_blocks;
 }
 
+static struct __stat64 dev_st;
+static bool dev_st_inited;
+
+void
+fhandler_base::set_ino_and_dev (struct __stat64 *buf)
+{
+  if (!buf->st_ino)
+    buf->st_ino = get_ino ();
+  /* For /dev-based devices, st_dev must be set to the device number of /dev,
+     not it's own device major/minor numbers.  What we do here to speed up
+     the process is to fetch the device number of /dev only once, liberally
+     assuming that /dev doesn't change over the lifetime of a process. */
+  if (!buf->st_dev)
+    {
+      if (!strncmp (dev ().name, "/dev/", 5))
+       {
+         if (!dev_st_inited)
+           {
+             stat64 ("/dev", &dev_st);
+             dev_st_inited = true;
+           }
+         buf->st_dev = dev_st.st_dev;
+       }
+      else
+       buf->st_dev = get_device ();
+    }
+  /* Only set st_rdev if it's a device. */
+  if (!buf->st_rdev && get_major () != DEV_VIRTFS_MAJOR
+      && get_major () != DEV_CYGDRIVE_MAJOR && get_major () != DEV_DEV_MAJOR)
+    buf->st_rdev = get_device ();
+}
+
 extern "C" int
 fstat64 (int fd, struct __stat64 *buf)
 {
@@ -1598,14 +1630,7 @@ fstat64 (int fd, struct __stat64 *buf)
       memset (buf, 0, sizeof (struct __stat64));
       res = cfd->fstat (buf);
       if (!res)
-       {
-         if (!buf->st_ino)
-           buf->st_ino = cfd->get_ino ();
-         if (!buf->st_dev)
-           buf->st_dev = cfd->get_device ();
-         if (!buf->st_rdev)
-           buf->st_rdev = buf->st_dev;
-       }
+       cfd->set_ino_and_dev (buf);
     }
 
   syscall_printf ("%R = fstat(%d, %p)", res, fd, buf);
@@ -1744,14 +1769,7 @@ stat_worker (path_conv &pc, struct __stat64 *buf)
       memset (buf, 0, sizeof (*buf));
       res = fh->fstat (buf);
       if (!res)
-       {
-         if (!buf->st_ino)
-           buf->st_ino = fh->get_ino ();
-         if (!buf->st_dev)
-           buf->st_dev = fh->get_device ();
-         if (!buf->st_rdev)
-           buf->st_rdev = buf->st_dev;
-       }
+       fh->set_ino_and_dev (buf);
       delete fh;
     }
   else
This page took 0.044291 seconds and 5 git commands to generate.