summaryrefslogtreecommitdiff
path: root/fpcsrc/rtl/bsd/ostypes.inc
blob: 9d073fa0c7c08da798a68d84b3488963777f84d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
{
    This file is part of the Free Pascal run time library.
    Copyright (c) 2001 by Free Pascal development team

    Types and structures for baseunix unit, also used in system.

    This file implements all the types/constants which must
    be defined to port FPC to a new POSIX compliant OS.

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

{***********************************************************************}
{                         POSIX STRUCTURES                              }
{***********************************************************************}

{$ifdef FPC_IS_SYSTEM}
  {$i ptypes.inc}
{$ENDIF}

{$ifdef cpupowerpc}
  {$ifdef netbsd}
    {$define netbsdpowerpc}
  {$endif}
{$endif}

{$if (defined(darwin) and defined(cpuarm)) or defined(iphonesim)}
  {$define darwinarm}
{$endif}

//      CONST SYS_NMLN=65;

// Can't find these two in Posix and in FreeBSD
//CONST
//    _UTSNAME_LENGTH = ;
//    _UTSNAME_NODENAME_LENGTH = ;

CONST                           // OS specific parameters for general<fd,sig>set behaviour
   BITSINWORD      = 8*sizeof(longint);
   FD_MAXFDSET     = 1024;
   ln2bitsinword   = 5;         { 32bit : ln(32)/ln(2)=5 }
   ln2bitmask      = 1 shl ln2bitsinword - 1;
   wordsinfdset    = FD_MAXFDSET DIV BITSINWORD;        // words in fdset_t
   wordsinsigset   = SIG_MAXSIG  DIV BITSINWORD;

TYPE
   { system information services }
   utsname = record
              sysname : Array[0..SYS_NMLN-1] OF Char;   // Name of this OS
              nodename: Array[0..SYS_NMLN-1] OF Char;   // Name of this network node.
              release : Array[0..SYS_NMLN-1] OF Char;   // Release level.
              version : Array[0..SYS_NMLN-1] OF Char;   // Version level.
              machine : Array[0..SYS_NMLN-1] OF Char;   // Hardware type.
             end;
  TUtsName= utsname;
  pUtsName= ^utsname;

  { file characteristics services }
   stat    = record { the types are real}
        st_dev        : dev_t;             // inode's device
{$ifdef darwinarm}
        st_mode       : mode_t;            // inode protection mode
        st_nlink      : nlink_t;           // number of hard links
        st_ino        : ino_t;             // inode's number
{$else}
{$ifdef netbsd_use_stat30}
     { order is inverted for better alignment probably }
        st_mode       : mode_t;            // inode protection mode
        st_ino        : ino_t;             // inode's number
{$else not netbsd}
        st_ino        : ino_t;             // inode's number
        st_mode       : mode_t;            // inode protection mode
{$endif not netbsd}
        st_nlink      : nlink_t;           // number of hard links
{$endif}
        st_uid        : uid_t;             // user ID of the file's owner
        st_gid        : gid_t;             // group ID of the file's group
        st_rdev       : dev_t;             // device type
{$ifdef openbsd}
        st_padd0      : cint;
{$endif}
        st_atime      : time_t;            // time of last access
        st_atimensec  : clong;             // nsec of last access
        st_mtime      : time_t;            // time of last data modification
        st_mtimensec  : clong;             // nsec of last data modification
        st_ctime      : time_t;            // time of last file status change
        st_ctimensec  : clong;             // nsec of last file status change
{$ifdef darwinarm}
        st_birthtime  : time_t;            // File creation time
        st_birthtimensec : clong;          // nsec of file creation time
{$endif}
{$ifdef netbsdPowerpc}
        st_padd1              : cint;
{$endif}
        st_size       : off_t;             // file size, in bytes
        st_blocks     : cint64;            // blocks allocated for file
        st_blksize    : cuint32;           // optimal blocksize for I/O
        st_flags      : cuint32;           // user defined flags for file
        st_gen        : cuint32;           // file generation number
{$ifdef netbsdPowerpc}
        st_padd2              : cint;
{$endif}
{$ifndef NetBSD}
        st_lspare     : cint32;
{$endif}
{$ifdef openbsd}
        st_birthtime  : time_t;            // File creation time
        st_birthtimensec : clong;          // nsec of file creation time
{$endif}
        st_qspare     : array[0..1] Of cint64;
   end;
   TStat = stat;
   pStat = ^stat;

  { directory services }
{$ifndef darwinarm}
   dirent  = record
        d_fileno      : cuint32;                        // file number of entry
        d_reclen      : cuint16;                        // length of this record
        d_type        : cuint8;                         // file type, see below
        d_namlen      : cuint8;                         // length of string in d_name
        d_name        : array[0..(255 + 1)-1] of char;  // name must be no longer than this
   end;
{$else not darwinarm}
   {$packrecords 4}
   { available on Mac OS X 10.6 and later, and used by all iPhoneOS versions }
   dirent  = record
        d_fileno      : cuint64;                        // file number of entry
        d_seekoff     : cuint64;                        // seek offset (optional, used by servers)
        d_reclen      : cuint16;                        // length of this record
        d_namlen      : cuint16;                        // length of string in d_name
        d_type        : cuint8;                         // file type, see below
        d_name        : array[0..PATH_MAX-1] of char;        // name must be no longer than this
   end;
   {$packrecords c}
{$endif darwinarm}
   TDirent = dirent;
   pDirent = ^dirent;

   dir     = record
        dd_fd     : cint;         // file descriptor associated with directory
        dd_loc    : clong;        // offset in current buffer
        dd_size   : clong;        // amount of data returned by getdirentries
        dd_buf    : pchar;        // data buffer
        dd_len    : cint;         // size of data buffer
{$ifdef netbsdpowerpc}
        dd_pad1   : cint;
        dd_seek   : cint64;        // magic cookie returned by getdirentries
{$else}
        dd_seek   : clong;        // magic cookie returned by getdirentries
{$endif}
        dd_rewind : clong;        // magic cookie for rewinding
        dd_flags  : cint;         // flags for readdir
{$ifdef darwin}
        __dd_lock : pthread_mutex_t; // for thread locking
        __dd_td : pointer;        // telldir position recording
{$endif}
   end;
   TDir    = dir;
   pDir    = ^dir;

   utimbuf  = record
                actime  : time_t;
                modtime : time_t;
                end;
   TUtimBuf = utimbuf;
   putimbuf = ^utimbuf;

   flock    = record
                l_start : off_t;        { starting offset }
                l_len   : off_t;        { len = 0 means until end of file }
                l_pid   : pid_t;        { lock owner }
                l_type  : cshort;       { lock type: read/write, etc. }
                l_whence: cshort;       { type of l_start }
                end;
   TFlock   = flock;
   pFlock   = ^flock;

 tms = record
         tms_utime  : clock_t;  { User CPU time }
         tms_stime  : clock_t;  { System CPU time }
         tms_cutime : clock_t;  { User CPU time of terminated child procs }
         tms_cstime : clock_t;  { System CPU time of terminated child procs }
         end;
 TTms= tms;
 pTms= ^tms;

 TFDSet    = ARRAY[0..(FD_MAXFDSET div 32)-1] of Cardinal;
 pFDSet    = ^TFDSet;

{***********************************************************************}
{                  POSIX CONSTANT ROUTINE DEFINITIONS                   }
{***********************************************************************}
CONST
    { access routine - these maybe OR'ed together }
    F_OK        =     0;        { test for existence of file }
    R_OK        =     4;        { test for read permission on file }
    W_OK        =     2;        { test for write permission on file }
    X_OK        =     1;        { test for execute or search permission }
    { seek routine }
    SEEK_SET    =     0;        { seek from beginning of file }
    SEEK_CUR    =     1;        { seek from current position  }
    SEEK_END    =     2;        { seek from end of file       }
    { open routine                                 }
    { File access modes for `open' and `fcntl'.    }
    O_RDONLY    =     0;        { Open read-only.  }
    O_WRONLY    =     1;        { Open write-only. }
    O_RDWR      =     2;        { Open read/write. }
    { Bits OR'd into the second argument to open.  }
    O_CREAT     =  $200;        { Create file if it doesn't exist.  }
    O_EXCL      =  $800;        { Fail if file already exists.      }
    O_TRUNC     =  $400;        { Truncate file to zero length.     }
    O_NOCTTY    = $8000;        { Don't assign a controlling terminal. }
    { File status flags for `open' and `fcntl'.  }
    O_APPEND    =     8;        { Writes append to the file.        }
    O_NONBLOCK  =     4;        { Non-blocking I/O.                 }

{$ifdef freebsd}
    { Other }
    O_SHLOCK    =   $10;        { Open with shared file lock }
    O_EXLOCK    =   $20;        { Open with exclusive file lock }
    O_ASYNC     =   $40;        { Signal pgrp when data ready }
    O_FSYNC     =   $80;        { Synchronous writes }
    O_SYNC      =   $80;        { POSIX synonym for O_FSYNC }
    O_NOFOLLOW  =  $100;        { Don't follow symlinks }
    O_DIRECT    =$10000;        { Attempt to bypass buffer cache }
{$endif}

    { mode_t possible values                                 }
    S_IRUSR =  %0100000000;     { Read permission for owner   }
    S_IWUSR =  %0010000000;     { Write permission for owner  }
    S_IXUSR =  %0001000000;     { Exec  permission for owner  }
    S_IRGRP =  %0000100000;     { Read permission for group   }
    S_IWGRP =  %0000010000;     { Write permission for group  }
    S_IXGRP =  %0000001000;     { Exec permission for group   }
    S_IROTH =  %0000000100;     { Read permission for world   }
    S_IWOTH =  %0000000010;     { Write permission for world  }
    S_IXOTH =  %0000000001;     { Exec permission for world   }

    { Used for waitpid }
    WNOHANG   =          1;     { don't block waiting               }
    WUNTRACED =          2;     { report status of stopped children }


  { For File control mechanism }
  F_DupFd          = 0;           { duplicate file descriptor }
  F_GetFd          = 1;           { get file descriptor flags }
  F_SetFd          = 2;           { set file descriptor flags }
  F_GetFl          = 3;           { get file status flags }
  F_SetFl          = 4;           { set file status flags }
  F_GetOwn         = 5;           { get SIGIO/SIGURG proc/pgrp }
  F_SetOwn         = 6;           { set SIGIO/SIGURG proc/pgrp }
{$ifdef freebsd}
  F_OGetLk         = 7;           { get record locking information }
  F_OSetLk         = 8;           { set record locking information }
  F_OSetLkW        = 9;           { F_SETLK; wait if blocked }
  F_Dup2Fd         = 10;          { duplicate file descriptor to arg }
  F_GetLk          = 11;          { get record locking information}
  F_SetLk          = 12;          { set record locking information }
  F_SetLkW         = 13;          { F_SETLK; wait if blocked }
  F_SetLkRemote    = 14;          { debugging support for remote locks }
{$endif}
{$ifdef netbsd}
  F_GetLk          = 7;           { get record locking information}
  F_SetLk          = 8;           { set record locking information }
  F_SetLkW         = 9;           { F_SETLK; wait if blocked }
  F_CloseM	   = 10;	  { close all fds >= to the one given }
  F_MaxFd          = 11;	  { return the max open fd }
  F_DupFd_CloExec  = 12;	  { close on exec duplicated fd }
{$endif}
{$ifdef openbsd}
  F_GetLk          = 7;           { get record locking information}
  F_SetLk          = 8;           { set record locking information }
  F_SetLkW         = 9;           { F_SETLK; wait if blocked }
  F_DupFd_CloExec  = 10;	  { duplicate with FD_CLOEXEC set }
{$endif}
{$ifdef darwin}
  F_GetLk          = 7;           { get record locking information}
  F_SetLk          = 8;           { set record locking information }
  F_SetLkW         = 9;           { F_SETLK; wait if blocked }
{$endif}

  { File descriptor flags (F_GETFD, F_SETFD) }
  FD_CLOEXEC	   = 1;		  { close-on-exec flag }

  { Record locking flags (F_GETLK, F_SETLK, F_SETLKW) }
  F_RDLCK          = 1;		  { shared or read lock }
  F_UNLCK          = 2;		  { unlock }
  F_WRLCK          = 3;		  { exclusive or write lock }
{$ifdef freebsd}
  F_UNLCKSYS       = 4;		  { purge locks for a given system ID }
  F_CANCEL         = 5;		  { cancel an async lock request }
{$endif}
{$ifndef darwin}
  F_WAIT	   = $10;	  { Wait until lock is granted }
  F_FLOCK          = $20;         { Use flock(2) semantics for lock }
  F_POSIX          = $40; 	  { Use POSIX semantics for lock }
{$endif}
{$ifdef freebsd}
  F_REMOTE	   = $80;	  { Lock owner is remote NFS client }
  F_NOINTR	   = $100;        { Ignore signals when waiting }
{$endif}

{$ifdef darwin}
  F_CHKCLEAN       = 41;          { Used for regression test }
  F_PREALLOCATE    = 42;          { Preallocate storage }
  F_SETSIZE        = 43;          { Truncate a file without zeroing space }
  F_RDADVISE       = 44;          { Issue an advisory read async with no copy to user }
  F_RDAHEAD        = 45;          { turn read ahead off/on }
  F_READBOOTSTRAP  = 46;          { Read bootstrap from disk }
  F_WRITEBOOTSTRAP = 47;          { Write bootstrap on disk }
  F_NOCACHE        = 48;          { turning data caching off/on }
  F_LOG2PHYS       = 49;          { file offset to device offset }
  F_GETPATH        = 50;          { return the full path of the fd }
  F_FULLFSYNC      = 51;          { fsync + ask the drive to flush to the media }
  F_PATHPKG_CHECK  = 52;          { find which component (if any) is a package }
  F_FREEZE_FS      = 53;          { "freeze" all fs operations }
  F_THAW_FS        = 54;          { "thaw" all fs operations }
  F_GLOBAL_NOCACHE = 55;          { turn data caching off/on (globally) for this file }
{$endif}


type
  timezone = record
    tz_minuteswest,
    tz_dsttime  : cint;
  end;
  ptimezone =^timezone;
  TTimeZone = timezone;

  rusage = record
        ru_utime    : timeval;          { user time used }
        ru_stime    : timeval;          { system time used }
        ru_maxrss   : clong;            { max resident set size }
        ru_ixrss    : clong;            { integral shared memory size }
        ru_idrss    : clong;            { integral unshared data " }
        ru_isrss    : clong;            { integral unshared stack " }
        ru_minflt   : clong;            { page reclaims }
        ru_majflt   : clong;            { page faults }
        ru_nswap    : clong;            { swaps }
        ru_inblock  : clong;            { block input operations }
        ru_oublock  : clong;            { block output operations }
        ru_msgsnd   : clong;            { messages sent }
        ru_msgrcv   : clong;            { messages received }
        ru_nsignals : clong;            { signals received }
        ru_nvcsw    : clong;            { voluntary context switches }
        ru_nivcsw   : clong;            { involuntary " }
        end;
// #define      ru_last         ru_nivcsw
// #define      ru_first        ru_ixrss

{ auto generated by a c prog, statmacr.c}

Const
  S_IFMT  = 61440;
  S_IFIFO = 4096;
  S_IFCHR = 8192;
  S_IFDIR = 16384;
  S_IFBLK = 24576;
  S_IFREG = 32768;
  S_IFLNK = 40960;
  S_IFSOCK= 49152;
  S_IFWHT = 57344;
  S_ISVTX = 512;

{
 * Resource limits from FreeBSD5. To be checked for the others.
}
  RLIMIT_CPU      = 0;              { cpu time in milliseconds }
  RLIMIT_FSIZE    = 1;              { maximum file size }
  RLIMIT_DATA     = 2;              { data size }
  RLIMIT_STACK    = 3;              { stack size }
  RLIMIT_CORE     = 4;              { core file size }
  RLIMIT_RSS      = 5;              { resident set size }
  RLIMIT_MEMLOCK  = 6;              { locked-in-memory address space }
  RLIMIT_NPROC    = 7;              { number of processes }
  RLIMIT_NOFILE   = 8;              { number of open files }
{$IFDEF FreeBSD}
  RLIMIT_SBSIZE   = 9;              { maximum size of all socket buffers }
  RLIMIT_VMEM     =10;              { virtual process size (inclusive of mmap) }
  RLIMIT_AS       = RLIMIT_VMEM;
{$ELSE}
  RLIMIT_AS       = 5;    	    { address space= resident set size}
{$ENDIF}

  {$ifdef FreeBSD}
  RLIM_NLIMITS    =11;              { number of resource limits }
  {$endif}

  {$ifdef Darwin}   // OS X 10.3
  RLIM_NLIMITS    =9;              { number of resource limits }
  {$endif}

Type
        TRLimit  = record
                     rlim_cur,               { current (soft) limit }
          	     rlim_max : TRLim;     { maximum value for rlim_cur }
		    end;	
        PRLimit  = ^TRLimit;

  iovec = record
            iov_base : pointer;
	    iov_len  : size_t;
	   end;
  tiovec=iovec;
  piovec=^tiovec;		

CONST
 { Constansts for MMAP }
{$ifdef FPC_IS_SYSTEM}
  MAP_PRIVATE   =2;
{$endif}
  MAP_ANONYMOUS =$1000;

const
  POLLIN      = $0001;
  POLLPRI     = $0002;
  POLLOUT     = $0004;
  POLLERR     = $0008;
  POLLHUP     = $0010;
  POLLNVAL    = $0020;

  { XOpen, XPG 4.2 }
  POLLRDNORM  = $0040;
  POLLRDBAND  = $0080;
  POLLWRNORM  = POLLOUT;
  POLLWRBAND  = $0100;

type
  pollfd = record
    fd: cint;
    events: cshort;
    revents: cshort;
  end;
  tpollfd = pollfd;
  ppollfd = ^pollfd;

    {*************************************************************************}
    {                               SIGNALS                                   }
    {*************************************************************************}

{$i signal.inc}