;
; ** $VER: dosextens.h 36.41 (14.5.92)
; ** Includes Release 40.15
; **
; ** DOS structures not needed for the casual AmigaDOS user
; **
; ** (C) Copyright 1985-1993 Commodore-Amiga, Inc.
; **     All Rights Reserved
;
;
; 27/03/1999
;   Fixed union stuff

IncludePath   "PureInclude:"
XIncludeFile "exec/tasks.pb"
XIncludeFile "exec/ports.pb"
XIncludeFile "exec/libraries.pb"
XIncludeFile "exec/semaphores.pb"
XIncludeFile "devices/timer.pb"

;XIncludeFile "dos/dos.pb"

;  All DOS processes have this structure
;  Create and Device Proc returns pointer to the MsgPort in this structure
;  dev_proc = (struct Process *) (DeviceProc(..) - sizeof(struct Task));

Structure Process
    pr_Task.Task
    pr_MsgPort.MsgPort ;  This is BPTR address from DOS functions
    pr_Pad.w  ;  Remaining variables on 4 byte boundaries
    pr_SegList.l  ;  Array of seg lists used by this process
    pr_StackSize.l ;  Size of process stack in bytes
    *pr_GlobVec.l  ;  Global vector for this process (BCPL)
    pr_TaskNum.l  ;  CLI task number of zero if not a CLI
    pr_StackBase.l ;  Ptr to high memory end of process stack
    pr_Result2.l  ;  Value of secondary result from last call
    pr_CurrentDir.l ;  Lock associated with current directory
    pr_CIS.l  ;  Current CLI Input Stream
    pr_COS.l  ;  Current CLI Output Stream
    *pr_ConsoleTask.l ;  Console handler process for current window
    *pr_FileSystemTask.l ;  File handler process for current drive
    pr_CLI.l  ;  pointer to CommandLineInterface
    *pr_ReturnAddr.l ;  pointer to previous stack frame
    *pr_PktWait.l  ;  Function to be called when awaiting msg
    *pr_WindowPtr.l ;  Window for error printing

    ;  following definitions are new with 2.0
    pr_HomeDir.l  ;  Home directory of executing program
    pr_Flags.l  ;  flags telling dos about process
    *pr_ExitCode.l ;  code to call on exit of program or NULL
    pr_ExitData.l ;  Passed as an argument to pr_ExitCode.
    *pr_Arguments.b ;  Arguments passed to the process at start
    pr_LocalVars.MinList ;  Local environment variables
    pr_ShellPrivate.l ;  for the use of the current shell
    pr_CES.l  ;  Error stream - if NULL, use pr_COS
EndStructure  ;  Process

;
;  * Flags for pr_Flags
;
#PRB_FREESEGLIST  = 0
#PRF_FREESEGLIST  = 1
#PRB_FREECURRDIR  = 1
#PRF_FREECURRDIR  = 2
#PRB_FREECLI  = 2
#PRF_FREECLI  = 4
#PRB_CLOSEINPUT  = 3
#PRF_CLOSEINPUT  = 8
#PRB_CLOSEOUTPUT  = 4
#PRF_CLOSEOUTPUT  = 16
#PRB_FREEARGS  = 5
#PRF_FREEARGS  = 32

;  The long word address (BPTR) of this structure is returned by
;  * Open() and other routines that return a file.  You need only worry
;  * about this struct to do async io's via PutMsg() instead of
;  * standard file system calls

Structure FileHandle
   *fh_Link.Message  ;  EXEC message
   *fh_Port.MsgPort  ;  Reply port for the packet
   *fh_Type.MsgPort  ;  Port to do PutMsg() to
;       * Address is negative if a plain file
   fh_Buf.l
   fh_Pos.l
   fh_End.l
   fh_Funcs.l
;#fh_Func1 = fh_Funcs
   fh_Func2.l
   fh_Func3.l
   fh_Args.l
;#fh_Arg1 = fh_Args
   fh_Arg2.l
EndStructure ;  FileHandle

;  This is the extension to EXEC Messages used by DOS

Structure DosPacket
   *dp_Link.Message  ;  EXEC message
   *dp_Port.MsgPort  ;  Reply port for the packet
     ;  Must be filled in each send.
   dp_Type.l   ;  See ACTION_... below and
;       * 'R' means Read, 'W' means Write to the
;       * file system
   dp_Res1.l   ;  For file system calls this is the result
;       * that would have been returned by the
;       * function, e.g. Write ('W') returns actual
;       * length written
   dp_Res2.l   ;  For file system calls this is what would
;       * have been returned by IoErr()
;   Device packets common equivalents
;#dp_Action  = dp_Type
;#dp_Status  = dp_Res1
;#dp_Status2 = dp_Res2
;#dp_BufAddr = dp_Arg1
   dp_Arg1.l
   dp_Arg2.l
   dp_Arg3.l
   dp_Arg4.l
   dp_Arg5.l
   dp_Arg6.l
   dp_Arg7.l
EndStructure ;  DosPacket

;  A Packet does not require the Message to be before it in memory, but
;  * for convenience it is useful to associate the two.
;  * Also see the function init_std_pkt for initializing this structure

Structure StandardPacket
   sp_Msg.Message
   sp_Pkt.DosPacket
EndStructure ;  StandardPacket

;  Packet types
#ACTION_NIL  = 0
#ACTION_STARTUP  = 0
#ACTION_GET_BLOCK = 2 ;  OBSOLETE
#ACTION_SET_MAP  = 4
#ACTION_DIE  = 5
#ACTION_EVENT  = 6
#ACTION_CURRENT_VOLUME = 7
#ACTION_LOCATE_OBJECT = 8
#ACTION_RENAME_DISK = 9
#ACTION_WRITE  = 87 ; 'W'
#ACTION_READ  =  82 ; 'R'
#ACTION_FREE_LOCK = 15
#ACTION_DELETE_OBJECT = 16
#ACTION_RENAME_OBJECT = 17
#ACTION_MORE_CACHE = 18
#ACTION_COPY_DIR  = 19
#ACTION_WAIT_CHAR = 20
#ACTION_SET_PROTECT = 21
#ACTION_CREATE_DIR = 22
#ACTION_EXAMINE_OBJECT = 23
#ACTION_EXAMINE_NEXT = 24
#ACTION_DISK_INFO = 25
#ACTION_INFO  = 26
#ACTION_FLUSH  = 27
#ACTION_SET_COMMENT = 28
#ACTION_PARENT  = 29
#ACTION_TIMER  = 30
#ACTION_INHIBIT  = 31
#ACTION_DISK_TYPE = 32
#ACTION_DISK_CHANGE = 33
#ACTION_SET_DATE  = 34

#ACTION_SCREEN_MODE = 994

#ACTION_READ_RETURN = 1001
#ACTION_WRITE_RETURN = 1002
#ACTION_SEEK  = 1008
#ACTION_FINDUPDATE = 1004
#ACTION_FINDINPUT = 1005
#ACTION_FINDOUTPUT = 1006
#ACTION_END  = 1007
#ACTION_SET_FILE_SIZE = 1022 ;  fast file system only in 1.3
#ACTION_WRITE_PROTECT = 1023 ;  fast file system only in 1.3

;  new 2.0 packets
#ACTION_SAME_LOCK = 40
#ACTION_CHANGE_SIGNAL = 995
#ACTION_FORMAT  = 1020
#ACTION_MAKE_LINK = 1021
;
;
#ACTION_READ_LINK = 1024
#ACTION_FH_FROM_LOCK = 1026
#ACTION_IS_FILESYSTEM = 1027
#ACTION_CHANGE_MODE = 1028
;
#ACTION_COPY_DIR_FH = 1030
#ACTION_PARENT_FH = 1031
#ACTION_EXAMINE_ALL = 1033
#ACTION_EXAMINE_FH = 1034

#ACTION_LOCK_RECORD = 2008
#ACTION_FREE_RECORD = 2009

#ACTION_ADD_NOTIFY = 4097
#ACTION_REMOVE_NOTIFY = 4098

;  Added in V39:
#ACTION_EXAMINE_ALL_END = 1035
#ACTION_SET_OWNER = 1036

;  Tell a file system to serialize the current volume. This is typically
;  * done by changing the creation date of the disk. This packet does not take
;  * any arguments.  NOTE: be prepared to handle failure of this packet for
;  * V37 ROM filesystems.
;
#ACTION_SERIALIZE_DISK = 4200

;
;  * A structure for holding error messages - stored as array with error == 0
;  * for the last entry.
;
Structure ErrorString
 *estr_Nums.l
 *estr_Strings.b
EndStructure

;  DOS library node structure.
;  * This is the data at positive offsets from the library node.
;  * Negative offsets from the node is the jump table to DOS functions
;  * node = (struct DosLibrary *) OpenLibrary( "dos.library" .. )

Structure DosLibrary
    dl_lib.Library
    *dl_Root.RootNode ;  Pointer to RootNode, described below
    *dl_GV.l       ;  Pointer to BCPL global vector
    dl_A2.l       ;  BCPL standard register values
    dl_A5.l
    dl_A6.l
    *dl_Errors.ErrorString   ;  PRIVATE pointer to array of error msgs
    *dl_TimeReq.timerequest   ;  PRIVATE pointer to timer request
    *dl_UtilityBase.l   ;  PRIVATE ptr to utility library
    *dl_IntuitionBase.l ;  PRIVATE ptr to intuition library
EndStructure  ;  DosLibrary

;

Structure RootNode
    rn_TaskArray.l      ;  [0] is max number of CLI's
;           * [1] is APTR to process id of CLI 1
;           * [n] is APTR to process id of CLI n
    rn_ConsoleSegment.l ;  SegList for the CLI
    rn_Time.DateStamp ;  Current time
    rn_RestartSeg.l     ;  SegList for the disk validator process
    rn_Info.l        ;  Pointer to the Info structure
    rn_FileHandlerSegment.l ;  segment for a file handler
    rn_CliList.MinList ;  new list of all CLI processes
          ;  the first cpl_Array is also rn_TaskArray
    *rn_BootProc.MsgPort ;  private ptr to msgport of boot fs
    rn_ShellSegment.l   ;  seglist for Shell (for NewShell)
    rn_Flags.l        ;  dos flags
EndStructure  ;  RootNode

#RNB_WILDSTAR = 24
#RNF_WILDSTAR = (1 LSL 24)
#RNB_PRIVATE1 = 1 ;  private for dos
#RNF_PRIVATE1 = 2

;  ONLY to be allocated by DOS!
Structure CliProcList
 cpl_Node.MinNode
 cpl_First.l      ;  number of first entry in array
 *cpl_Array.MsgPort
        ;  [0] is max number of CLI's in this entry (n)
;          * [1] is CPTR to process id of CLI cpl_First
;          * [n] is CPTR to process id of CLI cpl_First+n-1
;
EndStructure

Structure DosInfo
    di_McName.l        ;  PRIVATE: system resident module list
;#di_ResList = di_McName
    di_DevInfo.l        ;  Device List
    di_Devices.l        ;  Currently zero
    di_Handlers.l       ;  Currently zero
    *di_NetHand.l        ;  Network handler processid; currently zero
    di_DevLock.SignalSemaphore    ;  do NOT access directly!
    di_EntryLock.SignalSemaphore  ;  do NOT access directly!
    di_DeleteLock.SignalSemaphore ;  do NOT access directly!
EndStructure  ;  DosInfo

;  structure for the Dos resident list.  Do NOT allocate these, use
;  AddSegment(), and heed the warnings in the autodocs!

Structure Segment
 seg_Next.l
 seg_UC.l
 seg_Seg.l
 seg_Name.b[4] ;  actually the first 4 chars of BSTR name
EndStructure

#CMD_SYSTEM = -1
#CMD_INTERNAL = -2
#CMD_DISABLED = -999


;  DOS Processes started from the CLI via RUN or NEWCLI have this additional
;  * set to data associated with them

Structure CommandLineInterface
    cli_Result2.l        ;  Value of IoErr from last command
    cli_SetName.l        ;  Name of current directory
    cli_CommandDir.l     ;  Head of the path locklist
    cli_ReturnCode.l     ;  Return code from last command
    cli_CommandName.l    ;  Name of current command
    cli_FailLevel.l      ;  Fail level (set by FAILAT)
    cli_Prompt.l        ;  Current prompt (set by PROMPT)
    cli_StandardInput.l  ;  Default (terminal) CLI input
    cli_CurrentInput.l   ;  Current CLI input
    cli_CommandFile.l    ;  Name of EXECUTE command file
    cli_Interactive.l    ;  Boolean; True if prompts required
    cli_Background.l     ;  Boolean; True if CLI created by RUN
    cli_CurrentOutput.l  ;  Current CLI output
    cli_DefaultStack.l   ;  Stack size to be obtained in long words
    cli_StandardOutput.l ;  Default (terminal) CLI output
    cli_Module.l        ;  SegList of currently loaded command
EndStructure  ;  CommandLineInterface

;  This structure can take on different values depending on whether it is
;  * a device, an assigned directory, or a volume.  Below is the structure
;  * reflecting volumes only.  Following that is the structure representing
;  * only devices. Following that is the unioned structure representing all
;  * the values
;

;  structure representing a volume

Structure DeviceList
    dl_Next.l ;  bptr to next device list
    dl_Type.l ;  see DLT below
    *dl_Task.MsgPort ;  ptr to handler task
    dl_Lock.l ;  not for volumes
    dl_VolumeDate.DateStamp ;  creation date
    dl_LockList.l ;  outstanding locks
    dl_DiskType.l ;  'DOS', etc
    dl_unused.l
    dl_Name.l ;  bptr to bcpl name
EndStructure

;  device structure (same as the DeviceNode structure in filehandler.h)

Structure       DevInfo
    dvi_Next.l
    dvi_Type.l
    *dvi_Task.l
    dvi_Lock.l
    dvi_Handler.l
    dvi_StackSize.l
    dvi_Priority.l
    dvi_Startup.l
    dvi_SegList.l
    dvi_GlobVec.l
    dvi_Name.l
EndStructure

;  combined structure for devices, assigned directories, volumes

Structure DosList
  dol_Next.l       ;  bptr to next device on list
  dol_Type.l       ;  see DLT below
 *dol_Task.MsgPort ;  ptr to handler task
  dol_Lock.l

  StructureUnion
    dol_Handler.l       ;  file name to load if seglist is null
    dol_VolumeDate.DateStamp
   *dol_AssignName.b    ;  name for non-or-late-binding assign
  EndStructureUnion

  StructureUnion
    dol_StackSize.l     ;  stacksize to use when starting process
   *dol_List.AssignList ;  for multi-directory assigns (regular)
  EndStructureUnion

  StructureUnion
    dol_Priority.l      ;  task priority when starting process
    dol_LockList.l      ;  outstanding locks
  EndStructureUnion

  StructureUnion
    dol_Startup.l       ;  startup msg: FileSysStartupMsg for disks
    dol_DiskType.l      ;  'DOS', etc
  EndStructureUnion

  dol_SegList.l  ;  already loaded code for new task
  dol_GlobVec.l  ;  BCPL global vector to use when starting

 *dol_Name.b  ;  bptr to bcpl name

EndStructure

;  structure used for multi-directory assigns. AllocVec()ed.

Structure AssignList
 *al_Next.AssignList
 al_Lock.l
EndStructure

;  definitions for dl_Type
#DLT_DEVICE = 0
#DLT_DIRECTORY = 1 ;  assign
#DLT_VOLUME = 2
#DLT_LATE = 3 ;  late-binding assign
#DLT_NONBINDING = 4 ;  non-binding assign
#DLT_PRIVATE = -1 ;  for internal use only

;  structure return by GetDeviceProc()
Structure DevProc
 *dvp_Port.MsgPort
 dvp_Lock.l
 dvp_Flags.l
 *dvp_DevNode.DosList ;  DON'T TOUCH OR USE!
EndStructure

;  definitions for dvp_Flags
#DVPB_UNLOCK = 0
#DVPF_UNLOCK = (1  LSL  #DVPB_UNLOCK)
#DVPB_ASSIGN = 1
#DVPF_ASSIGN = (1  LSL  #DVPB_ASSIGN)

;  Flags to be passed to LockDosList(), etc
#LDB_DEVICES = 2
#LDF_DEVICES = (1  LSL  #LDB_DEVICES)
#LDB_VOLUMES = 3
#LDF_VOLUMES = (1  LSL  #LDB_VOLUMES)
#LDB_ASSIGNS = 4
#LDF_ASSIGNS = (1  LSL  #LDB_ASSIGNS)
#LDB_ENTRY = 5
#LDF_ENTRY = (1  LSL  #LDB_ENTRY)
#LDB_DELETE = 6
#LDF_DELETE = (1  LSL  #LDB_DELETE)

;  you MUST specify one of LDF_READ or LDF_WRITE
#LDB_READ = 0
#LDF_READ = (1  LSL  #LDB_READ)
#LDB_WRITE = 1
#LDF_WRITE = (1  LSL  #LDB_WRITE)

;  actually all but LDF_ENTRY (which is used for internal locking)
#LDF_ALL  = (#LDF_DEVICES|#LDF_VOLUMES|#LDF_ASSIGNS)

;  a lock structure, as returned by Lock() or DupLock()
Structure FileLock
  fl_Link.l       ;  bcpl pointer to next lock
  fl_Key.l        ;  disk block number
  fl_Access.l     ;  exclusive or shared
 *fl_Task.MsgPort ;  handler task's port
  fl_Volume.l     ;  bptr to DLT_VOLUME DosList entry
EndStructure

;  error report types for ErrorReport()
#REPORT_STREAM  = 0 ;  a stream
#REPORT_TASK  = 1 ;  a process - unused
#REPORT_LOCK  = 2 ;  a lock
#REPORT_VOLUME  = 3 ;  a volume node
#REPORT_INSERT  = 4 ;  please insert volume

;  Special error codes for ErrorReport()
#ABORT_DISK_ERROR = 296 ;  Read/write error
#ABORT_BUSY  = 288 ;  You MUST replace...

;  types for initial packets to shells from run/newcli/execute/system.
;  For shell-writers only
#RUN_EXECUTE  = -1
#RUN_SYSTEM  = -2
#RUN_SYSTEM_ASYNCH = -3

;  Types for fib_DirEntryType. NOTE that both USERDIR and ROOT are
;  directories, and that directory/file checks should use <0 and >=0.
;  This is not necessarily exhaustive! Some handlers may use other
;  values as needed, though <0 and >=0 should remain as supported as
;  possible.
#ST_ROOT  = 1
#ST_USERDIR = 2
#ST_SOFTLINK = 3 ;  looks like dir, but may point to a file!
#ST_LINKDIR = 4 ;  hard link to dir
#ST_FILE  = -3 ;  must be negative for FIB!
#ST_LINKFILE = -4 ;  hard link to file
#ST_PIPEFILE = -5 ;  for pipes that support ExamineFH

