Extended attribute bindings for Mono.Unix.Syscall Exposes the API found in and includes some convenience functions. Index: mono/configure.in =================================================================== --- mono/configure.in (revision 43087) +++ mono/configure.in (working copy) @@ -639,7 +639,12 @@ if test $large_offt = no; then AC_MSG_WARN([No 64 bit file size support available]) fi - + + dnl ************************************** + dnl *** Checks for extended attributes *** + dnl ************************************** + AC_CHECK_HEADERS(sys/xattr.h) + dnl ***************************** dnl *** Checks for libsocket *** dnl ***************************** Index: mono/ChangeLog =================================================================== --- mono/ChangeLog (revision 43087) +++ mono/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2004-04-16 Daniel Drake + + * configure.in: Add header checks for + 2005-04-15 Zoltan Varga * configure.in: Applied another freebsd patch from Bill Middleton (flashdict@gmail.com). Index: mono/support/xattr.c =================================================================== --- mono/support/xattr.c (revision 0) +++ mono/support/xattr.c (revision 0) @@ -0,0 +1,113 @@ +/* + * wrapper functions. + * + * Authors: + * Daniel Drake (dsd@gentoo.org) + * + * Copyright (C) 2005 Daniel Drake + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif /* ndef _GNU_SOURCE */ + +#include + +#ifdef HAVE_SYS_XATTR_H + +#include +#include +#include +#include +#include + +#include "map.h" +#include "mph.h" + +G_BEGIN_DECLS + +gint32 +Mono_Posix_Syscall_setxattr (const char *path, const char *name, char *value, mph_size_t size, gint32 flags) +{ + int _flags; + mph_return_if_size_t_overflow (size); + + if (Mono_Posix_FromXattrFlags (flags, &_flags) == -1) + return -1; + + return setxattr (path, name, value, size, _flags); +} + +gint32 +Mono_Posix_Syscall_lsetxattr (const char *path, const char *name, char *value, mph_size_t size, gint32 flags) +{ + int _flags; + mph_return_if_size_t_overflow (size); + + if (Mono_Posix_FromXattrFlags (flags, &_flags) == -1) + return -1; + + return lsetxattr (path, name, value, size, _flags); +} + +gint32 +Mono_Posix_Syscall_fsetxattr (int fd, const char *name, char *value, mph_size_t size, gint32 flags) +{ + int _flags; + mph_return_if_size_t_overflow (size); + + if (Mono_Posix_FromXattrFlags (flags, &_flags) == -1) + return -1; + + return lsetxattr (fd, name, value, (size_t) size, _flags); +} + +mph_ssize_t +Mono_Posix_Syscall_getxattr (const char *path, const char *name, void *value, mph_size_t size) +{ + mph_return_if_size_t_overflow (size); + return getxattr (path, name, value, (size_t) size); +} + +mph_ssize_t +Mono_Posix_Syscall_lgetxattr (const char *path, const char *name, void *value, mph_size_t size) +{ + mph_return_if_size_t_overflow (size); + return lgetxattr (path, name, value, (size_t) size); +} + +mph_ssize_t +Mono_Posix_Syscall_fgetxattr (int fd, const char *name, void *value, mph_size_t size) +{ + mph_return_if_size_t_overflow (size); + return fgetxattr (fd, name, value, (size_t) size); +} + +mph_ssize_t +Mono_Posix_Syscall_listxattr (const char *path, char *list, mph_size_t size) +{ + mph_return_if_size_t_overflow (size); + return listxattr (path, list, (size_t) size); +} + +mph_ssize_t +Mono_Posix_Syscall_llistxattr (const char *path, char *list, mph_size_t size) +{ + mph_return_if_size_t_overflow (size); + return llistxattr (path, list, (size_t) size); +} + +mph_ssize_t +Mono_Posix_Syscall_flistxattr (int fd, char *list, mph_size_t size) +{ + mph_return_if_size_t_overflow (size); + return flistxattr (fd, list, (size_t) size); +} + +G_END_DECLS + +#endif /* def HAVE_SYS_XATTR_H */ + +/* + * vim: noexpandtab + */ Index: mono/support/ChangeLog =================================================================== --- mono/support/ChangeLog (revision 43087) +++ mono/support/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2005-04-16 Daniel Drake + + * xattr.c: New file; wrapper functions + 2005-04-07 Zoltan Varga * errno.c: Use the GNU version of strerror_r if _GNU_SOURCE is defined Index: mono/support/Makefile.am =================================================================== --- mono/support/Makefile.am (revision 43087) +++ mono/support/Makefile.am (working copy) @@ -36,6 +36,7 @@ time.c \ unistd.c \ utime.c \ + xattr.c \ x-struct-str.c if PLATFORM_WIN32 Index: mcs/class/Mono.Posix/Mono.Unix/ChangeLog =================================================================== --- mcs/class/Mono.Posix/Mono.Unix/ChangeLog (revision 43090) +++ mcs/class/Mono.Posix/Mono.Unix/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2005-04-16 Daniel Drake + + * Syscall.cs: Add bindings for extended attribute manipulation + 2005-04-05 Miguel de Icaza * Syscall.cs: Set entry point for sys_syslog to be syslog. Index: mcs/class/Mono.Posix/Mono.Unix/Syscall.cs =================================================================== --- mcs/class/Mono.Posix/Mono.Unix/Syscall.cs (revision 43090) +++ mcs/class/Mono.Posix/Mono.Unix/Syscall.cs (working copy) @@ -613,6 +613,13 @@ POLLWRBAND = 0x0200, // Priority data may be written } + [Map][Flags] + public enum XattrFlags : int { + XATTR_AUTO = 0, + XATTR_CREATE = 1, + XATTR_REPLACE = 2, + } + #endregion #region Structures @@ -925,6 +932,210 @@ // // Then update UnixStream.BeginRead to use the aio* functions. + + #region Declarations + // + // -- COMPLETE + // + + // setxattr(2) + // int setxattr (const char *path, const char *name, + // const void *value, size_t size, int flags); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_setxattr")] + public static extern int setxattr (string path, string name, byte[] value, ulong size, XattrFlags flags); + + public static int setxattr (string path, string name, byte [] value, XattrFlags flags) + { + return setxattr (path, name, value, (ulong) value.Length, flags); + } + + // lsetxattr(2) + // int lsetxattr (const char *path, const char *name, + // const void *value, size_t size, int flags); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_lsetxattr")] + public static extern int lsetxattr (string path, string name, byte[] value, ulong size, XattrFlags flags); + + public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags) + { + return lsetxattr (path, name, value, (ulong) value.Length, flags); + } + + // fsetxattr(2) + // int fsetxattr (int fd, const char *name, + // const void *value, size_t size, int flags); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_fsetxattr")] + public static extern int fsetxattr (int fd, string name, byte[] value, ulong size, XattrFlags flags); + + public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags) + { + return fsetxattr (fd, name, value, (ulong) value.Length, flags); + } + + // getxattr(2) + // ssize_t getxattr (const char *path, const char *name, + // void *value, size_t size); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_getxattr")] + public static extern long getxattr (string path, string name, byte[] value, ulong size); + + public static long getxattr (string path, string name, byte [] value) + { + return getxattr (path, name, value, (ulong) value.Length); + } + + public static long getxattr (string path, string name, out byte [] value) + { + value = null; + long size = getxattr (path, name, value, 0); + if (size <= 0) + return size; + + value = new byte [size]; + return getxattr (path, name, value, (ulong) size); + } + + // lgetxattr(2) + // ssize_t lgetxattr (const char *path, const char *name, + // void *value, size_t size); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_lgetxattr")] + public static extern long lgetxattr (string path, string name, byte[] value, ulong size); + + public static long lgetxattr (string path, string name, byte [] value) + { + return lgetxattr (path, name, value, (ulong) value.Length); + } + + public static long lgetxattr (string path, string name, out byte [] value) + { + value = null; + long size = lgetxattr (path, name, value, 0); + if (size <= 0) + return size; + + value = new byte [size]; + return lgetxattr (path, name, value, (ulong) size); + } + + // fgetxattr(2) + // ssize_t fgetxattr (int fd, const char *name, + // void *value, size_t size); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_fgetxattr")] + public static extern long fgetxattr (int fd, string name, byte[] value, ulong size); + + public static long fgetxattr (int fd, string name, byte [] value) + { + return fgetxattr (fd, name, value, (ulong) value.Length); + } + + public static long fgetxattr (int fd, string name, out byte [] value) + { + value = null; + long size = fgetxattr (fd, name, value, 0); + if (size <= 0) + return size; + + value = new byte [size]; + return fgetxattr (fd, name, value, (ulong) size); + } + + // listxattr(2) + // ssize_t listxattr (const char *path, + // char *list, size_t size); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_listxattr")] + public static extern long listxattr (string path, byte[] list, ulong size); + + // Slight modification: returns 0 on success, negative on error + public static long listxattr (string path, Encoding encoding, out string [] values) + { + values = null; + long size = listxattr (path, null, 0); + if (size == 0) + values = new string [0]; + if (size <= 0) + return (int) size; + + byte[] list = new byte [size]; + long ret = listxattr (path, list, (ulong) size); + if (ret < 0) + return (int) ret; + + string [] output = encoding.GetString (list).Split((char) 0); + values = new string [output.Length - 1]; + Array.Copy (output, 0, values, 0, output.Length - 1); + return 0; + } + // llistxattr(2) + // ssize_t llistxattr (const char *path, + // char *list, size_t size); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_llistxattr")] + public static extern long llistxattr (string path, byte[] list, ulong size); + + // Slight modification: returns 0 on success, negative on error + public static long llistxattr (string path, Encoding encoding, out string [] values) + { + values = null; + long size = llistxattr (path, null, 0); + if (size == 0) + values = new string [0]; + if (size <= 0) + return (int) size; + + byte[] list = new byte [size]; + long ret = llistxattr (path, list, (ulong) size); + if (ret < 0) + return (int) ret; + + string [] output = encoding.GetString (list).Split((char) 0); + values = new string [output.Length - 1]; + Array.Copy (output, 0, values, 0, output.Length - 1); + return 0; + } + + // flistxattr(2) + // ssize_t flistxattr (int fd, + // char *list, size_t size); + [DllImport (MPH, SetLastError=true, + EntryPoint="Mono_Posix_Syscall_flistxattr")] + public static extern long flistxattr (int fd, byte[] list, ulong size); + + // Slight modification: returns 0 on success, negative on error + public static long flistxattr (int fd, Encoding encoding, out string [] values) + { + values = null; + long size = flistxattr (fd, null, 0); + if (size == 0) + values = new string [0]; + if (size <= 0) + return (int) size; + + byte[] list = new byte [size]; + long ret = flistxattr (fd, list, (ulong) size); + if (ret < 0) + return (int) ret; + + string [] output = encoding.GetString (list).Split((char) 0); + values = new string [output.Length - 1]; + Array.Copy (output, 0, values, 0, output.Length - 1); + return 0; + } + + [DllImport (LIBC, SetLastError=true)] + public static extern int removexattr (string path, string name); + + [DllImport (LIBC, SetLastError=true)] + public static extern int lremovexattr (string path, string name); + + [DllImport (LIBC, SetLastError=true)] + public static extern int fremovexattr (int fd, string name); + #endregion + #region Declarations // //