diff options
Diffstat (limited to 'winsup/cygwin/fhandler.h')
-rw-r--r-- | winsup/cygwin/fhandler.h | 617 |
1 files changed, 379 insertions, 238 deletions
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 753508266..6b80ff22d 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1,6 +1,6 @@ /* fhandler.h - Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -12,41 +12,7 @@ details. */ #define _FHANDLER_H_ #include <sys/ioctl.h> - -/* Classes - - Code is located in fhandler.cc unless another file name is given. - - fhandler_base normal I/O - - fhandler_disk_file - fhandler_serial Adds vmin and vtime. - fhandler_dev_null Not really I/O - fhandler_dev_zero Faked - - fhandler_dev_raw (fhandler_raw.cc) - fhandler_dev_floppy (fhandler_floppy.cc) - fhandler_dev_tape (fhandler_tape.cc) - - fhandler_pipe - fhandler_socket (fhandler_socket.cc) - - fhandler_tty_slave (tty.cc) - fhandler_pty_master (tty.cc) - fhandler_tty_master (tty.cc) - - fhandler_console Out with ansi control. (console.cc) - - fhandler_windows Windows messages I/O (fhandler_windows.cc) - - fhandler_dev_random /dev/[u]random implementation (fhandler_random.cc) - - fhandler_dev_mem /dev/mem implementation (fhandler_mem.cc) - - fhandler_dev_clipboard /dev/clipboard implementation (fhandler_clipboard.cc) - - fhandler_proc Interesting possibility, not implemented yet -*/ +#include <fcntl.h> enum { @@ -65,7 +31,7 @@ enum 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_UNUSED = 0x00800000, /* currently unused. */ + 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 */ @@ -102,10 +68,14 @@ enum 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 clipbaord 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 = 0x00000019, /* Maximum number of devices */ + FH_NDEV = 0x0000001d, /* Maximum number of devices */ FH_DEVMASK = 0x00000fff, /* devices live here */ FH_BAD = 0xffffffff }; @@ -124,20 +94,29 @@ enum /* newlib used to define O_NDELAY differently from O_NONBLOCK. Now it properly defines both to be the same. Unfortunately, we have to - behave properly the old version, too, to accomodate older executables. */ + behave properly the old version, too, to accommodate older executables. */ #define OLD_O_NDELAY (CYGWIN_VERSION_CHECK_FOR_OLD_O_NONBLOCK ? 4 : 0) /* Care for the old O_NDELAY flag. If one of the flags is set, both flags are set. */ #define O_NONBLOCK_MASK (O_NONBLOCK | OLD_O_NDELAY) +#define UNCONNECTED 0 +#define CONNECT_PENDING 1 +#define CONNECTED 2 + extern const char *windows_device_names[]; extern struct __cygwin_perfile *perfile_table; #define __fmode (*(user_data->fmode_ptr)) +extern const char proc[]; +extern const int proc_len; class select_record; class path_conv; class fhandler_disk_file; +typedef struct __DIR DIR; +struct dirent; +struct iovec; enum bg_check_types { @@ -150,24 +129,22 @@ enum bg_check_types enum executable_states { is_executable, - not_executable, dont_care_if_executable, + not_executable = dont_care_if_executable, dont_know_if_executable }; class fhandler_base { -protected: + protected: DWORD status; -public: - int cb; -private: + private: int access; HANDLE io_handle; unsigned long namehash; /* hashed filename, used as inode num */ -protected: + protected: /* Full unix path name of this file */ /* File open flags from open () and fcntl () calls */ int openflags; @@ -178,23 +155,20 @@ protected: size_t raixput; size_t rabuflen; - char *unix_path_name; - char *win32_path_name; + const char *unix_path_name; + const char *win32_path_name; DWORD open_status; -public: - void set_name (const char * unix_path, const char * win32_path = NULL, - int unit = 0); + public: + void set_name (const char * unix_path, const char *win32_path = NULL, int unit = 0); - void reset_unix_path_name (const char *); virtual fhandler_base& operator =(fhandler_base &x); - fhandler_base (DWORD dev, const char *name = 0, int unit = 0); + fhandler_base (DWORD dev, int unit = 0); virtual ~fhandler_base (); /* Non-virtual simple accessor functions. */ void set_io_handle (HANDLE x) { io_handle = x; } - void set_cb (size_t size) { cb = size; } DWORD get_device () { return status & FH_DEVMASK; } virtual int get_unit () { return 0; } virtual BOOL is_slow () { return get_device () < FH_SLOW; } @@ -202,40 +176,44 @@ public: int get_access () { return access; } void set_access (int x) { access = x; } - int get_async () { return FHISSETF (ASYNC); } + bool get_async () { return FHISSETF (ASYNC); } void set_async (int x) { FHCONDSETF (x, ASYNC); } int get_flags () { return openflags; } - void set_flags (int x) { openflags = x; } + void set_flags (int x, int supplied_bin = 0); - int is_nonblocking (); + bool is_nonblocking (); void set_nonblocking (int yes); - int get_w_binary () { return FHISSETF (WBINARY); } - int get_r_binary () { return FHISSETF (RBINARY); } + bool get_w_binary () { return FHISSETF (WBINSET) ? FHISSETF (WBINARY) : 1; } + bool get_r_binary () { return FHISSETF (RBINSET) ? FHISSETF (RBINARY) : 1; } - int get_w_binset () { return FHISSETF (WBINSET); } - int get_r_binset () { return FHISSETF (RBINSET); } + bool get_w_binset () { return FHISSETF (WBINSET); } + bool get_r_binset () { return FHISSETF (RBINSET); } void set_w_binary (int b) { FHCONDSETF (b, WBINARY); FHSETF (WBINSET); } void set_r_binary (int b) { FHCONDSETF (b, RBINARY); FHSETF (RBINSET); } void clear_w_binary () {FHCLEARF (WBINARY); FHCLEARF (WBINSET); } void clear_r_binary () {FHCLEARF (RBINARY); FHCLEARF (RBINSET); } + + bool get_nohandle () { return FHISSETF (NOHANDLE); } + void set_nohandle (int x) { FHCONDSETF (x, NOHANDLE); } + void set_open_status () {open_status = status;} DWORD get_open_status () {return open_status;} void reset_to_open_binmode () { - status = status & ~(FH_WBINARY | FH_WBINSET | FH_RBINARY | FH_RBINSET); - status = status | ((FH_WBINARY | FH_WBINSET | FH_RBINARY | FH_RBINSET) - & open_status); + set_flags ((get_flags () & ~(O_TEXT | O_BINARY)) + | ((open_status & (FH_WBINARY | FH_RBINARY) + ? O_BINARY : O_TEXT))); } int get_default_fmode (int flags); - int get_r_no_interrupt () { return FHISSETF (NOEINTR); } + bool get_r_no_interrupt () { return FHISSETF (NOEINTR); } void set_r_no_interrupt (int b) { FHCONDSETF (b, NOEINTR); } - int get_close_on_exec () { return FHISSETF (CLOEXEC); } + bool get_close_on_exec () { return FHISSETF (CLOEXEC); } int set_close_on_exec_flag (int b) { return FHCONDSETF (b, CLOEXEC); } LPSECURITY_ATTRIBUTES get_inheritance (bool all = 0) @@ -247,9 +225,9 @@ public: } void set_check_win95_lseek_bug (int b = 1) { FHCONDSETF (b, W95LSBUG); } - int get_check_win95_lseek_bug () { return FHISSETF (W95LSBUG); } + bool get_check_win95_lseek_bug () { return FHISSETF (W95LSBUG); } - int get_need_fork_fixup () { return FHISSETF (FFIXUP); } + bool get_need_fork_fixup () { return FHISSETF (FFIXUP); } void set_need_fork_fixup () { FHSETF (FFIXUP); } virtual void set_close_on_exec (int val); @@ -258,31 +236,32 @@ public: virtual void fixup_after_fork (HANDLE); virtual void fixup_after_exec (HANDLE) {} - int get_symlink_p () { return FHISSETF (SYMLINK); } + bool get_symlink_p () { return FHISSETF (SYMLINK); } void set_symlink_p (int val) { FHCONDSETF (val, SYMLINK); } void set_symlink_p () { FHSETF (SYMLINK); } - int get_socket_p () { return FHISSETF (LOCAL); } + bool get_socket_p () { return FHISSETF (LOCAL); } void set_socket_p (int val) { FHCONDSETF (val, LOCAL); } void set_socket_p () { FHSETF (LOCAL); } - int get_execable_p () { return FHISSETF (EXECABL); } + bool get_execable_p () { return FHISSETF (EXECABL); } void set_execable_p (executable_states val) { FHCONDSETF (val == is_executable, EXECABL); FHCONDSETF (val == dont_care_if_executable, DCEXEC); } void set_execable_p () { FHSETF (EXECABL); } - int dont_care_if_execable () { return FHISSETF (DCEXEC); } + bool dont_care_if_execable () { return FHISSETF (DCEXEC); } + bool exec_state_isknown () { return FHISSETF (DCEXEC) || FHISSETF (EXECABL); } - int get_append_p () { return FHISSETF (APPEND); } + bool get_append_p () { return FHISSETF (APPEND); } void set_append_p (int val) { FHCONDSETF (val, APPEND); } void set_append_p () { FHSETF (APPEND); } - int get_query_open () { return FHISSETF (QUERYOPEN); } - void set_query_open (int val) { FHCONDSETF (val, QUERYOPEN); } + bool get_query_open () { return FHISSETF (QUERYOPEN); } + void set_query_open (bool val) { FHCONDSETF (val, QUERYOPEN); } - int get_readahead_valid () { return raixget < ralen; } + bool get_readahead_valid () { return raixget < ralen; } int puts_readahead (const char *s, size_t len = (size_t) -1); int put_readahead (char value); @@ -295,10 +274,10 @@ public: int get_readahead_into_buffer (char *buf, size_t buflen); - int has_acls () { return FHISSETF (HASACLS); } + bool has_acls () { return FHISSETF (HASACLS); } void set_has_acls (int val) { FHCONDSETF (val, HASACLS); } - int isremote () { return FHISSETF (ISREMOTE); } + bool isremote () { return FHISSETF (ISREMOTE); } void set_isremote (int val) { FHCONDSETF (val, ISREMOTE); } const char *get_name () { return unix_path_name; } @@ -311,27 +290,23 @@ public: /* fixup fd possibly non-inherited handles after fork */ void fork_fixup (HANDLE parent, HANDLE &h, const char *name); - /* Potentially overridden virtual functions. */ - virtual int open (const char *, int flags, mode_t mode = 0) - { - return open (flags, mode); - } - virtual int open (path_conv& real_path, int flags, mode_t mode); - virtual int open (int flags, mode_t mode = 0); + virtual int open (path_conv *real_path, int flags, mode_t mode = 0); virtual int close (); - virtual int fstat (struct stat *buf) { return stat_dev (get_device (), get_unit (), get_namehash (), buf); } + virtual int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); virtual int ioctl (unsigned int cmd, void *); virtual int fcntl (int cmd, void *); virtual char const * ttyname () { return get_name(); } - virtual int read (void *ptr, size_t len); + virtual int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); virtual int write (const void *ptr, size_t len); - virtual off_t lseek (off_t offset, int whence); + virtual ssize_t readv (const struct iovec *, int iovcnt, ssize_t tot = -1); + virtual ssize_t writev (const struct iovec *, int iovcnt, ssize_t tot = -1); + virtual __off64_t lseek (__off64_t offset, int whence); virtual int lock (int, struct flock *); virtual void dump (); virtual int dup (fhandler_base *child); virtual HANDLE mmap (caddr_t *addr, size_t len, DWORD access, - int flags, off_t off); + int flags, __off64_t off); virtual int munmap (HANDLE h, caddr_t addr, size_t len); virtual int msync (HANDLE h, caddr_t addr, size_t len, int flags); virtual BOOL fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, @@ -368,7 +343,7 @@ public: virtual select_record *select_read (select_record *s); virtual select_record *select_write (select_record *s); virtual select_record *select_except (select_record *s); - virtual int ready_for_read (int fd, DWORD howlong, int ignra); + virtual int ready_for_read (int fd, DWORD howlong); virtual const char * get_native_name () { return windows_device_names[FHDEVN (status)]; @@ -380,18 +355,29 @@ public: rabuf = NULL; } void operator delete (void *); + virtual HANDLE get_guard () const {return NULL;} + virtual void set_eof () {} + virtual DIR *opendir (path_conv& pc); + virtual dirent *readdir (DIR *); + virtual __off64_t telldir (DIR *); + virtual void seekdir (DIR *, __off64_t); + virtual void rewinddir (DIR *); + virtual int closedir (DIR *); }; class fhandler_socket: public fhandler_base { -private: + private: int addr_family; + int type; int connect_secret [4]; HANDLE secret_event; struct _WSAPROTOCOL_INFOA *prot_info_ptr; + char *sun_path; + int had_connect_or_listen; -public: - fhandler_socket (const char *name = 0); + public: + fhandler_socket (); ~fhandler_socket (); int get_socket () { return (int) get_handle(); } fhandler_socket * is_socket () { return this; } @@ -402,11 +388,32 @@ public: void set_shutdown_read () {FHSETF (SHUTRD);} void set_shutdown_write () {FHSETF (SHUTWR);} - int write (const void *ptr, size_t len); - int read (void *ptr, size_t len); + bool is_unconnected () const {return had_connect_or_listen == UNCONNECTED;} + bool is_connect_pending () const {return had_connect_or_listen == CONNECT_PENDING;} + bool is_connected () const {return had_connect_or_listen == CONNECTED;} + void set_connect_state (int newstate) { had_connect_or_listen = newstate; } + + int bind (const struct sockaddr *name, int namelen); + int connect (const struct sockaddr *name, int namelen); + int listen (int backlog); + int accept (struct sockaddr *peer, int *len); + int getsockname (struct sockaddr *name, int *namelen); + int getpeername (struct sockaddr *name, int *namelen); + + ssize_t readv (const struct iovec *, int iovcnt, ssize_t tot = -1); + int recvfrom (void *ptr, size_t len, int flags, + struct sockaddr *from, int *fromlen); + int recvmsg (struct msghdr *msg, int flags, ssize_t tot = -1); + + ssize_t writev (const struct iovec *, int iovcnt, ssize_t tot = -1); + int sendto (const void *ptr, size_t len, int flags, + const struct sockaddr *to, int tolen); + int sendmsg (const struct msghdr *msg, int flags, ssize_t tot = -1); + int ioctl (unsigned int cmd, void *); int fcntl (int cmd, void *); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } + int shutdown (int how); int close (); void hclose (HANDLE) {close ();} int dup (fhandler_base *child); @@ -419,43 +426,49 @@ public: select_record *select_read (select_record *s); select_record *select_write (select_record *s); select_record *select_except (select_record *s); - int ready_for_read (int fd, DWORD howlong, int ignra); - int get_addr_family () {return addr_family;} void set_addr_family (int af) {addr_family = af;} + int get_addr_family () {return addr_family;} + void set_socket_type (int st) { type = st;} + int get_socket_type () {return type;} + void set_sun_path (const char *path); + char *get_sun_path () {return sun_path;} void set_connect_secret (); void get_connect_secret (char*); HANDLE create_secret_event (int *secret = NULL); int check_peer_secret_event (struct sockaddr_in *peer, int *secret = NULL); void signal_secret_event (); void close_secret_event (); + int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); }; class fhandler_pipe: public fhandler_base { HANDLE guard; + bool broken_pipe; HANDLE writepipe_exists; DWORD orig_pid; unsigned id; -public: - fhandler_pipe (const char *name = 0, DWORD devtype = FH_PIPE); - off_t lseek (off_t offset, int whence); + public: + fhandler_pipe (DWORD devtype); + __off64_t lseek (__off64_t offset, int whence); select_record *select_read (select_record *s); select_record *select_write (select_record *s); select_record *select_except (select_record *s); - int ready_for_read (int fd, DWORD howlong, int ignra); void set_close_on_exec (int val); - int read (void *ptr, size_t len); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int close (); void create_guard (SECURITY_ATTRIBUTES *sa) {guard = CreateMutex (sa, FALSE, NULL);} int dup (fhandler_base *child); void fixup_after_fork (HANDLE); bool hit_eof (); + void set_eof () {broken_pipe = true;} friend int make_pipe (int fildes[2], unsigned int psize, int mode); + HANDLE get_guard () const {return guard;} }; class fhandler_dev_raw: public fhandler_base { -protected: + protected: char *devbuf; size_t devbufsiz; size_t devbufstart; @@ -476,19 +489,19 @@ protected: /* returns not null, if `win_error' determines an end of file condition */ virtual int is_eof(int win_error) = 0; - fhandler_dev_raw (DWORD dev, const char *name, int unit); + fhandler_dev_raw (DWORD dev, int unit); -public: + public: ~fhandler_dev_raw (void); - int open (const char *path, int flags, mode_t mode = 0); + int get_unit () { return unit; } + + int open (path_conv *, int flags, mode_t mode = 0); int close (void); int raw_read (void *ptr, size_t ulen); int raw_write (const void *ptr, size_t ulen); - int fstat (struct stat *buf); - int dup (fhandler_base *child); int ioctl (unsigned int cmd, void *buf); @@ -499,47 +512,48 @@ public: class fhandler_dev_floppy: public fhandler_dev_raw { -protected: + protected: virtual int is_eom (int win_error); virtual int is_eof (int win_error); -public: - fhandler_dev_floppy (const char *name, int unit); + public: + fhandler_dev_floppy (int unit); - virtual int open (const char *path, int flags, mode_t mode = 0); + virtual int open (path_conv *, int flags, mode_t mode = 0); virtual int close (void); - virtual off_t lseek (off_t offset, int whence); + virtual __off64_t lseek (__off64_t offset, int whence); virtual int ioctl (unsigned int cmd, void *buf); }; class fhandler_dev_tape: public fhandler_dev_raw { - int norewind; int lasterr; -protected: + bool is_rewind_device () { return get_unit () < 128; } + + protected: virtual void clear (void); virtual int is_eom (int win_error); virtual int is_eof (int win_error); -public: - fhandler_dev_tape (const char *name, int unit); + public: + fhandler_dev_tape (int unit); - virtual int open (const char *path, int flags, mode_t mode = 0); + virtual int open (path_conv *, int flags, mode_t mode = 0); virtual int close (void); - virtual off_t lseek (off_t offset, int whence); + virtual __off64_t lseek (__off64_t offset, int whence); - virtual int fstat (struct stat *buf); + virtual int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); virtual int dup (fhandler_base *child); virtual int ioctl (unsigned int cmd, void *buf); -private: + private: int tape_write_marks (int marktype, DWORD len); int tape_get_pos (unsigned long *ret); int tape_set_pos (int mode, long count, BOOLEAN sfm_func = FALSE); @@ -556,38 +570,77 @@ private: class fhandler_disk_file: public fhandler_base { -public: - fhandler_disk_file (const char *name); + public: + fhandler_disk_file (); + fhandler_disk_file (DWORD devtype); - int open (const char *path, int flags, mode_t mode = 0); - int open (path_conv& real_path, int flags, mode_t mode); + int open (path_conv * real_path, int flags, mode_t mode); int close (); int lock (int, struct flock *); BOOL is_device () { return FALSE; } - int fstat (struct stat *buf); - - HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, off_t off); + int __stdcall fstat (struct __stat64 *buf, path_conv *pc) __attribute__ ((regparm (3))); + int __stdcall fstat_helper (struct __stat64 *buf, path_conv *pc, + FILETIME ftCreateionTime, + FILETIME ftLastAccessTime, + FILETIME ftLastWriteTime, + DWORD nFileSizeHigh, + DWORD nFileSizeLow, + DWORD nFileIndexHigh = 0, + DWORD nFileIndexLow = 0, + DWORD nNumberOfLinks = 1) + __attribute__ ((regparm (3))); + int __stdcall fstat_by_handle (struct __stat64 *buf, path_conv *pc) __attribute__ ((regparm (3))); + int __stdcall fstat_by_name (struct __stat64 *buf, path_conv *pc) __attribute__ ((regparm (3))); + + HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, __off64_t off); int munmap (HANDLE h, caddr_t addr, size_t len); int msync (HANDLE h, caddr_t addr, size_t len, int flags); BOOL fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, DWORD size, void *address); + DIR *opendir (path_conv& pc); + struct dirent *readdir (DIR *); + __off64_t telldir (DIR *); + void seekdir (DIR *, __off64_t); + void rewinddir (DIR *); + int closedir (DIR *); +}; + +class fhandler_cygdrive: public fhandler_disk_file +{ + int unit; + int ndrives; + const char *pdrive; + void set_drives (); + public: + bool iscygdrive_root () const { return !unit; } + fhandler_cygdrive (int unit); + DIR *opendir (path_conv& pc); + struct dirent *readdir (DIR *); + __off64_t telldir (DIR *); + void seekdir (DIR *, __off64_t); + void rewinddir (DIR *); + int closedir (DIR *); + int __stdcall fstat (struct __stat64 *buf, path_conv *pc) __attribute__ ((regparm (3))); }; class fhandler_serial: public fhandler_base { -private: + private: unsigned int vmin_; /* from termios */ unsigned int vtime_; /* from termios */ pid_t pgrp_; + int rts; /* for Windows 9x purposes only */ + int dtr; /* for Windows 9x purposes only */ -public: + public: int overlapped_armed; OVERLAPPED io_status; + DWORD ev; /* Constructor */ - fhandler_serial (const char *name, DWORD devtype = FH_SERIAL, int unit = 0); + fhandler_serial (int unit); - int open (const char *path, int flags, mode_t mode); + int open (path_conv *, int flags, mode_t mode); int close (); void init (HANDLE h, DWORD a, mode_t flags); void overlapped_setup (); @@ -597,9 +650,10 @@ public: int tcsendbreak (int); int tcdrain (); int tcflow (int); + int ioctl (unsigned int cmd, void *); int tcsetattr (int a, const struct termios *t); int tcgetattr (struct termios *t); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } int tcflush (int); void dump (); int is_tty () { return 1; } @@ -614,7 +668,6 @@ public: select_record *select_read (select_record *s); select_record *select_write (select_record *s); select_record *select_except (select_record *s); - int ready_for_read (int fd, DWORD howlong, int ignra); }; #define acquire_output_mutex(ms) \ @@ -627,14 +680,14 @@ class tty; class tty_min; class fhandler_termios: public fhandler_base { -protected: + protected: HANDLE output_handle; virtual void doecho (const void *, DWORD) {}; virtual int accept_input () {return 1;}; -public: + public: tty_min *tc; - fhandler_termios (DWORD dev, const char *name = 0, int unit = 0) : - fhandler_base (dev, name, unit) + fhandler_termios (DWORD dev, int unit = 0) : + fhandler_base (dev, unit) { set_need_fork_fixup (); } @@ -651,6 +704,7 @@ public: void fixup_after_fork (HANDLE); void fixup_after_exec (HANDLE parent) { fixup_after_fork (parent); } void echo_erase (int force = 0); + virtual __off64_t lseek (__off64_t, int); }; enum ansi_intensity @@ -674,7 +728,7 @@ enum ansi_intensity /* This is a input and output console handle */ class fhandler_console: public fhandler_termios { -private: + private: WORD default_color, underline_color, dim_color; @@ -686,13 +740,13 @@ private: int args_[MAXARGS]; int nargs_; unsigned rarg; - BOOL saw_question_mark; + bool saw_question_mark; char my_title_buf [TITLESIZE + 1]; WORD current_win32_attr; ansi_intensity intensity; - BOOL underline, blink, reverse; + bool underline, blink, reverse; WORD fg, bg; /* saved cursor coordinates */ @@ -720,9 +774,9 @@ private: DWORD dwLastButtonState; int nModifiers; - BOOL insert_mode; - BOOL use_mouse; - BOOL raw_win32_keyboard_mode; + bool insert_mode; + bool use_mouse; + bool raw_win32_keyboard_mode; /* Output calls */ void set_default_attr (); @@ -744,17 +798,17 @@ private: int input_tcsetattr (int a, const struct termios *t); void set_cursor_maybe (); -public: + public: - fhandler_console (const char *name); + fhandler_console (); fhandler_console* is_console () { return this; } - int open (const char *path, int flags, mode_t mode = 0); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); void doecho (const void *str, DWORD len) { (void) write (str, len); } - int read (void *ptr, size_t len); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int close (); int tcflush (int); @@ -771,19 +825,20 @@ public: select_record *select_read (select_record *s); select_record *select_write (select_record *s); select_record *select_except (select_record *s); - int ready_for_read (int fd, DWORD howlong, int ignra); void fixup_after_exec (HANDLE); void set_close_on_exec (int val); void fixup_after_fork (HANDLE parent); void set_input_state (); + void send_winch_maybe (); }; class fhandler_tty_common: public fhandler_termios { -public: - fhandler_tty_common (DWORD dev, const char *name = 0, int unit = 0) : - fhandler_termios (dev, name, unit), - ttynum (unit) + public: + fhandler_tty_common (DWORD dev, int unit = 0) + : fhandler_termios (dev, unit), output_done_event (NULL), + ioctl_request_event (NULL), ioctl_done_event (NULL), output_mutex (NULL), + input_mutex (NULL), input_available_event (NULL), inuse (NULL), ttynum (unit) { // nothing to do } @@ -796,12 +851,11 @@ public: HANDLE output_mutex, input_mutex; HANDLE input_available_event; HANDLE inuse; // used to indicate that a tty is in use - + int ttynum; // Master tty num. DWORD __acquire_output_mutex (const char *fn, int ln, DWORD ms); void __release_output_mutex (const char *fn, int ln); - int ttynum; // Master tty num. virtual int dup (fhandler_base *child); tty *get_ttyp () { return (tty *)tc; } @@ -813,19 +867,18 @@ public: select_record *select_read (select_record *s); select_record *select_write (select_record *s); select_record *select_except (select_record *s); - int ready_for_read (int fd, DWORD howlong, int ignra); }; class fhandler_tty_slave: public fhandler_tty_common { -public: + public: /* Constructor */ - fhandler_tty_slave (const char *name); - fhandler_tty_slave (int, const char *name); + fhandler_tty_slave (); + fhandler_tty_slave (int); - int open (const char *path, int flags, mode_t mode = 0); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); - int read (void *ptr, size_t len); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); void init (HANDLE, DWORD, mode_t); int tcsetattr (int a, const struct termios *t); @@ -833,28 +886,26 @@ public: int tcflush (int); int ioctl (unsigned int cmd, void *); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } select_record *select_read (select_record *s); - int ready_for_read (int fd, DWORD howlong, int ignra); - int cygserver_attach_tty (HANDLE*, HANDLE*); }; class fhandler_pty_master: public fhandler_tty_common { int pktmode; // non-zero if pty in a packet mode. -public: + public: int need_nl; // Next read should start with \n /* Constructor */ - fhandler_pty_master (const char *name, DWORD devtype = FH_PTYM, int unit = -1); + fhandler_pty_master (DWORD devtype = FH_PTYM, int unit = -1); int process_slave_output (char *buf, size_t len, int pktmode_on); void doecho (const void *str, DWORD len); int accept_input (); - int open (const char *path, int flags, mode_t mode = 0); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); - int read (void *ptr, size_t len); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int close (); int tcsetattr (int a, const struct termios *t); @@ -862,21 +913,22 @@ public: int tcflush (int); int ioctl (unsigned int cmd, void *); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } char *ptsname (); void set_close_on_exec (int val); bool hit_eof (); }; +class cygthread; class fhandler_tty_master: public fhandler_pty_master { -public: + public: /* Constructor */ - fhandler_tty_master (const char *name, int unit); fhandler_console *console; // device handler to perform real i/o. - HANDLE hThread; // process_output thread handle. + cygthread *output_thread; // process_output thread + fhandler_tty_master (int unit); int init (int); int init_console (); void fixup_after_fork (HANDLE parent); @@ -885,8 +937,8 @@ public: class fhandler_dev_null: public fhandler_base { -public: - fhandler_dev_null (const char *name); + public: + fhandler_dev_null (); void dump (); select_record *select_read (select_record *s); @@ -896,20 +948,19 @@ public: class fhandler_dev_zero: public fhandler_base { -public: - fhandler_dev_zero (const char *name); - int open (const char *path, int flags, mode_t mode = 0); + public: + fhandler_dev_zero (); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); - int read (void *ptr, size_t len); - off_t lseek (off_t offset, int whence); - int close (void); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); + __off64_t lseek (__off64_t offset, int whence); void dump (); }; class fhandler_dev_random: public fhandler_base { -protected: + protected: int unit; HCRYPTPROV crypt_prov; long pseudo; @@ -918,13 +969,13 @@ protected: int pseudo_write (const void *ptr, size_t len); int pseudo_read (void *ptr, size_t len); -public: - fhandler_dev_random (const char *name, int unit); + public: + fhandler_dev_random (int unit); int get_unit () { return unit; } - int open (const char *path, int flags, mode_t mode = 0); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); - int read (void *ptr, size_t len); - off_t lseek (off_t offset, int whence); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); + __off64_t lseek (__off64_t offset, int whence); int close (void); int dup (fhandler_base *child); @@ -933,24 +984,24 @@ public: class fhandler_dev_mem: public fhandler_base { -protected: + protected: int unit; DWORD mem_size; - DWORD pos; + __off64_t pos; -public: - fhandler_dev_mem (const char *name, int unit); + public: + fhandler_dev_mem (int unit); ~fhandler_dev_mem (void); - int open (const char *path, int flags, mode_t mode = 0); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t ulen); - int read (void *ptr, size_t ulen); - off_t lseek (off_t offset, int whence); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); + __off64_t lseek (__off64_t offset, int whence); int close (void); - int fstat (struct stat *buf); + int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); int dup (fhandler_base *child); - HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, off_t off); + HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, __off64_t off); int munmap (HANDLE h, caddr_t addr, size_t len); int msync (HANDLE h, caddr_t addr, size_t len, int flags); BOOL fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, @@ -961,39 +1012,39 @@ public: class fhandler_dev_clipboard: public fhandler_base { -public: - fhandler_dev_clipboard (const char *name); + public: + fhandler_dev_clipboard (); int is_windows (void) { return 1; } - int open (const char *path, int flags, mode_t mode = 0); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); - int read (void *ptr, size_t len); - off_t lseek (off_t offset, int whence); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); + __off64_t lseek (__off64_t offset, int whence); int close (void); int dup (fhandler_base *child); void dump (); -private: - off_t pos; + private: + __off64_t pos; void *membuffer; size_t msize; - BOOL eof; + bool eof; }; class fhandler_windows: public fhandler_base { -private: + private: HWND hWnd_; // the window whose messages are to be retrieved by read() call int method_; // write method (Post or Send) -public: - fhandler_windows (const char *name = 0); + public: + fhandler_windows (); int is_windows (void) { return 1; } - int open (const char *path, int flags, mode_t mode = 0); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); - int read (void *ptr, size_t len); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int ioctl (unsigned int cmd, void *); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } int close (void) { return 0; } void set_close_on_exec (int val); @@ -1001,78 +1052,168 @@ public: select_record *select_read (select_record *s); select_record *select_write (select_record *s); select_record *select_except (select_record *s); - int ready_for_read (int fd, DWORD howlong, int ignra); }; class fhandler_dev_dsp : public fhandler_base { -private: + private: int audioformat_; int audiofreq_; int audiobits_; int audiochannels_; bool setupwav(const char *pData, int nBytes); -public: - fhandler_dev_dsp (const char *name = 0); + public: + fhandler_dev_dsp (); ~fhandler_dev_dsp(); - int open (const char *path, int flags, mode_t mode = 0); + int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); - int read (void *ptr, size_t len); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int ioctl (unsigned int cmd, void *); - off_t lseek (off_t, int); + __off64_t lseek (__off64_t, int); int close (void); int dup (fhandler_base * child); void dump (void); void fixup_after_exec (HANDLE); }; -#if 0 -/* You can't do this */ +class fhandler_virtual : public fhandler_base +{ + protected: + char *filebuf; + size_t bufalloc, filesize; + __off64_t position; + int fileid; // unique within each class + public: + + fhandler_virtual (DWORD devtype); + virtual ~fhandler_virtual(); + + virtual int exists(); + DIR *opendir (path_conv& pc); + __off64_t telldir (DIR *); + void seekdir (DIR *, __off64_t); + void rewinddir (DIR *); + int closedir (DIR *); + int write (const void *ptr, size_t len); + int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); + __off64_t lseek (__off64_t, int); + int dup (fhandler_base * child); + int open (path_conv *, int flags, mode_t mode = 0); + int close (void); + int __stdcall fstat (struct stat *buf, path_conv *pc) __attribute__ ((regparm (3))); + virtual bool fill_filebuf (); +}; + +class fhandler_proc: public fhandler_virtual +{ + public: + fhandler_proc (); + fhandler_proc (DWORD devtype); + int exists(); + struct dirent *readdir (DIR *); + static DWORD get_proc_fhandler(const char *path); + + int open (path_conv *real_path, int flags, mode_t mode = 0); + int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); + bool fill_filebuf (); +}; + +class fhandler_registry: public fhandler_proc +{ + private: + char *value_name; + public: + fhandler_registry (); + int exists(); + struct dirent *readdir (DIR *); + __off64_t telldir (DIR *); + void seekdir (DIR *, __off64_t); + void rewinddir (DIR *); + int closedir (DIR *); + + int open (path_conv *real_path, int flags, mode_t mode = 0); + int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); + bool fill_filebuf (); + int close (void); +}; + +class pinfo; +class fhandler_process: public fhandler_proc +{ + pid_t pid; + public: + fhandler_process (); + int exists(); + struct dirent *readdir (DIR *); + int open (path_conv *real_path, int flags, mode_t mode = 0); + int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); + bool fill_filebuf (); +}; + typedef union { - fhandler_normal normal; - fhandler_dev_null dev_null; - fhandler bare; - fhandler_serial tty; + char base[sizeof(fhandler_base)]; + char console[sizeof(fhandler_console)]; + char dev_clipboard[sizeof(fhandler_dev_clipboard)]; + char dev_dsp[sizeof(fhandler_dev_dsp)]; + char dev_floppy[sizeof(fhandler_dev_floppy)]; + char dev_mem[sizeof(fhandler_dev_mem)]; + char dev_null[sizeof(fhandler_dev_null)]; + char dev_random[sizeof(fhandler_dev_random)]; + char dev_raw[sizeof(fhandler_dev_raw)]; + char dev_tape[sizeof(fhandler_dev_tape)]; + char dev_zero[sizeof(fhandler_dev_zero)]; + char disk_file[sizeof(fhandler_disk_file)]; + char pipe[sizeof(fhandler_pipe)]; + char proc[sizeof(fhandler_proc)]; + char process[sizeof(fhandler_process)]; + char pty_master[sizeof(fhandler_pty_master)]; + char registry[sizeof(fhandler_registry)]; + char serial[sizeof(fhandler_serial)]; + char socket[sizeof(fhandler_socket)]; + char termios[sizeof(fhandler_termios)]; + char tty_common[sizeof(fhandler_tty_common)]; + char tty_master[sizeof(fhandler_tty_master)]; + char tty_slave[sizeof(fhandler_tty_slave)]; + char windows[sizeof(fhandler_windows)]; } fhandler_union; -#else -#define fhandler_union fhandler_console -#endif + struct select_record { int fd; HANDLE h; fhandler_base *fh; - BOOL saw_error; - BOOL windows_handle; - BOOL read_ready, write_ready, except_ready; - BOOL read_selected, write_selected, except_selected; + bool saw_error; + bool windows_handle; + bool read_ready, write_ready, except_ready; + bool read_selected, write_selected, except_selected; + bool except_on_write; int (*startup) (select_record *me, class select_stuff *stuff); - int (*poll) (select_record *me, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds); + int (*peek) (select_record *, bool); int (*verify) (select_record *me, fd_set *readfds, fd_set *writefds, fd_set *exceptfds); void (*cleanup) (select_record *me, class select_stuff *stuff); struct select_record *next; select_record (fhandler_base *in_fh = NULL) : fd (0), h (NULL), - fh (in_fh), saw_error (0), windows_handle (0), - read_ready (0), write_ready (0), except_ready (0), - read_selected (0), write_selected (0), except_selected (0), - startup (NULL), poll (NULL), verify (NULL), cleanup (NULL), + fh (in_fh), saw_error (false), windows_handle (false), + read_ready (false), write_ready (false), except_ready (false), + read_selected (false), write_selected (false), + except_selected (false), except_on_write (false), + startup (NULL), peek (NULL), verify (NULL), cleanup (NULL), next (NULL) {} }; class select_stuff { -public: + public: ~select_stuff (); select_stuff (): always_ready (0), windows_used (0), start (0) { memset (device_specific, 0, sizeof (device_specific)); } - BOOL always_ready, windows_used; + bool always_ready, windows_used; select_record start; void *device_specific[FH_NDEV]; |