⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fldrvvxw.c

📁 DOC文件系统驱动源代码
💻 C
📖 第 1 页 / 共 5 页
字号:

STATUS  tffsMultidoc ( int   op, 
                       int * pVal )
{
    FLStatus  status = flBadFunction;

#ifdef FL_DRV_MULTIDOC

    int       dummy;

    if (tffsDrvCalled == TRUE) {

        /* can't enable/disable MTL after call to tffsDrv() */ 

        if (op != TFFS_MULTIDOC_STATUS)
            return ERROR;
    }

    /* if user isn't interested in multidoc's previous settings, discard it */

    if (pVal == NULL)
        pVal = &dummy;

    switch (op) {

        case TFFS_MULTIDOC_ENABLE:
            status = flSetEnvAll (FL_MULTI_DOC_ENABLED, (dword)FL_ON, (dword FAR2 *)pVal);
            break;

        case TFFS_MULTIDOC_DISABLE:
            status = flSetEnvAll (FL_MULTI_DOC_ENABLED, (dword)FL_OFF, (dword FAR2 *)pVal);
            break;

        case TFFS_MULTIDOC_STATUS:
            *pVal  = (int) flUseMultiDoc;
            status = flOK;
            break;
    }

#endif /* FL_DRV_MULTIDOC */

    return ((status == flOK) ? OK : ERROR);
}




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                        t f f s D r v                                   * 
 *                                                                        * 
 * Install TrueFFS driver. This routine should be called before any       * 
 * other FLite routine.                                                   * 
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      none                                                              * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        * 
 *      int             : OK or ERROR                                     * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

STATUS  tffsDrv ( void )
{
    int     iSoc;
    int     iDev;
    IOreq   ioreq;
    STATUS  stat;

    stat = OK;

    /* this routine is to be executed only once */

    if (tffsDrvCalled != TRUE) {

        tffsDrvCalled = TRUE;

        /* check if compiler packs data structures as we expect */

        if( sizeof(DOSBootSector) != SECTOR_SIZE ) {

            DEBUG_PRINT(("Debug: compiler doesn't pack data structures.\n"));
            return ERROR;
        }

        /* no TFFS devices have been created yet */

        for (iSoc = 0; iSoc < SOCKETS; iSoc++) {

            for (iDev = 0; iDev < FL_MAX_DISKS_PER_SOCKET; iDev++)
                tffsBlkDevs[iSoc][iDev] = NULL;
        }

        /* create mutexes, one per socket */

        for (iSoc = 0; iSoc < SOCKETS; iSoc++) {

            tffsSocketMutex[iSoc] = 
                semMCreate (SEM_DELETE_SAFE | /* SEM_INVERSION_SAFE | */ SEM_Q_FIFO);

            if (tffsSocketMutex[iSoc] == NULL) {

                DEBUG_PRINT(("Debug: can't allocate semaphore.\n"));
                stat = ERROR;

                break;
            }
        }

        /* initialize underlaying TFFS software */

        if( flInit() != flOK )
            stat = ERROR;

        /* initiate pre-mount on every socket */

        for (iSoc = 0; iSoc < (int)noOfSockets; iSoc++) {

            ioreq.irHandle = iSoc;
            (void) flCountVolumes(&ioreq);
        }
    }

    return stat;
}




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                        t f f s S o c k e t s                           * 
 *                                                                        * 
 * Get number of sockets in the system.                                   * 
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      none                                                              * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        * 
 *      int             : -1 if error, 1 if multi-doc is enabled,         * 
 *                        otherwise number of sockets                     * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

int  tffsSockets ( void )
{
    /* can't tell if tffsDrv() hasn't been called yet */

    if (tffsDrvCalled == FALSE)
        return -1;

#ifdef FL_DRV_MULTIDOC

    /* if multi-doc is enabled, pretend there is only one socket */

    if (flUseMultiDoc == 1)
        return 1;

#endif

    return ((int) noOfSockets);
}




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                   t f f s D i s k s O n S o c k e t                    * 
 *                                                                        * 
 * Get number of "disks" (BDTL partitions) on socket.                     * 
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      none                                                              * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        * 
 *      int             : -1 if error, 1 if multi-doc is enabled,         * 
 *                        otherwise number of BDTL partitions on socket   * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

int  tffsDisksOnSocket ( int  socNo )
{
    IOreq     ioreq;
    FLStatus  status;

    /* can't tell if tffsDrv() hasn't been called yet */

    if (tffsDrvCalled == FALSE)
        return -1;

#ifdef FL_DRV_MULTIDOC

    /* if multi-doc is enabled, pretend there is only one disk */

    if (flUseMultiDoc == 1)
        return 1;

#endif

    status = flGeneralFailure;     /* anything but flOK */

    if ((socNo >= 0) && (socNo < (int)noOfSockets)) {

        /* grab socket mutex */

        if (tffsSocketMutex[socNo] != NULL) {

            if( semTake(tffsSocketMutex[socNo], WAIT_FOREVER) == OK ) {

                /* get number of BDTL partitions on socket */

                ioreq.irHandle = socNo;
                status         = flCountVolumes(&ioreq);

                /* release socket mutex */

                semGive (tffsSocketMutex[socNo]);
            }
        }
    }

    return ((status == flOK) ? ((int)(ioreq.irFlags)) : -1);
}




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                        d e v R e c r e a t e                           * 
 *                                                                        * 
 * If TFFS device has been created for specified disk of given socket,    * 
 * update disk's TFFS_DEV struct. If FAT filters have been insatlled on   *
 * disk's FAT12/16 partitions, re-install them.                           * 
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      socNo           : TFFS socket#                                    * 
 *      diskNo          : TFFS disk#                                      * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        * 
 *      ERROR on error otherwise OK                                       * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

LOCAL STATUS  devRecreate ( int  socNo,
                            int  diskNo )
{  
    int        handle;
    TFFS_DEV * tmpTffsDev;
    STATUS     stat;

    /* check args for sanity */

    if ((socNo >= SOCKETS) || (diskNo >= FL_MAX_DISKS_PER_SOCKET))
        return ERROR;

    /* abort if TFFS device has never been created */

    if( tffsBlkDevs[socNo][diskNo] == NULL )
        return ERROR;

    stat = ERROR;

    /* construct TFFS handle */

    handle = tffsMakeHandle(socNo, diskNo);

    /* create temp. TFFS device, with the same flags as original device */

    tmpTffsDev = devCreate( handle, tffsBlkDevs[socNo][diskNo]->tffsFlags );

    if (tmpTffsDev != NULL) {

        /* re-install FAT monitors if they were installed before */

        if( tffsBlkDevs[socNo][diskNo]->tffsFlags & FL_TRUE_BLKDEV ) 
            (void) flffControl (handle, /* ignored */0, flStateInitInProgress);

#ifdef FL_DRV_CHK_BUFFER_ALIGNMENT

        /* free alignment buffer if exists */

        if( tffsBlkDevs[socNo][diskNo]->tffsAlignBuf != NULL )
            free( tffsBlkDevs[socNo][diskNo]->tffsAlignBuf ); 
#endif

        /* update original TFFS device from temp. one */

        memcpy( tffsBlkDevs[socNo][diskNo], tmpTffsDev, sizeof(TFFS_DEV) );
 
        /* discard temp. TFFS device */

        free (tmpTffsDev);

        /* tell dosFs to re-mount original TFFS device */

        tffsBlkDevs[socNo][diskNo]->tffsBlkdev.bd_readyChanged = TRUE;

        stat = OK;
    }

    return stat;
}




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                        d e v C r e a t e                               * 
 *                                                                        * 
 * Create TFFS disk device.                                               * 
 *                                                                        * 
 * The bits 3-0 of 'flags' contain the # of the desired partition. If     * 
 * it is zero, then partition table is searched for active FAT12/16       *  
 * partition; if none exist, the partition table is searched for the      * 
 * first FAT12/16 partition.                                              * 
 *                                                                        * 
 * If partition # is not zero, then the desired partition is picked up    * 
 * from the partition table.                                              *        
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      handle          : TFFS handle                                     * 
 *      flags           : various flags (see fldrvvxw.h)                  * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        * 
 *      NULL on error otherwise pointer to TFFS device                    * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

LOCAL TFFS_DEV * devCreate ( int  handle, 
                             int  flags )
{
    int                socNo;
    int                diskNo;
    FAST TFFS_DEV    * pTffsDev;     /* ptr to created TFFS_DEV struct */
    FAST BLK_DEV     * pBlkDev;      /* ptr to BLK_DEV struct          */
    IOreq              ioreq;
    unsigned long      cyls;
    unsigned long      heads;
    unsigned long      sects;
    long               offset;
    long               blocksInPart;
    BPB                bpb;
    FLStatus           status;
    dword              dontcare;

#ifdef FL_DRV_PHYSICAL_ACCESS
    VolumeInfoRecord   info;
#endif
 
    /* check args for sanity */

    socNo  = tffsHandle2Soc(handle);
    diskNo = tffsHandle2Disk(handle);
 
    if ((socNo >= SOCKETS) || (diskNo >= FL_MAX_DISKS_PER_SOCKET))
        return NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -