亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
国产自产2019最新不卡| 免费美女久久99| 91麻豆免费看片| 亚洲sss视频在线视频| 日韩欧美电影在线| av一区二区三区| 日本特黄久久久高潮| 欧美激情综合网| 欧美日韩高清一区二区不卡| 国产成人免费在线观看| 日精品一区二区三区| 亚洲三级电影全部在线观看高清| 欧美疯狂性受xxxxx喷水图片| 风流少妇一区二区| 香蕉av福利精品导航| 亚洲国产另类精品专区| 中文字幕av一区二区三区免费看 | 欧美日本在线看| 欧美日本国产一区| 日韩午夜电影在线观看| 欧美三级三级三级| 99久久免费精品| 成人免费毛片aaaaa**| 久久99国产精品尤物| 日韩精品视频网| 国产在线精品不卡| 激情综合色播五月| proumb性欧美在线观看| 欧美三级一区二区| 久久综合久久99| 精品国产网站在线观看| 欧美一级片在线观看| 91麻豆精品国产自产在线观看一区| 91免费小视频| 91 com成人网| 国产精品福利一区二区| 国产精品入口麻豆原神| 日本一二三四高清不卡| 亚洲国产成人porn| 成人h精品动漫一区二区三区| 国产成人自拍网| 欧美日韩性生活| 国产精品久久久久精k8| 日本欧美久久久久免费播放网| 国产自产高清不卡| 在线免费精品视频| 日本道在线观看一区二区| 一本到一区二区三区| 欧美亚日韩国产aⅴ精品中极品| 91色porny在线视频| 精品美女被调教视频大全网站| 精品电影一区二区三区| 亚洲理论在线观看| 日韩综合小视频| 一本一本大道香蕉久在线精品| 久久婷婷久久一区二区三区| 亚洲成av人片在线| 91国偷自产一区二区三区成为亚洲经典 | 国产伦精品一区二区三区视频青涩| 色哟哟精品一区| 国产亚洲精品免费| 日本一区二区成人在线| 麻豆一区二区在线| 成人黄色网址在线观看| 久久久美女毛片| 亚洲欧洲精品一区二区三区不卡| 亚洲国产精品视频| 色诱视频网站一区| 亚洲欧洲三级电影| 99久久精品免费看国产| 欧美高清在线视频| 成人av在线网| 国产精品麻豆一区二区| 国产精品中文字幕日韩精品| 91香蕉视频污在线| 亚洲女人的天堂| 久久精工是国产品牌吗| 成人白浆超碰人人人人| 久久久电影一区二区三区| 卡一卡二国产精品| 欧美tickle裸体挠脚心vk| 奇米888四色在线精品| 欧美精品成人一区二区三区四区| 亚洲18女电影在线观看| 欧美区在线观看| 日本免费新一区视频| 欧美另类变人与禽xxxxx| 亚洲成人一区二区在线观看| 欧美男男青年gay1069videost | 免费精品视频在线| 日韩一二三区视频| 国产一区啦啦啦在线观看| 国产欧美日韩不卡| 日韩精品福利网| 精品国产一区a| 99久久国产综合精品色伊| 亚洲精品成人在线| 欧美一区三区四区| 国产老女人精品毛片久久| 国产精品免费免费| 欧美日韩国产精品成人| 激情文学综合插| 久久久国产午夜精品| 99精品视频一区| 日韩精品电影在线观看| 国产日韩成人精品| 91豆麻精品91久久久久久| 日本中文字幕一区二区视频| 国产欧美精品国产国产专区| 欧美午夜视频网站| 国产在线视频精品一区| 亚洲视频图片小说| 精品国产乱码久久| 日本福利一区二区| 国产一区二区精品久久| 中文欧美字幕免费| 色女孩综合影院| 日韩欧美www| 成人sese在线| 久久国产精品72免费观看| 日韩美女啊v在线免费观看| 91精品国产色综合久久不卡电影 | 精品一区二区三区久久| 中文字幕不卡的av| 日韩午夜激情电影| 欧美在线一区二区| 不卡欧美aaaaa| 美女脱光内衣内裤视频久久网站 | 日韩av高清在线观看| 亚洲人妖av一区二区| 精品国产麻豆免费人成网站| 在线观看欧美精品| 92国产精品观看| 国产精品亚洲午夜一区二区三区 | 国产精品午夜电影| 精品久久久久久久久久久久久久久| 色综合久久久久久久久久久| 国产成人av网站| 久久国产麻豆精品| 男人操女人的视频在线观看欧美| 最新中文字幕一区二区三区| 精品国精品国产尤物美女| 欧美探花视频资源| 色伊人久久综合中文字幕| 波多野结衣中文字幕一区二区三区| 麻豆国产精品777777在线| 亚瑟在线精品视频| 一区二区三区成人在线视频| 欧美曰成人黄网| 一本到三区不卡视频| av影院午夜一区| 99国产精品视频免费观看| 99精品视频在线观看| 99麻豆久久久国产精品免费| 成人app网站| 成人性生交大片免费| 久久欧美一区二区| 久久免费午夜影院| 亚洲精品一区二区在线观看| 精品国产区一区| 国产欧美日韩综合| 国产精品久久久一区麻豆最新章节| 中文字幕不卡三区| 亚洲青青青在线视频| 亚洲欧洲国产专区| 一区二区三区欧美| 日韩电影在线观看网站| 九一久久久久久| 国产成人一区在线| 一本久道中文字幕精品亚洲嫩 | 欧美日本一区二区三区| 6080yy午夜一二三区久久| 91精品国产91久久久久久一区二区| 欧美一区二视频| 亚洲国产精品av| 亚洲午夜在线观看视频在线| 欧美aⅴ一区二区三区视频| 激情伊人五月天久久综合| www.一区二区| 欧美老女人第四色| 国产日韩欧美高清| 亚洲综合精品久久| 国产精品国产三级国产aⅴ入口| 亚洲欧美aⅴ...| 男男成人高潮片免费网站| 国产精品1区二区.| 欧美色精品在线视频| 欧美电影免费观看高清完整版在 | 久久噜噜亚洲综合| 亚洲欧美日韩一区二区三区在线观看 | 蜜桃久久精品一区二区| 国产传媒久久文化传媒| 91国偷自产一区二区开放时间| 欧美一卡在线观看| 国产精品国产三级国产aⅴ入口 | 激情综合网激情| 国产成人av一区二区三区在线 | 欧美日韩aaaaa| 久久综合国产精品| 午夜国产不卡在线观看视频|