home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / HFS- / MacSerialFS / MacSerialFS.c next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  66.9 KB  |  2,226 lines

  1. /******************************************************************************
  2.  * Copyright (c) 2000 Palm Computing, Inc. or its subsidiaries.
  3.  * All rights reserved.
  4.  *
  5.  * File: MacSerialFS.c
  6.  *
  7.  * Description: Sample file system library implementation.
  8.  *
  9.  * History:
  10.  *        03/21/00 Created by Jesse Donaldson, from the sample FSLib code
  11.  *
  12.  *****************************************************************************/
  13.  
  14. /********************************************************************
  15.  * Filename and Label conventions:
  16.  *
  17.  * All path names are absolute
  18.  *
  19.  * All filesystems must support filenames and labels that are up to 255 characters long,
  20.  * using any normal character including spaces and lower case characters in any
  21.  * character set and the following special characters:
  22.  * $ % ' - _ @ ~ ` ! ( ) ^ # & + , ; = [ ]
  23.  ********************************************************************
  24.  * When creating the 8.3 name or label from a long filename or label:
  25.  *  a) Create the name from the first 1-6 valid, non-space characters, before the last period.
  26.  *        The only valid characters are:
  27.  *            A-Z 0-9 $ % ' - _ @ ~ ` ! ( ) ^ # &
  28.  *  b) the extension is the first three valid characters after the last period '.'
  29.  *  c) the end of the 6 byte name is appended with ~1, or the next unique number.
  30.  *
  31.  * A label is created from the first 11 valid non-space characters.
  32.  ********************************************************************/
  33.  
  34. #define NON_PORTABLE
  35.  
  36. // Include Palm headers
  37. #include <PalmTypes.h>
  38. #include <ErrorMgr.h>
  39. #include <FeatureMgr.h>
  40. #include <Preferences.h>
  41. #include <SystemMgr.h>
  42. #include <SerialMgr.h>
  43. #include <SoundMgr.h>
  44. #include <SysUtils.h>
  45. #include <StringMgr.h>
  46.  
  47. #include <NotifyMgr.h>
  48. #include <VFSMgr.h>
  49.  
  50. #include <Globals.h>
  51.  
  52. // Our library public definitions
  53. #include "VFSMgr.h"
  54. #include "FSLib.h"
  55. #include "SlotDrvrLib.h"
  56.  
  57. #include "GenericSerial.h"
  58.  
  59. /********************************************************************
  60.  * Private structures:
  61.  ********************************************************************/
  62.  
  63. #define kMaxFilenameSize        60
  64. //#define kMaxFileDataSize        (100L*1024L)        // 100k maximum volume size
  65. #define kMacSerialFSCookie            'mcfs'
  66. //#define kDirectoryFileRefCookie    'root'
  67. #define kMacSerialFSLibCreator        'mcfs'
  68.  
  69. typedef struct MacSerialFSHeaderTag{
  70.     UInt32        cookie;                        // If the cookiematches, the volume is formatted.
  71.     Boolean        created;                    // Is the file created?
  72.     UInt8        reserved[3];
  73.     UInt32        size;                        // file size
  74.     Char        filename[kMaxFilenameSize];    // filename...
  75. } MacSerialFSHeaderType;
  76.  
  77. typedef MacSerialFSHeaderType *MacSerialFSHeaderPtr;
  78.  
  79. // can mount up to 5 volumes at once
  80. #define MaxMountedVolumes    5
  81.  
  82. /********************************************************************
  83.  * LIBRARY GLOBALS:
  84.  *
  85.  * IMPORTANT:
  86.  * ==========
  87.  * Libraries are *not* allowed to have global or static variables.  Instead,
  88.  * they allocate a memory chunk to hold their persistent data, and save
  89.  * a handle to it in the library's system library table entry.  Example
  90.  *    functions below demonstrate how the library "globals" chunk is set up, saved,
  91.  *  and accessed.
  92.  *
  93.  ********************************************************************/
  94. typedef struct {
  95.     UInt16        slotLibRefNum;        // slot library refNum for mounted volume, if any
  96.     UInt16        slotRefNum;            // slot number of slot w/ mounted volume, if any
  97.     
  98.     UInt16        volumeRef;            // vfsInvalidVolRef, or volRefNum if the volume is mounted
  99.     UInt16        openRef;            // vfsInvalidFileRef or fileRef, if the file is open
  100.     UInt16        dirRef;                // vfsInvalidFileRef or fileRef, if the root directory is open
  101.     
  102.     UInt32        fileMark;
  103.     UInt32        volumeSize;            // size of media in bytes
  104.     
  105.     MacSerialFSHeaderType    header;        // copy of volume header for mounted volume
  106.     
  107. //    Boolean        rootDirOpen;
  108.     
  109. } SimpleVolumeInfoType;
  110.  
  111.  
  112. typedef struct {
  113.     Int32        openCount;            // library open count
  114.     
  115.     SimpleVolumeInfoType volume[MaxMountedVolumes];
  116.     
  117.     UInt8        rwBuffer[slotSectorSize];    // buffer we use to read & write blocks from the slot driver
  118.     
  119. } MacSerialFSGlobalsType;
  120.  
  121. typedef MacSerialFSGlobalsType *MacSerialFSGlobalsPtr;
  122.  
  123.  
  124. /********************************************************************
  125.  * Private routines:
  126.  ********************************************************************/
  127.  
  128. Err PrvShouldWeInstall(void);
  129.  
  130. Err PrvCopy(void* bufBaseP, UInt32 offset, Boolean dataStoreBased, void *srcP, UInt32 numBytes);
  131.  
  132. Int16    FindVolumeByRefNum(MacSerialFSGlobalsPtr gP, UInt16    volRefNum);
  133. Int16    FindVolumeByFileRef(MacSerialFSGlobalsPtr gP, FileRef    ref);
  134. Int16    FindVolumeBySlotRefNum(MacSerialFSGlobalsPtr gP, UInt16    slotRefNum);
  135. Int16    FindNewVolume(MacSerialFSGlobalsPtr gP);
  136.  
  137.  
  138. /********************************************************************
  139.  * Standard library open, close, sleep and wake APIs:
  140.  ********************************************************************/
  141.  
  142. Err ResetNotifyProc(SysNotifyParamType *notifyParamsP);
  143. Err ResetNotifyProc(SysNotifyParamType *notifyParamsP)
  144. {
  145.     VFSAnyMountParamType mount;
  146.     Err err;
  147.     
  148.     mount.mountClass = kMacSerialFSLibCreator;
  149.     
  150.     err = VFSVolumeMount(vfsMountFlagsUseThisFileSystem, (UInt16)(notifyParamsP->userDataP), &mount);
  151.     
  152.     ErrFatalDisplayIf(err, "can't mount");
  153.     return errNone;
  154. }
  155.  
  156.  
  157. /************************************************************
  158.  *
  159.  *  FUNCTION:    FSLibOpen
  160.  *
  161.  *
  162.  *  DESCRIPTION:        Opens the FS library, creates and initializes the globals.
  163.  *                        This function must be called before any other FS Library functions,
  164.  *                        with the exception of FSLibAPIVersion.
  165.  *
  166.  *                        If FSLibOpen fails, do not call any other FS library API functions.
  167.  *                        If FSLibOpen succeeds, call FSLibClose when you are done using
  168.  *                        the library to enable it to release critical system resources.
  169.  *                        Clients (usually VFS Lib) should call FSLibOpen() before using the
  170.  *                        filesystem driver.
  171.  *
  172.  *  LIBRARY DEVELOPER NOTES:
  173.  *                        The library's "open" and "close" functions should *not* take an excessive
  174.  *                        amount of time to complete.  If the processing time for either of these
  175.  *                        is lengthy, consider creating additional library API function(s) to handle
  176.  *                        the time-consuming chores.
  177.  *
  178.  *
  179.  *  PARAMETERS:    fsLibRefNum    -- FS library reference number returned by SysLibLoad()
  180.  *                                or SysLibFind().
  181.  *
  182.  *  CALLED BY:        anyone who wants to use this library
  183.  *
  184.  *  RETURNS:        errNone                    -- no error
  185.  *                    memErrNotEnoughSpace    -- not enough memory to initialize
  186.  *
  187.  *************************************************************/ 
  188. Err FSLibOpen(UInt16 fsLibRefNum)
  189. {
  190.     Err error = errNone;
  191.     MacSerialFSGlobalsPtr gP;
  192.     UInt16    i;
  193.     
  194.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  195.     
  196.     if (!gP) {
  197.         gP = MemPtrNew(sizeof(MacSerialFSGlobalsType));
  198.         if (!gP) {
  199.             error = sysErrNoFreeRAM;
  200.             goto Done;
  201.         }
  202.         
  203.         // MemPtrNew sets the 'owner' of a chunk to whatever the current application is.
  204.         // When that app exits, all chunks owned by it are disposed of.
  205.         // Call MemPtrSetOwner() to set the owner to the unused/system one so that the
  206.         // chunk will not be disposed of when the current app exits.
  207.         MemPtrSetOwner(gP, 0);
  208.         SysLibTblEntry(fsLibRefNum)->globalsP = gP;
  209.         
  210.         gP->openCount = 0;        
  211.         
  212.         // init volumes:
  213.         i=0;
  214.         while(i<MaxMountedVolumes)
  215.         {
  216.             gP->volume[i].volumeRef = vfsInvalidVolRef;    // no volume mounted,
  217.             gP->volume[i].openRef = vfsInvalidFileRef;        // no file open,
  218.             gP->volume[i].dirRef = vfsInvalidFileRef;        // no file open,
  219.             gP->volume[i].slotLibRefNum = 0;                // and no slotLibRefNum,
  220.             gP->volume[i].slotRefNum = 0;                // and no slotLibRefNum,
  221.             gP->volume[i].fileMark = 0;
  222. //            gP->volume[i].rootDirOpen = false;
  223.             
  224.             i++;
  225.         }
  226.     }
  227.     gP->openCount++;                        // increment open count
  228.     
  229.     // Initialize serial:
  230.     {
  231.         UInt16 refNum;
  232.         MemPtr    rcvBuf;
  233.         
  234.         error = SrmOpen(sysFileCUart328EZ, 57600, &refNum);
  235.         ErrFatalDisplayIf(error, "can't open serial");
  236.         
  237.         rcvBuf = MemPtrNew(2048);
  238.         error = SrmSetReceiveBuffer(refNum, rcvBuf, 2048);
  239.         ErrFatalDisplayIf(error, "can't set buf");
  240.         
  241.         FtrSet(kMacSerialFSLibCreator, 1, (UInt32)refNum);
  242.     }
  243.     
  244.     
  245.     // register mounting routine:
  246.     error = SysNotifyRegister(0, sysNotifyNoDatabaseID, sysNotifyResetFinishedEvent, 
  247.                         ResetNotifyProc, sysNotifyNormalPriority, (void*)fsLibRefNum);
  248.     ErrFatalDisplayIf(error, "can't register");
  249.     
  250.     GDbgWasEntered = true;
  251.     
  252. Done:    
  253.     return error;
  254. }
  255.  
  256.  
  257. /************************************************************
  258.  *
  259.  *  FUNCTION:    FSLibClose
  260.  *
  261.  *  DESCRIPTION:    Closes the FS libary, frees client context and globals.
  262.  *                    Clients (usually VFS Lib) should call FSLibClose() after using the
  263.  *                    filesystem driver.
  264.  *
  265.  *                        ***IMPORTANT***
  266.  *                        May be called only if FSLibOpen succeeded.
  267.  *
  268.  *                        If other applications still have the library open, decrements
  269.  *                        the reference count and returns expErrStillOpen.
  270.  *
  271.  *
  272.  *  LIBRARY DEVELOPER NOTES:
  273.  *                        The library's "open" and "close" functions should *not* take an excessive
  274.  *                        amount of time to complete.  If the processing time for either of these
  275.  *                        is lengthy, consider creating additional library API function(s) to handle
  276.  *                        the time-consuming chores.
  277.  *                            
  278.  *
  279.  *  PARAMETERS:    fsLibRefNum        -- FS library reference number returned by SysLibLoad()
  280.  *                                    or SysLibFind().
  281.  *  CALLED BY:    Whoever wants to close the FS library (usually ExpansionLib or file system drivers)
  282.  *                should call this after using the driver
  283.  *
  284.  *  RETURNS:    errNone            -- no error
  285.  *                expErrStillOpen    -- library is still open by others (no error)
  286.  *                expErrNotOpen    -- library is not open
  287.  *
  288.  *************************************************************/
  289. Err FSLibClose(UInt16 fsLibRefNum)
  290. {
  291.     Err error = errNone;
  292.     MacSerialFSGlobalsPtr gP;
  293.     
  294.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  295.     if (!gP || !gP->openCount)
  296.         return expErrNotOpen;
  297.     
  298.     if (--gP->openCount)
  299.         return expErrStillOpen;
  300.  
  301.     // If open count is zero, remove globals
  302.     if (gP->openCount == 0) {
  303.         MemPtrFree(gP);
  304.     }    
  305.     
  306.     return error;
  307. }
  308.  
  309.  
  310. /************************************************************
  311.  *
  312.  *  FUNCTION:    FSLibSleep
  313.  *
  314.  *  DESCRIPTION:    Handles system sleep notification.
  315.  *
  316.  *                        ***IMPORTANT***
  317.  *                        This notification function is called from a system interrupt.
  318.  *                        It is only allowed to use system services which are interrupt-
  319.  *                        safe.  Presently, this is limited to EvtEnqueueKey, SysDisableInts,
  320.  *                        SysRestoreStatus.  Because it is called from an interrupt,
  321.  *                        it must *not* take a long time to complete to preserve system
  322.  *                        integrity.  The intention is to allow system-level libraries
  323.  *                        to disable hardware components to conserve power while the system
  324.  *                        is asleep.
  325.  *
  326.  *  PARAMETERS:    fsLibRefNum        -- FS library reference number
  327.  *
  328.  *  CALLED BY:    System when going to sleep.
  329.  *
  330.  *  RETURNS:    errNone            -- no error
  331.  *                expErrNotOpen    -- FS driver library has not been opened
  332.  *
  333.  *************************************************************/
  334. Err FSLibSleep(UInt16 /*fsLibRefNum*/)
  335. {
  336.     return errNone;
  337. }
  338.  
  339.  
  340. /************************************************************
  341.  *
  342.  *  FUNCTION:    FSLibWake
  343.  *
  344.  *  DESCRIPTION:    Handles system wake notification
  345.  *
  346.  *                        ***IMPORTANT***
  347.  *                        This notification function is called from a system interrupt.
  348.  *                        It is only allowed to use system services which are interrupt-
  349.  *                        safe.  Presently, this is limited to EvtEnqueueKey, SysDisableInts,
  350.  *                        SysRestoreStatus.  Because it is called from an interrupt,
  351.  *                        it must *not* take a long time to complete to preserve system
  352.  *                        integrity.  The intention is to allow system-level libraries
  353.  *                        to enable hardware components which were disabled when the system
  354.  *                        went to sleep.
  355.  *
  356.  *  PARAMETERS:    fsLibRefNum        -- FS library reference number
  357.  *
  358.  *  CALLED BY:    System when waking up.
  359.  *
  360.  *  RETURNS:    errNone            -- no error
  361.  *                expErrNotOpen    -- FS driver library has not been opened
  362.  *
  363.  *************************************************************/
  364. Err FSLibWake(UInt16 /*fsLibRefNum*/)
  365. {
  366.     return errNone;
  367. }
  368.  
  369.  
  370. /********************************************************************
  371.  * Custom library APIs:
  372.  ********************************************************************/
  373.  
  374. /************************************************************
  375.  *
  376.  *  FUNCTION:    FSLibAPIVersion
  377.  *
  378.  *  DESCRIPTION:    Return version of the library API
  379.  *                    library need not be open to call
  380.  *
  381.  *  PARAMETERS:    fsLibRefNum    -- FS library reference number
  382.  *
  383.  *  RETURNS:    32-bit API version
  384.  *
  385.  *************************************************************/
  386. UInt32 FSLibAPIVersion(UInt16 fsLibRefNum)
  387. {
  388. #pragma unused(fsLibRefNum)
  389.     return fsLibAPIVersion;
  390. }
  391.  
  392.  
  393. /************************************************************
  394.  *
  395.  *  FUNCTION:    FSCustomControl
  396.  *
  397.  *  DESCRIPTION:    Handles a custom call for a particular volume.
  398.  *
  399.  *  LIBRARY DEVELOPER NOTES:
  400.  *        The driver identifies the call and its API by a registered creator code and a selector.
  401.  *        This allows filesystem developers to extend the API by defining selectors for their 
  402.  *        creator code. It also allows filesystem developers to suppport selectors (and custom calls) 
  403.  *        defined by other filesystem developers.
  404.  *
  405.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  406.  *                 apiCreator                -- registered creator code
  407.  *                 apiSelector                -- custom operation to perform
  408.  *                 valueP                    -- buffer containing data specific to the operation
  409.  *                 valueLenP                -- size of the valueP buffer on entry,
  410.  *                                            size of data written to valueP on exit
  411.  *
  412.  *  RETURNS:    errNone                    -- no error
  413.  *                expErrNotOpen            -- FS driver library has not been opened
  414.  *                expErrUnsupportedOperation    -- for all unsupported or undefined opcodes
  415.  *                                                and/or creators.
  416.  *                sysErrParamErr            -- valueP buffer is too small
  417.  *                Sets the size of the returned valueP buffer in valueLenP
  418.  *
  419.  *************************************************************/
  420. Err FSCustomControl(UInt16 fsLibRefNum, UInt32 /*apiCreator*/, UInt16 /*apiSelector*/, 
  421.                     void * /*valueP*/, UInt16 * /*valueLenP*/)
  422. {
  423.     MacSerialFSGlobalsPtr gP;
  424.     Err error = expErrUnsupportedOperation;
  425.     
  426.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  427.     if (!gP)
  428.         return expErrNotOpen;
  429.         
  430.     return error;
  431. }
  432.  
  433.  
  434. /************************************************************
  435.  *
  436.  *  FUNCTION:    FSFilesystemType
  437.  *
  438.  *  DESCRIPTION:    Return the type of filesystem that this library implements.
  439.  *
  440.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  441.  *                filesystemTypeP            -- On return set to the type of filesystem
  442.  *                                            Common types are defined in VFSMgr.h
  443.  *
  444.  *  RETURNS:    errNone                    -- no error
  445.  *                expErrNotOpen            -- FS driver library has not been opened
  446.  *                Fills in filesystemTypeP with the type of filesystem that this library implements.
  447.  *
  448.  *************************************************************/
  449. Err FSFilesystemType(UInt16 /*fsLibRefNum*/, UInt32 *filesystemTypeP)
  450. {
  451.     if (filesystemTypeP != NULL)
  452.         *filesystemTypeP = kMacSerialFSCookie;
  453.     return errNone;
  454. }
  455.  
  456.  
  457. /********************************************************************
  458.  * File Stream APIs:
  459.  ********************************************************************/
  460.  
  461. /************************************************************
  462.  *
  463.  *  FUNCTION:    FSFileCreate
  464.  *
  465.  *  DESCRIPTION:    Create a file.  Does not open the file.
  466.  *                    All parts of the path, except the last part must already exist.
  467.  *
  468.  *  LIBRARY DEVELOPER NOTES:
  469.  *        It is the responsibility of the filesystem library to ensure that all filenames
  470.  *        are 'mangled' into a format that is compatible with the native format of
  471.  *        the filesystem.  (i.e. 8.3 for a FAT filesystem without long filename support)
  472.  *        See comment above on "Filename conventions"
  473.  *        Note that this function does not open the file.
  474.  *
  475.  *  PARAMETERS:    fsLibRefNum        -- FS library reference number
  476.  *                volRefNum        -- Volume reference number passed to FSVolumeMount
  477.  *                pathNameP        -- Full path of the file to be created
  478.  *
  479.  *  RETURNS:    errNone                    -- no error
  480.  *                expErrNotOpen            -- FS driver library has not been opened
  481.  *                vfsErrFileAlreadyExists    -- A file of this name exists already in this location
  482.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  483.  *                vfsErrVolumeFull        -- not enough space left on volume
  484.  *                vfsErrBadName            -- pathNameP is invalid
  485.  *
  486.  *************************************************************/
  487. Err FSFileCreate(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char *pathNameP)
  488. {
  489.     
  490.     RemoteFileCreate((char*)pathNameP);
  491.     
  492.     return errNone;
  493. }
  494.  
  495.  
  496. /************************************************************
  497.  *
  498.  *  FUNCTION:    FSFileOpen
  499.  *
  500.  *  DESCRIPTION:    Open a file or directory.
  501.  *                    Note the the FileRef obtained for a directory can not be used
  502.  *                    for all functions.  For example, it is not permitted (or logical)
  503.  *                    to read directly from an opened directory.
  504.  *                    openMode is ignored when opening a directory.
  505.  *
  506.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  507.  *                volRefNum                -- Volume reference number passed to FSVolumeMount
  508.  *                pathNameP                -- Full path of the file to be opened
  509.  *                                            This must all be valid -- non-null, non-empty
  510.  *                openMode                -- fsMode to use when opening the file.  Ignored for directories
  511.  *                fileRefP                -- Pointer to a reference to the opened file
  512.  *                                            Filled in on return.
  513.  *
  514.  *  RETURNS:    errNone                    -- no error
  515.  *                expErrNotOpen            -- FS driver library has not been opened
  516.  *                vfsErrFilePermissionDenied    -- The file or directory can not be opened with the requested
  517.  *                                                openMode or has already been opened with vfsModeExclusive
  518.  *                vfsErrFileNotFound        -- the file could not be found
  519.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  520.  *                expErrCardReadOnly        -- card is read only, but openMode includes vfsModeWrite
  521.  *                vfsErrBadName            -- pathNameP is invalid
  522.  *                Fills in the passed in fileRefP with the file reference number
  523.  *
  524.  *************************************************************/
  525. Err FSFileOpen(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char *pathNameP,
  526.     UInt16 /*openMode*/, FileRef *fileRefP)
  527. {
  528.     return RemoteFileOpen((char*)pathNameP, 0, (long*)fileRefP);
  529.     /*
  530.     MacSerialFSGlobalsPtr gP;
  531.     UInt16 len;
  532.     Int16    vol;
  533.     
  534.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  535.     if (!gP)
  536.         return expErrNotOpen;
  537.         
  538.     vol = FindVolumeByRefNum(gP, volRefNum);
  539.     
  540.     if(vol == -1) 
  541.         return vfsErrVolumeBadRef;
  542.     
  543.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  544.         return vfsErrVolumeBadRef;
  545.     
  546.     if(pathNameP[0] != '/')
  547.         return vfsErrBadName;
  548.     
  549.     len = StrLen(pathNameP);
  550.     if(len < 1 || len > kMaxFilenameSize)
  551.         return vfsErrBadName;
  552.     
  553.     // If it's the root directory, handle it here:
  554.     if(StrCompare(pathNameP, "/") == 0)
  555.     {
  556.         if(gP->volume[vol].dirRef != vfsInvalidFileRef) return vfsErrFileStillOpen;
  557.         
  558. //        gP->volume[vol].rootDirOpen = true;
  559.         
  560.         gP->volume[vol].dirRef = SysRandom(0);
  561.         *fileRefP = gP->volume[vol].dirRef;
  562.         
  563.         return errNone;
  564.     }
  565.     
  566.     if(gP->volume[vol].header.created == false)
  567.         return vfsErrFileNotFound;
  568.     
  569.     if(gP->volume[vol].openRef != 0) 
  570.         return vfsErrFileStillOpen;
  571.     
  572.     // Else, open the file!!
  573.     // Correct filename requested?
  574.     if(StrCompare(&pathNameP[1], gP->volume[vol].header.filename) != 0)
  575.         return vfsErrFileNotFound;
  576.     
  577.     gP->volume[vol].openRef = SysRandom(0);
  578.     *fileRefP = gP->volume[vol].openRef;
  579.     gP->volume[vol].fileMark = 0;
  580.     
  581.     return errNone;
  582.     */
  583. }
  584.  
  585.  
  586. /************************************************************
  587.  *
  588.  *  FUNCTION:    FSFileClose
  589.  *
  590.  *  DESCRIPTION:    Close a file or directory which has been opened with FSFileOpen
  591.  *
  592.  *  PARAMETERS:    fsLibRefNum        -- FS library reference number
  593.  *                fileRef            -- File reference number returned from FSFileOpen
  594.  *
  595.  *  RETURNS:    errNone                    -- no error
  596.  *                expErrNotOpen            -- FS driver library has not been opened
  597.  *                vfsErrFileBadRef        -- the fileref is invalid
  598.  *
  599.  *************************************************************/
  600. Err FSFileClose(UInt16 /*fsLibRefNum*/, FileRef fileRef)
  601. {
  602.     return RemoteFileClose(fileRef);
  603. /*    MacSerialFSGlobalsPtr gP;
  604.     Int16    vol;
  605.     
  606.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  607.     if (!gP)
  608.         return expErrNotOpen;
  609.     
  610.     vol = FindVolumeByFileRef(gP, fileRef);
  611.     
  612.     if(vol == -1) 
  613.         return vfsErrVolumeBadRef;
  614.     
  615.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  616.         return vfsErrVolumeBadRef;
  617.     
  618.     if(gP->volume[vol].dirRef != vfsInvalidFileRef)
  619.     {
  620. //        gP->volume[vol].rootDirOpen = false;
  621.         gP->volume[vol].dirRef = vfsInvalidFileRef;
  622.         return errNone;
  623.     }
  624.     
  625.     
  626.     if(gP->volume[vol].header.created == false)
  627.         return vfsErrFileNotFound;
  628.     
  629.     if(gP->volume[vol].openRef == vfsInvalidFileRef) 
  630.         return vfsErrFileBadRef;
  631.     
  632.     if(gP->volume[vol].openRef != fileRef) 
  633.         return vfsErrFileBadRef;
  634.     
  635.     gP->volume[vol].openRef = 0;
  636.     
  637.     return errNone;*/
  638.     
  639. }
  640.  
  641.  
  642. /************************************************************
  643.  *
  644.  *  FUNCTION:    FSFileRead
  645.  *
  646.  *  DESCRIPTION:    Read data from an open file into a buffer or a data storage heap-based
  647.  *                    chunk (record or resource).
  648.  *                    This function is not permitted for FileRefs to open directories.
  649.  *
  650.  *  LIBRARY DEVELOPER NOTES:
  651.  *                    This function must check the boolean dataStoreBased to determine if bufBaseP is a pointer
  652.  *                    to a storage heap based chunk.  If it is, this function must use DmWrite to write to the
  653.  *                    buffer.
  654.  *
  655.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  656.  *                fileRef                -- File reference number returned from FSFileOpen
  657.  *                numBytes            -- The number of bytes to read
  658.  *                bufBaseP            -- ptr to beginning of destination buffer for reading data (must be
  659.  *                                        beginning of record or resource for data storage heap based destination)
  660.  *                offset                -- offset from base ptr to the destination area
  661.  *                dataStoreBased        -- if true, the bufBaseP points to a buffer in the storage heap
  662.  *                                        if false the bufBaseP buffer is in the dynamic heap
  663.  *                numBytesReadP        -- Set to the number of bytes actually read on return if non-NULL
  664.  *                                        This does not need to be initialized on input.
  665.  *
  666.  *  RETURNS:    errNone                -- no error
  667.  *                expErrNotOpen        -- FS driver library has not been opened
  668.  *                vfsErrFileBadRef    -- the fileref is invalid
  669.  *              vfsErrIsADirectory  -- the fileref points to a directory
  670.  *                vfsErrFileEOF        -- file pointer is at end of file
  671.  *                vfsErrFilePermissionDenied    -- read permission is not enabled for this file
  672.  *                Returns the number of bytes actually read in numBytesReadP if it is not NULL
  673.  *
  674.  *************************************************************/
  675. Err FSFileRead(UInt16 /*fsLibRefNum*/, FileRef fileRef, UInt32 numBytes, void *bufBaseP, 
  676.                         UInt32 offset, Boolean dataStoreBased, UInt32 *numBytesReadP)
  677. {
  678. //    ErrFatalDisplayIf(dataStoreBased, "data store reading unsupported");
  679.     return RemoteFileRead(fileRef, numBytes, (long*)numBytesReadP, bufBaseP, dataStoreBased, offset);
  680. /*    MacSerialFSGlobalsPtr gP;
  681.     Err err = errNone;
  682.     UInt32    blockNum;
  683.     UInt16    blockOffset, blockBytes;
  684.     UInt32    numSectors;
  685.     Int16    vol;
  686.     
  687.     if(numBytesReadP) *numBytesReadP = 0;
  688.     
  689.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  690.     if (!gP)
  691.         return expErrNotOpen;
  692.     
  693.     vol = FindVolumeByFileRef(gP, fileRef);
  694.     
  695.     if(vol == -1) 
  696.         return vfsErrVolumeBadRef;
  697.         
  698.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
  699.         return vfsErrVolumeBadRef;
  700.     
  701.     if(gP->volume[vol].openRef != fileRef) 
  702.         return vfsErrFileBadRef;
  703.     
  704.     if(gP->volume[vol].fileMark + numBytes > gP->volume[vol].header.size)
  705.         return vfsErrFileEOF;
  706.     
  707.     // calculate block to read:
  708.     blockNum = 1 + (gP->volume[vol].fileMark / slotSectorSize);
  709.     
  710.     // calculate starting offset
  711.     blockOffset = gP->volume[vol].fileMark % slotSectorSize;
  712.     
  713.     while(numBytes > 0)
  714.     {
  715.         // calc # bytes to read within block
  716.         blockBytes = slotSectorSize - blockOffset;
  717.         if(blockBytes > numBytes) blockBytes = numBytes;
  718.         
  719.         
  720.         // read the block:
  721.         numSectors = 1;
  722.         err = SlotCardSectorRead(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, blockNum, gP->rwBuffer, &numSectors);
  723.         if(err) goto Exit;
  724.         
  725.         // copy data into user buffer
  726.         err = PrvCopy(bufBaseP, offset, dataStoreBased, (gP->rwBuffer + blockOffset), blockBytes);
  727.         if(err) goto Exit;
  728.         
  729.         // update loop variables:
  730.         blockOffset = 0;
  731.         blockNum++;
  732.         offset += blockBytes;
  733.         numBytes -= blockBytes;
  734.         gP->volume[vol].fileMark += blockBytes;
  735.         if(numBytesReadP) *numBytesReadP += blockBytes;
  736.     }
  737.     
  738.     
  739.     
  740.     Exit:
  741.     
  742.     return err;*/
  743. }
  744.  
  745.  
  746. /************************************************************
  747.  *
  748.  *  FUNCTION:    FSFileWrite
  749.  *
  750.  *  DESCRIPTION:    Write data to an open file
  751.  *                    This function is not permitted for FileRefs to open directories.
  752.  *
  753.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  754.  *                fileRef                -- File reference number returned from FSFileOpen
  755.  *                numBytes            -- The number of bytes to write
  756.  *                dataP                -- ptr to data to write
  757.  *                numBytesWrittenP    -- Set to the number of bytes actually written on return if non-NULL
  758.  *                                        This does not need to be initialized on input.
  759.  *
  760.  *  RETURNS:    errNone                -- no error
  761.  *                expErrNotOpen        -- FS driver library has not been opened
  762.  *                vfsErrFileBadRef    -- the fileref is invalid
  763.  *              vfsErrIsADirectory  -- the fileref points to a directory
  764.  *                vfsErrFilePermissionDenied    -- write permission is not enabled for this file
  765.  *                Returns the number of bytes actually written in numBytesWrittenP if it is not NULL
  766.  *
  767.  *************************************************************/
  768. Err FSFileWrite(UInt16 /*fsLibRefNum*/, FileRef fileRef, 
  769.                 UInt32 numBytes, const void *dataP, UInt32 *numBytesWrittenP)
  770. {
  771.     return RemoteFileWrite(fileRef, numBytes, (long*)numBytesWrittenP, (char*)dataP);
  772. /*    MacSerialFSGlobalsPtr gP;
  773.     Err err = errNone;
  774.     UInt32    blockNum;
  775.     UInt16    blockOffset, blockBytes;
  776.     UInt32    numSectors;
  777.     Int16    vol;
  778.     
  779.     if(numBytesWrittenP) *numBytesWrittenP = 0;
  780.     
  781.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  782.     if (!gP)
  783.         return expErrNotOpen;
  784.     
  785.     vol = FindVolumeByFileRef(gP, fileRef);
  786.     
  787.     if(vol == -1) 
  788.         return vfsErrVolumeBadRef;
  789.         
  790.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
  791.         return vfsErrVolumeBadRef;
  792.     
  793.     if(gP->volume[vol].openRef != fileRef) 
  794.         return vfsErrFileBadRef;
  795.     
  796.     if(gP->volume[vol].fileMark + numBytes > gP->volume[vol].header.size) {
  797.         // If the file is too small, grow it
  798.         err = FSFileResize(fsLibRefNum, fileRef, gP->volume[vol].fileMark + numBytes);
  799.         if (err) return err;
  800.         if(gP->volume[vol].fileMark + numBytes > gP->volume[vol].header.size)
  801.             return vfsErrFileEOF;
  802.     }
  803.     
  804.     // calculate block to read:
  805.     blockNum = 1 + (gP->volume[vol].fileMark / slotSectorSize);
  806.     
  807.     // calculate starting offset
  808.     blockOffset = gP->volume[vol].fileMark % slotSectorSize;
  809.     
  810.     while(numBytes > 0)
  811.     {
  812.         // calc # bytes to read within block
  813.         blockBytes = slotSectorSize - blockOffset;
  814.         if(blockBytes > numBytes) blockBytes = numBytes;
  815.         
  816.         
  817.         // read the block:
  818.         numSectors = 1;
  819.         err = SlotCardSectorRead(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, blockNum, gP->rwBuffer, &numSectors);
  820.         if(err) goto Exit;
  821.         
  822.         // copy data into temp buffer
  823.         err = MemMove((gP->rwBuffer + blockOffset), dataP, blockBytes);
  824.         if(err) goto Exit;
  825.         
  826.         // write back onto media:
  827.         numSectors = 1;
  828.         err = SlotCardSectorWrite(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, blockNum, gP->rwBuffer, &numSectors);
  829.         if(err) goto Exit;
  830.         
  831.         // update loop variables:
  832.         blockNum++;
  833.         blockOffset = 0;
  834.         numBytes -= blockBytes;
  835.         gP->volume[vol].fileMark += blockBytes;
  836.         if(numBytesWrittenP) *numBytesWrittenP += blockBytes;
  837.         (UInt8*)dataP += blockBytes;
  838.     }
  839.     
  840.     
  841.     
  842.     Exit:
  843.     
  844.     return err;*/
  845. }
  846.  
  847.  
  848. /************************************************************
  849.  *
  850.  *  FUNCTION:    FSFileDelete
  851.  *
  852.  *  DESCRIPTION:    Delete a closed file or directory.
  853.  *
  854.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  855.  *                volRefNum                -- Volume reference number passed to FSVolumeMount
  856.  *                pathNameP                -- Full path of the file or directory to be deleted
  857.  *
  858.  *  RETURNS:    errNone                    -- no error
  859.  *                expErrNotOpen            -- FS driver library has not been opened
  860.  *                vfsErrFileStillOpen        -- File is still open
  861.  *                vfsErrFileNotFound        -- the file could not be found 
  862.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  863.  *                vfsErrDirNotEmpty        -- (Only when the FileRef points to a directory)
  864.  *                                            can't delete a non-empty directory
  865.  *                vfsErrFilePermissionDenied    -- write permission is not enabled for this file
  866.  *                vfsErrBadName            -- pathNameP is invalid
  867.  *
  868.  *************************************************************/
  869. Err FSFileDelete(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char *pathNameP)
  870. {
  871.     return RemoteFileDelete((char*)pathNameP);
  872. /*    MacSerialFSGlobalsPtr gP;
  873.     Err err = errNone;
  874.     UInt16    len;
  875.     UInt32    numSectors;
  876.     Int16    vol;
  877.     
  878.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  879.     if (!gP)
  880.         return expErrNotOpen;
  881.         
  882.     
  883.     vol = FindVolumeByRefNum(gP, volRefNum);
  884.     
  885.     if(vol == -1) 
  886.         return vfsErrVolumeBadRef;
  887.         
  888.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  889.         return vfsErrVolumeBadRef;
  890.     
  891.     if(gP->volume[vol].volumeRef != volRefNum) 
  892.         return vfsErrVolumeBadRef;
  893.     
  894.     if(gP->volume[vol].header.created == false)
  895.         return vfsErrFileNotFound;
  896.     
  897.     if(gP->volume[vol].openRef != 0) 
  898.         return vfsErrFileStillOpen;
  899.     
  900.     if(pathNameP[0] != '/')
  901.         return vfsErrBadName;
  902.     
  903.     len = StrLen(pathNameP);
  904.     if(len < 1 || len > kMaxFilenameSize)
  905.         return vfsErrBadName;
  906.     
  907.     if(StrCompare(&pathNameP[1], gP->volume[vol].header.filename) != 0)
  908.         return vfsErrFileNotFound;
  909.     
  910.     // Else, everythings okay - delete the file!!
  911.     gP->volume[vol].header.created = false;
  912.     
  913.     // Write changed header onto media:
  914.     *(MacSerialFSHeaderPtr)(gP->rwBuffer) = gP->volume[vol].header;
  915.     numSectors = 1;
  916.     err = SlotCardSectorWrite(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, 0, gP->rwBuffer, &numSectors);
  917.     if(err) return err;
  918.     
  919.     return errNone;*/
  920. }
  921.  
  922.  
  923. /************************************************************
  924.  *
  925.  *  FUNCTION:    FSFileRename
  926.  *
  927.  *  DESCRIPTION:    Rename a closed file or directory.
  928.  *
  929.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  930.  *                volRefNum                -- Volume reference number passed to FSVolumeMount
  931.  *                pathNameP                -- Full path of the file or directory to be renamed
  932.  *                newNameP                -- new file name only (not a full path)
  933.  *
  934.  *  RETURNS:    errNone                    -- no error
  935.  *                expErrNotOpen            -- FS driver library has not been opened
  936.  *                vfsErrFileStillOpen        -- File is still open
  937.  *                vfsErrFileNotFound        -- the file could not be found
  938.  *                vfsErrFileAlreadyExists    -- A file of this name exists already in this location
  939.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  940.  *                vfsErrFilePermissionDenied    -- write permission is not enabled for this file
  941.  *                vfsErrBadName            -- pathNameP or newNameP is invalid
  942.  *
  943.  *************************************************************/
  944. Err FSFileRename(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char */*pathNameP*/, const Char * /*newNameP*/)
  945. {
  946.     ErrFatalDisplay("rename unsupported");
  947.     return 0;
  948. /*    MacSerialFSGlobalsPtr gP;
  949.     Err err = errNone;
  950.     UInt16    len;
  951.     UInt32    numSectors;
  952.     Int16    vol;
  953.     
  954.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  955.     if (!gP)
  956.         return expErrNotOpen;
  957.     
  958.     vol = FindVolumeByRefNum(gP, volRefNum);
  959.     
  960.     if(vol == -1) 
  961.         return vfsErrVolumeBadRef;
  962.         
  963.         
  964.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  965.         return vfsErrVolumeBadRef;
  966.     
  967.     if(gP->volume[vol].volumeRef != volRefNum) 
  968.         return vfsErrVolumeBadRef;
  969.     
  970.     if(gP->volume[vol].header.created == false)
  971.         return vfsErrFileNotFound;
  972.     
  973.     if(gP->volume[vol].openRef != 0) 
  974.         return vfsErrFileStillOpen;
  975.     
  976.     if(pathNameP[0] != '/')
  977.         return vfsErrBadName;
  978.     
  979.     len = StrLen(pathNameP);
  980.     if(len < 1 || len > kMaxFilenameSize)
  981.         return vfsErrBadName;
  982.     
  983.     if(StrCompare(&pathNameP[1], gP->volume[vol].header.filename) != 0)
  984.         return vfsErrFileNotFound;
  985.     
  986.     // Else, everythings okay - rename the file!!
  987.     StrCopy(gP->volume[vol].header.filename, &pathNameP[1]);
  988.     
  989.     // Write changed header onto media:
  990.     *(MacSerialFSHeaderPtr)(gP->rwBuffer) = gP->volume[vol].header;
  991.     numSectors = 1;
  992.     err = SlotCardSectorWrite(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, 0, gP->rwBuffer, &numSectors);
  993.     if(err) return err;
  994.     
  995.     return errNone;*/
  996. }
  997.  
  998.  
  999. /************************************************************
  1000.  *
  1001.  *  FUNCTION:    FSFileSeek
  1002.  *
  1003.  *  DESCRIPTION:    Set position within an open file.  If the resulting
  1004.  *                    position would be beyond the end of the file, sets the
  1005.  *                    position to the end of file.
  1006.  *                    This function is not permitted for FileRefs to open directories.
  1007.  *
  1008.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1009.  *                fileRef                -- File reference number returned from FSFileOpen
  1010.  *                origin                -- origin to use when calculating new position from the offset
  1011.  *                offset                -- offset from the origin to set the new position in the file
  1012.  *
  1013.  *  RETURNS:    errNone                -- no error
  1014.  *                vfsErrFileEOF        -- file pointer is at end of file (not an error)
  1015.  *                expErrNotOpen        -- FS driver library has not been opened
  1016.  *                vfsErrFileBadRef    -- the fileref is invalid
  1017.  *              vfsErrIsADirectory  -- the fileref points to a directory
  1018.  *                sysErrParamErr        -- origin is invalid
  1019.  *
  1020.  *************************************************************/
  1021. Err FSFileSeek(UInt16 /*fsLibRefNum*/, FileRef fileRef, FileOrigin origin, Int32 offset)
  1022. {
  1023.     return RemoteFileSeek(fileRef, origin, offset);
  1024.     
  1025. /*    MacSerialFSGlobalsPtr gP;
  1026.     Int16                vol;
  1027.     
  1028.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1029.     if (!gP)
  1030.         return expErrNotOpen;
  1031.     
  1032.     vol = FindVolumeByFileRef(gP, fileRef);
  1033.     
  1034.     if(vol == -1) 
  1035.         return vfsErrVolumeBadRef;
  1036.         
  1037.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1038.         return vfsErrVolumeBadRef;
  1039.     
  1040.     if(gP->volume[vol].header.created == false)
  1041.         return vfsErrFileNotFound;
  1042.     
  1043.     if(gP->volume[vol].openRef == 0) 
  1044.         return vfsErrFileBadRef;
  1045.     
  1046.     if(gP->volume[vol].openRef != fileRef) 
  1047.         return sysErrParamErr;
  1048.     
  1049.     switch(origin)
  1050.     {
  1051.         case vfsOriginBeginning:
  1052.             gP->volume[vol].fileMark = offset;
  1053.             break;
  1054.         case vfsOriginCurrent:
  1055.             gP->volume[vol].fileMark += offset;
  1056.             break;
  1057.         case vfsOriginEnd:
  1058.             gP->volume[vol].fileMark = gP->volume[vol].header.size + offset;
  1059.             break;
  1060.     }
  1061.     
  1062.  
  1063.     return errNone;*/
  1064. }
  1065.  
  1066.  
  1067. /************************************************************
  1068.  *
  1069.  *  FUNCTION:    FSFileEOF
  1070.  *
  1071.  *  DESCRIPTION:    Get end-of-file status of an open file.
  1072.  *                    This function is not permitted for FileRefs to open directories.
  1073.  *
  1074.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1075.  *                fileRef                -- File reference number returned from FSFileOpen
  1076.  *
  1077.  *  RETURNS:    errNone                -- file pointer is NOT at end of file
  1078.  *                vfsErrFileEOF        -- file pointer is at end of file
  1079.  *                expErrNotOpen        -- FS driver library has not been opened
  1080.  *                vfsErrFileBadRef    -- the fileref is invalid
  1081.  *              vfsErrIsADirectory  -- the fileref points to a directory
  1082.  *
  1083.  *************************************************************/
  1084. Err FSFileEOF(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/)
  1085. {
  1086.     ErrFatalDisplay("nope");
  1087.     return 0;
  1088. /*    MacSerialFSGlobalsPtr gP;
  1089.     Err error = errNone;
  1090.     Int16        vol;
  1091.     
  1092.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1093.     if (!gP)
  1094.         return expErrNotOpen;
  1095.     
  1096.     vol = FindVolumeByFileRef(gP, fileRef);
  1097.     
  1098.     if(vol == -1) 
  1099.         return vfsErrVolumeBadRef;
  1100.     
  1101.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1102.         return vfsErrVolumeBadRef;
  1103.     
  1104.     if(gP->volume[vol].header.created == false)
  1105.         return vfsErrFileNotFound;
  1106.     
  1107.     if(gP->volume[vol].openRef == 0) 
  1108.         return vfsErrFileBadRef;
  1109.     
  1110.     if(gP->volume[vol].openRef != fileRef) 
  1111.         return sysErrParamErr;
  1112.     
  1113.     if(gP->volume[vol].fileMark == gP->volume[vol].header.size) return vfsErrFileEOF;
  1114.     
  1115.     return errNone;*/
  1116. }
  1117.  
  1118.  
  1119. /************************************************************
  1120.  *
  1121.  *  FUNCTION:    FSFileTell
  1122.  *
  1123.  *  DESCRIPTION:    Get current position of the file pointer within an open file.
  1124.  *                    This function is not permitted for FileRefs to open directories.
  1125.  *
  1126.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1127.  *                fileRef                -- File reference number returned from FSFileOpen
  1128.  *                filePosP            -- Receives the current file position
  1129.  *
  1130.  *  RETURNS:    errNone                -- no error
  1131.  *                expErrNotOpen        -- FS driver library has not been opened
  1132.  *                vfsErrFileBadRef    -- the fileref is invalid
  1133.  *              vfsErrIsADirectory  -- the fileref points to a directory
  1134.  *                Sets filePosP with the current file position.
  1135.  *
  1136.  *************************************************************/
  1137. Err FSFileTell(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/, UInt32 */*filePosP*/)
  1138. {
  1139.     ErrFatalDisplay("nope");
  1140.     return 0;
  1141. /*    MacSerialFSGlobalsPtr gP;
  1142.     Int16    vol;
  1143.     
  1144.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1145.     if (!gP)
  1146.         return expErrNotOpen;
  1147.     
  1148.     vol = FindVolumeByFileRef(gP, fileRef);
  1149.     
  1150.     if(vol == -1) 
  1151.         return vfsErrVolumeBadRef;
  1152.         
  1153.     
  1154.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1155.         return vfsErrVolumeBadRef;
  1156.     
  1157.     if(gP->volume[vol].header.created == false)
  1158.         return vfsErrFileNotFound;
  1159.     
  1160.     if(gP->volume[vol].openRef == 0) 
  1161.         return vfsErrFileBadRef;
  1162.     
  1163.     if(gP->volume[vol].openRef != fileRef) 
  1164.         return sysErrParamErr;
  1165.     
  1166.     *filePosP = gP->volume[vol].fileMark;
  1167.     
  1168.     return errNone;*/
  1169. }
  1170.  
  1171.  
  1172. /************************************************************
  1173.  *
  1174.  *  FUNCTION:    FSFileResize
  1175.  *
  1176.  *  DESCRIPTION:    Change size of an open file.
  1177.  *                    If the resizing of the file would make the current
  1178.  *                    file pointer point beyond EOF, the file pointer will
  1179.  *                    be set to point to EOF.
  1180.  *                    This function is not permitted for FileRefs to open directories.
  1181.  *
  1182.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1183.  *                fileRef                -- File reference number returned from FSFileOpen
  1184.  *                newSize                -- The desired new size of the file.
  1185.  *                                        This can be bigger or smaller then the current file size.
  1186.  *
  1187.  *  RETURNS:    errNone                -- no error
  1188.  *                expErrNotOpen        -- FS driver library has not been opened
  1189.  *                vfsErrFileBadRef    -- the fileref is invalid
  1190.  *              vfsErrIsADirectory  -- the fileref points to a directory
  1191.  *
  1192.  *************************************************************/
  1193. Err FSFileResize(UInt16 /*fsLibRefNum*/, FileRef fileRef, UInt32 newSize)
  1194. {
  1195.     return RemoteFileResize(fileRef, newSize);
  1196.     
  1197. /*    MacSerialFSGlobalsPtr gP;
  1198.     Err err = errNone;
  1199.     UInt32    numSectors;
  1200.     Int16    vol;
  1201.     
  1202.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1203.     if (!gP)
  1204.         return expErrNotOpen;
  1205.     
  1206.     vol = FindVolumeByFileRef(gP, fileRef);
  1207.     
  1208.     if(vol == -1) 
  1209.         return vfsErrVolumeBadRef;
  1210.         
  1211.         
  1212.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1213.         return vfsErrVolumeBadRef;
  1214.     
  1215.     if(gP->volume[vol].header.created == false)
  1216.         return vfsErrFileNotFound;
  1217.     
  1218.     if(gP->volume[vol].openRef == 0) 
  1219.         return vfsErrFileBadRef;
  1220.     
  1221.     if(gP->volume[vol].openRef != fileRef) 
  1222.         return sysErrParamErr;
  1223.     
  1224.     if(newSize >= gP->volume[vol].volumeSize) return vfsErrVolumeFull;
  1225.     
  1226.     // change filesize:
  1227.     gP->volume[vol].header.size = newSize;
  1228.     
  1229.     // Write changed header onto media:
  1230.     *(MacSerialFSHeaderPtr)(gP->rwBuffer) = gP->volume[vol].header;
  1231.     numSectors = 1;
  1232.     err = SlotCardSectorWrite(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, 0, gP->rwBuffer, &numSectors);
  1233.     if(err) return err;
  1234.     
  1235.     return errNone;
  1236. */
  1237. }
  1238.  
  1239.  
  1240. /************************************************************
  1241.  *
  1242.  *  FUNCTION:    FSFileGetAttributes
  1243.  *
  1244.  *  DESCRIPTION:    Obtain the attributes of an open file or directory.
  1245.  *
  1246.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1247.  *                fileRef                -- File reference number returned from FSFileOpen
  1248.  *                attributesP            -- File or directory attributes, filled in on return
  1249.  *                                        These are defined in VFSMgr.h
  1250.  *
  1251.  *  RETURNS:    errNone                -- no error
  1252.  *                expErrNotOpen        -- FS driver library has not been opened
  1253.  *                vfsErrFileBadRef    -- the fileref is invalid
  1254.  *                Sets attributesP to the open file or directory attributes
  1255.  *
  1256.  *************************************************************/
  1257. Err FSFileGetAttributes(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/, UInt32 */*attributesP*/)
  1258. {
  1259.     ErrFatalDisplay("nope");
  1260.     return 0;
  1261. /*    MacSerialFSGlobalsPtr gP;
  1262.     Err error = errNone;
  1263.     Int16        vol;
  1264.     
  1265.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1266.     if (!gP)
  1267.         return expErrNotOpen;
  1268.     
  1269.     vol = FindVolumeByFileRef(gP, fileRef);
  1270.     
  1271.     if(vol == -1) 
  1272.         return vfsErrVolumeBadRef;
  1273.         
  1274.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1275.         return vfsErrVolumeBadRef;
  1276.     
  1277.     if(gP->volume[vol].header.created == false)
  1278.         return vfsErrFileNotFound;
  1279.     
  1280.     if(gP->volume[vol].openRef == 0) 
  1281.         return vfsErrFileBadRef;
  1282.     
  1283.     if(gP->volume[vol].openRef != fileRef) 
  1284.         return sysErrParamErr;
  1285.     
  1286.     *attributesP = 0; // no special attributes
  1287.     
  1288.     return error;
  1289. */
  1290. }
  1291.  
  1292.  
  1293. /************************************************************
  1294.  *
  1295.  *  FUNCTION:    FSFileSetAttributes
  1296.  *
  1297.  *  DESCRIPTION:    Change the attributes of an open file or directory.
  1298.  *                    Cannot use this function to set the fsAttribDirectory or fsAttribVolumeLabel
  1299.  *                    attributes.  Use FSDirCreate and FSVolumeLabelSet.
  1300.  *
  1301.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1302.  *                fileRef                -- File reference number returned from FSFileOpen
  1303.  *                attributes            -- The file attributes to set to the file
  1304.  *
  1305.  *  RETURNS:    errNone                -- no error
  1306.  *                expErrNotOpen        -- FS driver library has not been opened
  1307.  *                vfsErrFileBadRef    -- the fileref is invalid
  1308.  *                sysErrParamErr        -- attributes included fsAttribDirectory or fsAttribVolumeLabel
  1309.  *
  1310.  *************************************************************/
  1311. Err FSFileSetAttributes(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/, UInt32 /*attributes*/)
  1312. {
  1313.     ErrFatalDisplay("nope");
  1314.     return 0;
  1315. /*    MacSerialFSGlobalsPtr gP;
  1316.     Int16    vol;
  1317.     
  1318.     if (attributes & (vfsFileAttrDirectory | vfsFileAttrVolumeLabel))
  1319.         return sysErrParamErr;
  1320.     
  1321.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1322.     if (!gP)
  1323.         return expErrNotOpen;
  1324.         
  1325.     vol = FindVolumeByFileRef(gP, fileRef);
  1326.     
  1327.     if(vol == -1) 
  1328.         return vfsErrVolumeBadRef;
  1329.     
  1330.     return expErrUnsupportedOperation;
  1331. */
  1332. }
  1333.  
  1334.  
  1335. /************************************************************
  1336.  *
  1337.  *  FUNCTION:    FSFileGetDate
  1338.  *
  1339.  *  DESCRIPTION:    Obtain the dates of an open file or directory.
  1340.  *
  1341.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1342.  *                fileRef                -- File reference number returned from FSFileOpen
  1343.  *                whichDate            -- Specifies which date to return.  These are defined in VFSMgr.h
  1344.  *                dateP                -- Receives the requested date
  1345.  *
  1346.  *  RETURNS:    errNone                -- no error
  1347.  *                expErrNotOpen        -- FS driver library has not been opened
  1348.  *                vfsErrFileBadRef    -- the fileref is invalid
  1349.  *                sysErrParamErr        -- whichDate is not a defined constant
  1350.  *                Sets dateP with the date specified with whichDate 
  1351.  *
  1352.  *************************************************************/
  1353. Err FSFileGetDate(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/, 
  1354.                     UInt16 /*whichDate*/, UInt32 */*dateP*/)
  1355. {
  1356.     ErrFatalDisplay("nope");
  1357.     return 0;
  1358. /*    MacSerialFSGlobalsPtr gP;
  1359.     
  1360.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1361.     if (!gP)
  1362.         return expErrNotOpen;
  1363.         
  1364.     return expErrUnsupportedOperation;
  1365. */
  1366. }
  1367.  
  1368.  
  1369. /************************************************************
  1370.  *
  1371.  *  FUNCTION:    FSFileSetDate
  1372.  *
  1373.  *  DESCRIPTION:    Change the dates of an open file or directory.
  1374.  *
  1375.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1376.  *                fileRef                -- File reference number returned from FSFileOpen
  1377.  *                whichDate            -- Specifies which date to set.  These are defined in VFSMgr.h
  1378.  *                date                -- Contains the date to set
  1379.  *
  1380.  *  RETURNS:    errNone                -- no error
  1381.  *                expErrNotOpen        -- FS driver library has not been opened
  1382.  *                vfsErrFileBadRef    -- the fileref is invalid
  1383.  *                sysErrParamErr        -- whichDate is not a defined constant
  1384.  *
  1385.  *************************************************************/
  1386. Err FSFileSetDate(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/,
  1387.                     UInt16 /*whichDate*/, UInt32 /*date*/)
  1388. {
  1389.     ErrFatalDisplay("nope");
  1390.     return 0;
  1391. /*    MacSerialFSGlobalsPtr gP;
  1392.     
  1393.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1394.     if (!gP)
  1395.         return expErrNotOpen;
  1396.         
  1397.     return expErrUnsupportedOperation;
  1398. */
  1399. }
  1400.  
  1401.  
  1402. /************************************************************
  1403.  *
  1404.  *  FUNCTION:    FSFileSize
  1405.  *
  1406.  *  DESCRIPTION:    Obtain the size of an open file.
  1407.  *                    This function is not permitted for FileRefs to open directories.
  1408.  *
  1409.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1410.  *                fileRef                -- File reference number returned from FSFileOpen
  1411.  *                fileSizeP            -- Receives the size of the open file
  1412.  *
  1413.  *  RETURNS:    errNone                -- no error
  1414.  *                expErrNotOpen        -- FS driver library has not been opened
  1415.  *                vfsErrFileBadRef    -- the fileref is invalid
  1416.  *              vfsErrIsADirectory  -- the fileref points to a directory
  1417.  *                Sets fileSizeP to the size of the file.
  1418.  *
  1419.  *************************************************************/
  1420. Err FSFileSize(UInt16 /*fsLibRefNum*/, FileRef fileRef, UInt32 *fileSizeP)
  1421. {
  1422.     return RemoteFileSize(fileRef, (long*)fileSizeP);
  1423.     
  1424.     
  1425. /*    MacSerialFSGlobalsPtr gP;
  1426.     Err error = errNone;
  1427.     Int16        vol;
  1428.     
  1429.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1430.     if (!gP)
  1431.         return expErrNotOpen;
  1432.     
  1433.     vol = FindVolumeByFileRef(gP, fileRef);
  1434.     
  1435.     if(vol == -1) 
  1436.         return vfsErrVolumeBadRef;
  1437.         
  1438.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1439.         return vfsErrVolumeBadRef;
  1440.     
  1441.     if(gP->volume[vol].header.created == false)
  1442.         return vfsErrFileNotFound;
  1443.     
  1444.     if(gP->volume[vol].openRef == 0) 
  1445.         return vfsErrFileBadRef;
  1446.     
  1447.     if(gP->volume[vol].openRef != fileRef) 
  1448.         return sysErrParamErr;
  1449.     
  1450.     
  1451.     *fileSizeP = gP->volume[vol].header.size;
  1452.     
  1453.     return error;
  1454.     */
  1455. }
  1456.  
  1457.  
  1458. /********************************************************************
  1459.  * Directory APIs:
  1460.  ********************************************************************/
  1461.  
  1462. /************************************************************
  1463.  *
  1464.  *  FUNCTION:    FSDirCreate
  1465.  *
  1466.  *  DESCRIPTION:    Create a new directory
  1467.  *                    All parts of the path, except the last part must already exist.
  1468.  *
  1469.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1470.  *                volRefNum            -- Volume reference number passed to FSVolumeMount
  1471.  *                dirNameP            -- Full path of the directory to be created
  1472.  *
  1473.  *  RETURNS:    errNone                    -- no error
  1474.  *                expErrNotOpen            -- FS driver library has not been opened
  1475.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  1476.  *                vfsErrFileAlreadyExists    -- a directory or file with this name already exists at this location
  1477.  *                vfsErrBadName            -- the full path before the new directory does not exist
  1478.  *
  1479.  *************************************************************/
  1480. Err FSDirCreate(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char * dirNameP)
  1481. {
  1482.     return RemoteDirCreate((char*)dirNameP);
  1483.     
  1484. /*    MacSerialFSGlobalsPtr gP;
  1485.     Err error = errNone;
  1486.     
  1487.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1488.     if (!gP)
  1489.         return expErrNotOpen;
  1490.         
  1491.     return expErrUnsupportedOperation;
  1492. */
  1493. }
  1494.  
  1495.  
  1496. /************************************************************
  1497.  *
  1498.  *  FUNCTION:    FSDirEntryEnumerate
  1499.  *
  1500.  *  DESCRIPTION:    Enumerate the entries in the given directory.
  1501.  *                    Pass a dirEntryIteratorP of expIteratorStart to get the first entry.
  1502.  *                    dirEntryIteratorP will be updated to the next item.
  1503.  *                    When returning the last directory entry, the dirEntryIteratorP will be
  1504.  *                    set to expIteratorStop.  If there are no directory entries to enumerate,
  1505.  *                    FSDirEntryEnumerate will return expErrEnumerationEmpty when expIteratorStart is passed
  1506.  *                    for the dirEntryIteratorP.
  1507.  *                    The directory to be enumerated must first be opened in order
  1508.  *                    to obtain a FileRef.
  1509.  *                    This function is only permitted for FileRefs to open directories.
  1510.  *
  1511.  *                    FSDirEntryEnumerate should be called like this:
  1512.  *                        FileInfoType info;
  1513.  *                        UInt32 dirIterator = expIteratorStart;
  1514.  *                        while (dirIterator != expIteratorStop) {
  1515.  *                            if ((err = FSDirEntryEnumerate(fsLibRefNum, dirRef, &dirIterator, &info)) != errNone) {
  1516.  *                                // Do something with the directory entry info
  1517.  *                            } else {
  1518.  *                                // handle error... possibly by breaking out of the loop
  1519.  *                            }
  1520.  *                        }
  1521.  *
  1522.  *  PARAMETERS:    fsLibRefNum            -- FS library reference number
  1523.  *                dirRef                -- Directory reference number returned from FSFileOpen
  1524.  *                dirEntryIteratorP    -- Reference to the last entry enumerated
  1525.  *                                        Pass expIteratorStart to get the first entry
  1526.  *                                        This is updated on return to reference the next entry
  1527.  *                                        or set to expIteratorStop if infoP is the last directory entry.
  1528.  *                infoP                -- receives Info on the directory entry specified with dirEntryIteratorP
  1529.  *
  1530.  *  RETURNS:    errNone                    -- no error, infoP is valid
  1531.  *                expErrNotOpen            -- FS driver library has not been opened
  1532.  *                vfsErrFileBadRef        -- the fileref is invalid
  1533.  *                vfsErrNotADirectory        -- the fileref is valid, but does not point to a directory entry
  1534.  *                sysErrParamErr            -- the dirEntryIteratorP is not valid
  1535.  *                expErrEnumerationEmpty    -- there are no directory entries left to enumerate
  1536.  *                Fills in infoP for the directory entry specified with dirEntryIteratorP
  1537.  *                Updates dirEntryIteratorP to point to the next entry in the directory,
  1538.  *                or sets it to expIteratorStop when returning the last directory entry.
  1539.  *
  1540.  *************************************************************/
  1541. Err FSDirEntryEnumerate(UInt16 /*fsLibRefNum*/, FileRef dirRef, UInt32 *dirEntryIteratorP, FileInfoType *infoP)
  1542. {
  1543.     long size;
  1544.     Err err;
  1545.     
  1546.     infoP->attributes = 0;
  1547.     err = RemoteDirIterate(dirRef, (long*)dirEntryIteratorP, infoP->nameP, &size, (long*)&infoP->attributes);
  1548.     
  1549.     return err;
  1550.  
  1551. /*    MacSerialFSGlobalsPtr gP;
  1552.     Err error = errNone;
  1553.     Int16        vol;
  1554.     
  1555.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1556.     if (!gP)
  1557.         return expErrNotOpen;
  1558.     
  1559.     vol = FindVolumeByFileRef(gP, dirRef);
  1560.     
  1561.     if(vol == -1) 
  1562.         return vfsErrVolumeBadRef;
  1563.         
  1564.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1565.         return vfsErrVolumeBadRef;
  1566.     
  1567. //    if(dirRef != kDirectoryFileRefCookie)
  1568. //        return vfsErrFileBadRef;
  1569.     
  1570.     if(gP->volume[vol].dirRef == vfsInvalidFileRef)
  1571.         return vfsErrFileBadRef;
  1572.     
  1573.     if(gP->volume[vol].header.created == false)
  1574.         return expErrEnumerationEmpty;
  1575.     
  1576.     if(*dirEntryIteratorP != expIteratorStart)
  1577.         return sysErrParamErr;
  1578.     
  1579.     // This is the last entry to be enumerated, so return expIteratorStop for the dirEntry
  1580.     *dirEntryIteratorP = expIteratorStop;
  1581.     
  1582.     // okay, we're searching the root dir, and looking for the first file, which DOES exist.
  1583.     // Since there can be only one, just fill in the info structure with info about it.
  1584.     StrNCopy(infoP->nameP, gP->volume[vol].header.filename, infoP->nameBufLen);
  1585.     infoP->attributes = 0;
  1586.  
  1587.     return errNone;
  1588. */
  1589. }
  1590.  
  1591.  
  1592.  
  1593. /********************************************************************
  1594.  * Volume APIs:
  1595.  ********************************************************************/
  1596.  
  1597. /************************************************************
  1598.  *
  1599.  *  FUNCTION:    FSVolumeFormat
  1600.  *
  1601.  *  DESCRIPTION:    Format the first volume on the specified slot
  1602.  *                    (The Slot Driver currently only supports one volume per slot)
  1603.  *                    A volume must not be mounted on the slot when calling this function.
  1604.  *
  1605.  *  LIBRARY DEVELOPER NOTES:
  1606.  *                    As with all power-intensive operations, the filesystem
  1607.  *                    should check to make sure that enough power is available
  1608.  *                    to complete the format, and abort if not, returning
  1609.  *                    expErrNotEnoughPower.
  1610.  *
  1611.  *                    The vfsMountParamP should be switched off of
  1612.  *                    vfsMountParamP->mountClass and cast to the correct
  1613.  *                    MountParamType.  For example if mountClass == 'libs'
  1614.  *                    then vfsMountParamP should be cast to VFSSlotMountParamType.
  1615.  *
  1616.  *                    Before formatting the media, FSVolumeFormat should call
  1617.  *                    SlotCardLowLevelFormat().  It should then call SlotCardMetrics()
  1618.  *                    to get information about the physical metrics of the card.
  1619.  *                    The actual format should be accomplished with SlotSectorWrite() calls.
  1620.  *
  1621.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  1622.  *                vfsMountParamP            -- Mount parameters
  1623.  *
  1624.  *  RETURNS:    errNone                    -- no error
  1625.  *                expErrNotOpen            -- FS driver library has not been opened
  1626.  *                expErrNotEnoughPower    -- the required power is not available
  1627.  *                vfsErrVolumeStillMounted    -- There is already a volume mounted on this slot
  1628.  *
  1629.  *************************************************************/
  1630. Err FSVolumeFormat(UInt16 /*fsLibRefNum*/, VFSAnyMountParamPtr /*vfsMountParamP*/)
  1631. {
  1632.     ErrFatalDisplay("nope");
  1633.     return 0;
  1634. /*    MacSerialFSGlobalsPtr gP;
  1635.     Err err = errNone;
  1636.     VFSSlotMountParamType *slotMountP = (VFSSlotMountParamType*)vfsMountParamP;
  1637.     UInt16    slotLibRefNum, slotRefNum;
  1638.     UInt32    numSectors;
  1639.     Int16    vol;
  1640.     
  1641.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1642.     if (!gP)
  1643.         return expErrNotOpen;
  1644.         
  1645.     if(vfsMountParamP->mountClass != vfsMountClass_SlotDriver) 
  1646.         return expErrUnsupportedOperation;
  1647.     
  1648.     // Make sure that the volume is unmounted before formatting it.
  1649.     vol = FindVolumeBySlotRefNum(gP, slotMountP->slotRefNum);
  1650.     if(vol != -1)
  1651.     {
  1652.         err = vfsErrVolumeStillMounted;
  1653.         goto Exit;
  1654.     }
  1655.     
  1656.     slotLibRefNum = slotMountP->slotLibRefNum;
  1657.     slotRefNum = slotMountP->slotRefNum;
  1658.     
  1659.     // Low-level format the media
  1660.     err = SlotCardLowLevelFormat(slotLibRefNum, slotRefNum);
  1661.     if (err) goto Exit;
  1662.     
  1663.     // set up empty volume:
  1664.     ((MacSerialFSHeaderPtr)(gP->rwBuffer))->cookie = kMacSerialFSCookie;
  1665.     ((MacSerialFSHeaderPtr)(gP->rwBuffer))->created = false;
  1666.     ((MacSerialFSHeaderPtr)(gP->rwBuffer))->size = 0;
  1667.     ((MacSerialFSHeaderPtr)(gP->rwBuffer))->filename[0] = 0;
  1668.         
  1669.     // Write empty volume onto media:
  1670.     numSectors = 1;
  1671.     err = SlotCardSectorWrite(slotLibRefNum, slotRefNum, 0, gP->rwBuffer, &numSectors);
  1672.     if(err) goto Exit;
  1673.     
  1674. Exit:
  1675.     
  1676.     return err;*/
  1677.     
  1678. }
  1679.  
  1680.  
  1681. /************************************************************
  1682.  *
  1683.  *  FUNCTION:    FSVolumeMount
  1684.  *
  1685.  *  DESCRIPTION:    Mount the first volume on the specified slot
  1686.  *                    (The Slot Driver only supports one volume per slot)
  1687.  *                    The VFS posts a sysNotifyVolumeMountedEvent notification once the filesystem
  1688.  *                    is successfully mounted.
  1689.  *                    VFSAnyMountParamPtr->volRefNum must be set on entry to the volRefNum that will
  1690.  *                    be assigned to this volume if the mount succeeds.
  1691.  *
  1692.  *  LIBRARY DEVELOPER NOTES:
  1693.  *                    The VFS will post the sysNotifyVolumeMountedEvent notification ONLY if this
  1694.  *                    function returns errNone.
  1695.  *
  1696.  *                    Before mounting, it is important to check to make sure
  1697.  *                    that there is enough power to perform the mount.  If there is not
  1698.  *                    enough power to mount, FSVolumeMount should return expErrNotEnoughPower
  1699.  *                    and abort the mount operation.
  1700.  *
  1701.  *                    The vfsMountParamP should be switched off of
  1702.  *                    vfsMountParamP->mountClass and cast to the correct
  1703.  *                    MountParamType.  For example if mountClass == 'libs'
  1704.  *                    then vfsMountParamP should be cast to VFSSlotMountParamType.
  1705.  *
  1706.  *                    The vfsMountParamP contains the global volRefNum that will be assigned
  1707.  *                    to this volume if the mount succeeds.  The filesystem
  1708.  *                    library should store this, as all other calls which take a volRefNum
  1709.  *                    as a parameter will use this number.
  1710.  *
  1711.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  1712.  *                vfsMountParamP            -- Mount parameters
  1713.  *
  1714.  *  RETURNS:    errNone                    -- no error
  1715.  *                expErrNotOpen            -- FS driver library has not been opened
  1716.  *                expErrNotEnoughPower    -- the required power is not available
  1717.  *                vfsErrBadData            -- The volume cannot be mounted because the
  1718.  *                                            format of the media is unrecognized
  1719.  *                                            This will cause the VFS to attempt to format 
  1720.  *                                            and remount the media.
  1721.  *
  1722.  *************************************************************/
  1723. Err FSVolumeMount(UInt16 /*fsLibRefNum*/, VFSAnyMountParamPtr vfsMountParamP)
  1724. {
  1725.     if(vfsMountParamP->mountClass == kMacSerialFSLibCreator) return errNone;
  1726.     
  1727.     return expErrUnsupportedOperation;
  1728.     
  1729. /*    MacSerialFSGlobalsPtr gP;
  1730.     Err err = errNone;
  1731.     VFSSlotMountParamType *slotMountP = (VFSSlotMountParamType*)vfsMountParamP;
  1732.     UInt16    slotLibRefNum, slotRefNum;
  1733.     UInt32    numSectors;
  1734.     Int16    vol;
  1735.     CardMetricsType    metrics;
  1736.     
  1737.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1738.     if (!gP)
  1739.         return expErrNotOpen;
  1740.     
  1741.     if(vfsMountParamP->mountClass != vfsMountClass_SlotDriver) 
  1742.         return expErrUnsupportedOperation;
  1743.         
  1744.     // Make sure that the volume is unmounted before mounting it.
  1745.     vol = FindVolumeBySlotRefNum(gP, slotMountP->slotRefNum);
  1746.     if(vol != -1)
  1747.     {
  1748.         err = vfsErrVolumeStillMounted;
  1749.         goto Exit;
  1750.     }
  1751.     
  1752.     vol = FindNewVolume(gP);
  1753.     if(vol == -1)
  1754.     {
  1755.         err = expErrUnsupportedOperation;
  1756.         goto Exit;
  1757.     }
  1758.     
  1759.     if(gP->volume[vol].volumeRef != vfsInvalidVolRef) 
  1760.         return vfsErrVolumeStillMounted;
  1761.        
  1762.     slotLibRefNum = slotMountP->slotLibRefNum;
  1763.     slotRefNum = slotMountP->slotRefNum;
  1764.     
  1765.     numSectors = 1;
  1766.     
  1767.     err = SlotCardSectorRead(slotLibRefNum, slotRefNum, 0, gP->rwBuffer, &numSectors);
  1768.     if(err) goto Exit;
  1769.     
  1770.     gP->volume[vol].header = *(MacSerialFSHeaderPtr)(gP->rwBuffer);
  1771.     
  1772.     // has the volume been formatted?
  1773.     if(gP->volume[vol].header.cookie != kMacSerialFSCookie)
  1774.     {
  1775.         err = vfsErrBadData;
  1776.         goto Exit;
  1777.     }
  1778.     
  1779.     err = SlotCardMetrics(slotLibRefNum, slotRefNum, &metrics);
  1780.     if(err) goto Exit;
  1781.     
  1782. //    if(metrics.reservedRangesP) 
  1783. //        MemPtrFree(metrics.reservedRangesP);
  1784.     
  1785.     // Yes - volume is formatted, mount it:
  1786.     // Save the global volRefNum
  1787.     gP->volume[vol].volumeRef = slotMountP->vfsMountParam.volRefNum;
  1788.     gP->volume[vol].slotLibRefNum = slotLibRefNum;
  1789.     gP->volume[vol].slotRefNum = slotRefNum;
  1790.     
  1791.     gP->volume[vol].openRef = vfsInvalidFileRef;
  1792.     gP->volume[vol].fileMark = 0;
  1793.     gP->volume[vol].volumeSize = metrics.bytesPerSector * (metrics.totalSectors-1);
  1794.     
  1795.     err = errNone;
  1796.     
  1797.     Exit:
  1798.     
  1799.     return err;
  1800.     */
  1801. }
  1802.  
  1803.  
  1804. /************************************************************
  1805.  *
  1806.  *  FUNCTION:    FSVolumeUnmount
  1807.  *
  1808.  *  DESCRIPTION:    Unmount the given volume.  This closes any opened files.
  1809.  *                    The VFS posts a sysNotifyVolumeUnmountedEvent notification once the filesystem
  1810.  *                    is successfully unmounted.
  1811.  *
  1812.  *  LIBRARY DEVELOPER NOTES:
  1813.  *                    The VFS will post the sysNotifyVolumeUnmountedEvent notification ONLY if this
  1814.  *                    function returns errNone.
  1815.  *
  1816.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  1817.  *                volRefNum                -- Volume reference number passed to FSVolumeMount
  1818.  *
  1819.  *  RETURNS:    errNone                    -- no error
  1820.  *                expErrNotOpen            -- FS driver library has not been opened
  1821.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  1822.  *
  1823.  *************************************************************/
  1824. Err FSVolumeUnmount(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/)
  1825. {
  1826.     ErrFatalDisplay("nope");
  1827.     return 0;
  1828. /*    MacSerialFSGlobalsPtr gP;
  1829.     Err err = errNone;
  1830.     Int16    vol;
  1831.     
  1832.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1833.     if (!gP)
  1834.         return expErrNotOpen;
  1835.         
  1836.         
  1837.     vol = FindVolumeByRefNum(gP, volRefNum);
  1838.     
  1839.     if(vol == -1) 
  1840.         return vfsErrVolumeBadRef;
  1841.         
  1842.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1843.         return vfsErrVolumeBadRef;
  1844.     
  1845.     if(gP->volume[vol].openRef != 0) 
  1846.         return vfsErrFileStillOpen;
  1847.     
  1848.     
  1849.     gP->volume[vol].volumeRef = vfsInvalidVolRef;
  1850.     err = errNone;
  1851.     
  1852.     
  1853.     return err;
  1854.     */
  1855.     
  1856. }
  1857.  
  1858.  
  1859. /************************************************************
  1860.  *
  1861.  *  FUNCTION:    FSVolumeInfo
  1862.  *
  1863.  *  DESCRIPTION:    Get information about the specified volume
  1864.  *
  1865.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  1866.  *                volRefNum                -- Volume reference number passed to FSVolumeMount
  1867.  *                volInfoP                -- Receives the volume info for the specified volume
  1868.  *
  1869.  *  RETURNS:    errNone                    -- no error
  1870.  *                expErrNotOpen            -- FS driver library has not been opened
  1871.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  1872.  *                volInfoP is filled in on return with information about the specified volume
  1873.  *
  1874.  *************************************************************/
  1875. Err FSVolumeInfo(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, VolumeInfoType *volInfoP)
  1876. {
  1877.     
  1878.     volInfoP->attributes = 0;
  1879.     volInfoP->fsType = kMacSerialFSLibCreator;
  1880.     volInfoP->fsCreator = kMacSerialFSLibCreator;
  1881.     volInfoP->mountClass = kMacSerialFSLibCreator;
  1882.     
  1883.     return errNone;
  1884. /*    MacSerialFSGlobalsPtr gP;
  1885.     Err err = errNone;
  1886.     Int16        vol;
  1887.     
  1888.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1889.     if (!gP)
  1890.         return expErrNotOpen;
  1891.         
  1892.     vol = FindVolumeByRefNum(gP, volRefNum);
  1893.     
  1894.     if(vol == -1) 
  1895.         return vfsErrVolumeBadRef;
  1896.         
  1897.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  1898.         return vfsErrVolumeBadRef;
  1899.     
  1900.     if(gP->volume[vol].volumeRef != volRefNum) 
  1901.         return vfsErrVolumeBadRef;
  1902.     
  1903.     volInfoP->attributes    = 0;
  1904.     volInfoP->fsType        = kMacSerialFSCookie;        // Use the cookie as the filesystem type.
  1905.     volInfoP->fsCreator        = kMacSerialFSLibCreator;
  1906.     volInfoP->mountClass    = vfsMountClass_SlotDriver;
  1907.     volInfoP->slotLibRefNum = gP->volume[vol].slotLibRefNum;
  1908.     volInfoP->slotRefNum    = gP->volume[vol].slotRefNum;
  1909.     err = SlotCardMediaType(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, &(volInfoP->mediaType));
  1910.     volInfoP->fsCreator        = kMacSerialFSLibCreator;
  1911.     volInfoP->reserved        = 0;
  1912.     
  1913.     
  1914.     
  1915.     return err;
  1916. */
  1917. }
  1918.  
  1919.  
  1920. /************************************************************
  1921.  *
  1922.  *  FUNCTION:    FSVolumeGetLabel
  1923.  *
  1924.  *  DESCRIPTION:    Determine the volume label for a particular volume.
  1925.  *                    Clients that wish to remember a particular volume
  1926.  *                    should save this rather than the volRefNum. The volRefNum
  1927.  *                    may be different each time the volume is mounted.
  1928.  *
  1929.  *                    Volume labels are up to 255 characters long,
  1930.  *                    using any normal character including spaces and lower case
  1931.  *                    characters in any character set and the following special characters:
  1932.  *                    $ % ' - _ @ ~ ` ! ( ) ^ # & + , ; = [ ]
  1933.  *
  1934.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  1935.  *                volRefNum                -- Volume reference number passed to FSVolumeMount
  1936.  *                labelP                    -- Receives the label of the volume.
  1937.  *                bufLen                    -- The length of the labelP buffer
  1938.  *
  1939.  *  RETURNS:    errNone                    -- no error
  1940.  *                expErrNotOpen            -- FS driver library has not been opened
  1941.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  1942.  *                vfsErrBufferOverflow    -- bufLen is not big enough to receive the full volume label
  1943.  *                labelP is filled in on return with the volume label for the specified volume
  1944.  *
  1945.  *************************************************************/
  1946. Err FSVolumeGetLabel(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, Char *labelP, UInt16 /*bufLen*/)
  1947. {
  1948.     StrCopy(labelP, "Macintosh HD");
  1949.     
  1950.     return 0;
  1951. /*
  1952.     MacSerialFSGlobalsPtr gP;
  1953.     Int16        vol;
  1954.     UInt32        size;
  1955.     char        label[32];
  1956.     
  1957.     
  1958.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  1959.     if (!gP)
  1960.         return expErrNotOpen;
  1961.         
  1962.     vol = FindVolumeByRefNum(gP, volRefNum);
  1963.     
  1964.     if(vol == -1) 
  1965.         return vfsErrVolumeBadRef;
  1966.     
  1967.     size = gP->volume[vol].volumeSize;
  1968.     size /= 1024;
  1969.     
  1970.     if(size < 1024)
  1971.     {
  1972.         StrPrintF(label, "%dKB RAMDisk", (UInt16)size);
  1973.     }
  1974.     else
  1975.     {
  1976.         size /= 1024;
  1977.         StrPrintF(label, "%dMB RAMDisk", (UInt16)size);
  1978.     }
  1979.     
  1980.     if(StrLen(label) >= bufLen) return vfsErrBufferOverflow;
  1981.     
  1982.     StrCopy(labelP, label);
  1983.     
  1984. //    StrNCopy(labelP, "Untitled", bufLen);
  1985.     
  1986.     return errNone;
  1987. */
  1988. }
  1989.  
  1990.  
  1991. /************************************************************
  1992.  *
  1993.  *  FUNCTION:    FSVolumeSetLabel
  1994.  *
  1995.  *  DESCRIPTION:    Change the volume label for a particular volume.
  1996.  *                    Most clients should not need to call this routine.
  1997.  *
  1998.  *                    Volume labels are up to 255 characters long,
  1999.  *                    using any normal character including spaces and lower case
  2000.  *                    characters in any character set and the following special characters:
  2001.  *                    $ % ' - _ @ ~ ` ! ( ) ^ # & + , ; = [ ]
  2002.  *
  2003.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  2004.  *                volRefNum                -- Volume reference number passed to FSVolumeMount
  2005.  *                labelP                    -- Label to apply to the specified volume (NUL-terminated)
  2006.  *
  2007.  *  RETURNS:    errNone                    -- no error
  2008.  *                expErrNotOpen            -- FS driver library has not been opened
  2009.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  2010.  *
  2011.  *************************************************************/
  2012. Err FSVolumeSetLabel(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char * /*labelP*/)
  2013. {
  2014.     ErrFatalDisplay("nope");
  2015.     return 0;
  2016. /*    MacSerialFSGlobalsPtr gP;
  2017.     
  2018.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  2019.     if (!gP)
  2020.         return expErrNotOpen;
  2021.         
  2022.     return expErrUnsupportedOperation;
  2023. */
  2024. }
  2025.  
  2026.  
  2027. /************************************************************
  2028.  *
  2029.  *  FUNCTION:    FSVolumeSize
  2030.  *
  2031.  *  DESCRIPTION:    Determine the total amount of space on a volume,
  2032.  *                    and the amount that is currently used. (in bytes)
  2033.  *
  2034.  *  PARAMETERS:    fsLibRefNum                -- FS library reference number
  2035.  *                volRefNum                -- Volume reference number passed to FSVolumeMount
  2036.  *                volumeUsedP                -- Receives the amount of used space on the volume
  2037.  *                volumeTotalP            -- Receives the total amount of space on the volume
  2038.  *
  2039.  *  RETURNS:    errNone                    -- no error
  2040.  *                expErrNotOpen            -- FS driver library has not been opened
  2041.  *                vfsErrVolumeBadRef        -- the volume has not been mounted with FSVolumeMount
  2042.  *                Sets volumeUsedP and volumeTotalP to the amount of used and total
  2043.  *                space on the volume.
  2044.  *
  2045.  *************************************************************/
  2046. Err FSVolumeSize(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, UInt32 */*volumeUsedP*/, UInt32 */*volumeTotalP*/)
  2047. {
  2048.     ErrFatalDisplay("nope");
  2049.     return 0;
  2050. /*
  2051.     MacSerialFSGlobalsPtr gP;
  2052.     Err error = errNone;
  2053.     Int16        vol;
  2054.     
  2055.     gP = SysLibTblEntry(fsLibRefNum)->globalsP;
  2056.     if (!gP)
  2057.         return expErrNotOpen;
  2058.         
  2059.     vol = FindVolumeByRefNum(gP, volRefNum);
  2060.     
  2061.     if(vol == -1) 
  2062.         return vfsErrVolumeBadRef;
  2063.         
  2064.     if(gP->volume[vol].volumeRef == vfsInvalidVolRef) 
  2065.         return vfsErrVolumeBadRef;
  2066.     
  2067.     if(gP->volume[vol].volumeRef != volRefNum) 
  2068.         return vfsErrVolumeBadRef;
  2069.     
  2070.     if(volumeUsedP) *volumeUsedP = gP->volume[vol].header.size;
  2071.     if(volumeTotalP) *volumeTotalP = gP->volume[vol].volumeSize;
  2072.     
  2073.     return error;
  2074. */
  2075. }
  2076.  
  2077.  
  2078. /********************************************************************
  2079.  * Private routines:
  2080.  ********************************************************************/
  2081.  
  2082. /************************************************************
  2083.  *
  2084.  *  FUNCTION:    PrvShouldWeInstall
  2085.  *
  2086.  *  DESCRIPTION:    Called by the PrvFSInstall function to see
  2087.  *                    if we should install.  The FS Library should not
  2088.  *                    install it's dispatch table if this function fails.
  2089.  *
  2090.  *  PARAMETERS:    None
  2091.  *
  2092.  *  CALLED BY:    PrvFSInstall function to see if we should install
  2093.  *
  2094.  *  RETURNS:    errNone                -- no error
  2095.  *                anything else        -- Library will not be able to successfully run
  2096.  *
  2097.  *************************************************************/ 
  2098. Err PrvShouldWeInstall(void)
  2099. {
  2100.     // Verify that the Library will be able to successfully run.
  2101.     
  2102.     return errNone;
  2103. }
  2104.  
  2105.  
  2106. /************************************************************
  2107.  *
  2108.  *  FUNCTION:    PrvCopy
  2109.  *
  2110.  *  DESCRIPTION:    Copy data to a ptr that might be in the dynamic or storage heaps.
  2111.  *                    
  2112.  *
  2113.  *  PARAMETERS:    bufBaseP                -- ptr to destination chunk
  2114.  *                offset                    -- Offset within chunk to write data
  2115.  *                dataStoreBased            -- true if the destination is in the storage heap
  2116.  *                                            false if the destination is in the dynamic heap
  2117.  *                srcP                    -- Ptr to source data
  2118.  *                numBytes                -- number of bytes of source data to copy
  2119.  *
  2120.  *  RETURNS:    errNone if no error
  2121.  *
  2122.  *************************************************************/
  2123. Err PrvCopy(void* bufBaseP, UInt32 offset, Boolean dataStoreBased, void *srcP, UInt32 numBytes)
  2124. {
  2125.     Err err = errNone;
  2126.     
  2127.     if(dataStoreBased)
  2128.     {
  2129.         err = DmWrite(bufBaseP, offset, srcP, numBytes);
  2130.     }
  2131.     else
  2132.     {
  2133.         err = MemMove(((UInt8*)bufBaseP)+offset, srcP, numBytes);
  2134.     }
  2135.     
  2136.     return err;
  2137. }
  2138.  
  2139.  
  2140. Int16    FindVolumeByRefNum(MacSerialFSGlobalsPtr gP, UInt16    volRefNum)
  2141. {
  2142.     Int16 i=0;
  2143.     while(i<MaxMountedVolumes)
  2144.     {
  2145.         if(gP->volume[i].volumeRef != vfsInvalidVolRef && 
  2146.             gP->volume[i].volumeRef == volRefNum) return i;
  2147.         i++;
  2148.     }
  2149.     
  2150.     return -1;
  2151. }
  2152.  
  2153. Int16    FindVolumeByFileRef(MacSerialFSGlobalsPtr gP, FileRef    ref)
  2154. {
  2155.     Int16 i=0;
  2156.     while(i<MaxMountedVolumes)
  2157.     {
  2158.         if(gP->volume[i].volumeRef != vfsInvalidVolRef && 
  2159.             (gP->volume[i].openRef == ref || gP->volume[i].dirRef == ref)) 
  2160.                 return i;
  2161.         i++;
  2162.     }
  2163.     
  2164.     return -1;
  2165. }
  2166.  
  2167. Int16    FindVolumeBySlotRefNum(MacSerialFSGlobalsPtr gP, UInt16    slotRefNum)
  2168. {
  2169.     Int16 i=0;
  2170.     while(i<MaxMountedVolumes)
  2171.     {
  2172.         if(gP->volume[i].volumeRef != vfsInvalidVolRef && 
  2173.             gP->volume[i].slotRefNum == slotRefNum) return i;
  2174.         i++;
  2175.     }
  2176.     
  2177.     return -1;
  2178. }
  2179.  
  2180. Int16    FindNewVolume(MacSerialFSGlobalsPtr gP)
  2181. {
  2182.     Int16 i=0;
  2183.     while(i<MaxMountedVolumes)
  2184.     {
  2185.         if(gP->volume[i].volumeRef == vfsInvalidVolRef) return i;
  2186.         i++;
  2187.     }
  2188.     
  2189.     return -1;
  2190. }
  2191.  
  2192.  
  2193.  
  2194. short SerialRead(short numBytes, char *bufP)
  2195. {
  2196.     UInt32 longRef;
  2197.     UInt16 refNum;
  2198.     Err    err;
  2199.     
  2200.     FtrGet(kMacSerialFSLibCreator, 1, &longRef);
  2201.     refNum = longRef;
  2202.     
  2203. //    SrmReceive(refNum, bufP, numBytes, sysTicksPerSecond * 10, &err);
  2204.     SrmReceive(refNum, bufP, numBytes, -1, &err);
  2205.     
  2206.     return err;
  2207. }
  2208.  
  2209. short SerialWrite(short numBytes, char *bufP)
  2210. {
  2211.     UInt32 longRef;
  2212.     UInt16 refNum;
  2213.     Err err;
  2214.     
  2215.     FtrGet(kMacSerialFSLibCreator, 1, &longRef);
  2216.     refNum = longRef;
  2217.     
  2218. //    SrmSend(refNum, bufP, numBytes, &err);
  2219.     SrmSend(refNum, bufP, numBytes, &err);
  2220.     
  2221.     return err;
  2222. }
  2223.  
  2224.  
  2225.  
  2226.