Skip to content

Commit d9dd065

Browse files
joshpetersonUnityAlex
authored andcommitted
Handle the empty file inode on macOS and FAT32
On macOS and FAT32 partitions, we will sometimes get this inode value for more than one file. It means the file is empty. 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).
1 parent 4b29e9e commit d9dd065

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

mono/metadata/w32file-unix.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,22 @@ static mode_t convert_perms(guint32 sharemode)
18371837
}
18381838
#endif
18391839

1840+
static gboolean already_shared(gboolean file_alread_shared, ino_t inode)
1841+
{
1842+
#if PLATFORM_MACOSX
1843+
/* On macOS and FAT32 partitions, we will sometimes get this inode value
1844+
* for more than one file. It means the file is empty (FILENO_EMPTY is
1845+
* defined in an internal header). When this happens, the hash table of
1846+
* file shares becomes corrupt, since more then one file has the same
1847+
* inode. Instead, let's assume it is always fine to share empty files.
1848+
* (Unity case 950616).
1849+
*/
1850+
return file_alread_shared && inode != 999999999;
1851+
#else
1852+
return file_alread_shared;
1853+
#endif
1854+
}
1855+
18401856
static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
18411857
guint32 fileaccess,
18421858
FileShare **share_info)
@@ -1846,7 +1862,7 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
18461862

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

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

0 commit comments

Comments
 (0)