* Syscall.cs: The Statvfs structure should contain a MountFlags enumeration,
[mono.git] / mcs / class / Mono.Posix / Mono.Unix / Syscall.cs
index b3c40006ddf13302c1be58d7ed4d0493c82457bd..feaa7b37d5786d5f1163cc8076cd670feeb33904 100644 (file)
@@ -60,8 +60,8 @@ using System.Text;
 using Mono.Unix;
 
 [assembly:Mono.Unix.IncludeAttribute (
-       new string [] {"sys/types.h", "sys/stat.h", "sys/poll.h", "sys/wait.h",
-               "unistd.h", "fcntl.h", "signal.h", "poll.h", "grp.h", "errno.h"}, 
+       new string [] {"sys/types.h", "sys/stat.h", ">sys/poll.h", ">sys/wait.h",
+               "unistd.h", "fcntl.h", "signal.h", ">poll.h", ">grp.h", "errno.h", ">syslog.h"}, 
        new string [] {"_GNU_SOURCE", "_XOPEN_SOURCE"})]
 
 namespace Mono.Unix {
@@ -613,6 +613,27 @@ namespace Mono.Unix {
                POLLWRBAND  = 0x0200, // Priority data may be written
        }
 
+       [Map][Flags]
+       public enum XattrFlags : int {
+               XATTR_AUTO = 0,
+               XATTR_CREATE = 1,
+               XATTR_REPLACE = 2,
+       }
+
+       [Map][Flags]
+       public enum MountFlags : ulong {
+               ST_RDONLY      =    1,  // Mount read-only
+               ST_NOSUID      =    2,  // Ignore suid and sgid bits
+               ST_NODEV       =    4,  // Disallow access to device special files
+               ST_SYNCHRONOUS =   16,  // Writes are synced at once
+               ST_MANDLOCK    =   64,  // Allow mandatory locks on an FS
+               ST_WRITE       =  128,  // Write on file/directory/symlink
+               ST_APPEND      =  256,  // Append-only file
+               ST_IMMUTABLE   =  512,  // Immutable file
+               ST_NOATIME     = 1024,  // Do not update access times
+               ST_NODIRATIME  = 2048,  // Do not update directory access times
+       }
+
        #endregion
 
        #region Structures
@@ -659,7 +680,7 @@ namespace Mono.Unix {
                public /* fsfilcnt_t */ ulong f_ffree;    // # free inodes
                public /* fsfilcnt_t */ ulong f_favail;   // # free inodes for non-root
                public                  ulong f_fsid;     // file system id
-               public                  ulong f_flag;     // mount flags
+               public MountFlags             f_flag;     // mount flags
                public                  ulong f_namemax;  // maximum filename length
        }
 
@@ -894,6 +915,16 @@ namespace Mono.Unix {
        //
        // BSD- and GNU-specific exports can also be placed here.
        //
+       // Non-POSIX/XPG/etc. functions can also be placed here if:
+       //  (a) They'd be likely to be covered in a Steven's-like book
+       //  (b) The functions would be present in libc.so (or equivalent).
+       //
+       // If a function has its own library, that's a STRONG indicator that the
+       // function should get a different binding, probably in its own assembly, 
+       // so that package management can work sanely.  (That is, we'd like to avoid
+       // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
+       // run, and libFooLib.so doesn't exist.  That would be confusing.)
+       //
        // The only methods in here should be:
        //  (1) low-level functions
        //  (2) "Trivial" function overloads.  For example, if the parameters to a
@@ -925,6 +956,207 @@ namespace Mono.Unix {
                //
                // Then update UnixStream.BeginRead to use the aio* functions.
 
+
+               #region <attr/xattr.h> Declarations
+               //
+               // <attr/xattr.h> -- 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 <dirent.h> Declarations
                //
                // <dirent.h>
@@ -1880,7 +2112,7 @@ namespace Mono.Unix {
                        sys_openlog (ident, _option, _facility);
                }
 
-               [DllImport (LIBC)]
+               [DllImport (LIBC, EntryPoint="syslog")]
                private static extern void sys_syslog (int priority, string message);
 
                public static void syslog (SyslogFacility facility, SyslogLevel level, string message)
@@ -2111,17 +2343,17 @@ namespace Mono.Unix {
 
                // TODO: does Mono marshal arrays properly?
                [DllImport (LIBC, SetLastError=true)]
-               public static extern int execve (string path, string[] argv, string[] envp);
+               private static extern int execve (string path, string[] argv, string[] envp);
 
                [DllImport (LIBC, SetLastError=true)]
-               public static extern int fexecve (int fd, string[] argv, string[] envp);
+               private static extern int fexecve (int fd, string[] argv, string[] envp);
 
                [DllImport (LIBC, SetLastError=true)]
-               public static extern int execv (string path, string[] argv);
+               private static extern int execv (string path, string[] argv);
 
                // TODO: execle, execl, execlp
                [DllImport (LIBC, SetLastError=true)]
-               public static extern int execvp (string path, string[] argv);
+               private static extern int execvp (string path, string[] argv);
 
                [DllImport (LIBC, SetLastError=true)]
                public static extern int nice (int inc);
@@ -2270,14 +2502,14 @@ namespace Mono.Unix {
                [DllImport (LIBC, SetLastError=true)]
                [Obsolete ("DO NOT directly call fork(2); it bypasses essential " + 
                                "shutdown code.\nUse System.Diagnostics.Process instead")]
-               public static extern int fork ();
+               private static extern int fork ();
 
                // vfork(2)
                //    pid_t vfork(void);
                [DllImport (LIBC, SetLastError=true)]
                [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " + 
                                "shutdown code.\nUse System.Diagnostics.Process instead")]
-               public static extern int vfork ();
+               private static extern int vfork ();
 
                [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
                private static extern IntPtr sys_ttyname (int fd);