* fstab.c: Added; wrap <fstab.h> functions: getfsent(3), getfsfile(3),
authorJonathan Pryor <jpryor@novell.com>
Tue, 28 Dec 2004 17:08:46 +0000 (17:08 -0000)
committerJonathan Pryor <jpryor@novell.com>
Tue, 28 Dec 2004 17:08:46 +0000 (17:08 -0000)
    getfsspec(3).
  * map.c: Add new conversion functions for SyslogOptions, SyslogFacility,
    SyslogLevel; see syslog(3) for details.
  * map.h: Add new conversion functions and values for SyslogOptions,
    SyslogFacility, SyslogLevel; see syslog(3) for details.
  * Makefile.am (MPH_SOURCE): add fstab.c, sys-statvfs.c, x-struct-str.c.
  * mph.h: Document location for Mac OS X man page documentation; add
    MPH_INTERNAL macro for intra-library function calls (for functions that
    shouldn't be exported from libMonoPosixHelper.so); declare
    _mph_copy_structure_strings().
  * pwd.c: Use _mph_copy_structure_strings() to copy strings embedded within
    struct passwd.
  * sys-statvfs.c: Added; wrap <sys/statvfs.h> functions statvfs(2),
    fstatvfs(2), and (to complicate things) implement (f)statvfs(2) in terms
    of (f)statfs(2) on Mac OS X (which lacks the -vfs calls).
  * x-struct-str.c: implements _mph_copy_structure_strings(), which is a
    generalized interface to copy strings between structures (as is needed in
    pwd.c and fstab.c).

svn path=/trunk/mono/; revision=38132

support/ChangeLog
support/Makefile.am
support/fstab.c [new file with mode: 0644]
support/map.c
support/map.h
support/mph.h
support/pwd.c
support/sys-statvfs.c [new file with mode: 0644]
support/x-struct-str.c [new file with mode: 0644]

index c5331b60c129b08aa57453172345dde4de20cca9..e8bcd6e648b07c15c6972e731521ce80e53a2707 100644 (file)
@@ -1,3 +1,24 @@
+2004-11-30  Jonathan Pryor  <jonpryor@vt.edu>
+
+       * fstab.c: Added; wrap <fstab.h> functions: getfsent(3), getfsfile(3), 
+         getfsspec(3).
+       * map.c: Add new conversion functions for SyslogOptions, SyslogFacility, 
+         SyslogLevel; see syslog(3) for details.
+       * map.h: Add new conversion functions and values for SyslogOptions, 
+         SyslogFacility, SyslogLevel; see syslog(3) for details.
+       * Makefile.am (MPH_SOURCE): add fstab.c, sys-statvfs.c, x-struct-str.c.
+       * mph.h: Document location for Mac OS X man page documentation; add
+         MPH_INTERNAL macro for intra-library function calls (for functions that
+         shouldn't be exported from libMonoPosixHelper.so); declare
+         _mph_copy_structure_strings().
+       * pwd.c: Use _mph_copy_structure_strings() to copy strings embedded within
+         struct passwd.
+       * sys-statvfs.c: Added; wrap <sys/statvfs.h> functions statvfs(2),
+         fstatvfs(2), and (to complicate things) implement (f)statvfs(2) in terms
+         of (f)statfs(2) on Mac OS X (which lacks the -vfs calls).
+       * x-struct-str.c: implements _mph_copy_structure_strings(), which is a
+         generalized interface to copy strings between structures (as is needed in
+         pwd.c and fstab.c).
 
 Thu Dec 23 14:58:09 EST 2004 Paolo Molaro <lupus@ximian.com>
 
index 15171af53a084f4f519f2c0c5a74abc46a49dd37..dab02dedc1ed057ee1e92bca9e9147e1f197a891 100644 (file)
@@ -15,6 +15,7 @@ MPH_SOURCE = \
        dirent.c        \
        errno.c         \
        fcntl.c         \
+       fstab.c   \
        grp.c           \
        macros.c        \
        map.c           \
@@ -26,11 +27,13 @@ MPH_SOURCE = \
        sys-mman.c      \
        sys-sendfile.c  \
        sys-stat.c      \
+       sys-statvfs.c   \
        sys-time.c      \
        sys-wait.c      \
        time.c          \
        unistd.c         \
-       utime.c
+       utime.c    \
+       x-struct-str.c
 
 if HAVE_ZLIB
 libMonoPosixHelper_la_SOURCES = \
diff --git a/support/fstab.c b/support/fstab.c
new file mode 100644 (file)
index 0000000..124bc6b
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * <fstab.h> wrapper functions.
+ *
+ * Authors:
+ *   Jonathan Pryor (jonpryor@vt.edu)
+ *
+ * Copyright (C) 2004 Jonathan Pryor
+ */
+
+#include <fstab.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mph.h"
+
+G_BEGIN_DECLS
+
+struct Mono_Posix_Syscall__Fstab {
+       char  *fs_spec;     /* block device name */
+       char  *fs_file;     /* mount point */
+       char  *fs_vfstype;      /* filesystem type */
+       char  *fs_mntops;   /* mount options */
+       char  *fs_type;     /* rw/rq/ro/sw/xx option */
+       int    fs_freq;     /* dump frequency, in days */
+       int    fs_passno;   /* pass number on parallel dump */
+
+       char  *_fs_buf_;
+};
+
+static const size_t
+fstab_offsets[] = {
+       offsetof (struct fstab, fs_spec),
+       offsetof (struct fstab, fs_file),
+       offsetof (struct fstab, fs_vfstype),
+       offsetof (struct fstab, fs_mntops),
+       offsetof (struct fstab, fs_type)
+};
+
+static const size_t
+mph_fstab_offsets[] = {
+       offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
+       offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
+       offsetof (struct Mono_Posix_Syscall__Fstab, fs_vfstype),
+       offsetof (struct Mono_Posix_Syscall__Fstab, fs_mntops),
+       offsetof (struct Mono_Posix_Syscall__Fstab, fs_type)
+};
+
+/*
+ * Copy the native `passwd' structure to it's managed representation.
+ *
+ * To minimize separate mallocs, all the strings are allocated within the same
+ * memory block (stored in _fs_buf_).
+ */
+static int
+copy_fstab (struct Mono_Posix_Syscall__Fstab *to, struct fstab *from)
+{
+       char *buf;
+       buf = _mph_copy_structure_strings (to, mph_fstab_offsets,
+                       from, fstab_offsets, sizeof(fstab_offsets)/sizeof(fstab_offsets[0]));
+
+       to->fs_freq   = from->fs_freq;
+       to->fs_passno = from->fs_passno;
+
+       to->_fs_buf_ = buf;
+       if (buf == NULL) {
+               return -1;
+       }
+
+       return 0;
+}
+
+gint32
+Mono_Posix_Syscall_getfsent (struct Mono_Posix_Syscall__Fstab *fsbuf)
+{
+       struct fstab *fs;
+
+       if (fsbuf == NULL) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       fs = getfsent ();
+       if (fs == NULL)
+               return -1;
+
+       if (copy_fstab (fsbuf, fs) == -1) {
+               errno = ENOMEM;
+               return -1;
+       }
+       return 0;
+}
+
+gint32
+Mono_Posix_Syscall_getfsfile (const char *mount_point, 
+               struct Mono_Posix_Syscall__Fstab *fsbuf)
+{
+       struct fstab *fs;
+
+       if (fsbuf == NULL) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       fs = getfsfile (mount_point);
+       if (fs == NULL)
+               return -1;
+
+       if (copy_fstab (fsbuf, fs) == -1) {
+               errno = ENOMEM;
+               return -1;
+       }
+       return 0;
+}
+
+gint32
+Mono_Posix_Syscall_getfsspec (const char *special_file, 
+               struct Mono_Posix_Syscall__Fstab *fsbuf)
+{
+       struct fstab *fs;
+
+       if (fsbuf == NULL) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       fs = getfsspec (special_file);
+       if (fs == NULL)
+               return -1;
+
+       if (copy_fstab (fsbuf, fs) == -1) {
+               errno = ENOMEM;
+               return -1;
+       }
+       return 0;
+}
+
+G_END_DECLS
+
+/*
+ * vim: noexpandtab
+ */
index a987cacda3ead491a71c4f39c4bfccbeb57fdd4d..f6cb26690c235a3a219977c7ebdd812d37a786df 100644 (file)
@@ -1278,6 +1278,394 @@ int Mono_Posix_ToError (int x, int *r)
        errno = EINVAL; return -1;
 }
 
+int Mono_Posix_FromSyslogOptions (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+       if ((x & Mono_Posix_SyslogOptions_LOG_PID) == Mono_Posix_SyslogOptions_LOG_PID)
+#ifdef LOG_PID
+               *r |= LOG_PID;
+#else /* def LOG_PID */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_PID */
+       if ((x & Mono_Posix_SyslogOptions_LOG_CONS) == Mono_Posix_SyslogOptions_LOG_CONS)
+#ifdef LOG_CONS
+               *r |= LOG_CONS;
+#else /* def LOG_CONS */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_CONS */
+       if ((x & Mono_Posix_SyslogOptions_LOG_ODELAY) == Mono_Posix_SyslogOptions_LOG_ODELAY)
+#ifdef LOG_ODELAY
+               *r |= LOG_ODELAY;
+#else /* def LOG_ODELAY */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_ODELAY */
+       if ((x & Mono_Posix_SyslogOptions_LOG_NDELAY) == Mono_Posix_SyslogOptions_LOG_NDELAY)
+#ifdef LOG_NDELAY
+               *r |= LOG_NDELAY;
+#else /* def LOG_NDELAY */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_NDELAY */
+       if ((x & Mono_Posix_SyslogOptions_LOG_NOWAIT) == Mono_Posix_SyslogOptions_LOG_NOWAIT)
+#ifdef LOG_NOWAIT
+               *r |= LOG_NOWAIT;
+#else /* def LOG_NOWAIT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_NOWAIT */
+       if ((x & Mono_Posix_SyslogOptions_LOG_PERROR) == Mono_Posix_SyslogOptions_LOG_PERROR)
+#ifdef LOG_PERROR
+               *r |= LOG_PERROR;
+#else /* def LOG_PERROR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_PERROR */
+       return 0;
+}
+
+int Mono_Posix_ToSyslogOptions (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef LOG_PID
+       if ((x & LOG_PID) == LOG_PID)
+               *r |= Mono_Posix_SyslogOptions_LOG_PID;
+#endif /* ndef LOG_PID */
+#ifdef LOG_CONS
+       if ((x & LOG_CONS) == LOG_CONS)
+               *r |= Mono_Posix_SyslogOptions_LOG_CONS;
+#endif /* ndef LOG_CONS */
+#ifdef LOG_ODELAY
+       if ((x & LOG_ODELAY) == LOG_ODELAY)
+               *r |= Mono_Posix_SyslogOptions_LOG_ODELAY;
+#endif /* ndef LOG_ODELAY */
+#ifdef LOG_NDELAY
+       if ((x & LOG_NDELAY) == LOG_NDELAY)
+               *r |= Mono_Posix_SyslogOptions_LOG_NDELAY;
+#endif /* ndef LOG_NDELAY */
+#ifdef LOG_NOWAIT
+       if ((x & LOG_NOWAIT) == LOG_NOWAIT)
+               *r |= Mono_Posix_SyslogOptions_LOG_NOWAIT;
+#endif /* ndef LOG_NOWAIT */
+#ifdef LOG_PERROR
+       if ((x & LOG_PERROR) == LOG_PERROR)
+               *r |= Mono_Posix_SyslogOptions_LOG_PERROR;
+#endif /* ndef LOG_PERROR */
+       return 0;
+}
+
+int Mono_Posix_FromSyslogFacility (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+       if ((x & Mono_Posix_SyslogFacility_LOG_KERN) == Mono_Posix_SyslogFacility_LOG_KERN)
+#ifdef LOG_KERN
+               *r |= LOG_KERN;
+#else /* def LOG_KERN */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_KERN */
+       if ((x & Mono_Posix_SyslogFacility_LOG_USRE) == Mono_Posix_SyslogFacility_LOG_USRE)
+#ifdef LOG_USRE
+               *r |= LOG_USRE;
+#else /* def LOG_USRE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_USRE */
+       if ((x & Mono_Posix_SyslogFacility_LOG_MAIL) == Mono_Posix_SyslogFacility_LOG_MAIL)
+#ifdef LOG_MAIL
+               *r |= LOG_MAIL;
+#else /* def LOG_MAIL */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_MAIL */
+       if ((x & Mono_Posix_SyslogFacility_LOG_DAEMON) == Mono_Posix_SyslogFacility_LOG_DAEMON)
+#ifdef LOG_DAEMON
+               *r |= LOG_DAEMON;
+#else /* def LOG_DAEMON */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_DAEMON */
+       if ((x & Mono_Posix_SyslogFacility_LOG_AUTH) == Mono_Posix_SyslogFacility_LOG_AUTH)
+#ifdef LOG_AUTH
+               *r |= LOG_AUTH;
+#else /* def LOG_AUTH */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_AUTH */
+       if ((x & Mono_Posix_SyslogFacility_LOG_SYSLOG) == Mono_Posix_SyslogFacility_LOG_SYSLOG)
+#ifdef LOG_SYSLOG
+               *r |= LOG_SYSLOG;
+#else /* def LOG_SYSLOG */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_SYSLOG */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LPR) == Mono_Posix_SyslogFacility_LOG_LPR)
+#ifdef LOG_LPR
+               *r |= LOG_LPR;
+#else /* def LOG_LPR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LPR */
+       if ((x & Mono_Posix_SyslogFacility_LOG_NEWS) == Mono_Posix_SyslogFacility_LOG_NEWS)
+#ifdef LOG_NEWS
+               *r |= LOG_NEWS;
+#else /* def LOG_NEWS */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_NEWS */
+       if ((x & Mono_Posix_SyslogFacility_LOG_UUCP) == Mono_Posix_SyslogFacility_LOG_UUCP)
+#ifdef LOG_UUCP
+               *r |= LOG_UUCP;
+#else /* def LOG_UUCP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_UUCP */
+       if ((x & Mono_Posix_SyslogFacility_LOG_CRON) == Mono_Posix_SyslogFacility_LOG_CRON)
+#ifdef LOG_CRON
+               *r |= LOG_CRON;
+#else /* def LOG_CRON */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_CRON */
+       if ((x & Mono_Posix_SyslogFacility_LOG_AUTHPRIV) == Mono_Posix_SyslogFacility_LOG_AUTHPRIV)
+#ifdef LOG_AUTHPRIV
+               *r |= LOG_AUTHPRIV;
+#else /* def LOG_AUTHPRIV */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_AUTHPRIV */
+       if ((x & Mono_Posix_SyslogFacility_LOG_FTP) == Mono_Posix_SyslogFacility_LOG_FTP)
+#ifdef LOG_FTP
+               *r |= LOG_FTP;
+#else /* def LOG_FTP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_FTP */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LOCAL0) == Mono_Posix_SyslogFacility_LOG_LOCAL0)
+#ifdef LOG_LOCAL0
+               *r |= LOG_LOCAL0;
+#else /* def LOG_LOCAL0 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LOCAL0 */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LOCAL1) == Mono_Posix_SyslogFacility_LOG_LOCAL1)
+#ifdef LOG_LOCAL1
+               *r |= LOG_LOCAL1;
+#else /* def LOG_LOCAL1 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LOCAL1 */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LOCAL2) == Mono_Posix_SyslogFacility_LOG_LOCAL2)
+#ifdef LOG_LOCAL2
+               *r |= LOG_LOCAL2;
+#else /* def LOG_LOCAL2 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LOCAL2 */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LOCAL3) == Mono_Posix_SyslogFacility_LOG_LOCAL3)
+#ifdef LOG_LOCAL3
+               *r |= LOG_LOCAL3;
+#else /* def LOG_LOCAL3 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LOCAL3 */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LOCAL4) == Mono_Posix_SyslogFacility_LOG_LOCAL4)
+#ifdef LOG_LOCAL4
+               *r |= LOG_LOCAL4;
+#else /* def LOG_LOCAL4 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LOCAL4 */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LOCAL5) == Mono_Posix_SyslogFacility_LOG_LOCAL5)
+#ifdef LOG_LOCAL5
+               *r |= LOG_LOCAL5;
+#else /* def LOG_LOCAL5 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LOCAL5 */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LOCAL6) == Mono_Posix_SyslogFacility_LOG_LOCAL6)
+#ifdef LOG_LOCAL6
+               *r |= LOG_LOCAL6;
+#else /* def LOG_LOCAL6 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LOCAL6 */
+       if ((x & Mono_Posix_SyslogFacility_LOG_LOCAL7) == Mono_Posix_SyslogFacility_LOG_LOCAL7)
+#ifdef LOG_LOCAL7
+               *r |= LOG_LOCAL7;
+#else /* def LOG_LOCAL7 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_LOCAL7 */
+       return 0;
+}
+
+int Mono_Posix_ToSyslogFacility (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef LOG_KERN
+       if ((x & LOG_KERN) == LOG_KERN)
+               *r |= Mono_Posix_SyslogFacility_LOG_KERN;
+#endif /* ndef LOG_KERN */
+#ifdef LOG_USRE
+       if ((x & LOG_USRE) == LOG_USRE)
+               *r |= Mono_Posix_SyslogFacility_LOG_USRE;
+#endif /* ndef LOG_USRE */
+#ifdef LOG_MAIL
+       if ((x & LOG_MAIL) == LOG_MAIL)
+               *r |= Mono_Posix_SyslogFacility_LOG_MAIL;
+#endif /* ndef LOG_MAIL */
+#ifdef LOG_DAEMON
+       if ((x & LOG_DAEMON) == LOG_DAEMON)
+               *r |= Mono_Posix_SyslogFacility_LOG_DAEMON;
+#endif /* ndef LOG_DAEMON */
+#ifdef LOG_AUTH
+       if ((x & LOG_AUTH) == LOG_AUTH)
+               *r |= Mono_Posix_SyslogFacility_LOG_AUTH;
+#endif /* ndef LOG_AUTH */
+#ifdef LOG_SYSLOG
+       if ((x & LOG_SYSLOG) == LOG_SYSLOG)
+               *r |= Mono_Posix_SyslogFacility_LOG_SYSLOG;
+#endif /* ndef LOG_SYSLOG */
+#ifdef LOG_LPR
+       if ((x & LOG_LPR) == LOG_LPR)
+               *r |= Mono_Posix_SyslogFacility_LOG_LPR;
+#endif /* ndef LOG_LPR */
+#ifdef LOG_NEWS
+       if ((x & LOG_NEWS) == LOG_NEWS)
+               *r |= Mono_Posix_SyslogFacility_LOG_NEWS;
+#endif /* ndef LOG_NEWS */
+#ifdef LOG_UUCP
+       if ((x & LOG_UUCP) == LOG_UUCP)
+               *r |= Mono_Posix_SyslogFacility_LOG_UUCP;
+#endif /* ndef LOG_UUCP */
+#ifdef LOG_CRON
+       if ((x & LOG_CRON) == LOG_CRON)
+               *r |= Mono_Posix_SyslogFacility_LOG_CRON;
+#endif /* ndef LOG_CRON */
+#ifdef LOG_AUTHPRIV
+       if ((x & LOG_AUTHPRIV) == LOG_AUTHPRIV)
+               *r |= Mono_Posix_SyslogFacility_LOG_AUTHPRIV;
+#endif /* ndef LOG_AUTHPRIV */
+#ifdef LOG_FTP
+       if ((x & LOG_FTP) == LOG_FTP)
+               *r |= Mono_Posix_SyslogFacility_LOG_FTP;
+#endif /* ndef LOG_FTP */
+#ifdef LOG_LOCAL0
+       if ((x & LOG_LOCAL0) == LOG_LOCAL0)
+               *r |= Mono_Posix_SyslogFacility_LOG_LOCAL0;
+#endif /* ndef LOG_LOCAL0 */
+#ifdef LOG_LOCAL1
+       if ((x & LOG_LOCAL1) == LOG_LOCAL1)
+               *r |= Mono_Posix_SyslogFacility_LOG_LOCAL1;
+#endif /* ndef LOG_LOCAL1 */
+#ifdef LOG_LOCAL2
+       if ((x & LOG_LOCAL2) == LOG_LOCAL2)
+               *r |= Mono_Posix_SyslogFacility_LOG_LOCAL2;
+#endif /* ndef LOG_LOCAL2 */
+#ifdef LOG_LOCAL3
+       if ((x & LOG_LOCAL3) == LOG_LOCAL3)
+               *r |= Mono_Posix_SyslogFacility_LOG_LOCAL3;
+#endif /* ndef LOG_LOCAL3 */
+#ifdef LOG_LOCAL4
+       if ((x & LOG_LOCAL4) == LOG_LOCAL4)
+               *r |= Mono_Posix_SyslogFacility_LOG_LOCAL4;
+#endif /* ndef LOG_LOCAL4 */
+#ifdef LOG_LOCAL5
+       if ((x & LOG_LOCAL5) == LOG_LOCAL5)
+               *r |= Mono_Posix_SyslogFacility_LOG_LOCAL5;
+#endif /* ndef LOG_LOCAL5 */
+#ifdef LOG_LOCAL6
+       if ((x & LOG_LOCAL6) == LOG_LOCAL6)
+               *r |= Mono_Posix_SyslogFacility_LOG_LOCAL6;
+#endif /* ndef LOG_LOCAL6 */
+#ifdef LOG_LOCAL7
+       if ((x & LOG_LOCAL7) == LOG_LOCAL7)
+               *r |= Mono_Posix_SyslogFacility_LOG_LOCAL7;
+#endif /* ndef LOG_LOCAL7 */
+       return 0;
+}
+
+int Mono_Posix_FromSyslogLevel (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+       if ((x & Mono_Posix_SyslogLevel_LOG_EMERG) == Mono_Posix_SyslogLevel_LOG_EMERG)
+#ifdef LOG_EMERG
+               *r |= LOG_EMERG;
+#else /* def LOG_EMERG */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_EMERG */
+       if ((x & Mono_Posix_SyslogLevel_LOG_ALERT) == Mono_Posix_SyslogLevel_LOG_ALERT)
+#ifdef LOG_ALERT
+               *r |= LOG_ALERT;
+#else /* def LOG_ALERT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_ALERT */
+       if ((x & Mono_Posix_SyslogLevel_LOG_CRIT) == Mono_Posix_SyslogLevel_LOG_CRIT)
+#ifdef LOG_CRIT
+               *r |= LOG_CRIT;
+#else /* def LOG_CRIT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_CRIT */
+       if ((x & Mono_Posix_SyslogLevel_LOG_ERR) == Mono_Posix_SyslogLevel_LOG_ERR)
+#ifdef LOG_ERR
+               *r |= LOG_ERR;
+#else /* def LOG_ERR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_ERR */
+       if ((x & Mono_Posix_SyslogLevel_LOG_WARNING) == Mono_Posix_SyslogLevel_LOG_WARNING)
+#ifdef LOG_WARNING
+               *r |= LOG_WARNING;
+#else /* def LOG_WARNING */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_WARNING */
+       if ((x & Mono_Posix_SyslogLevel_LOG_NOTICE) == Mono_Posix_SyslogLevel_LOG_NOTICE)
+#ifdef LOG_NOTICE
+               *r |= LOG_NOTICE;
+#else /* def LOG_NOTICE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_NOTICE */
+       if ((x & Mono_Posix_SyslogLevel_LOG_INFO) == Mono_Posix_SyslogLevel_LOG_INFO)
+#ifdef LOG_INFO
+               *r |= LOG_INFO;
+#else /* def LOG_INFO */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_INFO */
+       if ((x & Mono_Posix_SyslogLevel_LOG_DEBUG) == Mono_Posix_SyslogLevel_LOG_DEBUG)
+#ifdef LOG_DEBUG
+               *r |= LOG_DEBUG;
+#else /* def LOG_DEBUG */
+               {errno = EINVAL; return -1;}
+#endif /* ndef LOG_DEBUG */
+       return 0;
+}
+
+int Mono_Posix_ToSyslogLevel (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef LOG_EMERG
+       if ((x & LOG_EMERG) == LOG_EMERG)
+               *r |= Mono_Posix_SyslogLevel_LOG_EMERG;
+#endif /* ndef LOG_EMERG */
+#ifdef LOG_ALERT
+       if ((x & LOG_ALERT) == LOG_ALERT)
+               *r |= Mono_Posix_SyslogLevel_LOG_ALERT;
+#endif /* ndef LOG_ALERT */
+#ifdef LOG_CRIT
+       if ((x & LOG_CRIT) == LOG_CRIT)
+               *r |= Mono_Posix_SyslogLevel_LOG_CRIT;
+#endif /* ndef LOG_CRIT */
+#ifdef LOG_ERR
+       if ((x & LOG_ERR) == LOG_ERR)
+               *r |= Mono_Posix_SyslogLevel_LOG_ERR;
+#endif /* ndef LOG_ERR */
+#ifdef LOG_WARNING
+       if ((x & LOG_WARNING) == LOG_WARNING)
+               *r |= Mono_Posix_SyslogLevel_LOG_WARNING;
+#endif /* ndef LOG_WARNING */
+#ifdef LOG_NOTICE
+       if ((x & LOG_NOTICE) == LOG_NOTICE)
+               *r |= Mono_Posix_SyslogLevel_LOG_NOTICE;
+#endif /* ndef LOG_NOTICE */
+#ifdef LOG_INFO
+       if ((x & LOG_INFO) == LOG_INFO)
+               *r |= Mono_Posix_SyslogLevel_LOG_INFO;
+#endif /* ndef LOG_INFO */
+#ifdef LOG_DEBUG
+       if ((x & LOG_DEBUG) == LOG_DEBUG)
+               *r |= Mono_Posix_SyslogLevel_LOG_DEBUG;
+#endif /* ndef LOG_DEBUG */
+       return 0;
+}
+
 int Mono_Posix_FromOpenFlags (int x, int *r)
 {
        *r = 0;
index e5cbd419095a70505587b94aeebf4ac42d0cbad5..e6b87f47e053549b062cf7f4205bcd10d10d91d5 100644 (file)
@@ -138,6 +138,49 @@ G_BEGIN_DECLS
 int Mono_Posix_FromError (int x, int *r);
 int Mono_Posix_ToError (int x, int *r);
 
+#define Mono_Posix_SyslogOptions_LOG_PID 0x00000001
+#define Mono_Posix_SyslogOptions_LOG_CONS 0x00000002
+#define Mono_Posix_SyslogOptions_LOG_ODELAY 0x00000004
+#define Mono_Posix_SyslogOptions_LOG_NDELAY 0x00000008
+#define Mono_Posix_SyslogOptions_LOG_NOWAIT 0x00000010
+#define Mono_Posix_SyslogOptions_LOG_PERROR 0x00000020
+int Mono_Posix_FromSyslogOptions (int x, int *r);
+int Mono_Posix_ToSyslogOptions (int x, int *r);
+
+#define Mono_Posix_SyslogFacility_LOG_KERN 0x00000000
+#define Mono_Posix_SyslogFacility_LOG_USRE 0x00000008
+#define Mono_Posix_SyslogFacility_LOG_MAIL 0x00000010
+#define Mono_Posix_SyslogFacility_LOG_DAEMON 0x00000018
+#define Mono_Posix_SyslogFacility_LOG_AUTH 0x00000020
+#define Mono_Posix_SyslogFacility_LOG_SYSLOG 0x00000028
+#define Mono_Posix_SyslogFacility_LOG_LPR 0x00000030
+#define Mono_Posix_SyslogFacility_LOG_NEWS 0x00000038
+#define Mono_Posix_SyslogFacility_LOG_UUCP 0x00000040
+#define Mono_Posix_SyslogFacility_LOG_CRON 0x00000040
+#define Mono_Posix_SyslogFacility_LOG_AUTHPRIV 0x00000050
+#define Mono_Posix_SyslogFacility_LOG_FTP 0x00000058
+#define Mono_Posix_SyslogFacility_LOG_LOCAL0 0x00000080
+#define Mono_Posix_SyslogFacility_LOG_LOCAL1 0x00000088
+#define Mono_Posix_SyslogFacility_LOG_LOCAL2 0x00000090
+#define Mono_Posix_SyslogFacility_LOG_LOCAL3 0x00000098
+#define Mono_Posix_SyslogFacility_LOG_LOCAL4 0x000000a0
+#define Mono_Posix_SyslogFacility_LOG_LOCAL5 0x000000a8
+#define Mono_Posix_SyslogFacility_LOG_LOCAL6 0x000000b0
+#define Mono_Posix_SyslogFacility_LOG_LOCAL7 0x000000b8
+int Mono_Posix_FromSyslogFacility (int x, int *r);
+int Mono_Posix_ToSyslogFacility (int x, int *r);
+
+#define Mono_Posix_SyslogLevel_LOG_EMERG 0x00000000
+#define Mono_Posix_SyslogLevel_LOG_ALERT 0x00000001
+#define Mono_Posix_SyslogLevel_LOG_CRIT 0x00000002
+#define Mono_Posix_SyslogLevel_LOG_ERR 0x00000003
+#define Mono_Posix_SyslogLevel_LOG_WARNING 0x00000004
+#define Mono_Posix_SyslogLevel_LOG_NOTICE 0x00000005
+#define Mono_Posix_SyslogLevel_LOG_INFO 0x00000006
+#define Mono_Posix_SyslogLevel_LOG_DEBUG 0x00000007
+int Mono_Posix_FromSyslogLevel (int x, int *r);
+int Mono_Posix_ToSyslogLevel (int x, int *r);
+
 #define Mono_Posix_OpenFlags_O_RDONLY 0x00000000
 #define Mono_Posix_OpenFlags_O_WRONLY 0x00000001
 #define Mono_Posix_OpenFlags_O_RDWR 0x00000002
index 95490117db9eadfaaefd78079b6f919d9d38626d..277095e70ccfce76fd07200dd78c1fe1c41fad85 100644 (file)
@@ -17,6 +17,9 @@
  *
  * See the typedefs for type size assumptions.  These typedefs *must* be kept
  * in sync with the types used in Mono.Posix.dll.
+ *
+ * See also:
+ *   http://developer.apple.com/documentation/Darwin/Reference/ManPages/
  */
 
 #ifndef INC_mph_H
@@ -36,6 +39,8 @@
 #define MPH_ON_BSD
 #endif
 
+#define MPH_INTERNAL __attribute__((visibility("hidden")))
+
 typedef    gint64 mph_blkcnt_t;
 typedef    gint64 mph_blksize_t;
 typedef   guint64 mph_dev_t;
@@ -49,6 +54,8 @@ typedef   guint32 mph_gid_t;
 typedef   guint32 mph_uid_t;
 typedef    gint64 mph_time_t;
 typedef    gint64 mph_clock_t;
+typedef   guint64 mph_fsblkcnt_t;
+typedef   guint64 mph_fsfilcnt_t;
 
 #ifdef HAVE_LARGE_FILE_SUPPORT
 #define MPH_OFF_T_MAX G_MAXINT64
@@ -126,6 +133,12 @@ recheck_range (int ret)
        return 0;
 }
 
+MPH_INTERNAL char* 
+_mph_copy_structure_strings (
+       void *to,   size_t *to_offsets, 
+       void *from, size_t *from_offsets, 
+       size_t num_strings);
+
 #endif /* ndef INC_mph_H */
 
 /*
index 05357f4f617603cfa866b81f2582240762da9765..37fd9bb6ff507efc37d1330878f0fa7b83ddd969 100644 (file)
@@ -28,6 +28,24 @@ struct Mono_Posix_Syscall__Passwd {
        /* string */ char      *_pw_buf_;
 };
 
+static const size_t
+passwd_offsets[] = {
+       offsetof (struct passwd, pw_name),
+       offsetof (struct passwd, pw_passwd),
+       offsetof (struct passwd, pw_gecos),
+       offsetof (struct passwd, pw_dir),
+       offsetof (struct passwd, pw_shell)
+};
+
+static const size_t
+mph_passwd_offsets[] = {
+       offsetof (struct Mono_Posix_Syscall__Passwd, pw_name),
+       offsetof (struct Mono_Posix_Syscall__Passwd, pw_passwd),
+       offsetof (struct Mono_Posix_Syscall__Passwd, pw_gecos),
+       offsetof (struct Mono_Posix_Syscall__Passwd, pw_dir),
+       offsetof (struct Mono_Posix_Syscall__Passwd, pw_shell)
+};
+
 /*
  * Copy the native `passwd' structure to it's managed representation.
  *
@@ -37,59 +55,18 @@ struct Mono_Posix_Syscall__Passwd {
 static int
 copy_passwd (struct Mono_Posix_Syscall__Passwd *to, struct passwd *from)
 {
-       enum {PW_NAME = 0, PW_PASSWD, PW_GECOS, PW_DIR, PW_SHELL, PW_LAST};
-       size_t buflen, len[PW_LAST];
-       /* bool */ unsigned char copy[PW_LAST] = {0};
-       const char *source[PW_LAST];
-       char **dest[PW_LAST];
-       int i;
-       char *cur;
+       char *buf;
+       buf = _mph_copy_structure_strings (to, mph_passwd_offsets,
+                       from, passwd_offsets, sizeof(passwd_offsets)/sizeof(passwd_offsets[0]));
 
        to->pw_uid    = from->pw_uid;
        to->pw_gid    = from->pw_gid;
 
-       to->pw_name   = NULL;
-       to->pw_passwd = NULL;
-       to->pw_gecos  = NULL;
-       to->pw_dir    = NULL;
-       to->pw_shell  = NULL;
-       to->_pw_buf_  = NULL;
-
-       source[PW_NAME]   = from->pw_name;
-       source[PW_PASSWD] = from->pw_passwd;
-       source[PW_GECOS]  = from->pw_gecos;
-       source[PW_DIR]    = from->pw_dir;
-       source[PW_SHELL]  = from->pw_shell;
-
-       dest[PW_NAME]   = &to->pw_name;
-       dest[PW_PASSWD] = &to->pw_passwd;
-       dest[PW_GECOS]  = &to->pw_gecos;
-       dest[PW_DIR]    = &to->pw_dir;
-       dest[PW_SHELL]  = &to->pw_shell;
-
-       buflen = PW_LAST;
-
-       /* over-rigorous checking for integer overflow */
-       for (i = 0; i != PW_LAST; ++i) {
-               len[i] = strlen (source[i]);
-               if (len[i] < INT_MAX - buflen) {
-                       buflen += len[i];
-                       copy[i] = 1;
-               }
-       }
-
-       cur = to->_pw_buf_ = (char*) malloc (buflen);
-       if (cur == NULL) {
+       to->_pw_buf_ = buf;
+       if (buf == NULL) {
                return -1;
        }
 
-       for (i = 0; i != PW_LAST; ++i) {
-               if (copy[i]) {
-                       *dest[i] = strcpy (cur, source[i]);
-                       cur += (len[i] + 1);
-               }
-       }
-
        return 0;
 }
 
diff --git a/support/sys-statvfs.c b/support/sys-statvfs.c
new file mode 100644 (file)
index 0000000..ce18cc9
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * <sys/sendfile.h> wrapper functions.
+ *
+ * Authors:
+ *   Jonathan Pryor (jonpryor@vt.edu)
+ *
+ * Copyright (C) 2004 Jonathan Pryor
+ */
+
+#include <errno.h>
+
+#include "mph.h"
+
+#ifdef HAVE_SYS_STATVFS_H
+#include <sys/statvfs.h>
+#endif /* def HAVE_SYS_STATVFS_H */
+
+#ifdef HAVE_GETFSSTAT
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/mount.h>
+#include <unistd.h>     /* for pathconf */
+#endif /* def HAVE_GETFSSTAT */
+
+G_BEGIN_DECLS
+
+struct Mono_Posix_Statvfs {
+       guint64         f_bsize;    /* file system block size */
+       guint64         f_frsize;   /* fragment size */
+       mph_fsblkcnt_t  f_blocks;   /* size of fs in f_frsize units */
+       mph_fsblkcnt_t  f_bfree;    /* # free blocks */
+       mph_fsblkcnt_t  f_bavail;   /* # free blocks for non-root */
+       mph_fsfilcnt_t  f_files;    /* # inodes */
+       mph_fsfilcnt_t  f_ffree;    /* # free inodes */
+       mph_fsfilcnt_t  f_favail;   /* # free inodes for non-root */
+       guint64         f_fsid;     /* file system id */
+       guint64         f_flag;     /* mount flags */
+       guint64         f_namemax;  /* maximum filename length */
+};
+
+#ifdef HAVE_SYS_STATVFS_H
+static void
+copy_statvfs (struct Mono_Posix_Statvfs *to, struct statvfs *from)
+{
+  to->f_bsize   = from->f_bsize;
+  to->f_frsize  = from->f_frsize;
+  to->f_blocks  = from->f_blocks;
+  to->f_bfree   = from->f_bfree;
+  to->f_bavail  = from->f_bavail;
+  to->f_files   = from->f_files;
+  to->f_ffree   = from->f_ffree;
+  to->f_favail  = from->f_favail;
+  to->f_fsid    = from->f_fsid;
+  to->f_flag    = from->f_flag;
+  to->f_namemax =      from->f_namemax;
+}
+#endif /* ndef HAVE_SYS_STATVFS_H */
+
+/*
+ * System V-compatible definitions
+ */
+
+#ifdef HAVE_STATVFS
+gint32
+Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
+{
+       struct statvfs s;
+       int r;
+
+       if (buf == NULL) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       if ((r = statvfs (path, &s)) == 0)
+               copy_statvfs (buf, &s);
+
+       return r;
+}
+#endif /* ndef HAVA_STATVFS */
+
+#ifdef HAVE_FSTATVFS
+gint32
+Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
+{
+       struct statvfs s;
+       int r;
+
+       if (buf == NULL) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       if ((r = fstatvfs (fd, &s)) == 0)
+               copy_statvfs (buf, &s);
+
+       return r;
+}
+#endif /* ndef HAVA_FSTATVFS */
+
+/*
+ * BSD-compatible definitions.
+ *
+ * Linux also provides these, but are deprecated in favor of (f)statvfs.
+ */
+
+#if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS)
+static void
+copy_statfs (struct Mono_Posix_Statvfs *to, struct statfs *from)
+{
+  to->f_bsize   = from->f_bsize;
+  to->f_frsize  = from->f_frsize;
+  to->f_blocks  = from->f_blocks;
+  to->f_bfree   = from->f_bfree;
+  to->f_bavail  = from->f_bavail;
+  to->f_files   = from->f_files;
+  to->f_ffree   = from->f_ffree;
+  to->f_favail  = from->f_ffree; /* OSX doesn't have f_avail */
+  to->f_fsid    = from->f_fsid;
+  to->f_flag    = from->f_flags;
+}
+
+static void
+set_namemax (const char *path, struct Mono_Posix_Statvfs *buf)
+{
+  buf->f_namemax = pathconf (path, _PC_NAME_MAX);
+}
+#endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
+
+#if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
+gint32
+Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
+{
+       struct statfs s;
+       int r;
+
+       if (buf == NULL) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       if ((r = statfs (path, &s)) == 0) {
+               copy_statfs (buf, &s);
+               set_namemax (path, buf);
+       }
+
+       return r;
+}
+#endif /* !def HAVE_STATVFS && def HAVE_STATFS */
+
+#if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
+gint32
+Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
+{
+       struct statfs s;
+       int r;
+
+       if (buf == NULL) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       if ((r = fstatfs (fd, &s)) == 0) {
+               copy_statvfs (buf, &s);
+               set_namemax (path, buf);
+       }
+
+       return r;
+}
+#endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */
+
+G_END_DECLS
+
+/*
+ * vim: noexpandtab
+ */
diff --git a/support/x-struct-str.c b/support/x-struct-str.c
new file mode 100644 (file)
index 0000000..09f1a67
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * A helper routine to copy the strings between differing structures.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "mph.h"
+
+#define MAX_OFFSETS 10
+
+#define str_at(p, n) (*(char**)(((char*)p)+n))
+
+char* MPH_INTERNAL
+_mph_copy_structure_strings (
+       void *to,   size_t *to_offsets, 
+       void *from, size_t *from_offsets, 
+       size_t num_strings)
+{
+       int i;
+       size_t buflen;
+       int len[MAX_OFFSETS];
+       char *buf, *cur = NULL;
+
+       g_assert (num_strings < MAX_OFFSETS);
+
+       for (i = 0; i < num_strings; ++i) {
+               str_at (to, to_offsets[i]) = NULL;
+       }
+
+       buflen = num_strings;
+       for (i = 0; i < num_strings; ++i) {
+               len[i] = strlen (str_at(from, from_offsets[i]));
+               if (len[i] < INT_MAX - buflen)
+                       buflen += len[i];
+               else
+                       len[i] = -1;
+       }
+
+       cur = buf = malloc (buflen);
+       if (buf == NULL) {
+               return NULL;
+       }
+
+       for (i = 0; i < num_strings; ++i) {
+               if (len[i] > 0) {
+                       str_at (to, to_offsets[i]) = 
+                               strcpy (cur, str_at (from, from_offsets[i]));
+                       cur += (len[i] +1);
+               }
+       }
+
+       return buf;
+}
+
+#ifdef TEST
+
+#include <stdio.h>
+
+struct foo {
+       char *a;
+       int   b;
+       char *c;
+};
+
+struct bar {
+       int    b;
+       char  *a;
+       double d;
+       char  *c;
+};
+
+int
+main ()
+{
+       /* test copying foo to bar */
+       struct foo f = {"hello", 42, "world"};
+       struct bar b;
+       size_t foo_offsets[] = {offsetof(struct foo, a), offsetof(struct foo, c)};
+       size_t bar_offsets[] = {offsetof(struct bar, a), offsetof(struct bar, c)};
+       char *buf;
+
+       buf = _mph_copy_structure_strings (&b, bar_offsets, 
+                       &f, foo_offsets, 2);
+       printf ("b.a=%s\n", b.a);
+       printf ("b.c=%s\n", b.c);
+
+       return 0;
+}
+#endif
+