home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / HFS- / MacSerialFS / MacSerialFSDispatch.c < prev    next >
Encoding:
Text File  |  2001-06-23  |  6.0 KB  |  236 lines

  1. /******************************************************************************
  2.  * Copyright (c) 1998-2000 Palm Computing, Inc. or its subsidiaries.
  3.  * All rights reserved.
  4.  *
  5.  * File: FSLibDispatch.c
  6.  *
  7.  * Description:    Sample filesystem library dispatch table implementation.
  8.  *
  9.  * History:
  10.  *        02/29/00    Created by Steve Minns
  11.  *
  12.  *****************************************************************************/
  13.  
  14. // If building from Metrowerks then build this as a standalone library
  15. #ifdef __PALMOS_TRAPS__
  16.   #ifdef EMULATION_LEVEL
  17.     #undef EMULATION_LEVEL
  18.   #endif
  19.   #define EMULATION_LEVEL EMULATION_NONE
  20. #endif
  21.  
  22. // Define __PALMOS_TRAPS__ to 0.  For some reason, this library is built as a PalmOS
  23. // Code resource (which sets __PALMOS_TRAPS__ to 1 internally which messes things up
  24. // since we need to get to the address of the routine names here (not use traps).
  25. #undef __PALMOS_TRAPS__
  26. #define __PALMOS_TRAPS__ 0
  27.  
  28. // Define this so that we can get the addresses of the Serial Library
  29. // routines. Other modules access the routines through traps.
  30. #define    USE_TRAPS     0
  31.  
  32.  
  33. // Include Palm headers
  34. #include <PalmTypes.h>
  35. #include <LibTraps.h>
  36. #include <SystemMgr.h>
  37.  
  38. // Our library public definitions
  39. #include "VFSMgr.h"
  40. #include "FSLib.h"
  41.  
  42.  
  43. /********************************************************************
  44.  * Private routines:
  45.  ********************************************************************/
  46.  
  47. #define PrvFSInstall        __Startup__
  48.  
  49. Err    PrvFSInstall(UInt16 refNum, SysLibTblEntryPtr entryP);
  50.  
  51. Err PrvShouldWeInstall(void);
  52.  
  53. static void *PrvDispatchTable();
  54.  
  55.  
  56. /************************************************************
  57.  *
  58.  *  FUNCTION:     __Startup__  (PrvFSInstall)
  59.  *
  60.  *  DESCRIPTION:    Entry point for FSLib Library installation resource. This
  61.  *        is a 'libr' resource in the "FSLib Library" resource database.
  62.  *        This resource contains the INet Library API entry points.
  63.  *
  64.  *        To install the library, the system calls SysLibLoad(). SysLibLoad()
  65.  *        will find the library database and call SysLibInstall() on
  66.  *        the 'libr' resource. SysLibInstall() will
  67.  *        jump to this resource to have it install it's dispatch table
  68.  *        into the library entry.
  69.  *
  70.  *  PARAMETERS:
  71.  *        refNum - refNum of library
  72.  *        entryP - the Library's entry pointer
  73.  *
  74.  *  RETURNS:        0 if no error
  75.  *
  76.  *  CALLED BY:    SysLibInstall(), SysLibRemove()
  77.  *
  78.  *************************************************************/
  79. Err    PrvFSInstall(UInt16 /* fsLibRefNum */, SysLibTblEntryPtr entryP)
  80. {
  81.     Err err;
  82.  
  83.     err = PrvShouldWeInstall();
  84.     if (err)
  85.         return err;
  86.             
  87.     // Install pointer to our dispatch table
  88.     entryP->dispatchTblP = (void **)PrvDispatchTable();
  89.     
  90.     return 0;
  91. }
  92.  
  93.  
  94. /************************************************************
  95.  *
  96.  *  FUNCTION: PrvDispatchTable
  97.  *
  98.  *  DESCRIPTION: Dispatch Table for FS Library.
  99.  *        This table gets installed into the dispatchTblP
  100.  *        field of the library entry in the library table. It gives
  101.  *        the 32-bit offset of every routine relative to the start of
  102.  *        the dispatch table.
  103.  *
  104.  *  PARAMETERS:    None
  105.  *
  106.  *    CALLED BY:
  107.  *        PrvFSInstall
  108.  *
  109.  *  RETURNS: Nothing
  110.  *
  111.  *************************************************************/
  112. #define    kNumDispatchEntries    32        // UPDATE THIS WHEN CALLS ARE ADDED TO @TABLE
  113. #define    kOffset                        ((kNumDispatchEntries + 1) * 2)
  114.  
  115. #if defined(__MC68K__)
  116. static asm void *  PrvDispatchTable()
  117. {
  118.     LEA        @Table, A0                                // table ptr
  119.     RTS                                                // return;
  120.  
  121. @Table:
  122.     DC.W        @Name
  123.     DC.W        (kOffset)                            // Open
  124.     DC.W        (kOffset+(1*4))                        // Close
  125.     DC.W        (kOffset+(2*4))                        // Sleep
  126.     DC.W        (kOffset+(3*4))                        // Wake
  127.     
  128.     DC.W        (kOffset+(4*4))                        // LibAPIVersion
  129.     DC.W        (kOffset+(5*4))                        // CustomControl
  130.     DC.W        (kOffset+(6*4))                        // FilesystemType
  131.     
  132.     DC.W        (kOffset+(7*4))                        // FileCreate
  133.     DC.W        (kOffset+(8*4))                        // FileOpen
  134.     DC.W        (kOffset+(9*4))                        // FileClose
  135.     DC.W        (kOffset+(10*4))                    // FileRead
  136.     DC.W        (kOffset+(11*4))                    // FileWrite
  137.     DC.W        (kOffset+(12*4))                    // FileDelete
  138.     DC.W        (kOffset+(13*4))                    // FileRename
  139.     DC.W        (kOffset+(14*4))                    // FileSeek
  140.     DC.W        (kOffset+(15*4))                    // FileEOF
  141.     DC.W        (kOffset+(16*4))                    // FileTell
  142.     DC.W        (kOffset+(17*4))                    // FileResize
  143.     DC.W        (kOffset+(18*4))                    // FileAttributesGet
  144.     DC.W        (kOffset+(19*4))                    // FileAttributesSet
  145.     DC.W        (kOffset+(20*4))                    // FileDateGet
  146.     DC.W        (kOffset+(21*4))                    // FileDateSet
  147.     DC.W        (kOffset+(22*4))                    // FileSize
  148.     
  149.     DC.W        (kOffset+(23*4))                    // DirCreate
  150.     DC.W        (kOffset+(24*4))                    // DirEntryEnumerate
  151.     
  152.     DC.W        (kOffset+(25*4))                    // VolumeFormat
  153.     DC.W        (kOffset+(26*4))                    // VolumeMount
  154.     DC.W        (kOffset+(27*4))                    // VolumeUnmount
  155.     DC.W        (kOffset+(28*4))                    // VolumeInfo
  156.     DC.W        (kOffset+(29*4))                    // VolumeLabelGet
  157.     DC.W        (kOffset+(30*4))                    // VolumeLabelSet
  158.     DC.W        (kOffset+(31*4))                    // VolumeSize
  159.     
  160.  
  161. @GotoLibOpen:
  162.     JMP     FSLibOpen
  163. @GotoLibClose:
  164.     JMP     FSLibClose
  165. @GotoLibSleep:
  166.     JMP     FSLibSleep
  167. @GotoLibWake:
  168.     JMP     FSLibWake
  169.     
  170. @GotoLibAPIVersion:
  171.     JMP     FSLibAPIVersion
  172. @GotoCustomControl:
  173.     JMP     FSCustomControl
  174. @GotoFilesystemType:
  175.     JMP     FSFilesystemType
  176.     
  177. @GotoFileCreate:
  178.     JMP     FSFileCreate
  179. @GotoFileOpen:
  180.     JMP     FSFileOpen
  181. @GotoFileClose:
  182.     JMP     FSFileClose
  183. @GotoFileReadLow:
  184.     JMP     FSFileRead
  185. @GotoFileWrite:
  186.     JMP     FSFileWrite
  187. @GotoFileDelete:
  188.     JMP     FSFileDelete
  189. @GotoFileRename:
  190.     JMP     FSFileRename
  191. @GotoFileSeek:
  192.     JMP     FSFileSeek
  193. @GotoFileEOF:
  194.     JMP     FSFileEOF
  195. @GotoFileTell:
  196.     JMP     FSFileTell
  197. @GotoFileSetSize:
  198.     JMP     FSFileResize
  199. @GotoFileGetAttributes:
  200.     JMP     FSFileGetAttributes
  201. @GotoFileSetAttributes:
  202.     JMP     FSFileSetAttributes
  203. @GotoFileGetDates:
  204.     JMP     FSFileGetDate
  205. @GotoFileSetDates:
  206.     JMP     FSFileSetDate
  207. @GotoFileGetSize:
  208.     JMP     FSFileSize
  209.     
  210. @GotoDirCreate:
  211.     JMP     FSDirCreate
  212. @GotoDirEntryEnumerate:
  213.     JMP     FSDirEntryEnumerate
  214.     
  215. @GotoVolumeFormat:
  216.     JMP     FSVolumeFormat
  217. @GotoVolumeMount:
  218.     JMP     FSVolumeMount
  219. @GotoVolumeUnmount:
  220.     JMP     FSVolumeUnmount
  221. @GotoVolumeInfo:
  222.     JMP     FSVolumeInfo
  223. @GotoVolumeGetLabel:
  224.     JMP     FSVolumeGetLabel
  225. @GotoVolumeSetLabel:
  226.     JMP     FSVolumeSetLabel
  227. @GotoVolumeSize:
  228.     JMP     FSVolumeSize
  229. @Name:
  230.     DC.B    "MacSerialFS Library"
  231. }
  232. #else
  233. #error "Processor type not defined"
  234. #endif
  235.  
  236.