summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <cgf@redhat.com>2002-12-29 06:14:13 +0000
committerChristopher Faylor <cgf@redhat.com>2002-12-29 06:14:13 +0000
commitf9b33a5c61c13d169ad09d66ad3c9909dc4b586f (patch)
treee033c0f4087598c8aa3027be7e91d81da6e966c8
parent14728874f380e2578661020eb97160ba5d4a9221 (diff)
downloadgdb-f9b33a5c61c13d169ad09d66ad3c9909dc4b586f.tar.gz
* cygwin-gperf: New file.
* Makefile.in: Use cygwin-gperf script to build devices.cc. * configure.in: Remove some comments. * configure: Regenerate. * devices.gperf: Remove max unit determination from FH_TTY. Add /dev/kmem. Add /dev/fifo. Add /dev/rawdrive. Remove specific "const device *" declarations since they are now autogenerated. (device::parse): Treat FH_TTY specially. Move logic for determining real tty device to separate function. (device::init): Reduce to nothing. (device::parse): New function taking different arguments. (device::parse): Ditto. (device::tty_to_real_device): New function. * devices.h (struct device): Define above new functions. (device::dev_on_fs): New element. (device::setfs): New function. (device::isfs): Ditto. * dtable.cc (dtable::build_fhandler): Treat FH_TTY specially. * fhandler.cc (fhandler_base::set_name): Make special determination for non-disk-resident devices. * fhandler.h (fhandler_base::isdevice): Renamed from 'is_device'. (fhandler_disk_file::isdevice): Ditto. (fhandler_base::is_auto_device): New function. (fhandler_base::is_fs_device): New function. (fhandler_tty_slave::get_unit): Declare. (fhandler_disk_file::readdir): Take special .lnk consideration for devices as well as symlinks. * fhandler_tty.cc: Use get_unit () rather than dev.minor throughout. (fhandler_tty_slave::get_unit): Define new function. * path.cc (symlink_info::major): New element. (symlink_info::major): Ditto. (symlink_info::devtype): Ditto. (path_conv::check): Handle devices detected by symlink_info::check. (win32_device_name): Eliminate special FH_TTY handling. (symlink): Move bulk of procesing to symlink_worker. (symlink_worker): New function. Handles devices. (symlink_info::parse_device): Parse info from potential device file into symlink_info elements. (symlink_info::check): If contents of .lnk file begin with a ':' then treat the file as a device file. * path.h (isdevice): Renamed from is_device. (is_auto_device): New function. (is_fs_device): Ditto. * syscalls.cc (chown_worker): Allow setting of ownership for on-disk devices. (chmod): Ditto. (mknod): Implement. * winsup.h (symlink_worker): Declare.
-rwxr-xr-xwinsup/cygwin/cygwin-gperf116
-rw-r--r--winsup/cygwin/devices.gperf84
-rw-r--r--winsup/cygwin/devices.h17
3 files changed, 183 insertions, 34 deletions
diff --git a/winsup/cygwin/cygwin-gperf b/winsup/cygwin/cygwin-gperf
new file mode 100755
index 00000000000..62dd1d1f49a
--- /dev/null
+++ b/winsup/cygwin/cygwin-gperf
@@ -0,0 +1,116 @@
+#!/usr/bin/perl
+use strict;
+sub read_devices($%);
+my $infile = shift;
+my $incfile = shift;
+open(GPERF, "gperf -c --key-positions='1-2,5-7,9-10' -r -t -C -E " .
+ "-T -L 'ANSI-C' -Hdevhash -N'device::lookup' -Z devstring " .
+ "-7 -G $infile |");
+my @lines = <GPERF>;
+my $ix = 0;
+my $i = 0;
+my $n = -1;
+my $findclose = 0;
+my $add_device = '';
+my %fh_static;
+my %fh_declare = (
+ 'cygdrive_dev' => '&cygdrive_dev_storage',
+ 'fs_dev' => '&fs_dev_storage',
+ 'proc_dev' => '&proc_dev_storage',
+ 'registry_dev' => '&registry_dev_storage',
+ 'process_dev' => '&process_dev_storage'
+);
+
+foreach (@lines) {
+ $i++;
+ s/\[(str\[[^\]]*\])\]/[(unsigned) cyg_tolower ($1)]/o and next;
+ s/static (.* )wordlist/static NO_COPY $1wordlist/o and do {
+ $findclose = 1;
+ };
+ s/([ ]*)if \(\*str.*$/$1if (strncasematch (str, s, len))/o and next;
+ $findclose and /};/o and do {
+ $_ .= "\n";
+ $_ .=<<'EOF';
+static const device cygdrive_dev_storage =
+ {"/cygdrive", FH_CYGDRIVE, "/cygdrive", 0, 0, 0, 0};
+
+static const device fs_dev_storage =
+ {"", FH_CYGDRIVE, "", 0, 0, 0, 0};
+
+static const device proc_dev_storage =
+ {"", FH_PROC, "", 0, 0, 0, 0};
+
+static const device registry_dev_storage =
+ {"", FH_REGISTRY, "", 0, 0, 0, 0};
+
+static const device process_dev_storage =
+ {"", FH_PROCESS, "", 0, 0, 0, 0};
+
+EOF
+ for my $f (sort keys %fh_declare) {
+ $_ .= "const device *$f = $fh_declare{$f};\n";
+ }
+ $_ .= "\n";
+ $_ .= read_devices($incfile, %fh_declare);
+ $findclose = 0;
+ };
+ /^(\s+)(\{".*)/ or next;
+ my $indent = $1;
+ my $rest = $2;
+ for my $f ($rest =~ /\{([^}]+)\}/g) {
+ $f eq '""' and do {
+ $ix++;
+ next;
+ };
+ my ($str, $fh) = (split(/, /, $f))[0..1];
+ if ($str !~ "/dev") {
+ $ix++;
+ } else {
+ my $what = lc(($fh =~ /FH_(.+)/o)[0]) . '_dev' ;
+ my $addon = '';
+ while (defined $fh_static{$what . $addon} &&
+ $fh_static{$what . $addon} ne $f) {
+ $addon++;
+ }
+ $what .= $addon;
+ $fh_static{$what} = $f;
+ $fh_declare{$what} = "wordlist + $ix";
+ $ix++;
+ }
+ }
+}
+
+print @lines;
+
+sub read_devices($%) {
+ my $fn = shift;
+ my %fh_declare = @_;
+ open(F, "$fn") or die "$0: couldn't open $fn - $!\n";
+ my (%dev, %fh);
+ local $_;
+ while (<F>) {
+ /^\s*DEV_([A-Z_0-9]+)_MAJOR\s*=\s*(\d+)/ and do {
+ my $a = sprintf "%08d", $2;
+ $dev{$2} = $fh_declare{lc($1) . '_dev'} . " /* \L$1 */";
+ next;
+ };
+ /^\s*FH_([A-Z_0-9]+)\s*=\s*FHDEV\s*\((\d+),\s*(\d+)\)/ and do {
+ my $a = sprintf "%08d.%08d", $2, $3;
+ $fh{$a} = $fh_declare{lc($1) . '_dev'} . " /* \L$1 */";
+ };
+ };
+ close F;
+ my $toprint = '';
+ $toprint = "const device *unit_devices[] =\n{";
+ for my $f (sort keys %dev) {
+ $toprint .= "\n $dev{$f},";
+ }
+ chop $toprint;
+ $toprint .= "\n};\n\nconst device *uniq_devices[] = \n{";
+ for my $f (sort keys %fh) {
+ $toprint .= "\n $fh{$f},";
+ }
+ chop $toprint;
+ $toprint .= "\n};\n";
+ return $toprint;
+}
diff --git a/winsup/cygwin/devices.gperf b/winsup/cygwin/devices.gperf
index b764e070e20..4dd2eb278b8 100644
--- a/winsup/cygwin/devices.gperf
+++ b/winsup/cygwin/devices.gperf
@@ -14,7 +14,7 @@ static unsigned int devhash (const char *, unsigned)
%}
struct device;
%%
-"/dev/tty", FH_TTY, "\\dev\\tty", 0, 255, 0, 0
+"/dev/tty", FH_TTY, "\\dev\\tty", 0, 0, 0, 0
"/dev/ttys", FH_TTYS, "\\dev\\tty%d", 0, 255, 0, 0
"/dev/console", FH_CONSOLE, "\\dev\\console", 0, 0, 0, 0
"/dev/ttym", FH_TTYM, "\\dev\\ttym", 0, 255, 0, 0
@@ -28,6 +28,7 @@ struct device;
"/dev/random", FH_RANDOM, "\\dev\\random", 0, 0, 0, 0
"/dev/urandom", FH_URANDOM, "\\dev\\urandom", 0, 0, 0, 0
"/dev/mem", FH_MEM, "\\dev\\mem", 0, 0, 0, 0
+"/dev/kmem", FH_KMEM, "\\dev\\mem", 0, 0, 0, 0
"/dev/clipboard", FH_CLIPBOARD, "\\dev\\clipboard", 0, 0, 0, 0
"/dev/port", FH_PORT, "\\dev\\port", 0, 0, 0, 0
"/dev/com", FH_SERIAL, "\\.\\com%d", 1, 99
@@ -35,6 +36,7 @@ struct device;
"/dev/pipe", FH_PIPE, "\\dev\\pipe", 0, 0, 0, 0
"/dev/piper", FH_PIPER, "\\dev\\piper", 0, 0, 0, 0
"/dev/pipew", FH_PIPEW, "\\dev\\pipew", 0, 0, 0, 0
+"/dev/fifo", FH_FIFO, "\\dev\\fifo", 0, 0, 0, 0
"/dev/streamsocket", FH_SOCKET, "\\dev\\socket", 0, 0, 0, 0
"/dev/tcp", FH_SOCKET, "\\dev\\socket", 0, 0, 0, 0
"/dev/udp", FH_SOCKET, "\\dev\\socket", 0, 0, 0, 0
@@ -49,6 +51,7 @@ struct device;
"\\\\.\\tape", FH_TAPE, "\\Device\\Tape%d", 0, 127, 0, 0
"\\\\.\\ntape", FH_NTAPE, "\\Device\\Tape%d", 0, 127, 128, 0
"\\\\.\\physicaldrive", FH_SD, "\\Device\\Harddisk%d\\Partition%d", 0, 224, 0, 16
+"/dev/rawdrive", FH_RAWDRIVE, "\\DosDevices\\%c:", 0, 0, 0, 0
"\\\\.\\a:", FH_RAWDRIVE, "\\DosDevices\\%c:", 0, 0, 0, 0
"\\\\.\\b:", FH_RAWDRIVE, "\\DosDevices\\%c:", 0, 0, 0, 0
"\\\\.\\c:", FH_RAWDRIVE, "\\DosDevices\\%c:", 0, 0, 0, 0
@@ -120,7 +123,7 @@ device::parse (const char *s)
if (++len < prior_len)
{
dev = lookup (s, len);
- if (!dev || !dev->upper)
+ if (!dev || (!dev->upper && ! dev->devn == FH_TTY))
dev = NULL;
else
{
@@ -135,41 +138,64 @@ device::parse (const char *s)
if (!dev || !*dev)
devn = 0;
+ else if (dev->devn == FH_TTY)
+ tty_to_real_device ();
else
{
- if (dev->devn != FH_TTY)
- *this = *dev;
- else
- {
- if (!real_tty_attached (myself))
- *this = *console_dev;
- else
- {
- unit = myself->ctty;
- *this = *ttys_dev;
- }
- }
+ *this = *dev;
if (!setunit (unit))
devn = 0;
}
}
-const device *console_dev;
-const device *piper_dev;
-const device *pipew_dev;
-const device *socket_dev;
-const device *ttym_dev;
-const device *ttys_dev;
-const device *urandom_dev;
-
void
device::init ()
{
- piper_dev = lookup ("/dev/piper", sizeof ("/dev/piper") - 1);
- pipew_dev = lookup ("/dev/pipew", sizeof ("/dev/pipew") - 1);
- console_dev = lookup ("/dev/console", sizeof ("/dev/console") - 1);
- ttym_dev = lookup ("/dev/ttym", sizeof ("/dev/ttym") - 1);
- ttys_dev = lookup ("/dev/ttys", sizeof ("/dev/ttys") - 1);
- socket_dev = lookup ("/dev/tcp", sizeof ("/dev/tcp") - 1);
- urandom_dev = lookup ("/dev/urandom", sizeof ("/dev/urandom") - 1);
+ /* nothing to do... yet */
+}
+
+void
+device::parse (_major_t major, _minor_t minor)
+{
+ _dev_t dev = FHDEV (major, 0);
+
+ devn = 0;
+
+ unsigned i;
+ for (i = 0; i < (sizeof (unit_devices) / sizeof (unit_devices[0])); i++)
+ if (unit_devices[i]->devn == dev)
+ {
+ *this = *unit_devices[i];
+ this->setunit (minor);
+ goto out;
+ }
+
+ dev = FHDEV (major, minor);
+ for (i = 0; i < (sizeof (uniq_devices) / sizeof (uniq_devices[0])); i++)
+ if (uniq_devices[i]->devn == dev)
+ {
+ *this = *uniq_devices[i];
+ break;
+ }
+
+out:
+ return;
+}
+
+void
+device::parse (_dev_t dev)
+{
+ parse (_major (dev), _minor (dev));
+}
+
+void
+device::tty_to_real_device ()
+{
+ if (!real_tty_attached (myself))
+ *this = *console_dev;
+ else
+ {
+ *this = *ttys_dev;
+ setunit (myself->ctty);
+ }
}
diff --git a/winsup/cygwin/devices.h b/winsup/cygwin/devices.h
index f3d48c9b773..d2542346aad 100644
--- a/winsup/cygwin/devices.h
+++ b/winsup/cygwin/devices.h
@@ -8,14 +8,15 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
-/* Change this if we use another size for devices */
-#define FHDEV(maj, min) ((((unsigned) (maj)) << 16) | (unsigned) (min))
-
typedef unsigned short _major_t;
typedef unsigned short _minor_t;
typedef unsigned char _devtype_t;
typedef __dev32_t _dev_t;
+#define FHDEV(maj, min) ((((unsigned) (maj)) << (sizeof (_major_t) * 8)) | (unsigned) (min))
+#define _minor(dev) ((dev) & ((1 << (sizeof (_minor_t) * 8)) - 1))
+#define _major(dev) ((dev) >> (sizeof (_major_t) * 8))
+
enum fh_devices
{
/* "Slow" devices */
@@ -26,8 +27,8 @@ enum fh_devices
FH_PTYM = FHDEV (5, 2), /* /dev/ptmx */
DEV_TTYM_MAJOR = 128,
- FH_TTYM = FHDEV (128, 0),
- FH_TTYM_MAX= FHDEV (128, 255),
+ FH_TTYM = FHDEV (DEV_TTYM_MAJOR, 0),
+ FH_TTYM_MAX= FHDEV (DEV_TTYM_MAJOR, 255),
DEV_TTYS_MAJOR = 136,
FH_TTYS = FHDEV (DEV_TTYS_MAJOR, 0), /* FIXME: Should separate ttys and ptys */
@@ -102,8 +103,11 @@ struct device
int adjust;
unsigned mul;
_devtype_t type;
+ bool dev_on_fs;
static const device *lookup (const char *, unsigned int = 0xffffffff);
void parse (const char *);
+ void parse (_major_t major, _minor_t minor);
+ void parse (_dev_t dev);
inline bool setunit (unsigned n)
{
if (mul && n > mul)
@@ -112,7 +116,10 @@ struct device
return true;
}
static void init ();
+ void tty_to_real_device ();
inline operator int () const {return devn;}
+ inline void setfs (bool x) {dev_on_fs = x;}
+ inline bool isfs () const {return dev_on_fs;}
};
extern const device *console_dev;