diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog index 54380d3..ec1aa5b 100644 --- a/Claunia.IO/ChangeLog +++ b/Claunia.IO/ChangeLog @@ -1,3 +1,17 @@ +2015-05-07 Natalia Portillo + + * Claunia.IO.csproj: + * Interop/Linux/Interop.Linux.stat.cs: + * Interop/Linux/Interop.Linux.xattr.cs: + * Interop/Linux/Interop.Linux.types.cs: + * Interop/Linux/Interop.Linux.statfs.cs: + * Interop/Linux/Interop.Linux.stat64.cs: + * Interop/Linux/Interop.Linux.xattr64.cs: + * Interop/Linux/Interop.Linux.statfs64.cs: + * Interop/FreeBSD/Interop.FreeBSD.stat64.cs: + * Interop/FreeBSD/Interop.FreeBSD.extattr64.cs: + Separate 32-bit from 64-bit calls. + 2015-05-07 Natalia Portillo * Interop/FreeBSD/Interop.FreeBSD.types.cs: diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index 04b7772..ba2a571 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -77,6 +77,11 @@ + + + + + diff --git a/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.extattr64.cs b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.extattr64.cs new file mode 100644 index 0000000..2f3574b --- /dev/null +++ b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.extattr64.cs @@ -0,0 +1,104 @@ +// +// Interop.FreeBSD.extattr64.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 FreeBSD 64-bit type definitions +using blkcnt_t = System.Int64; +using blksize_t = System.Int32; +using gid_t = System.UInt32; +using ino_t = System.UInt32; +using int64_t = System.Int64; +using nlink_t = System.UInt16; +using off_t = System.Int64; +using size_t = System.Int64; +using ssize_t = System.Int64; +using uid_t = System.UInt32; +using uint32_t = System.UInt32; +using uint64_t = System.UInt64; +using __dev_t = System.UInt32; +using __int32_t = System.Int32; +using __uint32_t = System.UInt32; + +#endregion + +internal static partial class Interop +{ + internal static partial class FreeBSD + { + /// + /// Gets an extended attribute value + /// Calls to system's extattr_get_file(2) + /// + /// Number of bytes read. If is null, then the size for the buffer to store the data. + /// Path to the file. + /// Extended attribute namespace, . + /// Extended attribute name. + /// Pointer to buffer where to store the data. + /// Size of the buffer. + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + public static extern ssize_t extattr_get_file(string path, attrNamespace attrnamespace, string attrname, IntPtr data, size_t nbytes); + + /// + /// Sets an extended attribute value + /// Calls to system's extattr_set_file(2) + /// + /// Number of bytes written. + /// Path to the file. + /// Extended attribute namespace, . + /// Extended attribute name. + /// Pointer where the data is stored. + /// Size of the data. + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + public static extern ssize_t extattr_set_file(string path, attrNamespace attrnamespace, string attrname, IntPtr data, size_t nbytes); + + /// + /// Deletes an extended attribute value + /// Calls to system's extattr_delete_file(2) + /// + /// 0 if successful, -1 if failure. + /// Path to the file. + /// Extended attribute namespace, . + /// Extended attribute name. + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + public static extern ssize_t extattr_delete_file(string path, attrNamespace attrnamespace, string attrname); + + /// + /// Gets a list of extended attributes that the file has in that namespace + /// The list is stored in the buffer as an undetermined length of Pascal strings, + /// 1 byte tells the size of the extended attribute name in bytes, and is followed by the name. + /// Calls to system's extattr_list_file(2) + /// + /// Size of the list in bytes. If is null, then the size for the buffer to store the list. + /// Path to the file. + /// Extended attribute namespace, . + /// Pointer to buffer where to store the list. + /// Size of the buffer. + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + public static extern ssize_t extattr_list_file(string path, attrNamespace attrnamespace, IntPtr data, size_t nbytes); + } +} + diff --git a/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.stat64.cs b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.stat64.cs new file mode 100644 index 0000000..d83900f --- /dev/null +++ b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.stat64.cs @@ -0,0 +1,135 @@ +// +// Interop.FreeBSD.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.Runtime.InteropServices; +using System; + +#region FreeBSD 64-bit type definitions +using blkcnt_t = System.Int64; +using blksize_t = System.Int32; +using gid_t = System.UInt32; +using ino_t = System.UInt32; +using int64_t = System.Int64; +using nlink_t = System.UInt16; +using off_t = System.Int64; +using size_t = System.Int64; +using ssize_t = System.Int64; +using uid_t = System.UInt32; +using uint32_t = System.UInt32; +using uint64_t = System.UInt64; +using __dev_t = System.UInt32; +using __int32_t = System.Int32; +using __uint32_t = System.UInt32; + +#endregion + +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 + /// + __dev_t st_dev; + /// + /// inode's number + /// + ino_t st_ino; + /// + /// inode protection mode + /// + mode_t st_mode; + /// + /// number of hard links + /// + nlink_t st_nlink; + /// + /// user ID of the file's owner + /// + uid_t st_uid; + /// + /// group ID of the file's group + /// + gid_t st_gid; + /// + /// device type + /// + __dev_t 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 + /// + off_t st_size; + /// + /// blocks allocated for file + /// + blkcnt_t st_blocks; + /// + /// optimal blocksize for I/O + /// + blksize_t st_blksize; + /// + /// user defined flags for file + /// + flags_t st_flags; + /// + /// file generation number + /// + __uint32_t st_gen; + __int32_t st_lspare; + /// + /// time of file creation + /// + Timespec64 st_birthtim; + } + + /// + /// 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/Linux/Interop.Linux.stat.cs b/Claunia.IO/Interop/Linux/Interop.Linux.stat.cs index a67292d..d699623 100644 --- a/Claunia.IO/Interop/Linux/Interop.Linux.stat.cs +++ b/Claunia.IO/Interop/Linux/Interop.Linux.stat.cs @@ -31,87 +31,7 @@ internal static partial class Interop internal static partial class Linux { /// - /// stat(2) structure when 64 bits - /// - [StructLayout(LayoutKind.Sequential)] - internal struct Stat64 - { - /// - /// ID of device containing file - /// - UInt64 st_dev; - /// - /// inode number - /// - UInt64 st_ino; - /// - /// number of hard links - /// - UInt64 st_nlink; - /// - /// protection - /// - mode_t st_mode; - /// - /// user ID of owner - /// - UInt32 st_uid; - /// - /// group ID of owner - /// - UInt32 st_gid; - /// - /// padding - /// - Int32 __pad0; - /// - /// device ID (if special file) - /// - UInt64 st_rdev; - /// - /// total size, in bytes - /// - Int64 st_size; - /// - /// blocksize for filesystem I/O - /// - Int64 st_blksize; - /// - /// number of 512B blocks allocated - /// - Int64 st_blocks; - /// - /// time of last access - /// - Int64 st_atime; - /// - /// time of last access nanosecond - /// - UInt64 st_atimensec; - /// - /// time of last modification - /// - Int64 st_mtime; - /// - /// time of last modification naonsecond - /// - UInt64 st_mtimensec; - /// - /// time of last status change - /// - Int64 st_ctime; - /// - /// time of last status change nanosecond - /// - UInt64 st_ctimensec; - [MarshalAs(UnmanagedType.ByValArray, - ArraySubType = UnmanagedType.I8, SizeConst = 3)] - [Obsolete("RESERVED: DO NOT USE")] - Int64[] __glibc_reserved; - } - - /// - /// stat(2) structure when __DARWIN_64_BIT_INO_T is NOT defined + /// stat(2) structure when 32 bits /// [StructLayout(LayoutKind.Sequential)] internal struct Stat @@ -182,107 +102,6 @@ internal static partial class Interop UInt32 __glibc_reserved5; } - /// - /// File mode and permissions - /// - [Flags] - internal enum mode_t : UInt32 - { - /// - /// bit mask for the file type bit fields - /// - S_IFMT = 0xF000, - /// - /// socket - /// - S_IFSOCK = 0xC000, - /// - /// symbolic link - /// - S_IFLNK = 0xA000, - /// - /// regular file - /// - S_IFREG = 0x8000, - /// - /// block device - /// - S_IFBLK = 0x6000, - /// - /// directory - /// - S_IFDIR = 0x4000, - /// - /// character device - /// - S_IFCHR = 0x2000, - /// - /// FIFO - /// - S_IFIFO = 0x1000, - /// - /// set-user-ID bit - /// - S_ISUID = 0x0800, - /// - /// set-group-ID bit - /// - S_ISGID = 0x0400, - /// - /// sticky bit (see below) - /// - S_ISVTX = 0x0200, - /// - /// mask for file owner permissions - /// - S_IRWXU = 0x01C0, - /// - /// owner has read permission - /// - S_IRUSR = 0x0100, - /// - /// owner has write permission - /// - S_IWUSR = 0x0080, - /// - /// owner has execute permission - /// - S_IXUSR = 0x0040, - /// - /// mask for group permissions - /// - S_IRWXG = 0x0038, - /// - /// group has read permission - /// - S_IRGRP = 0x0020, - /// - /// group has write permission - /// - S_IWGRP = 0x0010, - /// - /// group has execute permission - /// - S_IXGRP = 0x0008, - /// - /// mask for permissions for others (not in group) - /// - S_IRWXO = 0x0007, - /// - /// others have read permission - /// - S_IROTH = 0x0004, - /// - /// others have write permission - /// - S_IWOTH = 0x002, - /// - /// others have execute permission - /// - S_IXOTH = 0x00001 - } - - /// /// Obtains information of the file pointed by . /// Calls to system's stat(2) for 32 bit systems @@ -292,16 +111,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 stat(2) for 64 bit systems - /// - /// 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); } } diff --git a/Claunia.IO/Interop/Linux/Interop.Linux.stat64.cs b/Claunia.IO/Interop/Linux/Interop.Linux.stat64.cs new file mode 100644 index 0000000..a48a722 --- /dev/null +++ b/Claunia.IO/Interop/Linux/Interop.Linux.stat64.cs @@ -0,0 +1,124 @@ +// +// Interop.Linux.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.Runtime.InteropServices; +using System; + +internal static partial class Interop +{ + internal static partial class Linux + { + /// + /// stat(2) structure when 64 bits + /// + [StructLayout(LayoutKind.Sequential)] + internal struct Stat64 + { + /// + /// ID of device containing file + /// + UInt64 st_dev; + /// + /// inode number + /// + UInt64 st_ino; + /// + /// number of hard links + /// + UInt64 st_nlink; + /// + /// protection + /// + mode_t st_mode; + /// + /// user ID of owner + /// + UInt32 st_uid; + /// + /// group ID of owner + /// + UInt32 st_gid; + /// + /// padding + /// + Int32 __pad0; + /// + /// device ID (if special file) + /// + UInt64 st_rdev; + /// + /// total size, in bytes + /// + Int64 st_size; + /// + /// blocksize for filesystem I/O + /// + Int64 st_blksize; + /// + /// number of 512B blocks allocated + /// + Int64 st_blocks; + /// + /// time of last access + /// + Int64 st_atime; + /// + /// time of last access nanosecond + /// + UInt64 st_atimensec; + /// + /// time of last modification + /// + Int64 st_mtime; + /// + /// time of last modification naonsecond + /// + UInt64 st_mtimensec; + /// + /// time of last status change + /// + Int64 st_ctime; + /// + /// time of last status change nanosecond + /// + UInt64 st_ctimensec; + [MarshalAs(UnmanagedType.ByValArray, + ArraySubType = UnmanagedType.I8, SizeConst = 3)] + [Obsolete("RESERVED: DO NOT USE")] + Int64[] __glibc_reserved; + } + + /// + /// Obtains information of the file pointed by . + /// Calls to system's stat(2) for 64 bit systems + /// + /// 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); + } +} + diff --git a/Claunia.IO/Interop/Linux/Interop.Linux.statfs.cs b/Claunia.IO/Interop/Linux/Interop.Linux.statfs.cs index 26612d1..e3c3855 100644 --- a/Claunia.IO/Interop/Linux/Interop.Linux.statfs.cs +++ b/Claunia.IO/Interop/Linux/Interop.Linux.statfs.cs @@ -1,5 +1,5 @@ // -// Interop.Linux.stat.cs +// Interop.Linux.statfs.cs // // Author: // Natalia Portillo @@ -30,64 +30,6 @@ internal static partial class Interop { internal static partial class Linux { - /// - /// statfs(2) structure when __WORDSIZE is 64 - /// - [StructLayout(LayoutKind.Sequential)] - internal struct StatFS64 - { - /// - /// Type of filesystem (see below) - /// - Int64 f_type; - /// - /// Optimal transfer block size - /// - Int64 f_bsize; - /// - /// Total data blocks in filesystem - /// - UInt64 f_blocks; - /// - /// Free blocks in filesystem - /// - UInt64 f_bfree; - /// - /// Free blocks available to unprivileged user - /// - UInt64 f_bavail; - /// - /// Total file nodes in filesystem - /// - UInt64 f_files; - /// - /// Free file nodes in filesystem - /// - UInt64 f_ffree; - /// - /// Filesystem ID - /// - fsid_t f_fsid; - /// - /// Maximum length of filenames - /// - Int64 f_namelen; - /// - /// Fragment size (since Linux 2.6) - /// - Int64 f_frsize; - /// - /// Mount flags of filesystem (since Linux 2.6.36) - /// - f_flags64_t f_flags; - /// - /// Padding bytes reserved for future use - /// - [MarshalAs(UnmanagedType.ByValArray, - ArraySubType = UnmanagedType.I8, SizeConst = 4)] - Int64[] f_spare; - } - /// /// statfs(2) structure when __WORDSIZE is 32 /// @@ -156,17 +98,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 statfs(2) - /// Only call if __WORDSIZE == 64 - /// - /// Path to the filesystem mount point. - /// . - /// On success, 0. On failure, -1, and errno is set. - [DllImport(Libraries.Libc, SetLastError = true, EntryPoint = "statfs")] - public static extern int statfs64(string path, out StatFS64 buf); } } diff --git a/Claunia.IO/Interop/Linux/Interop.Linux.statfs64.cs b/Claunia.IO/Interop/Linux/Interop.Linux.statfs64.cs new file mode 100644 index 0000000..4126074 --- /dev/null +++ b/Claunia.IO/Interop/Linux/Interop.Linux.statfs64.cs @@ -0,0 +1,103 @@ +// +// Interop.Linux.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.Runtime.InteropServices; +using System; + +internal static partial class Interop +{ + internal static partial class Linux + { + /// + /// statfs(2) structure when __WORDSIZE is 64 + /// + [StructLayout(LayoutKind.Sequential)] + internal struct StatFS64 + { + /// + /// Type of filesystem (see below) + /// + Int64 f_type; + /// + /// Optimal transfer block size + /// + Int64 f_bsize; + /// + /// Total data blocks in filesystem + /// + UInt64 f_blocks; + /// + /// Free blocks in filesystem + /// + UInt64 f_bfree; + /// + /// Free blocks available to unprivileged user + /// + UInt64 f_bavail; + /// + /// Total file nodes in filesystem + /// + UInt64 f_files; + /// + /// Free file nodes in filesystem + /// + UInt64 f_ffree; + /// + /// Filesystem ID + /// + fsid_t f_fsid; + /// + /// Maximum length of filenames + /// + Int64 f_namelen; + /// + /// Fragment size (since Linux 2.6) + /// + Int64 f_frsize; + /// + /// Mount flags of filesystem (since Linux 2.6.36) + /// + f_flags64_t f_flags; + /// + /// Padding bytes reserved for future use + /// + [MarshalAs(UnmanagedType.ByValArray, + ArraySubType = UnmanagedType.I8, SizeConst = 4)] + Int64[] f_spare; + } + + /// + /// Obtains information of the file system mounted at . + /// Calls to system's statfs(2) + /// Only call if __WORDSIZE == 64 + /// + /// Path to the filesystem mount point. + /// . + /// On success, 0. On failure, -1, and errno is set. + [DllImport(Libraries.Libc, SetLastError = true, EntryPoint = "statfs")] + public static extern int statfs64(string path, out StatFS64 buf); + } +} + diff --git a/Claunia.IO/Interop/Linux/Interop.Linux.types.cs b/Claunia.IO/Interop/Linux/Interop.Linux.types.cs index c103be4..2e39e20 100644 --- a/Claunia.IO/Interop/Linux/Interop.Linux.types.cs +++ b/Claunia.IO/Interop/Linux/Interop.Linux.types.cs @@ -247,5 +247,117 @@ internal static partial class Interop /// public Int32 tv_nsec; } + + /// + /// File mode and permissions + /// + [Flags] + internal enum mode_t : UInt32 + { + /// + /// bit mask for the file type bit fields + /// + S_IFMT = 0xF000, + /// + /// socket + /// + S_IFSOCK = 0xC000, + /// + /// symbolic link + /// + S_IFLNK = 0xA000, + /// + /// regular file + /// + S_IFREG = 0x8000, + /// + /// block device + /// + S_IFBLK = 0x6000, + /// + /// directory + /// + S_IFDIR = 0x4000, + /// + /// character device + /// + S_IFCHR = 0x2000, + /// + /// FIFO + /// + S_IFIFO = 0x1000, + /// + /// set-user-ID bit + /// + S_ISUID = 0x0800, + /// + /// set-group-ID bit + /// + S_ISGID = 0x0400, + /// + /// sticky bit (see below) + /// + S_ISVTX = 0x0200, + /// + /// mask for file owner permissions + /// + S_IRWXU = 0x01C0, + /// + /// owner has read permission + /// + S_IRUSR = 0x0100, + /// + /// owner has write permission + /// + S_IWUSR = 0x0080, + /// + /// owner has execute permission + /// + S_IXUSR = 0x0040, + /// + /// mask for group permissions + /// + S_IRWXG = 0x0038, + /// + /// group has read permission + /// + S_IRGRP = 0x0020, + /// + /// group has write permission + /// + S_IWGRP = 0x0010, + /// + /// group has execute permission + /// + S_IXGRP = 0x0008, + /// + /// mask for permissions for others (not in group) + /// + S_IRWXO = 0x0007, + /// + /// others have read permission + /// + S_IROTH = 0x0004, + /// + /// others have write permission + /// + S_IWOTH = 0x002, + /// + /// others have execute permission + /// + S_IXOTH = 0x00001 + } + + public enum xattrFlags : int + { + /// + /// Set the value and fail if the xattr already exists + /// + XATTR_CREATE = 0x0001, + /// + /// Set the value and fail if the xattr does not exist + /// + XATTR_REPLACE = 0x0002 + } } } \ No newline at end of file diff --git a/Claunia.IO/Interop/Linux/Interop.Linux.xattr.cs b/Claunia.IO/Interop/Linux/Interop.Linux.xattr.cs index 0a3fed0..c8909da 100644 --- a/Claunia.IO/Interop/Linux/Interop.Linux.xattr.cs +++ b/Claunia.IO/Interop/Linux/Interop.Linux.xattr.cs @@ -1,5 +1,5 @@ // -// Interop.Apple.xattr.cs +// Interop.Linux.xattr.cs // // Author: // Natalia Portillo @@ -30,67 +30,6 @@ internal static partial class Interop { internal static partial class Linux { - public enum xattrFlags : int - { - /// - /// Set the value and fail if the xattr already exists - /// - XATTR_CREATE = 0x0001, - /// - /// Set the value and fail if the xattr does not exist - /// - XATTR_REPLACE = 0x0002 - } - - /// - /// Gets an extended attribute value - /// Calls to system's getxattr(2) - /// - /// Path to the file. - /// Name of the extended attribute. - /// Pointer to a buffer where to store the extended attribute. - /// Size of the allocated buffer. - /// Size of the extended attribute. On failure, -1, and errno is set - [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] - public static extern Int64 getxattr(string path, string name, IntPtr value, UInt64 size); - - /// - /// Sets an extended attribute value - /// Calls to system's setxattr(2) - /// - /// Path to the file. - /// Name of the extended attribute. - /// Pointer to a buffer where the extended attribute is stored. - /// Size of the allocated buffer. - /// On success, 0. On failure, -1, and errno is set - [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] - public static extern Int64 setxattr(string path, string name, IntPtr value, UInt64 size, xattrFlags options); - - /// - /// Removes an extended attribute - /// Calls to system's removexattr(2) - /// - /// Path to the file. - /// Name of the extended attribute. - /// On success, 0. On failure, -1, and errno is set - [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] - public static extern Int64 removexattr(string path, string name); - - /// - /// Lists the extended attributes from a file - /// Calls to system's listxattr(2) - /// - /// Path to the file. - /// Pointer to a buffer where an unordered list of null terminated strings wth the extended attributes names is to be stored. - /// Size of the allocated buffer. - /// If is set to null, the needed size to store the whole list. - /// On success, the size of the list. - /// If the file has no extended attributes, 0. - /// On failure, -1, and errno is set - [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] - public static extern Int64 listxattr(string path, IntPtr namebuf, UInt64 size); - - /// /// Gets an extended attribute value /// Calls to system's getxattr(2) diff --git a/Claunia.IO/Interop/Linux/Interop.Linux.xattr64.cs b/Claunia.IO/Interop/Linux/Interop.Linux.xattr64.cs new file mode 100644 index 0000000..a698a05 --- /dev/null +++ b/Claunia.IO/Interop/Linux/Interop.Linux.xattr64.cs @@ -0,0 +1,81 @@ +// +// Interop.Linux.xattr64.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; + +internal static partial class Interop +{ + internal static partial class Linux + { + /// + /// Gets an extended attribute value + /// Calls to system's getxattr(2) + /// + /// Path to the file. + /// Name of the extended attribute. + /// Pointer to a buffer where to store the extended attribute. + /// Size of the allocated buffer. + /// Size of the extended attribute. On failure, -1, and errno is set + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + public static extern Int64 getxattr(string path, string name, IntPtr value, UInt64 size); + + /// + /// Sets an extended attribute value + /// Calls to system's setxattr(2) + /// + /// Path to the file. + /// Name of the extended attribute. + /// Pointer to a buffer where the extended attribute is stored. + /// Size of the allocated buffer. + /// On success, 0. On failure, -1, and errno is set + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + public static extern Int64 setxattr(string path, string name, IntPtr value, UInt64 size, xattrFlags options); + + /// + /// Removes an extended attribute + /// Calls to system's removexattr(2) + /// + /// Path to the file. + /// Name of the extended attribute. + /// On success, 0. On failure, -1, and errno is set + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + public static extern Int64 removexattr(string path, string name); + + /// + /// Lists the extended attributes from a file + /// Calls to system's listxattr(2) + /// + /// Path to the file. + /// Pointer to a buffer where an unordered list of null terminated strings wth the extended attributes names is to be stored. + /// Size of the allocated buffer. + /// If is set to null, the needed size to store the whole list. + /// On success, the size of the list. + /// If the file has no extended attributes, 0. + /// On failure, -1, and errno is set + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + public static extern Int64 listxattr(string path, IntPtr namebuf, UInt64 size); + } +} \ No newline at end of file