From eee56684240cbd1f400fe760e874ed3103238947 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 26 Apr 2015 04:05:39 +0100 Subject: [PATCH] Implement statfs(2) and statfs64(2). --- Claunia.IO/ChangeLog | 7 + Claunia.IO/Claunia.IO.csproj | 1 + .../Interop/Apple/Interop.Apple.statfs.cs | 244 ++++++++++++++++++ .../Interop/Apple/Interop.Apple.types.cs | 10 + 4 files changed, 262 insertions(+) create mode 100644 Claunia.IO/Interop/Apple/Interop.Apple.statfs.cs diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog index fd49978..a771d8c 100644 --- a/Claunia.IO/ChangeLog +++ b/Claunia.IO/ChangeLog @@ -1,3 +1,10 @@ +2015-04-26 Natalia Portillo + + * Claunia.IO.csproj: + * Interop/Apple/Interop.Apple.types.cs: + * Interop/Apple/Interop.Apple.statfs.cs: + Implement statfs(2) and statfs64(2). + 2015-04-25 Natalia Portillo * Interop/Apple/Interop.Apple.xattr.cs: diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index 5812f9e..1f17679 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -55,6 +55,7 @@ + diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.statfs.cs b/Claunia.IO/Interop/Apple/Interop.Apple.statfs.cs new file mode 100644 index 0000000..13fe9a5 --- /dev/null +++ b/Claunia.IO/Interop/Apple/Interop.Apple.statfs.cs @@ -0,0 +1,244 @@ +// +// Interop.Apple.stat.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.Runtime.InteropServices; +using System; + +internal static partial class Interop +{ + internal static partial class Apple + { + /// + /// statfs(2) structure when _DARWIN_FEATURE_64_BIT_INODE is defined + /// + [StructLayout(LayoutKind.Sequential)] + internal struct StatFS64 + { + /// + /// Type of file system (reserved: zero) + /// + [MarshalAs(UnmanagedType.I2)] + Int16 f_otype; + /// + /// Copy of mount flags (reserved: zero) + /// + [MarshalAs(UnmanagedType.I2)] + Int16 f_oflags; + /// + /// Fundamental file system block size + /// + [MarshalAs(UnmanagedType.I8)] + Int64 f_bsize; + /// + /// Optimal transfer block size + /// + [MarshalAs(UnmanagedType.I8)] + Int64 f_iosize; + /// + /// Total data blocks in file system + /// + [MarshalAs(UnmanagedType.I8)] + Int64 f_blocks; + /// + /// Free blocks in file system + /// + [MarshalAs(UnmanagedType.I8)] + Int64 f_bfree; + /// + /// Free blocks avail to non-superuser + /// + [MarshalAs(UnmanagedType.I8)] + Int64 f_bavail; + /// + /// Total file nodes in file system + /// + [MarshalAs(UnmanagedType.I8)] + Int64 f_files; + /// + /// Free file nodes in file system + /// + [MarshalAs(UnmanagedType.I8)] + Int64 f_ffree; + /// + /// File system id + /// + fsid_t f_fsid; + /// + /// User that mounted the file system + /// + [MarshalAs(UnmanagedType.U4)] + UInt32 f_owner; + /// + /// Reserved for future use + /// + [MarshalAs(UnmanagedType.I2)] + [Obsolete("RESERVED: DO NOT USE")] + Int16 f_reserved1; + /// + /// Type of file system (reserved) + /// + [MarshalAs(UnmanagedType.I2)] + Int16 f_type; + /// + /// Copy of mount flags (reserved) + /// + [MarshalAs(UnmanagedType.I8)] + Int64 f_flags; + /// + /// Reserved for future use + /// + [MarshalAs(UnmanagedType.ByValArray, + ArraySubType = UnmanagedType.I8, SizeConst = 2)] + [Obsolete("RESERVED: DO NOT USE")] + Int64[] f_reserved2; + /// + /// File system type name + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)] + string f_fstypename; + /// + /// Directory on which mounted + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 90)] + string f_mntonname; + /// + /// Mounted file system + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 90)] + string f_mntfromname; + /// + /// Reserved for future use + /// + [Obsolete("RESERVED: DO NOT USE")] + sbyte f_reserved3; + /// + /// Reserved for future use + /// + [MarshalAs(UnmanagedType.ByValArray, + ArraySubType = UnmanagedType.I8, SizeConst = 4)] + [Obsolete("RESERVED: DO NOT USE")] + 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 pointed by . + /// Calls to system's stat(2) + /// + /// Path to the file. + /// on 32 bit systems and on 64 bit systems. + /// 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 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 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 a50400f..0be269a 100644 --- a/Claunia.IO/Interop/Apple/Interop.Apple.types.cs +++ b/Claunia.IO/Interop/Apple/Interop.Apple.types.cs @@ -24,6 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System.Runtime.InteropServices; +using System; internal static partial class Interop { @@ -551,5 +552,14 @@ internal static partial class Interop /// kTextEncodingUnknown = 0xFFFF } + + /// + /// File system ID type + /// + struct fsid_t + { + public Int32 val1; + public Int32 val2; + } } } \ No newline at end of file