* fhandler.cc (fhandler_base::write): Use bool parameter in calls to

set_did_lseek.
	(fhandler_base::fhandler_base): Accomodate new status and open_status
	constructor.
	* fhandler.h: Remove status bit enumerator.
	(FHDEVN): Remove.
	(FHISSETF): Remove.
	(FHSETF): Remove.
	(FHCLEARF): Remove.
	(FHCONDSETF): Remove.
	(FHSTATOFF): Remove.
	(UNCONNECTED, CONNECT_PENDING, CONNECTED): Substitute by enum
	connect_state.
	(fhandler_base::status): Define as bitfield struct type status_flags.
	Remove unused flags entirely.  Accomodate all status access methods.
	(open_status): Define as bitfield struct type status_flags.
	(fhandler_socket): Move socket related status bits to here.  Redefine
	had_connect_or_listen to be part of these status bits.  Accomodate
	related access methods.
	* fhandler_disk_file.cc (fhandler_base::fstat_helper): Use pc.issymlink
	instead of dropped method get_symlink_p.
	(fhandler_base::open_fs): Remove setting dropped status flags.
	* fhandler_socket.cc: Use values from enum connect_state throughout.
	(fhandler_socket::fhandler_socket): Initialize status bits.
	* fhandler_virtual.cc (fhandler_virtual::open): Remove setting dropped
	status flags.
	* net.cc: Use values from enum connect_state throughout.
	* select.cc: Ditto.
	* shared_info.h: Protect struct console_state using _FHANDLER_H_
	instead of FHDEVN.
This commit is contained in:
Corinna Vinschen 2004-04-09 08:43:29 +00:00
parent 00dd058f7e
commit b79f85c28b
9 changed files with 138 additions and 132 deletions

View File

@ -1,3 +1,36 @@
2004-04-09 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (fhandler_base::write): Use bool parameter in calls to
set_did_lseek.
(fhandler_base::fhandler_base): Accomodate new status and open_status
constructor.
* fhandler.h: Remove status bit enumerator.
(FHDEVN): Remove.
(FHISSETF): Remove.
(FHSETF): Remove.
(FHCLEARF): Remove.
(FHCONDSETF): Remove.
(FHSTATOFF): Remove.
(UNCONNECTED, CONNECT_PENDING, CONNECTED): Substitute by enum
connect_state.
(fhandler_base::status): Define as bitfield struct type status_flags.
Remove unused flags entirely. Accomodate all status access methods.
(open_status): Define as bitfield struct type status_flags.
(fhandler_socket): Move socket related status bits to here. Redefine
had_connect_or_listen to be part of these status bits. Accomodate
related access methods.
* fhandler_disk_file.cc (fhandler_base::fstat_helper): Use pc.issymlink
instead of dropped method get_symlink_p.
(fhandler_base::open_fs): Remove setting dropped status flags.
* fhandler_socket.cc: Use values from enum connect_state throughout.
(fhandler_socket::fhandler_socket): Initialize status bits.
* fhandler_virtual.cc (fhandler_virtual::open): Remove setting dropped
status flags.
* net.cc: Use values from enum connect_state throughout.
* select.cc: Ditto.
* shared_info.h: Protect struct console_state using _FHANDLER_H_
instead of FHDEVN.
2004-04-09 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_file_attribute): Fix conditional.

View File

@ -678,7 +678,7 @@ fhandler_base::write (const void *ptr, size_t len)
DWORD size_high = 0;
LONG pos_high = 0;
set_did_lseek (0); /* don't do it again */
set_did_lseek (false); /* don't do it again */
actual_length = GetFileSize (get_output_handle (), &size_high);
actual_length += ((_off64_t) size_high) << 32;
@ -970,7 +970,7 @@ fhandler_base::lseek (_off64_t offset, int whence)
/* When next we write(), we will check to see if *this* seek went beyond
the end of the file, and back-seek and fill with zeros if so - DJ */
set_did_lseek ();
set_did_lseek (true);
/* If this was a SEEK_CUR with offset 0, we still might have
readahead that we have to take into account when calculating
@ -1256,9 +1256,9 @@ fhandler_base::operator delete (void *p)
}
/* Normal I/O constructor */
fhandler_base::fhandler_base ():
status (0),
query_open (no_query),
fhandler_base::fhandler_base () :
status (),
open_status (),
access (0),
io_handle (NULL),
namehash (0),
@ -1268,7 +1268,6 @@ fhandler_base::fhandler_base ():
raixget (0),
raixput (0),
rabuflen (0),
open_status (0),
fs_flags (0),
read_state (NULL),
archetype (NULL),

View File

@ -11,42 +11,6 @@ details. */
#ifndef _FHANDLER_H_
#define _FHANDLER_H_
enum
{
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_ENC = 0x00080000, /* native path is encoded */
FH_SYMLINK = 0x00100000, /* is a symlink */
FH_EXECABL = 0x00200000, /* file looked like it would run:
* ends in .exe or .bat or begins with #! */
FH_LSEEKED = 0x00400000, /* set when lseek is called as a flag that
* _write should check if we've moved beyond
* EOF, zero filling or making file sparse
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 */
};
#define FHDEVN(n) (n)
#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)
#define FHSTATOFF 0
/* fcntl flags used only internaly. */
#define O_NOSYMLINK 0x080000
#define O_DIROPEN 0x100000
@ -60,10 +24,6 @@ enum
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))
@ -76,6 +36,13 @@ typedef struct __DIR DIR;
struct dirent;
struct iovec;
enum connect_state
{
unconnected = 0,
connect_pending = 1,
connected = 2
};
enum line_edit_status
{
line_edit_ok = 0,
@ -103,9 +70,37 @@ class fhandler_base
{
friend class dtable;
friend void close_all_files ();
protected:
DWORD status;
unsigned query_open : 2;
struct status_flags
{
unsigned rbinary : 1; /* binary read mode */
unsigned rbinset : 1; /* binary read mode explicitly set */
unsigned wbinary : 1; /* binary write mode */
unsigned wbinset : 1; /* binary write mode explicitly set */
unsigned no_handle : 1; /* No handle associated with fhandler. */
unsigned async_io : 1; /* async I/O */
unsigned uninterruptible_io : 1; /* Set if I/O should be uninterruptible. */
unsigned append_mode : 1; /* always append */
unsigned lseeked : 1; /* set when lseek is called as a flag that
_write should check if we've moved
beyond EOF, zero filling or making
file sparse if so. */
unsigned encoded : 1; /* native path is encoded */
unsigned query_open : 2; /* open file without requesting either
read or write access */
unsigned close_on_exec : 1; /* close-on-exec */
unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */
public:
status_flags () :
rbinary (0), rbinset (0), wbinary (0), wbinset (0), no_handle (0),
async_io (0), uninterruptible_io (0), append_mode (0), lseeked (0),
encoded (0), query_open (no_query), close_on_exec (0),
need_fork_fixup (0)
{}
} status, open_status;
private:
int access;
HANDLE io_handle;
@ -122,7 +117,6 @@ class fhandler_base
size_t raixput;
size_t rabuflen;
DWORD open_status;
DWORD fs_flags;
HANDLE read_state;
path_conv pc;
@ -155,8 +149,8 @@ class fhandler_base
int get_access () const { return access; }
void set_access (int x) { access = x; }
bool get_async () { return FHISSETF (ASYNC); }
void set_async (int x) { FHCONDSETF (x, ASYNC); }
bool get_async () { return status.async_io; }
void set_async (int x) { status.async_io = (x ? 1 : 0); }
int get_flags () { return openflags; }
void set_flags (int x, int supplied_bin = 0);
@ -164,36 +158,35 @@ class fhandler_base
bool is_nonblocking ();
void set_nonblocking (int yes);
bool get_w_binary () { return FHISSETF (WBINSET) ? FHISSETF (WBINARY) : 1; }
bool get_r_binary () { return FHISSETF (RBINSET) ? FHISSETF (RBINARY) : 1; }
bool get_w_binary () { return status.wbinset ? status.wbinary : 1; }
bool get_r_binary () { return status.rbinset ? status.rbinary : 1; }
bool get_w_binset () { return FHISSETF (WBINSET); }
bool get_r_binset () { return FHISSETF (RBINSET); }
bool get_w_binset () { return status.wbinset; }
bool get_r_binset () { return status.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); }
void set_w_binary (int b) {status.wbinary = (b ? 1 : 0); status.wbinset = 1;}
void set_r_binary (int b) {status.rbinary = (b ? 1 : 0); status.rbinset = 1;}
void clear_w_binary () { status.wbinary = 0; status.wbinset = 0; }
void clear_r_binary () { status.rbinary = 0; status.rbinset = 0; }
bool get_nohandle () { return FHISSETF (NOHANDLE); }
void set_nohandle (int x) { FHCONDSETF (x, NOHANDLE); }
bool get_nohandle () { return status.no_handle; }
void set_nohandle (bool x) { status.no_handle = x; }
void set_open_status () {open_status = status;}
DWORD get_open_status () {return open_status;}
void reset_to_open_binmode ()
{
set_flags ((get_flags () & ~(O_TEXT | O_BINARY))
| ((open_status & (FH_WBINARY | FH_RBINARY)
? O_BINARY : O_TEXT)));
| ((open_status.wbinary || open_status.rbinary)
? O_BINARY : O_TEXT));
}
int get_default_fmode (int flags);
bool get_r_no_interrupt () { return FHISSETF (NOEINTR); }
void set_r_no_interrupt (bool b) { FHCONDSETF (b, NOEINTR); }
bool get_r_no_interrupt () { return status.uninterruptible_io; }
void set_r_no_interrupt (bool b) { status.uninterruptible_io = b; }
bool get_close_on_exec () { return FHISSETF (CLOEXEC); }
int set_close_on_exec_flag (int b) { return FHCONDSETF (b, CLOEXEC); }
bool get_close_on_exec () { return status.close_on_exec; }
void set_close_on_exec_flag (int b) { status.close_on_exec = (b ? 1 : 0); }
LPSECURITY_ATTRIBUTES get_inheritance (bool all = 0)
{
@ -203,14 +196,14 @@ class fhandler_base
return get_close_on_exec () ? &sec_none_nih : &sec_none;
}
void set_did_lseek (int b = 1) { FHCONDSETF (b, LSEEKED); }
bool get_did_lseek () { return FHISSETF (LSEEKED); }
void set_did_lseek (bool b) { status.lseeked = b; }
bool get_did_lseek () { return status.lseeked; }
bool get_need_fork_fixup () { return FHISSETF (FFIXUP); }
void set_need_fork_fixup () { FHSETF (FFIXUP); }
bool get_need_fork_fixup () { return status.need_fork_fixup; }
void set_need_fork_fixup () { status.need_fork_fixup = 1; }
bool get_encoded () { return FHISSETF (ENC);}
void set_encoded () { FHSETF (ENC);}
bool get_encoded () { return status.encoded;}
void set_encoded () { status.encoded = 1;}
virtual void set_close_on_exec (int val);
@ -218,34 +211,15 @@ class fhandler_base
virtual void fixup_after_fork (HANDLE);
virtual void fixup_after_exec () {}
bool get_symlink_p () { return FHISSETF (SYMLINK); }
void set_symlink_p (int val) { FHCONDSETF (val, SYMLINK); }
void set_symlink_p () { FHSETF (SYMLINK); }
bool get_socket_p () { return FHISSETF (LOCAL); }
void set_socket_p (int val) { FHCONDSETF (val, LOCAL); }
void set_socket_p () { FHSETF (LOCAL); }
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); }
bool dont_care_if_execable () { return FHISSETF (DCEXEC); }
bool exec_state_isknown () { return FHISSETF (DCEXEC) || FHISSETF (EXECABL); }
bool get_append_p () { return FHISSETF (APPEND); }
void set_append_p (int val) { FHCONDSETF (val, APPEND); }
void set_append_p () { FHSETF (APPEND); }
bool get_append_p () { return status.append_mode; }
void set_append_p () { status.append_mode = 1; }
void set_fs_flags (DWORD flags) { fs_flags = flags; }
bool get_fs_flags (DWORD flagval = UINT32_MAX)
{ return (fs_flags & (flagval)); }
query_state get_query_open () { return (query_state) query_open; }
void set_query_open (query_state val) { query_open = val; }
query_state get_query_open () { return (query_state) status.query_open; }
void set_query_open (query_state val) { status.query_open = val; }
bool get_readahead_valid () { return raixget < ralen; }
int puts_readahead (const char *s, size_t len = (size_t) -1);
@ -381,7 +355,9 @@ class fhandler_socket: public fhandler_base
HANDLE secret_event;
struct _WSAPROTOCOL_INFOA *prot_info_ptr;
char *sun_path;
int had_connect_or_listen;
unsigned sock_saw_shut_rd : 1; /* Socket saw a SHUT_RD */
unsigned sock_saw_shut_wr : 1; /* Socket saw a SHUT_WR */
unsigned had_connect_or_listen : 2;
public:
fhandler_socket ();
@ -389,17 +365,20 @@ class fhandler_socket: public fhandler_base
int get_socket () { return (int) get_handle(); }
fhandler_socket *is_socket () { return this; }
bool saw_shutdown_read () const {return FHISSETF (SHUTRD);}
bool saw_shutdown_write () const {return FHISSETF (SHUTWR);}
bool saw_shutdown_read () const {return sock_saw_shut_rd;}
bool saw_shutdown_write () const {return sock_saw_shut_wr;}
void set_shutdown_read () {FHSETF (SHUTRD);}
void set_shutdown_write () {FHSETF (SHUTWR);}
void set_shutdown_read () { sock_saw_shut_rd = 1;}
void set_shutdown_write () { sock_saw_shut_wr = 1;}
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 get_connect_state () const { return had_connect_or_listen; }
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 (connect_state newstate)
{ had_connect_or_listen = newstate; }
connect_state get_connect_state () const
{ return (connect_state) had_connect_or_listen; }
int bind (const struct sockaddr *name, int namelen);
int connect (const struct sockaddr *name, int namelen);

View File

@ -296,7 +296,7 @@ fhandler_base::fstat_helper (struct __stat64 *buf,
&buf->st_mode, &buf->st_uid, &buf->st_gid))
{
/* If read-only attribute is set, modify ntsec return value */
if (pc.has_attribute (FILE_ATTRIBUTE_READONLY) && !get_symlink_p ())
if (pc.has_attribute (FILE_ATTRIBUTE_READONLY) && !pc.issymlink ())
buf->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
if (!(buf->st_mode & S_IFMT))
@ -339,7 +339,6 @@ fhandler_base::fstat_helper (struct __stat64 *buf,
if (ReadFile (get_handle (), magic, 3, &done, NULL)
&& has_exec_chars (magic, done))
{
set_execable_p ();
pc.set_exec ();
buf->st_mode |= STD_XBITS;
}
@ -416,9 +415,6 @@ fhandler_base::open_fs (int flags, mode_t mode)
set_file_attribute (has_acls (), get_win32_name (), mode);
set_fs_flags (pc.fs_flags ());
set_symlink_p (pc.issymlink ());
set_execable_p (pc.exec_state ());
set_socket_p (pc.issocket ());
out:
syscall_printf ("%d = fhandler_disk_file::open (%s, %p)", res,

View File

@ -121,8 +121,12 @@ get_inet_addr (const struct sockaddr *in, int inlen,
/**********************************************************************/
/* fhandler_socket */
fhandler_socket::fhandler_socket ()
: fhandler_base (), sun_path (NULL)
fhandler_socket::fhandler_socket () :
fhandler_base (),
sun_path (NULL),
sock_saw_shut_rd (0),
sock_saw_shut_wr (0),
had_connect_or_listen (unconnected)
{
set_need_fork_fixup ();
prot_info_ptr = (LPWSAPROTOCOL_INFOA) cmalloc (HEAP_BUF,
@ -545,9 +549,9 @@ fhandler_socket::connect (const struct sockaddr *name, int namelen)
err = WSAGetLastError ();
if (err == WSAEINPROGRESS || err == WSAEALREADY)
set_connect_state (CONNECT_PENDING);
set_connect_state (connect_pending);
else
set_connect_state (CONNECTED);
set_connect_state (connected);
return res;
}
@ -559,7 +563,7 @@ fhandler_socket::listen (int backlog)
if (res)
set_winsock_errno ();
else
set_connect_state (CONNECTED);
set_connect_state (connected);
return res;
}
@ -634,7 +638,7 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
((fhandler_socket *) res_fd)->set_sun_path (get_sun_path ());
((fhandler_socket *) res_fd)->set_addr_family (get_addr_family ());
((fhandler_socket *) res_fd)->set_socket_type (get_socket_type ());
((fhandler_socket *) res_fd)->set_connect_state (CONNECTED);
((fhandler_socket *) res_fd)->set_connect_state (connected);
res = res_fd;
}
else

View File

@ -210,11 +210,6 @@ fhandler_virtual::open (int flags, mode_t mode)
set_r_binary (1);
set_w_binary (1);
/* what to do about symlinks? */
set_symlink_p (false);
set_execable_p (not_executable);
set_socket_p (false);
set_flags ((flags & ~O_TEXT) | O_BINARY);
return 1;

View File

@ -1960,7 +1960,7 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser,
if (res_fd >= 0 && fdsock (res_fd, tcp_dev, res))
{
((fhandler_socket *) res_fd)->set_connect_state (CONNECTED);
((fhandler_socket *) res_fd)->set_connect_state (connected);
res = res_fd;
}
else
@ -1977,7 +1977,7 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser,
if (newfd >= 0 && fdsock (newfd, tcp_dev, fd2s))
{
*fd2p = newfd;
((fhandler_socket *) fd2p)->set_connect_state (CONNECTED);
((fhandler_socket *) fd2p)->set_connect_state (connected);
}
else
{
@ -2040,7 +2040,7 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser,
if (res_fd >= 0 && fdsock (res_fd, tcp_dev, res))
{
((fhandler_socket *) res_fd)->set_connect_state (CONNECTED);
((fhandler_socket *) res_fd)->set_connect_state (connected);
res = res_fd;
}
else
@ -2056,7 +2056,7 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser,
if (newfd >= 0 && fdsock (newfd, tcp_dev, fd2s))
{
((fhandler_socket *) fd2p)->set_connect_state (CONNECTED);
((fhandler_socket *) fd2p)->set_connect_state (connected);
*fd2p = newfd;
}
else
@ -2230,7 +2230,7 @@ socketpair (int family, int type, int protocol, int *sb)
((fhandler_socket *) sb0)->set_sun_path ("");
((fhandler_socket *) sb0)->set_addr_family (family);
((fhandler_socket *) sb0)->set_socket_type (type);
((fhandler_socket *) sb0)->set_connect_state (CONNECTED);
((fhandler_socket *) sb0)->set_connect_state (connected);
cygheap_fdnew sb1 (sb0, false);
@ -2239,7 +2239,7 @@ socketpair (int family, int type, int protocol, int *sb)
((fhandler_socket *) sb1)->set_sun_path ("");
((fhandler_socket *) sb1)->set_addr_family (family);
((fhandler_socket *) sb1)->set_socket_type (type);
((fhandler_socket *) sb1)->set_connect_state (CONNECTED);
((fhandler_socket *) sb1)->set_connect_state (connected);
sb[0] = sb0;
sb[1] = sb1;

View File

@ -335,7 +335,7 @@ set_bits (select_record *me, fd_set *readfds, fd_set *writefds,
{
UNIX_FD_SET (me->fd, writefds);
if (me->except_on_write && me->fh->is_socket ())
((fhandler_socket *) me->fh)->set_connect_state (CONNECTED);
((fhandler_socket *) me->fh)->set_connect_state (connected);
ready++;
}
if ((me->except_selected || me->except_on_write) && me->except_ready)
@ -344,7 +344,7 @@ set_bits (select_record *me, fd_set *readfds, fd_set *writefds,
{
UNIX_FD_SET (me->fd, writefds);
if (me->fh->is_socket ())
((fhandler_socket *) me->fh)->set_connect_state (CONNECTED);
((fhandler_socket *) me->fh)->set_connect_state (connected);
}
if (me->except_selected)
UNIX_FD_SET (me->fd, exceptfds);

View File

@ -188,7 +188,7 @@ void __stdcall memory_init ();
#define cygwin_shared_address ((void *) 0xa000000)
#ifdef FHDEVN
#ifdef _FHANDLER_H_
struct console_state
{
tty_min tty_min_state;