Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the empty file inode on macOS and FAT32 #1200

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion mono/metadata/w32file-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,22 @@ static mode_t convert_perms(guint32 sharemode)
}
#endif

static gboolean already_shared(gboolean file_alread_shared, ino_t inode)
{
#if PLATFORM_MACOSX
/* On macOS and FAT32 partitions, we will sometimes get this inode value
* for more than one file. It means the file is empty (FILENO_EMPTY is
* defined in an internal header). When this happens, the hash table of
* file shares becomes corrupt, since more then one file has the same
* inode. Instead, let's assume it is always fine to share empty files.
* (Unity case 950616).
*/
return file_alread_shared && inode != 999999999;
#else
return file_alread_shared;
#endif
}

static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
guint32 fileaccess,
FileShare **share_info)
Expand All @@ -1800,7 +1816,7 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,

file_already_shared = file_share_get (statbuf->st_dev, statbuf->st_ino, sharemode, fileaccess, &file_existing_share, &file_existing_access, share_info);

if (file_already_shared) {
if (already_shared (file_already_shared, statbuf->st_ino)) {
/* The reference to this share info was incremented
* when we looked it up, so be careful to put it back
* if we conclude we can't use this file.
Expand Down