* devices.cc: Regenerate.

* devices.h (device::exists_func): New member function pointer,
	replacing noexpose.
	(device::expose): Remove.
	(device::exists_never): Declare.
	(device::exists_ptys): Declare.
	(device::exists_cons): Declare.
	(device::exists_console): Declare.
	(device::exists_nt_dev): Declare.
	(device::exists): Declare.
	* devices.in (dev_storage): Replace former noexpose values with
	pointers to matching exists_XXX method.
	(device::exists_never): New method.
	(device::exists_ptys): New method.
	(device::exists_cons): New method.
	(device::exists_console): New method.
	(device::exists_nt_dev): New method.
	(device::exists): New method.
	* fhandler_dev.cc (fhandler_dev::readdir): Replace call to
	device::expose with call to device::exists and drop all further
	existence filtering since it's done in device::exists now.
	* path.cc (path_conv::check): Replace call to device::expose with call
	to device::exists.
This commit is contained in:
Corinna Vinschen 2012-03-31 20:14:14 +00:00
parent 4303e52e4f
commit e2e887c5ac
6 changed files with 2842 additions and 2740 deletions

View File

@ -1,3 +1,29 @@
2012-03-31 Corinna Vinschen <corinna@vinschen.de>
* devices.cc: Regenerate.
* devices.h (device::exists_func): New member function pointer,
replacing noexpose.
(device::expose): Remove.
(device::exists_never): Declare.
(device::exists_ptys): Declare.
(device::exists_cons): Declare.
(device::exists_console): Declare.
(device::exists_nt_dev): Declare.
(device::exists): Declare.
* devices.in (dev_storage): Replace former noexpose values with
pointers to matching exists_XXX method.
(device::exists_never): New method.
(device::exists_ptys): New method.
(device::exists_cons): New method.
(device::exists_console): New method.
(device::exists_nt_dev): New method.
(device::exists): New method.
* fhandler_dev.cc (fhandler_dev::readdir): Replace call to
device::expose with call to device::exists and drop all further
existence filtering since it's done in device::exists now.
* path.cc (path_conv::check): Replace call to device::expose with call
to device::exists.
2012-03-30 Christopher Faylor <me.cygwin2012@cgf.cx>
* devices.cc: Regenerate.

File diff suppressed because it is too large Load Diff

View File

@ -275,7 +275,7 @@ struct device
};
} d;
const char *native;
bool noexpose:1;
bool (device::*exists_func)() const;
bool dev_on_fs:1;
_mode_t mode;
static const device *lookup (const char *, unsigned int = UINT32_MAX);
@ -311,7 +311,6 @@ struct device
_minor_t get_minor () const {return d.minor;}
_major_t get_major () const {return d.major;}
inline bool expose () const {return !noexpose;}
inline operator int& () {return d.devn_int;}
inline operator fh_devices () {return d.devn_fh_devices;}
inline operator bool () {return !!d.devn_int;}
@ -320,6 +319,13 @@ struct device
inline void setfs (bool x) {dev_on_fs = x;}
inline bool isfs () const {return dev_on_fs || d.devn == FH_FS;}
inline bool is_fs_special () const {return dev_on_fs && d.devn != FH_FS;}
bool exists_never () const;
bool exists_ptys () const;
bool exists_cons () const;
bool exists_console () const;
bool exists_nt_dev () const;
bool exists () const;
};
extern const device dev_storage[];

View File

@ -4,6 +4,8 @@
#include "sys/cygwin.h"
#include "tty.h"
#include "pinfo.h"
#include "shared_info.h"
#include "ntdll.h"
typedef const device *KR_device_t;
}
%type KR_device_t
@ -64,15 +66,15 @@ const device dev_error_storage =
}
%%
"/dev/tty", BRACK(FH_TTY), "/dev/tty"
"/dev/pty%(0-63)d", BRACK(FHDEV(DEV_PTYS_MAJOR, {$1})), "/dev/pty{$1}", ptys_dev
"/dev/ptym%(0-63)d", BRACK(FHDEV(DEV_PTYM_MAJOR, {$1})), "/dev/ptym{$1}", true, ptym_dev
"/dev/cons%(0-63)d", BRACK(FHDEV(DEV_CONS_MAJOR, {$1})), "/dev/cons{$1}", cons_dev
"/dev/console", BRACK(FH_CONSOLE), "/dev/console", console_dev
"/dev/pty%(0-63)d", BRACK(FHDEV(DEV_PTYS_MAJOR, {$1})), "/dev/pty{$1}", &device::exists_ptys, ptys_dev
"/dev/ptym%(0-63)d", BRACK(FHDEV(DEV_PTYM_MAJOR, {$1})), "/dev/ptym{$1}", &device::exists_never, ptym_dev
"/dev/cons%(0-63)d", BRACK(FHDEV(DEV_CONS_MAJOR, {$1})), "/dev/cons{$1}", &device::exists_cons, cons_dev
"/dev/console", BRACK(FH_CONSOLE), "/dev/console", &device::exists_console, console_dev
"/dev/ptmx", BRACK(FH_PTMX), "/dev/ptmx"
"/dev/windows", BRACK(FH_WINDOWS), "/dev/windows"
"/dev/dsp", BRACK(FH_OSS_DSP), "/dev/dsp"
"/dev/conin", BRACK(FH_CONIN), "/dev/conin"
"/dev/conout", BRACK(FH_CONOUT), "/dev/conout"
"/dev/conin", BRACK(FH_CONIN), "/dev/conin", &device::exists_console
"/dev/conout", BRACK(FH_CONOUT), "/dev/conout", &device::exists_console
"/dev/null", BRACK(FH_NULL), "\\Device\\Null"
"/dev/zero", BRACK(FH_ZERO), "/dev/zero"
"/dev/full", BRACK(FH_FULL), "/dev/full"
@ -82,25 +84,25 @@ const device dev_error_storage =
"/dev/kmem", BRACK(FH_KMEM), "/dev/mem"
"/dev/clipboard", BRACK(FH_CLIPBOARD), "/dev/clipboard"
"/dev/port", BRACK(FH_PORT), "/dev/port"
"/dev/com%(1-16)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1 - 1})), "\\??\\COM{$1}", true
"/dev/ttyS%(0-63)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1})), "\\??\\COM{$1 + 1}"
"/dev/pipe", BRACK(FH_PIPE), "/dev/pipe", true
"/dev/fifo", BRACK(FH_FIFO), "/dev/fifo", true
"/dev/st%(0-127)d", BRACK(FHDEV(DEV_TAPE_MAJOR, {$1})), "\\Device\\Tape{$1}"
"/dev/nst%(0-127)d", BRACK(FHDEV(DEV_TAPE_MAJOR, {$1 + 128})), "\\Device\\Tape{$1}"
"/dev/fd%(0-15)d", BRACK(FHDEV(DEV_FLOPPY_MAJOR, {$1})), "\\Device\\Floppy{$1}"
"/dev/scd%(0-15)d", BRACK(FHDEV(DEV_CDROM_MAJOR, {$1})), "\\Device\\CdRom{$1}"
"/dev/sr%(0-15)d", BRACK(FHDEV(DEV_CDROM_MAJOR, {$1})), "\\Device\\CdRom{$1}"
"/dev/sd%{a-z}s", BRACK(FH_SD{uc $1}), "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition0"
"/dev/sda%{a-z}s", BRACK(FH_SDA{uc $1}), "\\Device\\Harddisk{26 + ord($1) - ord('a')}\\Partition0"
"/dev/sdb%{a-z}s", BRACK(FH_SDB{uc $1}), "\\Device\\Harddisk{52 + ord($1) - ord('a')}\\Partition0"
"/dev/sdc%{a-z}s", BRACK(FH_SDC{uc $1}), "\\Device\\Harddisk{78 + ord($1) - ord('a')}\\Partition0"
"/dev/sdd%{a-x}s", BRACK(FH_SDD{uc $1}), "\\Device\\Harddisk{104 + ord($1) - ord('a')}\\Partition0"
"/dev/sd%{a-z}s%(1-15)d", BRACK(FH_SD{uc $1} | {$2}), "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition{$2 % 16}"
"/dev/sda%{a-z}s%(1-15)d", BRACK(FH_SDA{uc $1} | {$2}), "\\Device\\Harddisk{26 + ord($1) - ord('a')}\\Partition{$2 % 16}"
"/dev/sdb%{a-z}s%(1-15)d", BRACK(FH_SDB{uc $1} | {$2}), "\\Device\\Harddisk{52 + ord($1) - ord('a')}\\Partition{$2 % 16}"
"/dev/sdc%{a-z}s%(1-15)d", BRACK(FH_SDC{uc $1} | {$2}), "\\Device\\Harddisk{78 + ord($1) - ord('a')}\\Partition{$2 % 16}"
"/dev/sdd%{a-x}s%(1-15)d", BRACK(FH_SDD{uc $1} | {$2}), "\\Device\\Harddisk{104 + ord($1) - ord('a')}\\Partition{$2 % 16}"
"/dev/com%(1-16)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1 - 1})), "\\??\\COM{$1}", &device::exists_never
"/dev/ttyS%(0-63)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1})), "\\??\\COM{$1 + 1}", &device::exists_nt_dev
"/dev/pipe", BRACK(FH_PIPE), "/dev/pipe", &device::exists_never
"/dev/fifo", BRACK(FH_FIFO), "/dev/fifo", &device::exists_never
"/dev/st%(0-127)d", BRACK(FHDEV(DEV_TAPE_MAJOR, {$1})), "\\Device\\Tape{$1}", &device::exists_nt_dev
"/dev/nst%(0-127)d", BRACK(FHDEV(DEV_TAPE_MAJOR, {$1 + 128})), "\\Device\\Tape{$1}", &device::exists_nt_dev
"/dev/fd%(0-15)d", BRACK(FHDEV(DEV_FLOPPY_MAJOR, {$1})), "\\Device\\Floppy{$1}", &device::exists_nt_dev
"/dev/scd%(0-15)d", BRACK(FHDEV(DEV_CDROM_MAJOR, {$1})), "\\Device\\CdRom{$1}", &device::exists_nt_dev
"/dev/sr%(0-15)d", BRACK(FHDEV(DEV_CDROM_MAJOR, {$1})), "\\Device\\CdRom{$1}", &device::exists_nt_dev
"/dev/sd%{a-z}s", BRACK(FH_SD{uc $1}), "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition0", &device::exists_nt_dev
"/dev/sda%{a-z}s", BRACK(FH_SDA{uc $1}), "\\Device\\Harddisk{26 + ord($1) - ord('a')}\\Partition0", &device::exists_nt_dev
"/dev/sdb%{a-z}s", BRACK(FH_SDB{uc $1}), "\\Device\\Harddisk{52 + ord($1) - ord('a')}\\Partition0", &device::exists_nt_dev
"/dev/sdc%{a-z}s", BRACK(FH_SDC{uc $1}), "\\Device\\Harddisk{78 + ord($1) - ord('a')}\\Partition0", &device::exists_nt_dev
"/dev/sdd%{a-x}s", BRACK(FH_SDD{uc $1}), "\\Device\\Harddisk{104 + ord($1) - ord('a')}\\Partition0", &device::exists_nt_dev
"/dev/sd%{a-z}s%(1-15)d", BRACK(FH_SD{uc $1} | {$2}), "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition{$2 % 16}", &device::exists_nt_dev
"/dev/sda%{a-z}s%(1-15)d", BRACK(FH_SDA{uc $1} | {$2}), "\\Device\\Harddisk{26 + ord($1) - ord('a')}\\Partition{$2 % 16}", &device::exists_nt_dev
"/dev/sdb%{a-z}s%(1-15)d", BRACK(FH_SDB{uc $1} | {$2}), "\\Device\\Harddisk{52 + ord($1) - ord('a')}\\Partition{$2 % 16}", &device::exists_nt_dev
"/dev/sdc%{a-z}s%(1-15)d", BRACK(FH_SDC{uc $1} | {$2}), "\\Device\\Harddisk{78 + ord($1) - ord('a')}\\Partition{$2 % 16}", &device::exists_nt_dev
"/dev/sdd%{a-x}s%(1-15)d", BRACK(FH_SDD{uc $1} | {$2}), "\\Device\\Harddisk{104 + ord($1) - ord('a')}\\Partition{$2 % 16}", &device::exists_nt_dev
"/dev/kmsg", BRACK(FH_KMSG), "\\Device\\MailSlot\\cygwin\\dev\\kmsg"
"/dev", BRACK(FH_DEV), "/dev"
%other {return NULL;}
@ -196,3 +198,71 @@ device::parsedisk (int drive, int part)
}
parse (base, part + (drive * 16));
}
bool
device::exists_never () const
{
return false;
}
bool
device::exists_ptys () const
{
/* Only in-use ptys exist. */
return cygwin_shared->tty.connect (get_minor ()) != -1;
}
bool
device::exists_cons () const
{
/* /dev/consX only exists, if it's the current controlling tty. */
return iscons_dev (myself->ctty) && myself->ctty == d.devn_int;
}
bool
device::exists_console () const
{
/* console, conin, conout only exist if a console is our controlling tty. */
return iscons_dev (myself->ctty);
}
bool
device::exists_nt_dev () const
{
/* POSIX devices backed by real NT devices only exist if their NT device
exists. */
WCHAR wpath[MAX_PATH];
UNICODE_STRING upath;
OBJECT_ATTRIBUTES attr;
HANDLE h;
NTSTATUS status;
sys_mbstowcs (wpath, MAX_PATH, native);
RtlInitUnicodeString (&upath, wpath);
InitializeObjectAttributes (&attr, &upath,
OBJ_CASE_INSENSITIVE, NULL, NULL);
/* 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)
{
case STATUS_OBJECT_NAME_NOT_FOUND:
case STATUS_OBJECT_PATH_NOT_FOUND:
return false;
case STATUS_SUCCESS:
NtClose (h);
break;
default:
break;
}
return true;
}
bool
device::exists () const
{
if (!exists_func)
return true;
return (this->*exists_func)();
}

View File

@ -12,8 +12,6 @@ details. */
#include <stdlib.h>
#include "path.h"
#include "fhandler.h"
#include "shared_info.h"
#include "ntdll.h"
#include "dtable.h"
#include "cygheap.h"
#include "devices.h"
@ -121,79 +119,8 @@ fhandler_dev::readdir (DIR *dir, dirent *de)
while (devidx < dev_storage_end)
{
const device& thisdev = *devidx++;
if (!thisdev.expose ())
if (!thisdev.exists ())
continue;
int devn = *const_cast<device *> (&thisdev);
/* Exclude devices which are only available for internal purposes
and devices which are not really existing at this time. */
switch (thisdev.get_major ())
{
case DEV_PTYS_MAJOR:
/* Show only existing slave ptys. */
if (cygwin_shared->tty.connect (thisdev.get_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 != devn)
continue;
break;
case DEV_TTY_MAJOR:
/* Show con{in,out,sole} only if we're running in a console. */
switch (devn)
{
case FH_CONIN:
case FH_CONOUT:
case FH_CONSOLE:
if (!iscons_dev (myself->ctty))
continue;
}
break;
case DEV_SERIAL_MAJOR:
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:
/* Check existence of POSIX devices backed by real NT devices. */
{
WCHAR wpath[MAX_PATH];
UNICODE_STRING upath;
OBJECT_ATTRIBUTES attr;
HANDLE h;
NTSTATUS status;
sys_mbstowcs (wpath, MAX_PATH, thisdev.native);
RtlInitUnicodeString (&upath, wpath);
InitializeObjectAttributes (&attr, &upath,
OBJ_CASE_INSENSITIVE, NULL, NULL);
/* 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)
{
case STATUS_OBJECT_NAME_NOT_FOUND:
case STATUS_OBJECT_PATH_NOT_FOUND:
continue;
case STATUS_SUCCESS:
NtClose (h);
break;
default:
break;
}
}
break;
}
++dir->__d_position;
strcpy (de->d_name, thisdev.name + dev_prefix_len);
de->d_ino = hash_path_name (0, thisdev.native);
@ -213,15 +140,18 @@ fhandler_dev::readdir (DIR *dir, dirent *de)
de->d_type = DT_BLK;
break;
case DEV_TTY_MAJOR:
switch (devn)
{
case FH_CONIN:
case FH_CONOUT:
case FH_CONSOLE:
dev.parse (myself->ctty);
de->d_ino = hash_path_name (0, dev.native);
break;
}
{
int devn = *const_cast<device *> (&thisdev);
switch (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;

View File

@ -718,7 +718,7 @@ path_conv::check (const char *src, unsigned opt,
sym.pflags |= pflags_or;
if (!dev.expose ())
if (!dev.exists ())
{
error = ENXIO;
return;