aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2007-07-29 15:57:41 +0000
committerCorinna Vinschen <corinna@vinschen.de>2007-07-29 15:57:41 +0000
commit9d017bd09cf60644db45802bb2e5fd5ffaed619a (patch)
tree6ed2f4a2155f7e3c4a0e32901503681f92e23b8c /winsup
parented7ec849f625609f8c8e061386adfcb593fcd54a (diff)
downloadnewlib-9d017bd09cf60644db45802bb2e5fd5ffaed619a.zip
newlib-9d017bd09cf60644db45802bb2e5fd5ffaed619a.tar.gz
newlib-9d017bd09cf60644db45802bb2e5fd5ffaed619a.tar.bz2
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Don't allow
FileAttributes set to 0 when calling NtSetInformationFile since it has a special meaning. (fhandler_disk_file::facl): Ditto. (fhandler_disk_file::link): Only set attributes after copying files. Use SetFileAttributesW. * syscalls.cc (unlink_nt): Only care for actual FILE_ATTRIBUTE_READONLY. Don't allow FileAttributes set to 0 when calling NtSetInformationFile. After marking for deletion, restore R/O attribute on files to accommodate hardlinks.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog13
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc15
-rw-r--r--winsup/cygwin/syscalls.cc29
3 files changed, 38 insertions, 19 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 389ff85..dfb3e78 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,18 @@
2007-07-29 Corinna Vinschen <corinna@vinschen.de>
+ * fhandler_disk_file.cc (fhandler_disk_file::fchmod): Don't allow
+ FileAttributes set to 0 when calling NtSetInformationFile since it has
+ a special meaning.
+ (fhandler_disk_file::facl): Ditto.
+ (fhandler_disk_file::link): Only set attributes after copying files.
+ Use SetFileAttributesW.
+ * syscalls.cc (unlink_nt): Only care for actual FILE_ATTRIBUTE_READONLY.
+ Don't allow FileAttributes set to 0 when calling NtSetInformationFile.
+ After marking for deletion, restore R/O attribute on files to
+ accommodate hardlinks.
+
+2007-07-29 Corinna Vinschen <corinna@vinschen.de>
+
* fhandler_disk_file.cc (fhandler_disk_file::link): Use FILE_ANY_ACCESS.
(fhandler_base::utimes_fs): Fix white space.
(fhandler_disk_file::lock): Remove 9x blurb from comment.
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index 07e499e..46b178f 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -776,7 +776,7 @@ fhandler_disk_file::fchmod (mode_t mode)
FILE_BASIC_INFORMATION fbi;
fbi.CreationTime.QuadPart = fbi.LastAccessTime.QuadPart
= fbi.LastWriteTime.QuadPart = fbi.ChangeTime.QuadPart = 0LL;
- fbi.FileAttributes = pc.file_attributes ();
+ fbi.FileAttributes = pc.file_attributes () ?: FILE_ATTRIBUTE_NORMAL;
NTSTATUS status = NtSetInformationFile (get_handle (), &io, &fbi, sizeof fbi,
FileBasicInformation);
if (!NT_SUCCESS (status))
@@ -914,8 +914,9 @@ fhandler_disk_file::facl (int cmd, int nentries, __aclent32_t *aclbufp)
= fbi.LastAccessTime.QuadPart
= fbi.LastWriteTime.QuadPart
= fbi.ChangeTime.QuadPart = 0LL;
- fbi.FileAttributes = pc.file_attributes ()
- & ~FILE_ATTRIBUTE_READONLY;
+ fbi.FileAttributes = (pc.file_attributes ()
+ & ~FILE_ATTRIBUTE_READONLY)
+ ?: FILE_ATTRIBUTE_NORMAL;
NtSetInformationFile (get_handle (), &io, &fbi, sizeof fbi,
FileBasicInformation);
}
@@ -1124,6 +1125,10 @@ fhandler_disk_file::link (const char *newpath)
__seterrno ();
return -1;
}
+ if (!allow_winsymlinks && pc.is_lnk_special ())
+ SetFileAttributesW (newpcw, pc.file_attributes ()
+ | FILE_ATTRIBUTE_SYSTEM
+ | FILE_ATTRIBUTE_READONLY);
}
else
{
@@ -1131,10 +1136,6 @@ fhandler_disk_file::link (const char *newpath)
return -1;
}
}
- if (!allow_winsymlinks && pc.is_lnk_special ())
- SetFileAttributes (newpc, (DWORD) pc
- | FILE_ATTRIBUTE_SYSTEM
- | FILE_ATTRIBUTE_READONLY);
return 0;
}
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 8d1c2bb..83b7bbb 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -238,12 +238,10 @@ unlink_nt (path_conv &pc)
FILE_BASIC_INFORMATION fbi;
ACCESS_MASK access = DELETE;
- /* If one of the R/O attributes is set, we have to open the file with
- FILE_WRITE_ATTRIBUTES to be able to remove these flags before trying
+ /* If the R/O attribute is set, we have to open the file with
+ FILE_WRITE_ATTRIBUTES to be able to remove this flags before trying
to delete it. */
- if (pc.file_attributes () & (FILE_ATTRIBUTE_READONLY
- | FILE_ATTRIBUTE_SYSTEM
- | FILE_ATTRIBUTE_HIDDEN))
+ if (pc.file_attributes () & FILE_ATTRIBUTE_READONLY)
access |= FILE_WRITE_ATTRIBUTES;
ULONG flags = FILE_OPEN_FOR_BACKUP_INTENT;
@@ -330,16 +328,14 @@ unlink_nt (path_conv &pc)
if (move_to_bin && !pc.isremote ())
try_to_bin (pc, fh);
- /* Get rid of read-only attributes. */
+ /* Get rid of read-only attribute. */
if (access & FILE_WRITE_ATTRIBUTES)
{
FILE_BASIC_INFORMATION fbi;
fbi.CreationTime.QuadPart = fbi.LastAccessTime.QuadPart =
fbi.LastWriteTime.QuadPart = fbi.ChangeTime.QuadPart = 0LL;
- fbi.FileAttributes = pc.file_attributes ()
- & ~(FILE_ATTRIBUTE_READONLY
- | FILE_ATTRIBUTE_SYSTEM
- | FILE_ATTRIBUTE_HIDDEN);
+ fbi.FileAttributes = (pc.file_attributes () & ~FILE_ATTRIBUTE_READONLY)
+ ?: FILE_ATTRIBUTE_NORMAL;
NtSetInformationFile (fh, &io, &fbi, sizeof fbi, FileBasicInformation);
}
@@ -349,14 +345,23 @@ unlink_nt (path_conv &pc)
if (!NT_SUCCESS (status))
{
syscall_printf ("Setting delete disposition failed, status = %p", status);
- /* Restore R/O attributes. */
if (access & FILE_WRITE_ATTRIBUTES)
- {
+ {
+ /* Restore R/O attributes. */
fbi.FileAttributes = pc.file_attributes ();
NtSetInformationFile (fh, &io, &fbi, sizeof fbi,
FileBasicInformation);
}
}
+ else if ((access & FILE_WRITE_ATTRIBUTES) && !pc.isdir ())
+ {
+ /* Restore R/O attribute to accommodate hardlinks. Don't try this
+ with directories! For some reason the below NtSetInformationFile
+ changes the disposition for delete back to FALSE, at least on XP. */
+ fbi.FileAttributes = pc.file_attributes ();
+ NtSetInformationFile (fh, &io, &fbi, sizeof fbi,
+ FileBasicInformation);
+ }
NtClose (fh);
return status;