Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1dd39be

Browse files
committed
Implement System.IO.FileSystem assembly on FreeBSD
This adds the bits necessary to build the System.IO.FileSystem assembly for FreeBSD. I moved the Interop.posix_fdadvise.cs from Linux to Unix, since that system call is identical between Linux and FreeBSD. That file is only used for Linux and FreeBSD.
1 parent 7ea9cd5 commit 1dd39be

File tree

6 files changed

+105
-3
lines changed

6 files changed

+105
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
internal static partial class Interop
5+
{
6+
internal static partial class libc
7+
{
8+
internal static class PathConfNames
9+
{
10+
internal const int _PC_NAME_MAX = 4;
11+
internal const int _PC_PATH_MAX = 5;
12+
}
13+
14+
internal static int DEFAULT_PC_NAME_MAX = 255;
15+
internal static int DEFAULT_PC_PATH_MAX = 1024;
16+
}
17+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
using ino_t = System.IntPtr;
8+
using off_t = System.Int64; // Assuming either 64-bit machine or _FILE_OFFSET_BITS == 64
9+
10+
internal static partial class Interop
11+
{
12+
internal static partial class libc
13+
{
14+
[DllImport(Libraries.Libc, SetLastError = true)]
15+
internal static extern IntPtr readdir(SafeDirHandle dirp);
16+
17+
internal static unsafe DType GetDirEntType(IntPtr dirEnt)
18+
{
19+
return ((dirent*)dirEnt)->d_type;
20+
}
21+
22+
internal static unsafe string GetDirEntName(IntPtr dirEnt)
23+
{
24+
return Marshal.PtrToStringAnsi((IntPtr)((dirent*)dirEnt)->d_name);
25+
}
26+
27+
internal enum DType : byte
28+
{
29+
DT_UNKNOWN = 0,
30+
DT_FIFO = 1,
31+
DT_CHR = 2,
32+
DT_DIR = 4,
33+
DT_BLK = 6,
34+
DT_REG = 8,
35+
DT_LNK = 10,
36+
DT_SOCK = 12,
37+
DT_WHT = 14
38+
}
39+
40+
#pragma warning disable 0649 // fields are assigned by P/Invoke call
41+
private unsafe struct dirent
42+
{
43+
internal UInt32 d_fileno;
44+
internal UInt16 d_reclen;
45+
internal DType d_type;
46+
internal byte d_namlen;
47+
internal fixed byte d_name[256];
48+
}
49+
#pragma warning restore 0649
50+
}
51+
}

src/System.IO.FileSystem/System.IO.FileSystem.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.IO.FileSystem.Tests"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
FreeBSD_Debug|Any CPU = FreeBSD_Debug|Any CPU
13+
FreeBSD_Release|Any CPU = FreeBSD_Release|Any CPU
1214
Linux_Debug|Any CPU = Linux_Debug|Any CPU
1315
Linux_Release|Any CPU = Linux_Release|Any CPU
1416
OSX_Debug|Any CPU = OSX_Debug|Any CPU
@@ -17,6 +19,10 @@ Global
1719
Windows_Release|Any CPU = Windows_Release|Any CPU
1820
EndGlobalSection
1921
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.FreeBSD_Debug|Any CPU.ActiveCfg = FreeBSD_Debug|Any CPU
23+
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.FreeBSD_Debug|Any CPU.Build.0 = FreeBSD_Debug|Any CPU
24+
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.FreeBSD_Release|Any CPU.ActiveCfg = FreeBSD_Release|Any CPU
25+
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.FreeBSD_Release|Any CPU.Build.0 = FreeBSD_Release|Any CPU
2026
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Linux_Debug|Any CPU.ActiveCfg = Linux_Debug|Any CPU
2127
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Linux_Debug|Any CPU.Build.0 = Linux_Debug|Any CPU
2228
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Linux_Release|Any CPU.ActiveCfg = Linux_Release|Any CPU
@@ -29,6 +35,10 @@ Global
2935
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Windows_Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
3036
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Windows_Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
3137
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Windows_Release|Any CPU.Build.0 = Windows_Release|Any CPU
38+
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.FreeBSD_Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.FreeBSD_Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.FreeBSD_Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.FreeBSD_Release|Any CPU.Build.0 = Release|Any CPU
3242
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.Linux_Debug|Any CPU.ActiveCfg = Debug|Any CPU
3343
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.Linux_Debug|Any CPU.Build.0 = Debug|Any CPU
3444
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.Linux_Release|Any CPU.ActiveCfg = Release|Any CPU

src/System.IO.FileSystem/src/System.IO.FileSystem.csproj

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<DefineConstants>$(DefineConstants);USE_OVERLAPPED</DefineConstants>
1919
</PropertyGroup>
2020
<!-- Help VS understand available configurations -->
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'FreeBSD_Debug|AnyCPU' " />
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'FreeBSD_Release|AnyCPU' " />
2123
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux_Debug|AnyCPU' " />
2224
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux_Release|AnyCPU' " />
2325
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'OSX_Debug|AnyCPU' " />
@@ -309,9 +311,31 @@
309311
<Link>Common\System\IO\PathInternal.Unix.cs</Link>
310312
</Compile>
311313
</ItemGroup>
314+
<!-- FreeBSD -->
315+
<ItemGroup Condition="'$(TargetsFreeBSD)' == 'true'">
316+
<Compile Include="System\IO\UnixFileStream.posix_fadvise.cs" />
317+
<Compile Include="$(CommonPath)\System\IO\PathInternal.CaseSensitive.cs">
318+
<Link>Common\System\IO\PathInternal.CaseSensitive.cs</Link>
319+
</Compile>
320+
<Compile Include="$(CommonPath)\Interop\FreeBSD\Interop.Errors.cs">
321+
<Link>Common\Interop\FreeBSD\Interop.Errors.cs</Link>
322+
</Compile>
323+
<Compile Include="$(CommonPath)\Interop\FreeBSD\libc\Interop.readdir.cs">
324+
<Link>Common\Interop\FreeBSD\Interop.readdir.cs</Link>
325+
</Compile>
326+
<Compile Include="$(CommonPath)\Interop\FreeBSD\libc\Interop.OpenFlags.cs">
327+
<Link>Common\Interop\FreeBSD\Interop.OpenFlags.cs</Link>
328+
</Compile>
329+
<Compile Include="$(CommonPath)\Interop\FreeBSD\libc\Interop.PathConfNames.cs">
330+
<Link>Common\Interop\FreeBSD\Interop.PathConfNames.cs</Link>
331+
</Compile>
332+
<Compile Include="$(CommonPath)\Interop\Unix\libc\Interop.posix_fadvise.cs">
333+
<Link>Common\Interop\Unix\Interop.posix_fadvise.cs</Link>
334+
</Compile>
335+
</ItemGroup>
312336
<!-- Linux -->
313337
<ItemGroup Condition="'$(TargetsLinux)' == 'true'">
314-
<Compile Include="System\IO\UnixFileStream.Linux.cs" />
338+
<Compile Include="System\IO\UnixFileStream.posix_fadvise.cs" />
315339
<Compile Include="$(CommonPath)\System\IO\PathInternal.CaseSensitive.cs">
316340
<Link>Common\System\IO\PathInternal.CaseSensitive.cs</Link>
317341
</Compile>
@@ -327,8 +351,8 @@
327351
<Compile Include="$(CommonPath)\Interop\Linux\libc\Interop.PathConfNames.cs">
328352
<Link>Common\Interop\Linux\Interop.PathConfNames.cs</Link>
329353
</Compile>
330-
<Compile Include="$(CommonPath)\Interop\Linux\libc\Interop.posix_fadvise.cs">
331-
<Link>Common\Interop\Linux\Interop.posix_fadvise.cs</Link>
354+
<Compile Include="$(CommonPath)\Interop\Unix\libc\Interop.posix_fadvise.cs">
355+
<Link>Common\Interop\Unix\Interop.posix_fadvise.cs</Link>
332356
</Compile>
333357
</ItemGroup>
334358
<!-- OSX -->

0 commit comments

Comments
 (0)