-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Initial commit of native shims building in corefx #2445
Changes from all commits
1f42d12
314d081
2715fe6
f802208
dfe7b80
4ae994a
e35129f
52f57e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // 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; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class NativeIO | ||
| { | ||
| internal struct FileStats | ||
| { | ||
| private FileStatsFlags Flags; | ||
| internal int Mode; | ||
| internal int Uid; | ||
| internal int Gid; | ||
| internal int Size; | ||
| internal int AccessTime; | ||
| internal int ModificationTime; | ||
| internal int StatusChangeTime; | ||
| internal int CreationTime; | ||
| } | ||
|
|
||
| internal static class FileTypes | ||
| { | ||
| internal const int S_IFMT = 0xF000; | ||
| internal const int S_IFIFO = 0x1000; | ||
| internal const int S_IFCHR = 0x2000; | ||
| internal const int S_IFDIR = 0x4000; | ||
| internal const int S_IFREG = 0x8000; | ||
| internal const int S_IFLNK = 0xA000; | ||
| } | ||
|
|
||
| [Flags] | ||
| internal enum FileStatsFlags | ||
| { | ||
| None = 0, | ||
| HasCreationTime = 1, | ||
| } | ||
|
|
||
| [DllImport(Libraries.IOInterop, SetLastError = true)] | ||
| internal static extern int FStat(int fileDescriptor, out FileStats output); | ||
|
|
||
| [DllImport(Libraries.IOInterop, SetLastError = true)] | ||
| internal static extern int Stat(string path, out FileStats output); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| cmake_minimum_required(VERSION 2.8.12) | ||
| project(CoreFX) | ||
|
|
||
| set(CMAKE_INSTALL_PREFIX $ENV{__CMakeBinDir}) | ||
| set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
| set(CMAKE_C_FLAGS "-std=c11") | ||
| set(CMAKE_CXX_FLAGS "-std=c++11") | ||
| set(CMAKE_SHARED_LIBRARY_PREFIX "") | ||
| add_compile_options(-Wall -Werror -fPIC) | ||
|
|
||
| if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64) | ||
| add_definitions(-DBIT64=1) | ||
| endif () | ||
|
|
||
| string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_CMAKE_BUILD_TYPE) | ||
| if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG) | ||
| add_compile_options(-g -O0) | ||
| add_definitions(-DDEBUG) | ||
| elseif (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE) | ||
| add_compile_options (-O3) | ||
| add_definitions(-DNDEBUG) | ||
| else () | ||
| message(FATAL_ERROR "Unknown build type. Set CMAKE_BUILD_TYPE to DEBUG or RELEASE.") | ||
| endif () | ||
|
|
||
| add_subdirectory(System.IO.Native) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| project(System.IO.Native) | ||
|
|
||
| set(NATIVEIO_SOURCES | ||
| nativeio.h | ||
| nativeio.cpp | ||
| ) | ||
|
|
||
| add_library(System.IO.Native | ||
| SHARED | ||
| ${NATIVEIO_SOURCES} | ||
| ) | ||
|
|
||
| install (TARGETS System.IO.Native DESTINATION .) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| #include "nativeio.h" | ||
| #include <sys/stat.h> | ||
|
|
||
| #if HAVE_STAT64 && !(defined(__APPLE__) && defined(_AMD64_)) | ||
| # define stat_ stat64 | ||
| # define fstat_ fstat64 | ||
| #else | ||
| # define stat_ stat | ||
| # define fstat_ fstat | ||
| #endif | ||
|
|
||
| static void ConvertFileStats(const struct stat_& src, FileStats* dst) | ||
| { | ||
| dst->Flags = FILESTATS_FLAGS_NONE; | ||
| dst->Mode = src.st_mode; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a TODO to ensure that the mode values are appropriately converted as needed?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also file a issue tracking any TODO's.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @weshaggard I'm not closing #2137 until these TODOs are done. I expect a lot of churn as this comes up and want to keep it moving forward incrementally. Separate issues for everything is going to be a bit painful. I've just added a comment to #2137 where I'll gather TODOs as they come up and make sure to drive the TODOs to zero before closing out the issue. Does that approach work for you?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that works for me thanks. |
||
| dst->Uid = src.st_uid; | ||
| dst->Gid = src.st_gid; | ||
| dst->Size = src.st_size; | ||
| dst->AccessTime = src.st_atime; | ||
| dst->ModificationTime = src.st_mtime; | ||
| dst->StatusChangeTime = src.st_ctime; | ||
|
|
||
| #if HAVE_STAT_BIRTHTIME | ||
| dst->CreationTime = src->st_birthtime; | ||
| dst->Flags |= FILESTATS_FLAGS_HAS_CREATION_TIME; | ||
| #endif | ||
| } | ||
|
|
||
| extern "C" | ||
| { | ||
| int32_t Stat(const char* path, struct FileStats* output) | ||
| { | ||
| struct stat_ result; | ||
| int ret = stat_(path, &result); | ||
|
|
||
| if (ret == 0) | ||
| { | ||
| ConvertFileStats(result, output); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a TODO for later about errno conversion? |
||
| return ret; // TODO: errno conversion | ||
| } | ||
|
|
||
| int32_t FStat(int32_t fileDescriptor, FileStats* output) | ||
| { | ||
| struct stat_ result; | ||
| int ret = fstat_(fileDescriptor, &result); | ||
|
|
||
| if (ret == 0) | ||
| { | ||
| ConvertFileStats(result, output); | ||
| } | ||
|
|
||
| return ret; // TODO: errno conversion | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| extern "C" | ||
| { | ||
| struct FileStats | ||
| { | ||
| int32_t Flags; // flags for testing if some members are present (see values below) | ||
| int32_t Mode; // protection | ||
| int32_t Uid; // user ID of owner | ||
| int32_t Gid; // group ID of owner | ||
| int64_t Size; // total size, in bytes | ||
| int64_t AccessTime; // time of last access (atime) | ||
| int64_t ModificationTime; // time of last modification (mtime) | ||
| int64_t StatusChangeTime; // time of last status change (ctime) | ||
| int64_t CreationTime; // time the file was created (birthtime) | ||
| }; | ||
|
|
||
| enum | ||
| { | ||
| FILESTATS_FLAGS_NONE = 0, | ||
| FILESTATS_FLAGS_HAS_CREATION_TIME = 1, | ||
| }; | ||
|
|
||
| /** | ||
| * Get file stats from a decriptor. Implemented as shim to fstat(2). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, a comment like that is what I was alluding to earlier. Thanks. |
||
| * | ||
| * Returns 0 for success, -1 for failure. Sets errno on failure. | ||
| */ | ||
| int32_t FStat(int32_t fileDescriptor, FileStats* output); | ||
|
|
||
| /** | ||
| * Get file stats from a full path. Implemented as shim to stat(2). | ||
| * | ||
| * Returns 0 for success, -1 for failure. Sets errno on failure. | ||
| */ | ||
| int32_t Stat(const char* path, FileStats* output); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be worth noting explicitly that this isn't just about Linux vs OS X vs FreeBSD vs... etc. It's also about 32-bit vs 64-bit, processor architecture, etc.