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

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

?? buffer.c

?? 從大量的wince源代碼中剝離出的fat文件系統源代碼。移植性非常高。 微軟的代碼
?? C
?? 第 1 頁 / 共 4 頁
字號:
#endif

    // If buffer is valid and dirty...

    if (pbuf->b_pvol && (pbuf->b_flags & BUF_DIRTY)) {

        if (pbuf->b_pvol->v_flags & VOLF_READONLY) {
            dwError = ERROR_WRITE_PROTECT;
        }
        
        DEBUGMSG(ZONE_BUFFERS,(DBGTEXT("FATFS!CommitBuffer(block %d)\n"), pbuf->b_blk));

        // Hold the buffer to insure that FindBuffer won't try to steal
        // it while the DIRTY bit is clear yet the buffer is still dirty.

        HoldBuffer(pbuf);


        // We clear the DIRTY bit before writing the buffer out, to
        // insure that we don't inadvertently lose some other thread's
        // modification to the buffer before our WriteVolume call is
        // complete.

        CleanBuffer(pbuf);

        // If the caller tells us that csBuffers is currently held, release
        // it across the WriteVolume call.

        pbuf->b_flags |= BUF_BUSY;

        // We used to release this critical section across a disk write but it would
        // sometimes cause data corruption on multithreaded writes with odd buffer
        // sizes. Beware if you try to "optimize" by adding the release back in.  
        //if (fCS)
        //    LeaveCriticalSection(&csBuffers);
        dwError = WriteVolume(pbuf->b_pvol, pbuf->b_blk, cblkBuf, pbuf->b_pdata);
        pbuf->b_flags &= ~BUF_BUSY;
        //if (fCS)
        //    EnterCriticalSection(&csBuffers);

        if (dwError) {
            if (dwError == ERROR_WRITE_PROTECT) {

                // Invalidate the buffer, it can't be written and is presumably
                // now out of sync with the disk's actual contents.

                pbuf->b_pvol = NULL;
            }
            else {

                // If the cause of failure might simply be that the disk has been
                // yanked, we can always hope that the user will put the disk back
                // in, so let's just re-dirty the buffer.

                DirtyBufferError(pbuf, pbMod, cbMod);
            }
        }
        UnholdBuffer(pbuf);
    }
    return dwError;
}


/*  CleanBuffer
 *
 *  ENTRY
 *      pbuf - pointer to BUF
 *
 *  EXIT
 *      The buffer is marked CLEAN, if it wasn't already.
 */

void CleanBuffer(PBUF pbuf)
{
    ASSERTHELDBUFFER(pbuf);

    pbuf->b_flags &= ~BUF_DIRTY;

    if (pbuf->b_flags & BUF_ERROR) {

        EnterCriticalSection(&csBuffers);

        if (pbuf->b_flags & BUF_ERROR) {
            cbufError--;
            if (cbufError % MIN_BUFFERS == 0)
                InterlockedIncrement(&cBufThreads);
            pbuf->b_flags &= ~BUF_ERROR;
        }

        LeaveCriticalSection(&csBuffers);
    }
}


/*  ChecksumBuffer
 *
 *  ENTRY
 *      pbuf - pointer to BUF
 *
 *  EXIT
 *      32-bit checksum of data in buffer
 */

DWORD ChecksumBuffer(PBUF pbuf)
{
    DWORD dwSum = 0;
    DWORD cdw = cbBuf / sizeof(DWORD);
    PDWORD pdw = (PDWORD)pbuf->b_pdata;

    ASSERT(cdw*sizeof(DWORD) == cbBuf);

    while (cdw--) {
        dwSum += *pdw++;            }
    return dwSum | 0x80000000;  // insure that the checksum for a buffer is always non-zero
}


/*  FindBuffer
 *
 *  ENTRY
 *      pvol - pointer to VOLUME
 *      blk - desired block on VOLUME
 *      pstm - pointer to DSTREAM containing block
 *      fNoRead - TRUE to skip reading the coresponding disk data
 *      ppbuf - pointer to address of BUF (to be returned)
 *
 *  EXIT
 *      ERROR_SUCCESS (0) if successful, non-zero if not.
 */

DWORD FindBuffer(PVOLUME pvol, DWORD blk, PDSTREAM pstm, BOOL fNoRead, PBUF *ppbuf)
{
    PBUF pbuf, pbufOld, pbufEnd;
    DWORD dwError = ERROR_SUCCESS;

    DEBUGMSG(ZONE_LOGIO && pstm && (pstm->s_flags & STF_DEMANDPAGED),(DBGTEXT("FATFS!FindBuffer(DP): begin entercritsec\n")));
    EnterCriticalSection(&csBuffers);
    DEBUGMSG(ZONE_LOGIO && pstm && (pstm->s_flags & STF_DEMANDPAGED),(DBGTEXT("FATFS!FindBuffer(DP): end entercritsec\n")));

    DEBUGMSG(ZONE_BUFFERS,(DBGTEXT("FATFS!FindBuffer(block %d, stream %.11hs)\n"), blk, pstm? pstm->s_achOEM : "<NONE>"));

    // Make sure the volume is allowed to use the buffer pool

    if (!(pvol->v_flags & VOLF_BUFFERED)) {
        DEBUGMSG(TRUE,(DBGTEXT("FATFS!FindBuffer: volume not allowed to use buffer pool yet!\n")));
        dwError = ERROR_GEN_FAILURE;
        goto error;
    }

    // If an associated stream is specified, the volume better match

    ASSERT(!pstm || pstm->s_pvol == pvol);

    // If the stream has a valid pbufCur, we'll check that buffer
    // first, but otherwise we'll walk the buffers in MRU order.  If we
    // don't find the desired block, then we'll read the data into the
    // oldest unheld buffer we saw.

    if (pstm && (pbuf = pstm->s_pbufCur)) {
        if (pbuf->b_pvol && pbuf->b_pvol == pvol && pbuf->b_blk == blk)
            goto foundLastBuffer;
        ReleaseStreamBuffer(pstm, TRUE);        }

    // Search the buffer pool in MRU order, and also keep track of
    // a likely candidate to re-use (pbufOld), in case we don't find what 
    // we're looking for.

restart:
    pbuf = dlBufMRU.pbufNext;
    pbufEnd = (PBUF)&dlBufMRU;

    pbufOld = NULL;
    while (pbuf != pbufEnd) {

        if (pbuf->b_pvol && pbuf->b_pvol == pvol && pbuf->b_blk == blk) {

            // An existing buffer might be in the BUF_UNCERTAIN state (ie, if another
            // thread had wanted the same buffer, started reading it, but hadn't finished
            // by the time *we* came along).  In that case, we must block until the
            // BUF_UNCERTAIN flag is cleared.

            while (pbuf->b_flags & BUF_UNCERTAIN) {
                DEBUGMSG(TRUE,(DBGTEXT("FATFS!FindBuffer: waiting for block %d to become certain...\n"), pbuf->b_blk));
                Sleep(2000);
            }

            // Furthermore, if an UNCERTAIN buffer could not be read, then we will have
            // set b_pvol to NULL to invalidate the buffer.  We need to check for that condition
            // now;  it needs to be checked outside the UNCERTAIN loop, since the timing might
            // have been such that we never even saw the UNCERTAIN bit get set.

            if (pbuf->b_pvol == NULL)
                goto restart;
            else
                goto foundBuffer;
        }

        // If this buffer isn't held, pick it.  The only exception is
        // if we already picked (a newer) one and this (older) one's dirty.

        if (!HeldBuffer(pbuf) && !(pbuf->b_flags & BUF_BUSY)) {
            if (!pbufOld || !(pbuf->b_flags & BUF_DIRTY))
                pbufOld = pbuf;
        }

        pbuf = pbuf->b_dlink.pbufNext;
    }

    // There should always be an unheld buffer in the pool (which we
    // now assert).  If there isn't, then MIN_BUFFERS has been set too low
    // (ie, the current thread must already be holding onto at least that
    // many buffers, or some other thread is holding onto more than MIN_BUFFERS).

    if (!pbufOld) {
        DEBUGMSGBREAK(TRUE,(DBGTEXT("FATFS!FindBuffer: buffer pool unexpectedly exhausted!\n")));
        dwError = ERROR_GEN_FAILURE;
        goto error;
    }

    pbuf = pbufOld;

    // Make sure any buffer we're about to (re)use has been committed;  the
    // only time we should end up using a dirty buffer is when no clean ones
    // are available, and if we can't commit a particular buffer, we probably
    // can't commit *any* of them, which is why I just give up.

    DEBUGMSG(ZONE_LOGIO && pstm && (pstm->s_flags & STF_DEMANDPAGED),(DBGTEXT("FATFS!FindBuffer(DP): begin commitbuffer\n")));
    dwError = CommitBuffer(pbuf, TRUE);
    DEBUGMSG(ZONE_LOGIO && pstm && (pstm->s_flags & STF_DEMANDPAGED),(DBGTEXT("FATFS!FindBuffer(DP): end commitbuffer\n")));
    if (dwError)
        goto error;

    pbuf->b_pvol = pvol;
    pbuf->b_blk = blk;
#ifdef DEBUG
    pbuf->b_refs = 0;
#endif

    // WARNING: The buffer critical section is not held across the actual
    // read, to insure that critical I/O (like demand-paging) can still occur
    // even if other threads start stacking up inside the driver.  Since
    // BUF_UNCERTAIN is set for the duration, no other threads entering FindBuffer
    // for the same block/buffer should continue until we're done here.

    if (!fNoRead) {
        pbuf->b_flags |= BUF_UNCERTAIN | BUF_BUSY;
        LeaveCriticalSection(&csBuffers);
        DEBUGMSG(ZONE_LOGIO && pstm && (pstm->s_flags & STF_DEMANDPAGED),(DBGTEXT("FATFS!FindBuffer(DP): begin readvolume\n")));
        dwError = ReadVolume(pvol, pbuf->b_blk, cblkBuf, pbuf->b_pdata);
        DEBUGMSG(ZONE_LOGIO && pstm && (pstm->s_flags & STF_DEMANDPAGED),(DBGTEXT("FATFS!FindBuffer(DP): end readvolume\n")));
        if (dwError) {
            // Invalidate the buffer if the data could not be read, and do it *before*
            // clearing BUF_UNCERTAIN, so that anyone waiting on BUF_UNCERTAIN cannot miss
            // the fact that this buffer is now invalid.
            pbuf->b_pvol = NULL;
            pbuf->b_flags &= ~(BUF_UNCERTAIN | BUF_BUSY);
            return dwError;
        }
        // We must clear BUF_UNCERTAIN *before* taking csBuffers, because otherwise we could
        // block forever due to another FindBuffer thread waiting for us to clear the same bit
        // on the same buffer.
        pbuf->b_flags &= ~BUF_UNCERTAIN;
        DEBUGMSG(ZONE_LOGIO && pstm && (pstm->s_flags & STF_DEMANDPAGED),(DBGTEXT("FATFS!FindBuffer(DP): begin entercritsec\n")));
        EnterCriticalSection(&csBuffers);
        DEBUGMSG(ZONE_LOGIO && pstm && (pstm->s_flags & STF_DEMANDPAGED),(DBGTEXT("FATFS!FindBuffer(DP): end entercritsec\n")));
        // We must clear BUF_BUSY *after* taking csBuffers, because otherwise the buffer is
        // vulnerable to re-use by another thread while (A) we're outside csBuffers and (B) no
        // hold has been applied yet.
        pbuf->b_flags &= ~BUF_BUSY;
    }

    // Move the buffer to MRU position now

  foundBuffer:
    RemoveItem((PDLINK)&pbuf->b_dlink);
    AddItem((PDLINK)&dlBufMRU, (PDLINK)&pbuf->b_dlink);

    // Apply a conventional hold or a stream hold, as appropriate

  foundLastBuffer:
    if (!pstm) {
        HoldBuffer(pbuf);
    }
    else {
        AssignStreamBuffer(pstm, pbuf, TRUE);
    }

#ifdef DEBUG
    pbuf->b_refs++;
#endif

    // Last but not least, return a pointer to the buffer structure

    *ppbuf = pbuf;

  error:
    LeaveCriticalSection(&csBuffers);
    return dwError;
}


/*  AssignStreamBuffer
 *
 *  ENTRY
 *      pstm - pointer to DSTREAM
 *      pbuf - pointer to buffer to assign to stream
 *      fCS - TRUE if csBuffers is held, FALSE if not
 *
 *  EXIT
 *      The buffer is held and assigned as the stream's current buffer.
 *
 *  NOTES
 *      Any caller messing with a stream's current buffer must also
 *      currently own the stream's critical section.
 */

void AssignStreamBuffer(PDSTREAM pstm, PBUF pbuf, BOOL fCS)
{
    ASSERT(OWNCRITICALSECTION(&pstm->s_cs));

    // If a buffer is changing hands, commit it first, because
    // CommitStreamBuffers for a given stream will only commit buffers
    // still associated with that stream, and we want to guarantee that
    // a stream is FULLY committed after calling CommitStreamBuffers.

    // We don't care if there's an error, because CommitBuffer no longer
    // invalidates a buffer on error;  it simply marks the buffer dirty again.

    if (pbuf->b_pstm != pstm) {
        if (pstm->s_flags & STF_WRITETHRU)
            CommitBuffer(pbuf, fCS);
    }

    pbuf->b_pstm = pstm;

#ifdef DEBUG
    memcpy(pbuf->b_achName, pstm->s_achOEM, min(sizeof(pbuf->b_achName),sizeof(pstm->s_achOEM)));
#endif

    if (!(pstm->s_flags & STF_BUFCURHELD)) {
        HoldBuffer(pbuf);
        pstm->s_pbufCur = pbuf;
        pstm->s_flags |= STF_BUFCURHELD;
    }
    else
        ASSERT(pstm->s_pbufCur == pbuf);
}


/*  ReleaseStreamBuffer
 *
 *  ENTRY
 *      pstm - pointer to DSTREAM
 *      fCS - TRUE if csBuffers is held, FALSE if not
 *
 *  EXIT
 *      The stream's current buffer is unheld, if it was currently in use.
 *
 *  NOTES
 *      Any caller messing with a stream's current buffer must also
 *      currently own the stream's critical section.
 */

DWORD ReleaseStreamBuffer(PDSTREAM pstm, BOOL fCS)
{
    DWORD dwError = ERROR_SUCCESS;

    ASSERT(OWNCRITICALSECTION(&pstm->s_cs));

    if (pstm->s_flags & STF_BUFCURHELD) {

        if (pstm->s_flags & STF_WRITETHRU)
            dwError = CommitBuffer(pstm->s_pbufCur, fCS);

        pstm->s_flags &= ~STF_BUFCURHELD;
        UnholdBuffer(pstm->s_pbufCur);

        // Zap the buffer pointer to prevent anyone from misusing it

        pstm->s_pbufCur = NULL;
    }
    return dwError;
}


/*  ReadStreamBuffer
 *
 *  ENTRY
 *      pstm - pointer to DSTREAM

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99精品久久99久久久久| 国产一区二区三区| 欧美国产精品劲爆| 久久久久久久综合日本| 欧美电视剧在线观看完整版| 欧美美女喷水视频| 这里只有精品免费| 欧美一区二区三区性视频| 欧美女孩性生活视频| 欧美日韩免费高清一区色橹橹| 91在线观看高清| 在线亚洲高清视频| 欧美午夜精品久久久| 欧美久久久久久蜜桃| 日韩欧美视频在线| 国产欧美一区二区在线观看| 亚洲国产成人午夜在线一区| 国产精品美女久久久久aⅴ| 国产精品传媒入口麻豆| 最新国产の精品合集bt伙计| 亚洲男人天堂av网| 视频在线在亚洲| 久久疯狂做爰流白浆xx| 国产98色在线|日韩| 91免费版在线看| 欧美高清一级片在线| 久久伊99综合婷婷久久伊| 亚洲国产精品激情在线观看| 亚洲丝袜自拍清纯另类| 日韩一区精品字幕| 粉嫩欧美一区二区三区高清影视| 日本国产一区二区| 日韩一区二区电影| 国产精品无人区| 首页国产欧美久久| 懂色av中文字幕一区二区三区| 91免费视频大全| 日韩精品一区二| 亚洲欧洲国产专区| 老鸭窝一区二区久久精品| 成人福利视频在线看| 欧美日韩第一区日日骚| 国产精品免费人成网站| 视频一区二区不卡| 99视频一区二区三区| 欧美一区二区三区四区五区| 国产精品毛片无遮挡高清| 日本不卡视频一二三区| av一二三不卡影片| 久久影院午夜论| 日本免费新一区视频| 成人av资源网站| 日韩一区二区高清| 亚洲国产成人tv| 成人av电影观看| 久久精品一级爱片| 蜜桃91丨九色丨蝌蚪91桃色| 欧美性猛交xxxxxxxx| 国产精品无码永久免费888| 六月丁香综合在线视频| 欧美疯狂性受xxxxx喷水图片| 国产精品久久久久久久久快鸭 | 极品美女销魂一区二区三区免费 | 亚洲一区在线观看免费观看电影高清 | 91精品福利在线一区二区三区| 欧美高清在线一区| 毛片一区二区三区| 欧美巨大另类极品videosbest| 成人免费在线视频观看| 国产乱码精品一区二区三| 欧美日韩国产三级| 一卡二卡三卡日韩欧美| 91论坛在线播放| 国产欧美一区二区精品秋霞影院| 青青草97国产精品免费观看| 欧美羞羞免费网站| 亚洲一区在线观看视频| 欧美无人高清视频在线观看| 亚洲综合一二区| 欧美日韩中字一区| 日韩**一区毛片| 欧美一区二区三区在线观看| 日本在线不卡视频一二三区| 8x8x8国产精品| 亚洲国产综合在线| 欧美日韩视频一区二区| 亚洲综合色区另类av| 欧美日韩一区二区三区在线| 亚洲黄网站在线观看| 色综合色综合色综合| 亚洲精品久久嫩草网站秘色| 色欧美88888久久久久久影院| 自拍偷拍国产精品| 欧美情侣在线播放| 久久精品国产99| 日本一区二区高清| 色老汉一区二区三区| 亚洲一区在线观看免费| 欧美一区日韩一区| 极品尤物av久久免费看| 国产精品进线69影院| 色老头久久综合| 蜜桃视频在线一区| 久久精品网站免费观看| 色香色香欲天天天影视综合网| 亚洲国产日韩综合久久精品| 91精品福利在线一区二区三区| 国产一区二区剧情av在线| 日韩一区欧美小说| 日韩一区二区中文字幕| 东方欧美亚洲色图在线| 亚洲一区二区三区激情| 日韩一区二区电影| 色哟哟欧美精品| 韩国精品在线观看| 亚洲精品国产一区二区精华液| 欧美色图激情小说| 国产高清在线精品| 亚洲午夜激情网站| 国产日韩欧美制服另类| 精品视频免费看| 北条麻妃一区二区三区| 日本不卡一区二区三区| 中文字幕一区免费在线观看| 日韩欧美一级二级三级| 色狠狠av一区二区三区| 高清不卡一区二区在线| 美女mm1313爽爽久久久蜜臀| 一区二区在线观看免费| 国产视频一区在线播放| 欧美视频精品在线观看| 成人av网址在线观看| 看电影不卡的网站| 亚洲一区二区三区中文字幕| 国产精品日产欧美久久久久| 日韩一区二区三区在线| 欧美图区在线视频| 91农村精品一区二区在线| 国产激情一区二区三区四区| 久久国产婷婷国产香蕉| 日韩在线a电影| 日韩精品亚洲专区| 亚洲成人你懂的| 亚洲成av人综合在线观看| 一区二区久久久| 亚洲女爱视频在线| 亚洲精品一二三区| 亚洲男人电影天堂| 国产精品国产三级国产专播品爱网 | 视频一区二区欧美| 亚洲一区国产视频| 一区二区三区**美女毛片| 欧美韩国日本综合| 国产女人水真多18毛片18精品视频| 日韩一区二区三| 精品国产sm最大网站免费看| 欧美精品一区二区三区视频| 久久综合成人精品亚洲另类欧美| 日韩一卡二卡三卡四卡| 日韩欧美国产一区二区在线播放 | 美女视频一区二区| 奇米影视在线99精品| 久热成人在线视频| 国产一区欧美一区| 欧美特级限制片免费在线观看| 日本乱人伦一区| 欧洲精品在线观看| 911精品国产一区二区在线| 欧美揉bbbbb揉bbbbb| 91精品国产手机| 久久久久亚洲蜜桃| 国产精品传媒在线| 亚洲自拍偷拍av| 喷水一区二区三区| 国产成人免费视频精品含羞草妖精 | www日韩大片| 亚洲第四色夜色| 蜜桃视频一区二区| 在线亚洲欧美专区二区| 国产精品美女久久久久久久久久久| 日韩高清中文字幕一区| 色香蕉久久蜜桃| 国产女同互慰高潮91漫画| 毛片不卡一区二区| 自拍偷拍欧美激情| 在线观看日韩av先锋影音电影院| 久久美女高清视频| 精品综合久久久久久8888| 欧美日韩国产不卡| 亚洲资源中文字幕| 色88888久久久久久影院野外 | 一本色道a无线码一区v| 国产三级精品视频| 欧美一区二区三区的| 亚洲高清三级视频| 欧美日韩精品久久久| 香蕉加勒比综合久久| 欧美日韩成人综合| 视频一区国产视频| 欧美一级理论片|