Skip to content

Commit

Permalink
Fix Android device issues related to filesystem/IO
Browse files Browse the repository at this point in the history
- Use F_SETLK64 for fcntl to fix an issue where 32bit arm Android apps would get the wrong flag
- Add numerical magic numbers for missing file systems to Interop.UnixFileSystemTypes so they are correctly recognized
- Make ping test a bit more forgiving if the process returns a few milliseconds _before_ the timeout
- Disable System.IO.Net5Compat.Tests.csproj on Helix for non-Windows platforms like intended, we were still building it since we pass `/p:ArchiveTests=true` on CI
  • Loading branch information
akoeplinger committed Sep 2, 2021
1 parent 49ea27e commit db5cf28
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static DriveType GetDriveType(string fileSystemName)
// This list is based primarily on "man fs", "man mount", "mntent.h", "/proc/filesystems", coreutils "stat.c",
// and "wiki.debian.org/FileSystem". It can be extended over time as we find additional file systems that should
// be recognized as a particular drive type.
// Keep this in sync with the UnixFileSystemTypes enum in Interop.UnixFileSystemTypes.cs
switch (fileSystemName)
{
case "cddafs":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal enum UnixFileSystemTypes : long
befs = 0x42465331,
bdevfs = 0x62646576,
bfs = 0x1BADFACE,
bpf_fs = 0xCAFE4A11,
binfmt_misc = 0x42494E4D,
bootfs = 0xA56D3FF9,
btrfs = 0x9123683E,
Expand All @@ -53,6 +54,7 @@ internal enum UnixFileSystemTypes : long
ext2 = 0xEF53,
ext3 = 0xEF53,
ext4 = 0xEF53,
f2fs = 0xF2F52010,
fat = 0x4006,
fd = 0xF00D1E,
fhgfs = 0x19830326,
Expand Down Expand Up @@ -122,6 +124,7 @@ internal enum UnixFileSystemTypes : long
sysv2 = 0x012FF7B6,
sysv4 = 0x012FF7B5,
tmpfs = 0x01021994,
tracefs = 0x74726163,
ubifs = 0x24051905,
udf = 0x15013346,
ufs = 0x00011954,
Expand Down
10 changes: 9 additions & 1 deletion src/libraries/Native/Unix/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,13 +1560,21 @@ int32_t SystemNative_LockFileRegion(intptr_t fd, int64_t offset, int64_t length,
struct flock lockArgs;
#endif

#if defined(TARGET_ANDROID) && defined(HAVE_FLOCK64)
// On Android, fcntl is always implemented by fcntl64 but before https://github.com/aosp-mirror/platform_bionic/commit/09e77f35ab8d291bf88302bb9673aaa518c6bcb0
// there was no remapping of F_SETLK to F_SETLK64 when _FILE_OFFSET_BITS=64 (which we set in eng/native/configurecompiler.cmake) so we need to always pass F_SETLK64
int command = F_SETLK64;
#else
int command = F_SETLK;
#endif

lockArgs.l_type = unixLockType;
lockArgs.l_whence = SEEK_SET;
lockArgs.l_start = (off_t)offset;
lockArgs.l_len = (off_t)length;

int32_t ret;
while ((ret = fcntl (ToFileDescriptor(fd), F_SETLK, &lockArgs)) < 0 && errno == EINTR);
while ((ret = fcntl (ToFileDescriptor(fd), command, &lockArgs)) < 0 && errno == EINTR);
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<!-- Windows is currently the only OS for which we provide a new strategy, so we test the Net5Compat only for Windows -->
<TargetFrameworks>$(NetCoreAppCurrent)-windows</TargetFrameworks>
<IgnoreForCI Condition="'$(TargetOS)' != 'windows'">true</IgnoreForCI>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\**\*.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static void TimeoutIsRespected(int timeout)
p.Start();
p.WaitForExit();

//ensure that the process takes longer than or equal to 'timeout'
Assert.True(stopWatch.ElapsedMilliseconds >= timeout);
//ensure that the process takes longer than or within 10ms of 'timeout', with a 5s maximum
Assert.InRange(stopWatch.ElapsedMilliseconds, timeout - 10, 5000);
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
Expand Down

0 comments on commit db5cf28

Please sign in to comment.