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-2005 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.Runtime.InteropServices;
59 using System.Security;
61 using Mono.Unix.Native;
63 [assembly:Mono.Unix.Native.HeaderAttribute (
84 namespace Mono.Unix.Native {
89 [CLSCompliant (false)]
90 public enum SyslogOptions {
91 LOG_PID = 0x01, // log the pid with each message
92 LOG_CONS = 0x02, // log on the console if errors in sending
93 LOG_ODELAY = 0x04, // delay open until first syslog (default)
94 LOG_NDELAY = 0x08, // don't delay open
95 LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
96 LOG_PERROR = 0x20 // log to stderr as well
100 [CLSCompliant (false)]
101 public enum SyslogFacility {
112 LOG_AUTHPRIV = 10 << 3,
114 LOG_LOCAL0 = 16 << 3,
115 LOG_LOCAL1 = 17 << 3,
116 LOG_LOCAL2 = 18 << 3,
117 LOG_LOCAL3 = 19 << 3,
118 LOG_LOCAL4 = 20 << 3,
119 LOG_LOCAL5 = 21 << 3,
120 LOG_LOCAL6 = 22 << 3,
121 LOG_LOCAL7 = 23 << 3,
125 [CLSCompliant (false)]
126 public enum SyslogLevel {
127 LOG_EMERG = 0, // system is unusable
128 LOG_ALERT = 1, // action must be taken immediately
129 LOG_CRIT = 2, // critical conditions
130 LOG_ERR = 3, // warning conditions
131 LOG_WARNING = 4, // warning conditions
132 LOG_NOTICE = 5, // normal but significant condition
133 LOG_INFO = 6, // informational
134 LOG_DEBUG = 7 // debug-level messages
138 [CLSCompliant (false)]
139 public enum OpenFlags : int {
143 O_RDONLY = 0x00000000,
144 O_WRONLY = 0x00000001,
148 // Or-ed with zero or more of these
150 O_CREAT = 0x00000040,
152 O_NOCTTY = 0x00000100,
153 O_TRUNC = 0x00000200,
154 O_APPEND = 0x00000400,
155 O_NONBLOCK = 0x00000800,
159 // These are non-Posix. Using them will result in errors/exceptions on
160 // non-supported platforms.
162 // (For example, "C-wrapped" system calls -- calls with implementation in
163 // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
164 // calls will generate an exception in NativeConvert, as the value can't be
165 // converted on the target platform.)
168 O_NOFOLLOW = 0x00020000,
169 O_DIRECTORY = 0x00010000,
170 O_DIRECT = 0x00004000,
171 O_ASYNC = 0x00002000,
172 O_LARGEFILE = 0x00008000
177 [CLSCompliant (false)]
178 public enum FilePermissions : uint {
179 S_ISUID = 0x0800, // Set user ID on execution
180 S_ISGID = 0x0400, // Set group ID on execution
181 S_ISVTX = 0x0200, // Save swapped text after use (sticky).
182 S_IRUSR = 0x0100, // Read by owner
183 S_IWUSR = 0x0080, // Write by owner
184 S_IXUSR = 0x0040, // Execute by owner
185 S_IRGRP = 0x0020, // Read by group
186 S_IWGRP = 0x0010, // Write by group
187 S_IXGRP = 0x0008, // Execute by group
188 S_IROTH = 0x0004, // Read by other
189 S_IWOTH = 0x0002, // Write by other
190 S_IXOTH = 0x0001, // Execute by other
192 S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
193 S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
194 S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
195 ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
196 ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
197 DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
200 // Why these are held in "mode_t" is beyond me...
201 S_IFMT = 0xF000, // Bits which determine file type
202 S_IFDIR = 0x4000, // Directory
203 S_IFCHR = 0x2000, // Character device
204 S_IFBLK = 0x6000, // Block device
205 S_IFREG = 0x8000, // Regular file
206 S_IFIFO = 0x1000, // FIFO
207 S_IFLNK = 0xA000, // Symbolic link
208 S_IFSOCK = 0xC000, // Socket
212 [CLSCompliant (false)]
213 public enum FcntlCommand : int {
214 // Form /usr/include/bits/fcntl.h
215 F_DUPFD = 0, // Duplicate file descriptor.
216 F_GETFD = 1, // Get file descriptor flags.
217 F_SETFD = 2, // Set file descriptor flags.
218 F_GETFL = 3, // Get file status flags.
219 F_SETFL = 4, // Set file status flags.
220 F_GETLK = 12, // Get record locking info. [64]
221 F_SETLK = 13, // Set record locking info (non-blocking). [64]
222 F_SETLKW = 14, // Set record locking info (blocking). [64]
223 F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
224 F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
225 F_SETSIG = 10, // Set number of signal to be sent.
226 F_GETSIG = 11, // Get number of signal to be sent.
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_SYNCHRONOUS = 16, // Writes are synced at once
664 ST_MANDLOCK = 64, // Allow mandatory locks on an FS
665 ST_WRITE = 128, // Write on file/directory/symlink
666 ST_APPEND = 256, // Append-only file
667 ST_IMMUTABLE = 512, // Immutable file
668 ST_NOATIME = 1024, // Do not update access times
669 ST_NODIRATIME = 2048, // Do not update directory access times
673 [CLSCompliant (false)]
674 public enum MmapFlags : int {
675 MAP_SHARED = 0x01, // Share changes.
676 MAP_PRIVATE = 0x02, // Changes are private.
677 MAP_TYPE = 0x0f, // Mask for type of mapping.
678 MAP_FIXED = 0x10, // Interpret addr exactly.
680 MAP_ANONYMOUS = 0x20, // Don't use a file.
681 MAP_ANON = MAP_ANONYMOUS,
683 // These are Linux-specific.
684 MAP_GROWSDOWN = 0x00100, // Stack-like segment.
685 MAP_DENYWRITE = 0x00800, // ETXTBSY
686 MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
687 MAP_LOCKED = 0x02000, // Lock the mapping.
688 MAP_NORESERVE = 0x04000, // Don't check for reservations.
689 MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
690 MAP_NONBLOCK = 0x10000, // Do not block on IO.
694 [CLSCompliant (false)]
695 public enum MmapProts : int {
696 PROT_READ = 0x1, // Page can be read.
697 PROT_WRITE = 0x2, // Page can be written.
698 PROT_EXEC = 0x4, // Page can be executed.
699 PROT_NONE = 0x0, // Page can not be accessed.
700 PROT_GROWSDOWN = 0x01000000, // Extend change to start of
701 // growsdown vma (mprotect only).
702 PROT_GROWSUP = 0x02000000, // Extend change to start of
703 // growsup vma (mprotect only).
707 [CLSCompliant (false)]
708 public enum MsyncFlags : int {
709 MS_ASYNC = 0x1, // Sync memory asynchronously.
710 MS_SYNC = 0x4, // Synchronous memory sync.
711 MS_INVALIDATE = 0x2, // Invalidate the caches.
715 [CLSCompliant (false)]
716 public enum MlockallFlags : int {
717 MCL_CURRENT = 0x1, // Lock all currently mapped pages.
718 MCL_FUTURE = 0x2, // Lock all additions to address
722 [CLSCompliant (false)]
723 public enum MremapFlags : ulong {
724 MREMAP_MAYMOVE = 0x1,
736 [CLSCompliant (false)]
737 public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
738 [CLSCompliant (false)]
739 public SeekFlags l_whence; // How to interpret l_start
740 public /* off_t */ long l_start; // Starting offset for lock
741 public /* off_t */ long l_len; // Number of bytes to lock
742 public /* pid_t */ int l_pid; // PID of process blocking our lock (F_GETLK only)
744 public override int GetHashCode ()
746 return l_type.GetHashCode () ^ l_whence.GetHashCode () ^
747 l_start.GetHashCode () ^ l_len.GetHashCode () ^
748 l_pid.GetHashCode ();
751 public override bool Equals (object obj)
753 if (obj.GetType() != GetType())
755 Flock value = (Flock) obj;
756 return l_type == value.l_type && l_whence == value.l_whence &&
757 l_start == value.l_start && l_len == value.l_len &&
758 l_pid == value.l_pid;
761 public bool Equals (Flock value)
763 return l_type == value.l_type && l_whence == value.l_whence &&
764 l_start == value.l_start && l_len == value.l_len &&
765 l_pid == value.l_pid;
768 public static bool operator== (Flock lhs, Flock rhs)
770 return lhs.Equals (rhs);
773 public static bool operator!= (Flock lhs, Flock rhs)
775 return !lhs.Equals (rhs);
781 : IEquatable <Pollfd>
785 [CLSCompliant (false)]
786 public PollEvents events;
787 [CLSCompliant (false)]
788 public PollEvents revents;
790 public override int GetHashCode ()
792 return events.GetHashCode () ^ revents.GetHashCode ();
795 public override bool Equals (object obj)
797 if (obj == null || obj.GetType () != GetType ())
799 Pollfd value = (Pollfd) obj;
800 return value.events == events && value.revents == revents;
803 public bool Equals (Pollfd value)
805 return value.events == events && value.revents == revents;
808 public static bool operator== (Pollfd lhs, Pollfd rhs)
810 return lhs.Equals (rhs);
813 public static bool operator!= (Pollfd lhs, Pollfd rhs)
815 return !lhs.Equals (rhs);
824 [CLSCompliant (false)]
825 public /* dev_t */ ulong st_dev; // device
826 [CLSCompliant (false)]
827 public /* ino_t */ ulong st_ino; // inode
828 [CLSCompliant (false)]
829 public FilePermissions st_mode; // protection
830 [CLSCompliant (false)]
831 private uint _padding_; // padding for structure alignment
832 [CLSCompliant (false)]
833 public /* nlink_t */ ulong st_nlink; // number of hard links
834 [CLSCompliant (false)]
835 public /* uid_t */ uint st_uid; // user ID of owner
836 [CLSCompliant (false)]
837 public /* gid_t */ uint st_gid; // group ID of owner
838 [CLSCompliant (false)]
839 public /* dev_t */ ulong st_rdev; // device type (if inode device)
840 public /* off_t */ long st_size; // total size, in bytes
841 public /* blksize_t */ long st_blksize; // blocksize for filesystem I/O
842 public /* blkcnt_t */ long st_blocks; // number of blocks allocated
843 public /* time_t */ long st_atime; // time of last access
844 public /* time_t */ long st_mtime; // time of last modification
845 public /* time_t */ long st_ctime; // time of last status change
847 public override int GetHashCode ()
849 return st_dev.GetHashCode () ^
850 st_ino.GetHashCode () ^
851 st_mode.GetHashCode () ^
852 st_nlink.GetHashCode () ^
853 st_uid.GetHashCode () ^
854 st_gid.GetHashCode () ^
855 st_rdev.GetHashCode () ^
856 st_size.GetHashCode () ^
857 st_blksize.GetHashCode () ^
858 st_blocks.GetHashCode () ^
859 st_atime.GetHashCode () ^
860 st_mtime.GetHashCode () ^
861 st_ctime.GetHashCode ();
864 public override bool Equals (object obj)
866 if (obj == null || obj.GetType() != GetType ())
868 Stat value = (Stat) obj;
869 return value.st_dev == st_dev &&
870 value.st_ino == st_ino &&
871 value.st_mode == st_mode &&
872 value.st_nlink == st_nlink &&
873 value.st_uid == st_uid &&
874 value.st_gid == st_gid &&
875 value.st_rdev == st_rdev &&
876 value.st_size == st_size &&
877 value.st_blksize == st_blksize &&
878 value.st_blocks == st_blocks &&
879 value.st_atime == st_atime &&
880 value.st_mtime == st_mtime &&
881 value.st_ctime == st_ctime;
884 public bool Equals (Stat value)
886 return value.st_dev == st_dev &&
887 value.st_ino == st_ino &&
888 value.st_mode == st_mode &&
889 value.st_nlink == st_nlink &&
890 value.st_uid == st_uid &&
891 value.st_gid == st_gid &&
892 value.st_rdev == st_rdev &&
893 value.st_size == st_size &&
894 value.st_blksize == st_blksize &&
895 value.st_blocks == st_blocks &&
896 value.st_atime == st_atime &&
897 value.st_mtime == st_mtime &&
898 value.st_ctime == st_ctime;
901 public static bool operator== (Stat lhs, Stat rhs)
903 return lhs.Equals (rhs);
906 public static bool operator!= (Stat lhs, Stat rhs)
908 return !lhs.Equals (rhs);
912 [CLSCompliant (false)]
913 public struct Statvfs
915 : IEquatable <Statvfs>
918 public ulong f_bsize; // file system block size
919 public ulong f_frsize; // fragment size
920 public /* fsblkcnt_t */ ulong f_blocks; // size of fs in f_frsize units
921 public /* fsblkcnt_t */ ulong f_bfree; // # free blocks
922 public /* fsblkcnt_t */ ulong f_bavail; // # free blocks for non-root
923 public /* fsfilcnt_t */ ulong f_files; // # inodes
924 public /* fsfilcnt_t */ ulong f_ffree; // # free inodes
925 public /* fsfilcnt_t */ ulong f_favail; // # free inodes for non-root
926 public ulong f_fsid; // file system id
927 public MountFlags f_flag; // mount flags
928 public ulong f_namemax; // maximum filename length
930 public override int GetHashCode ()
932 return f_bsize.GetHashCode () ^
933 f_frsize.GetHashCode () ^
934 f_blocks.GetHashCode () ^
935 f_bfree.GetHashCode () ^
936 f_bavail.GetHashCode () ^
937 f_files.GetHashCode () ^
938 f_ffree.GetHashCode () ^
939 f_favail.GetHashCode () ^
940 f_fsid.GetHashCode () ^
941 f_flag.GetHashCode () ^
942 f_namemax.GetHashCode ();
945 public override bool Equals (object obj)
947 if (obj == null || obj.GetType() != GetType ())
949 Statvfs value = (Statvfs) obj;
950 return value.f_bsize == f_bsize &&
951 value.f_frsize == f_frsize &&
952 value.f_blocks == f_blocks &&
953 value.f_bfree == f_bfree &&
954 value.f_bavail == f_bavail &&
955 value.f_files == f_files &&
956 value.f_ffree == f_ffree &&
957 value.f_favail == f_favail &&
958 value.f_fsid == f_fsid &&
959 value.f_flag == f_flag &&
960 value.f_namemax == f_namemax;
963 public bool Equals (Statvfs value)
965 return value.f_bsize == f_bsize &&
966 value.f_frsize == f_frsize &&
967 value.f_blocks == f_blocks &&
968 value.f_bfree == f_bfree &&
969 value.f_bavail == f_bavail &&
970 value.f_files == f_files &&
971 value.f_ffree == f_ffree &&
972 value.f_favail == f_favail &&
973 value.f_fsid == f_fsid &&
974 value.f_flag == f_flag &&
975 value.f_namemax == f_namemax;
978 public static bool operator== (Statvfs lhs, Statvfs rhs)
980 return lhs.Equals (rhs);
983 public static bool operator!= (Statvfs lhs, Statvfs rhs)
985 return !lhs.Equals (rhs);
989 public struct Timeval
991 : IEquatable <Timeval>
994 public /* time_t */ long tv_sec; // seconds
995 public /* suseconds_t */ long tv_usec; // microseconds
997 public override int GetHashCode ()
999 return tv_sec.GetHashCode () ^ tv_usec.GetHashCode ();
1002 public override bool Equals (object obj)
1004 if (obj == null || obj.GetType () != GetType ())
1006 Timeval value = (Timeval) obj;
1007 return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
1010 public bool Equals (Timeval value)
1012 return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
1015 public static bool operator== (Timeval lhs, Timeval rhs)
1017 return lhs.Equals (rhs);
1020 public static bool operator!= (Timeval lhs, Timeval rhs)
1022 return !lhs.Equals (rhs);
1026 public struct Timezone
1028 : IEquatable <Timezone>
1031 public int tz_minuteswest; // minutes W of Greenwich
1032 private int tz_dsttime; // type of dst correction (OBSOLETE)
1034 public override int GetHashCode ()
1036 return tz_minuteswest.GetHashCode ();
1039 public override bool Equals (object obj)
1041 if (obj == null || obj.GetType () != GetType ())
1043 Timezone value = (Timezone) obj;
1044 return value.tz_minuteswest == tz_minuteswest;
1047 public bool Equals (Timezone value)
1049 return value.tz_minuteswest == tz_minuteswest;
1052 public static bool operator== (Timezone lhs, Timezone rhs)
1054 return lhs.Equals (rhs);
1057 public static bool operator!= (Timezone lhs, Timezone rhs)
1059 return !lhs.Equals (rhs);
1063 public struct Utimbuf
1065 : IEquatable <Utimbuf>
1068 public /* time_t */ long actime; // access time
1069 public /* time_t */ long modtime; // modification time
1071 public override int GetHashCode ()
1073 return actime.GetHashCode () ^ modtime.GetHashCode ();
1076 public override bool Equals (object obj)
1078 if (obj == null || obj.GetType () != GetType ())
1080 Utimbuf value = (Utimbuf) obj;
1081 return value.actime == actime && value.modtime == modtime;
1084 public bool Equals (Utimbuf value)
1086 return value.actime == actime && value.modtime == modtime;
1089 public static bool operator== (Utimbuf lhs, Utimbuf rhs)
1091 return lhs.Equals (rhs);
1094 public static bool operator!= (Utimbuf lhs, Utimbuf rhs)
1096 return !lhs.Equals (rhs);
1104 public sealed class Dirent
1106 : IEquatable <Dirent>
1109 [CLSCompliant (false)]
1110 public /* ino_t */ ulong d_ino;
1111 public /* off_t */ long d_off;
1112 [CLSCompliant (false)]
1113 public ushort d_reclen;
1115 public string d_name;
1117 public override int GetHashCode ()
1119 return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
1120 d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
1121 d_name.GetHashCode ();
1124 public override bool Equals (object obj)
1126 if (obj == null || GetType() != obj.GetType())
1128 Dirent d = (Dirent) obj;
1132 public bool Equals (Dirent value)
1136 return value.d_ino == d_ino && value.d_off == d_off &&
1137 value.d_reclen == d_reclen && value.d_type == d_type &&
1138 value.d_name == d_name;
1141 public override string ToString ()
1146 public static bool operator== (Dirent lhs, Dirent rhs)
1148 return Object.Equals (lhs, rhs);
1151 public static bool operator!= (Dirent lhs, Dirent rhs)
1153 return !Object.Equals (lhs, rhs);
1157 public sealed class Fstab
1159 : IEquatable <Fstab>
1162 public string fs_spec;
1163 public string fs_file;
1164 public string fs_vfstype;
1165 public string fs_mntops;
1166 public string fs_type;
1168 public int fs_passno;
1170 public override int GetHashCode ()
1172 return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
1173 fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
1174 fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
1177 public override bool Equals (object obj)
1179 if (obj == null || GetType() != obj.GetType())
1181 Fstab f = (Fstab) obj;
1185 public bool Equals (Fstab value)
1189 return value.fs_spec == fs_spec && value.fs_file == fs_file &&
1190 value.fs_vfstype == fs_vfstype && value.fs_mntops == fs_mntops &&
1191 value.fs_type == fs_type && value.fs_freq == fs_freq &&
1192 value.fs_passno == fs_passno;
1195 public override string ToString ()
1200 public static bool operator== (Fstab lhs, Fstab rhs)
1202 return Object.Equals (lhs, rhs);
1205 public static bool operator!= (Fstab lhs, Fstab rhs)
1207 return !Object.Equals (lhs, rhs);
1211 public sealed class Group
1213 : IEquatable <Group>
1216 public string gr_name;
1217 public string gr_passwd;
1218 [CLSCompliant (false)]
1219 public /* gid_t */ uint gr_gid;
1220 public string[] gr_mem;
1222 public override int GetHashCode ()
1225 for (int i = 0; i < gr_mem.Length; ++i)
1226 memhc ^= gr_mem[i].GetHashCode ();
1228 return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
1229 gr_gid.GetHashCode () ^ memhc;
1232 public override bool Equals (object obj)
1234 if (obj == null || GetType() != obj.GetType())
1236 Group g = (Group) obj;
1240 public bool Equals (Group value)
1244 if (value.gr_gid != gr_gid)
1246 if (value.gr_gid == gr_gid && value.gr_name == gr_name &&
1247 value.gr_passwd == gr_passwd) {
1248 if (value.gr_mem == gr_mem)
1250 if (value.gr_mem == null || gr_mem == null)
1252 if (value.gr_mem.Length != gr_mem.Length)
1254 for (int i = 0; i < gr_mem.Length; ++i)
1255 if (gr_mem[i] != value.gr_mem[i])
1262 // Generate string in /etc/group format
1263 public override string ToString ()
1265 StringBuilder sb = new StringBuilder ();
1266 sb.Append (gr_name).Append (":").Append (gr_passwd).Append (":");
1267 sb.Append (gr_gid).Append (":");
1268 GetMembers (sb, gr_mem);
1269 return sb.ToString ();
1272 private static void GetMembers (StringBuilder sb, string[] members)
1274 if (members.Length > 0)
1275 sb.Append (members[0]);
1276 for (int i = 1; i < members.Length; ++i) {
1278 sb.Append (members[i]);
1282 public static bool operator== (Group lhs, Group rhs)
1284 return Object.Equals (lhs, rhs);
1287 public static bool operator!= (Group lhs, Group rhs)
1289 return !Object.Equals (lhs, rhs);
1293 public sealed class Passwd
1295 : IEquatable <Passwd>
1298 public string pw_name;
1299 public string pw_passwd;
1300 [CLSCompliant (false)]
1301 public /* uid_t */ uint pw_uid;
1302 [CLSCompliant (false)]
1303 public /* gid_t */ uint pw_gid;
1304 public string pw_gecos;
1305 public string pw_dir;
1306 public string pw_shell;
1308 public override int GetHashCode ()
1310 return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
1311 pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
1312 pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
1313 pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
1316 public override bool Equals (object obj)
1318 if (obj == null || GetType() != obj.GetType())
1320 Passwd p = (Passwd) obj;
1324 public bool Equals (Passwd value)
1328 return value.pw_uid == pw_uid && value.pw_gid == pw_gid &&
1329 value.pw_name == pw_name && value.pw_passwd == pw_passwd &&
1330 value.pw_gecos == pw_gecos && value.pw_dir == pw_dir &&
1331 value.pw_shell == pw_shell;
1334 // Generate string in /etc/passwd format
1335 public override string ToString ()
1337 return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
1338 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
1341 public static bool operator== (Passwd lhs, Passwd rhs)
1343 return Object.Equals (lhs, rhs);
1346 public static bool operator!= (Passwd lhs, Passwd rhs)
1348 return !Object.Equals (lhs, rhs);
1353 // Convention: Functions *not* part of the standard C library AND part of
1354 // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
1356 // For example, the man page should be similar to:
1358 // CONFORMING TO (or CONFORMS TO)
1359 // XPG2, SUSv2, POSIX, etc.
1361 // BSD- and GNU-specific exports can also be placed here.
1363 // Non-POSIX/XPG/etc. functions can also be placed here if:
1364 // (a) They'd be likely to be covered in a Steven's-like book
1365 // (b) The functions would be present in libc.so (or equivalent).
1367 // If a function has its own library, that's a STRONG indicator that the
1368 // function should get a different binding, probably in its own assembly,
1369 // so that package management can work sanely. (That is, we'd like to avoid
1370 // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
1371 // run, and libFooLib.so doesn't exist. That would be confusing.)
1373 // The only methods in here should be:
1374 // (1) low-level functions
1375 // (2) "Trivial" function overloads. For example, if the parameters to a
1376 // function are related (e.g. getgroups(2))
1377 // (3) The return type SHOULD NOT be changed. If you want to provide a
1378 // convenience function with a nicer return type, place it into one of
1379 // the Mono.Unix.Unix* wrapper classes, and give it a .NET-styled name.
1380 // - EXCEPTION: No public functions should have a `void' return type.
1381 // `void' return types should be replaced with `int'.
1382 // Rationality: `void'-return functions typically require a
1383 // complicated call sequence, such as clear errno, then call, then
1384 // check errno to see if any errors occurred. This sequence can't
1385 // be done safely in managed code, as errno may change as part of
1386 // the P/Invoke mechanism.
1387 // Instead, add a MonoPosixHelper export which does:
1390 // return errno == 0 ? 0 : -1;
1391 // This lets managed code check the return value in the usual manner.
1392 // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
1393 // - If you're wrapping *broken* methods which make assumptions about
1394 // input data, such as that an argument refers to N bytes of data.
1395 // This is currently limited to cuserid(3) and encrypt(3).
1396 // - If you call functions which themselves generate exceptions.
1397 // This is the case for using NativeConvert, which will throw an
1398 // exception if an invalid/unsupported value is used.
1400 // Naming Conventions:
1401 // - Syscall method names should have the same name as the function being
1402 // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
1403 // consult the appropriate man page if necessary.
1404 // - Methods need not have the same arguments IF this simplifies or
1405 // permits correct usage. The current example is syslog, in which
1406 // syslog(3)'s single `priority' argument is split into SyslogFacility
1407 // and SyslogLevel arguments.
1408 // - Type names (structures, classes, enumerations) are always PascalCased.
1409 // - Enumerations are named as <MethodName><ArgumentName>, and are located
1410 // in the Mono.Unix.Native namespace. For readability, if ArgumentName
1411 // is "cmd", use Command instead. For example, fcntl(2) takes a
1412 // FcntlCommand argument. This naming convention is to provide an
1413 // assocation between an enumeration and where it should be used, and
1414 // allows a single method to accept multiple different enumerations
1415 // (see mmap(2), which takes MmapProts and MmapFlags).
1416 // - EXCEPTION: if an enumeration is shared between multiple different
1417 // methods, AND/OR the "obvious" enumeration name conflicts with an
1418 // existing .NET type, a more appropriate name should be used.
1419 // Example: FilePermissions
1420 // - EXCEPTION: [Flags] enumerations should get plural names to follow
1421 // .NET name guidelines. Usually this doesn't result in a change
1422 // (OpenFlags is the `flags' parameter for open(2)), but it can
1423 // (mmap(2) prot ==> MmapProts, access(2) mode ==> AccessModes).
1424 // - Enumerations should have the [Map] and (optional) [Flags] attributes.
1425 // [Map] is required for make-map to find the type and generate the
1426 // appropriate NativeConvert conversion functions.
1427 // - Enumeration contents should match the original Unix names. This helps
1428 // with documentation (the existing man pages are still useful), and is
1429 // required for use with the make-map generation program.
1430 // - Structure names should be the PascalCased version of the actual
1431 // structure name (struct flock ==> Flock). Structure members should
1432 // have the same names, or a (reasonably) portable subset (Dirent being
1433 // the poster child for questionable members).
1434 // - Whether the managed type should be a reference type (class) or a
1435 // value type (struct) should be determined on a case-by-case basis:
1436 // if you ever need to be able to use NULL for it (such as with Dirent,
1437 // Group, Passwd, as these are method return types and `null' is used
1438 // to signify the end), it should be a reference type; otherwise, use
1439 // your discretion, and keep any expected usage patterns in mind.
1440 // - Syscall should be a Single Point Of Truth (SPOT). There should be
1441 // only ONE way to do anything. By convention, the Linux function names
1442 // are used, but that need not always be the case (use your discretion).
1443 // It SHOULD NOT be required that developers know what platform they're
1444 // on, and choose among a set of similar functions. In short, anything
1445 // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
1446 // we can afford to clean things up whenever possible.
1448 // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
1449 // statvfs(2). MonoPosixHelper will "thunk" between the two,
1450 // exporting a statvfs that works across platforms.
1451 // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
1452 // instead provides getvfsent(3). MonoPosixHelper provides wrappers
1453 // to convert getvfsent(3) into Fstab data.
1454 // - Exception: If it isn't possible to cleanly wrap platforms, then the
1455 // method shouldn't be exported. The user will be expected to do their
1456 // own platform check and their own DllImports.
1457 // Examples: mount(2), umount(2), etc.
1458 // - Note: if a platform doesn't support a function AT ALL, the
1459 // MonoPosixHelper wrapper won't be compiled, resulting in a
1460 // EntryPointNotFoundException. This is also consistent with a missing
1461 // P/Invoke into libc.so.
1463 [CLSCompliant (false)]
1464 public sealed class Syscall : Stdlib
1466 new internal const string LIBC = "libc";
1468 private Syscall () {}
1474 // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
1475 // aio_return(3), aio_suspend(3), aio_write(3)
1477 // Then update UnixStream.BeginRead to use the aio* functions.
1480 #region <attr/xattr.h> Declarations
1482 // <attr/xattr.h> -- COMPLETE
1486 // int setxattr (const char *path, const char *name,
1487 // const void *value, size_t size, int flags);
1488 [DllImport (MPH, SetLastError=true,
1489 EntryPoint="Mono_Posix_Syscall_setxattr")]
1490 public static extern int setxattr (
1491 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1493 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1494 string name, byte[] value, ulong size, XattrFlags flags);
1496 public static int setxattr (string path, string name, byte [] value, ulong size)
1498 return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1501 public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
1503 return setxattr (path, name, value, (ulong) value.Length, flags);
1506 public static int setxattr (string path, string name, byte [] value)
1508 return setxattr (path, name, value, (ulong) value.Length);
1512 // int lsetxattr (const char *path, const char *name,
1513 // const void *value, size_t size, int flags);
1514 [DllImport (MPH, SetLastError=true,
1515 EntryPoint="Mono_Posix_Syscall_lsetxattr")]
1516 public static extern int lsetxattr (
1517 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1519 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1520 string name, byte[] value, ulong size, XattrFlags flags);
1522 public static int lsetxattr (string path, string name, byte [] value, ulong size)
1524 return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
1527 public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
1529 return lsetxattr (path, name, value, (ulong) value.Length, flags);
1532 public static int lsetxattr (string path, string name, byte [] value)
1534 return lsetxattr (path, name, value, (ulong) value.Length);
1538 // int fsetxattr (int fd, const char *name,
1539 // const void *value, size_t size, int flags);
1540 [DllImport (MPH, SetLastError=true,
1541 EntryPoint="Mono_Posix_Syscall_fsetxattr")]
1542 public static extern int fsetxattr (int fd,
1543 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1544 string name, byte[] value, ulong size, XattrFlags flags);
1546 public static int fsetxattr (int fd, string name, byte [] value, ulong size)
1548 return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
1551 public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
1553 return fsetxattr (fd, name, value, (ulong) value.Length, flags);
1556 public static int fsetxattr (int fd, string name, byte [] value)
1558 return fsetxattr (fd, name, value, (ulong) value.Length);
1562 // ssize_t getxattr (const char *path, const char *name,
1563 // void *value, size_t size);
1564 [DllImport (MPH, SetLastError=true,
1565 EntryPoint="Mono_Posix_Syscall_getxattr")]
1566 public static extern long getxattr (
1567 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1569 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1570 string name, byte[] value, ulong size);
1572 public static long getxattr (string path, string name, byte [] value)
1574 return getxattr (path, name, value, (ulong) value.Length);
1577 public static long getxattr (string path, string name, out byte [] value)
1580 long size = getxattr (path, name, value, 0);
1584 value = new byte [size];
1585 return getxattr (path, name, value, (ulong) size);
1589 // ssize_t lgetxattr (const char *path, const char *name,
1590 // void *value, size_t size);
1591 [DllImport (MPH, SetLastError=true,
1592 EntryPoint="Mono_Posix_Syscall_lgetxattr")]
1593 public static extern long lgetxattr (
1594 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1596 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1597 string name, byte[] value, ulong size);
1599 public static long lgetxattr (string path, string name, byte [] value)
1601 return lgetxattr (path, name, value, (ulong) value.Length);
1604 public static long lgetxattr (string path, string name, out byte [] value)
1607 long size = lgetxattr (path, name, value, 0);
1611 value = new byte [size];
1612 return lgetxattr (path, name, value, (ulong) size);
1616 // ssize_t fgetxattr (int fd, const char *name, void *value, size_t size);
1617 [DllImport (MPH, SetLastError=true,
1618 EntryPoint="Mono_Posix_Syscall_fgetxattr")]
1619 public static extern long fgetxattr (int fd,
1620 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1621 string name, byte[] value, ulong size);
1623 public static long fgetxattr (int fd, string name, byte [] value)
1625 return fgetxattr (fd, name, value, (ulong) value.Length);
1628 public static long fgetxattr (int fd, string name, out byte [] value)
1631 long size = fgetxattr (fd, name, value, 0);
1635 value = new byte [size];
1636 return fgetxattr (fd, name, value, (ulong) size);
1640 // ssize_t listxattr (const char *path, char *list, size_t size);
1641 [DllImport (MPH, SetLastError=true,
1642 EntryPoint="Mono_Posix_Syscall_listxattr")]
1643 public static extern long listxattr (
1644 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1645 string path, byte[] list, ulong size);
1647 // Slight modification: returns 0 on success, negative on error
1648 public static long listxattr (string path, Encoding encoding, out string [] values)
1651 long size = listxattr (path, null, 0);
1653 values = new string [0];
1657 byte[] list = new byte [size];
1658 long ret = listxattr (path, list, (ulong) size);
1662 GetValues (list, encoding, out values);
1666 public static long listxattr (string path, out string[] values)
1668 return listxattr (path, UnixEncoding.Instance, out values);
1671 private static void GetValues (byte[] list, Encoding encoding, out string[] values)
1674 for (int i = 0; i < list.Length; ++i)
1678 values = new string [num_values];
1681 for (int i = 0; i < list.Length; ++i) {
1682 if (list [i] == 0) {
1683 values [num_values++] = encoding.GetString (list, str_start, i - str_start);
1690 // ssize_t llistxattr (const char *path, char *list, size_t size);
1691 [DllImport (MPH, SetLastError=true,
1692 EntryPoint="Mono_Posix_Syscall_llistxattr")]
1693 public static extern long llistxattr (
1694 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1695 string path, byte[] list, ulong size);
1697 // Slight modification: returns 0 on success, negative on error
1698 public static long llistxattr (string path, Encoding encoding, out string [] values)
1701 long size = llistxattr (path, null, 0);
1703 values = new string [0];
1707 byte[] list = new byte [size];
1708 long ret = llistxattr (path, list, (ulong) size);
1712 GetValues (list, encoding, out values);
1716 public static long llistxattr (string path, out string[] values)
1718 return llistxattr (path, UnixEncoding.Instance, out values);
1722 // ssize_t flistxattr (int fd, char *list, size_t size);
1723 [DllImport (MPH, SetLastError=true,
1724 EntryPoint="Mono_Posix_Syscall_flistxattr")]
1725 public static extern long flistxattr (int fd, byte[] list, ulong size);
1727 // Slight modification: returns 0 on success, negative on error
1728 public static long flistxattr (int fd, Encoding encoding, out string [] values)
1731 long size = flistxattr (fd, null, 0);
1733 values = new string [0];
1737 byte[] list = new byte [size];
1738 long ret = flistxattr (fd, list, (ulong) size);
1742 GetValues (list, encoding, out values);
1746 public static long flistxattr (int fd, out string[] values)
1748 return flistxattr (fd, UnixEncoding.Instance, out values);
1751 [DllImport (MPH, SetLastError=true,
1752 EntryPoint="Mono_Posix_Syscall_removexattr")]
1753 public static extern int removexattr (
1754 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1756 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1759 [DllImport (MPH, SetLastError=true,
1760 EntryPoint="Mono_Posix_Syscall_lremovexattr")]
1761 public static extern int lremovexattr (
1762 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1764 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1767 [DllImport (MPH, SetLastError=true,
1768 EntryPoint="Mono_Posix_Syscall_fremovexattr")]
1769 public static extern int fremovexattr (int fd,
1770 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1774 #region <dirent.h> Declarations
1778 // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
1780 [DllImport (LIBC, SetLastError=true)]
1781 public static extern IntPtr opendir (
1782 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1785 [DllImport (LIBC, SetLastError=true)]
1786 public static extern int closedir (IntPtr dir);
1789 // void seekdir (DIR *dir, off_t offset);
1790 // Slight modification. Returns -1 on error, 0 on success.
1791 [DllImport (MPH, SetLastError=true,
1792 EntryPoint="Mono_Posix_Syscall_seekdir")]
1793 public static extern int seekdir (IntPtr dir, long offset);
1796 // off_t telldir(DIR *dir);
1797 [DllImport (MPH, SetLastError=true,
1798 EntryPoint="Mono_Posix_Syscall_telldir")]
1799 public static extern long telldir (IntPtr dir);
1801 [DllImport (MPH, SetLastError=true,
1802 EntryPoint="Mono_Posix_Syscall_rewinddir")]
1803 public static extern int rewinddir (IntPtr dir);
1805 private struct _Dirent {
1806 public /* ino_t */ ulong d_ino;
1807 public /* off_t */ long d_off;
1808 public ushort d_reclen;
1810 public IntPtr d_name;
1813 private static void CopyDirent (Dirent to, ref _Dirent from)
1816 to.d_ino = from.d_ino;
1817 to.d_off = from.d_off;
1818 to.d_reclen = from.d_reclen;
1819 to.d_type = from.d_type;
1820 to.d_name = UnixMarshal.PtrToString (from.d_name);
1823 Stdlib.free (from.d_name);
1824 from.d_name = IntPtr.Zero;
1828 internal static object readdir_lock = new object ();
1830 [DllImport (MPH, SetLastError=true,
1831 EntryPoint="Mono_Posix_Syscall_readdir")]
1832 private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
1834 public static Dirent readdir (IntPtr dir)
1838 lock (readdir_lock) {
1839 r = sys_readdir (dir, out dentry);
1843 Dirent d = new Dirent ();
1844 CopyDirent (d, ref dentry);
1848 [DllImport (MPH, SetLastError=true,
1849 EntryPoint="Mono_Posix_Syscall_readdir_r")]
1850 private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
1852 public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
1858 entry.d_name = null;
1861 int r = sys_readdir_r (dirp, out _d, out result);
1863 if (r == 0 && result != IntPtr.Zero) {
1864 CopyDirent (entry, ref _d);
1870 [DllImport (LIBC, SetLastError=true)]
1871 public static extern int dirfd (IntPtr dir);
1874 #region <fcntl.h> Declarations
1876 // <fcntl.h> -- COMPLETE
1879 [DllImport (MPH, SetLastError=true,
1880 EntryPoint="Mono_Posix_Syscall_fcntl")]
1881 public static extern int fcntl (int fd, FcntlCommand cmd);
1883 [DllImport (MPH, SetLastError=true,
1884 EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
1885 public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
1887 public static int fcntl (int fd, FcntlCommand cmd, DirectoryNotifyFlags arg)
1889 if (cmd != FcntlCommand.F_NOTIFY) {
1890 SetLastError (Errno.EINVAL);
1893 long _arg = NativeConvert.FromDirectoryNotifyFlags (arg);
1894 return fcntl (fd, FcntlCommand.F_NOTIFY, _arg);
1897 [DllImport (MPH, SetLastError=true,
1898 EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
1899 public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
1901 [DllImport (MPH, SetLastError=true,
1902 EntryPoint="Mono_Posix_Syscall_open")]
1903 public static extern int open (
1904 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1905 string pathname, OpenFlags flags);
1908 // int open(const char *pathname, int flags, mode_t mode);
1909 [DllImport (MPH, SetLastError=true,
1910 EntryPoint="Mono_Posix_Syscall_open_mode")]
1911 public static extern int open (
1912 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1913 string pathname, OpenFlags flags, FilePermissions mode);
1916 // int creat(const char *pathname, mode_t mode);
1917 [DllImport (MPH, SetLastError=true,
1918 EntryPoint="Mono_Posix_Syscall_creat")]
1919 public static extern int creat (
1920 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
1921 string pathname, FilePermissions mode);
1924 // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
1925 [DllImport (MPH, SetLastError=true,
1926 EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
1927 public static extern int posix_fadvise (int fd, long offset,
1928 long len, PosixFadviseAdvice advice);
1930 // posix_fallocate(P)
1931 // int posix_fallocate(int fd, off_t offset, size_t len);
1932 [DllImport (MPH, SetLastError=true,
1933 EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
1934 public static extern int posix_fallocate (int fd, long offset, ulong len);
1937 #region <fstab.h> Declarations
1939 // <fstab.h> -- COMPLETE
1941 private struct _Fstab {
1942 public IntPtr fs_spec;
1943 public IntPtr fs_file;
1944 public IntPtr fs_vfstype;
1945 public IntPtr fs_mntops;
1946 public IntPtr fs_type;
1948 public int fs_passno;
1949 public IntPtr _fs_buf_;
1952 private static void CopyFstab (Fstab to, ref _Fstab from)
1955 to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
1956 to.fs_file = UnixMarshal.PtrToString (from.fs_file);
1957 to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
1958 to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
1959 to.fs_type = UnixMarshal.PtrToString (from.fs_type);
1960 to.fs_freq = from.fs_freq;
1961 to.fs_passno = from.fs_passno;
1964 Stdlib.free (from._fs_buf_);
1965 from._fs_buf_ = IntPtr.Zero;
1969 internal static object fstab_lock = new object ();
1971 [DllImport (MPH, SetLastError=true,
1972 EntryPoint="Mono_Posix_Syscall_endfsent")]
1973 private static extern int sys_endfsent ();
1975 public static int endfsent ()
1978 return sys_endfsent ();
1982 [DllImport (MPH, SetLastError=true,
1983 EntryPoint="Mono_Posix_Syscall_getfsent")]
1984 private static extern int sys_getfsent (out _Fstab fs);
1986 public static Fstab getfsent ()
1991 r = sys_getfsent (out fsbuf);
1995 Fstab fs = new Fstab ();
1996 CopyFstab (fs, ref fsbuf);
2000 [DllImport (MPH, SetLastError=true,
2001 EntryPoint="Mono_Posix_Syscall_getfsfile")]
2002 private static extern int sys_getfsfile (
2003 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2004 string mount_point, out _Fstab fs);
2006 public static Fstab getfsfile (string mount_point)
2011 r = sys_getfsfile (mount_point, out fsbuf);
2015 Fstab fs = new Fstab ();
2016 CopyFstab (fs, ref fsbuf);
2020 [DllImport (MPH, SetLastError=true,
2021 EntryPoint="Mono_Posix_Syscall_getfsspec")]
2022 private static extern int sys_getfsspec (
2023 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2024 string special_file, out _Fstab fs);
2026 public static Fstab getfsspec (string special_file)
2031 r = sys_getfsspec (special_file, out fsbuf);
2035 Fstab fs = new Fstab ();
2036 CopyFstab (fs, ref fsbuf);
2040 [DllImport (MPH, SetLastError=true,
2041 EntryPoint="Mono_Posix_Syscall_setfsent")]
2042 private static extern int sys_setfsent ();
2044 public static int setfsent ()
2047 return sys_setfsent ();
2053 #region <grp.h> Declarations
2057 // TODO: putgrent(3), fgetgrent_r(), getgrouplist(2), initgroups(3)
2060 // int setgroups (size_t size, const gid_t *list);
2061 [DllImport (MPH, SetLastError=true,
2062 EntryPoint="Mono_Posix_Syscall_setgroups")]
2063 public static extern int setgroups (ulong size, uint[] list);
2065 public static int setgroups (uint [] list)
2067 return setgroups ((ulong) list.Length, list);
2070 private struct _Group
2072 public IntPtr gr_name;
2073 public IntPtr gr_passwd;
2074 public /* gid_t */ uint gr_gid;
2075 public int _gr_nmem_;
2076 public IntPtr gr_mem;
2077 public IntPtr _gr_buf_;
2080 private static void CopyGroup (Group to, ref _Group from)
2083 to.gr_gid = from.gr_gid;
2084 to.gr_name = UnixMarshal.PtrToString (from.gr_name);
2085 to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
2086 to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
2089 Stdlib.free (from.gr_mem);
2090 Stdlib.free (from._gr_buf_);
2091 from.gr_mem = IntPtr.Zero;
2092 from._gr_buf_ = IntPtr.Zero;
2096 internal static object grp_lock = new object ();
2098 [DllImport (MPH, SetLastError=true,
2099 EntryPoint="Mono_Posix_Syscall_getgrnam")]
2100 private static extern int sys_getgrnam (string name, out _Group group);
2102 public static Group getgrnam (string name)
2107 r = sys_getgrnam (name, out group);
2111 Group gr = new Group ();
2112 CopyGroup (gr, ref group);
2117 // struct group *getgrgid(gid_t gid);
2118 [DllImport (MPH, SetLastError=true,
2119 EntryPoint="Mono_Posix_Syscall_getgrgid")]
2120 private static extern int sys_getgrgid (uint uid, out _Group group);
2122 public static Group getgrgid (uint uid)
2127 r = sys_getgrgid (uid, out group);
2131 Group gr = new Group ();
2132 CopyGroup (gr, ref group);
2136 [DllImport (MPH, SetLastError=true,
2137 EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
2138 private static extern int sys_getgrnam_r (
2139 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2140 string name, out _Group grbuf, out IntPtr grbufp);
2142 public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
2147 int r = sys_getgrnam_r (name, out group, out _grbufp);
2148 if (r == 0 && _grbufp != IntPtr.Zero) {
2149 CopyGroup (grbuf, ref group);
2156 // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
2157 // size_t buflen, struct group **gbufp);
2158 [DllImport (MPH, SetLastError=true,
2159 EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
2160 private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
2162 public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
2167 int r = sys_getgrgid_r (uid, out group, out _grbufp);
2168 if (r == 0 && _grbufp != IntPtr.Zero) {
2169 CopyGroup (grbuf, ref group);
2175 [DllImport (MPH, SetLastError=true,
2176 EntryPoint="Mono_Posix_Syscall_getgrent")]
2177 private static extern int sys_getgrent (out _Group grbuf);
2179 public static Group getgrent ()
2184 r = sys_getgrent (out group);
2188 Group gr = new Group();
2189 CopyGroup (gr, ref group);
2193 [DllImport (MPH, SetLastError=true,
2194 EntryPoint="Mono_Posix_Syscall_setgrent")]
2195 private static extern int sys_setgrent ();
2197 public static int setgrent ()
2200 return sys_setgrent ();
2204 [DllImport (MPH, SetLastError=true,
2205 EntryPoint="Mono_Posix_Syscall_endgrent")]
2206 private static extern int sys_endgrent ();
2208 public static int endgrent ()
2211 return sys_endgrent ();
2215 [DllImport (MPH, SetLastError=true,
2216 EntryPoint="Mono_Posix_Syscall_fgetgrent")]
2217 private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
2219 public static Group fgetgrent (IntPtr stream)
2224 r = sys_fgetgrent (stream, out group);
2228 Group gr = new Group ();
2229 CopyGroup (gr, ref group);
2234 #region <pwd.h> Declarations
2238 // TODO: putpwent(3), fgetpwent_r()
2240 // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
2242 private struct _Passwd
2244 public IntPtr pw_name;
2245 public IntPtr pw_passwd;
2246 public /* uid_t */ uint pw_uid;
2247 public /* gid_t */ uint pw_gid;
2248 public IntPtr pw_gecos;
2249 public IntPtr pw_dir;
2250 public IntPtr pw_shell;
2251 public IntPtr _pw_buf_;
2254 private static void CopyPasswd (Passwd to, ref _Passwd from)
2257 to.pw_name = UnixMarshal.PtrToString (from.pw_name);
2258 to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
2259 to.pw_uid = from.pw_uid;
2260 to.pw_gid = from.pw_gid;
2261 to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
2262 to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
2263 to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
2266 Stdlib.free (from._pw_buf_);
2267 from._pw_buf_ = IntPtr.Zero;
2271 internal static object pwd_lock = new object ();
2273 [DllImport (MPH, SetLastError=true,
2274 EntryPoint="Mono_Posix_Syscall_getpwnam")]
2275 private static extern int sys_getpwnam (string name, out _Passwd passwd);
2277 public static Passwd getpwnam (string name)
2282 r = sys_getpwnam (name, out passwd);
2286 Passwd pw = new Passwd ();
2287 CopyPasswd (pw, ref passwd);
2292 // struct passwd *getpwnuid(uid_t uid);
2293 [DllImport (MPH, SetLastError=true,
2294 EntryPoint="Mono_Posix_Syscall_getpwuid")]
2295 private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
2297 public static Passwd getpwuid (uint uid)
2302 r = sys_getpwuid (uid, out passwd);
2306 Passwd pw = new Passwd ();
2307 CopyPasswd (pw, ref passwd);
2311 [DllImport (MPH, SetLastError=true,
2312 EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
2313 private static extern int sys_getpwnam_r (
2314 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2315 string name, out _Passwd pwbuf, out IntPtr pwbufp);
2317 public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
2322 int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
2323 if (r == 0 && _pwbufp != IntPtr.Zero) {
2324 CopyPasswd (pwbuf, ref passwd);
2331 // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
2332 // buflen, struct passwd **pwbufp);
2333 [DllImport (MPH, SetLastError=true,
2334 EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
2335 private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
2337 public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
2342 int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
2343 if (r == 0 && _pwbufp != IntPtr.Zero) {
2344 CopyPasswd (pwbuf, ref passwd);
2350 [DllImport (MPH, SetLastError=true,
2351 EntryPoint="Mono_Posix_Syscall_getpwent")]
2352 private static extern int sys_getpwent (out _Passwd pwbuf);
2354 public static Passwd getpwent ()
2359 r = sys_getpwent (out passwd);
2363 Passwd pw = new Passwd ();
2364 CopyPasswd (pw, ref passwd);
2368 [DllImport (MPH, SetLastError=true,
2369 EntryPoint="Mono_Posix_Syscall_setpwent")]
2370 private static extern int sys_setpwent ();
2372 public static int setpwent ()
2375 return sys_setpwent ();
2379 [DllImport (MPH, SetLastError=true,
2380 EntryPoint="Mono_Posix_Syscall_endpwent")]
2381 private static extern int sys_endpwent ();
2383 public static int endpwent ()
2386 return sys_endpwent ();
2390 [DllImport (MPH, SetLastError=true,
2391 EntryPoint="Mono_Posix_Syscall_fgetpwent")]
2392 private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
2394 public static Passwd fgetpwent (IntPtr stream)
2399 r = sys_fgetpwent (stream, out passwd);
2403 Passwd pw = new Passwd ();
2404 CopyPasswd (pw, ref passwd);
2409 #region <signal.h> Declarations
2413 [DllImport (MPH, SetLastError=true,
2414 EntryPoint="Mono_Posix_Syscall_psignal")]
2415 private static extern int psignal (int sig, string s);
2417 public static int psignal (Signum sig, string s)
2419 int signum = NativeConvert.FromSignum (sig);
2420 return psignal (signum, s);
2424 // int kill(pid_t pid, int sig);
2425 [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
2426 private static extern int sys_kill (int pid, int sig);
2428 public static int kill (int pid, Signum sig)
2430 int _sig = NativeConvert.FromSignum (sig);
2431 return sys_kill (pid, _sig);
2434 private static object signal_lock = new object ();
2436 [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
2437 private static extern IntPtr sys_strsignal (int sig);
2439 public static string strsignal (Signum sig)
2441 int s = NativeConvert.FromSignum (sig);
2442 lock (signal_lock) {
2443 IntPtr r = sys_strsignal (s);
2444 return UnixMarshal.PtrToString (r);
2448 // TODO: sigaction(2)
2449 // TODO: sigsuspend(2)
2450 // TODO: sigpending(2)
2454 #region <stdio.h> Declarations
2458 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
2459 private static extern int _L_ctermid ();
2461 public static readonly int L_ctermid = _L_ctermid ();
2463 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
2464 private static extern int _L_cuserid ();
2466 public static readonly int L_cuserid = _L_cuserid ();
2468 internal static object getlogin_lock = new object ();
2470 [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
2471 private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
2473 [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
2474 "DO NOT USE cuserid().\n" +
2475 "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
2476 public static string cuserid (StringBuilder @string)
2478 if (@string.Capacity < L_cuserid) {
2479 throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
2481 lock (getlogin_lock) {
2482 IntPtr r = sys_cuserid (@string);
2483 return UnixMarshal.PtrToString (r);
2489 #region <stdlib.h> Declarations
2493 [DllImport (LIBC, SetLastError=true)]
2494 public static extern int mkstemp (StringBuilder template);
2496 [DllImport (LIBC, SetLastError=true)]
2497 public static extern int ttyslot ();
2499 [Obsolete ("This is insecure and should not be used", true)]
2500 public static int setkey (string key)
2502 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
2507 #region <string.h> Declarations
2513 // int strerror_r(int errnum, char *buf, size_t n);
2514 [DllImport (MPH, SetLastError=true,
2515 EntryPoint="Mono_Posix_Syscall_strerror_r")]
2516 private static extern int sys_strerror_r (int errnum,
2517 [Out] StringBuilder buf, ulong n);
2519 public static int strerror_r (Errno errnum, StringBuilder buf, ulong n)
2521 int e = NativeConvert.FromErrno (errnum);
2522 return sys_strerror_r (e, buf, n);
2525 public static int strerror_r (Errno errnum, StringBuilder buf)
2527 return strerror_r (errnum, buf, (ulong) buf.Capacity);
2532 #region <sys/mman.h> Declarations
2538 // int posix_madvise(void *addr, size_t len, int advice);
2539 [DllImport (MPH, SetLastError=true,
2540 EntryPoint="Mono_Posix_Syscall_posix_madvise")]
2541 public static extern int posix_madvise (IntPtr addr, ulong len,
2542 PosixMadviseAdvice advice);
2544 public static readonly IntPtr MAP_FAILED = unchecked((IntPtr)(-1));
2546 [DllImport (MPH, SetLastError=true,
2547 EntryPoint="Mono_Posix_Syscall_mmap")]
2548 public static extern IntPtr mmap (IntPtr start, ulong length,
2549 MmapProts prot, MmapFlags flags, int fd, long offset);
2551 [DllImport (MPH, SetLastError=true,
2552 EntryPoint="Mono_Posix_Syscall_munmap")]
2553 public static extern int munmap (IntPtr start, ulong length);
2555 [DllImport (MPH, SetLastError=true,
2556 EntryPoint="Mono_Posix_Syscall_mprotect")]
2557 public static extern int mprotect (IntPtr start, ulong len, MmapProts prot);
2559 [DllImport (MPH, SetLastError=true,
2560 EntryPoint="Mono_Posix_Syscall_msync")]
2561 public static extern int msync (IntPtr start, ulong len, MsyncFlags flags);
2563 [DllImport (MPH, SetLastError=true,
2564 EntryPoint="Mono_Posix_Syscall_mlock")]
2565 public static extern int mlock (IntPtr start, ulong len);
2567 [DllImport (MPH, SetLastError=true,
2568 EntryPoint="Mono_Posix_Syscall_munlock")]
2569 public static extern int munlock (IntPtr start, ulong len);
2571 [DllImport (LIBC, SetLastError=true, EntryPoint="mlockall")]
2572 private static extern int sys_mlockall (int flags);
2574 public static int mlockall (MlockallFlags flags)
2576 int _flags = NativeConvert.FromMlockallFlags (flags);
2577 return sys_mlockall (_flags);
2580 [DllImport (LIBC, SetLastError=true)]
2581 public static extern int munlockall ();
2583 [DllImport (MPH, SetLastError=true,
2584 EntryPoint="Mono_Posix_Syscall_mremap")]
2585 public static extern IntPtr mremap (IntPtr old_address, ulong old_size,
2586 ulong new_size, MremapFlags flags);
2588 [DllImport (MPH, SetLastError=true,
2589 EntryPoint="Mono_Posix_Syscall_mincore")]
2590 public static extern int mincore (IntPtr start, ulong length, byte[] vec);
2592 [DllImport (MPH, SetLastError=true,
2593 EntryPoint="Mono_Posix_Syscall_remap_file_pages")]
2594 public static extern int remap_file_pages (IntPtr start, ulong size,
2595 MmapProts prot, long pgoff, MmapFlags flags);
2599 #region <sys/poll.h> Declarations
2601 // <sys/poll.h> -- COMPLETE
2604 private struct _pollfd {
2606 public short events;
2607 public short revents;
2610 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
2611 private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
2613 public static int poll (Pollfd [] fds, uint nfds, int timeout)
2615 if (fds.Length < nfds)
2616 throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
2618 _pollfd[] send = new _pollfd[nfds];
2620 for (int i = 0; i < send.Length; i++) {
2621 send [i].fd = fds [i].fd;
2622 send [i].events = NativeConvert.FromPollEvents (fds [i].events);
2625 int r = sys_poll (send, nfds, timeout);
2627 for (int i = 0; i < send.Length; i++) {
2628 fds [i].revents = NativeConvert.ToPollEvents (send [i].revents);
2634 public static int poll (Pollfd [] fds, int timeout)
2636 return poll (fds, (uint) fds.Length, timeout);
2649 // TODO: setrlimit(2)
2650 // TODO: getrlimit(2)
2651 // TODO: getrusage(2)
2655 #region <sys/sendfile.h> Declarations
2657 // <sys/sendfile.h> -- COMPLETE
2660 [DllImport (MPH, SetLastError=true,
2661 EntryPoint="Mono_Posix_Syscall_sendfile")]
2662 public static extern long sendfile (int out_fd, int in_fd,
2663 ref long offset, ulong count);
2667 #region <sys/stat.h> Declarations
2669 // <sys/stat.h> -- COMPLETE
2671 [DllImport (MPH, SetLastError=true,
2672 EntryPoint="Mono_Posix_Syscall_stat")]
2673 public static extern int stat (
2674 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2675 string file_name, out Stat buf);
2677 [DllImport (MPH, SetLastError=true,
2678 EntryPoint="Mono_Posix_Syscall_fstat")]
2679 public static extern int fstat (int filedes, out Stat buf);
2681 [DllImport (MPH, SetLastError=true,
2682 EntryPoint="Mono_Posix_Syscall_lstat")]
2683 public static extern int lstat (
2684 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2685 string file_name, out Stat buf);
2688 // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
2689 // All take FilePermissions
2692 // int chmod(const char *path, mode_t mode);
2693 [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
2694 private static extern int sys_chmod (
2695 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2696 string path, uint mode);
2698 public static int chmod (string path, FilePermissions mode)
2700 uint _mode = NativeConvert.FromFilePermissions (mode);
2701 return sys_chmod (path, _mode);
2705 // int chmod(int filedes, mode_t mode);
2706 [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
2707 private static extern int sys_fchmod (int filedes, uint mode);
2709 public static int fchmod (int filedes, FilePermissions mode)
2711 uint _mode = NativeConvert.FromFilePermissions (mode);
2712 return sys_fchmod (filedes, _mode);
2716 // mode_t umask(mode_t mask);
2717 [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
2718 private static extern uint sys_umask (uint mask);
2720 public static FilePermissions umask (FilePermissions mask)
2722 uint _mask = NativeConvert.FromFilePermissions (mask);
2723 uint r = sys_umask (_mask);
2724 return NativeConvert.ToFilePermissions (r);
2728 // int mkdir(const char *pathname, mode_t mode);
2729 [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
2730 private static extern int sys_mkdir (
2731 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2732 string oldpath, uint mode);
2734 public static int mkdir (string oldpath, FilePermissions mode)
2736 uint _mode = NativeConvert.FromFilePermissions (mode);
2737 return sys_mkdir (oldpath, _mode);
2741 // int mknod (const char *pathname, mode_t mode, dev_t dev);
2742 [DllImport (MPH, SetLastError=true,
2743 EntryPoint="Mono_Posix_Syscall_mknod")]
2744 public static extern int mknod (
2745 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2746 string pathname, FilePermissions mode, ulong dev);
2749 // int mkfifo(const char *pathname, mode_t mode);
2750 [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
2751 private static extern int sys_mkfifo (
2752 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2753 string pathname, uint mode);
2755 public static int mkfifo (string pathname, FilePermissions mode)
2757 uint _mode = NativeConvert.FromFilePermissions (mode);
2758 return sys_mkfifo (pathname, _mode);
2763 #region <sys/stat.h> Declarations
2768 [DllImport (MPH, SetLastError=true,
2769 EntryPoint="Mono_Posix_Syscall_statvfs")]
2770 public static extern int statvfs (
2771 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2772 string path, out Statvfs buf);
2774 [DllImport (MPH, SetLastError=true,
2775 EntryPoint="Mono_Posix_Syscall_fstatvfs")]
2776 public static extern int fstatvfs (int fd, out Statvfs buf);
2780 #region <sys/time.h> Declarations
2784 // TODO: adjtime(), getitimer(2), setitimer(2)
2786 [DllImport (MPH, SetLastError=true,
2787 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2788 public static extern int gettimeofday (out Timeval tv, out Timezone tz);
2790 [DllImport (MPH, SetLastError=true,
2791 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2792 private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
2794 public static int gettimeofday (out Timeval tv)
2796 return gettimeofday (out tv, IntPtr.Zero);
2799 [DllImport (MPH, SetLastError=true,
2800 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2801 private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
2803 public static int gettimeofday (out Timezone tz)
2805 return gettimeofday (IntPtr.Zero, out tz);
2808 [DllImport (MPH, SetLastError=true,
2809 EntryPoint="Mono_Posix_Syscall_settimeofday")]
2810 public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
2812 [DllImport (MPH, SetLastError=true,
2813 EntryPoint="Mono_Posix_Syscall_gettimeofday")]
2814 private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
2816 public static int settimeofday (ref Timeval tv)
2818 return settimeofday (ref tv, IntPtr.Zero);
2821 [DllImport (MPH, SetLastError=true,
2822 EntryPoint="Mono_Posix_Syscall_utimes")]
2823 private static extern int sys_utimes (
2824 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2825 string filename, Timeval[] tvp);
2827 public static int utimes (string filename, Timeval[] tvp)
2829 if (tvp != null && tvp.Length != 2) {
2830 SetLastError (Errno.EINVAL);
2833 return sys_utimes (filename, tvp);
2836 [DllImport (MPH, SetLastError=true,
2837 EntryPoint="Mono_Posix_Syscall_lutimes")]
2838 private static extern int sys_lutimes (
2839 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
2840 string filename, Timeval[] tvp);
2842 public static int lutimes (string filename, Timeval[] tvp)
2844 if (tvp != null && tvp.Length != 2) {
2845 SetLastError (Errno.EINVAL);
2848 return sys_lutimes (filename, tvp);
2851 [DllImport (MPH, SetLastError=true,
2852 EntryPoint="Mono_Posix_Syscall_futimes")]
2853 private static extern int sys_futimes (int fd, Timeval[] tvp);
2855 public static int futimes (int fd, Timeval[] tvp)
2857 if (tvp != null && tvp.Length != 2) {
2858 SetLastError (Errno.EINVAL);
2861 return sys_futimes (fd, tvp);
2884 #region <sys/wait.h> Declarations
2890 // pid_t wait(int *status);
2891 [DllImport (LIBC, SetLastError=true)]
2892 public static extern int wait (out int status);
2895 // pid_t waitpid(pid_t pid, int *status, int options);
2896 [DllImport (LIBC, SetLastError=true)]
2897 private static extern int waitpid (int pid, out int status, int options);
2899 public static int waitpid (int pid, out int status, WaitOptions options)
2901 int _options = NativeConvert.FromWaitOptions (options);
2902 return waitpid (pid, out status, _options);
2905 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
2906 private static extern int _WIFEXITED (int status);
2908 public static bool WIFEXITED (int status)
2910 return _WIFEXITED (status) != 0;
2913 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
2914 public static extern int WEXITSTATUS (int status);
2916 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
2917 private static extern int _WIFSIGNALED (int status);
2919 public static bool WIFSIGNALED (int status)
2921 return _WIFSIGNALED (status) != 0;
2924 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
2925 private static extern int _WTERMSIG (int status);
2927 public static Signum WTERMSIG (int status)
2929 int r = _WTERMSIG (status);
2930 return NativeConvert.ToSignum (r);
2933 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
2934 private static extern int _WIFSTOPPED (int status);
2936 public static bool WIFSTOPPED (int status)
2938 return _WIFSTOPPED (status) != 0;
2941 [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
2942 private static extern int _WSTOPSIG (int status);
2944 public static Signum WSTOPSIG (int status)
2946 int r = _WSTOPSIG (status);
2947 return NativeConvert.ToSignum (r);
2956 #region <syslog.h> Declarations
2961 [DllImport (MPH, SetLastError=true,
2962 EntryPoint="Mono_Posix_Syscall_openlog")]
2963 private static extern int sys_openlog (IntPtr ident, int option, int facility);
2965 public static int openlog (IntPtr ident, SyslogOptions option,
2966 SyslogFacility defaultFacility)
2968 int _option = NativeConvert.FromSyslogOptions (option);
2969 int _facility = NativeConvert.FromSyslogFacility (defaultFacility);
2971 return sys_openlog (ident, _option, _facility);
2974 [DllImport (MPH, SetLastError=true,
2975 EntryPoint="Mono_Posix_Syscall_syslog")]
2976 private static extern int sys_syslog (int priority, string message);
2978 public static int syslog (SyslogFacility facility, SyslogLevel level, string message)
2980 int _facility = NativeConvert.FromSyslogFacility (facility);
2981 int _level = NativeConvert.FromSyslogLevel (level);
2982 return sys_syslog (_facility | _level, GetSyslogMessage (message));
2985 public static int syslog (SyslogLevel level, string message)
2987 int _level = NativeConvert.FromSyslogLevel (level);
2988 return sys_syslog (_level, GetSyslogMessage (message));
2991 private static string GetSyslogMessage (string message)
2993 return UnixMarshal.EscapeFormatString (message, new char[]{'m'});
2996 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
2997 "Use syslog(SyslogFacility, SyslogLevel, string) instead.")]
2998 public static int syslog (SyslogFacility facility, SyslogLevel level,
2999 string format, params object[] parameters)
3001 int _facility = NativeConvert.FromSyslogFacility (facility);
3002 int _level = NativeConvert.FromSyslogLevel (level);
3004 object[] _parameters = new object[checked(parameters.Length+2)];
3005 _parameters [0] = _facility | _level;
3006 _parameters [1] = format;
3007 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
3008 return (int) XPrintfFunctions.syslog (_parameters);
3011 [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
3012 "Use syslog(SyslogLevel, string) instead.")]
3013 public static int syslog (SyslogLevel level, string format,
3014 params object[] parameters)
3016 int _level = NativeConvert.FromSyslogLevel (level);
3018 object[] _parameters = new object[checked(parameters.Length+2)];
3019 _parameters [0] = _level;
3020 _parameters [1] = format;
3021 Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
3022 return (int) XPrintfFunctions.syslog (_parameters);
3025 [DllImport (MPH, SetLastError=true,
3026 EntryPoint="Mono_Posix_Syscall_closelog")]
3027 public static extern int closelog ();
3029 [DllImport (LIBC, SetLastError=true, EntryPoint="setlogmask")]
3030 private static extern int sys_setlogmask (int mask);
3032 public static int setlogmask (SyslogLevel mask)
3034 int _mask = NativeConvert.FromSyslogLevel (mask);
3035 return sys_setlogmask (_mask);
3040 #region <time.h> Declarations
3047 // int stime(time_t *t);
3048 [DllImport (MPH, SetLastError=true,
3049 EntryPoint="Mono_Posix_Syscall_stime")]
3050 public static extern int stime (ref long t);
3053 // time_t time(time_t *t);
3054 [DllImport (MPH, SetLastError=true,
3055 EntryPoint="Mono_Posix_Syscall_time")]
3056 public static extern long time (out long t);
3066 #region <unistd.h> Declarations
3070 // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
3071 // other TODOs listed below.
3073 [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
3074 private static extern int sys_access (
3075 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3076 string pathname, int mode);
3078 public static int access (string pathname, AccessModes mode)
3080 int _mode = NativeConvert.FromAccessModes (mode);
3081 return sys_access (pathname, _mode);
3085 // off_t lseek(int filedes, off_t offset, int whence);
3086 [DllImport (MPH, SetLastError=true,
3087 EntryPoint="Mono_Posix_Syscall_lseek")]
3088 private static extern long sys_lseek (int fd, long offset, int whence);
3090 public static long lseek (int fd, long offset, SeekFlags whence)
3092 short _whence = NativeConvert.FromSeekFlags (whence);
3093 return sys_lseek (fd, offset, _whence);
3096 [DllImport (LIBC, SetLastError=true)]
3097 public static extern int close (int fd);
3100 // ssize_t read(int fd, void *buf, size_t count);
3101 [DllImport (MPH, SetLastError=true,
3102 EntryPoint="Mono_Posix_Syscall_read")]
3103 public static extern long read (int fd, IntPtr buf, ulong count);
3105 public static unsafe long read (int fd, void *buf, ulong count)
3107 return read (fd, (IntPtr) buf, count);
3111 // ssize_t write(int fd, const void *buf, size_t count);
3112 [DllImport (MPH, SetLastError=true,
3113 EntryPoint="Mono_Posix_Syscall_write")]
3114 public static extern long write (int fd, IntPtr buf, ulong count);
3116 public static unsafe long write (int fd, void *buf, ulong count)
3118 return write (fd, (IntPtr) buf, count);
3122 // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
3123 [DllImport (MPH, SetLastError=true,
3124 EntryPoint="Mono_Posix_Syscall_pread")]
3125 public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
3127 public static unsafe long pread (int fd, void *buf, ulong count, long offset)
3129 return pread (fd, (IntPtr) buf, count, offset);
3133 // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
3134 [DllImport (MPH, SetLastError=true,
3135 EntryPoint="Mono_Posix_Syscall_pwrite")]
3136 public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
3138 public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
3140 return pwrite (fd, (IntPtr) buf, count, offset);
3143 [DllImport (MPH, SetLastError=true,
3144 EntryPoint="Mono_Posix_Syscall_pipe")]
3145 public static extern int pipe (out int reading, out int writing);
3147 public static int pipe (int[] filedes)
3149 if (filedes == null || filedes.Length != 2) {
3153 int reading, writing;
3154 int r = pipe (out reading, out writing);
3155 filedes[0] = reading;
3156 filedes[1] = writing;
3160 [DllImport (LIBC, SetLastError=true)]
3161 public static extern uint alarm (uint seconds);
3163 [DllImport (LIBC, SetLastError=true)]
3164 public static extern uint sleep (uint seconds);
3166 [DllImport (LIBC, SetLastError=true)]
3167 public static extern uint ualarm (uint usecs, uint interval);
3169 [DllImport (LIBC, SetLastError=true)]
3170 public static extern int pause ();
3173 // int chown(const char *path, uid_t owner, gid_t group);
3174 [DllImport (LIBC, SetLastError=true)]
3175 public static extern int chown (
3176 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3177 string path, uint owner, uint group);
3180 // int fchown(int fd, uid_t owner, gid_t group);
3181 [DllImport (LIBC, SetLastError=true)]
3182 public static extern int fchown (int fd, uint owner, uint group);
3185 // int lchown(const char *path, uid_t owner, gid_t group);
3186 [DllImport (LIBC, SetLastError=true)]
3187 public static extern int lchown (
3188 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3189 string path, uint owner, uint group);
3191 [DllImport (LIBC, SetLastError=true)]
3192 public static extern int chdir (
3193 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3196 [DllImport (LIBC, SetLastError=true)]
3197 public static extern int fchdir (int fd);
3200 // char *getcwd(char *buf, size_t size);
3201 [DllImport (MPH, SetLastError=true,
3202 EntryPoint="Mono_Posix_Syscall_getcwd")]
3203 public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
3205 public static StringBuilder getcwd (StringBuilder buf)
3207 getcwd (buf, (ulong) buf.Capacity);
3211 // getwd(2) is deprecated; don't expose it.
3213 [DllImport (LIBC, SetLastError=true)]
3214 public static extern int dup (int fd);
3216 [DllImport (LIBC, SetLastError=true)]
3217 public static extern int dup2 (int fd, int fd2);
3219 // TODO: does Mono marshal arrays properly?
3220 [DllImport (LIBC, SetLastError=true)]
3221 public static extern int execve (
3222 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3223 string path, string[] argv, string[] envp);
3225 [DllImport (LIBC, SetLastError=true)]
3226 public static extern int fexecve (int fd, string[] argv, string[] envp);
3228 [DllImport (LIBC, SetLastError=true)]
3229 public static extern int execv (
3230 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3231 string path, string[] argv);
3233 // TODO: execle, execl, execlp
3234 [DllImport (LIBC, SetLastError=true)]
3235 public static extern int execvp (
3236 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3237 string path, string[] argv);
3239 [DllImport (LIBC, SetLastError=true)]
3240 public static extern int nice (int inc);
3242 [DllImport (LIBC, SetLastError=true)]
3243 [CLSCompliant (false)]
3244 public static extern int _exit (int status);
3246 [DllImport (MPH, SetLastError=true,
3247 EntryPoint="Mono_Posix_Syscall_fpathconf")]
3248 public static extern long fpathconf (int filedes, PathconfName name, Errno defaultError);
3250 public static long fpathconf (int filedes, PathconfName name)
3252 return fpathconf (filedes, name, (Errno) 0);
3255 [DllImport (MPH, SetLastError=true,
3256 EntryPoint="Mono_Posix_Syscall_pathconf")]
3257 public static extern long pathconf (
3258 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3259 string path, PathconfName name, Errno defaultError);
3261 public static long pathconf (string path, PathconfName name)
3263 return pathconf (path, name, (Errno) 0);
3266 [DllImport (MPH, SetLastError=true,
3267 EntryPoint="Mono_Posix_Syscall_sysconf")]
3268 public static extern long sysconf (SysconfName name, Errno defaultError);
3270 public static long sysconf (SysconfName name)
3272 return sysconf (name, (Errno) 0);
3276 // size_t confstr(int name, char *buf, size_t len);
3277 [DllImport (MPH, SetLastError=true,
3278 EntryPoint="Mono_Posix_Syscall_confstr")]
3279 public static extern ulong confstr (ConfstrName name, [Out] StringBuilder buf, ulong len);
3282 // pid_t getpid(void);
3283 [DllImport (LIBC, SetLastError=true)]
3284 public static extern int getpid ();
3287 // pid_t getppid(void);
3288 [DllImport (LIBC, SetLastError=true)]
3289 public static extern int getppid ();
3292 // int setpgid(pid_t pid, pid_t pgid);
3293 [DllImport (LIBC, SetLastError=true)]
3294 public static extern int setpgid (int pid, int pgid);
3297 // pid_t getpgid(pid_t pid);
3298 [DllImport (LIBC, SetLastError=true)]
3299 public static extern int getpgid (int pid);
3301 [DllImport (LIBC, SetLastError=true)]
3302 public static extern int setpgrp ();
3305 // pid_t getpgrp(void);
3306 [DllImport (LIBC, SetLastError=true)]
3307 public static extern int getpgrp ();
3310 // pid_t setsid(void);
3311 [DllImport (LIBC, SetLastError=true)]
3312 public static extern int setsid ();
3315 // pid_t getsid(pid_t pid);
3316 [DllImport (LIBC, SetLastError=true)]
3317 public static extern int getsid (int pid);
3320 // uid_t getuid(void);
3321 [DllImport (LIBC, SetLastError=true)]
3322 public static extern uint getuid ();
3325 // uid_t geteuid(void);
3326 [DllImport (LIBC, SetLastError=true)]
3327 public static extern uint geteuid ();
3330 // gid_t getgid(void);
3331 [DllImport (LIBC, SetLastError=true)]
3332 public static extern uint getgid ();
3335 // gid_t getgid(void);
3336 [DllImport (LIBC, SetLastError=true)]
3337 public static extern uint getegid ();
3340 // int getgroups(int size, gid_t list[]);
3341 [DllImport (LIBC, SetLastError=true)]
3342 public static extern int getgroups (int size, uint[] list);
3344 public static int getgroups (uint[] list)
3346 return getgroups (list.Length, list);
3350 // int setuid(uid_t uid);
3351 [DllImport (LIBC, SetLastError=true)]
3352 public static extern int setuid (uint uid);
3355 // int setreuid(uid_t ruid, uid_t euid);
3356 [DllImport (LIBC, SetLastError=true)]
3357 public static extern int setreuid (uint ruid, uint euid);
3360 // int setregid(gid_t ruid, gid_t euid);
3361 [DllImport (LIBC, SetLastError=true)]
3362 public static extern int setregid (uint rgid, uint egid);
3365 // int seteuid(uid_t euid);
3366 [DllImport (LIBC, SetLastError=true)]
3367 public static extern int seteuid (uint euid);
3370 // int setegid(gid_t euid);
3371 [DllImport (LIBC, SetLastError=true)]
3372 public static extern int setegid (uint uid);
3375 // int setgid(gid_t gid);
3376 [DllImport (LIBC, SetLastError=true)]
3377 public static extern int setgid (uint gid);
3380 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
3381 [DllImport (LIBC, SetLastError=true)]
3382 public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
3385 // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
3386 [DllImport (LIBC, SetLastError=true)]
3387 public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
3390 // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
3391 [DllImport (LIBC, SetLastError=true)]
3392 public static extern int setresuid (uint ruid, uint euid, uint suid);
3395 // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
3396 [DllImport (LIBC, SetLastError=true)]
3397 public static extern int setresgid (uint rgid, uint egid, uint sgid);
3401 // pid_t fork(void);
3402 [DllImport (LIBC, SetLastError=true)]
3403 [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
3404 "shutdown code.\nUse System.Diagnostics.Process instead")]
3405 private static extern int fork ();
3408 // pid_t vfork(void);
3409 [DllImport (LIBC, SetLastError=true)]
3410 [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
3411 "shutdown code.\nUse System.Diagnostics.Process instead")]
3412 private static extern int vfork ();
3415 private static object tty_lock = new object ();
3417 [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
3418 private static extern IntPtr sys_ttyname (int fd);
3420 public static string ttyname (int fd)
3423 IntPtr r = sys_ttyname (fd);
3424 return UnixMarshal.PtrToString (r);
3429 // int ttyname_r(int fd, char *buf, size_t buflen);
3430 [DllImport (MPH, SetLastError=true,
3431 EntryPoint="Mono_Posix_Syscall_ttyname_r")]
3432 public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
3434 public static int ttyname_r (int fd, StringBuilder buf)
3436 return ttyname_r (fd, buf, (ulong) buf.Capacity);
3439 [DllImport (LIBC, EntryPoint="isatty")]
3440 private static extern int sys_isatty (int fd);
3442 public static bool isatty (int fd)
3444 return sys_isatty (fd) == 1;
3447 [DllImport (LIBC, SetLastError=true)]
3448 public static extern int link (
3449 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3451 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3454 [DllImport (LIBC, SetLastError=true)]
3455 public static extern int symlink (
3456 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3458 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3462 // int readlink(const char *path, char *buf, size_t bufsize);
3463 [DllImport (MPH, SetLastError=true,
3464 EntryPoint="Mono_Posix_Syscall_readlink")]
3465 public static extern int readlink (
3466 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3467 string path, [Out] StringBuilder buf, ulong bufsiz);
3469 public static int readlink (string path, [Out] StringBuilder buf)
3471 return readlink (path, buf, (ulong) buf.Capacity);
3474 [DllImport (LIBC, SetLastError=true)]
3475 public static extern int unlink (
3476 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3479 [DllImport (LIBC, SetLastError=true)]
3480 public static extern int rmdir (
3481 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3485 // pid_t tcgetpgrp(int fd);
3486 [DllImport (LIBC, SetLastError=true)]
3487 public static extern int tcgetpgrp (int fd);
3490 // int tcsetpgrp(int fd, pid_t pgrp);
3491 [DllImport (LIBC, SetLastError=true)]
3492 public static extern int tcsetpgrp (int fd, int pgrp);
3494 [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
3495 private static extern IntPtr sys_getlogin ();
3497 public static string getlogin ()
3499 lock (getlogin_lock) {
3500 IntPtr r = sys_getlogin ();
3501 return UnixMarshal.PtrToString (r);
3506 // int getlogin_r(char *buf, size_t bufsize);
3507 [DllImport (MPH, SetLastError=true,
3508 EntryPoint="Mono_Posix_Syscall_getlogin_r")]
3509 public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
3511 public static int getlogin_r (StringBuilder name)
3513 return getlogin_r (name, (ulong) name.Capacity);
3516 [DllImport (LIBC, SetLastError=true)]
3517 public static extern int setlogin (string name);
3520 // int gethostname(char *name, size_t len);
3521 [DllImport (MPH, SetLastError=true,
3522 EntryPoint="Mono_Posix_Syscall_gethostname")]
3523 public static extern int gethostname ([Out] StringBuilder name, ulong len);
3525 public static int gethostname (StringBuilder name)
3527 return gethostname (name, (ulong) name.Capacity);
3531 // int gethostname(const char *name, size_t len);
3532 [DllImport (MPH, SetLastError=true,
3533 EntryPoint="Mono_Posix_Syscall_sethostname")]
3534 public static extern int sethostname (string name, ulong len);
3536 public static int sethostname (string name)
3538 return sethostname (name, (ulong) name.Length);
3541 [DllImport (MPH, SetLastError=true,
3542 EntryPoint="Mono_Posix_Syscall_gethostid")]
3543 public static extern long gethostid ();
3545 [DllImport (MPH, SetLastError=true,
3546 EntryPoint="Mono_Posix_Syscall_sethostid")]
3547 public static extern int sethostid (long hostid);
3550 // int getdomainname(char *name, size_t len);
3551 [DllImport (MPH, SetLastError=true,
3552 EntryPoint="Mono_Posix_Syscall_getdomainname")]
3553 public static extern int getdomainname ([Out] StringBuilder name, ulong len);
3555 public static int getdomainname (StringBuilder name)
3557 return getdomainname (name, (ulong) name.Capacity);
3561 // int setdomainname(const char *name, size_t len);
3562 [DllImport (MPH, SetLastError=true,
3563 EntryPoint="Mono_Posix_Syscall_setdomainname")]
3564 public static extern int setdomainname (string name, ulong len);
3566 public static int setdomainname (string name)
3568 return setdomainname (name, (ulong) name.Length);
3571 [DllImport (LIBC, SetLastError=true)]
3572 public static extern int vhangup ();
3574 // Revoke doesn't appear to be POSIX. Include it?
3575 [DllImport (LIBC, SetLastError=true)]
3576 public static extern int revoke (
3577 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3580 // TODO: profil? It's not POSIX.
3582 [DllImport (LIBC, SetLastError=true)]
3583 public static extern int acct (
3584 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3587 [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
3588 private static extern IntPtr sys_getusershell ();
3590 internal static object usershell_lock = new object ();
3592 public static string getusershell ()
3594 lock (usershell_lock) {
3595 IntPtr r = sys_getusershell ();
3596 return UnixMarshal.PtrToString (r);
3600 [DllImport (MPH, SetLastError=true,
3601 EntryPoint="Mono_Posix_Syscall_setusershell")]
3602 private static extern int sys_setusershell ();
3604 public static int setusershell ()
3606 lock (usershell_lock) {
3607 return sys_setusershell ();
3611 [DllImport (MPH, SetLastError=true,
3612 EntryPoint="Mono_Posix_Syscall_endusershell")]
3613 private static extern int sys_endusershell ();
3615 public static int endusershell ()
3617 lock (usershell_lock) {
3618 return sys_endusershell ();
3623 [DllImport (LIBC, SetLastError=true)]
3624 private static extern int daemon (int nochdir, int noclose);
3626 // this implicitly forks, and thus isn't safe.
3627 private static int daemon (bool nochdir, bool noclose)
3629 return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
3633 [DllImport (LIBC, SetLastError=true)]
3634 public static extern int chroot (
3635 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3638 // skipping getpass(3) as the man page states:
3639 // This function is obsolete. Do not use it.
3641 [DllImport (LIBC, SetLastError=true)]
3642 public static extern int fsync (int fd);
3644 [DllImport (LIBC, SetLastError=true)]
3645 public static extern int fdatasync (int fd);
3647 [DllImport (MPH, SetLastError=true,
3648 EntryPoint="Mono_Posix_Syscall_sync")]
3649 public static extern int sync ();
3651 [DllImport (LIBC, SetLastError=true)]
3652 [Obsolete ("Dropped in POSIX 1003.1-2001. " +
3653 "Use Syscall.sysconf (SysconfName._SC_PAGESIZE).")]
3654 public static extern int getpagesize ();
3657 // int truncate(const char *path, off_t length);
3658 [DllImport (MPH, SetLastError=true,
3659 EntryPoint="Mono_Posix_Syscall_truncate")]
3660 public static extern int truncate (
3661 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3662 string path, long length);
3665 // int ftruncate(int fd, off_t length);
3666 [DllImport (MPH, SetLastError=true,
3667 EntryPoint="Mono_Posix_Syscall_ftruncate")]
3668 public static extern int ftruncate (int fd, long length);
3670 [DllImport (LIBC, SetLastError=true)]
3671 public static extern int getdtablesize ();
3673 [DllImport (LIBC, SetLastError=true)]
3674 public static extern int brk (IntPtr end_data_segment);
3676 [DllImport (LIBC, SetLastError=true)]
3677 public static extern IntPtr sbrk (IntPtr increment);
3679 // TODO: syscall(2)?
3680 // Probably safer to skip entirely.
3683 // int lockf(int fd, int cmd, off_t len);
3684 [DllImport (MPH, SetLastError=true,
3685 EntryPoint="Mono_Posix_Syscall_lockf")]
3686 public static extern int lockf (int fd, LockfCommand cmd, long len);
3688 [Obsolete ("This is insecure and should not be used", true)]
3689 public static string crypt (string key, string salt)
3691 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
3694 [Obsolete ("This is insecure and should not be used", true)]
3695 public static int encrypt (byte[] block, bool decode)
3697 throw new SecurityException ("crypt(3) has been broken. Use something more secure.");
3701 // void swab(const void *from, void *to, ssize_t n);
3702 [DllImport (MPH, SetLastError=true,
3703 EntryPoint="Mono_Posix_Syscall_swab")]
3704 public static extern int swab (IntPtr from, IntPtr to, long n);
3706 public static unsafe void swab (void* from, void* to, long n)
3708 swab ((IntPtr) from, (IntPtr) to, n);
3713 #region <utime.h> Declarations
3715 // <utime.h> -- COMPLETE
3718 [DllImport (MPH, SetLastError=true,
3719 EntryPoint="Mono_Posix_Syscall_utime")]
3720 private static extern int sys_utime (
3721 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
3722 string filename, ref Utimbuf buf, int use_buf);
3724 public static int utime (string filename, ref Utimbuf buf)
3726 return sys_utime (filename, ref buf, 1);
3729 public static int utime (string filename)
3731 Utimbuf buf = new Utimbuf ();
3732 return sys_utime (filename, ref buf, 0);