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

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

?? reclaim.c

?? MMI層OBJ不能完全編譯
?? C
?? 第 1 頁 / 共 2 頁
字號:
/******************************************************************************
 * Flash File System (ffs)
 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com
 *
 * FFS core reclaim functionality
 *
 * $Id: reclaim.c 1.4.1.28 Thu, 08 Jan 2004 15:05:23 +0100 tsj $
 *
 ******************************************************************************/

#ifndef TARGET
#include "ffs.cfg"
#endif

#include "ffs/ffs.h"
#include "ffs/board/core.h"
#include "ffs/board/drv.h"
#include "ffs/board/ffstrace.h"

#include <stdlib.h>  // rand()

/******************************************************************************
 * Inodes Reclaim
 ******************************************************************************/

void inodes_recurse(iref_t i)
{
    iref_t pi;
    struct inode_s *ip, *newip;

    tw(tr(TR_BEGIN, TrReclaimLow, "inodes_recurse(%d) {\n", i));

    ip    = inode_addr(i);
    newip = (struct inode_s *) offset2addr(dev.binfo[fs.newinodes].offset) + i;
    
    // copy inode dir to new block, except child, sibling and copied
    ffsdrv.write((uint32*) &newip->location, (uint32*) &ip->location, sizeof(location_t));
    ffsdrv.write_halfword((uint16*) &newip->size,     ip->size);
    ffsdrv_write_byte    (&newip->flags,    ip->flags);
    ffsdrv.write_halfword((uint16*) &newip->sequence, ip->sequence);
    ffsdrv.write_halfword((uint16*) &newip->updates,  ip->updates);
    bstat[fs.newinodes].used++;

    // if no children of this dir, we have no more work to do
    if (get_child(ip) == (iref_t) IREF_NULL) {
        tw(tr(TR_END, TrReclaimLow, "}\n"));
        return;
    }

    pi = -i;
    i = get_child(ip);
    ip = inode_addr(i);

    do {
        tw(tr(TR_FUNC, TrReclaimLow, "pi = %d, i = %d", pi, i));

        tw(tr(TR_NULL, TrReclaimLow, ", size = %d, location = 0x%x", ip->size, 
              ip->location));
        
        tw(tr(TR_NULL, TrReclaimLow, ", name_addr = 0x%x",
              addr2name(offset2addr(location2offset(ip->location)))));
        
        if (is_object(ip, OTE_SEGMENT)) 
            tw(tr(TR_NULL, TrReclaimLow, ", (segment)\n"));
        
        else
            tw(tr(TR_NULL, TrReclaimLow, ", '%s'\n",
                  (ip->size ? addr2name(offset2addr(location2offset(ip->location)))
                   : "(cleaned)")));

        if (is_object_valid(ip))
        {
            if (is_object(ip, OTE_DIR)) {
                tw(tr(TR_NULL, TrReclaimLow, "recursing...\n", i));
                inodes_recurse(i);
            }
            else {
                tw(tr(TR_NULL, TrReclaimLow, "copying...\n"));
                // copy inode to new block, except child, sibling and copied
                newip = (struct inode_s *)
                    offset2addr(dev.binfo[fs.newinodes].offset) + i;
                ffsdrv.write((uint32*) &newip->location, (uint32*) &ip->location, sizeof(location_t));
                ffsdrv.write_halfword((uint16*) &newip->size,     ip->size);
                ffsdrv_write_byte    (&newip->flags,    ip->flags);
                ffsdrv.write_halfword((uint16*) &newip->sequence, ip->sequence);
                ffsdrv.write_halfword((uint16*) &newip->updates,  ip->updates);
                bstat[fs.newinodes].used++;
            }

            tw(tr(TR_FUNC, TrReclaimLow, "Linking: %d->%d\n",pi, i));
            // now write the child or sibling link of previous inode
            newip = (struct inode_s *)
                offset2addr(dev.binfo[fs.newinodes].offset);
            if (pi > 0)
                ffsdrv.write_halfword((uint16*) &(newip + pi)->sibling, i);
            else
                ffsdrv.write_halfword((uint16*) &(newip + (-pi))->child, i);
            
            pi = i; // save index of previous inode
            
            if (get_child(ip) != (iref_t) IREF_NULL && is_object(ip, OTE_FILE)) {
                iref_t pis, is;
                struct inode_s *ips;
                pis = i;
                ips = ip;

                tw(tr(TR_FUNC, TrReclaimLow, "Follow segment head\n"));
                // While child is valid
                while ((is = get_child(ips)) != (iref_t) IREF_NULL) {

                    // Get child
                    is = get_child(ips);
                    ips = inode_addr(is);
                    tw(tr(TR_FUNC, TrReclaimLow, "Child ok, got new child i = %d\n", is));
                    // While object not is valid
                    while (!is_object_valid(ips)) {
                        tw(tr(TR_FUNC, TrReclaimLow, "pi = %d, i = %d c(cleaned)\n", pis, is));
                        // If sibling are valid
                        if (get_sibling(ips) != (iref_t) IREF_NULL) {  
                            // Get sibling
                            is = get_sibling(ips);
                            ips = inode_addr(is);
                            tw(tr(TR_FUNC, TrReclaimLow, "Sibling ok, got new sibling i = %d\n", is));
                        }
                        else {
                            tw(tr(TR_FUNC, TrReclaimLow, "Sibling = FF (%d)\n", ips->sibling));
                            break;  // Nothing more todo, child and sibling = FF
                        }
                    }
                    // If object is valid
                    if (is_object_valid(ips)) {
                        tw(tr(TR_NULL, TrReclaimLow, "copying...\n"));
                        // copy inode to new block, except child, sibling and copied
                        newip = (struct inode_s *)
                            offset2addr(dev.binfo[fs.newinodes].offset) + is;
                        ffsdrv.write((uint32*) &newip->location, (uint32*) &ips->location, sizeof(location_t));
                        ffsdrv.write_halfword((uint16*) &newip->size,     ips->size);
                        ffsdrv_write_byte    (&newip->flags,              ips->flags);
                        ffsdrv.write_halfword((uint16*) &newip->sequence, ips->sequence);
                        ffsdrv.write_halfword((uint16*) &newip->updates,  ips->updates);
                        bstat[fs.newinodes].used++;
                        
                        tw(tr(TR_FUNC, TrReclaimLow, "Linking child: %d->%d\n",pis, is));
                        // now write the child link of previous inode
                        newip = (struct inode_s *)
                            offset2addr(dev.binfo[fs.newinodes].offset);
                        ffsdrv.write_halfword((uint16*) &(newip + (pis))->child, is);
                        
                        pis = is; // save index of previous inode   
               
                    }     
                    else {
                        tw(tr(TR_FUNC, TrReclaimLow, "Sibling = FF (%d, %d)\n", 
                              ips->sibling, ips->child));
                    }

                }
            }
        }       
        else {
            tw(tr(TR_NULL, TrReclaimLow, "(ignoring)\n"));
        }
        i = get_sibling(ip);
        ip = inode_addr(i);
            
    } while (i != (iref_t) IREF_NULL);
    
    tw(tr(TR_END, TrReclaimLow, "}\n"));
}

// Reclaim inodes, eg. move inodes to another block and erase old one.
effs_t inodes_reclaim(void)
{
    tw(tr(TR_BEGIN, TrIReclaim, "inodes_reclaim() {\n"));
    ttw(str(TTrRec, "irec{"));

    if (fs.initerror != EFFS_OK) {
        tw(tr(TR_END, TrIReclaim, "} %d\n", fs.initerror));
        ttw(ttr(TTrRec, "} %d" NL, fs.initerror));
        return fs.initerror;
    }

    if ((fs.newinodes = block_alloc(1, BF_COPYING)) < 0) {
        tw(tr(TR_END, TrIReclaim, "} %d\n", EFFS_NOBLOCKS));
        ttw(ttr(TTrRec, "} %d" NL, EFFS_NOBLOCKS));
        return EFFS_NOBLOCKS;
    }

    statistics_update_irec(bstat[fs.inodes].used - bstat[fs.inodes].lost, 
                           bstat[fs.inodes].lost);

    // copy all inodes...
    bstat[fs.newinodes].used = 0;
    inodes_recurse(fs.root);

    // The replacement inodes are not copied to the new block thus the table
    // must be cleaned
    memset(fs.repi_table, 0, sizeof(fs.repi_table));

    block_commit();

    tw(tr(TR_END, TrIReclaim, "} 0\n"));
    ttw(str(TTrRec, "} 0" NL));

    return EFFS_OK;
}

// Inode -> Lost, Copying -> Inode, Lost -> Free
void block_commit(void)
{
    int oldinodes = fs.inodes;

    tw(tr(TR_BEGIN, TrIReclaim, "block_commit(%d -> %d) {\n", 
       oldinodes, fs.newinodes));
    ttw(ttr(TTrRec, "block_commit(%d -> %d) {\n" NL, 
       oldinodes, fs.newinodes)); 

    block_flags_write(oldinodes, BF_LOST);
 
    // Validate new block as an inodes block
    block_flags_write(fs.newinodes, BF_INODES);

    bstat[fs.newinodes].lost = 0;
    bstat[fs.newinodes].objects = 1;
    inodes_set(fs.newinodes);

    // Free old inodes block
    block_free(oldinodes);

    ttw(str(TTrRec, "} 0" NL));
    tw(tr(TR_END, TrIReclaim, "}\n"));
}


/******************************************************************************
 * Data Reclaim
 ******************************************************************************/

// Important note: We must NOT perform a data reclaim when we are in the
// process of creating the journal file!

// Reclaim a data block, eg. move files to other blocks and erase old one.
// When the reclaim is done, we must completely delete the old inodes which
// are pointing into the old data sector which is going to be erased now.
iref_t data_reclaim(void)
{
    iref_t error;

    tw(tr(TR_BEGIN, TrDReclaim, "data_reclaim() {\n"));

    if (fs.initerror != EFFS_OK) {
        tw(tr(TR_END, TrDReclaim, "} %d\n", fs.initerror));
        return fs.initerror;
    }

    error = data_reclaim_try();

    tw(tr(TR_END, TrDReclaim, "} (data_reclaim) %d\n", error));

    return error;
}

// This algorithm will reclaim a block when it exceeds a delta age of more
// than DAGE_MAX and the age gain is more than DAGE_MAX. When the block is
// younger than DAGE_MAX, the agegain needed (for accepting the reclaim) is
// decreased linearly with the block's increase in delta age.
//
// The algorithm is extended a wee bit in order to avoid data reclaim
// storms, i.e. when many static data blocks reach DAGE_MAX at the same
// time. What we do is that we allow a few early age based reclaims this
// way: The probability that a block is reclaimed early gets exponentially
// higher as the block's delta age is closing in on DAGE_MAX - provided that
// the agegain is good.
int dage_max_reached(int dage_blk, int agegain)
{
    int reclaim, early, log2, mask;

    tw(tr(TR_BEGIN, TrDReclaim, "young(%d, %d) {\n", dage_blk, agegain));
    
    // Simple algorithm
    reclaim = (dage_blk + agegain - 2 * FFS_DAGE_MAX >= 0);

    // Early exponential probability based reclaim
    early = FFS_DAGE_MAX - dage_blk;
    if (agegain > dage_blk - 4 && 0 < early && early <= FFS_DAGE_EARLY_WIDTH) {
        if (early < 4)
            early = 2;
        if (early < FFS_DAGE_EARLY_WIDTH) {
            // Now make an exponential probability distributon by
            // generating a bitmask of a size relative to (dage_blk
            // - DAGE_EARLY_WIDTH)
            log2 = -1;
            while (early > 0) {
                early >>= 1;
                log2++;
            }
            reclaim = log2;
            
            mask = (1 << (log2 + 1)) - 1;
            reclaim = ((rand() & mask) == 0);
        }
    }

    // Do not perform a reclaim unless we gain a certain minimum
    if (agegain < FFS_DAGE_GAIN_MIN)
        reclaim = 0;

    tw(tr(TR_END, TrDReclaim, "} (%d)\n", reclaim));
    return reclaim;
}


// Find a suitable block to reclaim. On success, return the number of bytes
// actually reclaimed. Otherwise, on failure, return a (negative) error.
int data_reclaim_try(void)
{
    int result = 0, reserved_ok = 0;
    bref_t b, blocks_free;
    bref_t brc_young_b, brc_lost_b;

    blocksize_t brc_lost_lost;
    blocksize_t unused, lost, lost_total, free;

    age_t brc_young_dage, free_dage, dage;
    struct block_header_s *bhp;
    // Note gain can be negative if the free block is younger than the
    // youngest data block
    int age_gain; 

    tw(tr(TR_BEGIN, TrDReclaim, "data_reclaim_try() {\n"));
    ttw(str(TTrRec, "drec{" NL));
    // While searching for a block to reclaim, we maintain two block reclaim
    // candidates (brc): 
    //
    // 1- The youngest block, e.g. the one with the largest age distance to
    // fs.age_max. This is to ensure that blocks with a high amount of
    // static data are used for wear-leveling.
    //
    // 2- The block with the highest amount of lost bytes. Note this
    // candidate is also used if the amount of free space is below
    // RESERVED_LOW.
    
    // This counts free blocks, so we initialize to number of blocks minus
    // one for inodes.
    blocks_free = dev.numblocks - 1;

    // Initialize Block Reclaim Candidate (brc) variables
    brc_lost_b   = -1; brc_lost_lost   = 0;
    brc_young_b  = -1; brc_young_dage = 0;  free_dage  = 0;

    lost_total   = 0;

    tw(tr(TR_FUNC, TrDReclaim,
          "blk  unused    lost  w/age   age dist  objs\n"));
    for (b = 0; b < dev.numblocks; b++)
    {
        bhp = (struct block_header_s *) offset2addr(dev.binfo[b].offset);

        if (is_block(b, BF_IS_DATA))
        {
            // Record number of lost bytes and number of unused bytes,
            // eg. total space that would be freed if this block was
            // reclaimed
            lost   = bstat[b].lost;
            unused = dev.blocksize - (bstat[b].used - bstat[b].lost);
            free   = dev.blocksize - bstat[b].used;

            lost_total   += lost;

            if (free >= RESERVED_LOW) 
                reserved_ok = 1;
            if (lost > brc_lost_lost) {
                brc_lost_b = b;
                brc_lost_lost = lost;
            }
            tw(tr(TR_FUNC, TrDReclaim, "%3d %7d %7d ", b, unused, lost));

            dage = saturate_dage(fs.age_max - bhp->age);

            tw(tr(TR_NULL, TrDReclaim, "%6d %5d %4d   %3d\n",
                  lost, bhp->age, dage, bstat[b].objects));

            if (dage >= brc_young_dage) {
                brc_young_b = b;
                brc_young_dage = dage;
            }
            blocks_free--;
        }
        else if (is_block(b, BF_IS_FREE)) {
            // Find youngest free block (in must cases we will only have one free b)
            dage = saturate_dage(fs.age_max - bhp->age);

            if (dage >= free_dage)
                free_dage = dage;   // Delta age of youngest free block
        }
    }
    tw(tr(TR_FUNC, TrDReclaim, "sum %7d\n", lost_total));
    tw(tr(TR_FUNC, TrDReclaim, "blocks_free = %d, fs.age_max = %d\n", blocks_free, fs.age_max));

    age_gain = brc_young_dage - free_dage; // Same as free - block age

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久成人免费电影| 国产亚洲精品中文字幕| 亚洲女同一区二区| av男人天堂一区| 国产精品久久777777| 国产伦理精品不卡| 久久亚区不卡日本| 久久精品国产亚洲一区二区三区| 91精品国产91久久久久久一区二区| 亚洲一区二区五区| 成人av午夜电影| 中文字幕一区在线观看视频| 99久久国产综合精品麻豆| 亚洲视频中文字幕| 在线免费av一区| 亚洲成人自拍一区| 日韩欧美三级在线| 国产高清久久久| 久久亚洲私人国产精品va媚药| 久久99精品国产麻豆婷婷 | 午夜精品久久久久久| 91九色最新地址| 一区二区三区四区视频精品免费| 91免费国产在线| 亚洲大型综合色站| 精品人伦一区二区色婷婷| 国产成人av电影在线观看| 久久久久久久久久看片| va亚洲va日韩不卡在线观看| 亚洲综合在线免费观看| 欧美一区二区在线播放| 天堂在线亚洲视频| 欧美tickling挠脚心丨vk| 国产91清纯白嫩初高中在线观看| 最新热久久免费视频| 欧美性xxxxxx少妇| 韩国一区二区视频| 综合av第一页| 日韩欧美国产高清| 成人av网站在线观看免费| 亚洲成人资源在线| 久久久午夜电影| 欧美在线一区二区| 国产麻豆欧美日韩一区| 亚洲欧美日韩精品久久久久| 91精品国产91久久久久久最新毛片| 国产不卡视频在线播放| 亚洲成人综合视频| 久久精品一区四区| 欧美日韩不卡一区| 七七婷婷婷婷精品国产| 国产精品久久三区| 91精品福利在线一区二区三区 | 日韩三级中文字幕| 国产91在线看| 香蕉久久一区二区不卡无毒影院 | 青草av.久久免费一区| 亚洲精品一区二区三区在线观看| 99精品国产热久久91蜜凸| 青青草97国产精品免费观看 | 中文字幕在线播放不卡一区| 日韩欧美一区二区免费| 国产成人精品亚洲777人妖 | 777亚洲妇女| 成人v精品蜜桃久久一区| 亚洲成av人片在线| 国产精品久久久久久久久动漫| 日韩欧美视频一区| 在线免费观看一区| 99国产精品久久久| 日本视频在线一区| 亚洲一级电影视频| 亚洲天天做日日做天天谢日日欢 | 国产精品天干天干在线综合| 国产日韩欧美不卡在线| 久久色在线视频| wwwwww.欧美系列| 久久久久久久性| 日韩精品一区二区三区在线观看| 精品少妇一区二区| 久久久蜜桃精品| 国产精品欧美久久久久无广告 | 欧美日韩一级黄| 欧美精品日日鲁夜夜添| 欧美日韩精品福利| 欧美精品久久天天躁| 欧美日韩电影在线| 日韩一级成人av| 精品成人私密视频| 国产精品欧美精品| 亚洲视频免费看| 视频一区中文字幕国产| 蜜桃久久久久久| 国产精品中文字幕日韩精品| 国产福利精品一区| 97久久超碰精品国产| 欧美中文字幕一二三区视频| 91精品国产日韩91久久久久久| 日韩精品中文字幕一区二区三区| 欧美成人免费网站| 国产精品第四页| 亚洲午夜精品久久久久久久久| 日韩国产精品久久| 国内精品国产成人国产三级粉色| 国产成人综合视频| 欧洲国产伦久久久久久久| 欧美一区二区网站| 久久久99精品免费观看不卡| 亚洲同性同志一二三专区| 日韩综合小视频| 国产成人丝袜美腿| 色8久久人人97超碰香蕉987| 欧美一区二区视频在线观看| 国产欧美视频一区二区三区| 亚洲综合无码一区二区| 精品一区二区三区日韩| av一区二区三区黑人| 欧美一三区三区四区免费在线看 | eeuss影院一区二区三区 | 在线观看亚洲精品视频| 日韩欧美专区在线| 国产精品精品国产色婷婷| 日本视频一区二区| www.av亚洲| 日韩精品一区二区三区视频 | 亚洲一区二区美女| 国产麻豆精品95视频| 欧美日韩国产成人在线91 | 国产精品久久久久久久久免费丝袜 | 99精品视频在线观看| 欧美二区在线观看| 亚洲视频一区二区在线| 久草中文综合在线| 欧美日韩不卡视频| 亚洲青青青在线视频| 国内精品在线播放| 欧美老年两性高潮| 成人免费一区二区三区在线观看| 美女视频第一区二区三区免费观看网站| 9色porny自拍视频一区二区| 日韩女优毛片在线| 亚洲午夜av在线| 色视频成人在线观看免| 国产调教视频一区| 激情综合色播激情啊| 777欧美精品| 亚洲国产视频一区二区| 97国产精品videossex| 久久精品欧美一区二区三区不卡| 蜜桃久久久久久| 8v天堂国产在线一区二区| 亚洲一区二区在线观看视频| 91丝袜呻吟高潮美腿白嫩在线观看| 久久综合久久99| 久久国产三级精品| 777xxx欧美| 日本三级韩国三级欧美三级| 欧美日韩久久久| 亚洲国产精品欧美一二99| 色哟哟精品一区| 亚洲三级电影网站| 成人av影视在线观看| 国产精品国产三级国产三级人妇| 国产乱子伦一区二区三区国色天香 | 国产综合色视频| 26uuu成人网一区二区三区| 免费观看在线色综合| 欧美日韩夫妻久久| 日韩国产欧美一区二区三区| 欧美精品黑人性xxxx| 偷偷要91色婷婷| 欧美日韩一区二区不卡| 亚洲a一区二区| 制服丝袜亚洲播放| 免费在线成人网| 欧美va亚洲va香蕉在线| 国产一区日韩二区欧美三区| 久久久久免费观看| 成人激情文学综合网| 中文字幕一区二区5566日韩| 一本一道波多野结衣一区二区| 亚洲婷婷在线视频| 欧美三级日韩三级| 蜜桃视频免费观看一区| 久久精品视频网| av电影在线观看完整版一区二区| 亚洲激情av在线| 欧美日韩久久一区二区| 精品中文字幕一区二区小辣椒| 久久久精品tv| 色中色一区二区| 日本不卡一区二区三区高清视频| 欧美变态凌虐bdsm| www.99精品| 日韩电影在线一区二区| 久久久久久久久久看片| 一本大道久久a久久综合| 日韩国产欧美一区二区三区| 国产亚洲婷婷免费| 日本乱人伦aⅴ精品|