/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs
C# | 4010 lines | 2955 code | 558 blank | 497 comment | 322 complexity | 35142eb8db78938addd8d27922c4199e MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- //
- // Mono.Unix/Syscall.cs
- //
- // Authors:
- // Miguel de Icaza (miguel@novell.com)
- // Jonathan Pryor (jonpryor@vt.edu)
- //
- // (C) 2003 Novell, Inc.
- // (C) 2004-2006 Jonathan Pryor
- //
- // This file implements the low-level syscall interface to the POSIX
- // subsystem.
- //
- // This file tries to stay close to the low-level API as much as possible
- // using enumerations, structures and in a few cases, using existing .NET
- // data types.
- //
- // Implementation notes:
- //
- // Since the values for the various constants on the API changes
- // from system to system (even Linux on different architectures will
- // have different values), we define our own set of values, and we
- // use a set of C helper routines to map from the constants we define
- // to the values of the native OS.
- //
- // Bitfields are flagged with the [Map] attribute, and a helper program
- // generates a set of routines that we can call to convert from our value
- // definitions to the value definitions expected by the OS; see
- // NativeConvert for the conversion routines.
- //
- // Methods that require tuning are bound as `private sys_NAME' methods
- // and then a `NAME' method is exposed.
- //
- //
- // 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.Collections;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using System.Security;
- using System.Text;
- using Mono.Unix.Native;
- namespace Mono.Unix.Native {
- #region Enumerations
- [Flags][Map]
- [CLSCompliant (false)]
- public enum SyslogOptions {
- LOG_PID = 0x01, // log the pid with each message
- LOG_CONS = 0x02, // log on the console if errors in sending
- LOG_ODELAY = 0x04, // delay open until first syslog (default)
- LOG_NDELAY = 0x08, // don't delay open
- LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
- LOG_PERROR = 0x20 // log to stderr as well
- }
- [Map]
- [CLSCompliant (false)]
- public enum SyslogFacility {
- LOG_KERN = 0 << 3,
- LOG_USER = 1 << 3,
- LOG_MAIL = 2 << 3,
- LOG_DAEMON = 3 << 3,
- LOG_AUTH = 4 << 3,
- LOG_SYSLOG = 5 << 3,
- LOG_LPR = 6 << 3,
- LOG_NEWS = 7 << 3,
- LOG_UUCP = 8 << 3,
- LOG_CRON = 9 << 3,
- LOG_AUTHPRIV = 10 << 3,
- LOG_FTP = 11 << 3,
- LOG_LOCAL0 = 16 << 3,
- LOG_LOCAL1 = 17 << 3,
- LOG_LOCAL2 = 18 << 3,
- LOG_LOCAL3 = 19 << 3,
- LOG_LOCAL4 = 20 << 3,
- LOG_LOCAL5 = 21 << 3,
- LOG_LOCAL6 = 22 << 3,
- LOG_LOCAL7 = 23 << 3,
- }
- [Map]
- [CLSCompliant (false)]
- public enum SyslogLevel {
- LOG_EMERG = 0, // system is unusable
- LOG_ALERT = 1, // action must be taken immediately
- LOG_CRIT = 2, // critical conditions
- LOG_ERR = 3, // warning conditions
- LOG_WARNING = 4, // warning conditions
- LOG_NOTICE = 5, // normal but significant condition
- LOG_INFO = 6, // informational
- LOG_DEBUG = 7 // debug-level messages
- }
- [Map][Flags]
- [CLSCompliant (false)]
- public enum OpenFlags : int {
- //
- // One of these
- //
- O_RDONLY = 0x00000000,
- O_WRONLY = 0x00000001,
- O_RDWR = 0x00000002,
- //
- // Or-ed with zero or more of these
- //
- O_CREAT = 0x00000040,
- O_EXCL = 0x00000080,
- O_NOCTTY = 0x00000100,
- O_TRUNC = 0x00000200,
- O_APPEND = 0x00000400,
- O_NONBLOCK = 0x00000800,
- O_SYNC = 0x00001000,
- //
- // These are non-Posix. Using them will result in errors/exceptions on
- // non-supported platforms.
- //
- // (For example, "C-wrapped" system calls -- calls with implementation in
- // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
- // calls will generate an exception in NativeConvert, as the value can't be
- // converted on the target platform.)
- //
-
- O_NOFOLLOW = 0x00020000,
- O_DIRECTORY = 0x00010000,
- O_DIRECT = 0x00004000,
- O_ASYNC = 0x00002000,
- O_LARGEFILE = 0x00008000
- }
-
- // mode_t
- [Flags][Map]
- [CLSCompliant (false)]
- public enum FilePermissions : uint {
- S_ISUID = 0x0800, // Set user ID on execution
- S_ISGID = 0x0400, // Set group ID on execution
- S_ISVTX = 0x0200, // Save swapped text after use (sticky).
- S_IRUSR = 0x0100, // Read by owner
- S_IWUSR = 0x0080, // Write by owner
- S_IXUSR = 0x0040, // Execute by owner
- S_IRGRP = 0x0020, // Read by group
- S_IWGRP = 0x0010, // Write by group
- S_IXGRP = 0x0008, // Execute by group
- S_IROTH = 0x0004, // Read by other
- S_IWOTH = 0x0002, // Write by other
- S_IXOTH = 0x0001, // Execute by other
- S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
- S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
- S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
- ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
- ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
- DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
- // Device types
- // Why these are held in "mode_t" is beyond me...
- S_IFMT = 0xF000, // Bits which determine file type
- [Map(SuppressFlags="S_IFMT")]
- S_IFDIR = 0x4000, // Directory
- [Map(SuppressFlags="S_IFMT")]
- S_IFCHR = 0x2000, // Character device
- [Map(SuppressFlags="S_IFMT")]
- S_IFBLK = 0x6000, // Block device
- [Map(SuppressFlags="S_IFMT")]
- S_IFREG = 0x8000, // Regular file
- [Map(SuppressFlags="S_IFMT")]
- S_IFIFO = 0x1000, // FIFO
- [Map(SuppressFlags="S_IFMT")]
- S_IFLNK = 0xA000, // Symbolic link
- [Map(SuppressFlags="S_IFMT")]
- S_IFSOCK = 0xC000, // Socket
- }
- [Map]
- [CLSCompliant (false)]
- public enum FcntlCommand : int {
- // Form /usr/include/bits/fcntl.h
- F_DUPFD = 0, // Duplicate file descriptor.
- F_GETFD = 1, // Get file descriptor flags.
- F_SETFD = 2, // Set file descriptor flags.
- F_GETFL = 3, // Get file status flags.
- F_SETFL = 4, // Set file status flags.
- F_GETLK = 12, // Get record locking info. [64]
- F_SETLK = 13, // Set record locking info (non-blocking). [64]
- F_SETLKW = 14, // Set record locking info (blocking). [64]
- F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
- F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
- F_SETSIG = 10, // Set number of signal to be sent.
- F_GETSIG = 11, // Get number of signal to be sent.
- F_SETLEASE = 1024, // Set a lease.
- F_GETLEASE = 1025, // Enquire what lease is active.
- F_NOTIFY = 1026, // Required notifications on a directory
- }
- [Map]
- [CLSCompliant (false)]
- public enum LockType : short {
- F_RDLCK = 0, // Read lock.
- F_WRLCK = 1, // Write lock.
- F_UNLCK = 2, // Remove lock.
- }
- [Map]
- [CLSCompliant (false)]
- public enum SeekFlags : short {
- // values liberally copied from /usr/include/unistd.h
- SEEK_SET = 0, // Seek from beginning of file.
- SEEK_CUR = 1, // Seek from current position.
- SEEK_END = 2, // Seek from end of file.
- L_SET = SEEK_SET, // BSD alias for SEEK_SET
- L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
- L_XTND = SEEK_END, // BSD alias for SEEK_END
- }
-
- [Map, Flags]
- [CLSCompliant (false)]
- public enum DirectoryNotifyFlags : int {
- // from /usr/include/bits/fcntl.h
- DN_ACCESS = 0x00000001, // File accessed.
- DN_MODIFY = 0x00000002, // File modified.
- DN_CREATE = 0x00000004, // File created.
- DN_DELETE = 0x00000008, // File removed.
- DN_RENAME = 0x00000010, // File renamed.
- DN_ATTRIB = 0x00000020, // File changed attributes.
- DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
- }
- [Map]
- [CLSCompliant (false)]
- public enum PosixFadviseAdvice : int {
- POSIX_FADV_NORMAL = 0, // No further special treatment.
- POSIX_FADV_RANDOM = 1, // Expect random page references.
- POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
- POSIX_FADV_WILLNEED = 3, // Will need these pages.
- POSIX_FADV_DONTNEED = 4, // Don't need these pages.
- POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
- }
- [Map]
- [CLSCompliant (false)]
- public enum PosixMadviseAdvice : int {
- POSIX_MADV_NORMAL = 0, // No further special treatment.
- POSIX_MADV_RANDOM = 1, // Expect random page references.
- POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
- POSIX_MADV_WILLNEED = 3, // Will need these pages.
- POSIX_MADV_DONTNEED = 4, // Don't need these pages.
- }
- [Map]
- public enum Signum : int {
- SIGHUP = 1, // Hangup (POSIX).
- SIGINT = 2, // Interrupt (ANSI).
- SIGQUIT = 3, // Quit (POSIX).
- SIGILL = 4, // Illegal instruction (ANSI).
- SIGTRAP = 5, // Trace trap (POSIX).
- SIGABRT = 6, // Abort (ANSI).
- SIGIOT = 6, // IOT trap (4.2 BSD).
- SIGBUS = 7, // BUS error (4.2 BSD).
- SIGFPE = 8, // Floating-point exception (ANSI).
- SIGKILL = 9, // Kill, unblockable (POSIX).
- SIGUSR1 = 10, // User-defined signal 1 (POSIX).
- SIGSEGV = 11, // Segmentation violation (ANSI).
- SIGUSR2 = 12, // User-defined signal 2 (POSIX).
- SIGPIPE = 13, // Broken pipe (POSIX).
- SIGALRM = 14, // Alarm clock (POSIX).
- SIGTERM = 15, // Termination (ANSI).
- SIGSTKFLT = 16, // Stack fault.
- SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
- SIGCHLD = 17, // Child status has changed (POSIX).
- SIGCONT = 18, // Continue (POSIX).
- SIGSTOP = 19, // Stop, unblockable (POSIX).
- SIGTSTP = 20, // Keyboard stop (POSIX).
- SIGTTIN = 21, // Background read from tty (POSIX).
- SIGTTOU = 22, // Background write to tty (POSIX).
- SIGURG = 23, // Urgent condition on socket (4.2 BSD).
- SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
- SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
- SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
- SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
- SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
- SIGPOLL = SIGIO, // Pollable event occurred (System V).
- SIGIO = 29, // I/O now possible (4.2 BSD).
- SIGPWR = 30, // Power failure restart (System V).
- SIGSYS = 31, // Bad system call.
- SIGUNUSED = 31
- }
- [Flags][Map]
- public enum WaitOptions : int {
- WNOHANG = 1, // Don't block waiting
- WUNTRACED = 2, // Report status of stopped children
- }
- [Flags][Map]
- [CLSCompliant (false)]
- public enum AccessModes : int {
- R_OK = 1,
- W_OK = 2,
- X_OK = 4,
- F_OK = 8,
- }
- [Map]
- [CLSCompliant (false)]
- public enum PathconfName : int {
- _PC_LINK_MAX,
- _PC_MAX_CANON,
- _PC_MAX_INPUT,
- _PC_NAME_MAX,
- _PC_PATH_MAX,
- _PC_PIPE_BUF,
- _PC_CHOWN_RESTRICTED,
- _PC_NO_TRUNC,
- _PC_VDISABLE,
- _PC_SYNC_IO,
- _PC_ASYNC_IO,
- _PC_PRIO_IO,
- _PC_SOCK_MAXBUF,
- _PC_FILESIZEBITS,
- _PC_REC_INCR_XFER_SIZE,
- _PC_REC_MAX_XFER_SIZE,
- _PC_REC_MIN_XFER_SIZE,
- _PC_REC_XFER_ALIGN,
- _PC_ALLOC_SIZE_MIN,
- _PC_SYMLINK_MAX,
- _PC_2_SYMLINKS
- }
- [Map]
- [CLSCompliant (false)]
- public enum SysconfName : int {
- _SC_ARG_MAX,
- _SC_CHILD_MAX,
- _SC_CLK_TCK,
- _SC_NGROUPS_MAX,
- _SC_OPEN_MAX,
- _SC_STREAM_MAX,
- _SC_TZNAME_MAX,
- _SC_JOB_CONTROL,
- _SC_SAVED_IDS,
- _SC_REALTIME_SIGNALS,
- _SC_PRIORITY_SCHEDULING,
- _SC_TIMERS,
- _SC_ASYNCHRONOUS_IO,
- _SC_PRIORITIZED_IO,
- _SC_SYNCHRONIZED_IO,
- _SC_FSYNC,
- _SC_MAPPED_FILES,
- _SC_MEMLOCK,
- _SC_MEMLOCK_RANGE,
- _SC_MEMORY_PROTECTION,
- _SC_MESSAGE_PASSING,
- _SC_SEMAPHORES,
- _SC_SHARED_MEMORY_OBJECTS,
- _SC_AIO_LISTIO_MAX,
- _SC_AIO_MAX,
- _SC_AIO_PRIO_DELTA_MAX,
- _SC_DELAYTIMER_MAX,
- _SC_MQ_OPEN_MAX,
- _SC_MQ_PRIO_MAX,
- _SC_VERSION,
- _SC_PAGESIZE,
- _SC_RTSIG_MAX,
- _SC_SEM_NSEMS_MAX,
- _SC_SEM_VALUE_MAX,
- _SC_SIGQUEUE_MAX,
- _SC_TIMER_MAX,
- /* Values for the argument to `sysconf'
- corresponding to _POSIX2_* symbols. */
- _SC_BC_BASE_MAX,
- _SC_BC_DIM_MAX,
- _SC_BC_SCALE_MAX,
- _SC_BC_STRING_MAX,
- _SC_COLL_WEIGHTS_MAX,
- _SC_EQUIV_CLASS_MAX,
- _SC_EXPR_NEST_MAX,
- _SC_LINE_MAX,
- _SC_RE_DUP_MAX,
- _SC_CHARCLASS_NAME_MAX,
- _SC_2_VERSION,
- _SC_2_C_BIND,
- _SC_2_C_DEV,
- _SC_2_FORT_DEV,
- _SC_2_FORT_RUN,
- _SC_2_SW_DEV,
- _SC_2_LOCALEDEF,
- _SC_PII,
- _SC_PII_XTI,
- _SC_PII_SOCKET,
- _SC_PII_INTERNET,
- _SC_PII_OSI,
- _SC_POLL,
- _SC_SELECT,
- _SC_UIO_MAXIOV,
- _SC_IOV_MAX = _SC_UIO_MAXIOV,
- _SC_PII_INTERNET_STREAM,
- _SC_PII_INTERNET_DGRAM,
- _SC_PII_OSI_COTS,
- _SC_PII_OSI_CLTS,
- _SC_PII_OSI_M,
- _SC_T_IOV_MAX,
- /* Values according to POSIX 1003.1c (POSIX threads). */
- _SC_THREADS,
- _SC_THREAD_SAFE_FUNCTIONS,
- _SC_GETGR_R_SIZE_MAX,
- _SC_GETPW_R_SIZE_MAX,
- _SC_LOGIN_NAME_MAX,
- _SC_TTY_NAME_MAX,
- _SC_THREAD_DESTRUCTOR_ITERATIONS,
- _SC_THREAD_KEYS_MAX,
- _SC_THREAD_STACK_MIN,
- _SC_THREAD_THREADS_MAX,
- _SC_THREAD_ATTR_STACKADDR,
- _SC_THREAD_ATTR_STACKSIZE,
- _SC_THREAD_PRIORITY_SCHEDULING,
- _SC_THREAD_PRIO_INHERIT,
- _SC_THREAD_PRIO_PROTECT,
- _SC_THREAD_PROCESS_SHARED,
- _SC_NPROCESSORS_CONF,
- _SC_NPROCESSORS_ONLN,
- _SC_PHYS_PAGES,
- _SC_AVPHYS_PAGES,
- _SC_ATEXIT_MAX,
- _SC_PASS_MAX,
- _SC_XOPEN_VERSION,
- _SC_XOPEN_XCU_VERSION,
- _SC_XOPEN_UNIX,
- _SC_XOPEN_CRYPT,
- _SC_XOPEN_ENH_I18N,
- _SC_XOPEN_SHM,
- _SC_2_CHAR_TERM,
- _SC_2_C_VERSION,
- _SC_2_UPE,
- _SC_XOPEN_XPG2,
- _SC_XOPEN_XPG3,
- _SC_XOPEN_XPG4,
- _SC_CHAR_BIT,
- _SC_CHAR_MAX,
- _SC_CHAR_MIN,
- _SC_INT_MAX,
- _SC_INT_MIN,
- _SC_LONG_BIT,
- _SC_WORD_BIT,
- _SC_MB_LEN_MAX,
- _SC_NZERO,
- _SC_SSIZE_MAX,
- _SC_SCHAR_MAX,
- _SC_SCHAR_MIN,
- _SC_SHRT_MAX,
- _SC_SHRT_MIN,
- _SC_UCHAR_MAX,
- _SC_UINT_MAX,
- _SC_ULONG_MAX,
- _SC_USHRT_MAX,
- _SC_NL_ARGMAX,
- _SC_NL_LANGMAX,
- _SC_NL_MSGMAX,
- _SC_NL_NMAX,
- _SC_NL_SETMAX,
- _SC_NL_TEXTMAX,
- _SC_XBS5_ILP32_OFF32,
- _SC_XBS5_ILP32_OFFBIG,
- _SC_XBS5_LP64_OFF64,
- _SC_XBS5_LPBIG_OFFBIG,
- _SC_XOPEN_LEGACY,
- _SC_XOPEN_REALTIME,
- _SC_XOPEN_REALTIME_THREADS,
- _SC_ADVISORY_INFO,
- _SC_BARRIERS,
- _SC_BASE,
- _SC_C_LANG_SUPPORT,
- _SC_C_LANG_SUPPORT_R,
- _SC_CLOCK_SELECTION,
- _SC_CPUTIME,
- _SC_THREAD_CPUTIME,
- _SC_DEVICE_IO,
- _SC_DEVICE_SPECIFIC,
- _SC_DEVICE_SPECIFIC_R,
- _SC_FD_MGMT,
- _SC_FIFO,
- _SC_PIPE,
- _SC_FILE_ATTRIBUTES,
- _SC_FILE_LOCKING,
- _SC_FILE_SYSTEM,
- _SC_MONOTONIC_CLOCK,
- _SC_MULTI_PROCESS,
- _SC_SINGLE_PROCESS,
- _SC_NETWORKING,
- _SC_READER_WRITER_LOCKS,
- _SC_SPIN_LOCKS,
- _SC_REGEXP,
- _SC_REGEX_VERSION,
- _SC_SHELL,
- _SC_SIGNALS,
- _SC_SPAWN,
- _SC_SPORADIC_SERVER,
- _SC_THREAD_SPORADIC_SERVER,
- _SC_SYSTEM_DATABASE,
- _SC_SYSTEM_DATABASE_R,
- _SC_TIMEOUTS,
- _SC_TYPED_MEMORY_OBJECTS,
- _SC_USER_GROUPS,
- _SC_USER_GROUPS_R,
- _SC_2_PBS,
- _SC_2_PBS_ACCOUNTING,
- _SC_2_PBS_LOCATE,
- _SC_2_PBS_MESSAGE,
- _SC_2_PBS_TRACK,
- _SC_SYMLOOP_MAX,
- _SC_STREAMS,
- _SC_2_PBS_CHECKPOINT,
- _SC_V6_ILP32_OFF32,
- _SC_V6_ILP32_OFFBIG,
- _SC_V6_LP64_OFF64,
- _SC_V6_LPBIG_OFFBIG,
- _SC_HOST_NAME_MAX,
- _SC_TRACE,
- _SC_TRACE_EVENT_FILTER,
- _SC_TRACE_INHERIT,
- _SC_TRACE_LOG,
- _SC_LEVEL1_ICACHE_SIZE,
- _SC_LEVEL1_ICACHE_ASSOC,
- _SC_LEVEL1_ICACHE_LINESIZE,
- _SC_LEVEL1_DCACHE_SIZE,
- _SC_LEVEL1_DCACHE_ASSOC,
- _SC_LEVEL1_DCACHE_LINESIZE,
- _SC_LEVEL2_CACHE_SIZE,
- _SC_LEVEL2_CACHE_ASSOC,
- _SC_LEVEL2_CACHE_LINESIZE,
- _SC_LEVEL3_CACHE_SIZE,
- _SC_LEVEL3_CACHE_ASSOC,
- _SC_LEVEL3_CACHE_LINESIZE,
- _SC_LEVEL4_CACHE_SIZE,
- _SC_LEVEL4_CACHE_ASSOC,
- _SC_LEVEL4_CACHE_LINESIZE
- }
- [Map]
- [CLSCompliant (false)]
- public enum ConfstrName : int {
- _CS_PATH, /* The default search path. */
- _CS_V6_WIDTH_RESTRICTED_ENVS,
- _CS_GNU_LIBC_VERSION,
- _CS_GNU_LIBPTHREAD_VERSION,
- _CS_LFS_CFLAGS = 1000,
- _CS_LFS_LDFLAGS,
- _CS_LFS_LIBS,
- _CS_LFS_LINTFLAGS,
- _CS_LFS64_CFLAGS,
- _CS_LFS64_LDFLAGS,
- _CS_LFS64_LIBS,
- _CS_LFS64_LINTFLAGS,
- _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
- _CS_XBS5_ILP32_OFF32_LDFLAGS,
- _CS_XBS5_ILP32_OFF32_LIBS,
- _CS_XBS5_ILP32_OFF32_LINTFLAGS,
- _CS_XBS5_ILP32_OFFBIG_CFLAGS,
- _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
- _CS_XBS5_ILP32_OFFBIG_LIBS,
- _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
- _CS_XBS5_LP64_OFF64_CFLAGS,
- _CS_XBS5_LP64_OFF64_LDFLAGS,
- _CS_XBS5_LP64_OFF64_LIBS,
- _CS_XBS5_LP64_OFF64_LINTFLAGS,
- _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
- _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
- _CS_XBS5_LPBIG_OFFBIG_LIBS,
- _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
- _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
- _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
- _CS_POSIX_V6_ILP32_OFF32_LIBS,
- _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
- _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
- _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
- _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
- _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
- _CS_POSIX_V6_LP64_OFF64_CFLAGS,
- _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
- _CS_POSIX_V6_LP64_OFF64_LIBS,
- _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
- _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
- _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
- _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
- _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
- }
- [Map]
- [CLSCompliant (false)]
- public enum LockfCommand : int {
- F_ULOCK = 0, // Unlock a previously locked region.
- F_LOCK = 1, // Lock a region for exclusive use.
- F_TLOCK = 2, // Test and lock a region for exclusive use.
- F_TEST = 3, // Test a region for other process locks.
- }
- [Map][Flags]
- public enum PollEvents : short {
- POLLIN = 0x0001, // There is data to read
- POLLPRI = 0x0002, // There is urgent data to read
- POLLOUT = 0x0004, // Writing now will not block
- POLLERR = 0x0008, // Error condition
- POLLHUP = 0x0010, // Hung up
- POLLNVAL = 0x0020, // Invalid request; fd not open
- // XPG4.2 definitions (via _XOPEN_SOURCE)
- POLLRDNORM = 0x0040, // Normal data may be read
- POLLRDBAND = 0x0080, // Priority data may be read
- POLLWRNORM = 0x0100, // Writing now will not block
- POLLWRBAND = 0x0200, // Priority data may be written
- }
- [Map][Flags]
- [CLSCompliant (false)]
- public enum XattrFlags : int {
- XATTR_AUTO = 0,
- XATTR_CREATE = 1,
- XATTR_REPLACE = 2,
- }
- [Map][Flags]
- [CLSCompliant (false)]
- 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_NOEXEC = 8, // Disallow program execution
- ST_SYNCHRONOUS = 16, // Writes are synced at once
- ST_REMOUNT = 32, // Alter flags of a mounted FS
- 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
- ST_BIND = 4096, // Bind directory at different place
- }
- [Map][Flags]
- [CLSCompliant (false)]
- public enum MmapFlags : int {
- MAP_SHARED = 0x01, // Share changes.
- MAP_PRIVATE = 0x02, // Changes are private.
- MAP_TYPE = 0x0f, // Mask for type of mapping.
- MAP_FIXED = 0x10, // Interpret addr exactly.
- MAP_FILE = 0,
- MAP_ANONYMOUS = 0x20, // Don't use a file.
- MAP_ANON = MAP_ANONYMOUS,
- // These are Linux-specific.
- MAP_GROWSDOWN = 0x00100, // Stack-like segment.
- MAP_DENYWRITE = 0x00800, // ETXTBSY
- MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
- MAP_LOCKED = 0x02000, // Lock the mapping.
- MAP_NORESERVE = 0x04000, // Don't check for reservations.
- MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
- MAP_NONBLOCK = 0x10000, // Do not block on IO.
- }
- [Map][Flags]
- [CLSCompliant (false)]
- public enum MmapProts : int {
- PROT_READ = 0x1, // Page can be read.
- PROT_WRITE = 0x2, // Page can be written.
- PROT_EXEC = 0x4, // Page can be executed.
- PROT_NONE = 0x0, // Page can not be accessed.
- PROT_GROWSDOWN = 0x01000000, // Extend change to start of
- // growsdown vma (mprotect only).
- PROT_GROWSUP = 0x02000000, // Extend change to start of
- // growsup vma (mprotect only).
- }
- [Map][Flags]
- [CLSCompliant (false)]
- public enum MsyncFlags : int {
- MS_ASYNC = 0x1, // Sync memory asynchronously.
- MS_SYNC = 0x4, // Synchronous memory sync.
- MS_INVALIDATE = 0x2, // Invalidate the caches.
- }
- [Map][Flags]
- [CLSCompliant (false)]
- public enum MlockallFlags : int {
- MCL_CURRENT = 0x1, // Lock all currently mapped pages.
- MCL_FUTURE = 0x2, // Lock all additions to address
- }
- [Map][Flags]
- [CLSCompliant (false)]
- public enum MremapFlags : ulong {
- MREMAP_MAYMOVE = 0x1,
- }
- #endregion
- #region Structures
- [Map ("struct flock")]
- public struct Flock
- #if NET_2_0
- : IEquatable <Flock>
- #endif
- {
- [CLSCompliant (false)]
- public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
- [CLSCompliant (false)]
- public SeekFlags l_whence; // How to interpret l_start
- [off_t] public long l_start; // Starting offset for lock
- [off_t] public long l_len; // Number of bytes to lock
- [pid_t] public int l_pid; // PID of process blocking our lock (F_GETLK only)
- public override int GetHashCode ()
- {
- return l_type.GetHashCode () ^ l_whence.GetHashCode () ^
- l_start.GetHashCode () ^ l_len.GetHashCode () ^
- l_pid.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if ((obj == null) || (obj.GetType () != GetType ()))
- return false;
- Flock value = (Flock) obj;
- return l_type == value.l_type && l_whence == value.l_whence &&
- l_start == value.l_start && l_len == value.l_len &&
- l_pid == value.l_pid;
- }
- public bool Equals (Flock value)
- {
- return l_type == value.l_type && l_whence == value.l_whence &&
- l_start == value.l_start && l_len == value.l_len &&
- l_pid == value.l_pid;
- }
- public static bool operator== (Flock lhs, Flock rhs)
- {
- return lhs.Equals (rhs);
- }
- public static bool operator!= (Flock lhs, Flock rhs)
- {
- return !lhs.Equals (rhs);
- }
- }
- [Map ("struct pollfd")]
- public struct Pollfd
- #if NET_2_0
- : IEquatable <Pollfd>
- #endif
- {
- public int fd;
- [CLSCompliant (false)]
- public PollEvents events;
- [CLSCompliant (false)]
- public PollEvents revents;
- public override int GetHashCode ()
- {
- return events.GetHashCode () ^ revents.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || obj.GetType () != GetType ())
- return false;
- Pollfd value = (Pollfd) obj;
- return value.events == events && value.revents == revents;
- }
- public bool Equals (Pollfd value)
- {
- return value.events == events && value.revents == revents;
- }
- public static bool operator== (Pollfd lhs, Pollfd rhs)
- {
- return lhs.Equals (rhs);
- }
- public static bool operator!= (Pollfd lhs, Pollfd rhs)
- {
- return !lhs.Equals (rhs);
- }
- }
- [Map ("struct stat")]
- public struct Stat
- #if NET_2_0
- : IEquatable <Stat>
- #endif
- {
- [CLSCompliant (false)]
- [dev_t] public ulong st_dev; // device
- [CLSCompliant (false)]
- [ino_t] public ulong st_ino; // inode
- [CLSCompliant (false)]
- public FilePermissions st_mode; // protection
- [NonSerialized]
- #pragma warning disable 169
- private uint _padding_; // padding for structure alignment
- #pragma warning restore 169
- [CLSCompliant (false)]
- [nlink_t] public ulong st_nlink; // number of hard links
- [CLSCompliant (false)]
- [uid_t] public uint st_uid; // user ID of owner
- [CLSCompliant (false)]
- [gid_t] public uint st_gid; // group ID of owner
- [CLSCompliant (false)]
- [dev_t] public ulong st_rdev; // device type (if inode device)
- [off_t] public long st_size; // total size, in bytes
- [blksize_t] public long st_blksize; // blocksize for filesystem I/O
- [blkcnt_t] public long st_blocks; // number of blocks allocated
- [time_t] public long st_atime; // time of last access
- [time_t] public long st_mtime; // time of last modification
- [time_t] public long st_ctime; // time of last status change
- public override int GetHashCode ()
- {
- return st_dev.GetHashCode () ^
- st_ino.GetHashCode () ^
- st_mode.GetHashCode () ^
- st_nlink.GetHashCode () ^
- st_uid.GetHashCode () ^
- st_gid.GetHashCode () ^
- st_rdev.GetHashCode () ^
- st_size.GetHashCode () ^
- st_blksize.GetHashCode () ^
- st_blocks.GetHashCode () ^
- st_atime.GetHashCode () ^
- st_mtime.GetHashCode () ^
- st_ctime.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || obj.GetType() != GetType ())
- return false;
- Stat value = (Stat) obj;
- return value.st_dev == st_dev &&
- value.st_ino == st_ino &&
- value.st_mode == st_mode &&
- value.st_nlink == st_nlink &&
- value.st_uid == st_uid &&
- value.st_gid == st_gid &&
- value.st_rdev == st_rdev &&
- value.st_size == st_size &&
- value.st_blksize == st_blksize &&
- value.st_blocks == st_blocks &&
- value.st_atime == st_atime &&
- value.st_mtime == st_mtime &&
- value.st_ctime == st_ctime;
- }
- public bool Equals (Stat value)
- {
- return value.st_dev == st_dev &&
- value.st_ino == st_ino &&
- value.st_mode == st_mode &&
- value.st_nlink == st_nlink &&
- value.st_uid == st_uid &&
- value.st_gid == st_gid &&
- value.st_rdev == st_rdev &&
- value.st_size == st_size &&
- value.st_blksize == st_blksize &&
- value.st_blocks == st_blocks &&
- value.st_atime == st_atime &&
- value.st_mtime == st_mtime &&
- value.st_ctime == st_ctime;
- }
- public static bool operator== (Stat lhs, Stat rhs)
- {
- return lhs.Equals (rhs);
- }
- public static bool operator!= (Stat lhs, Stat rhs)
- {
- return !lhs.Equals (rhs);
- }
- }
- // `struct statvfs' isn't portable, so don't generate To/From methods.
- [Map]
- [CLSCompliant (false)]
- public struct Statvfs
- #if NET_2_0
- : IEquatable <Statvfs>
- #endif
- {
- public ulong f_bsize; // file system block size
- public ulong f_frsize; // fragment size
- [fsblkcnt_t] public ulong f_blocks; // size of fs in f_frsize units
- [fsblkcnt_t] public ulong f_bfree; // # free blocks
- [fsblkcnt_t] public ulong f_bavail; // # free blocks for non-root
- [fsfilcnt_t] public ulong f_files; // # inodes
- [fsfilcnt_t] public ulong f_ffree; // # free inodes
- [fsfilcnt_t] public ulong f_favail; // # free inodes for non-root
- public ulong f_fsid; // file system id
- public MountFlags f_flag; // mount flags
- public ulong f_namemax; // maximum filename length
- public override int GetHashCode ()
- {
- return f_bsize.GetHashCode () ^
- f_frsize.GetHashCode () ^
- f_blocks.GetHashCode () ^
- f_bfree.GetHashCode () ^
- f_bavail.GetHashCode () ^
- f_files.GetHashCode () ^
- f_ffree.GetHashCode () ^
- f_favail.GetHashCode () ^
- f_fsid.GetHashCode () ^
- f_flag.GetHashCode () ^
- f_namemax.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || obj.GetType() != GetType ())
- return false;
- Statvfs value = (Statvfs) obj;
- return value.f_bsize == f_bsize &&
- value.f_frsize == f_frsize &&
- value.f_blocks == f_blocks &&
- value.f_bfree == f_bfree &&
- value.f_bavail == f_bavail &&
- value.f_files == f_files &&
- value.f_ffree == f_ffree &&
- value.f_favail == f_favail &&
- value.f_fsid == f_fsid &&
- value.f_flag == f_flag &&
- value.f_namemax == f_namemax;
- }
- public bool Equals (Statvfs value)
- {
- return value.f_bsize == f_bsize &&
- value.f_frsize == f_frsize &&
- value.f_blocks == f_blocks &&
- value.f_bfree == f_bfree &&
- value.f_bavail == f_bavail &&
- value.f_files == f_files &&
- value.f_ffree == f_ffree &&
- value.f_favail == f_favail &&
- value.f_fsid == f_fsid &&
- value.f_flag == f_flag &&
- value.f_namemax == f_namemax;
- }
- public static bool operator== (Statvfs lhs, Statvfs rhs)
- {
- return lhs.Equals (rhs);
- }
- public static bool operator!= (Statvfs lhs, Statvfs rhs)
- {
- return !lhs.Equals (rhs);
- }
- }
- [Map ("struct timeval")]
- public struct Timeval
- #if NET_2_0
- : IEquatable <Timeval>
- #endif
- {
- [time_t] public long tv_sec; // seconds
- [suseconds_t] public long tv_usec; // microseconds
- public override int GetHashCode ()
- {
- return tv_sec.GetHashCode () ^ tv_usec.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || obj.GetType () != GetType ())
- return false;
- Timeval value = (Timeval) obj;
- return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
- }
- public bool Equals (Timeval value)
- {
- return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
- }
- public static bool operator== (Timeval lhs, Timeval rhs)
- {
- return lhs.Equals (rhs);
- }
- public static bool operator!= (Timeval lhs, Timeval rhs)
- {
- return !lhs.Equals (rhs);
- }
- }
- [Map ("struct timezone")]
- public struct Timezone
- #if NET_2_0
- : IEquatable <Timezone>
- #endif
- {
- public int tz_minuteswest; // minutes W of Greenwich
- #pragma warning disable 169
- private int tz_dsttime; // type of dst correction (OBSOLETE)
- #pragma warning restore 169
- public override int GetHashCode ()
- {
- return tz_minuteswest.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || obj.GetType () != GetType ())
- return false;
- Timezone value = (Timezone) obj;
- return value.tz_minuteswest == tz_minuteswest;
- }
- public bool Equals (Timezone value)
- {
- return value.tz_minuteswest == tz_minuteswest;
- }
- public static bool operator== (Timezone lhs, Timezone rhs)
- {
- return lhs.Equals (rhs);
- }
- public static bool operator!= (Timezone lhs, Timezone rhs)
- {
- return !lhs.Equals (rhs);
- }
- }
- [Map ("struct utimbuf")]
- public struct Utimbuf
- #if NET_2_0
- : IEquatable <Utimbuf>
- #endif
- {
- [time_t] public long actime; // access time
- [time_t] public long modtime; // modification time
- public override int GetHashCode ()
- {
- return actime.GetHashCode () ^ modtime.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || obj.GetType () != GetType ())
- return false;
- Utimbuf value = (Utimbuf) obj;
- return value.actime == actime && value.modtime == modtime;
- }
- public bool Equals (Utimbuf value)
- {
- return value.actime == actime && value.modtime == modtime;
- }
- public static bool operator== (Utimbuf lhs, Utimbuf rhs)
- {
- return lhs.Equals (rhs);
- }
- public static bool operator!= (Utimbuf lhs, Utimbuf rhs)
- {
- return !lhs.Equals (rhs);
- }
- }
- [Map ("struct timespec")]
- public struct Timespec
- #if NET_2_0
- : IEquatable <Timespec>
- #endif
- {
- [time_t] public long tv_sec; // Seconds.
- public long tv_nsec; // Nanoseconds.
- public override int GetHashCode ()
- {
- return tv_sec.GetHashCode () ^ tv_nsec.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || obj.GetType () != GetType ())
- return false;
- Timespec value = (Timespec) obj;
- return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
- }
- public bool Equals (Timespec value)
- {
- return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
- }
- public static bool operator== (Timespec lhs, Timespec rhs)
- {
- return lhs.Equals (rhs);
- }
- public static bool operator!= (Timespec lhs, Timespec rhs)
- {
- return !lhs.Equals (rhs);
- }
- }
- [Flags][Map]
- public enum EpollFlags {
- EPOLL_CLOEXEC = 02000000,
- EPOLL_NONBLOCK = 04000,
- }
- [Flags][Map]
- [CLSCompliant (false)]
- public enum EpollEvents : uint {
- EPOLLIN = 0x001,
- EPOLLPRI = 0x002,
- EPOLLOUT = 0x004,
- EPOLLRDNORM = 0x040,
- EPOLLRDBAND = 0x080,
- EPOLLWRNORM = 0x100,
- EPOLLWRBAND = 0x200,
- EPOLLMSG = 0x400,
- EPOLLERR = 0x008,
- EPOLLHUP = 0x010,
- EPOLLRDHUP = 0x2000,
- EPOLLONESHOT = 1 << 30,
- EPOLLET = unchecked ((uint) (1 << 31))
- }
- public enum EpollOp {
- EPOLL_CTL_ADD = 1,
- EPOLL_CTL_DEL = 2,
- EPOLL_CTL_MOD = 3,
- }
- [StructLayout (LayoutKind.Explicit, Size=12, Pack=1)]
- [CLSCompliant (false)]
- public struct EpollEvent {
- [FieldOffset (0)]
- public EpollEvents events;
- [FieldOffset (4)]
- public int fd;
- [FieldOffset (4)]
- public IntPtr ptr;
- [FieldOffset (4)]
- public uint u32;
- [FieldOffset (4)]
- public ulong u64;
- }
- #endregion
- #region Classes
- public sealed class Dirent
- #if NET_2_0
- : IEquatable <Dirent>
- #endif
- {
- [CLSCompliant (false)]
- public /* ino_t */ ulong d_ino;
- public /* off_t */ long d_off;
- [CLSCompliant (false)]
- public ushort d_reclen;
- public byte d_type;
- public string d_name;
- public override int GetHashCode ()
- {
- return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
- d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
- d_name.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || GetType() != obj.GetType())
- return false;
- Dirent d = (Dirent) obj;
- return Equals (d);
- }
- public bool Equals (Dirent value)
- {
- if (value == null)
- return false;
- return value.d_ino == d_ino && value.d_off == d_off &&
- value.d_reclen == d_reclen && value.d_type == d_type &&
- value.d_name == d_name;
- }
- public override string ToString ()
- {
- return d_name;
- }
- public static bool operator== (Dirent lhs, Dirent rhs)
- {
- return Object.Equals (lhs, rhs);
- }
- public static bool operator!= (Dirent lhs, Dirent rhs)
- {
- return !Object.Equals (lhs, rhs);
- }
- }
- public sealed class Fstab
- #if NET_2_0
- : IEquatable <Fstab>
- #endif
- {
- public string fs_spec;
- public string fs_file;
- public string fs_vfstype;
- public string fs_mntops;
- public string fs_type;
- public int fs_freq;
- public int fs_passno;
- public override int GetHashCode ()
- {
- return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
- fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
- fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
- }
- public override bool Equals (object obj)
- {
- if (obj == null || GetType() != obj.GetType())
- return false;
- Fstab f = (Fstab) obj;
- return Equals (f);
- }
- public bool Equals (Fstab value)
- {
- if (value == null)
- return false;
- return value.fs_spec == fs_spec && value.fs_file == fs_file &&
- value.fs_vfstype == fs_vfstype && value.fs_mntops == fs_mntops &&
- value.fs_type == fs_type && value.fs_freq == fs_freq &&
- value.fs_passno == fs_passno;
- }
- public override string ToString ()
- {
- return fs_spec;
- }
- public static bool operator== (Fstab lhs, Fstab rhs)
- {
- return Object.Equals (lhs, rhs);
- }
- public static bool operator!= (Fstab lhs, Fstab rhs)
- {
- return !Object.Equals (lhs, rhs);
- }
- }
- public sealed class Group
- #if NET_2_0
- : IEquatable <Group>
- #endif
- {
- public string gr_name;
- public string gr_passwd;
- [CLSCompliant (false)]
- public /* gid_t */ uint gr_gid;
- public string[] gr_mem;
- public override int GetHashCode ()
- {
- int memhc = 0;
- for (int i = 0; i < gr_mem.Length; ++i)
- memhc ^= gr_mem[i].GetHashCode ();
- return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
- gr_gid.GetHashCode () ^ memhc;
- }
- public override bool Equals (object obj)
- {
- if (obj == null || GetType() != obj.GetType())
- return false;
- Group g = (Group) obj;
- return Equals (g);
- }
- public bool Equals (Group value)
- {
- if (value == null)
- return false;
- if (value.gr_gid != gr_gid)
- return false;
- if (value.gr_gid == gr_gid && value.gr_name == gr_name &&
- value.gr_passwd == gr_passwd) {
- if (value.gr_mem == gr_mem)
- return true;
- if (value.gr_mem == null || gr_mem == null)
- return false;
- if (value.gr_mem.Length != gr_mem.Length)
- return false;
- for (int i = 0; i < gr_mem.Length; ++i)
- if (gr_mem[i] != value.gr_mem[i])
- return false;
- return true;
- }
- return false;
- }
- // Generate string in /etc/group format
- public override string ToString ()
- {
- StringBuilder sb = new StringBuilder ();
- sb.Append (gr_name).Append (":").Append (gr_passwd).Append (":");
- sb.Append (gr_gid).Append (":");
- GetMembers (sb, gr_mem);
- return sb.ToString ();
- }
- private static void GetMembers (StringBuilder sb, string[] members)
- {
- if (members.Length > 0)
- sb.Append (members[0]);
- for (int i = 1; i < members.Length; ++i) {
- sb.Append (",");
- sb.Append (members[i]);
- }
- }
- public static bool operator== (Group lhs, Group rhs)
- {
- return Object.Equals (lhs, rhs);
- }
- public static bool operator!= (Group lhs, Group rhs)
- {
- return !Object.Equals (lhs, rhs);
- }
- }
- public sealed class Passwd
- #if NET_2_0
- : IEquatable <Passwd>
- #endif
- {
- public string pw_name;
- public string pw_passwd;
- [CLSCompliant (false)]
- public /* uid_t */ uint pw_uid;
- [CLSCompliant (false)]
- public /* gid_t */ uint pw_gid;
- public string pw_gecos;
- public string pw_dir;
- public string pw_shell;
- public override int GetHashCode ()
- {
- return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
- pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
- pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
- pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || GetType() != obj.GetType())
- return false;
- Passwd p = (Passwd) obj;
- return Equals (p);
- }
- public bool Equals (Passwd value)
- {
- if (value == null)
- return false;
- return value.pw_uid == pw_uid && value.pw_gid == pw_gid &&
- value.pw_name == pw_name && value.pw_passwd == pw_passwd &&
- value.pw_gecos == pw_gecos && value.pw_dir == pw_dir &&
- value.pw_shell == pw_shell;
- }
- // Generate string in /etc/passwd format
- public override string ToString ()
- {
- return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
- pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
- }
- public static bool operator== (Passwd lhs, Passwd rhs)
- {
- return Object.Equals (lhs, rhs);
- }
- public static bool operator!= (Passwd lhs, Passwd rhs)
- {
- return !Object.Equals (lhs, rhs);
- }
- }
- public sealed class Utsname
- #if NET_2_0
- : IEquatable <Utsname>
- #endif
- {
- public string sysname;
- public string nodename;
- public string release;
- public string version;
- public string machine;
- public string domainname;
- public override int GetHashCode ()
- {
- return sysname.GetHashCode () ^ nodename.GetHashCode () ^
- release.GetHashCode () ^ version.GetHashCode () ^
- machine.GetHashCode () ^ domainname.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- if (obj == null || GetType() != obj.GetType())
- return false;
- Utsname u = (Utsname) obj;
- return Equals (u);
- }
- public bool Equals (Utsname value)
- {
- return value.sysname == sysname && value.nodename == nodename &&
- value.release == release && value.version == version &&
- value.machine == machine && value.domainname == domainname;
- }
- // Generate string in /etc/passwd format
- public override string ToString ()
- {
- return string.Format ("{0} {1} {2} {3} {4}",
- sysname, nodename, release, version, machine);
- }
- public static bool operator== (Utsname lhs, Utsname rhs)
- {
- return Object.Equals (lhs, rhs);
- }
- public static bool operator!= (Utsname lhs, Utsname rhs)
- {
- return !Object.Equals (lhs, rhs);
- }
- }
- //
- // Convention: Functions *not* part of the standard C library AND part of
- // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
- //
- // For example, the man page should be similar to:
- //
- // CONFORMING TO (or CONFORMS TO)
- // XPG2, SUSv2, POSIX, etc.
- //
- // 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
- // function are related (e.g. getgroups(2))
- // (3) The return type SHOULD NOT be changed. If you want to provide a
- // convenience function with a nicer return type, place it into one of
- // the Mono.Unix.Unix* wrapper classes, and give it a .NET-styled name.
- // - EXCEPTION: No public functions should have a `void' return type.
- // `void' return types should be replaced with `int'.
- // Rationality: `void'-return functions typically require a
- // complicated call sequence, such as clear errno, then call, then
- // check errno to see if any errors occurred. This sequence can't
- // be done safely in managed code, as errno may change as part of
- // the P/Invoke mechanism.
- // Instead, add a MonoPosixHelper export which does:
- // errno = 0;
- // INVOKE SYSCALL;
- // return errno == 0 ? 0 : -1;
- // This lets managed code check the return value in the usual manner.
- // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
- // - If you're wrapping *broken* methods which make assumptions about
- // input data, such as that an argument refers to N bytes of data.
- // This is currently limited to cuserid(3) and encrypt(3).
- // - If you call functions which themselves generate exceptions.
- // This is the case for using NativeConvert, which will throw an
- // exception if an invalid/unsupported value is used.
- //
- // Naming Conventions:
- // - Syscall method names should have the same name as the function being
- // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
- // consult the appropriate man page if necessary.
- // - Methods need not have the same arguments IF this simplifies or
- // permits correct usage. The current example is syslog, in which
- // syslog(3)'s single `priority' argument is split into SyslogFacility
- // and SyslogLevel arguments.
- // - Type names (structures, classes, enumerations) are always PascalCased.
- // - Enumerations are named as <MethodName><ArgumentName>, and are located
- // in the Mono.Unix.Native namespace. For readability, if ArgumentName
- // is "cmd", use Command instead. For example, fcntl(2) takes a
- // FcntlCommand argument. This naming convention is to provide an
- // assocation between an enumeration and where it should be used, and
- // allows a single method to accept multiple different enumerations
- // (see mmap(2), which takes MmapProts and MmapFlags).
- // - EXCEPTION: if an enumeration is shared between multiple different
- // methods, AND/OR the "obvious" enumeration name conflicts with an
- // existing .NET type, a more appropriate name should be used.
- // Example: FilePermissions
- // - EXCEPTION: [Flags] enumerations should get plural names to follow
- // .NET name guidelines. Usually this doesn't result in a change
- // (OpenFlags is the `flags' parameter for open(2)), but it can
- // (mmap(2) prot ==> MmapProts, access(2) mode ==> AccessModes).
- // - Enumerations should have the [Map] and (optional) [Flags] attributes.
- // [Map] is required for make-map to find the type and generate the
- // appropriate NativeConvert conversion functions.
- // - Enumeration contents should match the original Unix names. This helps
- // with documentation (the existing man pages are still useful), and is
- // required for use with the make-map generation program.
- // - Structure names should be the PascalCased version of the actual
- // structure name (struct flock ==> Flock). Structure members should
- // have the same names, or a (reasonably) portable subset (Dirent being
- // the poster child for questionable members).
- // - Whether the managed type should be a reference type (class) or a
- // value type (struct) should be determined on a case-by-case basis:
- // if you ever need to be able to use NULL for it (such as with Dirent,
- // Group, Passwd, as these are method return types and `null' is used
- // to signify the end), it should be a reference type; otherwise, use
- // your discretion, and keep any expected usage patterns in mind.
- // - Syscall should be a Single Point Of Truth (SPOT). There should be
- // only ONE way to do anything. By convention, the Linux function names
- // are used, but that need not always be the case (use your discretion).
- // It SHOULD NOT be required that developers know what platform they're
- // on, and choose among a set of similar functions. In short, anything
- // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
- // we can afford to clean things up whenever possible.
- // - Examples:
- // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
- // statvfs(2). MonoPosixHelper will "thunk" between the two,
- // exporting a statvfs that works across platforms.
- // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
- // instead provides getvfsent(3). MonoPosixHelper provides wrappers
- // to convert getvfsent(3) into Fstab data.
- // - Exception: If it isn't possible to cleanly wrap platforms, then the
- // method shouldn't be exported. The user will be expected to do their
- // own platform check and their own DllImports.
- // Examples: mount(2), umount(2), etc.
- // - Note: if a platform doesn't support a function AT ALL, the
- // MonoPosixHelper wrapper won't be compiled, resulting in a
- // EntryPointNotFoundException. This is also consistent with a missing
- // P/Invoke into libc.so.
- //
- [CLSCompliant (false)]
- public sealed class Syscall : Stdlib
- {
- new internal const string LIBC = "libc";
- private Syscall () {}
- //
- // <aio.h>
- //
- // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
- // aio_return(3), aio_suspend(3), aio_write(3)
- //
- // 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 (
- [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
- string path,
- [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
- string name, byte[] value, ulong size, XattrFlags flags);
- public static int setxattr (string path, string name, byte [] value, ulong size)
- {
- return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
- }
- public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
- {
- return setxattr (path, name, value, (ulong) value.Length, flags);
- }
- public static int setxattr (string path, string name, byte [] value)
- {
- return setxattr (path, name, value, (ulong) value.Length);
- }
- // 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 (
- [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
- string path,
- [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
- string name, byte[] value, ulong size, XattrFlags flags);
- public static int lsetxattr (string path, string name, byte [] value, ulong size)
- {
- return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
- }
- public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
- {
- return lsetxattr (path, name, value, (ulong) value.Length, flags);
- }
- public static int lsetxattr (string path, string name, byte [] value)
- {
- return lsetxattr (path, name, value, (ulong) value.Length);
- }
- // 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,
- [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
- string name, byte[] value, ulong size, XattrFlags flags);
- public static int fsetxattr (int fd, string name, byte [] value, ulong size)
- {
- return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
- }
- public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
- {
- return fsetxattr…
Large files files are truncated, but you can click here to view the full file