diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog index bd84773..f545948 100644 --- a/Claunia.IO/ChangeLog +++ b/Claunia.IO/ChangeLog @@ -1,3 +1,10 @@ +2015-05-03 Natalia Portillo + + * Claunia.IO.csproj: + * Interop/FreeBSD/Interop.FreeBSD.types.cs: + * Interop/FreeBSD/Interop.FreeBSD.statfs.cs: + Implement FreeBSD's statfs(2). + 2015-05-03 Natalia Portillo * Claunia.IO.csproj: diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index 837f800..e5dbc05 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -65,6 +65,7 @@ + diff --git a/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.statfs.cs b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.statfs.cs new file mode 100644 index 0000000..3653944 --- /dev/null +++ b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.statfs.cs @@ -0,0 +1,104 @@ +// +// Interop.FreeBSD.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 FreeBSD + { + /// + /// statfs(2) structure + /// + [StructLayout(LayoutKind.Sequential)] + internal struct StatFS + { + /// structure version number + UInt32 f_version; + /// type of filesystem + UInt32 f_type; + /// copy of mount exported flags + mntflags_t f_flags; + /// filesystem fragment size + UInt64 f_bsize; + /// optimal transfer block size + UInt64 f_iosize; + /// total data blocks in filesystem + UInt64 f_blocks; + /// free blocks in filesystem + UInt64 f_bfree; + /// free blocks avail to non-superuser + Int64 f_bavail; + /// total file nodes in filesystem + UInt64 f_files; + /// free nodes avail to non-superuser + Int64 f_ffree; + /// count of sync writes since mount + UInt64 f_syncwrites; + /// count of async writes since mount + UInt64 f_asyncwrites; + /// count of sync reads since mount + UInt64 f_syncreads; + /// count of async reads since mount + UInt64 f_asyncreads; + /// unused spare + [MarshalAs(UnmanagedType.ByValArray, + ArraySubType = UnmanagedType.U8, SizeConst = 10)] + [Obsolete("RESERVED: DO NOT USE")] + UInt64[] f_spare; + /// maximum filename length + UInt32 f_namemax; + /// user that mounted the filesystem + UInt32 f_owner; + /// filesystem id + fsid_t f_fsid; + /// spare string space + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] + string f_charspare; + /// filesystem type name + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] + string f_fstypename; + /// mounted filesystem + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 88)] + string f_mntfromname; + /// directory on which mounted + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 88)] + string f_mntonname; + + } + + /// + /// Obtains information of the file system mounted at . + /// Calls to system's statfs(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 statfs(string path, out StatFS buf); + } +} + diff --git a/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.types.cs b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.types.cs index 5e014a5..c6142d0 100644 --- a/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.types.cs +++ b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.types.cs @@ -59,5 +59,87 @@ internal static partial class Interop [MarshalAs(UnmanagedType.I4)] public Int64 tv_nsec; } + + /// + /// File system ID type + /// + struct fsid_t + { + public Int32 val1; + public Int32 val2; + } + + [Flags] + enum mntflags_t : UInt64 + { + MNT_RDONLY = 0x0000000000000001, + /// read only filesystem + MNT_SYNCHRONOUS = 0x0000000000000002, + /// fs written synchronously + MNT_NOEXEC = 0x0000000000000004, + /// can't exec from filesystem + MNT_NOSUID = 0x0000000000000008, + /// don't honor setuid fs bits + MNT_NFS4ACLS = 0x0000000000000010, + /// enable NFS version 4 ACLs + MNT_UNION = 0x0000000000000020, + /// union with underlying fs + MNT_ASYNC = 0x0000000000000040, + /// fs written asynchronously + MNT_SUIDDIR = 0x0000000000100000, + /// special SUID dir handling + MNT_SOFTDEP = 0x0000000000200000, + /// using soft updates + MNT_NOSYMFOLLOW = 0x0000000000400000, + /// do not follow symlinks + MNT_GJOURNAL = 0x0000000002000000, + /// GEOM journal support enabled + MNT_MULTILABEL = 0x0000000004000000, + /// MAC support for objects + MNT_ACLS = 0x0000000008000000, + /// ACL support enabled + MNT_NOATIME = 0x0000000010000000, + /// dont update file access time + MNT_NOCLUSTERR = 0x0000000040000000, + /// disable cluster read + MNT_NOCLUSTERW = 0x0000000080000000, + /// disable cluster write + MNT_SUJ = 0x0000000100000000, + /// using journaled soft updates + MNT_AUTOMOUNTED = 0x0000000200000000, + /// mounted by automountd(8) + + /* + * NFS export related mount flags. + */ + MNT_EXRDONLY = 0x0000000000000080, + /// exported read only + MNT_EXPORTED = 0x0000000000000100, + /// filesystem is exported + MNT_DEFEXPORTED = 0x0000000000000200, + /// exported to the world + MNT_EXPORTANON = 0x0000000000000400, + /// anon uid mapping for all + MNT_EXKERB = 0x0000000000000800, + /// exported with Kerberos + MNT_EXPUBLIC = 0x0000000020000000, + /// public export (WebNFS) + + /* + * Flags set by internal operations, + * but visible to the user. + * XXX some of these are not quite right.. (I've never seen the root flag set) + */ + MNT_LOCAL = 0x0000000000001000, + /// filesystem is stored locally + MNT_QUOTA = 0x0000000000002000, + /// quotas are enabled on fs + MNT_ROOTFS = 0x0000000000004000, + /// identifies the root fs + MNT_USER = 0x0000000000008000, + /// mounted by a user + MNT_IGNORE = 0x0000000000800000 + /// do not show entry in df + } } } \ No newline at end of file