Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create a fake stat record for drive letters.
While refactoring the code we seem to have lost the special case for a
drive letter only which needs special handling e.g. a fake stat
structure as most API calls on it will fail with a resource busy error.
  • Loading branch information
Marco van Wieringen committed May 12, 2014
1 parent ea9a242 commit 5cf22af
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/win32/compat/compat.c
Expand Up @@ -1159,8 +1159,8 @@ int fstat(intptr_t fd, struct stat *sb)
Dmsg1(dbglvl, "st_nlink=%d\n", sb->st_nlink);
}

sb->st_mode |= S_IFREG;
sb->st_mode = 0777;
sb->st_mode |= S_IFREG;

/*
* See if we need to encode in the old Bacula compatible way.
Expand Down Expand Up @@ -1341,12 +1341,32 @@ int stat(const char *filename, struct stat *sb)
* As get_windows_file_info() fills the complete stat structs we only need to perform the
* other part of the code when we don't call the get_windows_file_info() function.
*/
if (((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
(data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) &&
!is_drive_letter_only(filename)) {
rval = get_windows_file_info(filename, sb, (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
(data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
if (!is_drive_letter_only(filename)) {
rval = get_windows_file_info(filename, sb, (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
} else {
time_t now = time(NULL);

/*
* The windows API doesn't allow you the normal operations on just a drive letter
* e.g. you always get a resource busy message then so we fake the information for
* drive letter.
*/
sb->st_mode = 0777;
sb->st_mode |= S_IFDIR;
sb->st_rdev = 0;
sb->st_nlink = 1;
sb->st_size = 1;
sb->st_blksize = 4096;
sb->st_ctime = now;
sb->st_mtime = now;
sb->st_atime = now;
sb->st_blocks = (uint32_t)(sb->st_size + 4095) / 4096;
}
} else {
sb->st_mode = 0777;
sb->st_mode |= S_IFREG;

/*
* See if we need to encode in the old Bacula compatible way.
Expand All @@ -1360,12 +1380,6 @@ int stat(const char *filename, struct stat *sb)
*/
sb->st_rdev = data.dwFileAttributes;

if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sb->st_mode |= S_IFDIR;
} else {
sb->st_mode |= S_IFREG;
}

sb->st_nlink = 1;
sb->st_size = data.nFileSizeHigh;
sb->st_size <<= 32;
Expand Down

0 comments on commit 5cf22af

Please sign in to comment.