diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog index 4a0badf..bd84773 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.stat.cs: + * Interop/FreeBSD/Interop.FreeBSD.types.cs: + Implement FreeBSD's stat(2). + 2015-05-03 Natalia Portillo * Interop/Linux/Interop.Linux.stat.cs: diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index 301ad0d..837f800 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -63,6 +63,8 @@ + + diff --git a/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.stat.cs b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.stat.cs new file mode 100644 index 0000000..4778879 --- /dev/null +++ b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.stat.cs @@ -0,0 +1,352 @@ +// +// 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 FreeBSD + { + /// + /// stat(2) structure when 64 bit + /// + [StructLayout(LayoutKind.Sequential)] + internal struct Stat64 + { + /// + /// inode's device + /// + UInt32 st_dev; + /// + /// inode's number + /// + UInt32 st_ino; + /// + /// inode protection mode + /// + mode_t st_mode; + /// + /// number of hard links + /// + UInt16 st_nlink; + /// + /// user ID of the file's owner + /// + UInt32 st_uid; + /// + /// group ID of the file's group + /// + UInt32 st_gid; + /// + /// device type + /// + UInt32 st_rdev; + /// + /// time of last access + /// + Timespec64 st_atim; + /// + /// time of last data modification + /// + Timespec64 st_mtim; + /// + /// time of last file status change + /// + Timespec64 st_ctim; + /// + /// file size, in bytes + /// + Int64 st_size; + /// + /// blocks allocated for file + /// + Int64 st_blocks; + /// + /// optimal blocksize for I/O + /// + Int32 st_blksize; + /// + /// user defined flags for file + /// + flags_t st_flags; + /// + /// file generation number + /// + UInt32 st_gen; + Int32 st_lspare; + /// + /// time of file creation + /// + Timespec64 st_birthtim; + } + + /// + /// stat(2) structure when 32 bit + /// + [StructLayout(LayoutKind.Sequential)] + internal struct Stat + { + /// + /// inode's device + /// + UInt32 st_dev; + /// + /// inode's number + /// + UInt32 st_ino; + /// + /// inode protection mode + /// + mode_t st_mode; + /// + /// number of hard links + /// + UInt16 st_nlink; + /// + /// user ID of the file's owner + /// + UInt32 st_uid; + /// + /// group ID of the file's group + /// + UInt32 st_gid; + /// + /// device type + /// + UInt32 st_rdev; + /// + /// time of last access + /// + Timespec st_atim; + /// + /// time of last data modification + /// + Timespec st_mtim; + /// + /// time of last file status change + /// + Timespec st_ctim; + /// + /// file size, in bytes + /// + Int64 st_size; + /// + /// blocks allocated for file + /// + Int64 st_blocks; + /// + /// optimal blocksize for I/O + /// + Int32 st_blksize; + /// + /// user defined flags for file + /// + flags_t st_flags; + /// + /// file generation number + /// + UInt32 st_gen; + Int32 st_lspare; + /// + /// time of file creation + /// + Timespec st_birthtim; + } + + /// + /// File mode and permissions + /// + [Flags] + internal enum mode_t : ushort + { + /// type of file mask + S_IFMT = 0xF000, + /// named pipe (fifo) + S_IFIFO = 0x1000, + /// character special + S_IFCHR = 0x2000, + /// directory + S_IFDIR = 0x4000, + /// block special + S_IFBLK = 0x6000, + /// regular + S_IFREG = 0x8000, + /// symbolic link + S_IFLNK = 0xA000, + /// socket + S_IFSOCK = 0xC000, + /// whiteout + S_IFWHT = 0xE000, + /// set user id on execution + S_ISUID = 0x0800, + /// set group id on execution + S_ISGID = 0x0400, + /// save swapped text even after use + S_ISVTX = 0x0200, + /// RWX mask for owner + S_IRWXU = 0x01C0, + /// read permission, owner + S_IRUSR = 0x0100, + /// write permission, owner + S_IWUSR = 0x0080, + /// execute/search permission, owner + S_IXUSR = 0x0040, + /// RWX mask for group + S_IRWXG = 0x0038, + /// read permission, group + S_IRGRP = 0x0020, + /// write permission, group + S_IWGRP = 0x0010, + /// execute/search permission, group + S_IXGRP = 0x0008, + /// RWX mask for other + S_IRWXO = 0x0007, + /// read permission, other + S_IROTH = 0x0004, + /// write permission, other + S_IWOTH = 0x0002, + /// execute/search permission, other + S_IXOTH = 0x0001 + } + + /// + /// User-set flags + /// + [Flags] + internal enum flags_t : uint + { + /// + /// Mask of owner changeable flags + /// + UF_SETTABLE = 0x0000FFFF, + /// + /// Do not dump file + /// + UF_NODUMP = 0x00000001, + /// + /// File may not be changed + /// + UF_IMMUTABLE = 0x00000002, + /// + /// Writes to file may only append + /// + UF_APPEND = 0x00000004, + /// + /// The directory is opaque when viewed through a union stack. + /// + UF_OPAQUE = 0x00000008, + /// + /// File may not be removed or renamed. + /// + UF_NOUNLINK = 0x00000010, + /// + /// File is compressed in HFS+ (>=10.6) + /// + [Obsolete("Unimplemented in FreeBSD")] + UF_COMPRESSED = 0x00000020, + /// + /// OBSOLETE: No longer used. + /// Issue notifications for deletes or renames of files with this flag set + /// + [Obsolete("Unimplemented in FreeBSD")] + UF_TRACKED = 0x00000040, + /// + /// Windows system file bit + /// + UF_SYSTEM = 0x00000080, + /// + /// Sparse file + /// + UF_SPARSE = 0x00000100, + /// + /// File is offline + /// + UF_OFFLINE = 0x00000200, + /// + /// Windows reparse point file bit + /// + UF_REPARSE = 0x00000400, + /// + /// File needs to be archived + /// + UF_ARCHIVE = 0x00000800, + /// + /// Windows readonly file bit + /// + UF_READONLY = 0x00001000, + + /// + /// File is hidden + /// + UF_HIDDEN = 0x00008000, + + /// + /// Mask of superuser changeable flags + /// + SF_SETTABLE = 0xffff0000, + /// + /// File is archived + /// + SF_ARCHIVED = 0x00010000, + /// + /// File may not be changed + /// + SF_IMMUTABLE = 0x00020000, + /// + /// Writes to file may only append + /// + SF_APPEND = 0x00040000, + /// + /// File may not be removed or renamed + /// + SF_NOUNLINK = 0x00100000, + /// + /// Snapshot inode + /// + SF_SNAPSHOT = 0x00200000 + } + + /// + /// 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 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, EntryPoint="stat")] + public static extern int stat64(string path, out Stat64 buf); + } +} \ No newline at end of file diff --git a/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.types.cs b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.types.cs new file mode 100644 index 0000000..5e014a5 --- /dev/null +++ b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.types.cs @@ -0,0 +1,63 @@ +// +// Interop.FreeBSD.types.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 + { + [StructLayout(LayoutKind.Sequential)] + internal struct Timespec + { + /// + /// Seconds + /// + [MarshalAs(UnmanagedType.I4)] + public Int32 tv_sec; + /// + /// Nanoseconds + /// + [MarshalAs(UnmanagedType.I4)] + public Int32 tv_nsec; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct Timespec64 + { + /// + /// Seconds + /// + [MarshalAs(UnmanagedType.I4)] + public Int64 tv_sec; + /// + /// Nanoseconds + /// + [MarshalAs(UnmanagedType.I4)] + public Int64 tv_nsec; + } + } +} \ No newline at end of file