2000-02-17 20:38:33 +01:00
|
|
|
/* dir.cc: Posix directory-related routines
|
|
|
|
|
2002-01-13 21:03:03 +01:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
2000-02-17 20:38:33 +01: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-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#define _COMPILING_NEWLIB
|
2000-08-22 07:10:20 +02:00
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
#include "pinfo.h"
|
|
|
|
#include "cygerrno.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2000-08-22 07:10:20 +02: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 02:37:18 +02:00
|
|
|
#include "fhandler.h"
|
2001-04-18 23:10:15 +02:00
|
|
|
#include "dtable.h"
|
2000-11-14 06:53:32 +01:00
|
|
|
#include "cygheap.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Cygwin internal */
|
|
|
|
/* Return whether the directory of a file is writable. Return 1 if it
|
|
|
|
is. Otherwise, return 0, and set errno appropriately. */
|
|
|
|
int __stdcall
|
|
|
|
writable_directory (const char *file)
|
|
|
|
{
|
2000-05-24 22:09:43 +02:00
|
|
|
#if 0
|
2000-02-17 20:38:33 +01:00
|
|
|
char dir[strlen (file) + 1];
|
|
|
|
|
|
|
|
strcpy (dir, file);
|
|
|
|
|
|
|
|
const char *usedir;
|
|
|
|
char *slash = strrchr (dir, '\\');
|
|
|
|
if (slash == NULL)
|
|
|
|
usedir = ".";
|
2000-05-23 21:25:18 +02:00
|
|
|
else if (slash == dir)
|
|
|
|
{
|
|
|
|
usedir = "\\";
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*slash = '\0';
|
|
|
|
usedir = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
int acc = access (usedir, W_OK);
|
|
|
|
|
|
|
|
return acc == 0;
|
2000-05-24 22:09:43 +02:00
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2001-09-03 18:36:54 +02:00
|
|
|
extern "C" int
|
|
|
|
dirfd (DIR *dir)
|
|
|
|
{
|
2001-11-21 07:47:57 +01:00
|
|
|
if (check_null_invalid_struct_errno (dir))
|
|
|
|
return -1;
|
2001-09-03 18:36:54 +02:00
|
|
|
if (dir->__d_cookie != __DIRENT_COOKIE)
|
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
|
|
|
syscall_printf ("-1 = dirfd (%p)", dir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return dir->__d_dirent->d_fd;
|
|
|
|
}
|
|
|
|
|
2003-09-08 06:04:19 +02:00
|
|
|
enum opendir_states
|
|
|
|
{
|
|
|
|
opendir_ok = 0,
|
|
|
|
opendir_saw_dot = 1,
|
|
|
|
opendir_saw_dot_dot = 2,
|
|
|
|
opendir_saw_eof = 4
|
|
|
|
};
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* opendir: POSIX 5.1.2.1 */
|
|
|
|
extern "C" DIR *
|
2001-11-21 07:47:57 +01:00
|
|
|
opendir (const char *name)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-11-21 07:47:57 +01:00
|
|
|
fhandler_base *fh;
|
2001-12-06 00:05:15 +01:00
|
|
|
DIR *res;
|
2001-11-21 07:47:57 +01:00
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fh = build_fh_name (name, NULL, PC_SYM_FOLLOW | PC_FULL);
|
2001-12-06 00:05:15 +01:00
|
|
|
if (!fh)
|
|
|
|
res = NULL;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
else if (fh->exists ())
|
|
|
|
res = fh->opendir ();
|
2001-12-06 00:05:15 +01:00
|
|
|
else
|
|
|
|
{
|
2002-01-06 04:32:32 +01:00
|
|
|
set_errno (ENOENT);
|
|
|
|
res = NULL;
|
2001-12-06 00:05:15 +01:00
|
|
|
}
|
2002-01-06 04:32:32 +01:00
|
|
|
|
2003-09-08 06:04:19 +02:00
|
|
|
if (res)
|
|
|
|
res->__flags = 0;
|
|
|
|
else if (fh)
|
2002-01-06 04:32:32 +01:00
|
|
|
delete fh;
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readdir: POSIX 5.1.2.1 */
|
|
|
|
extern "C" struct dirent *
|
2001-11-21 07:47:57 +01:00
|
|
|
readdir (DIR *dir)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-11-21 07:47:57 +01:00
|
|
|
if (check_null_invalid_struct_errno (dir))
|
|
|
|
return NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (dir->__d_cookie != __DIRENT_COOKIE)
|
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
2001-11-21 07:47:57 +01:00
|
|
|
syscall_printf ("%p = readdir (%p)", NULL, dir);
|
|
|
|
return NULL;
|
2001-02-21 22:49:37 +01:00
|
|
|
}
|
|
|
|
|
2003-09-08 06:04:19 +02:00
|
|
|
dirent *res = ((fhandler_base *) dir->__fh)->readdir (dir);
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
if (!(dir->__flags & opendir_saw_dot))
|
|
|
|
{
|
|
|
|
res = dir->__d_dirent;
|
|
|
|
strcpy (res->d_name, ".");
|
|
|
|
dir->__flags |= opendir_saw_dot;
|
2003-09-10 22:16:00 +02:00
|
|
|
dir->__d_position++;
|
2003-09-08 06:04:19 +02:00
|
|
|
}
|
|
|
|
else if (!(dir->__flags & opendir_saw_dot_dot))
|
|
|
|
{
|
|
|
|
res = dir->__d_dirent;
|
|
|
|
strcpy (res->d_name, "..");
|
|
|
|
dir->__flags |= opendir_saw_dot_dot;
|
2003-09-10 22:16:00 +02:00
|
|
|
dir->__d_position++;
|
2003-09-08 06:04:19 +02:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 04:45:38 +02:00
|
|
|
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
/* Compute d_ino by combining filename hash with the directory hash
|
|
|
|
(which was stored in dir->__d_dirhash when opendir was called). */
|
|
|
|
if (res->d_name[0] == '.')
|
|
|
|
{
|
|
|
|
if (res->d_name[1] == '\0')
|
2003-09-08 06:04:19 +02:00
|
|
|
{
|
|
|
|
dir->__d_dirent->d_ino = dir->__d_dirhash;
|
|
|
|
dir->__flags |= opendir_saw_dot;
|
|
|
|
}
|
2002-06-01 04:45:38 +02:00
|
|
|
else if (res->d_name[1] != '.' || res->d_name[2] != '\0')
|
|
|
|
goto hashit;
|
|
|
|
else
|
|
|
|
{
|
2003-09-08 06:04:19 +02:00
|
|
|
dir->__flags |= opendir_saw_dot_dot;
|
2002-06-01 04:45:38 +02:00
|
|
|
char *p, up[strlen (dir->__d_dirname) + 1];
|
|
|
|
strcpy (up, dir->__d_dirname);
|
|
|
|
if (!(p = strrchr (up, '\\')))
|
|
|
|
goto hashit;
|
|
|
|
*p = '\0';
|
|
|
|
if (!(p = strrchr (up, '\\')))
|
|
|
|
dir->__d_dirent->d_ino = hash_path_name (0, ".");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
dir->__d_dirent->d_ino = hash_path_name (0, up);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hashit:
|
2003-05-11 23:52:09 +02:00
|
|
|
__ino64_t dino = hash_path_name (dir->__d_dirhash, "\\");
|
2002-06-01 04:45:38 +02:00
|
|
|
dir->__d_dirent->d_ino = hash_path_name (dino, res->d_name);
|
|
|
|
}
|
2003-09-09 02:21:16 +02:00
|
|
|
res->__ino32 = dir->__d_dirent->d_ino; // for legacy applications
|
2002-06-01 04:45:38 +02:00
|
|
|
}
|
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
extern "C" _off64_t
|
2002-02-25 18:47:51 +01:00
|
|
|
telldir64 (DIR *dir)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-11-21 07:47:57 +01:00
|
|
|
if (check_null_invalid_struct_errno (dir))
|
|
|
|
return -1;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
if (dir->__d_cookie != __DIRENT_COOKIE)
|
|
|
|
return 0;
|
2003-09-08 06:04:19 +02:00
|
|
|
return ((fhandler_base *) dir->__fh)->telldir (dir);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-02-25 18:47:51 +01:00
|
|
|
/* telldir */
|
2003-04-01 18:11:41 +02:00
|
|
|
extern "C" _off_t
|
2002-02-25 18:47:51 +01:00
|
|
|
telldir (DIR *dir)
|
|
|
|
{
|
|
|
|
return telldir64 (dir);
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
extern "C" void
|
2003-04-01 18:11:41 +02:00
|
|
|
seekdir64 (DIR *dir, _off64_t loc)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-11-21 07:47:57 +01:00
|
|
|
if (check_null_invalid_struct_errno (dir))
|
|
|
|
return;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
if (dir->__d_cookie != __DIRENT_COOKIE)
|
|
|
|
return;
|
2003-09-08 06:04:19 +02:00
|
|
|
dir->__flags = 0;
|
|
|
|
return ((fhandler_base *) dir->__fh)->seekdir (dir, loc);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-02-25 18:47:51 +01:00
|
|
|
/* seekdir */
|
|
|
|
extern "C" void
|
2003-04-01 18:11:41 +02:00
|
|
|
seekdir (DIR *dir, _off_t loc)
|
2002-02-25 18:47:51 +01:00
|
|
|
{
|
2003-04-01 18:11:41 +02:00
|
|
|
seekdir64 (dir, (_off64_t)loc);
|
2002-02-25 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* rewinddir: POSIX 5.1.2.1 */
|
|
|
|
extern "C" void
|
2001-11-21 07:47:57 +01:00
|
|
|
rewinddir (DIR *dir)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-11-21 07:47:57 +01:00
|
|
|
if (check_null_invalid_struct_errno (dir))
|
|
|
|
return;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (dir->__d_cookie != __DIRENT_COOKIE)
|
|
|
|
return;
|
2003-09-08 06:04:19 +02:00
|
|
|
dir->__flags = 0;
|
|
|
|
return ((fhandler_base *) dir->__fh)->rewinddir (dir);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* closedir: POSIX 5.1.2.1 */
|
|
|
|
extern "C" int
|
2001-11-21 07:47:57 +01:00
|
|
|
closedir (DIR *dir)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-11-21 07:47:57 +01:00
|
|
|
if (check_null_invalid_struct_errno (dir))
|
|
|
|
return -1;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
if (dir->__d_cookie != __DIRENT_COOKIE)
|
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
|
|
|
syscall_printf ("-1 = closedir (%p)", dir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the marker in case the caller tries to use `dir' again. */
|
|
|
|
dir->__d_cookie = 0;
|
|
|
|
|
2003-09-08 06:04:19 +02:00
|
|
|
int res = ((fhandler_base *) dir->__fh)->closedir (dir);
|
2001-11-21 07:47:57 +01:00
|
|
|
|
|
|
|
cygheap->fdtab.release (dir->__d_dirent->d_fd);
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
free (dir->__d_dirname);
|
|
|
|
free (dir->__d_dirent);
|
|
|
|
free (dir);
|
2001-11-21 07:47:57 +01:00
|
|
|
syscall_printf ("%d = closedir (%p)", res);
|
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mkdir: POSIX 5.4.1.1 */
|
|
|
|
extern "C" int
|
|
|
|
mkdir (const char *dir, mode_t mode)
|
|
|
|
{
|
|
|
|
int res = -1;
|
2001-08-07 17:09:54 +02:00
|
|
|
SECURITY_ATTRIBUTES sa = sec_none_nih;
|
2003-11-26 14:23:27 +01:00
|
|
|
security_descriptor sd;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-17 21:18:21 +02:00
|
|
|
path_conv real_dir (dir, PC_SYM_NOFOLLOW);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (real_dir.error)
|
|
|
|
{
|
2001-04-12 23:21:37 +02:00
|
|
|
set_errno (real_dir.case_clash ? ECASECLASH : real_dir.error);
|
2000-02-17 20:38:33 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-09-23 02:31:31 +02:00
|
|
|
nofinalslash (real_dir.get_win32 (), real_dir.get_win32 ());
|
2000-02-17 20:38:33 +01:00
|
|
|
if (! writable_directory (real_dir.get_win32 ()))
|
|
|
|
goto done;
|
|
|
|
|
2001-08-07 17:09:54 +02:00
|
|
|
if (allow_ntsec && real_dir.has_acls ())
|
2001-08-07 18:14:59 +02:00
|
|
|
set_security_attribute (S_IFDIR | ((mode & 07777) & ~cygheap->umask),
|
2003-11-26 14:23:27 +01:00
|
|
|
&sa, sd);
|
2001-08-07 17:09:54 +02:00
|
|
|
|
|
|
|
if (CreateDirectoryA (real_dir.get_win32 (), &sa))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-08-07 17:09:54 +02:00
|
|
|
if (!allow_ntsec && allow_ntea)
|
2004-04-13 22:36:58 +02:00
|
|
|
set_file_attribute (real_dir.has_acls (), NULL, real_dir.get_win32 (),
|
2001-08-07 18:14:59 +02:00
|
|
|
S_IFDIR | ((mode & 07777) & ~cygheap->umask));
|
2001-11-13 22:49:06 +01:00
|
|
|
#ifdef HIDDEN_DOT_FILES
|
|
|
|
char *c = strrchr (real_dir.get_win32 (), '\\');
|
|
|
|
if ((c && c[1] == '.') || *real_dir.get_win32 () == '.')
|
2002-05-28 03:55:40 +02:00
|
|
|
SetFileAttributes (real_dir.get_win32 (), FILE_ATTRIBUTE_HIDDEN);
|
2001-11-13 22:49:06 +01:00
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
__seterrno ();
|
|
|
|
|
|
|
|
done:
|
|
|
|
syscall_printf ("%d = mkdir (%s, %d)", res, dir, mode);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rmdir: POSIX 5.5.2.1 */
|
|
|
|
extern "C" int
|
|
|
|
rmdir (const char *dir)
|
|
|
|
{
|
|
|
|
int res = -1;
|
2002-06-05 18:01:55 +02:00
|
|
|
DWORD devn;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-03-14 17:16:45 +01:00
|
|
|
path_conv real_dir (dir, PC_SYM_NOFOLLOW | PC_FULL);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (real_dir.error)
|
2002-06-05 18:01:55 +02:00
|
|
|
set_errno (real_dir.error);
|
|
|
|
else if ((devn = real_dir.get_devn ()) == FH_PROC || devn == FH_REGISTRY
|
|
|
|
|| devn == FH_PROCESS)
|
|
|
|
set_errno (EROFS);
|
2001-10-01 06:10:07 +02:00
|
|
|
else if (!real_dir.exists ())
|
2002-06-05 18:01:55 +02:00
|
|
|
set_errno (ENOENT);
|
2001-10-01 06:10:07 +02:00
|
|
|
else if (!real_dir.isdir ())
|
2002-06-05 18:01:55 +02:00
|
|
|
set_errno (ENOTDIR);
|
2001-05-12 18:24:05 +02:00
|
|
|
else
|
2000-05-22 19:15:47 +02:00
|
|
|
{
|
2001-10-01 06:10:07 +02:00
|
|
|
/* Even own directories can't be removed if R/O attribute is set. */
|
|
|
|
if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY))
|
|
|
|
SetFileAttributes (real_dir,
|
2001-11-05 07:09:15 +01:00
|
|
|
(DWORD) real_dir & ~FILE_ATTRIBUTE_READONLY);
|
2001-10-01 06:10:07 +02:00
|
|
|
|
2004-03-14 17:16:45 +01:00
|
|
|
for (bool is_cwd = false; ; is_cwd = true)
|
|
|
|
{
|
2004-03-20 01:03:32 +01:00
|
|
|
DWORD err;
|
2004-03-14 17:16:45 +01:00
|
|
|
int rc = RemoveDirectory (real_dir);
|
|
|
|
DWORD att = GetFileAttributes (real_dir);
|
2003-09-11 16:43:09 +02:00
|
|
|
|
2004-03-14 17:16:45 +01:00
|
|
|
/* Sometimes smb indicates failure when it really succeeds, so check for
|
|
|
|
this case specifically. */
|
|
|
|
if (rc || att == INVALID_FILE_ATTRIBUTES)
|
2001-10-01 06:10:07 +02:00
|
|
|
{
|
2004-03-14 17:16:45 +01:00
|
|
|
/* RemoveDirectory on a samba drive doesn't return an error if the
|
|
|
|
directory can't be removed because it's not empty. Checking for
|
|
|
|
existence afterwards keeps us informed about success. */
|
2004-03-20 01:03:32 +01:00
|
|
|
if (att == INVALID_FILE_ATTRIBUTES)
|
2004-03-14 17:16:45 +01:00
|
|
|
{
|
2004-03-20 01:03:32 +01:00
|
|
|
res = 0;
|
|
|
|
break;
|
2004-03-14 17:16:45 +01:00
|
|
|
}
|
2004-03-20 01:03:32 +01:00
|
|
|
err = ERROR_DIR_NOT_EMPTY;
|
2002-06-05 18:01:55 +02:00
|
|
|
}
|
2004-03-20 01:03:32 +01:00
|
|
|
else
|
|
|
|
err = GetLastError ();
|
|
|
|
|
|
|
|
/* This kludge detects if we are attempting to remove the current working
|
|
|
|
directory. If so, we will move elsewhere to potentially allow the
|
|
|
|
rmdir to succeed. This means that cygwin's concept of the current working
|
|
|
|
directory != Windows concept but, hey, whaddaregonnado?
|
|
|
|
Note that this will not cause something like the following to work:
|
|
|
|
$ cd foo
|
|
|
|
$ rmdir .
|
|
|
|
since the shell will have foo "open" in the above case and so Windows will
|
|
|
|
not allow the deletion. (Actually it does on 9X.)
|
|
|
|
FIXME: A potential workaround for this is for cygwin apps to *never* call
|
|
|
|
SetCurrentDirectory. */
|
|
|
|
|
|
|
|
if (strcasematch (real_dir, cygheap->cwd.win32)
|
|
|
|
&& !strcasematch ("c:\\", cygheap->cwd.win32)
|
|
|
|
&& !is_cwd
|
|
|
|
&& SetCurrentDirectory ("c:\\"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* On 9X ERROR_ACCESS_DENIED is returned
|
|
|
|
if you try to remove a non-empty directory. */
|
|
|
|
if (err == ERROR_ACCESS_DENIED
|
|
|
|
&& wincap.access_denied_on_delete ())
|
|
|
|
err = ERROR_DIR_NOT_EMPTY;
|
|
|
|
|
|
|
|
__seterrno_from_win_error (err);
|
|
|
|
|
|
|
|
/* Directory still exists, restore its characteristics. */
|
|
|
|
if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY))
|
|
|
|
SetFileAttributes (real_dir, real_dir);
|
|
|
|
if (is_cwd)
|
|
|
|
SetCurrentDirectory (real_dir);
|
2004-03-14 17:16:45 +01:00
|
|
|
break;
|
2001-10-01 06:10:07 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2004-03-20 01:03:32 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
syscall_printf ("%d = rmdir (%s)", res, dir);
|
|
|
|
return res;
|
|
|
|
}
|