diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog index 52239f4..8e7aac9 100644 --- a/Claunia.IO/ChangeLog +++ b/Claunia.IO/ChangeLog @@ -1,3 +1,11 @@ +2015-02-12 Natalia Portillo + + * Claunia.IO.csproj: + * Interop/Apple/Interop.Apple.stat.cs: + * Interop/Apple/Interop.Apple.types.cs: + * Interop/Apple/Interop.Apple.Libraries.cs: + Interoped OS X stat(2) + 2015-02-11 Natalia Portillo * AppleEnums.cs: diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index 6625dc5..305b422 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -37,6 +37,9 @@ + + + @@ -44,4 +47,8 @@ LICENSE + + + + \ No newline at end of file diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.Libraries.cs b/Claunia.IO/Interop/Apple/Interop.Apple.Libraries.cs new file mode 100644 index 0000000..de19e7f --- /dev/null +++ b/Claunia.IO/Interop/Apple/Interop.Apple.Libraries.cs @@ -0,0 +1,37 @@ +// +// Interop.Apple.Libraries.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. + +internal static partial class Interop +{ + internal static partial class Apple + { + static class Libraries + { + internal const string Libc = "libc"; + } + } +} + diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.stat.cs b/Claunia.IO/Interop/Apple/Interop.Apple.stat.cs new file mode 100644 index 0000000..466816b --- /dev/null +++ b/Claunia.IO/Interop/Apple/Interop.Apple.stat.cs @@ -0,0 +1,332 @@ +// +// 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 + { + /// + /// stat(2) structure + /// + internal struct Stat + { + /// + /// 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; + } + + /// + /// 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 + } + + [DllImport(Libraries.Libc, SetLastError = true)] + static extern int stat(string path, out Stat buf); + } +} + diff --git a/Claunia.IO/Interop/Apple/Interop.Apple.types.cs b/Claunia.IO/Interop/Apple/Interop.Apple.types.cs new file mode 100644 index 0000000..e936034 --- /dev/null +++ b/Claunia.IO/Interop/Apple/Interop.Apple.types.cs @@ -0,0 +1,49 @@ +// +// Interop.Apple.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; + +internal static partial class Interop +{ + internal static partial class Apple + { + [StructLayout(LayoutKind.Sequential)] + internal struct Timespec + { + // TODO: Mono is 32-bit only on Mac OS X, but when it becomes 64-bit this will become int64 + /// + /// Seconds + /// + [MarshalAs(UnmanagedType.I4)] + public int tv_sec; + /// + /// Nanoseconds + /// + [MarshalAs(UnmanagedType.I4)] + public int tv_nsec; + } + } +} +