home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Programming / powerd / modules.lha / modules / dos / dosextens.m < prev    next >
Encoding:
Text File  |  2000-06-04  |  13.5 KB  |  418 lines

  1. MODULE    'exec/tasks',
  2.             'exec/ports',
  3.             'exec/libraries',
  4.             'exec/semaphores',
  5.             'devices/timer',
  6.             'dos/dos'
  7.  
  8. #define    BSTR    PTR TO CHAR
  9.  
  10. /* All DOS processes have this structure */
  11. /* Create and Device Proc returns pointer to the MP in this structure */
  12. /* dev_proc = (struct Process *) (DeviceProc(..) - sizeof(struct Task)); */
  13.  
  14. OBJECT Process
  15.     Task:TC,
  16.     MsgPort:MP,                /* This is BPTR address from DOS functions  */
  17.     Pad:WORD,                /* Remaining variables on 4 byte boundaries */
  18.     SegList:BPTR,            /* Array of seg lists used by this process  */
  19.     StackSize:LONG,        /* Size of process stack in bytes        */
  20.     GlobVec:APTR,            /* Global vector for this process (BCPL)    */
  21.     TaskNum:LONG,            /* CLI task number of zero if not a CLI        */
  22.     StackBase:BPTR,        /* Ptr to high memory end of process stack  */
  23.     Result2:LONG,            /* Value of secondary result from last call */
  24.     CurrentDir:BPTR,        /* Lock associated with current directory   */
  25.     CIS:BPTR,                /* Current CLI Input Stream            */
  26.     COS:BPTR,                /* Current CLI Output Stream            */
  27.     ConsoleTask:APTR,        /* Console handler process for current window*/
  28.     FileSystemTask:APTR,    /* File handler process for current drive   */
  29.     CLI:BPTR,                /* pointer to CommandLineInterface        */
  30.     ReturnAddr:APTR,        /* pointer to previous stack frame        */
  31.     PktWait:APTR,            /* Function to be called when awaiting msg  */
  32.     WindowPtr:APTR,        /* Window for error printing            */
  33.  
  34.     /* following definitions are new with 2.0 */
  35.     HomeDir:BPTR,            /* Home directory of executing program        */
  36.     Flags:LONG,                /* flags telling dos about process        */
  37.     ExitCode/*()*/:PTR,        /* code to call on exit of program or NULL  */
  38.     ExitData:LONG,            /* Passed as an argument to pr_ExitCode.    */
  39.     Arguments:PTR TO UBYTE,    /* Arguments passed to the process at start */
  40.     LocalVars:MLH,            /* Local environment variables            */
  41.     ShellPrivate:ULONG,    /* for the use of the current shell        */
  42.     CES:BPTR                    /* Error stream - if NULL, use pr_COS        */
  43.  
  44. /*
  45.  * Flags for pr_Flags
  46.  */
  47. FLAG    PR_FREESEGLIST,
  48.         PR_FREECURRDIR,
  49.         PR_FREECLI,
  50.         PR_CLOSEINPUT,
  51.         PR_CLOSEOUTPUT,
  52.         PR_FREEARGS
  53.  
  54. /* The long word address (BPTR) of this structure is returned by
  55.  * Open() and other routines that return a file.  You need only worry
  56.  * about this struct to do async io's via PutMsg() instead of
  57.  * standard file system calls */
  58.  
  59. OBJECT FileHandle
  60.     Link:PTR TO MN,        /* EXEC message          */
  61.     Port:PTR TO MP,        /* Reply port for the packet */
  62.     Type:PTR TO MP,        /* Port to do PutMsg() to
  63.                                  * Address is negative if a plain file */
  64.     Buf:LONG,
  65.     Pos:LONG,
  66.     End:LONG,
  67.     Funcs|Func1:LONG,
  68.     Func2:LONG,
  69.     Func3:LONG,
  70.     Args|Arg1:LONG,
  71.     Arg2:LONG
  72.  
  73. /* This is the extension to EXEC Messages used by DOS */
  74.  
  75. OBJECT DosPacket
  76.     Link:PTR TO MN,         /* EXEC message          */
  77.     Port:PTR TO MP,         /* Reply port for the packet */
  78.                                  /* Must be filled in each send. */
  79.     Type|Action:LONG,         /* See ACTION_... below and
  80.                                   * 'R' means Read, 'W' means Write to the
  81.                                   * file system */
  82.     Res1|Status:LONG,         /* For file system calls this is the result
  83.                                   * that would have been returned by the
  84.                                   * function, e.g. Write ('W') returns actual
  85.                                   * length written */
  86.     Res2|Status2:LONG,     /* For file system calls this is what would
  87.                                   * have been returned by IoErr() */
  88.     Arg1|BufAddr:LONG,
  89.     Arg2:LONG,
  90.     Arg3:LONG,
  91.     Arg4:LONG,
  92.     Arg5:LONG,
  93.     Arg6:LONG,
  94.     Arg7:LONG
  95.  
  96. /* A Packet does not require the Message to be before it in memory, but
  97.  * for convenience it is useful to associate the two.
  98.  * Also see the function init_std_pkt for initializing this structure */
  99.  
  100. OBJECT StandardPacket
  101.     Msg:MN,
  102.     Pkt:DosPacket
  103.  
  104. /* Packet types */
  105. CONST    ACTION_NIL                    =0,
  106.         ACTION_STARTUP                =0,
  107.         ACTION_GET_BLOCK            =2,    /* OBSOLETE */
  108.         ACTION_SET_MAP                =4,
  109.         ACTION_DIE                    =5,
  110.         ACTION_EVENT                =6,
  111.         ACTION_CURRENT_VOLUME    =7,
  112.         ACTION_LOCATE_OBJECT        =8,
  113.         ACTION_RENAME_DISK        =9,
  114.         ACTION_WRITE                =87,    // "W",
  115.         ACTION_READ                    =82,    // "R",
  116.         ACTION_FREE_LOCK            =15,
  117.         ACTION_DELETE_OBJECT        =16,
  118.         ACTION_RENAME_OBJECT        =17,
  119.         ACTION_MORE_CACHE            =18,
  120.         ACTION_COPY_DIR            =19,
  121.         ACTION_WAIT_CHAR            =20,
  122.         ACTION_SET_PROTECT        =21,
  123.         ACTION_CREATE_DIR            =22,
  124.         ACTION_EXAMINE_OBJECT    =23,
  125.         ACTION_EXAMINE_NEXT        =24,
  126.         ACTION_DISK_INFO            =25,
  127.         ACTION_INFO                    =26,
  128.         ACTION_FLUSH                =27,
  129.         ACTION_SET_COMMENT        =28,
  130.         ACTION_PARENT                =29,
  131.         ACTION_TIMER                =30,
  132.         ACTION_INHIBIT                =31,
  133.         ACTION_DISK_TYPE            =32,
  134.         ACTION_DISK_CHANGE        =33,
  135.         ACTION_SET_DATE            =34,
  136.  
  137.         ACTION_SCREEN_MODE        =994,
  138.  
  139.         ACTION_READ_RETURN        =1001,
  140.         ACTION_WRITE_RETURN        =1002,
  141.         ACTION_SEEK                    =1008,
  142.         ACTION_FINDUPDATE            =1004,
  143.         ACTION_FINDINPUT            =1005,
  144.         ACTION_FINDOUTPUT            =1006,
  145.         ACTION_END                    =1007,
  146.         ACTION_SET_FILE_SIZE        =1022,    /* fast file system only in 1.3 */
  147.         ACTION_WRITE_PROTECT        =1023,    /* fast file system only in 1.3 */
  148.  
  149. /* new 2.0 packets */
  150.         ACTION_SAME_LOCK            =40,
  151.         ACTION_CHANGE_SIGNAL        =995,
  152.         ACTION_FORMAT                =1020,
  153.         ACTION_MAKE_LINK            =1021,
  154.  
  155.         ACTION_READ_LINK            =1024,
  156.         ACTION_FH_FROM_LOCK        =1026,
  157.         ACTION_IS_FILESYSTEM        =1027,
  158.         ACTION_CHANGE_MODE        =1028,
  159.  
  160.         ACTION_COPY_DIR_FH        =1030,
  161.         ACTION_PARENT_FH            =1031,
  162.         ACTION_EXAMINE_ALL        =1033,
  163.         ACTION_EXAMINE_FH            =1034,
  164.  
  165.         ACTION_LOCK_RECORD        =2008,
  166.         ACTION_FREE_RECORD        =2009,
  167.  
  168.         ACTION_ADD_NOTIFY            =4097,
  169.         ACTION_REMOVE_NOTIFY        =4098,
  170.  
  171. /* Added in V39: */
  172.         ACTION_EXAMINE_ALL_END    =1035,
  173.         ACTION_SET_OWNER            =1036,
  174.  
  175. /* Tell a file system to serialize the current volume. This is typically
  176.  * done by changing the creation date of the disk. This packet does not take
  177.  * any arguments.  NOTE: be prepared to handle failure of this packet for
  178.  * V37 ROM filesystems.
  179.  */
  180.         ACTION_SERIALIZE_DISK    =4200
  181.  
  182. /*
  183.  * A structure for holding error messages - stored as array with error == 0
  184.  * for the last entry.
  185.  */
  186. OBJECT ErrorString
  187.     Nums:PTR TO LONG,
  188.     Strings:PTR TO UBYTE
  189.  
  190. /* DOS library node structure.
  191.  * This is the data at positive offsets from the library node.
  192.  * Negative offsets from the node is the jump table to DOS functions
  193.  * node = (struct DosLibrary *) OpenLibrary( "dos.library" .. )         */
  194.  
  195. OBJECT DosLibrary
  196.     Lib:Lib,
  197.     Root:PTR TO RootNode,            /* Pointer to RootNode, described below */
  198.     GV:APTR,                                /* Pointer to BCPL global vector          */
  199.     A2:LONG,                                /* BCPL standard register values          */
  200.     A5:LONG,
  201.     A6:LONG,
  202.     Errors:PTR TO ErrorString,        /* PRIVATE pointer to array of error msgs */
  203.     TimeReq:PTR TO TimeRequest,    /* PRIVATE pointer to timer request */
  204.     UtilityBase:PTR TO Lib,            /* PRIVATE ptr to utility library */
  205.     IntuitionBase:PTR TO Lib        /* PRIVATE ptr to intuition library */
  206.  
  207. OBJECT RootNode
  208.     TaskArray:BPTR,            /* [0] is max number of CLI's
  209.                                      * [1] is APTR to process id of CLI 1
  210.                                      * [n] is APTR to process id of CLI n */
  211.     ConsoleSegment:BPTR,        /* SegList for the CLI               */
  212.     Time:DateStamp,            /* Current time                   */
  213.     RestartSeg:LONG,            /* SegList for the disk validator process   */
  214.     Info:BPTR,                    /* Pointer to the Info structure           */
  215.     FileHandlerSegment:BPTR,/* segment for a file handler       */
  216.     CliList:MLH,                /* new list of all CLI processes */
  217.                                     /* the first cpl_Array is also rn_TaskArray */
  218.     BootProc:PTR TO MP,        /* private ptr to msgport of boot fs       */
  219.     ShellSegment:BPTR,        /* seglist for Shell (for NewShell)       */
  220.     Flags:LONG                    /* dos flags */
  221.  
  222. FLAG    RN_WILDSTAR    =24,
  223.         RN_PRIVATE1    =1            /* private for dos */
  224.  
  225. /* ONLY to be allocated by DOS! */
  226. OBJECT CliProcList
  227.     Node:MN,
  228.     First:LONG,    /* number of first entry in array */
  229.     Array:PTR TO PTR TO MP
  230.                     /* [0] is max number of CLI's in this entry (n)
  231.                      * [1] is CPTR to process id of CLI cpl_First
  232.                      * [n] is CPTR to process id of CLI cpl_First+n-1
  233.                      */
  234.  
  235. OBJECT DosInfo
  236.     McName|ResList:BPTR,            /* PRIVATE: system resident module list        */
  237.     DevInfo:BPTR,                    /* Device List                    */
  238.     Devices:BPTR,                    /* Currently zero                */
  239.     Handlers:BPTR,                    /* Currently zero                */
  240.     NetHand:BPTR,                    /* Network handler processid; currently zero */
  241.     DevLock:SS,                        /* do NOT access directly! */
  242.     EntryLock:SS,                    /* do NOT access directly! */
  243.     DeleteLock:SS                    /* do NOT access directly! */
  244.  
  245. /* structure for the Dos resident list.  Do NOT allocate these, use      */
  246. /* AddSegment(), and heed the warnings in the autodocs!              */
  247.  
  248. OBJECT Segment
  249.     Next:BPTR,
  250.     UC:LONG,
  251.     Seg:BPTR,
  252.     Name[4]:UBYTE    /* actually the first 4 chars of BSTR name */
  253.  
  254. CONST    CMD_SYSTEM  =-1,
  255.         CMD_INTERNAL=-2,
  256.         CMD_DISABLED=-999
  257.  
  258.  
  259. /* DOS Processes started from the CLI via RUN or NEWCLI have this additional
  260.  * set to data associated with them */
  261.  
  262. OBJECT CommandLineInterface
  263.     Result2:LONG,            /* Value of IoErr from last command      */
  264.     SetName:BSTR,            /* Name of current directory          */
  265.     CommandDir:BPTR,        /* Head of the path locklist          */
  266.     ReturnCode:LONG,        /* Return code from last command          */
  267.     CommandName:BSTR,        /* Name of current command          */
  268.     FailLevel:LONG,        /* Fail level (set by FAILAT)          */
  269.     Prompt:BSTR,            /* Current prompt (set by PROMPT)      */
  270.     StandardInput:BPTR,    /* Default (terminal) CLI input          */
  271.     CurrentInput:BPTR,    /* Current CLI input              */
  272.     CommandFile:BSTR,        /* Name of EXECUTE command file          */
  273.     Interactive:LONG,        /* Boolean; True if prompts required      */
  274.     Background:LONG,        /* Boolean; True if CLI created by RUN      */
  275.     CurrentOutput:BPTR,    /* Current CLI output              */
  276.     DefaultStack:LONG,    /* Stack size to be obtained in long words */
  277.     StandardOutput:BPTR,    /* Default (terminal) CLI output          */
  278.     Module:BPTR                /* SegList of currently loaded command      */
  279.  
  280. /* This structure can take on different values depending on whether it is
  281.  * a device, an assigned directory, or a volume.  Below is the structure
  282.  * reflecting volumes only.  Following that is the structure representing
  283.  * only devices. Following that is the unioned structure representing all
  284.  * the values
  285.  */
  286.  
  287. /* structure representing a volume */
  288.  
  289. OBJECT DeviceList
  290.     Next:BPTR,                /* bptr to next device list */
  291.     Type:LONG,                /* see DLT below */
  292.     Task:PTR TO MP,        /* ptr to handler task */
  293.     Lock:BPTR,                /* not for volumes */
  294.     VolumeDate:DateStamp,/* creation date */
  295.     LockList:BPTR,            /* outstanding locks */
  296.     DiskType:LONG,            /* "DOS", etc */
  297.     unused:LONG,
  298.     Name:PTR TO CHAR        /* bptr to bcpl name */
  299.  
  300.  
  301. /* device structure (same as the DeviceNode structure in filehandler.h) */
  302.  
  303. OBJECT DevInfo
  304.     Next:BPTR,
  305.     Type:LONG,
  306.     Task:APTR,
  307.     Lock:BPTR,
  308.     Handler:BSTR,
  309.     StackSize:LONG,
  310.     Priority:LONG,
  311.     Startup:LONG,
  312.     SegList:BPTR,
  313.     GlobVec:BPTR,
  314.     Name:BSTR
  315.  
  316. /* combined structure for devices, assigned directories, volumes */
  317.  
  318. OBJECT DosList
  319.     Next:BPTR,                /* bptr to next device on list */
  320.     Type:LONG,                /* see DLT below */
  321.     Task:PTR TO MP,        /* ptr to handler task */
  322.     Lock:BPTR,
  323.     NEWUNION Misc
  324.         NEWUNION Handler
  325.             Handler:BPTR,        /* file name to load if seglist is null */
  326.             StackSize:LONG,    /* stacksize to use when starting process */
  327.             Priority:LONG,        /* task priority when starting process */
  328.             Startup:ULONG,        /* startup msg: FileSysStartupMsg for disks */
  329.             SegList:BPTR,        /* already loaded code for new task */
  330.             GlobVec:BPTR        /* BCPL global vector to use when starting
  331.                                      * a process. -1 indicates a C/Assembler
  332.                                      * program. */
  333.         UNION Volume
  334.             VolumeDate:DateStamp,     /* creation date */
  335.             LockList:BPTR,        /* outstanding locks */
  336.             DiskType:LONG        /* 'DOS', etc */
  337.         UNION Assign
  338.             AssignName:PTR TO CHAR,    /* name for non-or-late-binding assign */
  339.             List:PTR TO AssignList    /* for multi-directory assigns (regular) */
  340.         ENDUNION
  341.     ENDUNION,
  342.     Name:PTR TO CHAR            /* bptr to bcpl name */
  343.  
  344. /* structure used for multi-directory assigns. AllocVec()ed. */
  345.  
  346. OBJECT AssignList
  347.     Next:PTR TO AssignList,
  348.     Lock:BPTR
  349.  
  350. /* definitions for dl_Type */
  351. ENUM    DLT_PRIVATE=-1,        /* for internal use only */
  352.         DLT_DEVICE,
  353.         DLT_DIRECTORY,            /* assign */
  354.         DLT_VOLUME,
  355.         DLT_LATE,                /* late-binding assign */
  356.         DLT_NONBINDING            /* non-binding assign */
  357.  
  358. /* structure return by GetDeviceProc() */
  359. OBJECT DevProc
  360.     Port:PTR TO MP,
  361.     Lock:BPTR,
  362.     Flags:ULONG,
  363.     DevNode:PTR TO DosList    /* DON'T TOUCH OR USE! */
  364.  
  365. /* definitions for dvp_Flags */
  366. FLAG    DVP_UNLOCK,
  367.         DVP_ASSIGN,
  368. /* Flags to be passed to LockDosList(), etc */
  369. /* you MUST specify one of LDF_READ or LDF_WRITE */
  370.         LD_READ=0,
  371.         LD_WRITE,
  372.         LD_DEVICES,
  373.         LD_VOLUMES,
  374.         LD_ASSIGNS,
  375.         LD_ENTRY,
  376.         LD_DELETE
  377.  
  378. /* actually all but LDF_ENTRY (which is used for internal locking) */
  379. CONST    LDF_ALL=LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS
  380.  
  381. /* a lock structure, as returned by Lock() or DupLock() */
  382. OBJECT FileLock
  383.     Link:BPTR,                /* bcpl pointer to next lock */
  384.     Key:LONG,                /* disk block number */
  385.     Access:LONG,            /* exclusive or shared */
  386.     Task:PTR TO MP,        /* handler task's port */
  387.     Volume:BPTR                /* bptr to DLT_VOLUME DosList entry */
  388.  
  389. /* error report types for ErrorReport() */
  390. ENUM    REPORT_STREAM,        /* a stream */
  391.         REPORT_TASK,        /* a process - unused */
  392.         REPORT_LOCK,        /* a lock */
  393.         REPORT_VOLUME,        /* a volume node */
  394.         REPORT_INSERT        /* please insert volume */
  395.  
  396. /* Special error codes for ErrorReport() */
  397. CONST    ABORT_DISK_ERROR=296,/* Read/write error */
  398.         ABORT_BUSY=288            /* You MUST replace... */
  399.  
  400. /* types for initial packets to shells from run/newcli/execute/system. */
  401. /* For shell-writers only */
  402. CONST    RUN_EXECUTE=-1,
  403.         RUN_SYSTEM=-2,
  404.         RUN_SYSTEM_ASYNCH=-3
  405.  
  406. /* Types for fib_DirEntryType.    NOTE that both USERDIR and ROOT are     */
  407. /* directories, and that directory/file checks should use <0 and >=0.     */
  408. /* This is not necessarily exhaustive!    Some handlers may use other     */
  409. /* values as needed, though <0 and >=0 should remain as supported as     */
  410. /* possible.                                 */
  411. CONST    ST_ROOT        =1,
  412.         ST_USERDIR    =2,
  413.         ST_SOFTLINK    =3,    /* looks like dir, but may point to a file! */
  414.         ST_LINKDIR    =4,    /* hard link to dir */
  415.         ST_FILE        =-3,    /* must be negative for FIB! */
  416.         ST_LINKFILE    =-4,    /* hard link to file */
  417.         ST_PIPEFILE    =-5    /* for pipes that support ExamineFH */
  418.