ostypes.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. // CONST SYS_NMLN=65;
  25. // Can't find these two in Posix and in FreeBSD
  26. //CONST
  27. // _UTSNAME_LENGTH = ;
  28. // _UTSNAME_NODENAME_LENGTH = ;
  29. CONST // OS specific parameters for general<fd,sig>set behaviour
  30. BITSINWORD = 8*sizeof(longint);
  31. FD_MAXFDSET = 1024;
  32. ln2bitsinword = 5; { 32bit : ln(32)/ln(2)=5 }
  33. ln2bitmask = 1 shl ln2bitsinword - 1;
  34. wordsinfdset = FD_MAXFDSET DIV BITSINWORD; // words in fdset_t
  35. wordsinsigset = SIG_MAXSIG DIV BITSINWORD;
  36. TYPE
  37. { system information services }
  38. utsname = record
  39. sysname : Array[0..SYS_NMLN-1] OF Char; // Name of this OS
  40. nodename: Array[0..SYS_NMLN-1] OF Char; // Name of this network node.
  41. release : Array[0..SYS_NMLN-1] OF Char; // Release level.
  42. version : Array[0..SYS_NMLN-1] OF Char; // Version level.
  43. machine : Array[0..SYS_NMLN-1] OF Char; // Hardware type.
  44. end;
  45. TUtsName= utsname;
  46. pUtsName= ^utsname;
  47. { file characteristics services }
  48. stat = record { the types are real}
  49. case byte of
  50. 0:
  51. (dev : dev_t; // inode's device
  52. ino : ino_t; // inode's number
  53. mode : mode_t; // inode protection mode
  54. nlink : nlink_t; // number of hard links
  55. uid : uid_t; // user ID of the file's owner
  56. gid : gid_t; // group ID of the file's group
  57. rdev : dev_t; // device type
  58. atime : time_t; // time of last access
  59. atimensec : clong; // nsec of last access
  60. mtime : time_t; // time of last data modification
  61. mtimensec : clong; // nsec of last data modification
  62. ctime : time_t; // time of last file status change
  63. ctimensec : clong; // nsec of last file status change
  64. {$ifdef netbsdPowerpc}
  65. padd1 : cint;
  66. {$endif}
  67. size : off_t; // file size, in bytes
  68. blocks : cint64; // blocks allocated for file
  69. blksize : cuint32; // optimal blocksize for I/O
  70. flags : cuint32; // user defined flags for file
  71. gen : cuint32; // file generation number
  72. {$ifdef netbsdPowerpc}
  73. padd2 : cint;
  74. {$endif}
  75. {$ifndef NetBSD}
  76. lspare : cint32;
  77. {$endif}
  78. qspare : array[0..1] Of cint64;);
  79. 1:
  80. (st_dev : dev_t; // inode's device
  81. st_ino : ino_t; // inode's number
  82. st_mode : mode_t; // inode protection mode
  83. st_nlink : nlink_t; // number of hard links
  84. st_uid : uid_t; // user ID of the file's owner
  85. st_gid : gid_t; // group ID of the file's group
  86. st_rdev : dev_t; // device type
  87. st_atime : time_t; // time of last access
  88. st_atimensec : clong; // nsec of last access
  89. st_mtime : time_t; // time of last data modification
  90. st_mtimensec : clong; // nsec of last data modification
  91. st_ctime : time_t; // time of last file status change
  92. st_ctimensec : clong; // nsec of last file status change
  93. {$ifdef netbsdPowerpc}
  94. st_padd1 : cint;
  95. {$endif}
  96. st_size : off_t; // file size, in bytes
  97. st_blocks : cint64; // blocks allocated for file
  98. st_blksize : cuint32; // optimal blocksize for I/O
  99. st_flags : cuint32; // user defined flags for file
  100. st_gen : cuint32; // file generation number
  101. {$ifdef netbsdPowerpc}
  102. st_padd2 : cint;
  103. {$endif}
  104. {$ifndef NetBSD}
  105. st_lspare : cint32;
  106. {$endif}
  107. st_qspare : array[0..1] Of cint64;);
  108. end;
  109. TStat = stat;
  110. pStat = ^stat;
  111. { directory services }
  112. dirent = record
  113. d_fileno : cuint32; // file number of entry
  114. d_reclen : cuint16; // length of this record
  115. d_type : cuint8; // file type, see below
  116. d_namlen : cuint8; // length of string in d_name
  117. d_name : array[0..(255 + 1)-1] of char; // name must be no longer than this
  118. end;
  119. TDirent = dirent;
  120. pDirent = ^dirent;
  121. dir = packed record
  122. dd_fd : cint; // file descriptor associated with directory
  123. dd_loc : clong; // offset in current buffer
  124. dd_size : clong; // amount of data returned by getdirentries
  125. dd_buf : pchar; // data buffer
  126. dd_len : cint; // size of data buffer
  127. {$ifdef netbsdpowerpc}
  128. dd_pad1 : cint;
  129. dd_seek : cint64; // magic cookie returned by getdirentries
  130. {$else}
  131. dd_seek : clong; // magic cookie returned by getdirentries
  132. {$endif}
  133. dd_rewind : clong; // magic cookie for rewinding
  134. dd_flags : cint; // flags for readdir
  135. end;
  136. TDir = dir;
  137. pDir = ^dir;
  138. utimbuf = record
  139. actime : time_t;
  140. modtime : time_t;
  141. end;
  142. TUtimBuf = utimbuf;
  143. putimbuf = ^utimbuf;
  144. flock = record
  145. l_start : off_t; { starting offset }
  146. l_len : off_t; { len = 0 means until end of file }
  147. l_pid : pid_t; { lock owner }
  148. l_type : cshort; { lock type: read/write, etc. }
  149. l_whence: cshort; { type of l_start }
  150. end;
  151. TFlock = flock;
  152. pFlock = ^flock;
  153. tms = packed record
  154. tms_utime : clock_t; { User CPU time }
  155. tms_stime : clock_t; { System CPU time }
  156. tms_cutime : clock_t; { User CPU time of terminated child procs }
  157. tms_cstime : clock_t; { System CPU time of terminated child procs }
  158. end;
  159. TTms= tms;
  160. pTms= ^tms;
  161. TFDSet = ARRAY[0..(FD_MAXFDSET div 32)-1] of Cardinal;
  162. pFDSet = ^TFDSet;
  163. {***********************************************************************}
  164. { POSIX CONSTANT ROUTINE DEFINITIONS }
  165. {***********************************************************************}
  166. CONST
  167. { access routine - these maybe OR'ed together }
  168. F_OK = 0; { test for existence of file }
  169. R_OK = 4; { test for read permission on file }
  170. W_OK = 2; { test for write permission on file }
  171. X_OK = 1; { test for execute or search permission }
  172. { seek routine }
  173. SEEK_SET = 0; { seek from beginning of file }
  174. SEEK_CUR = 1; { seek from current position }
  175. SEEK_END = 2; { seek from end of file }
  176. { open routine }
  177. { File access modes for `open' and `fcntl'. }
  178. O_RDONLY = 0; { Open read-only. }
  179. O_WRONLY = 1; { Open write-only. }
  180. O_RDWR = 2; { Open read/write. }
  181. { Bits OR'd into the second argument to open. }
  182. O_CREAT = $200; { Create file if it doesn't exist. }
  183. O_EXCL = $800; { Fail if file already exists. }
  184. O_TRUNC = $400; { Truncate file to zero length. }
  185. O_NOCTTY = $8000; { Don't assign a controlling terminal. }
  186. { File status flags for `open' and `fcntl'. }
  187. O_APPEND = 8; { Writes append to the file. }
  188. O_NONBLOCK = 4; { Non-blocking I/O. }
  189. { mode_t possible values }
  190. S_IRUSR = %0100000000; { Read permission for owner }
  191. S_IWUSR = %0010000000; { Write permission for owner }
  192. S_IXUSR = %0001000000; { Exec permission for owner }
  193. S_IRGRP = %0000100000; { Read permission for group }
  194. S_IWGRP = %0000010000; { Write permission for group }
  195. S_IXGRP = %0000001000; { Exec permission for group }
  196. S_IROTH = %0000000100; { Read permission for world }
  197. S_IWOTH = %0000000010; { Write permission for world }
  198. S_IXOTH = %0000000001; { Exec permission for world }
  199. { Used for waitpid }
  200. WNOHANG = 1; { don't block waiting }
  201. WUNTRACED = 2; { report status of stopped children }
  202. { For File control mechanism }
  203. F_GetFd = 1;
  204. F_SetFd = 2;
  205. F_GetFl = 3;
  206. F_SetFl = 4;
  207. F_GetLk = 5;
  208. F_SetLk = 6;
  209. F_SetLkW = 7;
  210. F_SetOwn = 8;
  211. F_GetOwn = 9;
  212. type
  213. timezone = packed record
  214. tz_minuteswest,
  215. tz_dsttime : cint;
  216. end;
  217. ptimezone =^timezone;
  218. TTimeZone = timezone;
  219. rusage = packed record
  220. ru_utime : timeval; { user time used }
  221. ru_stime : timeval; { system time used }
  222. ru_maxrss : clong; { max resident set size }
  223. ru_ixrss : clong; { integral shared memory size }
  224. ru_idrss : clong; { integral unshared data " }
  225. ru_isrss : clong; { integral unshared stack " }
  226. ru_minflt : clong; { page reclaims }
  227. ru_majflt : clong; { page faults }
  228. ru_nswap : clong; { swaps }
  229. ru_inblock : clong; { block input operations }
  230. ru_oublock : clong; { block output operations }
  231. ru_msgsnd : clong; { messages sent }
  232. ru_msgrcv : clong; { messages received }
  233. ru_nsignals : clong; { signals received }
  234. ru_nvcsw : clong; { voluntary context switches }
  235. ru_nivcsw : clong; { involuntary " }
  236. end;
  237. // #define ru_last ru_nivcsw
  238. // #define ru_first ru_ixrss
  239. { auto generated by a c prog, statmacr.c}
  240. Const
  241. S_IFMT = 61440;
  242. S_IFIFO = 4096;
  243. S_IFCHR = 8192;
  244. S_IFDIR = 16384;
  245. S_IFBLK = 24576;
  246. S_IFREG = 32768;
  247. S_IFLNK = 40960;
  248. S_IFSOCK= 49152;
  249. S_IFWHT = 57344;
  250. S_ISVTX = 512;
  251. {
  252. * Resource limits from FreeBSD5. To be checked for the others.
  253. }
  254. RLIMIT_CPU = 0; { cpu time in milliseconds }
  255. RLIMIT_FSIZE = 1; { maximum file size }
  256. RLIMIT_DATA = 2; { data size }
  257. RLIMIT_STACK = 3; { stack size }
  258. RLIMIT_CORE = 4; { core file size }
  259. RLIMIT_RSS = 5; { resident set size }
  260. RLIMIT_MEMLOCK = 6; { locked-in-memory address space }
  261. RLIMIT_NPROC = 7; { number of processes }
  262. RLIMIT_NOFILE = 8; { number of open files }
  263. {$IFDEF FreeBSD}
  264. RLIMIT_SBSIZE = 9; { maximum size of all socket buffers }
  265. RLIMIT_VMEM =10; { virtual process size (inclusive of mmap) }
  266. RLIMIT_AS = RLIMIT_VMEM;
  267. {$ELSE}
  268. RLIMIT_AS = 5; { address space= resident set size}
  269. {$ENDIF}
  270. {$ifdef FreeBSD}
  271. RLIM_NLIMITS =11; { number of resource limits }
  272. {$endif}
  273. {$ifdef Darwin} // OS X 10.3
  274. RLIM_NLIMITS =9; { number of resource limits }
  275. {$endif}
  276. Type
  277. TRLimit = record
  278. rlim_cur, { current (soft) limit }
  279. rlim_max : TRLim; { maximum value for rlim_cur }
  280. end;
  281. PRLimit = ^TRLimit;
  282. iovec = record
  283. iov_base : pointer;
  284. iov_len : size_t;
  285. end;
  286. tiovec=iovec;
  287. piovec=^tiovec;
  288. CONST
  289. { Constansts for MMAP }
  290. MAP_PRIVATE =2;
  291. MAP_ANONYMOUS =$1000;
  292. {*************************************************************************}
  293. { SIGNALS }
  294. {*************************************************************************}
  295. {$i signal.inc}