2 // Mono.Unix/Syscall.cs
5 // Miguel de Icaza (miguel@novell.com)
6 // Jonathan Pryor (jonpryor@vt.edu)
8 // (C) 2003 Novell, Inc.
9 // (C) 2004-2006 Jonathan Pryor
11 // This file implements the low-level syscall interface to the POSIX
14 // This file tries to stay close to the low-level API as much as possible
15 // using enumerations, structures and in a few cases, using existing .NET
18 // Implementation notes:
20 // Since the values for the various constants on the API changes
21 // from system to system (even Linux on different architectures will
22 // have different values), we define our own set of values, and we
23 // use a set of C helper routines to map from the constants we define
24 // to the values of the native OS.
26 // Bitfields are flagged with the [Map] attribute, and a helper program
27 // generates a set of routines that we can call to convert from our value
28 // definitions to the value definitions expected by the OS; see
29 // NativeConvert for the conversion routines.
31 // Methods that require tuning are bound as `private sys_NAME' methods
32 // and then a `NAME' method is exposed.
36 // Permission is hereby granted, free of charge, to any person obtaining
37 // a copy of this software and associated documentation files (the
38 // "Software"), to deal in the Software without restriction, including
39 // without limitation the rights to use, copy, modify, merge, publish,
40 // distribute, sublicense, and/or sell copies of the Software, and to
41 // permit persons to whom the Software is furnished to do so, subject to
42 // the following conditions:
44 // The above copyright notice and this permission notice shall be
45 // included in all copies or substantial portions of the Software.
47 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57 using System.Collections;
58 using System.Collections.Generic;
59 using System.Runtime.InteropServices;
60 using System.Security;
62 using Mono.Unix.Native;
64 namespace Mono.Unix.Native {
69 [CLSCompliant (false)]
70 public enum SyslogOptions {
71 LOG_PID = 0x01, // log the pid with each message
72 LOG_CONS = 0x02, // log on the console if errors in sending
73 LOG_ODELAY = 0x04, // delay open until first syslog (default)
74 LOG_NDELAY = 0x08, // don't delay open
75 LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
76 LOG_PERROR = 0x20 // log to stderr as well
80 [CLSCompliant (false)]
81 public enum SyslogFacility {
92 LOG_AUTHPRIV = 10 << 3,
100 LOG_LOCAL6 = 22 << 3,
101 LOG_LOCAL7 = 23 << 3,
105 [CLSCompliant (false)]
106 public enum SyslogLevel {
107 LOG_EMERG = 0, // system is unusable
108 LOG_ALERT = 1, // action must be taken immediately
109 LOG_CRIT = 2, // critical conditions
110 LOG_ERR = 3, // warning conditions
111 LOG_WARNING = 4, // warning conditions
112 LOG_NOTICE = 5, // normal but significant condition
113 LOG_INFO = 6, // informational
114 LOG_DEBUG = 7 // debug-level messages
118 [CLSCompliant (false)]
119 public enum OpenFlags : int {
123 O_RDONLY = 0x00000000,
124 O_WRONLY = 0x00000001,
128 // Or-ed with zero or more of these
130 O_CREAT = 0x00000040,
132 O_NOCTTY = 0x00000100,
133 O_TRUNC = 0x00000200,
134 O_APPEND = 0x00000400,
135 O_NONBLOCK = 0x00000800,
139 // These are non-Posix. Using them will result in errors/exceptions on
140 // non-supported platforms.
142 // (For example, "C-wrapped" system calls -- calls with implementation in
143 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
144 // calls will generate an exception in NativeConvert, as the value can't be
145 // converted on the target platform.)
148 O_NOFOLLOW = 0x00020000,
149 O_DIRECTORY = 0x00010000,
150 O_DIRECT = 0x00004000,
151 O_ASYNC = 0x00002000,
152 O_LARGEFILE = 0x00008000,
153 O_CLOEXEC = 0x00080000,
158 [CLSCompliant (false)]
159 public enum AtFlags : int {
160 AT_SYMLINK_NOFOLLOW = 0x00000100,
161 AT_REMOVEDIR = 0x00000200,
162 AT_SYMLINK_FOLLOW = 0x00000400,
163 AT_NO_AUTOMOUNT = 0x00000800,
164 AT_EMPTY_PATH = 0x00001000
169 [CLSCompliant (false)]
170 public enum FilePermissions : uint {
171 S_ISUID = 0x0800, // Set user ID on execution
172 S_ISGID = 0x0400, // Set group ID on execution
173 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
174 S_IRUSR = 0x0100, // Read by owner
175 S_IWUSR = 0x0080, // Write by owner
176 S_IXUSR = 0x0040, // Execute by owner
177 S_IRGRP = 0x0020, // Read by group
178 S_IWGRP = 0x0010, // Write by group
179 S_IXGRP = 0x0008, // Execute by group
180 S_IROTH = 0x0004, // Read by other
181 S_IWOTH = 0x0002, // Write by other
182 S_IXOTH = 0x0001, // Execute by other
184 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
185 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
186 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
187 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
188 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
189 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
192 // Why these are held in "mode_t" is beyond me...
193 S_IFMT = 0xF000, // Bits which determine file type
194 [Map(SuppressFlags="S_IFMT")]
195 S_IFDIR = 0x4000, // Directory
196 [Map(SuppressFlags="S_IFMT")]
197 S_IFCHR = 0x2000, // Character device
198 [Map(SuppressFlags="S_IFMT")]
199 S_IFBLK = 0x6000, // Block device
200 [Map(SuppressFlags="S_IFMT")]
201 S_IFREG = 0x8000, // Regular file
202 [Map(SuppressFlags="S_IFMT")]
203 S_IFIFO = 0x1000, // FIFO
204 [Map(SuppressFlags="S_IFMT")]
205 S_IFLNK = 0xA000, // Symbolic link
206 [Map(SuppressFlags="S_IFMT")]
207 S_IFSOCK = 0xC000, // Socket
211 [CLSCompliant (false)]
212 public enum FcntlCommand : int {
213 // Form /usr/include/bits/fcntl.h
214 F_DUPFD = 0, // Duplicate file descriptor.
215 F_GETFD = 1, // Get file descriptor flags.
216 F_SETFD = 2, // Set file descriptor flags.
217 F_GETFL = 3, // Get file status flags.
218 F_SETFL = 4, // Set file status flags.
219 F_GETLK = 12, // Get record locking info. [64]
220 F_SETLK = 13, // Set record locking info (non-blocking). [64]
221 F_SETLKW = 14, // Set record locking info (blocking). [64]
222 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
223 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
224 F_SETSIG = 10, // Set number of signal to be sent.
225 F_GETSIG = 11, // Get number of signal to be sent.
226 F_NOCACHE = 48, // OSX: turn data caching off/on for this fd.
227 F_SETLEASE = 1024, // Set a lease.
228 F_GETLEASE = 1025, // Enquire what lease is active.
229 F_NOTIFY = 1026, // Required notifications on a directory
233 [CLSCompliant (false)]
234 public enum LockType : short {
235 F_RDLCK = 0, // Read lock.
236 F_WRLCK = 1, // Write lock.
237 F_UNLCK = 2, // Remove lock.
241 [CLSCompliant (false)]
242 public enum SeekFlags : short {
243 // values liberally copied from /usr/include/unistd.h
244 SEEK_SET = 0, // Seek from beginning of file.
245 SEEK_CUR = 1, // Seek from current position.
246 SEEK_END = 2, // Seek from end of file.
248 L_SET = SEEK_SET, // BSD alias for SEEK_SET
249 L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
250 L_XTND = SEEK_END, // BSD alias for SEEK_END
254 [CLSCompliant (false)]
255 public enum DirectoryNotifyFlags : int {
256 // from /usr/include/bits/fcntl.h
257 DN_ACCESS = 0x00000001, // File accessed.
258 DN_MODIFY = 0x00000002, // File modified.
259 DN_CREATE = 0x00000004, // File created.
260 DN_DELETE = 0x00000008, // File removed.
261 DN_RENAME = 0x00000010, // File renamed.
262 DN_ATTRIB = 0x00000020, // File changed attributes.
263 DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
267 [CLSCompliant (false)]
268 public enum PosixFadviseAdvice : int {
269 POSIX_FADV_NORMAL = 0, // No further special treatment.
270 POSIX_FADV_RANDOM = 1, // Expect random page references.
271 POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
272 POSIX_FADV_WILLNEED = 3, // Will need these pages.
273 POSIX_FADV_DONTNEED = 4, // Don't need these pages.
274 POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
278 [CLSCompliant (false)]
279 public enum PosixMadviseAdvice : int {
280 POSIX_MADV_NORMAL = 0, // No further special treatment.
281 POSIX_MADV_RANDOM = 1, // Expect random page references.
282 POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
283 POSIX_MADV_WILLNEED = 3, // Will need these pages.
284 POSIX_MADV_DONTNEED = 4, // Don't need these pages.
288 public enum Signum : int {
289 SIGHUP = 1, // Hangup (POSIX).
290 SIGINT = 2, // Interrupt (ANSI).
291 SIGQUIT = 3, // Quit (POSIX).
292 SIGILL = 4, // Illegal instruction (ANSI).
293 SIGTRAP = 5, // Trace trap (POSIX).
294 SIGABRT = 6, // Abort (ANSI).
295 SIGIOT = 6, // IOT trap (4.2 BSD).
296 SIGBUS = 7, // BUS error (4.2 BSD).
297 SIGFPE = 8, // Floating-point exception (ANSI).
298 SIGKILL = 9, // Kill, unblockable (POSIX).
299 SIGUSR1 = 10, // User-defined signal 1 (POSIX).
300 SIGSEGV = 11, // Segmentation violation (ANSI).
301 SIGUSR2 = 12, // User-defined signal 2 (POSIX).
302 SIGPIPE = 13, // Broken pipe (POSIX).
303 SIGALRM = 14, // Alarm clock (POSIX).
304 SIGTERM = 15, // Termination (ANSI).
305 SIGSTKFLT = 16, // Stack fault.
306 SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
307 SIGCHLD = 17, // Child status has changed (POSIX).
308 SIGCONT = 18, // Continue (POSIX).
309 SIGSTOP = 19, // Stop, unblockable (POSIX).
310 SIGTSTP = 20, // Keyboard stop (POSIX).
311 SIGTTIN = 21, // Background read from tty (POSIX).
312 SIGTTOU = 22, // Background write to tty (POSIX).
313 SIGURG = 23, // Urgent condition on socket (4.2 BSD).
314 SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
315 SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
316 SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
317 SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
318 SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
319 SIGPOLL = SIGIO, // Pollable event occurred (System V).
320 SIGIO = 29, // I/O now possible (4.2 BSD).
321 SIGPWR = 30, // Power failure restart (System V).
322 SIGSYS = 31, // Bad system call.
327 public enum WaitOptions : int {
328 WNOHANG = 1, // Don't block waiting
329 WUNTRACED = 2, // Report status of stopped children
333 [CLSCompliant (false)]
334 public enum AccessModes : int {
342 [CLSCompliant (false)]
343 public enum PathconfName : int {
350 _PC_CHOWN_RESTRICTED,
358 _PC_REC_INCR_XFER_SIZE,
359 _PC_REC_MAX_XFER_SIZE,
360 _PC_REC_MIN_XFER_SIZE,
368 [CLSCompliant (false)]
369 public enum SysconfName : int {
379 _SC_REALTIME_SIGNALS,
380 _SC_PRIORITY_SCHEDULING,
389 _SC_MEMORY_PROTECTION,
392 _SC_SHARED_MEMORY_OBJECTS,
395 _SC_AIO_PRIO_DELTA_MAX,
406 /* Values for the argument to `sysconf'
407 corresponding to _POSIX2_* symbols. */
412 _SC_COLL_WEIGHTS_MAX,
417 _SC_CHARCLASS_NAME_MAX,
433 _SC_IOV_MAX = _SC_UIO_MAXIOV,
434 _SC_PII_INTERNET_STREAM,
435 _SC_PII_INTERNET_DGRAM,
440 /* Values according to POSIX 1003.1c (POSIX threads). */
442 _SC_THREAD_SAFE_FUNCTIONS,
443 _SC_GETGR_R_SIZE_MAX,
444 _SC_GETPW_R_SIZE_MAX,
447 _SC_THREAD_DESTRUCTOR_ITERATIONS,
449 _SC_THREAD_STACK_MIN,
450 _SC_THREAD_THREADS_MAX,
451 _SC_THREAD_ATTR_STACKADDR,
452 _SC_THREAD_ATTR_STACKSIZE,
453 _SC_THREAD_PRIORITY_SCHEDULING,
454 _SC_THREAD_PRIO_INHERIT,
455 _SC_THREAD_PRIO_PROTECT,
456 _SC_THREAD_PROCESS_SHARED,
457 _SC_NPROCESSORS_CONF,
458 _SC_NPROCESSORS_ONLN,
464 _SC_XOPEN_XCU_VERSION,
499 _SC_XBS5_ILP32_OFF32,
500 _SC_XBS5_ILP32_OFFBIG,
502 _SC_XBS5_LPBIG_OFFBIG,
505 _SC_XOPEN_REALTIME_THREADS,
510 _SC_C_LANG_SUPPORT_R,
516 _SC_DEVICE_SPECIFIC_R,
527 _SC_READER_WRITER_LOCKS,
535 _SC_THREAD_SPORADIC_SERVER,
537 _SC_SYSTEM_DATABASE_R,
539 _SC_TYPED_MEMORY_OBJECTS,
543 _SC_2_PBS_ACCOUNTING,
549 _SC_2_PBS_CHECKPOINT,
556 _SC_TRACE_EVENT_FILTER,
559 _SC_LEVEL1_ICACHE_SIZE,
560 _SC_LEVEL1_ICACHE_ASSOC,
561 _SC_LEVEL1_ICACHE_LINESIZE,
562 _SC_LEVEL1_DCACHE_SIZE,
563 _SC_LEVEL1_DCACHE_ASSOC,
564 _SC_LEVEL1_DCACHE_LINESIZE,
565 _SC_LEVEL2_CACHE_SIZE,
566 _SC_LEVEL2_CACHE_ASSOC,
567 _SC_LEVEL2_CACHE_LINESIZE,
568 _SC_LEVEL3_CACHE_SIZE,
569 _SC_LEVEL3_CACHE_ASSOC,
570 _SC_LEVEL3_CACHE_LINESIZE,
571 _SC_LEVEL4_CACHE_SIZE,
572 _SC_LEVEL4_CACHE_ASSOC,
573 _SC_LEVEL4_CACHE_LINESIZE
577 [CLSCompliant (false)]
578 public enum ConfstrName : int {
579 _CS_PATH, /* The default search path. */
580 _CS_V6_WIDTH_RESTRICTED_ENVS,
581 _CS_GNU_LIBC_VERSION,
582 _CS_GNU_LIBPTHREAD_VERSION,
583 _CS_LFS_CFLAGS = 1000,
591 _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
592 _CS_XBS5_ILP32_OFF32_LDFLAGS,
593 _CS_XBS5_ILP32_OFF32_LIBS,
594 _CS_XBS5_ILP32_OFF32_LINTFLAGS,
595 _CS_XBS5_ILP32_OFFBIG_CFLAGS,
596 _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
597 _CS_XBS5_ILP32_OFFBIG_LIBS,
598 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
599 _CS_XBS5_LP64_OFF64_CFLAGS,
600 _CS_XBS5_LP64_OFF64_LDFLAGS,
601 _CS_XBS5_LP64_OFF64_LIBS,
602 _CS_XBS5_LP64_OFF64_LINTFLAGS,
603 _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
604 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
605 _CS_XBS5_LPBIG_OFFBIG_LIBS,
606 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
607 _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
608 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
609 _CS_POSIX_V6_ILP32_OFF32_LIBS,
610 _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
611 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
612 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
613 _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
614 _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
615 _CS_POSIX_V6_LP64_OFF64_CFLAGS,
616 _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
617 _CS_POSIX_V6_LP64_OFF64_LIBS,
618 _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
619 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
620 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
621 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
622 _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
626 [CLSCompliant (false)]
627 public enum LockfCommand : int {
628 F_ULOCK = 0, // Unlock a previously locked region.
629 F_LOCK = 1, // Lock a region for exclusive use.
630 F_TLOCK = 2, // Test and lock a region for exclusive use.
631 F_TEST = 3, // Test a region for other process locks.
635 public enum PollEvents : short {
636 POLLIN = 0x0001, // There is data to read
637 POLLPRI = 0x0002, // There is urgent data to read
638 POLLOUT = 0x0004, // Writing now will not block
639 POLLERR = 0x0008, // Error condition
640 POLLHUP = 0x0010, // Hung up
641 POLLNVAL = 0x0020, // Invalid request; fd not open
642 // XPG4.2 definitions (via _XOPEN_SOURCE)
643 POLLRDNORM = 0x0040, // Normal data may be read
644 POLLRDBAND = 0x0080, // Priority data may be read
645 POLLWRNORM = 0x0100, // Writing now will not block
646 POLLWRBAND = 0x0200, // Priority data may be written
650 [CLSCompliant (false)]
651 public enum XattrFlags : int {
658 [CLSCompliant (false)]
659 public enum MountFlags : ulong {
660 ST_RDONLY = 1, // Mount read-only
661 ST_NOSUID = 2, // Ignore suid and sgid bits
662 ST_NODEV = 4, // Disallow access to device special files
663 ST_NOEXEC = 8, // Disallow program execution
664 ST_SYNCHRONOUS = 16, // Writes are synced at once
665 ST_REMOUNT = 32, // Alter flags of a mounted FS
666 ST_MANDLOCK = 64, // Allow mandatory locks on an FS
667 ST_WRITE = 128, // Write on file/directory/symlink
668 ST_APPEND = 256, // Append-only file
669 ST_IMMUTABLE = 512, // Immutable file
670 ST_NOATIME = 1024, // Do not update access times
671 ST_NODIRATIME = 2048, // Do not update directory access times
672 ST_BIND = 4096, // Bind directory at different place
676 [CLSCompliant (false)]
677 public enum MmapFlags : int {
678 MAP_SHARED = 0x01, // Share changes.
679 MAP_PRIVATE = 0x02, // Changes are private.
680 MAP_TYPE = 0x0f, // Mask for type of mapping.
681 MAP_FIXED = 0x10, // Interpret addr exactly.
683 MAP_ANONYMOUS = 0x20, // Don't use a file.
684 MAP_ANON = MAP_ANONYMOUS,
686 // These are Linux-specific.
687 MAP_GROWSDOWN = 0x00100, // Stack-like segment.
688 MAP_DENYWRITE = 0x00800, // ETXTBSY
689 MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
690 MAP_LOCKED = 0x02000, // Lock the mapping.
691 MAP_NORESERVE = 0x04000, // Don't check for reservations.
692 MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
693 MAP_NONBLOCK = 0x10000, // Do not block on IO.
697 [CLSCompliant (false)]
698 public enum MmapProts : int {
699 PROT_READ = 0x1, // Page can be read.
700 PROT_WRITE = 0x2, // Page can be written.
701 PROT_EXEC = 0x4, // Page can be executed.
702 PROT_NONE = 0x0, // Page can not be accessed.
703 PROT_GROWSDOWN = 0x01000000, // Extend change to start of
704 // growsdown vma (mprotect only).
705 PROT_GROWSUP = 0x02000000, // Extend change to start of
706 // growsup vma (mprotect only).
710 [CLSCompliant (false)]
711 public enum MsyncFlags : int {
712 MS_ASYNC = 0x1, // Sync memory asynchronously.
713 MS_SYNC = 0x4, // Synchronous memory sync.
714 MS_INVALIDATE = 0x2, // Invalidate the caches.
718 [CLSCompliant (false)]
719 public enum MlockallFlags : int {
720 MCL_CURRENT = 0x1, // Lock all currently mapped pages.
721 MCL_FUTURE = 0x2, // Lock all additions to address
725 [CLSCompliant (false)]
726 public enum MremapFlags : ulong {
727 MREMAP_MAYMOVE = 0x1,
731 [CLSCompliant (false)]
732 public enum UnixSocketType : int {
733 SOCK_STREAM = 1, // Byte-stream socket
734 SOCK_DGRAM = 2, // Datagram socket
735 SOCK_RAW = 3, // Raw protocol interface (linux specific)
736 SOCK_RDM = 4, // Reliably-delivered messages (linux specific)
737 SOCK_SEQPACKET = 5, // Sequenced-packet socket
738 SOCK_DCCP = 6, // Datagram Congestion Control Protocol (linux specific)
739 SOCK_PACKET = 10, // Linux specific
743 [CLSCompliant (false)]
744 public enum UnixSocketFlags : int {
745 SOCK_CLOEXEC = 0x80000, /* Atomically set close-on-exec flag for the new descriptor(s). */
746 SOCK_NONBLOCK = 0x00800, /* Atomically mark descriptor(s) as non-blocking. */
750 [CLSCompliant (false)]
751 public enum UnixSocketProtocol : int {
752 IPPROTO_ICMP = 1, /* Internet Control Message Protocol */
753 IPPROTO_IGMP = 2, /* Internet Group Management Protocol */
754 IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94) */
755 IPPROTO_TCP = 6, /* Transmission Control Protocol */
756 IPPROTO_EGP = 8, /* Exterior Gateway Protocol */
757 IPPROTO_PUP = 12, /* PUP protocol */
758 IPPROTO_UDP = 17, /* User Datagram Protocol */
759 IPPROTO_IDP = 22, /* XNS IDP protocol */
760 IPPROTO_TP = 29, /* SO Transport Protocol Class 4 */
761 IPPROTO_DCCP = 33, /* Datagram Congestion Control Protocol */
762 IPPROTO_IPV6 = 41, /* IPv6-in-IPv4 tunnelling */
763 IPPROTO_RSVP = 46, /* RSVP Protocol */
764 IPPROTO_GRE = 47, /* Cisco GRE tunnels (rfc 1701,1702) */
765 IPPROTO_ESP = 50, /* Encapsulation Security Payload protocol */
766 IPPROTO_AH = 51, /* Authentication Header protocol */
767 IPPROTO_MTP = 92, /* Multicast Transport Protocol */
768 IPPROTO_BEETPH = 94, /* IP option pseudo header for BEET */
769 IPPROTO_ENCAP = 98, /* Encapsulation Header */
770 IPPROTO_PIM = 103, /* Protocol Independent Multicast */
771 IPPROTO_COMP = 108, /* Compression Header Protocol */
772 IPPROTO_SCTP = 132, /* Stream Control Transport Protocol */
773 IPPROTO_UDPLITE = 136, /* UDP-Lite (RFC 3828) */
774 IPPROTO_RAW = 255, /* Raw IP packets */
776 // Number used by linux (0) has a special meaning for socket()
777 IPPROTO_IP = 1024, /* Dummy protocol for TCP */
778 // Number used by linux (1) clashes with IPPROTO_ICMP
779 SOL_SOCKET = 2048, /* For setsockopt() / getsockopt(): Options to be accessed at socket level, not protocol level. */
783 [CLSCompliant (false)]
784 public enum UnixAddressFamily : int {
785 AF_UNSPEC = 0, /* Unspecified. */
786 AF_UNIX = 1, /* Local to host (pipes and file-domain). */
787 AF_INET = 2, /* IP protocol family. */
788 AF_AX25 = 3, /* Amateur Radio AX.25. */
789 AF_IPX = 4, /* Novell Internet Protocol. */
790 AF_APPLETALK = 5, /* Appletalk DDP. */
791 AF_NETROM = 6, /* Amateur radio NetROM. */
792 AF_BRIDGE = 7, /* Multiprotocol bridge. */
793 AF_ATMPVC = 8, /* ATM PVCs. */
794 AF_X25 = 9, /* Reserved for X.25 project. */
795 AF_INET6 = 10, /* IP version 6. */
796 AF_ROSE = 11, /* Amateur Radio X.25 PLP. */
797 AF_DECnet = 12, /* Reserved for DECnet project. */
798 AF_NETBEUI = 13, /* Reserved for 802.2LLC project. */
799 AF_SECURITY = 14, /* Security callback pseudo AF. */
800 AF_KEY = 15, /* PF_KEY key management API. */
802 AF_PACKET = 17, /* Packet family. */
803 AF_ASH = 18, /* Ash. */
804 AF_ECONET = 19, /* Acorn Econet. */
805 AF_ATMSVC = 20, /* ATM SVCs. */
806 AF_RDS = 21, /* RDS sockets. */
807 AF_SNA = 22, /* Linux SNA Project */
808 AF_IRDA = 23, /* IRDA sockets. */
809 AF_PPPOX = 24, /* PPPoX sockets. */
810 AF_WANPIPE = 25, /* Wanpipe API sockets. */
811 AF_LLC = 26, /* Linux LLC. */
812 AF_CAN = 29, /* Controller Area Network. */
813 AF_TIPC = 30, /* TIPC sockets. */
814 AF_BLUETOOTH = 31, /* Bluetooth sockets. */
815 AF_IUCV = 32, /* IUCV sockets. */
816 AF_RXRPC = 33, /* RxRPC sockets. */
817 AF_ISDN = 34, /* mISDN sockets. */
818 AF_PHONET = 35, /* Phonet sockets. */
819 AF_IEEE802154 = 36, /* IEEE 802.15.4 sockets. */
820 AF_CAIF = 37, /* CAIF sockets. */
821 AF_ALG = 38, /* Algorithm sockets. */
822 AF_NFC = 39, /* NFC sockets. */
823 AF_VSOCK = 40, /* vSockets. */
827 [CLSCompliant (false)]
828 public enum UnixSocketOptionName : int {
852 SO_SECURITY_AUTHENTICATION = 22,
853 SO_SECURITY_ENCRYPTION_TRANSPORT = 23,
854 SO_SECURITY_ENCRYPTION_NETWORK = 24,
855 SO_BINDTODEVICE = 25,
856 SO_ATTACH_FILTER = 26,
857 SO_DETACH_FILTER = 27,
865 SO_TIMESTAMPING = 37,
873 SO_SELECT_ERR_QUEUE = 45,
875 SO_MAX_PACING_RATE = 47,
879 [CLSCompliant (false)]
880 public enum MessageFlags : int {
881 MSG_OOB = 0x01, /* Process out-of-band data. */
882 MSG_PEEK = 0x02, /* Peek at incoming messages. */
883 MSG_DONTROUTE = 0x04, /* Don't use local routing. */
884 MSG_CTRUNC = 0x08, /* Control data lost before delivery. */
885 MSG_PROXY = 0x10, /* Supply or ask second address. */
887 MSG_DONTWAIT = 0x40, /* Nonblocking IO. */
888 MSG_EOR = 0x80, /* End of record. */
889 MSG_WAITALL = 0x100, /* Wait for a full request. */
892 MSG_CONFIRM = 0x800, /* Confirm path validity. */
894 MSG_ERRQUEUE = 0x2000, /* Fetch message from error queue. */
895 MSG_NOSIGNAL = 0x4000, /* Do not generate SIGPIPE. */
896 MSG_MORE = 0x8000, /* Sender will send more. */
897 MSG_WAITFORONE = 0x10000, /* Wait for at least one packet to return.*/
898 MSG_FASTOPEN = 0x20000000, /* Send data in TCP SYN. */
899 MSG_CMSG_CLOEXEC = 0x40000000, /* Set close_on_exit for file descriptor received through SCM_RIGHTS. */
903 [CLSCompliant (false)]
904 public enum ShutdownOption : int {
905 SHUT_RD = 0x01, /* No more receptions. */
906 SHUT_WR = 0x02, /* No more transmissions. */
907 SHUT_RDWR = 0x03, /* No more receptions or transmissions. */
914 [Map ("struct flock")]
918 [CLSCompliant (false)]
919 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
920 [CLSCompliant (false)]
921 public SeekFlags l_whence; // How to interpret l_start
922 [off_t] public long l_start; // Starting offset for lock
923 [off_t] public long l_len; // Number of bytes to lock
924 [pid_t] public int l_pid; // PID of process blocking our lock (F_GETLK only)
926 public override int GetHashCode ()
928 return l_type.GetHashCode () ^ l_whence.GetHashCode () ^
929 l_start.GetHashCode () ^ l_len.GetHashCode () ^
930 l_pid.GetHashCode ();
933 public override bool Equals (object obj)
935 if ((obj == null) || (obj.GetType () != GetType ()))
937 Flock value = (Flock) obj;
938 return l_type == value.l_type && l_whence == value.l_whence &&
939 l_start == value.l_start && l_len == value.l_len &&
940 l_pid == value.l_pid;
943 public bool Equals (Flock value)
945 return l_type == value.l_type && l_whence == value.l_whence &&
946 l_start == value.l_start && l_len == value.l_len &&
947 l_pid == value.l_pid;
950 public static bool operator== (Flock lhs, Flock rhs)
952 return lhs.Equals (rhs);
955 public static bool operator!= (Flock lhs, Flock rhs)
957 return !lhs.Equals (rhs);
961 [Map ("struct pollfd")]
963 : IEquatable <Pollfd>
966 [CLSCompliant (false)]
967 public PollEvents events;
968 [CLSCompliant (false)]
969 public PollEvents revents;
971 public override int GetHashCode ()
973 return events.GetHashCode () ^ revents.GetHashCode ();
976 public override bool Equals (object obj)
978 if (obj == null || obj.GetType () != GetType ())
980 Pollfd value = (Pollfd) obj;
981 return value.events == events && value.revents == revents;
984 public bool Equals (Pollfd value)
986 return value.events == events && value.revents == revents;
989 public static bool operator== (Pollfd lhs, Pollfd rhs)
991 return lhs.Equals (rhs);
994 public static bool operator!= (Pollfd lhs, Pollfd rhs)
996 return !lhs.Equals (rhs);
1000 // Use manually written To/From methods to handle fields st_atime_nsec etc.
1004 [CLSCompliant (false)]
1005 [dev_t] public ulong st_dev; // device
1006 [CLSCompliant (false)]
1007 [ino_t] public ulong st_ino; // inode
1008 [CLSCompliant (false)]
1009 public FilePermissions st_mode; // protection
1011 #pragma warning disable 169
1012 private uint _padding_; // padding for structure alignment
1013 #pragma warning restore 169
1014 [CLSCompliant (false)]
1015 [nlink_t] public ulong st_nlink; // number of hard links
1016 [CLSCompliant (false)]
1017 [uid_t] public uint st_uid; // user ID of owner
1018 [CLSCompliant (false)]
1019 [gid_t] public uint st_gid; // group ID of owner
1020 [CLSCompliant (false)]
1021 [dev_t] public ulong st_rdev; // device type (if inode device)
1022 [off_t] public long st_size; // total size, in bytes
1023 [blksize_t] public long st_blksize; // blocksize for filesystem I/O
1024 [blkcnt_t] public long st_blocks; // number of blocks allocated
1025 [time_t] public long st_atime; // time of last access
1026 [time_t] public long st_mtime; // time of last modification
1027 [time_t] public long st_ctime; // time of last status change
1028 public long st_atime_nsec; // Timespec.tv_nsec partner to st_atime
1029 public long st_mtime_nsec; // Timespec.tv_nsec partner to st_mtime
1030 public long st_ctime_nsec; // Timespec.tv_nsec partner to st_ctime
1032 public Timespec st_atim {
1034 return new Timespec { tv_sec = st_atime, tv_nsec = st_atime_nsec };
1037 st_atime = value.tv_sec;
1038 st_atime_nsec = value.tv_nsec;
1042 public Timespec st_mtim {
1044 return new Timespec { tv_sec = st_mtime, tv_nsec = st_mtime_nsec };
1047 st_mtime = value.tv_sec;
1048 st_mtime_nsec = value.tv_nsec;
1052 public Timespec st_ctim {
1054 return new Timespec { tv_sec = st_ctime, tv_nsec = st_ctime_nsec };
1057 st_ctime = value.tv_sec;
1058 st_ctime_nsec = value.tv_nsec;
1062 public override int GetHashCode ()
1064 return st_dev.GetHashCode () ^
1065 st_ino.GetHashCode () ^
1066 st_mode.GetHashCode () ^
1067 st_nlink.GetHashCode () ^
1068 st_uid.GetHashCode () ^
1069 st_gid.GetHashCode () ^
1070 st_rdev.GetHashCode () ^
1071 st_size.GetHashCode () ^
1072 st_blksize.GetHashCode () ^
1073 st_blocks.GetHashCode () ^
1074 st_atime.GetHashCode () ^
1075 st_mtime.GetHashCode () ^
1076 st_ctime.GetHashCode () ^
1077 st_atime_nsec.GetHashCode () ^
1078 st_mtime_nsec.GetHashCode () ^
1079 st_ctime_nsec.GetHashCode ();
1082 public override bool Equals (object obj)
1084 if (obj == null || obj.GetType() != GetType ())
1086 Stat value = (Stat) obj;
1087 return value.st_dev == st_dev &&
1088 value.st_ino == st_ino &&
1089 value.st_mode == st_mode &&
1090 value.st_nlink == st_nlink &&
1091 value.st_uid == st_uid &&
1092 value.st_gid == st_gid &&
1093 value.st_rdev == st_rdev &&
1094 value.st_size == st_size &&
1095 value.st_blksize == st_blksize &&
1096 value.st_blocks == st_blocks &&
1097 value.st_atime == st_atime &&
1098 value.st_mtime == st_mtime &&
1099 value.st_ctime == st_ctime &&
1100 value.st_atime_nsec == st_atime_nsec &&
1101 value.st_mtime_nsec == st_mtime_nsec &&
1102 value.st_ctime_nsec == st_ctime_nsec;
1105 public bool Equals (Stat value)
1107 return value.st_dev == st_dev &&
1108 value.st_ino == st_ino &&
1109 value.st_mode == st_mode &&
1110 value.st_nlink == st_nlink &&
1111 value.st_uid == st_uid &&
1112 value.st_gid == st_gid &&
1113 value.st_rdev == st_rdev &&
1114 value.st_size == st_size &&
1115 value.st_blksize == st_blksize &&
1116 value.st_blocks == st_blocks &&
1117 value.st_atime == st_atime &&
1118 value.st_mtime == st_mtime &&
1119 value.st_ctime == st_ctime &&
1120 value.st_atime_nsec == st_atime_nsec &&
1121 value.st_mtime_nsec == st_mtime_nsec &&
1122 value.st_ctime_nsec == st_ctime_nsec;
1125 public static bool operator== (Stat lhs, Stat rhs)
1127 return lhs.Equals (rhs);
1130 public static bool operator!= (Stat lhs, Stat rhs)
1132 return !lhs.Equals (rhs);
1136 // `struct statvfs' isn't portable, so don't generate To/From methods.
1138 [CLSCompliant (false)]
1139 public struct Statvfs
1140 : IEquatable <Statvfs>
1142 public ulong f_bsize; // file system block size
1143 public ulong f_frsize; // fragment size
1144 [fsblkcnt_t] public ulong f_blocks; // size of fs in f_frsize units
1145 [fsblkcnt_t] public ulong f_bfree; // # free blocks
1146 [fsblkcnt_t] public ulong f_bavail; // # free blocks for non-root
1147 [fsfilcnt_t] public ulong f_files; // # inodes
1148 [fsfilcnt_t] public ulong f_ffree; // # free inodes
1149 [fsfilcnt_t] public ulong f_favail; // # free inodes for non-root
1150 public ulong f_fsid; // file system id
1151 public MountFlags f_flag; // mount flags
1152 public ulong f_namemax; // maximum filename length
1154 public override int GetHashCode ()
1156 return f_bsize.GetHashCode () ^
1157 f_frsize.GetHashCode () ^
1158 f_blocks.GetHashCode () ^
1159 f_bfree.GetHashCode () ^
1160 f_bavail.GetHashCode () ^
1161 f_files.GetHashCode () ^
1162 f_ffree.GetHashCode () ^
1163 f_favail.GetHashCode () ^
1164 f_fsid.GetHashCode () ^
1165 f_flag.GetHashCode () ^
1166 f_namemax.GetHashCode ();
1169 public override bool Equals (object obj)
1171 if (obj == null || obj.GetType() != GetType ())
1173 Statvfs value = (Statvfs) obj;
1174 return value.f_bsize == f_bsize &&
1175 value.f_frsize == f_frsize &&
1176 value.f_blocks == f_blocks &&
1177 value.f_bfree == f_bfree &&
1178 value.f_bavail == f_bavail &&
1179 value.f_files == f_files &&
1180 value.f_ffree == f_ffree &&
1181 value.f_favail == f_favail &&
1182 value.f_fsid == f_fsid &&
1183 value.f_flag == f_flag &&
1184 value.f_namemax == f_namemax;
1187 public bool Equals (Statvfs value)
1189 return value.f_bsize == f_bsize &&
1190 value.f_frsize == f_frsize &&
1191 value.f_blocks == f_blocks &&
1192 value.f_bfree == f_bfree &&
1193 value.f_bavail == f_bavail &&
1194 value.f_files == f_files &&
1195 value.f_ffree == f_ffree &&
1196 value.f_favail == f_favail &&
1197 value.f_fsid == f_fsid &&
1198 value.f_flag == f_flag &&
1199 value.f_namemax == f_namemax;
1202 public static bool operator== (Statvfs lhs, Statvfs rhs)
1204 return lhs.Equals (rhs);
1207 public static bool operator!= (Statvfs lhs, Statvfs rhs)
1209 return !lhs.Equals (rhs);
1213 [Map ("struct timeval")]
1214 public struct Timeval
1215 : IEquatable <Timeval>
1217 [time_t] public long tv_sec; // seconds
1218 [suseconds_t] public long tv_usec; // microseconds
1220 public override int GetHashCode ()
1222 return tv_sec.GetHashCode () ^ tv_usec.GetHashCode ();
1225 public override bool Equals (object obj)
1227 if (obj == null || obj.GetType () != GetType ())
1229 Timeval value = (Timeval) obj;
1230 return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
1233 public bool Equals (Timeval value)
1235 return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
1238 public static bool operator== (Timeval lhs, Timeval rhs)
1240 return lhs.Equals (rhs);
1243 public static bool operator!= (Timeval lhs, Timeval rhs)
1245 return !lhs.Equals (rhs);
1249 [Map ("struct timezone")]
1250 public struct Timezone
1251 : IEquatable <Timezone>
1253 public int tz_minuteswest; // minutes W of Greenwich
1254 #pragma warning disable 169
1255 private int tz_dsttime; // type of dst correction (OBSOLETE)
1256 #pragma warning restore 169
1258 public override int GetHashCode ()
1260 return tz_minuteswest.GetHashCode ();
1263 public override bool Equals (object obj)
1265 if (obj == null || obj.GetType () != GetType ())
1267 Timezone value = (Timezone) obj;
1268 return value.tz_minuteswest == tz_minuteswest;
1271 public bool Equals (Timezone value)
1273 return value.tz_minuteswest == tz_minuteswest;
1276 public static bool operator== (Timezone lhs, Timezone rhs)
1278 return lhs.Equals (rhs);
1281 public static bool operator!= (Timezone lhs, Timezone rhs)
1283 return !lhs.Equals (rhs);
1287 [Map ("struct utimbuf")]
1288 public struct Utimbuf
1289 : IEquatable <Utimbuf>
1291 [time_t] public long actime; // access time
1292 [time_t] public long modtime; // modification time
1294 public override int GetHashCode ()
1296 return actime.GetHashCode () ^ modtime.GetHashCode ();
1299 public override bool Equals (object obj)
1301 if (obj == null || obj.GetType () != GetType ())
1303 Utimbuf value = (Utimbuf) obj;
1304 return value.actime == actime && value.modtime == modtime;
1307 public bool Equals (Utimbuf value)
1309 return value.actime == actime && value.modtime == modtime;
1312 public static bool operator== (Utimbuf lhs, Utimbuf rhs)
1314 return lhs.Equals (rhs);
1317 public static bool operator!= (Utimbuf lhs, Utimbuf rhs)
1319 return !lhs.Equals (rhs);
1323 [Map ("struct timespec")]
1324 public struct Timespec
1325 : IEquatable <Timespec>
1327 [time_t] public long tv_sec; // Seconds.
1328 public long tv_nsec; // Nanoseconds.
1330 public override int GetHashCode ()
1332 return tv_sec.GetHashCode () ^ tv_nsec.GetHashCode ();
1335 public override bool Equals (object obj)
1337 if (obj == null || obj.GetType () != GetType ())
1339 Timespec value = (Timespec) obj;
1340 return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
1343 public bool Equals (Timespec value)
1345 return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
1348 public static bool operator== (Timespec lhs, Timespec rhs)
1350 return lhs.Equals (rhs);
1353 public static bool operator!= (Timespec lhs, Timespec rhs)
1355 return !lhs.Equals (rhs);
1359 [Map ("struct iovec")]
1362 public IntPtr iov_base; // Starting address
1363 [CLSCompliant (false)]
1364 public ulong iov_len; // Number of bytes to transfer
1368 public enum EpollFlags {
1369 EPOLL_CLOEXEC = 02000000,
1370 EPOLL_NONBLOCK = 04000,
1374 [CLSCompliant (false)]
1375 public enum EpollEvents : uint {
1379 EPOLLRDNORM = 0x040,
1380 EPOLLRDBAND = 0x080,
1381 EPOLLWRNORM = 0x100,
1382 EPOLLWRBAND = 0x200,
1386 EPOLLRDHUP = 0x2000,
1387 EPOLLONESHOT = 1 << 30,
1388 EPOLLET = unchecked ((uint) (1 << 31))
1391 public enum EpollOp {
1397 [StructLayout (LayoutKind.Explicit, Size=12, Pack=1)]
1398 [CLSCompliant (false)]
1399 public struct EpollEvent {
1401 public EpollEvents events;
1412 [Map ("struct linger")]
1413 [CLSCompliant (false)]
1414 public struct Linger {
1416 public int l_linger;
1418 public override string ToString ()
1420 return string.Format ("{0}, {1}", l_onoff, l_linger);
1428 public sealed class Dirent
1429 : IEquatable <Dirent>
1431 [CLSCompliant (false)]
1432 public /* ino_t */ ulong d_ino;
1433 public /* off_t */ long d_off;
1434 [CLSCompliant (false)]
1435 public ushort d_reclen;
1437 public string d_name;
1439 public override int GetHashCode ()
1441 return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
1442 d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
1443 d_name.GetHashCode ();
1446 public override bool Equals (object obj)
1448 if (obj == null || GetType() != obj.GetType())
1450 Dirent d = (Dirent) obj;
1454 public bool Equals (Dirent value)
1458 return value.d_ino == d_ino && value.d_off == d_off &&
1459 value.d_reclen == d_reclen && value.d_type == d_type &&
1460 value.d_name == d_name;
1463 public override string ToString ()
1468 public static bool operator== (Dirent lhs, Dirent rhs)
1470 return Object.Equals (lhs, rhs);
1473 public static bool operator!= (Dirent lhs, Dirent rhs)
1475 return !Object.Equals (lhs, rhs);
1479 public sealed class Fstab
1480 : IEquatable <Fstab>
1482 public string fs_spec;
1483 public string fs_file;
1484 public string fs_vfstype;
1485 public string fs_mntops;
1486 public string fs_type;
1488 public int fs_passno;
1490 public override int GetHashCode ()
1492 return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
1493 fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
1494 fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
1497 public override bool Equals (object obj)
1499 if (obj == null || GetType() != obj.GetType())
1501 Fstab f = (Fstab) obj;
1505 public bool Equals (Fstab value)
1509 return value.fs_spec == fs_spec && value.fs_file == fs_file &&
1510 value.fs_vfstype == fs_vfstype && value.fs_mntops == fs_mntops &&
1511 value.fs_type == fs_type && value.fs_freq == fs_freq &&
1512 value.fs_passno == fs_passno;
1515 public override string ToString ()
1520 public static bool operator== (Fstab lhs, Fstab rhs)
1522 return Object.Equals (lhs, rhs);
1525 public static bool operator!= (Fstab lhs, Fstab rhs)
1527 return !Object.Equals (lhs, rhs);
1531 public sealed class Group
1532 : IEquatable <Group>
1534 public string gr_name;
1535 public string gr_passwd;
1536 [CLSCompliant (false)]
1537 public /* gid_t */ uint gr_gid;
1538 public string[] gr_mem;
1540 public override int GetHashCode ()
1543 for (int i = 0; i < gr_mem.Length; ++i)
1544 memhc ^= gr_mem[i].GetHashCode ();
1546 return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
1547 gr_gid.GetHashCode () ^ memhc;
1550 public override bool Equals (object obj)
1552 if (obj == null || GetType() != obj.GetType())
1554 Group g = (Group) obj;
1558 public bool Equals (Group value)
1562 if (value.gr_gid != gr_gid)
1564 if (value.gr_gid == gr_gid && value.gr_name == gr_name &&
1565 value.gr_passwd == gr_passwd) {
1566 if (value.gr_mem == gr_mem)
1568 if (value.gr_mem == null || gr_mem == null)
1570 if (value.gr_mem.Length != gr_mem.Length)
1572 for (int i = 0; i < gr_mem.Length; ++i)
1573 if (gr_mem[i] != value.gr_mem[i])
1580 // Generate string in /etc/group format
1581 public override string ToString ()
1583 StringBuilder sb = new StringBuilder ();
1584 sb.Append (gr_name).Append (":").Append (gr_passwd).Append (":");
1585 sb.Append (gr_gid).Append (":");
1586 GetMembers (sb, gr_mem);
1587 return sb.ToString ();
1590 private static void GetMembers (StringBuilder sb, string[] members)
1592 if (members.Length > 0)
1593 sb.Append (members[0]);
1594 for (int i = 1; i < members.Length; ++i) {
1596 sb.Append (members[i]);
1600 public static bool operator== (Group lhs, Group rhs)
1602 return Object.Equals (lhs, rhs);
1605 public static bool operator!= (Group lhs, Group rhs)
1607 return !Object.Equals (lhs, rhs);
1611 public sealed class Passwd
1612 : IEquatable <Passwd>
1614 public string pw_name;
1615 public string pw_passwd;
1616 [CLSCompliant (false)]
1617 public /* uid_t */ uint pw_uid;
1618 [CLSCompliant (false)]
1619 public /* gid_t */ uint pw_gid;
1620 public string pw_gecos;
1621 public string pw_dir;
1622 public string pw_shell;
1624 public override int GetHashCode ()
1626 return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
1627 pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
1628 pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
1629 pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
1632 public override bool Equals (object obj)
1634 if (obj == null || GetType() != obj.GetType())
1636 Passwd p = (Passwd) obj;
1640 public bool Equals (Passwd value)
1644 return value.pw_uid == pw_uid && value.pw_gid == pw_gid &&
1645 value.pw_name == pw_name && value.pw_passwd == pw_passwd &&
1646 value.pw_gecos == pw_gecos && value.pw_dir == pw_dir &&
1647 value.pw_shell == pw_shell;
1650 // Generate string in /etc/passwd format
1651 public override string ToString ()
1653 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
1654 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
1657 public static bool operator== (Passwd lhs, Passwd rhs)
1659 return Object.Equals (lhs, rhs);
1662 public static bool operator!= (Passwd lhs, Passwd rhs)
1664 return !Object.Equals (lhs, rhs);
1668 public sealed class Utsname
1669 : IEquatable <Utsname>
1671 public string sysname;
1672 public string nodename;
1673 public string release;
1674 public string version;
1675 public string machine;
1676 public string domainname;
1678 public override int GetHashCode ()
1680 return sysname.GetHashCode () ^ nodename.GetHashCode () ^
1681 release.GetHashCode () ^ version.GetHashCode () ^
1682 machine.GetHashCode () ^ domainname.GetHashCode ();
1685 public override bool Equals (object obj)
1687 if (obj == null || GetType() != obj.GetType())
1689 Utsname u = (Utsname) obj;
1693 public bool Equals (Utsname value)
1695 return value.sysname == sysname && value.nodename == nodename &&
1696 value.release == release && value.version == version &&
1697 value.machine == machine && value.domainname == domainname;
1700 // Generate string in /etc/passwd format
1701 public override string ToString ()
1703 return string.Format ("{0} {1} {2} {3} {4}",
1704 sysname, nodename, release, version, machine);
1707 public static bool operator== (Utsname lhs, Utsname rhs)
1709 return Object.Equals (lhs, rhs);
1712 public static bool operator!= (Utsname lhs, Utsname rhs)
1714 return !Object.Equals (lhs, rhs);
1719 // Convention: Functions *not* part of the standard C library AND part of
1720 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
1722 // For example, the man page should be similar to:
1724 // CONFORMING TO (or CONFORMS TO)
1725 // XPG2, SUSv2, POSIX, etc.
1727 // BSD- and GNU-specific exports can also be placed here.
1729 // Non-POSIX/XPG/etc. functions can also be placed here if:
1730 // (a) They'd be likely to be covered in a Steven's-like book
1731 // (b) The functions would be present in libc.so (or equivalent).
1733 // If a function has its own library, that's a STRONG indicator that the
1734 // function should get a different binding, probably in its own assembly,
1735 // so that package management can work sanely. (That is, we'd like to avoid
1736 // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
1737 // run, and libFooLib.so doesn't exist. That would be confusing.)
1739 // The only methods in here should be:
1740 // (1) low-level functions
1741 // (2) "Trivial" function overloads. For example, if the parameters to a
1742 // function are related (e.g. getgroups(2))
1743 // (3) The return type SHOULD NOT be changed. If you want to provide a
1744 // convenience function with a nicer return type, place it into one of
1745 // the Mono.Unix.Unix* wrapper classes, and give it a .NET-styled name.
1746 // - EXCEPTION: No public functions should have a `void' return type.
1747 // `void' return types should be replaced with `int'.
1748 // Rationality: `void'-return functions typically require a
1749 // complicated call sequence, such as clear errno, then call, then
1750 // check errno to see if any errors occurred. This sequence can't
1751 // be done safely in managed code, as errno may change as part of
1752 // the P/Invoke mechanism.
1753 // Instead, add a MonoPosixHelper export which does:
1756 // return errno == 0 ? 0 : -1;
1757 // This lets managed code check the return value in the usual manner.
1758 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
1759 // - If you're wrapping *broken* methods which make assumptions about
1760 // input data, such as that an argument refers to N bytes of data.
1761 // This is currently limited to cuserid(3) and encrypt(3).
1762 // - If you call functions which themselves generate exceptions.
1763 // This is the case for using NativeConvert, which will throw an
1764 // exception if an invalid/unsupported value is used.
1766 // Naming Conventions:
1767 // - Syscall method names should have the same name as the function being
1768 // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
1769 // consult the appropriate man page if necessary.
1770 // - Methods need not have the same arguments IF this simplifies or
1771 // permits correct usage. The current example is syslog, in which
1772 // syslog(3)'s single `priority' argument is split into SyslogFacility
1773 // and SyslogLevel arguments.
1774 // - Type names (structures, classes, enumerations) are always PascalCased.
1775 // - Enumerations are named as <MethodName><ArgumentName>, and are located
1776 // in the Mono.Unix.Native namespace. For readability, if ArgumentName
1777 // is "cmd", use Command instead. For example, fcntl(2) takes a
1778 // FcntlCommand argument. This naming convention is to provide an
1779 // assocation between an enumeration and where it should be used, and
1780 // allows a single method to accept multiple different enumerations
1781 // (see mmap(2), which takes MmapProts and MmapFlags).
1782 // - EXCEPTION: if an enumeration is shared between multiple different
1783 // methods, AND/OR the "obvious" enumeration name conflicts with an
1784 // existing .NET type, a more appropriate name should be used.
1785 // Example: FilePermissions
1786 // - EXCEPTION: [Flags] enumerations should get plural names to follow
1787 // .NET name guidelines. Usually this doesn't result in a change
1788 // (OpenFlags is the `flags' parameter for open(2)), but it can
1789 // (mmap(2) prot ==> MmapProts, access(2) mode ==> AccessModes).
1790 // - Enumerations should have the [Map] and (optional) [Flags] attributes.
1791 // [Map] is required for make-map to find the type and generate the
1792 // appropriate NativeConvert conversion functions.
1793 // - Enumeration contents should match the original Unix names. This helps
1794 // with documentation (the existing man pages are still useful), and is
1795 // required for use with the make-map generation program.
1796 // - Structure names should be the PascalCased version of the actual
1797 // structure name (struct flock ==> Flock). Structure members should
1798 // have the same names, or a (reasonably) portable subset (Dirent being
1799 // the poster child for questionable members).
1800 // - Whether the managed type should be a reference type (class) or a
1801 // value type (struct) should be determined on a case-by-case basis:
1802 // if you ever need to be able to use NULL for it (such as with Dirent,
1803 // Group, Passwd, as these are method return types and `null' is used
1804 // to signify the end), it should be a reference type; otherwise, use
1805 // your discretion, and keep any expected usage patterns in mind.
1806 // - Syscall should be a Single Point Of Truth (SPOT). There should be
1807 // only ONE way to do anything. By convention, the Linux function names
1808 // are used, but that need not always be the case (use your discretion).
1809 // It SHOULD NOT be required that developers know what platform they're
1810 // on, and choose among a set of similar functions. In short, anything
1811 // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
1812 // we can afford to clean things up whenever possible.
1814 // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
1815 // statvfs(2). MonoPosixHelper will "thunk" between the two,
1816 // exporting a statvfs that works across platforms.
1817 // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
1818 // instead provides getvfsent(3). MonoPosixHelper provides wrappers
1819 // to convert getvfsent(3) into Fstab data.
1820 // - Exception: If it isn't possible to cleanly wrap platforms, then the
1821 // method shouldn't be exported. The user will be expected to do their
1822 // own platform check and their own DllImports.
1823 // Examples: mount(2), umount(2), etc.
1824 // - Note: if a platform doesn't support a function AT ALL, the
1825 // MonoPosixHelper wrapper won't be compiled, resulting in a
1826 // EntryPointNotFoundException. This is also consistent with a missing
1827 // P/Invoke into libc.so.
1829 [CLSCompliant (false)]
1830 public sealed class Syscall : Stdlib
1832 new internal const string LIBC = "libc";
1834 private Syscall () {}
1840 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
1841 // aio_return(3), aio_suspend(3), aio_write(3)
1843 // Then update UnixStream.BeginRead to use the aio* functions.
1846 #region <attr/xattr.h> Declarations
1848 // <attr/xattr.h> -- COMPLETE
1852 // int setxattr (const char *path, const char *name,
1853 // const void *value, size_t size, int flags);
1854 [DllImport (MPH, SetLastError=true,
1855 EntryPoint="Mono_Posix_Syscall_setxattr")]
1856 public static extern int setxattr (
1857 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1859 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1860 string name, byte[] value, ulong size, XattrFlags flags);
1862 public static int setxattr (string path, string name, byte [] value, ulong size)
1864 return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1867 public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
1869 return setxattr (path, name, value, (ulong) value.Length, flags);
1872 public static int setxattr (string path, string name, byte [] value)
1874 return setxattr (path, name, value, (ulong) value.Length);
1878 // int lsetxattr (const char *path, const char *name,
1879 // const void *value, size_t size, int flags);
1880 [DllImport (MPH, SetLastError=true,
1881 EntryPoint="Mono_Posix_Syscall_lsetxattr")]
1882 public static extern int lsetxattr (
1883 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1885 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1886 string name, byte[] value, ulong size, XattrFlags flags);
1888 public static int lsetxattr (string path, string name, byte [] value, ulong size)
1890 return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1893 public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
1895 return lsetxattr (path, name, value, (ulong) value.Length, flags);
1898 public static int lsetxattr (string path, string name, byte [] value)
1900 return lsetxattr (path, name, value, (ulong) value.Length);
1904 // int fsetxattr (int fd, const char *name,
1905 // const void *value, size_t size, int flags);
1906 [DllImport (MPH, SetLastError=true,
1907 EntryPoint="Mono_Posix_Syscall_fsetxattr")]
1908 public static extern int fsetxattr (int fd,
1909 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1910 string name, byte[] value, ulong size, XattrFlags flags);
1912 public static int fsetxattr (int fd, string name, byte [] value, ulong size)
1914 return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
1917 public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
1919 return fsetxattr (fd, name, value, (ulong) value.Length, flags);
1922 public static int fsetxattr (int fd, string name, byte [] value)
1924 return fsetxattr (fd, name, value, (ulong) value.Length);
1928 // ssize_t getxattr (const char *path, const char *name,
1929 // void *value, size_t size);
1930 [DllImport (MPH, SetLastError=true,
1931 EntryPoint="Mono_Posix_Syscall_getxattr")]
1932 public static extern long getxattr (
1933 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1935 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1936 string name, byte[] value, ulong size);
1938 public static long getxattr (string path, string name, byte [] value)
1940 return getxattr (path, name, value, (ulong) value.Length);
1943 public static long getxattr (string path, string name, out byte [] value)
1946 long size = getxattr (path, name, value, 0);
1950 value = new byte [size];
1951 return getxattr (path, name, value, (ulong) size);
1955 // ssize_t lgetxattr (const char *path, const char *name,
1956 // void *value, size_t size);
1957 [DllImport (MPH, SetLastError=true,
1958 EntryPoint="Mono_Posix_Syscall_lgetxattr")]
1959 public static extern long lgetxattr (
1960 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1962 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1963 string name, byte[] value, ulong size);
1965 public static long lgetxattr (string path, string name, byte [] value)
1967 return lgetxattr (path, name, value, (ulong) value.Length);
1970 public static long lgetxattr (string path, string name, out byte [] value)
1973 long size = lgetxattr (path, name, value, 0);
1977 value = new byte [size];
1978 return lgetxattr (path, name, value, (ulong) size);
1982 // ssize_t fgetxattr (int fd, const char *name, void *value, size_t size);
1983 [DllImport (MPH, SetLastError=true,
1984 EntryPoint="Mono_Posix_Syscall_fgetxattr")]
1985 public static extern long fgetxattr (int fd,
1986 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1987 string name, byte[] value, ulong size);
1989 public static long fgetxattr (int fd, string name, byte [] value)
1991 return fgetxattr (fd, name, value, (ulong) value.Length);
1994 public static long fgetxattr (int fd, string name, out byte [] value)
1997 long size = fgetxattr (fd, name, value, 0);
2001 value = new byte [size];
2002 return fgetxattr (fd, name, value, (ulong) size);
2006 // ssize_t listxattr (const char *path, char *list, size_t size);
2007 [DllImport (MPH, SetLastError=true,
2008 EntryPoint="Mono_Posix_Syscall_listxattr")]
2009 public static extern long listxattr (
2010 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2011 string path, byte[] list, ulong size);
2013 // Slight modification: returns 0 on success, negative on error
2014 public static long listxattr (string path, Encoding encoding, out string [] values)
2017 long size = listxattr (path, null, 0);
2019 values = new string [0];
2023 byte[] list = new byte [size];
2024 long ret = listxattr (path, list, (ulong) size);
2028 GetValues (list, encoding, out values);
2032 public static long listxattr (string path, out string[] values)
2034 return listxattr (path, UnixEncoding.Instance, out values);
2037 private static void GetValues (byte[] list, Encoding encoding, out string[] values)
2040 for (int i = 0; i < list.Length; ++i)
2044 values = new string [num_values];
2047 for (int i = 0; i < list.Length; ++i) {
2048 if (list [i] == 0) {
2049 values [num_values++] = encoding.GetString (list, str_start, i - str_start);
2056 // ssize_t llistxattr (const char *path, char *list, size_t size);
2057 [DllImport (MPH, SetLastError=true,
2058 EntryPoint="Mono_Posix_Syscall_llistxattr")]
2059 public static extern long llistxattr (
2060 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2061 string path, byte[] list, ulong size);
2063 // Slight modification: returns 0 on success, negative on error
2064 public static long llistxattr (string path, Encoding encoding, out string [] values)
2067 long size = llistxattr (path, null, 0);
2069 values = new string [0];
2073 byte[] list = new byte [size];
2074 long ret = llistxattr (path, list, (ulong) size);
2078 GetValues (list, encoding, out values);
2082 public static long llistxattr (string path, out string[] values)
2084 return llistxattr (path, UnixEncoding.Instance, out values);
2088 // ssize_t flistxattr (int fd, char *list, size_t size);
2089 [DllImport (MPH, SetLastError=true,
2090 EntryPoint="Mono_Posix_Syscall_flistxattr")]
2091 public static extern long flistxattr (int fd, byte[] list, ulong size);
2093 // Slight modification: returns 0 on success, negative on error
2094 public static long flistxattr (int fd, Encoding encoding, out string [] values)
2097 long size = flistxattr (fd, null, 0);
2099 values = new string [0];
2103 byte[] list = new byte [size];
2104 long ret = flistxattr (fd, list, (ulong) size);
2108 GetValues (list, encoding, out values);
2112 public static long flistxattr (int fd, out string[] values)
2114 return flistxattr (fd, UnixEncoding.Instance, out values);
2117 [DllImport (MPH, SetLastError=true,
2118 EntryPoint="Mono_Posix_Syscall_removexattr")]
2119 public static extern int removexattr (
2120 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2122 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2125 [DllImport (MPH, SetLastError=true,
2126 EntryPoint="Mono_Posix_Syscall_lremovexattr")]
2127 public static extern int lremovexattr (
2128 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2130 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2133 [DllImport (MPH, SetLastError=true,
2134 EntryPoint="Mono_Posix_Syscall_fremovexattr")]
2135 public static extern int fremovexattr (int fd,
2136 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2140 #region <dirent.h> Declarations
2144 // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
2146 [DllImport (LIBC, SetLastError=true)]
2147 public static extern IntPtr opendir (
2148 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2151 [DllImport (LIBC, SetLastError=true)]
2152 public static extern int closedir (IntPtr dir);
2155 // void seekdir (DIR *dir, off_t offset);
2156 // Slight modification. Returns -1 on error, 0 on success.
2157 [DllImport (MPH, SetLastError=true,
2158 EntryPoint="Mono_Posix_Syscall_seekdir")]
2159 public static extern int seekdir (IntPtr dir, long offset);
2162 // off_t telldir(DIR *dir);
2163 [DllImport (MPH, SetLastError=true,
2164 EntryPoint="Mono_Posix_Syscall_telldir")]
2165 public static extern long telldir (IntPtr dir);
2167 [DllImport (MPH, SetLastError=true,
2168 EntryPoint="Mono_Posix_Syscall_rewinddir")]
2169 public static extern int rewinddir (IntPtr dir);
2171 private struct _Dirent {
2172 [ino_t] public ulong d_ino;
2173 [off_t] public long d_off;
2174 public ushort d_reclen;
2176 public IntPtr d_name;
2179 private static void CopyDirent (Dirent to, ref _Dirent from)
2182 to.d_ino = from.d_ino;
2183 to.d_off = from.d_off;
2184 to.d_reclen = from.d_reclen;
2185 to.d_type = from.d_type;
2186 to.d_name = UnixMarshal.PtrToString (from.d_name);
2189 Stdlib.free (from.d_name);
2190 from.d_name = IntPtr.Zero;
2194 internal static object readdir_lock = new object ();
2196 [DllImport (MPH, SetLastError=true,
2197 EntryPoint="Mono_Posix_Syscall_readdir")]
2198 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
2200 public static Dirent readdir (IntPtr dir)
2204 lock (readdir_lock) {
2205 r = sys_readdir (dir, out dentry);
2209 Dirent d = new Dirent ();
2210 CopyDirent (d, ref dentry);
2214 [DllImport (MPH, SetLastError=true,
2215 EntryPoint="Mono_Posix_Syscall_readdir_r")]
2216 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
2218 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
2224 entry.d_name = null;
2227 int r = sys_readdir_r (dirp, out _d, out result);
2229 if (r == 0 && result != IntPtr.Zero) {
2230 CopyDirent (entry, ref _d);
2236 [DllImport (LIBC, SetLastError=true)]
2237 public static extern int dirfd (IntPtr dir);
2239 [DllImport (LIBC, SetLastError=true)]
2240 public static extern IntPtr fdopendir (int fd);
2243 #region <fcntl.h> Declarations
2245 // <fcntl.h> -- COMPLETE
2248 [DllImport (MPH, SetLastError=true,
2249 EntryPoint="Mono_Posix_Syscall_fcntl")]
2250 public static extern int fcntl (int fd, FcntlCommand cmd);
2252 [DllImport (MPH, SetLastError=true,
2253 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
2254 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
2256 [DllImport (MPH, SetLastError=true,
2257 EntryPoint="Mono_Posix_Syscall_fcntl_arg_int")]
2258 public static extern int fcntl (int fd, FcntlCommand cmd, int arg);
2260 [DllImport (MPH, SetLastError=true,
2261 EntryPoint="Mono_Posix_Syscall_fcntl_arg_ptr")]
2262 public static extern int fcntl (int fd, FcntlCommand cmd, IntPtr ptr);
2264 public static int fcntl (int fd, FcntlCommand cmd, DirectoryNotifyFlags arg)
2266 if (cmd != FcntlCommand.F_NOTIFY) {
2267 SetLastError (Errno.EINVAL);
2270 long _arg = NativeConvert.FromDirectoryNotifyFlags (arg);
2271 return fcntl (fd, FcntlCommand.F_NOTIFY, _arg);
2274 [DllImport (MPH, SetLastError=true,
2275 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
2276 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
2278 [DllImport (MPH, SetLastError=true,
2279 EntryPoint="Mono_Posix_Syscall_open")]
2280 public static extern int open (
2281 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2282 string pathname, OpenFlags flags);
2285 // int open(const char *pathname, int flags, mode_t mode);
2286 [DllImport (MPH, SetLastError=true,
2287 EntryPoint="Mono_Posix_Syscall_open_mode")]
2288 public static extern int open (
2289 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2290 string pathname, OpenFlags flags, FilePermissions mode);
2293 // int creat(const char *pathname, mode_t mode);
2294 [DllImport (MPH, SetLastError=true,
2295 EntryPoint="Mono_Posix_Syscall_creat")]
2296 public static extern int creat (
2297 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2298 string pathname, FilePermissions mode);
2301 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
2302 [DllImport (MPH, SetLastError=true,
2303 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
2304 public static extern int posix_fadvise (int fd, long offset,
2305 long len, PosixFadviseAdvice advice);
2307 // posix_fallocate(P)
2308 // int posix_fallocate(int fd, off_t offset, size_t len);
2309 [DllImport (MPH, SetLastError=true,
2310 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
2311 public static extern int posix_fallocate (int fd, long offset, ulong len);
2313 [DllImport (LIBC, SetLastError=true,
2314 EntryPoint="openat")]
2315 private static extern int sys_openat (int dirfd,
2316 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2317 string pathname, int flags);
2320 // int openat(int dirfd, const char *pathname, int flags, mode_t mode);
2321 [DllImport (LIBC, SetLastError=true,
2322 EntryPoint="openat")]
2323 private static extern int sys_openat (int dirfd,
2324 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2325 string pathname, int flags, uint mode);
2327 public static int openat (int dirfd, string pathname, OpenFlags flags)
2329 int _flags = NativeConvert.FromOpenFlags (flags);
2330 return sys_openat (dirfd, pathname, _flags);
2333 public static int openat (int dirfd, string pathname, OpenFlags flags, FilePermissions mode)
2335 int _flags = NativeConvert.FromOpenFlags (flags);
2336 uint _mode = NativeConvert.FromFilePermissions (mode);
2337 return sys_openat (dirfd, pathname, _flags, _mode);
2340 [DllImport (MPH, SetLastError=true,
2341 EntryPoint="Mono_Posix_Syscall_get_at_fdcwd")]
2342 private static extern int get_at_fdcwd ();
2344 public static readonly int AT_FDCWD = get_at_fdcwd ();
2348 #region <fstab.h> Declarations
2350 // <fstab.h> -- COMPLETE
2353 private struct _Fstab {
2354 public IntPtr fs_spec;
2355 public IntPtr fs_file;
2356 public IntPtr fs_vfstype;
2357 public IntPtr fs_mntops;
2358 public IntPtr fs_type;
2360 public int fs_passno;
2361 public IntPtr _fs_buf_;
2364 private static void CopyFstab (Fstab to, ref _Fstab from)
2367 to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
2368 to.fs_file = UnixMarshal.PtrToString (from.fs_file);
2369 to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
2370 to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
2371 to.fs_type = UnixMarshal.PtrToString (from.fs_type);
2372 to.fs_freq = from.fs_freq;
2373 to.fs_passno = from.fs_passno;
2376 Stdlib.free (from._fs_buf_);
2377 from._fs_buf_ = IntPtr.Zero;
2381 internal static object fstab_lock = new object ();
2383 [DllImport (MPH, SetLastError=true,
2384 EntryPoint="Mono_Posix_Syscall_endfsent")]
2385 private static extern int sys_endfsent ();
2387 public static int endfsent ()
2390 return sys_endfsent ();
2394 [DllImport (MPH, SetLastError=true,
2395 EntryPoint="Mono_Posix_Syscall_getfsent")]
2396 private static extern int sys_getfsent (out _Fstab fs);
2398 public static Fstab getfsent ()
2403 r = sys_getfsent (out fsbuf);
2407 Fstab fs = new Fstab ();
2408 CopyFstab (fs, ref fsbuf);
2412 [DllImport (MPH, SetLastError=true,
2413 EntryPoint="Mono_Posix_Syscall_getfsfile")]
2414 private static extern int sys_getfsfile (
2415 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2416 string mount_point, out _Fstab fs);
2418 public static Fstab getfsfile (string mount_point)
2423 r = sys_getfsfile (mount_point, out fsbuf);
2427 Fstab fs = new Fstab ();
2428 CopyFstab (fs, ref fsbuf);
2432 [DllImport (MPH, SetLastError=true,
2433 EntryPoint="Mono_Posix_Syscall_getfsspec")]
2434 private static extern int sys_getfsspec (
2435 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2436 string special_file, out _Fstab fs);
2438 public static Fstab getfsspec (string special_file)
2443 r = sys_getfsspec (special_file, out fsbuf);
2447 Fstab fs = new Fstab ();
2448 CopyFstab (fs, ref fsbuf);
2452 [DllImport (MPH, SetLastError=true,
2453 EntryPoint="Mono_Posix_Syscall_setfsent")]
2454 private static extern int sys_setfsent ();
2456 public static int setfsent ()
2459 return sys_setfsent ();
2465 #region <grp.h> Declarations
2469 // TODO: putgrent(3), fgetgrent_r(), initgroups(3)
2472 [DllImport (LIBC, SetLastError=true, EntryPoint="getgrouplist")]
2473 private static extern int sys_getgrouplist (string user, uint grp, uint [] groups,ref int ngroups);
2475 public static Group [] getgrouplist (string username)
2477 if (username == null)
2478 throw new ArgumentNullException ("username");
2479 if (username.Trim () == "")
2480 throw new ArgumentException ("Username cannot be empty", "username");
2481 // Syscall to getpwnam to retrieve user uid
2482 Passwd pw = Syscall.getpwnam (username);
2484 throw new ArgumentException (string.Format ("User {0} does not exist", username), "username");
2485 return getgrouplist (pw);
2488 public static Group [] getgrouplist (Passwd user)
2491 throw new ArgumentNullException ("user");
2492 // initializing ngroups by 16 to get the group count
2495 // allocating buffer to store group uid's
2496 uint [] groups=null;
2498 Array.Resize (ref groups, ngroups*=2);
2499 res = sys_getgrouplist (user.pw_name, user.pw_gid, groups, ref ngroups);
2502 List<Group> result = new List<Group> ();
2504 for (int i = 0; i < res; i++) {
2505 gr = Syscall.getgrgid (groups [i]);
2509 return result.ToArray ();
2513 // int setgroups (size_t size, const gid_t *list);
2514 [DllImport (MPH, SetLastError=true,
2515 EntryPoint="Mono_Posix_Syscall_setgroups")]
2516 public static extern int setgroups (ulong size, uint[] list);
2518 public static int setgroups (uint [] list)
2520 return setgroups ((ulong) list.Length, list);
2524 private struct _Group
2526 public IntPtr gr_name;
2527 public IntPtr gr_passwd;
2528 [gid_t] public uint gr_gid;
2529 public int _gr_nmem_;
2530 public IntPtr gr_mem;
2531 public IntPtr _gr_buf_;
2534 private static void CopyGroup (Group to, ref _Group from)
2537 to.gr_gid = from.gr_gid;
2538 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
2539 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
2540 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
2543 Stdlib.free (from.gr_mem);
2544 Stdlib.free (from._gr_buf_);
2545 from.gr_mem = IntPtr.Zero;
2546 from._gr_buf_ = IntPtr.Zero;
2550 internal static object grp_lock = new object ();
2552 [DllImport (MPH, SetLastError=true,
2553 EntryPoint="Mono_Posix_Syscall_getgrnam")]
2554 private static extern int sys_getgrnam (string name, out _Group group);
2556 public static Group getgrnam (string name)
2561 r = sys_getgrnam (name, out group);
2565 Group gr = new Group ();
2566 CopyGroup (gr, ref group);
2571 // struct group *getgrgid(gid_t gid);
2572 [DllImport (MPH, SetLastError=true,
2573 EntryPoint="Mono_Posix_Syscall_getgrgid")]
2574 private static extern int sys_getgrgid (uint uid, out _Group group);
2576 public static Group getgrgid (uint uid)
2581 r = sys_getgrgid (uid, out group);
2585 Group gr = new Group ();
2586 CopyGroup (gr, ref group);
2590 [DllImport (MPH, SetLastError=true,
2591 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
2592 private static extern int sys_getgrnam_r (
2593 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2594 string name, out _Group grbuf, out IntPtr grbufp);
2596 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
2601 int r = sys_getgrnam_r (name, out group, out _grbufp);
2602 if (r == 0 && _grbufp != IntPtr.Zero) {
2603 CopyGroup (grbuf, ref group);
2610 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
2611 // size_t buflen, struct group **gbufp);
2612 [DllImport (MPH, SetLastError=true,
2613 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
2614 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
2616 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
2621 int r = sys_getgrgid_r (uid, out group, out _grbufp);
2622 if (r == 0 && _grbufp != IntPtr.Zero) {
2623 CopyGroup (grbuf, ref group);
2629 [DllImport (MPH, SetLastError=true,
2630 EntryPoint="Mono_Posix_Syscall_getgrent")]
2631 private static extern int sys_getgrent (out _Group grbuf);
2633 public static Group getgrent ()
2638 r = sys_getgrent (out group);
2642 Group gr = new Group();
2643 CopyGroup (gr, ref group);
2647 [DllImport (MPH, SetLastError=true,
2648 EntryPoint="Mono_Posix_Syscall_setgrent")]
2649 private static extern int sys_setgrent ();
2651 public static int setgrent ()
2654 return sys_setgrent ();
2658 [DllImport (MPH, SetLastError=true,
2659 EntryPoint="Mono_Posix_Syscall_endgrent")]
2660 private static extern int sys_endgrent ();
2662 public static int endgrent ()
2665 return sys_endgrent ();
2669 [DllImport (MPH, SetLastError=true,
2670 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
2671 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
2673 public static Group fgetgrent (IntPtr stream)
2678 r = sys_fgetgrent (stream, out group);
2682 Group gr = new Group ();
2683 CopyGroup (gr, ref group);
2688 #region <pwd.h> Declarations
2692 // TODO: putpwent(3), fgetpwent_r()
2694 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
2697 private struct _Passwd
2699 public IntPtr pw_name;
2700 public IntPtr pw_passwd;
2701 [uid_t] public uint pw_uid;
2702 [gid_t] public uint pw_gid;
2703 public IntPtr pw_gecos;
2704 public IntPtr pw_dir;
2705 public IntPtr pw_shell;
2706 public IntPtr _pw_buf_;
2709 private static void CopyPasswd (Passwd to, ref _Passwd from)
2712 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
2713 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
2714 to.pw_uid = from.pw_uid;
2715 to.pw_gid = from.pw_gid;
2716 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
2717 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
2718 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
2721 Stdlib.free (from._pw_buf_);
2722 from._pw_buf_ = IntPtr.Zero;
2726 internal static object pwd_lock = new object ();
2728 [DllImport (MPH, SetLastError=true,
2729 EntryPoint="Mono_Posix_Syscall_getpwnam")]
2730 private static extern int sys_getpwnam (string name, out _Passwd passwd);
2732 public static Passwd getpwnam (string name)
2737 r = sys_getpwnam (name, out passwd);
2741 Passwd pw = new Passwd ();
2742 CopyPasswd (pw, ref passwd);
2747 // struct passwd *getpwnuid(uid_t uid);
2748 [DllImport (MPH, SetLastError=true,
2749 EntryPoint="Mono_Posix_Syscall_getpwuid")]
2750 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
2752 public static Passwd getpwuid (uint uid)
2757 r = sys_getpwuid (uid, out passwd);
2761 Passwd pw = new Passwd ();
2762 CopyPasswd (pw, ref passwd);
2766 [DllImport (MPH, SetLastError=true,
2767 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
2768 private static extern int sys_getpwnam_r (
2769 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2770 string name, out _Passwd pwbuf, out IntPtr pwbufp);
2772 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
2777 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
2778 if (r == 0 && _pwbufp != IntPtr.Zero) {
2779 CopyPasswd (pwbuf, ref passwd);
2786 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
2787 // buflen, struct passwd **pwbufp);
2788 [DllImport (MPH, SetLastError=true,
2789 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
2790 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
2792 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
2797 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
2798 if (r == 0 && _pwbufp != IntPtr.Zero) {
2799 CopyPasswd (pwbuf, ref passwd);
2805 [DllImport (MPH, SetLastError=true,
2806 EntryPoint="Mono_Posix_Syscall_getpwent")]
2807 private static extern int sys_getpwent (out _Passwd pwbuf);
2809 public static Passwd getpwent ()
2814 r = sys_getpwent (out passwd);
2818 Passwd pw = new Passwd ();
2819 CopyPasswd (pw, ref passwd);
2823 [DllImport (MPH, SetLastError=true,
2824 EntryPoint="Mono_Posix_Syscall_setpwent")]
2825 private static extern int sys_setpwent ();
2827 public static int setpwent ()
2830 return sys_setpwent ();
2834 [DllImport (MPH, SetLastError=true,
2835 EntryPoint="Mono_Posix_Syscall_endpwent")]
2836 private static extern int sys_endpwent ();
2838 public static int endpwent ()
2841 return sys_endpwent ();
2845 [DllImport (MPH, SetLastError=true,
2846 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
2847 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
2849 public static Passwd fgetpwent (IntPtr stream)
2854 r = sys_fgetpwent (stream, out passwd);
2858 Passwd pw = new Passwd ();
2859 CopyPasswd (pw, ref passwd);
2864 #region <signal.h> Declarations
2868 [DllImport (MPH, SetLastError=true,
2869 EntryPoint="Mono_Posix_Syscall_psignal")]
2870 private static extern int psignal (int sig, string s);
2872 public static int psignal (Signum sig, string s)
2874 int signum = NativeConvert.FromSignum (sig);
2875 return psignal (signum, s);
2879 // int kill(pid_t pid, int sig);
2880 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
2881 private static extern int sys_kill (int pid, int sig);
2883 public static int kill (int pid, Signum sig)
2885 int _sig = NativeConvert.FromSignum (sig);
2886 return sys_kill (pid, _sig);
2889 private static object signal_lock = new object ();
2891 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
2892 private static extern IntPtr sys_strsignal (int sig);
2894 public static string strsignal (Signum sig)
2896 int s = NativeConvert.FromSignum (sig);
2897 lock (signal_lock) {
2898 IntPtr r = sys_strsignal (s);
2899 return UnixMarshal.PtrToString (r);
2903 // TODO: sigaction(2)
2904 // TODO: sigsuspend(2)
2905 // TODO: sigpending(2)
2909 #region <stdio.h> Declarations
2913 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
2914 private static extern int _L_ctermid ();
2916 public static readonly int L_ctermid = _L_ctermid ();
2918 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
2919 private static extern int _L_cuserid ();
2921 public static readonly int L_cuserid = _L_cuserid ();
2923 internal static object getlogin_lock = new object ();
2925 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
2926 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
2928 [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
2929 "DO NOT USE cuserid().\n" +
2930 "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
2931 public static string cuserid (StringBuilder @string)
2933 if (@string.Capacity < L_cuserid) {
2934 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
2936 lock (getlogin_lock) {
2937 IntPtr r = sys_cuserid (@string);
2938 return UnixMarshal.PtrToString (r);
2942 [DllImport (LIBC, SetLastError=true)]
2943 public static extern int renameat (int olddirfd,
2944 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2945 string oldpath, int newdirfd,
2946 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2950 #region <stdlib.h> Declarations
2954 [DllImport (LIBC, SetLastError=true)]
2955 public static extern int mkstemp (StringBuilder template);
2957 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdtemp")]
2958 private static extern IntPtr sys_mkdtemp (StringBuilder template);
2960 public static StringBuilder mkdtemp (StringBuilder template)
2962 if (sys_mkdtemp (template) == IntPtr.Zero)
2967 [DllImport (LIBC, SetLastError=true)]
2968 public static extern int ttyslot ();
2970 [Obsolete ("This is insecure and should not be used", true)]
2971 public static int setkey (string key)
2973 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
2978 #region <string.h> Declarations
2984 // int strerror_r(int errnum, char *buf, size_t n);
2985 [DllImport (MPH, SetLastError=true,
2986 EntryPoint="Mono_Posix_Syscall_strerror_r")]
2987 private static extern int sys_strerror_r (int errnum,
2988 [Out] StringBuilder buf, ulong n);
2990 public static int strerror_r (Errno errnum, StringBuilder buf, ulong n)
2992 int e = NativeConvert.FromErrno (errnum);
2993 return sys_strerror_r (e, buf, n);
2996 public static int strerror_r (Errno errnum, StringBuilder buf)
2998 return strerror_r (errnum, buf, (ulong) buf.Capacity);
3003 #region <sys/epoll.h> Declarations
3005 public static int epoll_create (int size)
3007 return sys_epoll_create (size);
3010 public static int epoll_create (EpollFlags flags)
3012 return sys_epoll_create1 (flags);
3015 public static int epoll_ctl (int epfd, EpollOp op, int fd, EpollEvents events)
3017 EpollEvent ee = new EpollEvent ();
3021 return epoll_ctl (epfd, op, fd, ref ee);
3024 public static int epoll_wait (int epfd, EpollEvent [] events, int max_events, int timeout)
3026 if (events.Length < max_events)
3027 throw new ArgumentOutOfRangeException ("events", "Must refer to at least 'max_events' elements.");
3029 return sys_epoll_wait (epfd, events, max_events, timeout);
3032 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_create")]
3033 private static extern int sys_epoll_create (int size);
3035 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_create1")]
3036 private static extern int sys_epoll_create1 (EpollFlags flags);
3038 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_ctl")]
3039 public static extern int epoll_ctl (int epfd, EpollOp op, int fd, ref EpollEvent ee);
3041 [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_wait")]
3042 private static extern int sys_epoll_wait (int epfd, EpollEvent [] ee, int maxevents, int timeout);
3045 #region <sys/mman.h> Declarations
3051 // int posix_madvise(void *addr, size_t len, int advice);
3052 [DllImport (MPH, SetLastError=true,
3053 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
3054 public static extern int posix_madvise (IntPtr addr, ulong len,
3055 PosixMadviseAdvice advice);
3057 public static readonly IntPtr MAP_FAILED = unchecked((IntPtr)(-1));
3059 [DllImport (MPH, SetLastError=true,
3060 EntryPoint="Mono_Posix_Syscall_mmap")]
3061 public static extern IntPtr mmap (IntPtr start, ulong length,
3062 MmapProts prot, MmapFlags flags, int fd, long offset);
3064 [DllImport (MPH, SetLastError=true,
3065 EntryPoint="Mono_Posix_Syscall_munmap")]
3066 public static extern int munmap (IntPtr start, ulong length);
3068 [DllImport (MPH, SetLastError=true,
3069 EntryPoint="Mono_Posix_Syscall_mprotect")]
3070 public static extern int mprotect (IntPtr start, ulong len, MmapProts prot);
3072 [DllImport (MPH, SetLastError=true,
3073 EntryPoint="Mono_Posix_Syscall_msync")]
3074 public static extern int msync (IntPtr start, ulong len, MsyncFlags flags);
3076 [DllImport (MPH, SetLastError=true,
3077 EntryPoint="Mono_Posix_Syscall_mlock")]
3078 public static extern int mlock (IntPtr start, ulong len);
3080 [DllImport (MPH, SetLastError=true,
3081 EntryPoint="Mono_Posix_Syscall_munlock")]
3082 public static extern int munlock (IntPtr start, ulong len);
3084 [DllImport (LIBC, SetLastError=true, EntryPoint="mlockall")]
3085 private static extern int sys_mlockall (int flags);
3087 public static int mlockall (MlockallFlags flags)
3089 int _flags = NativeConvert.FromMlockallFlags (flags);
3090 return sys_mlockall (_flags);
3093 [DllImport (LIBC, SetLastError=true)]
3094 public static extern int munlockall ();
3096 [DllImport (MPH, SetLastError=true,
3097 EntryPoint="Mono_Posix_Syscall_mremap")]
3098 public static extern IntPtr mremap (IntPtr old_address, ulong old_size,
3099 ulong new_size, MremapFlags flags);
3101 [DllImport (MPH, SetLastError=true,
3102 EntryPoint="Mono_Posix_Syscall_mincore")]
3103 public static extern int mincore (IntPtr start, ulong length, byte[] vec);
3105 [DllImport (MPH, SetLastError=true,
3106 EntryPoint="Mono_Posix_Syscall_remap_file_pages")]
3107 public static extern int remap_file_pages (IntPtr start, ulong size,
3108 MmapProts prot, long pgoff, MmapFlags flags);
3112 #region <sys/poll.h> Declarations
3114 // <sys/poll.h> -- COMPLETE
3117 private struct _pollfd {
3119 public short events;
3120 public short revents;
3123 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
3124 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
3126 public static int poll (Pollfd [] fds, uint nfds, int timeout)
3128 if (fds.Length < nfds)
3129 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
3131 _pollfd[] send = new _pollfd[nfds];
3133 for (int i = 0; i < send.Length; i++) {
3134 send [i].fd = fds [i].fd;
3135 send [i].events = NativeConvert.FromPollEvents (fds [i].events);
3138 int r = sys_poll (send, nfds, timeout);
3140 for (int i = 0; i < send.Length; i++) {
3141 fds [i].revents = NativeConvert.ToPollEvents (send [i].revents);
3147 public static int poll (Pollfd [] fds, int timeout)
3149 return poll (fds, (uint) fds.Length, timeout);
3162 // TODO: setrlimit(2)
3163 // TODO: getrlimit(2)
3164 // TODO: getrusage(2)
3168 #region <sys/sendfile.h> Declarations
3170 // <sys/sendfile.h> -- COMPLETE
3173 [DllImport (MPH, SetLastError=true,
3174 EntryPoint="Mono_Posix_Syscall_sendfile")]
3175 public static extern long sendfile (int out_fd, int in_fd,
3176 ref long offset, ulong count);
3180 #region <sys/stat.h> Declarations
3182 // <sys/stat.h> -- COMPLETE
3184 [DllImport (MPH, SetLastError=true,
3185 EntryPoint="Mono_Posix_Syscall_stat")]
3186 public static extern int stat (
3187 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3188 string file_name, out Stat buf);
3190 [DllImport (MPH, SetLastError=true,
3191 EntryPoint="Mono_Posix_Syscall_fstat")]
3192 public static extern int fstat (int filedes, out Stat buf);
3194 [DllImport (MPH, SetLastError=true,
3195 EntryPoint="Mono_Posix_Syscall_lstat")]
3196 public static extern int lstat (
3197 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3198 string file_name, out Stat buf);
3201 // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
3202 // All take FilePermissions
3205 // int chmod(const char *path, mode_t mode);
3206 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
3207 private static extern int sys_chmod (
3208 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3209 string path, uint mode);
3211 public static int chmod (string path, FilePermissions mode)
3213 uint _mode = NativeConvert.FromFilePermissions (mode);
3214 return sys_chmod (path, _mode);
3218 // int chmod(int filedes, mode_t mode);
3219 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
3220 private static extern int sys_fchmod (int filedes, uint mode);
3222 public static int fchmod (int filedes, FilePermissions mode)
3224 uint _mode = NativeConvert.FromFilePermissions (mode);
3225 return sys_fchmod (filedes, _mode);
3229 // mode_t umask(mode_t mask);
3230 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
3231 private static extern uint sys_umask (uint mask);
3233 public static FilePermissions umask (FilePermissions mask)
3235 uint _mask = NativeConvert.FromFilePermissions (mask);
3236 uint r = sys_umask (_mask);
3237 return NativeConvert.ToFilePermissions (r);
3241 // int mkdir(const char *pathname, mode_t mode);
3242 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
3243 private static extern int sys_mkdir (
3244 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3245 string oldpath, uint mode);
3247 public static int mkdir (string oldpath, FilePermissions mode)
3249 uint _mode = NativeConvert.FromFilePermissions (mode);
3250 return sys_mkdir (oldpath, _mode);
3254 // int mknod (const char *pathname, mode_t mode, dev_t dev);
3255 [DllImport (MPH, SetLastError=true,
3256 EntryPoint="Mono_Posix_Syscall_mknod")]
3257 public static extern int mknod (
3258 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3259 string pathname, FilePermissions mode, ulong dev);
3262 // int mkfifo(const char *pathname, mode_t mode);
3263 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
3264 private static extern int sys_mkfifo (
3265 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3266 string pathname, uint mode);
3268 public static int mkfifo (string pathname, FilePermissions mode)
3270 uint _mode = NativeConvert.FromFilePermissions (mode);
3271 return sys_mkfifo (pathname, _mode);
3275 // int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
3276 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmodat")]
3277 private static extern int sys_fchmodat (int dirfd,
3278 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3279 string pathname, uint mode, int flags);
3281 public static int fchmodat (int dirfd, string pathname, FilePermissions mode, AtFlags flags)
3283 uint _mode = NativeConvert.FromFilePermissions (mode);
3284 int _flags = NativeConvert.FromAtFlags (flags);
3285 return sys_fchmodat (dirfd, pathname, _mode, _flags);
3288 [DllImport (MPH, SetLastError=true,
3289 EntryPoint="Mono_Posix_Syscall_fstatat")]
3290 public static extern int fstatat (int dirfd,
3291 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3292 string file_name, out Stat buf, AtFlags flags);
3294 [DllImport (MPH, SetLastError=true,
3295 EntryPoint="Mono_Posix_Syscall_get_utime_now")]
3296 private static extern long get_utime_now ();
3298 [DllImport (MPH, SetLastError=true,
3299 EntryPoint="Mono_Posix_Syscall_get_utime_omit")]
3300 private static extern long get_utime_omit ();
3302 public static readonly long UTIME_NOW = get_utime_now ();
3304 public static readonly long UTIME_OMIT = get_utime_omit ();
3306 [DllImport (MPH, SetLastError=true,
3307 EntryPoint="Mono_Posix_Syscall_futimens")]
3308 private static extern int sys_futimens (int fd, Timespec[] times);
3310 public static int futimens (int fd, Timespec[] times)
3312 if (times != null && times.Length != 2) {
3313 SetLastError (Errno.EINVAL);
3316 return sys_futimens (fd, times);
3319 [DllImport (MPH, SetLastError=true,
3320 EntryPoint="Mono_Posix_Syscall_utimensat")]
3321 private static extern int sys_utimensat (int dirfd,
3322 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3323 string pathname, Timespec[] times, int flags);
3325 public static int utimensat (int dirfd, string pathname, Timespec[] times, AtFlags flags)
3327 if (times != null && times.Length != 2) {
3328 SetLastError (Errno.EINVAL);
3331 int _flags = NativeConvert.FromAtFlags (flags);
3332 return sys_utimensat (dirfd, pathname, times, _flags);
3336 // int mkdirat(int dirfd, const char *pathname, mode_t mode);
3337 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdirat")]
3338 private static extern int sys_mkdirat (int dirfd,
3339 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3340 string oldpath, uint mode);
3342 public static int mkdirat (int dirfd, string oldpath, FilePermissions mode)
3344 uint _mode = NativeConvert.FromFilePermissions (mode);
3345 return sys_mkdirat (dirfd, oldpath, _mode);
3349 // int mknodat (int dirfd, const char *pathname, mode_t mode, dev_t dev);
3350 [DllImport (MPH, SetLastError=true,
3351 EntryPoint="Mono_Posix_Syscall_mknodat")]
3352 public static extern int mknodat (int dirfd,
3353 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3354 string pathname, FilePermissions mode, ulong dev);
3357 // int mkfifoat(int dirfd, const char *pathname, mode_t mode);
3358 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifoat")]
3359 private static extern int sys_mkfifoat (int dirfd,
3360 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3361 string pathname, uint mode);
3363 public static int mkfifoat (int dirfd, string pathname, FilePermissions mode)
3365 uint _mode = NativeConvert.FromFilePermissions (mode);
3366 return sys_mkfifoat (dirfd, pathname, _mode);
3370 #region <sys/stat.h> Declarations
3375 [DllImport (MPH, SetLastError=true,
3376 EntryPoint="Mono_Posix_Syscall_statvfs")]
3377 public static extern int statvfs (
3378 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3379 string path, out Statvfs buf);
3381 [DllImport (MPH, SetLastError=true,
3382 EntryPoint="Mono_Posix_Syscall_fstatvfs")]
3383 public static extern int fstatvfs (int fd, out Statvfs buf);
3387 #region <sys/time.h> Declarations
3391 // TODO: adjtime(), getitimer(2), setitimer(2)
3393 [DllImport (MPH, SetLastError=true,
3394 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
3395 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
3397 [DllImport (MPH, SetLastError=true,
3398 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
3399 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
3401 public static int gettimeofday (out Timeval tv)
3403 return gettimeofday (out tv, IntPtr.Zero);
3406 [DllImport (MPH, SetLastError=true,
3407 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
3408 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
3410 public static int gettimeofday (out Timezone tz)
3412 return gettimeofday (IntPtr.Zero, out tz);
3415 [DllImport (MPH, SetLastError=true,
3416 EntryPoint="Mono_Posix_Syscall_settimeofday")]
3417 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
3419 [DllImport (MPH, SetLastError=true,
3420 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
3421 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
3423 public static int settimeofday (ref Timeval tv)
3425 return settimeofday (ref tv, IntPtr.Zero);
3428 [DllImport (MPH, SetLastError=true,
3429 EntryPoint="Mono_Posix_Syscall_utimes")]
3430 private static extern int sys_utimes (
3431 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3432 string filename, Timeval[] tvp);
3434 public static int utimes (string filename, Timeval[] tvp)
3436 if (tvp != null && tvp.Length != 2) {
3437 SetLastError (Errno.EINVAL);
3440 return sys_utimes (filename, tvp);
3443 [DllImport (MPH, SetLastError=true,
3444 EntryPoint="Mono_Posix_Syscall_lutimes")]
3445 private static extern int sys_lutimes (
3446 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3447 string filename, Timeval[] tvp);
3449 public static int lutimes (string filename, Timeval[] tvp)
3451 if (tvp != null && tvp.Length != 2) {
3452 SetLastError (Errno.EINVAL);
3455 return sys_lutimes (filename, tvp);
3458 [DllImport (MPH, SetLastError=true,
3459 EntryPoint="Mono_Posix_Syscall_futimes")]
3460 private static extern int sys_futimes (int fd, Timeval[] tvp);
3462 public static int futimes (int fd, Timeval[] tvp)
3464 if (tvp != null && tvp.Length != 2) {
3465 SetLastError (Errno.EINVAL);
3468 return sys_futimes (fd, tvp);
3490 private struct _Utsname
3492 public IntPtr sysname;
3493 public IntPtr nodename;
3494 public IntPtr release;
3495 public IntPtr version;
3496 public IntPtr machine;
3497 public IntPtr domainname;
3498 public IntPtr _buf_;
3501 private static void CopyUtsname (ref Utsname to, ref _Utsname from)
3504 to = new Utsname ();
3505 to.sysname = UnixMarshal.PtrToString (from.sysname);
3506 to.nodename = UnixMarshal.PtrToString (from.nodename);
3507 to.release = UnixMarshal.PtrToString (from.release);
3508 to.version = UnixMarshal.PtrToString (from.version);
3509 to.machine = UnixMarshal.PtrToString (from.machine);
3510 to.domainname = UnixMarshal.PtrToString (from.domainname);
3513 Stdlib.free (from._buf_);
3514 from._buf_ = IntPtr.Zero;
3518 [DllImport (MPH, SetLastError=true,
3519 EntryPoint="Mono_Posix_Syscall_uname")]
3520 private static extern int sys_uname (out _Utsname buf);
3522 public static int uname (out Utsname buf)
3525 int r = sys_uname (out _buf);
3526 buf = new Utsname ();
3528 CopyUtsname (ref buf, ref _buf);
3533 #region <sys/wait.h> Declarations
3539 // pid_t wait(int *status);
3540 [DllImport (LIBC, SetLastError=true)]
3541 public static extern int wait (out int status);
3544 // pid_t waitpid(pid_t pid, int *status, int options);
3545 [DllImport (LIBC, SetLastError=true)]
3546 private static extern int waitpid (int pid, out int status, int options);
3548 public static int waitpid (int pid, out int status, WaitOptions options)
3550 int _options = NativeConvert.FromWaitOptions (options);
3551 return waitpid (pid, out status, _options);
3554 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
3555 private static extern int _WIFEXITED (int status);
3557 public static bool WIFEXITED (int status)
3559 return _WIFEXITED (status) != 0;
3562 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
3563 public static extern int WEXITSTATUS (int status);
3565 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
3566 private static extern int _WIFSIGNALED (int status);
3568 public static bool WIFSIGNALED (int status)
3570 return _WIFSIGNALED (status) != 0;
3573 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
3574 private static extern int _WTERMSIG (int status);
3576 public static Signum WTERMSIG (int status)
3578 int r = _WTERMSIG (status);
3579 return NativeConvert.ToSignum (r);
3582 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
3583 private static extern int _WIFSTOPPED (int status);
3585 public static bool WIFSTOPPED (int status)
3587 return _WIFSTOPPED (status) != 0;
3590 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
3591 private static extern int _WSTOPSIG (int status);
3593 public static Signum WSTOPSIG (int status)
3595 int r = _WSTOPSIG (status);
3596 return NativeConvert.ToSignum (r);
3605 #region <syslog.h> Declarations
3610 [DllImport (MPH, SetLastError=true,
3611 EntryPoint="Mono_Posix_Syscall_openlog")]
3612 private static extern int sys_openlog (IntPtr ident, int option, int facility);
3614 public static int openlog (IntPtr ident, SyslogOptions option,
3615 SyslogFacility defaultFacility)
3617 int _option = NativeConvert.FromSyslogOptions (option);
3618 int _facility = NativeConvert.FromSyslogFacility (defaultFacility);
3620 return sys_openlog (ident, _option, _facility);
3623 [DllImport (MPH, SetLastError=true,
3624 EntryPoint="Mono_Posix_Syscall_syslog")]
3625 private static extern int sys_syslog (int priority, string message);
3627 public static int syslog (SyslogFacility facility, SyslogLevel level, string message)
3629 int _facility = NativeConvert.FromSyslogFacility (facility);
3630 int _level = NativeConvert.FromSyslogLevel (level);
3631 return sys_syslog (_facility | _level, GetSyslogMessage (message));
3634 public static int syslog (SyslogLevel level, string message)
3636 int _level = NativeConvert.FromSyslogLevel (level);
3637 return sys_syslog (_level, GetSyslogMessage (message));
3640 private static string GetSyslogMessage (string message)
3642 return UnixMarshal.EscapeFormatString (message, new char[]{'m'});
3645 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
3646 "Use syslog(SyslogFacility, SyslogLevel, string) instead.")]
3647 public static int syslog (SyslogFacility facility, SyslogLevel level,
3648 string format, params object[] parameters)
3650 int _facility = NativeConvert.FromSyslogFacility (facility);
3651 int _level = NativeConvert.FromSyslogLevel (level);
3653 object[] _parameters = new object[checked(parameters.Length+2)];
3654 _parameters [0] = _facility | _level;
3655 _parameters [1] = format;
3656 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
3657 return (int) XPrintfFunctions.syslog (_parameters);
3660 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
3661 "Use syslog(SyslogLevel, string) instead.")]
3662 public static int syslog (SyslogLevel level, string format,
3663 params object[] parameters)
3665 int _level = NativeConvert.FromSyslogLevel (level);
3667 object[] _parameters = new object[checked(parameters.Length+2)];
3668 _parameters [0] = _level;
3669 _parameters [1] = format;
3670 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
3671 return (int) XPrintfFunctions.syslog (_parameters);
3674 [DllImport (MPH, SetLastError=true,
3675 EntryPoint="Mono_Posix_Syscall_closelog")]
3676 public static extern int closelog ();
3678 [DllImport (LIBC, SetLastError=true, EntryPoint="setlogmask")]
3679 private static extern int sys_setlogmask (int mask);
3681 public static int setlogmask (SyslogLevel mask)
3683 int _mask = NativeConvert.FromSyslogLevel (mask);
3684 return sys_setlogmask (_mask);
3689 #region <time.h> Declarations
3696 // int nanosleep(const struct timespec *req, struct timespec *rem);
3697 [DllImport (MPH, SetLastError=true,
3698 EntryPoint="Mono_Posix_Syscall_nanosleep")]
3699 public static extern int nanosleep (ref Timespec req, ref Timespec rem);
3702 // int stime(time_t *t);
3703 [DllImport (MPH, SetLastError=true,
3704 EntryPoint="Mono_Posix_Syscall_stime")]
3705 public static extern int stime (ref long t);
3708 // time_t time(time_t *t);
3709 [DllImport (MPH, SetLastError=true,
3710 EntryPoint="Mono_Posix_Syscall_time")]
3711 public static extern long time (out long t);
3721 #region <unistd.h> Declarations
3725 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
3726 // other TODOs listed below.
3728 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
3729 private static extern int sys_access (
3730 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3731 string pathname, int mode);
3733 public static int access (string pathname, AccessModes mode)
3735 int _mode = NativeConvert.FromAccessModes (mode);
3736 return sys_access (pathname, _mode);
3740 // off_t lseek(int filedes, off_t offset, int whence);
3741 [DllImport (MPH, SetLastError=true,
3742 EntryPoint="Mono_Posix_Syscall_lseek")]
3743 private static extern long sys_lseek (int fd, long offset, int whence);
3745 public static long lseek (int fd, long offset, SeekFlags whence)
3747 short _whence = NativeConvert.FromSeekFlags (whence);
3748 return sys_lseek (fd, offset, _whence);
3751 [DllImport (LIBC, SetLastError=true)]
3752 public static extern int close (int fd);
3755 // ssize_t read(int fd, void *buf, size_t count);
3756 [DllImport (MPH, SetLastError=true,
3757 EntryPoint="Mono_Posix_Syscall_read")]
3758 public static extern long read (int fd, IntPtr buf, ulong count);
3760 public static unsafe long read (int fd, void *buf, ulong count)
3762 return read (fd, (IntPtr) buf, count);
3766 // ssize_t write(int fd, const void *buf, size_t count);
3767 [DllImport (MPH, SetLastError=true,
3768 EntryPoint="Mono_Posix_Syscall_write")]
3769 public static extern long write (int fd, IntPtr buf, ulong count);
3771 public static unsafe long write (int fd, void *buf, ulong count)
3773 return write (fd, (IntPtr) buf, count);
3777 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
3778 [DllImport (MPH, SetLastError=true,
3779 EntryPoint="Mono_Posix_Syscall_pread")]
3780 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
3782 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
3784 return pread (fd, (IntPtr) buf, count, offset);
3788 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
3789 [DllImport (MPH, SetLastError=true,
3790 EntryPoint="Mono_Posix_Syscall_pwrite")]
3791 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
3793 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
3795 return pwrite (fd, (IntPtr) buf, count, offset);
3798 [DllImport (MPH, SetLastError=true,
3799 EntryPoint="Mono_Posix_Syscall_pipe")]
3800 public static extern int pipe (out int reading, out int writing);
3802 public static int pipe (int[] filedes)
3804 if (filedes == null || filedes.Length != 2) {
3808 int reading, writing;
3809 int r = pipe (out reading, out writing);
3810 filedes[0] = reading;
3811 filedes[1] = writing;
3815 [DllImport (LIBC, SetLastError=true)]
3816 public static extern uint alarm (uint seconds);
3818 [DllImport (LIBC, SetLastError=true)]
3819 public static extern uint sleep (uint seconds);
3821 [DllImport (LIBC, SetLastError=true)]
3822 public static extern uint ualarm (uint usecs, uint interval);
3824 [DllImport (LIBC, SetLastError=true)]
3825 public static extern int pause ();
3828 // int chown(const char *path, uid_t owner, gid_t group);
3829 [DllImport (LIBC, SetLastError=true)]
3830 public static extern int chown (
3831 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3832 string path, uint owner, uint group);
3835 // int fchown(int fd, uid_t owner, gid_t group);
3836 [DllImport (LIBC, SetLastError=true)]
3837 public static extern int fchown (int fd, uint owner, uint group);
3840 // int lchown(const char *path, uid_t owner, gid_t group);
3841 [DllImport (LIBC, SetLastError=true)]
3842 public static extern int lchown (
3843 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3844 string path, uint owner, uint group);
3846 [DllImport (LIBC, SetLastError=true)]
3847 public static extern int chdir (
3848 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3851 [DllImport (LIBC, SetLastError=true)]
3852 public static extern int fchdir (int fd);
3855 // char *getcwd(char *buf, size_t size);
3856 [DllImport (MPH, SetLastError=true,
3857 EntryPoint="Mono_Posix_Syscall_getcwd")]
3858 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
3860 public static StringBuilder getcwd (StringBuilder buf)
3862 getcwd (buf, (ulong) buf.Capacity);
3866 // getwd(2) is deprecated; don't expose it.
3868 [DllImport (LIBC, SetLastError=true)]
3869 public static extern int dup (int fd);
3871 [DllImport (LIBC, SetLastError=true)]
3872 public static extern int dup2 (int fd, int fd2);
3874 // TODO: does Mono marshal arrays properly?
3875 [DllImport (LIBC, SetLastError=true)]
3876 public static extern int execve (
3877 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3878 string path, string[] argv, string[] envp);
3880 [DllImport (LIBC, SetLastError=true)]
3881 public static extern int fexecve (int fd, string[] argv, string[] envp);
3883 [DllImport (LIBC, SetLastError=true)]
3884 public static extern int execv (
3885 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3886 string path, string[] argv);
3888 // TODO: execle, execl, execlp
3889 [DllImport (LIBC, SetLastError=true)]
3890 public static extern int execvp (
3891 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3892 string path, string[] argv);
3894 [DllImport (LIBC, SetLastError=true)]
3895 public static extern int nice (int inc);
3897 [DllImport (LIBC, SetLastError=true)]
3898 [CLSCompliant (false)]
3899 public static extern int _exit (int status);
3901 [DllImport (MPH, SetLastError=true,
3902 EntryPoint="Mono_Posix_Syscall_fpathconf")]
3903 public static extern long fpathconf (int filedes, PathconfName name, Errno defaultError);
3905 public static long fpathconf (int filedes, PathconfName name)
3907 return fpathconf (filedes, name, (Errno) 0);
3910 [DllImport (MPH, SetLastError=true,
3911 EntryPoint="Mono_Posix_Syscall_pathconf")]
3912 public static extern long pathconf (
3913 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3914 string path, PathconfName name, Errno defaultError);
3916 public static long pathconf (string path, PathconfName name)
3918 return pathconf (path, name, (Errno) 0);
3921 [DllImport (MPH, SetLastError=true,
3922 EntryPoint="Mono_Posix_Syscall_sysconf")]
3923 public static extern long sysconf (SysconfName name, Errno defaultError);
3925 public static long sysconf (SysconfName name)
3927 return sysconf (name, (Errno) 0);
3931 // size_t confstr(int name, char *buf, size_t len);
3932 [DllImport (MPH, SetLastError=true,
3933 EntryPoint="Mono_Posix_Syscall_confstr")]
3934 public static extern ulong confstr (ConfstrName name, [Out] StringBuilder buf, ulong len);
3937 // pid_t getpid(void);
3938 [DllImport (LIBC, SetLastError=true)]
3939 public static extern int getpid ();
3942 // pid_t getppid(void);
3943 [DllImport (LIBC, SetLastError=true)]
3944 public static extern int getppid ();
3947 // int setpgid(pid_t pid, pid_t pgid);
3948 [DllImport (LIBC, SetLastError=true)]
3949 public static extern int setpgid (int pid, int pgid);
3952 // pid_t getpgid(pid_t pid);
3953 [DllImport (LIBC, SetLastError=true)]
3954 public static extern int getpgid (int pid);
3956 [DllImport (LIBC, SetLastError=true)]
3957 public static extern int setpgrp ();
3960 // pid_t getpgrp(void);
3961 [DllImport (LIBC, SetLastError=true)]
3962 public static extern int getpgrp ();
3965 // pid_t setsid(void);
3966 [DllImport (LIBC, SetLastError=true)]
3967 public static extern int setsid ();
3970 // pid_t getsid(pid_t pid);
3971 [DllImport (LIBC, SetLastError=true)]
3972 public static extern int getsid (int pid);
3975 // uid_t getuid(void);
3976 [DllImport (LIBC, SetLastError=true)]
3977 public static extern uint getuid ();
3980 // uid_t geteuid(void);
3981 [DllImport (LIBC, SetLastError=true)]
3982 public static extern uint geteuid ();
3985 // gid_t getgid(void);
3986 [DllImport (LIBC, SetLastError=true)]
3987 public static extern uint getgid ();
3990 // gid_t getgid(void);
3991 [DllImport (LIBC, SetLastError=true)]
3992 public static extern uint getegid ();
3995 // int getgroups(int size, gid_t list[]);
3996 [DllImport (LIBC, SetLastError=true)]
3997 public static extern int getgroups (int size, uint[] list);
3999 public static int getgroups (uint[] list)
4001 return getgroups (list.Length, list);
4005 // int setuid(uid_t uid);
4006 [DllImport (LIBC, SetLastError=true)]
4007 public static extern int setuid (uint uid);
4010 // int setreuid(uid_t ruid, uid_t euid);
4011 [DllImport (LIBC, SetLastError=true)]
4012 public static extern int setreuid (uint ruid, uint euid);
4015 // int setregid(gid_t ruid, gid_t euid);
4016 [DllImport (LIBC, SetLastError=true)]
4017 public static extern int setregid (uint rgid, uint egid);
4020 // int seteuid(uid_t euid);
4021 [DllImport (LIBC, SetLastError=true)]
4022 public static extern int seteuid (uint euid);
4025 // int setegid(gid_t euid);
4026 [DllImport (LIBC, SetLastError=true)]
4027 public static extern int setegid (uint uid);
4030 // int setgid(gid_t gid);
4031 [DllImport (LIBC, SetLastError=true)]
4032 public static extern int setgid (uint gid);
4035 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
4036 [DllImport (LIBC, SetLastError=true)]
4037 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
4040 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
4041 [DllImport (LIBC, SetLastError=true)]
4042 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
4045 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
4046 [DllImport (LIBC, SetLastError=true)]
4047 public static extern int setresuid (uint ruid, uint euid, uint suid);
4050 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
4051 [DllImport (LIBC, SetLastError=true)]
4052 public static extern int setresgid (uint rgid, uint egid, uint sgid);
4056 // pid_t fork(void);
4057 [DllImport (LIBC, SetLastError=true)]
4058 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
4059 "shutdown code.\nUse System.Diagnostics.Process instead")]
4060 private static extern int fork ();
4063 // pid_t vfork(void);
4064 [DllImport (LIBC, SetLastError=true)]
4065 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
4066 "shutdown code.\nUse System.Diagnostics.Process instead")]
4067 private static extern int vfork ();
4070 private static object tty_lock = new object ();
4072 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
4073 private static extern IntPtr sys_ttyname (int fd);
4075 public static string ttyname (int fd)
4078 IntPtr r = sys_ttyname (fd);
4079 return UnixMarshal.PtrToString (r);
4084 // int ttyname_r(int fd, char *buf, size_t buflen);
4085 [DllImport (MPH, SetLastError=true,
4086 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
4087 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
4089 public static int ttyname_r (int fd, StringBuilder buf)
4091 return ttyname_r (fd, buf, (ulong) buf.Capacity);
4094 [DllImport (LIBC, EntryPoint="isatty")]
4095 private static extern int sys_isatty (int fd);
4097 public static bool isatty (int fd)
4099 return sys_isatty (fd) == 1;
4102 [DllImport (LIBC, SetLastError=true)]
4103 public static extern int link (
4104 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4106 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4109 [DllImport (LIBC, SetLastError=true)]
4110 public static extern int symlink (
4111 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4113 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4116 delegate long DoReadlinkFun (byte[] target);
4118 // Helper function for readlink(string, StringBuilder) and readlinkat (int, string, StringBuilder)
4119 static int ReadlinkIntoStringBuilder (DoReadlinkFun doReadlink, [Out] StringBuilder buf, ulong bufsiz)
4121 // bufsiz > int.MaxValue can't work because StringBuilder can store only int.MaxValue chars
4122 int bufsizInt = checked ((int) bufsiz);
4123 var target = new byte [bufsizInt];
4125 var r = doReadlink (target);
4127 return checked ((int) r);
4130 var chars = UnixEncoding.Instance.GetChars (target, 0, checked ((int) r));
4131 // Make sure that at more bufsiz chars are written
4132 buf.Append (chars, 0, System.Math.Min (bufsizInt, chars.Length));
4133 if (r == bufsizInt) {
4134 // may not have read full contents; fill 'buf' so that caller can properly check
4135 buf.Append (new string ('\x00', bufsizInt - buf.Length));
4141 // ssize_t readlink(const char *path, char *buf, size_t bufsize);
4142 public static int readlink (string path, [Out] StringBuilder buf, ulong bufsiz)
4144 return ReadlinkIntoStringBuilder (target => readlink (path, target), buf, bufsiz);
4147 public static int readlink (string path, [Out] StringBuilder buf)
4149 return readlink (path, buf, (ulong) buf.Capacity);
4152 [DllImport (MPH, SetLastError=true,
4153 EntryPoint="Mono_Posix_Syscall_readlink")]
4154 private static extern long readlink (
4155 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4156 string path, byte[] buf, ulong bufsiz);
4158 public static long readlink (string path, byte[] buf)
4160 return readlink (path, buf, (ulong) buf.LongLength);
4163 [DllImport (LIBC, SetLastError=true)]
4164 public static extern int unlink (
4165 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4168 [DllImport (LIBC, SetLastError=true)]
4169 public static extern int rmdir (
4170 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4174 // pid_t tcgetpgrp(int fd);
4175 [DllImport (LIBC, SetLastError=true)]
4176 public static extern int tcgetpgrp (int fd);
4179 // int tcsetpgrp(int fd, pid_t pgrp);
4180 [DllImport (LIBC, SetLastError=true)]
4181 public static extern int tcsetpgrp (int fd, int pgrp);
4183 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
4184 private static extern IntPtr sys_getlogin ();
4186 public static string getlogin ()
4188 lock (getlogin_lock) {
4189 IntPtr r = sys_getlogin ();
4190 return UnixMarshal.PtrToString (r);
4195 // int getlogin_r(char *buf, size_t bufsize);
4196 [DllImport (MPH, SetLastError=true,
4197 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
4198 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
4200 public static int getlogin_r (StringBuilder name)
4202 return getlogin_r (name, (ulong) name.Capacity);
4205 [DllImport (LIBC, SetLastError=true)]
4206 public static extern int setlogin (string name);
4209 // int gethostname(char *name, size_t len);
4210 [DllImport (MPH, SetLastError=true,
4211 EntryPoint="Mono_Posix_Syscall_gethostname")]
4212 public static extern int gethostname ([Out] StringBuilder name, ulong len);
4214 public static int gethostname (StringBuilder name)
4216 return gethostname (name, (ulong) name.Capacity);
4220 // int gethostname(const char *name, size_t len);
4221 [DllImport (MPH, SetLastError=true,
4222 EntryPoint="Mono_Posix_Syscall_sethostname")]
4223 public static extern int sethostname (string name, ulong len);
4225 public static int sethostname (string name)
4227 return sethostname (name, (ulong) name.Length);
4230 [DllImport (MPH, SetLastError=true,
4231 EntryPoint="Mono_Posix_Syscall_gethostid")]
4232 public static extern long gethostid ();
4234 [DllImport (MPH, SetLastError=true,
4235 EntryPoint="Mono_Posix_Syscall_sethostid")]
4236 public static extern int sethostid (long hostid);
4239 // int getdomainname(char *name, size_t len);
4240 [DllImport (MPH, SetLastError=true,
4241 EntryPoint="Mono_Posix_Syscall_getdomainname")]
4242 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
4244 public static int getdomainname (StringBuilder name)
4246 return getdomainname (name, (ulong) name.Capacity);
4250 // int setdomainname(const char *name, size_t len);
4251 [DllImport (MPH, SetLastError=true,
4252 EntryPoint="Mono_Posix_Syscall_setdomainname")]
4253 public static extern int setdomainname (string name, ulong len);
4255 public static int setdomainname (string name)
4257 return setdomainname (name, (ulong) name.Length);
4260 [DllImport (LIBC, SetLastError=true)]
4261 public static extern int vhangup ();
4263 // Revoke doesn't appear to be POSIX. Include it?
4264 [DllImport (LIBC, SetLastError=true)]
4265 public static extern int revoke (
4266 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4269 // TODO: profil? It's not POSIX.
4271 [DllImport (LIBC, SetLastError=true)]
4272 public static extern int acct (
4273 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4276 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
4277 private static extern IntPtr sys_getusershell ();
4279 internal static object usershell_lock = new object ();
4281 public static string getusershell ()
4283 lock (usershell_lock) {
4284 IntPtr r = sys_getusershell ();
4285 return UnixMarshal.PtrToString (r);
4289 [DllImport (MPH, SetLastError=true,
4290 EntryPoint="Mono_Posix_Syscall_setusershell")]
4291 private static extern int sys_setusershell ();
4293 public static int setusershell ()
4295 lock (usershell_lock) {
4296 return sys_setusershell ();
4300 [DllImport (MPH, SetLastError=true,
4301 EntryPoint="Mono_Posix_Syscall_endusershell")]
4302 private static extern int sys_endusershell ();
4304 public static int endusershell ()
4306 lock (usershell_lock) {
4307 return sys_endusershell ();
4312 [DllImport (LIBC, SetLastError=true)]
4313 private static extern int daemon (int nochdir, int noclose);
4315 // this implicitly forks, and thus isn't safe.
4316 private static int daemon (bool nochdir, bool noclose)
4318 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
4322 [DllImport (LIBC, SetLastError=true)]
4323 public static extern int chroot (
4324 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4327 // skipping getpass(3) as the man page states:
4328 // This function is obsolete. Do not use it.
4330 [DllImport (LIBC, SetLastError=true)]
4331 public static extern int fsync (int fd);
4333 [DllImport (LIBC, SetLastError=true)]
4334 public static extern int fdatasync (int fd);
4336 [DllImport (MPH, SetLastError=true,
4337 EntryPoint="Mono_Posix_Syscall_sync")]
4338 public static extern int sync ();
4340 [DllImport (LIBC, SetLastError=true)]
4341 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
4342 "Use Syscall.sysconf (SysconfName._SC_PAGESIZE).")]
4343 public static extern int getpagesize ();
4346 // int truncate(const char *path, off_t length);
4347 [DllImport (MPH, SetLastError=true,
4348 EntryPoint="Mono_Posix_Syscall_truncate")]
4349 public static extern int truncate (
4350 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4351 string path, long length);
4354 // int ftruncate(int fd, off_t length);
4355 [DllImport (MPH, SetLastError=true,
4356 EntryPoint="Mono_Posix_Syscall_ftruncate")]
4357 public static extern int ftruncate (int fd, long length);
4359 [DllImport (LIBC, SetLastError=true)]
4360 public static extern int getdtablesize ();
4362 [DllImport (LIBC, SetLastError=true)]
4363 public static extern int brk (IntPtr end_data_segment);
4365 [DllImport (LIBC, SetLastError=true)]
4366 public static extern IntPtr sbrk (IntPtr increment);
4368 // TODO: syscall(2)?
4369 // Probably safer to skip entirely.
4372 // int lockf(int fd, int cmd, off_t len);
4373 [DllImport (MPH, SetLastError=true,
4374 EntryPoint="Mono_Posix_Syscall_lockf")]
4375 public static extern int lockf (int fd, LockfCommand cmd, long len);
4377 [Obsolete ("This is insecure and should not be used", true)]
4378 public static string crypt (string key, string salt)
4380 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
4383 [Obsolete ("This is insecure and should not be used", true)]
4384 public static int encrypt (byte[] block, bool decode)
4386 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
4390 // void swab(const void *from, void *to, ssize_t n);
4391 [DllImport (MPH, SetLastError=true,
4392 EntryPoint="Mono_Posix_Syscall_swab")]
4393 public static extern int swab (IntPtr from, IntPtr to, long n);
4395 public static unsafe void swab (void* from, void* to, long n)
4397 swab ((IntPtr) from, (IntPtr) to, n);
4400 [DllImport (LIBC, SetLastError=true, EntryPoint="faccessat")]
4401 private static extern int sys_faccessat (int dirfd,
4402 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4403 string pathname, int mode, int flags);
4405 public static int faccessat (int dirfd, string pathname, AccessModes mode, AtFlags flags)
4407 int _mode = NativeConvert.FromAccessModes (mode);
4408 int _flags = NativeConvert.FromAtFlags (flags);
4409 return sys_faccessat (dirfd, pathname, _mode, _flags);
4413 // int fchownat(int dirfd, const char *path, uid_t owner, gid_t group, int flags);
4414 [DllImport (LIBC, SetLastError=true, EntryPoint="fchownat")]
4415 private static extern int sys_fchownat (int dirfd,
4416 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4417 string pathname, uint owner, uint group, int flags);
4419 public static int fchownat (int dirfd, string pathname, uint owner, uint group, AtFlags flags)
4421 int _flags = NativeConvert.FromAtFlags (flags);
4422 return sys_fchownat (dirfd, pathname, owner, group, _flags);
4425 [DllImport (LIBC, SetLastError=true, EntryPoint="linkat")]
4426 private static extern int sys_linkat (int olddirfd,
4427 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4428 string oldpath, int newdirfd,
4429 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4430 string newpath, int flags);
4432 public static int linkat (int olddirfd, string oldpath, int newdirfd, string newpath, AtFlags flags)
4434 int _flags = NativeConvert.FromAtFlags (flags);
4435 return sys_linkat (olddirfd, oldpath, newdirfd, newpath, _flags);
4439 // ssize_t readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsize);
4440 public static int readlinkat (int dirfd, string pathname, [Out] StringBuilder buf, ulong bufsiz)
4442 return ReadlinkIntoStringBuilder (target => readlinkat (dirfd, pathname, target), buf, bufsiz);
4445 public static int readlinkat (int dirfd, string pathname, [Out] StringBuilder buf)
4447 return readlinkat (dirfd, pathname, buf, (ulong) buf.Capacity);
4450 [DllImport (MPH, SetLastError=true,
4451 EntryPoint="Mono_Posix_Syscall_readlinkat")]
4452 private static extern long readlinkat (int dirfd,
4453 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4454 string pathname, byte[] buf, ulong bufsiz);
4456 public static long readlinkat (int dirfd, string pathname, byte[] buf)
4458 return readlinkat (dirfd, pathname, buf, (ulong) buf.LongLength);
4461 [DllImport (LIBC, SetLastError=true)]
4462 public static extern int symlinkat (
4463 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4464 string oldpath, int dirfd,
4465 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4468 [DllImport (LIBC, SetLastError=true, EntryPoint="unlinkat")]
4469 private static extern int sys_unlinkat (int dirfd,
4470 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4471 string pathname, int flags);
4473 public static int unlinkat (int dirfd, string pathname, AtFlags flags)
4475 int _flags = NativeConvert.FromAtFlags (flags);
4476 return sys_unlinkat (dirfd, pathname, _flags);
4480 #region <utime.h> Declarations
4482 // <utime.h> -- COMPLETE
4485 [DllImport (MPH, SetLastError=true,
4486 EntryPoint="Mono_Posix_Syscall_utime")]
4487 private static extern int sys_utime (
4488 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
4489 string filename, ref Utimbuf buf, int use_buf);
4491 public static int utime (string filename, ref Utimbuf buf)
4493 return sys_utime (filename, ref buf, 1);
4496 public static int utime (string filename)
4498 Utimbuf buf = new Utimbuf ();
4499 return sys_utime (filename, ref buf, 0);
4503 #region <sys/uio.h> Declarations
4505 // <sys/uio.h> -- COMPLETE
4509 // ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
4510 [DllImport (MPH, SetLastError=true,
4511 EntryPoint="Mono_Posix_Syscall_readv")]
4512 private static extern long sys_readv (int fd, Iovec[] iov, int iovcnt);
4514 public static long readv (int fd, Iovec[] iov)
4516 return sys_readv (fd, iov, iov.Length);
4520 // ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
4521 [DllImport (MPH, SetLastError=true,
4522 EntryPoint="Mono_Posix_Syscall_writev")]
4523 private static extern long sys_writev (int fd, Iovec[] iov, int iovcnt);
4525 public static long writev (int fd, Iovec[] iov)
4527 return sys_writev (fd, iov, iov.Length);
4531 // ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);
4532 [DllImport (MPH, SetLastError=true,
4533 EntryPoint="Mono_Posix_Syscall_preadv")]
4534 private static extern long sys_preadv (int fd, Iovec[] iov, int iovcnt, long offset);
4536 public static long preadv (int fd, Iovec[] iov, long offset)
4538 return sys_preadv (fd, iov, iov.Length, offset);
4542 // ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);
4543 [DllImport (MPH, SetLastError=true,
4544 EntryPoint="Mono_Posix_Syscall_pwritev")]
4545 private static extern long sys_pwritev (int fd, Iovec[] iov, int iovcnt, long offset);
4547 public static long pwritev (int fd, Iovec[] iov, long offset)
4549 return sys_pwritev (fd, iov, iov.Length, offset);
4553 #region <socket.h> Declarations
4559 // int socket(int domain, int type, int protocol);
4560 [DllImport (LIBC, SetLastError=true,
4561 EntryPoint="socket")]
4562 static extern int sys_socket (int domain, int type, int protocol);
4564 public static int socket (UnixAddressFamily domain, UnixSocketType type, UnixSocketFlags flags, UnixSocketProtocol protocol)
4566 var _domain = NativeConvert.FromUnixAddressFamily (domain);
4567 var _type = NativeConvert.FromUnixSocketType (type);
4568 var _flags = NativeConvert.FromUnixSocketFlags (flags);
4569 // protocol == 0 is a special case (uses default protocol)
4570 var _protocol = protocol == 0 ? 0 : NativeConvert.FromUnixSocketProtocol (protocol);
4572 return sys_socket (_domain, _type | _flags, _protocol);
4575 public static int socket (UnixAddressFamily domain, UnixSocketType type, UnixSocketProtocol protocol)
4577 return socket (domain, type, 0, protocol);
4581 // int socketpair(int domain, int type, int protocol, int sv[2]);
4582 [DllImport (MPH, SetLastError=true,
4583 EntryPoint="Mono_Posix_Syscall_socketpair")]
4584 static extern int sys_socketpair (int domain, int type, int protocol, out int socket1, out int socket2);
4586 public static int socketpair (UnixAddressFamily domain, UnixSocketType type, UnixSocketFlags flags, UnixSocketProtocol protocol, out int socket1, out int socket2)
4588 var _domain = NativeConvert.FromUnixAddressFamily (domain);
4589 var _type = NativeConvert.FromUnixSocketType (type);
4590 var _flags = NativeConvert.FromUnixSocketFlags (flags);
4591 // protocol == 0 is a special case (uses default protocol)
4592 var _protocol = protocol == 0 ? 0 : NativeConvert.FromUnixSocketProtocol (protocol);
4594 return sys_socketpair (_domain, _type | _flags, _protocol, out socket1, out socket2);
4597 public static int socketpair (UnixAddressFamily domain, UnixSocketType type, UnixSocketProtocol protocol, out int socket1, out int socket2)
4599 return socketpair (domain, type, 0, protocol, out socket1, out socket2);
4603 // int sockatmark(int sockfd);
4604 [DllImport (LIBC, SetLastError=true)]
4605 public static extern int sockatmark (int socket);
4608 // int listen(int sockfd, int backlog);
4609 [DllImport (LIBC, SetLastError=true)]
4610 public static extern int listen (int socket, int backlog);
4613 // int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
4614 [DllImport (MPH, SetLastError=true,
4615 EntryPoint="Mono_Posix_Syscall_getsockopt")]
4616 static extern unsafe int sys_getsockopt (int socket, int level, int option_name, void *option_value, ref long option_len);
4618 [DllImport (MPH, SetLastError=true,
4619 EntryPoint="Mono_Posix_Syscall_getsockopt_timeval")]
4620 static extern unsafe int sys_getsockopt_timeval (int socket, int level, int option_name, out Timeval option_value);
4622 [DllImport (MPH, SetLastError=true,
4623 EntryPoint="Mono_Posix_Syscall_getsockopt_linger")]
4624 static extern unsafe int sys_getsockopt_linger (int socket, int level, int option_name, out Linger option_value);
4626 public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, void *option_value, ref long option_len)
4628 var _level = NativeConvert.FromUnixSocketProtocol (level);
4629 var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
4630 return sys_getsockopt (socket, _level, _option_name, option_value, ref option_len);
4633 public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, IntPtr option_value, ref long option_len)
4635 return getsockopt (socket, level, option_name, (void*) option_value, ref option_len);
4638 public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, out int option_value)
4641 long size = sizeof (int);
4642 int ret = getsockopt (socket, level, option_name, &value, ref size);
4643 if (ret != -1 && size != sizeof (int)) {
4644 SetLastError (Errno.EINVAL);
4647 option_value = value;
4651 public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, byte[] option_value, ref long option_len)
4653 if (option_len > (option_value == null ? 0 : option_value.Length))
4654 throw new ArgumentOutOfRangeException ("option_len", "option_len > (option_value == null ? 0 : option_value.Length)");
4655 fixed (byte* ptr = option_value)
4656 return getsockopt (socket, level, option_name, ptr, ref option_len);
4659 public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, out Timeval option_value)
4661 var _level = NativeConvert.FromUnixSocketProtocol (level);
4662 var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
4663 return sys_getsockopt_timeval (socket, _level, _option_name, out option_value);
4666 public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, out Linger option_value)
4668 var _level = NativeConvert.FromUnixSocketProtocol (level);
4669 var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
4670 return sys_getsockopt_linger (socket, _level, _option_name, out option_value);
4674 // int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
4675 [DllImport (MPH, SetLastError=true,
4676 EntryPoint="Mono_Posix_Syscall_setsockopt")]
4677 static extern unsafe int sys_setsockopt (int socket, int level, int option_name, void *option_value, long option_len);
4679 [DllImport (MPH, SetLastError=true,
4680 EntryPoint="Mono_Posix_Syscall_setsockopt_timeval")]
4681 static extern unsafe int sys_setsockopt_timeval (int socket, int level, int option_name, ref Timeval option_value);
4683 [DllImport (MPH, SetLastError=true,
4684 EntryPoint="Mono_Posix_Syscall_setsockopt_linger")]
4685 static extern unsafe int sys_setsockopt_linger (int socket, int level, int option_name, ref Linger option_value);
4687 public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, void *option_value, long option_len)
4689 var _level = NativeConvert.FromUnixSocketProtocol (level);
4690 var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
4691 return sys_setsockopt (socket, _level, _option_name, option_value, option_len);
4694 public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, IntPtr option_value, long option_len)
4696 return setsockopt (socket, level, option_name, (void*) option_value, option_len);
4699 public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, int option_value)
4701 return setsockopt (socket, level, option_name, &option_value, sizeof (int));
4704 public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, byte[] option_value, long option_len)
4706 if (option_len > (option_value == null ? 0 : option_value.Length))
4707 throw new ArgumentOutOfRangeException ("option_len", "option_len > (option_value == null ? 0 : option_value.Length)");
4708 fixed (byte* ptr = option_value)
4709 return setsockopt (socket, level, option_name, ptr, option_len);
4712 public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, Timeval option_value)
4714 var _level = NativeConvert.FromUnixSocketProtocol (level);
4715 var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
4716 return sys_setsockopt_timeval (socket, _level, _option_name, ref option_value);
4719 public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, Linger option_value)
4721 var _level = NativeConvert.FromUnixSocketProtocol (level);
4722 var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
4723 return sys_setsockopt_linger (socket, _level, _option_name, ref option_value);
4727 // int shutdown(int sockfd, int how);
4728 [DllImport (LIBC, SetLastError=true,
4729 EntryPoint="shutdown")]
4730 static extern int sys_shutdown (int socket, int how);
4732 public static int shutdown (int socket, ShutdownOption how)
4734 var _how = NativeConvert.FromShutdownOption (how);
4735 return sys_shutdown (socket, _how);
4739 // ssize_t recv(int sockfd, void *buf, size_t len, int flags);
4740 [DllImport (MPH, SetLastError=true,
4741 EntryPoint="Mono_Posix_Syscall_recv")]
4742 static extern unsafe long sys_recv (int socket, void *buffer, ulong length, int flags);
4744 public static unsafe long recv (int socket, void *buffer, ulong length, MessageFlags flags)
4746 int _flags = NativeConvert.FromMessageFlags (flags);
4747 return sys_recv (socket, buffer, length, _flags);
4750 public static unsafe long recv (int socket, IntPtr buffer, ulong length, MessageFlags flags)
4752 return recv (socket, (void*) buffer, length, flags);
4755 public static unsafe long recv (int socket, byte[] buffer, ulong length, MessageFlags flags)
4757 if (length > (ulong) (buffer == null ? 0 : buffer.LongLength))
4758 throw new ArgumentOutOfRangeException ("length", "length > (buffer == null ? 0 : buffer.LongLength)");
4759 fixed (byte* ptr = buffer)
4760 return recv (socket, ptr, length, flags);
4764 // ssize_t send(int sockfd, const void *buf, size_t len, int flags);
4765 [DllImport (MPH, SetLastError=true,
4766 EntryPoint="Mono_Posix_Syscall_send")]
4767 static extern unsafe long sys_send (int socket, void *message, ulong length, int flags);
4769 public static unsafe long send (int socket, void *message, ulong length, MessageFlags flags)
4771 int _flags = NativeConvert.FromMessageFlags (flags);
4772 return sys_send (socket, message, length, _flags);
4775 public static unsafe long send (int socket, IntPtr message, ulong length, MessageFlags flags)
4777 return send (socket, (void*) message, length, flags);
4780 public static unsafe long send (int socket, byte[] message, ulong length, MessageFlags flags)
4782 if (length > (ulong) (message == null ? 0 : message.LongLength))
4783 throw new ArgumentOutOfRangeException ("length", "length > (message == null ? 0 : message.LongLength)");
4784 fixed (byte* ptr = message)
4785 return send (socket, ptr, length, flags);