PreviousUpNext

15.3.525  src/lib/std/src/psx/posix-file.api

## posix-file.api

# Compiled by:
#     src/lib/std/src/standard-core.sublib




# Api for POSIX 1003.1 file system operations



###                 "I think the major good idea in Unix
###                  was its clean and simple interface:
###                  open, close, read, and write."
###
###                                  Ken Thompson 



stipulate
    package hi  =  host_int;                                                            # host_int                              is from   src/lib/std/src/psx/host-int.pkg
    package hug =  host_unt_guts;                                                       # host_unt_guts                         is from   src/lib/std/src/bind-sysword-32.pkg
    package i1w =  one_word_int;                                                        # one_word_int                          is from   src/lib/std/types-only/basis-structs.pkg
    package rt  =  runtime;                                                             # runtime                               is from   src/lib/core/init/runtime.pkg
    package ti  =  tagged_int;                                                          # tagged_int                            is from   src/lib/std/types-only/basis-structs.pkg
    package wty =  winix_types;                                                         # winix_types                           is from   src/lib/std/src/posix/winix-types.pkg
herein

    api Posix_File {
        #
        eqtype User_Id;
        eqtype Group_Id;
        eqtype File_Descriptor;

        fd_to_int:     File_Descriptor -> host_int::Int;
        int_to_fd:     host_int::Int -> File_Descriptor;

        fd_to_iod:     File_Descriptor -> wty::io::Iod;
        iod_to_fd:     wty::io::Iod -> File_Descriptor;

        Directory_Stream;

        open_directory_stream:    String -> Directory_Stream;
        read_directory_entry:     Directory_Stream -> Null_Or( String );
        rewind_directory_stream:  Directory_Stream -> Void;
        close_directory_stream:   Directory_Stream -> Void;

        change_directory:   String -> Void;
        current_directory:  Void -> String;

        stdin:   File_Descriptor;
        stdout:  File_Descriptor;
        stderr:  File_Descriptor;

        package s:  api {
                         Mode;
                         include api Bit_Flags          # Bit_Flags     is from   src/lib/std/src/bit-flags.api
                                     where  Flags == Mode;

                         irwxu:  Mode;
                         irusr:  Mode;
                         iwusr:  Mode;
                         ixusr:  Mode;
                         irwxg:  Mode;
                         irgrp:  Mode;
                         iwgrp:  Mode;
                         ixgrp:  Mode;
                         irwxo:  Mode;
                         iroth:  Mode;
                         iwoth:  Mode;
                         ixoth:  Mode;
                         isuid:  Mode;
                         isgid:  Mode;

                    };

                                    # We really need proper octal constant support :(  XXX BUGGO FIXME
                                    # How about 0666_u16 for 16-bit unsigned octal constants,
                                    #            077_u8  for  8-bit unsigned octal constants,
                                    #            037_i32 for 32-bit   signed octal constants, and so forth?

        mode_0755:   s::Mode;
        mode_0700:   s::Mode;
        mode_0666:   s::Mode;
        mode_0644:   s::Mode;
        mode_0600:   s::Mode;

        package o:  api {
                        include api Bit_Flags;          # Bit_Flags     is from   src/lib/std/src/bit-flags.api

                        append:    Flags;
                        dsync:     Flags;
                        excl:      Flags;
                        noctty:    Flags;
                        nonblock:  Flags;
                        rsync:     Flags;
                        sync:      Flags;
                        trunc:     Flags;

                    };

        include api Posix_Common;                                                       # Posix_Common                  is from   src/lib/std/src/posix/posix-common.api

        openf:      (String, Open_Mode, o::Flags) -> File_Descriptor;           # Maps to C open(2).
        createf:    (String, Open_Mode, o::Flags, s::Mode) -> File_Descriptor;
        creat:      (String, s::Mode) -> File_Descriptor;
        umask:      s::Mode -> s::Mode;
        link:   { old:  String, new:  String } -> Void;

        mkstemp:    Void -> File_Descriptor;                            # This may not be posix.

        mkdir:                  (String, s::Mode) -> Void;
        make_named_pipe:        (String, s::Mode) -> Void;                      # For vanilla pipes see make_pipe in   src/lib/std/src/psx/posix-io.api

        unlink:     String -> Void;
        rmdir:      String -> Void;
        rename:     { from:  String, to:  String } -> Void;
        symlink:    { old:  String, new:  String } -> Void;             #  POSIX 1003.1a 
        readlink:   String -> String;                                   #  POSIX 1003.1a 
        ftruncate:  (File_Descriptor, file_position::Int) -> Void;      #  POSIX 1003.1a 

        eqtype Device;
        unt_to_dev:  host_unt::Unt -> Device;
        dev_to_unt:  Device -> host_unt::Unt;

        eqtype Inode;
        unt_to_ino:  host_unt::Unt -> Inode;
        ino_to_unt:  Inode -> host_unt::Unt;

        package stat:   api {
                            Stat =
                                { ftype:  host_int::Int,
                                  mode:   s::Flags,
                                  inode:  Int,
                                  dev:    Int,
                                  nlink:  Int,
                                  uid:    host_unt::Unt,
                                  gid:    host_unt::Unt,
                                  size:   file_position::Int,
                                  atime:  time::Time,
                                  mtime:  time::Time,
                                  ctime:  time::Time
                                };

                            is_directory:   Stat -> Bool;
                            is_char_dev:    Stat -> Bool;
                            is_block_dev:   Stat -> Bool;
                            is_file:        Stat -> Bool;
                            is_pipe:        Stat -> Bool;
                            is_symlink:     Stat -> Bool;
                            is_socket:      Stat -> Bool;

                            mode:    Stat -> s::Mode;
                            inode:   Stat -> Int;
                            dev:     Stat -> Int;
                            nlink:   Stat -> Int;
                            uid:     Stat -> User_Id;
                            gid:     Stat -> Group_Id;
                            size:    Stat -> file_position::Int;
                            atime:   Stat -> time::Time;
                            mtime:   Stat -> time::Time;
                            ctime:   Stat -> time::Time;
                        };

        stat:   String          -> stat::Stat;
        lstat:  String          -> stat::Stat;     #  POSIX 1003.1a 
        fstat:  File_Descriptor -> stat::Stat;

        Access_Mode = MAY_READ | MAY_WRITE | MAY_EXECUTE;
        access:  (String, List( Access_Mode )) -> Bool;

        chmod:    (String, s::Mode) -> Void;
        fchmod:   (File_Descriptor, s::Mode) -> Void;

        chown:    (String, User_Id, Group_Id) -> Void;
        fchown:    (File_Descriptor, User_Id, Group_Id) -> Void;

        utime:  (String, Null_Or { actime:  time::Time, modtime:  time::Time }) -> Void;

         pathconf:  (String,          String) ->  Null_Or( host_unt::Unt );
        fpathconf:  (File_Descriptor, String) ->  Null_Or( host_unt::Unt );



        #######################################################################
        # Below stuff is intended only for one-time use during
        # booting, to switch from direct to indirect syscalls:                                                  # For background see Note[1]            in   src/lib/std/src/unsafe/mythryl-callable-c-library-interface.pkg

             osval3__syscall:    String -> hi::Int;
        set__osval3__ref:      ({ lib_name: String, fun_name: String, io_call: (String -> hi::Int) } -> (String -> hi::Int)) -> Void;

        Ckit_Dirstream = rt::Chunk;  #  the underlying C DIRSTREAM 

             opendir__syscall:    String -> Ckit_Dirstream;
        set__opendir__ref:      ({ lib_name: String, fun_name: String, io_call: (String -> Ckit_Dirstream) } -> (String -> Ckit_Dirstream)) -> Void;

             readdir__syscall:    Ckit_Dirstream -> String;
        set__readdir__ref:      ({ lib_name: String, fun_name: String, io_call: (Ckit_Dirstream -> String) } -> (Ckit_Dirstream -> String)) -> Void;

             rewinddir__syscall:    Ckit_Dirstream -> Void;
        set__rewinddir__ref:      ({ lib_name: String, fun_name: String, io_call: (Ckit_Dirstream -> Void) } -> (Ckit_Dirstream -> Void)) -> Void;

             closedir__syscall:    Ckit_Dirstream -> Void;
        set__closedir__ref:      ({ lib_name: String, fun_name: String, io_call: (Ckit_Dirstream -> Void) } -> (Ckit_Dirstream -> Void)) -> Void;

             change_directory__syscall:    String -> Void;
        set__change_directory__ref:      ({ lib_name: String, fun_name: String, io_call: (String -> Void) } -> (String -> Void)) -> Void;

             current_directory__syscall:    Void -> String;
        set__current_directory__ref:      ({ lib_name: String, fun_name: String, io_call: (Void -> String) } -> (Void -> String)) -> Void;

             openf__syscall:    (String, hug::Unt, hug::Unt) -> hi::Int;
        set__openf__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, hug::Unt, hug::Unt) -> hi::Int) } -> ((String, hug::Unt, hug::Unt) -> hi::Int)) -> Void;

             mkstemp__syscall:    Void -> hi::Int;
        set__mkstemp__ref:      ({ lib_name: String, fun_name: String, io_call: (Void -> hi::Int) } -> (Void -> hi::Int)) -> Void;

             umask__syscall:    hug::Unt -> hug::Unt;
        set__umask__ref:      ({ lib_name: String, fun_name: String, io_call: (hug::Unt -> hug::Unt) } -> (hug::Unt -> hug::Unt)) -> Void;

             link__syscall:    (String, String) -> Void;
        set__link__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, String) -> Void) } -> ((String, String) -> Void)) -> Void;

             rename__syscall:    (String, String) -> Void;
        set__rename__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, String) -> Void) } -> ((String, String) -> Void)) -> Void;

             symlink__syscall:    (String, String) -> Void;
        set__symlink__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, String) -> Void) } -> ((String, String) -> Void)) -> Void;

             mkdir__syscall:    (String, hug::Unt) -> Void;
        set__mkdir__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, hug::Unt) -> Void) } -> ((String, hug::Unt) -> Void)) -> Void;

             make_named_pipe__syscall:    (String, hug::Unt) -> Void;
        set__make_named_pipe__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, hug::Unt) -> Void) } -> ((String, hug::Unt) -> Void)) -> Void;

             unlink__syscall:    String -> Void;
        set__unlink__ref:      ({ lib_name: String, fun_name: String, io_call: (String -> Void) } -> (String -> Void)) -> Void;

             rmdir__syscall:    String -> Void;
        set__rmdir__ref:      ({ lib_name: String, fun_name: String, io_call: (String -> Void) } -> (String -> Void)) -> Void;

             readlink__syscall:    String -> String;
        set__readlink__ref:      ({ lib_name: String, fun_name: String, io_call: (String -> String) } -> (String -> String)) -> Void;

             ftruncate__syscall:    (hi::Int, tagged_int_guts::Int) -> Void;
        set__ftruncate__ref:      ({ lib_name: String, fun_name: String, io_call: ((hi::Int, tagged_int_guts::Int) -> Void) } -> ((hi::Int, tagged_int_guts::Int) -> Void)) -> Void;

        # This layout needs to track src/c/lib/posix-file-system/stat.c 
        Statrep
          =
          ( (hi::Int,           #  file type 
             hug::Unt,          #  mode 
             hug::Unt,          #  inode 
             hug::Unt,          #  Devno 
             hug::Unt,          #  nlink 
             hug::Unt,          #  uid 
             hug::Unt,          #  gid 
             ti::Int,           #  size 
             i1w::Int,          #  Atime 
             i1w::Int,          #  mtime 
             i1w::Int)          #  Ctime 
          );

             stat__syscall:    String -> Statrep;
        set__stat__ref:      ({ lib_name: String, fun_name: String, io_call: (String -> Statrep) } -> (String -> Statrep)) -> Void;

             lstat__syscall:   String -> Statrep;
        set__lstat__ref:     ({ lib_name: String, fun_name: String, io_call: (String -> Statrep) } -> (String -> Statrep)) -> Void;

             fstat__syscall:    hi::Int -> Statrep;
        set__fstat__ref:      ({ lib_name: String, fun_name: String, io_call: (hi::Int -> Statrep) } -> (hi::Int -> Statrep)) -> Void;

             access__syscall:    (String, hug::Unt) -> Bool;
        set__access__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, hug::Unt) -> Bool) } -> ((String, hug::Unt) -> Bool)) -> Void;

             chmod__syscall:    (String, hug::Unt) -> Void;
        set__chmod__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, hug::Unt) -> Void) } -> ((String, hug::Unt) -> Void)) -> Void;

             fchmod__syscall:   (hi::Int, hug::Unt) -> Void;
        set__fchmod__ref:     ({ lib_name: String, fun_name: String, io_call: ((hi::Int, hug::Unt) -> Void) } -> ((hi::Int, hug::Unt) -> Void)) -> Void;

             chown__syscall:    (String, hug::Unt, hug::Unt) -> Void;
        set__chown__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, hug::Unt, hug::Unt) -> Void) } -> ((String, hug::Unt, hug::Unt) -> Void)) -> Void;

             fchown__syscall:    (hi::Int, hug::Unt, hug::Unt) -> Void;
        set__fchown__ref:      ({ lib_name: String, fun_name: String, io_call: ((hi::Int, hug::Unt, hug::Unt) -> Void) } -> ((hi::Int, hug::Unt, hug::Unt) -> Void)) -> Void;

             utime__syscall:    (String, i1w::Int, i1w::Int) -> Void;
        set__utime__ref:      ({ lib_name: String, fun_name: String, io_call: ((String, i1w::Int, i1w::Int) -> Void) } -> ((String, i1w::Int, i1w::Int) -> Void)) -> Void;

             pathconf__syscall:    (String,  String) -> Null_Or( hug::Unt );
        set__pathconf__ref:      ({ lib_name: String, fun_name: String, io_call: ((String,  String) -> Null_Or( hug::Unt )) } -> ((String,  String) -> Null_Or( hug::Unt ))) -> Void;

             fpathconf__syscall:    (hi::Int, String) -> Null_Or( hug::Unt );
        set__fpathconf__ref:      ({ lib_name: String, fun_name: String, io_call: ((hi::Int, String) -> Null_Or( hug::Unt )) } -> ((hi::Int, String) -> Null_Or( hug::Unt ))) -> Void;
      };                                                                                                        # Api Posix_File 
end;


## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext