* Makefile.in: Add YA method for generating devices.cc.

* child_info.h: YA update of another magic number.
* gendevices: New file.
* devices.in: New file.
* devices.cc: Regenerate.
* devices.shilka: Remove.
* devices.h: Correctly define device pointers.
(device): Remove now obsolete fields.
(device::native): Renamed from device::fmt.
* dtable.cc (build_fh_dev): Simplify in light of new unit parsing scheme.
(build_fh_pc): Ditto.
* path.cc (win32_device_name): Ditto.
* fhandler.h (fhandler_base::get_native_name): Reflect renaming of fmt to
native.
* fhandler_tty.cc (fhandler_tty_mster::init): Initialize slave device prior to
reporting unit.
This commit is contained in:
Christopher Faylor 2003-10-01 12:36:39 +00:00
parent 883c5345d4
commit 0e1ba88882
11 changed files with 15028 additions and 609 deletions

View File

@ -1,3 +1,23 @@
2003-09-30 Christopher Faylor <cgf@redhat.com>
* Makefile.in: Add YA method for generating devices.cc.
* child_info.h: YA update of another magic number.
* gendevices: New file.
* devices.in: New file.
* devices.cc: Regenerate.
* devices.shilka: Remove.
* devices.h: Correctly define device pointers.
(device): Remove now obsolete fields.
(device::native): Renamed from device::fmt.
* dtable.cc (build_fh_dev): Simplify in light of new unit parsing
scheme.
(build_fh_pc): Ditto.
* path.cc (win32_device_name): Ditto.
* fhandler.h (fhandler_base::get_native_name): Reflect renaming of fmt
to native.
* fhandler_tty.cc (fhandler_tty_mster::init): Initialize slave device
prior to reporting unit.
2003-09-30 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (fhandler_base::fstat): Drop FH_FLOPPY case.

View File

@ -216,6 +216,7 @@ TARGET_LIBS:=$(LIB_NAME) $(CYGWIN_START) $(GMON_START) $(LIBGMON_A) $(SUBLIBS) $
ifneq "${filter -O%,$(CFLAGS)}" ""
cygheap_CFLAGS:=-fomit-frame-pointer
devices_CFLAGS:=-fomit-frame-pointer -Os
malloc_CFLAGS:=-fomit-frame-pointer
malloc_wrapper_CFLAGS:=-fomit-frame-pointer
shared_CFLAGS:=-fomit-frame-pointer
@ -389,7 +390,7 @@ shared.o: shared_info_magic.h
$(srcdir)/qevices.cc: cygwin-gperf devices.gperf devices.h
$^ > $@
$(srcdir)/devices.cc: cygwin-shilka devices.shilka devices.h
$(srcdir)/devices.cc: gendevices devices.in devices.h
${wordlist 1,2,$^} $@
$(PWD)/libpthread.a: speclib $(LIB_NAME) pthread.o thread.o

View File

@ -29,7 +29,7 @@ enum
#define EXEC_MAGIC_SIZE sizeof(child_info)
#define CURR_CHILD_INFO_MAGIC 0x8e0899faU
#define CURR_CHILD_INFO_MAGIC 0x1e4c5751U
/* NOTE: Do not make gratuitous changes to the names or organization of the
below class. The layout is checksummed to determine compatibility between

File diff suppressed because it is too large Load Diff

View File

@ -128,10 +128,7 @@ struct device
_major_t major;
};
};
const char *fmt;
unsigned lower, upper;
int adjust;
unsigned mul;
const char *native;
_mode_t mode;
bool dev_on_fs;
static const device *lookup (const char *, unsigned int = 0xffffffff);
@ -140,9 +137,7 @@ struct device
void parse (_dev_t dev);
inline bool setunit (unsigned n)
{
if (mul && n > mul)
return false;
minor += (n + adjust) * (mul ?: 1);
minor = n;
return true;
}
static void init ();
@ -152,32 +147,21 @@ struct device
inline bool isfs () const {return dev_on_fs;}
};
extern const device dev_console_storage;
#define console_dev (&dev_console_storage)
extern const device *console_dev;
extern const device *dgram_dev;
extern const device *icmp_dev;
extern const device *stream_dev;
extern const device *tcp_dev;
extern const device *ttym_dev;
extern const device *ttys_dev;
extern const device *udp_dev;
extern const device *unix_dev;
extern const device *urandom_dev;
extern const device dev_piper_storage;
#define piper_dev (&dev_piper_storage)
extern const device dev_pipew_storage;
#define pipew_dev (&dev_pipew_storage)
extern const device dev_socket_storage;
#define socket_dev (&dev_socket_storage)
extern const device dev_ttym_storage;
#define ttym_dev (&dev_ttym_storage)
extern const device dev_ttys_storage;
#define ttys_dev (&dev_ttys_storage)
extern const device dev_urandom_storage;
#define urandom_dev (&dev_urandom_storage)
extern const device dev_tcp_storage;
#define tcp_dev (&dev_tcp_storage)
extern const device dev_udp_storage;
#define udp_dev (&dev_udp_storage)
extern const device dev_icmp_storage;
#define icmp_dev (&dev_icmp_storage)
extern const device dev_unix_storage;
#define unix_dev (&dev_unix_storage)
extern const device dev_stream_storage;
#define stream_dev (&dev_stream_storage)
extern const device dev_dgram_storage;
#define dgram_dev (&dev_dgram_storage)
extern const device dev_proc_storage;
#define proc_dev (&dev_proc_storage)
extern const device dev_cygdrive_storage;

128
winsup/cygwin/devices.in Normal file
View File

@ -0,0 +1,128 @@
%import {
#include "winsup.h"
#include <sys/types.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "devices.h"
#include "sys/cygwin.h"
#include "tty.h"
#include "pinfo.h"
typedef const device *KR_device_t;
}
%type KR_device_t
%local {
const device dev_cygdrive_storage =
{"/cygdrive", FH_CYGDRIVE, "/cygdrive"};
const device dev_fs_storage =
{"", FH_FS, ""};
const device dev_proc_storage =
{"", FH_PROC, ""};
const device dev_registry_storage =
{"", FH_REGISTRY, ""};
const device dev_piper_storage =
{"", FH_PIPER, ""};
const device dev_pipew_storage =
{"", FH_PIPEW, ""};
const device dev_bad_storage =
{":bad:", FH_BAD, ""};
%storage_here
}
%%
"/dev/inet/tcp", FH_TCP, "", tcp_dev
"/dev/inet/udp", FH_UDP, "", udp_dev
"/dev/inet/icmp", FH_ICMP, "", icmp_dev
"/dev/inet/unix", FH_UNIX, "", unix_dev
"/dev/inet/stream", FH_STREAM, "", stream_dev
"/dev/inet/dgram", FH_DGRAM, "", dgram_dev
"/dev/tty", FH_TTY, "\\dev\\tty"
"/dev/tty%(0-63)d", FHDEV(DEV_TTYS_MAJOR, {$1}), "\\dev\\tty{$1}", ttys_dev
"/dev/console", FH_CONSOLE, "\\dev\\console", console_dev
"/dev/ttym", FH_TTYM, "\\dev\\ttym", ttym_dev
"/dev/ptmx", FH_PTYM, "\\dev\\ptmx"
"/dev/windows", FH_WINDOWS, "\\dev\\windows"
"/dev/dsp", FH_OSS_DSP, "\\dev\\dsp"
"/dev/conin", FH_CONIN, "conin"
"/dev/conout", FH_CONOUT, "conout"
"/dev/null", FH_NULL, "nul"
"/dev/zero", FH_ZERO, "\\dev\\zero"
"/dev/random", FH_RANDOM, "\\dev\\random"
"/dev/urandom", FH_URANDOM, "\\dev\\urandom", urandom_dev
"/dev/mem", FH_MEM, "\\dev\\mem"
"/dev/kmem", FH_KMEM, "\\dev\\mem"
"/dev/clipboard", FH_CLIPBOARD, "\\dev\\clipboard"
"/dev/port", FH_PORT, "\\dev\\port"
"/dev/com%(0-16)d", FHDEV(DEV_SERIAL_MAJOR, {$1}), "\\.\\com{$1}"
"/dev/ttyS%(0-15)d", FHDEV(DEV_SERIAL_MAJOR, {$1 + 1}), "\\.\\com{$1 + 1}"
"/dev/pipe", FH_PIPE, "\\dev\\pipe"
"/dev/fifo", FH_FIFO, "\\dev\\fifo"
"/dev/st%(0-127)d", FHDEV(DEV_TAPE_MAJOR, {$1}), "\\Device\\Tape{$1}"
"/dev/nst%(0-127)d", FHDEV(DEV_TAPE_MAJOR, {$1 + 128}), "\\Device\\Tape{$1}"
"/dev/fd%(0-15)d", FHDEV(DEV_FLOPPY_MAJOR, {$1}), "\\Device\\Floppy{$1}"
"/dev/scd%(0-15)d", FHDEV(DEV_CDROM_MAJOR, {$1}), "\\Device\\CdRom{$1}"
"/dev/sr%(0-15)d", FHDEV(DEV_CDROM_MAJOR, {$1}), "\\Device\\CdRom{$1}"
"/dev/sd%{a-z}s", FH_SD{uc $1}, "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition0"
"/dev/sd%{a-z}s%(1-15)d", FH_SD{uc $1} | {$2}, "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition{$2 % 16}"
%other {return NULL;}
%%
void
device::parse (const char *s)
{
size_t len = strlen (s);
const device *dev = KR_find_keyword (s, len);
if (!dev)
*this = *fs_dev;
else if (dev->devn == FH_TTY)
tty_to_real_device ();
else
*this = *dev;
}
void
device::init ()
{
/* nothing to do... yet */
}
void
device::parse (_major_t major, _minor_t minor)
{
_dev_t dev = FHDEV (major, minor);
devn = 0;
for (unsigned i = 0; i < (sizeof (dev_storage) / sizeof (dev_storage[0])); i++)
if (dev_storage[i].devn == dev)
{
*this = dev_storage[i];
break;
}
if (!*this)
devn = FHDEV (major, minor);
return;
}
void
device::parse (_dev_t dev)
{
parse (_major (dev), _minor (dev));
}
void
device::tty_to_real_device ()
{
if (!real_tty_attached (myself))
*this = myself->ctty < 0 ? dev_bad_storage : *console_dev;
else
parse (DEV_TTYS_MAJOR, myself->ctty);
}

View File

@ -308,21 +308,10 @@ fhandler_base *
build_fh_dev (const device& dev, const char *unix_name)
{
path_conv pc (dev);
char *w32buf = const_cast<char *> (pc.get_win32 ());
__small_sprintf (w32buf, dev.fmt, dev.minor);
if (unix_name)
pc.set_normalized_path (unix_name);
else if (!dev.upper)
pc.set_normalized_path (dev.name);
else
{
pc.set_normalized_path (w32buf);
for (char *p = strchr (pc.normalized_path, '\\');
p;
p = strchr (p + 1, '\\'))
*p = '/';
}
pc.set_normalized_path (dev.name);
return build_fh_pc (pc);
}
@ -331,7 +320,6 @@ build_fh_pc (path_conv& pc)
{
fhandler_base *fh = NULL;
if (pc.dev.upper)
switch (pc.dev.major)
{
case DEV_TTYS_MAJOR:
@ -351,8 +339,7 @@ build_fh_pc (path_conv& pc)
case DEV_TAPE_MAJOR:
fh = cnew (fhandler_dev_tape) ();
break;
}
else
default:
switch (pc.dev)
{
case FH_CONSOLE:
@ -435,6 +422,7 @@ build_fh_pc (path_conv& pc)
}
}
}
}
if (!fh)
fh = cnew (fhandler_nodevice) ();

View File

@ -339,7 +339,7 @@ class fhandler_base
virtual int ready_for_read (int fd, DWORD howlong);
virtual const char *get_native_name ()
{
return dev ().fmt;
return dev ().native;
}
virtual bg_check_types bg_check (int) {return bg_ok;}
void clear_readahead ()

View File

@ -60,9 +60,8 @@ fhandler_tty_master::set_winsize (bool sendSIGWINCH)
int
fhandler_tty_master::init ()
{
termios_printf ("Creating master for tty%d", get_unit ());
slave = dev ();
termios_printf ("Creating master for tty%d", get_unit ());
if (init_console ())
{

141
winsup/cygwin/gendevices Executable file
View File

@ -0,0 +1,141 @@
#!/usr/bin/perl
use File::Basename;
use Cwd;
my $cwd = getcwd;
use strict;
use integer;
sub devsort;
my $input = shift;
my $output = shift;
my $base = "/tmp/" . basename($input, '.in') . '.' . $$;
my $c = $base . '.c';
my $shilka = $base . '.shilka';
open(INPUT, $input) or die "$0: couldn't open '$input' - $!\n";
my @lines = ();
my $storage_ix = -1;
my @storage = ();
my %pointers = ();
my @patterns = ();
my $patterns_ix = -1;
while (<INPUT>) {
if (/%storage_here/) {
$storage_ix = @lines;
} elsif (/^"([^"]+)",\s*(.*)$/o) {
push(@patterns, [$1, $2]);
next;
}
if (@patterns) {
for my $f (sort devsort @patterns) {
my $x = $f->[0];
my $rest = $f->[1];
my ($dev, $devrest) = ($x =~ /([^%]+)(%.*)?$/o);
push(@lines, generate($dev, $devrest, $rest, []));
}
@patterns = ();
}
push(@lines, $_);
}
close INPUT;
# @storage = sort devsort @storage;
chop $storage[$#storage];
chop $storage[$#storage];
$storage[$#storage] .= "\n";
splice(@lines, $storage_ix, 1,
"static const device dev_storage[] =\n", "{\n",
@storage, "};\n\n",
sort {$a cmp $b} values %pointers);
open(SHILKA, '>', $shilka);
print SHILKA @lines;
close SHILKA;
chdir '/tmp';
system qw'shilka -length -strip -no-definitions', $shilka;
exit $? if $?;
chdir $cwd;
unlink $shilka;
open(C, $c) or die "$0: couldn't open $c - $!\n";
@lines = <C>;
close C;
unlink $c;
splice(@lines, 0, 3);
my $ign_until_brace = 0;
for (my $i = 0; $i < @lines; $i++) {
$_ = $lines[$i];
$ign_until_brace = 1 if /(?:KR_reset|KR_output_statistics).*\)\s*$/o;
if ($ign_until_brace || /(?:#\s*line|(?:KR_reset|KR_output_statistics).*;)/) {
$ign_until_brace = 0 if $ign_until_brace && /}/o;
splice(@lines, $i, 1);
redo;
};
}
open(OUTPUT, '>', $output) or die "$0: couldn't open $output - $!\n";
print OUTPUT @lines;
close OUTPUT;
sub generate {
my $dev = shift;
my $devrest = shift;
my $rest = shift;
my $vars = shift;
my $res;
my @lines = ();
if ($devrest) {
my ($a, $low, $high, $fmt, $b) = ($devrest =~ /%([\({])([^-]+)-([^\)}]+)[\)}](.)(.*)/o);
my ($middle, $devrest0) = ($b =~ /^([^%]*)(%.*)?$/);
$fmt = "%$fmt";
my $vars_ix = @{$vars};
for my $f ($low .. $high) {
$vars->[$vars_ix] = $f;
$#{$vars} = $vars_ix;
my $dev0 = $dev . sprintf($fmt, $f) . $middle;
push(@lines, generate($dev0, $devrest0, $rest, $vars));
}
} else {
my $fh = $dev;
$fh =~ s%/%_%og;
my $shilka_id = $fh;
my $storage_str = $fh . '_storage';
$fh =~ s/^_dev_/FH_/o;
$fh = uc $fh;
$shilka_id =~ s/^_dev_//o;
$storage_str =~ s/^_dev/dev/o;
my $storage_loc = "dev_storage + " . @storage;
@lines = ('"' . $dev . '"' . " = $shilka_id {return $storage_loc;}\n");
$rest = "$fh, $rest" if $rest =~ /^"/o;
$rest = fixup($rest, $vars);
if ($rest =~ /^(.*), ([a-z_]*_dev)/) {
$pointers{$2} ||= "const device *$2 = $storage_loc;\n";
$rest = $1;
}
push(@storage, " {\"$dev\", " . $rest . "},\n");
}
return @lines;
}
sub fixup {
my $rest = shift;
my $vars = shift;
0 while $rest =~ s/{([^}]*)}/evalit($1, $vars)/eg;
return $rest;
}
sub evalit {
my $what = shift;
my $vars = shift;
$what =~ s/\$(\d+)/'$vars->[$1-1]'/g;
my $res = eval $what;
return $res;
}
sub devsort {
my $a0 = $a->[0];
my $b0 = $b->[0];
$a0 =~ s/(\D)(\d+)/"$1" . sprintf "%05d", $2/e;
$b0 =~ s/(\D)(\d+)/"$1" . sprintf "%05d", $2/e;
return $a0 cmp $b0;
}

View File

@ -899,22 +899,8 @@ static BOOL
win32_device_name (const char *src_path, char *win32_path, device& dev)
{
dev.parse (src_path);
if (dev.devn == FH_FS)
return false;
switch (dev.major)
{
case DEV_TAPE_MAJOR:
__small_sprintf (win32_path, dev.fmt, dev.minor % 128);
break;
case DEV_SD_MAJOR:
__small_sprintf (win32_path, dev.fmt, dev.minor / 16, dev.minor % 16);
break;
default:
__small_sprintf (win32_path, dev.fmt, dev.minor);
}
return true;
strcpy (win32_path, dev.native);
return dev.devn != FH_FS;
}
/* Normalize a Win32 path.