/* Directories must be created with CreateDirectoryW(). Then the call
* to CreateFileW() will merely open the directory that was already
* created rather than creating a new file. */
- if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) {
+ if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY &&
+ !path_is_root_of_drive(path)) {
if (!CreateDirectoryW(path, NULL)) {
err = GetLastError();
- switch (err) {
- case ERROR_ALREADY_EXISTS:
- break;
- case ERROR_ACCESS_DENIED:
- if (path_is_root_of_drive(path))
- break;
- /* Fall through */
- default:
+ if (err != ERROR_ALREADY_EXISTS) {
ERROR("Failed to create directory \"%ls\"",
path);
win32_error(err);
/* Set file attributes if we created the file. Otherwise, we haven't
* created the file set and we will set the attributes in the call to
- * CreateFileW(). */
- if (*creationDisposition_ret == OPEN_EXISTING) {
+ * CreateFileW().
+ *
+ * The FAT filesystem does not let you change the attributes of the root
+ * directory, so treat that as a special case and do not set attributes.
+ * */
+ if (*creationDisposition_ret == OPEN_EXISTING &&
+ !path_is_root_of_drive(path))
+ {
if (!SetFileAttributesW(path,
win32_mask_attributes(inode->i_attributes)))
{
NULL);
if (h == INVALID_HANDLE_VALUE) {
err = GetLastError();
- if (err == ERROR_PRIVILEGE_NOT_HELD &&
+ if (err == ERROR_ACCESS_DENIED &&
+ path_is_root_of_drive(stream_path))
+ {
+ ret = 0;
+ goto out;
+ }
+ if ((err == ERROR_PRIVILEGE_NOT_HELD ||
+ err == ERROR_ACCESS_DENIED) &&
(requestedAccess & ACCESS_SYSTEM_SECURITY))
{
/* Try opening the file again without privilege to