Separate 32-bit from 64-bit calls.

This commit is contained in:
2015-05-07 05:59:59 +01:00
parent 9d2a1da76f
commit 6268db9279
11 changed files with 681 additions and 324 deletions

View File

@@ -1,3 +1,17 @@
2015-05-07 Natalia Portillo <claunia@claunia.com>
* 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 <claunia@claunia.com>
* Interop/FreeBSD/Interop.FreeBSD.types.cs:

View File

@@ -77,6 +77,11 @@
<Compile Include="Interop\Windows\Interop.Windows.Volumes.cs" />
<Compile Include="Interop\Apple\Interop.Apple.stat64.cs" />
<Compile Include="Interop\Apple\Interop.Apple.statfs64.cs" />
<Compile Include="Interop\FreeBSD\Interop.FreeBSD.extattr64.cs" />
<Compile Include="Interop\FreeBSD\Interop.FreeBSD.stat64.cs" />
<Compile Include="Interop\Linux\Interop.Linux.stat64.cs" />
<Compile Include="Interop\Linux\Interop.Linux.statfs64.cs" />
<Compile Include="Interop\Linux\Interop.Linux.xattr64.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

View File

@@ -0,0 +1,104 @@
//
// Interop.FreeBSD.extattr64.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// 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
{
/// <summary>
/// Gets an extended attribute value
/// Calls to system's extattr_get_file(2)
/// </summary>
/// <returns>Number of bytes read. If <paramref name="data"/> is <c>null</c>, then the size for the buffer to store the data.</returns>
/// <param name="path">Path to the file.</param>
/// <param name="attrnamespace">Extended attribute namespace, <see cref="attrNamespace"/>.</param>
/// <param name="attrname">Extended attribute name.</param>
/// <param name="data">Pointer to buffer where to store the data.</param>
/// <param name="nbytes">Size of the buffer.</param>
[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);
/// <summary>
/// Sets an extended attribute value
/// Calls to system's extattr_set_file(2)
/// </summary>
/// <returns>Number of bytes written.</returns>
/// <param name="path">Path to the file.</param>
/// <param name="attrnamespace">Extended attribute namespace, <see cref="attrNamespace"/>.</param>
/// <param name="attrname">Extended attribute name.</param>
/// <param name="data">Pointer where the data is stored.</param>
/// <param name="nbytes">Size of the data.</param>
[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);
/// <summary>
/// Deletes an extended attribute value
/// Calls to system's extattr_delete_file(2)
/// </summary>
/// <returns>0 if successful, -1 if failure.</returns>
/// <param name="path">Path to the file.</param>
/// <param name="attrnamespace">Extended attribute namespace, <see cref="attrNamespace"/>.</param>
/// <param name="attrname">Extended attribute name.</param>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern ssize_t extattr_delete_file(string path, attrNamespace attrnamespace, string attrname);
/// <summary>
/// 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)
/// </summary>
/// <returns>Size of the list in bytes. If <paramref name="data"/> is <c>null</c>, then the size for the buffer to store the list.</returns>
/// <param name="path">Path to the file.</param>
/// <param name="attrnamespace">Extended attribute namespace, <see cref="attrNamespace"/>.</param>
/// <param name="data">Pointer to buffer where to store the list.</param>
/// <param name="nbytes">Size of the buffer.</param>
[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);
}
}

View File

@@ -0,0 +1,135 @@
//
// Interop.FreeBSD.stat64.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// 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
{
/// <summary>
/// stat(2) structure when 64 bit
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct Stat64
{
/// <summary>
/// inode's device
/// </summary>
__dev_t st_dev;
/// <summary>
/// inode's number
/// </summary>
ino_t st_ino;
/// <summary>
/// inode protection mode
/// </summary>
mode_t st_mode;
/// <summary>
/// number of hard links
/// </summary>
nlink_t st_nlink;
/// <summary>
/// user ID of the file's owner
/// </summary>
uid_t st_uid;
/// <summary>
/// group ID of the file's group
/// </summary>
gid_t st_gid;
/// <summary>
/// device type
/// </summary>
__dev_t st_rdev;
/// <summary>
/// time of last access
/// </summary>
Timespec64 st_atim;
/// <summary>
/// time of last data modification
/// </summary>
Timespec64 st_mtim;
/// <summary>
/// time of last file status change
/// </summary>
Timespec64 st_ctim;
/// <summary>
/// file size, in bytes
/// </summary>
off_t st_size;
/// <summary>
/// blocks allocated for file
/// </summary>
blkcnt_t st_blocks;
/// <summary>
/// optimal blocksize for I/O
/// </summary>
blksize_t st_blksize;
/// <summary>
/// user defined flags for file
/// </summary>
flags_t st_flags;
/// <summary>
/// file generation number
/// </summary>
__uint32_t st_gen;
__int32_t st_lspare;
/// <summary>
/// time of file creation
/// </summary>
Timespec64 st_birthtim;
}
/// <summary>
/// Obtains information of the file pointed by <paramref name="path"/>.
/// Calls to system's stat64(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="buf"><see cref="Stat64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true, EntryPoint = "stat")]
public static extern int stat64(string path, out Stat64 buf);
}
}

View File

@@ -31,87 +31,7 @@ internal static partial class Interop
internal static partial class Linux
{
/// <summary>
/// stat(2) structure when 64 bits
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct Stat64
{
/// <summary>
/// ID of device containing file
/// </summary>
UInt64 st_dev;
/// <summary>
/// inode number
/// </summary>
UInt64 st_ino;
/// <summary>
/// number of hard links
/// </summary>
UInt64 st_nlink;
/// <summary>
/// protection
/// </summary>
mode_t st_mode;
/// <summary>
/// user ID of owner
/// </summary>
UInt32 st_uid;
/// <summary>
/// group ID of owner
/// </summary>
UInt32 st_gid;
/// <summary>
/// padding
/// </summary>
Int32 __pad0;
/// <summary>
/// device ID (if special file)
/// </summary>
UInt64 st_rdev;
/// <summary>
/// total size, in bytes
/// </summary>
Int64 st_size;
/// <summary>
/// blocksize for filesystem I/O
/// </summary>
Int64 st_blksize;
/// <summary>
/// number of 512B blocks allocated
/// </summary>
Int64 st_blocks;
/// <summary>
/// time of last access
/// </summary>
Int64 st_atime;
/// <summary>
/// time of last access nanosecond
/// </summary>
UInt64 st_atimensec;
/// <summary>
/// time of last modification
/// </summary>
Int64 st_mtime;
/// <summary>
/// time of last modification naonsecond
/// </summary>
UInt64 st_mtimensec;
/// <summary>
/// time of last status change
/// </summary>
Int64 st_ctime;
/// <summary>
/// time of last status change nanosecond
/// </summary>
UInt64 st_ctimensec;
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.I8, SizeConst = 3)]
[Obsolete("RESERVED: DO NOT USE")]
Int64[] __glibc_reserved;
}
/// <summary>
/// stat(2) structure when __DARWIN_64_BIT_INO_T is NOT defined
/// stat(2) structure when 32 bits
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct Stat
@@ -182,107 +102,6 @@ internal static partial class Interop
UInt32 __glibc_reserved5;
}
/// <summary>
/// File mode and permissions
/// </summary>
[Flags]
internal enum mode_t : UInt32
{
/// <summary>
/// bit mask for the file type bit fields
/// </summary>
S_IFMT = 0xF000,
/// <summary>
/// socket
/// </summary>
S_IFSOCK = 0xC000,
/// <summary>
/// symbolic link
/// </summary>
S_IFLNK = 0xA000,
/// <summary>
/// regular file
/// </summary>
S_IFREG = 0x8000,
/// <summary>
/// block device
/// </summary>
S_IFBLK = 0x6000,
/// <summary>
/// directory
/// </summary>
S_IFDIR = 0x4000,
/// <summary>
/// character device
/// </summary>
S_IFCHR = 0x2000,
/// <summary>
/// FIFO
/// </summary>
S_IFIFO = 0x1000,
/// <summary>
/// set-user-ID bit
/// </summary>
S_ISUID = 0x0800,
/// <summary>
/// set-group-ID bit
/// </summary>
S_ISGID = 0x0400,
/// <summary>
/// sticky bit (see below)
/// </summary>
S_ISVTX = 0x0200,
/// <summary>
/// mask for file owner permissions
/// </summary>
S_IRWXU = 0x01C0,
/// <summary>
/// owner has read permission
/// </summary>
S_IRUSR = 0x0100,
/// <summary>
/// owner has write permission
/// </summary>
S_IWUSR = 0x0080,
/// <summary>
/// owner has execute permission
/// </summary>
S_IXUSR = 0x0040,
/// <summary>
/// mask for group permissions
/// </summary>
S_IRWXG = 0x0038,
/// <summary>
/// group has read permission
/// </summary>
S_IRGRP = 0x0020,
/// <summary>
/// group has write permission
/// </summary>
S_IWGRP = 0x0010,
/// <summary>
/// group has execute permission
/// </summary>
S_IXGRP = 0x0008,
/// <summary>
/// mask for permissions for others (not in group)
/// </summary>
S_IRWXO = 0x0007,
/// <summary>
/// others have read permission
/// </summary>
S_IROTH = 0x0004,
/// <summary>
/// others have write permission
/// </summary>
S_IWOTH = 0x002,
/// <summary>
/// others have execute permission
/// </summary>
S_IXOTH = 0x00001
}
/// <summary>
/// Obtains information of the file pointed by <paramref name="path"/>.
/// Calls to system's stat(2) for 32 bit systems
@@ -292,16 +111,6 @@ internal static partial class Interop
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int stat(string path, out Stat buf);
/// <summary>
/// Obtains information of the file pointed by <paramref name="path"/>.
/// Calls to system's stat(2) for 64 bit systems
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="buf"><see cref="Stat64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true, EntryPoint="stat")]
public static extern int stat64(string path, out Stat64 buf);
}
}

View File

@@ -0,0 +1,124 @@
//
// Interop.Linux.stat64.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// 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
{
/// <summary>
/// stat(2) structure when 64 bits
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct Stat64
{
/// <summary>
/// ID of device containing file
/// </summary>
UInt64 st_dev;
/// <summary>
/// inode number
/// </summary>
UInt64 st_ino;
/// <summary>
/// number of hard links
/// </summary>
UInt64 st_nlink;
/// <summary>
/// protection
/// </summary>
mode_t st_mode;
/// <summary>
/// user ID of owner
/// </summary>
UInt32 st_uid;
/// <summary>
/// group ID of owner
/// </summary>
UInt32 st_gid;
/// <summary>
/// padding
/// </summary>
Int32 __pad0;
/// <summary>
/// device ID (if special file)
/// </summary>
UInt64 st_rdev;
/// <summary>
/// total size, in bytes
/// </summary>
Int64 st_size;
/// <summary>
/// blocksize for filesystem I/O
/// </summary>
Int64 st_blksize;
/// <summary>
/// number of 512B blocks allocated
/// </summary>
Int64 st_blocks;
/// <summary>
/// time of last access
/// </summary>
Int64 st_atime;
/// <summary>
/// time of last access nanosecond
/// </summary>
UInt64 st_atimensec;
/// <summary>
/// time of last modification
/// </summary>
Int64 st_mtime;
/// <summary>
/// time of last modification naonsecond
/// </summary>
UInt64 st_mtimensec;
/// <summary>
/// time of last status change
/// </summary>
Int64 st_ctime;
/// <summary>
/// time of last status change nanosecond
/// </summary>
UInt64 st_ctimensec;
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.I8, SizeConst = 3)]
[Obsolete("RESERVED: DO NOT USE")]
Int64[] __glibc_reserved;
}
/// <summary>
/// Obtains information of the file pointed by <paramref name="path"/>.
/// Calls to system's stat(2) for 64 bit systems
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="buf"><see cref="Stat64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true, EntryPoint = "stat")]
public static extern int stat64(string path, out Stat64 buf);
}
}

View File

@@ -1,5 +1,5 @@
//
// Interop.Linux.stat.cs
// Interop.Linux.statfs.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
@@ -30,64 +30,6 @@ internal static partial class Interop
{
internal static partial class Linux
{
/// <summary>
/// statfs(2) structure when __WORDSIZE is 64
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct StatFS64
{
/// <summary>
/// Type of filesystem (see below)
/// </summary>
Int64 f_type;
/// <summary>
/// Optimal transfer block size
/// </summary>
Int64 f_bsize;
/// <summary>
/// Total data blocks in filesystem
/// </summary>
UInt64 f_blocks;
/// <summary>
/// Free blocks in filesystem
/// </summary>
UInt64 f_bfree;
/// <summary>
/// Free blocks available to unprivileged user
/// </summary>
UInt64 f_bavail;
/// <summary>
/// Total file nodes in filesystem
/// </summary>
UInt64 f_files;
/// <summary>
/// Free file nodes in filesystem
/// </summary>
UInt64 f_ffree;
/// <summary>
/// Filesystem ID
/// </summary>
fsid_t f_fsid;
/// <summary>
/// Maximum length of filenames
/// </summary>
Int64 f_namelen;
/// <summary>
/// Fragment size (since Linux 2.6)
/// </summary>
Int64 f_frsize;
/// <summary>
/// Mount flags of filesystem (since Linux 2.6.36)
/// </summary>
f_flags64_t f_flags;
/// <summary>
/// Padding bytes reserved for future use
/// </summary>
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.I8, SizeConst = 4)]
Int64[] f_spare;
}
/// <summary>
/// statfs(2) structure when __WORDSIZE is 32
/// </summary>
@@ -156,17 +98,6 @@ internal static partial class Interop
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true)]
public static extern int statfs(string path, out StatFS buf);
/// <summary>
/// Obtains information of the file system mounted at <paramref name="path"/>.
/// Calls to system's statfs(2)
/// Only call if __WORDSIZE == 64
/// </summary>
/// <param name="path">Path to the filesystem mount point.</param>
/// <param name="buf"><see cref="StatFS64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true, EntryPoint = "statfs")]
public static extern int statfs64(string path, out StatFS64 buf);
}
}

View File

@@ -0,0 +1,103 @@
//
// Interop.Linux.statfs64.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// 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
{
/// <summary>
/// statfs(2) structure when __WORDSIZE is 64
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct StatFS64
{
/// <summary>
/// Type of filesystem (see below)
/// </summary>
Int64 f_type;
/// <summary>
/// Optimal transfer block size
/// </summary>
Int64 f_bsize;
/// <summary>
/// Total data blocks in filesystem
/// </summary>
UInt64 f_blocks;
/// <summary>
/// Free blocks in filesystem
/// </summary>
UInt64 f_bfree;
/// <summary>
/// Free blocks available to unprivileged user
/// </summary>
UInt64 f_bavail;
/// <summary>
/// Total file nodes in filesystem
/// </summary>
UInt64 f_files;
/// <summary>
/// Free file nodes in filesystem
/// </summary>
UInt64 f_ffree;
/// <summary>
/// Filesystem ID
/// </summary>
fsid_t f_fsid;
/// <summary>
/// Maximum length of filenames
/// </summary>
Int64 f_namelen;
/// <summary>
/// Fragment size (since Linux 2.6)
/// </summary>
Int64 f_frsize;
/// <summary>
/// Mount flags of filesystem (since Linux 2.6.36)
/// </summary>
f_flags64_t f_flags;
/// <summary>
/// Padding bytes reserved for future use
/// </summary>
[MarshalAs(UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.I8, SizeConst = 4)]
Int64[] f_spare;
}
/// <summary>
/// Obtains information of the file system mounted at <paramref name="path"/>.
/// Calls to system's statfs(2)
/// Only call if __WORDSIZE == 64
/// </summary>
/// <param name="path">Path to the filesystem mount point.</param>
/// <param name="buf"><see cref="StatFS64"/>.</param>
/// <returns>On success, 0. On failure, -1, and errno is set.</returns>
[DllImport(Libraries.Libc, SetLastError = true, EntryPoint = "statfs")]
public static extern int statfs64(string path, out StatFS64 buf);
}
}

View File

@@ -247,5 +247,117 @@ internal static partial class Interop
/// </summary>
public Int32 tv_nsec;
}
/// <summary>
/// File mode and permissions
/// </summary>
[Flags]
internal enum mode_t : UInt32
{
/// <summary>
/// bit mask for the file type bit fields
/// </summary>
S_IFMT = 0xF000,
/// <summary>
/// socket
/// </summary>
S_IFSOCK = 0xC000,
/// <summary>
/// symbolic link
/// </summary>
S_IFLNK = 0xA000,
/// <summary>
/// regular file
/// </summary>
S_IFREG = 0x8000,
/// <summary>
/// block device
/// </summary>
S_IFBLK = 0x6000,
/// <summary>
/// directory
/// </summary>
S_IFDIR = 0x4000,
/// <summary>
/// character device
/// </summary>
S_IFCHR = 0x2000,
/// <summary>
/// FIFO
/// </summary>
S_IFIFO = 0x1000,
/// <summary>
/// set-user-ID bit
/// </summary>
S_ISUID = 0x0800,
/// <summary>
/// set-group-ID bit
/// </summary>
S_ISGID = 0x0400,
/// <summary>
/// sticky bit (see below)
/// </summary>
S_ISVTX = 0x0200,
/// <summary>
/// mask for file owner permissions
/// </summary>
S_IRWXU = 0x01C0,
/// <summary>
/// owner has read permission
/// </summary>
S_IRUSR = 0x0100,
/// <summary>
/// owner has write permission
/// </summary>
S_IWUSR = 0x0080,
/// <summary>
/// owner has execute permission
/// </summary>
S_IXUSR = 0x0040,
/// <summary>
/// mask for group permissions
/// </summary>
S_IRWXG = 0x0038,
/// <summary>
/// group has read permission
/// </summary>
S_IRGRP = 0x0020,
/// <summary>
/// group has write permission
/// </summary>
S_IWGRP = 0x0010,
/// <summary>
/// group has execute permission
/// </summary>
S_IXGRP = 0x0008,
/// <summary>
/// mask for permissions for others (not in group)
/// </summary>
S_IRWXO = 0x0007,
/// <summary>
/// others have read permission
/// </summary>
S_IROTH = 0x0004,
/// <summary>
/// others have write permission
/// </summary>
S_IWOTH = 0x002,
/// <summary>
/// others have execute permission
/// </summary>
S_IXOTH = 0x00001
}
public enum xattrFlags : int
{
/// <summary>
/// Set the value and fail if the xattr already exists
/// </summary>
XATTR_CREATE = 0x0001,
/// <summary>
/// Set the value and fail if the xattr does not exist
/// </summary>
XATTR_REPLACE = 0x0002
}
}
}

View File

@@ -1,5 +1,5 @@
//
// Interop.Apple.xattr.cs
// Interop.Linux.xattr.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
@@ -30,67 +30,6 @@ internal static partial class Interop
{
internal static partial class Linux
{
public enum xattrFlags : int
{
/// <summary>
/// Set the value and fail if the xattr already exists
/// </summary>
XATTR_CREATE = 0x0001,
/// <summary>
/// Set the value and fail if the xattr does not exist
/// </summary>
XATTR_REPLACE = 0x0002
}
/// <summary>
/// Gets an extended attribute value
/// Calls to system's getxattr(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="name">Name of the extended attribute.</param>
/// <param name="value">Pointer to a buffer where to store the extended attribute.</param>
/// <param name="size">Size of the allocated buffer.</param>
/// <returns>Size of the extended attribute. On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern Int64 getxattr(string path, string name, IntPtr value, UInt64 size);
/// <summary>
/// Sets an extended attribute value
/// Calls to system's setxattr(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="name">Name of the extended attribute.</param>
/// <param name="value">Pointer to a buffer where the extended attribute is stored.</param>
/// <param name="size">Size of the allocated buffer.</param>
/// <returns>On success, 0. On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern Int64 setxattr(string path, string name, IntPtr value, UInt64 size, xattrFlags options);
/// <summary>
/// Removes an extended attribute
/// Calls to system's removexattr(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="name">Name of the extended attribute.</param>
/// <returns>On success, 0. On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern Int64 removexattr(string path, string name);
/// <summary>
/// Lists the extended attributes from a file
/// Calls to system's listxattr(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="namebuf">Pointer to a buffer where an unordered list of null terminated strings wth the extended attributes names is to be stored.</param>
/// <param name="size">Size of the allocated buffer.</param>
/// <returns>If <paramref name="namebuf"/> 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</returns>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern Int64 listxattr(string path, IntPtr namebuf, UInt64 size);
/// <summary>
/// Gets an extended attribute value
/// Calls to system's getxattr(2)

View File

@@ -0,0 +1,81 @@
//
// Interop.Linux.xattr64.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// 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
{
/// <summary>
/// Gets an extended attribute value
/// Calls to system's getxattr(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="name">Name of the extended attribute.</param>
/// <param name="value">Pointer to a buffer where to store the extended attribute.</param>
/// <param name="size">Size of the allocated buffer.</param>
/// <returns>Size of the extended attribute. On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern Int64 getxattr(string path, string name, IntPtr value, UInt64 size);
/// <summary>
/// Sets an extended attribute value
/// Calls to system's setxattr(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="name">Name of the extended attribute.</param>
/// <param name="value">Pointer to a buffer where the extended attribute is stored.</param>
/// <param name="size">Size of the allocated buffer.</param>
/// <returns>On success, 0. On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern Int64 setxattr(string path, string name, IntPtr value, UInt64 size, xattrFlags options);
/// <summary>
/// Removes an extended attribute
/// Calls to system's removexattr(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="name">Name of the extended attribute.</param>
/// <returns>On success, 0. On failure, -1, and errno is set</returns>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern Int64 removexattr(string path, string name);
/// <summary>
/// Lists the extended attributes from a file
/// Calls to system's listxattr(2)
/// </summary>
/// <param name="path">Path to the file.</param>
/// <param name="namebuf">Pointer to a buffer where an unordered list of null terminated strings wth the extended attributes names is to be stored.</param>
/// <param name="size">Size of the allocated buffer.</param>
/// <returns>If <paramref name="namebuf"/> 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</returns>
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern Int64 listxattr(string path, IntPtr namebuf, UInt64 size);
}
}