ostypes.inc 17 KB

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