2000-09-08 04:56:55 +02:00
|
|
|
/* shared_info.h: shared info for cygwin
|
2000-09-07 18:23:51 +02:00
|
|
|
|
2006-07-26 17:59:39 +02:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
|
2000-09-07 18:23:51 +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. */
|
|
|
|
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "tty.h"
|
2003-09-10 04:12:26 +02:00
|
|
|
#include "security.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
|
2000-09-07 18:23:51 +02:00
|
|
|
/* Mount table entry */
|
|
|
|
|
|
|
|
class mount_item
|
|
|
|
{
|
2001-05-25 05:13:14 +02:00
|
|
|
public:
|
2000-09-07 18:23:51 +02: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 00:40:06 +01:00
|
|
|
char native_path[CYG_MAX_PATH];
|
2000-09-07 18:23:51 +02:00
|
|
|
int native_pathlen;
|
|
|
|
|
|
|
|
/* POSIX-style mount point ("/foo/bar") */
|
2003-11-15 00:40:06 +01:00
|
|
|
char posix_path[CYG_MAX_PATH];
|
2000-09-07 18:23:51 +02:00
|
|
|
int posix_pathlen;
|
|
|
|
|
|
|
|
unsigned flags;
|
|
|
|
|
|
|
|
void init (const char *dev, const char *path, unsigned flags);
|
|
|
|
|
|
|
|
struct mntent *getmntent ();
|
2004-02-21 05:46:00 +01:00
|
|
|
int fnmunge (char *, const char *, int&);
|
2004-12-18 17:41:27 +01:00
|
|
|
int build_win32 (char *, const char *, unsigned *, unsigned);
|
2000-09-07 18:23:51 +02: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 04:29:05 +02:00
|
|
|
#define USER_VERSION 1 // increment when mount table changes and
|
2003-09-25 06:03:53 +02:00
|
|
|
#define USER_VERSION_MAGIC CYGWIN_VERSION_MAGIC (USER_MAGIC, USER_VERSION)
|
2006-08-01 20:00:44 +02:00
|
|
|
#define CURR_USER_MAGIC 0x38edd704U
|
2001-01-28 06:51:15 +01:00
|
|
|
|
2000-09-08 04:56:55 +02: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 02:37:18 +02:00
|
|
|
struct device;
|
2001-12-26 07:18:41 +01: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-07 18:23:51 +02:00
|
|
|
class mount_info
|
|
|
|
{
|
2001-05-25 05:13:14 +02:00
|
|
|
public:
|
2001-01-28 07:23:42 +01:00
|
|
|
DWORD sys_mount_table_counter;
|
2000-09-07 18:23:51 +02: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 00:40:06 +01:00
|
|
|
char cygdrive[CYG_MAX_PATH];
|
2000-09-07 18:23:51 +02:00
|
|
|
size_t cygdrive_len;
|
|
|
|
unsigned cygdrive_flags;
|
2001-05-25 05:13:14 +02:00
|
|
|
private:
|
2001-01-28 06:51:15 +01:00
|
|
|
int posix_sorted[MAX_MOUNTS];
|
|
|
|
int native_sorted[MAX_MOUNTS];
|
2000-09-07 18:23:51 +02:00
|
|
|
|
2001-05-25 05:13:14 +02:00
|
|
|
public:
|
2000-09-07 18:23:51 +02:00
|
|
|
void init ();
|
|
|
|
int add_item (const char *dev, const char *path, unsigned flags, int reg_p);
|
|
|
|
int del_item (const char *path, unsigned flags, int reg_p);
|
|
|
|
|
|
|
|
void from_registry ();
|
|
|
|
int add_reg_mount (const char * native_path, const char * posix_path,
|
|
|
|
unsigned mountflags);
|
|
|
|
int del_reg_mount (const char * posix_path, unsigned mountflags);
|
|
|
|
|
|
|
|
unsigned set_flags_from_win32_path (const char *path);
|
2004-12-18 17:41:27 +01:00
|
|
|
int conv_to_win32_path (const char *src_path, char *dst, device&,
|
2004-04-10 02:50:16 +02:00
|
|
|
unsigned *flags = NULL);
|
2004-12-18 17:41:27 +01:00
|
|
|
int conv_to_posix_path (const char *src_path, char *posix_path,
|
2000-09-07 18:23:51 +02:00
|
|
|
int keep_rel_p);
|
|
|
|
struct mntent *getmntent (int x);
|
|
|
|
|
|
|
|
int write_cygdrive_info_to_registry (const char *cygdrive_prefix, unsigned flags);
|
|
|
|
int remove_cygdrive_info_from_registry (const char *cygdrive_prefix, unsigned flags);
|
2000-11-08 21:36:37 +01:00
|
|
|
int get_cygdrive_info (char *user, char *system, char* user_flags,
|
2001-09-07 23:32:07 +02:00
|
|
|
char* system_flags);
|
2005-08-26 17:11:06 +02:00
|
|
|
void cygdrive_posix_path (const char *src, char *dst, int trailing_slash_p);
|
2006-03-01 14:47:49 +01:00
|
|
|
int get_mounts_here (const char *parent_dir, int, char **mount_points);
|
2000-09-07 18:23:51 +02:00
|
|
|
|
2001-05-25 05:13:14 +02:00
|
|
|
private:
|
2000-09-07 18:23:51 +02:00
|
|
|
|
|
|
|
void sort ();
|
|
|
|
void read_mounts (reg_key& r);
|
|
|
|
void mount_slash ();
|
|
|
|
void to_registry ();
|
|
|
|
|
2001-11-22 06:59:07 +01:00
|
|
|
int cygdrive_win32_path (const char *src, char *dst, int& unit);
|
2000-09-07 18:23:51 +02:00
|
|
|
void read_cygdrive_info_from_registry ();
|
|
|
|
};
|
|
|
|
|
2000-09-08 04:56:55 +02:00
|
|
|
/******** Close-on-delete queue ********/
|
|
|
|
|
|
|
|
/* First pass at a file deletion queue structure.
|
|
|
|
|
|
|
|
We can't keep this list in the per-process info, since
|
|
|
|
one process may open a file, and outlive a process which
|
|
|
|
wanted to unlink the file - and the data would go away.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_DELQUEUES_PENDING 100
|
|
|
|
|
|
|
|
class delqueue_list
|
|
|
|
{
|
2003-11-15 00:40:06 +01:00
|
|
|
char name[MAX_DELQUEUES_PENDING][CYG_MAX_PATH];
|
2000-09-08 04:56:55 +02:00
|
|
|
char inuse[MAX_DELQUEUES_PENDING];
|
|
|
|
int empty;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void init ();
|
|
|
|
void queue_file (const char *dosname);
|
|
|
|
void process_queue ();
|
|
|
|
};
|
|
|
|
|
2003-09-25 04:29:05 +02:00
|
|
|
class user_info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DWORD version;
|
|
|
|
DWORD cb;
|
|
|
|
delqueue_list delqueue;
|
2006-08-01 20:00:44 +02:00
|
|
|
bool warned_msdos;
|
2003-09-25 04:29:05 +02:00
|
|
|
mount_info mountinfo;
|
|
|
|
};
|
2000-09-07 18:23:51 +02:00
|
|
|
/******** Shared Info ********/
|
|
|
|
/* Data accessible to all tasks */
|
|
|
|
|
2001-12-26 05:53:34 +01: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)
|
|
|
|
|
2006-06-02 17:41:34 +02:00
|
|
|
#define SHARED_INFO_CB 19984
|
2001-12-26 22:35:16 +01:00
|
|
|
|
2003-09-25 06:03:53 +02:00
|
|
|
#define CURR_SHARED_MAGIC 0x818f75beU
|
2001-12-26 05:53:34 +01:00
|
|
|
|
2001-12-26 07:18:41 +01: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-07 18:23:51 +02:00
|
|
|
class shared_info
|
|
|
|
{
|
2001-12-26 22:35:16 +01:00
|
|
|
DWORD version;
|
|
|
|
DWORD cb;
|
2001-05-25 05:13:14 +02:00
|
|
|
public:
|
2002-10-22 18:18:55 +02:00
|
|
|
unsigned heap_chunk;
|
2001-01-28 07:23:42 +01:00
|
|
|
DWORD sys_mount_table_counter;
|
2000-09-07 18:23:51 +02:00
|
|
|
|
|
|
|
tty_list tty;
|
2003-09-10 23:01:40 +02:00
|
|
|
void initialize ();
|
2001-09-09 21:06:50 +02:00
|
|
|
unsigned heap_chunk_size ();
|
2000-09-07 18:23:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern shared_info *cygwin_shared;
|
2005-02-13 19:17:29 +01:00
|
|
|
extern user_info *user_shared;
|
2003-09-25 04:29:05 +02:00
|
|
|
#define mount_table (&(user_shared->mountinfo))
|
|
|
|
extern HANDLE cygwin_user_h;
|
2000-09-07 18:23:51 +02:00
|
|
|
|
2002-10-15 09:03:45 +02:00
|
|
|
enum shared_locations
|
|
|
|
{
|
2003-09-25 04:29:05 +02:00
|
|
|
SH_USER_SHARED,
|
2002-10-15 09:03:45 +02:00
|
|
|
SH_SHARED_CONSOLE,
|
|
|
|
SH_MYSELF,
|
2005-04-29 01:59:44 +02:00
|
|
|
SH_TOTAL_SIZE,
|
|
|
|
SH_JUSTCREATE,
|
|
|
|
SH_JUSTOPEN
|
|
|
|
|
2002-10-15 09:03:45 +02:00
|
|
|
};
|
2002-10-14 22:25:52 +02:00
|
|
|
void __stdcall memory_init ();
|
2000-09-07 18:23:51 +02:00
|
|
|
|
2001-01-28 06:51:15 +01:00
|
|
|
#define shared_align_past(p) \
|
|
|
|
((char *) (system_info.dwAllocationGranularity * \
|
|
|
|
(((DWORD) ((p) + 1) + system_info.dwAllocationGranularity - 1) / \
|
|
|
|
system_info.dwAllocationGranularity)))
|
|
|
|
|
2004-04-09 10:43:29 +02:00
|
|
|
#ifdef _FHANDLER_H_
|
2002-10-15 09:03:45 +02:00
|
|
|
struct console_state
|
|
|
|
{
|
|
|
|
tty_min tty_min_state;
|
|
|
|
dev_console dev_state;
|
|
|
|
};
|
|
|
|
#endif
|
2001-01-28 06:51:15 +01:00
|
|
|
|
2003-05-21 10:01:57 +02:00
|
|
|
char *__stdcall shared_name (char *, const char *, int);
|
2005-02-13 19:17:29 +01:00
|
|
|
void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size,
|
2005-04-29 01:59:44 +02:00
|
|
|
shared_locations&, PSECURITY_ATTRIBUTES psa = &sec_all,
|
|
|
|
DWORD access = FILE_MAP_READ | FILE_MAP_WRITE);
|
2003-09-25 04:29:05 +02:00
|
|
|
extern void user_shared_initialize (bool reinit);
|