--
--	filelib.inc - include file for file library
--	Copyright (C) 2000-2003 Fred Barnes <frmb2@ukc.ac.uk>
--
--	This program is free software; you can redistribute it and/or modify
--	it under the terms of the GNU General Public License as published by
--	the Free Software Foundation; either version 2 of the License, or
--	(at your option) any later version.
--
--	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.  See the
--	GNU General Public License for more details.
--
--	You should have received a copy of the GNU General Public License
--	along with this program; if not, write to the Free Software
--	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--

--{{{  constants for file.check.access
VAL R.OK IS 4:
VAL W.OK IS 2:
VAL X.OK IS 1:
VAL F.OK IS 0:
--}}}  
--{{{  constants for open
VAL O.RDONLY IS #00000000:
VAL O.WRONLY IS #00000001:
VAL O.RDWR IS #00000002:
VAL O.CREAT IS #00000040:
VAL O.EXCL IS #00000080:
VAL O.NOCTTY IS #00000100:
VAL O.TRUNC IS #00000200:
VAL O.APPEND IS #00000400:
VAL O.NONBLOCK IS #00000800:
VAL O.NDELAY IS O.NONBLOCK:
VAL O.SYNC IS #00001000:
VAL O.ASYNC IS #00002000:
VAL O.DIRECT IS #00004000:
VAL O.LARGEFILE IS #00008000:
VAL O.DIRECTORY IS #00010000:
VAL O.NOFOLLOW IS #00020000:
--}}}  
--{{{  constants for seek
VAL SEEK.SET IS 0:
VAL SEEK.CUR IS 1:
VAL SEEK.END IS 2:
--}}}  
--{{{  constants for fcntl
VAL F.DUPFD IS 0:         -- use fd >= "arg"
VAL F.GETFD IS 1:         -- read the close-on-exec flag
VAL F.SETFD IS 2:         -- set the close-on-exec flag from "arg" (1)
VAL F.GETFL IS 3:         -- get descriptor flags (open O.. constants)
VAL F.SETFL IS 4:         -- set descriptor flags ("arg" is OR of O.APPEND, O.NONBLOCK or O.ASYNC)
VAL F.GETLK IS 5:         -- get flock structure (not fully supported)
VAL F.SETLK IS 6:         -- set flock (not fully supported)
VAL F.SETLKW IS 7:        -- set flock with wait (not fully supported)

VAL F.SETOWN IS 8:        -- set process ID (-ve for group) that will receive SIGIO and SIGURG signals (not sensibly supported)
VAL F.GETOWN IS 9:        -- get process ID (-ve for process group) receiving SIGIO and SIGURG signals (not sensibly supported)
VAL F.SETSIG IS 10:       -- get signal sent when I/O becomes available on the descriptor (0 means SIGIO) -- SA_SIGINFO may be availble (not sensibly supported)
VAL F.GETSIG IS 11:       -- set signal sent when I/O becomes available on the descriptor (0 means SIGIO) -- SA_SIGINFO may be availble (not sensibly supported)

VAL F.GETLK64 IS 12:
VAL F.SETLK64 IS 13:
VAL F.SETLKW IS 14:

VAL FD.CLOEXEC IS 1:      -- close-on-exec flag for GETFD/SETFD
VAL F.RDLCK IS 0:
VAL F.WRLCK IS 1:
VAL F.UNLCK IS 2:

VAL F.INPROGRESS IS 16:   -- for leases
--}}}
--{{{  constants for file permissions
VAL S.IRWXU IS #1C0:
VAL S.IRUSR IS #100:
VAL S.IWUSR IS #80:
VAL S.IXUSR IS #40:
VAL S.IRWXG IS #38:
VAL S.IRGRP IS #20:
VAL S.IWGRP IS #10:
VAL S.IXGRP IS #8:
VAL S.IRWXO IS #7:
VAL S.IROTH IS #4:
VAL S.IWOTH IS #2:
VAL S.IXOTH IS #1:
VAL S.I644 IS #1A4:
VAL S.I755 IS #1ED:
--}}}  
--{{{  external declarations for killable blocking calls
#PRAGMA EXTERNAL "PROC BX.fl.read (CHAN OF INT c, VAL INT fd, []BYTE buffer, INT result) = 3"
#PRAGMA EXTERNAL "PROC BX.fl.write (CHAN OF INT c, VAL INT fd, VAL []BYTE buffer, INT result) = 3"
#PRAGMA EXTERNAL "PROC BX.fl.fd.fd.copy (CHAN OF INT c, VAL INT src.fd, dst.fd, count, INT result) = 3"
--}}}  
--{{{  C.STAT and STAT
DATA TYPE C.STAT IS [18]INT32:

DATA TYPE STAT
  RECORD
    INT64 dev:
    INT32 ino:
    INT32 mode:
    INT32 nlink:
    INT32 uid:
    INT32 gid:
    INT64 rdev:
    INT32 size:
    INT32 blksize:
    INT32 blocks:
    INT32 atime:
    INT32 mtime:
    INT32 ctime:
:
--}}}
--{{{  C.DIRENT and DIRENT
DATA TYPE C.DIRENT IS [3 + 64]INT32:

DATA TYPE DIRENT
  RECORD
    INT32 ino:
    INT32 off:
    INT16 reclen:
    BYTE type:
    [256]BYTE filename:
:
--}}}
--{{{  mode constants
VAL INT32 S.IFMT   IS     #F000: -- 0170000 bitmask for the file type bitfields
VAL INT32 S.IFSOCK IS     #C000: -- 0140000 socket
VAL INT32 S.IFLNK  IS     #A000: -- 0120000 symbolic link
VAL INT32 S.IFREG  IS     #8000: -- 0100000 regular file
VAL INT32 S.IFBLK  IS     #6000: -- 0060000 block device
VAL INT32 S.IFDIR  IS     #4000: -- 0040000 directory
VAL INT32 S.IFCHR  IS     #2000: -- 0020000 character device
VAL INT32 S.IFIFO  IS     #1000: -- 0010000 fifo
VAL INT32 S.ISUID  IS     #800:  -- 0004000 set UID bit
VAL INT32 S.ISGID  IS     #400:  -- 0002000 set GID bit (see below)
VAL INT32 S.ISVTX  IS     #200:  -- 0001000 sticky bit (see below)
VAL INT32 S.IRWXU  IS     #1C0:  -- 00700   mask for file owner permissions
VAL INT32 S.IRUSR  IS     #100:  -- 00400   owner has read permission
VAL INT32 S.IWUSR  IS     #80:   -- 00200   owner has write permission
VAL INT32 S.IXUSR  IS     #40:   -- 00100   owner has execute permission
VAL INT32 S.IRWXG  IS     #38:   -- 00070   mask for group permissions
VAL INT32 S.IRGRP  IS     #20:   -- 00040   group has read permission
VAL INT32 S.IWGRP  IS     #10:   -- 00020   group has write permission
VAL INT32 S.IXGRP  IS     #8:    -- 00010   group has execute permission
VAL INT32 S.IRWXO  IS     #7:    -- 00007   mask for permissions for others (not in group)
VAL INT32 S.IROTH  IS     #4:    -- 00004   others have read permission
VAL INT32 S.IWOTH  IS     #2:    -- 00002   others have write permisson
VAL INT32 S.IXOTH  IS     #1:    -- 00001   others have execute permission
--}}}



