From eb7729eb36da9c27121d17d088860079d4c64625 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 2 Apr 2012 19:25:58 +0000 Subject: * devices.h (device::get_device): New method. * fhandler_dev.cc (fhandler_dev::readdir): Set st_ino to device number. * syscalls.cc (fhandler_base::stat_fixup): Ditto. Fix link count for CD-ROM devices. Fix typo in comment. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/devices.h | 1 + winsup/cygwin/fhandler_dev.cc | 5 ++--- winsup/cygwin/syscalls.cc | 9 +++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 5ef183e0b..9066d56f3 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2012-04-02 Corinna Vinschen + + * devices.h (device::get_device): New method. + * fhandler_dev.cc (fhandler_dev::readdir): Set st_ino to device number. + * syscalls.cc (fhandler_base::stat_fixup): Ditto. Fix link count for + CD-ROM devices. Fix typo in comment. + 2012-04-02 Corinna Vinschen * fhandler.h (fhandler_base::stat_fixup): Rename from diff --git a/winsup/cygwin/devices.h b/winsup/cygwin/devices.h index f5607f8c8..dca3e4584 100644 --- a/winsup/cygwin/devices.h +++ b/winsup/cygwin/devices.h @@ -308,6 +308,7 @@ struct device _minor_t get_minor () const {return d.minor;} _major_t get_major () const {return d.major;} + _dev_t get_device () const {return d.devn;} inline operator int& () {return d.devn_int;} inline operator fh_devices () {return d.devn_fh_devices;} diff --git a/winsup/cygwin/fhandler_dev.cc b/winsup/cygwin/fhandler_dev.cc index 44061e050..9d8750436 100644 --- a/winsup/cygwin/fhandler_dev.cc +++ b/winsup/cygwin/fhandler_dev.cc @@ -208,11 +208,10 @@ fhandler_dev::readdir (DIR *dir, dirent *de) { /* Make sure conin, conout, and console have the same inode number as the current consX. */ - dev.parse (myself->ctty); - de->d_ino = hash_path_name (0, dev.native); + de->d_ino = myself->ctty; } else - de->d_ino = hash_path_name (0, curdev->native); + de->d_ino = curdev->get_device (); de->d_type = curdev->type (); ret = 0; break; diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 81a1238dd..e70bb9772 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1591,8 +1591,10 @@ static bool dev_st_inited; void fhandler_base::stat_fixup (struct __stat64 *buf) { + /* Set inode number to device number. This gives us a valid, unique + inode number and we especially don't have to call hash_path_name. */ if (!buf->st_ino) - buf->st_ino = get_ino (); + buf->st_ino = get_device (); /* 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 @@ -1616,9 +1618,12 @@ fhandler_base::stat_fixup (struct __stat64 *buf) { buf->st_rdev = get_device (); /* consX, console, conin, and conout point to the same device. - make sure the link count is correct. */ + Make sure the link count is correct. */ if (buf->st_rdev == (dev_t) myself->ctty && iscons_dev (myself->ctty)) buf->st_nlink = 4; + /* CD-ROM drives have two links, /dev/srX and /dev/scdX. */ + else if (gnu_dev_major (buf->st_rdev) == DEV_CDROM_MAJOR) + buf->st_nlink = 2; } } -- cgit v1.2.3