2002-05-02 06:26:05 +02:00
|
|
|
/* fhandler_proc.cc: fhandler for /proc virtual filesystem
|
|
|
|
|
2006-01-12 16:53:51 +01:00
|
|
|
Copyright 2002, 2003, 2004, 2005, 2006 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. */
|
|
|
|
|
2003-03-09 21:10:25 +01:00
|
|
|
#define _WIN32_WINNT 0x0501
|
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
#include "winsup.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/cygwin.h>
|
2002-05-12 03:37:48 +02:00
|
|
|
#include <ntdef.h>
|
2002-05-02 06:26:05 +02:00
|
|
|
#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-02 06:26:05 +02:00
|
|
|
#include "pinfo.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>
|
|
|
|
#include <sys/utsname.h>
|
2002-08-31 18:37:51 +02:00
|
|
|
#include <sys/param.h>
|
2002-05-12 03:37:48 +02:00
|
|
|
#include "ntdll.h"
|
2006-03-09 10:01:08 +01:00
|
|
|
#include <ctype.h>
|
2003-03-09 21:10:25 +01:00
|
|
|
#include <winioctl.h>
|
2006-03-09 10:01:08 +01:00
|
|
|
#include <wchar.h>
|
2003-04-16 05:03:45 +02:00
|
|
|
#include "cpuid.h"
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
#define _COMPILING_NEWLIB
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
/* offsets in proc_listing */
|
2002-05-12 03:37:48 +02:00
|
|
|
static const int PROC_LOADAVG = 2; // /proc/loadavg
|
|
|
|
static const int PROC_MEMINFO = 3; // /proc/meminfo
|
|
|
|
static const int PROC_REGISTRY = 4; // /proc/registry
|
|
|
|
static const int PROC_STAT = 5; // /proc/stat
|
|
|
|
static const int PROC_VERSION = 6; // /proc/version
|
|
|
|
static const int PROC_UPTIME = 7; // /proc/uptime
|
2003-03-09 21:10:25 +01:00
|
|
|
static const int PROC_CPUINFO = 8; // /proc/cpuinfo
|
|
|
|
static const int PROC_PARTITIONS = 9; // /proc/partitions
|
2005-01-29 12:23:07 +01:00
|
|
|
static const int PROC_SELF = 10; // /proc/self
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
/* names of objects in /proc */
|
|
|
|
static const char *proc_listing[] = {
|
2002-05-04 05:24:35 +02:00
|
|
|
".",
|
|
|
|
"..",
|
2002-05-12 03:37:48 +02:00
|
|
|
"loadavg",
|
|
|
|
"meminfo",
|
2002-05-02 06:26:05 +02:00
|
|
|
"registry",
|
2002-05-12 03:37:48 +02:00
|
|
|
"stat",
|
2002-05-02 06:26:05 +02:00
|
|
|
"version",
|
|
|
|
"uptime",
|
2003-03-09 21:10:25 +01:00
|
|
|
"cpuinfo",
|
|
|
|
"partitions",
|
2004-12-18 17:37:44 +01:00
|
|
|
"self",
|
2002-05-02 06:26:05 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-09-22 05:38:57 +02:00
|
|
|
static const int PROC_LINK_COUNT = (sizeof (proc_listing) / sizeof (const char *)) - 1;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
/* FH_PROC in the table below means the file/directory is handles by
|
|
|
|
* fhandler_proc.
|
|
|
|
*/
|
2002-05-12 03:37:48 +02:00
|
|
|
static const DWORD proc_fhandlers[PROC_LINK_COUNT] = {
|
|
|
|
FH_PROC,
|
|
|
|
FH_PROC,
|
2002-05-04 05:24:35 +02:00
|
|
|
FH_PROC,
|
|
|
|
FH_PROC,
|
2002-05-02 06:26:05 +02:00
|
|
|
FH_REGISTRY,
|
|
|
|
FH_PROC,
|
2002-05-12 03:37:48 +02:00
|
|
|
FH_PROC,
|
2003-03-09 21:10:25 +01:00
|
|
|
FH_PROC,
|
|
|
|
FH_PROC,
|
|
|
|
FH_PROC,
|
2005-01-29 12:23:07 +01:00
|
|
|
FH_PROC,
|
2002-05-02 06:26:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* name of the /proc filesystem */
|
|
|
|
const char proc[] = "/proc";
|
|
|
|
const int proc_len = sizeof (proc) - 1;
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t format_proc_meminfo (char *destbuf, size_t maxsize);
|
|
|
|
static _off64_t format_proc_stat (char *destbuf, size_t maxsize);
|
|
|
|
static _off64_t format_proc_uptime (char *destbuf, size_t maxsize);
|
|
|
|
static _off64_t format_proc_cpuinfo (char *destbuf, size_t maxsize);
|
|
|
|
static _off64_t format_proc_partitions (char *destbuf, size_t maxsize);
|
2002-05-12 03:37:48 +02:00
|
|
|
|
2003-03-09 21:10:25 +01:00
|
|
|
/* Auxillary function that returns the fhandler associated with the given path
|
|
|
|
this is where it would be nice to have pattern matching in C - polymorphism
|
|
|
|
just doesn't cut it. */
|
2002-05-02 06:26:05 +02:00
|
|
|
DWORD
|
|
|
|
fhandler_proc::get_proc_fhandler (const char *path)
|
|
|
|
{
|
|
|
|
debug_printf ("get_proc_fhandler(%s)", path);
|
|
|
|
path += proc_len;
|
|
|
|
/* Since this method is called from path_conv::check we can't rely on
|
2003-03-09 21:10:25 +01:00
|
|
|
it being normalised and therefore the path may have runs of slashes
|
|
|
|
in it. */
|
2003-01-09 09:22:05 +01:00
|
|
|
while (isdirsep (*path))
|
2002-05-02 06:26:05 +02:00
|
|
|
path++;
|
|
|
|
|
|
|
|
/* Check if this is the root of the virtual filesystem (i.e. /proc). */
|
|
|
|
if (*path == 0)
|
|
|
|
return FH_PROC;
|
|
|
|
|
|
|
|
for (int i = 0; proc_listing[i]; i++)
|
|
|
|
{
|
|
|
|
if (path_prefix_p (proc_listing[i], path, strlen (proc_listing[i])))
|
2002-05-28 03:55:40 +02:00
|
|
|
return proc_fhandlers[i];
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
2002-06-02 08:07:01 +02:00
|
|
|
if (pinfo (atoi (path)))
|
|
|
|
return FH_PROCESS;
|
2002-05-04 05:24:35 +02:00
|
|
|
|
2002-06-02 08:07:01 +02:00
|
|
|
bool has_subdir = false;
|
|
|
|
while (*path)
|
2003-01-09 09:22:05 +01:00
|
|
|
if (isdirsep (*path++))
|
2002-06-02 08:07:01 +02:00
|
|
|
{
|
|
|
|
has_subdir = true;
|
|
|
|
break;
|
|
|
|
}
|
2002-05-04 05:24:35 +02:00
|
|
|
|
2002-06-02 08:07:01 +02:00
|
|
|
if (has_subdir)
|
|
|
|
/* The user is trying to access a non-existent subdirectory of /proc. */
|
|
|
|
return FH_BAD;
|
|
|
|
else
|
|
|
|
/* Return FH_PROC so that we can return EROFS if the user is trying to create
|
|
|
|
a file. */
|
|
|
|
return FH_PROC;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 if path doesn't exist, >0 if path is a directory,
|
2005-02-01 16:11:47 +01:00
|
|
|
-1 if path is a file, -2 if it's a symlink. */
|
2002-05-02 06:26:05 +02:00
|
|
|
int
|
2002-05-23 00:09:58 +02:00
|
|
|
fhandler_proc::exists ()
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
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);
|
|
|
|
path += proc_len;
|
|
|
|
if (*path == 0)
|
|
|
|
return 2;
|
|
|
|
for (int i = 0; proc_listing[i]; i++)
|
|
|
|
if (pathmatch (path + 1, proc_listing[i]))
|
2005-01-29 12:23:07 +01:00
|
|
|
{
|
|
|
|
fileid = i;
|
2005-02-01 16:11:47 +01:00
|
|
|
return (proc_fhandlers[i] == FH_PROC) ? (i == PROC_SELF ? -2 : -1) : 1;
|
2005-01-29 12:23:07 +01:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fhandler_proc::fhandler_proc ():
|
* 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_virtual ()
|
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_proc::fstat (struct __stat64 *buf)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
const char *path = get_name ();
|
2002-06-02 05:13:22 +02:00
|
|
|
debug_printf ("fstat (%s)", path);
|
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
path += proc_len;
|
2005-07-06 22:05:03 +02:00
|
|
|
fhandler_base::fstat (buf);
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
buf->st_mode &= ~_IFMT & NO_W;
|
|
|
|
|
|
|
|
if (!*path)
|
|
|
|
{
|
2006-03-01 23:56:12 +01:00
|
|
|
buf->st_nlink = 1;
|
2002-05-02 06:26:05 +02:00
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path++;
|
|
|
|
for (int i = 0; proc_listing[i]; i++)
|
2002-05-28 03:55:40 +02:00
|
|
|
if (pathmatch (path, proc_listing[i]))
|
|
|
|
{
|
2002-05-02 06:26:05 +02:00
|
|
|
if (proc_fhandlers[i] != FH_PROC)
|
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
2005-01-29 12:23:07 +01:00
|
|
|
else if (i == PROC_SELF)
|
|
|
|
buf->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
buf->st_mode &= NO_X;
|
|
|
|
buf->st_mode |= S_IFREG;
|
|
|
|
}
|
2002-05-28 03:55:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-08-20 08:19:55 +02:00
|
|
|
int
|
|
|
|
fhandler_proc::readdir (DIR *dir, dirent *de)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2005-08-20 08:19:55 +02:00
|
|
|
int res;
|
|
|
|
if (dir->__d_position < PROC_LINK_COUNT)
|
|
|
|
{
|
|
|
|
strcpy (de->d_name, proc_listing[dir->__d_position++]);
|
2006-01-27 22:50:42 +01:00
|
|
|
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
|
2005-08-20 08:19:55 +02:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2005-05-19 03:25:20 +02:00
|
|
|
winpids pids ((DWORD) 0);
|
2002-05-02 06:26:05 +02:00
|
|
|
int found = 0;
|
2005-08-20 08:19:55 +02:00
|
|
|
res = ENMFILE;
|
2002-05-02 06:26:05 +02:00
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
2002-06-02 08:07:01 +02:00
|
|
|
if (found++ == dir->__d_position - PROC_LINK_COUNT)
|
|
|
|
{
|
2005-08-20 08:19:55 +02:00
|
|
|
__small_sprintf (de->d_name, "%d", pids[i]->pid);
|
2002-06-02 08:07:01 +02:00
|
|
|
dir->__d_position++;
|
2005-08-20 08:19:55 +02:00
|
|
|
res = 0;
|
|
|
|
break;
|
2002-06-02 08:07:01 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
2005-08-20 08:19:55 +02:00
|
|
|
syscall_printf ("%d = readdir (%p, %p) (%s)", res, dir, de, de->d_name);
|
|
|
|
return res;
|
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_proc::open (int flags, mode_t mode)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
int proc_file_no = -1;
|
|
|
|
|
* 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;
|
|
|
|
|
2004-04-10 15:45:10 +02:00
|
|
|
nohandle (true);
|
2002-07-02 03:36:15 +02:00
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
const char *path;
|
|
|
|
|
2002-05-03 04:43:45 +02:00
|
|
|
path = get_name () + proc_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
|
|
|
}
|
|
|
|
|
|
|
|
proc_file_no = -1;
|
|
|
|
for (int i = 0; proc_listing[i]; i++)
|
|
|
|
if (path_prefix_p (proc_listing[i], path + 1, strlen (proc_listing[i])))
|
|
|
|
{
|
2002-05-28 03:55:40 +02:00
|
|
|
proc_file_no = i;
|
|
|
|
if (proc_fhandlers[i] != FH_PROC)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
flags |= O_DIROPEN;
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proc_file_no == -1)
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
|
|
|
|
fileid = proc_file_no;
|
2002-07-02 03:36:15 +02:00
|
|
|
if (!fill_filebuf ())
|
|
|
|
{
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
|
|
|
position = filesize;
|
|
|
|
else
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
success:
|
|
|
|
res = 1;
|
2002-07-01 21:03:26 +02:00
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
2002-05-12 03:37:48 +02:00
|
|
|
set_open_status ();
|
|
|
|
out:
|
|
|
|
syscall_printf ("%d = fhandler_proc::open (%p, %d)", res, flags, mode);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
bool
|
2002-05-12 03:37:48 +02:00
|
|
|
fhandler_proc::fill_filebuf ()
|
|
|
|
{
|
|
|
|
switch (fileid)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
case PROC_VERSION:
|
|
|
|
{
|
2002-05-28 03:55:40 +02:00
|
|
|
if (!filebuf)
|
|
|
|
{
|
2002-06-02 18:42:02 +02:00
|
|
|
struct utsname uts_name;
|
|
|
|
uname (&uts_name);
|
|
|
|
bufalloc = strlen (uts_name.sysname) + 1 + strlen (uts_name.release) +
|
|
|
|
1 + strlen (uts_name.version) + 2;
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc);
|
2002-06-02 18:42:02 +02:00
|
|
|
filesize = __small_sprintf (filebuf, "%s %s %s\n", uts_name.sysname,
|
|
|
|
uts_name.release, uts_name.version);
|
2002-05-28 03:55:40 +02:00
|
|
|
}
|
|
|
|
break;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
case PROC_UPTIME:
|
|
|
|
{
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc = 80);
|
2002-05-28 03:55:40 +02:00
|
|
|
filesize = format_proc_uptime (filebuf, bufalloc);
|
|
|
|
break;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
case PROC_STAT:
|
|
|
|
{
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc = 16384);
|
2002-05-28 03:55:40 +02:00
|
|
|
filesize = format_proc_stat (filebuf, bufalloc);
|
|
|
|
break;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
case PROC_LOADAVG:
|
|
|
|
{
|
2002-05-28 03:55:40 +02:00
|
|
|
/*
|
|
|
|
* not really supported - Windows doesn't keep track of these values
|
|
|
|
* Windows 95/98/me does have the KERNEL/CPUUsage performance counter
|
|
|
|
* which is similar.
|
|
|
|
*/
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc = 16);
|
2002-05-28 03:55:40 +02:00
|
|
|
filesize = __small_sprintf (filebuf, "%u.%02u %u.%02u %u.%02u\n",
|
|
|
|
0, 0, 0, 0, 0, 0);
|
|
|
|
break;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
case PROC_MEMINFO:
|
|
|
|
{
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
|
2002-05-28 03:55:40 +02:00
|
|
|
filesize = format_proc_meminfo (filebuf, bufalloc);
|
|
|
|
break;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
case PROC_CPUINFO:
|
|
|
|
{
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc = 16384);
|
2003-03-09 21:10:25 +01:00
|
|
|
filesize = format_proc_cpuinfo (filebuf, bufalloc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROC_PARTITIONS:
|
|
|
|
{
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc = 4096);
|
2003-03-09 21:10:25 +01:00
|
|
|
filesize = format_proc_partitions (filebuf, bufalloc);
|
|
|
|
break;
|
|
|
|
}
|
2005-01-29 12:23:07 +01:00
|
|
|
case PROC_SELF:
|
|
|
|
{
|
2005-08-24 06:38:39 +02:00
|
|
|
filebuf = (char *) crealloc (filebuf, bufalloc = 32);
|
2005-01-29 12:23:07 +01:00
|
|
|
filesize = __small_sprintf (filebuf, "%d", getpid ());
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2002-07-02 03:36:15 +02:00
|
|
|
return true;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t
|
2002-05-12 03:37:48 +02:00
|
|
|
format_proc_meminfo (char *destbuf, size_t maxsize)
|
|
|
|
{
|
|
|
|
unsigned long mem_total = 0UL, mem_free = 0UL, swap_total = 0UL,
|
2002-05-28 03:55:40 +02:00
|
|
|
swap_free = 0UL;
|
2002-05-12 03:37:48 +02:00
|
|
|
MEMORYSTATUS memory_status;
|
|
|
|
GlobalMemoryStatus (&memory_status);
|
|
|
|
mem_total = memory_status.dwTotalPhys;
|
|
|
|
mem_free = memory_status.dwAvailPhys;
|
2004-03-18 13:28:47 +01:00
|
|
|
PSYSTEM_PAGEFILE_INFORMATION spi = NULL;
|
|
|
|
ULONG size = 512;
|
2004-07-19 15:13:48 +02:00
|
|
|
NTSTATUS ret = STATUS_SUCCESS;
|
2004-03-18 13:28:47 +01:00
|
|
|
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size);
|
|
|
|
if (spi)
|
|
|
|
{
|
|
|
|
ret = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi,
|
|
|
|
size, &size);
|
|
|
|
if (ret == STATUS_INFO_LENGTH_MISMATCH)
|
2004-05-28 21:50:07 +02:00
|
|
|
{
|
2004-03-18 13:28:47 +01:00
|
|
|
free (spi);
|
|
|
|
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size);
|
|
|
|
if (spi)
|
|
|
|
ret = NtQuerySystemInformation (SystemPagefileInformation,
|
|
|
|
(PVOID) spi, size, &size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!spi || ret || (!ret && GetLastError () == ERROR_PROC_NOT_FOUND))
|
|
|
|
{
|
|
|
|
swap_total = memory_status.dwTotalPageFile - mem_total;
|
|
|
|
swap_free = memory_status.dwAvailPageFile - mem_total;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PSYSTEM_PAGEFILE_INFORMATION spp = spi;
|
|
|
|
do
|
2004-05-28 21:50:07 +02:00
|
|
|
{
|
2005-11-28 23:32:29 +01:00
|
|
|
swap_total += spp->CurrentSize * getsystempagesize ();
|
|
|
|
swap_free += (spp->CurrentSize - spp->TotalUsed)
|
|
|
|
* getsystempagesize ();
|
2004-03-18 13:28:47 +01:00
|
|
|
}
|
|
|
|
while (spp->NextEntryOffset
|
|
|
|
&& (spp = (PSYSTEM_PAGEFILE_INFORMATION)
|
|
|
|
((char *) spp + spp->NextEntryOffset)));
|
|
|
|
}
|
|
|
|
if (spi)
|
|
|
|
free (spi);
|
2002-05-12 03:37:48 +02:00
|
|
|
return __small_sprintf (destbuf, " total: used: free:\n"
|
2002-05-28 03:55:40 +02:00
|
|
|
"Mem: %10lu %10lu %10lu\n"
|
|
|
|
"Swap: %10lu %10lu %10lu\n"
|
|
|
|
"MemTotal: %10lu kB\n"
|
|
|
|
"MemFree: %10lu kB\n"
|
|
|
|
"MemShared: 0 kB\n"
|
|
|
|
"HighTotal: 0 kB\n"
|
|
|
|
"HighFree: 0 kB\n"
|
|
|
|
"LowTotal: %10lu kB\n"
|
|
|
|
"LowFree: %10lu kB\n"
|
|
|
|
"SwapTotal: %10lu kB\n"
|
|
|
|
"SwapFree: %10lu kB\n",
|
|
|
|
mem_total, mem_total - mem_free, mem_free,
|
|
|
|
swap_total, swap_total - swap_free, swap_free,
|
|
|
|
mem_total >> 10, mem_free >> 10,
|
|
|
|
mem_total >> 10, mem_free >> 10,
|
|
|
|
swap_total >> 10, swap_free >> 10);
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t
|
2002-05-12 03:37:48 +02:00
|
|
|
format_proc_uptime (char *destbuf, size_t maxsize)
|
|
|
|
{
|
|
|
|
unsigned long long uptime = 0ULL, idle_time = 0ULL;
|
|
|
|
|
2005-12-12 13:18:14 +01:00
|
|
|
if (wincap.is_winnt ())
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
2005-12-12 13:18:14 +01:00
|
|
|
NTSTATUS ret;
|
|
|
|
SYSTEM_BASIC_INFORMATION sbi;
|
|
|
|
|
|
|
|
ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
|
|
|
|
sizeof sbi, NULL);
|
|
|
|
if (!NT_SUCCESS (ret))
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2005-04-13 18:41:33 +02:00
|
|
|
__seterrno_from_nt_status (ret);
|
2005-12-12 13:18:14 +01:00
|
|
|
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
|
|
|
|
sbi.NumberProcessors = 1;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2005-12-12 13:18:14 +01:00
|
|
|
|
|
|
|
SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors];
|
|
|
|
ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
|
|
|
|
sizeof spt[0] * sbi.NumberProcessors,
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS (ret))
|
|
|
|
for (int i = 0; i < sbi.NumberProcessors; i++)
|
|
|
|
{
|
|
|
|
uptime += (spt[i].KernelTime.QuadPart + spt[i].UserTime.QuadPart)
|
|
|
|
/ 100000ULL;
|
|
|
|
idle_time += spt[i].IdleTime.QuadPart / 100000ULL;
|
|
|
|
}
|
|
|
|
uptime /= sbi.NumberProcessors;
|
|
|
|
idle_time /= sbi.NumberProcessors;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
2005-12-12 13:18:14 +01:00
|
|
|
if (!uptime)
|
|
|
|
uptime = GetTickCount () / 10;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2002-05-12 03:37:48 +02:00
|
|
|
return __small_sprintf (destbuf, "%U.%02u %U.%02u\n",
|
2002-05-28 03:55:40 +02:00
|
|
|
uptime / 100, long (uptime % 100),
|
|
|
|
idle_time / 100, long (idle_time % 100));
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t
|
2002-05-12 03:37:48 +02:00
|
|
|
format_proc_stat (char *destbuf, size_t maxsize)
|
|
|
|
{
|
|
|
|
unsigned long pages_in = 0UL, pages_out = 0UL, interrupt_count = 0UL,
|
2002-05-28 03:55:40 +02:00
|
|
|
context_switches = 0UL, swap_in = 0UL, swap_out = 0UL;
|
2002-05-12 03:37:48 +02:00
|
|
|
time_t boot_time = 0;
|
|
|
|
|
2003-07-10 03:09:24 +02:00
|
|
|
char *eobuf = destbuf;
|
|
|
|
if (!wincap.is_winnt ())
|
2003-07-10 04:09:24 +02:00
|
|
|
eobuf += __small_sprintf (destbuf, "cpu %U %U %U %U\n", 0ULL, 0ULL, 0ULL, 0ULL);
|
2003-07-10 03:09:24 +02:00
|
|
|
else
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
SYSTEM_PERFORMANCE_INFORMATION spi;
|
|
|
|
SYSTEM_TIME_OF_DAY_INFORMATION stodi;
|
2003-07-10 03:09:24 +02:00
|
|
|
|
|
|
|
SYSTEM_BASIC_INFORMATION sbi;
|
|
|
|
if ((ret = NtQuerySystemInformation (SystemBasicInformation,
|
|
|
|
(PVOID) &sbi, sizeof sbi, NULL))
|
|
|
|
!= STATUS_SUCCESS)
|
|
|
|
{
|
2005-04-13 18:41:33 +02:00
|
|
|
__seterrno_from_nt_status (ret);
|
|
|
|
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
|
2003-07-10 03:09:24 +02:00
|
|
|
sbi.NumberProcessors = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors];
|
|
|
|
ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
|
|
|
|
sizeof spt[0] * sbi.NumberProcessors, NULL);
|
|
|
|
interrupt_count = 0;
|
2002-05-12 03:37:48 +02:00
|
|
|
if (ret == STATUS_SUCCESS)
|
2003-07-10 03:09:24 +02:00
|
|
|
{
|
|
|
|
unsigned long long user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
|
|
|
|
for (int i = 0; i < sbi.NumberProcessors; i++)
|
|
|
|
{
|
|
|
|
kernel_time += (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / 10000000ULL;
|
|
|
|
user_time += spt[i].UserTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
idle_time += spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
eobuf += __small_sprintf (eobuf, "cpu %U %U %U %U\n",
|
|
|
|
user_time, 0ULL, kernel_time, idle_time);
|
|
|
|
user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
|
|
|
|
for (int i = 0; i < sbi.NumberProcessors; i++)
|
|
|
|
{
|
|
|
|
interrupt_count += spt[i].InterruptCount;
|
|
|
|
kernel_time = (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / 10000000ULL;
|
|
|
|
user_time = spt[i].UserTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
idle_time = spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
eobuf += __small_sprintf (eobuf, "cpu%d %U %U %U %U\n", i,
|
|
|
|
user_time, 0ULL, kernel_time, idle_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = NtQuerySystemInformation (SystemPerformanceInformation,
|
|
|
|
(PVOID) &spi, sizeof spi, NULL);
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
if (ret == STATUS_SUCCESS)
|
2002-05-30 09:45:30 +02:00
|
|
|
ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
|
2002-05-28 03:55:40 +02:00
|
|
|
(PVOID) &stodi,
|
|
|
|
sizeof stodi, NULL);
|
2002-05-12 03:37:48 +02:00
|
|
|
if (ret != STATUS_SUCCESS)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
2005-04-13 18:41:33 +02:00
|
|
|
__seterrno_from_nt_status (ret);
|
|
|
|
debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
|
2002-05-28 03:55:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
pages_in = spi.PagesRead;
|
|
|
|
pages_out = spi.PagefilePagesWritten + spi.MappedFilePagesWritten;
|
|
|
|
/*
|
|
|
|
* Note: there is no distinction made in this structure between pages
|
|
|
|
* read from the page file and pages read from mapped files, but there
|
|
|
|
* is such a distinction made when it comes to writing. Goodness knows
|
|
|
|
* why. The value of swap_in, then, will obviously be wrong but its our
|
|
|
|
* best guess.
|
|
|
|
*/
|
|
|
|
swap_in = spi.PagesRead;
|
|
|
|
swap_out = spi.PagefilePagesWritten;
|
|
|
|
context_switches = spi.ContextSwitches;
|
|
|
|
boot_time = to_time_t ((FILETIME *) &stodi.BootTime.QuadPart);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* else
|
|
|
|
* {
|
|
|
|
* There are only two relevant performance counters on Windows 95/98/me,
|
|
|
|
* VMM/cPageIns and VMM/cPageOuts. The extra effort needed to read these
|
|
|
|
* counters is by no means worth it.
|
|
|
|
* }
|
|
|
|
*/
|
2003-07-10 03:09:24 +02:00
|
|
|
eobuf += __small_sprintf (eobuf, "page %u %u\n"
|
2002-05-28 03:55:40 +02:00
|
|
|
"swap %u %u\n"
|
|
|
|
"intr %u\n"
|
|
|
|
"ctxt %u\n"
|
|
|
|
"btime %u\n",
|
2003-07-10 03:09:24 +02:00
|
|
|
pages_in, pages_out,
|
|
|
|
swap_in, swap_out,
|
|
|
|
interrupt_count,
|
|
|
|
context_switches,
|
|
|
|
boot_time);
|
|
|
|
return eobuf - destbuf;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
|
|
|
|
#define read_value(x,y) \
|
|
|
|
do {\
|
|
|
|
dwCount = BUFSIZE; \
|
|
|
|
if ((dwError = RegQueryValueEx (hKey, x, NULL, &dwType, (BYTE *) szBuffer, &dwCount)), \
|
|
|
|
(dwError != ERROR_SUCCESS && dwError != ERROR_MORE_DATA)) \
|
|
|
|
{ \
|
|
|
|
__seterrno_from_win_error (dwError); \
|
|
|
|
debug_printf ("RegQueryValueEx failed retcode %d", dwError); \
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
if (dwType != y) \
|
|
|
|
{ \
|
|
|
|
debug_printf ("Value %s had an unexpected type (expected %d, found %d)", y, dwType); \
|
|
|
|
return 0; \
|
|
|
|
}\
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define print(x) \
|
|
|
|
do { \
|
|
|
|
strcpy (bufptr, x), \
|
|
|
|
bufptr += sizeof (x) - 1; \
|
|
|
|
} while (0)
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t
|
2003-03-09 21:10:25 +01:00
|
|
|
format_proc_cpuinfo (char *destbuf, size_t maxsize)
|
|
|
|
{
|
|
|
|
SYSTEM_INFO siSystemInfo;
|
|
|
|
HKEY hKey;
|
|
|
|
DWORD dwError, dwCount, dwType;
|
|
|
|
DWORD dwOldThreadAffinityMask;
|
|
|
|
int cpu_number;
|
|
|
|
const int BUFSIZE = 256;
|
|
|
|
CHAR szBuffer[BUFSIZE];
|
|
|
|
char *bufptr = destbuf;
|
|
|
|
|
|
|
|
GetSystemInfo (&siSystemInfo);
|
|
|
|
|
2005-10-02 02:13:41 +02:00
|
|
|
for (cpu_number = 0; ; cpu_number++)
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
|
|
|
__small_sprintf (szBuffer, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d", cpu_number);
|
|
|
|
|
|
|
|
if ((dwError = RegOpenKeyEx (HKEY_LOCAL_MACHINE, szBuffer, 0, KEY_QUERY_VALUE, &hKey)) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (dwError == ERROR_FILE_NOT_FOUND)
|
|
|
|
break;
|
|
|
|
__seterrno_from_win_error (dwError);
|
|
|
|
debug_printf ("RegOpenKeyEx failed retcode %d", dwError);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwOldThreadAffinityMask = SetThreadAffinityMask (GetCurrentThread (), 1 << cpu_number);
|
|
|
|
if (dwOldThreadAffinityMask == 0)
|
|
|
|
debug_printf ("SetThreadAffinityMask failed %E");
|
|
|
|
// I'm not sure whether the thread changes processor immediately
|
|
|
|
// and I'm not sure whether this function will cause the thread to be rescheduled
|
|
|
|
low_priority_sleep (0);
|
|
|
|
|
|
|
|
bool has_cpuid = false;
|
|
|
|
|
|
|
|
if (!can_set_flag (0x00040000))
|
|
|
|
debug_printf ("386 processor - no cpuid");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_printf ("486 processor");
|
|
|
|
if (can_set_flag (0x00200000))
|
|
|
|
{
|
|
|
|
debug_printf ("processor supports CPUID instruction");
|
|
|
|
has_cpuid = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
debug_printf ("processor does not support CPUID instruction");
|
|
|
|
}
|
|
|
|
|
2003-03-18 10:30:03 +01:00
|
|
|
|
|
|
|
if (!has_cpuid)
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
|
|
|
bufptr += __small_sprintf (bufptr, "processor : %d\n", cpu_number);
|
|
|
|
read_value ("VendorIdentifier", REG_SZ);
|
2003-04-19 03:03:16 +02:00
|
|
|
bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", szBuffer);
|
2003-03-09 21:10:25 +01:00
|
|
|
read_value ("Identifier", REG_SZ);
|
|
|
|
bufptr += __small_sprintf (bufptr, "identifier : %s\n", szBuffer);
|
2003-07-26 06:53:59 +02:00
|
|
|
if (wincap.is_winnt ())
|
|
|
|
{
|
2003-03-18 10:30:03 +01:00
|
|
|
read_value ("~Mhz", REG_DWORD);
|
|
|
|
bufptr += __small_sprintf (bufptr, "cpu MHz : %u\n", *(DWORD *) szBuffer);
|
|
|
|
|
|
|
|
print ("flags :");
|
|
|
|
if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE))
|
2003-07-26 06:53:59 +02:00
|
|
|
print (" 3dnow");
|
2003-03-18 10:30:03 +01:00
|
|
|
if (IsProcessorFeaturePresent (PF_COMPARE_EXCHANGE_DOUBLE))
|
2003-07-26 06:53:59 +02:00
|
|
|
print (" cx8");
|
2003-03-18 10:30:03 +01:00
|
|
|
if (!IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED))
|
2003-07-26 06:53:59 +02:00
|
|
|
print (" fpu");
|
2003-03-18 10:30:03 +01:00
|
|
|
if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE))
|
2003-07-26 06:53:59 +02:00
|
|
|
print (" mmx");
|
2003-03-18 10:30:03 +01:00
|
|
|
if (IsProcessorFeaturePresent (PF_PAE_ENABLED))
|
2003-07-26 06:53:59 +02:00
|
|
|
print (" pae");
|
2003-03-18 10:30:03 +01:00
|
|
|
if (IsProcessorFeaturePresent (PF_RDTSC_INSTRUCTION_AVAILABLE))
|
2003-07-26 06:53:59 +02:00
|
|
|
print (" tsc");
|
2003-03-18 10:30:03 +01:00
|
|
|
if (IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE))
|
2003-07-26 06:53:59 +02:00
|
|
|
print (" sse");
|
2003-03-18 10:30:03 +01:00
|
|
|
if (IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE))
|
2003-07-26 06:53:59 +02:00
|
|
|
print (" sse2");
|
2003-03-18 10:30:03 +01:00
|
|
|
}
|
2003-07-26 06:53:59 +02:00
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
bufptr += __small_sprintf (bufptr, "processor : %d\n", cpu_number);
|
|
|
|
unsigned maxf, vendor_id[4], unused;
|
2003-03-13 23:32:40 +01:00
|
|
|
cpuid (&maxf, &vendor_id[0], &vendor_id[2], &vendor_id[1], 0);
|
2003-03-09 21:10:25 +01:00
|
|
|
maxf &= 0xffff;
|
|
|
|
vendor_id[3] = 0;
|
2004-07-26 15:19:03 +02:00
|
|
|
|
2004-06-23 18:09:32 +02:00
|
|
|
// vendor identification
|
|
|
|
bool is_amd = false, is_intel = false;
|
|
|
|
if (!strcmp ((char*)vendor_id, "AuthenticAMD"))
|
|
|
|
is_amd = true;
|
|
|
|
else if (!strcmp ((char*)vendor_id, "GenuineIntel"))
|
|
|
|
is_intel = true;
|
2004-07-26 15:19:03 +02:00
|
|
|
|
2003-04-19 03:03:16 +02:00
|
|
|
bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", (char *)vendor_id);
|
2003-07-26 06:53:59 +02:00
|
|
|
unsigned cpu_mhz = 0;
|
|
|
|
if (wincap.is_winnt ())
|
|
|
|
{
|
2003-03-18 10:30:03 +01:00
|
|
|
read_value ("~Mhz", REG_DWORD);
|
|
|
|
cpu_mhz = *(DWORD *)szBuffer;
|
2003-07-26 06:53:59 +02:00
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
if (maxf >= 1)
|
|
|
|
{
|
|
|
|
unsigned features2, features1, extra_info, cpuid_sig;
|
|
|
|
cpuid (&cpuid_sig, &extra_info, &features2, &features1, 1);
|
|
|
|
/* unsigned extended_family = (cpuid_sig & 0x0ff00000) >> 20,
|
|
|
|
extended_model = (cpuid_sig & 0x000f0000) >> 16; */
|
2004-05-28 21:50:07 +02:00
|
|
|
unsigned type = (cpuid_sig & 0x00003000) >> 12,
|
|
|
|
family = (cpuid_sig & 0x00000f00) >> 8,
|
|
|
|
model = (cpuid_sig & 0x000000f0) >> 4,
|
|
|
|
stepping = cpuid_sig & 0x0000000f;
|
|
|
|
unsigned brand_id = extra_info & 0x0000000f,
|
|
|
|
cpu_count = (extra_info & 0x00ff0000) >> 16,
|
|
|
|
apic_id = (extra_info & 0xff000000) >> 24;
|
2003-03-09 21:10:25 +01:00
|
|
|
const char *type_str;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
type_str = "primary processor";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
type_str = "overdrive processor";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
type_str = "secondary processor";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
type_str = "reserved";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unsigned maxe = 0;
|
|
|
|
cpuid (&maxe, &unused, &unused, &unused, 0x80000000);
|
|
|
|
if (maxe >= 0x80000004)
|
|
|
|
{
|
|
|
|
unsigned *model_name = (unsigned *) szBuffer;
|
|
|
|
cpuid (&model_name[0], &model_name[1], &model_name[2], &model_name[3], 0x80000002);
|
|
|
|
cpuid (&model_name[4], &model_name[5], &model_name[6], &model_name[7], 0x80000003);
|
|
|
|
cpuid (&model_name[8], &model_name[9], &model_name[10], &model_name[11], 0x80000004);
|
|
|
|
model_name[12] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// could implement a lookup table here if someone needs it
|
|
|
|
strcpy (szBuffer, "unknown");
|
|
|
|
}
|
2003-07-26 06:53:59 +02:00
|
|
|
if (wincap.is_winnt ())
|
|
|
|
{
|
|
|
|
bufptr += __small_sprintf (bufptr, "type : %s\n"
|
|
|
|
"cpu family : %d\n"
|
2003-03-18 10:30:03 +01:00
|
|
|
"model : %d\n"
|
|
|
|
"model name : %s\n"
|
|
|
|
"stepping : %d\n"
|
|
|
|
"brand id : %d\n"
|
|
|
|
"cpu count : %d\n"
|
|
|
|
"apic id : %d\n"
|
|
|
|
"cpu MHz : %d\n"
|
|
|
|
"fpu : %s\n",
|
|
|
|
type_str,
|
|
|
|
family,
|
|
|
|
model,
|
2006-01-10 17:49:28 +01:00
|
|
|
szBuffer + strspn (szBuffer, " "),
|
2003-03-18 10:30:03 +01:00
|
|
|
stepping,
|
|
|
|
brand_id,
|
|
|
|
cpu_count,
|
|
|
|
apic_id,
|
|
|
|
cpu_mhz,
|
|
|
|
(features1 & (1 << 0)) ? "yes" : "no");
|
2003-07-26 06:53:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bufptr += __small_sprintf (bufptr, "type : %s\n"
|
|
|
|
"cpu family : %d\n"
|
|
|
|
"model : %d\n"
|
|
|
|
"model name : %s\n"
|
|
|
|
"stepping : %d\n"
|
|
|
|
"brand id : %d\n"
|
|
|
|
"cpu count : %d\n"
|
|
|
|
"apic id : %d\n"
|
|
|
|
"fpu : %s\n",
|
|
|
|
type_str,
|
|
|
|
family,
|
|
|
|
model,
|
|
|
|
szBuffer,
|
|
|
|
stepping,
|
|
|
|
brand_id,
|
|
|
|
cpu_count,
|
|
|
|
apic_id,
|
|
|
|
(features1 & (1 << 0)) ? "yes" : "no");
|
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
print ("flags :");
|
|
|
|
if (features1 & (1 << 0))
|
|
|
|
print (" fpu");
|
|
|
|
if (features1 & (1 << 1))
|
|
|
|
print (" vme");
|
|
|
|
if (features1 & (1 << 2))
|
|
|
|
print (" de");
|
|
|
|
if (features1 & (1 << 3))
|
|
|
|
print (" pse");
|
|
|
|
if (features1 & (1 << 4))
|
|
|
|
print (" tsc");
|
|
|
|
if (features1 & (1 << 5))
|
|
|
|
print (" msr");
|
|
|
|
if (features1 & (1 << 6))
|
|
|
|
print (" pae");
|
|
|
|
if (features1 & (1 << 7))
|
|
|
|
print (" mce");
|
|
|
|
if (features1 & (1 << 8))
|
|
|
|
print (" cx8");
|
|
|
|
if (features1 & (1 << 9))
|
|
|
|
print (" apic");
|
|
|
|
if (features1 & (1 << 11))
|
|
|
|
print (" sep");
|
|
|
|
if (features1 & (1 << 12))
|
|
|
|
print (" mtrr");
|
|
|
|
if (features1 & (1 << 13))
|
|
|
|
print (" pge");
|
|
|
|
if (features1 & (1 << 14))
|
|
|
|
print (" mca");
|
|
|
|
if (features1 & (1 << 15))
|
|
|
|
print (" cmov");
|
|
|
|
if (features1 & (1 << 16))
|
|
|
|
print (" pat");
|
|
|
|
if (features1 & (1 << 17))
|
|
|
|
print (" pse36");
|
|
|
|
if (features1 & (1 << 18))
|
|
|
|
print (" psn");
|
|
|
|
if (features1 & (1 << 19))
|
|
|
|
print (" clfl");
|
2004-07-26 15:19:03 +02:00
|
|
|
if (is_intel && features1 & (1 << 21))
|
2003-03-09 21:10:25 +01:00
|
|
|
print (" dtes");
|
2004-07-26 15:19:03 +02:00
|
|
|
if (is_intel && features1 & (1 << 22))
|
2003-03-09 21:10:25 +01:00
|
|
|
print (" acpi");
|
|
|
|
if (features1 & (1 << 23))
|
|
|
|
print (" mmx");
|
|
|
|
if (features1 & (1 << 24))
|
|
|
|
print (" fxsr");
|
|
|
|
if (features1 & (1 << 25))
|
|
|
|
print (" sse");
|
2004-07-26 15:19:03 +02:00
|
|
|
if (is_intel)
|
2004-09-12 05:47:57 +02:00
|
|
|
{
|
|
|
|
if (features1 & (1 << 26))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" sse2");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features1 & (1 << 27))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" ss");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features1 & (1 << 28))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" htt");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features1 & (1 << 29))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" tmi");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features1 & (1 << 30))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" ia-64");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features1 & (1 << 31))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" pbe");
|
|
|
|
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features2 & (1 << 0))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" pni");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features2 & (1 << 3))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" monitor");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features2 & (1 << 4))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" ds_cpl");
|
|
|
|
if (features2 & (1 << 7))
|
|
|
|
print (" tm2");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features2 & (1 << 8))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" est");
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features2 & (1 << 10))
|
2004-07-26 15:19:03 +02:00
|
|
|
print (" cid");
|
2004-09-12 05:47:57 +02:00
|
|
|
}
|
2004-07-26 15:19:03 +02:00
|
|
|
|
|
|
|
if (is_amd && maxe >= 0x80000001)
|
2004-09-12 05:47:57 +02:00
|
|
|
{
|
2004-06-23 18:09:32 +02:00
|
|
|
// uses AMD extended calls to check
|
|
|
|
// for 3dnow and 3dnow extended support
|
|
|
|
// (source: AMD Athlon Processor Recognition Application Note)
|
2004-07-26 15:19:03 +02:00
|
|
|
|
|
|
|
if (maxe >= 0x80000001) // has basic capabilities
|
2004-06-23 18:09:32 +02:00
|
|
|
{
|
2004-07-26 15:19:03 +02:00
|
|
|
cpuid (&unused, &unused, &unused, &features2, 0x80000001);
|
|
|
|
|
2004-09-12 05:47:57 +02:00
|
|
|
if (features2 & (1 << 11))
|
|
|
|
print (" syscall");
|
|
|
|
if (features2 & (1 << 19))
|
|
|
|
print (" mp");
|
|
|
|
if (features2 & (1 << 22))
|
|
|
|
print (" mmxext");
|
|
|
|
if (features2 & (1 << 29))
|
|
|
|
print (" lm");
|
2004-07-26 15:19:03 +02:00
|
|
|
if (features2 & (1 << 30)) // 31th bit is on
|
2004-06-23 18:09:32 +02:00
|
|
|
print (" 3dnowext");
|
2004-07-26 15:19:03 +02:00
|
|
|
if (features2 & (1 << 31)) // 32th bit (highest) is on
|
2004-06-23 18:09:32 +02:00
|
|
|
print (" 3dnow");
|
|
|
|
}
|
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2003-03-18 10:30:03 +01:00
|
|
|
else if (wincap.is_winnt ())
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
|
|
|
bufptr += __small_sprintf (bufptr, "cpu MHz : %d\n"
|
|
|
|
"fpu : %s\n",
|
|
|
|
cpu_mhz,
|
|
|
|
IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED) ? "no" : "yes");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dwOldThreadAffinityMask != 0)
|
|
|
|
SetThreadAffinityMask (GetCurrentThread (), dwOldThreadAffinityMask);
|
|
|
|
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
bufptr += __small_sprintf (bufptr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return bufptr - destbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef read_value
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t
|
2003-03-09 21:10:25 +01:00
|
|
|
format_proc_partitions (char *destbuf, size_t maxsize)
|
|
|
|
{
|
|
|
|
char *bufptr = destbuf;
|
|
|
|
print ("major minor #blocks name\n\n");
|
|
|
|
|
2006-03-09 10:01:08 +01:00
|
|
|
if (!wincap.is_winnt ())
|
|
|
|
return bufptr - destbuf;
|
|
|
|
|
|
|
|
char devname[CYG_MAX_PATH];
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
HANDLE dirhdl, devhdl;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
/* Open \Device object directory. */
|
|
|
|
wchar_t wpath[CYG_MAX_PATH] = L"\\Device";
|
|
|
|
UNICODE_STRING upath = {14, 16, wpath};
|
|
|
|
InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
status = NtOpenDirectoryObject (&dirhdl, DIRECTORY_QUERY, &attr);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
|
|
|
debug_printf ("NtOpenDirectoryObject %x", status);
|
|
|
|
return bufptr - destbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Traverse \Device directory ... */
|
|
|
|
PDIRECTORY_BASIC_INFORMATION dbi = (PDIRECTORY_BASIC_INFORMATION)
|
|
|
|
alloca (640);
|
|
|
|
BOOLEAN restart = TRUE;
|
|
|
|
ULONG context = 0;
|
|
|
|
while (NT_SUCCESS (NtQueryDirectoryObject (dirhdl, dbi, 640, TRUE, restart,
|
|
|
|
&context, NULL)))
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2006-03-09 10:01:08 +01:00
|
|
|
restart = FALSE;
|
|
|
|
sys_wcstombs (devname, CYG_MAX_PATH - 1, dbi->ObjectName.Buffer,
|
|
|
|
dbi->ObjectName.Length / 2);
|
|
|
|
/* ... and check for a "Harddisk[0-9]*" entry. */
|
|
|
|
if (!strncasematch (devname, "Harddisk", 8)
|
|
|
|
|| dbi->ObjectName.Length < 18
|
|
|
|
|| !isdigit (devname[8]))
|
|
|
|
continue;
|
|
|
|
/* Construct path name for partition 0, which is the whole disk,
|
2006-05-28 17:50:14 +02:00
|
|
|
and try to open. */
|
2006-03-09 10:01:08 +01:00
|
|
|
wcscpy (wpath, dbi->ObjectName.Buffer);
|
|
|
|
wcscpy (wpath + dbi->ObjectName.Length / 2, L"\\Partition0");
|
|
|
|
upath.Length = 22 + dbi->ObjectName.Length;
|
|
|
|
upath.MaximumLength = upath.Length + 2;
|
|
|
|
InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE,
|
|
|
|
dirhdl, NULL);
|
|
|
|
status = NtOpenFile (&devhdl, READ_CONTROL | FILE_READ_DATA, &attr, &io,
|
|
|
|
wincap.shared (), 0);
|
|
|
|
if (!NT_SUCCESS (status))
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2006-03-09 10:01:08 +01:00
|
|
|
/* Retry with READ_CONTROL only for non-privileged users. This
|
|
|
|
at least prints the Partition0 info, but it doesn't allow access
|
|
|
|
to the drive's layout information. It beats me, though, why
|
|
|
|
a non-privileged user shouldn't get read access to the drive
|
|
|
|
layout information. */
|
|
|
|
status = NtOpenFile (&devhdl, READ_CONTROL, &attr, &io,
|
|
|
|
wincap.shared (), 0);
|
|
|
|
if (!NT_SUCCESS (status))
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2006-03-09 10:01:08 +01:00
|
|
|
debug_printf ("NtOpenFile(%s) %x", devname, status);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use a buffer since some ioctl buffers aren't fixed size. */
|
|
|
|
char buf[256];
|
|
|
|
PARTITION_INFORMATION *pi = NULL;
|
|
|
|
PARTITION_INFORMATION_EX *pix = NULL;
|
|
|
|
DISK_GEOMETRY *dg = NULL;
|
|
|
|
DWORD bytes;
|
|
|
|
unsigned long drive_number = strtoul (devname + 8, NULL, 10);
|
|
|
|
unsigned long long size;
|
|
|
|
|
|
|
|
if (wincap.has_disk_ex_ioctls ()
|
|
|
|
&& DeviceIoControl (devhdl, IOCTL_DISK_GET_PARTITION_INFO_EX,
|
|
|
|
NULL, 0, buf, 256, &bytes, NULL))
|
|
|
|
{
|
|
|
|
pix = (PARTITION_INFORMATION_EX *) buf;
|
|
|
|
size = pix->PartitionLength.QuadPart;
|
|
|
|
}
|
|
|
|
else if (DeviceIoControl (devhdl, IOCTL_DISK_GET_PARTITION_INFO,
|
|
|
|
NULL, 0, buf, 256, &bytes, NULL))
|
|
|
|
{
|
|
|
|
pi = (PARTITION_INFORMATION *) buf;
|
|
|
|
size = pi->PartitionLength.QuadPart;
|
|
|
|
}
|
|
|
|
else if (DeviceIoControl (devhdl, IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
|
|
|
NULL, 0, buf, 256, &bytes, NULL))
|
|
|
|
{
|
|
|
|
dg = (DISK_GEOMETRY *) buf;
|
|
|
|
size = (unsigned long long) dg->Cylinders.QuadPart
|
|
|
|
* dg->TracksPerCylinder
|
|
|
|
* dg->SectorsPerTrack
|
|
|
|
* dg->BytesPerSector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
if (!pi && !pix && !dg)
|
|
|
|
debug_printf ("DeviceIoControl %E");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
device dev;
|
|
|
|
dev.parsedisk (drive_number, 0);
|
|
|
|
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n",
|
|
|
|
dev.major, dev.minor,
|
|
|
|
size >> 10, dev.name + 5);
|
|
|
|
}
|
|
|
|
size_t buf_size = 8192;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
char buf[buf_size];
|
|
|
|
if (DeviceIoControl (devhdl, IOCTL_DISK_GET_DRIVE_LAYOUT,
|
|
|
|
NULL, 0, (DRIVE_LAYOUT_INFORMATION *) buf,
|
|
|
|
buf_size, &bytes, NULL))
|
|
|
|
/* fall through */;
|
|
|
|
else if (GetLastError () == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
|
|
|
buf_size *= 2;
|
|
|
|
continue;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-09 10:01:08 +01:00
|
|
|
debug_printf ("DeviceIoControl %E");
|
|
|
|
break;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2006-03-09 10:01:08 +01:00
|
|
|
DRIVE_LAYOUT_INFORMATION *dli = (DRIVE_LAYOUT_INFORMATION *) buf;
|
|
|
|
for (unsigned part = 0; part < dli->PartitionCount; part++)
|
|
|
|
{
|
|
|
|
if (!dli->PartitionEntry[part].PartitionLength.QuadPart
|
|
|
|
|| !dli->PartitionEntry[part].RecognizedPartition)
|
|
|
|
continue;
|
|
|
|
device dev;
|
|
|
|
dev.parsedisk (drive_number,
|
|
|
|
dli->PartitionEntry[part].PartitionNumber);
|
|
|
|
size = dli->PartitionEntry[part].PartitionLength.QuadPart >> 10;
|
|
|
|
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n",
|
|
|
|
dev.major, dev.minor,
|
|
|
|
size, dev.name + 5);
|
|
|
|
}
|
|
|
|
break;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2006-03-09 10:01:08 +01:00
|
|
|
NtClose (devhdl);
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2006-03-09 10:01:08 +01:00
|
|
|
NtClose (dirhdl);
|
|
|
|
|
2003-03-09 21:10:25 +01:00
|
|
|
return bufptr - destbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef print
|