From 6b4da34ab306768a9e91e40332c2bccdde64f73c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 7 May 2015 05:31:02 +0100 Subject: [PATCH] Changed everything to use base API type definitions, with "using" as alias to .NET types. --- Claunia.IO/ChangeLog | 21 + Claunia.IO/Claunia.IO.csproj | 2 + .../Apple/Interop.Apple.getattrlist.cs | 35 +- .../Interop/Apple/Interop.Apple.stat.cs | 375 ++---------------- .../Interop/Apple/Interop.Apple.stat64.cs | 159 ++++++++ .../Interop/Apple/Interop.Apple.statfs.cs | 101 +---- .../Interop/Apple/Interop.Apple.statfs64.cs | 130 ++++++ .../Interop/Apple/Interop.Apple.types.cs | 212 ++++++++++ .../Interop/Apple/Interop.Apple.uname.cs | 1 - .../Interop/Apple/Interop.Apple.xattr.cs | 28 +- .../Interop/Windows/Interop.Windows.Backup.cs | 59 ++- .../Interop/Windows/Interop.Windows.EAs.cs | 57 ++- .../Interop/Windows/Interop.Windows.Errors.cs | 30 +- .../Interop/Windows/Interop.Windows.Files.cs | 97 +++-- .../Windows/Interop.Windows.Streams.cs | 39 +- .../Windows/Interop.Windows.Volumes.cs | 53 ++- .../Interop/Windows/Interop.Windows.types.cs | 34 +- 17 files changed, 887 insertions(+), 546 deletions(-) create mode 100644 Claunia.IO/Interop/Apple/Interop.Apple.stat64.cs create mode 100644 Claunia.IO/Interop/Apple/Interop.Apple.statfs64.cs diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog index 63ec8ae..044e7a6 100644 --- a/Claunia.IO/ChangeLog +++ b/Claunia.IO/ChangeLog @@ -1,3 +1,24 @@ +2015-05-07 Natalia Portillo + + * 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 * Tests/Interop.Apple.cs: diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index 64cddf7..04b7772 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -75,6 +75,8 @@ + + diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.getattrlist.cs b/Claunia.IO/Interop/Apple/Interop.Apple.getattrlist.cs index 78b42de..c2e6435 100644 --- a/Claunia.IO/Interop/Apple/Interop.Apple.getattrlist.cs +++ b/Claunia.IO/Interop/Apple/Interop.Apple.getattrlist.cs @@ -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 /// [MarshalAs(UnmanagedType.U2)] - public ushort bitmapCount; + public u_short bitmapCount; /// /// To maintain 4-byte alignment /// [MarshalAs(UnmanagedType.U2)] - public UInt16 reserved; + public u_int16_t reserved; /// /// Common attribut group /// @@ -83,12 +94,12 @@ internal static partial class Interop /// Offset in bytes from this structure to the structure data /// [MarshalAs(UnmanagedType.I4)] - Int32 dataOffset; + int32_t dataOffset; /// /// Length of the attribute data in bytes, always alligned to 4 bytes. /// [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 /// [MarshalAs(UnmanagedType.U4)] - public UInt32 volCapabilitiesInterfaces; + public volCapabilitiesInterfaces_t volCapabilitiesInterfaces; /// /// Reserved, should be 0. /// [MarshalAs(UnmanagedType.U4)] - public UInt32 volCapabilitiesReserved1; + public u_int32_t volCapabilitiesReserved1; /// /// Reserved, should be 0. /// [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 { /// /// 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 { /// /// The volume implementation supports searchfs(2) @@ -743,7 +754,7 @@ internal static partial class Interop /// . /// On success, 0. On failure, -1, and errno is set. [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); /// /// Sets the specified lists of attributes for the file system object. @@ -756,7 +767,7 @@ internal static partial class Interop /// . /// On success, 0. On failure, -1, and errno is set. [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); } } diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.stat.cs b/Claunia.IO/Interop/Apple/Interop.Apple.stat.cs index 4000dde..2511edc 100644 --- a/Claunia.IO/Interop/Apple/Interop.Apple.stat.cs +++ b/Claunia.IO/Interop/Apple/Interop.Apple.stat.cs @@ -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 { - /// - /// stat(2) structure when __DARWIN_64_BIT_INO_T is defined - /// - [StructLayout(LayoutKind.Sequential)] - internal struct Stat64 - { - /// - /// ID of device containing file - /// - [MarshalAs(UnmanagedType.I4)] - public int st_dev; - /// - /// Mode of file - /// - [MarshalAs(UnmanagedType.U2)] - public mode_t st_mode; - /// - /// Number of hard links - /// - [MarshalAs(UnmanagedType.U2)] - public ushort st_nlink; - /// - /// File serial number - /// - [MarshalAs(UnmanagedType.U8)] - public ulong st_ino; - /// - /// User ID of the file - /// - [MarshalAs(UnmanagedType.U4)] - public uint st_uid; - /// - /// Group ID of the file - /// - [MarshalAs(UnmanagedType.U4)] - public uint st_gid; - /// - /// Device ID - /// - [MarshalAs(UnmanagedType.I4)] - public int st_rdev; - /// - /// time of last access - /// - public Timespec st_atimespec; - /// - /// time of last data modification - /// - public Timespec st_mtimespec; - /// - /// time of last status change - /// - public Timespec st_ctimespec; - /// - /// time of file creation(birth) - /// - public Timespec st_birthtimespec; - /// - /// file size, in bytes - /// - [MarshalAs(UnmanagedType.I8)] - public long st_size; - /// - /// blocks allocated for file - /// - [MarshalAs(UnmanagedType.I8)] - public long st_blocks; - /// - /// optimal blocksize for I/O - /// - [MarshalAs(UnmanagedType.I4)] - public int st_blksize; - /// - /// user defined flags for file - /// - [MarshalAs(UnmanagedType.U4)] - public flags_t st_flags; - /// - /// file generation number - /// - [MarshalAs(UnmanagedType.U4)] - public uint st_gen; - /// - /// Reserved: DO NOT USE - /// - [MarshalAs(UnmanagedType.U4)] - [Obsolete("RESERVED: DO NOT USE")] - public uint st_lspare; - /// - /// Reserved: DO NOT USE - /// - [MarshalAs(UnmanagedType.ByValArray, - ArraySubType = UnmanagedType.U8, SizeConst = 2)] - [Obsolete("RESERVED: DO NOT USE")] - public ulong[] st_qspare; - } - /// /// stat(2) structure when __DARWIN_64_BIT_INO_T is NOT defined /// @@ -137,12 +61,12 @@ internal static partial class Interop /// ID of device containing file /// [MarshalAs(UnmanagedType.I4)] - public int st_dev; + public dev_t st_dev; /// /// File serial number /// [MarshalAs(UnmanagedType.U4)] - public uint st_ino; + public ino_t st_ino; /// /// Mode of file /// @@ -152,22 +76,22 @@ internal static partial class Interop /// Number of hard links /// [MarshalAs(UnmanagedType.U2)] - public ushort st_nlink; + public nlink_t st_nlink; /// /// User ID of the file /// [MarshalAs(UnmanagedType.U4)] - public uint st_uid; + public uid_t st_uid; /// /// Group ID of the file /// [MarshalAs(UnmanagedType.U4)] - public uint st_gid; + public gid_t st_gid; /// /// Device ID /// [MarshalAs(UnmanagedType.I4)] - public int st_rdev; + public dev_t st_rdev; /// /// time of last access /// @@ -184,17 +108,17 @@ internal static partial class Interop /// file size, in bytes /// [MarshalAs(UnmanagedType.I8)] - public long st_size; + public off_t st_size; /// /// blocks allocated for file /// [MarshalAs(UnmanagedType.I8)] - public long st_blocks; + public quad_t st_blocks; /// /// optimal blocksize for I/O /// [MarshalAs(UnmanagedType.I4)] - public int st_blksize; + public u_long st_blksize; /// /// user defined flags for file /// @@ -204,232 +128,7 @@ internal static partial class Interop /// file generation number /// [MarshalAs(UnmanagedType.U4)] - public uint st_gen; - /// - /// Reserved: DO NOT USE - /// - [MarshalAs(UnmanagedType.U4)] - [Obsolete("RESERVED: DO NOT USE")] - public uint st_lspare; - /// - /// Reserved: DO NOT USE - /// - [MarshalAs(UnmanagedType.ByValArray, - ArraySubType = UnmanagedType.U8, SizeConst = 2)] - [Obsolete("RESERVED: DO NOT USE")] - public ulong[] st_qspare; - } - - /// - /// File mode and permissions - /// - [Flags] - internal enum mode_t : ushort - { - // File type - - /// - /// File type mask - /// - S_IFMT = 0xF000, - /// - /// Named pipe (FIFO) - /// - S_IFIFO = 0x1000, - /// - /// Character device - /// - S_IFCHR = 0x2000, - /// - /// Directory - /// - S_IFDIR = 0x4000, - /// - /// Block device - /// - S_IFBLK = 0x6000, - /// - /// Regular file - /// - S_IFREG = 0x8000, - /// - /// Symbolic link - /// - S_IFLNK = 0xA000, - /// - /// Socket file - /// - S_IFSOCK = 0xC000, - /// - /// OBSOLETE: whiteout - /// - [Obsolete] - S_IFWHT = 0xE000, - - // POSIX Permissions - - /// - /// Owner permissions mask - /// - S_IRWXU = 0x01C0, - /// - /// Readable by owner - /// - S_IRUSR = 0x0100, - /// - /// Writable by owner - /// - S_IWUSR = 0x0080, - /// - /// Executable by owner - /// - S_IXUSR = 0x0040, - - /// - /// Group permissions mask - /// - S_IRWXG = 0x0038, - /// - /// Readable by group - /// - S_IRGRP = 0x0020, - /// - /// Writable by group - /// - S_IWGRP = 0x0010, - /// - /// Executable by group - /// - S_IXGRP = 0x0008, - - /// - /// Others permissions mask - /// - S_IRWXO = 0x0007, - /// - /// Readable by others - /// - S_IROTH = 0x0004, - /// - /// Writable by others - /// - S_IWOTH = 0x0002, - /// - /// Executable by others - /// - S_IXOTH = 0x0001, - - /// - /// Set UID on execution - /// - S_ISUID = 0x0800, - /// - /// Set GID on execution - /// - S_ISGID = 0x0400, - /// - /// Only file/directory owners (or suser) can removed files from directory - /// - S_ISVTX = 0x0200, - - /// - /// Sticky bit, not supported by OS X - /// - [Obsolete("Not supported under OS X")] - S_ISTXT = S_ISVTX, - /// - /// For backwards compatibility - /// - S_IREAD = S_IRUSR, - /// - /// For backwards compatibility - /// - S_IWRITE = S_IWUSR, - /// - /// For backwards compatibility - /// - S_IEXEC = S_IXUSR - } - - /// - /// User-set flags - /// - [Flags] - internal enum flags_t : uint - { - /// - /// Mask of flags changeable by owner - /// - UF_SETTABLE = 0x0000FFFF, - /// - /// Do not dump file - /// - UF_NODUMP = 0x00000001, - /// - /// File is immutable (read-only) - /// - UF_IMMUTABLE = 0x00000002, - /// - /// File can only be appended - /// - UF_APPEND = 0x00000004, - /// - /// The directory is opaque when viewed through a union stack. - /// - UF_OPAQUE = 0x00000008, - /// - /// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X. - /// File cannot be removed or renamed. - /// - [Obsolete("Unimplemented in OS X")] - UF_NOUNLINK = 0x00000010, - /// - /// File is compressed in HFS+ (>=10.6) - /// - UF_COMPRESSED = 0x00000020, - /// - /// OBSOLETE: No longer used. - /// Issue notifications for deletes or renames of files with this flag set - /// - [Obsolete("No longer used")] - UF_TRACKED = 0x00000040, - /// - /// Hide the file in Finder - /// - UF_HIDDEN = 0x00008000, - - /// - /// Mask of flags changeable by the superuser - /// - SF_SETTABLE = 0xffff0000, - /// - /// File has been archived - /// - SF_ARCHIVED = 0x00010000, - /// - /// File is immutable (read-only) - /// - SF_IMMUTABLE = 0x00020000, - /// - /// File can only be appended - /// - SF_APPEND = 0x00040000, - /// - /// Restricted access - /// - SF_RESTRICTED = 0x00080000, - /// - /// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X. - /// File cannot be removed or renamed. - /// - [Obsolete("Unimplemented in OS X")] - SF_NOUNLINK = 0x00100000, - /// - /// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X. - /// Snapshot inode - /// - [Obsolete("Unimplemented in OS X")] - SF_SNAPSHOT = 0x00200000 + public u_long st_gen; } /// @@ -441,16 +140,6 @@ internal static partial class Interop /// On success, 0. On failure, -1, and errno is set. [DllImport(Libraries.Libc, SetLastError = true)] public static extern int stat(string path, out Stat buf); - - /// - /// Obtains information of the file pointed by . - /// Calls to system's stat64(2) - /// - /// Path to the file. - /// . - /// On success, 0. On failure, -1, and errno is set. - [DllImport(Libraries.Libc, SetLastError = true)] - public static extern int stat64(string path, out Stat64 buf); } } diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.stat64.cs b/Claunia.IO/Interop/Apple/Interop.Apple.stat64.cs new file mode 100644 index 0000000..92fdaf3 --- /dev/null +++ b/Claunia.IO/Interop/Apple/Interop.Apple.stat64.cs @@ -0,0 +1,159 @@ +// +// Interop.Apple.stat64.cs +// +// Author: +// Natalia Portillo +// +// 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 + { + /// + /// stat(2) structure when __DARWIN_64_BIT_INO_T is defined + /// + [StructLayout(LayoutKind.Sequential)] + internal struct Stat64 + { + /// + /// ID of device containing file + /// + [MarshalAs(UnmanagedType.I4)] + public int st_dev; + /// + /// Mode of file + /// + [MarshalAs(UnmanagedType.U2)] + public mode_t st_mode; + /// + /// Number of hard links + /// + [MarshalAs(UnmanagedType.U2)] + public ushort st_nlink; + /// + /// File serial number + /// + [MarshalAs(UnmanagedType.U8)] + public ulong st_ino; + /// + /// User ID of the file + /// + [MarshalAs(UnmanagedType.U4)] + public uint st_uid; + /// + /// Group ID of the file + /// + [MarshalAs(UnmanagedType.U4)] + public uint st_gid; + /// + /// Device ID + /// + [MarshalAs(UnmanagedType.I4)] + public int st_rdev; + /// + /// time of last access + /// + public Timespec st_atimespec; + /// + /// time of last data modification + /// + public Timespec st_mtimespec; + /// + /// time of last status change + /// + public Timespec st_ctimespec; + /// + /// time of file creation(birth) + /// + public Timespec st_birthtimespec; + /// + /// file size, in bytes + /// + [MarshalAs(UnmanagedType.I8)] + public long st_size; + /// + /// blocks allocated for file + /// + [MarshalAs(UnmanagedType.I8)] + public long st_blocks; + /// + /// optimal blocksize for I/O + /// + [MarshalAs(UnmanagedType.I4)] + public int st_blksize; + /// + /// user defined flags for file + /// + [MarshalAs(UnmanagedType.U4)] + public flags_t st_flags; + /// + /// file generation number + /// + [MarshalAs(UnmanagedType.U4)] + public uint st_gen; + /// + /// Reserved: DO NOT USE + /// + [MarshalAs(UnmanagedType.U4)] + [Obsolete("RESERVED: DO NOT USE")] + public uint st_lspare; + /// + /// Reserved: DO NOT USE + /// + [MarshalAs(UnmanagedType.ByValArray, + ArraySubType = UnmanagedType.U8, SizeConst = 2)] + [Obsolete("RESERVED: DO NOT USE")] + public ulong[] st_qspare; + } + + /// + /// Obtains information of the file pointed by . + /// Calls to system's stat64(2) + /// + /// Path to the file. + /// . + /// On success, 0. On failure, -1, and errno is set. + [DllImport(Libraries.Libc, SetLastError = true)] + public static extern int stat64(string path, out Stat64 buf); + } +} + diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.statfs.cs b/Claunia.IO/Interop/Apple/Interop.Apple.statfs.cs index 29c91c7..36d5cab 100644 --- a/Claunia.IO/Interop/Apple/Interop.Apple.statfs.cs +++ b/Claunia.IO/Interop/Apple/Interop.Apple.statfs.cs @@ -1,5 +1,5 @@ // -// Interop.Apple.stat.cs +// Interop.Apple.statfs.cs // // Author: // Natalia Portillo @@ -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 /// [StructLayout(LayoutKind.Sequential)] - internal struct StatFS64 + internal struct StatFS { /// /// Type of file system (reserved: zero) @@ -89,7 +94,7 @@ internal static partial class Interop /// User that mounted the file system /// [MarshalAs(UnmanagedType.U4)] - UInt32 f_owner; + uid_t f_owner; /// /// Reserved for future use /// @@ -142,84 +147,6 @@ internal static partial class Interop Int64[] f_reserved4; } - /// - /// statfs(2) structure when _DARWIN_FEATURE_64_BIT_INODE is NOT defined - /// - [StructLayout(LayoutKind.Sequential)] - internal struct StatFS - { - /// - /// Fundamental file system block size - /// - UInt32 f_bsize; - /// - /// Optimal transfer block size - /// - Int32 f_iosize; - /// - /// Total data blocks in file system - /// - UInt64 f_blocks; - /// - /// Free blocks in file system - /// - UInt64 f_bfree; - /// - /// Free blocks avail to non-superuser - /// - UInt64 f_bavail; - /// - /// Total file nodes in file system - /// - UInt64 f_files; - /// - /// Free file nodes in file system - /// - UInt64 f_ffree; - /// - /// File system id - /// - fsid_t f_fsid; - /// - /// User that mounted the filesystem - /// - UInt32 f_owner; - /// - /// Type of filesystem - /// - UInt32 f_type; - /// - /// Copy of mount exported flags - /// - UInt32 f_flags; - /// - /// File system sub-type (flavor) - /// - UInt32 f_fssubtype; - /// - /// File system type name - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] - string f_fstypename; - /// - /// Directory on which mounted - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] - string f_mntonname; - /// - /// Mounted file system - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] - string f_mntfromname; - /// - /// For future use - /// - [MarshalAs(UnmanagedType.ByValArray, - ArraySubType = UnmanagedType.I8, SizeConst = 8)] - [Obsolete("RESERVED: DO NOT USE")] - UInt32[] f_reserved; - } - /// /// Obtains information of the file system mounted at . /// Calls to system's statfs(2) @@ -229,16 +156,6 @@ internal static partial class Interop /// On success, 0. On failure, -1, and errno is set. [DllImport(Libraries.Libc, SetLastError = true)] public static extern int statfs(string path, out StatFS buf); - - /// - /// Obtains information of the file system mounted at . - /// Calls to system's statfs64(2) - /// - /// Path to the filesystem mount point. - /// . - /// On success, 0. On failure, -1, and errno is set. - [DllImport(Libraries.Libc, SetLastError = true)] - public static extern int statfs64(string path, out StatFS64 buf); } } diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.statfs64.cs b/Claunia.IO/Interop/Apple/Interop.Apple.statfs64.cs new file mode 100644 index 0000000..592c760 --- /dev/null +++ b/Claunia.IO/Interop/Apple/Interop.Apple.statfs64.cs @@ -0,0 +1,130 @@ +// +// Interop.Apple.statfs64.cs +// +// Author: +// Natalia Portillo +// +// 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 + { + /// + /// statfs(2) structure when _DARWIN_FEATURE_64_BIT_INODE is NOT defined + /// + [StructLayout(LayoutKind.Sequential)] + internal struct StatFS64 + { + /// + /// Fundamental file system block size + /// + uint32_t f_bsize; + /// + /// Optimal transfer block size + /// + int32_t f_iosize; + /// + /// Total data blocks in file system + /// + uint64_t f_blocks; + /// + /// Free blocks in file system + /// + uint64_t f_bfree; + /// + /// Free blocks avail to non-superuser + /// + uint64_t f_bavail; + /// + /// Total file nodes in file system + /// + uint64_t f_files; + /// + /// Free file nodes in file system + /// + uint64_t f_ffree; + /// + /// File system id + /// + fsid_t f_fsid; + /// + /// User that mounted the filesystem + /// + uid_t f_owner; + /// + /// Type of filesystem + /// + UInt32 f_type; + /// + /// Copy of mount exported flags + /// + UInt32 f_flags; + /// + /// File system sub-type (flavor) + /// + UInt32 f_fssubtype; + /// + /// File system type name + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] + string f_fstypename; + /// + /// Directory on which mounted + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] + string f_mntonname; + /// + /// Mounted file system + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] + string f_mntfromname; + /// + /// For future use + /// + [MarshalAs(UnmanagedType.ByValArray, + ArraySubType = UnmanagedType.I8, SizeConst = 8)] + [Obsolete("RESERVED: DO NOT USE")] + uint32_t[] f_reserved; + } + + /// + /// Obtains information of the file system mounted at . + /// Calls to system's statfs64(2) + /// + /// Path to the filesystem mount point. + /// . + /// On success, 0. On failure, -1, and errno is set. + [DllImport(Libraries.Libc, SetLastError = true)] + public static extern int statfs64(string path, out StatFS64 buf); + } +} + diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.types.cs b/Claunia.IO/Interop/Apple/Interop.Apple.types.cs index 0be269a..12a7170 100644 --- a/Claunia.IO/Interop/Apple/Interop.Apple.types.cs +++ b/Claunia.IO/Interop/Apple/Interop.Apple.types.cs @@ -30,6 +30,218 @@ internal static partial class Interop { internal static partial class Apple { + /// + /// File mode and permissions + /// + [Flags] + internal enum mode_t : ushort + { + // File type + + /// + /// File type mask + /// + S_IFMT = 0xF000, + /// + /// Named pipe (FIFO) + /// + S_IFIFO = 0x1000, + /// + /// Character device + /// + S_IFCHR = 0x2000, + /// + /// Directory + /// + S_IFDIR = 0x4000, + /// + /// Block device + /// + S_IFBLK = 0x6000, + /// + /// Regular file + /// + S_IFREG = 0x8000, + /// + /// Symbolic link + /// + S_IFLNK = 0xA000, + /// + /// Socket file + /// + S_IFSOCK = 0xC000, + /// + /// OBSOLETE: whiteout + /// + [Obsolete] + S_IFWHT = 0xE000, + + // POSIX Permissions + + /// + /// Owner permissions mask + /// + S_IRWXU = 0x01C0, + /// + /// Readable by owner + /// + S_IRUSR = 0x0100, + /// + /// Writable by owner + /// + S_IWUSR = 0x0080, + /// + /// Executable by owner + /// + S_IXUSR = 0x0040, + + /// + /// Group permissions mask + /// + S_IRWXG = 0x0038, + /// + /// Readable by group + /// + S_IRGRP = 0x0020, + /// + /// Writable by group + /// + S_IWGRP = 0x0010, + /// + /// Executable by group + /// + S_IXGRP = 0x0008, + + /// + /// Others permissions mask + /// + S_IRWXO = 0x0007, + /// + /// Readable by others + /// + S_IROTH = 0x0004, + /// + /// Writable by others + /// + S_IWOTH = 0x0002, + /// + /// Executable by others + /// + S_IXOTH = 0x0001, + + /// + /// Set UID on execution + /// + S_ISUID = 0x0800, + /// + /// Set GID on execution + /// + S_ISGID = 0x0400, + /// + /// Only file/directory owners (or suser) can removed files from directory + /// + S_ISVTX = 0x0200, + + /// + /// Sticky bit, not supported by OS X + /// + [Obsolete("Not supported under OS X")] + S_ISTXT = S_ISVTX, + /// + /// For backwards compatibility + /// + S_IREAD = S_IRUSR, + /// + /// For backwards compatibility + /// + S_IWRITE = S_IWUSR, + /// + /// For backwards compatibility + /// + S_IEXEC = S_IXUSR + } + + /// + /// User-set flags + /// + [Flags] + internal enum flags_t : uint + { + /// + /// Mask of flags changeable by owner + /// + UF_SETTABLE = 0x0000FFFF, + /// + /// Do not dump file + /// + UF_NODUMP = 0x00000001, + /// + /// File is immutable (read-only) + /// + UF_IMMUTABLE = 0x00000002, + /// + /// File can only be appended + /// + UF_APPEND = 0x00000004, + /// + /// The directory is opaque when viewed through a union stack. + /// + UF_OPAQUE = 0x00000008, + /// + /// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X. + /// File cannot be removed or renamed. + /// + [Obsolete("Unimplemented in OS X")] + UF_NOUNLINK = 0x00000010, + /// + /// File is compressed in HFS+ (>=10.6) + /// + UF_COMPRESSED = 0x00000020, + /// + /// OBSOLETE: No longer used. + /// Issue notifications for deletes or renames of files with this flag set + /// + [Obsolete("No longer used")] + UF_TRACKED = 0x00000040, + /// + /// Hide the file in Finder + /// + UF_HIDDEN = 0x00008000, + + /// + /// Mask of flags changeable by the superuser + /// + SF_SETTABLE = 0xffff0000, + /// + /// File has been archived + /// + SF_ARCHIVED = 0x00010000, + /// + /// File is immutable (read-only) + /// + SF_IMMUTABLE = 0x00020000, + /// + /// File can only be appended + /// + SF_APPEND = 0x00040000, + /// + /// Restricted access + /// + SF_RESTRICTED = 0x00080000, + /// + /// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X. + /// File cannot be removed or renamed. + /// + [Obsolete("Unimplemented in OS X")] + SF_NOUNLINK = 0x00100000, + /// + /// INCOMPATIBLE: Used in FreeBSD, unimplemented in OS X. + /// Snapshot inode + /// + [Obsolete("Unimplemented in OS X")] + SF_SNAPSHOT = 0x00200000 + } + [StructLayout(LayoutKind.Sequential, Pack = 4)] internal struct Timespec { diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.uname.cs b/Claunia.IO/Interop/Apple/Interop.Apple.uname.cs index 912a12b..947c840 100644 --- a/Claunia.IO/Interop/Apple/Interop.Apple.uname.cs +++ b/Claunia.IO/Interop/Apple/Interop.Apple.uname.cs @@ -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 diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.xattr.cs b/Claunia.IO/Interop/Apple/Interop.Apple.xattr.cs index 6aeb83b..06009ef 100644 --- a/Claunia.IO/Interop/Apple/Interop.Apple.xattr.cs +++ b/Claunia.IO/Interop/Apple/Interop.Apple.xattr.cs @@ -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 /// . /// Size of the extended attribute. On failure, -1, and errno is set [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); /// /// Sets an extended attribute value @@ -98,7 +120,7 @@ internal static partial class Interop /// . /// On success, 0. On failure, -1, and errno is set [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); /// /// 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 [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); } } diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.Backup.cs b/Claunia.IO/Interop/Windows/Interop.Windows.Backup.cs index 5500912..1d76568 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.Backup.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.Backup.cs @@ -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 /// /// Type of data on alternate stream. /// - public enum StreamType + public enum StreamType : DWORD { /// /// 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 { /// /// Normal attribute @@ -110,19 +139,19 @@ internal static partial class Interop /// /// Attributes of data to facilitate cross-operating system transfer. /// - public int dwStreamAttributes; + public StreamAttributes dwStreamAttributes; /// /// Size of data, in bytes. /// - public long Size; + public LARGE_INTEGER Size; /// /// Length of the name of the alternative data stream, in bytes. /// - public int dwStreamNameSize; + public DWORD dwStreamNameSize; /// /// Unicode string that specifies the name of the alternative data stream. /// - public string cStreamName; + public WCHAR cStreamName; } /// @@ -141,11 +170,11 @@ internal static partial class Interop /// To release the memory used by the data structure, call BackupRead with the parameter set to true when the backup operation is complete. [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); /// /// The BackupSeek function seeks forward in a data stream initially accessed by using the or function. @@ -159,8 +188,8 @@ internal static partial class Interop /// Pointer to an internal data structure used by the function. This structure must be the same structure that was initialized by the or function. An application must not touch the contents of this structure. [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); } } \ No newline at end of file diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.EAs.cs b/Claunia.IO/Interop/Windows/Interop.Windows.EAs.cs index aa3e48e..2ec729a 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.EAs.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.EAs.cs @@ -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 /// /// 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. /// - public ulong information; + public PVOID information; } const byte FILE_NEED_EA = 0x80; @@ -55,23 +84,23 @@ internal static partial class Interop /// /// The offset of the next -type entry. This member is zero if no other entries follow this one. /// - public ulong NextEntryOffset; + public ULONG NextEntryOffset; /// /// Can be zero or can be set with , indicating that the file to which the EA belongs cannot be interpreted without understanding the associated extended attributes. /// - public byte Flags; + public UCHAR Flags; /// /// The length in bytes of the array. This value does not include a null-terminator to . /// - public byte EaNameLength; + public UCHAR EaNameLength; /// /// The length in bytes of each EA value in the array. /// - public ushort EaValueLength; + public USHORT EaValueLength; /// /// An array of characters naming the EA for this entry. /// - public byte[] EaName; + public CHAR[] EaName; } /// @@ -82,15 +111,15 @@ internal static partial class Interop /// /// Offset, in bytes, of the next -typed entry. This member is zero if no other entries follow this one. /// - public ulong NextEntryOffset; + public ULONG NextEntryOffset; /// /// Length, in bytes, of the EaName array. This value does not include a NULL terminator. /// - public byte EaNameLength; + public UCHAR EaNameLength; /// /// 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. /// - public byte[] EaName; + public CHAR[] EaName; } /// @@ -112,9 +141,9 @@ internal static partial class Interop /// Set to true if NtQueryEaFile should begin the scan at the first entry in the file's extended-attribute list. If this parameter is set to false, the routine resumes the scan from a previous call to ZwQueryEaFile. [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); /// /// Sets extended-attribute (EA) values for a file. @@ -127,7 +156,7 @@ internal static partial class Interop /// A pointer to a caller-supplied, -structured input buffer that contains the extended attribute values to be set. /// Length, in bytes, of the buffer that the Buffer parameter points to. [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); } } diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.Errors.cs b/Claunia.IO/Interop/Windows/Interop.Windows.Errors.cs index 4698134..e197731 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.Errors.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.Errors.cs @@ -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 diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.Files.cs b/Claunia.IO/Interop/Windows/Interop.Windows.Files.cs index 4f41387..5793bc1 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.Files.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.Files.cs @@ -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 { /// /// 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 { /// /// The file is a directory. @@ -188,11 +210,11 @@ internal static partial class Interop /// Pointer to a -structured buffer that contains the starting attributes to write to the file when creating, replacing or overwriting it. /// Length of the buffer pointed by [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); /// /// Closes an object handle @@ -200,7 +222,7 @@ internal static partial class Interop /// returns on success, or the appropriate error code on failure. In particular, it returns if Handle is not a valid handle, or if the calling thread does not have permission to close the handle. /// Handle to an object of any type. [DllImport(Libraries.NTDLL)] - public static extern NTSTATUS NtClose(SafeFileHandle handle); + public static extern NTSTATUS NtClose(HANDLE handle); /// /// 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 /// The file or device attributes and flags. /// 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 null. [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 + { /// /// Minimal information for the file should be retrieved or set. /// /// - FileBasicInfo = 0, + FileBasicInfo = 0, /// /// Extended information for the file should be retrieved. /// /// - FileStandardInfo = 1, + FileStandardInfo = 1, /// /// The file name should be retrieved. /// /// - FileNameInfo = 2, + FileNameInfo = 2, /// /// The file name should be changed. /// /// - FileRenameInfo = 3, + FileRenameInfo = 3, /// /// The file should be deleted. /// /// - FileDispositionInfo = 4, + FileDispositionInfo = 4, /// /// The file allocation information should be changed. /// /// - FileAllocationInfo = 5, + FileAllocationInfo = 5, /// /// The end of the file should be set. /// /// - FileEndOfFileInfo = 6, + FileEndOfFileInfo = 6, /// /// File stream information for the specified file should be retrieved. /// /// - FileStreamInfo = 7, + FileStreamInfo = 7, /// /// File compression information should be retrieved. /// /// - FileCompressionInfo = 8, + FileCompressionInfo = 8, /// /// File attribute information should be retrieved. /// /// - FileAttributeTagInfo = 9, + FileAttributeTagInfo = 9, /// /// 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. /// /// - FileIdBothDirectoryInfo = 10, + FileIdBothDirectoryInfo = 10, /// /// Identical to , but forces the enumeration operation to start again from the beginning. /// /// - FileIdBothDirectoryRestartInfo = 11, + FileIdBothDirectoryRestartInfo = 11, /// /// Priority hint information should be set. /// /// - FileIoPriorityHintInfo = 12, + FileIoPriorityHintInfo = 12, /// /// File remote protocol information should be retrieved. /// /// - FileRemoteProtocolInfo = 13, + FileRemoteProtocolInfo = 13, /// /// Files in the specified directory should be retrieved. /// /// This value is not supported before Windows 8 and Windows Server 2012 /// - FileFullDirectoryInfo = 14, + FileFullDirectoryInfo = 14, /// /// Identical to FileFullDirectoryInfo, but forces the enumeration operation to start again from the beginning. /// /// This value is not supported before Windows 8 and Windows Server 2012 /// - FileFullDirectoryRestartInfo = 15, + FileFullDirectoryRestartInfo = 15, /// /// File storage information should be retrieved. /// /// This value is not supported before Windows 8 and Windows Server 2012 /// - FileStorageInfo = 16, + FileStorageInfo = 16, /// /// File alignment information should be retrieved. /// /// This value is not supported before Windows 8 and Windows Server 2012 /// - FileAlignmentInfo = 17, + FileAlignmentInfo = 17, /// /// File information should be retrieved. /// /// This value is not supported before Windows 8 and Windows Server 2012 /// - FileIdInfo = 18, + FileIdInfo = 18, /// /// Files in the specified directory should be retrieved. /// /// This value is not supported before Windows 8 and Windows Server 2012 /// - FileIdExtdDirectoryInfo = 19, + FileIdExtdDirectoryInfo = 19, /// /// Identical to FileIdExtdDirectoryInfo, but forces the enumeration operation to start again from the beginning. /// /// This value is not supported before Windows 8 and Windows Server 2012 /// - FileIdExtdDirectoryRestartInfo = 20, + FileIdExtdDirectoryRestartInfo = 20, /// /// This value is used for validation. Supported values are less than this value. /// @@ -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); /// /// 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); } } diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.Streams.cs b/Claunia.IO/Interop/Windows/Interop.Windows.Streams.cs index 708213d..cd084e0 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.Streams.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.Streams.cs @@ -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 /// A pointer to a buffer that receives the file stream data. The format of this data depends on the value of the parameter. /// Reserved for future use. This parameter must be zero. [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); /// @@ -99,7 +128,7 @@ internal static partial class Interop /// A pointer to the structure that receives information about the stream. [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); } } \ No newline at end of file diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.Volumes.cs b/Claunia.IO/Interop/Windows/Interop.Windows.Volumes.cs index cadc8f7..96f7e18 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.Volumes.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.Volumes.cs @@ -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 { /// /// The specified volume supports case-sensitive file names. @@ -146,15 +174,14 @@ internal static partial class Interop /// Length of , to a maxium of . [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); } -} - +} \ No newline at end of file diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.types.cs b/Claunia.IO/Interop/Windows/Interop.Windows.types.cs index 9b6a58a..bbeb412 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.types.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.types.cs @@ -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 { /// Right to read data from the file. (FILE) FILE_READ_DATA = 0x00000001, @@ -855,7 +867,8 @@ internal static partial class Interop /// /// Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC). /// - public struct FILETIME { + public struct FILETIME + { /// /// The low-order part of the file time. /// @@ -869,11 +882,12 @@ internal static partial class Interop /// /// Contains information that the function retrieves. /// - public struct BY_HANDLE_FILE_INFORMATION { + public struct BY_HANDLE_FILE_INFORMATION + { /// /// The file attributes. /// - public FILE_ATTRIBUTES dwFileAttributes; + public FILE_ATTRIBUTES dwFileAttributes; /// /// 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). /// @@ -889,23 +903,23 @@ internal static partial class Interop /// /// The serial number of the volume that contains a file. /// - public DWORD dwVolumeSerialNumber; + public DWORD dwVolumeSerialNumber; /// /// The high-order part of the file size. /// - public DWORD nFileSizeHigh; + public DWORD nFileSizeHigh; /// /// The low-order part of the file size. /// - public DWORD nFileSizeLow; + public DWORD nFileSizeLow; /// /// 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. /// - public DWORD nNumberOfLinks; + public DWORD nNumberOfLinks; /// /// The high-order part of a unique identifier that is associated with a file. For more information, see . /// - public DWORD nFileIndexHigh; + public DWORD nFileIndexHigh; /// /// 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 /// structure. The 64-bit identifier in this structure /// is not guaranteed to be unique on ReFS. /// - public DWORD nFileIndexLow; + public DWORD nFileIndexLow; } } } \ No newline at end of file