diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2012-03-30 13:26:45 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2012-03-30 13:26:45 +0400 |
commit | a918afd7033d33525ed4eb4c42ba974a8d766d65 (patch) | |
tree | d5a10371d1be7aa61c1e89752f66ab1964c95f0b /winsup/cygwin/fhandler_dev.cc | |
parent | 9ae37ea0c61324f730d71739e919af70cb1900a7 (diff) |
* devices.h (DEV_TTY_MAJOR): Define, use throughout where appropriate.
(DEV_VIRTFS_MAJOR): Ditto.
* fhandler_dev.cc (fhandler_dev::readdir): Add comments. Tweak tests
for invisible devices. Don't print comX devices, only ttySX. Drop
requirement to call stat64.
Diffstat (limited to 'winsup/cygwin/fhandler_dev.cc')
-rw-r--r-- | winsup/cygwin/fhandler_dev.cc | 83 |
1 files changed, 66 insertions, 17 deletions
diff --git a/winsup/cygwin/fhandler_dev.cc b/winsup/cygwin/fhandler_dev.cc index ad39961e5..27b1ef321 100644 --- a/winsup/cygwin/fhandler_dev.cc +++ b/winsup/cygwin/fhandler_dev.cc @@ -32,6 +32,7 @@ int fhandler_dev::readdir (DIR *dir, dirent *de) { int ret; + device dev; if (dir_exists && !lastrealpos) { @@ -40,7 +41,6 @@ fhandler_dev::readdir (DIR *dir, dirent *de) /* Avoid to print devices for which users have created files under /dev already, for instance by using the old script from Igor Peshansky. */ - device dev; dev.name = de->d_name; if (!bsearch (&dev, ext_dev_storage, dev_storage_size, sizeof dev, device_cmp)) @@ -56,36 +56,57 @@ fhandler_dev::readdir (DIR *dir, dirent *de) idx < dev_storage_size; ++idx) { - struct __stat64 st; - ++dir->__d_position; /* Exclude devices which are only available for internal purposes and devices which are not really existing at this time. */ switch (ext_dev_storage[idx].d.major) { - case 0: - if (ext_dev_storage[idx].d.minor == FH_FIFO - || ext_dev_storage[idx].d.minor == FH_PIPE) - continue; + case DEV_VIRTFS_MAJOR: + /* Drop /dev/fifo and /dev/pipe since they are internal only. */ + switch (ext_dev_storage[idx].d.devn) + { + case FH_FIFO: + case FH_PIPE: + continue; + } + break; case DEV_PTYM_MAJOR: - if (ext_dev_storage[idx].d.minor - || !strcmp (ext_dev_storage[idx].name, "/dev/ptm0")) + /* Only /dev/ptmx is user-visible. */ + if (strcmp (ext_dev_storage[idx].name + dev_prefix_len, "ptmx")) continue; break; case DEV_PTYS_MAJOR: + /* Show only existing slave ptys. */ if (cygwin_shared->tty.connect (ext_dev_storage[idx].d.minor) == -1) continue; break; case DEV_CONS_MAJOR: + /* Show only the one console which is our controlling tty + right now. */ if (!iscons_dev (myself->ctty) || myself->ctty != ext_dev_storage[idx].d.devn_int) continue; break; + case DEV_TTY_MAJOR: + /* Show con{in,out,sole} only if we're running in a console. */ + switch (ext_dev_storage[idx].d.devn) + { + case FH_CONIN: + case FH_CONOUT: + case FH_CONSOLE: + if (!iscons_dev (myself->ctty)) + continue; + } + break; + case DEV_SERIAL_MAJOR: + /* Ignore comX devices, only print ttySx. */ + if (ext_dev_storage[idx].name[dev_prefix_len] == 'c') + continue; + /*FALLTHRU*/ case DEV_FLOPPY_MAJOR: case DEV_TAPE_MAJOR: case DEV_CDROM_MAJOR: - case DEV_SERIAL_MAJOR: case DEV_SD_MAJOR: case DEV_SD1_MAJOR: case DEV_SD2_MAJOR: @@ -94,6 +115,7 @@ fhandler_dev::readdir (DIR *dir, dirent *de) case DEV_SD5_MAJOR: case DEV_SD6_MAJOR: case DEV_SD7_MAJOR: + /* Check existence of POSIX devices backed by real NT devices. */ { WCHAR wpath[MAX_PATH]; UNICODE_STRING upath; @@ -105,8 +127,9 @@ fhandler_dev::readdir (DIR *dir, dirent *de) RtlInitUnicodeString (&upath, wpath); InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, NULL, NULL); - /* The native paths are devices, not symlinks, so we expect - a matching error message. */ + /* Except for the serial IO devices, the native paths are + direct device paths, not symlinks, so every status code + except for "NOT_FOUND" means the device exists. */ status = NtOpenSymbolicLinkObject (&h, SYMBOLIC_LINK_QUERY, &attr); switch (status) @@ -123,14 +146,40 @@ fhandler_dev::readdir (DIR *dir, dirent *de) } break; } - if (!lstat64 (ext_dev_storage[idx].name, &st)) + strcpy (de->d_name, ext_dev_storage[idx].name + dev_prefix_len); + de->d_ino = hash_path_name (0, ext_dev_storage[idx].native); + switch (ext_dev_storage[idx].d.major) { - strcpy (de->d_name, ext_dev_storage[idx].name + dev_prefix_len); - de->d_ino = st.st_ino; - de->d_type = S_ISBLK (st.st_mode) ? DT_BLK : DT_CHR; - ret = 0; + case DEV_FLOPPY_MAJOR: + case DEV_TAPE_MAJOR: + case DEV_CDROM_MAJOR: + case DEV_SD_MAJOR: + case DEV_SD1_MAJOR: + case DEV_SD2_MAJOR: + case DEV_SD3_MAJOR: + case DEV_SD4_MAJOR: + case DEV_SD5_MAJOR: + case DEV_SD6_MAJOR: + case DEV_SD7_MAJOR: + de->d_type = DT_BLK; + break; + case DEV_TTY_MAJOR: + switch (ext_dev_storage[idx].d.devn) + { + case FH_CONIN: + case FH_CONOUT: + case FH_CONSOLE: + dev.parse (myself->ctty); + de->d_ino = hash_path_name (0, dev.native); + break; + } + /*FALLTHRU*/ + default: + de->d_type = DT_CHR; break; } + ret = 0; + break; } } return ret; |