Skip to content

Commit 5174f7e

Browse files
joshpetersonJosh Peterson
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 1bc3c9a commit 5174f7e

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
@@ -1791,6 +1791,22 @@ static mode_t convert_perms(guint32 sharemode)
17911791
}
17921792
#endif
17931793

1794+
static gboolean already_shared(gboolean file_alread_shared, ino_t inode)
1795+
{
1796+
#if PLATFORM_MACOSX
1797+
/* On macOS and FAT32 partitions, we will sometimes get this inode value
1798+
* for more than one file. It means the file is empty (FILENO_EMPTY is
1799+
* defined in an internal header). When this happens, the hash table of
1800+
* file shares becomes corrupt, since more then one file has the same
1801+
* inode. Instead, let's assume it is always fine to share empty files.
1802+
* (Unity case 950616).
1803+
*/
1804+
return file_alread_shared && inode != 999999999;
1805+
#else
1806+
return file_alread_shared;
1807+
#endif
1808+
}
1809+
17941810
static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
17951811
guint32 fileaccess,
17961812
FileShare **share_info)
@@ -1800,7 +1816,7 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
18001816

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

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

0 commit comments

Comments
 (0)