2000-09-08 10:56:55 +08:00
|
|
|
/* shared_info.h: shared info for cygwin
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2008-04-01 21:22:47 +08:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 Red Hat, Inc.
|
2000-09-08 00:23:51 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "tty.h"
|
2003-09-10 10:12:26 +08:00
|
|
|
#include "security.h"
|
2008-04-19 04:13:37 +08:00
|
|
|
#include "mtinfo.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
|
2000-09-08 00:23:51 +08:00
|
|
|
/* Mount table entry */
|
|
|
|
|
|
|
|
class mount_item
|
|
|
|
{
|
2001-05-25 11:13:14 +08:00
|
|
|
public:
|
2000-09-08 00:23:51 +08:00
|
|
|
/* FIXME: Nasty static allocation. Need to have a heap in the shared
|
|
|
|
area [with the user being able to configure at runtime the max size]. */
|
|
|
|
/* Win32-style mounted partition source ("C:\foo\bar").
|
|
|
|
native_path[0] == 0 for unused entries. */
|
2003-11-15 07:40:06 +08:00
|
|
|
char native_path[CYG_MAX_PATH];
|
2000-09-08 00:23:51 +08:00
|
|
|
int native_pathlen;
|
|
|
|
|
|
|
|
/* POSIX-style mount point ("/foo/bar") */
|
2003-11-15 07:40:06 +08:00
|
|
|
char posix_path[CYG_MAX_PATH];
|
2000-09-08 00:23:51 +08:00
|
|
|
int posix_pathlen;
|
|
|
|
|
|
|
|
unsigned flags;
|
|
|
|
|
|
|
|
void init (const char *dev, const char *path, unsigned flags);
|
|
|
|
|
|
|
|
struct mntent *getmntent ();
|
2004-12-19 00:41:27 +08:00
|
|
|
int build_win32 (char *, const char *, unsigned *, unsigned);
|
2000-09-08 00:23:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Warning: Decreasing this value will cause cygwin.dll to ignore existing
|
|
|
|
higher numbered registry entries. Don't change this number willy-nilly.
|
|
|
|
What we need is to have a more dynamic allocation scheme, but the current
|
|
|
|
scheme should be satisfactory for a long while yet. */
|
|
|
|
#define MAX_MOUNTS 30
|
|
|
|
|
2003-09-25 10:29:05 +08:00
|
|
|
#define USER_VERSION 1 // increment when mount table changes and
|
2003-09-25 12:03:53 +08:00
|
|
|
#define USER_VERSION_MAGIC CYGWIN_VERSION_MAGIC (USER_MAGIC, USER_VERSION)
|
2007-08-14 01:16:05 +08:00
|
|
|
#define CURR_USER_MAGIC 0xb2232e71U
|
2001-01-28 13:51:15 +08:00
|
|
|
|
2000-09-08 10:56:55 +08:00
|
|
|
class reg_key;
|
* 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
|
|
|
struct device;
|
2001-12-26 14:18:41 +08:00
|
|
|
|
|
|
|
/* NOTE: Do not make gratuitous changes to the names or organization of the
|
|
|
|
below class. The layout is checksummed to determine compatibility between
|
|
|
|
different cygwin versions. */
|
2000-09-08 00:23:51 +08:00
|
|
|
class mount_info
|
|
|
|
{
|
2001-05-25 11:13:14 +08:00
|
|
|
public:
|
2001-01-28 14:23:42 +08:00
|
|
|
DWORD sys_mount_table_counter;
|
2000-09-08 00:23:51 +08:00
|
|
|
int nmounts;
|
|
|
|
mount_item mount[MAX_MOUNTS];
|
|
|
|
|
|
|
|
/* cygdrive_prefix is used as the root of the path automatically
|
|
|
|
prepended to a path when the path has no associated mount.
|
|
|
|
cygdrive_flags are the default flags for the cygdrives. */
|
2003-11-15 07:40:06 +08:00
|
|
|
char cygdrive[CYG_MAX_PATH];
|
2000-09-08 00:23:51 +08:00
|
|
|
size_t cygdrive_len;
|
|
|
|
unsigned cygdrive_flags;
|
2001-05-25 11:13:14 +08:00
|
|
|
private:
|
2001-01-28 13:51:15 +08:00
|
|
|
int posix_sorted[MAX_MOUNTS];
|
|
|
|
int native_sorted[MAX_MOUNTS];
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2001-05-25 11:13:14 +08:00
|
|
|
public:
|
2000-09-08 00:23:51 +08:00
|
|
|
void init ();
|
2008-04-05 17:30:06 +08:00
|
|
|
int add_item (const char *dev, const char *path, unsigned flags);
|
|
|
|
int del_item (const char *path, unsigned flags);
|
2000-09-08 00:23:51 +08:00
|
|
|
|
|
|
|
unsigned set_flags_from_win32_path (const char *path);
|
2004-12-19 00:41:27 +08:00
|
|
|
int conv_to_win32_path (const char *src_path, char *dst, device&,
|
2004-04-10 08:50:16 +08:00
|
|
|
unsigned *flags = NULL);
|
2007-10-24 00:26:28 +08:00
|
|
|
int conv_to_posix_path (PWCHAR src_path, char *posix_path,
|
|
|
|
int keep_rel_p);
|
2004-12-19 00:41:27 +08:00
|
|
|
int conv_to_posix_path (const char *src_path, char *posix_path,
|
2000-09-08 00:23:51 +08:00
|
|
|
int keep_rel_p);
|
|
|
|
struct mntent *getmntent (int x);
|
|
|
|
|
2008-04-05 17:30:06 +08:00
|
|
|
int write_cygdrive_info (const char *cygdrive_prefix, unsigned flags);
|
2000-11-09 04:36:37 +08:00
|
|
|
int get_cygdrive_info (char *user, char *system, char* user_flags,
|
2001-09-08 05:32:07 +08:00
|
|
|
char* system_flags);
|
2005-08-26 23:11:06 +08:00
|
|
|
void cygdrive_posix_path (const char *src, char *dst, int trailing_slash_p);
|
2007-07-27 01:30:54 +08:00
|
|
|
int get_mounts_here (const char *parent_dir, int,
|
|
|
|
PUNICODE_STRING mount_points,
|
|
|
|
PUNICODE_STRING cygd);
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2001-05-25 11:13:14 +08:00
|
|
|
private:
|
2000-09-08 00:23:51 +08:00
|
|
|
void sort ();
|
|
|
|
void mount_slash ();
|
2008-05-24 00:38:51 +08:00
|
|
|
void mount_info::create_root_entry (const PWCHAR root);
|
|
|
|
|
|
|
|
bool from_fstab_line (char *line, bool user);
|
|
|
|
bool from_fstab (bool user, WCHAR [], PWCHAR);
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2001-11-22 13:59:07 +08:00
|
|
|
int cygdrive_win32_path (const char *src, char *dst, int& unit);
|
2000-09-08 00:23:51 +08:00
|
|
|
};
|
|
|
|
|
2003-09-25 10:29:05 +08:00
|
|
|
class user_info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DWORD version;
|
|
|
|
DWORD cb;
|
2006-08-02 02:00:44 +08:00
|
|
|
bool warned_msdos;
|
2003-09-25 10:29:05 +08:00
|
|
|
mount_info mountinfo;
|
|
|
|
};
|
2000-09-08 00:23:51 +08:00
|
|
|
/******** Shared Info ********/
|
|
|
|
/* Data accessible to all tasks */
|
|
|
|
|
2001-12-26 12:53:34 +08:00
|
|
|
#define SHARED_VERSION (unsigned)(cygwin_version.api_major << 8 | \
|
|
|
|
cygwin_version.api_minor)
|
|
|
|
#define SHARED_VERSION_MAGIC CYGWIN_VERSION_MAGIC (SHARED_MAGIC, SHARED_VERSION)
|
|
|
|
|
2008-07-15 19:42:45 +08:00
|
|
|
#define SHARED_INFO_CB 31136
|
2001-12-27 05:35:16 +08:00
|
|
|
|
2008-07-17 04:20:45 +08:00
|
|
|
#define CURR_SHARED_MAGIC 0x18da899eU
|
2001-12-26 12:53:34 +08:00
|
|
|
|
2001-12-26 14:18:41 +08:00
|
|
|
/* NOTE: Do not make gratuitous changes to the names or organization of the
|
|
|
|
below class. The layout is checksummed to determine compatibility between
|
|
|
|
different cygwin versions. */
|
2000-09-08 00:23:51 +08:00
|
|
|
class shared_info
|
|
|
|
{
|
2001-12-27 05:35:16 +08:00
|
|
|
DWORD version;
|
|
|
|
DWORD cb;
|
2001-05-25 11:13:14 +08:00
|
|
|
public:
|
2002-10-23 00:18:55 +08:00
|
|
|
unsigned heap_chunk;
|
2007-06-28 01:08:19 +08:00
|
|
|
bool heap_slop_inited;
|
2006-11-01 02:41:16 +08:00
|
|
|
unsigned heap_slop;
|
2001-01-28 14:23:42 +08:00
|
|
|
DWORD sys_mount_table_counter;
|
2000-09-08 00:23:51 +08:00
|
|
|
tty_list tty;
|
2008-04-19 04:13:37 +08:00
|
|
|
LONG last_used_bindresvport;
|
2008-07-17 04:20:45 +08:00
|
|
|
DWORD obcaseinsensitive;
|
2008-04-19 04:13:37 +08:00
|
|
|
mtinfo mt;
|
|
|
|
|
2003-09-11 05:01:40 +08:00
|
|
|
void initialize ();
|
2008-07-17 04:20:45 +08:00
|
|
|
void init_obcaseinsensitive ();
|
2001-09-10 03:06:50 +08:00
|
|
|
unsigned heap_chunk_size ();
|
2006-11-01 02:41:16 +08:00
|
|
|
unsigned heap_slop_size ();
|
2000-09-08 00:23:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern shared_info *cygwin_shared;
|
2005-02-14 02:17:29 +08:00
|
|
|
extern user_info *user_shared;
|
2003-09-25 10:29:05 +08:00
|
|
|
#define mount_table (&(user_shared->mountinfo))
|
|
|
|
extern HANDLE cygwin_user_h;
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2002-10-15 15:03:45 +08:00
|
|
|
enum shared_locations
|
|
|
|
{
|
2008-04-19 04:13:37 +08:00
|
|
|
SH_CYGWIN_SHARED,
|
2003-09-25 10:29:05 +08:00
|
|
|
SH_USER_SHARED,
|
2002-10-15 15:03:45 +08:00
|
|
|
SH_SHARED_CONSOLE,
|
|
|
|
SH_MYSELF,
|
2005-04-29 07:59:44 +08:00
|
|
|
SH_TOTAL_SIZE,
|
|
|
|
SH_JUSTCREATE,
|
|
|
|
SH_JUSTOPEN
|
|
|
|
|
2002-10-15 15:03:45 +08:00
|
|
|
};
|
2002-10-15 04:25:52 +08:00
|
|
|
void __stdcall memory_init ();
|
2000-09-08 00:23:51 +08:00
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
#define shared_align_past(p) \
|
|
|
|
((char *) (system_info.dwAllocationGranularity * \
|
|
|
|
(((DWORD) ((p) + 1) + system_info.dwAllocationGranularity - 1) / \
|
|
|
|
system_info.dwAllocationGranularity)))
|
|
|
|
|
2004-04-09 16:43:29 +08:00
|
|
|
#ifdef _FHANDLER_H_
|
2002-10-15 15:03:45 +08:00
|
|
|
struct console_state
|
|
|
|
{
|
|
|
|
tty_min tty_min_state;
|
|
|
|
dev_console dev_state;
|
|
|
|
};
|
|
|
|
#endif
|
2001-01-28 13:51:15 +08:00
|
|
|
|
2008-04-19 04:13:37 +08:00
|
|
|
HANDLE get_shared_parent_dir ();
|
2008-04-21 20:46:58 +08:00
|
|
|
HANDLE get_session_parent_dir ();
|
2008-04-19 04:13:37 +08:00
|
|
|
char *__stdcall shared_name (char *, const char *, int);
|
2005-02-14 02:17:29 +08:00
|
|
|
void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size,
|
2005-04-29 07:59:44 +08:00
|
|
|
shared_locations&, PSECURITY_ATTRIBUTES psa = &sec_all,
|
|
|
|
DWORD access = FILE_MAP_READ | FILE_MAP_WRITE);
|
2003-09-25 10:29:05 +08:00
|
|
|
extern void user_shared_initialize (bool reinit);
|