* 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.
This commit is contained in:
Corinna Vinschen 2012-03-30 09:26:45 +00:00
parent 9ae37ea0c6
commit a918afd703
3 changed files with 96 additions and 37 deletions

View File

@ -1,3 +1,11 @@
2012-03-30 Corinna Vinschen <corinna@vinschen.de>
* 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.
2012-03-29 Corinna Vinschen <corinna@vinschen.de> 2012-03-29 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Add fhandler_dev.o. * Makefile.in (DLL_OFILES): Add fhandler_dev.o.

View File

@ -23,11 +23,12 @@ typedef __dev32_t _dev_t;
#define MAX_CONSOLES 63 #define MAX_CONSOLES 63
enum fh_devices enum fh_devices
{ {
FH_TTY = FHDEV (5, 0), DEV_TTY_MAJOR = 5,
FH_CONSOLE = FHDEV (5, 1), FH_TTY = FHDEV (DEV_TTY_MAJOR, 0),
FH_PTMX = FHDEV (5, 2), FH_CONSOLE = FHDEV (DEV_TTY_MAJOR, 1),
FH_CONIN = FHDEV (5, 255), FH_PTMX = FHDEV (DEV_TTY_MAJOR, 2),
FH_CONOUT = FHDEV (5, 254), FH_CONIN = FHDEV (DEV_TTY_MAJOR, 255),
FH_CONOUT = FHDEV (DEV_TTY_MAJOR, 254),
DEV_CONS_MAJOR = 3, DEV_CONS_MAJOR = 3,
FH_CONS = FHDEV (DEV_CONS_MAJOR, 0), FH_CONS = FHDEV (DEV_CONS_MAJOR, 0),
@ -50,24 +51,25 @@ enum fh_devices
/* begin /proc directories */ /* begin /proc directories */
FH_PROC_MIN_MINOR = FHDEV (0, 200), DEV_VIRTFS_MAJOR = 0,
FH_PROCSYSVIPC = FHDEV (0, 249), FH_PROC_MIN_MINOR = FHDEV (DEV_VIRTFS_MAJOR, 200),
FH_PROCSYS = FHDEV (0, 250), FH_PROCSYSVIPC = FHDEV (DEV_VIRTFS_MAJOR, 249),
FH_PROCESSFD = FHDEV (0, 251), FH_PROCSYS = FHDEV (DEV_VIRTFS_MAJOR, 250),
FH_PROCNET = FHDEV (0, 252), FH_PROCESSFD = FHDEV (DEV_VIRTFS_MAJOR, 251),
FH_REGISTRY= FHDEV (0, 253), FH_PROCNET = FHDEV (DEV_VIRTFS_MAJOR, 252),
FH_PROCESS = FHDEV (0, 254), FH_REGISTRY= FHDEV (DEV_VIRTFS_MAJOR, 253),
FH_PROC = FHDEV (0, 255), FH_PROCESS = FHDEV (DEV_VIRTFS_MAJOR, 254),
FH_PROC_MAX_MINOR = FHDEV (0, 255), FH_PROC = FHDEV (DEV_VIRTFS_MAJOR, 255),
FH_PROC_MAX_MINOR = FHDEV (DEV_VIRTFS_MAJOR, 255),
/* end /proc directories */ /* end /proc directories */
FH_PIPE = FHDEV (0, 199), FH_PIPE = FHDEV (DEV_VIRTFS_MAJOR, 199),
FH_PIPER = FHDEV (0, 198), FH_PIPER = FHDEV (DEV_VIRTFS_MAJOR, 198),
FH_PIPEW = FHDEV (0, 197), FH_PIPEW = FHDEV (DEV_VIRTFS_MAJOR, 197),
FH_FIFO = FHDEV (0, 196), FH_FIFO = FHDEV (DEV_VIRTFS_MAJOR, 196),
FH_FS = FHDEV (0, 195), /* filesystem based device */ FH_FS = FHDEV (DEV_VIRTFS_MAJOR, 195), /* filesystem based device */
FH_NETDRIVE= FHDEV (0, 194), FH_NETDRIVE= FHDEV (DEV_VIRTFS_MAJOR, 194),
DEV_FLOPPY_MAJOR = 2, DEV_FLOPPY_MAJOR = 2,
FH_FLOPPY = FHDEV (DEV_FLOPPY_MAJOR, 0), FH_FLOPPY = FHDEV (DEV_FLOPPY_MAJOR, 0),

View File

@ -32,6 +32,7 @@ int
fhandler_dev::readdir (DIR *dir, dirent *de) fhandler_dev::readdir (DIR *dir, dirent *de)
{ {
int ret; int ret;
device dev;
if (dir_exists && !lastrealpos) 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 /* Avoid to print devices for which users have created files under
/dev already, for instance by using the old script from Igor /dev already, for instance by using the old script from Igor
Peshansky. */ Peshansky. */
device dev;
dev.name = de->d_name; dev.name = de->d_name;
if (!bsearch (&dev, ext_dev_storage, dev_storage_size, sizeof dev, if (!bsearch (&dev, ext_dev_storage, dev_storage_size, sizeof dev,
device_cmp)) device_cmp))
@ -56,36 +56,57 @@ fhandler_dev::readdir (DIR *dir, dirent *de)
idx < dev_storage_size; idx < dev_storage_size;
++idx) ++idx)
{ {
struct __stat64 st;
++dir->__d_position; ++dir->__d_position;
/* Exclude devices which are only available for internal purposes /* Exclude devices which are only available for internal purposes
and devices which are not really existing at this time. */ and devices which are not really existing at this time. */
switch (ext_dev_storage[idx].d.major) switch (ext_dev_storage[idx].d.major)
{ {
case 0: case DEV_VIRTFS_MAJOR:
if (ext_dev_storage[idx].d.minor == FH_FIFO /* Drop /dev/fifo and /dev/pipe since they are internal only. */
|| ext_dev_storage[idx].d.minor == FH_PIPE) switch (ext_dev_storage[idx].d.devn)
continue; {
case FH_FIFO:
case FH_PIPE:
continue;
}
break;
case DEV_PTYM_MAJOR: case DEV_PTYM_MAJOR:
if (ext_dev_storage[idx].d.minor /* Only /dev/ptmx is user-visible. */
|| !strcmp (ext_dev_storage[idx].name, "/dev/ptm0")) if (strcmp (ext_dev_storage[idx].name + dev_prefix_len, "ptmx"))
continue; continue;
break; break;
case DEV_PTYS_MAJOR: case DEV_PTYS_MAJOR:
/* Show only existing slave ptys. */
if (cygwin_shared->tty.connect (ext_dev_storage[idx].d.minor) if (cygwin_shared->tty.connect (ext_dev_storage[idx].d.minor)
== -1) == -1)
continue; continue;
break; break;
case DEV_CONS_MAJOR: case DEV_CONS_MAJOR:
/* Show only the one console which is our controlling tty
right now. */
if (!iscons_dev (myself->ctty) if (!iscons_dev (myself->ctty)
|| myself->ctty != ext_dev_storage[idx].d.devn_int) || myself->ctty != ext_dev_storage[idx].d.devn_int)
continue; continue;
break; 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_FLOPPY_MAJOR:
case DEV_TAPE_MAJOR: case DEV_TAPE_MAJOR:
case DEV_CDROM_MAJOR: case DEV_CDROM_MAJOR:
case DEV_SERIAL_MAJOR:
case DEV_SD_MAJOR: case DEV_SD_MAJOR:
case DEV_SD1_MAJOR: case DEV_SD1_MAJOR:
case DEV_SD2_MAJOR: case DEV_SD2_MAJOR:
@ -94,6 +115,7 @@ fhandler_dev::readdir (DIR *dir, dirent *de)
case DEV_SD5_MAJOR: case DEV_SD5_MAJOR:
case DEV_SD6_MAJOR: case DEV_SD6_MAJOR:
case DEV_SD7_MAJOR: case DEV_SD7_MAJOR:
/* Check existence of POSIX devices backed by real NT devices. */
{ {
WCHAR wpath[MAX_PATH]; WCHAR wpath[MAX_PATH];
UNICODE_STRING upath; UNICODE_STRING upath;
@ -105,8 +127,9 @@ fhandler_dev::readdir (DIR *dir, dirent *de)
RtlInitUnicodeString (&upath, wpath); RtlInitUnicodeString (&upath, wpath);
InitializeObjectAttributes (&attr, &upath, InitializeObjectAttributes (&attr, &upath,
OBJ_CASE_INSENSITIVE, NULL, NULL); OBJ_CASE_INSENSITIVE, NULL, NULL);
/* The native paths are devices, not symlinks, so we expect /* Except for the serial IO devices, the native paths are
a matching error message. */ direct device paths, not symlinks, so every status code
except for "NOT_FOUND" means the device exists. */
status = NtOpenSymbolicLinkObject (&h, SYMBOLIC_LINK_QUERY, status = NtOpenSymbolicLinkObject (&h, SYMBOLIC_LINK_QUERY,
&attr); &attr);
switch (status) switch (status)
@ -123,14 +146,40 @@ fhandler_dev::readdir (DIR *dir, dirent *de)
} }
break; 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); case DEV_FLOPPY_MAJOR:
de->d_ino = st.st_ino; case DEV_TAPE_MAJOR:
de->d_type = S_ISBLK (st.st_mode) ? DT_BLK : DT_CHR; case DEV_CDROM_MAJOR:
ret = 0; 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; break;
} }
ret = 0;
break;
} }
} }
return ret; return ret;