summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/devices.h
blob: 97002ed2d6a627c60897c10a3d3d8e0fad08625d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* devices.h

   Copyright 2002 Red Hat, Inc.

This file is part of Cygwin.

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;

enum fh_devices
{
  /* "Slow" devices */
  FH_TTY     = FHDEV (5, 0),
  FH_CONSOLE = FHDEV (5, 1),
  FH_CONIN   = FHDEV (5, 512),
  FH_CONOUT  = FHDEV (5, 513),
  FH_PTYM    = FHDEV (5, 2),	/* /dev/ptmx */

  DEV_TTYM_MAJOR = 128,
  FH_TTYM    = FHDEV (128, 0),
  FH_TTYM_MAX= FHDEV (128, 255),

  DEV_TTYS_MAJOR = 136,
  FH_TTYS    = FHDEV (DEV_TTYS_MAJOR, 0),	/* FIXME: Should separate ttys and ptys */
  FH_TTYS_MAX= FHDEV (DEV_TTYS_MAJOR, 255),	/* FIXME: Should separate ttys and ptys */

  DEV_SERIAL_MAJOR = 117,
  FH_SERIAL  = FHDEV (117, 0),	/* /dev/ttyS? */

  FH_PIPE    = FHDEV (0, 512),
  FH_PIPER   = FHDEV (0, 513),
  FH_PIPEW   = FHDEV (0, 514),
  FH_FIFO    = FHDEV (0, 515),
  FH_SOCKET  = FHDEV (0, 516),
  FH_WINDOWS = FHDEV (13, 512),

  /* Fast devices */
  FH_FS      = FHDEV (0, 517),	/* filesystem based device */

  DEV_FLOPPY_MAJOR = 2,
  FH_FLOPPY  = FHDEV (DEV_FLOPPY_MAJOR, 0),

  DEV_CDROM_MAJOR = 11,
  FH_CDROM   = FHDEV (DEV_CDROM_MAJOR, 0),

  DEV_TAPE_MAJOR = 9,
  FH_TAPE    = FHDEV (DEV_TAPE_MAJOR, 0),
  FH_NTAPE   = FHDEV (DEV_TAPE_MAJOR, 128),
  FH_MAXNTAPE= FHDEV (DEV_TAPE_MAJOR, 255),

  DEV_SD_MAJOR = 8,
  FH_SD      = FHDEV (8, 0),

  FH_NULL    = FHDEV (1, 3),
  FH_ZERO    = FHDEV (1, 4),
  FH_PORT    = FHDEV (1, 5),
  FH_RANDOM  = FHDEV (1, 8),
  FH_URANDOM = FHDEV (1, 9),
  FH_MEM     = FHDEV (1, 1),
  FH_CLIPBOARD=FHDEV (13, 513),
  FH_OSS_DSP = FHDEV (14, 3),

  DEV_CYGDRIVE_MAJOR = 30,
  FH_CYGDRIVE= FHDEV (DEV_CYGDRIVE_MAJOR, 0),
  FH_CYGDRIVE_A= FHDEV (DEV_CYGDRIVE_MAJOR, 'a'),
  FH_CYGDRIVE_Z= FHDEV (DEV_CYGDRIVE_MAJOR, 'z'),

  FH_PROC    = FHDEV (0, 519),
  FH_REGISTRY= FHDEV (0, 520),
  FH_PROCESS = FHDEV (0, 521),

  DEV_RAWDRIVE_MAJOR = 65,
  FH_RAWDRIVE= FHDEV (DEV_RAWDRIVE_MAJOR, 0),

  FH_BAD     = 0
};

struct device
{
  const char *name;
  union
  {
    _dev_t devn;
    struct
    {
      _minor_t minor;
      _major_t major;
    };
  };
  const char *fmt;
  unsigned lower, upper;
  int adjust;
  unsigned mul;
  _devtype_t type;
  static const device *lookup (const char *, unsigned int = 0xffffffff);
  void parse (const char *);
  inline bool setunit (unsigned n)
  {
    if (mul && n > mul)
      return false;
    minor += (n + adjust) * (mul ?: 1);
    return true;
  }
  static void init ();
  inline operator int () const {return devn;}
};

extern const device *console_dev;
extern const device *piper_dev;
extern const device *pipew_dev;
extern const device *socket_dev;
extern const device *ttym_dev;
extern const device *ttys_dev;