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

📄 fldrvvxw.c

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

/******************************************************************************* 
 *                                                                             * 
 *                        M-Systems Confidential                               * 
 *           Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2001        * 
 *                         All Rights Reserved                                 * 
 *                                                                             * 
 ******************************************************************************* 
 *                                                                             * 
 *                            NOTICE OF M-SYSTEMS OEM                          * 
 *                           SOFTWARE LICENSE AGREEMENT                        * 
 *                                                                             * 
 *      THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE             * 
 *      AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT       * 
 *      FOR THE SPECIFIC TERMS AND CONDITIONS OF USE,                          * 
 *      OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE:                           * 
 *      E-MAIL = info@m-sys.com                                                * 
 *                                                                             * 
 ******************************************************************************* 
 *                                                                             * 
 *                         Module: FLDRVVXW                                    * 
 *                                                                             * 
 *  This module implements VxWorks driver layer for TFFS.                      *
 *                                                                             * 
 *******************************************************************************/

/*
DESCRIPTION

USER CALLABLE ROUTINES
Most of the routines in this driver are accessible only through the I/O
system.  Two routines, however, must be called directly, tffsDrv () to
initialize the driver, and tffsDevCreate () to create devices.

TFFSDRV
Before using the driver, it must be initialized by calling the routine:
.CS
    tffsDrv ()
.CE
This routine should be called exactly once, before any reads, writes, or
tffsDevCreates.  Normally, it is called from usrRoot.

CREATING DISK DEVICES
Before a disk device can be used, it must be created.
This is done with the tffsDevCreate call.

IOCTL
This driver responds to all the same ioctl codes by setting global error flag.
To format a disk use tffsDevFormat().
*/

/*
 $Log:   V:/Flite/archives/OSAK/examples/drivers/VxWorks/fldrvvxw.c_v  $
 * 
 *    Rev 1.21   26 Jun 2003 00:57:58   andrayk
 * bug fix with releasing mutex in TffsBlkRd()
 * 
 *    Rev 1.20   16 May 2003 19:58:58   andrayk
 * TrueFFS-5.1.4
 * 
 *    Rev 1.19   04 Jun 2002 22:58:12   andreyk
 * set bd_readyChanged only if error occured
 * 
 *    Rev 1.18   24 Apr 2002 02:36:10   andreyk
 * TrueFFS-5.1 update
 * 
 *    Rev 1.17   15 Feb 2002 00:49:30   andreyk
 * bug fix: by default disable TL write verification
 * 
 *    Rev 1.16   12 Feb 2002 01:05:28   andreyk
 * TrueFFS-5.1
 * 
 *    Rev 1.15   Nov 28 2001 22:07:34   andreyk
 * TrueFFS-5.04
 * 
 *    Rev 1.13   Sep 25 2001 21:02:12   oris
 * compiler warning fixed
 * 
 *    Rev 1.12   21 Sep 2001 17:41:14   andreyk
 * runtime check for structure packing
 * 
 *    Rev 1.11   03 Sep 2001 03:44:40   andreyk
 * alignment of file system's buffers
 * 
 *    Rev 1.10   Jun 20 2001 19:52:50   oris
 * minor change to copyright statement
 * 
 *    Rev 1.9   17 May 2001 02:38:30   andreyk
 * bug fixes in osak-5
 * 
 *    Rev 1.8   19 Feb 2001 20:39:48   andreyk
 * dosFs-2 support added
 * 
 *    Rev 1.7   Dec 31 2000 16:41:34   vadimk
 * OSAK-4.2.1: support for dosFs's long filenames
 * 
 *    Rev 1.6   Aug 07 2000 10:37:34   vadimk
 * OSAK-4.2. added FL_IOCTL_READ/WRITE_SECTORS
 * 
 *    Rev 1.5   May 28 2000 11:08:06   vadimk
 * OSAK-4.1 with IOCTL support
 * 
 *    Rev 1.4   Apr 27 2000 11:35:44   vadimk
 * VERIFY_WRITE option was added
 * 
 *    Rev 1.3   Mar 08 2000 11:53:22   veredg
 * OSAK-4.1/VxWorks
 *
 *    Rev 1.2   Jul 21 1999 15:22:12   Administrator
 * OSAK-121 based driver
 *
 *    Rev 1.1   30 Sep 1997 13:00:28   ANDRY
 * big endian bug fix
 *
 *    Rev 1.0   25 Aug 1997 11:59:20   ANDRY
 * Initial revision.
*/




/*
 * Configuration 
 */

#define FL_DRV_DOSFS2_SUPPORT         /* full support for DosFs-2           */
#define FL_DRV_DOSFS_LONGNAME_SUPPORT /* support for dosFs long filenames   */ 
#define FL_DRV_VERIFY_WRITE           /* verify all sector write operations */
#define FL_DRV_PHYSICAL_ACCESS        /* include flPhys..() API             */
#define FL_DRV_CHK_BUFFER_ALIGNMENT   /* check if data buffers are aligned  */
#undef  FL_DRV_MULTIDOC               /* include Multi-Doc                  */



/*
 * defines
 */

#define  FL_MAX_DISKS_PER_SOCKET  MAX_TL_PARTITIONS




/*
 * Includes
 */

#include "fldrvvxw.h"
#include "flioctl.h"
#include "fatfilt.h"




/*
 * Global data
 */

/* TFFS devices */

TFFS_DEV * tffsBlkDevs[SOCKETS][FL_MAX_DISKS_PER_SOCKET] = { { NULL} } ;

/* mutexes protecting sockets */

SEM_ID  tffsSocketMutex[SOCKETS] = { (SEM_ID)0 };
 



/*
 * Local data 
 */

static BOOL  tffsSetupCalled = FALSE;
static BOOL  tffsDrvCalled = FALSE;

#ifdef FL_DRV_PHYSICAL_ACCESS

/* physical characteristics of flash media */

static int   physReadWriteUnitSize[SOCKETS] = { SECTOR_SIZE };
static int   physEraseUnitSize[SOCKETS]     = { (16 * 1024) };

#endif /* FL_DRV_PHYSICAL_ACCESS */




/*
 * Local routines
 */

LOCAL STATUS     tffsIoctl   (TFFS_DEV *pTffsDev, int function, int arg);
LOCAL STATUS     tffsBlkRd   (FAST TFFS_DEV *pTffsDev, int startBlk, int numBlks, 
                                             char *pBuffer);
LOCAL STATUS     tffsBlkWrt  (FAST TFFS_DEV *pTffsDev, int startBlk, int numBlks,
                                             char *pBuffer);
LOCAL STATUS     tffsStatChk (TFFS_DEV *pTffsDev);
LOCAL void       setFromBPB  (BLK_DEV *pBlkDev, BPB *pBPB);
LOCAL long       getPart     (int handle, int partNo, long *pPartSize);
LOCAL STATUS     devRecreate (int socNo, int diskNo);
LOCAL TFFS_DEV*  devCreate   (int handle, int flags);




/*
 * Extern
 */

extern void  flBuildGeometry (dword capacity, dword FAR2 *cylinders,
                              dword FAR2 *heads, dword FAR2 *sectors, 
                              FLBoolean oldFormat); /* blockdev.c */
extern int   fl_vols;                               /* flcustom.c */
extern long  fl_volsAddr[];                         /* flcustom.c */




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                    t f f s H a n d l e 2 D e v                         * 
 *                                                                        * 
 * Convert TFFS handle to pointer to TFFS device.                         * 
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      handle          : TFFS handle                                     * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        * 
 *      Pointer to TFFS device or NULL                                    * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

TFFS_DEV *  tffsHandle2Dev ( int handle )
{
    int  socNo;
    int  diskNo;

    /* check args for sanity */

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

    /* check if driver has been initialized */

    if (tffsSetupCalled != TRUE)
        return NULL;

    return tffsBlkDevs[socNo][diskNo];
}        
  



/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                        t f f s S e t u p                               * 
 *                                                                        * 
 * Specify how many DiskOnChip sockets to search for, and search address  * 
 * ranges for every such socket.                                          * 
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      sockets         : DiskOnChip sockets to search for                * 
 *      addressRange    : array of start/end addresses of the search      * 
 *                           range for every DiskOnChip.                  * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

void  tffsSetup ( int    sockets, 
                  long * addressRange )
{
    register int  i;

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

    if (tffsSetupCalled != TRUE) {

        if (sockets > 0) {

            /* number of DiskOnChips to search for */

            fl_vols = ((sockets <= SOCKETS) ? sockets : SOCKETS);

            /* 
             * Search ranges for every DiskOnChip. The validity of the 
             * address ranges will be checked by flRegisterComponents() 
             */

            for (i = 0; i < fl_vols; i++) {

                fl_volsAddr[2*i]     = addressRange[2*i];
                fl_volsAddr[2*i + 1] = addressRange[2*i + 1];
            }

            tffsSetupCalled = TRUE;
        }
    }
}




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                   t f f s S e t O p t i o n                            * 
 *                                                                        * 
 * Sets various TFFS runtime configuration options which are common for   * 
 * all sockets/disks/partitions.                                          * 
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      option          : TFFS runtime confi. option (see fldrvvxw.h)     * 
 *      pVal            : on entry - new setting of 'option'              * 
 *                        on exit  - previous setting of option           * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        * 
 *      ERROR if any error, otherwise OK                                  * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

STATUS  tffsSetOption ( int    option, 
                        void * pVal )
{
    FLStatus  status;

    /* arg sanity check */

    if (pVal == NULL)
        return ERROR;

    /* 
     * Since these config. vars are TrueFFS-wide, do not allow to change them
     * after call to tffsDrv().
     */  

    if (tffsDrvCalled == TRUE) 
        return ERROR;

    status = flBadFunction;

    switch (option) {
    
        case TFFS_OPT_NFTL_CHAIN:     /* limit of TL chain length */

            status = flSetEnvAll (FL_SET_MAX_CHAIN, *((dword *) pVal), (dword FAR2 *)pVal);
            break;

        case TFFS_OPT_SEC_PER_FOLD:   /* sectors verified during TL chain folding */

            status = flSetEnvAll (FL_SECTORS_VERIFIED_PER_FOLDING, *((dword *) pVal), 
                                                                     (dword FAR2 *)pVal);
            break;

        case TFFS_OPT_NFTL_CACHE:     /* enable/disable TL cache */

            status = flSetEnvAll (FL_TL_CACHE_ENABLED, *((dword *) pVal), 
                                                         (dword FAR2 *)pVal);
            break;

        case TFFS_OPT_8BIT_ACCESS:    /* 32-bit or 8-bit memory routines */

            status = flSetEnvAll (FL_DOC_8BIT_ACCESS, *((dword *) pVal), 

⌨️ 快捷键说明

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