3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
6 This file is part of Cygwin.
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
16 /* fcntl flags used only internaly. */
17 #define O_NOSYMLINK 0x080000
18 #define O_DIROPEN 0x100000
20 /* newlib used to define O_NDELAY differently from O_NONBLOCK. Now it
21 properly defines both to be the same. Unfortunately, we have to
22 behave properly the old version, too, to accommodate older executables. */
23 #define OLD_O_NDELAY (CYGWIN_VERSION_CHECK_FOR_OLD_O_NONBLOCK ? 4 : 0)
25 /* Care for the old O_NDELAY flag. If one of the flags is set,
26 both flags are set. */
27 #define O_NONBLOCK_MASK (O_NONBLOCK | OLD_O_NDELAY)
29 /* It appears that 64K is the block size used for buffered I/O on NT.
30 Using this blocksize in read/write calls in the application results
31 in a much better performance than using smaller values. */
32 #define PREFERRED_IO_BLKSIZE ((blksize_t) 65536)
34 /* It also appears that this may be the only acceptable block size for
35 atomic writes to a pipe. It is a shame that we have to make this
36 so small. http://cygwin.com/ml/cygwin/2011-03/msg00541.html */
37 #define DEFAULT_PIPEBUFSIZE PREFERRED_IO_BLKSIZE
39 extern const char *windows_device_names[];
40 extern struct __cygwin_perfile *perfile_table;
41 #define __fmode (*(user_data->fmode_ptr))
42 extern const char proc[];
43 extern const size_t proc_len;
44 extern const char procsys[];
45 extern const size_t procsys_len;
49 class fhandler_disk_file;
51 typedef struct __DIR DIR;
59 dirent_saw_dot = 0x0001,
60 dirent_saw_dot_dot = 0x0002,
61 dirent_saw_eof = 0x0004,
62 dirent_isroot = 0x0008,
63 dirent_set_d_ino = 0x0010,
64 dirent_get_d_ino = 0x0020,
65 dirent_nfs_d_ino = 0x0040,
67 /* Global flags which must not be deleted on rewinddir or seekdir. */
68 dirent_info_mask = 0x0078
82 line_edit_input_done = 1,
83 line_edit_signalled = 2,
85 line_edit_pipe_full = 4
98 query_read_control = 1,
99 query_read_attributes = 2,
100 query_write_control = 3,
102 query_write_attributes = 5
105 enum del_lock_called_from {
111 enum virtual_ftype_t {
112 virt_blk = -7, /* Block special */
113 virt_chr = -6, /* Character special */
114 virt_fsfile = -5, /* FS-based file via /proc/sys */
115 virt_socket = -4, /* Socket */
116 virt_pipe = -3, /* Pipe */
117 virt_symlink = -2, /* Symlink */
118 virt_file = -1, /* Regular file */
119 virt_none = 0, /* Invalid, Error */
120 virt_directory = 1, /* Directory */
121 virt_rootdir = 2, /* Root directory of virtual FS */
122 virt_fsdir = 3, /* FS-based directory via /proc/sys */
128 friend void close_all_files (bool);
132 unsigned rbinary : 1; /* binary read mode */
133 unsigned rbinset : 1; /* binary read mode explicitly set */
134 unsigned wbinary : 1; /* binary write mode */
135 unsigned wbinset : 1; /* binary write mode explicitly set */
136 unsigned nohandle : 1; /* No handle associated with fhandler. */
137 unsigned did_lseek : 1; /* set when lseek is called as a flag that
138 _write should check if we've moved
139 beyond EOF, zero filling or making
140 file sparse if so. */
141 unsigned query_open : 3; /* open file without requesting either
142 read or write access */
143 unsigned close_on_exec : 1; /* close-on-exec */
144 unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */
148 rbinary (0), rbinset (0), wbinary (0), wbinset (0), nohandle (0),
149 did_lseek (0), query_open (no_query), close_on_exec (0),
152 } status, open_status;
160 __ino64_t ino; /* file ID or hashed filename, depends on FS. */
163 /* File open flags from open () and fcntl () calls */
166 char *rabuf; /* used for crlf conversion in text files */
172 /* Used for advisory file locking. See flock.cc. */
174 void del_my_locks (del_lock_called_from);
179 class fhandler_base *archetype;
184 virtual bool use_archetype () const {return false;}
185 virtual void set_name (path_conv &pc);
186 virtual void set_name (const char *s)
188 pc.set_normalized_path (s);
191 int error () const {return pc.error;}
192 void set_error (int error) {pc.error = error;}
193 bool exists () const {return pc.exists ();}
194 int pc_binmode () const {return pc.binmode ();}
195 device& dev () {return pc.dev;}
196 operator DWORD& () {return (DWORD&) pc;}
197 virtual size_t size () const {return sizeof (*this);}
199 virtual fhandler_base& operator =(fhandler_base &x);
201 virtual ~fhandler_base ();
203 /* Non-virtual simple accessor functions. */
204 void set_io_handle (HANDLE x) { io_handle = x; }
206 DWORD& get_device () { return dev (); }
207 DWORD get_major () { return dev ().get_major (); }
208 DWORD get_minor () { return dev ().get_minor (); }
209 virtual int get_unit () { return dev ().get_minor (); }
211 ACCESS_MASK get_access () const { return access; }
212 void set_access (ACCESS_MASK x) { access = x; }
214 ULONG get_options () const { return options; }
215 void set_options (ULONG x) { options = x; }
217 int get_flags () { return openflags; }
218 void set_flags (int x, int supplied_bin = 0);
220 bool is_nonblocking ();
221 void set_nonblocking (int);
223 bool wbinary () const { return status.wbinset ? status.wbinary : 1; }
224 bool rbinary () const { return status.rbinset ? status.rbinary : 1; }
226 void wbinary (bool b) {status.wbinary = b; status.wbinset = 1;}
227 void rbinary (bool b) {status.rbinary = b; status.rbinset = 1;}
229 void set_open_status () {open_status = status;}
230 void reset_to_open_binmode ()
232 set_flags ((get_flags () & ~(O_TEXT | O_BINARY))
233 | ((open_status.wbinary || open_status.rbinary)
234 ? O_BINARY : O_TEXT));
237 IMPLEMENT_STATUS_FLAG (bool, wbinset)
238 IMPLEMENT_STATUS_FLAG (bool, rbinset)
239 IMPLEMENT_STATUS_FLAG (bool, nohandle)
240 IMPLEMENT_STATUS_FLAG (bool, did_lseek)
241 IMPLEMENT_STATUS_FLAG (query_state, query_open)
242 IMPLEMENT_STATUS_FLAG (bool, close_on_exec)
243 IMPLEMENT_STATUS_FLAG (bool, need_fork_fixup)
245 int get_default_fmode (int flags);
247 virtual void set_close_on_exec (bool val);
249 LPSECURITY_ATTRIBUTES get_inheritance (bool all = 0)
252 return close_on_exec () ? &sec_all_nih : &sec_all;
254 return close_on_exec () ? &sec_none_nih : &sec_none;
257 virtual int fixup_before_fork_exec (DWORD) { return 0; }
258 virtual void fixup_after_fork (HANDLE);
259 virtual void fixup_after_exec ();
260 void create_read_state (LONG n)
262 read_state = CreateSemaphore (&sec_none_nih, 0, n, NULL);
263 ProtectHandle (read_state);
266 void signal_read_state (LONG n)
268 ReleaseSemaphore (read_state, n, NULL);
271 bool get_readahead_valid () { return raixget < ralen; }
272 int puts_readahead (const char *s, size_t len = (size_t) -1);
273 int put_readahead (char value);
275 int get_readahead ();
276 int peek_readahead (int queryput = 0);
278 int eat_readahead (int n);
280 void set_readahead_valid (int val, int ch = -1);
282 int get_readahead_into_buffer (char *buf, size_t buflen);
284 bool has_acls () const { return pc.has_acls (); }
286 bool isremote () { return pc.isremote (); }
288 bool has_attribute (DWORD x) const {return pc.has_attribute (x);}
289 const char *get_name () const { return pc.normalized_path; }
290 const char *get_win32_name () { return pc.get_win32 (); }
291 __dev32_t get_dev () { return pc.fs_serial_number (); }
292 __ino64_t get_ino () { return ino ?: ino = hash_path_name (0, pc.get_nt_native_path ()); }
293 long long get_unique_id () const { return unique_id; }
294 /* Returns name used for /proc/<pid>/fd in buf. */
295 virtual char *get_proc_fd_name (char *buf);
297 virtual void hclose (HANDLE h) {CloseHandle (h);}
298 virtual void set_no_inheritance (HANDLE &, bool);
300 /* fixup fd possibly non-inherited handles after fork */
301 bool fork_fixup (HANDLE, HANDLE &, const char *);
302 virtual bool need_fixup_before () const {return false;}
304 int open_with_arch (int, mode_t = 0);
305 virtual int open (int, mode_t);
306 virtual void open_setup (int flags) { return; }
308 int close_with_arch ();
309 virtual int close ();
310 virtual void cleanup () { return; }
311 int _archetype_usecount (const char *fn, int ln, int n)
315 archetype->usecount += n;
316 if (strace.active ())
317 strace.prntf (_STRACE_ALL, fn, "line %d: %s<%p> usecount + %d = %d", ln, get_name (), archetype, n, archetype->usecount);
318 return archetype->usecount;
321 int open_fs (int, mode_t = 0);
322 # define archetype_usecount(n) _archetype_usecount (__PRETTY_FUNCTION__, __LINE__, (n))
323 int close_fs () { return fhandler_base::close (); }
324 virtual int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
325 int __stdcall fstat_fs (struct __stat64 *buf) __attribute__ ((regparm (2)));
327 int __stdcall fstat_helper (struct __stat64 *buf,
328 DWORD nNumberOfLinks)
329 __attribute__ ((regparm (3)));
330 int __stdcall fstat_by_nfs_ea (struct __stat64 *buf) __attribute__ ((regparm (2)));
331 int __stdcall fstat_by_handle (struct __stat64 *buf) __attribute__ ((regparm (2)));
332 int __stdcall fstat_by_name (struct __stat64 *buf) __attribute__ ((regparm (2)));
334 virtual int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2)));
335 int utimens_fs (const struct timespec *) __attribute__ ((regparm (2)));
336 virtual int __stdcall fchmod (mode_t mode) __attribute__ ((regparm (1)));
337 virtual int __stdcall fchown (__uid32_t uid, __gid32_t gid) __attribute__ ((regparm (2)));
338 virtual int __stdcall facl (int, int, __acl32 *) __attribute__ ((regparm (3)));
339 virtual ssize_t __stdcall fgetxattr (const char *, void *, size_t) __attribute__ ((regparm (3)));
340 virtual int __stdcall fsetxattr (const char *, const void *, size_t, int) __attribute__ ((regparm (3)));
341 virtual int __stdcall fadvise (_off64_t, _off64_t, int) __attribute__ ((regparm (3)));
342 virtual int __stdcall ftruncate (_off64_t, bool) __attribute__ ((regparm (3)));
343 virtual int __stdcall link (const char *) __attribute__ ((regparm (2)));
344 virtual int __stdcall utimens (const struct timespec *) __attribute__ ((regparm (2)));
345 virtual int __stdcall fsync () __attribute__ ((regparm (1)));
346 virtual int ioctl (unsigned int cmd, void *);
347 virtual int fcntl (int cmd, void *);
348 virtual char const *ttyname () { return get_name (); }
349 virtual void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
350 virtual ssize_t __stdcall write (const void *ptr, size_t len);
351 virtual ssize_t __stdcall readv (const struct iovec *, int iovcnt, ssize_t tot = -1);
352 virtual ssize_t __stdcall writev (const struct iovec *, int iovcnt, ssize_t tot = -1);
353 virtual ssize_t __stdcall pread (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
354 virtual ssize_t __stdcall pwrite (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
355 virtual _off64_t lseek (_off64_t offset, int whence);
356 virtual int lock (int, struct __flock64 *);
357 virtual int dup (fhandler_base *child);
358 virtual int fpathconf (int);
360 virtual HANDLE mmap (caddr_t *addr, size_t len, int prot,
361 int flags, _off64_t off);
362 virtual int munmap (HANDLE h, caddr_t addr, size_t len);
363 virtual int msync (HANDLE h, caddr_t addr, size_t len, int flags);
364 virtual bool fixup_mmap_after_fork (HANDLE h, int prot, int flags,
365 _off64_t offset, DWORD size,
368 void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
370 virtual int init (HANDLE, DWORD, mode_t);
372 virtual int tcflush (int);
373 virtual int tcsendbreak (int);
374 virtual int tcdrain ();
375 virtual int tcflow (int);
376 virtual int tcsetattr (int a, const struct termios *t);
377 virtual int tcgetattr (struct termios *t);
378 virtual int tcsetpgrp (const pid_t pid);
379 virtual int tcgetpgrp ();
380 virtual bool is_tty () const { return false; }
381 virtual bool ispipe () const { return false; }
382 virtual pid_t get_popen_pid () const {return 0;}
383 virtual bool isdevice () const { return true; }
384 virtual bool isfifo () const { return false; }
385 virtual char *ptsname () { return NULL;}
386 virtual class fhandler_socket *is_socket () { return NULL; }
387 virtual class fhandler_console *is_console () { return 0; }
388 virtual int is_windows () {return 0; }
390 virtual void __stdcall raw_read (void *ptr, size_t& ulen) __attribute__ ((regparm (3)));
391 virtual ssize_t __stdcall raw_write (const void *ptr, size_t ulen) __attribute__ ((regparm (3)));
393 /* Virtual accessor functions to hide the fact
394 that some fd's have two handles. */
395 virtual HANDLE& get_handle () { return io_handle; }
396 virtual HANDLE& get_io_handle () { return io_handle; }
397 virtual HANDLE& get_output_handle () { return io_handle; }
398 virtual HANDLE get_stat_handle () { return pc.handle () ?: io_handle; }
399 virtual bool hit_eof () {return false;}
400 virtual select_record *select_read (select_stuff *);
401 virtual select_record *select_write (select_stuff *);
402 virtual select_record *select_except (select_stuff *);
403 virtual const char *get_native_name ()
405 return dev ().native;
407 virtual bg_check_types bg_check (int) {return bg_ok;}
408 void clear_readahead ()
410 raixput = raixget = ralen = rabuflen = 0;
413 void operator delete (void *);
414 virtual void set_eof () {}
415 virtual int mkdir (mode_t mode);
416 virtual int rmdir ();
417 virtual DIR *opendir (int fd) __attribute__ ((regparm (2)));
418 virtual int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
419 virtual long telldir (DIR *);
420 virtual void seekdir (DIR *, long);
421 virtual void rewinddir (DIR *);
422 virtual int closedir (DIR *);
423 bool is_auto_device () {return isdevice () && !dev ().isfs ();}
424 bool is_fs_special () {return pc.is_fs_special ();}
425 bool issymlink () {return pc.issymlink ();}
426 bool device_access_denied (int) __attribute__ ((regparm (2)));
427 int fhaccess (int flags, bool) __attribute__ ((regparm (3)));
428 virtual bool __stdcall has_ongoing_io () __attribute__ ((regparm (1))) {return false;}
435 int connect_errorcode;
439 class fhandler_socket: public fhandler_base
444 int connect_secret[4];
446 wsa_event *wsock_events;
451 int evaluate_events (const long event_mask, long &events, const bool erase);
452 const HANDLE wsock_event () const { return wsock_evt; }
453 const LONG serial_number () const { return wsock_events->serial_number; }
455 int wait_for_events (const long event_mask, const DWORD flags);
456 void release_events ();
462 __uid32_t sec_peer_uid;
463 __gid32_t sec_peer_gid;
464 void af_local_set_secret (char *);
465 void af_local_setblocking (bool &, bool &);
466 void af_local_unsetblocking (bool, bool);
467 void af_local_set_cred ();
468 void af_local_copy (fhandler_socket *);
469 bool af_local_recv_secret ();
470 bool af_local_send_secret ();
471 bool af_local_recv_cred ();
472 bool af_local_send_cred ();
473 int af_local_accept ();
475 int af_local_connect ();
476 void af_local_set_sockpair_cred ();
482 int &rmem () { return _rmem; }
483 int &wmem () { return _wmem; }
484 void rmem (int nrmem) { _rmem = nrmem; }
485 void wmem (int nwmem) { _wmem = nwmem; }
488 struct _WSAPROTOCOL_INFOW *prot_info_ptr;
490 void init_fixup_before ();
491 bool need_fixup_before () const {return prot_info_ptr != NULL;}
498 unsigned async_io : 1; /* async I/O */
499 unsigned saw_shutdown_read : 1; /* Socket saw a SHUT_RD */
500 unsigned saw_shutdown_write : 1; /* Socket saw a SHUT_WR */
501 unsigned saw_reuseaddr : 1; /* Socket saw SO_REUSEADDR call */
502 unsigned listener : 1; /* listen called */
503 unsigned connect_state : 2;
506 async_io (0), saw_shutdown_read (0), saw_shutdown_write (0),
507 listener (0), connect_state (unconnected)
514 int get_socket () { return (int) get_handle(); }
515 fhandler_socket *is_socket () { return this; }
517 IMPLEMENT_STATUS_FLAG (bool, async_io)
518 IMPLEMENT_STATUS_FLAG (bool, saw_shutdown_read)
519 IMPLEMENT_STATUS_FLAG (bool, saw_shutdown_write)
520 IMPLEMENT_STATUS_FLAG (bool, saw_reuseaddr)
521 IMPLEMENT_STATUS_FLAG (bool, listener)
522 IMPLEMENT_STATUS_FLAG (conn_state, connect_state)
524 int bind (const struct sockaddr *name, int namelen);
525 int connect (const struct sockaddr *name, int namelen);
526 int listen (int backlog);
527 int accept4 (struct sockaddr *peer, int *len, int flags);
528 int getsockname (struct sockaddr *name, int *namelen);
529 int getpeername (struct sockaddr *name, int *namelen);
530 int getpeereid (pid_t *pid, __uid32_t *euid, __gid32_t *egid);
532 int open (int flags, mode_t mode = 0);
533 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
534 ssize_t __stdcall readv (const struct iovec *, int iovcnt, ssize_t tot = -1);
535 inline ssize_t recv_internal (struct _WSAMSG *wsamsg);
536 ssize_t recvfrom (void *ptr, size_t len, int flags,
537 struct sockaddr *from, int *fromlen);
538 ssize_t recvmsg (struct msghdr *msg, int flags);
540 ssize_t __stdcall write (const void *ptr, size_t len);
541 ssize_t __stdcall writev (const struct iovec *, int iovcnt, ssize_t tot = -1);
542 inline ssize_t send_internal (struct _WSAMSG *wsamsg, int flags);
543 ssize_t sendto (const void *ptr, size_t len, int flags,
544 const struct sockaddr *to, int tolen);
545 ssize_t sendmsg (const struct msghdr *msg, int flags);
547 int ioctl (unsigned int cmd, void *);
548 int fcntl (int cmd, void *);
549 _off64_t lseek (_off64_t, int) { return 0; }
550 int shutdown (int how);
552 void hclose (HANDLE) {close ();}
553 int dup (fhandler_base *child);
555 void set_close_on_exec (bool val);
556 int fixup_before_fork_exec (DWORD);
557 void fixup_after_fork (HANDLE);
558 void fixup_after_exec ();
559 char *get_proc_fd_name (char *buf);
561 select_record *select_read (select_stuff *);
562 select_record *select_write (select_stuff *);
563 select_record *select_except (select_stuff *);
564 void set_addr_family (int af) {addr_family = af;}
565 int get_addr_family () {return addr_family;}
566 void set_socket_type (int st) { type = st;}
567 int get_socket_type () {return type;}
568 void set_sun_path (const char *path);
569 char *get_sun_path () {return sun_path;}
570 void set_peer_sun_path (const char *path);
571 char *get_peer_sun_path () {return peer_sun_path;}
573 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
574 int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2)));
575 int __stdcall fchmod (mode_t mode) __attribute__ ((regparm (1)));
576 int __stdcall fchown (__uid32_t uid, __gid32_t gid) __attribute__ ((regparm (2)));
577 int __stdcall facl (int, int, __acl32 *) __attribute__ ((regparm (3)));
578 int __stdcall link (const char *) __attribute__ ((regparm (2)));
579 size_t size () const { return sizeof (*this);}
582 class fhandler_base_overlapped: public fhandler_base
587 overlapped_unknown = 0,
590 overlapped_nonblocking_no_data,
594 OVERLAPPED io_status;
595 OVERLAPPED *overlapped;
596 size_t max_atomic_write;
598 wait_return __stdcall wait_overlapped (bool, bool, DWORD *, bool, DWORD = 0) __attribute__ ((regparm (3)));
599 int __stdcall setup_overlapped () __attribute__ ((regparm (1)));
600 void __stdcall destroy_overlapped () __attribute__ ((regparm (1)));
601 virtual void __stdcall raw_read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
602 virtual ssize_t __stdcall raw_write (const void *ptr, size_t len) __attribute__ ((regparm (3)));
603 OVERLAPPED *&get_overlapped () {return overlapped;}
604 OVERLAPPED *get_overlapped_buffer () {return &io_status;}
605 void set_overlapped (OVERLAPPED *ov) {overlapped = ov;}
606 fhandler_base_overlapped (): io_pending (false), overlapped (NULL), max_atomic_write (0)
608 memset (&io_status, 0, sizeof io_status);
610 bool __stdcall has_ongoing_io () __attribute__ ((regparm (1)));
612 void fixup_after_fork (HANDLE);
613 void fixup_after_exec ();
616 int dup (fhandler_base *child);
617 virtual size_t size () const { return sizeof (*this);} /* probably not needed */
620 class fhandler_pipe: public fhandler_base_overlapped
628 bool ispipe() const { return true; }
630 void set_popen_pid (pid_t pid) {popen_pid = pid;}
631 pid_t get_popen_pid () const {return popen_pid;}
632 _off64_t lseek (_off64_t offset, int whence);
633 select_record *select_read (select_stuff *);
634 select_record *select_write (select_stuff *);
635 select_record *select_except (select_stuff *);
636 char *get_proc_fd_name (char *buf);
637 int open (int flags, mode_t mode = 0);
638 int dup (fhandler_base *child);
639 int ioctl (unsigned int cmd, void *);
640 int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2)));
641 int __stdcall fadvise (_off64_t, _off64_t, int) __attribute__ ((regparm (3)));
642 int __stdcall ftruncate (_off64_t, bool) __attribute__ ((regparm (3)));
643 int init (HANDLE, DWORD, mode_t);
644 static int create (fhandler_pipe *[2], unsigned, int);
645 static int create_selectable (LPSECURITY_ATTRIBUTES, HANDLE&, HANDLE&, DWORD, const char * = NULL);
646 friend class fhandler_fifo;
647 size_t size () const { return sizeof (*this);}
650 class fhandler_fifo: public fhandler_base_overlapped
655 fifo_wait_for_client,
656 fifo_wait_for_server,
657 fifo_wait_for_next_client,
663 fifo_state wait_state;
665 HANDLE open_nonserver (const char *, unsigned, LPSECURITY_ATTRIBUTES);
666 bool wait (bool) __attribute__ ((regparm (1)));
667 char *fifo_name (char *) __attribute__ ((regparm (2)));
670 void __stdcall raw_read (void *, size_t&) __attribute__ ((regparm (3)));
671 ssize_t __stdcall raw_write (const void *, size_t) __attribute__ ((regparm (3)));
672 int open (int, mode_t);
674 int dup (fhandler_base *child);
675 bool isfifo () const { return true; }
676 void set_close_on_exec (bool val);
677 int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2)));
678 select_record *select_read (select_stuff *);
679 select_record *select_write (select_stuff *);
680 select_record *select_except (select_stuff *);
681 size_t size () const { return sizeof (*this);}
684 class fhandler_mailslot : public fhandler_base_overlapped
686 POBJECT_ATTRIBUTES get_object_attr (OBJECT_ATTRIBUTES &, PUNICODE_STRING, int);
688 fhandler_mailslot ();
689 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
690 int open (int flags, mode_t mode = 0);
691 ssize_t __stdcall raw_write (const void *, size_t) __attribute__ ((regparm (3)));
692 int ioctl (unsigned int cmd, void *);
693 select_record *select_read (select_stuff *);
694 size_t size () const { return sizeof (*this);}
697 class fhandler_dev_raw: public fhandler_base
706 unsigned lastblk_to_read : 1;
708 status_flags () : lastblk_to_read (0) {}
711 IMPLEMENT_STATUS_FLAG (bool, lastblk_to_read)
716 ~fhandler_dev_raw ();
718 int open (int flags, mode_t mode = 0);
720 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
722 int dup (fhandler_base *child);
723 int ioctl (unsigned int cmd, void *buf);
725 void fixup_after_fork (HANDLE);
726 void fixup_after_exec ();
727 size_t size () const { return sizeof (*this);}
730 #define MAX_PARTITIONS 15
735 HANDLE hdl[MAX_PARTITIONS];
738 class fhandler_dev_floppy: public fhandler_dev_raw
742 unsigned long bytes_per_sector;
746 unsigned eom_detected : 1;
748 status_flags () : eom_detected (0) {}
751 IMPLEMENT_STATUS_FLAG (bool, eom_detected)
753 inline _off64_t get_current_position ();
754 int get_drive_info (struct hd_geometry *geo);
756 int lock_partition (DWORD to_write);
758 BOOL write_file (const void *buf, DWORD to_write, DWORD *written, int *err);
759 BOOL read_file (void *buf, DWORD to_read, DWORD *read, int *err);
762 fhandler_dev_floppy ();
764 int open (int flags, mode_t mode = 0);
766 int dup (fhandler_base *child);
767 void __stdcall raw_read (void *ptr, size_t& ulen) __attribute__ ((regparm (3)));
768 ssize_t __stdcall raw_write (const void *ptr, size_t ulen) __attribute__ ((regparm (3)));
769 _off64_t lseek (_off64_t offset, int whence);
770 int ioctl (unsigned int cmd, void *buf);
771 size_t size () const { return sizeof (*this);}
774 class fhandler_dev_tape: public fhandler_dev_raw
779 bool is_rewind_device () { return get_minor () < 128; }
780 unsigned int driveno () { return (unsigned int) get_minor () & 0x7f; }
783 inline bool _lock (bool);
784 inline int unlock (int ret = 0);
787 fhandler_dev_tape ();
789 int open (int flags, mode_t mode = 0);
790 virtual int close ();
792 void __stdcall raw_read (void *ptr, size_t& ulen) __attribute__ ((regparm (3)));
793 ssize_t __stdcall raw_write (const void *ptr, size_t ulen) __attribute__ ((regparm (3)));
795 virtual _off64_t lseek (_off64_t offset, int whence);
797 virtual int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
799 virtual int dup (fhandler_base *child);
800 virtual void fixup_after_fork (HANDLE parent);
801 virtual void set_close_on_exec (bool val);
802 virtual int ioctl (unsigned int cmd, void *buf);
803 size_t size () const { return sizeof (*this);}
806 /* Standard disk file */
808 class fhandler_disk_file: public fhandler_base
811 int readdir_helper (DIR *, dirent *, DWORD, DWORD, PUNICODE_STRING fname) __attribute__ ((regparm (3)));
816 fhandler_disk_file ();
817 fhandler_disk_file (path_conv &pc);
819 int open (int flags, mode_t mode);
821 int dup (fhandler_base *child);
822 void fixup_after_fork (HANDLE parent);
823 int lock (int, struct __flock64 *);
824 bool isdevice () const { return false; }
825 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
826 int __stdcall fchmod (mode_t mode) __attribute__ ((regparm (1)));
827 int __stdcall fchown (__uid32_t uid, __gid32_t gid) __attribute__ ((regparm (2)));
828 int __stdcall facl (int, int, __acl32 *) __attribute__ ((regparm (3)));
829 ssize_t __stdcall fgetxattr (const char *, void *, size_t) __attribute__ ((regparm (3)));
830 int __stdcall fsetxattr (const char *, const void *, size_t, int) __attribute__ ((regparm (3)));
831 int __stdcall fadvise (_off64_t, _off64_t, int) __attribute__ ((regparm (3)));
832 int __stdcall ftruncate (_off64_t, bool) __attribute__ ((regparm (3)));
833 int __stdcall link (const char *) __attribute__ ((regparm (2)));
834 int __stdcall utimens (const struct timespec *) __attribute__ ((regparm (2)));
835 int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2)));
837 HANDLE mmap (caddr_t *addr, size_t len, int prot, int flags, _off64_t off);
838 int munmap (HANDLE h, caddr_t addr, size_t len);
839 int msync (HANDLE h, caddr_t addr, size_t len, int flags);
840 bool fixup_mmap_after_fork (HANDLE h, int prot, int flags,
841 _off64_t offset, DWORD size, void *address);
842 int mkdir (mode_t mode);
844 DIR *opendir (int fd) __attribute__ ((regparm (2)));
845 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
846 long telldir (DIR *);
847 void seekdir (DIR *, long);
848 void rewinddir (DIR *);
849 int closedir (DIR *);
851 ssize_t __stdcall pread (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
852 ssize_t __stdcall pwrite (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
853 size_t size () const { return sizeof (*this);}
856 class fhandler_cygdrive: public fhandler_disk_file
860 DRVSZ = sizeof ("x:\\")
864 char pdrive_buf[1 + (2 * 26 * DRVSZ)];
867 fhandler_cygdrive ();
868 int open (int flags, mode_t mode);
870 DIR *opendir (int fd) __attribute__ ((regparm (2)));
871 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
872 void rewinddir (DIR *);
873 int closedir (DIR *);
874 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
875 size_t size () const { return sizeof (*this);}
878 class fhandler_serial: public fhandler_base
881 size_t vmin_; /* from termios */
882 unsigned int vtime_; /* from termios */
884 int rts; /* for Windows 9x purposes only */
885 int dtr; /* for Windows 9x purposes only */
888 int overlapped_armed;
889 OVERLAPPED io_status;
895 int open (int flags, mode_t mode);
897 int init (HANDLE h, DWORD a, mode_t flags);
898 void overlapped_setup ();
899 int dup (fhandler_base *child);
900 void __stdcall raw_read (void *ptr, size_t& ulen) __attribute__ ((regparm (3)));
901 ssize_t __stdcall raw_write (const void *ptr, size_t ulen) __attribute__ ((regparm (3)));
902 int tcsendbreak (int);
905 int ioctl (unsigned int cmd, void *);
906 int switch_modem_lines (int set, int clr);
907 int tcsetattr (int a, const struct termios *t);
908 int tcgetattr (struct termios *t);
909 _off64_t lseek (_off64_t, int) { return 0; }
911 bool is_tty () const { return true; }
912 void fixup_after_fork (HANDLE parent);
913 void fixup_after_exec ();
915 /* We maintain a pgrp so that tcsetpgrp and tcgetpgrp work, but we
916 don't use it for permissions checking. fhandler_pty_slave does
917 permission checking on pgrps. */
918 virtual int tcgetpgrp () { return pgrp_; }
919 virtual int tcsetpgrp (const pid_t pid) { pgrp_ = pid; return 0; }
920 select_record *select_read (select_stuff *);
921 select_record *select_write (select_stuff *);
922 select_record *select_except (select_stuff *);
923 size_t size () const { return sizeof (*this);}
926 #define acquire_output_mutex(ms) \
927 __acquire_output_mutex (__PRETTY_FUNCTION__, __LINE__, ms)
929 #define release_output_mutex() \
930 __release_output_mutex (__PRETTY_FUNCTION__, __LINE__)
934 class fhandler_termios: public fhandler_base
937 HANDLE output_handle;
938 virtual void doecho (const void *, DWORD) {};
939 virtual int accept_input () {return 1;};
942 virtual tty_min *tc () const {return _tc; }
943 fhandler_termios () :
946 need_fork_fixup (true);
948 HANDLE& get_output_handle () { return output_handle; }
949 line_edit_status line_edit (const char *rptr, int nread, termios&);
950 void set_output_handle (HANDLE h) { output_handle = h; }
951 void tcinit (bool force);
952 bool is_tty () const { return true; }
953 tty *get_ttyp () { return (tty *) tc (); }
956 int tcsetpgrp (int pid);
957 bg_check_types bg_check (int sig);
958 virtual DWORD __acquire_output_mutex (const char *fn, int ln, DWORD ms) {return 1;}
959 virtual void __release_output_mutex (const char *fn, int ln) {}
960 void echo_erase (int force = 0);
961 virtual _off64_t lseek (_off64_t, int);
962 virtual size_t size () const { return sizeof (*this);} /* probably not needed */
987 WORD default_color, underline_color, dim_color;
989 /* Used to determine if an input keystroke should be modified with META. */
997 bool saw_question_mark;
998 bool saw_greater_than_sign;
999 bool vt100_graphics_mode_G0;
1000 bool vt100_graphics_mode_G1;
1002 bool alternate_charset_active;
1004 char backspace_keycode;
1006 char my_title_buf [TITLESIZE + 1];
1008 WORD current_win32_attr;
1009 ansi_intensity intensity;
1010 bool underline, blink, reverse;
1013 /* saved cursor coordinates */
1030 COORD dwCursorPosition;
1034 COORD dwLastCursorPosition;
1035 COORD dwMousePosition; /* scroll-adjusted coord of mouse event */
1036 COORD dwLastMousePosition; /* scroll-adjusted coord of previous mouse event */
1037 DWORD dwLastButtonState; /* (not noting mouse wheel events) */
1038 int last_button_code; /* transformed mouse report button code */
1044 bool raw_win32_keyboard_mode;
1046 inline UINT get_console_cp ();
1047 DWORD con_to_str (char *d, int dlen, WCHAR w);
1048 DWORD str_to_con (mbtowc_p, const char *, PWCHAR d, const char *s, DWORD sz);
1049 void set_color (HANDLE);
1050 bool fillin_info (HANDLE);
1051 void set_default_attr ();
1053 friend class fhandler_console;
1056 /* This is a input and output console handle */
1057 class fhandler_console: public fhandler_termios
1060 struct console_state
1062 tty_min tty_min_state;
1063 dev_console dev_state;
1066 static const unsigned MAX_WRITE_CHARS;
1067 static console_state *shared_console_info;
1068 static bool invisible_console;
1070 /* Used when we encounter a truncated multi-byte sequence. The
1071 lead bytes are stored here and revisited in the next write call. */
1074 unsigned char buf[4]; /* Max len of valid UTF-8 sequence. */
1079 void set_default_attr ();
1081 void clear_screen (int, int, int, int);
1082 void scroll_screen (int, int, int, int, int, int);
1083 void cursor_set (bool, int, int);
1084 void cursor_get (int *, int *);
1085 void cursor_rel (int, int);
1086 inline void write_replacement_char ();
1087 inline bool write_console (PWCHAR, DWORD, DWORD&);
1088 const unsigned char *write_normal (unsigned const char*, unsigned const char *);
1089 void char_command (char);
1090 bool set_raw_win32_keyboard_mode (bool);
1091 int output_tcsetattr (int a, const struct termios *t);
1094 int igncr_enabled ();
1095 int input_tcsetattr (int a, const struct termios *t);
1096 void set_cursor_maybe ();
1097 static bool create_invisible_console (HWINSTA);
1098 static bool create_invisible_console_workaround ();
1099 static console_state *open_shared_console (HWND, HANDLE&, bool&);
1100 tty_min *tc () const {return &(shared_console_info->tty_min_state);}
1103 fhandler_console (fh_devices);
1104 static console_state *open_shared_console (HWND hw, HANDLE& h)
1106 bool createit = false;
1107 return open_shared_console (hw, h, createit);
1110 fhandler_console* is_console () { return this; }
1112 bool use_archetype () const {return true;}
1114 int open (int flags, mode_t mode);
1115 void open_setup (int flags);
1117 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1118 ssize_t __stdcall write (const void *ptr, size_t len);
1119 void doecho (const void *str, DWORD len) { (void) write (str, len); }
1123 int tcsetattr (int a, const struct termios *t);
1124 int tcgetattr (struct termios *t);
1126 int ioctl (unsigned int cmd, void *);
1127 int init (HANDLE, DWORD, mode_t);
1128 bool mouse_aware (MOUSE_EVENT_RECORD& mouse_event);
1129 bool focus_aware () {return shared_console_info->dev_state.use_focus;}
1131 select_record *select_read (select_stuff *);
1132 select_record *select_write (select_stuff *);
1133 select_record *select_except (select_stuff *);
1134 void fixup_after_fork_exec (bool);
1135 void fixup_after_exec () {fixup_after_fork_exec (true);}
1136 void fixup_after_fork (HANDLE) {fixup_after_fork_exec (false);}
1137 void set_close_on_exec (bool val);
1138 void set_input_state ();
1139 void send_winch_maybe ();
1140 void get_tty_stuff ();
1142 static bool need_invisible ();
1143 static bool has_a () {return !invisible_console;}
1144 size_t size () const { return sizeof (*this);}
1145 friend tty_min * tty_list::get_cttyp ();
1148 class fhandler_pty_common: public fhandler_termios
1151 fhandler_pty_common ()
1152 : fhandler_termios (),
1153 output_mutex (NULL),
1154 input_mutex (NULL), input_available_event (NULL)
1156 pc.file_attributes (FILE_ATTRIBUTE_NORMAL);
1158 HANDLE output_mutex, input_mutex;
1159 HANDLE input_available_event;
1161 DWORD __acquire_output_mutex (const char *fn, int ln, DWORD ms);
1162 void __release_output_mutex (const char *fn, int ln);
1165 _off64_t lseek (_off64_t, int);
1166 void set_close_on_exec (bool val);
1167 select_record *select_read (select_stuff *);
1168 select_record *select_write (select_stuff *);
1169 select_record *select_except (select_stuff *);
1170 virtual size_t size () const { return sizeof (*this);} /* probably not needed */
1173 class fhandler_pty_slave: public fhandler_pty_common
1175 HANDLE inuse; // used to indicate that a tty is in use
1177 /* Helper functions for fchmod and fchown. */
1178 bool fch_open_handles ();
1179 int fch_set_sd (security_descriptor &sd, bool chown);
1180 void fch_close_handles ();
1184 fhandler_pty_slave (int);
1186 bool use_archetype () const {return true;}
1187 int open (int flags, mode_t mode = 0);
1188 void open_setup (int flags);
1189 ssize_t __stdcall write (const void *ptr, size_t len);
1190 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1191 int init (HANDLE, DWORD, mode_t);
1193 int tcsetattr (int a, const struct termios *t);
1194 int tcgetattr (struct termios *t);
1196 int ioctl (unsigned int cmd, void *);
1199 int dup (fhandler_base *child);
1200 void fixup_after_fork (HANDLE parent);
1201 void fixup_after_exec ();
1203 select_record *select_read (select_stuff *);
1205 virtual char const *ttyname () { return pc.dev.name; }
1206 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1207 int __stdcall fchmod (mode_t mode) __attribute__ ((regparm (1)));
1208 int __stdcall fchown (__uid32_t uid, __gid32_t gid) __attribute__ ((regparm (2)));
1209 size_t size () const { return sizeof (*this);}
1212 class fhandler_pty_master: public fhandler_pty_common
1214 int pktmode; // non-zero if pty in a packet mode.
1215 HANDLE master_ctl; // Control socket for handle duplication
1216 cygthread *master_thread; // Master control thread
1219 int need_nl; // Next read should start with \n
1220 DWORD dwProcessId; // Owner of master handles
1221 HANDLE from_master, to_master;
1224 fhandler_pty_master ();
1226 virtual bool use_archetype () const {return true;}
1227 DWORD pty_master_thread ();
1228 int process_slave_output (char *buf, size_t len, int pktmode_on);
1229 void doecho (const void *str, DWORD len);
1230 int accept_input ();
1231 int open (int flags, mode_t mode = 0);
1232 ssize_t __stdcall write (const void *ptr, size_t len);
1233 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1237 int tcsetattr (int a, const struct termios *t);
1238 int tcgetattr (struct termios *t);
1240 int ioctl (unsigned int cmd, void *);
1246 int dup (fhandler_base *);
1247 void fixup_after_fork (HANDLE parent);
1248 void fixup_after_exec ();
1250 size_t size () const { return sizeof (*this);}
1253 class fhandler_dev_null: public fhandler_base
1256 fhandler_dev_null ();
1258 select_record *select_read (select_stuff *);
1259 select_record *select_write (select_stuff *);
1260 select_record *select_except (select_stuff *);
1261 size_t size () const { return sizeof (*this);}
1264 class fhandler_dev_zero: public fhandler_base
1267 fhandler_dev_zero ();
1268 int open (int flags, mode_t mode = 0);
1269 ssize_t __stdcall write (const void *ptr, size_t len);
1270 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1271 _off64_t lseek (_off64_t offset, int whence);
1273 virtual HANDLE mmap (caddr_t *addr, size_t len, int prot,
1274 int flags, _off64_t off);
1275 virtual int munmap (HANDLE h, caddr_t addr, size_t len);
1276 virtual int msync (HANDLE h, caddr_t addr, size_t len, int flags);
1277 virtual bool fixup_mmap_after_fork (HANDLE h, int prot, int flags,
1278 _off64_t offset, DWORD size,
1280 size_t size () const { return sizeof (*this);}
1283 class fhandler_dev_random: public fhandler_base
1286 HCRYPTPROV crypt_prov;
1288 _off64_t dummy_offset;
1290 bool crypt_gen_random (void *ptr, size_t len);
1291 int pseudo_write (const void *ptr, size_t len);
1292 int pseudo_read (void *ptr, size_t len);
1295 fhandler_dev_random ();
1296 int open (int flags, mode_t mode = 0);
1297 ssize_t __stdcall write (const void *ptr, size_t len);
1298 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1299 _off64_t lseek (_off64_t offset, int whence);
1301 int dup (fhandler_base *child);
1302 size_t size () const { return sizeof (*this);}
1305 class fhandler_dev_mem: public fhandler_base
1312 fhandler_dev_mem ();
1313 ~fhandler_dev_mem ();
1315 int open (int flags, mode_t mode = 0);
1316 ssize_t __stdcall write (const void *ptr, size_t ulen);
1317 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1318 _off64_t lseek (_off64_t offset, int whence);
1319 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1321 HANDLE mmap (caddr_t *addr, size_t len, int prot, int flags, _off64_t off);
1322 int munmap (HANDLE h, caddr_t addr, size_t len);
1323 int msync (HANDLE h, caddr_t addr, size_t len, int flags);
1324 bool fixup_mmap_after_fork (HANDLE h, int prot, int flags,
1325 _off64_t offset, DWORD size, void *address);
1326 size_t size () const { return sizeof (*this);}
1329 class fhandler_dev_clipboard: public fhandler_base
1336 fhandler_dev_clipboard ();
1337 int is_windows () { return 1; }
1338 int open (int flags, mode_t mode = 0);
1339 ssize_t __stdcall write (const void *ptr, size_t len);
1340 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1341 _off64_t lseek (_off64_t offset, int whence);
1344 int dup (fhandler_base *child);
1345 void fixup_after_exec ();
1346 size_t size () const { return sizeof (*this);}
1349 class fhandler_windows: public fhandler_base
1352 HWND hWnd_; // the window whose messages are to be retrieved by read() call
1353 int method_; // write method (Post or Send)
1355 fhandler_windows ();
1356 int is_windows () { return 1; }
1357 int open (int flags, mode_t mode = 0);
1358 ssize_t __stdcall write (const void *ptr, size_t len);
1359 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1360 int ioctl (unsigned int cmd, void *);
1361 _off64_t lseek (_off64_t, int) { return 0; }
1362 int close () { return 0; }
1364 void set_close_on_exec (bool val);
1365 void fixup_after_fork (HANDLE parent);
1366 select_record *select_read (select_stuff *);
1367 select_record *select_write (select_stuff *);
1368 select_record *select_except (select_stuff *);
1369 size_t size () const { return sizeof (*this);}
1372 class fhandler_dev_dsp: public fhandler_base
1383 Audio_out *audio_out_;
1384 Audio_in *audio_in_;
1386 fhandler_dev_dsp ();
1388 int open (int flags, mode_t mode = 0);
1389 ssize_t __stdcall write (const void *ptr, size_t len);
1390 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1391 int ioctl (unsigned int cmd, void *);
1392 _off64_t lseek (_off64_t, int);
1394 void fixup_after_fork (HANDLE parent);
1395 void fixup_after_exec ();
1397 void close_audio_in ();
1398 void close_audio_out (bool immediately = false);
1399 bool use_archetype () const {return true;}
1400 size_t size () const { return sizeof (*this);}
1403 class fhandler_virtual : public fhandler_base
1409 int fileid; // unique within each class
1412 fhandler_virtual ();
1413 virtual ~fhandler_virtual();
1415 virtual virtual_ftype_t exists();
1416 DIR *opendir (int fd) __attribute__ ((regparm (2)));
1417 long telldir (DIR *);
1418 void seekdir (DIR *, long);
1419 void rewinddir (DIR *);
1420 int closedir (DIR *);
1421 ssize_t __stdcall write (const void *ptr, size_t len);
1422 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1423 _off64_t lseek (_off64_t, int);
1424 int dup (fhandler_base *child);
1425 int open (int flags, mode_t mode = 0);
1427 int __stdcall fstat (struct stat *buf) __attribute__ ((regparm (2)));
1428 int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2)));
1429 int __stdcall fchmod (mode_t mode) __attribute__ ((regparm (1)));
1430 int __stdcall fchown (__uid32_t uid, __gid32_t gid) __attribute__ ((regparm (2)));
1431 int __stdcall facl (int, int, __acl32 *) __attribute__ ((regparm (3)));
1432 virtual bool fill_filebuf ();
1433 char *get_filebuf () { return filebuf; }
1434 void fixup_after_exec ();
1435 virtual size_t size () const { return sizeof (*this);}
1438 class fhandler_proc: public fhandler_virtual
1442 virtual_ftype_t exists();
1443 DIR *opendir (int fd) __attribute__ ((regparm (2)));
1444 int closedir (DIR *);
1445 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
1446 static fh_devices get_proc_fhandler (const char *path);
1448 int open (int flags, mode_t mode = 0);
1449 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1450 bool fill_filebuf ();
1451 virtual size_t size () const { return sizeof (*this);}
1454 class fhandler_procsys: public fhandler_virtual
1457 fhandler_procsys ();
1458 virtual_ftype_t exists(struct __stat64 *buf) __attribute__ ((regparm (2)));
1459 virtual_ftype_t exists();
1460 DIR *opendir (int fd) __attribute__ ((regparm (2)));
1461 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
1462 long telldir (DIR *);
1463 void seekdir (DIR *, long);
1464 int closedir (DIR *);
1465 int open (int flags, mode_t mode = 0);
1467 void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
1468 ssize_t __stdcall write (const void *ptr, size_t len);
1469 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1470 bool fill_filebuf ();
1471 size_t size () const { return sizeof (*this);}
1474 class fhandler_procsysvipc: public fhandler_proc
1478 fhandler_procsysvipc ();
1479 virtual_ftype_t exists();
1480 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
1481 int open (int flags, mode_t mode = 0);
1482 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1483 bool fill_filebuf ();
1484 size_t size () const { return sizeof (*this);}
1487 class fhandler_netdrive: public fhandler_virtual
1490 fhandler_netdrive ();
1491 virtual_ftype_t exists();
1492 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
1493 void seekdir (DIR *, long);
1494 void rewinddir (DIR *);
1495 int closedir (DIR *);
1496 int open (int flags, mode_t mode = 0);
1497 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1498 size_t size () const { return sizeof (*this);}
1501 class fhandler_registry: public fhandler_proc
1504 wchar_t *value_name;
1508 fhandler_registry ();
1509 void set_name (path_conv &pc);
1510 virtual_ftype_t exists();
1511 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
1512 long telldir (DIR *);
1513 void seekdir (DIR *, long);
1514 void rewinddir (DIR *);
1515 int closedir (DIR *);
1517 int open (int flags, mode_t mode = 0);
1518 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1519 bool fill_filebuf ();
1521 int dup (fhandler_base *child);
1522 size_t size () const { return sizeof (*this);}
1526 class fhandler_process: public fhandler_proc
1530 fhandler_process ();
1531 virtual_ftype_t exists();
1532 DIR *opendir (int fd) __attribute__ ((regparm (2)));
1533 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
1534 int open (int flags, mode_t mode = 0);
1535 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1536 bool fill_filebuf ();
1537 size_t size () const { return sizeof (*this);}
1540 class fhandler_procnet: public fhandler_proc
1544 fhandler_procnet ();
1545 virtual_ftype_t exists();
1546 int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
1547 int open (int flags, mode_t mode = 0);
1548 int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
1549 bool fill_filebuf ();
1550 size_t size () const { return sizeof (*this);}
1553 struct fhandler_nodevice: public fhandler_base
1555 fhandler_nodevice ();
1556 int open (int flags, mode_t mode = 0);
1557 // int __stdcall fstat (struct __stat64 *buf, path_conv *);
1560 #define report_tty_counts(fh, call, use_op) \
1561 termios_printf ("%s %s, %susecount %d",\
1562 fh->ttyname (), call,\
1563 use_op, ((fhandler_pty_slave *) (fh->archetype ?: fh))->usecount);
1567 char __base[sizeof (fhandler_base)];
1568 char __console[sizeof (fhandler_console)];
1569 char __cygdrive[sizeof (fhandler_cygdrive)];
1570 char __dev_clipboard[sizeof (fhandler_dev_clipboard)];
1571 char __dev_dsp[sizeof (fhandler_dev_dsp)];
1572 char __dev_floppy[sizeof (fhandler_dev_floppy)];
1573 char __dev_mem[sizeof (fhandler_dev_mem)];
1574 char __dev_null[sizeof (fhandler_dev_null)];
1575 char __dev_random[sizeof (fhandler_dev_random)];
1576 char __dev_raw[sizeof (fhandler_dev_raw)];
1577 char __dev_tape[sizeof (fhandler_dev_tape)];
1578 char __dev_zero[sizeof (fhandler_dev_zero)];
1579 char __disk_file[sizeof (fhandler_disk_file)];
1580 char __fifo[sizeof (fhandler_fifo)];
1581 char __mailslot[sizeof (fhandler_mailslot)];
1582 char __netdrive[sizeof (fhandler_netdrive)];
1583 char __nodevice[sizeof (fhandler_nodevice)];
1584 char __pipe[sizeof (fhandler_pipe)];
1585 char __proc[sizeof (fhandler_proc)];
1586 char __process[sizeof (fhandler_process)];
1587 char __procnet[sizeof (fhandler_procnet)];
1588 char __procsys[sizeof (fhandler_procsys)];
1589 char __procsysvipc[sizeof (fhandler_procsysvipc)];
1590 char __pty_master[sizeof (fhandler_pty_master)];
1591 char __registry[sizeof (fhandler_registry)];
1592 char __serial[sizeof (fhandler_serial)];
1593 char __socket[sizeof (fhandler_socket)];
1594 char __termios[sizeof (fhandler_termios)];
1595 char __pty_common[sizeof (fhandler_pty_common)];
1596 char __pty_slave[sizeof (fhandler_pty_slave)];
1597 char __virtual[sizeof (fhandler_virtual)];
1598 char __windows[sizeof (fhandler_windows)];
1600 #endif /* _FHANDLER_H_ */