home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- * Copyright (c) 2000 Palm Computing, Inc. or its subsidiaries.
- * All rights reserved.
- *
- * File: MacSerialFS.c
- *
- * Description: Sample file system library implementation.
- *
- * History:
- * 03/21/00 Created by Jesse Donaldson, from the sample FSLib code
- *
- *****************************************************************************/
-
- /********************************************************************
- * Filename and Label conventions:
- *
- * All path names are absolute
- *
- * All filesystems must support filenames and labels that are up to 255 characters long,
- * using any normal character including spaces and lower case characters in any
- * character set and the following special characters:
- * $ % ' - _ @ ~ ` ! ( ) ^ # & + , ; = [ ]
- ********************************************************************
- * When creating the 8.3 name or label from a long filename or label:
- * a) Create the name from the first 1-6 valid, non-space characters, before the last period.
- * The only valid characters are:
- * A-Z 0-9 $ % ' - _ @ ~ ` ! ( ) ^ # &
- * b) the extension is the first three valid characters after the last period '.'
- * c) the end of the 6 byte name is appended with ~1, or the next unique number.
- *
- * A label is created from the first 11 valid non-space characters.
- ********************************************************************/
-
- #define NON_PORTABLE
-
- // Include Palm headers
- #include <PalmTypes.h>
- #include <ErrorMgr.h>
- #include <FeatureMgr.h>
- #include <Preferences.h>
- #include <SystemMgr.h>
- #include <SerialMgr.h>
- #include <SoundMgr.h>
- #include <SysUtils.h>
- #include <StringMgr.h>
-
- #include <NotifyMgr.h>
- #include <VFSMgr.h>
-
- #include <Globals.h>
-
- // Our library public definitions
- #include "VFSMgr.h"
- #include "FSLib.h"
- #include "SlotDrvrLib.h"
-
- #include "GenericSerial.h"
-
- /********************************************************************
- * Private structures:
- ********************************************************************/
-
- #define kMaxFilenameSize 60
- //#define kMaxFileDataSize (100L*1024L) // 100k maximum volume size
- #define kMacSerialFSCookie 'mcfs'
- //#define kDirectoryFileRefCookie 'root'
- #define kMacSerialFSLibCreator 'mcfs'
-
- typedef struct MacSerialFSHeaderTag{
- UInt32 cookie; // If the cookiematches, the volume is formatted.
- Boolean created; // Is the file created?
- UInt8 reserved[3];
- UInt32 size; // file size
- Char filename[kMaxFilenameSize]; // filename...
- } MacSerialFSHeaderType;
-
- typedef MacSerialFSHeaderType *MacSerialFSHeaderPtr;
-
- // can mount up to 5 volumes at once
- #define MaxMountedVolumes 5
-
- /********************************************************************
- * LIBRARY GLOBALS:
- *
- * IMPORTANT:
- * ==========
- * Libraries are *not* allowed to have global or static variables. Instead,
- * they allocate a memory chunk to hold their persistent data, and save
- * a handle to it in the library's system library table entry. Example
- * functions below demonstrate how the library "globals" chunk is set up, saved,
- * and accessed.
- *
- ********************************************************************/
- typedef struct {
- UInt16 slotLibRefNum; // slot library refNum for mounted volume, if any
- UInt16 slotRefNum; // slot number of slot w/ mounted volume, if any
-
- UInt16 volumeRef; // vfsInvalidVolRef, or volRefNum if the volume is mounted
- UInt16 openRef; // vfsInvalidFileRef or fileRef, if the file is open
- UInt16 dirRef; // vfsInvalidFileRef or fileRef, if the root directory is open
-
- UInt32 fileMark;
- UInt32 volumeSize; // size of media in bytes
-
- MacSerialFSHeaderType header; // copy of volume header for mounted volume
-
- // Boolean rootDirOpen;
-
- } SimpleVolumeInfoType;
-
-
- typedef struct {
- Int32 openCount; // library open count
-
- SimpleVolumeInfoType volume[MaxMountedVolumes];
-
- UInt8 rwBuffer[slotSectorSize]; // buffer we use to read & write blocks from the slot driver
-
- } MacSerialFSGlobalsType;
-
- typedef MacSerialFSGlobalsType *MacSerialFSGlobalsPtr;
-
-
- /********************************************************************
- * Private routines:
- ********************************************************************/
-
- Err PrvShouldWeInstall(void);
-
- Err PrvCopy(void* bufBaseP, UInt32 offset, Boolean dataStoreBased, void *srcP, UInt32 numBytes);
-
- Int16 FindVolumeByRefNum(MacSerialFSGlobalsPtr gP, UInt16 volRefNum);
- Int16 FindVolumeByFileRef(MacSerialFSGlobalsPtr gP, FileRef ref);
- Int16 FindVolumeBySlotRefNum(MacSerialFSGlobalsPtr gP, UInt16 slotRefNum);
- Int16 FindNewVolume(MacSerialFSGlobalsPtr gP);
-
-
- /********************************************************************
- * Standard library open, close, sleep and wake APIs:
- ********************************************************************/
-
- Err ResetNotifyProc(SysNotifyParamType *notifyParamsP);
- Err ResetNotifyProc(SysNotifyParamType *notifyParamsP)
- {
- VFSAnyMountParamType mount;
- Err err;
-
- mount.mountClass = kMacSerialFSLibCreator;
-
- err = VFSVolumeMount(vfsMountFlagsUseThisFileSystem, (UInt16)(notifyParamsP->userDataP), &mount);
-
- ErrFatalDisplayIf(err, "can't mount");
- return errNone;
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSLibOpen
- *
- *
- * DESCRIPTION: Opens the FS library, creates and initializes the globals.
- * This function must be called before any other FS Library functions,
- * with the exception of FSLibAPIVersion.
- *
- * If FSLibOpen fails, do not call any other FS library API functions.
- * If FSLibOpen succeeds, call FSLibClose when you are done using
- * the library to enable it to release critical system resources.
- * Clients (usually VFS Lib) should call FSLibOpen() before using the
- * filesystem driver.
- *
- * LIBRARY DEVELOPER NOTES:
- * The library's "open" and "close" functions should *not* take an excessive
- * amount of time to complete. If the processing time for either of these
- * is lengthy, consider creating additional library API function(s) to handle
- * the time-consuming chores.
- *
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number returned by SysLibLoad()
- * or SysLibFind().
- *
- * CALLED BY: anyone who wants to use this library
- *
- * RETURNS: errNone -- no error
- * memErrNotEnoughSpace -- not enough memory to initialize
- *
- *************************************************************/
- Err FSLibOpen(UInt16 fsLibRefNum)
- {
- Err error = errNone;
- MacSerialFSGlobalsPtr gP;
- UInt16 i;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
-
- if (!gP) {
- gP = MemPtrNew(sizeof(MacSerialFSGlobalsType));
- if (!gP) {
- error = sysErrNoFreeRAM;
- goto Done;
- }
-
- // MemPtrNew sets the 'owner' of a chunk to whatever the current application is.
- // When that app exits, all chunks owned by it are disposed of.
- // Call MemPtrSetOwner() to set the owner to the unused/system one so that the
- // chunk will not be disposed of when the current app exits.
- MemPtrSetOwner(gP, 0);
- SysLibTblEntry(fsLibRefNum)->globalsP = gP;
-
- gP->openCount = 0;
-
- // init volumes:
- i=0;
- while(i<MaxMountedVolumes)
- {
- gP->volume[i].volumeRef = vfsInvalidVolRef; // no volume mounted,
- gP->volume[i].openRef = vfsInvalidFileRef; // no file open,
- gP->volume[i].dirRef = vfsInvalidFileRef; // no file open,
- gP->volume[i].slotLibRefNum = 0; // and no slotLibRefNum,
- gP->volume[i].slotRefNum = 0; // and no slotLibRefNum,
- gP->volume[i].fileMark = 0;
- // gP->volume[i].rootDirOpen = false;
-
- i++;
- }
- }
- gP->openCount++; // increment open count
-
- // Initialize serial:
- {
- UInt16 refNum;
- MemPtr rcvBuf;
-
- error = SrmOpen(sysFileCUart328EZ, 57600, &refNum);
- ErrFatalDisplayIf(error, "can't open serial");
-
- rcvBuf = MemPtrNew(2048);
- error = SrmSetReceiveBuffer(refNum, rcvBuf, 2048);
- ErrFatalDisplayIf(error, "can't set buf");
-
- FtrSet(kMacSerialFSLibCreator, 1, (UInt32)refNum);
- }
-
-
- // register mounting routine:
- error = SysNotifyRegister(0, sysNotifyNoDatabaseID, sysNotifyResetFinishedEvent,
- ResetNotifyProc, sysNotifyNormalPriority, (void*)fsLibRefNum);
- ErrFatalDisplayIf(error, "can't register");
-
- GDbgWasEntered = true;
-
- Done:
- return error;
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSLibClose
- *
- * DESCRIPTION: Closes the FS libary, frees client context and globals.
- * Clients (usually VFS Lib) should call FSLibClose() after using the
- * filesystem driver.
- *
- * ***IMPORTANT***
- * May be called only if FSLibOpen succeeded.
- *
- * If other applications still have the library open, decrements
- * the reference count and returns expErrStillOpen.
- *
- *
- * LIBRARY DEVELOPER NOTES:
- * The library's "open" and "close" functions should *not* take an excessive
- * amount of time to complete. If the processing time for either of these
- * is lengthy, consider creating additional library API function(s) to handle
- * the time-consuming chores.
- *
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number returned by SysLibLoad()
- * or SysLibFind().
- * CALLED BY: Whoever wants to close the FS library (usually ExpansionLib or file system drivers)
- * should call this after using the driver
- *
- * RETURNS: errNone -- no error
- * expErrStillOpen -- library is still open by others (no error)
- * expErrNotOpen -- library is not open
- *
- *************************************************************/
- Err FSLibClose(UInt16 fsLibRefNum)
- {
- Err error = errNone;
- MacSerialFSGlobalsPtr gP;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP || !gP->openCount)
- return expErrNotOpen;
-
- if (--gP->openCount)
- return expErrStillOpen;
-
- // If open count is zero, remove globals
- if (gP->openCount == 0) {
- MemPtrFree(gP);
- }
-
- return error;
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSLibSleep
- *
- * DESCRIPTION: Handles system sleep notification.
- *
- * ***IMPORTANT***
- * This notification function is called from a system interrupt.
- * It is only allowed to use system services which are interrupt-
- * safe. Presently, this is limited to EvtEnqueueKey, SysDisableInts,
- * SysRestoreStatus. Because it is called from an interrupt,
- * it must *not* take a long time to complete to preserve system
- * integrity. The intention is to allow system-level libraries
- * to disable hardware components to conserve power while the system
- * is asleep.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- *
- * CALLED BY: System when going to sleep.
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- *
- *************************************************************/
- Err FSLibSleep(UInt16 /*fsLibRefNum*/)
- {
- return errNone;
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSLibWake
- *
- * DESCRIPTION: Handles system wake notification
- *
- * ***IMPORTANT***
- * This notification function is called from a system interrupt.
- * It is only allowed to use system services which are interrupt-
- * safe. Presently, this is limited to EvtEnqueueKey, SysDisableInts,
- * SysRestoreStatus. Because it is called from an interrupt,
- * it must *not* take a long time to complete to preserve system
- * integrity. The intention is to allow system-level libraries
- * to enable hardware components which were disabled when the system
- * went to sleep.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- *
- * CALLED BY: System when waking up.
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- *
- *************************************************************/
- Err FSLibWake(UInt16 /*fsLibRefNum*/)
- {
- return errNone;
- }
-
-
- /********************************************************************
- * Custom library APIs:
- ********************************************************************/
-
- /************************************************************
- *
- * FUNCTION: FSLibAPIVersion
- *
- * DESCRIPTION: Return version of the library API
- * library need not be open to call
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- *
- * RETURNS: 32-bit API version
- *
- *************************************************************/
- UInt32 FSLibAPIVersion(UInt16 fsLibRefNum)
- {
- #pragma unused(fsLibRefNum)
- return fsLibAPIVersion;
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSCustomControl
- *
- * DESCRIPTION: Handles a custom call for a particular volume.
- *
- * LIBRARY DEVELOPER NOTES:
- * The driver identifies the call and its API by a registered creator code and a selector.
- * This allows filesystem developers to extend the API by defining selectors for their
- * creator code. It also allows filesystem developers to suppport selectors (and custom calls)
- * defined by other filesystem developers.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * apiCreator -- registered creator code
- * apiSelector -- custom operation to perform
- * valueP -- buffer containing data specific to the operation
- * valueLenP -- size of the valueP buffer on entry,
- * size of data written to valueP on exit
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * expErrUnsupportedOperation -- for all unsupported or undefined opcodes
- * and/or creators.
- * sysErrParamErr -- valueP buffer is too small
- * Sets the size of the returned valueP buffer in valueLenP
- *
- *************************************************************/
- Err FSCustomControl(UInt16 fsLibRefNum, UInt32 /*apiCreator*/, UInt16 /*apiSelector*/,
- void * /*valueP*/, UInt16 * /*valueLenP*/)
- {
- MacSerialFSGlobalsPtr gP;
- Err error = expErrUnsupportedOperation;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- return error;
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFilesystemType
- *
- * DESCRIPTION: Return the type of filesystem that this library implements.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * filesystemTypeP -- On return set to the type of filesystem
- * Common types are defined in VFSMgr.h
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * Fills in filesystemTypeP with the type of filesystem that this library implements.
- *
- *************************************************************/
- Err FSFilesystemType(UInt16 /*fsLibRefNum*/, UInt32 *filesystemTypeP)
- {
- if (filesystemTypeP != NULL)
- *filesystemTypeP = kMacSerialFSCookie;
- return errNone;
- }
-
-
- /********************************************************************
- * File Stream APIs:
- ********************************************************************/
-
- /************************************************************
- *
- * FUNCTION: FSFileCreate
- *
- * DESCRIPTION: Create a file. Does not open the file.
- * All parts of the path, except the last part must already exist.
- *
- * LIBRARY DEVELOPER NOTES:
- * It is the responsibility of the filesystem library to ensure that all filenames
- * are 'mangled' into a format that is compatible with the native format of
- * the filesystem. (i.e. 8.3 for a FAT filesystem without long filename support)
- * See comment above on "Filename conventions"
- * Note that this function does not open the file.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * pathNameP -- Full path of the file to be created
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileAlreadyExists -- A file of this name exists already in this location
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- * vfsErrVolumeFull -- not enough space left on volume
- * vfsErrBadName -- pathNameP is invalid
- *
- *************************************************************/
- Err FSFileCreate(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char *pathNameP)
- {
-
- RemoteFileCreate((char*)pathNameP);
-
- return errNone;
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileOpen
- *
- * DESCRIPTION: Open a file or directory.
- * Note the the FileRef obtained for a directory can not be used
- * for all functions. For example, it is not permitted (or logical)
- * to read directly from an opened directory.
- * openMode is ignored when opening a directory.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * pathNameP -- Full path of the file to be opened
- * This must all be valid -- non-null, non-empty
- * openMode -- fsMode to use when opening the file. Ignored for directories
- * fileRefP -- Pointer to a reference to the opened file
- * Filled in on return.
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFilePermissionDenied -- The file or directory can not be opened with the requested
- * openMode or has already been opened with vfsModeExclusive
- * vfsErrFileNotFound -- the file could not be found
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- * expErrCardReadOnly -- card is read only, but openMode includes vfsModeWrite
- * vfsErrBadName -- pathNameP is invalid
- * Fills in the passed in fileRefP with the file reference number
- *
- *************************************************************/
- Err FSFileOpen(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char *pathNameP,
- UInt16 /*openMode*/, FileRef *fileRefP)
- {
- return RemoteFileOpen((char*)pathNameP, 0, (long*)fileRefP);
- /*
- MacSerialFSGlobalsPtr gP;
- UInt16 len;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByRefNum(gP, volRefNum);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(pathNameP[0] != '/')
- return vfsErrBadName;
-
- len = StrLen(pathNameP);
- if(len < 1 || len > kMaxFilenameSize)
- return vfsErrBadName;
-
- // If it's the root directory, handle it here:
- if(StrCompare(pathNameP, "/") == 0)
- {
- if(gP->volume[vol].dirRef != vfsInvalidFileRef) return vfsErrFileStillOpen;
-
- // gP->volume[vol].rootDirOpen = true;
-
- gP->volume[vol].dirRef = SysRandom(0);
- *fileRefP = gP->volume[vol].dirRef;
-
- return errNone;
- }
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef != 0)
- return vfsErrFileStillOpen;
-
- // Else, open the file!!
- // Correct filename requested?
- if(StrCompare(&pathNameP[1], gP->volume[vol].header.filename) != 0)
- return vfsErrFileNotFound;
-
- gP->volume[vol].openRef = SysRandom(0);
- *fileRefP = gP->volume[vol].openRef;
- gP->volume[vol].fileMark = 0;
-
- return errNone;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileClose
- *
- * DESCRIPTION: Close a file or directory which has been opened with FSFileOpen
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- *
- *************************************************************/
- Err FSFileClose(UInt16 /*fsLibRefNum*/, FileRef fileRef)
- {
- return RemoteFileClose(fileRef);
- /* MacSerialFSGlobalsPtr gP;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].dirRef != vfsInvalidFileRef)
- {
- // gP->volume[vol].rootDirOpen = false;
- gP->volume[vol].dirRef = vfsInvalidFileRef;
- return errNone;
- }
-
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef == vfsInvalidFileRef)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return vfsErrFileBadRef;
-
- gP->volume[vol].openRef = 0;
-
- return errNone;*/
-
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileRead
- *
- * DESCRIPTION: Read data from an open file into a buffer or a data storage heap-based
- * chunk (record or resource).
- * This function is not permitted for FileRefs to open directories.
- *
- * LIBRARY DEVELOPER NOTES:
- * This function must check the boolean dataStoreBased to determine if bufBaseP is a pointer
- * to a storage heap based chunk. If it is, this function must use DmWrite to write to the
- * buffer.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * numBytes -- The number of bytes to read
- * bufBaseP -- ptr to beginning of destination buffer for reading data (must be
- * beginning of record or resource for data storage heap based destination)
- * offset -- offset from base ptr to the destination area
- * dataStoreBased -- if true, the bufBaseP points to a buffer in the storage heap
- * if false the bufBaseP buffer is in the dynamic heap
- * numBytesReadP -- Set to the number of bytes actually read on return if non-NULL
- * This does not need to be initialized on input.
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * vfsErrIsADirectory -- the fileref points to a directory
- * vfsErrFileEOF -- file pointer is at end of file
- * vfsErrFilePermissionDenied -- read permission is not enabled for this file
- * Returns the number of bytes actually read in numBytesReadP if it is not NULL
- *
- *************************************************************/
- Err FSFileRead(UInt16 /*fsLibRefNum*/, FileRef fileRef, UInt32 numBytes, void *bufBaseP,
- UInt32 offset, Boolean dataStoreBased, UInt32 *numBytesReadP)
- {
- // ErrFatalDisplayIf(dataStoreBased, "data store reading unsupported");
- return RemoteFileRead(fileRef, numBytes, (long*)numBytesReadP, bufBaseP, dataStoreBased, offset);
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- UInt32 blockNum;
- UInt16 blockOffset, blockBytes;
- UInt32 numSectors;
- Int16 vol;
-
- if(numBytesReadP) *numBytesReadP = 0;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].fileMark + numBytes > gP->volume[vol].header.size)
- return vfsErrFileEOF;
-
- // calculate block to read:
- blockNum = 1 + (gP->volume[vol].fileMark / slotSectorSize);
-
- // calculate starting offset
- blockOffset = gP->volume[vol].fileMark % slotSectorSize;
-
- while(numBytes > 0)
- {
- // calc # bytes to read within block
- blockBytes = slotSectorSize - blockOffset;
- if(blockBytes > numBytes) blockBytes = numBytes;
-
-
- // read the block:
- numSectors = 1;
- err = SlotCardSectorRead(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, blockNum, gP->rwBuffer, &numSectors);
- if(err) goto Exit;
-
- // copy data into user buffer
- err = PrvCopy(bufBaseP, offset, dataStoreBased, (gP->rwBuffer + blockOffset), blockBytes);
- if(err) goto Exit;
-
- // update loop variables:
- blockOffset = 0;
- blockNum++;
- offset += blockBytes;
- numBytes -= blockBytes;
- gP->volume[vol].fileMark += blockBytes;
- if(numBytesReadP) *numBytesReadP += blockBytes;
- }
-
-
-
- Exit:
-
- return err;*/
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileWrite
- *
- * DESCRIPTION: Write data to an open file
- * This function is not permitted for FileRefs to open directories.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * numBytes -- The number of bytes to write
- * dataP -- ptr to data to write
- * numBytesWrittenP -- Set to the number of bytes actually written on return if non-NULL
- * This does not need to be initialized on input.
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * vfsErrIsADirectory -- the fileref points to a directory
- * vfsErrFilePermissionDenied -- write permission is not enabled for this file
- * Returns the number of bytes actually written in numBytesWrittenP if it is not NULL
- *
- *************************************************************/
- Err FSFileWrite(UInt16 /*fsLibRefNum*/, FileRef fileRef,
- UInt32 numBytes, const void *dataP, UInt32 *numBytesWrittenP)
- {
- return RemoteFileWrite(fileRef, numBytes, (long*)numBytesWrittenP, (char*)dataP);
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- UInt32 blockNum;
- UInt16 blockOffset, blockBytes;
- UInt32 numSectors;
- Int16 vol;
-
- if(numBytesWrittenP) *numBytesWrittenP = 0;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].fileMark + numBytes > gP->volume[vol].header.size) {
- // If the file is too small, grow it
- err = FSFileResize(fsLibRefNum, fileRef, gP->volume[vol].fileMark + numBytes);
- if (err) return err;
- if(gP->volume[vol].fileMark + numBytes > gP->volume[vol].header.size)
- return vfsErrFileEOF;
- }
-
- // calculate block to read:
- blockNum = 1 + (gP->volume[vol].fileMark / slotSectorSize);
-
- // calculate starting offset
- blockOffset = gP->volume[vol].fileMark % slotSectorSize;
-
- while(numBytes > 0)
- {
- // calc # bytes to read within block
- blockBytes = slotSectorSize - blockOffset;
- if(blockBytes > numBytes) blockBytes = numBytes;
-
-
- // read the block:
- numSectors = 1;
- err = SlotCardSectorRead(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, blockNum, gP->rwBuffer, &numSectors);
- if(err) goto Exit;
-
- // copy data into temp buffer
- err = MemMove((gP->rwBuffer + blockOffset), dataP, blockBytes);
- if(err) goto Exit;
-
- // write back onto media:
- numSectors = 1;
- err = SlotCardSectorWrite(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, blockNum, gP->rwBuffer, &numSectors);
- if(err) goto Exit;
-
- // update loop variables:
- blockNum++;
- blockOffset = 0;
- numBytes -= blockBytes;
- gP->volume[vol].fileMark += blockBytes;
- if(numBytesWrittenP) *numBytesWrittenP += blockBytes;
- (UInt8*)dataP += blockBytes;
- }
-
-
-
- Exit:
-
- return err;*/
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileDelete
- *
- * DESCRIPTION: Delete a closed file or directory.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * pathNameP -- Full path of the file or directory to be deleted
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileStillOpen -- File is still open
- * vfsErrFileNotFound -- the file could not be found
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- * vfsErrDirNotEmpty -- (Only when the FileRef points to a directory)
- * can't delete a non-empty directory
- * vfsErrFilePermissionDenied -- write permission is not enabled for this file
- * vfsErrBadName -- pathNameP is invalid
- *
- *************************************************************/
- Err FSFileDelete(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char *pathNameP)
- {
- return RemoteFileDelete((char*)pathNameP);
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- UInt16 len;
- UInt32 numSectors;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
-
- vol = FindVolumeByRefNum(gP, volRefNum);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef != volRefNum)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef != 0)
- return vfsErrFileStillOpen;
-
- if(pathNameP[0] != '/')
- return vfsErrBadName;
-
- len = StrLen(pathNameP);
- if(len < 1 || len > kMaxFilenameSize)
- return vfsErrBadName;
-
- if(StrCompare(&pathNameP[1], gP->volume[vol].header.filename) != 0)
- return vfsErrFileNotFound;
-
- // Else, everythings okay - delete the file!!
- gP->volume[vol].header.created = false;
-
- // Write changed header onto media:
- *(MacSerialFSHeaderPtr)(gP->rwBuffer) = gP->volume[vol].header;
- numSectors = 1;
- err = SlotCardSectorWrite(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, 0, gP->rwBuffer, &numSectors);
- if(err) return err;
-
- return errNone;*/
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileRename
- *
- * DESCRIPTION: Rename a closed file or directory.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * pathNameP -- Full path of the file or directory to be renamed
- * newNameP -- new file name only (not a full path)
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileStillOpen -- File is still open
- * vfsErrFileNotFound -- the file could not be found
- * vfsErrFileAlreadyExists -- A file of this name exists already in this location
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- * vfsErrFilePermissionDenied -- write permission is not enabled for this file
- * vfsErrBadName -- pathNameP or newNameP is invalid
- *
- *************************************************************/
- Err FSFileRename(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char */*pathNameP*/, const Char * /*newNameP*/)
- {
- ErrFatalDisplay("rename unsupported");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- UInt16 len;
- UInt32 numSectors;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByRefNum(gP, volRefNum);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef != volRefNum)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef != 0)
- return vfsErrFileStillOpen;
-
- if(pathNameP[0] != '/')
- return vfsErrBadName;
-
- len = StrLen(pathNameP);
- if(len < 1 || len > kMaxFilenameSize)
- return vfsErrBadName;
-
- if(StrCompare(&pathNameP[1], gP->volume[vol].header.filename) != 0)
- return vfsErrFileNotFound;
-
- // Else, everythings okay - rename the file!!
- StrCopy(gP->volume[vol].header.filename, &pathNameP[1]);
-
- // Write changed header onto media:
- *(MacSerialFSHeaderPtr)(gP->rwBuffer) = gP->volume[vol].header;
- numSectors = 1;
- err = SlotCardSectorWrite(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, 0, gP->rwBuffer, &numSectors);
- if(err) return err;
-
- return errNone;*/
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileSeek
- *
- * DESCRIPTION: Set position within an open file. If the resulting
- * position would be beyond the end of the file, sets the
- * position to the end of file.
- * This function is not permitted for FileRefs to open directories.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * origin -- origin to use when calculating new position from the offset
- * offset -- offset from the origin to set the new position in the file
- *
- * RETURNS: errNone -- no error
- * vfsErrFileEOF -- file pointer is at end of file (not an error)
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * vfsErrIsADirectory -- the fileref points to a directory
- * sysErrParamErr -- origin is invalid
- *
- *************************************************************/
- Err FSFileSeek(UInt16 /*fsLibRefNum*/, FileRef fileRef, FileOrigin origin, Int32 offset)
- {
- return RemoteFileSeek(fileRef, origin, offset);
-
- /* MacSerialFSGlobalsPtr gP;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef == 0)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return sysErrParamErr;
-
- switch(origin)
- {
- case vfsOriginBeginning:
- gP->volume[vol].fileMark = offset;
- break;
- case vfsOriginCurrent:
- gP->volume[vol].fileMark += offset;
- break;
- case vfsOriginEnd:
- gP->volume[vol].fileMark = gP->volume[vol].header.size + offset;
- break;
- }
-
-
- return errNone;*/
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileEOF
- *
- * DESCRIPTION: Get end-of-file status of an open file.
- * This function is not permitted for FileRefs to open directories.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- *
- * RETURNS: errNone -- file pointer is NOT at end of file
- * vfsErrFileEOF -- file pointer is at end of file
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * vfsErrIsADirectory -- the fileref points to a directory
- *
- *************************************************************/
- Err FSFileEOF(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
- Err error = errNone;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef == 0)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return sysErrParamErr;
-
- if(gP->volume[vol].fileMark == gP->volume[vol].header.size) return vfsErrFileEOF;
-
- return errNone;*/
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileTell
- *
- * DESCRIPTION: Get current position of the file pointer within an open file.
- * This function is not permitted for FileRefs to open directories.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * filePosP -- Receives the current file position
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * vfsErrIsADirectory -- the fileref points to a directory
- * Sets filePosP with the current file position.
- *
- *************************************************************/
- Err FSFileTell(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/, UInt32 */*filePosP*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef == 0)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return sysErrParamErr;
-
- *filePosP = gP->volume[vol].fileMark;
-
- return errNone;*/
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileResize
- *
- * DESCRIPTION: Change size of an open file.
- * If the resizing of the file would make the current
- * file pointer point beyond EOF, the file pointer will
- * be set to point to EOF.
- * This function is not permitted for FileRefs to open directories.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * newSize -- The desired new size of the file.
- * This can be bigger or smaller then the current file size.
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * vfsErrIsADirectory -- the fileref points to a directory
- *
- *************************************************************/
- Err FSFileResize(UInt16 /*fsLibRefNum*/, FileRef fileRef, UInt32 newSize)
- {
- return RemoteFileResize(fileRef, newSize);
-
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- UInt32 numSectors;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef == 0)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return sysErrParamErr;
-
- if(newSize >= gP->volume[vol].volumeSize) return vfsErrVolumeFull;
-
- // change filesize:
- gP->volume[vol].header.size = newSize;
-
- // Write changed header onto media:
- *(MacSerialFSHeaderPtr)(gP->rwBuffer) = gP->volume[vol].header;
- numSectors = 1;
- err = SlotCardSectorWrite(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, 0, gP->rwBuffer, &numSectors);
- if(err) return err;
-
- return errNone;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileGetAttributes
- *
- * DESCRIPTION: Obtain the attributes of an open file or directory.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * attributesP -- File or directory attributes, filled in on return
- * These are defined in VFSMgr.h
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * Sets attributesP to the open file or directory attributes
- *
- *************************************************************/
- Err FSFileGetAttributes(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/, UInt32 */*attributesP*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
- Err error = errNone;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef == 0)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return sysErrParamErr;
-
- *attributesP = 0; // no special attributes
-
- return error;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileSetAttributes
- *
- * DESCRIPTION: Change the attributes of an open file or directory.
- * Cannot use this function to set the fsAttribDirectory or fsAttribVolumeLabel
- * attributes. Use FSDirCreate and FSVolumeLabelSet.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * attributes -- The file attributes to set to the file
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * sysErrParamErr -- attributes included fsAttribDirectory or fsAttribVolumeLabel
- *
- *************************************************************/
- Err FSFileSetAttributes(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/, UInt32 /*attributes*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
- Int16 vol;
-
- if (attributes & (vfsFileAttrDirectory | vfsFileAttrVolumeLabel))
- return sysErrParamErr;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- return expErrUnsupportedOperation;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileGetDate
- *
- * DESCRIPTION: Obtain the dates of an open file or directory.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * whichDate -- Specifies which date to return. These are defined in VFSMgr.h
- * dateP -- Receives the requested date
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * sysErrParamErr -- whichDate is not a defined constant
- * Sets dateP with the date specified with whichDate
- *
- *************************************************************/
- Err FSFileGetDate(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/,
- UInt16 /*whichDate*/, UInt32 */*dateP*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- return expErrUnsupportedOperation;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileSetDate
- *
- * DESCRIPTION: Change the dates of an open file or directory.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * whichDate -- Specifies which date to set. These are defined in VFSMgr.h
- * date -- Contains the date to set
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * sysErrParamErr -- whichDate is not a defined constant
- *
- *************************************************************/
- Err FSFileSetDate(UInt16 /*fsLibRefNum*/, FileRef /*fileRef*/,
- UInt16 /*whichDate*/, UInt32 /*date*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- return expErrUnsupportedOperation;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSFileSize
- *
- * DESCRIPTION: Obtain the size of an open file.
- * This function is not permitted for FileRefs to open directories.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * fileRef -- File reference number returned from FSFileOpen
- * fileSizeP -- Receives the size of the open file
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * vfsErrIsADirectory -- the fileref points to a directory
- * Sets fileSizeP to the size of the file.
- *
- *************************************************************/
- Err FSFileSize(UInt16 /*fsLibRefNum*/, FileRef fileRef, UInt32 *fileSizeP)
- {
- return RemoteFileSize(fileRef, (long*)fileSizeP);
-
-
- /* MacSerialFSGlobalsPtr gP;
- Err error = errNone;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, fileRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].header.created == false)
- return vfsErrFileNotFound;
-
- if(gP->volume[vol].openRef == 0)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].openRef != fileRef)
- return sysErrParamErr;
-
-
- *fileSizeP = gP->volume[vol].header.size;
-
- return error;
- */
- }
-
-
- /********************************************************************
- * Directory APIs:
- ********************************************************************/
-
- /************************************************************
- *
- * FUNCTION: FSDirCreate
- *
- * DESCRIPTION: Create a new directory
- * All parts of the path, except the last part must already exist.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * dirNameP -- Full path of the directory to be created
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- * vfsErrFileAlreadyExists -- a directory or file with this name already exists at this location
- * vfsErrBadName -- the full path before the new directory does not exist
- *
- *************************************************************/
- Err FSDirCreate(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char * dirNameP)
- {
- return RemoteDirCreate((char*)dirNameP);
-
- /* MacSerialFSGlobalsPtr gP;
- Err error = errNone;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- return expErrUnsupportedOperation;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSDirEntryEnumerate
- *
- * DESCRIPTION: Enumerate the entries in the given directory.
- * Pass a dirEntryIteratorP of expIteratorStart to get the first entry.
- * dirEntryIteratorP will be updated to the next item.
- * When returning the last directory entry, the dirEntryIteratorP will be
- * set to expIteratorStop. If there are no directory entries to enumerate,
- * FSDirEntryEnumerate will return expErrEnumerationEmpty when expIteratorStart is passed
- * for the dirEntryIteratorP.
- * The directory to be enumerated must first be opened in order
- * to obtain a FileRef.
- * This function is only permitted for FileRefs to open directories.
- *
- * FSDirEntryEnumerate should be called like this:
- * FileInfoType info;
- * UInt32 dirIterator = expIteratorStart;
- * while (dirIterator != expIteratorStop) {
- * if ((err = FSDirEntryEnumerate(fsLibRefNum, dirRef, &dirIterator, &info)) != errNone) {
- * // Do something with the directory entry info
- * } else {
- * // handle error... possibly by breaking out of the loop
- * }
- * }
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * dirRef -- Directory reference number returned from FSFileOpen
- * dirEntryIteratorP -- Reference to the last entry enumerated
- * Pass expIteratorStart to get the first entry
- * This is updated on return to reference the next entry
- * or set to expIteratorStop if infoP is the last directory entry.
- * infoP -- receives Info on the directory entry specified with dirEntryIteratorP
- *
- * RETURNS: errNone -- no error, infoP is valid
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrFileBadRef -- the fileref is invalid
- * vfsErrNotADirectory -- the fileref is valid, but does not point to a directory entry
- * sysErrParamErr -- the dirEntryIteratorP is not valid
- * expErrEnumerationEmpty -- there are no directory entries left to enumerate
- * Fills in infoP for the directory entry specified with dirEntryIteratorP
- * Updates dirEntryIteratorP to point to the next entry in the directory,
- * or sets it to expIteratorStop when returning the last directory entry.
- *
- *************************************************************/
- Err FSDirEntryEnumerate(UInt16 /*fsLibRefNum*/, FileRef dirRef, UInt32 *dirEntryIteratorP, FileInfoType *infoP)
- {
- long size;
- Err err;
-
- infoP->attributes = 0;
- err = RemoteDirIterate(dirRef, (long*)dirEntryIteratorP, infoP->nameP, &size, (long*)&infoP->attributes);
-
- return err;
-
- /* MacSerialFSGlobalsPtr gP;
- Err error = errNone;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByFileRef(gP, dirRef);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- // if(dirRef != kDirectoryFileRefCookie)
- // return vfsErrFileBadRef;
-
- if(gP->volume[vol].dirRef == vfsInvalidFileRef)
- return vfsErrFileBadRef;
-
- if(gP->volume[vol].header.created == false)
- return expErrEnumerationEmpty;
-
- if(*dirEntryIteratorP != expIteratorStart)
- return sysErrParamErr;
-
- // This is the last entry to be enumerated, so return expIteratorStop for the dirEntry
- *dirEntryIteratorP = expIteratorStop;
-
- // okay, we're searching the root dir, and looking for the first file, which DOES exist.
- // Since there can be only one, just fill in the info structure with info about it.
- StrNCopy(infoP->nameP, gP->volume[vol].header.filename, infoP->nameBufLen);
- infoP->attributes = 0;
-
- return errNone;
- */
- }
-
-
-
- /********************************************************************
- * Volume APIs:
- ********************************************************************/
-
- /************************************************************
- *
- * FUNCTION: FSVolumeFormat
- *
- * DESCRIPTION: Format the first volume on the specified slot
- * (The Slot Driver currently only supports one volume per slot)
- * A volume must not be mounted on the slot when calling this function.
- *
- * LIBRARY DEVELOPER NOTES:
- * As with all power-intensive operations, the filesystem
- * should check to make sure that enough power is available
- * to complete the format, and abort if not, returning
- * expErrNotEnoughPower.
- *
- * The vfsMountParamP should be switched off of
- * vfsMountParamP->mountClass and cast to the correct
- * MountParamType. For example if mountClass == 'libs'
- * then vfsMountParamP should be cast to VFSSlotMountParamType.
- *
- * Before formatting the media, FSVolumeFormat should call
- * SlotCardLowLevelFormat(). It should then call SlotCardMetrics()
- * to get information about the physical metrics of the card.
- * The actual format should be accomplished with SlotSectorWrite() calls.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * vfsMountParamP -- Mount parameters
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * expErrNotEnoughPower -- the required power is not available
- * vfsErrVolumeStillMounted -- There is already a volume mounted on this slot
- *
- *************************************************************/
- Err FSVolumeFormat(UInt16 /*fsLibRefNum*/, VFSAnyMountParamPtr /*vfsMountParamP*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- VFSSlotMountParamType *slotMountP = (VFSSlotMountParamType*)vfsMountParamP;
- UInt16 slotLibRefNum, slotRefNum;
- UInt32 numSectors;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- if(vfsMountParamP->mountClass != vfsMountClass_SlotDriver)
- return expErrUnsupportedOperation;
-
- // Make sure that the volume is unmounted before formatting it.
- vol = FindVolumeBySlotRefNum(gP, slotMountP->slotRefNum);
- if(vol != -1)
- {
- err = vfsErrVolumeStillMounted;
- goto Exit;
- }
-
- slotLibRefNum = slotMountP->slotLibRefNum;
- slotRefNum = slotMountP->slotRefNum;
-
- // Low-level format the media
- err = SlotCardLowLevelFormat(slotLibRefNum, slotRefNum);
- if (err) goto Exit;
-
- // set up empty volume:
- ((MacSerialFSHeaderPtr)(gP->rwBuffer))->cookie = kMacSerialFSCookie;
- ((MacSerialFSHeaderPtr)(gP->rwBuffer))->created = false;
- ((MacSerialFSHeaderPtr)(gP->rwBuffer))->size = 0;
- ((MacSerialFSHeaderPtr)(gP->rwBuffer))->filename[0] = 0;
-
- // Write empty volume onto media:
- numSectors = 1;
- err = SlotCardSectorWrite(slotLibRefNum, slotRefNum, 0, gP->rwBuffer, &numSectors);
- if(err) goto Exit;
-
- Exit:
-
- return err;*/
-
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSVolumeMount
- *
- * DESCRIPTION: Mount the first volume on the specified slot
- * (The Slot Driver only supports one volume per slot)
- * The VFS posts a sysNotifyVolumeMountedEvent notification once the filesystem
- * is successfully mounted.
- * VFSAnyMountParamPtr->volRefNum must be set on entry to the volRefNum that will
- * be assigned to this volume if the mount succeeds.
- *
- * LIBRARY DEVELOPER NOTES:
- * The VFS will post the sysNotifyVolumeMountedEvent notification ONLY if this
- * function returns errNone.
- *
- * Before mounting, it is important to check to make sure
- * that there is enough power to perform the mount. If there is not
- * enough power to mount, FSVolumeMount should return expErrNotEnoughPower
- * and abort the mount operation.
- *
- * The vfsMountParamP should be switched off of
- * vfsMountParamP->mountClass and cast to the correct
- * MountParamType. For example if mountClass == 'libs'
- * then vfsMountParamP should be cast to VFSSlotMountParamType.
- *
- * The vfsMountParamP contains the global volRefNum that will be assigned
- * to this volume if the mount succeeds. The filesystem
- * library should store this, as all other calls which take a volRefNum
- * as a parameter will use this number.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * vfsMountParamP -- Mount parameters
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * expErrNotEnoughPower -- the required power is not available
- * vfsErrBadData -- The volume cannot be mounted because the
- * format of the media is unrecognized
- * This will cause the VFS to attempt to format
- * and remount the media.
- *
- *************************************************************/
- Err FSVolumeMount(UInt16 /*fsLibRefNum*/, VFSAnyMountParamPtr vfsMountParamP)
- {
- if(vfsMountParamP->mountClass == kMacSerialFSLibCreator) return errNone;
-
- return expErrUnsupportedOperation;
-
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- VFSSlotMountParamType *slotMountP = (VFSSlotMountParamType*)vfsMountParamP;
- UInt16 slotLibRefNum, slotRefNum;
- UInt32 numSectors;
- Int16 vol;
- CardMetricsType metrics;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- if(vfsMountParamP->mountClass != vfsMountClass_SlotDriver)
- return expErrUnsupportedOperation;
-
- // Make sure that the volume is unmounted before mounting it.
- vol = FindVolumeBySlotRefNum(gP, slotMountP->slotRefNum);
- if(vol != -1)
- {
- err = vfsErrVolumeStillMounted;
- goto Exit;
- }
-
- vol = FindNewVolume(gP);
- if(vol == -1)
- {
- err = expErrUnsupportedOperation;
- goto Exit;
- }
-
- if(gP->volume[vol].volumeRef != vfsInvalidVolRef)
- return vfsErrVolumeStillMounted;
-
- slotLibRefNum = slotMountP->slotLibRefNum;
- slotRefNum = slotMountP->slotRefNum;
-
- numSectors = 1;
-
- err = SlotCardSectorRead(slotLibRefNum, slotRefNum, 0, gP->rwBuffer, &numSectors);
- if(err) goto Exit;
-
- gP->volume[vol].header = *(MacSerialFSHeaderPtr)(gP->rwBuffer);
-
- // has the volume been formatted?
- if(gP->volume[vol].header.cookie != kMacSerialFSCookie)
- {
- err = vfsErrBadData;
- goto Exit;
- }
-
- err = SlotCardMetrics(slotLibRefNum, slotRefNum, &metrics);
- if(err) goto Exit;
-
- // if(metrics.reservedRangesP)
- // MemPtrFree(metrics.reservedRangesP);
-
- // Yes - volume is formatted, mount it:
- // Save the global volRefNum
- gP->volume[vol].volumeRef = slotMountP->vfsMountParam.volRefNum;
- gP->volume[vol].slotLibRefNum = slotLibRefNum;
- gP->volume[vol].slotRefNum = slotRefNum;
-
- gP->volume[vol].openRef = vfsInvalidFileRef;
- gP->volume[vol].fileMark = 0;
- gP->volume[vol].volumeSize = metrics.bytesPerSector * (metrics.totalSectors-1);
-
- err = errNone;
-
- Exit:
-
- return err;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSVolumeUnmount
- *
- * DESCRIPTION: Unmount the given volume. This closes any opened files.
- * The VFS posts a sysNotifyVolumeUnmountedEvent notification once the filesystem
- * is successfully unmounted.
- *
- * LIBRARY DEVELOPER NOTES:
- * The VFS will post the sysNotifyVolumeUnmountedEvent notification ONLY if this
- * function returns errNone.
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- *
- *************************************************************/
- Err FSVolumeUnmount(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
-
- vol = FindVolumeByRefNum(gP, volRefNum);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].openRef != 0)
- return vfsErrFileStillOpen;
-
-
- gP->volume[vol].volumeRef = vfsInvalidVolRef;
- err = errNone;
-
-
- return err;
- */
-
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSVolumeInfo
- *
- * DESCRIPTION: Get information about the specified volume
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * volInfoP -- Receives the volume info for the specified volume
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- * volInfoP is filled in on return with information about the specified volume
- *
- *************************************************************/
- Err FSVolumeInfo(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, VolumeInfoType *volInfoP)
- {
-
- volInfoP->attributes = 0;
- volInfoP->fsType = kMacSerialFSLibCreator;
- volInfoP->fsCreator = kMacSerialFSLibCreator;
- volInfoP->mountClass = kMacSerialFSLibCreator;
-
- return errNone;
- /* MacSerialFSGlobalsPtr gP;
- Err err = errNone;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByRefNum(gP, volRefNum);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef != volRefNum)
- return vfsErrVolumeBadRef;
-
- volInfoP->attributes = 0;
- volInfoP->fsType = kMacSerialFSCookie; // Use the cookie as the filesystem type.
- volInfoP->fsCreator = kMacSerialFSLibCreator;
- volInfoP->mountClass = vfsMountClass_SlotDriver;
- volInfoP->slotLibRefNum = gP->volume[vol].slotLibRefNum;
- volInfoP->slotRefNum = gP->volume[vol].slotRefNum;
- err = SlotCardMediaType(gP->volume[vol].slotLibRefNum, gP->volume[vol].slotRefNum, &(volInfoP->mediaType));
- volInfoP->fsCreator = kMacSerialFSLibCreator;
- volInfoP->reserved = 0;
-
-
-
- return err;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSVolumeGetLabel
- *
- * DESCRIPTION: Determine the volume label for a particular volume.
- * Clients that wish to remember a particular volume
- * should save this rather than the volRefNum. The volRefNum
- * may be different each time the volume is mounted.
- *
- * Volume labels are up to 255 characters long,
- * using any normal character including spaces and lower case
- * characters in any character set and the following special characters:
- * $ % ' - _ @ ~ ` ! ( ) ^ # & + , ; = [ ]
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * labelP -- Receives the label of the volume.
- * bufLen -- The length of the labelP buffer
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- * vfsErrBufferOverflow -- bufLen is not big enough to receive the full volume label
- * labelP is filled in on return with the volume label for the specified volume
- *
- *************************************************************/
- Err FSVolumeGetLabel(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, Char *labelP, UInt16 /*bufLen*/)
- {
- StrCopy(labelP, "Macintosh HD");
-
- return 0;
- /*
- MacSerialFSGlobalsPtr gP;
- Int16 vol;
- UInt32 size;
- char label[32];
-
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByRefNum(gP, volRefNum);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- size = gP->volume[vol].volumeSize;
- size /= 1024;
-
- if(size < 1024)
- {
- StrPrintF(label, "%dKB RAMDisk", (UInt16)size);
- }
- else
- {
- size /= 1024;
- StrPrintF(label, "%dMB RAMDisk", (UInt16)size);
- }
-
- if(StrLen(label) >= bufLen) return vfsErrBufferOverflow;
-
- StrCopy(labelP, label);
-
- // StrNCopy(labelP, "Untitled", bufLen);
-
- return errNone;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSVolumeSetLabel
- *
- * DESCRIPTION: Change the volume label for a particular volume.
- * Most clients should not need to call this routine.
- *
- * Volume labels are up to 255 characters long,
- * using any normal character including spaces and lower case
- * characters in any character set and the following special characters:
- * $ % ' - _ @ ~ ` ! ( ) ^ # & + , ; = [ ]
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * labelP -- Label to apply to the specified volume (NUL-terminated)
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- *
- *************************************************************/
- Err FSVolumeSetLabel(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, const Char * /*labelP*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /* MacSerialFSGlobalsPtr gP;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- return expErrUnsupportedOperation;
- */
- }
-
-
- /************************************************************
- *
- * FUNCTION: FSVolumeSize
- *
- * DESCRIPTION: Determine the total amount of space on a volume,
- * and the amount that is currently used. (in bytes)
- *
- * PARAMETERS: fsLibRefNum -- FS library reference number
- * volRefNum -- Volume reference number passed to FSVolumeMount
- * volumeUsedP -- Receives the amount of used space on the volume
- * volumeTotalP -- Receives the total amount of space on the volume
- *
- * RETURNS: errNone -- no error
- * expErrNotOpen -- FS driver library has not been opened
- * vfsErrVolumeBadRef -- the volume has not been mounted with FSVolumeMount
- * Sets volumeUsedP and volumeTotalP to the amount of used and total
- * space on the volume.
- *
- *************************************************************/
- Err FSVolumeSize(UInt16 /*fsLibRefNum*/, UInt16 /*volRefNum*/, UInt32 */*volumeUsedP*/, UInt32 */*volumeTotalP*/)
- {
- ErrFatalDisplay("nope");
- return 0;
- /*
- MacSerialFSGlobalsPtr gP;
- Err error = errNone;
- Int16 vol;
-
- gP = SysLibTblEntry(fsLibRefNum)->globalsP;
- if (!gP)
- return expErrNotOpen;
-
- vol = FindVolumeByRefNum(gP, volRefNum);
-
- if(vol == -1)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef == vfsInvalidVolRef)
- return vfsErrVolumeBadRef;
-
- if(gP->volume[vol].volumeRef != volRefNum)
- return vfsErrVolumeBadRef;
-
- if(volumeUsedP) *volumeUsedP = gP->volume[vol].header.size;
- if(volumeTotalP) *volumeTotalP = gP->volume[vol].volumeSize;
-
- return error;
- */
- }
-
-
- /********************************************************************
- * Private routines:
- ********************************************************************/
-
- /************************************************************
- *
- * FUNCTION: PrvShouldWeInstall
- *
- * DESCRIPTION: Called by the PrvFSInstall function to see
- * if we should install. The FS Library should not
- * install it's dispatch table if this function fails.
- *
- * PARAMETERS: None
- *
- * CALLED BY: PrvFSInstall function to see if we should install
- *
- * RETURNS: errNone -- no error
- * anything else -- Library will not be able to successfully run
- *
- *************************************************************/
- Err PrvShouldWeInstall(void)
- {
- // Verify that the Library will be able to successfully run.
-
- return errNone;
- }
-
-
- /************************************************************
- *
- * FUNCTION: PrvCopy
- *
- * DESCRIPTION: Copy data to a ptr that might be in the dynamic or storage heaps.
- *
- *
- * PARAMETERS: bufBaseP -- ptr to destination chunk
- * offset -- Offset within chunk to write data
- * dataStoreBased -- true if the destination is in the storage heap
- * false if the destination is in the dynamic heap
- * srcP -- Ptr to source data
- * numBytes -- number of bytes of source data to copy
- *
- * RETURNS: errNone if no error
- *
- *************************************************************/
- Err PrvCopy(void* bufBaseP, UInt32 offset, Boolean dataStoreBased, void *srcP, UInt32 numBytes)
- {
- Err err = errNone;
-
- if(dataStoreBased)
- {
- err = DmWrite(bufBaseP, offset, srcP, numBytes);
- }
- else
- {
- err = MemMove(((UInt8*)bufBaseP)+offset, srcP, numBytes);
- }
-
- return err;
- }
-
-
- Int16 FindVolumeByRefNum(MacSerialFSGlobalsPtr gP, UInt16 volRefNum)
- {
- Int16 i=0;
- while(i<MaxMountedVolumes)
- {
- if(gP->volume[i].volumeRef != vfsInvalidVolRef &&
- gP->volume[i].volumeRef == volRefNum) return i;
- i++;
- }
-
- return -1;
- }
-
- Int16 FindVolumeByFileRef(MacSerialFSGlobalsPtr gP, FileRef ref)
- {
- Int16 i=0;
- while(i<MaxMountedVolumes)
- {
- if(gP->volume[i].volumeRef != vfsInvalidVolRef &&
- (gP->volume[i].openRef == ref || gP->volume[i].dirRef == ref))
- return i;
- i++;
- }
-
- return -1;
- }
-
- Int16 FindVolumeBySlotRefNum(MacSerialFSGlobalsPtr gP, UInt16 slotRefNum)
- {
- Int16 i=0;
- while(i<MaxMountedVolumes)
- {
- if(gP->volume[i].volumeRef != vfsInvalidVolRef &&
- gP->volume[i].slotRefNum == slotRefNum) return i;
- i++;
- }
-
- return -1;
- }
-
- Int16 FindNewVolume(MacSerialFSGlobalsPtr gP)
- {
- Int16 i=0;
- while(i<MaxMountedVolumes)
- {
- if(gP->volume[i].volumeRef == vfsInvalidVolRef) return i;
- i++;
- }
-
- return -1;
- }
-
-
-
- short SerialRead(short numBytes, char *bufP)
- {
- UInt32 longRef;
- UInt16 refNum;
- Err err;
-
- FtrGet(kMacSerialFSLibCreator, 1, &longRef);
- refNum = longRef;
-
- // SrmReceive(refNum, bufP, numBytes, sysTicksPerSecond * 10, &err);
- SrmReceive(refNum, bufP, numBytes, -1, &err);
-
- return err;
- }
-
- short SerialWrite(short numBytes, char *bufP)
- {
- UInt32 longRef;
- UInt16 refNum;
- Err err;
-
- FtrGet(kMacSerialFSLibCreator, 1, &longRef);
- refNum = longRef;
-
- // SrmSend(refNum, bufP, numBytes, &err);
- SrmSend(refNum, bufP, numBytes, &err);
-
- return err;
- }
-
-
-
-