亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? volume.c

?? 從大量的wince源代碼中剝離出的fat文件系統源代碼.移植性非常高. 里面帶有source i.rar
?? C
?? 第 1 頁 / 共 5 頁
字號:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
/*++


Module Name:

    volume.c

Abstract:

    This file contains routines for mounting volumes, direct volume access, etc.

Revision History:

--*/

#include "fatfs.h"

#if defined(UNDER_WIN95) && !defined(INCLUDE_FATFS)
#include <pcmd.h>               // for interacting with ReadVolume/WriteVolume
#endif


ERRFALSE(offsetof(BOOTSEC, bsBPB) == offsetof(BIGFATBOOTSEC, bgbsBPB));


/*  ReadVolume
 *
 *  Like ReadWriteDisk, except it takes a PVOLUME, and it works with
 *  volume-relative BLOCKS instead of disk-relative SECTORS.
 *
 *  For now, the caller must specify a block number that starts on a sector
 *  boundary, and the number of blocks must map to a whole number of sectors.
 *
 *  Entry:
 *      pvol        address of VOLUME structure
 *      block       0-based block number
 *      cBlocks     number of blocks to read
 *      pvBuffer    address of buffer to read sectors into
 *
 *  Exit:
 *      ERROR_SUCCESS if successful, else GetLastError() from the FSDMGR_DiskIoControl call issued
 */         

DWORD ReadVolume(PVOLUME pvol, DWORD block, int cBlocks, PVOID pvBuffer)
{
#ifdef UNDER_WIN95
    if (ZONE_BUFFERS && ZONE_PROMPTS) {
        WCHAR wsBuf[10];
        DBGPRINTFW(TEXTW("Read:  block %d, total %d;  allow (Y/N)? "), block, cBlocks);
        DBGSCANFW(wsBuf, ARRAYSIZE(wsBuf));
        if (TOLOWER(wsBuf[0]) == 'n')
            return ERROR_BAD_UNIT;
    }
#endif


    // Assert that the shifted bits in both block and cBlocks are zero

    ASSERT(pvol->v_log2cblkSec<=0? 1 : (((block | cBlocks) & ((1 << pvol->v_log2cblkSec) - 1)) == 0));

    if (pvol->v_flags & VOLF_FROZEN) {
        DEBUGMSG(ZONE_INIT || ZONE_ERRORS,(DBGTEXT("FATFS!ReadVolume: frozen volume, cannot read block %d!\n"), block));
        return ERROR_DEV_NOT_EXIST;
    }

    // NOTE that all sectors computed in this function are relative to
    // block 0, and that before they are passed to ReadWriteDisk, they are
    // adjusted by v_secBlkBias (the sector bias for block 0).  Thus, it is
    // impossible for this function to read from any of the volume's reserved
    // sectors (eg, the boot sector and BPB) or hidden sectors, because they
    // precede block 0.
    //
    // See the code in IOCTL_DISK_READ_SECTORS and IOCTL_DISK_WRITE_SECTORS
    // to access sectors outside the normal block range.

    return ReadWriteDisk(pvol, pvol->v_pdsk->d_hdsk, DISK_IOCTL_READ, &pvol->v_pdsk->d_diActive, pvol->v_secBlkBias + (block>>pvol->v_log2cblkSec), (cBlocks>>pvol->v_log2cblkSec), pvBuffer);
}


/*  WriteVolume
 *
 *  Like ReadWriteDisk, except it takes a PVOLUME, and it works with
 *  volume-relative BLOCKS instead of disk-relative SECTORS.
 *
 *  For now, the caller must specify a block number that starts on a sector
 *  boundary, and the number of blocks must map to a whole number of sectors.
 *
 *  Entry:
 *      pvol        address of VOLUME structure
 *      block       0-based block number
 *      cBlocks     number of blocks to write
 *      pvBuffer    address of buffer to write sectors from
 *
 *  Exit:
 *      ERROR_SUCCESS if successful, else GetLastError() from the FSDMGR_DiskIoControl call issued
 */         

DWORD WriteVolume(PVOLUME pvol, DWORD block, int cBlocks, PVOID pvBuffer)
{
    DWORD sec, csec, secEnd, secBackup;

#ifdef UNDER_WIN95
    if (ZONE_BUFFERS && ZONE_PROMPTS) {
        WCHAR wsBuf[10];
        DBGPRINTFW(TEXTW("Write: block %d, total %d;  allow (Y/N)? "), block, cBlocks);
        DBGSCANFW(wsBuf, ARRAYSIZE(wsBuf));
        if (TOLOWER(wsBuf[0]) == 'n')
            return ERROR_BAD_UNIT;
    }
#endif


    // Assert that the shifted bits in both block and cBlocks are zero

    ASSERT(pvol->v_log2cblkSec<=0? 1 : (((block | cBlocks) & ((1 << pvol->v_log2cblkSec) - 1)) == 0));

    if (pvol->v_flags & VOLF_FROZEN) {
        DEBUGMSG(ZONE_INIT || ZONE_ERRORS,(DBGTEXT("FATFS!WriteVolume: frozen volume, cannot write block %d!\n"), block));
        return ERROR_DEV_NOT_EXIST;
    }

    // NOTE that all sectors computed in this function are relative to
    // block 0, and that before they are passed to ReadWriteDisk, they are
    // adjusted by v_secBlkBias (the sector bias for block 0).  Thus, it is
    // impossible for this function to write to any of the volume's reserved
    // sectors (eg, the boot sector and BPB) or hidden sectors, because they
    // precede block 0.
    //
    // See the code in IOCTL_DISK_READ_SECTORS and IOCTL_DISK_WRITE_SECTORS
    // to access sectors outside the normal block range.

    sec = block >> pvol->v_log2cblkSec;
    csec = cBlocks >> pvol->v_log2cblkSec;

    // If we have multiple FATs, and we're writing to the FAT region,
    // adjust and/or mirror the write appropriately.

    if ((pvol->v_flags & VOLF_BACKUP_FAT) && sec < pvol->v_secEndAllFATs) {

        secEnd = sec + csec;

        // Check for write to root directory area that starts inside
        // a backup FAT.  Backup FATs are not buffered, hence any buffered
        // data inside the range of the backup FAT could be stale and
        // must NOT be written.

        if (sec >= pvol->v_secEndFAT) {
            ASSERT(secEnd > pvol->v_secEndAllFATs);
            csec = secEnd - pvol->v_secEndAllFATs;
            sec = pvol->v_secEndAllFATs;
            goto write;
        }

        // Check for write to end of the active FAT that ends inside
        // a backup FAT.  Backup FATs are not buffered, hence any buffered
        // data inside the range of the backup FAT could be stale and
        // must NOT be written.

        secBackup = sec;

        if (secEnd > pvol->v_secEndFAT) {

            DWORD csecFATWrite;

            csecFATWrite = pvol->v_secEndFAT - sec;

            if (secEnd < pvol->v_secEndAllFATs) {
                csec = csecFATWrite;
            }
            else {

                DWORD cbFATWrite;
                PBYTE pFAT, pFATBackup;

                // The current buffer spans all the FATs, so we need to
                // copy the FAT data to the backup FAT location(s) instead of
                // doing extra writes.

                pFAT = (PBYTE)pvBuffer;
                pFATBackup = pFAT + (pvol->v_csecFAT << pvol->v_log2cbSec);
                cbFATWrite = (csecFATWrite << pvol->v_log2cbSec);

                
                while ((secBackup += pvol->v_csecFAT) < pvol->v_secEndAllFATs) {
                    memcpy(pFATBackup, pFAT, cbFATWrite);
                    pFATBackup += pvol->v_csecFAT << pvol->v_log2cbSec;
                }
                goto write;
            }
        }

        // If we're still here, we've got a FAT write that's been restricted
        // to the just the sectors within the active FAT.  Start cycling through
        // the backup FATs now.

        
        while ((secBackup += pvol->v_csecFAT) < pvol->v_secEndAllFATs) {

            DEBUGMSG(ZONE_FATIO,(DBGTEXT("FATFS!WriteVolume: mirroring %d FAT sectors at %d to %d\n"), csec, sec, secBackup));

            ASSERT(secBackup + csec <= pvol->v_secEndAllFATs);

            // We ignore any error here, on the assumption that perhaps the
            // backup FAT has simply gone bad.

            ReadWriteDisk(pvol, pvol->v_pdsk->d_hdsk, DISK_IOCTL_WRITE, &pvol->v_pdsk->d_diActive, pvol->v_secBlkBias + secBackup, csec, pvBuffer);
        }
    }
  write:
    return ReadWriteDisk(pvol, pvol->v_pdsk->d_hdsk, DISK_IOCTL_WRITE, &pvol->v_pdsk->d_diActive, pvol->v_secBlkBias + sec, csec, pvBuffer);
}


/*  InitVolume - Initialize a VOLUME structure
 *
 *  ENTRY
 *      pvol - pointer to VOLUME
 *      pbgbs - pointer to PBR (partition boot record) for volume
 *
 *  EXIT
 *      TRUE if VOLUME structure successfully initialized, FALSE if not
 */

BOOL InitVolume(PVOLUME pvol, PBIGFATBOOTSEC pbgbs)
{
    DWORD cmaxClus;
    PBIGFATBPB pbpb;
    PDSTREAM pstmFAT;
    PDSTREAM pstmRoot;

    ASSERT(OWNCRITICALSECTION(&pvol->v_cs));

    pvol->v_flags &= ~(VOLF_INVALID | VOLF_12BIT_FAT | VOLF_16BIT_FAT | VOLF_32BIT_FAT | VOLF_BACKUP_FAT);


    // Allocate special DSTREAMs for the FAT and the root directory,
    // using PSEUDO cluster numbers 0 and 1.  Root directories of FAT32
    // volumes do have a REAL cluster number, and if we're in a nested init
    // path, we need to use it, but otherwise we'll just use ROOT_PSEUDO_CLUSTER
    // and record the real cluster number when we figure it out, in the
    // FAT32-specific code farther down...

    pstmFAT = OpenStream(pvol, FAT_PSEUDO_CLUSTER, NULL, NULL, NULL, OPENSTREAM_CREATE);
    ASSERT(pvol->v_pstmFAT == NULL || pvol->v_pstmFAT == pstmFAT);

    pstmRoot = OpenStream(pvol, pvol->v_pstmRoot? pvol->v_pstmRoot->s_clusFirst : ROOT_PSEUDO_CLUSTER, NULL, NULL, NULL, OPENSTREAM_CREATE);
    ASSERT(pvol->v_pstmRoot == NULL || pvol->v_pstmRoot == pstmRoot);

    if (!pstmFAT || !pstmRoot)
        goto exit;

    // Add extra refs to these special streams to make them stick around;
    // we only want to do this if the current open is their only reference,
    // because if they've been resurrected, then they still have their original
    // extra refs.

    if (pstmFAT->s_refs == 1) {
        pstmFAT->s_refs++;
    }

    if (pstmRoot->s_refs == 1) {
        pstmRoot->s_refs++;
    }

    pvol->v_pstmFAT = pstmFAT;
    pvol->v_pstmRoot = pstmRoot;

    pstmRoot->s_attr = ATTR_DIRECTORY;

    // We have completed the required stream initialization for this
    // volume.  Now perform boot sector verification and BPB validation.

    if (pvol->v_pdsk->d_diActive.di_flags & DISK_INFO_FLAG_UNFORMATTED) {
        RETAILMSG(TRUE,(DBGTEXT("FATFS!InitVolume: driver has set 'unformatted' bit, marking volume invalid\n")));
        pvol->v_flags |= VOLF_INVALID;
    }

    
    if (!(pvol->v_flags & VOLF_INVALID)) {
        if (pbgbs->bgbsJump[0] != BSNOP     &&
            pbgbs->bgbsJump[0] != BS2BYTJMP &&
            pbgbs->bgbsJump[0] != BS3BYTJMP) {
            RETAILMSG(TRUE,(DBGTEXT("FATFS!InitVolume: sector 0 byte 0 suspicious (0x%x)\n"), pbgbs->bgbsJump[0]));
        }
        if (pbgbs->bgbsBPB.oldBPB.BPB_BytesPerSector < DEFAULT_SECTOR_SIZE ||
            Log2(pbgbs->bgbsBPB.oldBPB.BPB_BytesPerSector) == -1 ||
            pbgbs->bgbsBPB.oldBPB.BPB_NumberOfFATs < 1 ||
            *(PWORD)((PBYTE)pbgbs+DEFAULT_SECTOR_SIZE-2) != BOOTSECTRAILSIGH) {
            DEBUGMSG(ZONE_INIT || ZONE_ERRORS,(DBGTEXT("FATFS!InitVolume: invalid BPB, volume deemed invalid\n")));
            pvol->v_flags |= VOLF_INVALID;
        }
    }

    pbpb = &pbgbs->bgbsBPB;

    // Preliminary FAT32 detection: if FAT32 support is disabled, then ALWAYS
    // set VOLF_INVALID;  otherwise, do it only if there is a version mismatch.

    if (!(pvol->v_flags & VOLF_INVALID) && pbpb->oldBPB.BPB_SectorsPerFAT == 0) {

#ifdef FAT32
        if (pbpb->BGBPB_FS_Version > FAT32_Curr_FS_Version) {
            RETAILMSG(TRUE,(TEXT("FATFS!InitVolume: FAT32 volume version unsupported (%d > %d)\n"),
                        pbpb->BGBPB_FS_Version, FAT32_Curr_FS_Version));
#else
            RETAILMSG(TRUE,(TEXT("FATFS!InitVolume: FAT32 volumes not supported in this build\n")));
#endif
            pvol->v_flags |= VOLF_INVALID;

#ifdef FAT32
        }

        if (!(pvol->v_flags & VOLF_INVALID)) {
            pvol->v_flags |= VOLF_32BIT_FAT;
            pvol->v_secFSInfo = pbpb->BGBPB_FSInfoSec;
        }
#endif
    }

    if (pvol->v_flags & VOLF_INVALID) {

        
        memset(&pvol->v_bMediaDesc, 0, offsetof(VOLUME, v_pstmFAT) - offsetof(VOLUME, v_bMediaDesc));
        memset(&pstmFAT->s_run, 0, sizeof(pstmFAT->s_run));
        memset(&pstmRoot->s_run, 0, sizeof(pstmRoot->s_run));
        goto exit;
    }

    // Now compute volume dimensions, etc, from BPB data

    pvol->v_bMediaDesc = pbpb->oldBPB.BPB_MediaDescriptor;

    if (pbpb->oldBPB.BPB_NumberOfFATs > 1)
        pvol->v_flags |= VOLF_BACKUP_FAT;

    // Compute sector bias for volume (for sector-based I/O)

    pvol->v_secVolBias = pbpb->oldBPB.BPB_HiddenSectors;

    // Compute sector bias for block 0 (for block-based I/O only)

    pvol->v_secBlkBias = pbpb->oldBPB.BPB_HiddenSectors + pbpb->oldBPB.BPB_ReservedSectors;

    // Compute how many sectors are on the volume

    pvol->v_csecTotal = pbpb->oldBPB.BPB_TotalSectors;
    if (pvol->v_csecTotal == 0)
        pvol->v_csecTotal = pbpb->oldBPB.BPB_BigTotalSectors;

    if (pvol->v_csecTotal <= pbpb->oldBPB.BPB_ReservedSectors) {
        DEBUGMSGBREAK(ZONE_INIT || ZONE_ERRORS,
                 (DBGTEXT("FATFS!InitVolume: total sectors (%d) is incorrect, adjusting to match driver\n"), pvol->v_csecTotal));
        pvol->v_csecTotal = pvol->v_pdsk->d_diActive.di_total_sectors - pvol->v_secBlkBias;
    }
    else
        pvol->v_csecTotal -= pbpb->oldBPB.BPB_ReservedSectors;

#ifdef DEBUG
    

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美高清在线一区二区| 国产精品伦一区| 亚洲美女电影在线| 成人开心网精品视频| 国产精品美女久久久久久久| 99久久精品99国产精品| 一区二区三区欧美日| 精品视频在线免费看| 日韩经典中文字幕一区| 精品少妇一区二区三区视频免付费| 久久久久久久久久久久久久久99 | 亚洲一二三四在线观看| 91国偷自产一区二区开放时间 | 精品免费视频.| www.久久精品| 国产精品欧美精品| 91国偷自产一区二区开放时间| 午夜亚洲福利老司机| 日韩美女一区二区三区| 国产激情精品久久久第一区二区 | av爱爱亚洲一区| 亚洲一区二区三区四区在线免费观看| 欧美吻胸吃奶大尺度电影 | 亚洲人快播电影网| 欧美日韩精品一区二区三区| 久久99久国产精品黄毛片色诱| 国产精品视频一二| 欧美三级欧美一级| 国产高清精品在线| 一二三四社区欧美黄| 国产精品自拍网站| 国产日韩精品久久久| 91美女在线观看| 免费精品视频最新在线| 国产精品福利在线播放| 欧美日韩久久久久久| 国产精品一区二区三区四区| 亚洲国产精品自拍| 久久久久久久久久久久久夜| 欧美日韩中文字幕一区| 国产精品系列在线观看| 香蕉成人啪国产精品视频综合网| 久久综合色8888| 欧美日韩一区高清| 成人美女视频在线观看18| 亚洲va中文字幕| 国产精品女上位| 精品久久国产97色综合| 色婷婷综合视频在线观看| 国产一区二区精品久久91| 亚洲aⅴ怡春院| 亚洲人妖av一区二区| 久久精品夜色噜噜亚洲a∨| 日本乱人伦一区| 国产精品久久久久永久免费观看| 欧美日韩国产系列| www.99精品| 国产乱一区二区| 日韩精品欧美成人高清一区二区| 亚洲视频一区二区在线| 久久综合久久久久88| 69堂成人精品免费视频| 91国模大尺度私拍在线视频| 成人福利视频在线看| 国产一区二区三区在线观看精品 | 免费成人在线网站| 玉米视频成人免费看| 国产精品私人影院| 日韩三级视频在线看| 在线视频欧美区| 国产精品一二三| 日本强好片久久久久久aaa| 亚洲欧洲综合另类| 国产精品福利一区二区三区| 蜜桃av噜噜一区| 亚洲人精品午夜| 国产欧美视频在线观看| 欧美一区二区三区男人的天堂| jlzzjlzz欧美大全| 国产一区二区三区免费播放| 日本va欧美va瓶| 亚洲午夜久久久久久久久电影院 | 国内不卡的二区三区中文字幕 | 欧美高清在线精品一区| 日韩一区二区免费视频| 91精品国产综合久久福利| 欧美性高清videossexo| 成人ar影院免费观看视频| 国产精品白丝jk黑袜喷水| 国模套图日韩精品一区二区 | 欧美亚洲尤物久久| 成人一区二区在线观看| 久久99精品视频| 国产精品66部| 国产成人小视频| 国产精品一线二线三线| 国产一区二区久久| 国产精品一区二区在线看| 国产九色sp调教91| 国产91丝袜在线观看| 成人小视频在线观看| 成人高清av在线| 国产精品一卡二卡在线观看| 国产最新精品免费| 国产成人h网站| av在线一区二区三区| 99精品热视频| 欧美日韩dvd在线观看| 4438x成人网最大色成网站| 欧美日韩国产综合草草| 3atv一区二区三区| 精品欧美一区二区久久| 久久久夜色精品亚洲| 国产精品午夜春色av| 亚洲免费观看高清完整版在线观看 | 亚洲国产中文字幕| 日韩激情一二三区| 九九精品一区二区| 国产大陆亚洲精品国产| 成人综合婷婷国产精品久久| 亚洲综合丁香婷婷六月香| 亚洲精品久久7777| 亚洲自拍另类综合| 国产成人综合网站| 久久精品夜色噜噜亚洲a∨| 国产精品理论片在线观看| 国产精品91xxx| 丝袜美腿亚洲综合| 国内精品国产成人| 91视频在线观看免费| 欧美区在线观看| 欧美绝品在线观看成人午夜影视| 26uuu亚洲综合色| 亚洲同性gay激情无套| 日韩精彩视频在线观看| 国产精品99久久久久久久女警| 91麻豆产精品久久久久久| 日韩三级在线观看| 亚洲欧美电影一区二区| 久久精品国产亚洲5555| av一区二区三区黑人| 欧美日韩久久不卡| 亚洲免费观看在线视频| 国产一二精品视频| 欧美系列亚洲系列| 欧美国产精品中文字幕| 污片在线观看一区二区| 成人av资源网站| 欧美成人精品福利| 亚洲最新视频在线观看| 精品综合久久久久久8888| 欧美日产国产精品| 一区二区中文视频| 激情六月婷婷久久| 欧美区一区二区三区| 中文字幕在线播放不卡一区| 中文字幕在线观看不卡视频| 亚洲一区二区欧美激情| 国产精品中文欧美| 久久亚洲精品小早川怜子| 亚洲国产成人av网| a美女胸又www黄视频久久| 欧美sm美女调教| 视频一区二区中文字幕| 99热精品国产| 亚洲国产日韩精品| 99在线精品观看| 欧美精品一区二区三区一线天视频| 日韩精品免费专区| 91久久精品网| 亚洲另类在线一区| jlzzjlzz欧美大全| 国产亚洲污的网站| 国产精品99久| 久久久激情视频| 国产激情一区二区三区四区| 精品日韩在线观看| 美女久久久精品| 欧美一级黄色片| 三级不卡在线观看| 欧美日韩国产综合一区二区三区| 亚洲视频狠狠干| 99re8在线精品视频免费播放| 国产精品久久福利| 成人av在线资源网站| 国产女人aaa级久久久级| 欧美视频在线一区二区三区| 欧美日韩国产中文| 亚洲国产日韩综合久久精品| 色美美综合视频| 亚洲免费在线观看视频| 色婷婷综合久色| 亚洲一区在线播放| 欧美日韩久久久一区| 久久99精品国产麻豆婷婷| 日韩免费视频线观看| 国产乱国产乱300精品| 精品一区二区国语对白| 经典三级在线一区| 国内精品国产成人国产三级粉色 |