Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #2049 from janhenke/System.IO.FileSystem
Browse files Browse the repository at this point in the history
Implement System.IO.FileSystem assembly on FreeBSD
  • Loading branch information
stephentoub committed Jun 15, 2015
2 parents ec73071 + 1dd39be commit 6dba5e5
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/Common/src/Interop/FreeBSD/libc/Interop.PathConfNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

internal static partial class Interop
{
internal static partial class libc
{
internal static class PathConfNames
{
internal const int _PC_NAME_MAX = 4;
internal const int _PC_PATH_MAX = 5;
}

internal static int DEFAULT_PC_NAME_MAX = 255;
internal static int DEFAULT_PC_PATH_MAX = 1024;
}
}
51 changes: 51 additions & 0 deletions src/Common/src/Interop/FreeBSD/libc/Interop.readdir.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.InteropServices;

using ino_t = System.IntPtr;
using off_t = System.Int64; // Assuming either 64-bit machine or _FILE_OFFSET_BITS == 64

internal static partial class Interop
{
internal static partial class libc
{
[DllImport(Libraries.Libc, SetLastError = true)]
internal static extern IntPtr readdir(SafeDirHandle dirp);

internal static unsafe DType GetDirEntType(IntPtr dirEnt)
{
return ((dirent*)dirEnt)->d_type;
}

internal static unsafe string GetDirEntName(IntPtr dirEnt)
{
return Marshal.PtrToStringAnsi((IntPtr)((dirent*)dirEnt)->d_name);
}

internal enum DType : byte
{
DT_UNKNOWN = 0,
DT_FIFO = 1,
DT_CHR = 2,
DT_DIR = 4,
DT_BLK = 6,
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
DT_WHT = 14
}

#pragma warning disable 0649 // fields are assigned by P/Invoke call
private unsafe struct dirent
{
internal UInt32 d_fileno;
internal UInt16 d_reclen;
internal DType d_type;
internal byte d_namlen;
internal fixed byte d_name[256];
}
#pragma warning restore 0649
}
}
10 changes: 10 additions & 0 deletions src/System.IO.FileSystem/System.IO.FileSystem.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.IO.FileSystem.Tests"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
FreeBSD_Debug|Any CPU = FreeBSD_Debug|Any CPU
FreeBSD_Release|Any CPU = FreeBSD_Release|Any CPU
Linux_Debug|Any CPU = Linux_Debug|Any CPU
Linux_Release|Any CPU = Linux_Release|Any CPU
OSX_Debug|Any CPU = OSX_Debug|Any CPU
Expand All @@ -17,6 +19,10 @@ Global
Windows_Release|Any CPU = Windows_Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.FreeBSD_Debug|Any CPU.ActiveCfg = FreeBSD_Debug|Any CPU
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.FreeBSD_Debug|Any CPU.Build.0 = FreeBSD_Debug|Any CPU
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.FreeBSD_Release|Any CPU.ActiveCfg = FreeBSD_Release|Any CPU
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.FreeBSD_Release|Any CPU.Build.0 = FreeBSD_Release|Any CPU
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Linux_Debug|Any CPU.ActiveCfg = Linux_Debug|Any CPU
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Linux_Debug|Any CPU.Build.0 = Linux_Debug|Any CPU
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Linux_Release|Any CPU.ActiveCfg = Linux_Release|Any CPU
Expand All @@ -29,6 +35,10 @@ Global
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Windows_Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Windows_Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
{879C23DC-D828-4DFB-8E92-ABBC11B71035}.Windows_Release|Any CPU.Build.0 = Windows_Release|Any CPU
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.FreeBSD_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.FreeBSD_Debug|Any CPU.Build.0 = Debug|Any CPU
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.FreeBSD_Release|Any CPU.ActiveCfg = Release|Any CPU
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.FreeBSD_Release|Any CPU.Build.0 = Release|Any CPU
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.Linux_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.Linux_Debug|Any CPU.Build.0 = Debug|Any CPU
{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}.Linux_Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
30 changes: 27 additions & 3 deletions src/System.IO.FileSystem/src/System.IO.FileSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<DefineConstants>$(DefineConstants);USE_OVERLAPPED</DefineConstants>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'FreeBSD_Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'FreeBSD_Release|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux_Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux_Release|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'OSX_Debug|AnyCPU' " />
Expand Down Expand Up @@ -309,9 +311,31 @@
<Link>Common\System\IO\PathInternal.Unix.cs</Link>
</Compile>
</ItemGroup>
<!-- FreeBSD -->
<ItemGroup Condition="'$(TargetsFreeBSD)' == 'true'">
<Compile Include="System\IO\UnixFileStream.posix_fadvise.cs" />
<Compile Include="$(CommonPath)\System\IO\PathInternal.CaseSensitive.cs">
<Link>Common\System\IO\PathInternal.CaseSensitive.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\FreeBSD\Interop.Errors.cs">
<Link>Common\Interop\FreeBSD\Interop.Errors.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\FreeBSD\libc\Interop.readdir.cs">
<Link>Common\Interop\FreeBSD\Interop.readdir.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\FreeBSD\libc\Interop.OpenFlags.cs">
<Link>Common\Interop\FreeBSD\Interop.OpenFlags.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\FreeBSD\libc\Interop.PathConfNames.cs">
<Link>Common\Interop\FreeBSD\Interop.PathConfNames.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Unix\libc\Interop.posix_fadvise.cs">
<Link>Common\Interop\Unix\Interop.posix_fadvise.cs</Link>
</Compile>
</ItemGroup>
<!-- Linux -->
<ItemGroup Condition="'$(TargetsLinux)' == 'true'">
<Compile Include="System\IO\UnixFileStream.Linux.cs" />
<Compile Include="System\IO\UnixFileStream.posix_fadvise.cs" />
<Compile Include="$(CommonPath)\System\IO\PathInternal.CaseSensitive.cs">
<Link>Common\System\IO\PathInternal.CaseSensitive.cs</Link>
</Compile>
Expand All @@ -327,8 +351,8 @@
<Compile Include="$(CommonPath)\Interop\Linux\libc\Interop.PathConfNames.cs">
<Link>Common\Interop\Linux\Interop.PathConfNames.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Linux\libc\Interop.posix_fadvise.cs">
<Link>Common\Interop\Linux\Interop.posix_fadvise.cs</Link>
<Compile Include="$(CommonPath)\Interop\Unix\libc\Interop.posix_fadvise.cs">
<Link>Common\Interop\Unix\Interop.posix_fadvise.cs</Link>
</Compile>
</ItemGroup>
<!-- OSX -->
Expand Down

0 comments on commit 6dba5e5

Please sign in to comment.