ostypes.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. {$ifndef darwinarm}
  95. dirent = record
  96. d_fileno : cuint32; // file number of entry
  97. d_reclen : cuint16; // length of this record
  98. d_type : cuint8; // file type, see below
  99. d_namlen : cuint8; // length of string in d_name
  100. d_name : array[0..(255 + 1)-1] of char; // name must be no longer than this
  101. end;
  102. {$else not darwinarm}
  103. {$packrecords 4}
  104. { available on Mac OS X 10.6 and later, and used by all iPhoneOS versions }
  105. dirent = record
  106. d_fileno : cuint64; // file number of entry
  107. d_seekoff : cuint64; // seek offset (optional, used by servers)
  108. d_reclen : cuint16; // length of this record
  109. d_namlen : cuint16; // length of string in d_name
  110. d_type : cuint8; // file type, see below
  111. d_name : array[0..PATH_MAX-1] of char; // name must be no longer than this
  112. end;
  113. {$packrecords c}
  114. {$endif darwinarm}
  115. TDirent = dirent;
  116. pDirent = ^dirent;
  117. dir = packed record
  118. dd_fd : cint; // file descriptor associated with directory
  119. dd_loc : clong; // offset in current buffer
  120. dd_size : clong; // amount of data returned by getdirentries
  121. dd_buf : pchar; // data buffer
  122. dd_len : cint; // size of data buffer
  123. {$ifdef netbsdpowerpc}
  124. dd_pad1 : cint;
  125. dd_seek : cint64; // magic cookie returned by getdirentries
  126. {$else}
  127. dd_seek : clong; // magic cookie returned by getdirentries
  128. {$endif}
  129. dd_rewind : clong; // magic cookie for rewinding
  130. dd_flags : cint; // flags for readdir
  131. {$ifdef darwin}
  132. __dd_lock : pthread_mutex_t; // for thread locking
  133. __dd_td : pointer; // telldir position recording
  134. {$endif}
  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. {$ifdef darwin}
  213. F_CHKCLEAN = 41; { Used for regression test }
  214. F_PREALLOCATE = 42; { Preallocate storage }
  215. F_SETSIZE = 43; { Truncate a file without zeroing space }
  216. F_RDADVISE = 44; { Issue an advisory read async with no copy to user }
  217. F_RDAHEAD = 45; { turn read ahead off/on }
  218. F_READBOOTSTRAP = 46; { Read bootstrap from disk }
  219. F_WRITEBOOTSTRAP = 47; { Write bootstrap on disk }
  220. F_NOCACHE = 48; { turning data caching off/on }
  221. F_LOG2PHYS = 49; { file offset to device offset }
  222. F_GETPATH = 50; { return the full path of the fd }
  223. F_FULLFSYNC = 51; { fsync + ask the drive to flush to the media }
  224. F_PATHPKG_CHECK = 52; { find which component (if any) is a package }
  225. F_FREEZE_FS = 53; { "freeze" all fs operations }
  226. F_THAW_FS = 54; { "thaw" all fs operations }
  227. F_GLOBAL_NOCACHE = 55; { turn data caching off/on (globally) for this file }
  228. {$endif}
  229. type
  230. timezone = packed record
  231. tz_minuteswest,
  232. tz_dsttime : cint;
  233. end;
  234. ptimezone =^timezone;
  235. TTimeZone = timezone;
  236. rusage = packed record
  237. ru_utime : timeval; { user time used }
  238. ru_stime : timeval; { system time used }
  239. ru_maxrss : clong; { max resident set size }
  240. ru_ixrss : clong; { integral shared memory size }
  241. ru_idrss : clong; { integral unshared data " }
  242. ru_isrss : clong; { integral unshared stack " }
  243. ru_minflt : clong; { page reclaims }
  244. ru_majflt : clong; { page faults }
  245. ru_nswap : clong; { swaps }
  246. ru_inblock : clong; { block input operations }
  247. ru_oublock : clong; { block output operations }
  248. ru_msgsnd : clong; { messages sent }
  249. ru_msgrcv : clong; { messages received }
  250. ru_nsignals : clong; { signals received }
  251. ru_nvcsw : clong; { voluntary context switches }
  252. ru_nivcsw : clong; { involuntary " }
  253. end;
  254. // #define ru_last ru_nivcsw
  255. // #define ru_first ru_ixrss
  256. { auto generated by a c prog, statmacr.c}
  257. Const
  258. S_IFMT = 61440;
  259. S_IFIFO = 4096;
  260. S_IFCHR = 8192;
  261. S_IFDIR = 16384;
  262. S_IFBLK = 24576;
  263. S_IFREG = 32768;
  264. S_IFLNK = 40960;
  265. S_IFSOCK= 49152;
  266. S_IFWHT = 57344;
  267. S_ISVTX = 512;
  268. {
  269. * Resource limits from FreeBSD5. To be checked for the others.
  270. }
  271. RLIMIT_CPU = 0; { cpu time in milliseconds }
  272. RLIMIT_FSIZE = 1; { maximum file size }
  273. RLIMIT_DATA = 2; { data size }
  274. RLIMIT_STACK = 3; { stack size }
  275. RLIMIT_CORE = 4; { core file size }
  276. RLIMIT_RSS = 5; { resident set size }
  277. RLIMIT_MEMLOCK = 6; { locked-in-memory address space }
  278. RLIMIT_NPROC = 7; { number of processes }
  279. RLIMIT_NOFILE = 8; { number of open files }
  280. {$IFDEF FreeBSD}
  281. RLIMIT_SBSIZE = 9; { maximum size of all socket buffers }
  282. RLIMIT_VMEM =10; { virtual process size (inclusive of mmap) }
  283. RLIMIT_AS = RLIMIT_VMEM;
  284. {$ELSE}
  285. RLIMIT_AS = 5; { address space= resident set size}
  286. {$ENDIF}
  287. {$ifdef FreeBSD}
  288. RLIM_NLIMITS =11; { number of resource limits }
  289. {$endif}
  290. {$ifdef Darwin} // OS X 10.3
  291. RLIM_NLIMITS =9; { number of resource limits }
  292. {$endif}
  293. Type
  294. TRLimit = record
  295. rlim_cur, { current (soft) limit }
  296. rlim_max : TRLim; { maximum value for rlim_cur }
  297. end;
  298. PRLimit = ^TRLimit;
  299. iovec = record
  300. iov_base : pointer;
  301. iov_len : size_t;
  302. end;
  303. tiovec=iovec;
  304. piovec=^tiovec;
  305. CONST
  306. { Constansts for MMAP }
  307. {$ifdef FPC_IS_SYSTEM}
  308. MAP_PRIVATE =2;
  309. {$endif}
  310. MAP_ANONYMOUS =$1000;
  311. const
  312. POLLIN = $0001;
  313. POLLPRI = $0002;
  314. POLLOUT = $0004;
  315. POLLERR = $0008;
  316. POLLHUP = $0010;
  317. POLLNVAL = $0020;
  318. { XOpen, XPG 4.2 }
  319. POLLRDNORM = $0040;
  320. POLLRDBAND = $0080;
  321. POLLWRNORM = POLLOUT;
  322. POLLWRBAND = $0100;
  323. type
  324. pollfd = record
  325. fd: cint;
  326. events: cshort;
  327. revents: cshort;
  328. end;
  329. tpollfd = pollfd;
  330. ppollfd = ^pollfd;
  331. {*************************************************************************}
  332. { SIGNALS }
  333. {*************************************************************************}
  334. {$i signal.inc}