2000-02-17 20:38:33 +01:00
|
|
|
/* fhandler.cc. See console.cc for fhandler_console functions.
|
|
|
|
|
2005-02-02 23:42:06 +01:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
2007-01-04 10:17:55 +01:00
|
|
|
2005, 2006, 2007 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2000-09-08 04:56:55 +02:00
|
|
|
#include <sys/cygwin.h>
|
2002-08-30 17:47:10 +02:00
|
|
|
#include <sys/uio.h>
|
2004-04-14 18:36:26 +02:00
|
|
|
#include <sys/acl.h>
|
2000-09-08 04:56:55 +02:00
|
|
|
#include <signal.h>
|
2000-08-22 05:58:47 +02:00
|
|
|
#include "cygerrno.h"
|
2001-03-05 07:28:25 +01:00
|
|
|
#include "perprocess.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2001-08-07 02:01:42 +02:00
|
|
|
#include "cygwin/version.h"
|
2001-10-01 06:10:07 +02:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
#include "fhandler.h"
|
2001-04-18 23:10:15 +02:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2000-09-07 18:23:51 +02:00
|
|
|
#include "shared_info.h"
|
2001-10-05 06:21:41 +02:00
|
|
|
#include "pinfo.h"
|
2001-10-01 06:10:07 +02:00
|
|
|
#include <assert.h>
|
2002-02-25 18:47:51 +01:00
|
|
|
#include <limits.h>
|
2003-05-26 11:54:01 +02:00
|
|
|
#include <winioctl.h>
|
2004-04-16 23:22:13 +02:00
|
|
|
#include <ntdef.h>
|
|
|
|
#include "ntdll.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
static NO_COPY const int CHUNK_SIZE = 1024; /* Used for crlf conversions */
|
|
|
|
|
2001-09-06 06:41:59 +02:00
|
|
|
struct __cygwin_perfile *perfile_table;
|
2000-07-09 07:29:51 +02:00
|
|
|
|
2001-09-06 06:41:59 +02:00
|
|
|
DWORD binmode;
|
2000-07-01 05:51:55 +02:00
|
|
|
|
2000-09-03 06:16:35 +02:00
|
|
|
inline fhandler_base&
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_base::operator =(fhandler_base& x)
|
2000-09-03 06:16:35 +02:00
|
|
|
{
|
|
|
|
memcpy (this, &x, sizeof *this);
|
2004-12-23 22:37:44 +01:00
|
|
|
pc.set_normalized_path (x.pc.normalized_path, false);
|
2000-09-03 06:16:35 +02:00
|
|
|
rabuf = NULL;
|
|
|
|
ralen = 0;
|
|
|
|
raixget = 0;
|
|
|
|
raixput = 0;
|
|
|
|
rabuflen = 0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
int
|
2002-02-19 23:06:50 +01:00
|
|
|
fhandler_base::puts_readahead (const char *s, size_t len)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int success = 1;
|
2004-12-12 03:15:34 +01:00
|
|
|
while ((len == (size_t) -1 ? *s : len--)
|
2000-09-03 06:16:35 +02:00
|
|
|
&& (success = put_readahead (*s++) > 0))
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::put_readahead (char value)
|
|
|
|
{
|
|
|
|
char *newrabuf;
|
|
|
|
if (raixput < rabuflen)
|
|
|
|
/* Nothing to do */;
|
|
|
|
else if ((newrabuf = (char *) realloc (rabuf, rabuflen += 32)))
|
|
|
|
rabuf = newrabuf;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rabuf[raixput++] = value;
|
|
|
|
ralen++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::get_readahead ()
|
|
|
|
{
|
|
|
|
int chret = -1;
|
|
|
|
if (raixget < ralen)
|
2001-04-18 23:10:15 +02:00
|
|
|
chret = ((unsigned char) rabuf[raixget++]) & 0xff;
|
2000-02-17 20:38:33 +01:00
|
|
|
/* FIXME - not thread safe */
|
|
|
|
if (raixget >= ralen)
|
|
|
|
raixget = raixput = ralen = 0;
|
|
|
|
return chret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::peek_readahead (int queryput)
|
|
|
|
{
|
|
|
|
int chret = -1;
|
|
|
|
if (!queryput && raixget < ralen)
|
|
|
|
chret = ((unsigned char) rabuf[raixget]) & 0xff;
|
|
|
|
else if (queryput && raixput > 0)
|
|
|
|
chret = ((unsigned char) rabuf[raixput - 1]) & 0xff;
|
|
|
|
return chret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-19 23:06:50 +01:00
|
|
|
fhandler_base::set_readahead_valid (int val, int ch)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
if (!val)
|
|
|
|
ralen = raixget = raixput = 0;
|
|
|
|
if (ch != -1)
|
2002-09-22 05:38:57 +02:00
|
|
|
put_readahead (ch);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::eat_readahead (int n)
|
|
|
|
{
|
|
|
|
int oralen = ralen;
|
|
|
|
if (n < 0)
|
|
|
|
n = ralen;
|
|
|
|
if (n > 0 && ralen)
|
|
|
|
{
|
2000-02-21 06:20:38 +01:00
|
|
|
if ((int) (ralen -= n) < 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
ralen = 0;
|
|
|
|
|
|
|
|
if (raixget >= ralen)
|
|
|
|
raixget = raixput = ralen = 0;
|
|
|
|
else if (raixput > ralen)
|
|
|
|
raixput = ralen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return oralen;
|
|
|
|
}
|
|
|
|
|
2000-03-12 07:29:54 +01:00
|
|
|
int
|
|
|
|
fhandler_base::get_readahead_into_buffer (char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
int copied_chars = 0;
|
|
|
|
|
|
|
|
while (buflen)
|
|
|
|
if ((ch = get_readahead ()) < 0)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[copied_chars++] = (unsigned char)(ch & 0xff);
|
|
|
|
buflen--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copied_chars;
|
|
|
|
}
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
/* Record the file name. and name hash */
|
|
|
|
void
|
|
|
|
fhandler_base::set_name (path_conv &in_pc)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
memcpy (&pc, &in_pc, in_pc.size ());
|
2004-12-23 22:37:44 +01:00
|
|
|
pc.set_normalized_path (in_pc.normalized_path, false);
|
2001-10-01 06:10:07 +02:00
|
|
|
}
|
|
|
|
|
2005-01-31 11:28:55 +01:00
|
|
|
char *fhandler_base::get_proc_fd_name (char *buf)
|
|
|
|
{
|
|
|
|
if (get_name ())
|
|
|
|
return strcpy (buf, get_name ());
|
|
|
|
if (dev ().name)
|
|
|
|
return strcpy (buf, dev ().name);
|
2005-02-01 16:11:47 +01:00
|
|
|
return strcpy (buf, "");
|
2005-01-31 11:28:55 +01:00
|
|
|
}
|
|
|
|
|
2000-11-26 22:45:16 +01:00
|
|
|
/* Detect if we are sitting at EOF for conditions where Windows
|
|
|
|
returns an error but UNIX doesn't. */
|
|
|
|
static int __stdcall
|
|
|
|
is_at_eof (HANDLE h, DWORD err)
|
|
|
|
{
|
|
|
|
DWORD size, upper1, curr;
|
|
|
|
|
|
|
|
size = GetFileSize (h, &upper1);
|
2003-05-26 17:43:54 +02:00
|
|
|
if (size != INVALID_FILE_SIZE || GetLastError () == NO_ERROR)
|
2000-11-26 22:45:16 +01:00
|
|
|
{
|
|
|
|
LONG upper2 = 0;
|
|
|
|
curr = SetFilePointer (h, 0, &upper2, FILE_CURRENT);
|
|
|
|
if (curr == size && upper1 == (DWORD) upper2)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError (err);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-20 02:36:40 +02:00
|
|
|
void
|
|
|
|
fhandler_base::set_flags (int flags, int supplied_bin)
|
|
|
|
{
|
|
|
|
int bin;
|
|
|
|
int fmode;
|
|
|
|
debug_printf ("flags %p, supplied_bin %p", flags, supplied_bin);
|
|
|
|
if ((bin = flags & (O_BINARY | O_TEXT)))
|
|
|
|
debug_printf ("O_TEXT/O_BINARY set in flags %p", bin);
|
2004-04-10 15:45:10 +02:00
|
|
|
else if (rbinset () && wbinset ())
|
|
|
|
bin = rbinary () ? O_BINARY : O_TEXT; // FIXME: Not quite right
|
2002-06-20 02:36:40 +02:00
|
|
|
else if ((fmode = get_default_fmode (flags)) & O_BINARY)
|
|
|
|
bin = O_BINARY;
|
|
|
|
else if (fmode & O_TEXT)
|
|
|
|
bin = O_TEXT;
|
|
|
|
else if (supplied_bin)
|
|
|
|
bin = supplied_bin;
|
|
|
|
else
|
2004-04-10 15:45:10 +02:00
|
|
|
bin = wbinary () || rbinary () || (binmode != O_TEXT)
|
2002-09-19 05:30:20 +02:00
|
|
|
? O_BINARY : O_TEXT;
|
2002-06-20 02:36:40 +02:00
|
|
|
|
|
|
|
openflags = flags | bin;
|
|
|
|
|
|
|
|
bin &= O_BINARY;
|
2004-04-10 15:45:10 +02:00
|
|
|
rbinary (bin ? true : false);
|
|
|
|
wbinary (bin ? true : false);
|
2002-06-20 02:36:40 +02:00
|
|
|
syscall_printf ("filemode set to %s", bin ? "binary" : "text");
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Normal file i/o handlers. */
|
|
|
|
|
|
|
|
/* Cover function to ReadFile to achieve (as much as possible) Posix style
|
|
|
|
semantics and use of errno. */
|
2002-12-14 05:01:32 +01:00
|
|
|
void
|
|
|
|
fhandler_base::raw_read (void *ptr, size_t& ulen)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-09-07 04:22:58 +02:00
|
|
|
#define bytes_read ulen
|
2002-12-14 05:01:32 +01:00
|
|
|
|
2002-12-14 19:01:08 +01:00
|
|
|
HANDLE h = NULL; /* grumble */
|
|
|
|
int prio = 0; /* ditto */
|
2006-08-10 16:16:24 +02:00
|
|
|
int try_noreserve = 1;
|
2002-12-14 05:01:32 +01:00
|
|
|
DWORD len = ulen;
|
2002-12-14 19:01:08 +01:00
|
|
|
|
2006-08-10 16:16:24 +02:00
|
|
|
retry:
|
2003-09-01 04:05:32 +02:00
|
|
|
ulen = (size_t) -1;
|
2002-12-14 05:01:32 +01:00
|
|
|
if (read_state)
|
2002-12-14 19:01:08 +01:00
|
|
|
{
|
|
|
|
h = GetCurrentThread ();
|
|
|
|
prio = GetThreadPriority (h);
|
2005-07-06 22:05:03 +02:00
|
|
|
SetThreadPriority (h, THREAD_PRIORITY_TIME_CRITICAL);
|
2005-02-06 06:04:34 +01:00
|
|
|
signal_read_state (1);
|
2002-12-14 19:01:08 +01:00
|
|
|
}
|
2006-08-10 16:16:24 +02:00
|
|
|
BOOL res = ReadFile (get_handle (), ptr, len, (DWORD *) &ulen, 0);
|
2005-02-11 16:24:15 +01:00
|
|
|
if (read_state)
|
|
|
|
{
|
|
|
|
signal_read_state (1);
|
2005-07-06 22:05:03 +02:00
|
|
|
SetThreadPriority (h, prio);
|
2005-02-11 16:24:15 +01:00
|
|
|
}
|
2002-12-14 05:01:32 +01:00
|
|
|
if (!res)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
/* Some errors are not really errors. Detect such cases here. */
|
|
|
|
|
2002-12-14 05:01:32 +01:00
|
|
|
DWORD errcode = GetLastError ();
|
2000-02-17 20:38:33 +01:00
|
|
|
switch (errcode)
|
|
|
|
{
|
|
|
|
case ERROR_BROKEN_PIPE:
|
|
|
|
/* This is really EOF. */
|
|
|
|
bytes_read = 0;
|
|
|
|
break;
|
|
|
|
case ERROR_MORE_DATA:
|
|
|
|
/* `bytes_read' is supposedly valid. */
|
|
|
|
break;
|
2000-11-26 22:45:16 +01:00
|
|
|
case ERROR_NOACCESS:
|
|
|
|
if (is_at_eof (get_handle (), errcode))
|
2002-12-14 05:01:32 +01:00
|
|
|
{
|
|
|
|
bytes_read = 0;
|
|
|
|
break;
|
|
|
|
}
|
2006-08-10 16:16:24 +02:00
|
|
|
if (try_noreserve)
|
|
|
|
{
|
|
|
|
try_noreserve = 0;
|
|
|
|
switch (mmap_is_attached_or_noreserve (ptr, len))
|
|
|
|
{
|
|
|
|
case MMAP_NORESERVE_COMMITED:
|
|
|
|
goto retry;
|
|
|
|
case MMAP_RAISE_SIGBUS:
|
|
|
|
raise(SIGBUS);
|
|
|
|
case MMAP_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-25 21:23:23 +02:00
|
|
|
/*FALLTHRU*/
|
2001-10-01 06:10:07 +02:00
|
|
|
case ERROR_INVALID_FUNCTION:
|
|
|
|
case ERROR_INVALID_PARAMETER:
|
2002-09-19 05:30:20 +02:00
|
|
|
case ERROR_INVALID_HANDLE:
|
2006-07-13 22:56:24 +02:00
|
|
|
if (pc.isdir ())
|
2001-10-01 06:10:07 +02:00
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
2003-09-07 04:22:58 +02:00
|
|
|
bytes_read = (size_t) -1;
|
2002-12-14 05:01:32 +01:00
|
|
|
break;
|
2001-10-01 06:10:07 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
default:
|
2005-06-07 20:41:31 +02:00
|
|
|
syscall_printf ("ReadFile %s(%p) failed, %E", get_name (), get_handle ());
|
2000-09-03 06:16:35 +02:00
|
|
|
__seterrno_from_win_error (errcode);
|
2003-09-07 04:22:58 +02:00
|
|
|
bytes_read = (size_t) -1;
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-12-14 05:01:32 +01:00
|
|
|
#undef bytes_read
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cover function to WriteFile to provide Posix interface and semantics
|
|
|
|
(as much as possible). */
|
|
|
|
int
|
|
|
|
fhandler_base::raw_write (const void *ptr, size_t len)
|
|
|
|
{
|
|
|
|
DWORD bytes_written;
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
if (!WriteFile (get_output_handle (), ptr, len, &bytes_written, 0))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
if (GetLastError () == ERROR_DISK_FULL && bytes_written > 0)
|
2005-02-11 16:37:26 +01:00
|
|
|
goto written;
|
2000-02-17 20:38:33 +01:00
|
|
|
__seterrno ();
|
|
|
|
if (get_errno () == EPIPE)
|
|
|
|
raise (SIGPIPE);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-11 16:37:26 +01:00
|
|
|
written:
|
2000-02-17 20:38:33 +01:00
|
|
|
return bytes_written;
|
|
|
|
}
|
|
|
|
|
2000-07-09 07:29:51 +02:00
|
|
|
int
|
|
|
|
fhandler_base::get_default_fmode (int flags)
|
|
|
|
{
|
2002-07-13 22:00:27 +02:00
|
|
|
int fmode = __fmode;
|
2000-07-09 07:29:51 +02:00
|
|
|
if (perfile_table)
|
|
|
|
{
|
|
|
|
size_t nlen = strlen (get_name ());
|
2005-12-14 17:38:22 +01:00
|
|
|
unsigned accflags = (flags & O_ACCMODE);
|
2000-07-09 07:29:51 +02:00
|
|
|
for (__cygwin_perfile *pf = perfile_table; pf->name; pf++)
|
2005-12-14 17:38:22 +01:00
|
|
|
if (!*pf->name && (pf->flags & O_ACCMODE) == accflags)
|
2002-07-13 22:00:27 +02:00
|
|
|
{
|
2005-12-14 17:38:22 +01:00
|
|
|
fmode = pf->flags & ~O_ACCMODE;
|
2002-07-13 22:00:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2000-11-03 05:27:03 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t pflen = strlen (pf->name);
|
|
|
|
const char *stem = get_name () + nlen - pflen;
|
|
|
|
if (pflen > nlen || (stem != get_name () && !isdirsep (stem[-1])))
|
|
|
|
continue;
|
2005-12-14 17:38:22 +01:00
|
|
|
else if ((pf->flags & O_ACCMODE) == accflags
|
|
|
|
&& strcasematch (stem, pf->name))
|
2002-07-13 22:00:27 +02:00
|
|
|
{
|
2005-12-14 17:38:22 +01:00
|
|
|
fmode = pf->flags & ~O_ACCMODE;
|
2002-07-13 22:00:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2000-11-03 05:27:03 +01:00
|
|
|
}
|
2000-07-09 07:29:51 +02:00
|
|
|
}
|
2002-07-13 22:00:27 +02:00
|
|
|
return fmode;
|
2000-07-09 07:29:51 +02:00
|
|
|
}
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
bool
|
|
|
|
fhandler_base::device_access_denied (int flags)
|
|
|
|
{
|
|
|
|
int mode = 0;
|
|
|
|
|
|
|
|
if (flags & O_RDWR)
|
|
|
|
mode |= R_OK | W_OK;
|
|
|
|
if (flags & (O_WRONLY | O_APPEND))
|
|
|
|
mode |= W_OK;
|
|
|
|
if (!mode)
|
|
|
|
mode |= R_OK;
|
|
|
|
|
2004-01-24 04:40:33 +01:00
|
|
|
return fhaccess (mode);
|
|
|
|
}
|
|
|
|
|
2004-01-24 21:34:27 +01:00
|
|
|
int
|
2004-01-24 04:40:33 +01:00
|
|
|
fhandler_base::fhaccess (int flags)
|
|
|
|
{
|
2004-01-24 21:34:27 +01:00
|
|
|
int res = -1;
|
2004-01-24 04:40:33 +01:00
|
|
|
if (error ())
|
|
|
|
{
|
|
|
|
set_errno (error ());
|
2004-01-24 21:34:27 +01:00
|
|
|
goto done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!exists ())
|
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
2004-01-24 21:34:27 +01:00
|
|
|
goto done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & (R_OK | W_OK | X_OK)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (is_fs_special ())
|
|
|
|
/* short circuit */;
|
|
|
|
else if (has_attribute (FILE_ATTRIBUTE_READONLY) && (flags & W_OK))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
|
|
|
else if (has_acls () && allow_ntsec)
|
2004-01-24 04:40:33 +01:00
|
|
|
{
|
2004-01-26 00:39:26 +01:00
|
|
|
res = check_file_access (get_win32_name (), flags);
|
2004-01-24 21:34:27 +01:00
|
|
|
goto done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
2006-10-22 11:38:47 +02:00
|
|
|
else if (get_device () == FH_REGISTRY && allow_ntsec && open (O_RDONLY, 0)
|
|
|
|
&& get_handle ())
|
2006-10-21 13:05:32 +02:00
|
|
|
{
|
|
|
|
res = check_registry_access (get_handle (), flags);
|
|
|
|
close ();
|
|
|
|
return res;
|
|
|
|
}
|
2004-01-24 04:40:33 +01:00
|
|
|
|
|
|
|
struct __stat64 st;
|
2004-01-24 21:34:27 +01:00
|
|
|
if (fstat (&st))
|
|
|
|
goto done;
|
|
|
|
|
2004-01-24 04:40:33 +01:00
|
|
|
if (flags & R_OK)
|
|
|
|
{
|
|
|
|
if (st.st_uid == myself->uid)
|
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IRUSR))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
|
|
|
else if (st.st_gid == myself->gid)
|
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IRGRP))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
|
|
|
else if (!(st.st_mode & S_IROTH))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
2004-01-24 21:34:27 +01:00
|
|
|
|
2004-01-24 04:40:33 +01:00
|
|
|
if (flags & W_OK)
|
|
|
|
{
|
|
|
|
if (st.st_uid == myself->uid)
|
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IWUSR))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
|
|
|
else if (st.st_gid == myself->gid)
|
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IWGRP))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
|
|
|
else if (!(st.st_mode & S_IWOTH))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
2004-01-24 21:34:27 +01:00
|
|
|
|
2004-01-24 04:40:33 +01:00
|
|
|
if (flags & X_OK)
|
|
|
|
{
|
|
|
|
if (st.st_uid == myself->uid)
|
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IXUSR))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
|
|
|
else if (st.st_gid == myself->gid)
|
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IXGRP))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
|
|
|
else if (!(st.st_mode & S_IXOTH))
|
2004-01-26 00:39:26 +01:00
|
|
|
goto eaccess_done;
|
2004-01-24 04:40:33 +01:00
|
|
|
}
|
2004-01-26 00:39:26 +01:00
|
|
|
|
2004-01-24 21:34:27 +01:00
|
|
|
res = 0;
|
2004-01-26 00:39:26 +01:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
eaccess_done:
|
|
|
|
set_errno (EACCES);
|
2004-01-24 04:40:33 +01:00
|
|
|
done:
|
2004-01-24 21:34:27 +01:00
|
|
|
debug_printf ("returning %d", res);
|
|
|
|
return res;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2001-10-04 04:34:20 +02:00
|
|
|
/* Open system call handler function. */
|
2001-09-22 23:44:07 +02:00
|
|
|
int
|
2004-04-16 23:22:13 +02:00
|
|
|
fhandler_base::open_9x (int flags, mode_t mode)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
HANDLE x;
|
|
|
|
int file_attributes;
|
|
|
|
int shared;
|
|
|
|
int creation_distribution;
|
2001-08-07 17:09:54 +02:00
|
|
|
SECURITY_ATTRIBUTES sa = sec_none;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-04-16 23:22:13 +02:00
|
|
|
syscall_printf ("(%s, %p)", get_win32_name (), flags);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2005-03-04 14:54:59 +01:00
|
|
|
switch (query_open ())
|
|
|
|
{
|
|
|
|
case query_read_control:
|
|
|
|
case query_stat_control:
|
|
|
|
access = GENERIC_READ;
|
|
|
|
break;
|
|
|
|
case query_write_control:
|
|
|
|
case query_write_attributes:
|
|
|
|
access = GENERIC_READ | FILE_WRITE_ATTRIBUTES;
|
|
|
|
break;
|
|
|
|
default:
|
2005-12-14 17:38:22 +01:00
|
|
|
if ((flags & O_ACCMODE) == O_RDONLY)
|
2005-03-04 14:54:59 +01:00
|
|
|
access = GENERIC_READ;
|
2005-12-14 17:38:22 +01:00
|
|
|
else if ((flags & O_ACCMODE) == O_WRONLY)
|
2005-03-04 14:54:59 +01:00
|
|
|
access = GENERIC_WRITE;
|
|
|
|
else
|
|
|
|
access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
break;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if ((flags & O_TRUNC) && ((flags & O_ACCMODE) != O_RDONLY))
|
|
|
|
{
|
|
|
|
if (flags & O_CREAT)
|
2001-10-01 06:10:07 +02:00
|
|
|
creation_distribution = CREATE_ALWAYS;
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
2001-10-01 06:10:07 +02:00
|
|
|
creation_distribution = TRUNCATE_EXISTING;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
else if (flags & O_CREAT)
|
|
|
|
creation_distribution = OPEN_ALWAYS;
|
|
|
|
else
|
|
|
|
creation_distribution = OPEN_EXISTING;
|
|
|
|
|
|
|
|
if ((flags & O_EXCL) && (flags & O_CREAT))
|
2001-10-01 06:10:07 +02:00
|
|
|
creation_distribution = CREATE_NEW;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
2004-04-10 15:45:10 +02:00
|
|
|
append_mode (true);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* These flags are host dependent. */
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-12 19:46:37 +02:00
|
|
|
shared = wincap.shared ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
file_attributes = FILE_ATTRIBUTE_NORMAL;
|
|
|
|
if (flags & O_DIROPEN)
|
|
|
|
file_attributes |= FILE_FLAG_BACKUP_SEMANTICS;
|
2005-12-14 16:54:33 +01:00
|
|
|
if (flags & O_SYNC)
|
|
|
|
file_attributes |= FILE_FLAG_WRITE_THROUGH;
|
|
|
|
if (flags & O_DIRECT)
|
|
|
|
file_attributes |= FILE_FLAG_NO_BUFFERING;
|
2004-01-21 19:19:29 +01:00
|
|
|
if (get_major () == DEV_SERIAL_MAJOR)
|
2000-02-17 20:38:33 +01:00
|
|
|
file_attributes |= FILE_FLAG_OVERLAPPED;
|
|
|
|
|
2001-11-13 22:49:06 +01:00
|
|
|
#ifdef HIDDEN_DOT_FILES
|
2004-01-22 16:08:08 +01:00
|
|
|
if (flags & O_CREAT && get_device () == FH_FS)
|
2001-11-13 22:49:06 +01:00
|
|
|
{
|
|
|
|
char *c = strrchr (get_win32_name (), '\\');
|
|
|
|
if ((c && c[1] == '.') || *get_win32_name () == '.')
|
2002-05-28 03:55:40 +02:00
|
|
|
file_attributes |= FILE_ATTRIBUTE_HIDDEN;
|
2001-11-13 22:49:06 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-08-14 05:01:21 +02:00
|
|
|
if (flags & O_CREAT && get_device () == FH_FS)
|
|
|
|
{
|
|
|
|
/* If mode has no write bits set, we set the R/O attribute. */
|
|
|
|
if (!(mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
|
2004-09-12 05:47:57 +02:00
|
|
|
file_attributes |= FILE_ATTRIBUTE_READONLY;
|
2004-08-14 05:01:21 +02:00
|
|
|
/* The file attributes are needed for later use in, e.g. fchmod. */
|
|
|
|
pc.file_attributes (file_attributes & FILE_ATTRIBUTE_VALID_SET_FLAGS);
|
2004-09-12 05:47:57 +02:00
|
|
|
}
|
2002-04-09 15:01:00 +02:00
|
|
|
|
2001-10-04 04:34:20 +02:00
|
|
|
x = CreateFile (get_win32_name (), access, shared, &sa, creation_distribution,
|
2001-11-05 07:09:15 +01:00
|
|
|
file_attributes, 0);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (x == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2004-04-20 17:51:24 +02:00
|
|
|
if (pc.isdir ())
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
{
|
2005-12-14 17:38:22 +01:00
|
|
|
if ((flags & O_ACCMODE) != O_RDONLY)
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
set_errno (EISDIR);
|
|
|
|
else
|
2004-04-10 15:45:10 +02:00
|
|
|
nohandle (true);
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
}
|
2002-09-19 05:30:20 +02:00
|
|
|
else if (GetLastError () == ERROR_INVALID_HANDLE)
|
2004-03-23 19:52:39 +01:00
|
|
|
set_errno (ENOENT);
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
2004-03-23 19:52:39 +01:00
|
|
|
__seterrno ();
|
2004-04-10 15:45:10 +02:00
|
|
|
if (!nohandle ())
|
2004-03-23 19:52:39 +01:00
|
|
|
goto done;
|
2003-02-21 05:33:53 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
set_io_handle (x);
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
set_flags (flags, pc.binmode ());
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
res = 1;
|
2001-04-24 04:07:58 +02:00
|
|
|
set_open_status ();
|
2000-02-17 20:38:33 +01:00
|
|
|
done:
|
2004-06-17 15:34:26 +02:00
|
|
|
debug_printf ("%p = CreateFile (%s, %p, %p, %p, %p, %p, 0)",
|
|
|
|
x, get_win32_name (), access, shared, &sa,
|
|
|
|
creation_distribution, file_attributes);
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
syscall_printf ("%d = fhandler_base::open (%s, %p)", res, get_win32_name (),
|
|
|
|
flags);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-04-16 23:22:13 +02:00
|
|
|
/* Open system call handler function. */
|
|
|
|
int
|
|
|
|
fhandler_base::open (int flags, mode_t mode)
|
|
|
|
{
|
2004-06-03 23:33:29 +02:00
|
|
|
if (!wincap.is_winnt ())
|
2004-04-16 23:22:13 +02:00
|
|
|
return fhandler_base::open_9x (flags, mode);
|
|
|
|
|
2005-09-28 21:22:25 +02:00
|
|
|
WCHAR wpath[CYG_MAX_PATH + 10];
|
|
|
|
UNICODE_STRING upath = {0, sizeof (wpath), wpath};
|
|
|
|
pc.get_nt_native_path (upath);
|
|
|
|
|
|
|
|
if (RtlIsDosDeviceName_U (upath.Buffer))
|
|
|
|
return fhandler_base::open_9x (flags, mode);
|
2004-06-04 00:27:25 +02:00
|
|
|
|
2004-04-16 23:22:13 +02:00
|
|
|
int res = 0;
|
|
|
|
HANDLE x;
|
|
|
|
ULONG file_attributes = 0;
|
2004-08-19 17:47:51 +02:00
|
|
|
ULONG shared = (get_major () == DEV_TAPE_MAJOR ? 0 : wincap.shared ());
|
2004-04-16 23:22:13 +02:00
|
|
|
ULONG create_disposition;
|
|
|
|
ULONG create_options;
|
|
|
|
SECURITY_ATTRIBUTES sa = sec_none;
|
|
|
|
security_descriptor sd;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
syscall_printf ("(%s, %p)", get_win32_name (), flags);
|
2004-04-30 16:02:37 +02:00
|
|
|
|
2005-09-28 21:22:25 +02:00
|
|
|
InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
|
2006-01-26 17:58:53 +01:00
|
|
|
NULL, sa.lpSecurityDescriptor);
|
2004-04-16 23:22:13 +02:00
|
|
|
|
|
|
|
switch (query_open ())
|
|
|
|
{
|
|
|
|
case query_read_control:
|
2006-02-22 17:40:42 +01:00
|
|
|
access = READ_CONTROL | FILE_READ_ATTRIBUTES;
|
2004-05-28 21:50:07 +02:00
|
|
|
create_options = FILE_OPEN_FOR_BACKUP_INTENT;
|
|
|
|
break;
|
2004-04-16 23:22:13 +02:00
|
|
|
case query_stat_control:
|
2006-07-03 20:30:08 +02:00
|
|
|
access = READ_CONTROL | FILE_READ_ATTRIBUTES
|
|
|
|
| (allow_ntea ? FILE_READ_EA : 0);
|
2004-05-28 21:50:07 +02:00
|
|
|
create_options = FILE_OPEN_FOR_BACKUP_INTENT;
|
|
|
|
break;
|
2004-04-16 23:22:13 +02:00
|
|
|
case query_write_control:
|
2006-07-03 20:30:08 +02:00
|
|
|
access = READ_CONTROL | WRITE_OWNER | WRITE_DAC | FILE_WRITE_ATTRIBUTES
|
|
|
|
| (allow_ntea ? FILE_WRITE_EA : 0);
|
2004-05-28 21:50:07 +02:00
|
|
|
create_options = FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_FOR_RECOVERY;
|
|
|
|
break;
|
2005-02-20 12:44:32 +01:00
|
|
|
case query_write_attributes:
|
|
|
|
access = READ_CONTROL | FILE_WRITE_ATTRIBUTES;
|
|
|
|
create_options = FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_FOR_RECOVERY;
|
|
|
|
break;
|
2004-04-16 23:22:13 +02:00
|
|
|
default:
|
2005-12-14 17:38:22 +01:00
|
|
|
if ((flags & O_ACCMODE) == O_RDONLY)
|
2006-10-16 14:26:59 +02:00
|
|
|
{
|
|
|
|
access = GENERIC_READ;
|
|
|
|
create_options = FILE_OPEN_FOR_BACKUP_INTENT;
|
|
|
|
}
|
2005-12-14 17:38:22 +01:00
|
|
|
else if ((flags & O_ACCMODE) == O_WRONLY)
|
2006-10-16 14:26:59 +02:00
|
|
|
{
|
|
|
|
access = GENERIC_WRITE | FILE_READ_ATTRIBUTES;
|
|
|
|
create_options = FILE_OPEN_FOR_RECOVERY;
|
|
|
|
}
|
2004-04-16 23:22:13 +02:00
|
|
|
else
|
2006-10-16 14:26:59 +02:00
|
|
|
{
|
|
|
|
access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
create_options = FILE_OPEN_FOR_BACKUP_INTENT
|
|
|
|
| FILE_OPEN_FOR_RECOVERY;
|
|
|
|
}
|
2005-12-14 16:54:33 +01:00
|
|
|
if (flags & O_SYNC)
|
|
|
|
create_options |= FILE_WRITE_THROUGH;
|
|
|
|
if (flags & O_DIRECT)
|
|
|
|
create_options |= FILE_NO_INTERMEDIATE_BUFFERING;
|
2004-04-20 13:01:22 +02:00
|
|
|
if (get_major () != DEV_SERIAL_MAJOR && get_major () != DEV_TAPE_MAJOR)
|
2004-04-16 23:22:13 +02:00
|
|
|
{
|
|
|
|
create_options |= FILE_SYNCHRONOUS_IO_NONALERT;
|
|
|
|
access |= SYNCHRONIZE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & O_TRUNC) && ((flags & O_ACCMODE) != O_RDONLY))
|
|
|
|
{
|
|
|
|
if (flags & O_CREAT)
|
2004-06-17 09:03:09 +02:00
|
|
|
create_disposition = FILE_OVERWRITE_IF;
|
2004-04-16 23:22:13 +02:00
|
|
|
else
|
|
|
|
create_disposition = FILE_OVERWRITE;
|
|
|
|
}
|
|
|
|
else if (flags & O_CREAT)
|
|
|
|
create_disposition = FILE_OPEN_IF;
|
|
|
|
else
|
|
|
|
create_disposition = FILE_OPEN;
|
|
|
|
|
|
|
|
if ((flags & O_EXCL) && (flags & O_CREAT))
|
|
|
|
create_disposition = FILE_CREATE;
|
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
|
|
|
append_mode (true);
|
|
|
|
|
|
|
|
if (flags & O_CREAT && get_device () == FH_FS)
|
|
|
|
{
|
|
|
|
file_attributes = FILE_ATTRIBUTE_NORMAL;
|
|
|
|
/* If mode has no write bits set, we set the R/O attribute. */
|
|
|
|
if (!(mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
|
|
|
|
file_attributes |= FILE_ATTRIBUTE_READONLY;
|
|
|
|
#ifdef HIDDEN_DOT_FILES
|
|
|
|
char *c = strrchr (get_win32_name (), '\\');
|
|
|
|
if ((c && c[1] == '.') || *get_win32_name () == '.')
|
|
|
|
file_attributes |= FILE_ATTRIBUTE_HIDDEN;
|
|
|
|
#endif
|
2006-11-27 20:14:24 +01:00
|
|
|
/* Starting with Windows 2000, when trying to overwrite an already
|
2006-11-28 10:57:01 +01:00
|
|
|
existing file with FILE_ATTRIBUTE_HIDDEN and/or FILE_ATTRIBUTE_SYSTEM
|
|
|
|
attribute set, CreateFile fails with ERROR_ACCESS_DENIED.
|
|
|
|
Per MSDN you have to create the file with the same attributes as
|
|
|
|
already specified for the file. */
|
|
|
|
if (has_attribute (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM))
|
2006-11-27 20:14:24 +01:00
|
|
|
file_attributes |= pc.file_attributes ();
|
|
|
|
|
2004-04-16 23:22:13 +02:00
|
|
|
/* If the file should actually be created and ntsec is on,
|
|
|
|
set files attributes. */
|
|
|
|
if (allow_ntsec && has_acls ())
|
|
|
|
{
|
|
|
|
set_security_attribute (mode, &sa, sd);
|
|
|
|
attr.SecurityDescriptor = sa.lpSecurityDescriptor;
|
|
|
|
}
|
2004-05-11 17:39:50 +02:00
|
|
|
/* The file attributes are needed for later use in, e.g. fchmod. */
|
|
|
|
pc.file_attributes (file_attributes);
|
2004-04-16 23:22:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
status = NtCreateFile (&x, access, &attr, &io, NULL, file_attributes, shared,
|
2004-05-28 21:50:07 +02:00
|
|
|
create_disposition, create_options, NULL, 0);
|
2004-04-16 23:22:13 +02:00
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
2005-04-13 18:41:33 +02:00
|
|
|
__seterrno_from_nt_status (status);
|
2004-04-16 23:22:13 +02:00
|
|
|
if (!nohandle ())
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_io_handle (x);
|
|
|
|
set_flags (flags, pc.binmode ());
|
|
|
|
|
|
|
|
res = 1;
|
|
|
|
set_open_status ();
|
|
|
|
done:
|
2004-06-17 15:34:26 +02:00
|
|
|
debug_printf ("%x = NtCreateFile "
|
|
|
|
"(%p, %x, %s, io, NULL, %x, %x, %x, %x, NULL, 0)",
|
|
|
|
status, x, access, get_win32_name (), file_attributes, shared,
|
|
|
|
create_disposition, create_options);
|
|
|
|
|
2004-04-16 23:22:13 +02:00
|
|
|
syscall_printf ("%d = fhandler_base::open (%s, %p)", res, get_win32_name (),
|
|
|
|
flags);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* states:
|
|
|
|
open buffer in binary mode? Just do the read.
|
|
|
|
|
|
|
|
open buffer in text mode? Scan buffer for control zs and handle
|
|
|
|
the first one found. Then scan buffer, converting every \r\n into
|
|
|
|
an \n. If last char is an \r, look ahead one more char, if \n then
|
|
|
|
modify \r, if not, remember char.
|
|
|
|
*/
|
2002-12-14 05:01:32 +01:00
|
|
|
void
|
|
|
|
fhandler_base::read (void *in_ptr, size_t& len)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
char *ptr = (char *) in_ptr;
|
2006-07-27 05:32:51 +02:00
|
|
|
ssize_t copied_chars = get_readahead_into_buffer (ptr, len);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-11-03 06:42:21 +01:00
|
|
|
if (copied_chars && is_slow ())
|
2002-12-14 05:01:32 +01:00
|
|
|
{
|
|
|
|
len = (size_t) copied_chars;
|
2002-12-14 19:01:08 +01:00
|
|
|
goto out;
|
2002-12-14 05:01:32 +01:00
|
|
|
}
|
2001-11-03 06:42:21 +01:00
|
|
|
|
2006-07-27 05:32:51 +02:00
|
|
|
len -= copied_chars;
|
2002-12-14 19:01:08 +01:00
|
|
|
if (!len)
|
2002-12-14 05:01:32 +01:00
|
|
|
{
|
|
|
|
len = (size_t) copied_chars;
|
2002-12-14 19:01:08 +01:00
|
|
|
goto out;
|
2000-10-07 20:12:11 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2005-02-06 06:04:34 +01:00
|
|
|
raw_read (ptr + copied_chars, len);
|
2002-12-14 19:01:08 +01:00
|
|
|
if (!copied_chars)
|
|
|
|
/* nothing */;
|
|
|
|
else if ((ssize_t) len > 0)
|
|
|
|
len += copied_chars;
|
|
|
|
else
|
|
|
|
len = copied_chars;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-04-10 15:45:10 +02:00
|
|
|
if (rbinary () || len <= 0)
|
2002-12-14 19:01:08 +01:00
|
|
|
goto out;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Scan buffer and turn \r\n into \n */
|
2002-12-14 19:01:08 +01:00
|
|
|
char *src, *dst, *end;
|
|
|
|
src = (char *) ptr;
|
|
|
|
dst = (char *) ptr;
|
|
|
|
end = src + len - 1;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Read up to the last but one char - the last char needs special handling */
|
|
|
|
while (src < end)
|
|
|
|
{
|
2002-12-14 05:01:32 +01:00
|
|
|
if (*src == '\r' && src[1] == '\n')
|
|
|
|
src++;
|
|
|
|
*dst++ = *src++;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-12-14 19:01:08 +01:00
|
|
|
/* If not beyond end and last char is a '\r' then read one more
|
|
|
|
to see if we should translate this one too */
|
|
|
|
if (src > end)
|
|
|
|
/* nothing */;
|
|
|
|
else if (*src != '\r')
|
|
|
|
*dst++ = *src;
|
|
|
|
else
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-12-14 19:01:08 +01:00
|
|
|
char c1;
|
|
|
|
size_t c1len = 1;
|
|
|
|
raw_read (&c1, c1len);
|
|
|
|
if (c1len <= 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
/* nothing */;
|
2002-12-14 19:01:08 +01:00
|
|
|
else if (c1 == '\n')
|
|
|
|
*dst++ = '\n';
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
2002-12-14 05:01:32 +01:00
|
|
|
{
|
2002-12-14 19:01:08 +01:00
|
|
|
set_readahead_valid (1, c1);
|
|
|
|
*dst++ = *src;
|
2002-12-14 05:01:32 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-12-14 19:01:08 +01:00
|
|
|
len = dst - (char *) ptr;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
#ifndef NOSTRACE
|
2005-12-29 21:46:34 +01:00
|
|
|
if (strace.active ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
char buf[16 * 6 + 1];
|
|
|
|
char *p = buf;
|
|
|
|
|
|
|
|
for (int i = 0; i < copied_chars && i < 16; ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = ((unsigned char *) ptr)[i];
|
2004-12-05 08:28:27 +01:00
|
|
|
__small_sprintf (p, " %c", c);
|
2000-02-17 20:38:33 +01:00
|
|
|
p += strlen (p);
|
|
|
|
}
|
2004-12-05 02:53:47 +01:00
|
|
|
*p = '\0';
|
2000-02-17 20:38:33 +01:00
|
|
|
debug_printf ("read %d bytes (%s%s)", copied_chars, buf,
|
|
|
|
copied_chars > 16 ? " ..." : "");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-12-14 19:01:08 +01:00
|
|
|
out:
|
2004-04-10 15:45:10 +02:00
|
|
|
debug_printf ("returning %d, %s mode", len, rbinary () ? "binary" : "text");
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::write (const void *ptr, size_t len)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
2004-04-10 15:45:10 +02:00
|
|
|
if (append_mode ())
|
2003-09-14 03:58:03 +02:00
|
|
|
SetFilePointer (get_output_handle (), 0, 0, FILE_END);
|
2004-04-10 15:45:10 +02:00
|
|
|
else if (did_lseek ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-05-26 11:54:01 +02:00
|
|
|
_off64_t actual_length, current_position;
|
|
|
|
DWORD size_high = 0;
|
|
|
|
LONG pos_high = 0;
|
|
|
|
|
2004-04-10 15:45:10 +02:00
|
|
|
did_lseek (false); /* don't do it again */
|
2003-05-26 11:54:01 +02:00
|
|
|
|
2003-09-14 03:58:03 +02:00
|
|
|
actual_length = GetFileSize (get_output_handle (), &size_high);
|
2003-05-26 11:54:01 +02:00
|
|
|
actual_length += ((_off64_t) size_high) << 32;
|
|
|
|
|
2003-09-14 03:58:03 +02:00
|
|
|
current_position = SetFilePointer (get_output_handle (), 0, &pos_high,
|
2003-05-26 11:54:01 +02:00
|
|
|
FILE_CURRENT);
|
|
|
|
current_position += ((_off64_t) pos_high) << 32;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
if (current_position > actual_length)
|
|
|
|
{
|
2003-05-26 11:54:01 +02:00
|
|
|
if ((get_fs_flags (FILE_SUPPORTS_SPARSE_FILES))
|
2003-06-06 10:11:19 +02:00
|
|
|
&& current_position >= actual_length + (128 * 1024))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-05-26 11:54:01 +02:00
|
|
|
/* If the file systemn supports sparse files and the application
|
2004-05-28 21:50:07 +02:00
|
|
|
is writing after a long seek beyond EOF, convert the file to
|
2003-05-26 11:54:01 +02:00
|
|
|
a sparse file. */
|
|
|
|
DWORD dw;
|
2003-09-14 03:58:03 +02:00
|
|
|
HANDLE h = get_output_handle ();
|
2003-05-26 11:54:01 +02:00
|
|
|
BOOL r = DeviceIoControl (h, FSCTL_SET_SPARSE, NULL, 0, NULL,
|
2004-05-28 21:50:07 +02:00
|
|
|
0, &dw, NULL);
|
2005-02-02 23:42:06 +01:00
|
|
|
syscall_printf ("%d = DeviceIoControl(%p, FSCTL_SET_SPARSE)",
|
|
|
|
r, h);
|
2003-05-26 11:54:01 +02:00
|
|
|
}
|
|
|
|
else if (wincap.has_lseek_bug ())
|
|
|
|
{
|
|
|
|
/* Oops, this is the bug case - Win95 uses whatever is on the
|
2004-05-28 21:50:07 +02:00
|
|
|
disk instead of some known (safe) value, so we must seek
|
2003-05-26 11:54:01 +02:00
|
|
|
back and fill in the gap with zeros. - DJ
|
2004-05-28 21:50:07 +02:00
|
|
|
Note: this bug doesn't happen on NT4, even though the
|
|
|
|
documentation for WriteFile() says that it *may* happen
|
2003-05-26 11:54:01 +02:00
|
|
|
on any OS. */
|
2004-08-28 17:46:57 +02:00
|
|
|
/* Check there is enough space */
|
|
|
|
if (!SetEndOfFile (get_output_handle ()))
|
2004-09-12 05:47:57 +02:00
|
|
|
{
|
2004-08-28 17:46:57 +02:00
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2003-05-26 11:54:01 +02:00
|
|
|
char zeros[512];
|
|
|
|
int number_of_zeros_to_write = current_position - actual_length;
|
|
|
|
memset (zeros, 0, 512);
|
2004-08-28 17:46:57 +02:00
|
|
|
SetFilePointer (get_output_handle (), actual_length, NULL,
|
|
|
|
FILE_BEGIN);
|
2003-05-26 11:54:01 +02:00
|
|
|
while (number_of_zeros_to_write > 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-05-26 11:54:01 +02:00
|
|
|
DWORD zeros_this_time = (number_of_zeros_to_write > 512
|
|
|
|
? 512 : number_of_zeros_to_write);
|
|
|
|
DWORD written;
|
2004-08-28 17:46:57 +02:00
|
|
|
DWORD ret = WriteFile (get_output_handle (), zeros,
|
|
|
|
zeros_this_time, &written, NULL);
|
|
|
|
if (!ret || written < zeros_this_time)
|
2003-05-26 11:54:01 +02:00
|
|
|
{
|
2004-08-28 17:46:57 +02:00
|
|
|
if (!ret)
|
2004-09-12 05:47:57 +02:00
|
|
|
{
|
2004-08-28 17:46:57 +02:00
|
|
|
__seterrno ();
|
|
|
|
if (get_errno () == EPIPE)
|
|
|
|
raise (SIGPIPE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
set_errno (ENOSPC);
|
2003-05-26 11:54:01 +02:00
|
|
|
/* This might fail, but it's the best we can hope for */
|
2004-08-28 17:46:57 +02:00
|
|
|
SetFilePointer (get_output_handle (), current_position,
|
|
|
|
NULL, FILE_BEGIN);
|
2003-05-26 11:54:01 +02:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
number_of_zeros_to_write -= written;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-10 15:45:10 +02:00
|
|
|
if (wbinary ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-10-07 20:12:11 +02:00
|
|
|
debug_printf ("binary write");
|
2000-02-17 20:38:33 +01:00
|
|
|
res = raw_write (ptr, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-07 20:12:11 +02:00
|
|
|
debug_printf ("text write");
|
2000-02-17 20:38:33 +01:00
|
|
|
/* This is the Microsoft/DJGPP way. Still not ideal, but it's
|
2000-10-07 20:12:11 +02:00
|
|
|
compatible.
|
|
|
|
Modified slightly by CGF 2000-10-07 */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
int left_in_data = len;
|
|
|
|
char *data = (char *)ptr;
|
2000-10-07 20:12:11 +02:00
|
|
|
res = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
while (left_in_data > 0)
|
|
|
|
{
|
2000-10-07 20:12:11 +02:00
|
|
|
char buf[CHUNK_SIZE + 1], *buf_ptr = buf;
|
2000-02-17 20:38:33 +01:00
|
|
|
int left_in_buf = CHUNK_SIZE;
|
|
|
|
|
|
|
|
while (left_in_buf > 0 && left_in_data > 0)
|
|
|
|
{
|
2000-10-07 20:12:11 +02:00
|
|
|
char ch = *data++;
|
|
|
|
if (ch == '\n')
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
*buf_ptr++ = '\r';
|
|
|
|
left_in_buf--;
|
|
|
|
}
|
2000-10-07 20:12:11 +02:00
|
|
|
*buf_ptr++ = ch;
|
2000-02-17 20:38:33 +01:00
|
|
|
left_in_buf--;
|
|
|
|
left_in_data--;
|
2000-10-07 20:12:11 +02:00
|
|
|
if (left_in_data > 0 && ch == '\r' && *data == '\n')
|
|
|
|
{
|
|
|
|
*buf_ptr++ = *data++;
|
|
|
|
left_in_buf--;
|
|
|
|
left_in_data--;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We've got a buffer-full, or we're out of data. Write it out */
|
2000-10-07 20:12:11 +02:00
|
|
|
int nbytes;
|
2000-02-17 20:38:33 +01:00
|
|
|
int want = buf_ptr - buf;
|
2000-10-07 20:12:11 +02:00
|
|
|
if ((nbytes = raw_write (buf, want)) == want)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-10-07 20:12:11 +02:00
|
|
|
/* Keep track of how much written not counting additional \r's */
|
|
|
|
res = data - (char *)ptr;
|
|
|
|
continue;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-10-07 20:12:11 +02:00
|
|
|
if (nbytes == -1)
|
|
|
|
res = -1; /* Error */
|
|
|
|
else
|
|
|
|
res += nbytes; /* Partial write. Return total bytes written. */
|
|
|
|
break; /* All done */
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-10-07 20:12:11 +02:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-08-30 17:47:10 +02:00
|
|
|
ssize_t
|
|
|
|
fhandler_base::readv (const struct iovec *const iov, const int iovcnt,
|
|
|
|
ssize_t tot)
|
|
|
|
{
|
|
|
|
assert (iov);
|
|
|
|
assert (iovcnt >= 1);
|
|
|
|
|
2003-07-28 23:13:17 +02:00
|
|
|
size_t len = tot;
|
2002-08-30 17:47:10 +02:00
|
|
|
if (iovcnt == 1)
|
2002-12-14 05:01:32 +01:00
|
|
|
{
|
2003-07-28 23:13:17 +02:00
|
|
|
len = iov->iov_len;
|
2002-12-14 05:01:32 +01:00
|
|
|
read (iov->iov_base, len);
|
|
|
|
return len;
|
|
|
|
}
|
2002-08-30 17:47:10 +02:00
|
|
|
|
|
|
|
if (tot == -1) // i.e. if not pre-calculated by the caller.
|
|
|
|
{
|
2003-07-28 23:13:17 +02:00
|
|
|
len = 0;
|
2002-08-30 17:47:10 +02:00
|
|
|
const struct iovec *iovptr = iov + iovcnt;
|
2002-09-19 05:30:20 +02:00
|
|
|
do
|
2002-08-30 17:47:10 +02:00
|
|
|
{
|
|
|
|
iovptr -= 1;
|
2003-07-28 23:13:17 +02:00
|
|
|
len += iovptr->iov_len;
|
2002-08-30 17:47:10 +02:00
|
|
|
}
|
|
|
|
while (iovptr != iov);
|
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:17 +02:00
|
|
|
if (!len)
|
2002-08-30 17:47:10 +02:00
|
|
|
return 0;
|
|
|
|
|
2005-11-09 00:25:55 +01:00
|
|
|
char *buf = (char *) malloc (len);
|
2002-08-30 17:47:10 +02:00
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:17 +02:00
|
|
|
read (buf, len);
|
|
|
|
ssize_t nbytes = (ssize_t) len;
|
2002-08-30 17:47:10 +02:00
|
|
|
|
|
|
|
const struct iovec *iovptr = iov;
|
|
|
|
|
2005-11-09 00:25:55 +01:00
|
|
|
char *p = buf;
|
2002-08-30 17:47:10 +02:00
|
|
|
while (nbytes > 0)
|
|
|
|
{
|
|
|
|
const int frag = min (nbytes, (ssize_t) iovptr->iov_len);
|
2005-11-09 00:25:55 +01:00
|
|
|
memcpy (iovptr->iov_base, p, frag);
|
|
|
|
p += frag;
|
2002-08-30 17:47:10 +02:00
|
|
|
iovptr += 1;
|
|
|
|
nbytes -= frag;
|
|
|
|
}
|
|
|
|
|
2005-06-30 19:00:10 +02:00
|
|
|
free (buf);
|
2003-07-28 23:13:17 +02:00
|
|
|
return len;
|
2002-08-30 17:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
fhandler_base::writev (const struct iovec *const iov, const int iovcnt,
|
|
|
|
ssize_t tot)
|
|
|
|
{
|
|
|
|
assert (iov);
|
|
|
|
assert (iovcnt >= 1);
|
|
|
|
|
|
|
|
if (iovcnt == 1)
|
|
|
|
return write (iov->iov_base, iov->iov_len);
|
|
|
|
|
|
|
|
if (tot == -1) // i.e. if not pre-calculated by the caller.
|
|
|
|
{
|
|
|
|
tot = 0;
|
|
|
|
const struct iovec *iovptr = iov + iovcnt;
|
2002-09-19 05:30:20 +02:00
|
|
|
do
|
2002-08-30 17:47:10 +02:00
|
|
|
{
|
|
|
|
iovptr -= 1;
|
|
|
|
tot += iovptr->iov_len;
|
|
|
|
}
|
|
|
|
while (iovptr != iov);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (tot >= 0);
|
|
|
|
|
|
|
|
if (tot == 0)
|
|
|
|
return 0;
|
|
|
|
|
2005-06-30 19:00:10 +02:00
|
|
|
char *const buf = (char *) malloc (tot);
|
2002-08-30 17:47:10 +02:00
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *bufptr = buf;
|
|
|
|
const struct iovec *iovptr = iov;
|
|
|
|
int nbytes = tot;
|
|
|
|
|
|
|
|
while (nbytes != 0)
|
|
|
|
{
|
|
|
|
const int frag = min (nbytes, (ssize_t) iovptr->iov_len);
|
|
|
|
memcpy (bufptr, iovptr->iov_base, frag);
|
|
|
|
bufptr += frag;
|
|
|
|
iovptr += 1;
|
|
|
|
nbytes -= frag;
|
|
|
|
}
|
2005-06-30 19:00:10 +02:00
|
|
|
ssize_t ret = write (buf, tot);
|
|
|
|
free (buf);
|
|
|
|
return ret;
|
2002-08-30 17:47:10 +02:00
|
|
|
}
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
_off64_t
|
|
|
|
fhandler_base::lseek (_off64_t offset, int whence)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-04-01 18:11:41 +02:00
|
|
|
_off64_t res;
|
2002-02-25 18:47:51 +01:00
|
|
|
|
|
|
|
/* 9x/Me doesn't support 64bit offsets. We trap that here and return
|
|
|
|
EINVAL. It doesn't make sense to simulate bigger offsets by a
|
|
|
|
SetFilePointer sequence since FAT and FAT32 don't support file
|
|
|
|
size >= 4GB anyway. */
|
|
|
|
if (!wincap.has_64bit_file_access ()
|
|
|
|
&& (offset < LONG_MIN || offset > LONG_MAX))
|
|
|
|
{
|
|
|
|
debug_printf ("Win9x, offset not 32 bit.");
|
|
|
|
set_errno (EINVAL);
|
2003-04-01 18:11:41 +02:00
|
|
|
return (_off64_t)-1;
|
2002-02-25 18:47:51 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Seeks on text files is tough, we rewind and read till we get to the
|
|
|
|
right place. */
|
|
|
|
|
|
|
|
if (whence != SEEK_CUR || offset != 0)
|
|
|
|
{
|
|
|
|
if (whence == SEEK_CUR)
|
|
|
|
offset -= ralen - raixget;
|
|
|
|
set_readahead_valid (0);
|
|
|
|
}
|
|
|
|
|
2003-09-14 03:58:03 +02:00
|
|
|
debug_printf ("lseek (%s, %D, %d)", get_name (), offset, whence);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
DWORD win32_whence = whence == SEEK_SET ? FILE_BEGIN
|
|
|
|
: (whence == SEEK_CUR ? FILE_CURRENT : FILE_END);
|
|
|
|
|
2003-12-03 17:35:52 +01:00
|
|
|
LONG off_low = ((__uint64_t) offset) & UINT32_MAX;
|
2002-05-17 21:30:52 +02:00
|
|
|
LONG *poff_high, off_high;
|
|
|
|
if (!wincap.has_64bit_file_access ())
|
|
|
|
poff_high = NULL;
|
|
|
|
else
|
|
|
|
{
|
2003-08-05 06:49:44 +02:00
|
|
|
off_high = ((__uint64_t) offset) >> 32LL;
|
2002-05-17 21:30:52 +02:00
|
|
|
poff_high = &off_high;
|
|
|
|
}
|
2002-02-25 18:47:51 +01:00
|
|
|
|
2002-05-17 21:30:52 +02:00
|
|
|
debug_printf ("setting file pointer to %u (high), %u (low)", off_high, off_low);
|
2002-09-22 05:38:57 +02:00
|
|
|
res = SetFilePointer (get_handle (), off_low, poff_high, win32_whence);
|
2002-02-25 18:47:51 +01:00
|
|
|
if (res == INVALID_SET_FILE_POINTER && GetLastError ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
__seterrno ();
|
2004-04-21 10:16:13 +02:00
|
|
|
res = -1;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-17 23:18:42 +01:00
|
|
|
if (poff_high)
|
2004-05-28 21:50:07 +02:00
|
|
|
res += (_off64_t) *poff_high << 32;
|
2003-11-17 23:18:42 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* 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 */
|
2004-04-10 15:45:10 +02:00
|
|
|
did_lseek (true);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* If this was a SEEK_CUR with offset 0, we still might have
|
|
|
|
readahead that we have to take into account when calculating
|
|
|
|
the actual position for the application. */
|
|
|
|
if (whence == SEEK_CUR)
|
|
|
|
res -= ralen - raixget;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-07-29 19:04:46 +02:00
|
|
|
ssize_t __stdcall
|
|
|
|
fhandler_base::pread (void *, size_t, _off64_t)
|
|
|
|
{
|
|
|
|
set_errno (ESPIPE);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t __stdcall
|
|
|
|
fhandler_base::pwrite (void *, size_t, _off64_t)
|
|
|
|
{
|
|
|
|
set_errno (ESPIPE);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
int
|
2001-09-01 07:17:34 +02:00
|
|
|
fhandler_base::close ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
|
2002-09-22 05:38:57 +02:00
|
|
|
syscall_printf ("closing '%s' handle %p", get_name (), get_handle ());
|
2004-04-10 15:45:10 +02:00
|
|
|
if (nohandle () || CloseHandle (get_handle ()))
|
2000-02-17 20:38:33 +01:00
|
|
|
res = 0;
|
|
|
|
else
|
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
paranoid_printf ("CloseHandle (%d <%s>) failed", get_handle (),
|
2000-02-17 20:38:33 +01:00
|
|
|
get_name ());
|
|
|
|
|
|
|
|
__seterrno ();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::ioctl (unsigned int cmd, void *buf)
|
|
|
|
{
|
2003-10-25 14:32:56 +02:00
|
|
|
int res;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-10-25 14:32:56 +02:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case FIONBIO:
|
|
|
|
set_nonblocking (*(int *) buf);
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
syscall_printf ("%d = ioctl (%x, %p)", res, cmd, buf);
|
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-12-01 18:26:28 +01:00
|
|
|
fhandler_base::lock (int, struct __flock64 *)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-09-19 05:30:20 +02:00
|
|
|
set_errno (EINVAL);
|
2000-02-17 20:38:33 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" char * __stdcall
|
2004-04-10 21:24:55 +02:00
|
|
|
rootdir (const char *full_path, char *root_path)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
/* Possible choices:
|
|
|
|
* d:... -> d:/
|
|
|
|
* \\server\share... -> \\server\share\
|
|
|
|
*/
|
2004-04-10 21:24:55 +02:00
|
|
|
int len;
|
|
|
|
char *rootp = root_path;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (full_path[1] == ':')
|
2004-04-10 21:24:55 +02:00
|
|
|
{
|
2006-12-10 13:56:50 +01:00
|
|
|
*rootp++ = *full_path;
|
2004-04-10 21:24:55 +02:00
|
|
|
*rootp++ = ':';
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
else if (full_path[0] == '\\' && full_path[1] == '\\')
|
|
|
|
{
|
2004-04-10 21:24:55 +02:00
|
|
|
const char *cp = strchr (full_path + 2, '\\');
|
|
|
|
if (!cp)
|
2005-06-24 11:12:15 +02:00
|
|
|
return NULL;
|
2004-04-10 21:24:55 +02:00
|
|
|
while (*++cp && *cp != '\\')
|
|
|
|
;
|
|
|
|
memcpy (root_path, full_path, (len = cp - full_path));
|
|
|
|
rootp = root_path + len;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
else
|
2005-06-24 11:12:15 +02:00
|
|
|
return NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-04-10 21:24:55 +02:00
|
|
|
*rootp++ = '\\';
|
|
|
|
*rootp = '\0';
|
2006-12-10 13:56:50 +01:00
|
|
|
|
2006-12-10 17:20:43 +01:00
|
|
|
/* This determines whether reparse points are available. Volume reparse
|
2006-12-11 10:07:22 +01:00
|
|
|
points on remote shares are neither recognized by Windows functions
|
|
|
|
like GetVolumeInformation, nor by their native NT counterparts. */
|
2006-12-10 17:18:51 +01:00
|
|
|
if (!wincap.has_guid_volumes () || GetDriveType (root_path) == DRIVE_REMOTE)
|
2006-12-10 13:56:50 +01:00
|
|
|
return root_path;
|
|
|
|
|
|
|
|
PREPARSE_DATA_BUFFER rp = (PREPARSE_DATA_BUFFER)
|
|
|
|
alloca (MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
|
|
|
|
|
|
|
|
char *test_path = (char *) alloca (CYG_MAX_PATH);
|
|
|
|
strcpy (test_path, full_path);
|
|
|
|
|
|
|
|
/* This determines the minimum length of the path we test for mount points.
|
|
|
|
If we're below this value, it's the root dir of the path itself. */
|
|
|
|
char *min_c = test_path + (rootp - root_path);
|
|
|
|
char *c = min_c;
|
|
|
|
while (*c)
|
|
|
|
++c;
|
|
|
|
while (c > min_c)
|
|
|
|
{
|
|
|
|
*c = '\0';
|
|
|
|
|
|
|
|
# define MOUNTPT_ATTR (FILE_ATTRIBUTE_DIRECTORY \
|
|
|
|
| FILE_ATTRIBUTE_REPARSE_POINT)
|
|
|
|
DWORD attr = GetFileAttributes (test_path);
|
|
|
|
if (attr != INVALID_FILE_ATTRIBUTES
|
|
|
|
&& (attr & MOUNTPT_ATTR) == MOUNTPT_ATTR)
|
|
|
|
{
|
|
|
|
HANDLE h = CreateFile (test_path, GENERIC_READ, FILE_SHARE_READ,
|
|
|
|
&sec_none_nih, OPEN_EXISTING,
|
|
|
|
FILE_FLAG_OPEN_REPARSE_POINT
|
|
|
|
| FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
|
|
|
if (h != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret = DeviceIoControl (h, FSCTL_GET_REPARSE_POINT, NULL,
|
|
|
|
0, (LPVOID) rp,
|
|
|
|
MAXIMUM_REPARSE_DATA_BUFFER_SIZE,
|
|
|
|
&size, NULL);
|
|
|
|
CloseHandle (h);
|
|
|
|
if (ret
|
|
|
|
&& rp->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT
|
|
|
|
&& !rp->SymbolicLinkReparseBuffer.PrintNameLength)
|
|
|
|
{
|
|
|
|
memcpy (root_path, test_path, len = c - test_path);
|
|
|
|
strcpy (root_path + len, "\\");
|
|
|
|
CloseHandle (h);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (--c > min_c && *c != '\\')
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2004-04-10 21:24:55 +02:00
|
|
|
return root_path;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2001-10-05 06:21:41 +02:00
|
|
|
int __stdcall
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_base::fstat (struct __stat64 *buf)
|
2001-10-05 06:21:41 +02:00
|
|
|
{
|
2002-07-13 22:00:27 +02:00
|
|
|
debug_printf ("here");
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
|
|
|
|
if (is_fs_special ())
|
|
|
|
return fstat_fs (buf);
|
|
|
|
|
2001-10-05 06:21:41 +02:00
|
|
|
switch (get_device ())
|
|
|
|
{
|
2002-06-24 04:23:14 +02:00
|
|
|
case FH_PIPE:
|
|
|
|
buf->st_mode = S_IFIFO | STD_RBITS | STD_WBITS | S_IWGRP | S_IWOTH;
|
|
|
|
break;
|
2001-10-05 06:21:41 +02:00
|
|
|
case FH_PIPEW:
|
2002-06-24 04:23:14 +02:00
|
|
|
buf->st_mode = S_IFIFO | STD_WBITS | S_IWGRP | S_IWOTH;
|
2001-10-05 06:21:41 +02:00
|
|
|
break;
|
|
|
|
case FH_PIPER:
|
2002-06-24 04:23:14 +02:00
|
|
|
buf->st_mode = S_IFIFO | STD_RBITS;
|
|
|
|
break;
|
2005-02-23 13:30:31 +01:00
|
|
|
case FH_FULL:
|
|
|
|
buf->st_mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
|
|
|
|
break;
|
2001-10-05 06:21:41 +02:00
|
|
|
default:
|
2002-06-24 04:23:14 +02:00
|
|
|
buf->st_mode = S_IFCHR | STD_RBITS | STD_WBITS | S_IWGRP | S_IWOTH;
|
2001-10-05 06:21:41 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-04-01 19:17:46 +02:00
|
|
|
buf->st_uid = geteuid32 ();
|
|
|
|
buf->st_gid = getegid32 ();
|
2001-10-05 06:21:41 +02:00
|
|
|
buf->st_nlink = 1;
|
2007-01-04 10:17:55 +01:00
|
|
|
buf->st_blksize = PREFERRED_IO_BLKSIZE;
|
2002-06-06 17:35:09 +02:00
|
|
|
time_as_timestruc_t (&buf->st_ctim);
|
|
|
|
buf->st_atim = buf->st_mtim = buf->st_ctim;
|
2001-10-05 06:21:41 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
void
|
|
|
|
fhandler_base::init (HANDLE f, DWORD a, mode_t bin)
|
|
|
|
{
|
|
|
|
set_io_handle (f);
|
2001-04-24 04:07:58 +02:00
|
|
|
access = a;
|
2000-02-17 20:38:33 +01:00
|
|
|
a &= GENERIC_READ | GENERIC_WRITE;
|
2002-06-05 03:42:28 +02:00
|
|
|
int flags = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
if (a == GENERIC_READ)
|
2002-06-05 03:42:28 +02:00
|
|
|
flags = O_RDONLY;
|
2002-05-31 22:48:14 +02:00
|
|
|
else if (a == GENERIC_WRITE)
|
2002-06-05 03:42:28 +02:00
|
|
|
flags = O_WRONLY;
|
2002-05-31 22:48:14 +02:00
|
|
|
else if (a == (GENERIC_READ | GENERIC_WRITE))
|
2002-06-05 03:42:28 +02:00
|
|
|
flags = O_RDWR;
|
2002-07-03 20:02:54 +02:00
|
|
|
set_flags (flags | bin);
|
2001-04-24 04:07:58 +02:00
|
|
|
set_open_status ();
|
2004-04-10 15:45:10 +02:00
|
|
|
debug_printf ("created new fhandler_base for handle %p, bin %d", f, rbinary ());
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-09-28 21:22:25 +02:00
|
|
|
fhandler_base::dup (fhandler_base *child)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
debug_printf ("in fhandler_base dup");
|
|
|
|
|
|
|
|
HANDLE nh;
|
2004-04-10 15:45:10 +02:00
|
|
|
if (!nohandle ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-09-28 21:22:25 +02:00
|
|
|
if (!DuplicateHandle (hMainProc, get_handle (), hMainProc, &nh, 0, TRUE,
|
2002-09-22 05:38:57 +02:00
|
|
|
DUPLICATE_SAME_ACCESS))
|
|
|
|
{
|
2004-09-10 10:34:37 +02:00
|
|
|
debug_printf ("dup(%s) failed, handle %x, %E",
|
|
|
|
get_name (), get_handle ());
|
2002-09-22 05:38:57 +02:00
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-01-24 00:05:33 +01:00
|
|
|
VerifyHandle (nh);
|
2002-09-22 05:38:57 +02:00
|
|
|
child->set_io_handle (nh);
|
|
|
|
}
|
2005-09-28 21:22:25 +02:00
|
|
|
set_flags (child->get_flags ());
|
2000-02-17 20:38:33 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-23 22:16:52 +02:00
|
|
|
int fhandler_base::fcntl (int cmd, void *arg)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case F_GETFD:
|
2004-04-10 15:45:10 +02:00
|
|
|
res = close_on_exec () ? FD_CLOEXEC : 0;
|
2000-10-23 22:16:52 +02:00
|
|
|
break;
|
|
|
|
case F_SETFD:
|
2004-04-10 15:45:10 +02:00
|
|
|
set_close_on_exec (((int) arg & FD_CLOEXEC) ? 1 : 0);
|
2000-10-23 22:16:52 +02:00
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
case F_GETFL:
|
|
|
|
res = get_flags ();
|
2006-03-22 17:42:45 +01:00
|
|
|
debug_printf ("GETFL: %p", res);
|
2000-10-23 22:16:52 +02:00
|
|
|
break;
|
|
|
|
case F_SETFL:
|
2000-10-23 22:29:31 +02:00
|
|
|
{
|
|
|
|
/*
|
2000-10-24 20:15:25 +02:00
|
|
|
* Only O_APPEND, O_ASYNC and O_NONBLOCK/O_NDELAY are allowed.
|
2000-10-23 22:29:31 +02:00
|
|
|
* Each other flag will be ignored.
|
|
|
|
* Since O_ASYNC isn't defined in fcntl.h it's currently
|
|
|
|
* ignored as well.
|
|
|
|
*/
|
2001-09-07 23:32:07 +02:00
|
|
|
const int allowed_flags = O_APPEND | O_NONBLOCK_MASK;
|
2001-08-07 02:01:42 +02:00
|
|
|
int new_flags = (int) arg & allowed_flags;
|
2001-09-07 23:32:07 +02:00
|
|
|
/* Carefully test for the O_NONBLOCK or deprecated OLD_O_NDELAY flag.
|
2001-08-07 02:01:42 +02:00
|
|
|
Set only the flag that has been passed in. If both are set, just
|
|
|
|
record O_NONBLOCK. */
|
|
|
|
if ((new_flags & OLD_O_NDELAY) && (new_flags & O_NONBLOCK))
|
2003-10-24 14:11:20 +02:00
|
|
|
new_flags &= ~OLD_O_NDELAY;
|
2001-08-07 02:01:42 +02:00
|
|
|
set_flags ((get_flags () & ~allowed_flags) | new_flags);
|
2000-10-23 22:29:31 +02:00
|
|
|
}
|
2000-10-23 22:16:52 +02:00
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
case F_GETLK:
|
|
|
|
case F_SETLK:
|
|
|
|
case F_SETLKW:
|
2003-12-01 18:26:28 +01:00
|
|
|
res = lock (cmd, (struct __flock64 *) arg);
|
2000-10-23 22:16:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Base terminal handlers. These just return errors. */
|
|
|
|
|
|
|
|
int
|
2000-02-21 06:20:38 +01:00
|
|
|
fhandler_base::tcflush (int)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 06:20:38 +01:00
|
|
|
fhandler_base::tcsendbreak (int)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-07-05 05:16:46 +02:00
|
|
|
fhandler_base::tcdrain ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 06:20:38 +01:00
|
|
|
fhandler_base::tcflow (int)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 06:20:38 +01:00
|
|
|
fhandler_base::tcsetattr (int, const struct termios *)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 06:20:38 +01:00
|
|
|
fhandler_base::tcgetattr (struct termios *)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 06:20:38 +01:00
|
|
|
fhandler_base::tcsetpgrp (const pid_t)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-07-05 05:16:46 +02:00
|
|
|
fhandler_base::tcgetpgrp ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-09-03 06:16:35 +02:00
|
|
|
void
|
|
|
|
fhandler_base::operator delete (void *p)
|
|
|
|
{
|
|
|
|
cfree (p);
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Normal I/O constructor */
|
2004-04-09 10:43:29 +02:00
|
|
|
fhandler_base::fhandler_base () :
|
|
|
|
status (),
|
|
|
|
open_status (),
|
2001-04-24 04:07:58 +02:00
|
|
|
access (0),
|
2000-02-17 20:38:33 +01:00
|
|
|
io_handle (NULL),
|
2001-04-24 04:07:58 +02:00
|
|
|
namehash (0),
|
|
|
|
openflags (0),
|
2000-02-17 20:38:33 +01:00
|
|
|
rabuf (NULL),
|
|
|
|
ralen (0),
|
|
|
|
raixget (0),
|
|
|
|
raixput (0),
|
2001-04-24 04:07:58 +02:00
|
|
|
rabuflen (0),
|
2003-05-26 11:54:01 +02:00
|
|
|
fs_flags (0),
|
2003-12-11 07:12:41 +01:00
|
|
|
read_state (NULL),
|
|
|
|
archetype (NULL),
|
|
|
|
usecount (0)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal I/O destructor */
|
2005-07-05 05:16:46 +02:00
|
|
|
fhandler_base::~fhandler_base ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-09-03 06:16:35 +02:00
|
|
|
if (rabuf)
|
|
|
|
free (rabuf);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
/* /dev/null */
|
|
|
|
|
2001-10-13 19:23:35 +02:00
|
|
|
fhandler_dev_null::fhandler_dev_null () :
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_base ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-01-31 22:29:59 +01:00
|
|
|
int
|
|
|
|
fhandler_dev_null::open (int flags, mode_t mode)
|
|
|
|
{
|
|
|
|
char posix[strlen (get_name ()) + 1];
|
|
|
|
strcpy (posix, get_name ());
|
|
|
|
pc.set_name ("NUL", posix);
|
|
|
|
return fhandler_base::open_9x (flags, mode);
|
|
|
|
}
|
|
|
|
|
2000-04-20 06:38:10 +02:00
|
|
|
void
|
2006-12-11 19:55:29 +01:00
|
|
|
fhandler_base::set_no_inheritance (HANDLE &h, bool not_inheriting)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2006-12-11 19:55:29 +01:00
|
|
|
if (wincap.has_set_handle_information ())
|
|
|
|
{
|
|
|
|
if (!SetHandleInformation (h, HANDLE_FLAG_INHERIT, not_inheriting ? 0 : HANDLE_FLAG_INHERIT))
|
|
|
|
debug_printf ("SetHandleInformation failed, %E");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HANDLE oh = h;
|
|
|
|
if (!DuplicateHandle (hMainProc, oh, hMainProc, &h, 0, !not_inheriting,
|
|
|
|
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
|
|
|
|
debug_printf ("DuplicateHandle failed, %E");
|
|
|
|
|
|
|
|
if (oh != h)
|
|
|
|
VerifyHandle (h);
|
|
|
|
}
|
2002-07-14 21:15:32 +02:00
|
|
|
#ifdef DEBUGGING_AND_FDS_PROTECTED
|
2001-10-24 06:16:45 +02:00
|
|
|
if (h)
|
2002-07-13 22:00:27 +02:00
|
|
|
setclexec (oh, h, not_inheriting);
|
2000-02-17 20:38:33 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-05-25 07:40:51 +02:00
|
|
|
bool
|
2000-02-17 20:38:33 +01:00
|
|
|
fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
|
|
|
|
{
|
2004-01-24 00:05:33 +01:00
|
|
|
HANDLE oh = h;
|
2006-05-25 07:40:51 +02:00
|
|
|
bool res = false;
|
2004-04-10 15:45:10 +02:00
|
|
|
if (/* !is_socket () && */ !close_on_exec ())
|
2001-07-21 05:20:01 +02:00
|
|
|
debug_printf ("handle %p already opened", h);
|
2004-04-10 15:45:10 +02:00
|
|
|
else if (!DuplicateHandle (parent, h, hMainProc, &h, 0, !close_on_exec (),
|
2001-10-06 03:04:24 +02:00
|
|
|
DUPLICATE_SAME_ACCESS))
|
2000-02-17 20:38:33 +01:00
|
|
|
system_printf ("%s - %E, handle %s<%p>", get_name (), name, h);
|
2006-05-25 07:40:51 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (oh != h)
|
|
|
|
VerifyHandle (h);
|
|
|
|
res = true;
|
|
|
|
}
|
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-10 15:45:10 +02:00
|
|
|
fhandler_base::set_close_on_exec (bool val)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2004-04-10 15:45:10 +02:00
|
|
|
if (!nohandle ())
|
2004-02-02 21:33:09 +01:00
|
|
|
set_no_inheritance (io_handle, val);
|
2004-04-10 15:45:10 +02:00
|
|
|
close_on_exec (val);
|
2000-02-17 20:38:33 +01:00
|
|
|
debug_printf ("set close_on_exec for %s to %d", get_name (), val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_base::fixup_after_fork (HANDLE parent)
|
|
|
|
{
|
|
|
|
debug_printf ("inheriting '%s' from parent", get_name ());
|
2004-04-10 15:45:10 +02:00
|
|
|
if (!nohandle ())
|
2002-09-19 05:30:20 +02:00
|
|
|
fork_fixup (parent, io_handle, "io_handle");
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2001-08-15 09:49:15 +02:00
|
|
|
|
2006-06-02 17:41:34 +02:00
|
|
|
void
|
|
|
|
fhandler_base::fixup_after_exec ()
|
|
|
|
{
|
|
|
|
debug_printf ("here for '%s'", get_name ());
|
|
|
|
}
|
|
|
|
|
2001-11-24 04:11:39 +01:00
|
|
|
bool
|
2001-08-15 09:49:15 +02:00
|
|
|
fhandler_base::is_nonblocking ()
|
|
|
|
{
|
|
|
|
return (openflags & O_NONBLOCK_MASK) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_base::set_nonblocking (int yes)
|
|
|
|
{
|
|
|
|
int current = openflags & O_NONBLOCK_MASK;
|
|
|
|
int new_flags = yes ? (!current ? O_NONBLOCK : current) : 0;
|
|
|
|
openflags = (openflags & ~O_NONBLOCK_MASK) | new_flags;
|
|
|
|
}
|
2001-11-21 07:47:57 +01:00
|
|
|
|
2005-05-25 06:32:59 +02:00
|
|
|
int
|
|
|
|
fhandler_base::mkdir (mode_t)
|
|
|
|
{
|
|
|
|
if (exists ())
|
|
|
|
set_errno (EEXIST);
|
|
|
|
else
|
|
|
|
set_errno (EROFS);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::rmdir ()
|
|
|
|
{
|
|
|
|
if (!exists ())
|
|
|
|
set_errno (ENOENT);
|
|
|
|
else if (!pc.isdir ())
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
else
|
|
|
|
set_errno (EROFS);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-11-21 07:47:57 +01:00
|
|
|
DIR *
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_base::opendir ()
|
2001-11-21 07:47:57 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-20 08:19:55 +02:00
|
|
|
int
|
|
|
|
fhandler_base::readdir (DIR *, dirent *)
|
2001-11-21 07:47:57 +01:00
|
|
|
{
|
2005-08-20 08:19:55 +02:00
|
|
|
return ENOTDIR;
|
2001-11-21 07:47:57 +01:00
|
|
|
}
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
_off64_t
|
2001-11-21 07:47:57 +01:00
|
|
|
fhandler_base::telldir (DIR *)
|
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-04-01 18:11:41 +02:00
|
|
|
fhandler_base::seekdir (DIR *, _off64_t)
|
2001-11-21 07:47:57 +01:00
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_base::rewinddir (DIR *)
|
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::closedir (DIR *)
|
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-13 22:36:58 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::fchmod (mode_t mode)
|
|
|
|
{
|
2004-12-26 03:10:30 +01:00
|
|
|
extern int chmod_device (path_conv& pc, mode_t mode);
|
|
|
|
if (pc.is_fs_special ())
|
|
|
|
return chmod_device (pc, mode);
|
2004-04-13 22:36:58 +02:00
|
|
|
/* By default, just succeeds. */
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-14 15:40:07 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::fchown (__uid32_t uid, __gid32_t gid)
|
|
|
|
{
|
2004-12-26 03:10:30 +01:00
|
|
|
if (pc.is_fs_special ())
|
|
|
|
return ((fhandler_disk_file *) this)->fhandler_disk_file::fchown (uid, gid);
|
2004-04-14 15:40:07 +02:00
|
|
|
/* By default, just succeeds. */
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-14 18:36:26 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::facl (int cmd, int nentries, __aclent32_t *aclbufp)
|
|
|
|
{
|
2005-01-14 23:03:40 +01:00
|
|
|
int res = -1;
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SETACL:
|
|
|
|
/* By default, just succeeds. */
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
case GETACL:
|
|
|
|
if (!aclbufp)
|
|
|
|
set_errno(EFAULT);
|
|
|
|
else if (nentries < MIN_ACL_ENTRIES)
|
|
|
|
set_errno (ENOSPC);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aclbufp[0].a_type = USER_OBJ;
|
|
|
|
aclbufp[0].a_id = myself->uid;
|
|
|
|
aclbufp[0].a_perm = (S_IRUSR | S_IWUSR) >> 6;
|
|
|
|
aclbufp[1].a_type = GROUP_OBJ;
|
|
|
|
aclbufp[1].a_id = myself->gid;
|
|
|
|
aclbufp[1].a_perm = (S_IRGRP | S_IWGRP) >> 3;
|
|
|
|
aclbufp[2].a_type = OTHER_OBJ;
|
|
|
|
aclbufp[2].a_id = ILLEGAL_GID;
|
|
|
|
aclbufp[2].a_perm = S_IROTH | S_IWOTH;
|
|
|
|
aclbufp[3].a_type = CLASS_OBJ;
|
|
|
|
aclbufp[3].a_id = ILLEGAL_GID;
|
|
|
|
aclbufp[3].a_perm = S_IRWXU | S_IRWXG | S_IRWXO;
|
|
|
|
res = MIN_ACL_ENTRIES;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GETACLCNT:
|
|
|
|
res = MIN_ACL_ENTRIES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
2004-04-14 18:36:26 +02:00
|
|
|
}
|
2005-02-02 23:42:06 +01:00
|
|
|
|
|
|
|
int
|
2006-08-07 21:29:14 +02:00
|
|
|
fhandler_base::fadvise (_off64_t offset, _off64_t length, int advice)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::ftruncate (_off64_t length, bool allow_truncate)
|
2005-02-02 23:42:06 +01:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-19 22:53:36 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::link (const char *newpath)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-20 12:44:32 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::utimes (const struct timeval *tvp)
|
|
|
|
{
|
2005-04-13 18:17:37 +02:00
|
|
|
if (is_fs_special ())
|
|
|
|
return utimes_fs (tvp);
|
|
|
|
|
2005-02-20 12:44:32 +01:00
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-20 14:28:23 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::fsync ()
|
|
|
|
{
|
2005-02-22 16:30:09 +01:00
|
|
|
if (!get_handle () || nohandle ())
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-20 14:28:23 +01:00
|
|
|
if (pc.isdir ()) /* Just succeed. */
|
|
|
|
return 0;
|
|
|
|
if (FlushFileBuffers (get_handle ()))
|
|
|
|
return 0;
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2006-11-07 18:59:54 +01:00
|
|
|
|
|
|
|
/* Helper function for Cygwin specific pathconf flags _PC_POSIX_PERMISSIONS
|
|
|
|
and _PC_POSIX_SECURITY. */
|
|
|
|
static int
|
|
|
|
check_posix_perm (const char *fname, int v)
|
|
|
|
{
|
|
|
|
/* Windows 95/98/ME don't support file system security at all. */
|
|
|
|
if (!wincap.has_security ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* ntea is ok for supporting permission bits but it doesn't support
|
|
|
|
full POSIX security settings. */
|
|
|
|
if (v == _PC_POSIX_PERMISSIONS && allow_ntea)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!allow_ntsec)
|
|
|
|
return 0;
|
|
|
|
|
2006-12-10 13:56:50 +01:00
|
|
|
char *root = rootdir (fname, (char *)alloca (strlen (fname) + 2));
|
2006-11-07 18:59:54 +01:00
|
|
|
|
|
|
|
if (!allow_smbntsec
|
|
|
|
&& ((root[0] == '\\' && root[1] == '\\')
|
|
|
|
|| GetDriveType (root) == DRIVE_REMOTE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
DWORD vsn, len, flags;
|
|
|
|
if (!GetVolumeInformation (root, NULL, 0, &vsn, &len, &flags, NULL, 16))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (flags & FS_PERSISTENT_ACLS) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::fpathconf (int v)
|
|
|
|
{
|
|
|
|
switch (v)
|
|
|
|
{
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
return pc.fs_is_ntfs () || pc.fs_is_samba () || pc.fs_is_nfs ()
|
|
|
|
? LINK_MAX : 1;
|
|
|
|
case _PC_MAX_CANON:
|
|
|
|
if (is_tty ())
|
|
|
|
return MAX_CANON;
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
case _PC_MAX_INPUT:
|
|
|
|
if (is_tty ())
|
|
|
|
return MAX_INPUT;
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
case _PC_NAME_MAX:
|
|
|
|
/* NAME_MAX is without trailing \0 */
|
|
|
|
return pc.isdir () ? PATH_MAX - strlen (get_name ()) - 2 : NAME_MAX;
|
|
|
|
case _PC_PATH_MAX:
|
|
|
|
/* PATH_MAX is with trailing \0 */
|
|
|
|
return pc.isdir () ? PATH_MAX - strlen (get_name ()) - 1 : PATH_MAX;
|
|
|
|
case _PC_PIPE_BUF:
|
|
|
|
if (pc.isdir ()
|
|
|
|
|| get_device () == FH_FIFO || get_device () == FH_PIPE
|
|
|
|
|| get_device () == FH_PIPER || get_device () == FH_PIPEW)
|
|
|
|
return PIPE_BUF;
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
case _PC_CHOWN_RESTRICTED:
|
|
|
|
return 1;
|
|
|
|
case _PC_NO_TRUNC:
|
|
|
|
return 1;
|
|
|
|
case _PC_VDISABLE:
|
|
|
|
if (!is_tty ())
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
case _PC_ASYNC_IO:
|
|
|
|
case _PC_PRIO_IO:
|
|
|
|
case _PC_SYNC_IO:
|
|
|
|
break;
|
|
|
|
case _PC_FILESIZEBITS:
|
|
|
|
return FILESIZEBITS;
|
|
|
|
case _PC_2_SYMLINKS:
|
|
|
|
return 1;
|
|
|
|
case _PC_SYMLINK_MAX:
|
|
|
|
break;
|
|
|
|
case _PC_POSIX_PERMISSIONS:
|
|
|
|
case _PC_POSIX_SECURITY:
|
|
|
|
if (get_device () == FH_FS)
|
|
|
|
return check_posix_perm (get_win32_name (), v);
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|