newlib-cygwin/winsup/cygwin/devices.gperf

167 lines
5.0 KiB
Plaintext

%{
#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"
#undef __GNUC__
static unsigned int devhash (const char *, unsigned)
__attribute__ ((regparm (2)));
#define bad_dev (&dev_bad_storage)
%}
struct device;
%%
"/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
"/dev/ptmx", FH_PTYM, "\\dev\\ptmx", 0, 0, 0, 0
"/dev/windows", FH_WINDOWS, "\\dev\\windows", 0, 0, 0, 0
"/dev/dsp", FH_OSS_DSP, "\\dev\\dsp", 0, 0, 0, 0
"/dev/conin", FH_CONIN, "conin", 0, 0, 0, 0
"/dev/conout", FH_CONOUT, "conout", 0, 0, 0, 0
"/dev/null", FH_NULL, "nul", 0, 0, 0, 0
"/dev/zero", FH_ZERO, "\\dev\\zero", 0, 0, 0, 0
"/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
"/dev/ttyS", FH_SERIAL, "\\.\\com%d", 0, 99, -1
"/dev/pipe", FH_PIPE, "\\dev\\pipe", 0, 0, 0, 0
"/dev/fifo", FH_FIFO, "\\dev\\fifo", 0, 0, 0, 0
"/dev/st", FH_TAPE, "\\Device\\Tape%d", 0, 127
"/dev/nst", FH_NTAPE, "\\Device\\Tape%d", 0, 127
"/dev/fd", FH_FLOPPY, "\\Device\\Floppy%d", 0, 15
"/dev/scd", FH_CDROM, "\\Device\\CdRom%d", 0, 15
"/dev/sr", FH_CDROM, "\\Device\\CdRom%d", 0, 15
"/dev/hda", FH_SDA, "\\Device\\Harddisk%d\\Partition%d", 1, 16, -1
"/dev/hdb", FH_SDB, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 15
"/dev/hdc", FH_SDC, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 31
"/dev/hdd", FH_SDD, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 47
"/dev/hde", FH_SDE, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 63
"/dev/hdf", FH_SDF, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 79
"/dev/hdg", FH_SDG, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 95
"/dev/hdh", FH_SDH, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 111
"/dev/hdi", FH_SDI, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 127
"/dev/hdj", FH_SDJ, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 143
"/dev/hdk", FH_SDK, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 159
"/dev/hdl", FH_SDL, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 175
"/dev/hdm", FH_SDM, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 191
"/dev/hdn", FH_SDN, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 207
"/dev/hdo", FH_SDO, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 223
"/dev/hdp", FH_SDP, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 239
"/dev/hdq", FH_SDQ, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 255 /* FIXME 8 bit lunacy */
"/dev/hdr", FH_SDR, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 271
"/dev/hds", FH_SDS, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 287
"/dev/hdt", FH_SDT, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 303
"/dev/hdu", FH_SDU, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 319
"/dev/hdv", FH_SDV, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 335
"/dev/hdw", FH_SDW, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 351
"/dev/hdx", FH_SDX, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 367
"/dev/hdy", FH_SDY, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 383
"/dev/hdz", FH_SDZ, "\\Device\\Harddisk%d\\Partition%d", 1, 16, 399
"/dev/rawdrive", FH_RAWDRIVE, "\\DosDevices\\%c:", 0, 0, 0, 0
":bad:", FH_BAD, ":bad:", 0, 0, 0, 0
%%
void
device::parse (const char *s)
{
size_t len = strlen (s);
const device *dev = lookup (s, len);
unsigned unit = 0;
if (!dev || !*dev)
{
size_t prior_len = len;
while (len-- > 0 && isdigit (s[len]))
continue;
if (++len < prior_len)
{
dev = lookup (s, len);
if (!dev || !dev->upper)
dev = NULL;
else
{
unsigned n = atoi (s + len);
if (dev->devn == FH_TTY)
dev = ttys_dev; // SIGH
if (n >= dev->lower && n <= dev->upper)
unit = n;
}
}
}
if (!dev || !*dev)
*this = *fs_dev;
else if (dev->devn == FH_TTY)
tty_to_real_device ();
else
{
*this = *dev;
if (!setunit (unit))
devn = 0;
}
}
void
device::init ()
{
/* 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:
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 ? *bad_dev : *console_dev;
else
{
*this = *ttys_dev;
setunit (myself->ctty);
}
}