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

📄 serv.c

📁 wince3.0的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	sgi.dwFlags     = 0;
	sgi.idDsk       = (DWORD)pDsk;
	sgi.dwSector    = dwSector;
	sgi.cSectors    = cSectors;
	sgi.pfdi        = NULL;
	sgi.cfbi        = 1;
	sgi.pfbi        = &bi;
	sgi.pfnCallBack = NULL;

    return ReadWriteDiskEx(&sgi, NULL, DISK_IOCTL_WRITE);
}


/*  FSDMGR_ReadDiskEx - Called by an FSD to read sectors from a disk into discontiguous buffers
 *
 *  ENTRY
 *      pfsgi -> FSD_SCATTER_GATHER_INFO
 *      pfsgr -> FSD_SCATTER_GATHER_RESULTS
 *
 *  EXIT
 *      ERROR_SUCCESS if successful, or an error code
 */

DWORD FSDMGR_ReadDiskEx(FSD_SCATTER_GATHER_INFO *pfsgi, FSD_SCATTER_GATHER_RESULTS *pfsgr)
{
    return ReadWriteDiskEx(pfsgi, pfsgr, DISK_IOCTL_READ);
}


/*  FSDMGR_WriteDiskEx - Called by an FSD to write sectors to a disk from discontiguous buffers
 *
 *  ENTRY
 *      pfsgi -> FSD_SCATTER_GATHER_INFO
 *      pfsgr -> FSD_SCATTER_GATHER_RESULTS
 *
 *  EXIT
 *      ERROR_SUCCESS if successful, or an error code
 */

DWORD FSDMGR_WriteDiskEx(FSD_SCATTER_GATHER_INFO *pfsgi, FSD_SCATTER_GATHER_RESULTS *pfsgr)
{
    return ReadWriteDiskEx(pfsgi, pfsgr, DISK_IOCTL_WRITE);
}


/*  FSDMGR_RegisterVolume - Called by an FSD to register a volume
 *
 *  ENTRY
 *      pDsk -> DSK passed to FSD_MountDisk
 *      pwsName -> desired volume name, NULL for default name (eg, "Storage Card")
 *      pVolume == FSD-defined volume-specific data
 *
 *  EXIT
 *      Volume identifier, NULL if none
 */

PVOL FSDMGR_RegisterVolume(PDSK pDsk, PWSTR pwsName, PVOLUME pVolume)
{
    PVOL pVol;

    ASSERT(VALIDSIG(pDsk, DSK_SIG));

    EnterCriticalSection(&csFSD);

    if (pVol = AllocVolume(pDsk, (DWORD)pVolume)) {

        PFSD pFSD = pVol->pDsk->pFSD;

        if (GetFSDProcArray(pFSD, pFSD->apfnAFS,  apfnAFSStubs,  apwsAFSAPIs,  ARRAY_SIZE(apwsAFSAPIs)) &&
            GetFSDProcArray(pFSD, pFSD->apfnFile, apfnFileStubs, apwsFileAPIs, ARRAY_SIZE(apwsFileAPIs)) &&
            GetFSDProcArray(pFSD, pFSD->apfnFind, apfnFindStubs, apwsFindAPIs, ARRAY_SIZE(apwsFindAPIs))) {

            if (pVol->iAFS == INVALID_AFS) {

                // Determine what AFS index to use.  We try to use OID_FIRST_AFS
                // first, because FILESYS.EXE pre-registers the name "Storage Card"
                // at that index (to prevent anyone from creating a folder or file
                // with that name).  However, if that fails, then we'll try to create
                // a unique derivation of whatever name FILESYS.EXE had reserved at
                // that index, register the new name, and use the resulting AFS index.

                
                int cch;
                int iAFS, iSuffix = 1;
                WCHAR wsAFS[128];

                cch = GetAFSName(OID_FIRST_AFS, wsAFS, ARRAY_SIZE(wsAFS));

                if (pwsName == NULL && cch) {

                    // The FSD did not provide a name, and the default name is already in use,
                    // so we should just try derivations of the default name.

                    iSuffix = 2;
                    pwsName = wsAFS;
                }

                if (pwsName == NULL) {

                    // The FSD did not provide a name, and the default name is NOT in use,
                    // so we should be able to use the default name.

                    if (RegisterAFS(OID_FIRST_AFS, hAFSAPI, (DWORD)pVol, AFS_VERSION)) {
                        pVol->iAFS = OID_FIRST_AFS;
#ifdef DEBUG
                        VERIFYTRUE(GetAFSName(pVol->iAFS, wsAFS, ARRAY_SIZE(wsAFS)));
                        memcpy(pVol->wsVol, wsAFS, min(sizeof(pVol->wsVol),sizeof(wsAFS)));
                        DEBUGMSGW(ZONE_EVENTS,(DBGTEXTW("FSDMGR_RegisterVolume: registered primary volume as %s\n"), pVol->wsVol));
#endif
                    }
                    else
                        DEBUGMSGW(ZONE_EVENTS,(DBGTEXTW("FSDMGR_RegisterVolume: primary volume could not be registered (%d)\n"), GetLastError()));
                }
                else {

                    // Either the FSD provided a name, or the default name is in use,
                    // so we should try all the appropriate derivations.

                    wcscpy(wsAFS, pwsName[0] == '\\'? pwsName+1 : pwsName);
                    cch = wcslen(wsAFS);

                    do {
                        if (iSuffix > 1) {
                            wsAFS[cch] = '0'+iSuffix;
                            wsAFS[cch+1] = 0;
                        }

                        
                        iAFS = RegisterAFSName(wsAFS);
                        if (iAFS != INVALID_AFS && GetLastError() == 0) {
                            DEBUGMSGW(ZONE_EVENTS,(DBGTEXTW("FSDMGR_RegisterVolume: registering secondary volume as %s\n"), wsAFS));
                            if (RegisterAFS(iAFS, hAFSAPI, (DWORD)pVol, AFS_VERSION)) {
                                pVol->iAFS = iAFS;
                                break;
                            }
                            DEBUGMSGW(ZONE_EVENTS,(DBGTEXTW("FSDMGR_RegisterVolume: registering secondary volume failed (%d)\n"), GetLastError()));
                            VERIFYTRUE(DeregisterAFSName(iAFS));
                        }
                    } while (iSuffix++ < 9);
                }
            }

            // End of "if pVol->iAFS == INVALID_AFS".  Note, however, that pVol->iAFS may
            // *still* be INVALID_AFS if all our attempts to register a volume name were rebuffed.
        }

        // End of "if GetFSDProcArray()" calls

        if (pVol->iAFS == INVALID_AFS) {
            DeallocVolume(pVol);
            pVol = NULL;
        }
    }

    LeaveCriticalSection(&csFSD);

    return pVol;
}


/*  FSDMGR_GetVolumeName - Called by an FSD to query a volume's registered name
 *
 *  ENTRY
 *      pVol -> VOL structure returned from FSDMGR_RegisterVolume
 *      pwsName -> buffer, or NULL to query size of name
 *      cchMax == max chars allowed in buffer (including terminating NULL), ignored if pwsName is NULL
 *
 *  EXIT
 *      Number of characters returned, NOT including terminating NULL, or 0 if error
 */

int FSDMGR_GetVolumeName(PVOL pVol, PWSTR pwsName, int cchMax)
{
    ASSERT(VALIDSIG(pVol, VOL_SIG));

    return GetAFSName(pVol->iAFS, pwsName, cchMax);
}


/*  FSDMGR_DeregisterVolume - Called by an FSD to deregister a volume
 *
 *  ENTRY
 *      pVol -> VOL structure returned from FSDMGR_RegisterVolume
 *
 *  EXIT
 *      None
 */

void FSDMGR_DeregisterVolume(PVOL pVol)
{
    ASSERT(VALIDSIG(pVol, VOL_SIG));

    EnterCriticalSection(&csFSD);

    if (pVol) {

        if (pVol->iAFS != INVALID_AFS) {
            VERIFYTRUE(DeregisterAFS(pVol->iAFS));
            if (pVol->iAFS > OID_FIRST_AFS)
                VERIFYTRUE(DeregisterAFSName(pVol->iAFS));
            pVol->iAFS = INVALID_AFS;
        }

        DeallocVolume(pVol);
    }

    LeaveCriticalSection(&csFSD);
}


/*  FSDMGR_CreateFileHandle - Called by an FSD to create 'file' handles
 *
 *  ENTRY
 *      pVol -> VOL structure returned from FSDMGR_RegisterVolume
 *      hProc == originating process handle
 *      pFile == FSD-defined file-specific data for the new handle
 *
 *  EXIT
 *      A 'file' handle associated with the originating process, or INVALID_HANDLE_VALUE
 */

HANDLE FSDMGR_CreateFileHandle(PVOL pVol, HANDLE hProc, PFILE pFile)
{
    ASSERT(VALIDSIG(pVol, VOL_SIG));

    return AllocFSDHandle(pVol, hProc, (DWORD)pFile, HDL_FILE);
}


/*  FSDMGR_CreateSearchHandle - Called by an FSD to create 'search' (aka 'find') handles
 *
 *  ENTRY
 *      pVol -> VOL structure returned from FSDMGR_RegisterVolume
 *      hProc == originating process handle
 *      pSearch == FSD-defined search-specific data for the new handle
 *
 *  EXIT
 *      A 'search' handle associated with the originating process, or INVALID_HANDLE_VALUE
 */

HANDLE FSDMGR_CreateSearchHandle(PVOL pVol, HANDLE hProc, PSEARCH pSearch)
{
    ASSERT(VALIDSIG(pVol, VOL_SIG));

    return AllocFSDHandle(pVol, hProc, (DWORD)pSearch, HDL_SEARCH);
}

⌨️ 快捷键说明

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