Cygwin: cygtls: rename sig to current_sig
[newlib-cygwin.git] / winsup / cygwin / local_includes / devices.h
blobc4f06127418c420ecac35bc650d242d091d9a642
1 /* devices.h
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
9 #pragma once
11 typedef unsigned short _major_t;
12 typedef unsigned short _minor_t;
14 #define FHDEV(maj, min) ((((unsigned) (maj)) << (sizeof (_major_t) * 8)) | (unsigned) (min))
15 #define _minor(dev) ((dev) & ((1 << (sizeof (_minor_t) * 8)) - 1))
16 #define _major(dev) ((dev) >> (sizeof (_major_t) * 8))
18 #include <dirent.h>
19 #include "cygheap_malloc.h"
21 enum fh_devices
23 DEV_TTY_MAJOR = 5,
24 FH_TTY = FHDEV (DEV_TTY_MAJOR, 0),
25 FH_CONSOLE = FHDEV (DEV_TTY_MAJOR, 1),
26 FH_PTMX = FHDEV (DEV_TTY_MAJOR, 2),
27 FH_CONIN = FHDEV (DEV_TTY_MAJOR, 255),
28 FH_CONOUT = FHDEV (DEV_TTY_MAJOR, 254),
30 DEV_CONS_MAJOR = 3,
31 FH_CONS = FHDEV (DEV_CONS_MAJOR, 0),
32 FH_CONS_MAX = FHDEV (DEV_CONS_MAJOR, 127),
34 DEV_PTYM_MAJOR = 128,
35 FH_PTYM = FHDEV (DEV_PTYM_MAJOR, 0),
36 FH_PTYM_MAX= FHDEV (DEV_PTYM_MAJOR, 255),
38 DEV_PTYS_MAJOR = 136,
39 FH_PTYS = FHDEV (DEV_PTYS_MAJOR, 0), /* FIXME: Should separate ttys and ptys */
40 FH_PTYS_MAX= FHDEV (DEV_PTYS_MAJOR, 255), /* FIXME: Should separate ttys and ptys */
42 DEV_SERIAL_MAJOR = 117,
43 FH_SERIAL = FHDEV (117, 0), /* /dev/ttyS? */
45 DEV_MISC_MAJOR = 13,
46 FH_WINDOWS = FHDEV (DEV_MISC_MAJOR, 255),
47 FH_CLIPBOARD=FHDEV (DEV_MISC_MAJOR, 254),
49 /* begin /proc directories */
51 DEV_VIRTFS_MAJOR = 0,
52 FH_PROC_MIN_MINOR = FHDEV (DEV_VIRTFS_MAJOR, 200),
53 FH_PROCSYSVIPC = FHDEV (DEV_VIRTFS_MAJOR, 249),
54 FH_PROCSYS = FHDEV (DEV_VIRTFS_MAJOR, 250),
55 FH_PROCESSFD = FHDEV (DEV_VIRTFS_MAJOR, 251),
56 FH_PROCNET = FHDEV (DEV_VIRTFS_MAJOR, 252),
57 FH_REGISTRY= FHDEV (DEV_VIRTFS_MAJOR, 253),
58 FH_PROCESS = FHDEV (DEV_VIRTFS_MAJOR, 254),
59 FH_PROC = FHDEV (DEV_VIRTFS_MAJOR, 255),
60 FH_PROC_MAX_MINOR = FHDEV (DEV_VIRTFS_MAJOR, 255),
62 /* end /proc directories */
64 FH_PIPE = FHDEV (DEV_VIRTFS_MAJOR, 199),
65 FH_PIPER = FHDEV (DEV_VIRTFS_MAJOR, 198),
66 FH_PIPEW = FHDEV (DEV_VIRTFS_MAJOR, 197),
67 FH_FIFO = FHDEV (DEV_VIRTFS_MAJOR, 196),
68 FH_FS = FHDEV (DEV_VIRTFS_MAJOR, 195), /* filesystem based device */
69 FH_NETDRIVE= FHDEV (DEV_VIRTFS_MAJOR, 194),
70 FH_DEV = FHDEV (DEV_VIRTFS_MAJOR, 193),
71 FH_CYGDRIVE= FHDEV (DEV_VIRTFS_MAJOR, 192),
72 FH_DEV_FD = FHDEV (DEV_VIRTFS_MAJOR, 191),
73 FH_DEV_DISK= FHDEV (DEV_VIRTFS_MAJOR, 190),
75 FH_SIGNALFD= FHDEV (DEV_VIRTFS_MAJOR, 13),
76 FH_TIMERFD = FHDEV (DEV_VIRTFS_MAJOR, 14),
77 FH_MQUEUE = FHDEV (DEV_VIRTFS_MAJOR, 15),
79 DEV_FLOPPY_MAJOR = 2,
80 FH_FLOPPY = FHDEV (DEV_FLOPPY_MAJOR, 0),
82 DEV_CDROM_MAJOR = 11,
83 FH_CDROM = FHDEV (DEV_CDROM_MAJOR, 0),
85 DEV_TAPE_MAJOR = 9,
86 FH_TAPE = FHDEV (DEV_TAPE_MAJOR, 0),
87 FH_NTAPE = FHDEV (DEV_TAPE_MAJOR, 128),
88 FH_MAXNTAPE= FHDEV (DEV_TAPE_MAJOR, 255),
90 DEV_SD_MAJOR = 8,
91 DEV_SD1_MAJOR = 65,
92 DEV_SD2_MAJOR = 66,
93 DEV_SD3_MAJOR = 67,
94 DEV_SD4_MAJOR = 68,
95 DEV_SD5_MAJOR = 69,
96 DEV_SD6_MAJOR = 70,
97 DEV_SD7_MAJOR = 71,
98 DEV_SD_HIGHPART_START = 259, /* partition # > 15 */
99 DEV_SD_HIGHPART_END = 284,
100 FH_SD = FHDEV (DEV_SD_MAJOR, 0),
101 FH_SD1 = FHDEV (DEV_SD1_MAJOR, 0),
102 FH_SD2 = FHDEV (DEV_SD2_MAJOR, 0),
103 FH_SD3 = FHDEV (DEV_SD3_MAJOR, 0),
104 FH_SD4 = FHDEV (DEV_SD4_MAJOR, 0),
105 FH_SD5 = FHDEV (DEV_SD5_MAJOR, 0),
106 FH_SD6 = FHDEV (DEV_SD6_MAJOR, 0),
107 FH_SD7 = FHDEV (DEV_SD7_MAJOR, 0),
108 FH_SDA = FHDEV (DEV_SD_MAJOR, 0),
109 FH_SDB = FHDEV (DEV_SD_MAJOR, 16),
110 FH_SDC = FHDEV (DEV_SD_MAJOR, 32),
111 FH_SDD = FHDEV (DEV_SD_MAJOR, 48),
112 FH_SDE = FHDEV (DEV_SD_MAJOR, 64),
113 FH_SDF = FHDEV (DEV_SD_MAJOR, 80),
114 FH_SDG = FHDEV (DEV_SD_MAJOR, 96),
115 FH_SDH = FHDEV (DEV_SD_MAJOR, 112),
116 FH_SDI = FHDEV (DEV_SD_MAJOR, 128),
117 FH_SDJ = FHDEV (DEV_SD_MAJOR, 144),
118 FH_SDK = FHDEV (DEV_SD_MAJOR, 160),
119 FH_SDL = FHDEV (DEV_SD_MAJOR, 176),
120 FH_SDM = FHDEV (DEV_SD_MAJOR, 192),
121 FH_SDN = FHDEV (DEV_SD_MAJOR, 208),
122 FH_SDO = FHDEV (DEV_SD_MAJOR, 224),
123 FH_SDP = FHDEV (DEV_SD_MAJOR, 240),
124 FH_SDQ = FHDEV (DEV_SD1_MAJOR, 0),
125 FH_SDR = FHDEV (DEV_SD1_MAJOR, 16),
126 FH_SDS = FHDEV (DEV_SD1_MAJOR, 32),
127 FH_SDT = FHDEV (DEV_SD1_MAJOR, 48),
128 FH_SDU = FHDEV (DEV_SD1_MAJOR, 64),
129 FH_SDV = FHDEV (DEV_SD1_MAJOR, 80),
130 FH_SDW = FHDEV (DEV_SD1_MAJOR, 96),
131 FH_SDX = FHDEV (DEV_SD1_MAJOR, 112),
132 FH_SDY = FHDEV (DEV_SD1_MAJOR, 128),
133 FH_SDZ = FHDEV (DEV_SD1_MAJOR, 144),
134 FH_SDAA = FHDEV (DEV_SD1_MAJOR, 160),
135 FH_SDAB = FHDEV (DEV_SD1_MAJOR, 176),
136 FH_SDAC = FHDEV (DEV_SD1_MAJOR, 192),
137 FH_SDAD = FHDEV (DEV_SD1_MAJOR, 208),
138 FH_SDAE = FHDEV (DEV_SD1_MAJOR, 224),
139 FH_SDAF = FHDEV (DEV_SD1_MAJOR, 240),
140 FH_SDAG = FHDEV (DEV_SD2_MAJOR, 0),
141 FH_SDAH = FHDEV (DEV_SD2_MAJOR, 16),
142 FH_SDAI = FHDEV (DEV_SD2_MAJOR, 32),
143 FH_SDAJ = FHDEV (DEV_SD2_MAJOR, 48),
144 FH_SDAK = FHDEV (DEV_SD2_MAJOR, 64),
145 FH_SDAL = FHDEV (DEV_SD2_MAJOR, 80),
146 FH_SDAM = FHDEV (DEV_SD2_MAJOR, 96),
147 FH_SDAN = FHDEV (DEV_SD2_MAJOR, 112),
148 FH_SDAO = FHDEV (DEV_SD2_MAJOR, 128),
149 FH_SDAP = FHDEV (DEV_SD2_MAJOR, 144),
150 FH_SDAQ = FHDEV (DEV_SD2_MAJOR, 160),
151 FH_SDAR = FHDEV (DEV_SD2_MAJOR, 176),
152 FH_SDAS = FHDEV (DEV_SD2_MAJOR, 192),
153 FH_SDAT = FHDEV (DEV_SD2_MAJOR, 208),
154 FH_SDAU = FHDEV (DEV_SD2_MAJOR, 224),
155 FH_SDAV = FHDEV (DEV_SD2_MAJOR, 240),
156 FH_SDAW = FHDEV (DEV_SD3_MAJOR, 0),
157 FH_SDAX = FHDEV (DEV_SD3_MAJOR, 16),
158 FH_SDAY = FHDEV (DEV_SD3_MAJOR, 32),
159 FH_SDAZ = FHDEV (DEV_SD3_MAJOR, 48),
160 FH_SDBA = FHDEV (DEV_SD3_MAJOR, 64),
161 FH_SDBB = FHDEV (DEV_SD3_MAJOR, 80),
162 FH_SDBC = FHDEV (DEV_SD3_MAJOR, 96),
163 FH_SDBD = FHDEV (DEV_SD3_MAJOR, 112),
164 FH_SDBE = FHDEV (DEV_SD3_MAJOR, 128),
165 FH_SDBF = FHDEV (DEV_SD3_MAJOR, 144),
166 FH_SDBG = FHDEV (DEV_SD3_MAJOR, 160),
167 FH_SDBH = FHDEV (DEV_SD3_MAJOR, 176),
168 FH_SDBI = FHDEV (DEV_SD3_MAJOR, 192),
169 FH_SDBJ = FHDEV (DEV_SD3_MAJOR, 208),
170 FH_SDBK = FHDEV (DEV_SD3_MAJOR, 224),
171 FH_SDBL = FHDEV (DEV_SD3_MAJOR, 240),
172 FH_SDBM = FHDEV (DEV_SD4_MAJOR, 0),
173 FH_SDBN = FHDEV (DEV_SD4_MAJOR, 16),
174 FH_SDBO = FHDEV (DEV_SD4_MAJOR, 32),
175 FH_SDBP = FHDEV (DEV_SD4_MAJOR, 48),
176 FH_SDBQ = FHDEV (DEV_SD4_MAJOR, 64),
177 FH_SDBR = FHDEV (DEV_SD4_MAJOR, 80),
178 FH_SDBS = FHDEV (DEV_SD4_MAJOR, 96),
179 FH_SDBT = FHDEV (DEV_SD4_MAJOR, 112),
180 FH_SDBU = FHDEV (DEV_SD4_MAJOR, 128),
181 FH_SDBV = FHDEV (DEV_SD4_MAJOR, 144),
182 FH_SDBW = FHDEV (DEV_SD4_MAJOR, 160),
183 FH_SDBX = FHDEV (DEV_SD4_MAJOR, 176),
184 FH_SDBY = FHDEV (DEV_SD4_MAJOR, 192),
185 FH_SDBZ = FHDEV (DEV_SD4_MAJOR, 208),
186 FH_SDCA = FHDEV (DEV_SD4_MAJOR, 224),
187 FH_SDCB = FHDEV (DEV_SD4_MAJOR, 240),
188 FH_SDCC = FHDEV (DEV_SD5_MAJOR, 0),
189 FH_SDCD = FHDEV (DEV_SD5_MAJOR, 16),
190 FH_SDCE = FHDEV (DEV_SD5_MAJOR, 32),
191 FH_SDCF = FHDEV (DEV_SD5_MAJOR, 48),
192 FH_SDCG = FHDEV (DEV_SD5_MAJOR, 64),
193 FH_SDCH = FHDEV (DEV_SD5_MAJOR, 80),
194 FH_SDCI = FHDEV (DEV_SD5_MAJOR, 96),
195 FH_SDCJ = FHDEV (DEV_SD5_MAJOR, 112),
196 FH_SDCK = FHDEV (DEV_SD5_MAJOR, 128),
197 FH_SDCL = FHDEV (DEV_SD5_MAJOR, 144),
198 FH_SDCM = FHDEV (DEV_SD5_MAJOR, 160),
199 FH_SDCN = FHDEV (DEV_SD5_MAJOR, 176),
200 FH_SDCO = FHDEV (DEV_SD5_MAJOR, 192),
201 FH_SDCP = FHDEV (DEV_SD5_MAJOR, 208),
202 FH_SDCQ = FHDEV (DEV_SD5_MAJOR, 224),
203 FH_SDCR = FHDEV (DEV_SD5_MAJOR, 240),
204 FH_SDCS = FHDEV (DEV_SD6_MAJOR, 0),
205 FH_SDCT = FHDEV (DEV_SD6_MAJOR, 16),
206 FH_SDCU = FHDEV (DEV_SD6_MAJOR, 32),
207 FH_SDCV = FHDEV (DEV_SD6_MAJOR, 48),
208 FH_SDCW = FHDEV (DEV_SD6_MAJOR, 64),
209 FH_SDCX = FHDEV (DEV_SD6_MAJOR, 80),
210 FH_SDCY = FHDEV (DEV_SD6_MAJOR, 96),
211 FH_SDCZ = FHDEV (DEV_SD6_MAJOR, 112),
212 FH_SDDA = FHDEV (DEV_SD6_MAJOR, 128),
213 FH_SDDB = FHDEV (DEV_SD6_MAJOR, 144),
214 FH_SDDC = FHDEV (DEV_SD6_MAJOR, 160),
215 FH_SDDD = FHDEV (DEV_SD6_MAJOR, 176),
216 FH_SDDE = FHDEV (DEV_SD6_MAJOR, 192),
217 FH_SDDF = FHDEV (DEV_SD6_MAJOR, 208),
218 FH_SDDG = FHDEV (DEV_SD6_MAJOR, 224),
219 FH_SDDH = FHDEV (DEV_SD6_MAJOR, 240),
220 FH_SDDI = FHDEV (DEV_SD7_MAJOR, 0),
221 FH_SDDJ = FHDEV (DEV_SD7_MAJOR, 16),
222 FH_SDDK = FHDEV (DEV_SD7_MAJOR, 32),
223 FH_SDDL = FHDEV (DEV_SD7_MAJOR, 48),
224 FH_SDDM = FHDEV (DEV_SD7_MAJOR, 64),
225 FH_SDDN = FHDEV (DEV_SD7_MAJOR, 80),
226 FH_SDDO = FHDEV (DEV_SD7_MAJOR, 96),
227 FH_SDDP = FHDEV (DEV_SD7_MAJOR, 112),
228 FH_SDDQ = FHDEV (DEV_SD7_MAJOR, 128),
229 FH_SDDR = FHDEV (DEV_SD7_MAJOR, 144),
230 FH_SDDS = FHDEV (DEV_SD7_MAJOR, 160),
231 FH_SDDT = FHDEV (DEV_SD7_MAJOR, 176),
232 FH_SDDU = FHDEV (DEV_SD7_MAJOR, 192),
233 FH_SDDV = FHDEV (DEV_SD7_MAJOR, 208),
234 FH_SDDW = FHDEV (DEV_SD7_MAJOR, 224),
235 FH_SDDX = FHDEV (DEV_SD7_MAJOR, 240),
237 DEV_MEM_MAJOR = 1,
238 FH_NULL = FHDEV (DEV_MEM_MAJOR, 3),
239 FH_ZERO = FHDEV (DEV_MEM_MAJOR, 5),
240 FH_FULL = FHDEV (DEV_MEM_MAJOR, 7),
241 FH_RANDOM = FHDEV (DEV_MEM_MAJOR, 8),
242 FH_URANDOM = FHDEV (DEV_MEM_MAJOR, 9),
244 DEV_SOUND_MAJOR = 14,
245 FH_OSS_MIXER = FHDEV (DEV_SOUND_MAJOR, 0),
246 FH_OSS_DSP = FHDEV (DEV_SOUND_MAJOR, 3),
248 DEV_SOCK_MAJOR = 30,
249 FH_SOCKET = FHDEV (DEV_SOCK_MAJOR, 0),
250 FH_INET = FHDEV (DEV_SOCK_MAJOR, 36),
251 FH_UNIX = FHDEV (DEV_SOCK_MAJOR, 42),
252 FH_LOCAL = FHDEV (DEV_SOCK_MAJOR, 120),
254 FH_NADA = FHDEV (0, 0),
255 FH_ERROR = FHDEV (255, 255) /* Set by fh constructor when error detected */
258 /* struct _device is required to allow the code in devices.cc autogenerated
259 from devices.in continuing to work, even with a proper class device.
260 We need to keep up with this as long as we use shilka to build a device
261 table.
263 Do not add members to device. Always add it to _device. */
265 class device;
267 struct _device
269 const char *_name;
270 union __cygwin_dev
272 dev_t devn;
273 fh_devices devn_fh_devices;
274 struct
276 _minor_t minor;
277 _major_t major;
279 } d;
280 const char *_native;
281 int (*exists_func) (const device&);
282 __mode_t _mode;
283 bool lives_in_dev;
284 bool dev_on_fs;
285 bool name_allocated;
286 bool native_allocated;
289 class device : private _device
291 void parsedisk (int, int);
292 void name (const char *n, bool a)
294 _name = (!(name_allocated = a)) ? n : cstrdup (n);
296 void native (const char *n, bool a)
298 _native = (!(native_allocated = a)) ? n : cstrdup (n);
301 public:
302 device () { memset (this, 0, sizeof *this); }
303 device (int drive, int part)
305 memset (this, 0, sizeof *this);
306 parsedisk (drive, part);
308 ~device ()
310 if (name_allocated)
311 cfree ((void *) _name);
312 if (native_allocated)
313 cfree ((void *) _native);
316 const char *name () const { return _name; }
317 const char *native () const { return _native; }
318 __mode_t mode () const { return _mode; }
319 void mode (__mode_t m) { _mode = m; }
321 void name (const char *n) { name (n, false); }
322 void native (const char *n) { native (n, false); }
323 void dup ()
325 name (_name, name_allocated);
326 native (_native, native_allocated);
329 void parse (const char *);
330 void parse (_major_t major, _minor_t minor);
331 void parse (dev_t dev);
332 inline bool setunit (unsigned n)
334 d.minor = n;
335 return true;
337 static void init ();
339 static _major_t major (dev_t n)
341 __cygwin_dev d;
342 d.devn = n;
343 return d.major;
345 static _minor_t minor (dev_t n)
347 __cygwin_dev d;
348 d.devn = n;
349 return d.minor;
351 static _major_t major (int n) {return major ((dev_t) n);}
352 static _minor_t minor (int n) {return minor ((dev_t) n);}
354 bool is_device (dev_t n) const {return n == d.devn; }
355 bool not_device (dev_t n) const {return d.devn && n != d.devn; }
357 _minor_t get_minor () const {return d.minor;}
358 _major_t get_major () const {return d.major;}
359 dev_t get_device () const {return d.devn;}
361 inline operator fh_devices () {return d.devn_fh_devices;}
362 inline operator bool () {return !!d.devn;}
363 inline operator dev_t& () {return d.devn;}
364 device &operator = (_device _d)
366 memcpy (this, &_d, sizeof _d);
367 dev_on_fs = name_allocated = native_allocated = false;
368 return *this;
370 device &operator = (device &_d)
372 memcpy (this, &_d, sizeof _d);
373 name (_d.name (), _d.name_allocated);
374 native (_d.native (), _d.native_allocated);
375 return *this;
377 fh_devices operator = (fh_devices n) {return d.devn_fh_devices = n;}
378 inline void setfs (bool x) {dev_on_fs = x;}
379 inline bool isfs () const {return dev_on_fs || d.devn == FH_FS;}
380 inline bool is_fs_special () const {return dev_on_fs && d.devn != FH_FS;}
381 inline bool is_dev_resident () const {return lives_in_dev;}
382 inline int exists () const {return exists_func (*this);}
383 unsigned char type () const
385 return IFTODT (_mode);
389 extern const _device dev_storage[];
390 extern const _device *dev_storage_end;
392 extern const _device *console_dev;
393 extern const _device *ptmx_dev;
394 extern const _device *ptys_dev;
395 extern const _device *urandom_dev;
397 extern const _device dev_socket_storage;
398 #define socket_dev ((device *) &dev_socket_storage)
399 extern const _device dev_af_inet_storage;
400 #define af_inet_dev ((device *) &dev_af_inet_storage)
401 extern const _device dev_af_local_storage;
402 #define af_local_dev ((device *) &dev_af_local_storage)
403 extern const _device dev_af_unix_storage;
404 #define af_unix_dev ((device *) &dev_af_unix_storage)
406 extern const _device dev_signalfd_storage;
407 #define signalfd_dev ((device *) &dev_signalfd_storage)
408 extern const _device dev_timerfd_storage;
409 #define timerfd_dev ((device *) &dev_timerfd_storage)
410 extern const _device dev_mqueue_storage;
411 #define mqueue_dev ((device *) &dev_mqueue_storage)
412 extern const _device dev_piper_storage;
413 #define piper_dev ((device *) &dev_piper_storage)
414 extern const _device dev_pipew_storage;
415 #define pipew_dev ((device *) &dev_pipew_storage)
416 extern const _device dev_dev_disk_storage;
417 #define dev_disk_dev ((device *) &dev_dev_disk_storage)
418 extern const _device dev_proc_storage;
419 #define proc_dev ((device *) &dev_proc_storage)
420 extern const _device dev_dev_storage;
421 #define dev_dev ((device *) &dev_dev_storage)
422 extern const _device dev_netdrive_storage;
423 #define netdrive_dev ((device *) &dev_netdrive_storage)
424 extern const _device dev_cygdrive_storage;
425 #define cygdrive_dev ((device *) &dev_cygdrive_storage)
426 extern const _device dev_fh_storage;
427 #define fh_dev ((device *) &dev_fh_storage)
428 extern const _device dev_fs_storage;
429 #define fs_dev ((device *) &dev_fs_storage)
431 #define isproc_dev(devn) \
432 (devn >= FH_PROC_MIN_MINOR && devn <= FH_PROC_MAX_MINOR)
434 #define iscygdrive_dev(devn) (devn == FH_CYGDRIVE)
436 #define isdev_dev(devn) (devn == FH_DEV)
437 #define isdevfd_dev(devn) (devn == FH_DEV_FD)
439 #define isprocsys_dev(devn) (devn == FH_PROCSYS)
441 #define isvirtual_dev(devn) \
442 (isproc_dev (devn) || devn == FH_CYGDRIVE || devn == FH_NETDRIVE \
443 || devn == FH_DEV_FD || devn == FH_DEV_DISK)
445 #define iscons_dev(n) \
446 ((device::major ((dev_t) (n)) == DEV_CONS_MAJOR) \
447 || (((dev_t) n) == FH_CONSOLE) \
448 || (((dev_t) n) == FH_CONIN) \
449 || (((dev_t) n) == FH_CONOUT))
451 #define istty_slave_dev(n) (device::major (n) == DEV_PTYS_MAJOR)