PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs

https://bitbucket.org/danipen/mono
C# | 4010 lines | 2955 code | 558 blank | 497 comment | 322 complexity | 35142eb8db78938addd8d27922c4199e MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. //
  2. // Mono.Unix/Syscall.cs
  3. //
  4. // Authors:
  5. // Miguel de Icaza (miguel@novell.com)
  6. // Jonathan Pryor (jonpryor@vt.edu)
  7. //
  8. // (C) 2003 Novell, Inc.
  9. // (C) 2004-2006 Jonathan Pryor
  10. //
  11. // This file implements the low-level syscall interface to the POSIX
  12. // subsystem.
  13. //
  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
  16. // data types.
  17. //
  18. // Implementation notes:
  19. //
  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.
  25. //
  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.
  30. //
  31. // Methods that require tuning are bound as `private sys_NAME' methods
  32. // and then a `NAME' method is exposed.
  33. //
  34. //
  35. // Permission is hereby granted, free of charge, to any person obtaining
  36. // a copy of this software and associated documentation files (the
  37. // "Software"), to deal in the Software without restriction, including
  38. // without limitation the rights to use, copy, modify, merge, publish,
  39. // distribute, sublicense, and/or sell copies of the Software, and to
  40. // permit persons to whom the Software is furnished to do so, subject to
  41. // the following conditions:
  42. //
  43. // The above copyright notice and this permission notice shall be
  44. // included in all copies or substantial portions of the Software.
  45. //
  46. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  47. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  48. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  49. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  50. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  51. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  52. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  53. //
  54. using System;
  55. using System.Collections;
  56. using System.Collections.Generic;
  57. using System.Runtime.InteropServices;
  58. using System.Security;
  59. using System.Text;
  60. using Mono.Unix.Native;
  61. namespace Mono.Unix.Native {
  62. #region Enumerations
  63. [Flags][Map]
  64. [CLSCompliant (false)]
  65. public enum SyslogOptions {
  66. LOG_PID = 0x01, // log the pid with each message
  67. LOG_CONS = 0x02, // log on the console if errors in sending
  68. LOG_ODELAY = 0x04, // delay open until first syslog (default)
  69. LOG_NDELAY = 0x08, // don't delay open
  70. LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
  71. LOG_PERROR = 0x20 // log to stderr as well
  72. }
  73. [Map]
  74. [CLSCompliant (false)]
  75. public enum SyslogFacility {
  76. LOG_KERN = 0 << 3,
  77. LOG_USER = 1 << 3,
  78. LOG_MAIL = 2 << 3,
  79. LOG_DAEMON = 3 << 3,
  80. LOG_AUTH = 4 << 3,
  81. LOG_SYSLOG = 5 << 3,
  82. LOG_LPR = 6 << 3,
  83. LOG_NEWS = 7 << 3,
  84. LOG_UUCP = 8 << 3,
  85. LOG_CRON = 9 << 3,
  86. LOG_AUTHPRIV = 10 << 3,
  87. LOG_FTP = 11 << 3,
  88. LOG_LOCAL0 = 16 << 3,
  89. LOG_LOCAL1 = 17 << 3,
  90. LOG_LOCAL2 = 18 << 3,
  91. LOG_LOCAL3 = 19 << 3,
  92. LOG_LOCAL4 = 20 << 3,
  93. LOG_LOCAL5 = 21 << 3,
  94. LOG_LOCAL6 = 22 << 3,
  95. LOG_LOCAL7 = 23 << 3,
  96. }
  97. [Map]
  98. [CLSCompliant (false)]
  99. public enum SyslogLevel {
  100. LOG_EMERG = 0, // system is unusable
  101. LOG_ALERT = 1, // action must be taken immediately
  102. LOG_CRIT = 2, // critical conditions
  103. LOG_ERR = 3, // warning conditions
  104. LOG_WARNING = 4, // warning conditions
  105. LOG_NOTICE = 5, // normal but significant condition
  106. LOG_INFO = 6, // informational
  107. LOG_DEBUG = 7 // debug-level messages
  108. }
  109. [Map][Flags]
  110. [CLSCompliant (false)]
  111. public enum OpenFlags : int {
  112. //
  113. // One of these
  114. //
  115. O_RDONLY = 0x00000000,
  116. O_WRONLY = 0x00000001,
  117. O_RDWR = 0x00000002,
  118. //
  119. // Or-ed with zero or more of these
  120. //
  121. O_CREAT = 0x00000040,
  122. O_EXCL = 0x00000080,
  123. O_NOCTTY = 0x00000100,
  124. O_TRUNC = 0x00000200,
  125. O_APPEND = 0x00000400,
  126. O_NONBLOCK = 0x00000800,
  127. O_SYNC = 0x00001000,
  128. //
  129. // These are non-Posix. Using them will result in errors/exceptions on
  130. // non-supported platforms.
  131. //
  132. // (For example, "C-wrapped" system calls -- calls with implementation in
  133. // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
  134. // calls will generate an exception in NativeConvert, as the value can't be
  135. // converted on the target platform.)
  136. //
  137. O_NOFOLLOW = 0x00020000,
  138. O_DIRECTORY = 0x00010000,
  139. O_DIRECT = 0x00004000,
  140. O_ASYNC = 0x00002000,
  141. O_LARGEFILE = 0x00008000
  142. }
  143. // mode_t
  144. [Flags][Map]
  145. [CLSCompliant (false)]
  146. public enum FilePermissions : uint {
  147. S_ISUID = 0x0800, // Set user ID on execution
  148. S_ISGID = 0x0400, // Set group ID on execution
  149. S_ISVTX = 0x0200, // Save swapped text after use (sticky).
  150. S_IRUSR = 0x0100, // Read by owner
  151. S_IWUSR = 0x0080, // Write by owner
  152. S_IXUSR = 0x0040, // Execute by owner
  153. S_IRGRP = 0x0020, // Read by group
  154. S_IWGRP = 0x0010, // Write by group
  155. S_IXGRP = 0x0008, // Execute by group
  156. S_IROTH = 0x0004, // Read by other
  157. S_IWOTH = 0x0002, // Write by other
  158. S_IXOTH = 0x0001, // Execute by other
  159. S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
  160. S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
  161. S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
  162. ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
  163. ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
  164. DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
  165. // Device types
  166. // Why these are held in "mode_t" is beyond me...
  167. S_IFMT = 0xF000, // Bits which determine file type
  168. [Map(SuppressFlags="S_IFMT")]
  169. S_IFDIR = 0x4000, // Directory
  170. [Map(SuppressFlags="S_IFMT")]
  171. S_IFCHR = 0x2000, // Character device
  172. [Map(SuppressFlags="S_IFMT")]
  173. S_IFBLK = 0x6000, // Block device
  174. [Map(SuppressFlags="S_IFMT")]
  175. S_IFREG = 0x8000, // Regular file
  176. [Map(SuppressFlags="S_IFMT")]
  177. S_IFIFO = 0x1000, // FIFO
  178. [Map(SuppressFlags="S_IFMT")]
  179. S_IFLNK = 0xA000, // Symbolic link
  180. [Map(SuppressFlags="S_IFMT")]
  181. S_IFSOCK = 0xC000, // Socket
  182. }
  183. [Map]
  184. [CLSCompliant (false)]
  185. public enum FcntlCommand : int {
  186. // Form /usr/include/bits/fcntl.h
  187. F_DUPFD = 0, // Duplicate file descriptor.
  188. F_GETFD = 1, // Get file descriptor flags.
  189. F_SETFD = 2, // Set file descriptor flags.
  190. F_GETFL = 3, // Get file status flags.
  191. F_SETFL = 4, // Set file status flags.
  192. F_GETLK = 12, // Get record locking info. [64]
  193. F_SETLK = 13, // Set record locking info (non-blocking). [64]
  194. F_SETLKW = 14, // Set record locking info (blocking). [64]
  195. F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
  196. F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
  197. F_SETSIG = 10, // Set number of signal to be sent.
  198. F_GETSIG = 11, // Get number of signal to be sent.
  199. F_SETLEASE = 1024, // Set a lease.
  200. F_GETLEASE = 1025, // Enquire what lease is active.
  201. F_NOTIFY = 1026, // Required notifications on a directory
  202. }
  203. [Map]
  204. [CLSCompliant (false)]
  205. public enum LockType : short {
  206. F_RDLCK = 0, // Read lock.
  207. F_WRLCK = 1, // Write lock.
  208. F_UNLCK = 2, // Remove lock.
  209. }
  210. [Map]
  211. [CLSCompliant (false)]
  212. public enum SeekFlags : short {
  213. // values liberally copied from /usr/include/unistd.h
  214. SEEK_SET = 0, // Seek from beginning of file.
  215. SEEK_CUR = 1, // Seek from current position.
  216. SEEK_END = 2, // Seek from end of file.
  217. L_SET = SEEK_SET, // BSD alias for SEEK_SET
  218. L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
  219. L_XTND = SEEK_END, // BSD alias for SEEK_END
  220. }
  221. [Map, Flags]
  222. [CLSCompliant (false)]
  223. public enum DirectoryNotifyFlags : int {
  224. // from /usr/include/bits/fcntl.h
  225. DN_ACCESS = 0x00000001, // File accessed.
  226. DN_MODIFY = 0x00000002, // File modified.
  227. DN_CREATE = 0x00000004, // File created.
  228. DN_DELETE = 0x00000008, // File removed.
  229. DN_RENAME = 0x00000010, // File renamed.
  230. DN_ATTRIB = 0x00000020, // File changed attributes.
  231. DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
  232. }
  233. [Map]
  234. [CLSCompliant (false)]
  235. public enum PosixFadviseAdvice : int {
  236. POSIX_FADV_NORMAL = 0, // No further special treatment.
  237. POSIX_FADV_RANDOM = 1, // Expect random page references.
  238. POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
  239. POSIX_FADV_WILLNEED = 3, // Will need these pages.
  240. POSIX_FADV_DONTNEED = 4, // Don't need these pages.
  241. POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
  242. }
  243. [Map]
  244. [CLSCompliant (false)]
  245. public enum PosixMadviseAdvice : int {
  246. POSIX_MADV_NORMAL = 0, // No further special treatment.
  247. POSIX_MADV_RANDOM = 1, // Expect random page references.
  248. POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
  249. POSIX_MADV_WILLNEED = 3, // Will need these pages.
  250. POSIX_MADV_DONTNEED = 4, // Don't need these pages.
  251. }
  252. [Map]
  253. public enum Signum : int {
  254. SIGHUP = 1, // Hangup (POSIX).
  255. SIGINT = 2, // Interrupt (ANSI).
  256. SIGQUIT = 3, // Quit (POSIX).
  257. SIGILL = 4, // Illegal instruction (ANSI).
  258. SIGTRAP = 5, // Trace trap (POSIX).
  259. SIGABRT = 6, // Abort (ANSI).
  260. SIGIOT = 6, // IOT trap (4.2 BSD).
  261. SIGBUS = 7, // BUS error (4.2 BSD).
  262. SIGFPE = 8, // Floating-point exception (ANSI).
  263. SIGKILL = 9, // Kill, unblockable (POSIX).
  264. SIGUSR1 = 10, // User-defined signal 1 (POSIX).
  265. SIGSEGV = 11, // Segmentation violation (ANSI).
  266. SIGUSR2 = 12, // User-defined signal 2 (POSIX).
  267. SIGPIPE = 13, // Broken pipe (POSIX).
  268. SIGALRM = 14, // Alarm clock (POSIX).
  269. SIGTERM = 15, // Termination (ANSI).
  270. SIGSTKFLT = 16, // Stack fault.
  271. SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
  272. SIGCHLD = 17, // Child status has changed (POSIX).
  273. SIGCONT = 18, // Continue (POSIX).
  274. SIGSTOP = 19, // Stop, unblockable (POSIX).
  275. SIGTSTP = 20, // Keyboard stop (POSIX).
  276. SIGTTIN = 21, // Background read from tty (POSIX).
  277. SIGTTOU = 22, // Background write to tty (POSIX).
  278. SIGURG = 23, // Urgent condition on socket (4.2 BSD).
  279. SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
  280. SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
  281. SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
  282. SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
  283. SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
  284. SIGPOLL = SIGIO, // Pollable event occurred (System V).
  285. SIGIO = 29, // I/O now possible (4.2 BSD).
  286. SIGPWR = 30, // Power failure restart (System V).
  287. SIGSYS = 31, // Bad system call.
  288. SIGUNUSED = 31
  289. }
  290. [Flags][Map]
  291. public enum WaitOptions : int {
  292. WNOHANG = 1, // Don't block waiting
  293. WUNTRACED = 2, // Report status of stopped children
  294. }
  295. [Flags][Map]
  296. [CLSCompliant (false)]
  297. public enum AccessModes : int {
  298. R_OK = 1,
  299. W_OK = 2,
  300. X_OK = 4,
  301. F_OK = 8,
  302. }
  303. [Map]
  304. [CLSCompliant (false)]
  305. public enum PathconfName : int {
  306. _PC_LINK_MAX,
  307. _PC_MAX_CANON,
  308. _PC_MAX_INPUT,
  309. _PC_NAME_MAX,
  310. _PC_PATH_MAX,
  311. _PC_PIPE_BUF,
  312. _PC_CHOWN_RESTRICTED,
  313. _PC_NO_TRUNC,
  314. _PC_VDISABLE,
  315. _PC_SYNC_IO,
  316. _PC_ASYNC_IO,
  317. _PC_PRIO_IO,
  318. _PC_SOCK_MAXBUF,
  319. _PC_FILESIZEBITS,
  320. _PC_REC_INCR_XFER_SIZE,
  321. _PC_REC_MAX_XFER_SIZE,
  322. _PC_REC_MIN_XFER_SIZE,
  323. _PC_REC_XFER_ALIGN,
  324. _PC_ALLOC_SIZE_MIN,
  325. _PC_SYMLINK_MAX,
  326. _PC_2_SYMLINKS
  327. }
  328. [Map]
  329. [CLSCompliant (false)]
  330. public enum SysconfName : int {
  331. _SC_ARG_MAX,
  332. _SC_CHILD_MAX,
  333. _SC_CLK_TCK,
  334. _SC_NGROUPS_MAX,
  335. _SC_OPEN_MAX,
  336. _SC_STREAM_MAX,
  337. _SC_TZNAME_MAX,
  338. _SC_JOB_CONTROL,
  339. _SC_SAVED_IDS,
  340. _SC_REALTIME_SIGNALS,
  341. _SC_PRIORITY_SCHEDULING,
  342. _SC_TIMERS,
  343. _SC_ASYNCHRONOUS_IO,
  344. _SC_PRIORITIZED_IO,
  345. _SC_SYNCHRONIZED_IO,
  346. _SC_FSYNC,
  347. _SC_MAPPED_FILES,
  348. _SC_MEMLOCK,
  349. _SC_MEMLOCK_RANGE,
  350. _SC_MEMORY_PROTECTION,
  351. _SC_MESSAGE_PASSING,
  352. _SC_SEMAPHORES,
  353. _SC_SHARED_MEMORY_OBJECTS,
  354. _SC_AIO_LISTIO_MAX,
  355. _SC_AIO_MAX,
  356. _SC_AIO_PRIO_DELTA_MAX,
  357. _SC_DELAYTIMER_MAX,
  358. _SC_MQ_OPEN_MAX,
  359. _SC_MQ_PRIO_MAX,
  360. _SC_VERSION,
  361. _SC_PAGESIZE,
  362. _SC_RTSIG_MAX,
  363. _SC_SEM_NSEMS_MAX,
  364. _SC_SEM_VALUE_MAX,
  365. _SC_SIGQUEUE_MAX,
  366. _SC_TIMER_MAX,
  367. /* Values for the argument to `sysconf'
  368. corresponding to _POSIX2_* symbols. */
  369. _SC_BC_BASE_MAX,
  370. _SC_BC_DIM_MAX,
  371. _SC_BC_SCALE_MAX,
  372. _SC_BC_STRING_MAX,
  373. _SC_COLL_WEIGHTS_MAX,
  374. _SC_EQUIV_CLASS_MAX,
  375. _SC_EXPR_NEST_MAX,
  376. _SC_LINE_MAX,
  377. _SC_RE_DUP_MAX,
  378. _SC_CHARCLASS_NAME_MAX,
  379. _SC_2_VERSION,
  380. _SC_2_C_BIND,
  381. _SC_2_C_DEV,
  382. _SC_2_FORT_DEV,
  383. _SC_2_FORT_RUN,
  384. _SC_2_SW_DEV,
  385. _SC_2_LOCALEDEF,
  386. _SC_PII,
  387. _SC_PII_XTI,
  388. _SC_PII_SOCKET,
  389. _SC_PII_INTERNET,
  390. _SC_PII_OSI,
  391. _SC_POLL,
  392. _SC_SELECT,
  393. _SC_UIO_MAXIOV,
  394. _SC_IOV_MAX = _SC_UIO_MAXIOV,
  395. _SC_PII_INTERNET_STREAM,
  396. _SC_PII_INTERNET_DGRAM,
  397. _SC_PII_OSI_COTS,
  398. _SC_PII_OSI_CLTS,
  399. _SC_PII_OSI_M,
  400. _SC_T_IOV_MAX,
  401. /* Values according to POSIX 1003.1c (POSIX threads). */
  402. _SC_THREADS,
  403. _SC_THREAD_SAFE_FUNCTIONS,
  404. _SC_GETGR_R_SIZE_MAX,
  405. _SC_GETPW_R_SIZE_MAX,
  406. _SC_LOGIN_NAME_MAX,
  407. _SC_TTY_NAME_MAX,
  408. _SC_THREAD_DESTRUCTOR_ITERATIONS,
  409. _SC_THREAD_KEYS_MAX,
  410. _SC_THREAD_STACK_MIN,
  411. _SC_THREAD_THREADS_MAX,
  412. _SC_THREAD_ATTR_STACKADDR,
  413. _SC_THREAD_ATTR_STACKSIZE,
  414. _SC_THREAD_PRIORITY_SCHEDULING,
  415. _SC_THREAD_PRIO_INHERIT,
  416. _SC_THREAD_PRIO_PROTECT,
  417. _SC_THREAD_PROCESS_SHARED,
  418. _SC_NPROCESSORS_CONF,
  419. _SC_NPROCESSORS_ONLN,
  420. _SC_PHYS_PAGES,
  421. _SC_AVPHYS_PAGES,
  422. _SC_ATEXIT_MAX,
  423. _SC_PASS_MAX,
  424. _SC_XOPEN_VERSION,
  425. _SC_XOPEN_XCU_VERSION,
  426. _SC_XOPEN_UNIX,
  427. _SC_XOPEN_CRYPT,
  428. _SC_XOPEN_ENH_I18N,
  429. _SC_XOPEN_SHM,
  430. _SC_2_CHAR_TERM,
  431. _SC_2_C_VERSION,
  432. _SC_2_UPE,
  433. _SC_XOPEN_XPG2,
  434. _SC_XOPEN_XPG3,
  435. _SC_XOPEN_XPG4,
  436. _SC_CHAR_BIT,
  437. _SC_CHAR_MAX,
  438. _SC_CHAR_MIN,
  439. _SC_INT_MAX,
  440. _SC_INT_MIN,
  441. _SC_LONG_BIT,
  442. _SC_WORD_BIT,
  443. _SC_MB_LEN_MAX,
  444. _SC_NZERO,
  445. _SC_SSIZE_MAX,
  446. _SC_SCHAR_MAX,
  447. _SC_SCHAR_MIN,
  448. _SC_SHRT_MAX,
  449. _SC_SHRT_MIN,
  450. _SC_UCHAR_MAX,
  451. _SC_UINT_MAX,
  452. _SC_ULONG_MAX,
  453. _SC_USHRT_MAX,
  454. _SC_NL_ARGMAX,
  455. _SC_NL_LANGMAX,
  456. _SC_NL_MSGMAX,
  457. _SC_NL_NMAX,
  458. _SC_NL_SETMAX,
  459. _SC_NL_TEXTMAX,
  460. _SC_XBS5_ILP32_OFF32,
  461. _SC_XBS5_ILP32_OFFBIG,
  462. _SC_XBS5_LP64_OFF64,
  463. _SC_XBS5_LPBIG_OFFBIG,
  464. _SC_XOPEN_LEGACY,
  465. _SC_XOPEN_REALTIME,
  466. _SC_XOPEN_REALTIME_THREADS,
  467. _SC_ADVISORY_INFO,
  468. _SC_BARRIERS,
  469. _SC_BASE,
  470. _SC_C_LANG_SUPPORT,
  471. _SC_C_LANG_SUPPORT_R,
  472. _SC_CLOCK_SELECTION,
  473. _SC_CPUTIME,
  474. _SC_THREAD_CPUTIME,
  475. _SC_DEVICE_IO,
  476. _SC_DEVICE_SPECIFIC,
  477. _SC_DEVICE_SPECIFIC_R,
  478. _SC_FD_MGMT,
  479. _SC_FIFO,
  480. _SC_PIPE,
  481. _SC_FILE_ATTRIBUTES,
  482. _SC_FILE_LOCKING,
  483. _SC_FILE_SYSTEM,
  484. _SC_MONOTONIC_CLOCK,
  485. _SC_MULTI_PROCESS,
  486. _SC_SINGLE_PROCESS,
  487. _SC_NETWORKING,
  488. _SC_READER_WRITER_LOCKS,
  489. _SC_SPIN_LOCKS,
  490. _SC_REGEXP,
  491. _SC_REGEX_VERSION,
  492. _SC_SHELL,
  493. _SC_SIGNALS,
  494. _SC_SPAWN,
  495. _SC_SPORADIC_SERVER,
  496. _SC_THREAD_SPORADIC_SERVER,
  497. _SC_SYSTEM_DATABASE,
  498. _SC_SYSTEM_DATABASE_R,
  499. _SC_TIMEOUTS,
  500. _SC_TYPED_MEMORY_OBJECTS,
  501. _SC_USER_GROUPS,
  502. _SC_USER_GROUPS_R,
  503. _SC_2_PBS,
  504. _SC_2_PBS_ACCOUNTING,
  505. _SC_2_PBS_LOCATE,
  506. _SC_2_PBS_MESSAGE,
  507. _SC_2_PBS_TRACK,
  508. _SC_SYMLOOP_MAX,
  509. _SC_STREAMS,
  510. _SC_2_PBS_CHECKPOINT,
  511. _SC_V6_ILP32_OFF32,
  512. _SC_V6_ILP32_OFFBIG,
  513. _SC_V6_LP64_OFF64,
  514. _SC_V6_LPBIG_OFFBIG,
  515. _SC_HOST_NAME_MAX,
  516. _SC_TRACE,
  517. _SC_TRACE_EVENT_FILTER,
  518. _SC_TRACE_INHERIT,
  519. _SC_TRACE_LOG,
  520. _SC_LEVEL1_ICACHE_SIZE,
  521. _SC_LEVEL1_ICACHE_ASSOC,
  522. _SC_LEVEL1_ICACHE_LINESIZE,
  523. _SC_LEVEL1_DCACHE_SIZE,
  524. _SC_LEVEL1_DCACHE_ASSOC,
  525. _SC_LEVEL1_DCACHE_LINESIZE,
  526. _SC_LEVEL2_CACHE_SIZE,
  527. _SC_LEVEL2_CACHE_ASSOC,
  528. _SC_LEVEL2_CACHE_LINESIZE,
  529. _SC_LEVEL3_CACHE_SIZE,
  530. _SC_LEVEL3_CACHE_ASSOC,
  531. _SC_LEVEL3_CACHE_LINESIZE,
  532. _SC_LEVEL4_CACHE_SIZE,
  533. _SC_LEVEL4_CACHE_ASSOC,
  534. _SC_LEVEL4_CACHE_LINESIZE
  535. }
  536. [Map]
  537. [CLSCompliant (false)]
  538. public enum ConfstrName : int {
  539. _CS_PATH, /* The default search path. */
  540. _CS_V6_WIDTH_RESTRICTED_ENVS,
  541. _CS_GNU_LIBC_VERSION,
  542. _CS_GNU_LIBPTHREAD_VERSION,
  543. _CS_LFS_CFLAGS = 1000,
  544. _CS_LFS_LDFLAGS,
  545. _CS_LFS_LIBS,
  546. _CS_LFS_LINTFLAGS,
  547. _CS_LFS64_CFLAGS,
  548. _CS_LFS64_LDFLAGS,
  549. _CS_LFS64_LIBS,
  550. _CS_LFS64_LINTFLAGS,
  551. _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
  552. _CS_XBS5_ILP32_OFF32_LDFLAGS,
  553. _CS_XBS5_ILP32_OFF32_LIBS,
  554. _CS_XBS5_ILP32_OFF32_LINTFLAGS,
  555. _CS_XBS5_ILP32_OFFBIG_CFLAGS,
  556. _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
  557. _CS_XBS5_ILP32_OFFBIG_LIBS,
  558. _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
  559. _CS_XBS5_LP64_OFF64_CFLAGS,
  560. _CS_XBS5_LP64_OFF64_LDFLAGS,
  561. _CS_XBS5_LP64_OFF64_LIBS,
  562. _CS_XBS5_LP64_OFF64_LINTFLAGS,
  563. _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
  564. _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
  565. _CS_XBS5_LPBIG_OFFBIG_LIBS,
  566. _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
  567. _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
  568. _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
  569. _CS_POSIX_V6_ILP32_OFF32_LIBS,
  570. _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
  571. _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
  572. _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
  573. _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
  574. _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
  575. _CS_POSIX_V6_LP64_OFF64_CFLAGS,
  576. _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
  577. _CS_POSIX_V6_LP64_OFF64_LIBS,
  578. _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
  579. _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
  580. _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
  581. _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
  582. _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
  583. }
  584. [Map]
  585. [CLSCompliant (false)]
  586. public enum LockfCommand : int {
  587. F_ULOCK = 0, // Unlock a previously locked region.
  588. F_LOCK = 1, // Lock a region for exclusive use.
  589. F_TLOCK = 2, // Test and lock a region for exclusive use.
  590. F_TEST = 3, // Test a region for other process locks.
  591. }
  592. [Map][Flags]
  593. public enum PollEvents : short {
  594. POLLIN = 0x0001, // There is data to read
  595. POLLPRI = 0x0002, // There is urgent data to read
  596. POLLOUT = 0x0004, // Writing now will not block
  597. POLLERR = 0x0008, // Error condition
  598. POLLHUP = 0x0010, // Hung up
  599. POLLNVAL = 0x0020, // Invalid request; fd not open
  600. // XPG4.2 definitions (via _XOPEN_SOURCE)
  601. POLLRDNORM = 0x0040, // Normal data may be read
  602. POLLRDBAND = 0x0080, // Priority data may be read
  603. POLLWRNORM = 0x0100, // Writing now will not block
  604. POLLWRBAND = 0x0200, // Priority data may be written
  605. }
  606. [Map][Flags]
  607. [CLSCompliant (false)]
  608. public enum XattrFlags : int {
  609. XATTR_AUTO = 0,
  610. XATTR_CREATE = 1,
  611. XATTR_REPLACE = 2,
  612. }
  613. [Map][Flags]
  614. [CLSCompliant (false)]
  615. public enum MountFlags : ulong {
  616. ST_RDONLY = 1, // Mount read-only
  617. ST_NOSUID = 2, // Ignore suid and sgid bits
  618. ST_NODEV = 4, // Disallow access to device special files
  619. ST_NOEXEC = 8, // Disallow program execution
  620. ST_SYNCHRONOUS = 16, // Writes are synced at once
  621. ST_REMOUNT = 32, // Alter flags of a mounted FS
  622. ST_MANDLOCK = 64, // Allow mandatory locks on an FS
  623. ST_WRITE = 128, // Write on file/directory/symlink
  624. ST_APPEND = 256, // Append-only file
  625. ST_IMMUTABLE = 512, // Immutable file
  626. ST_NOATIME = 1024, // Do not update access times
  627. ST_NODIRATIME = 2048, // Do not update directory access times
  628. ST_BIND = 4096, // Bind directory at different place
  629. }
  630. [Map][Flags]
  631. [CLSCompliant (false)]
  632. public enum MmapFlags : int {
  633. MAP_SHARED = 0x01, // Share changes.
  634. MAP_PRIVATE = 0x02, // Changes are private.
  635. MAP_TYPE = 0x0f, // Mask for type of mapping.
  636. MAP_FIXED = 0x10, // Interpret addr exactly.
  637. MAP_FILE = 0,
  638. MAP_ANONYMOUS = 0x20, // Don't use a file.
  639. MAP_ANON = MAP_ANONYMOUS,
  640. // These are Linux-specific.
  641. MAP_GROWSDOWN = 0x00100, // Stack-like segment.
  642. MAP_DENYWRITE = 0x00800, // ETXTBSY
  643. MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
  644. MAP_LOCKED = 0x02000, // Lock the mapping.
  645. MAP_NORESERVE = 0x04000, // Don't check for reservations.
  646. MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
  647. MAP_NONBLOCK = 0x10000, // Do not block on IO.
  648. }
  649. [Map][Flags]
  650. [CLSCompliant (false)]
  651. public enum MmapProts : int {
  652. PROT_READ = 0x1, // Page can be read.
  653. PROT_WRITE = 0x2, // Page can be written.
  654. PROT_EXEC = 0x4, // Page can be executed.
  655. PROT_NONE = 0x0, // Page can not be accessed.
  656. PROT_GROWSDOWN = 0x01000000, // Extend change to start of
  657. // growsdown vma (mprotect only).
  658. PROT_GROWSUP = 0x02000000, // Extend change to start of
  659. // growsup vma (mprotect only).
  660. }
  661. [Map][Flags]
  662. [CLSCompliant (false)]
  663. public enum MsyncFlags : int {
  664. MS_ASYNC = 0x1, // Sync memory asynchronously.
  665. MS_SYNC = 0x4, // Synchronous memory sync.
  666. MS_INVALIDATE = 0x2, // Invalidate the caches.
  667. }
  668. [Map][Flags]
  669. [CLSCompliant (false)]
  670. public enum MlockallFlags : int {
  671. MCL_CURRENT = 0x1, // Lock all currently mapped pages.
  672. MCL_FUTURE = 0x2, // Lock all additions to address
  673. }
  674. [Map][Flags]
  675. [CLSCompliant (false)]
  676. public enum MremapFlags : ulong {
  677. MREMAP_MAYMOVE = 0x1,
  678. }
  679. #endregion
  680. #region Structures
  681. [Map ("struct flock")]
  682. public struct Flock
  683. #if NET_2_0
  684. : IEquatable <Flock>
  685. #endif
  686. {
  687. [CLSCompliant (false)]
  688. public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
  689. [CLSCompliant (false)]
  690. public SeekFlags l_whence; // How to interpret l_start
  691. [off_t] public long l_start; // Starting offset for lock
  692. [off_t] public long l_len; // Number of bytes to lock
  693. [pid_t] public int l_pid; // PID of process blocking our lock (F_GETLK only)
  694. public override int GetHashCode ()
  695. {
  696. return l_type.GetHashCode () ^ l_whence.GetHashCode () ^
  697. l_start.GetHashCode () ^ l_len.GetHashCode () ^
  698. l_pid.GetHashCode ();
  699. }
  700. public override bool Equals (object obj)
  701. {
  702. if ((obj == null) || (obj.GetType () != GetType ()))
  703. return false;
  704. Flock value = (Flock) obj;
  705. return l_type == value.l_type && l_whence == value.l_whence &&
  706. l_start == value.l_start && l_len == value.l_len &&
  707. l_pid == value.l_pid;
  708. }
  709. public bool Equals (Flock value)
  710. {
  711. return l_type == value.l_type && l_whence == value.l_whence &&
  712. l_start == value.l_start && l_len == value.l_len &&
  713. l_pid == value.l_pid;
  714. }
  715. public static bool operator== (Flock lhs, Flock rhs)
  716. {
  717. return lhs.Equals (rhs);
  718. }
  719. public static bool operator!= (Flock lhs, Flock rhs)
  720. {
  721. return !lhs.Equals (rhs);
  722. }
  723. }
  724. [Map ("struct pollfd")]
  725. public struct Pollfd
  726. #if NET_2_0
  727. : IEquatable <Pollfd>
  728. #endif
  729. {
  730. public int fd;
  731. [CLSCompliant (false)]
  732. public PollEvents events;
  733. [CLSCompliant (false)]
  734. public PollEvents revents;
  735. public override int GetHashCode ()
  736. {
  737. return events.GetHashCode () ^ revents.GetHashCode ();
  738. }
  739. public override bool Equals (object obj)
  740. {
  741. if (obj == null || obj.GetType () != GetType ())
  742. return false;
  743. Pollfd value = (Pollfd) obj;
  744. return value.events == events && value.revents == revents;
  745. }
  746. public bool Equals (Pollfd value)
  747. {
  748. return value.events == events && value.revents == revents;
  749. }
  750. public static bool operator== (Pollfd lhs, Pollfd rhs)
  751. {
  752. return lhs.Equals (rhs);
  753. }
  754. public static bool operator!= (Pollfd lhs, Pollfd rhs)
  755. {
  756. return !lhs.Equals (rhs);
  757. }
  758. }
  759. [Map ("struct stat")]
  760. public struct Stat
  761. #if NET_2_0
  762. : IEquatable <Stat>
  763. #endif
  764. {
  765. [CLSCompliant (false)]
  766. [dev_t] public ulong st_dev; // device
  767. [CLSCompliant (false)]
  768. [ino_t] public ulong st_ino; // inode
  769. [CLSCompliant (false)]
  770. public FilePermissions st_mode; // protection
  771. [NonSerialized]
  772. #pragma warning disable 169
  773. private uint _padding_; // padding for structure alignment
  774. #pragma warning restore 169
  775. [CLSCompliant (false)]
  776. [nlink_t] public ulong st_nlink; // number of hard links
  777. [CLSCompliant (false)]
  778. [uid_t] public uint st_uid; // user ID of owner
  779. [CLSCompliant (false)]
  780. [gid_t] public uint st_gid; // group ID of owner
  781. [CLSCompliant (false)]
  782. [dev_t] public ulong st_rdev; // device type (if inode device)
  783. [off_t] public long st_size; // total size, in bytes
  784. [blksize_t] public long st_blksize; // blocksize for filesystem I/O
  785. [blkcnt_t] public long st_blocks; // number of blocks allocated
  786. [time_t] public long st_atime; // time of last access
  787. [time_t] public long st_mtime; // time of last modification
  788. [time_t] public long st_ctime; // time of last status change
  789. public override int GetHashCode ()
  790. {
  791. return st_dev.GetHashCode () ^
  792. st_ino.GetHashCode () ^
  793. st_mode.GetHashCode () ^
  794. st_nlink.GetHashCode () ^
  795. st_uid.GetHashCode () ^
  796. st_gid.GetHashCode () ^
  797. st_rdev.GetHashCode () ^
  798. st_size.GetHashCode () ^
  799. st_blksize.GetHashCode () ^
  800. st_blocks.GetHashCode () ^
  801. st_atime.GetHashCode () ^
  802. st_mtime.GetHashCode () ^
  803. st_ctime.GetHashCode ();
  804. }
  805. public override bool Equals (object obj)
  806. {
  807. if (obj == null || obj.GetType() != GetType ())
  808. return false;
  809. Stat value = (Stat) obj;
  810. return value.st_dev == st_dev &&
  811. value.st_ino == st_ino &&
  812. value.st_mode == st_mode &&
  813. value.st_nlink == st_nlink &&
  814. value.st_uid == st_uid &&
  815. value.st_gid == st_gid &&
  816. value.st_rdev == st_rdev &&
  817. value.st_size == st_size &&
  818. value.st_blksize == st_blksize &&
  819. value.st_blocks == st_blocks &&
  820. value.st_atime == st_atime &&
  821. value.st_mtime == st_mtime &&
  822. value.st_ctime == st_ctime;
  823. }
  824. public bool Equals (Stat value)
  825. {
  826. return value.st_dev == st_dev &&
  827. value.st_ino == st_ino &&
  828. value.st_mode == st_mode &&
  829. value.st_nlink == st_nlink &&
  830. value.st_uid == st_uid &&
  831. value.st_gid == st_gid &&
  832. value.st_rdev == st_rdev &&
  833. value.st_size == st_size &&
  834. value.st_blksize == st_blksize &&
  835. value.st_blocks == st_blocks &&
  836. value.st_atime == st_atime &&
  837. value.st_mtime == st_mtime &&
  838. value.st_ctime == st_ctime;
  839. }
  840. public static bool operator== (Stat lhs, Stat rhs)
  841. {
  842. return lhs.Equals (rhs);
  843. }
  844. public static bool operator!= (Stat lhs, Stat rhs)
  845. {
  846. return !lhs.Equals (rhs);
  847. }
  848. }
  849. // `struct statvfs' isn't portable, so don't generate To/From methods.
  850. [Map]
  851. [CLSCompliant (false)]
  852. public struct Statvfs
  853. #if NET_2_0
  854. : IEquatable <Statvfs>
  855. #endif
  856. {
  857. public ulong f_bsize; // file system block size
  858. public ulong f_frsize; // fragment size
  859. [fsblkcnt_t] public ulong f_blocks; // size of fs in f_frsize units
  860. [fsblkcnt_t] public ulong f_bfree; // # free blocks
  861. [fsblkcnt_t] public ulong f_bavail; // # free blocks for non-root
  862. [fsfilcnt_t] public ulong f_files; // # inodes
  863. [fsfilcnt_t] public ulong f_ffree; // # free inodes
  864. [fsfilcnt_t] public ulong f_favail; // # free inodes for non-root
  865. public ulong f_fsid; // file system id
  866. public MountFlags f_flag; // mount flags
  867. public ulong f_namemax; // maximum filename length
  868. public override int GetHashCode ()
  869. {
  870. return f_bsize.GetHashCode () ^
  871. f_frsize.GetHashCode () ^
  872. f_blocks.GetHashCode () ^
  873. f_bfree.GetHashCode () ^
  874. f_bavail.GetHashCode () ^
  875. f_files.GetHashCode () ^
  876. f_ffree.GetHashCode () ^
  877. f_favail.GetHashCode () ^
  878. f_fsid.GetHashCode () ^
  879. f_flag.GetHashCode () ^
  880. f_namemax.GetHashCode ();
  881. }
  882. public override bool Equals (object obj)
  883. {
  884. if (obj == null || obj.GetType() != GetType ())
  885. return false;
  886. Statvfs value = (Statvfs) obj;
  887. return value.f_bsize == f_bsize &&
  888. value.f_frsize == f_frsize &&
  889. value.f_blocks == f_blocks &&
  890. value.f_bfree == f_bfree &&
  891. value.f_bavail == f_bavail &&
  892. value.f_files == f_files &&
  893. value.f_ffree == f_ffree &&
  894. value.f_favail == f_favail &&
  895. value.f_fsid == f_fsid &&
  896. value.f_flag == f_flag &&
  897. value.f_namemax == f_namemax;
  898. }
  899. public bool Equals (Statvfs value)
  900. {
  901. return value.f_bsize == f_bsize &&
  902. value.f_frsize == f_frsize &&
  903. value.f_blocks == f_blocks &&
  904. value.f_bfree == f_bfree &&
  905. value.f_bavail == f_bavail &&
  906. value.f_files == f_files &&
  907. value.f_ffree == f_ffree &&
  908. value.f_favail == f_favail &&
  909. value.f_fsid == f_fsid &&
  910. value.f_flag == f_flag &&
  911. value.f_namemax == f_namemax;
  912. }
  913. public static bool operator== (Statvfs lhs, Statvfs rhs)
  914. {
  915. return lhs.Equals (rhs);
  916. }
  917. public static bool operator!= (Statvfs lhs, Statvfs rhs)
  918. {
  919. return !lhs.Equals (rhs);
  920. }
  921. }
  922. [Map ("struct timeval")]
  923. public struct Timeval
  924. #if NET_2_0
  925. : IEquatable <Timeval>
  926. #endif
  927. {
  928. [time_t] public long tv_sec; // seconds
  929. [suseconds_t] public long tv_usec; // microseconds
  930. public override int GetHashCode ()
  931. {
  932. return tv_sec.GetHashCode () ^ tv_usec.GetHashCode ();
  933. }
  934. public override bool Equals (object obj)
  935. {
  936. if (obj == null || obj.GetType () != GetType ())
  937. return false;
  938. Timeval value = (Timeval) obj;
  939. return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
  940. }
  941. public bool Equals (Timeval value)
  942. {
  943. return value.tv_sec == tv_sec && value.tv_usec == tv_usec;
  944. }
  945. public static bool operator== (Timeval lhs, Timeval rhs)
  946. {
  947. return lhs.Equals (rhs);
  948. }
  949. public static bool operator!= (Timeval lhs, Timeval rhs)
  950. {
  951. return !lhs.Equals (rhs);
  952. }
  953. }
  954. [Map ("struct timezone")]
  955. public struct Timezone
  956. #if NET_2_0
  957. : IEquatable <Timezone>
  958. #endif
  959. {
  960. public int tz_minuteswest; // minutes W of Greenwich
  961. #pragma warning disable 169
  962. private int tz_dsttime; // type of dst correction (OBSOLETE)
  963. #pragma warning restore 169
  964. public override int GetHashCode ()
  965. {
  966. return tz_minuteswest.GetHashCode ();
  967. }
  968. public override bool Equals (object obj)
  969. {
  970. if (obj == null || obj.GetType () != GetType ())
  971. return false;
  972. Timezone value = (Timezone) obj;
  973. return value.tz_minuteswest == tz_minuteswest;
  974. }
  975. public bool Equals (Timezone value)
  976. {
  977. return value.tz_minuteswest == tz_minuteswest;
  978. }
  979. public static bool operator== (Timezone lhs, Timezone rhs)
  980. {
  981. return lhs.Equals (rhs);
  982. }
  983. public static bool operator!= (Timezone lhs, Timezone rhs)
  984. {
  985. return !lhs.Equals (rhs);
  986. }
  987. }
  988. [Map ("struct utimbuf")]
  989. public struct Utimbuf
  990. #if NET_2_0
  991. : IEquatable <Utimbuf>
  992. #endif
  993. {
  994. [time_t] public long actime; // access time
  995. [time_t] public long modtime; // modification time
  996. public override int GetHashCode ()
  997. {
  998. return actime.GetHashCode () ^ modtime.GetHashCode ();
  999. }
  1000. public override bool Equals (object obj)
  1001. {
  1002. if (obj == null || obj.GetType () != GetType ())
  1003. return false;
  1004. Utimbuf value = (Utimbuf) obj;
  1005. return value.actime == actime && value.modtime == modtime;
  1006. }
  1007. public bool Equals (Utimbuf value)
  1008. {
  1009. return value.actime == actime && value.modtime == modtime;
  1010. }
  1011. public static bool operator== (Utimbuf lhs, Utimbuf rhs)
  1012. {
  1013. return lhs.Equals (rhs);
  1014. }
  1015. public static bool operator!= (Utimbuf lhs, Utimbuf rhs)
  1016. {
  1017. return !lhs.Equals (rhs);
  1018. }
  1019. }
  1020. [Map ("struct timespec")]
  1021. public struct Timespec
  1022. #if NET_2_0
  1023. : IEquatable <Timespec>
  1024. #endif
  1025. {
  1026. [time_t] public long tv_sec; // Seconds.
  1027. public long tv_nsec; // Nanoseconds.
  1028. public override int GetHashCode ()
  1029. {
  1030. return tv_sec.GetHashCode () ^ tv_nsec.GetHashCode ();
  1031. }
  1032. public override bool Equals (object obj)
  1033. {
  1034. if (obj == null || obj.GetType () != GetType ())
  1035. return false;
  1036. Timespec value = (Timespec) obj;
  1037. return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
  1038. }
  1039. public bool Equals (Timespec value)
  1040. {
  1041. return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec;
  1042. }
  1043. public static bool operator== (Timespec lhs, Timespec rhs)
  1044. {
  1045. return lhs.Equals (rhs);
  1046. }
  1047. public static bool operator!= (Timespec lhs, Timespec rhs)
  1048. {
  1049. return !lhs.Equals (rhs);
  1050. }
  1051. }
  1052. [Flags][Map]
  1053. public enum EpollFlags {
  1054. EPOLL_CLOEXEC = 02000000,
  1055. EPOLL_NONBLOCK = 04000,
  1056. }
  1057. [Flags][Map]
  1058. [CLSCompliant (false)]
  1059. public enum EpollEvents : uint {
  1060. EPOLLIN = 0x001,
  1061. EPOLLPRI = 0x002,
  1062. EPOLLOUT = 0x004,
  1063. EPOLLRDNORM = 0x040,
  1064. EPOLLRDBAND = 0x080,
  1065. EPOLLWRNORM = 0x100,
  1066. EPOLLWRBAND = 0x200,
  1067. EPOLLMSG = 0x400,
  1068. EPOLLERR = 0x008,
  1069. EPOLLHUP = 0x010,
  1070. EPOLLRDHUP = 0x2000,
  1071. EPOLLONESHOT = 1 << 30,
  1072. EPOLLET = unchecked ((uint) (1 << 31))
  1073. }
  1074. public enum EpollOp {
  1075. EPOLL_CTL_ADD = 1,
  1076. EPOLL_CTL_DEL = 2,
  1077. EPOLL_CTL_MOD = 3,
  1078. }
  1079. [StructLayout (LayoutKind.Explicit, Size=12, Pack=1)]
  1080. [CLSCompliant (false)]
  1081. public struct EpollEvent {
  1082. [FieldOffset (0)]
  1083. public EpollEvents events;
  1084. [FieldOffset (4)]
  1085. public int fd;
  1086. [FieldOffset (4)]
  1087. public IntPtr ptr;
  1088. [FieldOffset (4)]
  1089. public uint u32;
  1090. [FieldOffset (4)]
  1091. public ulong u64;
  1092. }
  1093. #endregion
  1094. #region Classes
  1095. public sealed class Dirent
  1096. #if NET_2_0
  1097. : IEquatable <Dirent>
  1098. #endif
  1099. {
  1100. [CLSCompliant (false)]
  1101. public /* ino_t */ ulong d_ino;
  1102. public /* off_t */ long d_off;
  1103. [CLSCompliant (false)]
  1104. public ushort d_reclen;
  1105. public byte d_type;
  1106. public string d_name;
  1107. public override int GetHashCode ()
  1108. {
  1109. return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
  1110. d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
  1111. d_name.GetHashCode ();
  1112. }
  1113. public override bool Equals (object obj)
  1114. {
  1115. if (obj == null || GetType() != obj.GetType())
  1116. return false;
  1117. Dirent d = (Dirent) obj;
  1118. return Equals (d);
  1119. }
  1120. public bool Equals (Dirent value)
  1121. {
  1122. if (value == null)
  1123. return false;
  1124. return value.d_ino == d_ino && value.d_off == d_off &&
  1125. value.d_reclen == d_reclen && value.d_type == d_type &&
  1126. value.d_name == d_name;
  1127. }
  1128. public override string ToString ()
  1129. {
  1130. return d_name;
  1131. }
  1132. public static bool operator== (Dirent lhs, Dirent rhs)
  1133. {
  1134. return Object.Equals (lhs, rhs);
  1135. }
  1136. public static bool operator!= (Dirent lhs, Dirent rhs)
  1137. {
  1138. return !Object.Equals (lhs, rhs);
  1139. }
  1140. }
  1141. public sealed class Fstab
  1142. #if NET_2_0
  1143. : IEquatable <Fstab>
  1144. #endif
  1145. {
  1146. public string fs_spec;
  1147. public string fs_file;
  1148. public string fs_vfstype;
  1149. public string fs_mntops;
  1150. public string fs_type;
  1151. public int fs_freq;
  1152. public int fs_passno;
  1153. public override int GetHashCode ()
  1154. {
  1155. return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
  1156. fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
  1157. fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
  1158. }
  1159. public override bool Equals (object obj)
  1160. {
  1161. if (obj == null || GetType() != obj.GetType())
  1162. return false;
  1163. Fstab f = (Fstab) obj;
  1164. return Equals (f);
  1165. }
  1166. public bool Equals (Fstab value)
  1167. {
  1168. if (value == null)
  1169. return false;
  1170. return value.fs_spec == fs_spec && value.fs_file == fs_file &&
  1171. value.fs_vfstype == fs_vfstype && value.fs_mntops == fs_mntops &&
  1172. value.fs_type == fs_type && value.fs_freq == fs_freq &&
  1173. value.fs_passno == fs_passno;
  1174. }
  1175. public override string ToString ()
  1176. {
  1177. return fs_spec;
  1178. }
  1179. public static bool operator== (Fstab lhs, Fstab rhs)
  1180. {
  1181. return Object.Equals (lhs, rhs);
  1182. }
  1183. public static bool operator!= (Fstab lhs, Fstab rhs)
  1184. {
  1185. return !Object.Equals (lhs, rhs);
  1186. }
  1187. }
  1188. public sealed class Group
  1189. #if NET_2_0
  1190. : IEquatable <Group>
  1191. #endif
  1192. {
  1193. public string gr_name;
  1194. public string gr_passwd;
  1195. [CLSCompliant (false)]
  1196. public /* gid_t */ uint gr_gid;
  1197. public string[] gr_mem;
  1198. public override int GetHashCode ()
  1199. {
  1200. int memhc = 0;
  1201. for (int i = 0; i < gr_mem.Length; ++i)
  1202. memhc ^= gr_mem[i].GetHashCode ();
  1203. return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
  1204. gr_gid.GetHashCode () ^ memhc;
  1205. }
  1206. public override bool Equals (object obj)
  1207. {
  1208. if (obj == null || GetType() != obj.GetType())
  1209. return false;
  1210. Group g = (Group) obj;
  1211. return Equals (g);
  1212. }
  1213. public bool Equals (Group value)
  1214. {
  1215. if (value == null)
  1216. return false;
  1217. if (value.gr_gid != gr_gid)
  1218. return false;
  1219. if (value.gr_gid == gr_gid && value.gr_name == gr_name &&
  1220. value.gr_passwd == gr_passwd) {
  1221. if (value.gr_mem == gr_mem)
  1222. return true;
  1223. if (value.gr_mem == null || gr_mem == null)
  1224. return false;
  1225. if (value.gr_mem.Length != gr_mem.Length)
  1226. return false;
  1227. for (int i = 0; i < gr_mem.Length; ++i)
  1228. if (gr_mem[i] != value.gr_mem[i])
  1229. return false;
  1230. return true;
  1231. }
  1232. return false;
  1233. }
  1234. // Generate string in /etc/group format
  1235. public override string ToString ()
  1236. {
  1237. StringBuilder sb = new StringBuilder ();
  1238. sb.Append (gr_name).Append (":").Append (gr_passwd).Append (":");
  1239. sb.Append (gr_gid).Append (":");
  1240. GetMembers (sb, gr_mem);
  1241. return sb.ToString ();
  1242. }
  1243. private static void GetMembers (StringBuilder sb, string[] members)
  1244. {
  1245. if (members.Length > 0)
  1246. sb.Append (members[0]);
  1247. for (int i = 1; i < members.Length; ++i) {
  1248. sb.Append (",");
  1249. sb.Append (members[i]);
  1250. }
  1251. }
  1252. public static bool operator== (Group lhs, Group rhs)
  1253. {
  1254. return Object.Equals (lhs, rhs);
  1255. }
  1256. public static bool operator!= (Group lhs, Group rhs)
  1257. {
  1258. return !Object.Equals (lhs, rhs);
  1259. }
  1260. }
  1261. public sealed class Passwd
  1262. #if NET_2_0
  1263. : IEquatable <Passwd>
  1264. #endif
  1265. {
  1266. public string pw_name;
  1267. public string pw_passwd;
  1268. [CLSCompliant (false)]
  1269. public /* uid_t */ uint pw_uid;
  1270. [CLSCompliant (false)]
  1271. public /* gid_t */ uint pw_gid;
  1272. public string pw_gecos;
  1273. public string pw_dir;
  1274. public string pw_shell;
  1275. public override int GetHashCode ()
  1276. {
  1277. return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
  1278. pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
  1279. pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
  1280. pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
  1281. }
  1282. public override bool Equals (object obj)
  1283. {
  1284. if (obj == null || GetType() != obj.GetType())
  1285. return false;
  1286. Passwd p = (Passwd) obj;
  1287. return Equals (p);
  1288. }
  1289. public bool Equals (Passwd value)
  1290. {
  1291. if (value == null)
  1292. return false;
  1293. return value.pw_uid == pw_uid && value.pw_gid == pw_gid &&
  1294. value.pw_name == pw_name && value.pw_passwd == pw_passwd &&
  1295. value.pw_gecos == pw_gecos && value.pw_dir == pw_dir &&
  1296. value.pw_shell == pw_shell;
  1297. }
  1298. // Generate string in /etc/passwd format
  1299. public override string ToString ()
  1300. {
  1301. return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
  1302. pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
  1303. }
  1304. public static bool operator== (Passwd lhs, Passwd rhs)
  1305. {
  1306. return Object.Equals (lhs, rhs);
  1307. }
  1308. public static bool operator!= (Passwd lhs, Passwd rhs)
  1309. {
  1310. return !Object.Equals (lhs, rhs);
  1311. }
  1312. }
  1313. public sealed class Utsname
  1314. #if NET_2_0
  1315. : IEquatable <Utsname>
  1316. #endif
  1317. {
  1318. public string sysname;
  1319. public string nodename;
  1320. public string release;
  1321. public string version;
  1322. public string machine;
  1323. public string domainname;
  1324. public override int GetHashCode ()
  1325. {
  1326. return sysname.GetHashCode () ^ nodename.GetHashCode () ^
  1327. release.GetHashCode () ^ version.GetHashCode () ^
  1328. machine.GetHashCode () ^ domainname.GetHashCode ();
  1329. }
  1330. public override bool Equals (object obj)
  1331. {
  1332. if (obj == null || GetType() != obj.GetType())
  1333. return false;
  1334. Utsname u = (Utsname) obj;
  1335. return Equals (u);
  1336. }
  1337. public bool Equals (Utsname value)
  1338. {
  1339. return value.sysname == sysname && value.nodename == nodename &&
  1340. value.release == release && value.version == version &&
  1341. value.machine == machine && value.domainname == domainname;
  1342. }
  1343. // Generate string in /etc/passwd format
  1344. public override string ToString ()
  1345. {
  1346. return string.Format ("{0} {1} {2} {3} {4}",
  1347. sysname, nodename, release, version, machine);
  1348. }
  1349. public static bool operator== (Utsname lhs, Utsname rhs)
  1350. {
  1351. return Object.Equals (lhs, rhs);
  1352. }
  1353. public static bool operator!= (Utsname lhs, Utsname rhs)
  1354. {
  1355. return !Object.Equals (lhs, rhs);
  1356. }
  1357. }
  1358. //
  1359. // Convention: Functions *not* part of the standard C library AND part of
  1360. // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
  1361. //
  1362. // For example, the man page should be similar to:
  1363. //
  1364. // CONFORMING TO (or CONFORMS TO)
  1365. // XPG2, SUSv2, POSIX, etc.
  1366. //
  1367. // BSD- and GNU-specific exports can also be placed here.
  1368. //
  1369. // Non-POSIX/XPG/etc. functions can also be placed here if:
  1370. // (a) They'd be likely to be covered in a Steven's-like book
  1371. // (b) The functions would be present in libc.so (or equivalent).
  1372. //
  1373. // If a function has its own library, that's a STRONG indicator that the
  1374. // function should get a different binding, probably in its own assembly,
  1375. // so that package management can work sanely. (That is, we'd like to avoid
  1376. // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
  1377. // run, and libFooLib.so doesn't exist. That would be confusing.)
  1378. //
  1379. // The only methods in here should be:
  1380. // (1) low-level functions
  1381. // (2) "Trivial" function overloads. For example, if the parameters to a
  1382. // function are related (e.g. getgroups(2))
  1383. // (3) The return type SHOULD NOT be changed. If you want to provide a
  1384. // convenience function with a nicer return type, place it into one of
  1385. // the Mono.Unix.Unix* wrapper classes, and give it a .NET-styled name.
  1386. // - EXCEPTION: No public functions should have a `void' return type.
  1387. // `void' return types should be replaced with `int'.
  1388. // Rationality: `void'-return functions typically require a
  1389. // complicated call sequence, such as clear errno, then call, then
  1390. // check errno to see if any errors occurred. This sequence can't
  1391. // be done safely in managed code, as errno may change as part of
  1392. // the P/Invoke mechanism.
  1393. // Instead, add a MonoPosixHelper export which does:
  1394. // errno = 0;
  1395. // INVOKE SYSCALL;
  1396. // return errno == 0 ? 0 : -1;
  1397. // This lets managed code check the return value in the usual manner.
  1398. // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
  1399. // - If you're wrapping *broken* methods which make assumptions about
  1400. // input data, such as that an argument refers to N bytes of data.
  1401. // This is currently limited to cuserid(3) and encrypt(3).
  1402. // - If you call functions which themselves generate exceptions.
  1403. // This is the case for using NativeConvert, which will throw an
  1404. // exception if an invalid/unsupported value is used.
  1405. //
  1406. // Naming Conventions:
  1407. // - Syscall method names should have the same name as the function being
  1408. // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
  1409. // consult the appropriate man page if necessary.
  1410. // - Methods need not have the same arguments IF this simplifies or
  1411. // permits correct usage. The current example is syslog, in which
  1412. // syslog(3)'s single `priority' argument is split into SyslogFacility
  1413. // and SyslogLevel arguments.
  1414. // - Type names (structures, classes, enumerations) are always PascalCased.
  1415. // - Enumerations are named as <MethodName><ArgumentName>, and are located
  1416. // in the Mono.Unix.Native namespace. For readability, if ArgumentName
  1417. // is "cmd", use Command instead. For example, fcntl(2) takes a
  1418. // FcntlCommand argument. This naming convention is to provide an
  1419. // assocation between an enumeration and where it should be used, and
  1420. // allows a single method to accept multiple different enumerations
  1421. // (see mmap(2), which takes MmapProts and MmapFlags).
  1422. // - EXCEPTION: if an enumeration is shared between multiple different
  1423. // methods, AND/OR the "obvious" enumeration name conflicts with an
  1424. // existing .NET type, a more appropriate name should be used.
  1425. // Example: FilePermissions
  1426. // - EXCEPTION: [Flags] enumerations should get plural names to follow
  1427. // .NET name guidelines. Usually this doesn't result in a change
  1428. // (OpenFlags is the `flags' parameter for open(2)), but it can
  1429. // (mmap(2) prot ==> MmapProts, access(2) mode ==> AccessModes).
  1430. // - Enumerations should have the [Map] and (optional) [Flags] attributes.
  1431. // [Map] is required for make-map to find the type and generate the
  1432. // appropriate NativeConvert conversion functions.
  1433. // - Enumeration contents should match the original Unix names. This helps
  1434. // with documentation (the existing man pages are still useful), and is
  1435. // required for use with the make-map generation program.
  1436. // - Structure names should be the PascalCased version of the actual
  1437. // structure name (struct flock ==> Flock). Structure members should
  1438. // have the same names, or a (reasonably) portable subset (Dirent being
  1439. // the poster child for questionable members).
  1440. // - Whether the managed type should be a reference type (class) or a
  1441. // value type (struct) should be determined on a case-by-case basis:
  1442. // if you ever need to be able to use NULL for it (such as with Dirent,
  1443. // Group, Passwd, as these are method return types and `null' is used
  1444. // to signify the end), it should be a reference type; otherwise, use
  1445. // your discretion, and keep any expected usage patterns in mind.
  1446. // - Syscall should be a Single Point Of Truth (SPOT). There should be
  1447. // only ONE way to do anything. By convention, the Linux function names
  1448. // are used, but that need not always be the case (use your discretion).
  1449. // It SHOULD NOT be required that developers know what platform they're
  1450. // on, and choose among a set of similar functions. In short, anything
  1451. // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
  1452. // we can afford to clean things up whenever possible.
  1453. // - Examples:
  1454. // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
  1455. // statvfs(2). MonoPosixHelper will "thunk" between the two,
  1456. // exporting a statvfs that works across platforms.
  1457. // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
  1458. // instead provides getvfsent(3). MonoPosixHelper provides wrappers
  1459. // to convert getvfsent(3) into Fstab data.
  1460. // - Exception: If it isn't possible to cleanly wrap platforms, then the
  1461. // method shouldn't be exported. The user will be expected to do their
  1462. // own platform check and their own DllImports.
  1463. // Examples: mount(2), umount(2), etc.
  1464. // - Note: if a platform doesn't support a function AT ALL, the
  1465. // MonoPosixHelper wrapper won't be compiled, resulting in a
  1466. // EntryPointNotFoundException. This is also consistent with a missing
  1467. // P/Invoke into libc.so.
  1468. //
  1469. [CLSCompliant (false)]
  1470. public sealed class Syscall : Stdlib
  1471. {
  1472. new internal const string LIBC = "libc";
  1473. private Syscall () {}
  1474. //
  1475. // <aio.h>
  1476. //
  1477. // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
  1478. // aio_return(3), aio_suspend(3), aio_write(3)
  1479. //
  1480. // Then update UnixStream.BeginRead to use the aio* functions.
  1481. #region <attr/xattr.h> Declarations
  1482. //
  1483. // <attr/xattr.h> -- COMPLETE
  1484. //
  1485. // setxattr(2)
  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))]
  1492. string path,
  1493. [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
  1494. string name, byte[] value, ulong size, XattrFlags flags);
  1495. public static int setxattr (string path, string name, byte [] value, ulong size)
  1496. {
  1497. return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
  1498. }
  1499. public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
  1500. {
  1501. return setxattr (path, name, value, (ulong) value.Length, flags);
  1502. }
  1503. public static int setxattr (string path, string name, byte [] value)
  1504. {
  1505. return setxattr (path, name, value, (ulong) value.Length);
  1506. }
  1507. // lsetxattr(2)
  1508. // int lsetxattr (const char *path, const char *name,
  1509. // const void *value, size_t size, int flags);
  1510. [DllImport (MPH, SetLastError=true,
  1511. EntryPoint="Mono_Posix_Syscall_lsetxattr")]
  1512. public static extern int lsetxattr (
  1513. [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
  1514. string path,
  1515. [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
  1516. string name, byte[] value, ulong size, XattrFlags flags);
  1517. public static int lsetxattr (string path, string name, byte [] value, ulong size)
  1518. {
  1519. return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
  1520. }
  1521. public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
  1522. {
  1523. return lsetxattr (path, name, value, (ulong) value.Length, flags);
  1524. }
  1525. public static int lsetxattr (string path, string name, byte [] value)
  1526. {
  1527. return lsetxattr (path, name, value, (ulong) value.Length);
  1528. }
  1529. // fsetxattr(2)
  1530. // int fsetxattr (int fd, const char *name,
  1531. // const void *value, size_t size, int flags);
  1532. [DllImport (MPH, SetLastError=true,
  1533. EntryPoint="Mono_Posix_Syscall_fsetxattr")]
  1534. public static extern int fsetxattr (int fd,
  1535. [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
  1536. string name, byte[] value, ulong size, XattrFlags flags);
  1537. public static int fsetxattr (int fd, string name, byte [] value, ulong size)
  1538. {
  1539. return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
  1540. }
  1541. public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
  1542. {
  1543. return fsetxattr

Large files files are truncated, but you can click here to view the full file