2002-05-02 06:26:05 +02:00
|
|
|
/* fhandler_registry.cc: fhandler for /proc/registry virtual filesystem
|
|
|
|
|
2007-02-26 13:39:25 +01:00
|
|
|
Copyright 2002, 2003, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
/* FIXME: Access permissions are ignored at the moment. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/cygwin.h>
|
|
|
|
#include "cygerrno.h"
|
|
|
|
#include "security.h"
|
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
#include "fhandler.h"
|
2002-05-04 05:24:35 +02:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2002-05-02 06:26:05 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#define _COMPILING_NEWLIB
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
/* If this bit is set in __d_position then we are enumerating values,
|
|
|
|
* else sub-keys. keeping track of where we are is horribly messy
|
|
|
|
* the bottom 16 bits are the absolute position and the top 15 bits
|
|
|
|
* make up the value index if we are enuerating values.
|
|
|
|
*/
|
2003-04-01 18:11:41 +02:00
|
|
|
static const _off_t REG_ENUM_VALUES_MASK = 0x8000000;
|
|
|
|
static const _off_t REG_POSITION_MASK = 0xffff;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
/* List of root keys in /proc/registry.
|
|
|
|
* Possibly we should filter out those not relevant to the flavour of Windows
|
|
|
|
* Cygwin is running on.
|
|
|
|
*/
|
2002-05-04 05:24:35 +02:00
|
|
|
static const char *registry_listing[] =
|
|
|
|
{
|
|
|
|
".",
|
|
|
|
"..",
|
2002-05-02 06:26:05 +02:00
|
|
|
"HKEY_CLASSES_ROOT",
|
|
|
|
"HKEY_CURRENT_CONFIG",
|
|
|
|
"HKEY_CURRENT_USER",
|
|
|
|
"HKEY_LOCAL_MACHINE",
|
|
|
|
"HKEY_USERS",
|
2004-07-15 04:07:14 +02:00
|
|
|
"HKEY_PERFORMANCE_DATA", // NT/2000/XP
|
2002-05-02 06:26:05 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-05-04 05:24:35 +02:00
|
|
|
static const HKEY registry_keys[] =
|
|
|
|
{
|
|
|
|
(HKEY) INVALID_HANDLE_VALUE,
|
|
|
|
(HKEY) INVALID_HANDLE_VALUE,
|
2002-05-02 06:26:05 +02:00
|
|
|
HKEY_CLASSES_ROOT,
|
|
|
|
HKEY_CURRENT_CONFIG,
|
|
|
|
HKEY_CURRENT_USER,
|
|
|
|
HKEY_LOCAL_MACHINE,
|
|
|
|
HKEY_USERS,
|
|
|
|
HKEY_PERFORMANCE_DATA
|
|
|
|
};
|
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
static const int ROOT_KEY_COUNT = sizeof (registry_keys) / sizeof (HKEY);
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2002-05-04 05:24:35 +02:00
|
|
|
/* These get added to each subdirectory in /proc/registry.
|
|
|
|
* If we wanted to implement writing, we could maybe add a '.writable' entry or
|
|
|
|
* suchlike.
|
|
|
|
*/
|
|
|
|
static const char *special_dot_files[] =
|
|
|
|
{
|
|
|
|
".",
|
|
|
|
"..",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
static const int SPECIAL_DOT_FILE_COUNT =
|
|
|
|
(sizeof (special_dot_files) / sizeof (const char *)) - 1;
|
2002-05-04 05:24:35 +02:00
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
/* Name given to default values */
|
|
|
|
static const char *DEFAULT_VALUE_NAME = "@";
|
|
|
|
|
2006-10-19 12:01:03 +02:00
|
|
|
static HKEY open_key (const char *name, REGSAM access, DWORD wow64, bool isValue);
|
2002-07-02 03:36:15 +02:00
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
/* Returns 0 if path doesn't exist, >0 if path is a directory,
|
|
|
|
* <0 if path is a file.
|
|
|
|
*
|
|
|
|
* We open the last key but one and then enum it's sub-keys and values to see if the
|
|
|
|
* final component is there. This gets round the problem of not having security access
|
|
|
|
* to the final key in the path.
|
|
|
|
*/
|
|
|
|
int
|
2002-05-23 00:09:58 +02:00
|
|
|
fhandler_registry::exists ()
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
int file_type = 0, index = 0, pathlen;
|
2003-11-15 00:40:06 +01:00
|
|
|
DWORD buf_size = CYG_MAX_PATH;
|
2002-05-02 06:26:05 +02:00
|
|
|
LONG error;
|
|
|
|
char buf[buf_size];
|
|
|
|
const char *file;
|
|
|
|
HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
|
|
|
|
|
2002-05-23 00:09:58 +02:00
|
|
|
const char *path = get_name ();
|
2002-05-02 06:26:05 +02:00
|
|
|
debug_printf ("exists (%s)", path);
|
2006-10-19 12:01:03 +02:00
|
|
|
path += proc_len + prefix_len + 1;
|
2003-01-31 00:15:15 +01:00
|
|
|
if (*path)
|
|
|
|
path++;
|
|
|
|
else
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
file_type = 2;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
pathlen = strlen (path);
|
|
|
|
file = path + pathlen - 1;
|
2003-01-09 09:22:05 +01:00
|
|
|
if (isdirsep (*file) && pathlen > 1)
|
2002-05-02 06:26:05 +02:00
|
|
|
file--;
|
2003-01-09 09:22:05 +01:00
|
|
|
while (!isdirsep (*file))
|
2002-05-02 06:26:05 +02:00
|
|
|
file--;
|
|
|
|
file++;
|
|
|
|
|
|
|
|
if (file == path)
|
|
|
|
{
|
|
|
|
for (int i = 0; registry_listing[i]; i++)
|
2002-05-28 03:55:40 +02:00
|
|
|
if (path_prefix_p
|
|
|
|
(registry_listing[i], path, strlen (registry_listing[i])))
|
|
|
|
{
|
|
|
|
file_type = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2006-10-19 12:01:03 +02:00
|
|
|
hKey = open_key (path, KEY_READ, wow64, false);
|
2002-07-02 03:36:15 +02:00
|
|
|
if (hKey != (HKEY) INVALID_HANDLE_VALUE)
|
|
|
|
file_type = 1;
|
|
|
|
else
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2006-10-19 12:01:03 +02:00
|
|
|
hKey = open_key (path, KEY_READ, wow64, true);
|
2002-07-02 03:36:15 +02:00
|
|
|
if (hKey == (HKEY) INVALID_HANDLE_VALUE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (ERROR_SUCCESS ==
|
|
|
|
(error = RegEnumKeyEx (hKey, index++, buf, &buf_size, NULL, NULL,
|
|
|
|
NULL, NULL))
|
|
|
|
|| (error == ERROR_MORE_DATA))
|
|
|
|
{
|
|
|
|
if (pathmatch (buf, file))
|
|
|
|
{
|
|
|
|
file_type = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-11-15 00:40:06 +01:00
|
|
|
buf_size = CYG_MAX_PATH;
|
2002-07-02 03:36:15 +02:00
|
|
|
}
|
|
|
|
if (error != ERROR_NO_MORE_ITEMS)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
seterrno_from_win_error (__FILE__, __LINE__, error);
|
2002-05-28 03:55:40 +02:00
|
|
|
goto out;
|
|
|
|
}
|
2002-07-02 03:36:15 +02:00
|
|
|
index = 0;
|
2003-11-15 00:40:06 +01:00
|
|
|
buf_size = CYG_MAX_PATH;
|
2002-07-02 03:36:15 +02:00
|
|
|
while (ERROR_SUCCESS ==
|
|
|
|
(error = RegEnumValue (hKey, index++, buf, &buf_size, NULL, NULL,
|
|
|
|
NULL, NULL))
|
|
|
|
|| (error == ERROR_MORE_DATA))
|
|
|
|
{
|
|
|
|
if (pathmatch (buf, file) || (buf[0] == '\0' &&
|
|
|
|
pathmatch (file, DEFAULT_VALUE_NAME)))
|
|
|
|
{
|
|
|
|
file_type = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-11-15 00:40:06 +01:00
|
|
|
buf_size = CYG_MAX_PATH;
|
2002-07-02 03:36:15 +02:00
|
|
|
}
|
|
|
|
if (error != ERROR_NO_MORE_ITEMS)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
seterrno_from_win_error (__FILE__, __LINE__, error);
|
2002-05-28 03:55:40 +02:00
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (hKey != (HKEY) INVALID_HANDLE_VALUE)
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
return file_type;
|
|
|
|
}
|
|
|
|
|
2006-10-19 12:01:03 +02:00
|
|
|
void
|
|
|
|
fhandler_registry::set_name (path_conv &in_pc)
|
2007-02-20 01:16:18 +01:00
|
|
|
{
|
2006-10-19 12:01:03 +02:00
|
|
|
if (strncasematch (in_pc.normalized_path, "/proc/registry32", 16))
|
|
|
|
{
|
|
|
|
wow64 = KEY_WOW64_32KEY;
|
|
|
|
prefix_len += 2;
|
|
|
|
}
|
|
|
|
else if (strncasematch (in_pc.normalized_path, "/proc/registry64", 16))
|
|
|
|
{
|
|
|
|
wow64 = KEY_WOW64_64KEY;
|
|
|
|
prefix_len += 2;
|
|
|
|
}
|
|
|
|
fhandler_base::set_name (in_pc);
|
|
|
|
}
|
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
fhandler_registry::fhandler_registry ():
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_proc ()
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2006-10-19 12:01:03 +02:00
|
|
|
wow64 = 0;
|
|
|
|
prefix_len = sizeof ("registry") - 1;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_registry::fstat (struct __stat64 *buf)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_base::fstat (buf);
|
2002-05-02 06:26:05 +02:00
|
|
|
buf->st_mode &= ~_IFMT & NO_W;
|
2002-05-23 00:09:58 +02:00
|
|
|
int file_type = exists ();
|
2002-05-02 06:26:05 +02:00
|
|
|
switch (file_type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return -1;
|
|
|
|
case 1:
|
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
|
|
|
buf->st_nlink = ROOT_KEY_COUNT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case -1:
|
|
|
|
buf->st_mode |= S_IFREG;
|
|
|
|
buf->st_mode &= NO_X;
|
|
|
|
break;
|
|
|
|
}
|
2002-07-02 03:36:15 +02:00
|
|
|
if (file_type != 0 && file_type != 2)
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
2006-10-19 12:01:03 +02:00
|
|
|
const char *path = get_name () + proc_len + prefix_len + 2;
|
2002-07-02 03:36:15 +02:00
|
|
|
hKey =
|
2006-10-19 12:01:03 +02:00
|
|
|
open_key (path, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, wow64,
|
2002-07-02 03:36:15 +02:00
|
|
|
(file_type < 0) ? true : false);
|
|
|
|
|
|
|
|
if (hKey != (HKEY) INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
FILETIME ftLastWriteTime;
|
|
|
|
DWORD subkey_count;
|
|
|
|
if (ERROR_SUCCESS ==
|
|
|
|
RegQueryInfoKey (hKey, NULL, NULL, NULL, &subkey_count, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL,
|
|
|
|
&ftLastWriteTime))
|
|
|
|
{
|
|
|
|
to_timestruc_t (&ftLastWriteTime, &buf->st_mtim);
|
2007-03-06 15:48:25 +01:00
|
|
|
buf->st_ctim = buf->st_birthtim = buf->st_mtim;
|
2002-07-02 03:36:15 +02:00
|
|
|
time_as_timestruc_t (&buf->st_atim);
|
|
|
|
if (file_type > 0)
|
2005-01-31 11:28:55 +01:00
|
|
|
buf->st_nlink = subkey_count + 2;
|
2002-07-02 03:36:15 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int pathlen = strlen (path);
|
|
|
|
const char *value_name = path + pathlen - 1;
|
2003-01-09 09:22:05 +01:00
|
|
|
if (isdirsep (*value_name) && pathlen > 1)
|
2002-07-02 03:36:15 +02:00
|
|
|
value_name--;
|
2003-01-09 09:22:05 +01:00
|
|
|
while (!isdirsep (*value_name))
|
2002-07-02 03:36:15 +02:00
|
|
|
value_name--;
|
|
|
|
value_name++;
|
|
|
|
DWORD dwSize;
|
|
|
|
if (ERROR_SUCCESS ==
|
|
|
|
RegQueryValueEx (hKey, value_name, NULL, NULL, NULL,
|
|
|
|
&dwSize))
|
|
|
|
buf->st_size = dwSize;
|
|
|
|
}
|
|
|
|
__uid32_t uid;
|
|
|
|
__gid32_t gid;
|
2007-07-20 16:29:43 +02:00
|
|
|
if (get_reg_attribute (hKey, &buf->st_mode, &uid, &gid) == 0)
|
2002-07-02 03:36:15 +02:00
|
|
|
{
|
|
|
|
buf->st_uid = uid;
|
|
|
|
buf->st_gid = gid;
|
|
|
|
buf->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
|
|
|
|
if (file_type > 0)
|
|
|
|
buf->st_mode |= S_IFDIR;
|
|
|
|
else
|
|
|
|
buf->st_mode &= NO_X;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
}
|
2006-10-21 12:58:35 +02:00
|
|
|
else
|
2007-02-20 01:16:18 +01:00
|
|
|
{
|
2006-10-21 12:58:35 +02:00
|
|
|
/* Here's the problem: If we can't open the key, we don't know
|
|
|
|
nothing at all about the key/value. It's only clear that
|
|
|
|
the current user has no read access. At this point it's
|
|
|
|
rather unlikely that the user has write or execute access
|
|
|
|
and it's also rather unlikely that the user is the owner.
|
|
|
|
Therefore it's probably most safe to assume unknown ownership
|
|
|
|
and no permissions for nobody. */
|
|
|
|
buf->st_uid = UNKNOWN_UID;
|
|
|
|
buf->st_gid = UNKNOWN_GID;
|
|
|
|
buf->st_mode &= ~0777;
|
|
|
|
}
|
2002-07-02 03:36:15 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-20 08:19:55 +02:00
|
|
|
int
|
|
|
|
fhandler_registry::readdir (DIR *dir, dirent *de)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2003-11-15 00:40:06 +01:00
|
|
|
DWORD buf_size = CYG_MAX_PATH;
|
2002-05-02 06:26:05 +02:00
|
|
|
char buf[buf_size];
|
|
|
|
HANDLE handle;
|
2006-10-19 12:01:03 +02:00
|
|
|
const char *path = dir->__d_dirname + proc_len + 1 + prefix_len;
|
2002-05-02 06:26:05 +02:00
|
|
|
LONG error;
|
2005-08-20 08:19:55 +02:00
|
|
|
int res = ENMFILE;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2006-01-27 22:50:42 +01:00
|
|
|
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
|
2002-05-02 06:26:05 +02:00
|
|
|
if (*path == 0)
|
|
|
|
{
|
|
|
|
if (dir->__d_position >= ROOT_KEY_COUNT)
|
2002-05-28 03:55:40 +02:00
|
|
|
goto out;
|
2005-08-20 08:19:55 +02:00
|
|
|
strcpy (de->d_name, registry_listing[dir->__d_position++]);
|
|
|
|
res = 0;
|
2002-05-02 06:26:05 +02:00
|
|
|
goto out;
|
|
|
|
}
|
2005-08-20 08:19:55 +02:00
|
|
|
if (dir->__handle == INVALID_HANDLE_VALUE && dir->__d_position == 0)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2006-10-19 12:01:03 +02:00
|
|
|
handle = open_key (path + 1, KEY_READ, wow64, false);
|
2003-09-08 06:04:19 +02:00
|
|
|
dir->__handle = handle;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2003-09-08 06:04:19 +02:00
|
|
|
if (dir->__handle == INVALID_HANDLE_VALUE)
|
2002-05-02 06:26:05 +02:00
|
|
|
goto out;
|
2002-05-04 05:24:35 +02:00
|
|
|
if (dir->__d_position < SPECIAL_DOT_FILE_COUNT)
|
|
|
|
{
|
2005-08-20 08:19:55 +02:00
|
|
|
strcpy (de->d_name, special_dot_files[dir->__d_position++]);
|
|
|
|
res = 0;
|
2002-05-04 05:24:35 +02:00
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
retry:
|
|
|
|
if (dir->__d_position & REG_ENUM_VALUES_MASK)
|
|
|
|
/* For the moment, the type of key is ignored here. when write access is added,
|
|
|
|
* maybe add an extension for the type of each value?
|
|
|
|
*/
|
2003-09-08 06:04:19 +02:00
|
|
|
error = RegEnumValue ((HKEY) dir->__handle,
|
2002-05-28 03:55:40 +02:00
|
|
|
(dir->__d_position & ~REG_ENUM_VALUES_MASK) >> 16,
|
|
|
|
buf, &buf_size, NULL, NULL, NULL, NULL);
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
|
|
|
error =
|
2003-09-08 06:04:19 +02:00
|
|
|
RegEnumKeyEx ((HKEY) dir->__handle, dir->__d_position -
|
2002-07-02 03:36:15 +02:00
|
|
|
SPECIAL_DOT_FILE_COUNT, buf, &buf_size, NULL, NULL, NULL,
|
|
|
|
NULL);
|
2002-05-02 06:26:05 +02:00
|
|
|
if (error == ERROR_NO_MORE_ITEMS
|
|
|
|
&& (dir->__d_position & REG_ENUM_VALUES_MASK) == 0)
|
|
|
|
{
|
|
|
|
/* If we're finished with sub-keys, start on values under this key. */
|
|
|
|
dir->__d_position |= REG_ENUM_VALUES_MASK;
|
2003-11-15 00:40:06 +01:00
|
|
|
buf_size = CYG_MAX_PATH;
|
2002-05-02 06:26:05 +02:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
if (error != ERROR_SUCCESS && error != ERROR_MORE_DATA)
|
|
|
|
{
|
2003-09-08 06:04:19 +02:00
|
|
|
RegCloseKey ((HKEY) dir->__handle);
|
|
|
|
dir->__handle = INVALID_HANDLE_VALUE;
|
2003-08-05 05:04:28 +02:00
|
|
|
if (error != ERROR_NO_MORE_ITEMS)
|
|
|
|
seterrno_from_win_error (__FILE__, __LINE__, error);
|
2002-05-02 06:26:05 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We get here if `buf' contains valid data. */
|
|
|
|
if (*buf == 0)
|
2005-08-20 08:19:55 +02:00
|
|
|
strcpy (de->d_name, DEFAULT_VALUE_NAME);
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2005-08-20 08:19:55 +02:00
|
|
|
strcpy (de->d_name, buf);
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
dir->__d_position++;
|
|
|
|
if (dir->__d_position & REG_ENUM_VALUES_MASK)
|
|
|
|
dir->__d_position += 0x10000;
|
2005-08-20 08:19:55 +02:00
|
|
|
res = 0;
|
2002-05-02 06:26:05 +02:00
|
|
|
out:
|
2005-08-20 08:19:55 +02:00
|
|
|
syscall_printf ("%d = readdir (%p, %p)", res, dir, de);
|
2002-05-02 06:26:05 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
_off64_t
|
2002-05-02 06:26:05 +02:00
|
|
|
fhandler_registry::telldir (DIR * dir)
|
|
|
|
{
|
2002-05-04 05:24:35 +02:00
|
|
|
return dir->__d_position & REG_POSITION_MASK;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-04-01 18:11:41 +02:00
|
|
|
fhandler_registry::seekdir (DIR * dir, _off64_t loc)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
/* Unfortunately cannot simply set __d_position due to transition from sub-keys to
|
|
|
|
* values.
|
|
|
|
*/
|
|
|
|
rewinddir (dir);
|
2002-05-04 05:24:35 +02:00
|
|
|
while (loc > (dir->__d_position & REG_POSITION_MASK))
|
2005-08-20 08:19:55 +02:00
|
|
|
if (!readdir (dir, dir->__d_dirent))
|
2002-05-02 06:26:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_registry::rewinddir (DIR * dir)
|
|
|
|
{
|
2003-09-08 06:04:19 +02:00
|
|
|
if (dir->__handle != INVALID_HANDLE_VALUE)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2005-07-06 22:05:03 +02:00
|
|
|
RegCloseKey ((HKEY) dir->__handle);
|
2003-09-08 06:04:19 +02:00
|
|
|
dir->__handle = INVALID_HANDLE_VALUE;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
dir->__d_position = 0;
|
2005-03-16 22:20:56 +01:00
|
|
|
dir->__flags = dirent_saw_dot | dirent_saw_dot_dot;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_registry::closedir (DIR * dir)
|
|
|
|
{
|
|
|
|
int res = 0;
|
2003-09-08 06:04:19 +02:00
|
|
|
if (dir->__handle != INVALID_HANDLE_VALUE &&
|
|
|
|
RegCloseKey ((HKEY) dir->__handle) != ERROR_SUCCESS)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
syscall_printf ("%d = closedir (%p)", res, dir);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_registry::open (int flags, mode_t mode)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
int pathlen;
|
|
|
|
const char *file;
|
2002-07-02 03:36:15 +02:00
|
|
|
HKEY handle;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
int res = fhandler_virtual::open (flags, mode);
|
2002-05-02 06:26:05 +02:00
|
|
|
if (!res)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
const char *path;
|
2006-10-19 12:01:03 +02:00
|
|
|
path = get_name () + proc_len + 1 + prefix_len;
|
2002-05-02 06:26:05 +02:00
|
|
|
if (!*path)
|
|
|
|
{
|
2002-05-04 05:24:35 +02:00
|
|
|
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EEXIST);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-04 05:24:35 +02:00
|
|
|
else if (flags & O_WRONLY)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
flags |= O_DIROPEN;
|
|
|
|
goto success;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
path++;
|
|
|
|
pathlen = strlen (path);
|
|
|
|
file = path + pathlen - 1;
|
2003-01-09 09:22:05 +01:00
|
|
|
if (isdirsep (*file) && pathlen > 1)
|
2002-05-02 06:26:05 +02:00
|
|
|
file--;
|
2003-01-09 09:22:05 +01:00
|
|
|
while (!isdirsep (*file))
|
2002-05-02 06:26:05 +02:00
|
|
|
file--;
|
|
|
|
file++;
|
|
|
|
|
|
|
|
if (file == path)
|
|
|
|
{
|
|
|
|
for (int i = 0; registry_listing[i]; i++)
|
2002-05-28 03:55:40 +02:00
|
|
|
if (path_prefix_p
|
|
|
|
(registry_listing[i], path, strlen (registry_listing[i])))
|
|
|
|
{
|
|
|
|
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
|
|
|
{
|
|
|
|
set_errno (EEXIST);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else if (flags & O_WRONLY)
|
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-22 11:38:47 +02:00
|
|
|
set_io_handle (registry_keys[i]);
|
2002-05-28 03:55:40 +02:00
|
|
|
flags |= O_DIROPEN;
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2002-05-04 05:24:35 +02:00
|
|
|
if (flags & O_CREAT)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
2002-05-04 05:24:35 +02:00
|
|
|
if (flags & O_WRONLY)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2002-05-04 05:24:35 +02:00
|
|
|
set_errno (EROFS);
|
2002-05-02 06:26:05 +02:00
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-04 05:24:35 +02:00
|
|
|
|
2006-10-19 12:01:03 +02:00
|
|
|
handle = open_key (path, KEY_READ, wow64, false);
|
2002-07-02 03:36:15 +02:00
|
|
|
if (handle == (HKEY) INVALID_HANDLE_VALUE)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2006-10-19 12:01:03 +02:00
|
|
|
handle = open_key (path, KEY_READ, wow64, true);
|
2005-08-08 17:33:32 +02:00
|
|
|
if (handle == (HKEY) INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2005-08-08 17:33:32 +02:00
|
|
|
else
|
|
|
|
flags |= O_DIROPEN;
|
2002-07-02 03:36:15 +02:00
|
|
|
|
|
|
|
set_io_handle (handle);
|
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
if (pathmatch (file, DEFAULT_VALUE_NAME))
|
2002-07-02 03:36:15 +02:00
|
|
|
value_name = cstrdup ("");
|
|
|
|
else
|
|
|
|
value_name = cstrdup (file);
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2005-08-08 17:33:32 +02:00
|
|
|
if (!(flags & O_DIROPEN) && !fill_filebuf ())
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
RegCloseKey (handle);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
|
|
|
position = filesize;
|
|
|
|
else
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
success:
|
|
|
|
res = 1;
|
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
|
|
|
set_open_status ();
|
|
|
|
out:
|
|
|
|
syscall_printf ("%d = fhandler_registry::open (%p, %d)", res, flags, mode);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_registry::close ()
|
|
|
|
{
|
|
|
|
int res = fhandler_virtual::close ();
|
|
|
|
if (res != 0)
|
|
|
|
return res;
|
|
|
|
HKEY handle = (HKEY) get_handle ();
|
|
|
|
if (handle != (HKEY) INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if (RegCloseKey (handle) != ERROR_SUCCESS)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
__seterrno ();
|
2002-05-28 03:55:40 +02:00
|
|
|
res = -1;
|
2002-07-02 03:36:15 +02:00
|
|
|
}
|
|
|
|
}
|
2005-07-05 05:16:46 +02:00
|
|
|
if (!hExeced && value_name)
|
2005-08-24 06:38:39 +02:00
|
|
|
{
|
|
|
|
cfree (value_name);
|
|
|
|
value_name = NULL;
|
|
|
|
}
|
2002-07-26 21:58:00 +02:00
|
|
|
return res;
|
2002-07-02 03:36:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
fhandler_registry::fill_filebuf ()
|
|
|
|
{
|
|
|
|
DWORD type, size;
|
|
|
|
LONG error;
|
|
|
|
HKEY handle = (HKEY) get_handle ();
|
|
|
|
if (handle != HKEY_PERFORMANCE_DATA)
|
|
|
|
{
|
|
|
|
error = RegQueryValueEx (handle, value_name, NULL, &type, NULL, &size);
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (error != ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
seterrno_from_win_error (__FILE__, __LINE__, error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
goto value_not_found;
|
2002-05-28 03:55:40 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
bufalloc = size;
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc);
|
2002-05-02 06:26:05 +02:00
|
|
|
error =
|
2002-07-02 03:36:15 +02:00
|
|
|
RegQueryValueEx (handle, value_name, NULL, NULL, (BYTE *) filebuf,
|
|
|
|
&size);
|
2002-05-02 06:26:05 +02:00
|
|
|
if (error != ERROR_SUCCESS)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
seterrno_from_win_error (__FILE__, __LINE__, error);
|
2002-07-02 03:36:15 +02:00
|
|
|
return true;
|
2002-05-28 03:55:40 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
filesize = size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bufalloc = 0;
|
|
|
|
do
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
bufalloc += 1000;
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc);
|
2004-07-15 04:07:14 +02:00
|
|
|
size = bufalloc;
|
2002-10-30 22:05:18 +01:00
|
|
|
error = RegQueryValueEx (handle, value_name, NULL, &type,
|
|
|
|
(BYTE *) filebuf, &size);
|
2002-07-02 03:36:15 +02:00
|
|
|
if (error != ERROR_SUCCESS && error != ERROR_MORE_DATA)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
if (error != ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
seterrno_from_win_error (__FILE__, __LINE__, error);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
goto value_not_found;
|
2002-05-28 03:55:40 +02:00
|
|
|
}
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
while (error == ERROR_MORE_DATA);
|
|
|
|
filesize = size;
|
|
|
|
}
|
2002-07-02 03:36:15 +02:00
|
|
|
return true;
|
|
|
|
value_not_found:
|
2003-11-15 00:40:06 +01:00
|
|
|
DWORD buf_size = CYG_MAX_PATH;
|
2002-07-02 03:36:15 +02:00
|
|
|
char buf[buf_size];
|
|
|
|
int index = 0;
|
|
|
|
while (ERROR_SUCCESS ==
|
|
|
|
(error = RegEnumKeyEx (handle, index++, buf, &buf_size, NULL, NULL,
|
|
|
|
NULL, NULL)) || (error == ERROR_MORE_DATA))
|
|
|
|
{
|
|
|
|
if (pathmatch (buf, value_name))
|
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
|
|
|
return false;
|
|
|
|
}
|
2003-11-15 00:40:06 +01:00
|
|
|
buf_size = CYG_MAX_PATH;
|
2002-07-02 03:36:15 +02:00
|
|
|
}
|
|
|
|
if (error != ERROR_NO_MORE_ITEMS)
|
|
|
|
{
|
|
|
|
seterrno_from_win_error (__FILE__, __LINE__, error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return false;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
/* Auxillary member function to open registry keys. */
|
2002-07-02 03:36:15 +02:00
|
|
|
static HKEY
|
2006-10-19 12:01:03 +02:00
|
|
|
open_key (const char *name, REGSAM access, DWORD wow64, bool isValue)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
|
|
|
|
HKEY hParentKey = (HKEY) INVALID_HANDLE_VALUE;
|
|
|
|
bool parentOpened = false;
|
2003-11-15 00:40:06 +01:00
|
|
|
char component[CYG_MAX_PATH];
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
while (*name)
|
|
|
|
{
|
|
|
|
const char *anchor = name;
|
2003-01-09 09:22:05 +01:00
|
|
|
while (*name && !isdirsep (*name))
|
2002-05-28 03:55:40 +02:00
|
|
|
name++;
|
2002-05-02 06:26:05 +02:00
|
|
|
strncpy (component, anchor, name - anchor);
|
|
|
|
component[name - anchor] = '\0';
|
|
|
|
if (*name)
|
2002-05-28 03:55:40 +02:00
|
|
|
name++;
|
2002-05-02 06:26:05 +02:00
|
|
|
if (*name == 0 && isValue == true)
|
2002-05-28 03:55:40 +02:00
|
|
|
goto out;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
if (hParentKey != (HKEY) INVALID_HANDLE_VALUE)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
REGSAM effective_access = KEY_READ;
|
|
|
|
if ((strchr (name, '/') == NULL && isValue == true) || *name == 0)
|
|
|
|
effective_access = access;
|
2006-10-21 12:58:35 +02:00
|
|
|
LONG error = RegOpenKeyEx (hParentKey, component, 0,
|
|
|
|
effective_access | wow64, &hKey);
|
|
|
|
if (error == ERROR_ACCESS_DENIED) /* Try opening with backup intent */
|
|
|
|
error = RegCreateKeyEx (hParentKey, component, 0, NULL,
|
|
|
|
REG_OPTION_BACKUP_RESTORE,
|
|
|
|
effective_access | wow64, NULL,
|
|
|
|
&hKey, NULL);
|
2002-07-02 03:36:15 +02:00
|
|
|
if (error != ERROR_SUCCESS)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
hKey = (HKEY) INVALID_HANDLE_VALUE;
|
2002-05-28 03:55:40 +02:00
|
|
|
seterrno_from_win_error (__FILE__, __LINE__, error);
|
|
|
|
return hKey;
|
|
|
|
}
|
|
|
|
if (parentOpened)
|
|
|
|
RegCloseKey (hParentKey);
|
|
|
|
hParentKey = hKey;
|
|
|
|
parentOpened = true;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; registry_listing[i]; i++)
|
|
|
|
if (pathmatch (component, registry_listing[i]))
|
|
|
|
hKey = registry_keys[i];
|
|
|
|
if (hKey == (HKEY) INVALID_HANDLE_VALUE)
|
|
|
|
return hKey;
|
|
|
|
hParentKey = hKey;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
return hKey;
|
|
|
|
}
|