home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / powerd / modules / dos / dosextens.m < prev    next >
Encoding:
Text File  |  1999-06-23  |  13.6 KB  |  420 lines

  1. MODULE    'exec/tasks',
  2.             'exec/ports',
  3.             'exec/libraries',
  4.             'exec/semaphores',
  5.             'devices/timer',
  6.             'dos/dos'
  7.  
  8. /* All DOS processes have this structure */
  9. /* Create and Device Proc returns pointer to the MsgPort in this structure */
  10. /* dev_proc = (struct Process *) (DeviceProc(..) - sizeof(struct Task)); */
  11.  
  12. OBJECT Process
  13.     Task:Task,
  14.     MsgPort:MsgPort,        /* This is BPTR address from DOS functions  */
  15.     Pad:WORD,                /* Remaining variables on 4 byte boundaries */
  16.     SegList:BPTR,            /* Array of seg lists used by this process  */
  17.     StackSize:LONG,        /* Size of process stack in bytes        */
  18.     GlobVec:APTR,            /* Global vector for this process (BCPL)    */
  19.     TaskNum:LONG,            /* CLI task number of zero if not a CLI        */
  20.     StackBase:BPTR,        /* Ptr to high memory end of process stack  */
  21.     Result2:LONG,            /* Value of secondary result from last call */
  22.     CurrentDir:BPTR,        /* Lock associated with current directory   */
  23.     CIS:BPTR,                /* Current CLI Input Stream            */
  24.     COS:BPTR,                /* Current CLI Output Stream            */
  25.     ConsoleTask:APTR,        /* Console handler process for current window*/
  26.     FileSystemTask:APTR,    /* File handler process for current drive   */
  27.     CLI:BPTR,                /* pointer to CommandLineInterface        */
  28.     ReturnAddr:APTR,        /* pointer to previous stack frame        */
  29.     PktWait:APTR,            /* Function to be called when awaiting msg  */
  30.     WindowPtr:APTR,        /* Window for error printing            */
  31.  
  32.     /* following definitions are new with 2.0 */
  33.     HomeDir:BPTR,            /* Home directory of executing program        */
  34.     Flags:LONG,                /* flags telling dos about process        */
  35.     ExitCode/*()*/:PTR,        /* code to call on exit of program or NULL  */
  36.     ExitData:LONG,            /* Passed as an argument to pr_ExitCode.    */
  37.     Arguments:PTR TO UBYTE,    /* Arguments passed to the process at start */
  38.     LocalVars:MinList,    /* Local environment variables            */
  39.     ShellPrivate:ULONG,    /* for the use of the current shell        */
  40.     CES:BPTR                    /* Error stream - if NULL, use pr_COS        */
  41.  
  42. /*
  43.  * Flags for pr_Flags
  44.  */
  45. FLAG    PRB_FREESEGLIST,
  46.         PRB_FREECURRDIR,
  47.         PRB_FREECLI,
  48.         PRB_CLOSEINPUT,
  49.         PRB_CLOSEOUTPUT,
  50.         PRB_FREEARGS
  51.  
  52. /* The long word address (BPTR) of this structure is returned by
  53.  * Open() and other routines that return a file.  You need only worry
  54.  * about this struct to do async io's via PutMsg() instead of
  55.  * standard file system calls */
  56.  
  57. OBJECT FileHandle
  58.     Link:PTR TO Message,    /* EXEC message          */
  59.     Port:PTR TO MsgPort,    /* Reply port for the packet */
  60.     Type:PTR TO MsgPort,    /* Port to do PutMsg() to
  61.                                  * Address is negative if a plain file */
  62.     Buf:LONG,
  63.     Pos:LONG,
  64.     End:LONG,
  65.     Funcs|Func1:LONG,
  66.     Func2:LONG,
  67.     Func3:LONG,
  68.     Args|Arg1:LONG,
  69.     Arg2:LONG
  70.  
  71. /* This is the extension to EXEC Messages used by DOS */
  72.  
  73. OBJECT DosPacket
  74.     Link:PTR TO Message,     /* EXEC message          */
  75.     Port:PTR TO MsgPort,     /* Reply port for the packet */
  76.                                  /* Must be filled in each send. */
  77.     Type|Action:LONG,         /* See ACTION_... below and
  78.                                   * 'R' means Read, 'W' means Write to the
  79.                                   * file system */
  80.     Res1|Status:LONG,         /* For file system calls this is the result
  81.                                   * that would have been returned by the
  82.                                   * function, e.g. Write ('W') returns actual
  83.                                   * length written */
  84.     Res2|Status2:LONG,     /* For file system calls this is what would
  85.                                   * have been returned by IoErr() */
  86.     Arg1|BufAddr:LONG,
  87.     Arg2:LONG,
  88.     Arg3:LONG,
  89.     Arg4:LONG,
  90.     Arg5:LONG,
  91.     Arg6:LONG,
  92.     Arg7:LONG
  93.  
  94. /* A Packet does not require the Message to be before it in memory, but
  95.  * for convenience it is useful to associate the two.
  96.  * Also see the function init_std_pkt for initializing this structure */
  97.  
  98. OBJECT StandardPacket
  99.     Msg:Message,
  100.     Pkt:DosPacket
  101.  
  102. /* Packet types */
  103. CONST    ACTION_NIL                    =0,
  104.         ACTION_STARTUP                =0,
  105.         ACTION_GET_BLOCK            =2,    /* OBSOLETE */
  106.         ACTION_SET_MAP                =4,
  107.         ACTION_DIE                    =5,
  108.         ACTION_EVENT                =6,
  109.         ACTION_CURRENT_VOLUME    =7,
  110.         ACTION_LOCATE_OBJECT        =8,
  111.         ACTION_RENAME_DISK        =9,
  112.         ACTION_WRITE                ="W",
  113.         ACTION_READ                    ="R",
  114.         ACTION_FREE_LOCK            =15,
  115.         ACTION_DELETE_OBJECT        =16,
  116.         ACTION_RENAME_OBJECT        =17,
  117.         ACTION_MORE_CACHE            =18,
  118.         ACTION_COPY_DIR            =19,
  119.         ACTION_WAIT_CHAR            =20,
  120.         ACTION_SET_PROTECT        =21,
  121.         ACTION_CREATE_DIR            =22,
  122.         ACTION_EXAMINE_OBJECT    =23,
  123.         ACTION_EXAMINE_NEXT        =24,
  124.         ACTION_DISK_INFO            =25,
  125.         ACTION_INFO                    =26,
  126.         ACTION_FLUSH                =27,
  127.         ACTION_SET_COMMENT        =28,
  128.         ACTION_PARENT                =29,
  129.         ACTION_TIMER                =30,
  130.         ACTION_INHIBIT                =31,
  131.         ACTION_DISK_TYPE            =32,
  132.         ACTION_DISK_CHANGE        =33,
  133.         ACTION_SET_DATE            =34,
  134.  
  135.         ACTION_SCREEN_MODE        =994,
  136.  
  137.         ACTION_READ_RETURN        =1001,
  138.         ACTION_WRITE_RETURN        =1002,
  139.         ACTION_SEEK                    =1008,
  140.         ACTION_FINDUPDATE            =1004,
  141.         ACTION_FINDINPUT            =1005,
  142.         ACTION_FINDOUTPUT            =1006,
  143.         ACTION_END                    =1007,
  144.         ACTION_SET_FILE_SIZE        =1022,    /* fast file system only in 1.3 */
  145.         ACTION_WRITE_PROTECT        =1023,    /* fast file system only in 1.3 */
  146.  
  147. /* new 2.0 packets */
  148.         ACTION_SAME_LOCK            =40,
  149.         ACTION_CHANGE_SIGNAL        =995,
  150.         ACTION_FORMAT                =1020,
  151.         ACTION_MAKE_LINK            =1021,
  152.  
  153.         ACTION_READ_LINK            =1024,
  154.         ACTION_FH_FROM_LOCK        =1026,
  155.         ACTION_IS_FILESYSTEM        =1027,
  156.         ACTION_CHANGE_MODE        =1028,
  157.  
  158.         ACTION_COPY_DIR_FH        =1030,
  159.         ACTION_PARENT_FH            =1031,
  160.         ACTION_EXAMINE_ALL        =1033,
  161.         ACTION_EXAMINE_FH            =1034,
  162.  
  163.         ACTION_LOCK_RECORD        =2008,
  164.         ACTION_FREE_RECORD        =2009,
  165.  
  166.         ACTION_ADD_NOTIFY            =4097,
  167.         ACTION_REMOVE_NOTIFY        =4098,
  168.  
  169. /* Added in V39: */
  170.         ACTION_EXAMINE_ALL_END    =1035,
  171.         ACTION_SET_OWNER            =1036,
  172.  
  173. /* Tell a file system to serialize the current volume. This is typically
  174.  * done by changing the creation date of the disk. This packet does not take
  175.  * any arguments.  NOTE: be prepared to handle failure of this packet for
  176.  * V37 ROM filesystems.
  177.  */
  178.         ACTION_SERIALIZE_DISK    =4200
  179.  
  180. /*
  181.  * A structure for holding error messages - stored as array with error == 0
  182.  * for the last entry.
  183.  */
  184. OBJECT ErrorString
  185.     Nums:PTR TO LONG,
  186.     Strings:PTR TO UBATE
  187.  
  188. /* DOS library node structure.
  189.  * This is the data at positive offsets from the library node.
  190.  * Negative offsets from the node is the jump table to DOS functions
  191.  * node = (struct DosLibrary *) OpenLibrary( "dos.library" .. )         */
  192.  
  193. OBJECT DosLibrary
  194.     lib:Library,
  195.     Root:PTR TO RootNode,            /* Pointer to RootNode, described below */
  196.     GV:APTR,                                /* Pointer to BCPL global vector          */
  197.     A2:LONG,                                /* BCPL standard register values          */
  198.     A5:LONG,
  199.     A6:LONG,
  200.     Errors:PTR TO ErrorString,        /* PRIVATE pointer to array of error msgs */
  201.     TimeReq:timerequest,                /* PRIVATE pointer to timer request */
  202.     UtilityBase:PTR TO Library,    /* PRIVATE ptr to utility library */
  203.     IntuitionBase:PTR TO Library    /* PRIVATE ptr to intuition library */
  204.  
  205. OBJECT RootNode
  206.     TaskArray:BPTR,            /* [0] is max number of CLI's
  207.                                      * [1] is APTR to process id of CLI 1
  208.                                      * [n] is APTR to process id of CLI n */
  209.     ConsoleSegment:BPTR,        /* SegList for the CLI               */
  210.     Time:DateStamp,            /* Current time                   */
  211.     RestartSeg:LONG,            /* SegList for the disk validator process   */
  212.     Info:BPTR,                    /* Pointer to the Info structure           */
  213.     FileHandlerSegment:BPTR,/* segment for a file handler       */
  214.     CliList:MinList,            /* new list of all CLI processes */
  215.                                     /* the first cpl_Array is also rn_TaskArray */
  216.     BootProc:PTR TO MsgPort,/* private ptr to msgport of boot fs       */
  217.     ShellSegment:BPTR,        /* seglist for Shell (for NewShell)       */
  218.     Flags:LONG                    /* dos flags */
  219.  
  220. CONST    RNB_WILDSTAR    =24,
  221.         RNF_WILDSTAR    =1<<24,
  222.         RNB_PRIVATE1    =1,    /* private for dos */
  223.         RNF_PRIVATE1    =2
  224.  
  225. /* ONLY to be allocated by DOS! */
  226. OBJECT CliProcList
  227.     Node:MinNode,
  228.     First:LONG,    /* number of first entry in array */
  229.     Array:PTR TO PTR TO MsgPort,
  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:SignalSemaphore,    /* do NOT access directly! */
  242.     EntryLock:SignalSemaphore,    /* do NOT access directly! */
  243.     DeleteLock:SignalSemaphore,/* 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 MsgPort,    /* 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 MsgPort,    /* 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.         ENDUNION,
  334.         NEWUNION Volume
  335.             VolumeDate:DateStamp,     /* creation date */
  336.             LockList:BPTR,        /* outstanding locks */
  337.             DiskType:LONG        /* 'DOS', etc */
  338.         ENDUNION,
  339.         NEWUNION Assign
  340.             AssignName:PTR TO CHAR,    /* name for non-or-late-binding assign */
  341.             List:PTR TO AssignList    /* for multi-directory assigns (regular) */
  342.         ENDUNION
  343.     ENDUNION,
  344.     Name:PTR TO CHAR            /* bptr to bcpl name */
  345.  
  346. /* structure used for multi-directory assigns. AllocVec()ed. */
  347.  
  348. OBJECT AssignList
  349.     Next:PTR TO AssignList,
  350.     Lock:BPTR
  351.  
  352. /* definitions for dl_Type */
  353. ENUM    DLT_PRIVATE=-1,        /* for internal use only */
  354.         DLT_DEVICE,
  355.         DLT_DIRECTORY,            /* assign */
  356.         DLT_VOLUME,
  357.         DLT_LATE,                /* late-binding assign */
  358.         DLT_NONBINDING            /* non-binding assign */
  359.  
  360. /* structure return by GetDeviceProc() */
  361. OBJECT DevProc
  362.     Port:PTR TO MsgPort,
  363.     Lock:BPTR,
  364.     Flags:ULONG
  365.     DevNode:PTR TO DosList    /* DON'T TOUCH OR USE! */
  366.  
  367. /* definitions for dvp_Flags */
  368. FLAG    DVP_UNLOCK,
  369.         DVP_ASSIGN,
  370. /* Flags to be passed to LockDosList(), etc */
  371. /* you MUST specify one of LDF_READ or LDF_WRITE */
  372.         LD_READ=0,
  373.         LD_WRITE,
  374.         LD_DEVICES,
  375.         LD_VOLUMES,
  376.         LD_ASSIGNS,
  377.         LD_ENTRY,
  378.         LD_DELETE
  379.  
  380. /* actually all but LDF_ENTRY (which is used for internal locking) */
  381. CONST    LDF_ALL=LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS
  382.  
  383. /* a lock structure, as returned by Lock() or DupLock() */
  384. OBJECT FileLock
  385.     Link:BPTR,                /* bcpl pointer to next lock */
  386.     Key:LONG,                /* disk block number */
  387.     Access:LONG,            /* exclusive or shared */
  388.     Task:PTR TO MsgPort,    /* handler task's port */
  389.     Volume:BPTR                /* bptr to DLT_VOLUME DosList entry */
  390.  
  391. /* error report types for ErrorReport() */
  392. ENUM    REPORT_STREAM,        /* a stream */
  393.         REPORT_TASK,        /* a process - unused */
  394.         REPORT_LOCK,        /* a lock */
  395.         REPORT_VOLUME,        /* a volume node */
  396.         REPORT_INSERT,        /* please insert volume */
  397.  
  398. /* Special error codes for ErrorReport() */
  399. CONST    ABORT_DISK_ERROR=296    /* Read/write error */
  400.         ABORT_BUSY=288            /* You MUST replace... */
  401.  
  402. /* types for initial packets to shells from run/newcli/execute/system. */
  403. /* For shell-writers only */
  404. CONST    RUN_EXECUTE=-1,
  405.         RUN_SYSTEM=-2,
  406.         RUN_SYSTEM_ASYNCH=-3
  407.  
  408. /* Types for fib_DirEntryType.    NOTE that both USERDIR and ROOT are     */
  409. /* directories, and that directory/file checks should use <0 and >=0.     */
  410. /* This is not necessarily exhaustive!    Some handlers may use other     */
  411. /* values as needed, though <0 and >=0 should remain as supported as     */
  412. /* possible.                                 */
  413. CONST    ST_ROOT        =1,
  414.         ST_USERDIR    =2,
  415.         ST_SOFTLINK    =3,    /* looks like dir, but may point to a file! */
  416.         ST_LINKDIR    =4,    /* hard link to dir */
  417.         ST_FILE        =-3,    /* must be negative for FIB! */
  418.         ST_LINKFILE    =-4,    /* hard link to file */
  419.         ST_PIPEFILE    =-5,    /* for pipes that support ExamineFH */
  420.