2000-02-18 03:38:33 +08:00
|
|
|
/* fhandler.cc. See console.cc for fhandler_console functions.
|
|
|
|
|
|
|
|
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-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-30 23:47:10 +08:00
|
|
|
#include <sys/uio.h>
|
2016-01-07 01:41:36 +08:00
|
|
|
#include <cygwin/acl.h>
|
2012-03-08 17:36:11 +08:00
|
|
|
#include <sys/param.h>
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2001-03-05 14:28:25 +08:00
|
|
|
#include "perprocess.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-08-07 08:01:42 +08:00
|
|
|
#include "cygwin/version.h"
|
2001-10-01 12:10:07 +08: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 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2001-10-05 12:21:41 +08:00
|
|
|
#include "pinfo.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include <assert.h>
|
2003-05-26 17:54:01 +08:00
|
|
|
#include <winioctl.h>
|
2004-04-17 05:22:13 +08:00
|
|
|
#include "ntdll.h"
|
2007-07-08 01:00:33 +08:00
|
|
|
#include "cygtls.h"
|
|
|
|
#include "sigproc.h"
|
2011-11-29 23:34:49 +08:00
|
|
|
#include "shared_info.h"
|
2011-07-22 04:21:46 +08:00
|
|
|
#include <asm/socket.h>
|
2012-06-18 04:50:24 +08:00
|
|
|
#include "cygwait.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-11-07 18:06:45 +08:00
|
|
|
static const int CHUNK_SIZE = 1024; /* Used for crlf conversions */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-09-06 12:41:59 +08:00
|
|
|
struct __cygwin_perfile *perfile_table;
|
2000-07-09 13:29:51 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2002-02-20 06:06:50 +08:00
|
|
|
fhandler_base::puts_readahead (const char *s, size_t len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int success = 1;
|
2004-12-12 10:15:34 +08:00
|
|
|
while ((len == (size_t) -1 ? *s : len--)
|
2000-09-03 12:16:35 +08:00
|
|
|
&& (success = put_readahead (*s++) > 0))
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::put_readahead (char value)
|
|
|
|
{
|
|
|
|
char *newrabuf;
|
2020-01-27 20:14:32 +08:00
|
|
|
if (raixput () < rabuflen ())
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Nothing to do */;
|
2020-01-27 20:14:32 +08:00
|
|
|
else if ((newrabuf = (char *) realloc (rabuf (), rabuflen () += 32)))
|
|
|
|
rabuf () = newrabuf;
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
2020-01-27 20:14:32 +08:00
|
|
|
rabuf ()[raixput ()++] = value;
|
|
|
|
ralen ()++;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::get_readahead ()
|
|
|
|
{
|
|
|
|
int chret = -1;
|
2020-01-27 20:14:32 +08:00
|
|
|
if (raixget () < ralen ())
|
|
|
|
chret = ((unsigned char) rabuf ()[raixget ()++]) & 0xff;
|
2000-02-18 03:38:33 +08:00
|
|
|
/* FIXME - not thread safe */
|
2020-01-27 20:14:32 +08:00
|
|
|
if (raixget () >= ralen ())
|
|
|
|
raixget () = raixput () = ralen () = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
return chret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::peek_readahead (int queryput)
|
|
|
|
{
|
|
|
|
int chret = -1;
|
2020-01-27 20:14:32 +08:00
|
|
|
if (!queryput && raixget () < ralen ())
|
|
|
|
chret = ((unsigned char) rabuf ()[raixget ()]) & 0xff;
|
|
|
|
else if (queryput && raixput () > 0)
|
|
|
|
chret = ((unsigned char) rabuf ()[raixput () - 1]) & 0xff;
|
2000-02-18 03:38:33 +08:00
|
|
|
return chret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-20 06:06:50 +08:00
|
|
|
fhandler_base::set_readahead_valid (int val, int ch)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (!val)
|
2020-01-27 20:14:32 +08:00
|
|
|
ralen () = raixget () = raixput () = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (ch != -1)
|
2002-09-22 11:38:57 +08:00
|
|
|
put_readahead (ch);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-03-12 14:29:54 +08: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 08:37:18 +08:00
|
|
|
/* Record the file name. and name hash */
|
|
|
|
void
|
|
|
|
fhandler_base::set_name (path_conv &in_pc)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-10-23 00:26:30 +08:00
|
|
|
pc << in_pc;
|
2001-10-01 12:10:07 +08:00
|
|
|
}
|
|
|
|
|
2005-01-31 18:28:55 +08:00
|
|
|
char *fhandler_base::get_proc_fd_name (char *buf)
|
|
|
|
{
|
2018-12-27 04:22:40 +08:00
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
FILE_STANDARD_INFORMATION fsi;
|
|
|
|
|
2019-01-06 05:16:30 +08:00
|
|
|
/* If the file had been opened with O_TMPFILE, don't expose the filename. */
|
|
|
|
if ((get_flags () & O_TMPFILE)
|
2018-12-27 04:22:40 +08:00
|
|
|
|| (get_device () == FH_FS
|
|
|
|
&& NT_SUCCESS (NtQueryInformationFile (get_handle (), &io,
|
|
|
|
&fsi, sizeof fsi,
|
|
|
|
FileStandardInformation))
|
|
|
|
&& fsi.DeletePending))
|
|
|
|
{
|
|
|
|
stpcpy (stpcpy (buf, get_name ()), " (deleted)");
|
|
|
|
return buf;
|
|
|
|
}
|
2005-01-31 18:28:55 +08:00
|
|
|
if (get_name ())
|
|
|
|
return strcpy (buf, get_name ());
|
2016-06-23 22:56:41 +08:00
|
|
|
if (dev ().name ())
|
|
|
|
return strcpy (buf, dev ().name ());
|
2005-02-01 23:11:47 +08:00
|
|
|
return strcpy (buf, "");
|
2005-01-31 18:28:55 +08:00
|
|
|
}
|
|
|
|
|
2000-11-27 05:45:16 +08:00
|
|
|
/* Detect if we are sitting at EOF for conditions where Windows
|
|
|
|
returns an error but UNIX doesn't. */
|
2011-05-05 17:05:04 +08:00
|
|
|
int __stdcall
|
|
|
|
is_at_eof (HANDLE h)
|
2000-11-27 05:45:16 +08:00
|
|
|
{
|
2007-10-15 16:25:38 +08:00
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
FILE_POSITION_INFORMATION fpi;
|
|
|
|
FILE_STANDARD_INFORMATION fsi;
|
|
|
|
|
|
|
|
if (NT_SUCCESS (NtQueryInformationFile (h, &io, &fsi, sizeof fsi,
|
|
|
|
FileStandardInformation))
|
|
|
|
&& NT_SUCCESS (NtQueryInformationFile (h, &io, &fpi, sizeof fpi,
|
|
|
|
FilePositionInformation))
|
|
|
|
&& fsi.EndOfFile.QuadPart == fpi.CurrentByteOffset.QuadPart)
|
|
|
|
return 1;
|
2000-11-27 05:45:16 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-20 08:36:40 +08:00
|
|
|
void
|
|
|
|
fhandler_base::set_flags (int flags, int supplied_bin)
|
|
|
|
{
|
|
|
|
int bin;
|
|
|
|
int fmode;
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("flags %y, supplied_bin %y", flags, supplied_bin);
|
2002-06-20 08:36:40 +08:00
|
|
|
if ((bin = flags & (O_BINARY | O_TEXT)))
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("O_TEXT/O_BINARY set in flags %y", bin);
|
2004-04-10 21:45:10 +08:00
|
|
|
else if (rbinset () && wbinset ())
|
|
|
|
bin = rbinary () ? O_BINARY : O_TEXT; // FIXME: Not quite right
|
2002-06-20 08:36:40 +08: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
|
2008-07-18 16:16:40 +08:00
|
|
|
bin = wbinary () || rbinary () ? O_BINARY : O_TEXT;
|
2002-06-20 08:36:40 +08:00
|
|
|
|
|
|
|
openflags = flags | bin;
|
|
|
|
|
|
|
|
bin &= O_BINARY;
|
2004-04-10 21:45:10 +08:00
|
|
|
rbinary (bin ? true : false);
|
|
|
|
wbinary (bin ? true : false);
|
2002-06-20 08:36:40 +08:00
|
|
|
syscall_printf ("filemode set to %s", bin ? "binary" : "text");
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Normal file i/o handlers. */
|
|
|
|
|
|
|
|
/* Cover function to ReadFile to achieve (as much as possible) Posix style
|
|
|
|
semantics and use of errno. */
|
2013-05-01 09:20:37 +08:00
|
|
|
void __reg3
|
2013-04-23 17:44:36 +08:00
|
|
|
fhandler_base::raw_read (void *ptr, size_t& len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK io;
|
2006-08-10 22:16:24 +08:00
|
|
|
int try_noreserve = 1;
|
2002-12-15 02:01:08 +08:00
|
|
|
|
2006-08-10 22:16:24 +08:00
|
|
|
retry:
|
2013-04-23 17:44:36 +08:00
|
|
|
status = NtReadFile (get_handle (), NULL, NULL, NULL, &io, ptr, len,
|
|
|
|
NULL, NULL);
|
2019-05-09 22:41:41 +08:00
|
|
|
if (NT_SUCCESS (status))
|
2013-04-23 17:44:36 +08:00
|
|
|
len = io.Information;
|
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* Some errors are not really errors. Detect such cases here. */
|
2013-04-23 17:44:36 +08:00
|
|
|
switch (status)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
case STATUS_END_OF_FILE:
|
|
|
|
case STATUS_PIPE_BROKEN:
|
2000-02-18 03:38:33 +08:00
|
|
|
/* This is really EOF. */
|
2013-04-23 17:44:36 +08:00
|
|
|
len = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2013-04-23 17:44:36 +08:00
|
|
|
case STATUS_MORE_ENTRIES:
|
|
|
|
case STATUS_BUFFER_OVERFLOW:
|
|
|
|
/* `io.Information' is supposedly valid. */
|
|
|
|
len = io.Information;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2013-04-23 17:44:36 +08:00
|
|
|
case STATUS_ACCESS_VIOLATION:
|
2011-05-05 17:05:04 +08:00
|
|
|
if (is_at_eof (get_handle ()))
|
2002-12-14 12:01:32 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
len = 0;
|
2002-12-14 12:01:32 +08:00
|
|
|
break;
|
|
|
|
}
|
2006-08-10 22:16:24 +08: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;
|
|
|
|
}
|
|
|
|
}
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2013-04-23 17:44:36 +08:00
|
|
|
case STATUS_INVALID_DEVICE_REQUEST:
|
|
|
|
case STATUS_INVALID_PARAMETER:
|
|
|
|
case STATUS_INVALID_HANDLE:
|
2006-07-14 04:56:24 +08:00
|
|
|
if (pc.isdir ())
|
2001-10-01 12:10:07 +08:00
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
2013-04-23 17:44:36 +08:00
|
|
|
len = (size_t) -1;
|
2002-12-14 12:01:32 +08:00
|
|
|
break;
|
2001-10-01 12:10:07 +08:00
|
|
|
}
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2000-02-18 03:38:33 +08:00
|
|
|
default:
|
2013-04-23 17:44:36 +08:00
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
len = (size_t) -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cover function to WriteFile to provide Posix interface and semantics
|
|
|
|
(as much as possible). */
|
2013-05-01 09:20:37 +08:00
|
|
|
ssize_t __reg3
|
2000-02-18 03:38:33 +08:00
|
|
|
fhandler_base::raw_write (const void *ptr, size_t len)
|
|
|
|
{
|
2007-10-15 16:25:38 +08:00
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK io;
|
2011-11-04 01:47:33 +08:00
|
|
|
static _RDATA LARGE_INTEGER off_current =
|
|
|
|
{ QuadPart:FILE_USE_FILE_POINTER_POSITION };
|
|
|
|
static _RDATA LARGE_INTEGER off_append =
|
|
|
|
{ QuadPart:FILE_WRITE_TO_END_OF_FILE };
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2007-10-15 16:25:38 +08:00
|
|
|
status = NtWriteFile (get_output_handle (), NULL, NULL, NULL, &io,
|
|
|
|
(PVOID) ptr, len,
|
|
|
|
(get_flags () & O_APPEND) ? &off_append : &off_current,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS (status))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-10-15 16:25:38 +08:00
|
|
|
__seterrno_from_nt_status (status);
|
2000-02-18 03:38:33 +08:00
|
|
|
if (get_errno () == EPIPE)
|
|
|
|
raise (SIGPIPE);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-15 16:25:38 +08:00
|
|
|
return io.Information;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-07-09 13:29:51 +08:00
|
|
|
int
|
|
|
|
fhandler_base::get_default_fmode (int flags)
|
|
|
|
{
|
2002-07-14 04:00:27 +08:00
|
|
|
int fmode = __fmode;
|
2000-07-09 13:29:51 +08:00
|
|
|
if (perfile_table)
|
|
|
|
{
|
|
|
|
size_t nlen = strlen (get_name ());
|
2005-12-15 00:38:22 +08:00
|
|
|
unsigned accflags = (flags & O_ACCMODE);
|
2000-07-09 13:29:51 +08:00
|
|
|
for (__cygwin_perfile *pf = perfile_table; pf->name; pf++)
|
2005-12-15 00:38:22 +08:00
|
|
|
if (!*pf->name && (pf->flags & O_ACCMODE) == accflags)
|
2002-07-14 04:00:27 +08:00
|
|
|
{
|
2005-12-15 00:38:22 +08:00
|
|
|
fmode = pf->flags & ~O_ACCMODE;
|
2002-07-14 04:00:27 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-11-03 12:27:03 +08: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-15 00:38:22 +08:00
|
|
|
else if ((pf->flags & O_ACCMODE) == accflags
|
2008-07-17 04:20:45 +08:00
|
|
|
&& pathmatch (stem, pf->name, !!pc.objcaseinsensitive ()))
|
2002-07-14 04:00:27 +08:00
|
|
|
{
|
2005-12-15 00:38:22 +08:00
|
|
|
fmode = pf->flags & ~O_ACCMODE;
|
2002-07-14 04:00:27 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-11-03 12:27:03 +08:00
|
|
|
}
|
2000-07-09 13:29:51 +08:00
|
|
|
}
|
2002-07-14 04:00:27 +08:00
|
|
|
return fmode;
|
2000-07-09 13:29:51 +08: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 08:37:18 +08:00
|
|
|
bool
|
|
|
|
fhandler_base::device_access_denied (int flags)
|
|
|
|
{
|
|
|
|
int mode = 0;
|
|
|
|
|
2020-01-24 00:31:04 +08:00
|
|
|
if (flags & O_PATH)
|
|
|
|
return false;
|
|
|
|
|
* 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 08:37:18 +08:00
|
|
|
if (flags & O_RDWR)
|
|
|
|
mode |= R_OK | W_OK;
|
|
|
|
if (flags & (O_WRONLY | O_APPEND))
|
|
|
|
mode |= W_OK;
|
|
|
|
if (!mode)
|
|
|
|
mode |= R_OK;
|
|
|
|
|
2009-09-25 21:44:45 +08:00
|
|
|
return fhaccess (mode, true);
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
|
|
|
|
2004-01-25 04:34:27 +08:00
|
|
|
int
|
2009-09-25 21:44:45 +08:00
|
|
|
fhandler_base::fhaccess (int flags, bool effective)
|
2004-01-24 11:40:33 +08:00
|
|
|
{
|
2004-01-25 04:34:27 +08:00
|
|
|
int res = -1;
|
2004-01-24 11:40:33 +08:00
|
|
|
if (error ())
|
|
|
|
{
|
|
|
|
set_errno (error ());
|
2004-01-25 04:34:27 +08:00
|
|
|
goto done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!exists ())
|
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
2004-01-25 04:34:27 +08:00
|
|
|
goto done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & (R_OK | W_OK | X_OK)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (is_fs_special ())
|
|
|
|
/* short circuit */;
|
2007-10-30 20:32:16 +08:00
|
|
|
else if (has_attribute (FILE_ATTRIBUTE_READONLY) && (flags & W_OK)
|
|
|
|
&& !pc.isdir ())
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2008-07-15 04:22:03 +08:00
|
|
|
else if (has_acls ())
|
2004-01-24 11:40:33 +08:00
|
|
|
{
|
2009-09-25 21:44:45 +08:00
|
|
|
res = check_file_access (pc, flags, effective);
|
2004-01-25 04:34:27 +08:00
|
|
|
goto done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
2008-07-15 04:22:03 +08:00
|
|
|
else if (get_device () == FH_REGISTRY && open (O_RDONLY, 0) && get_handle ())
|
2006-10-21 19:05:32 +08:00
|
|
|
{
|
2009-09-25 21:44:45 +08:00
|
|
|
res = check_registry_access (get_handle (), flags, effective);
|
2006-10-21 19:05:32 +08:00
|
|
|
close ();
|
|
|
|
return res;
|
|
|
|
}
|
2004-01-24 11:40:33 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
struct stat st;
|
2004-01-25 04:34:27 +08:00
|
|
|
if (fstat (&st))
|
|
|
|
goto done;
|
|
|
|
|
2004-01-24 11:40:33 +08:00
|
|
|
if (flags & R_OK)
|
|
|
|
{
|
2009-09-25 21:44:45 +08:00
|
|
|
if (st.st_uid == (effective ? myself->uid : cygheap->user.real_uid))
|
2004-01-24 11:40:33 +08:00
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IRUSR))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
2009-09-25 21:44:45 +08:00
|
|
|
else if (st.st_gid == (effective ? myself->gid : cygheap->user.real_gid))
|
2004-01-24 11:40:33 +08:00
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IRGRP))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
|
|
|
else if (!(st.st_mode & S_IROTH))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
2004-01-25 04:34:27 +08:00
|
|
|
|
2004-01-24 11:40:33 +08:00
|
|
|
if (flags & W_OK)
|
|
|
|
{
|
2009-09-25 21:44:45 +08:00
|
|
|
if (st.st_uid == (effective ? myself->uid : cygheap->user.real_uid))
|
2004-01-24 11:40:33 +08:00
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IWUSR))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
2009-09-25 21:44:45 +08:00
|
|
|
else if (st.st_gid == (effective ? myself->gid : cygheap->user.real_gid))
|
2004-01-24 11:40:33 +08:00
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IWGRP))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
|
|
|
else if (!(st.st_mode & S_IWOTH))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
2004-01-25 04:34:27 +08:00
|
|
|
|
2004-01-24 11:40:33 +08:00
|
|
|
if (flags & X_OK)
|
|
|
|
{
|
2009-09-25 21:44:45 +08:00
|
|
|
if (st.st_uid == (effective ? myself->uid : cygheap->user.real_uid))
|
2004-01-24 11:40:33 +08:00
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IXUSR))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
2009-09-25 21:44:45 +08:00
|
|
|
else if (st.st_gid == (effective ? myself->gid : cygheap->user.real_gid))
|
2004-01-24 11:40:33 +08:00
|
|
|
{
|
|
|
|
if (!(st.st_mode & S_IXGRP))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
|
|
|
else if (!(st.st_mode & S_IXOTH))
|
2004-01-26 07:39:26 +08:00
|
|
|
goto eaccess_done;
|
2004-01-24 11:40:33 +08:00
|
|
|
}
|
2004-01-26 07:39:26 +08:00
|
|
|
|
2004-01-25 04:34:27 +08:00
|
|
|
res = 0;
|
2004-01-26 07:39:26 +08:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
eaccess_done:
|
|
|
|
set_errno (EACCES);
|
2004-01-24 11:40:33 +08:00
|
|
|
done:
|
2007-07-17 22:39:02 +08:00
|
|
|
if (!res && (flags & W_OK) && get_device () == FH_FS
|
|
|
|
&& (pc.fs_flags () & FILE_READ_ONLY_VOLUME))
|
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = -1;
|
|
|
|
}
|
2004-01-25 04:34:27 +08: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 08:37:18 +08:00
|
|
|
}
|
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
int
|
|
|
|
fhandler_base::open_with_arch (int flags, mode_t mode)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
if (!(res = (archetype && archetype->io_handle)
|
Reapply POSIX ACL changes.
- New, unified implementation of POSIX permission and ACL handling. The
new ACLs now store the POSIX ACL MASK/CLASS_OBJ permission mask, and
they allow to inherit the S_ISGID bit. ACL inheritance now really
works as desired, in a limited, but theoretically equivalent fashion
even for non-Cygwin processes.
To accommodate Windows default ACLs, the new code ignores SYSTEM and
Administrators group permissions when computing the MASK/CLASS_OBJ
permission mask on old ACLs, and it doesn't deny access to SYSTEM and
Administrators group based on the value of MASK/CLASS_OBJ when
creating the new ACLs.
The new code now handles the S_ISGID bit on directories as on Linux:
Setting S_ISGID on a directory causes new files and subdirs created
within to inherit its group, rather than the primary group of the user
who created the file. This only works for files and directories
created by Cygwin processes.
2015-05-29 Corinna Vinschen <corinna@vinschen.de>
Reapply POSIX ACL changes.
* utils.xml (setfacl): Show new option output.
(getfacl): Show new option output.
* sec_acl.cc (get_posix_access): Check for Cygwin "standard" ACL.
Apply umask, if so. Align comments.
* security.cc (set_created_file_access): Fix permission masking by
incoming requested file mode.
* sec_acl.cc (set_posix_access): Apply mask only in terms of execute bit
for SYSTEM and Admins group.
* sec_acl.cc (set_posix_access): Don't create DENY ACEs for USER and
GROUP entries if they are the same as USER_OBJ or GROUP_OBJ.
* fhandler.h (fhandler_pty_slave::facl): Add prototype.
* fhandler_tty.cc (fhandler_pty_slave::facl): New method.
(fhandler_pty_slave::fchown): Fix uid/gid handling.
* sec_acl.cc (set_posix_access): Drop superfluous class_idx variable.
Simplify and move around code in a few places. To improve ACL
readability, add r/w permissions to Admins ACE appended to pty ACL.
Add comment to explain Windows ACE Mask filtering being in the way of
creating a real CLASS_OBJ.
(get_posix_access): Fake CLASS_OBJ for ptys. Explain why.
* security.cc (get_object_attribute): Add S_IFCHR flag to attributes
when calling get_posix_access.
* sec_acl.cc (set_posix_access): Move merging group perms into owner
perms in case of owner == group after mask has been computed. Take
mask into account when doing so to avoid unnecessary ACCESS_DENIED_ACE.
* sec_acl.cc (get_posix_access): Only set saw_group_obj flag if we saw
the ACCESS_ALLOWED_ACE.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Deliberatly
set GROUP_OBJ and CLASS_OBJ perms to new group perms. Add comment
to explain why.
* security.cc (set_created_file_access): Ditto.
* sec_acl.cc (set_posix_access): Replace previous patch. Return
EINVAL if uid and/or guid is invalid and not backed by an actual
Windows account.
* sec_acl.cc (set_posix_access): Workaround owner/group SIDs being NULL.
* sec_acl.cc (set_posix_access): Handle files with owner == group.
Rephrase switch statement checking against unfiltered a_type value.
(get_posix_access): Handle files with owner == group.
* sec_acl.cc (get_posix_access): Don't use GROUP_OBJ access to fix up
CLASS_OBJ mask on old-style ACLs. Fix a comment.
* sec_acl.cc (set_posix_access): Always make sure Admins have
WRITE_DAC and WRITE_OWNER permissions.
* security.h (create_object_sd_from_attribute): Drop handle parameter
from prototype.
* security.cc (create_object_sd_from_attribute): Drop handle parameter.
Just create the standard POSIXy security descriptor.
(set_object_attribute): Accommodate dropped paramter in call to
create_object_sd_from_attribute.
* fhandler_tty.cc: Ditto, throughout.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Fix typo in
mask computation.
* fhandler.cc (fhandler_base::open_with_arch): Call open with mode
not umasked.
(fhandler_base::open): Explicitely umask mode on NFS here. Call new
set_created_file_access rather than set_file_attribute.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Reimplement
setting permissions on filesystems supporting ACLs using the new
set_posix_access call.
(fhandler_disk_file::fchown): Ditto.
(fhandler_disk_file::mkdir): Call new set_created_file_access rather
than set_file_attribute.
* fhandler_socket.cc (fhandler_socket::bind): Don't umask here. Add
WRITE_OWNER access to allow writing group in case of SGID bit set.
Call new set_created_file_access rather than set_file_attribute.
* path.cc (symlink_worker): Call new set_created_file_access rather
than set_file_attribute.
* sec_acl.cc (searchace): Un-staticize.
(set_posix_access): New, complementary functionality to
get_posix_access.
(setacl): Implement in terms of get_posix_access/set_posix_access.
(get_posix_access): Add handling for just created files requiring
their first Cygwin ACL. Fix new_style recognition. Handle SGID
bit. For old-style ACLs, ignore SYSTEM and Administrators when
computing the {DEF_}CLASS_OBJ perms.
* security.cc (get_file_sd): Revamp comment. Change and (hopefully)
speed up inheritance processing for just created files.
(alloc_sd): Remove.
(set_security_attribute): Call set_posix_access instead of alloc_sd.
(get_object_attribute): Fix return value.
(create_object_sd_from_attribute): Call set_posix_access instead of
alloc_sd.
(set_file_attribute): Remove.
(set_created_file_access): New function implemented in terms of
get_posix_access/set_posix_access.
* security.h (set_file_attribute): Remove prototype.
(set_created_file_access): Add prototype.
(searchace): Ditto.
(set_posix_access): Ditto.
* syscalls.cc (open): Call open_with_arch with mode not umasked.
* sec_acl.cc: Change preceeding comment explaining new-style ACLs.
Describe how to generate deny ACEs in more detail. Accommodate the
fact that a NULL deny ACE is used for {DEF_}CLASS_OBJ, rather than
a special Cygwin ACE. Improve further comments.
(CYG_ACE_NEW_STYLE): Define.
(get_posix_access): Change from Cygwin ACE to NULL deny ACE. Fix
CLASS_OBJ handling to generate CLASS_OBJ and DEF_CLASS_OBJ from a single
NULL deny ACE if the inheritance flags say so.
* sec_helper.cc (well_known_cygwin_sid): Remove.
* security.h (well_known_cygwin_sid): Drop declaration.
* sec_acl.cc (CYG_ACE_ISBITS_TO_WIN): Fix typo.
(get_posix_access): Rename index variable from i to idx. Define only
once at top level.
* security.cc (add_access_allowed_ace): Drop unused parameter "offset".
Accommodate throughout.
(add_access_denied_ace): Ditto.
* sec_acl.cc: Accommodate above change throughout.
* security.h (add_access_allowed_ace): Adjust prototype to above change.
(add_access_denied_ace): Ditto.
* sec_acl.cc (get_posix_access): Handle multiple ACEs for the
owner and primary group of the file. Handle the default primary
group ACE as DEF_GROUP_OBJ entry if the directory has the S_ISGID bit
set. Add comments. Minor code rearrangements.
Preliminary read side implementation of new permission handling.
* acl.h (MAX_ACL_ENTRIES): Raise to 2730. Add comment to explain.
* sec_acl.cc: Add leading comment to explain new ACL style.
Add definitions and macros to use for bits in new Cygwin ACL.
(DENY_RWX): New mask value for all temporary deny bits.
(getace): Add bool parameter to decide when leaving all bits intact,
rather than filtering them per the already set bits.
(get_posix_access): New function, taking over functionality to read
POSIX ACL from SECURITY_DESCRIPTOR.
(getacl): Just call get_posix_access.
* sec_helper.cc (well_known_cygwin_sid): Define.
* security.cc (get_attribute_from_acl): Remove.
(get_info_from_sd): Remove.
(get_reg_sd): Call get_posix_access instead of get_info_from_sd.
(get_file_attribute): Ditto.
(get_object_attribute): Ditto.
* security.h (well_known_cygwin_sid): Declare.
(get_posix_access): Add prototype.
* Throughout, use simpler ACE macros from Windows' accctrl.h.
* getfacl.c (main): Special-case SYSTEM and Admins group. Add comments.
* setfacl.c: Align more to Linux tool.
(delacl): New function to delete acl entries only.
(modacl): Drop delete functionality. Add handling of recomputing the
mask and default mask values.
(delallacl): Rename from delacl.
(setfacl): Call delacl in Delete case. Call delallacl in DeleteAll
and DeleteDef case.
(usage): Accommodate new options. Rearrange and rephrase slightly.
(longopts): Emit 'x' in --delete case. Add --no-mask and --mask
options.
(opts): Add -x and -n options.
(main): Handle -d and -x the same. Handle -n and --mask options.
Drop handling for -r option.
* getfacl.c (usage): Align more closely to Linux version. Add new
options -c, -e, -E. Change formatting to accommodate longer options.
(longopts): Rename --noname to --numeric. Keep --noname for backward
compatibility. Add --omit-header, --all-effective and --no-effective
options.
(opts): Add -c, -e and -E option.
(main): Handle new -c, -e, and -E options.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-24 17:52:29 +08:00
|
|
|
|| open (flags, mode & 07777)))
|
2011-05-06 06:30:53 +08:00
|
|
|
{
|
|
|
|
if (archetype)
|
|
|
|
delete archetype;
|
|
|
|
}
|
|
|
|
else if (archetype)
|
|
|
|
{
|
2019-03-30 15:12:02 +08:00
|
|
|
if (!archetype->get_handle ())
|
2011-05-06 06:30:53 +08:00
|
|
|
{
|
2021-02-10 17:42:05 +08:00
|
|
|
archetype->copy_from (this);
|
2011-05-06 06:30:53 +08:00
|
|
|
archetype_usecount (1);
|
|
|
|
archetype->archetype = NULL;
|
2011-10-16 06:37:30 +08:00
|
|
|
usecount = 0;
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-20 22:02:54 +08:00
|
|
|
char *name;
|
|
|
|
/* Preserve any name (like /dev/tty) derived from build_fh_pc. */
|
|
|
|
if (!get_name ())
|
|
|
|
name = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = (char *) alloca (strlen (get_name ()) + 1);
|
|
|
|
strcpy (name, get_name ());
|
|
|
|
}
|
2011-05-06 06:30:53 +08:00
|
|
|
fhandler_base *arch = archetype;
|
2021-02-10 17:42:05 +08:00
|
|
|
copy_from (archetype);
|
2011-10-20 22:02:54 +08:00
|
|
|
if (name)
|
|
|
|
set_name (name);
|
2011-05-06 06:30:53 +08:00
|
|
|
archetype = arch;
|
|
|
|
archetype_usecount (1);
|
|
|
|
usecount = 0;
|
|
|
|
}
|
2021-09-18 21:10:23 +08:00
|
|
|
if (!open_setup (flags))
|
|
|
|
api_fatal ("open_setup failed, %E");
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
|
|
|
|
2011-07-04 13:08:28 +08:00
|
|
|
close_on_exec (flags & O_CLOEXEC);
|
2013-10-24 17:41:17 +08:00
|
|
|
/* A unique ID is necessary to recognize fhandler entries which are
|
|
|
|
duplicated by dup(2) or fork(2). This is used in BSD flock calls
|
|
|
|
to identify the descriptor. Skip nohandle fhandlers since advisory
|
|
|
|
locking is unusable for those anyway. */
|
|
|
|
if (!nohandle ())
|
|
|
|
set_unique_id ();
|
2011-05-06 06:30:53 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-10-31 22:26:42 +08:00
|
|
|
/* Open a fake handle to \\Device\\Null. This is a helper function for
|
|
|
|
fhandlers which just need some handle to keep track of BSD flock locks. */
|
|
|
|
int
|
|
|
|
fhandler_base::open_null (int flags)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
HANDLE fh;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
InitializeObjectAttributes (&attr, &ro_u_null, OBJ_CASE_INSENSITIVE |
|
|
|
|
((flags & O_CLOEXEC) ? 0 : OBJ_INHERIT),
|
|
|
|
NULL, NULL);
|
|
|
|
status = NtCreateFile (&fh, GENERIC_READ | SYNCHRONIZE, &attr, &io, NULL, 0,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
goto done;
|
|
|
|
}
|
2019-03-30 15:12:02 +08:00
|
|
|
set_handle (fh);
|
2013-10-31 22:26:42 +08:00
|
|
|
set_flags (flags, pc.binmode ());
|
|
|
|
res = 1;
|
|
|
|
set_open_status ();
|
|
|
|
done:
|
|
|
|
debug_printf ("%y = NtCreateFile (%p, ... %S ...)", status, fh, &ro_u_null);
|
|
|
|
syscall_printf ("%d = fhandler_base::open_null (%y)", res, flags);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-04-17 05:22:13 +08:00
|
|
|
/* Open system call handler function. */
|
|
|
|
int
|
|
|
|
fhandler_base::open (int flags, mode_t mode)
|
|
|
|
{
|
|
|
|
int res = 0;
|
2008-07-18 20:21:22 +08:00
|
|
|
HANDLE fh;
|
2004-04-17 05:22:13 +08:00
|
|
|
ULONG file_attributes = 0;
|
2007-02-22 19:17:01 +08:00
|
|
|
ULONG shared = (get_major () == DEV_TAPE_MAJOR ? 0 : FILE_SHARE_VALID_FLAGS);
|
2004-04-17 05:22:13 +08:00
|
|
|
ULONG create_disposition;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
2008-05-20 23:11:23 +08:00
|
|
|
PFILE_FULL_EA_INFORMATION p = NULL;
|
|
|
|
ULONG plen = 0;
|
2004-04-17 05:22:13 +08:00
|
|
|
|
2019-01-28 17:23:59 +08:00
|
|
|
syscall_printf ("(%S, %y)%s", pc.get_nt_native_path (), flags,
|
|
|
|
get_handle () ? " by handle" : "");
|
2004-04-30 22:02:37 +08:00
|
|
|
|
2019-01-08 02:33:11 +08:00
|
|
|
if (flags & O_PATH)
|
|
|
|
query_open (query_read_attributes);
|
|
|
|
|
2019-01-06 04:49:16 +08:00
|
|
|
/* Allow to reopen from handle. This is utilized by
|
|
|
|
open ("/proc/PID/fd/DESCRIPTOR", ...); */
|
|
|
|
if (get_handle ())
|
2019-01-09 01:50:11 +08:00
|
|
|
{
|
|
|
|
pc.init_reopen_attr (attr, get_handle ());
|
|
|
|
if (!(flags & O_CLOEXEC))
|
|
|
|
attr.Attributes |= OBJ_INHERIT;
|
2019-01-28 17:23:59 +08:00
|
|
|
if (pc.has_buggy_reopen ())
|
|
|
|
debug_printf ("Reopen by handle requested but FS doesn't support it");
|
2019-01-09 01:50:11 +08:00
|
|
|
}
|
2019-01-06 04:49:16 +08:00
|
|
|
else
|
|
|
|
pc.get_object_attr (attr, *sec_none_cloexec (flags));
|
2004-04-17 05:22:13 +08:00
|
|
|
|
2011-06-17 19:04:44 +08:00
|
|
|
options = FILE_OPEN_FOR_BACKUP_INTENT;
|
2004-04-17 05:22:13 +08:00
|
|
|
switch (query_open ())
|
|
|
|
{
|
2013-10-31 22:26:42 +08:00
|
|
|
case query_read_control:
|
|
|
|
access = READ_CONTROL;
|
|
|
|
break;
|
|
|
|
case query_read_attributes:
|
|
|
|
access = READ_CONTROL | FILE_READ_ATTRIBUTES;
|
|
|
|
break;
|
|
|
|
case query_write_control:
|
2021-11-05 04:48:45 +08:00
|
|
|
access = READ_CONTROL | WRITE_OWNER | WRITE_DAC
|
|
|
|
| (pc.fs_is_samba () ? 0 : FILE_WRITE_ATTRIBUTES);
|
2013-10-31 22:26:42 +08:00
|
|
|
break;
|
|
|
|
case query_write_dac:
|
2021-11-05 04:48:45 +08:00
|
|
|
access = READ_CONTROL | WRITE_DAC
|
|
|
|
| (pc.fs_is_samba () ? 0 : FILE_WRITE_ATTRIBUTES);
|
2013-10-31 22:26:42 +08:00
|
|
|
break;
|
|
|
|
case query_write_attributes:
|
|
|
|
access = READ_CONTROL | FILE_WRITE_ATTRIBUTES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
switch (flags & O_ACCMODE)
|
|
|
|
{
|
|
|
|
case O_RDONLY:
|
2009-05-04 17:16:42 +08:00
|
|
|
access = GENERIC_READ;
|
2013-10-31 22:26:42 +08:00
|
|
|
break;
|
|
|
|
case O_WRONLY:
|
2009-05-04 17:16:42 +08:00
|
|
|
access = GENERIC_WRITE | READ_CONTROL | FILE_READ_ATTRIBUTES;
|
2013-10-31 22:26:42 +08:00
|
|
|
break;
|
|
|
|
default:
|
2009-05-04 17:16:42 +08:00
|
|
|
access = GENERIC_READ | GENERIC_WRITE;
|
2013-10-31 22:26:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (flags & O_SYNC)
|
|
|
|
options |= FILE_WRITE_THROUGH;
|
|
|
|
if (flags & O_DIRECT)
|
|
|
|
options |= FILE_NO_INTERMEDIATE_BUFFERING;
|
|
|
|
if (get_major () != DEV_SERIAL_MAJOR && get_major () != DEV_TAPE_MAJOR)
|
|
|
|
{
|
|
|
|
options |= FILE_SYNCHRONOUS_IO_NONALERT;
|
|
|
|
access |= SYNCHRONIZE;
|
|
|
|
}
|
|
|
|
break;
|
2004-04-17 05:22:13 +08:00
|
|
|
}
|
|
|
|
|
2011-08-25 21:35:43 +08:00
|
|
|
/* Don't use the FILE_OVERWRITE{_IF} flags here. See below for an
|
|
|
|
explanation, why that's not such a good idea. */
|
2017-11-15 04:28:45 +08:00
|
|
|
if (((flags & O_EXCL) && (flags & O_CREAT)) || (flags & O_TMPFILE))
|
2004-04-17 05:22:13 +08:00
|
|
|
create_disposition = FILE_CREATE;
|
2011-08-25 21:35:43 +08:00
|
|
|
else
|
|
|
|
create_disposition = (flags & O_CREAT) ? FILE_OPEN_IF : FILE_OPEN;
|
2004-04-17 05:22:13 +08:00
|
|
|
|
2020-09-29 03:57:56 +08:00
|
|
|
if (get_device () == FH_FS
|
|
|
|
#ifdef __WITH_AF_UNIX
|
|
|
|
|| get_device () == FH_UNIX
|
|
|
|
#endif
|
|
|
|
)
|
2004-04-17 05:22:13 +08:00
|
|
|
{
|
2020-09-29 03:57:56 +08:00
|
|
|
/* Add the reparse point flag to known reparse points, otherwise we
|
2018-03-01 23:41:45 +08:00
|
|
|
open the target, not the reparse point. This would break lstat. */
|
|
|
|
if (pc.is_known_reparse_point ())
|
2011-06-17 19:04:44 +08:00
|
|
|
options |= FILE_OPEN_REPARSE_POINT;
|
2020-09-29 03:57:56 +08:00
|
|
|
}
|
2007-10-18 20:40:27 +08:00
|
|
|
|
2020-09-29 03:57:56 +08:00
|
|
|
if (get_device () == FH_FS)
|
|
|
|
{
|
2017-11-15 04:28:45 +08:00
|
|
|
/* O_TMPFILE files are created with delete-on-close semantics, as well
|
|
|
|
as with FILE_ATTRIBUTE_TEMPORARY. The latter speeds up file access,
|
|
|
|
because the OS tries to keep the file in memory as much as possible.
|
|
|
|
In conjunction with FILE_DELETE_ON_CLOSE, ideally the OS never has
|
2018-02-14 19:55:24 +08:00
|
|
|
to write to the disk at all.
|
|
|
|
Note that O_TMPFILE_FILE_ATTRS also sets the DOS HIDDEN attribute
|
|
|
|
to help telling Cygwin O_TMPFILE files apart from other files
|
|
|
|
accidentally setting FILE_ATTRIBUTE_TEMPORARY. */
|
2017-11-15 04:28:45 +08:00
|
|
|
if (flags & O_TMPFILE)
|
|
|
|
{
|
|
|
|
access |= DELETE;
|
2018-02-14 19:55:24 +08:00
|
|
|
file_attributes |= O_TMPFILE_FILE_ATTRS;
|
2017-11-15 04:28:45 +08:00
|
|
|
options |= FILE_DELETE_ON_CLOSE;
|
|
|
|
}
|
|
|
|
|
2011-07-01 19:23:43 +08:00
|
|
|
if (pc.fs_is_nfs ())
|
|
|
|
{
|
|
|
|
/* Make sure we can read EAs of files on an NFS share. Also make
|
|
|
|
sure that we're going to act on the file itself, even if it's a
|
|
|
|
a symlink. */
|
|
|
|
access |= FILE_READ_EA;
|
|
|
|
if (query_open ())
|
|
|
|
{
|
|
|
|
if (query_open () >= query_write_control)
|
|
|
|
access |= FILE_WRITE_EA;
|
|
|
|
plen = sizeof nfs_aol_ffei;
|
|
|
|
p = (PFILE_FULL_EA_INFORMATION) &nfs_aol_ffei;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 04:28:45 +08:00
|
|
|
if (flags & (O_CREAT | O_TMPFILE))
|
2004-04-17 05:22:13 +08:00
|
|
|
{
|
2008-04-26 00:59:41 +08:00
|
|
|
file_attributes |= FILE_ATTRIBUTE_NORMAL;
|
|
|
|
|
2009-10-24 16:26:01 +08:00
|
|
|
if (pc.fs_is_nfs ())
|
2008-05-20 23:11:23 +08:00
|
|
|
{
|
|
|
|
/* When creating a file on an NFS share, we have to set the
|
2008-11-27 01:21:04 +08:00
|
|
|
file mode by writing a NFS fattr3 structure with the
|
2008-05-20 23:11:23 +08:00
|
|
|
correct mode bits set. */
|
|
|
|
access |= FILE_WRITE_EA;
|
|
|
|
plen = sizeof (FILE_FULL_EA_INFORMATION) + sizeof (NFS_V3_ATTR)
|
|
|
|
+ sizeof (fattr3);
|
|
|
|
p = (PFILE_FULL_EA_INFORMATION) alloca (plen);
|
|
|
|
p->NextEntryOffset = 0;
|
|
|
|
p->Flags = 0;
|
|
|
|
p->EaNameLength = sizeof (NFS_V3_ATTR) - 1;
|
|
|
|
p->EaValueLength = sizeof (fattr3);
|
|
|
|
strcpy (p->EaName, NFS_V3_ATTR);
|
|
|
|
fattr3 *nfs_attr = (fattr3 *) (p->EaName
|
2008-11-27 01:21:04 +08:00
|
|
|
+ p->EaNameLength + 1);
|
2008-05-20 23:11:23 +08:00
|
|
|
memset (nfs_attr, 0, sizeof (fattr3));
|
|
|
|
nfs_attr->type = NF3REG;
|
Reapply POSIX ACL changes.
- New, unified implementation of POSIX permission and ACL handling. The
new ACLs now store the POSIX ACL MASK/CLASS_OBJ permission mask, and
they allow to inherit the S_ISGID bit. ACL inheritance now really
works as desired, in a limited, but theoretically equivalent fashion
even for non-Cygwin processes.
To accommodate Windows default ACLs, the new code ignores SYSTEM and
Administrators group permissions when computing the MASK/CLASS_OBJ
permission mask on old ACLs, and it doesn't deny access to SYSTEM and
Administrators group based on the value of MASK/CLASS_OBJ when
creating the new ACLs.
The new code now handles the S_ISGID bit on directories as on Linux:
Setting S_ISGID on a directory causes new files and subdirs created
within to inherit its group, rather than the primary group of the user
who created the file. This only works for files and directories
created by Cygwin processes.
2015-05-29 Corinna Vinschen <corinna@vinschen.de>
Reapply POSIX ACL changes.
* utils.xml (setfacl): Show new option output.
(getfacl): Show new option output.
* sec_acl.cc (get_posix_access): Check for Cygwin "standard" ACL.
Apply umask, if so. Align comments.
* security.cc (set_created_file_access): Fix permission masking by
incoming requested file mode.
* sec_acl.cc (set_posix_access): Apply mask only in terms of execute bit
for SYSTEM and Admins group.
* sec_acl.cc (set_posix_access): Don't create DENY ACEs for USER and
GROUP entries if they are the same as USER_OBJ or GROUP_OBJ.
* fhandler.h (fhandler_pty_slave::facl): Add prototype.
* fhandler_tty.cc (fhandler_pty_slave::facl): New method.
(fhandler_pty_slave::fchown): Fix uid/gid handling.
* sec_acl.cc (set_posix_access): Drop superfluous class_idx variable.
Simplify and move around code in a few places. To improve ACL
readability, add r/w permissions to Admins ACE appended to pty ACL.
Add comment to explain Windows ACE Mask filtering being in the way of
creating a real CLASS_OBJ.
(get_posix_access): Fake CLASS_OBJ for ptys. Explain why.
* security.cc (get_object_attribute): Add S_IFCHR flag to attributes
when calling get_posix_access.
* sec_acl.cc (set_posix_access): Move merging group perms into owner
perms in case of owner == group after mask has been computed. Take
mask into account when doing so to avoid unnecessary ACCESS_DENIED_ACE.
* sec_acl.cc (get_posix_access): Only set saw_group_obj flag if we saw
the ACCESS_ALLOWED_ACE.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Deliberatly
set GROUP_OBJ and CLASS_OBJ perms to new group perms. Add comment
to explain why.
* security.cc (set_created_file_access): Ditto.
* sec_acl.cc (set_posix_access): Replace previous patch. Return
EINVAL if uid and/or guid is invalid and not backed by an actual
Windows account.
* sec_acl.cc (set_posix_access): Workaround owner/group SIDs being NULL.
* sec_acl.cc (set_posix_access): Handle files with owner == group.
Rephrase switch statement checking against unfiltered a_type value.
(get_posix_access): Handle files with owner == group.
* sec_acl.cc (get_posix_access): Don't use GROUP_OBJ access to fix up
CLASS_OBJ mask on old-style ACLs. Fix a comment.
* sec_acl.cc (set_posix_access): Always make sure Admins have
WRITE_DAC and WRITE_OWNER permissions.
* security.h (create_object_sd_from_attribute): Drop handle parameter
from prototype.
* security.cc (create_object_sd_from_attribute): Drop handle parameter.
Just create the standard POSIXy security descriptor.
(set_object_attribute): Accommodate dropped paramter in call to
create_object_sd_from_attribute.
* fhandler_tty.cc: Ditto, throughout.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Fix typo in
mask computation.
* fhandler.cc (fhandler_base::open_with_arch): Call open with mode
not umasked.
(fhandler_base::open): Explicitely umask mode on NFS here. Call new
set_created_file_access rather than set_file_attribute.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Reimplement
setting permissions on filesystems supporting ACLs using the new
set_posix_access call.
(fhandler_disk_file::fchown): Ditto.
(fhandler_disk_file::mkdir): Call new set_created_file_access rather
than set_file_attribute.
* fhandler_socket.cc (fhandler_socket::bind): Don't umask here. Add
WRITE_OWNER access to allow writing group in case of SGID bit set.
Call new set_created_file_access rather than set_file_attribute.
* path.cc (symlink_worker): Call new set_created_file_access rather
than set_file_attribute.
* sec_acl.cc (searchace): Un-staticize.
(set_posix_access): New, complementary functionality to
get_posix_access.
(setacl): Implement in terms of get_posix_access/set_posix_access.
(get_posix_access): Add handling for just created files requiring
their first Cygwin ACL. Fix new_style recognition. Handle SGID
bit. For old-style ACLs, ignore SYSTEM and Administrators when
computing the {DEF_}CLASS_OBJ perms.
* security.cc (get_file_sd): Revamp comment. Change and (hopefully)
speed up inheritance processing for just created files.
(alloc_sd): Remove.
(set_security_attribute): Call set_posix_access instead of alloc_sd.
(get_object_attribute): Fix return value.
(create_object_sd_from_attribute): Call set_posix_access instead of
alloc_sd.
(set_file_attribute): Remove.
(set_created_file_access): New function implemented in terms of
get_posix_access/set_posix_access.
* security.h (set_file_attribute): Remove prototype.
(set_created_file_access): Add prototype.
(searchace): Ditto.
(set_posix_access): Ditto.
* syscalls.cc (open): Call open_with_arch with mode not umasked.
* sec_acl.cc: Change preceeding comment explaining new-style ACLs.
Describe how to generate deny ACEs in more detail. Accommodate the
fact that a NULL deny ACE is used for {DEF_}CLASS_OBJ, rather than
a special Cygwin ACE. Improve further comments.
(CYG_ACE_NEW_STYLE): Define.
(get_posix_access): Change from Cygwin ACE to NULL deny ACE. Fix
CLASS_OBJ handling to generate CLASS_OBJ and DEF_CLASS_OBJ from a single
NULL deny ACE if the inheritance flags say so.
* sec_helper.cc (well_known_cygwin_sid): Remove.
* security.h (well_known_cygwin_sid): Drop declaration.
* sec_acl.cc (CYG_ACE_ISBITS_TO_WIN): Fix typo.
(get_posix_access): Rename index variable from i to idx. Define only
once at top level.
* security.cc (add_access_allowed_ace): Drop unused parameter "offset".
Accommodate throughout.
(add_access_denied_ace): Ditto.
* sec_acl.cc: Accommodate above change throughout.
* security.h (add_access_allowed_ace): Adjust prototype to above change.
(add_access_denied_ace): Ditto.
* sec_acl.cc (get_posix_access): Handle multiple ACEs for the
owner and primary group of the file. Handle the default primary
group ACE as DEF_GROUP_OBJ entry if the directory has the S_ISGID bit
set. Add comments. Minor code rearrangements.
Preliminary read side implementation of new permission handling.
* acl.h (MAX_ACL_ENTRIES): Raise to 2730. Add comment to explain.
* sec_acl.cc: Add leading comment to explain new ACL style.
Add definitions and macros to use for bits in new Cygwin ACL.
(DENY_RWX): New mask value for all temporary deny bits.
(getace): Add bool parameter to decide when leaving all bits intact,
rather than filtering them per the already set bits.
(get_posix_access): New function, taking over functionality to read
POSIX ACL from SECURITY_DESCRIPTOR.
(getacl): Just call get_posix_access.
* sec_helper.cc (well_known_cygwin_sid): Define.
* security.cc (get_attribute_from_acl): Remove.
(get_info_from_sd): Remove.
(get_reg_sd): Call get_posix_access instead of get_info_from_sd.
(get_file_attribute): Ditto.
(get_object_attribute): Ditto.
* security.h (well_known_cygwin_sid): Declare.
(get_posix_access): Add prototype.
* Throughout, use simpler ACE macros from Windows' accctrl.h.
* getfacl.c (main): Special-case SYSTEM and Admins group. Add comments.
* setfacl.c: Align more to Linux tool.
(delacl): New function to delete acl entries only.
(modacl): Drop delete functionality. Add handling of recomputing the
mask and default mask values.
(delallacl): Rename from delacl.
(setfacl): Call delacl in Delete case. Call delallacl in DeleteAll
and DeleteDef case.
(usage): Accommodate new options. Rearrange and rephrase slightly.
(longopts): Emit 'x' in --delete case. Add --no-mask and --mask
options.
(opts): Add -x and -n options.
(main): Handle -d and -x the same. Handle -n and --mask options.
Drop handling for -r option.
* getfacl.c (usage): Align more closely to Linux version. Add new
options -c, -e, -E. Change formatting to accommodate longer options.
(longopts): Rename --noname to --numeric. Keep --noname for backward
compatibility. Add --omit-header, --all-effective and --no-effective
options.
(opts): Add -c, -e and -E option.
(main): Handle new -c, -e, and -E options.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-24 17:52:29 +08:00
|
|
|
nfs_attr->mode = (mode & 07777) & ~cygheap->umask;
|
2008-05-20 23:11:23 +08:00
|
|
|
}
|
Reapply POSIX ACL changes.
- New, unified implementation of POSIX permission and ACL handling. The
new ACLs now store the POSIX ACL MASK/CLASS_OBJ permission mask, and
they allow to inherit the S_ISGID bit. ACL inheritance now really
works as desired, in a limited, but theoretically equivalent fashion
even for non-Cygwin processes.
To accommodate Windows default ACLs, the new code ignores SYSTEM and
Administrators group permissions when computing the MASK/CLASS_OBJ
permission mask on old ACLs, and it doesn't deny access to SYSTEM and
Administrators group based on the value of MASK/CLASS_OBJ when
creating the new ACLs.
The new code now handles the S_ISGID bit on directories as on Linux:
Setting S_ISGID on a directory causes new files and subdirs created
within to inherit its group, rather than the primary group of the user
who created the file. This only works for files and directories
created by Cygwin processes.
2015-05-29 Corinna Vinschen <corinna@vinschen.de>
Reapply POSIX ACL changes.
* utils.xml (setfacl): Show new option output.
(getfacl): Show new option output.
* sec_acl.cc (get_posix_access): Check for Cygwin "standard" ACL.
Apply umask, if so. Align comments.
* security.cc (set_created_file_access): Fix permission masking by
incoming requested file mode.
* sec_acl.cc (set_posix_access): Apply mask only in terms of execute bit
for SYSTEM and Admins group.
* sec_acl.cc (set_posix_access): Don't create DENY ACEs for USER and
GROUP entries if they are the same as USER_OBJ or GROUP_OBJ.
* fhandler.h (fhandler_pty_slave::facl): Add prototype.
* fhandler_tty.cc (fhandler_pty_slave::facl): New method.
(fhandler_pty_slave::fchown): Fix uid/gid handling.
* sec_acl.cc (set_posix_access): Drop superfluous class_idx variable.
Simplify and move around code in a few places. To improve ACL
readability, add r/w permissions to Admins ACE appended to pty ACL.
Add comment to explain Windows ACE Mask filtering being in the way of
creating a real CLASS_OBJ.
(get_posix_access): Fake CLASS_OBJ for ptys. Explain why.
* security.cc (get_object_attribute): Add S_IFCHR flag to attributes
when calling get_posix_access.
* sec_acl.cc (set_posix_access): Move merging group perms into owner
perms in case of owner == group after mask has been computed. Take
mask into account when doing so to avoid unnecessary ACCESS_DENIED_ACE.
* sec_acl.cc (get_posix_access): Only set saw_group_obj flag if we saw
the ACCESS_ALLOWED_ACE.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Deliberatly
set GROUP_OBJ and CLASS_OBJ perms to new group perms. Add comment
to explain why.
* security.cc (set_created_file_access): Ditto.
* sec_acl.cc (set_posix_access): Replace previous patch. Return
EINVAL if uid and/or guid is invalid and not backed by an actual
Windows account.
* sec_acl.cc (set_posix_access): Workaround owner/group SIDs being NULL.
* sec_acl.cc (set_posix_access): Handle files with owner == group.
Rephrase switch statement checking against unfiltered a_type value.
(get_posix_access): Handle files with owner == group.
* sec_acl.cc (get_posix_access): Don't use GROUP_OBJ access to fix up
CLASS_OBJ mask on old-style ACLs. Fix a comment.
* sec_acl.cc (set_posix_access): Always make sure Admins have
WRITE_DAC and WRITE_OWNER permissions.
* security.h (create_object_sd_from_attribute): Drop handle parameter
from prototype.
* security.cc (create_object_sd_from_attribute): Drop handle parameter.
Just create the standard POSIXy security descriptor.
(set_object_attribute): Accommodate dropped paramter in call to
create_object_sd_from_attribute.
* fhandler_tty.cc: Ditto, throughout.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Fix typo in
mask computation.
* fhandler.cc (fhandler_base::open_with_arch): Call open with mode
not umasked.
(fhandler_base::open): Explicitely umask mode on NFS here. Call new
set_created_file_access rather than set_file_attribute.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Reimplement
setting permissions on filesystems supporting ACLs using the new
set_posix_access call.
(fhandler_disk_file::fchown): Ditto.
(fhandler_disk_file::mkdir): Call new set_created_file_access rather
than set_file_attribute.
* fhandler_socket.cc (fhandler_socket::bind): Don't umask here. Add
WRITE_OWNER access to allow writing group in case of SGID bit set.
Call new set_created_file_access rather than set_file_attribute.
* path.cc (symlink_worker): Call new set_created_file_access rather
than set_file_attribute.
* sec_acl.cc (searchace): Un-staticize.
(set_posix_access): New, complementary functionality to
get_posix_access.
(setacl): Implement in terms of get_posix_access/set_posix_access.
(get_posix_access): Add handling for just created files requiring
their first Cygwin ACL. Fix new_style recognition. Handle SGID
bit. For old-style ACLs, ignore SYSTEM and Administrators when
computing the {DEF_}CLASS_OBJ perms.
* security.cc (get_file_sd): Revamp comment. Change and (hopefully)
speed up inheritance processing for just created files.
(alloc_sd): Remove.
(set_security_attribute): Call set_posix_access instead of alloc_sd.
(get_object_attribute): Fix return value.
(create_object_sd_from_attribute): Call set_posix_access instead of
alloc_sd.
(set_file_attribute): Remove.
(set_created_file_access): New function implemented in terms of
get_posix_access/set_posix_access.
* security.h (set_file_attribute): Remove prototype.
(set_created_file_access): Add prototype.
(searchace): Ditto.
(set_posix_access): Ditto.
* syscalls.cc (open): Call open_with_arch with mode not umasked.
* sec_acl.cc: Change preceeding comment explaining new-style ACLs.
Describe how to generate deny ACEs in more detail. Accommodate the
fact that a NULL deny ACE is used for {DEF_}CLASS_OBJ, rather than
a special Cygwin ACE. Improve further comments.
(CYG_ACE_NEW_STYLE): Define.
(get_posix_access): Change from Cygwin ACE to NULL deny ACE. Fix
CLASS_OBJ handling to generate CLASS_OBJ and DEF_CLASS_OBJ from a single
NULL deny ACE if the inheritance flags say so.
* sec_helper.cc (well_known_cygwin_sid): Remove.
* security.h (well_known_cygwin_sid): Drop declaration.
* sec_acl.cc (CYG_ACE_ISBITS_TO_WIN): Fix typo.
(get_posix_access): Rename index variable from i to idx. Define only
once at top level.
* security.cc (add_access_allowed_ace): Drop unused parameter "offset".
Accommodate throughout.
(add_access_denied_ace): Ditto.
* sec_acl.cc: Accommodate above change throughout.
* security.h (add_access_allowed_ace): Adjust prototype to above change.
(add_access_denied_ace): Ditto.
* sec_acl.cc (get_posix_access): Handle multiple ACEs for the
owner and primary group of the file. Handle the default primary
group ACE as DEF_GROUP_OBJ entry if the directory has the S_ISGID bit
set. Add comments. Minor code rearrangements.
Preliminary read side implementation of new permission handling.
* acl.h (MAX_ACL_ENTRIES): Raise to 2730. Add comment to explain.
* sec_acl.cc: Add leading comment to explain new ACL style.
Add definitions and macros to use for bits in new Cygwin ACL.
(DENY_RWX): New mask value for all temporary deny bits.
(getace): Add bool parameter to decide when leaving all bits intact,
rather than filtering them per the already set bits.
(get_posix_access): New function, taking over functionality to read
POSIX ACL from SECURITY_DESCRIPTOR.
(getacl): Just call get_posix_access.
* sec_helper.cc (well_known_cygwin_sid): Define.
* security.cc (get_attribute_from_acl): Remove.
(get_info_from_sd): Remove.
(get_reg_sd): Call get_posix_access instead of get_info_from_sd.
(get_file_attribute): Ditto.
(get_object_attribute): Ditto.
* security.h (well_known_cygwin_sid): Declare.
(get_posix_access): Add prototype.
* Throughout, use simpler ACE macros from Windows' accctrl.h.
* getfacl.c (main): Special-case SYSTEM and Admins group. Add comments.
* setfacl.c: Align more to Linux tool.
(delacl): New function to delete acl entries only.
(modacl): Drop delete functionality. Add handling of recomputing the
mask and default mask values.
(delallacl): Rename from delacl.
(setfacl): Call delacl in Delete case. Call delallacl in DeleteAll
and DeleteDef case.
(usage): Accommodate new options. Rearrange and rephrase slightly.
(longopts): Emit 'x' in --delete case. Add --no-mask and --mask
options.
(opts): Add -x and -n options.
(main): Handle -d and -x the same. Handle -n and --mask options.
Drop handling for -r option.
* getfacl.c (usage): Align more closely to Linux version. Add new
options -c, -e, -E. Change formatting to accommodate longer options.
(longopts): Rename --noname to --numeric. Keep --noname for backward
compatibility. Add --omit-header, --all-effective and --no-effective
options.
(opts): Add -c, -e and -E option.
(main): Handle new -c, -e, and -E options.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-24 17:52:29 +08:00
|
|
|
else if (!has_acls ()
|
|
|
|
&& !(mode & ~cygheap->umask & (S_IWUSR | S_IWGRP | S_IWOTH)))
|
2009-10-24 16:26:01 +08:00
|
|
|
/* If mode has no write bits set, and ACLs are not used, we set
|
|
|
|
the DOS R/O attribute. */
|
|
|
|
file_attributes |= FILE_ATTRIBUTE_READONLY;
|
2007-10-18 20:40:27 +08:00
|
|
|
/* The file attributes are needed for later use in, e.g. fchmod. */
|
|
|
|
pc.file_attributes (file_attributes);
|
2011-07-05 20:02:10 +08:00
|
|
|
/* Never set the WRITE_DAC flag here. Calls to fstat may return
|
|
|
|
wrong st_ctime information after calls to fchmod, fchown, etc
|
2011-12-04 04:35:36 +08:00
|
|
|
because Windows only guarantees the update of metadata when
|
2011-07-05 20:02:10 +08:00
|
|
|
the handle is closed or flushed. However, flushing the file
|
2011-12-03 22:21:30 +08:00
|
|
|
on every fstat to enforce POSIXy stat behaviour is excessivly
|
|
|
|
slow, compared to an extra open/close to change the file's
|
2011-07-05 20:02:10 +08:00
|
|
|
security descriptor. */
|
2004-04-17 05:22:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-18 20:21:22 +08:00
|
|
|
status = NtCreateFile (&fh, access, &attr, &io, NULL, file_attributes, shared,
|
2011-06-17 19:04:44 +08:00
|
|
|
create_disposition, options, p, plen);
|
2019-01-28 17:23:59 +08:00
|
|
|
/* Pre-W10, we can't reopen a file by handle with delete disposition
|
2019-01-09 04:37:43 +08:00
|
|
|
set, so we have to lie our ass off. */
|
|
|
|
if (get_handle () && status == STATUS_DELETE_PENDING)
|
|
|
|
{
|
|
|
|
BOOL ret = DuplicateHandle (GetCurrentProcess (), get_handle (),
|
|
|
|
GetCurrentProcess (), &fh,
|
|
|
|
access, !(flags & O_CLOEXEC), 0);
|
|
|
|
if (!ret)
|
|
|
|
ret = DuplicateHandle (GetCurrentProcess (), get_handle (),
|
|
|
|
GetCurrentProcess (), &fh,
|
|
|
|
0, !(flags & O_CLOEXEC),
|
|
|
|
DUPLICATE_SAME_ACCESS);
|
|
|
|
if (!ret)
|
|
|
|
debug_printf ("DuplicateHandle after STATUS_DELETE_PENDING, %E");
|
|
|
|
else
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
}
|
2004-04-17 05:22:13 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
2008-03-06 18:01:33 +08:00
|
|
|
/* Trying to create a directory should return EISDIR, not ENOENT. */
|
2008-03-06 02:31:09 +08:00
|
|
|
PUNICODE_STRING upath = pc.get_nt_native_path ();
|
2008-03-06 18:16:07 +08:00
|
|
|
if (status == STATUS_OBJECT_NAME_INVALID && (flags & O_CREAT)
|
2008-03-06 02:31:09 +08:00
|
|
|
&& upath->Buffer[upath->Length / sizeof (WCHAR) - 1] == '\\')
|
|
|
|
set_errno (EISDIR);
|
|
|
|
else
|
|
|
|
__seterrno_from_nt_status (status);
|
2004-04-17 05:22:13 +08:00
|
|
|
if (!nohandle ())
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2009-10-24 16:26:01 +08:00
|
|
|
/* Always create files using a NULL SD. Create correct permission bits
|
|
|
|
afterwards, maintaining the owner and group information just like chmod.
|
|
|
|
|
|
|
|
This is done for two reasons.
|
2008-08-08 00:20:03 +08:00
|
|
|
|
2009-10-24 16:26:01 +08:00
|
|
|
On Windows filesystems we need to create the file with default
|
|
|
|
permissions to allow inheriting ACEs. When providing an explicit DACL
|
|
|
|
in calls to [Nt]CreateFile, the created file will not inherit default
|
|
|
|
permissions from the parent object. This breaks not only Windows
|
|
|
|
inheritance, but also POSIX ACL inheritance.
|
2008-08-08 00:20:03 +08:00
|
|
|
|
2009-10-24 16:26:01 +08:00
|
|
|
Another reason to do this are remote shares. Files on a remote share
|
|
|
|
are created as the user used for authentication. In a domain that's
|
2008-08-08 00:20:03 +08:00
|
|
|
usually the user you're logged in as. Outside of a domain you're
|
|
|
|
authenticating using a local user account on the sharing machine.
|
|
|
|
If the SIDs of the client machine are used, that's entirely
|
2009-10-24 16:26:01 +08:00
|
|
|
unexpected behaviour. Doing it like we do here creates the expected SD
|
|
|
|
in a domain as well as on standalone servers.
|
|
|
|
This is the result of a discussion on the samba-technical list, starting at
|
|
|
|
http://lists.samba.org/archive/samba-technical/2008-July/060247.html */
|
2009-10-31 03:58:53 +08:00
|
|
|
if (io.Information == FILE_CREATED && has_acls ())
|
Reapply POSIX ACL changes.
- New, unified implementation of POSIX permission and ACL handling. The
new ACLs now store the POSIX ACL MASK/CLASS_OBJ permission mask, and
they allow to inherit the S_ISGID bit. ACL inheritance now really
works as desired, in a limited, but theoretically equivalent fashion
even for non-Cygwin processes.
To accommodate Windows default ACLs, the new code ignores SYSTEM and
Administrators group permissions when computing the MASK/CLASS_OBJ
permission mask on old ACLs, and it doesn't deny access to SYSTEM and
Administrators group based on the value of MASK/CLASS_OBJ when
creating the new ACLs.
The new code now handles the S_ISGID bit on directories as on Linux:
Setting S_ISGID on a directory causes new files and subdirs created
within to inherit its group, rather than the primary group of the user
who created the file. This only works for files and directories
created by Cygwin processes.
2015-05-29 Corinna Vinschen <corinna@vinschen.de>
Reapply POSIX ACL changes.
* utils.xml (setfacl): Show new option output.
(getfacl): Show new option output.
* sec_acl.cc (get_posix_access): Check for Cygwin "standard" ACL.
Apply umask, if so. Align comments.
* security.cc (set_created_file_access): Fix permission masking by
incoming requested file mode.
* sec_acl.cc (set_posix_access): Apply mask only in terms of execute bit
for SYSTEM and Admins group.
* sec_acl.cc (set_posix_access): Don't create DENY ACEs for USER and
GROUP entries if they are the same as USER_OBJ or GROUP_OBJ.
* fhandler.h (fhandler_pty_slave::facl): Add prototype.
* fhandler_tty.cc (fhandler_pty_slave::facl): New method.
(fhandler_pty_slave::fchown): Fix uid/gid handling.
* sec_acl.cc (set_posix_access): Drop superfluous class_idx variable.
Simplify and move around code in a few places. To improve ACL
readability, add r/w permissions to Admins ACE appended to pty ACL.
Add comment to explain Windows ACE Mask filtering being in the way of
creating a real CLASS_OBJ.
(get_posix_access): Fake CLASS_OBJ for ptys. Explain why.
* security.cc (get_object_attribute): Add S_IFCHR flag to attributes
when calling get_posix_access.
* sec_acl.cc (set_posix_access): Move merging group perms into owner
perms in case of owner == group after mask has been computed. Take
mask into account when doing so to avoid unnecessary ACCESS_DENIED_ACE.
* sec_acl.cc (get_posix_access): Only set saw_group_obj flag if we saw
the ACCESS_ALLOWED_ACE.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Deliberatly
set GROUP_OBJ and CLASS_OBJ perms to new group perms. Add comment
to explain why.
* security.cc (set_created_file_access): Ditto.
* sec_acl.cc (set_posix_access): Replace previous patch. Return
EINVAL if uid and/or guid is invalid and not backed by an actual
Windows account.
* sec_acl.cc (set_posix_access): Workaround owner/group SIDs being NULL.
* sec_acl.cc (set_posix_access): Handle files with owner == group.
Rephrase switch statement checking against unfiltered a_type value.
(get_posix_access): Handle files with owner == group.
* sec_acl.cc (get_posix_access): Don't use GROUP_OBJ access to fix up
CLASS_OBJ mask on old-style ACLs. Fix a comment.
* sec_acl.cc (set_posix_access): Always make sure Admins have
WRITE_DAC and WRITE_OWNER permissions.
* security.h (create_object_sd_from_attribute): Drop handle parameter
from prototype.
* security.cc (create_object_sd_from_attribute): Drop handle parameter.
Just create the standard POSIXy security descriptor.
(set_object_attribute): Accommodate dropped paramter in call to
create_object_sd_from_attribute.
* fhandler_tty.cc: Ditto, throughout.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Fix typo in
mask computation.
* fhandler.cc (fhandler_base::open_with_arch): Call open with mode
not umasked.
(fhandler_base::open): Explicitely umask mode on NFS here. Call new
set_created_file_access rather than set_file_attribute.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Reimplement
setting permissions on filesystems supporting ACLs using the new
set_posix_access call.
(fhandler_disk_file::fchown): Ditto.
(fhandler_disk_file::mkdir): Call new set_created_file_access rather
than set_file_attribute.
* fhandler_socket.cc (fhandler_socket::bind): Don't umask here. Add
WRITE_OWNER access to allow writing group in case of SGID bit set.
Call new set_created_file_access rather than set_file_attribute.
* path.cc (symlink_worker): Call new set_created_file_access rather
than set_file_attribute.
* sec_acl.cc (searchace): Un-staticize.
(set_posix_access): New, complementary functionality to
get_posix_access.
(setacl): Implement in terms of get_posix_access/set_posix_access.
(get_posix_access): Add handling for just created files requiring
their first Cygwin ACL. Fix new_style recognition. Handle SGID
bit. For old-style ACLs, ignore SYSTEM and Administrators when
computing the {DEF_}CLASS_OBJ perms.
* security.cc (get_file_sd): Revamp comment. Change and (hopefully)
speed up inheritance processing for just created files.
(alloc_sd): Remove.
(set_security_attribute): Call set_posix_access instead of alloc_sd.
(get_object_attribute): Fix return value.
(create_object_sd_from_attribute): Call set_posix_access instead of
alloc_sd.
(set_file_attribute): Remove.
(set_created_file_access): New function implemented in terms of
get_posix_access/set_posix_access.
* security.h (set_file_attribute): Remove prototype.
(set_created_file_access): Add prototype.
(searchace): Ditto.
(set_posix_access): Ditto.
* syscalls.cc (open): Call open_with_arch with mode not umasked.
* sec_acl.cc: Change preceeding comment explaining new-style ACLs.
Describe how to generate deny ACEs in more detail. Accommodate the
fact that a NULL deny ACE is used for {DEF_}CLASS_OBJ, rather than
a special Cygwin ACE. Improve further comments.
(CYG_ACE_NEW_STYLE): Define.
(get_posix_access): Change from Cygwin ACE to NULL deny ACE. Fix
CLASS_OBJ handling to generate CLASS_OBJ and DEF_CLASS_OBJ from a single
NULL deny ACE if the inheritance flags say so.
* sec_helper.cc (well_known_cygwin_sid): Remove.
* security.h (well_known_cygwin_sid): Drop declaration.
* sec_acl.cc (CYG_ACE_ISBITS_TO_WIN): Fix typo.
(get_posix_access): Rename index variable from i to idx. Define only
once at top level.
* security.cc (add_access_allowed_ace): Drop unused parameter "offset".
Accommodate throughout.
(add_access_denied_ace): Ditto.
* sec_acl.cc: Accommodate above change throughout.
* security.h (add_access_allowed_ace): Adjust prototype to above change.
(add_access_denied_ace): Ditto.
* sec_acl.cc (get_posix_access): Handle multiple ACEs for the
owner and primary group of the file. Handle the default primary
group ACE as DEF_GROUP_OBJ entry if the directory has the S_ISGID bit
set. Add comments. Minor code rearrangements.
Preliminary read side implementation of new permission handling.
* acl.h (MAX_ACL_ENTRIES): Raise to 2730. Add comment to explain.
* sec_acl.cc: Add leading comment to explain new ACL style.
Add definitions and macros to use for bits in new Cygwin ACL.
(DENY_RWX): New mask value for all temporary deny bits.
(getace): Add bool parameter to decide when leaving all bits intact,
rather than filtering them per the already set bits.
(get_posix_access): New function, taking over functionality to read
POSIX ACL from SECURITY_DESCRIPTOR.
(getacl): Just call get_posix_access.
* sec_helper.cc (well_known_cygwin_sid): Define.
* security.cc (get_attribute_from_acl): Remove.
(get_info_from_sd): Remove.
(get_reg_sd): Call get_posix_access instead of get_info_from_sd.
(get_file_attribute): Ditto.
(get_object_attribute): Ditto.
* security.h (well_known_cygwin_sid): Declare.
(get_posix_access): Add prototype.
* Throughout, use simpler ACE macros from Windows' accctrl.h.
* getfacl.c (main): Special-case SYSTEM and Admins group. Add comments.
* setfacl.c: Align more to Linux tool.
(delacl): New function to delete acl entries only.
(modacl): Drop delete functionality. Add handling of recomputing the
mask and default mask values.
(delallacl): Rename from delacl.
(setfacl): Call delacl in Delete case. Call delallacl in DeleteAll
and DeleteDef case.
(usage): Accommodate new options. Rearrange and rephrase slightly.
(longopts): Emit 'x' in --delete case. Add --no-mask and --mask
options.
(opts): Add -x and -n options.
(main): Handle -d and -x the same. Handle -n and --mask options.
Drop handling for -r option.
* getfacl.c (usage): Align more closely to Linux version. Add new
options -c, -e, -E. Change formatting to accommodate longer options.
(longopts): Rename --noname to --numeric. Keep --noname for backward
compatibility. Add --omit-header, --all-effective and --no-effective
options.
(opts): Add -c, -e and -E option.
(main): Handle new -c, -e, and -E options.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-24 17:52:29 +08:00
|
|
|
set_created_file_access (fh, pc, mode);
|
2008-07-18 20:21:22 +08:00
|
|
|
|
2011-08-25 21:35:43 +08:00
|
|
|
/* If you O_TRUNC a file on Linux, the data is truncated, but the EAs are
|
|
|
|
preserved. If you open a file on Windows with FILE_OVERWRITE{_IF} or
|
|
|
|
FILE_SUPERSEDE, all streams are truncated, including the EAs. So we don't
|
|
|
|
use the FILE_OVERWRITE{_IF} flags, but instead just open the file and set
|
|
|
|
the size of the data stream explicitely to 0. Apart from being more Linux
|
|
|
|
compatible, this implementation has the pleasant side-effect to be more
|
|
|
|
than 5% faster than using FILE_OVERWRITE{_IF} (tested on W7 32 bit). */
|
|
|
|
if ((flags & O_TRUNC)
|
|
|
|
&& (flags & O_ACCMODE) != O_RDONLY
|
|
|
|
&& io.Information != FILE_CREATED
|
|
|
|
&& get_device () == FH_FS)
|
|
|
|
{
|
|
|
|
FILE_END_OF_FILE_INFORMATION feofi = { EndOfFile:{ QuadPart:0 } };
|
|
|
|
status = NtSetInformationFile (fh, &io, &feofi, sizeof feofi,
|
|
|
|
FileEndOfFileInformation);
|
|
|
|
/* In theory, truncating the file should never fail, since the opened
|
2011-08-28 04:01:29 +08:00
|
|
|
handle has FILE_WRITE_DATA permissions, which is all you need to
|
2011-08-25 21:35:43 +08:00
|
|
|
be allowed to truncate a file. Better safe than sorry. */
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
NtClose (fh);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-30 15:12:02 +08:00
|
|
|
set_handle (fh);
|
2004-04-17 05:22:13 +08:00
|
|
|
set_flags (flags, pc.binmode ());
|
|
|
|
|
|
|
|
res = 1;
|
|
|
|
set_open_status ();
|
|
|
|
done:
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("%y = NtCreateFile "
|
|
|
|
"(%p, %y, %S, io, NULL, %y, %y, %y, %y, NULL, 0)",
|
2008-07-18 20:21:22 +08:00
|
|
|
status, fh, access, pc.get_nt_native_path (), file_attributes,
|
2011-06-17 19:04:44 +08:00
|
|
|
shared, create_disposition, options);
|
2004-06-17 21:34:26 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("%d = fhandler_base::open(%S, %y)",
|
2007-08-13 23:08:25 +08:00
|
|
|
res, pc.get_nt_native_path (), flags);
|
2004-04-17 05:22:13 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-01-06 05:13:42 +08:00
|
|
|
fhandler_base *
|
2019-02-05 22:20:13 +08:00
|
|
|
fhandler_base::fd_reopen (int, mode_t)
|
2019-01-06 05:13:42 +08:00
|
|
|
{
|
|
|
|
/* This is implemented in fhandler_process only. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-09-18 20:13:55 +08:00
|
|
|
bool
|
2013-10-24 23:26:21 +08:00
|
|
|
fhandler_base::open_setup (int)
|
|
|
|
{
|
2021-09-18 20:13:55 +08:00
|
|
|
return true;
|
2013-10-24 23:26:21 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08: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.
|
|
|
|
*/
|
2013-05-01 09:20:37 +08:00
|
|
|
void __reg3
|
2002-12-14 12:01:32 +08:00
|
|
|
fhandler_base::read (void *in_ptr, size_t& len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
char *ptr = (char *) in_ptr;
|
2006-07-27 11:32:51 +08:00
|
|
|
ssize_t copied_chars = get_readahead_into_buffer (ptr, len);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
if (copied_chars || !len)
|
2002-12-14 12:01:32 +08:00
|
|
|
{
|
|
|
|
len = (size_t) copied_chars;
|
2002-12-15 02:01:08 +08:00
|
|
|
goto out;
|
2002-12-14 12:01:32 +08:00
|
|
|
}
|
2001-11-03 13:42:21 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
raw_read (ptr, len);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2009-07-25 04:54:33 +08:00
|
|
|
if (rbinary () || (ssize_t) len <= 0)
|
2002-12-15 02:01:08 +08:00
|
|
|
goto out;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Scan buffer and turn \r\n into \n */
|
2002-12-15 02:01:08 +08:00
|
|
|
char *src, *dst, *end;
|
|
|
|
src = (char *) ptr;
|
|
|
|
dst = (char *) ptr;
|
|
|
|
end = src + len - 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Read up to the last but one char - the last char needs special handling */
|
|
|
|
while (src < end)
|
|
|
|
{
|
2002-12-14 12:01:32 +08:00
|
|
|
if (*src == '\r' && src[1] == '\n')
|
|
|
|
src++;
|
|
|
|
*dst++ = *src++;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-12-15 02:01:08 +08: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-18 03:38:33 +08:00
|
|
|
{
|
2002-12-15 02:01:08 +08:00
|
|
|
char c1;
|
|
|
|
size_t c1len = 1;
|
|
|
|
raw_read (&c1, c1len);
|
|
|
|
if (c1len <= 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
/* nothing */;
|
2002-12-15 02:01:08 +08:00
|
|
|
else if (c1 == '\n')
|
|
|
|
*dst++ = '\n';
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2002-12-14 12:01:32 +08:00
|
|
|
{
|
2002-12-15 02:01:08 +08:00
|
|
|
set_readahead_valid (1, c1);
|
|
|
|
*dst++ = *src;
|
2002-12-14 12:01:32 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-12-15 02:01:08 +08:00
|
|
|
len = dst - (char *) ptr;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-12-15 02:01:08 +08:00
|
|
|
out:
|
2004-04-10 21:45:10 +08:00
|
|
|
debug_printf ("returning %d, %s mode", len, rbinary () ? "binary" : "text");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:54:33 +08:00
|
|
|
ssize_t __stdcall
|
2000-02-18 03:38:33 +08:00
|
|
|
fhandler_base::write (const void *ptr, size_t len)
|
|
|
|
{
|
2017-03-12 19:16:23 +08:00
|
|
|
ssize_t res;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2007-10-15 16:25:38 +08:00
|
|
|
if (did_lseek ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2012-12-14 18:45:29 +08:00
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
FILE_POSITION_INFORMATION fpi;
|
|
|
|
FILE_STANDARD_INFORMATION fsi;
|
|
|
|
|
2004-04-10 21:45:10 +08:00
|
|
|
did_lseek (false); /* don't do it again */
|
2003-05-26 17:54:01 +08:00
|
|
|
|
2007-10-15 16:25:38 +08:00
|
|
|
if (!(get_flags () & O_APPEND)
|
2012-12-14 18:45:29 +08:00
|
|
|
&& !has_attribute (FILE_ATTRIBUTE_SPARSE_FILE)
|
2007-10-15 16:25:38 +08:00
|
|
|
&& NT_SUCCESS (NtQueryInformationFile (get_output_handle (),
|
|
|
|
&io, &fsi, sizeof fsi,
|
|
|
|
FileStandardInformation))
|
|
|
|
&& NT_SUCCESS (NtQueryInformationFile (get_output_handle (),
|
|
|
|
&io, &fpi, sizeof fpi,
|
|
|
|
FilePositionInformation))
|
|
|
|
&& fpi.CurrentByteOffset.QuadPart
|
2012-12-14 18:45:29 +08:00
|
|
|
>= fsi.EndOfFile.QuadPart + (128 * 1024))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-02-23 00:22:38 +08:00
|
|
|
/* If the file system supports sparse files and the application
|
|
|
|
is writing after a long seek beyond EOF, convert the file to
|
|
|
|
a sparse file. */
|
2007-10-15 16:25:38 +08:00
|
|
|
NTSTATUS status;
|
|
|
|
status = NtFsControlFile (get_output_handle (), NULL, NULL, NULL,
|
|
|
|
&io, FSCTL_SET_SPARSE, NULL, 0, NULL, 0);
|
2012-12-14 18:45:29 +08:00
|
|
|
if (NT_SUCCESS (status))
|
|
|
|
pc.file_attributes (pc.file_attributes ()
|
|
|
|
| FILE_ATTRIBUTE_SPARSE_FILE);
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("%y = NtFsControlFile(%S, FSCTL_SET_SPARSE)",
|
2011-12-17 15:01:21 +08:00
|
|
|
status, pc.get_nt_native_path ());
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-10 21:45:10 +08:00
|
|
|
if (wbinary ())
|
2011-12-17 15:01:21 +08:00
|
|
|
res = raw_write (ptr, len);
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
|
|
|
{
|
2000-10-08 02:12:11 +08:00
|
|
|
debug_printf ("text write");
|
2000-02-18 03:38:33 +08:00
|
|
|
/* This is the Microsoft/DJGPP way. Still not ideal, but it's
|
2000-10-08 02:12:11 +08:00
|
|
|
compatible.
|
|
|
|
Modified slightly by CGF 2000-10-07 */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int left_in_data = len;
|
|
|
|
char *data = (char *)ptr;
|
2000-10-08 02:12:11 +08:00
|
|
|
res = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
while (left_in_data > 0)
|
|
|
|
{
|
2000-10-08 02:12:11 +08:00
|
|
|
char buf[CHUNK_SIZE + 1], *buf_ptr = buf;
|
2000-02-18 03:38:33 +08:00
|
|
|
int left_in_buf = CHUNK_SIZE;
|
|
|
|
|
|
|
|
while (left_in_buf > 0 && left_in_data > 0)
|
|
|
|
{
|
2000-10-08 02:12:11 +08:00
|
|
|
char ch = *data++;
|
|
|
|
if (ch == '\n')
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
*buf_ptr++ = '\r';
|
|
|
|
left_in_buf--;
|
|
|
|
}
|
2000-10-08 02:12:11 +08:00
|
|
|
*buf_ptr++ = ch;
|
2000-02-18 03:38:33 +08:00
|
|
|
left_in_buf--;
|
|
|
|
left_in_data--;
|
2000-10-08 02:12:11 +08:00
|
|
|
if (left_in_data > 0 && ch == '\r' && *data == '\n')
|
|
|
|
{
|
|
|
|
*buf_ptr++ = *data++;
|
|
|
|
left_in_buf--;
|
|
|
|
left_in_data--;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We've got a buffer-full, or we're out of data. Write it out */
|
2020-04-24 22:14:43 +08:00
|
|
|
ssize_t nbytes;
|
|
|
|
ptrdiff_t want = buf_ptr - buf;
|
|
|
|
if ((nbytes = raw_write (buf, (size_t) want)) == want)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-10-08 02:12:11 +08:00
|
|
|
/* Keep track of how much written not counting additional \r's */
|
|
|
|
res = data - (char *)ptr;
|
|
|
|
continue;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-10-08 02:12:11 +08:00
|
|
|
if (nbytes == -1)
|
|
|
|
res = -1; /* Error */
|
|
|
|
else
|
|
|
|
res += nbytes; /* Partial write. Return total bytes written. */
|
|
|
|
break; /* All done */
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-10-08 02:12:11 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-07-25 04:54:33 +08:00
|
|
|
ssize_t __stdcall
|
2002-08-30 23:47:10 +08:00
|
|
|
fhandler_base::readv (const struct iovec *const iov, const int iovcnt,
|
|
|
|
ssize_t tot)
|
|
|
|
{
|
|
|
|
assert (iov);
|
|
|
|
assert (iovcnt >= 1);
|
|
|
|
|
2003-07-29 05:13:17 +08:00
|
|
|
size_t len = tot;
|
2002-08-30 23:47:10 +08:00
|
|
|
if (iovcnt == 1)
|
2002-12-14 12:01:32 +08:00
|
|
|
{
|
2003-07-29 05:13:17 +08:00
|
|
|
len = iov->iov_len;
|
2002-12-14 12:01:32 +08:00
|
|
|
read (iov->iov_base, len);
|
|
|
|
return len;
|
|
|
|
}
|
2002-08-30 23:47:10 +08:00
|
|
|
|
|
|
|
if (tot == -1) // i.e. if not pre-calculated by the caller.
|
|
|
|
{
|
2003-07-29 05:13:17 +08:00
|
|
|
len = 0;
|
2002-08-30 23:47:10 +08:00
|
|
|
const struct iovec *iovptr = iov + iovcnt;
|
2002-09-19 11:30:20 +08:00
|
|
|
do
|
2002-08-30 23:47:10 +08:00
|
|
|
{
|
|
|
|
iovptr -= 1;
|
2003-07-29 05:13:17 +08:00
|
|
|
len += iovptr->iov_len;
|
2002-08-30 23:47:10 +08:00
|
|
|
}
|
|
|
|
while (iovptr != iov);
|
|
|
|
}
|
|
|
|
|
2003-07-29 05:13:17 +08:00
|
|
|
if (!len)
|
2002-08-30 23:47:10 +08:00
|
|
|
return 0;
|
|
|
|
|
2005-11-09 07:25:55 +08:00
|
|
|
char *buf = (char *) malloc (len);
|
2002-08-30 23:47:10 +08:00
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-07-29 05:13:17 +08:00
|
|
|
read (buf, len);
|
|
|
|
ssize_t nbytes = (ssize_t) len;
|
2002-08-30 23:47:10 +08:00
|
|
|
|
|
|
|
const struct iovec *iovptr = iov;
|
|
|
|
|
2005-11-09 07:25:55 +08:00
|
|
|
char *p = buf;
|
2002-08-30 23:47:10 +08:00
|
|
|
while (nbytes > 0)
|
|
|
|
{
|
2012-03-08 17:36:11 +08:00
|
|
|
const int frag = MIN (nbytes, (ssize_t) iovptr->iov_len);
|
2005-11-09 07:25:55 +08:00
|
|
|
memcpy (iovptr->iov_base, p, frag);
|
|
|
|
p += frag;
|
2002-08-30 23:47:10 +08:00
|
|
|
iovptr += 1;
|
|
|
|
nbytes -= frag;
|
|
|
|
}
|
|
|
|
|
2005-07-01 01:00:10 +08:00
|
|
|
free (buf);
|
2003-07-29 05:13:17 +08:00
|
|
|
return len;
|
2002-08-30 23:47:10 +08:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:54:33 +08:00
|
|
|
ssize_t __stdcall
|
2002-08-30 23:47:10 +08:00
|
|
|
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 11:30:20 +08:00
|
|
|
do
|
2002-08-30 23:47:10 +08:00
|
|
|
{
|
|
|
|
iovptr -= 1;
|
|
|
|
tot += iovptr->iov_len;
|
|
|
|
}
|
|
|
|
while (iovptr != iov);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (tot >= 0);
|
|
|
|
|
|
|
|
if (tot == 0)
|
|
|
|
return 0;
|
|
|
|
|
2005-07-01 01:00:10 +08:00
|
|
|
char *const buf = (char *) malloc (tot);
|
2002-08-30 23:47:10 +08:00
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *bufptr = buf;
|
|
|
|
const struct iovec *iovptr = iov;
|
|
|
|
int nbytes = tot;
|
|
|
|
|
|
|
|
while (nbytes != 0)
|
|
|
|
{
|
2012-03-08 17:36:11 +08:00
|
|
|
const int frag = MIN (nbytes, (ssize_t) iovptr->iov_len);
|
2002-08-30 23:47:10 +08:00
|
|
|
memcpy (bufptr, iovptr->iov_base, frag);
|
|
|
|
bufptr += frag;
|
|
|
|
iovptr += 1;
|
|
|
|
nbytes -= frag;
|
|
|
|
}
|
2005-07-01 01:00:10 +08:00
|
|
|
ssize_t ret = write (buf, tot);
|
|
|
|
free (buf);
|
|
|
|
return ret;
|
2002-08-30 23:47:10 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
off_t
|
|
|
|
fhandler_base::lseek (off_t offset, int whence)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-10-15 16:25:38 +08:00
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
FILE_POSITION_INFORMATION fpi;
|
|
|
|
FILE_STANDARD_INFORMATION fsi;
|
2002-02-26 01:47:51 +08:00
|
|
|
|
2000-02-18 03:38:33 +08: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)
|
2020-01-27 20:14:32 +08:00
|
|
|
offset -= ralen () - raixget ();
|
2000-02-18 03:38:33 +08:00
|
|
|
set_readahead_valid (0);
|
|
|
|
}
|
|
|
|
|
2007-10-15 16:25:38 +08:00
|
|
|
switch (whence)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-10-15 16:25:38 +08:00
|
|
|
case SEEK_SET:
|
|
|
|
fpi.CurrentByteOffset.QuadPart = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
status = NtQueryInformationFile (get_handle (), &io, &fpi, sizeof fpi,
|
|
|
|
FilePositionInformation);
|
|
|
|
if (!NT_SUCCESS (status))
|
2008-02-16 01:53:11 +08:00
|
|
|
{
|
2007-10-15 16:25:38 +08:00
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fpi.CurrentByteOffset.QuadPart += offset;
|
|
|
|
break;
|
|
|
|
default: /* SEEK_END */
|
|
|
|
status = NtQueryInformationFile (get_handle (), &io, &fsi, sizeof fsi,
|
|
|
|
FileStandardInformation);
|
|
|
|
if (!NT_SUCCESS (status))
|
2008-02-16 01:53:11 +08:00
|
|
|
{
|
2007-10-15 16:25:38 +08:00
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fpi.CurrentByteOffset.QuadPart = fsi.EndOfFile.QuadPart + offset;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2007-10-15 16:25:38 +08:00
|
|
|
|
|
|
|
debug_printf ("setting file pointer to %U", fpi.CurrentByteOffset.QuadPart);
|
|
|
|
status = NtSetInformationFile (get_handle (), &io, &fpi, sizeof fpi,
|
|
|
|
FilePositionInformation);
|
|
|
|
if (!NT_SUCCESS (status))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-10-15 16:25:38 +08:00
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
off_t res = fpi.CurrentByteOffset.QuadPart;
|
2003-11-18 06:18:42 +08:00
|
|
|
|
2007-10-15 16:25:38 +08:00
|
|
|
/* When next we write(), we will check to see if *this* seek went beyond
|
|
|
|
the end of the file and if so, potentially sparsify the file. */
|
2012-12-14 18:45:29 +08:00
|
|
|
if (pc.support_sparse ())
|
|
|
|
did_lseek (true);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2007-10-15 16:25:38 +08: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)
|
2020-01-27 20:14:32 +08:00
|
|
|
res -= ralen () - raixget ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:20:37 +08:00
|
|
|
ssize_t __reg3
|
2018-07-24 13:31:58 +08:00
|
|
|
fhandler_base::pread (void *, size_t, off_t, void *)
|
2005-07-30 01:04:46 +08:00
|
|
|
{
|
|
|
|
set_errno (ESPIPE);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:20:37 +08:00
|
|
|
ssize_t __reg3
|
2018-07-24 13:31:58 +08:00
|
|
|
fhandler_base::pwrite (void *, size_t, off_t, void *)
|
2005-07-30 01:04:46 +08:00
|
|
|
{
|
|
|
|
set_errno (ESPIPE);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-05-06 06:30:53 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::close_with_arch ()
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
fhandler_base *fh;
|
|
|
|
if (usecount)
|
|
|
|
{
|
2013-07-04 04:26:44 +08:00
|
|
|
/* This was the archetype itself. */
|
|
|
|
if (--usecount)
|
2011-05-06 06:30:53 +08:00
|
|
|
{
|
2013-07-04 04:26:44 +08:00
|
|
|
debug_printf ("not closing passed in archetype %p, usecount %d", archetype, usecount);
|
2011-05-06 06:30:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2013-07-04 04:26:44 +08:00
|
|
|
debug_printf ("closing passed in archetype %p, usecount %d", archetype, usecount);
|
|
|
|
/* Set archetype temporarily so that it will eventually be deleted. */
|
|
|
|
archetype = fh = this;
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
|
|
|
else if (!archetype)
|
|
|
|
fh = this;
|
2013-07-04 04:26:44 +08:00
|
|
|
else if (archetype_usecount (-1) == 0)
|
|
|
|
{
|
|
|
|
debug_printf ("closing archetype");
|
|
|
|
fh = archetype;
|
|
|
|
}
|
2011-05-06 06:30:53 +08:00
|
|
|
else
|
|
|
|
{
|
2013-07-04 04:26:44 +08:00
|
|
|
debug_printf ("not closing archetype");
|
|
|
|
return 0;
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
|
|
|
|
2013-07-04 04:26:44 +08:00
|
|
|
cleanup ();
|
2011-05-06 06:30:53 +08:00
|
|
|
res = fh->close ();
|
|
|
|
if (archetype)
|
|
|
|
{
|
|
|
|
cygheap->fdtab.delete_archetype (archetype);
|
|
|
|
archetype = NULL;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2005-07-30 01:04:46 +08:00
|
|
|
|
2013-10-23 04:41:09 +08:00
|
|
|
void
|
|
|
|
fhandler_base::cleanup ()
|
|
|
|
{
|
2013-10-24 17:41:17 +08:00
|
|
|
/* Delete all POSIX locks on the file. Delete all flock locks on the
|
|
|
|
file if this is the last reference to this file. */
|
|
|
|
if (unique_id)
|
|
|
|
del_my_locks (on_close);
|
2013-10-23 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2001-09-01 13:17:34 +08:00
|
|
|
fhandler_base::close ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
syscall_printf ("closing '%s' handle %p", get_name (), get_handle ());
|
2004-04-10 21:45:10 +08:00
|
|
|
if (nohandle () || CloseHandle (get_handle ()))
|
2000-02-18 03:38:33 +08:00
|
|
|
res = 0;
|
|
|
|
else
|
|
|
|
{
|
2011-12-17 08:03:31 +08:00
|
|
|
paranoid_printf ("CloseHandle failed, %E");
|
2000-02-18 03:38:33 +08:00
|
|
|
__seterrno ();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::ioctl (unsigned int cmd, void *buf)
|
|
|
|
{
|
2003-10-25 20:32:56 +08:00
|
|
|
int res;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-10-25 20:32:56 +08:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case FIONBIO:
|
|
|
|
set_nonblocking (*(int *) buf);
|
|
|
|
res = 0;
|
|
|
|
break;
|
2011-07-22 04:21:46 +08:00
|
|
|
case FIONREAD:
|
2011-10-12 07:20:38 +08:00
|
|
|
case TIOCSCTTY:
|
2011-07-22 04:21:46 +08:00
|
|
|
set_errno (ENOTTY);
|
|
|
|
res = -1;
|
|
|
|
break;
|
2003-10-25 20:32:56 +08:00
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-04 05:43:27 +08:00
|
|
|
syscall_printf ("%d = ioctl(%x, %p)", res, cmd, buf);
|
2003-10-25 20:32:56 +08:00
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
int __reg2
|
2013-04-23 17:44:36 +08:00
|
|
|
fhandler_base::fstat (struct stat *buf)
|
2001-10-05 12:21:41 +08: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 08:37:18 +08:00
|
|
|
if (is_fs_special ())
|
|
|
|
return fstat_fs (buf);
|
|
|
|
|
2001-10-05 12:21:41 +08:00
|
|
|
switch (get_device ())
|
|
|
|
{
|
2002-06-24 10:23:14 +08:00
|
|
|
case FH_PIPE:
|
2007-06-12 16:28:44 +08:00
|
|
|
buf->st_mode = S_IFIFO | S_IRUSR | S_IWUSR;
|
2002-06-24 10:23:14 +08:00
|
|
|
break;
|
2001-10-05 12:21:41 +08:00
|
|
|
case FH_PIPEW:
|
2007-06-12 16:28:44 +08:00
|
|
|
buf->st_mode = S_IFIFO | S_IWUSR;
|
2001-10-05 12:21:41 +08:00
|
|
|
break;
|
|
|
|
case FH_PIPER:
|
2007-06-12 16:28:44 +08:00
|
|
|
buf->st_mode = S_IFIFO | S_IRUSR;
|
2002-06-24 10:23:14 +08:00
|
|
|
break;
|
2001-10-05 12:21:41 +08:00
|
|
|
default:
|
2002-06-24 10:23:14 +08:00
|
|
|
buf->st_mode = S_IFCHR | STD_RBITS | STD_WBITS | S_IWGRP | S_IWOTH;
|
2001-10-05 12:21:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-04-02 01:17:46 +08:00
|
|
|
buf->st_uid = geteuid32 ();
|
|
|
|
buf->st_gid = getegid32 ();
|
2001-10-05 12:21:41 +08:00
|
|
|
buf->st_nlink = 1;
|
2007-01-04 17:17:55 +08:00
|
|
|
buf->st_blksize = PREFERRED_IO_BLKSIZE;
|
2010-03-29 23:02:50 +08:00
|
|
|
|
|
|
|
buf->st_ctim.tv_sec = 1164931200L; /* Arbitrary value: 2006-12-01 */
|
2007-02-26 22:19:00 +08:00
|
|
|
buf->st_ctim.tv_nsec = 0L;
|
2010-03-29 23:02:50 +08:00
|
|
|
buf->st_birthtim = buf->st_ctim;
|
|
|
|
buf->st_mtim.tv_sec = time (NULL); /* Arbitrary value: current time,
|
|
|
|
like Linux */
|
|
|
|
buf->st_mtim.tv_nsec = 0L;
|
|
|
|
buf->st_atim = buf->st_mtim;
|
|
|
|
|
2001-10-05 12:21:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:20:37 +08:00
|
|
|
int __reg2
|
2007-02-27 20:58:56 +08:00
|
|
|
fhandler_base::fstatvfs (struct statvfs *sfs)
|
|
|
|
{
|
|
|
|
/* If we hit this base implementation, it's some device in /dev.
|
|
|
|
Just call statvfs on /dev for simplicity. */
|
2010-06-15 20:05:15 +08:00
|
|
|
path_conv pc ("/dev", PC_KEEP_HANDLE);
|
2007-02-27 20:58:56 +08:00
|
|
|
fhandler_disk_file fh (pc);
|
|
|
|
return fh.fstatvfs (sfs);
|
|
|
|
}
|
|
|
|
|
2009-07-04 02:05:51 +08:00
|
|
|
int
|
2000-02-18 03:38:33 +08:00
|
|
|
fhandler_base::init (HANDLE f, DWORD a, mode_t bin)
|
|
|
|
{
|
2019-03-30 15:12:02 +08:00
|
|
|
set_handle (f);
|
2001-04-24 10:07:58 +08:00
|
|
|
access = a;
|
2000-02-18 03:38:33 +08:00
|
|
|
a &= GENERIC_READ | GENERIC_WRITE;
|
2002-06-05 09:42:28 +08:00
|
|
|
int flags = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (a == GENERIC_READ)
|
2002-06-05 09:42:28 +08:00
|
|
|
flags = O_RDONLY;
|
2002-06-01 04:48:14 +08:00
|
|
|
else if (a == GENERIC_WRITE)
|
2002-06-05 09:42:28 +08:00
|
|
|
flags = O_WRONLY;
|
2002-06-01 04:48:14 +08:00
|
|
|
else if (a == (GENERIC_READ | GENERIC_WRITE))
|
2002-06-05 09:42:28 +08:00
|
|
|
flags = O_RDWR;
|
2002-07-04 02:02:54 +08:00
|
|
|
set_flags (flags | bin);
|
2001-04-24 10:07:58 +08:00
|
|
|
set_open_status ();
|
2004-04-10 21:45:10 +08:00
|
|
|
debug_printf ("created new fhandler_base for handle %p, bin %d", f, rbinary ());
|
2009-07-04 02:05:51 +08:00
|
|
|
return 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2021-09-14 11:48:03 +08:00
|
|
|
fhandler_base::dup (fhandler_base *child, int flags)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
debug_printf ("in fhandler_base dup");
|
|
|
|
|
|
|
|
HANDLE nh;
|
2011-05-07 04:12:20 +08:00
|
|
|
if (!nohandle () && !archetype)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2009-12-19 04:32:04 +08:00
|
|
|
if (!DuplicateHandle (GetCurrentProcess (), get_handle (),
|
|
|
|
GetCurrentProcess (), &nh,
|
2021-09-14 11:48:03 +08:00
|
|
|
0, !(flags & O_CLOEXEC), DUPLICATE_SAME_ACCESS))
|
2002-09-22 11:38:57 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("dup(%s) failed, handle %p, %E",
|
2004-09-10 16:34:37 +08:00
|
|
|
get_name (), get_handle ());
|
2002-09-22 11:38:57 +08:00
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-01-24 07:05:33 +08:00
|
|
|
VerifyHandle (nh);
|
2019-03-30 15:12:02 +08:00
|
|
|
child->set_handle (nh);
|
2002-09-22 11:38:57 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
int fhandler_base::fcntl (int cmd, intptr_t arg)
|
2000-10-24 04:16:52 +08:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case F_GETFD:
|
2004-04-10 21:45:10 +08:00
|
|
|
res = close_on_exec () ? FD_CLOEXEC : 0;
|
2000-10-24 04:16:52 +08:00
|
|
|
break;
|
|
|
|
case F_SETFD:
|
2013-04-23 17:44:36 +08:00
|
|
|
set_close_on_exec ((arg & FD_CLOEXEC) ? 1 : 0);
|
2000-10-24 04:16:52 +08:00
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
case F_GETFL:
|
|
|
|
res = get_flags ();
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("GETFL: %y", res);
|
2000-10-24 04:16:52 +08:00
|
|
|
break;
|
|
|
|
case F_SETFL:
|
2000-10-24 04:29:31 +08:00
|
|
|
{
|
2009-06-15 07:42:09 +08:00
|
|
|
/* Only O_APPEND, O_ASYNC and O_NONBLOCK/O_NDELAY are allowed.
|
|
|
|
Each other flag will be ignored.
|
|
|
|
Since O_ASYNC isn't defined in fcntl.h it's currently
|
|
|
|
ignored as well. */
|
2001-09-08 05:32:07 +08:00
|
|
|
const int allowed_flags = O_APPEND | O_NONBLOCK_MASK;
|
2013-04-23 17:44:36 +08:00
|
|
|
int new_flags = arg & allowed_flags;
|
2001-09-08 05:32:07 +08:00
|
|
|
/* Carefully test for the O_NONBLOCK or deprecated OLD_O_NDELAY flag.
|
2001-08-07 08:01:42 +08: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 20:11:20 +08:00
|
|
|
new_flags &= ~OLD_O_NDELAY;
|
2001-08-07 08:01:42 +08:00
|
|
|
set_flags ((get_flags () & ~allowed_flags) | new_flags);
|
2000-10-24 04:29:31 +08:00
|
|
|
}
|
2000-10-24 04:16:52 +08:00
|
|
|
res = 0;
|
|
|
|
break;
|
2013-10-24 17:41:17 +08:00
|
|
|
case F_GETLK:
|
|
|
|
case F_SETLK:
|
|
|
|
case F_SETLKW:
|
|
|
|
{
|
|
|
|
struct flock *fl = (struct flock *) arg;
|
|
|
|
fl->l_type &= F_RDLCK | F_WRLCK | F_UNLCK;
|
|
|
|
res = mandatory_locking () ? mand_lock (cmd, fl) : lock (cmd, fl);
|
|
|
|
}
|
|
|
|
break;
|
2000-10-24 04:16:52 +08:00
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Base terminal handlers. These just return errors. */
|
|
|
|
|
|
|
|
int
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_base::tcflush (int)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_base::tcsendbreak (int)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-07-05 11:16:46 +08:00
|
|
|
fhandler_base::tcdrain ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_base::tcflow (int)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_base::tcsetattr (int, const struct termios *)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_base::tcgetattr (struct termios *)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_base::tcsetpgrp (const pid_t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-07-05 11:16:46 +08:00
|
|
|
fhandler_base::tcgetpgrp ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-28 22:03:03 +08:00
|
|
|
pid_t
|
2011-10-12 07:20:38 +08:00
|
|
|
fhandler_base::tcgetsid ()
|
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-11-08 04:05:49 +08:00
|
|
|
int
|
|
|
|
fhandler_base::ptsname_r (char *, size_t)
|
|
|
|
{
|
|
|
|
set_errno (ENOTTY);
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Normal I/O constructor */
|
2004-04-09 16:43:29 +08:00
|
|
|
fhandler_base::fhandler_base () :
|
|
|
|
status (),
|
|
|
|
open_status (),
|
2001-04-24 10:07:58 +08:00
|
|
|
access (0),
|
2000-02-18 03:38:33 +08:00
|
|
|
io_handle (NULL),
|
2008-04-01 02:03:25 +08:00
|
|
|
ino (0),
|
2011-12-17 08:03:31 +08:00
|
|
|
_refcnt (0),
|
2001-04-24 10:07:58 +08:00
|
|
|
openflags (0),
|
2008-04-01 02:03:25 +08:00
|
|
|
unique_id (0),
|
2021-09-08 16:18:35 +08:00
|
|
|
select_sem (NULL),
|
2003-12-11 14:12:41 +08:00
|
|
|
archetype (NULL),
|
|
|
|
usecount (0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2020-01-27 20:14:32 +08:00
|
|
|
ra.rabuf = NULL;
|
|
|
|
ra.ralen = 0;
|
|
|
|
ra.raixget = 0;
|
|
|
|
ra.raixput = 0;
|
|
|
|
ra.rabuflen = 0;
|
2011-12-17 08:03:31 +08:00
|
|
|
isclosed (false);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal I/O destructor */
|
2005-07-05 11:16:46 +08:00
|
|
|
fhandler_base::~fhandler_base ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2020-01-27 20:14:32 +08:00
|
|
|
if (ra.rabuf)
|
|
|
|
free (ra.rabuf);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
/* /dev/null */
|
|
|
|
|
2001-10-14 01:23:35 +08: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 08:37:18 +08:00
|
|
|
fhandler_base ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:17:43 +08:00
|
|
|
ssize_t __stdcall
|
|
|
|
fhandler_dev_null::write (const void *ptr, size_t len)
|
|
|
|
{
|
|
|
|
/* Shortcut. This also fixes a problem with the NUL device on 64 bit:
|
|
|
|
If you write > 4 GB in a single attempt, the bytes written returned
|
|
|
|
from by is numBytes & 0xffffffff. */
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2000-04-20 12:38:10 +08:00
|
|
|
void
|
2006-12-12 02:55:29 +08:00
|
|
|
fhandler_base::set_no_inheritance (HANDLE &h, bool not_inheriting)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-02-23 01:09:46 +08:00
|
|
|
if (!SetHandleInformation (h, HANDLE_FLAG_INHERIT,
|
|
|
|
not_inheriting ? 0 : HANDLE_FLAG_INHERIT))
|
|
|
|
debug_printf ("SetHandleInformation failed, %E");
|
2002-07-15 03:15:32 +08:00
|
|
|
#ifdef DEBUGGING_AND_FDS_PROTECTED
|
2001-10-24 12:16:45 +08:00
|
|
|
if (h)
|
2002-07-14 04:00:27 +08:00
|
|
|
setclexec (oh, h, not_inheriting);
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-05-25 13:40:51 +08:00
|
|
|
bool
|
2000-02-18 03:38:33 +08:00
|
|
|
fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
|
|
|
|
{
|
2004-01-24 07:05:33 +08:00
|
|
|
HANDLE oh = h;
|
2006-05-25 13:40:51 +08:00
|
|
|
bool res = false;
|
2018-02-23 22:24:18 +08:00
|
|
|
if (!close_on_exec ())
|
2001-07-21 11:20:01 +08:00
|
|
|
debug_printf ("handle %p already opened", h);
|
2009-12-19 04:32:04 +08:00
|
|
|
else if (!DuplicateHandle (parent, h, GetCurrentProcess (), &h,
|
|
|
|
0, !close_on_exec (), DUPLICATE_SAME_ACCESS))
|
2000-02-18 03:38:33 +08:00
|
|
|
system_printf ("%s - %E, handle %s<%p>", get_name (), name, h);
|
2006-05-25 13:40:51 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (oh != h)
|
|
|
|
VerifyHandle (h);
|
|
|
|
res = true;
|
|
|
|
}
|
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-10 21:45:10 +08:00
|
|
|
fhandler_base::set_close_on_exec (bool val)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-04-10 21:45:10 +08:00
|
|
|
if (!nohandle ())
|
2004-02-03 04:33:09 +08:00
|
|
|
set_no_inheritance (io_handle, val);
|
2004-04-10 21:45:10 +08:00
|
|
|
close_on_exec (val);
|
2000-02-18 03:38:33 +08: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 21:45:10 +08:00
|
|
|
if (!nohandle ())
|
2002-09-19 11:30:20 +08:00
|
|
|
fork_fixup (parent, io_handle, "io_handle");
|
2008-04-01 02:03:25 +08:00
|
|
|
/* POSIX locks are not inherited across fork. */
|
|
|
|
if (unique_id)
|
2009-07-22 23:46:36 +08:00
|
|
|
del_my_locks (after_fork);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-08-15 15:49:15 +08:00
|
|
|
|
2006-06-02 23:41:34 +08:00
|
|
|
void
|
|
|
|
fhandler_base::fixup_after_exec ()
|
|
|
|
{
|
|
|
|
debug_printf ("here for '%s'", get_name ());
|
2008-04-01 02:03:25 +08:00
|
|
|
if (unique_id && close_on_exec ())
|
2009-07-22 23:46:36 +08:00
|
|
|
del_my_locks (after_exec);
|
2013-06-04 18:24:43 +08:00
|
|
|
mandatory_locking (false);
|
2006-06-02 23:41:34 +08:00
|
|
|
}
|
|
|
|
|
2001-11-24 11:11:39 +08:00
|
|
|
bool
|
2001-08-15 15:49:15 +08: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 14:47:57 +08:00
|
|
|
|
2005-05-25 12:32:59 +08: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 14:47:57 +08:00
|
|
|
DIR *
|
2007-06-29 23:13:01 +08:00
|
|
|
fhandler_base::opendir (int fd)
|
2001-11-21 14:47:57 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-20 14:19:55 +08:00
|
|
|
int
|
|
|
|
fhandler_base::readdir (DIR *, dirent *)
|
2001-11-21 14:47:57 +08:00
|
|
|
{
|
2005-08-20 14:19:55 +08:00
|
|
|
return ENOTDIR;
|
2001-11-21 14:47:57 +08:00
|
|
|
}
|
|
|
|
|
2010-07-06 00:59:56 +08:00
|
|
|
long
|
2001-11-21 14:47:57 +08:00
|
|
|
fhandler_base::telldir (DIR *)
|
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-06 00:59:56 +08:00
|
|
|
fhandler_base::seekdir (DIR *, long)
|
2001-11-21 14:47:57 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_base::rewinddir (DIR *)
|
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::closedir (DIR *)
|
|
|
|
{
|
|
|
|
set_errno (ENOTDIR);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-14 04:36:58 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::fchmod (mode_t mode)
|
|
|
|
{
|
2004-12-26 10:10:30 +08:00
|
|
|
if (pc.is_fs_special ())
|
|
|
|
return chmod_device (pc, mode);
|
2004-04-14 04:36:58 +08:00
|
|
|
/* By default, just succeeds. */
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-14 21:40:07 +08:00
|
|
|
|
|
|
|
int
|
2013-04-23 17:44:36 +08:00
|
|
|
fhandler_base::fchown (uid_t uid, gid_t gid)
|
2004-04-14 21:40:07 +08:00
|
|
|
{
|
2004-12-26 10:10:30 +08:00
|
|
|
if (pc.is_fs_special ())
|
|
|
|
return ((fhandler_disk_file *) this)->fhandler_disk_file::fchown (uid, gid);
|
2004-04-14 21:40:07 +08:00
|
|
|
/* By default, just succeeds. */
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-15 00:36:26 +08:00
|
|
|
|
|
|
|
int
|
2013-04-23 17:44:36 +08:00
|
|
|
fhandler_base::facl (int cmd, int nentries, aclent_t *aclbufp)
|
2004-04-15 00:36:26 +08:00
|
|
|
{
|
2005-01-15 06:03:40 +08: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;
|
|
|
|
res = MIN_ACL_ENTRIES;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GETACLCNT:
|
|
|
|
res = MIN_ACL_ENTRIES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
2004-04-15 00:36:26 +08:00
|
|
|
}
|
2005-02-03 06:42:06 +08:00
|
|
|
|
* Makefile.in (DLL_OFILES): Add ntea.o.
* cygwin.din (getxattr, listxattr, removexattr, setxattr, lgetxattr,
llistxattr, lremovexattr, lsetxattr, fgetxattr, flistxattr,
fremovexattr, fsetxattr): Export Linux extended attribute functions.
Sort.
* errno.cc (errmap): Add mappings for ERROR_EAS_DIDNT_FIT,
ERROR_EAS_NOT_SUPPORTED, ERROR_EA_LIST_INCONSISTENT,
ERROR_EA_TABLE_FULL, ERROR_FILE_CORRUPT, ERROR_INVALID_EA_NAME.
* fhandler.h (class fhandler_base): Declare new fgetxattr and
fsetxattr methods.
(class fhandler_disk_file): Ditto.
* fhandler.cc (fhandler_base::fgetxattr): New method.
(fhandler_base::fsetxattr): New method.
* fhandler_disk_file.cc (fhandler_disk_file::fgetxattr): New method.
(fhandler_disk_file::fsetxattr): New method.
* ntdll.h (STATUS_EA_TOO_LARGE): Define.
(STATUS_NONEXISTENT_EA_ENTRY): Define.
(STATUS_NO_EAS_ON_FILE): Define.
* ntea.cc (read_ea): Rewrite for long pathnames and for using with
Linux extended attribute functions.
(write_ea): Ditto.
(getxattr_worker): New static function.
(getxattr): New function.
(lgetxattr): New function.
(fgetxattr): New function.
(listxattr): New function.
(llistxattr): New function.
(flistxattr): New function.
(setxattr_worker): New static function.
(setxattr): New function.
(lsetxattr): New function.
(fsetxattr): New function.
(removexattr): New function.
(lsetxattr): New function.
(fsetxattr): New function.
* security.h (read_ea): Change declaration according to above changes.
(write_ea): Ditto.
* include/cygwin/version.h: Bump API minor version.
2008-02-10 23:43:04 +08:00
|
|
|
ssize_t
|
|
|
|
fhandler_base::fgetxattr (const char *name, void *value, size_t size)
|
|
|
|
{
|
|
|
|
set_errno (ENOTSUP);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::fsetxattr (const char *name, const void *value, size_t size,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
set_errno (ENOTSUP);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-02-03 06:42:06 +08:00
|
|
|
int
|
2013-04-23 17:44:36 +08:00
|
|
|
fhandler_base::fadvise (off_t offset, off_t length, int advice)
|
2006-08-08 03:29:14 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-04-23 17:44:36 +08:00
|
|
|
fhandler_base::ftruncate (off_t length, bool allow_truncate)
|
2005-02-03 06:42:06 +08:00
|
|
|
{
|
2017-11-02 23:45:35 +08:00
|
|
|
return EINVAL;
|
2005-02-03 06:42:06 +08:00
|
|
|
}
|
2005-02-20 05:53:36 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::link (const char *newpath)
|
|
|
|
{
|
2009-09-26 23:51:53 +08:00
|
|
|
set_errno (EPERM);
|
2005-02-20 05:53:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2005-02-20 19:44:32 +08:00
|
|
|
|
|
|
|
int
|
2008-04-24 17:59:54 +08:00
|
|
|
fhandler_base::utimens (const struct timespec *tvp)
|
2005-02-20 19:44:32 +08:00
|
|
|
{
|
2005-04-14 00:17:37 +08:00
|
|
|
if (is_fs_special ())
|
2008-04-24 17:59:54 +08:00
|
|
|
return utimens_fs (tvp);
|
2005-04-14 00:17:37 +08:00
|
|
|
|
2005-02-20 19:44:32 +08:00
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-20 21:28:23 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::fsync ()
|
|
|
|
{
|
2005-02-22 23:30:09 +08:00
|
|
|
if (!get_handle () || nohandle ())
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-20 21:28:23 +08:00
|
|
|
if (pc.isdir ()) /* Just succeed. */
|
|
|
|
return 0;
|
|
|
|
if (FlushFileBuffers (get_handle ()))
|
|
|
|
return 0;
|
2011-02-01 16:46:48 +08:00
|
|
|
|
|
|
|
/* Ignore ERROR_INVALID_FUNCTION because FlushFileBuffers() always fails
|
|
|
|
with this code on raw devices which are unbuffered by default. */
|
|
|
|
DWORD errcode = GetLastError();
|
|
|
|
if (errcode == ERROR_INVALID_FUNCTION)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
__seterrno_from_win_error (errcode);
|
2005-02-20 21:28:23 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2006-11-08 01:59:54 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::fpathconf (int v)
|
|
|
|
{
|
2008-02-16 17:43:19 +08:00
|
|
|
int ret;
|
|
|
|
|
2006-11-08 01:59:54 +08:00
|
|
|
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 ())
|
2007-02-20 08:16:18 +08:00
|
|
|
return MAX_CANON;
|
2006-11-08 01:59:54 +08:00
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
case _PC_MAX_INPUT:
|
|
|
|
if (is_tty ())
|
2007-02-20 08:16:18 +08:00
|
|
|
return MAX_INPUT;
|
2006-11-08 01:59:54 +08:00
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
case _PC_NAME_MAX:
|
|
|
|
/* NAME_MAX is without trailing \0 */
|
2008-02-16 17:43:19 +08:00
|
|
|
if (!pc.isdir ())
|
2008-11-27 01:21:04 +08:00
|
|
|
return NAME_MAX;
|
2008-02-16 17:43:19 +08:00
|
|
|
ret = NT_MAX_PATH - strlen (get_name ()) - 2;
|
|
|
|
return ret < 0 ? 0 : ret > NAME_MAX ? NAME_MAX : ret;
|
2006-11-08 01:59:54 +08:00
|
|
|
case _PC_PATH_MAX:
|
|
|
|
/* PATH_MAX is with trailing \0 */
|
2008-02-16 17:43:19 +08:00
|
|
|
if (!pc.isdir ())
|
|
|
|
return PATH_MAX;
|
|
|
|
ret = NT_MAX_PATH - strlen (get_name ()) - 1;
|
|
|
|
return ret < 0 ? 0 : ret > PATH_MAX ? PATH_MAX : ret;
|
2006-11-08 01:59:54 +08:00
|
|
|
case _PC_PIPE_BUF:
|
|
|
|
if (pc.isdir ()
|
|
|
|
|| get_device () == FH_FIFO || get_device () == FH_PIPE
|
|
|
|
|| get_device () == FH_PIPER || get_device () == FH_PIPEW)
|
2007-02-20 08:16:18 +08:00
|
|
|
return PIPE_BUF;
|
2006-11-08 01:59:54 +08:00
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
case _PC_CHOWN_RESTRICTED:
|
|
|
|
return 1;
|
|
|
|
case _PC_NO_TRUNC:
|
|
|
|
return 1;
|
|
|
|
case _PC_VDISABLE:
|
2007-02-08 01:22:40 +08:00
|
|
|
if (is_tty ())
|
2007-02-20 08:16:18 +08:00
|
|
|
return _POSIX_VDISABLE;
|
2007-02-08 01:22:40 +08:00
|
|
|
set_errno (EINVAL);
|
2006-11-08 01:59:54 +08:00
|
|
|
break;
|
|
|
|
case _PC_ASYNC_IO:
|
2018-07-26 04:00:43 +08:00
|
|
|
return 1;
|
2006-11-08 01:59:54 +08:00
|
|
|
case _PC_PRIO_IO:
|
|
|
|
break;
|
2007-02-08 01:22:40 +08:00
|
|
|
case _PC_SYNC_IO:
|
|
|
|
return 1;
|
2006-11-08 01:59:54 +08:00
|
|
|
case _PC_FILESIZEBITS:
|
|
|
|
return FILESIZEBITS;
|
|
|
|
case _PC_2_SYMLINKS:
|
|
|
|
return 1;
|
|
|
|
case _PC_SYMLINK_MAX:
|
2007-02-08 01:22:40 +08:00
|
|
|
return SYMLINK_MAX;
|
2006-11-08 01:59:54 +08:00
|
|
|
case _PC_POSIX_PERMISSIONS:
|
|
|
|
case _PC_POSIX_SECURITY:
|
|
|
|
if (get_device () == FH_FS)
|
2008-07-15 04:46:27 +08:00
|
|
|
return pc.has_acls () || pc.fs_is_nfs ();
|
2006-11-08 01:59:54 +08:00
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
2016-10-21 03:35:54 +08:00
|
|
|
case _PC_CASE_INSENSITIVE:
|
|
|
|
return !!pc.objcaseinsensitive ();
|
2006-11-08 01:59:54 +08:00
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2021-08-27 06:05:53 +08:00
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
fhandler_base::npfs_handle (HANDLE &nph)
|
|
|
|
{
|
|
|
|
static NO_COPY SRWLOCK npfs_lock;
|
|
|
|
static NO_COPY HANDLE npfs_dirh;
|
|
|
|
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
|
|
|
/* Lockless after first call. */
|
|
|
|
if (npfs_dirh)
|
|
|
|
{
|
|
|
|
nph = npfs_dirh;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
AcquireSRWLockExclusive (&npfs_lock);
|
|
|
|
if (!npfs_dirh)
|
|
|
|
{
|
|
|
|
InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
|
|
|
|
status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
|
|
|
|
&attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
ReleaseSRWLockExclusive (&npfs_lock);
|
|
|
|
if (NT_SUCCESS (status))
|
|
|
|
nph = npfs_dirh;
|
|
|
|
return status;
|
|
|
|
}
|