diff options
author | Christopher Faylor <me@cgf.cx> | 2003-09-25 00:37:18 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-09-25 00:37:18 +0000 |
commit | 7ac6173643b13a5a3bc7daf3649eb20c48c9c908 (patch) | |
tree | b6acd69d1804e5e8b7482e7b943e74aca80b5787 /winsup/cygwin/devices.h | |
parent | 2d9af27bf33f28984cf7b0e121bb56d1cb21897c (diff) | |
download | newlib-7ac6173643b13a5a3bc7daf3649eb20c48c9c908.zip newlib-7ac6173643b13a5a3bc7daf3649eb20c48c9c908.tar.gz newlib-7ac6173643b13a5a3bc7daf3649eb20c48c9c908.tar.bz2 |
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
Diffstat (limited to 'winsup/cygwin/devices.h')
-rw-r--r-- | winsup/cygwin/devices.h | 251 |
1 files changed, 176 insertions, 75 deletions
diff --git a/winsup/cygwin/devices.h b/winsup/cygwin/devices.h index c8b7524..7e91b52 100644 --- a/winsup/cygwin/devices.h +++ b/winsup/cygwin/devices.h @@ -1,6 +1,6 @@ /* devices.h - Copyright 2002 Red Hat, Inc. + Copyright 2002, 2003 Red Hat, Inc. This file is part of Cygwin. @@ -8,83 +8,184 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ -#ifndef _DEVICES_H_ -#define _DEVICES_H_ +typedef unsigned short _major_t; +typedef unsigned short _minor_t; +typedef mode_t _mode_t; +typedef __dev32_t _dev_t; -#include <sys/ioctl.h> -#include <fcntl.h> +#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 +enum fh_devices { - FH_RBINARY = 0x00001000, /* binary read mode */ - FH_WBINARY = 0x00002000, /* binary write mode */ - FH_CLOEXEC = 0x00004000, /* close-on-exec */ - FH_RBINSET = 0x00008000, /* binary read mode has been explicitly set */ - FH_WBINSET = 0x00010000, /* binary write mode has been explicitly set */ - FH_APPEND = 0x00020000, /* always append */ - FH_ASYNC = 0x00040000, /* async I/O */ - FH_SIGCLOSE = 0x00080000, /* signal handler should close fd on interrupt */ - - FH_SYMLINK = 0x00100000, /* is a symlink */ - FH_EXECABL = 0x00200000, /* file looked like it would run: - * ends in .exe or .bat or begins with #! */ - FH_W95LSBUG = 0x00400000, /* set when lseek is called as a flag that - * _write should check if we've moved beyond - * EOF, zero filling if so. */ - FH_NOHANDLE = 0x00800000, /* No handle associated with fhandler. */ - FH_NOEINTR = 0x01000000, /* Set if I/O should be uninterruptible. */ - FH_FFIXUP = 0x02000000, /* Set if need to fixup after fork. */ - FH_LOCAL = 0x04000000, /* File is unix domain socket */ - FH_SHUTRD = 0x08000000, /* Socket saw a SHUT_RD */ - FH_SHUTWR = 0x10000000, /* Socket saw a SHUT_WR */ - FH_ISREMOTE = 0x10000000, /* File is on a remote drive */ - FH_DCEXEC = 0x20000000, /* Don't care if this is executable */ - FH_HASACLS = 0x40000000, /* True if fs of file has ACLS */ - FH_QUERYOPEN = 0x80000000, /* open file without requesting either read - or write access */ - - /* Device flags */ - - /* Slow devices */ - FH_CONSOLE = 0x00000001, /* is a console */ - FH_CONIN = 0x00000002, /* console input */ - FH_CONOUT = 0x00000003, /* console output */ - FH_TTYM = 0x00000004, /* is a tty master */ - FH_TTYS = 0x00000005, /* is a tty slave */ - FH_PTYM = 0x00000006, /* is a pty master */ - FH_SERIAL = 0x00000007, /* is a serial port */ - FH_PIPE = 0x00000008, /* is a pipe */ - FH_PIPER = 0x00000009, /* read end of a pipe */ - FH_PIPEW = 0x0000000a, /* write end of a pipe */ - FH_SOCKET = 0x0000000b, /* is a socket */ - FH_WINDOWS = 0x0000000c, /* is a window */ - FH_SLOW = 0x00000010, /* "slow" device if below this */ - - /* Fast devices */ - FH_DISK = 0x00000010, /* is a disk */ - FH_FLOPPY = 0x00000011, /* is a floppy */ - FH_TAPE = 0x00000012, /* is a tape */ - FH_NULL = 0x00000013, /* is the null device */ - FH_ZERO = 0x00000014, /* is the zero device */ - FH_RANDOM = 0x00000015, /* is a random device */ - FH_MEM = 0x00000016, /* is a mem device */ - FH_CLIPBOARD = 0x00000017, /* is a clipboard device */ - FH_OSS_DSP = 0x00000018, /* is a dsp audio device */ - FH_CYGDRIVE= 0x00000019, /* /cygdrive/x */ - FH_PROC = 0x0000001a, /* /proc */ - FH_REGISTRY =0x0000001b, /* /proc/registry */ - FH_PROCESS = 0x0000001c, /* /proc/<n> */ - - FH_NDEV = 0x0000001d, /* Maximum number of devices */ - FH_DEVMASK = 0x00000fff, /* devices live here */ - FH_BAD = 0xffffffff + FH_TTY = FHDEV (5, 0), + FH_CONSOLE = FHDEV (5, 1), + FH_PTYM = FHDEV (5, 2), /* /dev/ptmx */ + FH_CONIN = FHDEV (5, 255), + FH_CONOUT = FHDEV (5, 254), + + DEV_TTYM_MAJOR = 128, + 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 */ + 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_WINDOWS = FHDEV (13, 255), + FH_CLIPBOARD=FHDEV (13, 254), + + FH_PIPE = FHDEV (0, 255), + FH_PIPER = FHDEV (0, 254), + FH_PIPEW = FHDEV (0, 253), + FH_FIFO = FHDEV (0, 252), + FH_PROC = FHDEV (0, 250), + FH_REGISTRY= FHDEV (0, 249), + FH_PROCESS = FHDEV (0, 248), + + FH_FS = FHDEV (0, 247), /* 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 = 3, + DEV_SD1_MAJOR = 90, + FH_SD = FHDEV (DEV_SD_MAJOR, 0), + FH_SD1 = FHDEV (DEV_SD1_MAJOR, 0), + FH_SDA = FHDEV (DEV_SD_MAJOR, 0), + FH_SDB = FHDEV (DEV_SD_MAJOR, 16), + FH_SDC = FHDEV (DEV_SD_MAJOR, 32), + FH_SDD = FHDEV (DEV_SD_MAJOR, 48), + FH_SDE = FHDEV (DEV_SD_MAJOR, 64), + FH_SDF = FHDEV (DEV_SD_MAJOR, 80), + FH_SDG = FHDEV (DEV_SD_MAJOR, 96), + FH_SDH = FHDEV (DEV_SD_MAJOR, 112), + FH_SDI = FHDEV (DEV_SD_MAJOR, 128), + FH_SDJ = FHDEV (DEV_SD_MAJOR, 144), + FH_SDK = FHDEV (DEV_SD_MAJOR, 160), + FH_SDL = FHDEV (DEV_SD_MAJOR, 176), + FH_SDM = FHDEV (DEV_SD_MAJOR, 192), + FH_SDN = FHDEV (DEV_SD_MAJOR, 208), + FH_SDO = FHDEV (DEV_SD_MAJOR, 224), + FH_SDP = FHDEV (DEV_SD_MAJOR, 240), + FH_SDQ = FHDEV (DEV_SD1_MAJOR, 0), + FH_SDR = FHDEV (DEV_SD1_MAJOR, 16), + FH_SDS = FHDEV (DEV_SD1_MAJOR, 32), + FH_SDT = FHDEV (DEV_SD1_MAJOR, 48), + FH_SDU = FHDEV (DEV_SD1_MAJOR, 64), + FH_SDV = FHDEV (DEV_SD1_MAJOR, 80), + FH_SDW = FHDEV (DEV_SD1_MAJOR, 96), + FH_SDX = FHDEV (DEV_SD1_MAJOR, 112), + FH_SDY = FHDEV (DEV_SD1_MAJOR, 128), + FH_SDZ = FHDEV (DEV_SD1_MAJOR, 144), + + FH_MEM = FHDEV (1, 1), + FH_KMEM = FHDEV (1, 2), /* not implemented yet */ + 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_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'), + + DEV_RAWDRIVE_MAJOR = 65, + FH_RAWDRIVE= FHDEV (DEV_RAWDRIVE_MAJOR, 0), + + DEV_TCP_MAJOR = 30, + FH_TCP = FHDEV (DEV_TCP_MAJOR, 36), + FH_UCP = FHDEV (DEV_TCP_MAJOR, 39), + FH_ICMP = FHDEV (DEV_TCP_MAJOR, 33), + FH_UNIX = FHDEV (DEV_TCP_MAJOR, 120), + FH_STREAM = FHDEV (DEV_TCP_MAJOR, 121), + FH_DGRAM = FHDEV (DEV_TCP_MAJOR, 122), + + FH_BAD = FHDEV (0, 0) }; -#define FHDEVN(n) ((n) & FH_DEVMASK) -#define FHISSETF(x) __ISSETF (this, x, FH) -#define FHSETF(x) __SETF (this, x, FH) -#define FHCLEARF(x) __CLEARF (this, x, FH) -#define FHCONDSETF(n, x) __CONDSETF(n, this, x, FH) +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; + _mode_t mode; + 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) + return false; + minor += (n + adjust) * (mul ?: 1); + 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;} +}; -#define FHSTATOFF 0 -#endif +extern const device dev_console_storage; +#define console_dev (&dev_console_storage) +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; +#define cygdrive_dev (&dev_cygdrive_storage) +extern const device dev_fh_storage; +#define fh_dev (&dev_fh_storage) +extern const device dev_fs_storage; +#define fs_dev (&dev_fs_storage) |