Changed everything to use base API type definitions, with

"using" as alias to .NET types.
This commit is contained in:
2015-05-07 05:31:02 +01:00
parent 0c42860fab
commit 6b4da34ab3
17 changed files with 887 additions and 546 deletions

View File

@@ -1,3 +1,24 @@
2015-05-07 Natalia Portillo <claunia@claunia.com>
* Claunia.IO.csproj:
* Interop/Apple/Interop.Apple.stat.cs:
* Interop/Apple/Interop.Apple.uname.cs:
* Interop/Apple/Interop.Apple.xattr.cs:
* Interop/Apple/Interop.Apple.types.cs:
* Interop/Apple/Interop.Apple.stat64.cs:
* Interop/Apple/Interop.Apple.statfs.cs:
* Interop/Windows/Interop.Windows.EAs.cs:
* Interop/Apple/Interop.Apple.statfs64.cs:
* Interop/Windows/Interop.Windows.Files.cs:
* Interop/Windows/Interop.Windows.types.cs:
* Interop/Windows/Interop.Windows.Backup.cs:
* Interop/Windows/Interop.Windows.Errors.cs:
* Interop/Apple/Interop.Apple.getattrlist.cs:
* Interop/Windows/Interop.Windows.Streams.cs:
* Interop/Windows/Interop.Windows.Volumes.cs:
Changed everything to use base API type definitions, with
"using" as alias to .NET types.
2015-05-07 Natalia Portillo <claunia@claunia.com>
* Tests/Interop.Apple.cs:

View File

@@ -75,6 +75,8 @@
<Compile Include="Interop\Windows\Interop.Windows.Streams.cs" />
<Compile Include="Interop\Windows\Interop.Windows.Backup.cs" />
<Compile Include="Interop\Windows\Interop.Windows.Volumes.cs" />
<Compile Include="Interop\Apple\Interop.Apple.stat64.cs" />
<Compile Include="Interop\Apple\Interop.Apple.statfs64.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

View File

@@ -23,8 +23,19 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
#region Mac OS X type definitions
using int32_t = System.Int32;
using u_int16_t = System.UInt16;
using u_int32_t = System.UInt32;
using u_short = System.UInt16;
// Only applicable to Mac OS X 32-bit ABI
using size_t = System.UInt32;
#endregion
internal static partial class Interop
{
@@ -40,12 +51,12 @@ internal static partial class Interop
/// Number of attr bit sets in list, ATTR_BIT_MAP_COUNT
/// </summary>
[MarshalAs(UnmanagedType.U2)]
public ushort bitmapCount;
public u_short bitmapCount;
/// <summary>
/// To maintain 4-byte alignment
/// </summary>
[MarshalAs(UnmanagedType.U2)]
public UInt16 reserved;
public u_int16_t reserved;
/// <summary>
/// Common attribut group
/// </summary>
@@ -83,12 +94,12 @@ internal static partial class Interop
/// Offset in bytes from this structure to the structure data
/// </summary>
[MarshalAs(UnmanagedType.I4)]
Int32 dataOffset;
int32_t dataOffset;
/// <summary>
/// Length of the attribute data in bytes, always alligned to 4 bytes.
/// </summary>
[MarshalAs(UnmanagedType.U4)]
UInt32 Length;
u_int32_t Length;
}
[StructLayout(LayoutKind.Sequential)]
@@ -103,17 +114,17 @@ internal static partial class Interop
/// Contains information about optional functions supported by the volume format implementation
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public UInt32 volCapabilitiesInterfaces;
public volCapabilitiesInterfaces_t volCapabilitiesInterfaces;
/// <summary>
/// Reserved, should be 0.
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public UInt32 volCapabilitiesReserved1;
public u_int32_t volCapabilitiesReserved1;
/// <summary>
/// Reserved, should be 0.
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public UInt32 volCapabilitiesReserved2;
public u_int32_t volCapabilitiesReserved2;
}
[StructLayout(LayoutKind.Sequential)]
@@ -577,7 +588,7 @@ internal static partial class Interop
}
[Flags]
internal enum volCapabilitiesFormat_t : uint
internal enum volCapabilitiesFormat_t : u_int32_t
{
/// <summary>
/// The volume supports persistent object identifiers
@@ -664,7 +675,7 @@ internal static partial class Interop
}
[Flags]
internal enum volCapabilitiesInterfaces_t : uint
internal enum volCapabilitiesInterfaces_t : u_int32_t
{
/// <summary>
/// The volume implementation supports searchfs(2)
@@ -743,7 +754,7 @@ internal static partial class Interop
/// <param name="options"><see cref="getAttrListOptions"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int getattrlist(string path, AttrList attrList, IntPtr attrBuf, UInt32 attrBufSize, UInt32 options);
public static extern int getattrlist(string path, AttrList attrList, IntPtr attrBuf, size_t attrBufSize, UInt32 options);
/// <summary>
/// Sets the specified lists of attributes for the file system object.
@@ -756,7 +767,7 @@ internal static partial class Interop
/// <param name="options"><see cref="getAttrListOptions"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int setattrlist(string path, AttrList attrList, IntPtr attrBuf, UInt32 attrBufSize, UInt32 options);
public static extern int setattrlist(string path, AttrList attrList, IntPtr attrBuf, size_t attrBufSize, UInt32 options);
}
}

View File

@@ -23,110 +23,34 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
#region Mac OS X 32-bit type definitions
using blkcnt_t = System.Int64;
using blksize_t = System.Int32;
using dev_t = System.Int32;
using gid_t = System.UInt32;
using ino_t = System.UInt32;
using int32_t = System.Int32;
using int64_t = System.Int64;
using nlink_t = System.UInt16;
using off_t = System.Int64;
using quad_t = System.Int64;
using size_t = System.UInt32;
using uid_t = System.UInt32;
using uint32_t = System.UInt32;
using u_int16_t = System.UInt16;
using u_int32_t = System.UInt32;
using u_long = System.UInt32;
using u_short = System.UInt16;
#endregion
internal static partial class Interop
{
internal static partial class Apple
{
/// <summary>
/// stat(2) structure when __DARWIN_64_BIT_INO_T is defined
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct Stat64
{
/// <summary>
/// ID of device containing file
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_dev;
/// <summary>
/// Mode of file
/// </summary>
[MarshalAs(UnmanagedType.U2)]
public mode_t st_mode;
/// <summary>
/// Number of hard links
/// </summary>
[MarshalAs(UnmanagedType.U2)]
public ushort st_nlink;
/// <summary>
/// File serial number
/// </summary>
[MarshalAs(UnmanagedType.U8)]
public ulong st_ino;
/// <summary>
/// User ID of the file
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_uid;
/// <summary>
/// Group ID of the file
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_gid;
/// <summary>
/// Device ID
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_rdev;
/// <summary>
/// time of last access
/// </summary>
public Timespec st_atimespec;
/// <summary>
/// time of last data modification
/// </summary>
public Timespec st_mtimespec;
/// <summary>
/// time of last status change
/// </summary>
public Timespec st_ctimespec;
/// <summary>
/// time of file creation(birth)
/// </summary>
public Timespec st_birthtimespec;
/// <summary>
/// file size, in bytes
/// </summary>
[MarshalAs(UnmanagedType.I8)]
public long st_size;
/// <summary>
/// blocks allocated for file
/// </summary>
[MarshalAs(UnmanagedType.I8)]
public long st_blocks;
/// <summary>
/// optimal blocksize for I/O
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_blksize;
/// <summary>
/// user defined flags for file
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public flags_t st_flags;
/// <summary>
/// file generation number
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_gen;
/// <summary>
/// Reserved: DO NOT USE
/// </summary>
[MarshalAs(UnmanagedType.U4)]
[Obsolete("RESERVED: DO NOT USE")]
public uint st_lspare;
/// <summary>
/// Reserved: DO NOT USE
/// </summary>
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.U8, SizeConst = 2)]
[Obsolete("RESERVED: DO NOT USE")]
public ulong[] st_qspare;
}
/// <summary>
/// stat(2) structure when __DARWIN_64_BIT_INO_T is NOT defined
/// </summary>
@@ -137,12 +61,12 @@ internal static partial class Interop
/// ID of device containing file
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_dev;
public dev_t st_dev;
/// <summary>
/// File serial number
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_ino;
public ino_t st_ino;
/// <summary>
/// Mode of file
/// </summary>
@@ -152,22 +76,22 @@ internal static partial class Interop
/// Number of hard links
/// </summary>
[MarshalAs(UnmanagedType.U2)]
public ushort st_nlink;
public nlink_t st_nlink;
/// <summary>
/// User ID of the file
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_uid;
public uid_t st_uid;
/// <summary>
/// Group ID of the file
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_gid;
public gid_t st_gid;
/// <summary>
/// Device ID
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_rdev;
public dev_t st_rdev;
/// <summary>
/// time of last access
/// </summary>
@@ -184,17 +108,17 @@ internal static partial class Interop
/// file size, in bytes
/// </summary>
[MarshalAs(UnmanagedType.I8)]
public long st_size;
public off_t st_size;
/// <summary>
/// blocks allocated for file
/// </summary>
[MarshalAs(UnmanagedType.I8)]
public long st_blocks;
public quad_t st_blocks;
/// <summary>
/// optimal blocksize for I/O
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_blksize;
public u_long st_blksize;
/// <summary>
/// user defined flags for file
/// </summary>
@@ -204,232 +128,7 @@ internal static partial class Interop
/// file generation number
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_gen;
/// <summary>
/// Reserved: DO NOT USE
/// </summary>
[MarshalAs(UnmanagedType.U4)]
[Obsolete("RESERVED: DO NOT USE")]
public uint st_lspare;
/// <summary>
/// Reserved: DO NOT USE
/// </summary>
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.U8, SizeConst = 2)]
[Obsolete("RESERVED: DO NOT USE")]
public ulong[] st_qspare;
}
/// <summary>
/// File mode and permissions
/// </summary>
[Flags]
internal enum mode_t : ushort
{
// File type
/// <summary>
/// File type mask
/// </summary>
S_IFMT = 0xF000,
/// <summary>
/// Named pipe (FIFO)
/// </summary>
S_IFIFO = 0x1000,
/// <summary>
/// Character device
/// </summary>
S_IFCHR = 0x2000,
/// <summary>
/// Directory
/// </summary>
S_IFDIR = 0x4000,
/// <summary>
/// Block device
/// </summary>
S_IFBLK = 0x6000,
/// <summary>
/// Regular file
/// </summary>
S_IFREG = 0x8000,
/// <summary>
/// Symbolic link
/// </summary>
S_IFLNK = 0xA000,
/// <summary>
/// Socket file
/// </summary>
S_IFSOCK = 0xC000,
/// <summary>
/// OBSOLETE: whiteout
/// </summary>
[Obsolete]
S_IFWHT = 0xE000,
// POSIX Permissions
/// <summary>
/// Owner permissions mask
/// </summary>
S_IRWXU = 0x01C0,
/// <summary>
/// Readable by owner
/// </summary>
S_IRUSR = 0x0100,
/// <summary>
/// Writable by owner
/// </summary>
S_IWUSR = 0x0080,
/// <summary>
/// Executable by owner
/// </summary>
S_IXUSR = 0x0040,
/// <summary>
/// Group permissions mask
/// </summary>
S_IRWXG = 0x0038,
/// <summary>
/// Readable by group
/// </summary>
S_IRGRP = 0x0020,
/// <summary>
/// Writable by group
/// </summary>
S_IWGRP = 0x0010,
/// <summary>
/// Executable by group
/// </summary>
S_IXGRP = 0x0008,
/// <summary>
/// Others permissions mask
/// </summary>
S_IRWXO = 0x0007,
/// <summary>
/// Readable by others
/// </summary>
S_IROTH = 0x0004,
/// <summary>
/// Writable by others
/// </summary>
S_IWOTH = 0x0002,
/// <summary>
/// Executable by others
/// </summary>
S_IXOTH = 0x0001,
/// <summary>
/// Set UID on execution
/// </summary>
S_ISUID = 0x0800,
/// <summary>
/// Set GID on execution
/// </summary>
S_ISGID = 0x0400,
/// <summary>
/// Only file/directory owners (or suser) can removed files from directory
/// </summary>
S_ISVTX = 0x0200,
/// <summary>
/// Sticky bit, not supported by OS X
/// </summary>
[Obsolete("Not supported under OS X")]
S_ISTXT = S_ISVTX,
/// <summary>
/// For backwards compatibility
/// </summary>
S_IREAD = S_IRUSR,
/// <summary>
/// For backwards compatibility
/// </summary>
S_IWRITE = S_IWUSR,
/// <summary>
/// For backwards compatibility
/// </summary>
S_IEXEC = S_IXUSR
}
/// <summary>
/// User-set flags
/// </summary>
[Flags]
internal enum flags_t : uint
{
/// <summary>
/// Mask of flags changeable by owner
/// </summary>
UF_SETTABLE = 0x0000FFFF,
/// <summary>
/// Do not dump file
/// </summary>
UF_NODUMP = 0x00000001,
/// <summary>
/// File is immutable (read-only)
/// </summary>
UF_IMMUTABLE = 0x00000002,
/// <summary>
/// File can only be appended
/// </summary>
UF_APPEND = 0x00000004,
/// <summary>
/// The directory is opaque when viewed through a union stack.
/// </summary>
UF_OPAQUE = 0x00000008,
/// <summary>
/// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X.
/// File cannot be removed or renamed.
/// </summary>
[Obsolete("Unimplemented in OS X")]
UF_NOUNLINK = 0x00000010,
/// <summary>
/// File is compressed in HFS+ (>=10.6)
/// </summary>
UF_COMPRESSED = 0x00000020,
/// <summary>
/// OBSOLETE: No longer used.
/// Issue notifications for deletes or renames of files with this flag set
/// </summary>
[Obsolete("No longer used")]
UF_TRACKED = 0x00000040,
/// <summary>
/// Hide the file in Finder
/// </summary>
UF_HIDDEN = 0x00008000,
/// <summary>
/// Mask of flags changeable by the superuser
/// </summary>
SF_SETTABLE = 0xffff0000,
/// <summary>
/// File has been archived
/// </summary>
SF_ARCHIVED = 0x00010000,
/// <summary>
/// File is immutable (read-only)
/// </summary>
SF_IMMUTABLE = 0x00020000,
/// <summary>
/// File can only be appended
/// </summary>
SF_APPEND = 0x00040000,
/// <summary>
/// Restricted access
/// </summary>
SF_RESTRICTED = 0x00080000,
/// <summary>
/// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X.
/// File cannot be removed or renamed.
/// </summary>
[Obsolete("Unimplemented in OS X")]
SF_NOUNLINK = 0x00100000,
/// <summary>
/// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X.
/// Snapshot inode
/// </summary>
[Obsolete("Unimplemented in OS X")]
SF_SNAPSHOT = 0x00200000
public u_long st_gen;
}
/// <summary>
@@ -441,16 +140,6 @@ internal static partial class Interop
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int stat(string path, out Stat buf);
/// <summary>
/// Obtains information of the file pointed by <paramref name="path"/>.
/// Calls to system's stat64(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="buf"><see cref="Stat64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int stat64(string path, out Stat64 buf);
}
}

View File

@@ -0,0 +1,159 @@
//
// Interop.Apple.stat64.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// Copyright (c) 2015 © Claunia.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
#region Mac OS X 64-bit type definitions
using blkcnt_t = System.Int64;
using blksize_t = System.Int32;
using dev_t = System.Int32;
using gid_t = System.UInt32;
using ino_t = System.UInt64;
using int32_t = System.Int32;
using int64_t = System.Int64;
using nlink_t = System.UInt16;
using off_t = System.Int64;
using uid_t = System.UInt32;
using uint32_t = System.UInt32;
using u_int16_t = System.UInt16;
using u_int32_t = System.UInt32;
using u_short = System.UInt16;
#endregion
internal static partial class Interop
{
internal static partial class Apple
{
/// <summary>
/// stat(2) structure when __DARWIN_64_BIT_INO_T is defined
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct Stat64
{
/// <summary>
/// ID of device containing file
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_dev;
/// <summary>
/// Mode of file
/// </summary>
[MarshalAs(UnmanagedType.U2)]
public mode_t st_mode;
/// <summary>
/// Number of hard links
/// </summary>
[MarshalAs(UnmanagedType.U2)]
public ushort st_nlink;
/// <summary>
/// File serial number
/// </summary>
[MarshalAs(UnmanagedType.U8)]
public ulong st_ino;
/// <summary>
/// User ID of the file
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_uid;
/// <summary>
/// Group ID of the file
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_gid;
/// <summary>
/// Device ID
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_rdev;
/// <summary>
/// time of last access
/// </summary>
public Timespec st_atimespec;
/// <summary>
/// time of last data modification
/// </summary>
public Timespec st_mtimespec;
/// <summary>
/// time of last status change
/// </summary>
public Timespec st_ctimespec;
/// <summary>
/// time of file creation(birth)
/// </summary>
public Timespec st_birthtimespec;
/// <summary>
/// file size, in bytes
/// </summary>
[MarshalAs(UnmanagedType.I8)]
public long st_size;
/// <summary>
/// blocks allocated for file
/// </summary>
[MarshalAs(UnmanagedType.I8)]
public long st_blocks;
/// <summary>
/// optimal blocksize for I/O
/// </summary>
[MarshalAs(UnmanagedType.I4)]
public int st_blksize;
/// <summary>
/// user defined flags for file
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public flags_t st_flags;
/// <summary>
/// file generation number
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint st_gen;
/// <summary>
/// Reserved: DO NOT USE
/// </summary>
[MarshalAs(UnmanagedType.U4)]
[Obsolete("RESERVED: DO NOT USE")]
public uint st_lspare;
/// <summary>
/// Reserved: DO NOT USE
/// </summary>
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.U8, SizeConst = 2)]
[Obsolete("RESERVED: DO NOT USE")]
public ulong[] st_qspare;
}
/// <summary>
/// Obtains information of the file pointed by <paramref name="path"/>.
/// Calls to system's stat64(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="buf"><see cref="Stat64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int stat64(string path, out Stat64 buf);
}
}

View File

@@ -1,5 +1,5 @@
//
// Interop.Apple.stat.cs
// Interop.Apple.statfs.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
@@ -23,8 +23,13 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
#region Mac OS X type definitions
using uid_t = System.UInt32;
#endregion
internal static partial class Interop
{
@@ -34,7 +39,7 @@ internal static partial class Interop
/// statfs(2) structure when _DARWIN_FEATURE_64_BIT_INODE is defined
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct StatFS64
internal struct StatFS
{
/// <summary>
/// Type of file system (reserved: zero)
@@ -89,7 +94,7 @@ internal static partial class Interop
/// User that mounted the file system
/// </summary>
[MarshalAs(UnmanagedType.U4)]
UInt32 f_owner;
uid_t f_owner;
/// <summary>
/// Reserved for future use
/// </summary>
@@ -142,84 +147,6 @@ internal static partial class Interop
Int64[] f_reserved4;
}
/// <summary>
/// statfs(2) structure when _DARWIN_FEATURE_64_BIT_INODE is NOT defined
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct StatFS
{
/// <summary>
/// Fundamental file system block size
/// </summary>
UInt32 f_bsize;
/// <summary>
/// Optimal transfer block size
/// </summary>
Int32 f_iosize;
/// <summary>
/// Total data blocks in file system
/// </summary>
UInt64 f_blocks;
/// <summary>
/// Free blocks in file system
/// </summary>
UInt64 f_bfree;
/// <summary>
/// Free blocks avail to non-superuser
/// </summary>
UInt64 f_bavail;
/// <summary>
/// Total file nodes in file system
/// </summary>
UInt64 f_files;
/// <summary>
/// Free file nodes in file system
/// </summary>
UInt64 f_ffree;
/// <summary>
/// File system id
/// </summary>
fsid_t f_fsid;
/// <summary>
/// User that mounted the filesystem
/// </summary>
UInt32 f_owner;
/// <summary>
/// Type of filesystem
/// </summary>
UInt32 f_type;
/// <summary>
/// Copy of mount exported flags
/// </summary>
UInt32 f_flags;
/// <summary>
/// File system sub-type (flavor)
/// </summary>
UInt32 f_fssubtype;
/// <summary>
/// File system type name
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
string f_fstypename;
/// <summary>
/// Directory on which mounted
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
string f_mntonname;
/// <summary>
/// Mounted file system
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
string f_mntfromname;
/// <summary>
/// For future use
/// </summary>
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.I8, SizeConst = 8)]
[Obsolete("RESERVED: DO NOT USE")]
UInt32[] f_reserved;
}
/// <summary>
/// Obtains information of the file system mounted at <paramref name="path"/>.
/// Calls to system's statfs(2)
@@ -229,16 +156,6 @@ internal static partial class Interop
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int statfs(string path, out StatFS buf);
/// <summary>
/// Obtains information of the file system mounted at <paramref name="path"/>.
/// Calls to system's statfs64(2)
/// </summary>
/// <param name="path">Path to the filesystem mount point.</param>
/// <param name="buf"><see cref="Stat64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int statfs64(string path, out StatFS64 buf);
}
}

View File

@@ -0,0 +1,130 @@
//
// Interop.Apple.statfs64.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// Copyright (c) 2015 © Claunia.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
#region Mac OS X type definitions
using int32_t = System.Int32;
using uid_t = System.UInt32;
using uint32_t = System.UInt32;
using uint64_t = System.UInt64;
#endregion
internal static partial class Interop
{
internal static partial class Apple
{
/// <summary>
/// statfs(2) structure when _DARWIN_FEATURE_64_BIT_INODE is NOT defined
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct StatFS64
{
/// <summary>
/// Fundamental file system block size
/// </summary>
uint32_t f_bsize;
/// <summary>
/// Optimal transfer block size
/// </summary>
int32_t f_iosize;
/// <summary>
/// Total data blocks in file system
/// </summary>
uint64_t f_blocks;
/// <summary>
/// Free blocks in file system
/// </summary>
uint64_t f_bfree;
/// <summary>
/// Free blocks avail to non-superuser
/// </summary>
uint64_t f_bavail;
/// <summary>
/// Total file nodes in file system
/// </summary>
uint64_t f_files;
/// <summary>
/// Free file nodes in file system
/// </summary>
uint64_t f_ffree;
/// <summary>
/// File system id
/// </summary>
fsid_t f_fsid;
/// <summary>
/// User that mounted the filesystem
/// </summary>
uid_t f_owner;
/// <summary>
/// Type of filesystem
/// </summary>
UInt32 f_type;
/// <summary>
/// Copy of mount exported flags
/// </summary>
UInt32 f_flags;
/// <summary>
/// File system sub-type (flavor)
/// </summary>
UInt32 f_fssubtype;
/// <summary>
/// File system type name
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
string f_fstypename;
/// <summary>
/// Directory on which mounted
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
string f_mntonname;
/// <summary>
/// Mounted file system
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
string f_mntfromname;
/// <summary>
/// For future use
/// </summary>
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.I8, SizeConst = 8)]
[Obsolete("RESERVED: DO NOT USE")]
uint32_t[] f_reserved;
}
/// <summary>
/// Obtains information of the file system mounted at <paramref name="path"/>.
/// Calls to system's statfs64(2)
/// </summary>
/// <param name="path">Path to the filesystem mount point.</param>
/// <param name="buf"><see cref="Stat64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int statfs64(string path, out StatFS64 buf);
}
}

View File

@@ -30,6 +30,218 @@ internal static partial class Interop
{
internal static partial class Apple
{
/// <summary>
/// File mode and permissions
/// </summary>
[Flags]
internal enum mode_t : ushort
{
// File type
/// <summary>
/// File type mask
/// </summary>
S_IFMT = 0xF000,
/// <summary>
/// Named pipe (FIFO)
/// </summary>
S_IFIFO = 0x1000,
/// <summary>
/// Character device
/// </summary>
S_IFCHR = 0x2000,
/// <summary>
/// Directory
/// </summary>
S_IFDIR = 0x4000,
/// <summary>
/// Block device
/// </summary>
S_IFBLK = 0x6000,
/// <summary>
/// Regular file
/// </summary>
S_IFREG = 0x8000,
/// <summary>
/// Symbolic link
/// </summary>
S_IFLNK = 0xA000,
/// <summary>
/// Socket file
/// </summary>
S_IFSOCK = 0xC000,
/// <summary>
/// OBSOLETE: whiteout
/// </summary>
[Obsolete]
S_IFWHT = 0xE000,
// POSIX Permissions
/// <summary>
/// Owner permissions mask
/// </summary>
S_IRWXU = 0x01C0,
/// <summary>
/// Readable by owner
/// </summary>
S_IRUSR = 0x0100,
/// <summary>
/// Writable by owner
/// </summary>
S_IWUSR = 0x0080,
/// <summary>
/// Executable by owner
/// </summary>
S_IXUSR = 0x0040,
/// <summary>
/// Group permissions mask
/// </summary>
S_IRWXG = 0x0038,
/// <summary>
/// Readable by group
/// </summary>
S_IRGRP = 0x0020,
/// <summary>
/// Writable by group
/// </summary>
S_IWGRP = 0x0010,
/// <summary>
/// Executable by group
/// </summary>
S_IXGRP = 0x0008,
/// <summary>
/// Others permissions mask
/// </summary>
S_IRWXO = 0x0007,
/// <summary>
/// Readable by others
/// </summary>
S_IROTH = 0x0004,
/// <summary>
/// Writable by others
/// </summary>
S_IWOTH = 0x0002,
/// <summary>
/// Executable by others
/// </summary>
S_IXOTH = 0x0001,
/// <summary>
/// Set UID on execution
/// </summary>
S_ISUID = 0x0800,
/// <summary>
/// Set GID on execution
/// </summary>
S_ISGID = 0x0400,
/// <summary>
/// Only file/directory owners (or suser) can removed files from directory
/// </summary>
S_ISVTX = 0x0200,
/// <summary>
/// Sticky bit, not supported by OS X
/// </summary>
[Obsolete("Not supported under OS X")]
S_ISTXT = S_ISVTX,
/// <summary>
/// For backwards compatibility
/// </summary>
S_IREAD = S_IRUSR,
/// <summary>
/// For backwards compatibility
/// </summary>
S_IWRITE = S_IWUSR,
/// <summary>
/// For backwards compatibility
/// </summary>
S_IEXEC = S_IXUSR
}
/// <summary>
/// User-set flags
/// </summary>
[Flags]
internal enum flags_t : uint
{
/// <summary>
/// Mask of flags changeable by owner
/// </summary>
UF_SETTABLE = 0x0000FFFF,
/// <summary>
/// Do not dump file
/// </summary>
UF_NODUMP = 0x00000001,
/// <summary>
/// File is immutable (read-only)
/// </summary>
UF_IMMUTABLE = 0x00000002,
/// <summary>
/// File can only be appended
/// </summary>
UF_APPEND = 0x00000004,
/// <summary>
/// The directory is opaque when viewed through a union stack.
/// </summary>
UF_OPAQUE = 0x00000008,
/// <summary>
/// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X.
/// File cannot be removed or renamed.
/// </summary>
[Obsolete("Unimplemented in OS X")]
UF_NOUNLINK = 0x00000010,
/// <summary>
/// File is compressed in HFS+ (>=10.6)
/// </summary>
UF_COMPRESSED = 0x00000020,
/// <summary>
/// OBSOLETE: No longer used.
/// Issue notifications for deletes or renames of files with this flag set
/// </summary>
[Obsolete("No longer used")]
UF_TRACKED = 0x00000040,
/// <summary>
/// Hide the file in Finder
/// </summary>
UF_HIDDEN = 0x00008000,
/// <summary>
/// Mask of flags changeable by the superuser
/// </summary>
SF_SETTABLE = 0xffff0000,
/// <summary>
/// File has been archived
/// </summary>
SF_ARCHIVED = 0x00010000,
/// <summary>
/// File is immutable (read-only)
/// </summary>
SF_IMMUTABLE = 0x00020000,
/// <summary>
/// File can only be appended
/// </summary>
SF_APPEND = 0x00040000,
/// <summary>
/// Restricted access
/// </summary>
SF_RESTRICTED = 0x00080000,
/// <summary>
/// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X.
/// File cannot be removed or renamed.
/// </summary>
[Obsolete("Unimplemented in OS X")]
SF_NOUNLINK = 0x00100000,
/// <summary>
/// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X.
/// Snapshot inode
/// </summary>
[Obsolete("Unimplemented in OS X")]
SF_SNAPSHOT = 0x00200000
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal struct Timespec
{

View File

@@ -23,7 +23,6 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
internal static partial class Interop

View File

@@ -26,6 +26,28 @@
using System;
using System.Runtime.InteropServices;
#region Mac OS X 32-bit type definitions
using blkcnt_t = System.Int64;
using blksize_t = System.Int32;
using dev_t = System.Int32;
using gid_t = System.UInt32;
using ino_t = System.UInt32;
using int32_t = System.Int32;
using int64_t = System.Int64;
using nlink_t = System.UInt16;
using off_t = System.Int64;
using quad_t = System.Int64;
using size_t = System.UInt32;
using uid_t = System.UInt32;
using uint32_t = System.UInt32;
using u_int16_t = System.UInt16;
using u_int32_t = System.UInt32;
using u_long = System.UInt32;
using u_short = System.UInt16;
#endregion
internal static partial class Interop
{
internal static partial class Apple
@@ -84,7 +106,7 @@ internal static partial class Interop
/// <param name="options"><see cref="xattrOptions"/>.</param>
/// <returns>Size of the extended attribute. On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int getxattr(string path, string name, IntPtr value, UInt32 size, UInt32 position, xattrOptions options);
public static extern int getxattr(string path, string name, IntPtr value, size_t size, u_int32_t position, xattrOptions options);
/// <summary>
/// Sets an extended attribute value
@@ -98,7 +120,7 @@ internal static partial class Interop
/// <param name="options"><see cref="xattrOptions"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int setxattr(string path, string name, IntPtr value, UInt32 size, UInt32 position, xattrOptions options);
public static extern int setxattr(string path, string name, IntPtr value, size_t size, u_int32_t position, xattrOptions options);
/// <summary>
/// Removes an extended attribute
@@ -124,7 +146,7 @@ internal static partial class Interop
/// If the file has no extended attributes, 0.
/// On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int listxattr(string path, IntPtr namebuf, UInt32 size, xattrOptions options);
public static extern int listxattr(string path, IntPtr namebuf, size_t size, xattrOptions options);
}
}

View File

@@ -23,10 +23,39 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
#region Win32 type definitions
using BOOL = System.Boolean;
using BOOLEAN = System.Boolean;
using CCHAR = System.SByte;
using CHAR = System.Byte;
using DWORD = System.UInt32;
using FILE_ID_128 = System.Guid;
using HANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using LARGE_INTEGER = System.Int64;
using LONGLONG = System.Int64;
using LPBYTE = System.IntPtr;
using LPCTSTR = System.String;
using LPCWSTR = System.String;
using LPDWORD = System.UInt32;
using LPTSTR = System.Text.StringBuilder;
using LPVOID = System.IntPtr;
using PHANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using PLARGE_INTEGER = System.Int64;
using PULONG = System.UInt32;
using PVOID = System.IntPtr;
using UCHAR = System.Byte;
using ULONG = System.UInt32;
using ULONGLONG = System.UInt64;
using USHORT = System.UInt16;
using WCHAR = System.String;
using WORD = System.UInt16;
#endregion
internal static partial class Interop
{
internal static partial class Windows
@@ -34,7 +63,7 @@ internal static partial class Interop
/// <summary>
/// Type of data on alternate stream.
/// </summary>
public enum StreamType
public enum StreamType : DWORD
{
/// <summary>
/// Standard data. This corresponds to the NTFS $DATA stream type on the default (unnamed) data stream.
@@ -79,7 +108,7 @@ internal static partial class Interop
}
[Flags]
public enum StreamAttributes
public enum StreamAttributes : DWORD
{
/// <summary>
/// Normal attribute
@@ -110,19 +139,19 @@ internal static partial class Interop
/// <summary>
/// Attributes of data to facilitate cross-operating system transfer.
/// </summary>
public int dwStreamAttributes;
public StreamAttributes dwStreamAttributes;
/// <summary>
/// Size of data, in bytes.
/// </summary>
public long Size;
public LARGE_INTEGER Size;
/// <summary>
/// Length of the name of the alternative data stream, in bytes.
/// </summary>
public int dwStreamNameSize;
public DWORD dwStreamNameSize;
/// <summary>
/// Unicode string that specifies the name of the alternative data stream.
/// </summary>
public string cStreamName;
public WCHAR cStreamName;
}
/// <summary>
@@ -141,11 +170,11 @@ internal static partial class Interop
/// To release the memory used by the data structure, call BackupRead with the <paramref name="bAbort"/> parameter set to <c>true</c> when the backup operation is complete.</param>
[DllImport(Libraries.Kernel32)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BackupRead(SafeFileHandle hFile, IntPtr lpBuffer,
uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead,
[MarshalAs(UnmanagedType.Bool)] bool bAbort,
[MarshalAs(UnmanagedType.Bool)] bool bProcessSecurity,
ref IntPtr lpContext);
public static extern bool BackupRead(HANDLE hFile, LPBYTE lpBuffer,
DWORD nNumberOfBytesToRead, out LPDWORD lpNumberOfBytesRead,
[MarshalAs(UnmanagedType.Bool)] BOOL bAbort,
[MarshalAs(UnmanagedType.Bool)] BOOL bProcessSecurity,
ref LPVOID lpContext);
/// <summary>
/// The BackupSeek function seeks forward in a data stream initially accessed by using the <see cref="BackupRead"/> or <see cref="BackupWrite"/> function.
@@ -159,8 +188,8 @@ internal static partial class Interop
/// <param name="lpContext">Pointer to an internal data structure used by the function. This structure must be the same structure that was initialized by the <see cref="BackupRead"/> or <see cref="BackupWrite"/> function. An application must not touch the contents of this structure.</param>
[DllImport(Libraries.Kernel32)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BackupSeek(SafeFileHandle hFile,
uint dwLowBytesToSeek, uint dwHighBytesToSeek, out uint lpdwLowByteSeeked,
out uint lpdwHighByteSeeked, ref IntPtr lpContext);
public static extern bool BackupSeek(HANDLE hFile,
DWORD dwLowBytesToSeek, DWORD dwHighBytesToSeek, out LPDWORD lpdwLowByteSeeked,
out LPDWORD lpdwHighByteSeeked, ref LPVOID lpContext);
}
}

View File

@@ -23,8 +23,37 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
#region Win32 type definitions
using BOOL = System.Boolean;
using BOOLEAN = System.Boolean;
using CCHAR = System.SByte;
using CHAR = System.Byte;
using DWORD = System.UInt32;
using FILE_ID_128 = System.Guid;
using HANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using LARGE_INTEGER = System.Int64;
using LONGLONG = System.Int64;
using LPBYTE = System.IntPtr;
using LPCTSTR = System.String;
using LPCWSTR = System.String;
using LPDWORD = System.UInt32;
using LPTSTR = System.Text.StringBuilder;
using LPVOID = System.IntPtr;
using PHANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using PLARGE_INTEGER = System.Int64;
using PULONG = System.UInt32;
using PVOID = System.IntPtr;
using UCHAR = System.Byte;
using ULONG = System.UInt32;
using ULONGLONG = System.UInt64;
using USHORT = System.UInt16;
using WCHAR = System.String;
using WORD = System.UInt16;
#endregion
internal static partial class Interop
{
@@ -42,7 +71,7 @@ internal static partial class Interop
/// <summary>
/// This is set to a request-dependent value. For example, on successful completion of a transfer request, this is set to the number of bytes transferred. If a transfer request is completed with another STATUS_XXX, this member is set to zero.
/// </summary>
public ulong information;
public PVOID information;
}
const byte FILE_NEED_EA = 0x80;
@@ -55,23 +84,23 @@ internal static partial class Interop
/// <summary>
/// The offset of the next <see cref="FILE_FULL_EA_INFORMATION"/>-type entry. This member is zero if no other entries follow this one.
/// </summary>
public ulong NextEntryOffset;
public ULONG NextEntryOffset;
/// <summary>
/// Can be zero or can be set with <see cref="FILE_NEED_EA"/>, indicating that the file to which the EA belongs cannot be interpreted without understanding the associated extended attributes.
/// </summary>
public byte Flags;
public UCHAR Flags;
/// <summary>
/// The length in bytes of the <see cref="EaName"/> array. This value does not include a <c>null</c>-terminator to <see cref="EaName"/>.
/// </summary>
public byte EaNameLength;
public UCHAR EaNameLength;
/// <summary>
/// The length in bytes of each EA value in the array.
/// </summary>
public ushort EaValueLength;
public USHORT EaValueLength;
/// <summary>
/// An array of characters naming the EA for this entry.
/// </summary>
public byte[] EaName;
public CHAR[] EaName;
}
/// <summary>
@@ -82,15 +111,15 @@ internal static partial class Interop
/// <summary>
/// Offset, in bytes, of the next <see cref="FILE_GET_EA_INFORMATION"/>-typed entry. This member is zero if no other entries follow this one.
/// </summary>
public ulong NextEntryOffset;
public ULONG NextEntryOffset;
/// <summary>
/// Length, in bytes, of the EaName array. This value does not include a <c>NULL</c> terminator.
/// </summary>
public byte EaNameLength;
public UCHAR EaNameLength;
/// <summary>
/// Specifies the first character of the name of the extended attribute to be queried. This is followed in memory by the remainder of the string.
/// </summary>
public byte[] EaName;
public CHAR[] EaName;
}
/// <summary>
@@ -112,9 +141,9 @@ internal static partial class Interop
/// <param name="RestartScan">Set to <c>true</c> if NtQueryEaFile should begin the scan at the first entry in the file's extended-attribute list. If this parameter is set to <c>false</c>, the routine resumes the scan from a previous call to ZwQueryEaFile.</param>
[DllImport(Libraries.NTDLL)]
public static extern NTSTATUS NtQueryEaFile(IntPtr FileHandle,
ref IO_STATUS_BLOCK IoStatusBlock, IntPtr Buffer, ulong Length,
[MarshalAs(UnmanagedType.Bool)] bool ReturnSingleEntry, IntPtr EaList, UInt32 EaListLength, ref UInt32 EaIndex,
UInt32 RestartScan);
ref IO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length,
[MarshalAs(UnmanagedType.Bool)] BOOLEAN ReturnSingleEntry, PVOID EaList, ULONG EaListLength, ref PULONG EaIndex,
[MarshalAs(UnmanagedType.Bool)] BOOLEAN RestartScan);
/// <summary>
/// Sets extended-attribute (EA) values for a file.
@@ -127,7 +156,7 @@ internal static partial class Interop
/// <param name="Buffer">A pointer to a caller-supplied, <see cref="FILE_FULL_EA_INFORMATION"/>-structured input buffer that contains the extended attribute values to be set.</param>
/// <param name="Length">Length, in bytes, of the buffer that the Buffer parameter points to.</param>
[DllImport(Libraries.NTDLL)]
public static extern NTSTATUS NtSetEaFile(IntPtr FileHandle, ref IO_STATUS_BLOCK IoStatusBlock, IntPtr Buffer, UInt32 Length);
public static extern NTSTATUS NtSetEaFile(HANDLE FileHandle, ref IO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length);
}
}

View File

@@ -23,9 +23,37 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
#region Win32 type definitions
using BOOL = System.Boolean;
using BOOLEAN = System.Boolean;
using CCHAR = System.SByte;
using CHAR = System.Byte;
using DWORD = System.UInt32;
using FILE_ID_128 = System.Guid;
using HANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using LARGE_INTEGER = System.Int64;
using LONGLONG = System.Int64;
using LPBYTE = System.IntPtr;
using LPCTSTR = System.String;
using LPCWSTR = System.String;
using LPDWORD = System.UInt32;
using LPTSTR = System.Text.StringBuilder;
using LPVOID = System.IntPtr;
using PHANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using PLARGE_INTEGER = System.Int64;
using PULONG = System.UInt32;
using PVOID = System.IntPtr;
using UCHAR = System.Byte;
using ULONG = System.UInt32;
using ULONGLONG = System.UInt64;
using USHORT = System.UInt16;
using WCHAR = System.String;
using WORD = System.UInt16;
#endregion
internal static partial class Interop
{
internal static partial class Windows

View File

@@ -23,16 +23,38 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
using Microsoft.Win32.SafeHandles;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
#region Win32 type definitions
using BOOL = System.Boolean;
using BOOLEAN = System.Boolean;
using CCHAR = System.SByte;
using CHAR = System.Byte;
using DWORD = System.UInt32;
using FILE_ID_128 = System.Guid;
using HANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using LARGE_INTEGER = System.Int64;
using LONGLONG = System.Int64;
using LPBYTE = System.IntPtr;
using LPCTSTR = System.String;
using LPCWSTR = System.String;
using LPDWORD = System.UInt32;
using LPTSTR = System.Text.StringBuilder;
using LPVOID = System.IntPtr;
using PHANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using PLARGE_INTEGER = System.Int64;
using PULONG = System.UInt32;
using PVOID = System.IntPtr;
using UCHAR = System.Byte;
using ULONG = System.UInt32;
using ULONGLONG = System.UInt64;
using USHORT = System.UInt16;
using WCHAR = System.String;
using WORD = System.UInt16;
#endregion
internal static partial class Interop
@@ -40,7 +62,7 @@ internal static partial class Interop
internal static partial class Windows
{
public enum CreateDispositionFlags : uint
public enum CreateDispositionFlags : ULONG
{
/// <summary>
/// Replaces the file if it exists.
@@ -70,7 +92,7 @@ internal static partial class Interop
FILE_MAXIMUM_DISPOSITION = FILE_OVERWRITE_IF
}
public enum CreateOptionsFlags : uint
public enum CreateOptionsFlags : ULONG
{
/// <summary>
/// The file is a directory.
@@ -188,11 +210,11 @@ internal static partial class Interop
/// <param name="EaBuffer">Pointer to a <see cref="FILE_FULL_EA_INFORMATION"/>-structured buffer that contains the starting attributes to write to the file when creating, replacing or overwriting it.</param>
/// <param name="EaLength">Length of the buffer pointed by <paramref name="EaBuffer"/></param>
[DllImport(Libraries.NTDLL)]
public static extern NTSTATUS NtCreateFile(out SafeFileHandle FileHandle,
public static extern NTSTATUS NtCreateFile(out PHANDLE FileHandle,
ACCESS_MASK DesiredAccess, ref OBJECT_ATTRIBUTES ObjectAttributes,
ref IO_STATUS_BLOCK IoStatusBlock, ref long AllocationSize, uint FileAttributes,
ref IO_STATUS_BLOCK IoStatusBlock, ref PLARGE_INTEGER AllocationSize, ULONG FileAttributes,
FileShare ShareAccess, CreateDispositionFlags CreateDisposition, CreateOptionsFlags CreateOptions,
IntPtr EaBuffer, uint EaLength);
PVOID EaBuffer, ULONG EaLength);
/// <summary>
/// Closes an object handle
@@ -200,7 +222,7 @@ internal static partial class Interop
/// <returns>returns <see cref="NTSTATUS.STATUS_SUCCESS"/> on success, or the appropriate <see cref="NTSTATUS"/> error code on failure. In particular, it returns <see cref="NTSTATUS.STATUS_INVALID_HANDLE"/> if Handle is not a valid handle, or <see cref="NTSTATUS.STATUS_HANDLE_NOT_CLOSABLE"/> if the calling thread does not have permission to close the handle.</returns>
/// <param name="handle">Handle to an object of any type.</param>
[DllImport(Libraries.NTDLL)]
public static extern NTSTATUS NtClose(SafeFileHandle handle);
public static extern NTSTATUS NtClose(HANDLE handle);
/// <summary>
/// Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: file, file stream, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe. The function returns a handle that can be used to access the file or device for various types of I/O depending on the file or device and the flags and attributes specified.
@@ -217,62 +239,63 @@ internal static partial class Interop
/// <param name="dwFlagsAndAttributes">The file or device attributes and flags.</param>
/// <param name="hTemplateFile">A valid handle to a template file with the GENERIC_READ access right. The template file supplies file attributes and extended attributes for the file that is being created. This parameter can be <c>null</c>.</param>
[DllImport(Libraries.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
public static extern SafeFileHandle CreateFile(string lpFileName,
FileAccess dwDesiredAccess, FileShare dwShareMode,
IntPtr lpSecurityAttributes, FileMode dwCreationDisposition,
int dwFlagsAndAttributes, IntPtr hTemplateFile);
public static extern HANDLE CreateFile(LPCTSTR lpFileName,
FileAccess dwDesiredAccess, FileShare dwShareMode,
IntPtr lpSecurityAttributes, FileMode dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
public enum FILE_INFO_BY_HANDLE_CLASS {
public enum FILE_INFO_BY_HANDLE_CLASS
{
/// <summary>
/// Minimal information for the file should be retrieved or set.
/// <see cref="FILE_BASIC_INFO"/>
/// </summary>
FileBasicInfo = 0,
FileBasicInfo = 0,
/// <summary>
/// Extended information for the file should be retrieved.
/// <see cref="FILE_STANDARD_INFO"/>
/// </summary>
FileStandardInfo = 1,
FileStandardInfo = 1,
/// <summary>
/// The file name should be retrieved.
/// <see cref="FILE_NAME_INFO"/>
/// </summary>
FileNameInfo = 2,
FileNameInfo = 2,
/// <summary>
/// The file name should be changed.
/// <see cref="FILE_RENAME_INFO"/>
/// </summary>
FileRenameInfo = 3,
FileRenameInfo = 3,
/// <summary>
/// The file should be deleted.
/// <see cref="FILE_DISPOSITION_INFO"/>
/// </summary>
FileDispositionInfo = 4,
FileDispositionInfo = 4,
/// <summary>
/// The file allocation information should be changed.
/// <see cref="FILE_ALLOCATION_INFO"/>
/// </summary>
FileAllocationInfo = 5,
FileAllocationInfo = 5,
/// <summary>
/// The end of the file should be set.
/// <see cref="FILE_END_OF_FILE_INFO"/>
/// </summary>
FileEndOfFileInfo = 6,
FileEndOfFileInfo = 6,
/// <summary>
/// File stream information for the specified file should be retrieved.
/// <see cref="FILE_STREAM_INFO"/>
/// </summary>
FileStreamInfo = 7,
FileStreamInfo = 7,
/// <summary>
/// File compression information should be retrieved.
/// <see cref="FILE_COMPRESSION_INFO"/>
/// </summary>
FileCompressionInfo = 8,
FileCompressionInfo = 8,
/// <summary>
/// File attribute information should be retrieved.
/// <see cref="FILE_ATTRIBUTE_TAG_INFO"/>
/// </summary>
FileAttributeTagInfo = 9,
FileAttributeTagInfo = 9,
/// <summary>
/// Files in the specified directory should be retrieved. Used for directory handles.
/// Use only when calling GetFileInformationByHandleEx.
@@ -282,64 +305,64 @@ internal static partial class Interop
/// enumeration operation after the last file is returned.
/// <see cref="FILE_ID_BOTH_DIR_INFO"/>
/// </summary>
FileIdBothDirectoryInfo = 10,
FileIdBothDirectoryInfo = 10,
/// <summary>
/// Identical to <see cref="FileIdBothDirectoryInfo"/>, but forces the enumeration operation to start again from the beginning.
/// <see cref="FILE_ID_BOTH_DIR_INFO"/>
/// </summary>
FileIdBothDirectoryRestartInfo = 11,
FileIdBothDirectoryRestartInfo = 11,
/// <summary>
/// Priority hint information should be set.
/// <see cref="FILE_IO_PRIORITY_HINT_INFO"/>
/// </summary>
FileIoPriorityHintInfo = 12,
FileIoPriorityHintInfo = 12,
/// <summary>
/// File remote protocol information should be retrieved.
/// <see cref="FILE_REMOTE_PROTOCOL_INFO"/>
/// </summary>
FileRemoteProtocolInfo = 13,
FileRemoteProtocolInfo = 13,
/// <summary>
/// Files in the specified directory should be retrieved.
/// <see cref="FILE_FULL_DIR_INFO"/>
/// This value is not supported before Windows 8 and Windows Server 2012
/// </summary>
FileFullDirectoryInfo = 14,
FileFullDirectoryInfo = 14,
/// <summary>
/// Identical to FileFullDirectoryInfo, but forces the enumeration operation to start again from the beginning.
/// <see cref="FILE_FULL_DIR_INFO"/>
/// This value is not supported before Windows 8 and Windows Server 2012
/// </summary>
FileFullDirectoryRestartInfo = 15,
FileFullDirectoryRestartInfo = 15,
/// <summary>
/// File storage information should be retrieved.
/// <see cref="FILE_STORAGE_INFO"/>
/// This value is not supported before Windows 8 and Windows Server 2012
/// </summary>
FileStorageInfo = 16,
FileStorageInfo = 16,
/// <summary>
/// File alignment information should be retrieved.
/// <see cref="FILE_ALIGNMENT_INFO"/>
/// This value is not supported before Windows 8 and Windows Server 2012
/// </summary>
FileAlignmentInfo = 17,
FileAlignmentInfo = 17,
/// <summary>
/// File information should be retrieved.
/// <see cref="FILE_ID_INFO"/>
/// This value is not supported before Windows 8 and Windows Server 2012
/// </summary>
FileIdInfo = 18,
FileIdInfo = 18,
/// <summary>
/// Files in the specified directory should be retrieved.
/// <see cref="FILE_ID_EXTD_DIR_INFO"/>
/// This value is not supported before Windows 8 and Windows Server 2012
/// </summary>
FileIdExtdDirectoryInfo = 19,
FileIdExtdDirectoryInfo = 19,
/// <summary>
/// Identical to FileIdExtdDirectoryInfo, but forces the enumeration operation to start again from the beginning.
/// <see cref="FILE_ID_EXTD_DIR_INFO"/>
/// This value is not supported before Windows 8 and Windows Server 2012
/// </summary>
FileIdExtdDirectoryRestartInfo = 20,
FileIdExtdDirectoryRestartInfo = 20,
/// <summary>
/// This value is used for validation. Supported values are less than this value.
/// </summary>
@@ -358,8 +381,8 @@ internal static partial class Interop
[DllImport(Libraries.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern BOOL GetFileInformationByHandleEx(HANDLE hFile,
FILE_INFO_BY_HANDLE_CLASS FileInformationClass, out LPVOID lpFileInformation,
DWORD dwBufferSize);
FILE_INFO_BY_HANDLE_CLASS FileInformationClass, out LPVOID lpFileInformation,
DWORD dwBufferSize);
/// <summary>
/// Retrieves file information for the specified file.
@@ -371,7 +394,7 @@ internal static partial class Interop
[DllImport(Libraries.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern BOOL GetFileInformationByHandleEx(HANDLE hFile,
ref BY_HANDLE_FILE_INFORMATION lpFileInformation);
ref BY_HANDLE_FILE_INFORMATION lpFileInformation);
}
}

View File

@@ -23,11 +23,40 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.Win32.SafeHandles;
#region Win32 type definitions
using BOOL = System.Boolean;
using BOOLEAN = System.Boolean;
using CCHAR = System.SByte;
using CHAR = System.Byte;
using DWORD = System.UInt32;
using FILE_ID_128 = System.Guid;
using HANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using LARGE_INTEGER = System.Int64;
using LONGLONG = System.Int64;
using LPBYTE = System.IntPtr;
using LPCTSTR = System.String;
using LPCWSTR = System.String;
using LPDWORD = System.UInt32;
using LPTSTR = System.Text.StringBuilder;
using LPVOID = System.IntPtr;
using PHANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using PLARGE_INTEGER = System.Int64;
using PULONG = System.UInt32;
using PVOID = System.IntPtr;
using UCHAR = System.Byte;
using ULONG = System.UInt32;
using ULONGLONG = System.UInt64;
using USHORT = System.UInt16;
using WCHAR = System.String;
using WORD = System.UInt16;
#endregion
internal static partial class Interop
{
@@ -85,10 +114,10 @@ internal static partial class Interop
/// <param name="lpFindStreamData">A pointer to a buffer that receives the file stream data. The format of this data depends on the value of the <paramref name="InfoLevel"/> parameter.</param>
/// <param name="dwFlags">Reserved for future use. This parameter must be zero.</param>
[DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
public static extern SafeFindHandle FindFirstStreamW(string lpFileName,
public static extern SafeFindHandle FindFirstStreamW(LPCWSTR lpFileName,
STREAM_INFO_LEVELS InfoLevel,
[In, Out, MarshalAs(UnmanagedType.LPStruct)] WIN32_FIND_STREAM_DATA lpFindStreamData,
uint dwFlags);
DWORD dwFlags);
/// <summary>
@@ -99,7 +128,7 @@ internal static partial class Interop
/// <param name="lpFindStreamData">A pointer to the <see cref="WIN32_FIND_STREAM_DATA"/> structure that receives information about the stream.</param>
[DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FindNextStreamW(SafeFindHandle hndFindFile,
public static extern BOOL FindNextStreamW(SafeFindHandle hndFindFile,
[In, Out, MarshalAs(UnmanagedType.LPStruct)] WIN32_FIND_STREAM_DATA lpFindStreamData);
}
}

View File

@@ -23,16 +23,44 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Runtime.InteropServices;
using System;
using System.Text;
using System.Runtime.InteropServices;
#region Win32 type definitions
using BOOL = System.Boolean;
using BOOLEAN = System.Boolean;
using CCHAR = System.SByte;
using CHAR = System.Byte;
using DWORD = System.UInt32;
using FILE_ID_128 = System.Guid;
using HANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using LARGE_INTEGER = System.Int64;
using LONGLONG = System.Int64;
using LPBYTE = System.IntPtr;
using LPCTSTR = System.String;
using LPCWSTR = System.String;
using LPDWORD = System.UInt32;
using LPTSTR = System.Text.StringBuilder;
using LPVOID = System.IntPtr;
using PHANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using PLARGE_INTEGER = System.Int64;
using PULONG = System.UInt32;
using PVOID = System.IntPtr;
using UCHAR = System.Byte;
using ULONG = System.UInt32;
using ULONGLONG = System.UInt64;
using USHORT = System.UInt16;
using WCHAR = System.String;
using WORD = System.UInt16;
#endregion
internal static partial class Interop
{
internal static partial class Windows
{
[Flags]
public enum FileSystemFlags : uint
public enum FileSystemFlags : LPDWORD
{
/// <summary>
/// The specified volume supports case-sensitive file names.
@@ -146,15 +174,14 @@ internal static partial class Interop
/// <param name="nFileSystemNameSize">Length of <paramref name="lpFileSystemNameBuffer"/>, to a maxium of <see cref="MAX_PATH"/>.</param>
[DllImport(Libraries.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
extern static bool GetVolumeInformation(
string lpRootPathName,
StringBuilder lpVolumeNameBuffer,
int nVolumeNameSize,
out uint lpVolumeSerialNumber,
out uint lpMaximumComponentLength,
extern static BOOL GetVolumeInformation(
LPCTSTR lpRootPathName,
LPTSTR lpVolumeNameBuffer,
DWORD nVolumeNameSize,
out LPDWORD lpVolumeSerialNumber,
out LPDWORD lpMaximumComponentLength,
out FileSystemFlags lpFileSystemFlags,
StringBuilder lpFileSystemNameBuffer,
int nFileSystemNameSize);
LPTSTR lpFileSystemNameBuffer,
DWORD nFileSystemNameSize);
}
}
}

View File

@@ -30,17 +30,29 @@ using System.Runtime.InteropServices;
using BOOL = System.Boolean;
using BOOLEAN = System.Boolean;
using CCHAR = System.SByte;
using CHAR = System.Byte;
using DWORD = System.UInt32;
using FILE_ID_128 = System.Guid;
using HANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using LARGE_INTEGER = System.Int64;
using LONGLONG = System.Int64;
using LPBYTE = System.IntPtr;
using LPCTSTR = System.String;
using LPCWSTR = System.String;
using LPDWORD = System.UInt32;
using LPTSTR = System.Text.StringBuilder;
using LPVOID = System.IntPtr;
using PHANDLE = Microsoft.Win32.SafeHandles.SafeFileHandle;
using PLARGE_INTEGER = System.Int64;
using PULONG = System.UInt32;
using PVOID = System.IntPtr;
using UCHAR = System.Byte;
using ULONG = System.UInt32;
using ULONGLONG = System.UInt64;
using USHORT = System.UInt16;
using WCHAR = System.String;
using WORD = System.UInt16;
#endregion
internal static partial class Interop
@@ -48,7 +60,7 @@ internal static partial class Interop
internal static partial class Windows
{
[Flags]
public enum ACCESS_MASK : UInt32
public enum ACCESS_MASK : DWORD
{
/// <summary>Right to read data from the file. (FILE)</summary>
FILE_READ_DATA = 0x00000001,
@@ -855,7 +867,8 @@ internal static partial class Interop
/// <summary>
/// Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
/// </summary>
public struct FILETIME {
public struct FILETIME
{
/// <summary>
/// The low-order part of the file time.
/// </summary>
@@ -869,11 +882,12 @@ internal static partial class Interop
/// <summary>
/// Contains information that the <see cref="GetFileInformationByHandle"/> function retrieves.
/// </summary>
public struct BY_HANDLE_FILE_INFORMATION {
public struct BY_HANDLE_FILE_INFORMATION
{
/// <summary>
/// The file attributes. <see cref="FILE_ATTRIBUTES"/>
/// </summary>
public FILE_ATTRIBUTES dwFileAttributes;
public FILE_ATTRIBUTES dwFileAttributes;
/// <summary>
/// A FILETIME structure that specifies when a file or directory is created. If the underlying file system does not support creation time, this member is zero (0).
/// </summary>
@@ -889,23 +903,23 @@ internal static partial class Interop
/// <summary>
/// The serial number of the volume that contains a file.
/// </summary>
public DWORD dwVolumeSerialNumber;
public DWORD dwVolumeSerialNumber;
/// <summary>
/// The high-order part of the file size.
/// </summary>
public DWORD nFileSizeHigh;
public DWORD nFileSizeHigh;
/// <summary>
/// The low-order part of the file size.
/// </summary>
public DWORD nFileSizeLow;
public DWORD nFileSizeLow;
/// <summary>
/// The number of links to this file. For the FAT file system this member is always 1. For the NTFS file system, it can be more than 1.
/// </summary>
public DWORD nNumberOfLinks;
public DWORD nNumberOfLinks;
/// <summary>
/// The high-order part of a unique identifier that is associated with a file. For more information, see <see cref="nFileIndexLow"/>.
/// </summary>
public DWORD nFileIndexHigh;
public DWORD nFileIndexHigh;
/// <summary>
/// The low-order part of a unique identifier that is associated with a file.
/// The identifier (low and high parts) and the volume serial number uniquely
@@ -919,7 +933,7 @@ internal static partial class Interop
/// <see cref="FILE_ID_INFO"/> structure. The 64-bit identifier in this structure
/// is not guaranteed to be unique on ReFS.
/// </summary>
public DWORD nFileIndexLow;
public DWORD nFileIndexLow;
}
}
}