2000-02-18 03:38:33 +08:00
|
|
|
/* fhandler_tape.cc. See fhandler.h for a description of the fhandler
|
|
|
|
classes.
|
|
|
|
|
2004-02-09 12:04:24 +08:00
|
|
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <sys/termios.h>
|
|
|
|
#include <unistd.h>
|
2004-03-15 02:01:45 +08:00
|
|
|
#include <stdlib.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <sys/mtio.h>
|
2004-03-15 02:01:45 +08:00
|
|
|
#include <ddk/ntddstor.h>
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2001-03-05 14:28:25 +08:00
|
|
|
#include "perprocess.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
/* Media changes and bus resets are sometimes reported and the function
|
|
|
|
hasn't been executed. We repeat all functions which return with one
|
|
|
|
of these error codes. */
|
2004-03-15 02:01:45 +08:00
|
|
|
/* FIXME: Note that this is wrong! The correct behaviour after getting
|
|
|
|
an ERROR_BUS_RESET is to raise a flag and then to block any access,
|
|
|
|
except for MTREW, MTOFFL, MT_RETEN, MTERASE, MTSEEK and MTEOM, and
|
|
|
|
to set errno to EIO in all other cases. */
|
2004-03-14 02:15:06 +08:00
|
|
|
#define TAPE_FUNC(func) do { \
|
|
|
|
lasterr = (func); \
|
|
|
|
} while (lasterr == ERROR_MEDIA_CHANGED \
|
|
|
|
|| lasterr == ERROR_BUS_RESET)
|
|
|
|
|
|
|
|
/* Convert LARGE_INTEGER into long long */
|
|
|
|
#define get_ll(pl) (((long long) (pl).HighPart << 32) | (pl).LowPart)
|
|
|
|
|
|
|
|
#define IS_EOM(err) ((err) == ERROR_END_OF_MEDIA \
|
|
|
|
|| (err) == ERROR_EOM_OVERFLOW \
|
|
|
|
|| (err) == ERROR_NO_DATA_DETECTED)
|
|
|
|
|
|
|
|
#define IS_EOF(err) ((err) == ERROR_FILEMARK_DETECTED \
|
|
|
|
|| (err) == ERROR_SETMARK_DETECTED)
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/**********************************************************************/
|
|
|
|
/* fhandler_dev_tape */
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_dev_tape::clear (void)
|
|
|
|
{
|
|
|
|
lasterr = 0;
|
|
|
|
fhandler_dev_raw::clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::is_eom (int win_error)
|
|
|
|
{
|
2004-03-14 02:15:06 +08:00
|
|
|
int ret = IS_EOM (win_error);
|
2000-02-18 03:38:33 +08:00
|
|
|
if (ret)
|
|
|
|
debug_printf ("end of medium");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::is_eof (int win_error)
|
|
|
|
{
|
2004-03-14 02:15:06 +08:00
|
|
|
int ret = IS_EOF (win_error);
|
2000-02-18 03:38:33 +08:00
|
|
|
if (ret)
|
|
|
|
debug_printf ("end of file");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
BOOL
|
|
|
|
fhandler_dev_tape::write_file (const void *buf, DWORD to_write,
|
|
|
|
DWORD *written, int *err)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*err = 0;
|
|
|
|
if (!(ret = WriteFile (get_handle (), buf, to_write, written, 0)))
|
|
|
|
*err = GetLastError ();
|
|
|
|
}
|
|
|
|
while (*err == ERROR_MEDIA_CHANGED || *err == ERROR_BUS_RESET);
|
|
|
|
syscall_printf ("%d (err %d) = WriteFile (%d, %d, write %d, written %d, 0)",
|
|
|
|
ret, *err, get_handle (), buf, to_write, *written);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
fhandler_dev_tape::read_file (void *buf, DWORD to_read, DWORD *read, int *err)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*err = 0;
|
|
|
|
if (!(ret = ReadFile (get_handle (), buf, to_read, read, 0)))
|
|
|
|
*err = GetLastError ();
|
|
|
|
}
|
|
|
|
while (*err == ERROR_MEDIA_CHANGED || *err == ERROR_BUS_RESET);
|
|
|
|
syscall_printf ("%d (err %d) = ReadFile (%d, %d, to_read %d, read %d, 0)",
|
|
|
|
ret, *err, get_handle (), buf, to_read, *read);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_dev_tape::fhandler_dev_tape ()
|
|
|
|
: fhandler_dev_raw ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
debug_printf ("unit: %d", dev ().minor);
|
2000-02-18 03:38:33 +08: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 08:37:18 +08:00
|
|
|
fhandler_dev_tape::open (int flags, mode_t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
devbufsiz = 1L;
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
ret = fhandler_dev_raw::open (flags);
|
2000-02-18 03:38:33 +08:00
|
|
|
if (ret)
|
|
|
|
{
|
2004-03-14 02:15:06 +08:00
|
|
|
DWORD varlen;
|
2004-03-15 19:37:37 +08:00
|
|
|
struct mtget get;
|
|
|
|
unsigned long block;
|
2004-03-14 02:15:06 +08:00
|
|
|
|
|
|
|
TAPE_FUNC (GetTapeParameters (get_handle (), GET_TAPE_DRIVE_INFORMATION,
|
|
|
|
(varlen = sizeof dp, &varlen), &dp));
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-03-15 19:37:37 +08:00
|
|
|
if (!tape_status (&get))
|
2004-03-15 02:01:45 +08:00
|
|
|
{
|
|
|
|
long blksize = (get.mt_dsreg & MT_ST_BLKSIZE_MASK)
|
|
|
|
>> MT_ST_BLKSIZE_SHIFT;
|
|
|
|
/* Tape drive supports and is set to variable block size. */
|
|
|
|
if (blksize == 0)
|
|
|
|
devbufsiz = get.mt_maxblksize;
|
|
|
|
else
|
|
|
|
devbufsiz = blksize;
|
|
|
|
varblkop = blksize == 0;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (devbufsiz > 1L)
|
2000-11-01 06:20:59 +08:00
|
|
|
devbuf = new char [devbufsiz];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-24 03:33:44 +08:00
|
|
|
/* The following rewind in position 0 solves a problem which appears
|
2000-02-18 03:38:33 +08:00
|
|
|
* in case of multi volume archives: The last ReadFile on first medium
|
|
|
|
* returns ERROR_NO_DATA_DETECTED. After media change, all subsequent
|
2000-07-24 03:33:44 +08:00
|
|
|
* ReadFile calls return ERROR_NO_DATA_DETECTED, too.
|
|
|
|
* The call to tape_set_pos seems to reset some internal flags. */
|
2004-03-15 19:37:37 +08:00
|
|
|
if (!tape_get_pos (&block) && !block)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-03-02 21:07:47 +08:00
|
|
|
debug_printf ("rewinding");
|
2004-03-15 19:37:37 +08:00
|
|
|
tape_set_pos (TAPE_REWIND, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
|
|
|
{
|
|
|
|
/* In append mode, seek to beginning of next filemark */
|
2004-03-15 19:37:37 +08:00
|
|
|
tape_set_pos (TAPE_SPACE_FILEMARKS, 1, true);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::close (void)
|
|
|
|
{
|
|
|
|
struct mtop op;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (is_writing)
|
|
|
|
{
|
|
|
|
ret = writebuf ();
|
2004-03-14 02:15:06 +08:00
|
|
|
if (has_written && !eom_detected)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* if last operation was writing, write a filemark */
|
2002-09-30 12:35:18 +08:00
|
|
|
debug_printf ("writing filemark");
|
2000-02-18 03:38:33 +08:00
|
|
|
op.mt_op = MTWEOF;
|
|
|
|
op.mt_count = 1;
|
|
|
|
ioctl (MTIOCTOP, &op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// To protected reads on signaling (e.g. Ctrl-C)
|
|
|
|
eof_detected = 1;
|
|
|
|
|
2001-10-16 22:53:26 +08:00
|
|
|
if (is_rewind_device ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-09-30 12:35:18 +08:00
|
|
|
debug_printf ("rewinding");
|
2004-03-15 19:37:37 +08:00
|
|
|
tape_set_pos (TAPE_REWIND, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
fhandler_dev_raw::close ();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fhandler_dev_raw::close ();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 08:37:18 +08:00
|
|
|
fhandler_dev_tape::fstat (struct __stat64 *buf)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
if (!(ret = fhandler_base::fstat (buf)))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
struct mtget get;
|
|
|
|
|
2002-06-02 11:13:22 +08:00
|
|
|
if (!ioctl (MTIOCGET, &get))
|
|
|
|
buf->st_blocks = get.mt_capacity / buf->st_blksize;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t
|
|
|
|
fhandler_dev_tape::lseek (_off64_t offset, int whence)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
struct mtop op;
|
|
|
|
struct mtpos pos;
|
|
|
|
|
2002-09-30 12:35:18 +08:00
|
|
|
debug_printf ("lseek (%s, %d, %d)", get_name (), offset, whence);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
writebuf ();
|
|
|
|
|
|
|
|
if (ioctl (MTIOCPOS, &pos))
|
|
|
|
{
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
return ILLEGAL_SEEK;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
case SEEK_END:
|
|
|
|
op.mt_op = MTFSF;
|
|
|
|
op.mt_count = 1;
|
|
|
|
if (ioctl (MTIOCTOP, &op))
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case SEEK_SET:
|
|
|
|
if (whence == SEEK_SET && offset < 0)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
op.mt_op = MTFSR;
|
|
|
|
op.mt_count = offset / devbufsiz
|
|
|
|
- (whence == SEEK_SET ? pos.mt_blkno : 0);
|
|
|
|
|
|
|
|
if (op.mt_count < 0)
|
|
|
|
{
|
|
|
|
op.mt_op = MTBSR;
|
|
|
|
op.mt_count = -op.mt_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl (MTIOCTOP, &op) || ioctl (MTIOCPOS, &pos))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return (pos.mt_blkno * devbufsiz);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::dup (fhandler_base *child)
|
|
|
|
{
|
|
|
|
fhandler_dev_tape *fhc = (fhandler_dev_tape *) child;
|
|
|
|
|
|
|
|
fhc->lasterr = lasterr;
|
2004-03-14 02:15:06 +08:00
|
|
|
fhc->dp = dp;
|
2000-02-18 03:38:33 +08:00
|
|
|
return fhandler_dev_raw::dup (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::ioctl (unsigned int cmd, void *buf)
|
|
|
|
{
|
|
|
|
int ret = NO_ERROR;
|
|
|
|
unsigned long block;
|
|
|
|
|
|
|
|
if (cmd == MTIOCTOP)
|
|
|
|
{
|
|
|
|
struct mtop *op = (struct mtop *) buf;
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!op)
|
2000-02-18 03:38:33 +08:00
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
switch (op->mt_op)
|
|
|
|
{
|
|
|
|
case MTRESET:
|
|
|
|
break;
|
|
|
|
case MTFSF:
|
|
|
|
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, op->mt_count);
|
|
|
|
break;
|
|
|
|
case MTBSF:
|
|
|
|
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, -op->mt_count);
|
|
|
|
break;
|
|
|
|
case MTFSR:
|
|
|
|
ret = tape_set_pos (TAPE_SPACE_RELATIVE_BLOCKS, op->mt_count);
|
|
|
|
break;
|
|
|
|
case MTBSR:
|
|
|
|
ret = tape_set_pos (TAPE_SPACE_RELATIVE_BLOCKS, -op->mt_count);
|
|
|
|
break;
|
|
|
|
case MTWEOF:
|
2000-05-17 05:42:55 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_WRITE_FILEMARKS))
|
|
|
|
ret = tape_write_marks (TAPE_FILEMARKS, op->mt_count);
|
|
|
|
else if (tape_get_feature (TAPE_DRIVE_WRITE_LONG_FMKS))
|
|
|
|
ret = tape_write_marks (TAPE_LONG_FILEMARKS, op->mt_count);
|
|
|
|
else
|
|
|
|
ret = tape_write_marks (TAPE_SHORT_FILEMARKS, op->mt_count);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTREW:
|
|
|
|
ret = tape_set_pos (TAPE_REWIND, 0);
|
|
|
|
break;
|
|
|
|
case MTOFFL:
|
2004-03-15 02:01:45 +08:00
|
|
|
case MTUNLOAD:
|
2000-02-18 03:38:33 +08:00
|
|
|
ret = tape_prepare (TAPE_UNLOAD);
|
|
|
|
break;
|
|
|
|
case MTNOP:
|
2004-03-15 02:01:45 +08:00
|
|
|
reset_devbuf ();
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTRETEN:
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!tape_get_feature (TAPE_DRIVE_END_OF_DATA))
|
2000-07-24 03:33:44 +08:00
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
2004-03-14 02:15:06 +08:00
|
|
|
else if (!(ret = tape_set_pos (TAPE_REWIND, 0, false)))
|
2000-07-24 03:33:44 +08:00
|
|
|
ret = tape_prepare (TAPE_TENSION);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTBSFM:
|
2003-12-08 06:37:12 +08:00
|
|
|
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, -op->mt_count, true);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTFSFM:
|
2003-12-08 06:37:12 +08:00
|
|
|
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, op->mt_count, true);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTEOM:
|
|
|
|
if (tape_get_feature (TAPE_DRIVE_END_OF_DATA))
|
2000-07-24 03:33:44 +08:00
|
|
|
ret = tape_set_pos (TAPE_SPACE_END_OF_DATA, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2000-07-24 03:33:44 +08:00
|
|
|
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, 32767);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTERASE:
|
2004-03-15 19:37:37 +08:00
|
|
|
ret = tape_erase (TAPE_ERASE_LONG);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTRAS1:
|
|
|
|
case MTRAS2:
|
|
|
|
case MTRAS3:
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
case MTSETBLK:
|
2004-03-15 02:01:45 +08:00
|
|
|
if (!tape_get_feature (TAPE_DRIVE_SET_BLOCK_SIZE))
|
|
|
|
{
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((devbuf && (size_t) op->mt_count == devbufsiz)
|
|
|
|
|| (!devbuf && op->mt_count == 0))
|
|
|
|
{
|
|
|
|
/* Nothing has changed. */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((op->mt_count == 0
|
|
|
|
&& !tape_get_feature (TAPE_DRIVE_VARIABLE_BLOCK))
|
|
|
|
|| (op->mt_count > 0
|
|
|
|
&& ((DWORD) op->mt_count < dp.MinimumBlockSize
|
|
|
|
|| (DWORD) op->mt_count > dp.MaximumBlockSize)))
|
|
|
|
{
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (devbuf && devbufend - devbufstart > 0
|
|
|
|
&& (op->mt_count == 0
|
|
|
|
|| (op->mt_count > 0
|
|
|
|
&& (size_t) op->mt_count < devbufend - devbufstart)))
|
|
|
|
{
|
|
|
|
/* Not allowed if still data in devbuf. */
|
|
|
|
ret = ERROR_INVALID_BLOCK_LENGTH; /* EIO */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!(ret = tape_set_blocksize (op->mt_count)))
|
|
|
|
{
|
|
|
|
char *buf = NULL;
|
|
|
|
if (op->mt_count > 1L && !(buf = new char [op->mt_count]))
|
|
|
|
{
|
|
|
|
ret = ERROR_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (devbufsiz > 1L && op->mt_count > 1L)
|
|
|
|
{
|
|
|
|
memcpy (buf, devbuf + devbufstart,
|
|
|
|
devbufend - devbufstart);
|
|
|
|
devbufend -= devbufstart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
devbufend = 0;
|
|
|
|
devbufstart = 0;
|
|
|
|
delete [] devbuf;
|
|
|
|
devbuf = buf;
|
|
|
|
devbufsiz = op->mt_count;
|
|
|
|
varblkop = op->mt_count == 0;
|
|
|
|
}
|
|
|
|
reset_devbuf ();
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTSEEK:
|
2004-03-15 19:37:37 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_LOGICAL_BLK))
|
|
|
|
ret = tape_set_pos (TAPE_LOGICAL_BLOCK, op->mt_count);
|
2004-03-14 02:15:06 +08:00
|
|
|
else if (!(ret = tape_get_pos (&block)))
|
|
|
|
ret = tape_set_pos (TAPE_SPACE_RELATIVE_BLOCKS,
|
|
|
|
op->mt_count - block);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTTELL:
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!(ret = tape_get_pos (&block)))
|
2000-02-18 03:38:33 +08:00
|
|
|
op->mt_count = block;
|
|
|
|
break;
|
|
|
|
case MTFSS:
|
|
|
|
ret = tape_set_pos (TAPE_SPACE_SETMARKS, op->mt_count);
|
|
|
|
break;
|
|
|
|
case MTBSS:
|
|
|
|
ret = tape_set_pos (TAPE_SPACE_SETMARKS, -op->mt_count);
|
|
|
|
break;
|
|
|
|
case MTWSM:
|
|
|
|
ret = tape_write_marks (TAPE_SETMARKS, op->mt_count);
|
2004-03-15 02:01:45 +08:00
|
|
|
reset_devbuf ();
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case MTLOCK:
|
|
|
|
ret = tape_prepare (TAPE_LOCK);
|
|
|
|
break;
|
|
|
|
case MTUNLOCK:
|
|
|
|
ret = tape_prepare (TAPE_UNLOCK);
|
|
|
|
break;
|
|
|
|
case MTLOAD:
|
|
|
|
ret = tape_prepare (TAPE_LOAD);
|
|
|
|
break;
|
|
|
|
case MTCOMPRESSION:
|
|
|
|
ret = tape_compression (op->mt_count);
|
|
|
|
break;
|
|
|
|
case MTSETPART:
|
2004-03-15 19:37:37 +08:00
|
|
|
ret = tape_set_partition (op->mt_count);
|
|
|
|
reset_devbuf ();
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
case MTMKPART:
|
2004-03-15 19:37:37 +08:00
|
|
|
ret = tape_partition (op->mt_count);
|
|
|
|
reset_devbuf ();
|
|
|
|
break;
|
2004-03-15 02:01:45 +08:00
|
|
|
case MTSETDENSITY:
|
|
|
|
case MTSETDRVBUFFER:
|
|
|
|
reset_devbuf ();
|
2000-02-18 03:38:33 +08:00
|
|
|
default:
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmd == MTIOCGET)
|
|
|
|
ret = tape_status ((struct mtget *) buf);
|
|
|
|
else if (cmd == MTIOCPOS)
|
|
|
|
{
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
if (buf && (ret = tape_get_pos (&block)))
|
|
|
|
((struct mtpos *) buf)->mt_blkno = block;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return fhandler_dev_raw::ioctl (cmd, buf);
|
|
|
|
|
|
|
|
if (ret != NO_ERROR)
|
|
|
|
{
|
|
|
|
SetLastError (ret);
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
/* Private functions used by `ioctl' */
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_error (const char *txt)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (lasterr)
|
2002-09-30 12:35:18 +08:00
|
|
|
debug_printf ("%s: error: %d", txt, lasterr);
|
2000-02-18 03:38:33 +08:00
|
|
|
return lasterr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_write_marks (int marktype, DWORD len)
|
|
|
|
{
|
2002-09-30 12:35:18 +08:00
|
|
|
syscall_printf ("write_tapemark");
|
2004-03-14 02:15:06 +08:00
|
|
|
TAPE_FUNC (WriteTapemark (get_handle (), marktype, len, FALSE));
|
|
|
|
return tape_error ("tape_write_marks");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-03-15 19:37:37 +08:00
|
|
|
fhandler_dev_tape::tape_get_pos (unsigned long *block,
|
|
|
|
unsigned long *partition)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
DWORD part, low, high;
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
lasterr = ERROR_INVALID_PARAMETER;
|
|
|
|
if (tape_get_feature (TAPE_DRIVE_GET_LOGICAL_BLK))
|
|
|
|
TAPE_FUNC (GetTapePosition (get_handle (), TAPE_LOGICAL_POSITION,
|
|
|
|
&part, &low, &high));
|
2004-03-15 19:37:37 +08:00
|
|
|
else if (tape_get_feature (TAPE_DRIVE_GET_ABSOLUTE_BLK))
|
|
|
|
TAPE_FUNC (GetTapePosition (get_handle (), TAPE_ABSOLUTE_POSITION,
|
|
|
|
&part, &low, &high));
|
2004-03-14 02:15:06 +08:00
|
|
|
|
2004-03-15 19:37:37 +08:00
|
|
|
if (!tape_error ("tape_get_pos"))
|
|
|
|
{
|
|
|
|
if (block)
|
|
|
|
*block = low;
|
|
|
|
if (partition)
|
|
|
|
*partition = part > 0 ? part - 1 : part;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return lasterr;
|
|
|
|
}
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
int
|
2004-03-15 19:37:37 +08:00
|
|
|
fhandler_dev_tape::_tape_set_pos (int mode, long count, int partition)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-03-15 19:37:37 +08:00
|
|
|
TAPE_FUNC (SetTapePosition (get_handle (), mode, partition, count,
|
2004-03-14 02:15:06 +08:00
|
|
|
count < 0 ? -1 : 0, FALSE));
|
|
|
|
/* Reset buffer after successful repositioning. */
|
|
|
|
if (!lasterr || IS_EOF (lasterr) || IS_EOM (lasterr))
|
|
|
|
{
|
|
|
|
reset_devbuf ();
|
|
|
|
eof_detected = IS_EOF (lasterr);
|
|
|
|
eom_detected = IS_EOM (lasterr);
|
|
|
|
}
|
|
|
|
return lasterr;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-12-08 06:37:12 +08:00
|
|
|
fhandler_dev_tape::tape_set_pos (int mode, long count, bool sfm_func)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case TAPE_SPACE_RELATIVE_BLOCKS:
|
|
|
|
case TAPE_SPACE_FILEMARKS:
|
2004-03-15 02:01:45 +08:00
|
|
|
if (!count)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-03-15 02:01:45 +08:00
|
|
|
lasterr = 0;
|
|
|
|
return tape_error ("tape_set_pos");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-15 02:01:45 +08:00
|
|
|
}
|
|
|
|
_tape_set_pos (mode, count);
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case TAPE_SPACE_FILEMARKS:
|
|
|
|
if (!lasterr && sfm_func)
|
|
|
|
return tape_set_pos (mode, count > 0 ? -1 : 1, false);
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2004-03-14 02:15:06 +08:00
|
|
|
return tape_error ("tape_set_pos");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_erase (int mode)
|
|
|
|
{
|
2004-03-15 19:37:37 +08:00
|
|
|
if (tape_set_pos (TAPE_REWIND, 0))
|
|
|
|
return lasterr;
|
2000-02-18 03:38:33 +08:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case TAPE_ERASE_SHORT:
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!tape_get_feature (TAPE_DRIVE_ERASE_SHORT))
|
2000-02-18 03:38:33 +08:00
|
|
|
mode = TAPE_ERASE_LONG;
|
|
|
|
break;
|
|
|
|
case TAPE_ERASE_LONG:
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!tape_get_feature (TAPE_DRIVE_ERASE_LONG))
|
2000-02-18 03:38:33 +08:00
|
|
|
mode = TAPE_ERASE_SHORT;
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 02:15:06 +08:00
|
|
|
TAPE_FUNC (EraseTape (get_handle (), mode, false));
|
|
|
|
/* Reset buffer after successful tape erasing. */
|
|
|
|
if (!lasterr)
|
|
|
|
reset_devbuf ();
|
|
|
|
return tape_error ("tape_erase");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_prepare (int action)
|
|
|
|
{
|
2004-03-14 02:15:06 +08:00
|
|
|
TAPE_FUNC (PrepareTape (get_handle (), action, FALSE));
|
|
|
|
/* Reset buffer after all successful preparations but lock and unlock. */
|
|
|
|
if (!lasterr && action != TAPE_LOCK && action != TAPE_UNLOCK)
|
|
|
|
reset_devbuf ();
|
|
|
|
return tape_error ("tape_prepare");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_set_blocksize (long count)
|
|
|
|
{
|
|
|
|
TAPE_SET_MEDIA_PARAMETERS mp;
|
|
|
|
|
|
|
|
mp.BlockSize = count;
|
2004-03-14 02:15:06 +08:00
|
|
|
TAPE_FUNC (SetTapeParameters (get_handle (), SET_TAPE_MEDIA_INFORMATION,
|
|
|
|
&mp));
|
|
|
|
return tape_error ("tape_set_blocksize");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_status (struct mtget *get)
|
|
|
|
{
|
|
|
|
DWORD varlen;
|
|
|
|
TAPE_GET_MEDIA_PARAMETERS mp;
|
|
|
|
int notape = 0;
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!get)
|
2000-02-18 03:38:33 +08:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
/* Setting varlen to sizeof DP is by intention, actually! Never set
|
2001-06-15 17:17:10 +08:00
|
|
|
it to sizeof MP which seems to be more correct but results in a
|
|
|
|
ERROR_MORE_DATA error at least on W2K. */
|
2004-03-14 02:15:06 +08:00
|
|
|
TAPE_FUNC (GetTapeParameters (get_handle (), GET_TAPE_MEDIA_INFORMATION,
|
|
|
|
(varlen = sizeof dp, &varlen), &mp));
|
|
|
|
if (lasterr)
|
2000-02-18 03:38:33 +08:00
|
|
|
notape = 1;
|
|
|
|
|
|
|
|
memset (get, 0, sizeof *get);
|
|
|
|
|
|
|
|
get->mt_type = MT_ISUNKNOWN;
|
|
|
|
|
2004-03-15 19:37:37 +08:00
|
|
|
if (!notape && tape_get_feature (TAPE_DRIVE_SET_BLOCK_SIZE))
|
2004-03-15 02:01:45 +08:00
|
|
|
get->mt_dsreg = (mp.BlockSize << MT_ST_BLKSIZE_SHIFT)
|
|
|
|
& MT_ST_BLKSIZE_MASK;
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2004-03-15 02:01:45 +08:00
|
|
|
get->mt_dsreg = (dp.DefaultBlockSize << MT_ST_BLKSIZE_SHIFT)
|
|
|
|
& MT_ST_BLKSIZE_MASK;
|
2004-03-15 19:37:37 +08:00
|
|
|
|
2004-03-15 02:01:45 +08:00
|
|
|
if (wincap.has_ioctl_storage_get_media_types_ex ())
|
|
|
|
{
|
|
|
|
DWORD size = sizeof (GET_MEDIA_TYPES) + 10 * sizeof (DEVICE_MEDIA_INFO);
|
|
|
|
void *buf = alloca (size);
|
|
|
|
if (DeviceIoControl (get_handle (), IOCTL_STORAGE_GET_MEDIA_TYPES_EX,
|
|
|
|
NULL, 0, buf, size, &size, NULL)
|
|
|
|
|| GetLastError () == ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
PGET_MEDIA_TYPES gmt = (PGET_MEDIA_TYPES) buf;
|
|
|
|
for (DWORD i = 0; i < gmt->MediaInfoCount; ++i)
|
|
|
|
{
|
|
|
|
PDEVICE_MEDIA_INFO dmi = &gmt->MediaInfo[i];
|
2004-03-15 19:37:37 +08:00
|
|
|
get->mt_type = dmi->DeviceSpecific.TapeInfo.MediaType;
|
2004-03-15 02:01:45 +08:00
|
|
|
#define TINFO DeviceSpecific.TapeInfo
|
|
|
|
if (dmi->TINFO.MediaCharacteristics & MEDIA_CURRENTLY_MOUNTED)
|
|
|
|
{
|
|
|
|
get->mt_type = dmi->DeviceSpecific.TapeInfo.MediaType;
|
|
|
|
if (dmi->TINFO.BusType == BusTypeScsi)
|
|
|
|
get->mt_dsreg |=
|
|
|
|
(dmi->TINFO.BusSpecificData.ScsiInformation.DensityCode
|
|
|
|
<< MT_ST_DENSITY_SHIFT)
|
|
|
|
& MT_ST_DENSITY_MASK;
|
2004-03-15 19:37:37 +08:00
|
|
|
break;
|
2004-03-15 02:01:45 +08:00
|
|
|
}
|
|
|
|
#undef TINFO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
if (notape)
|
|
|
|
get->mt_gstat |= GMT_DR_OPEN (-1);
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!notape)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-03-15 19:37:37 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_GET_LOGICAL_BLK)
|
|
|
|
|| tape_get_feature (TAPE_DRIVE_GET_ABSOLUTE_BLK))
|
|
|
|
tape_get_pos ((unsigned long *) &get->mt_blkno,
|
|
|
|
(unsigned long *) &get->mt_resid);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!get->mt_blkno)
|
2000-02-18 03:38:33 +08:00
|
|
|
get->mt_gstat |= GMT_BOT (-1);
|
|
|
|
|
|
|
|
get->mt_gstat |= GMT_ONLINE (-1);
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_WRITE_PROTECT) && mp.WriteProtected)
|
2000-02-18 03:38:33 +08:00
|
|
|
get->mt_gstat |= GMT_WR_PROT (-1);
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_TAPE_CAPACITY))
|
|
|
|
get->mt_capacity = get_ll (mp.Capacity);
|
2004-03-15 19:37:37 +08:00
|
|
|
|
|
|
|
if (tape_get_feature (TAPE_DRIVE_TAPE_REMAINING))
|
|
|
|
get->mt_remaining = get_ll (mp.Remaining);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_COMPRESSION) && dp.Compression)
|
2000-02-18 03:38:33 +08:00
|
|
|
get->mt_gstat |= GMT_HW_COMP (-1);
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_ECC) && dp.ECC)
|
2000-02-18 03:38:33 +08:00
|
|
|
get->mt_gstat |= GMT_HW_ECC (-1);
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_PADDING) && dp.DataPadding)
|
2000-02-18 03:38:33 +08:00
|
|
|
get->mt_gstat |= GMT_PADDING (-1);
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (tape_get_feature (TAPE_DRIVE_REPORT_SMKS) && dp.ReportSetmarks)
|
2000-02-18 03:38:33 +08:00
|
|
|
get->mt_gstat |= GMT_IM_REP_EN (-1);
|
|
|
|
|
|
|
|
get->mt_erreg = lasterr;
|
|
|
|
|
|
|
|
get->mt_minblksize = dp.MinimumBlockSize;
|
|
|
|
get->mt_maxblksize = dp.MaximumBlockSize;
|
|
|
|
get->mt_defblksize = dp.DefaultBlockSize;
|
|
|
|
get->mt_featureslow = dp.FeaturesLow;
|
|
|
|
get->mt_featureshigh = dp.FeaturesHigh;
|
2001-10-17 00:28:39 +08:00
|
|
|
get->mt_eotwarningzonesize = dp.EOTWarningZoneSize;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_compression (long count)
|
|
|
|
{
|
|
|
|
TAPE_SET_DRIVE_PARAMETERS dps;
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
if (!tape_get_feature (TAPE_DRIVE_COMPRESSION))
|
2000-02-18 03:38:33 +08:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2004-03-14 02:15:06 +08:00
|
|
|
dps.ECC = dp.ECC;
|
|
|
|
dps.Compression = count ? TRUE : FALSE;
|
|
|
|
dps.DataPadding = dp.DataPadding;
|
|
|
|
dps.ReportSetmarks = dp.ReportSetmarks;
|
|
|
|
dps.EOTWarningZoneSize = dp.EOTWarningZoneSize;
|
|
|
|
TAPE_FUNC (SetTapeParameters (get_handle (), SET_TAPE_DRIVE_INFORMATION,
|
|
|
|
&dps));
|
|
|
|
if (!lasterr)
|
|
|
|
dp.Compression = dps.Compression;
|
|
|
|
return tape_error ("tape_compression");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2004-03-15 19:37:37 +08:00
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_partition (long count)
|
|
|
|
{
|
|
|
|
if (dp.MaximumPartitionCount <= 1)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
if (tape_set_pos (TAPE_REWIND, 0))
|
|
|
|
return lasterr;
|
|
|
|
if (count <= 0)
|
|
|
|
debug_printf ("Formatting tape with one partition");
|
|
|
|
else
|
|
|
|
debug_printf ("Formatting tape with two partitions");
|
|
|
|
TAPE_FUNC (CreateTapePartition (get_handle (), TAPE_SELECT_PARTITIONS,
|
|
|
|
count <= 0 ? 1 : 2, 0));
|
|
|
|
return tape_error ("tape_partition");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_tape::tape_set_partition (long count)
|
|
|
|
{
|
|
|
|
if (count < 0 || (unsigned long) count >= dp.MaximumPartitionCount)
|
|
|
|
lasterr = ERROR_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
lasterr = _tape_set_pos (TAPE_LOGICAL_BLOCK, 0, count + 1);
|
|
|
|
return tape_error ("tape_set_partition");
|
|
|
|
}
|