diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog index f545948..a3aa2d6 100644 --- a/Claunia.IO/ChangeLog +++ b/Claunia.IO/ChangeLog @@ -1,3 +1,9 @@ +2015-05-03 Natalia Portillo + + * Claunia.IO.csproj: + * Interop/FreeBSD/Interop.FreeBSD.extattr.cs: + Implemented FreeBSD's extattr(2). + 2015-05-03 Natalia Portillo * Claunia.IO.csproj: diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index e5dbc05..ced3490 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -66,6 +66,7 @@ + diff --git a/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.extattr.cs b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.extattr.cs new file mode 100644 index 0000000..36193a4 --- /dev/null +++ b/Claunia.IO/Interop/FreeBSD/Interop.FreeBSD.extattr.cs @@ -0,0 +1,162 @@ +// +// Interop.Apple.xattr.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 FreeBSD + { + public enum attrNamespace + { + /// + /// Empty namespace + /// + EXTATTR_NAMESPACE_EMPTY = 0x00000000, + /// + /// User namespace + /// + EXTATTR_NAMESPACE_USER = 0x00000001, + /// + /// System namespace + /// + EXTATTR_NAMESPACE_SYSTEM = 0x00000002 + } + + /// + /// Gets an extended attribute value + /// Calls to system's extattr_get_file(2) + /// + /// Number of bytes read. If is , 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)] + Int64 extattr_get_file(string path, attrNamespace attrnamespace, string attrname, IntPtr data, Int64 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)] + Int64 extattr_set_file(string path, attrNamespace attrnamespace, string attrname, IntPtr data, Int64 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. + /// Pointer to buffer where the data is stored. + /// Size of the pointer. + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + Int64 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 , then the size for the buffer to store the list. + /// Path to the file. + /// Extended attribute namespace, . + /// Extended attribute name. + /// Pointer to buffer where to store the list. + /// Size of the buffer. + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)] + Int64 extattr_list_file(string path, attrNamespace attrnamespace, IntPtr data, Int64 nbytes); + + /// + /// Gets an extended attribute value + /// Calls to system's extattr_get_file(2) + /// For 32-bit systems + /// + /// Number of bytes read. If is , 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, EntryPoint = "extattr_get_file")] + Int32 extattr_get_file32(string path, attrNamespace attrnamespace, string attrname, IntPtr data, Int32 nbytes); + + /// + /// Sets an extended attribute value + /// Calls to system's extattr_set_file(2) + /// For 32-bit systems + /// + /// 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, EntryPoint = "extattr_set_file")] + Int32 extattr_set_file32(string path, attrNamespace attrnamespace, string attrname, IntPtr data, Int32 nbytes); + + /// + /// Deletes an extended attribute value + /// Calls to system's extattr_delete_file(2) + /// For 32-bit systems + /// + /// 0 if successful, -1 if failure. + /// Path to the file. + /// Extended attribute namespace, . + /// Extended attribute name. + /// Pointer to buffer where the data is stored. + /// Size of the pointer. + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi, EntryPoint = "extattr_delete_file")] + Int32 extattr_delete_file32(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) + /// For 32-bit systems + /// + /// Size of the list in bytes. If is , then the size for the buffer to store the list. + /// Path to the file. + /// Extended attribute namespace, . + /// Extended attribute name. + /// Pointer to buffer where to store the list. + /// Size of the buffer. + [DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi, EntryPoint = "extattr_list_file")] + Int32 extattr_list_file32(string path, attrNamespace attrnamespace, IntPtr data, Int32 nbytes); + } +} +