ostypes.inc 13 KB

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