ostypes.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Free Pascal development team
  4. Types and structures for baseunix unit, also used in system.
  5. This file implements all the types/constants which must
  6. be defined to port FPC to a new POSIX compliant OS.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {***********************************************************************}
  14. { POSIX STRUCTURES }
  15. {***********************************************************************}
  16. {$ifdef FPC_IS_SYSTEM}
  17. {$i ptypes.inc}
  18. {$ENDIF}
  19. {$ifdef cpupowerpc}
  20. {$ifdef netbsd}
  21. {$define netbsdpowerpc}
  22. {$endif}
  23. {$endif}
  24. {$if (defined(darwin) and defined(cpuarm)) or defined(iphonesim)}
  25. {$define darwinarm}
  26. {$endif}
  27. // CONST SYS_NMLN=65;
  28. // Can't find these two in Posix and in FreeBSD
  29. //CONST
  30. // _UTSNAME_LENGTH = ;
  31. // _UTSNAME_NODENAME_LENGTH = ;
  32. CONST // OS specific parameters for general<fd,sig>set behaviour
  33. BITSINWORD = 8*sizeof(longint);
  34. FD_MAXFDSET = 1024;
  35. ln2bitsinword = 5; { 32bit : ln(32)/ln(2)=5 }
  36. ln2bitmask = 1 shl ln2bitsinword - 1;
  37. wordsinfdset = FD_MAXFDSET DIV BITSINWORD; // words in fdset_t
  38. wordsinsigset = SIG_MAXSIG DIV BITSINWORD;
  39. TYPE
  40. { system information services }
  41. utsname = record
  42. sysname : Array[0..SYS_NMLN-1] OF Char; // Name of this OS
  43. nodename: Array[0..SYS_NMLN-1] OF Char; // Name of this network node.
  44. release : Array[0..SYS_NMLN-1] OF Char; // Release level.
  45. version : Array[0..SYS_NMLN-1] OF Char; // Version level.
  46. machine : Array[0..SYS_NMLN-1] OF Char; // Hardware type.
  47. end;
  48. TUtsName= utsname;
  49. pUtsName= ^utsname;
  50. { file characteristics services }
  51. stat = record { the types are real}
  52. {$ifdef openbsd}
  53. st_mode : mode_t; // inode protection mode
  54. {$endif}
  55. st_dev : dev_t; // inode's device
  56. {$ifdef darwinarm}
  57. st_mode : mode_t; // inode protection mode
  58. st_nlink : nlink_t; // number of hard links
  59. st_ino : ino_t; // inode's number
  60. {$else}
  61. {$ifdef netbsd_use_stat30}
  62. { order is inverted for better alignment probably }
  63. st_mode : mode_t; // inode protection mode
  64. st_ino : ino_t; // inode's number
  65. {$else not netbsd}
  66. st_ino : ino_t; // inode's number
  67. {$ifndef openbsd}
  68. st_mode : mode_t; // inode protection mode
  69. {$endif}
  70. {$endif not netbsd}
  71. st_nlink : nlink_t; // number of hard links
  72. {$endif}
  73. st_uid : uid_t; // user ID of the file's owner
  74. st_gid : gid_t; // group ID of the file's group
  75. st_rdev : dev_t; // device type
  76. st_atime : time_t; // time of last access
  77. st_atimensec : clong; // nsec of last access
  78. st_mtime : time_t; // time of last data modification
  79. st_mtimensec : clong; // nsec of last data modification
  80. st_ctime : time_t; // time of last file status change
  81. st_ctimensec : clong; // nsec of last file status change
  82. {$ifdef darwinarm}
  83. st_birthtime : time_t; // File creation time
  84. st_birthtimensec : clong; // nsec of file creation time
  85. {$endif}
  86. {$ifdef netbsdPowerpc}
  87. st_padd1 : cint;
  88. {$endif}
  89. st_size : off_t; // file size, in bytes
  90. st_blocks : cint64; // blocks allocated for file
  91. st_blksize : cuint32; // optimal blocksize for I/O
  92. st_flags : cuint32; // user defined flags for file
  93. st_gen : cuint32; // file generation number
  94. {$ifdef netbsdPowerpc}
  95. st_padd2 : cint;
  96. {$endif}
  97. {$ifndef NetBSD}
  98. st_lspare : cint32;
  99. {$endif}
  100. {$ifdef openbsd}
  101. st_birthtime : time_t; // File creation time
  102. st_birthtimensec : clong; // nsec of file creation time
  103. {$endif}
  104. st_qspare : array[0..1] Of cint64;
  105. end;
  106. TStat = stat;
  107. pStat = ^stat;
  108. { directory services }
  109. {$ifndef darwinarm}
  110. dirent = record
  111. {$ifdef openbsd}
  112. d_fileno : ino_t;
  113. {$else}
  114. d_fileno : cuint32; // file number of entry
  115. {$endif}
  116. {$ifdef openbsd}
  117. d_off : off_t;
  118. {$endif}
  119. d_reclen : cuint16; // length of this record
  120. d_type : cuint8; // file type, see below
  121. d_namlen : cuint8; // length of string in d_name
  122. {$ifdef openbsd}
  123. d_padding : array[1..4] of cuint8;
  124. {$endif}
  125. d_name : array[0..(255 + 1)-1] of char; // name must be no longer than this
  126. end;
  127. {$else not darwinarm}
  128. {$packrecords 4}
  129. { available on Mac OS X 10.6 and later, and used by all iPhoneOS versions }
  130. dirent = record
  131. d_fileno : cuint64; // file number of entry
  132. d_seekoff : cuint64; // seek offset (optional, used by servers)
  133. d_reclen : cuint16; // length of this record
  134. d_namlen : cuint16; // length of string in d_name
  135. d_type : cuint8; // file type, see below
  136. d_name : array[0..PATH_MAX-1] of char; // name must be no longer than this
  137. end;
  138. {$packrecords c}
  139. {$endif darwinarm}
  140. TDirent = dirent;
  141. pDirent = ^dirent;
  142. dir = record
  143. dd_fd : cint; // file descriptor associated with directory
  144. dd_loc : clong; // offset in current buffer
  145. dd_size : clong; // amount of data returned by getdirentries
  146. dd_buf : pchar; // data buffer
  147. dd_len : cint; // size of data buffer
  148. {$ifdef openbsd}
  149. dd_curpos : off_t;
  150. dd_lock : pointer;
  151. dd_rewind : clong;
  152. {$else}
  153. {$ifdef netbsdpowerpc}
  154. dd_pad1 : cint;
  155. dd_seek : cint64; // magic cookie returned by getdirentries
  156. {$else}
  157. dd_seek : clong; // magic cookie returned by getdirentries
  158. {$endif}
  159. dd_rewind : clong; // magic cookie for rewinding
  160. dd_flags : cint; // flags for readdir
  161. {$ifdef darwin}
  162. __dd_lock : pthread_mutex_t; // for thread locking
  163. __dd_td : pointer; // telldir position recording
  164. {$endif}
  165. {$endif not openbsd}
  166. end;
  167. TDir = dir;
  168. pDir = ^dir;
  169. utimbuf = record
  170. actime : time_t;
  171. modtime : time_t;
  172. end;
  173. TUtimBuf = utimbuf;
  174. putimbuf = ^utimbuf;
  175. flock = record
  176. l_start : off_t; { starting offset }
  177. l_len : off_t; { len = 0 means until end of file }
  178. l_pid : pid_t; { lock owner }
  179. l_type : cshort; { lock type: read/write, etc. }
  180. l_whence: cshort; { type of l_start }
  181. end;
  182. TFlock = flock;
  183. pFlock = ^flock;
  184. tms = record
  185. tms_utime : clock_t; { User CPU time }
  186. tms_stime : clock_t; { System CPU time }
  187. tms_cutime : clock_t; { User CPU time of terminated child procs }
  188. tms_cstime : clock_t; { System CPU time of terminated child procs }
  189. end;
  190. TTms= tms;
  191. pTms= ^tms;
  192. TFDSet = ARRAY[0..(FD_MAXFDSET div 32)-1] of Cardinal;
  193. pFDSet = ^TFDSet;
  194. {***********************************************************************}
  195. { POSIX CONSTANT ROUTINE DEFINITIONS }
  196. {***********************************************************************}
  197. CONST
  198. { access routine - these maybe OR'ed together }
  199. F_OK = 0; { test for existence of file }
  200. R_OK = 4; { test for read permission on file }
  201. W_OK = 2; { test for write permission on file }
  202. X_OK = 1; { test for execute or search permission }
  203. { seek routine }
  204. SEEK_SET = 0; { seek from beginning of file }
  205. SEEK_CUR = 1; { seek from current position }
  206. SEEK_END = 2; { seek from end of file }
  207. { open routine }
  208. { File access modes for `open' and `fcntl'. }
  209. O_RDONLY = 0; { Open read-only. }
  210. O_WRONLY = 1; { Open write-only. }
  211. O_RDWR = 2; { Open read/write. }
  212. { Bits OR'd into the second argument to open. }
  213. O_CREAT = $200; { Create file if it doesn't exist. }
  214. O_EXCL = $800; { Fail if file already exists. }
  215. O_TRUNC = $400; { Truncate file to zero length. }
  216. O_NOCTTY = $8000; { Don't assign a controlling terminal. }
  217. { File status flags for `open' and `fcntl'. }
  218. O_APPEND = 8; { Writes append to the file. }
  219. O_NONBLOCK = 4; { Non-blocking I/O. }
  220. {$ifdef freebsd}
  221. { Other }
  222. O_SHLOCK = $10; { Open with shared file lock }
  223. O_EXLOCK = $20; { Open with exclusive file lock }
  224. O_ASYNC = $40; { Signal pgrp when data ready }
  225. O_FSYNC = $80; { Synchronous writes }
  226. O_SYNC = $80; { POSIX synonym for O_FSYNC }
  227. O_NOFOLLOW = $100; { Don't follow symlinks }
  228. O_DIRECT =$10000; { Attempt to bypass buffer cache }
  229. {$endif}
  230. { mode_t possible values }
  231. S_IRUSR = %0100000000; { Read permission for owner }
  232. S_IWUSR = %0010000000; { Write permission for owner }
  233. S_IXUSR = %0001000000; { Exec permission for owner }
  234. S_IRGRP = %0000100000; { Read permission for group }
  235. S_IWGRP = %0000010000; { Write permission for group }
  236. S_IXGRP = %0000001000; { Exec permission for group }
  237. S_IROTH = %0000000100; { Read permission for world }
  238. S_IWOTH = %0000000010; { Write permission for world }
  239. S_IXOTH = %0000000001; { Exec permission for world }
  240. S_IRWXU = S_IRUSR or S_IWUSR or S_IXUSR;
  241. S_IRWXG = S_IRGRP or S_IWGRP or S_IXGRP;
  242. S_IRWXO = S_IROTH or S_IWOTH or S_IXOTH;
  243. { Used for waitpid }
  244. WNOHANG = 1; { don't block waiting }
  245. WUNTRACED = 2; { report status of stopped children }
  246. { For File control mechanism }
  247. F_DupFd = 0; { duplicate file descriptor }
  248. F_GetFd = 1; { get file descriptor flags }
  249. F_SetFd = 2; { set file descriptor flags }
  250. F_GetFl = 3; { get file status flags }
  251. F_SetFl = 4; { set file status flags }
  252. F_GetOwn = 5; { get SIGIO/SIGURG proc/pgrp }
  253. F_SetOwn = 6; { set SIGIO/SIGURG proc/pgrp }
  254. {$ifdef freebsd}
  255. F_OGetLk = 7; { get record locking information }
  256. F_OSetLk = 8; { set record locking information }
  257. F_OSetLkW = 9; { F_SETLK; wait if blocked }
  258. F_Dup2Fd = 10; { duplicate file descriptor to arg }
  259. F_GetLk = 11; { get record locking information}
  260. F_SetLk = 12; { set record locking information }
  261. F_SetLkW = 13; { F_SETLK; wait if blocked }
  262. F_SetLkRemote = 14; { debugging support for remote locks }
  263. {$endif}
  264. {$ifdef netbsd}
  265. F_GetLk = 7; { get record locking information}
  266. F_SetLk = 8; { set record locking information }
  267. F_SetLkW = 9; { F_SETLK; wait if blocked }
  268. F_CloseM = 10; { close all fds >= to the one given }
  269. F_MaxFd = 11; { return the max open fd }
  270. F_DupFd_CloExec = 12; { close on exec duplicated fd }
  271. {$endif}
  272. {$ifdef openbsd}
  273. F_GetLk = 7; { get record locking information}
  274. F_SetLk = 8; { set record locking information }
  275. F_SetLkW = 9; { F_SETLK; wait if blocked }
  276. F_DupFd_CloExec = 10; { duplicate with FD_CLOEXEC set }
  277. {$endif}
  278. {$ifdef darwin}
  279. F_GetLk = 7; { get record locking information}
  280. F_SetLk = 8; { set record locking information }
  281. F_SetLkW = 9; { F_SETLK; wait if blocked }
  282. {$endif}
  283. { File descriptor flags (F_GETFD, F_SETFD) }
  284. FD_CLOEXEC = 1; { close-on-exec flag }
  285. { Record locking flags (F_GETLK, F_SETLK, F_SETLKW) }
  286. F_RDLCK = 1; { shared or read lock }
  287. F_UNLCK = 2; { unlock }
  288. F_WRLCK = 3; { exclusive or write lock }
  289. {$ifdef freebsd}
  290. F_UNLCKSYS = 4; { purge locks for a given system ID }
  291. F_CANCEL = 5; { cancel an async lock request }
  292. {$endif}
  293. {$ifndef darwin}
  294. F_WAIT = $10; { Wait until lock is granted }
  295. F_FLOCK = $20; { Use flock(2) semantics for lock }
  296. F_POSIX = $40; { Use POSIX semantics for lock }
  297. {$endif}
  298. {$ifdef freebsd}
  299. F_REMOTE = $80; { Lock owner is remote NFS client }
  300. F_NOINTR = $100; { Ignore signals when waiting }
  301. {$endif}
  302. {$ifdef darwin}
  303. F_CHKCLEAN = 41; { Used for regression test }
  304. F_PREALLOCATE = 42; { Preallocate storage }
  305. F_SETSIZE = 43; { Truncate a file without zeroing space }
  306. F_RDADVISE = 44; { Issue an advisory read async with no copy to user }
  307. F_RDAHEAD = 45; { turn read ahead off/on }
  308. F_READBOOTSTRAP = 46; { Read bootstrap from disk }
  309. F_WRITEBOOTSTRAP = 47; { Write bootstrap on disk }
  310. F_NOCACHE = 48; { turning data caching off/on }
  311. F_LOG2PHYS = 49; { file offset to device offset }
  312. F_GETPATH = 50; { return the full path of the fd }
  313. F_FULLFSYNC = 51; { fsync + ask the drive to flush to the media }
  314. F_PATHPKG_CHECK = 52; { find which component (if any) is a package }
  315. F_FREEZE_FS = 53; { "freeze" all fs operations }
  316. F_THAW_FS = 54; { "thaw" all fs operations }
  317. F_GLOBAL_NOCACHE = 55; { turn data caching off/on (globally) for this file }
  318. {$endif}
  319. type
  320. timezone = record
  321. tz_minuteswest,
  322. tz_dsttime : cint;
  323. end;
  324. ptimezone =^timezone;
  325. TTimeZone = timezone;
  326. rusage = record
  327. ru_utime : timeval; { user time used }
  328. ru_stime : timeval; { system time used }
  329. ru_maxrss : clong; { max resident set size }
  330. ru_ixrss : clong; { integral shared memory size }
  331. ru_idrss : clong; { integral unshared data " }
  332. ru_isrss : clong; { integral unshared stack " }
  333. ru_minflt : clong; { page reclaims }
  334. ru_majflt : clong; { page faults }
  335. ru_nswap : clong; { swaps }
  336. ru_inblock : clong; { block input operations }
  337. ru_oublock : clong; { block output operations }
  338. ru_msgsnd : clong; { messages sent }
  339. ru_msgrcv : clong; { messages received }
  340. ru_nsignals : clong; { signals received }
  341. ru_nvcsw : clong; { voluntary context switches }
  342. ru_nivcsw : clong; { involuntary " }
  343. end;
  344. // #define ru_last ru_nivcsw
  345. // #define ru_first ru_ixrss
  346. { auto generated by a c prog, statmacr.c}
  347. Const
  348. S_IFMT = 61440;
  349. S_IFIFO = 4096;
  350. S_IFCHR = 8192;
  351. S_IFDIR = 16384;
  352. S_IFBLK = 24576;
  353. S_IFREG = 32768;
  354. S_IFLNK = 40960;
  355. S_IFSOCK= 49152;
  356. S_IFWHT = 57344;
  357. S_ISVTX = 512;
  358. {
  359. * Resource limits from FreeBSD5. To be checked for the others.
  360. }
  361. RLIMIT_CPU = 0; { cpu time in milliseconds }
  362. RLIMIT_FSIZE = 1; { maximum file size }
  363. RLIMIT_DATA = 2; { data size }
  364. RLIMIT_STACK = 3; { stack size }
  365. RLIMIT_CORE = 4; { core file size }
  366. RLIMIT_RSS = 5; { resident set size }
  367. RLIMIT_MEMLOCK = 6; { locked-in-memory address space }
  368. RLIMIT_NPROC = 7; { number of processes }
  369. RLIMIT_NOFILE = 8; { number of open files }
  370. {$IFDEF FreeBSD}
  371. RLIMIT_SBSIZE = 9; { maximum size of all socket buffers }
  372. RLIMIT_VMEM =10; { virtual process size (inclusive of mmap) }
  373. RLIMIT_AS = RLIMIT_VMEM;
  374. {$ELSE}
  375. RLIMIT_AS = 5; { address space= resident set size}
  376. {$ENDIF}
  377. {$ifdef FreeBSD}
  378. RLIM_NLIMITS =11; { number of resource limits }
  379. {$endif}
  380. {$ifdef Darwin} // OS X 10.3
  381. RLIM_NLIMITS =9; { number of resource limits }
  382. {$endif}
  383. Type
  384. TRLimit = record
  385. rlim_cur, { current (soft) limit }
  386. rlim_max : TRLim; { maximum value for rlim_cur }
  387. end;
  388. PRLimit = ^TRLimit;
  389. iovec = record
  390. iov_base : pointer;
  391. iov_len : size_t;
  392. end;
  393. tiovec=iovec;
  394. piovec=^tiovec;
  395. CONST
  396. { Constansts for MMAP }
  397. {$ifdef FPC_IS_SYSTEM}
  398. MAP_PRIVATE =2;
  399. {$endif}
  400. MAP_ANONYMOUS =$1000;
  401. const
  402. POLLIN = $0001;
  403. POLLPRI = $0002;
  404. POLLOUT = $0004;
  405. POLLERR = $0008;
  406. POLLHUP = $0010;
  407. POLLNVAL = $0020;
  408. { XOpen, XPG 4.2 }
  409. POLLRDNORM = $0040;
  410. POLLRDBAND = $0080;
  411. POLLWRNORM = POLLOUT;
  412. POLLWRBAND = $0100;
  413. type
  414. pollfd = record
  415. fd: cint;
  416. events: cshort;
  417. revents: cshort;
  418. end;
  419. tpollfd = pollfd;
  420. ppollfd = ^pollfd;
  421. {*************************************************************************}
  422. { SIGNALS }
  423. {*************************************************************************}
  424. {$i signal.inc}