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

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

?? cache.c

?? be文件系統實現的源碼
?? C
?? 第 1 頁 / 共 5 頁
字號:
/*   This file contains the global device cache for the BeOS.  All   file system I/O comes through here.  The cache can handle blocks   of different sizes for multiple different underlying physical   devices.   The cache is organized as a hash table (for lookups by device   and block number) and two doubly-linked lists.  The normal   list is for "normal" blocks which are either clean or dirty.   The locked list is for blocks that are locked in the cache by   BFS.  The lists are LRU ordered.   Most of the work happens in the function cache_block_io() which   is quite lengthy.  The other functions of interest are get_ents()   which picks victims to be kicked out of the cache; flush_ents()   which does the work of flushing them; and set_blocks_info() which   handles cloning blocks and setting callbacks so that the BFS   journal will work properly.  If you want to modify this code it   will take some study but it's not too bad.  Do not think about   separating the list of clean and dirty blocks into two lists as   I did that already and it's slower.   Originally this cache code was written while listening to the album   "Ride the Lightning" by Metallica.  The current version was written   while listening to "Welcome to SkyValley" by Kyuss as well as an   ambient collection on the German label FAX.  Music helps a lot when   writing code.     THIS CODE COPYRIGHT DOMINIC GIAMPAOLO.  NO WARRANTY IS EXPRESSED    OR IMPLIED.  YOU MAY USE THIS CODE AND FREELY DISTRIBUTE IT FOR   NON-COMMERCIAL USE AS LONG AS THIS NOTICE REMAINS ATTACHED.   FOR COMMERCIAL USE, CONTACT DOMINIC GIAMPAOLO (dbg@be.com).   Dominic Giampaolo   dbg@be.com*/   #include <stdio.h>#include <stdlib.h>#include <memory.h>#include <string.h>#include <errno.h>#include <fcntl.h>#include <sys/types.h>#include <unistd.h>#ifdef __BEOS__#include <OS.h>#include <KernelExport.h>#endif#include "compat.h"#include "lock.h"#include "cache.h"#ifndef USER#define printf dprintf#endif#ifdef USER#define kprintf printf#endif/* forward prototypes */static int   flush_ents(cache_ent **ents, int n_ents);static int   do_dump(int argc, char **argv);static int   do_find_block(int argc, char **argv);static int   do_find_data(int argc, char **argv);static void  cache_flusher(void *arg, int phase);int chatty_io = 0;#define CHUNK (512 * 1024)   /* a hack to work around scsi driver bugs */size_tread_phys_blocks(int fd, fs_off_t bnum, void *data, uint num_blocks, int bsize){    size_t ret = 0;    size_t sum;        if (chatty_io)        printf("R: %8ld : %3d\n", bnum, num_blocks);    if (num_blocks * bsize < CHUNK)        ret = read_pos(fd, bnum * bsize, data, num_blocks * bsize);    else {        for(sum=0; (sum + CHUNK) <= (num_blocks * bsize); sum += CHUNK) {            ret = read_pos(fd, (bnum * bsize) + sum, data, CHUNK);            if (ret != CHUNK)                break;                    data = (void *)((char *)data + CHUNK);        }        if (ret == CHUNK && ((num_blocks * bsize) - sum) > 0) {            ret = read_pos(fd, (bnum * bsize) + sum, data,                           (num_blocks * bsize) - sum);            if (ret == (num_blocks * bsize) - sum)                ret = num_blocks * bsize;        } else if (ret == CHUNK) {            ret = num_blocks * bsize;        }    }    if (ret == num_blocks * bsize)        return 0;    else        return EBADF;}size_twrite_phys_blocks(int fd, fs_off_t bnum, void *data, uint num_blocks, int bsize){    size_t ret = 0;    size_t sum;    if (chatty_io)        printf("W: %8ld : %3d\n", bnum, num_blocks);    if (num_blocks * bsize < CHUNK)        ret = write_pos(fd, bnum * bsize, data, num_blocks * bsize);    else {        for(sum=0; (sum + CHUNK) <= (num_blocks * bsize); sum += CHUNK) {            ret = write_pos(fd, (bnum * bsize) + sum, data, CHUNK);            if (ret != CHUNK)                break;                    data = (void *)((char *)data + CHUNK);        }        if (ret == CHUNK && ((num_blocks * bsize) - sum) > 0) {            ret = write_pos(fd, (bnum * bsize) + sum, data,                            (num_blocks * bsize) - sum);            if (ret == (num_blocks * bsize) - sum)                ret = num_blocks * bsize;        } else if (ret == CHUNK) {            ret = num_blocks * bsize;        }    }    if (ret == num_blocks * bsize)        return 0;    else        return EBADF;}static intinit_hash_table(hash_table *ht){    ht->max   = HT_DEFAULT_MAX;    ht->mask  = ht->max - 1;    ht->num_elements = 0;    ht->table = (hash_ent **)calloc(ht->max, sizeof(hash_ent *));    if (ht->table == NULL)        return ENOMEM;    return 0;}static voidshutdown_hash_table(hash_table *ht){    int       i, hash_len;    hash_ent *he, *next;    for(i=0; i < ht->max; i++) {        he = ht->table[i];        for(hash_len=0; he; hash_len++, he=next) {            next = he->next;            free(he);        }    }    if (ht->table)        free(ht->table);    ht->table = NULL;}static voidprint_hash_stats(hash_table *ht){    int       i, hash_len, max = -1, sum = 0;    hash_ent *he, *next;    for(i=0; i < ht->max; i++) {        he = ht->table[i];        for(hash_len=0; he; hash_len++, he=next) {            next = he->next;        }        if (hash_len)            printf("bucket %3d : %3d\n", i, hash_len);        sum += hash_len;        if (hash_len > max)            max = hash_len;    }    printf("max # of chains: %d,  average chain length %d\n", max,sum/ht->max);}#define HASH(d, b)   ((((fs_off_t)d) << (sizeof(fs_off_t)*8 - 6)) | (b))static hash_ent *new_hash_ent(int dev, fs_off_t bnum, void *data){    hash_ent *he;    he = (hash_ent *)malloc(sizeof(*he));    if (he == NULL)        return NULL;    he->hash_val = HASH(dev, bnum);    he->dev      = dev;    he->bnum     = bnum;    he->data     = data;    he->next     = NULL;    return he;}static intgrow_hash_table(hash_table *ht){    int        i, omax, newsize, newmask;    fs_off_t      hash;    hash_ent **new_table, *he, *next;        if (ht->max & ht->mask) {        printf("*** hashtable size %d or mask %d looks weird!\n", ht->max,               ht->mask);    }    omax    = ht->max;    newsize = omax * 2;        /* have to grow in powers of two */    newmask = newsize - 1;    new_table = (hash_ent **)calloc(newsize, sizeof(hash_ent *));    if (new_table == NULL)        return ENOMEM;    for(i=0; i < omax; i++) {        for(he=ht->table[i]; he; he=next) {            hash = he->hash_val & newmask;            next = he->next;                        he->next        = new_table[hash];            new_table[hash] = he;        }    }        free(ht->table);    ht->table = new_table;    ht->max   = newsize;    ht->mask  = newmask;            return 0;}static inthash_insert(hash_table *ht, int dev, fs_off_t bnum, void *data){    fs_off_t    hash;    hash_ent *he, *curr;    hash = HASH(dev, bnum) & ht->mask;    curr = ht->table[hash];    for(; curr != NULL; curr=curr->next)        if (curr->dev == dev && curr->bnum == bnum)            break;    if (curr && curr->dev == dev && curr->bnum == bnum) {        printf("entry %d:%ld already in the hash table!\n", dev, bnum);        return EEXIST;    }    he = new_hash_ent(dev, bnum, data);    if (he == NULL)        return ENOMEM;        he->next        = ht->table[hash];    ht->table[hash] = he;    ht->num_elements++;    if (ht->num_elements >= ((ht->max * 3) / 4)) {        if (grow_hash_table(ht) != 0)            return ENOMEM;    }    return 0;}static void *hash_lookup(hash_table *ht, int dev, fs_off_t bnum){    hash_ent *he;    he = ht->table[HASH(dev, bnum) & ht->mask];    for(; he != NULL; he=he->next) {        if (he->dev == dev && he->bnum == bnum)            break;    }    if (he)        return he->data;    else        return NULL;}static void *hash_delete(hash_table *ht, int dev, fs_off_t bnum){    void     *data;    fs_off_t     hash;    hash_ent *he, *prev = NULL;    hash = HASH(dev, bnum) & ht->mask;    he = ht->table[hash];    for(; he != NULL; prev=he,he=he->next) {        if (he->dev == dev && he->bnum == bnum)            break;    }    if (he == NULL) {        printf("*** hash_delete: tried to delete non-existent block %d:%ld\n",               dev, bnum);        return NULL;    }    data = he->data;    if (ht->table[hash] == he)        ht->table[hash] = he->next;    else if (prev)        prev->next = he->next;    else        panic("hash table is inconsistent\n");    free(he);    ht->num_elements--;    return data;}/*  These are the global variables for the cache.*/  static block_cache  bc;#define       MAX_IOVECS  64           /* # of iovecs for use by cache code */static lock   iovec_lock;static struct iovec *iovec_pool[MAX_IOVECS];  /* each ptr is to an array of iovecs */static int    iovec_used[MAX_IOVECS];  /* non-zero == iovec is in use */#define NUM_FLUSH_BLOCKS 64    /* size of the iovec array pointed by each ptr */#define DEFAULT_READ_AHEAD_SIZE  (32 * 1024)static int read_ahead_size = DEFAULT_READ_AHEAD_SIZE;/* this array stores the size of each device so we can error check requests */#define MAX_DEVICES  256fs_off_t max_device_blocks[MAX_DEVICES];/* has the time of the last cache access so cache flushing doesn't interfere */static bigtime_t last_cache_access = 0;intinit_block_cache(int max_blocks, int flags){    memset(&bc, 0, sizeof(bc));    memset(iovec_pool, 0, sizeof(iovec_pool));    memset(iovec_used, 0, sizeof(iovec_used));    memset(&max_device_blocks, 0, sizeof(max_device_blocks));    if (init_hash_table(&bc.ht) != 0)        return ENOMEM;    bc.lock.s = iovec_lock.s = -1;    bc.max_blocks = max_blocks;    bc.flags      = flags;    if (new_lock(&bc.lock, "bollockcache") != 0)        goto err;    if (new_lock(&iovec_lock, "iovec_lock") != 0)        goto err;        /* allocate two of these up front so vm won't accidently re-enter itself */    iovec_pool[0] = (struct iovec *)malloc(sizeof(struct iovec)*NUM_FLUSH_BLOCKS);    iovec_pool[1] = (struct iovec *)malloc(sizeof(struct iovec)*NUM_FLUSH_BLOCKS);#ifdef DEBUG    add_debugger_command("bcache", do_dump, "dump the block cache list");    add_debugger_command("fblock", do_find_block, "find a block in the cache");    add_debugger_command("fdata",  do_find_data, "find a data block ptr in the cache");#endif#ifndef USER    register_kernel_daemon(cache_flusher, NULL, 3);#endif    return 0; err:    if (bc.lock.s >= 0)        free_lock(&bc.lock);    if (iovec_lock.s >= 0)        free_lock(&iovec_lock);    shutdown_hash_table(&bc.ht);    memset((void *)&bc, 0, sizeof(bc));    return ENOMEM;}static struct iovec *get_iovec_array(void){    int i;    struct iovec *iov;    LOCK(iovec_lock);    for(i=0; i < MAX_IOVECS; i++) {        if (iovec_used[i] == 0)            break;    }    if (i >= MAX_IOVECS)       /* uh-oh */        panic("cache: ran out of iovecs (pool 0x%x, used 0x%x)!\n",              &iovec_pool[0], &iovec_used[0]);        if (iovec_pool[i] == NULL) {        iovec_pool[i] = (struct iovec *)malloc(sizeof(struct iovec)*NUM_FLUSH_BLOCKS);        if (iovec_pool == NULL)            panic("can't allocate an iovec!\n");    }    iov = iovec_pool[i];    iovec_used[i] = 1;    UNLOCK(iovec_lock);    return iov;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产区在线观看成人精品| 国产乱人伦偷精品视频免下载| 精品一区二区免费看| 精品国产网站在线观看| 麻豆极品一区二区三区| 久久久影视传媒| 一本久久精品一区二区| 亚洲成av人片在线| 精品国产sm最大网站| 精品日本一线二线三线不卡| a4yy欧美一区二区三区| 日韩国产成人精品| 中文字幕av免费专区久久| 在线电影国产精品| 国产电影一区二区三区| 夜夜揉揉日日人人青青一国产精品| 欧美一区二区三区人| 成人av电影免费在线播放| 亚洲成人精品影院| 美女一区二区三区| 国产精品一区二区不卡| 一本一道久久a久久精品| 欧美日韩一区二区在线观看| 大桥未久av一区二区三区中文| 视频在线在亚洲| 亚洲欧美另类图片小说| 久久久久国产精品麻豆| 亚洲免费观看高清完整| 人人狠狠综合久久亚洲| 亚洲国产中文字幕| 亚洲视频中文字幕| 国产日本一区二区| 亚洲国产欧美日韩另类综合 | 亚洲美女一区二区三区| 午夜日韩在线电影| 亚洲另类春色校园小说| 中文字幕一区二区三区四区不卡 | 国产乱人伦偷精品视频免下载| 不卡的看片网站| 欧美精品日韩综合在线| 国产午夜亚洲精品理论片色戒| 欧美日韩1区2区| 欧美色涩在线第一页| 欧美精品一区二区三区视频| 亚洲精品乱码久久久久久久久 | 成+人+亚洲+综合天堂| 制服.丝袜.亚洲.另类.中文| 欧美高清精品3d| 国产精品三级av在线播放| 欧美国产日本视频| 日韩黄色小视频| 91蜜桃网址入口| 一本大道综合伊人精品热热| 久久久久九九视频| 日韩福利电影在线观看| 91视频xxxx| 亚洲国产精华液网站w | 国产美女在线观看一区| 国产一二三精品| 日韩一区二区三区电影| 国产亚洲一区二区三区四区| 肉色丝袜一区二区| 欧美日韩视频专区在线播放| 亚洲欧美视频在线观看视频| 成人性色生活片免费看爆迷你毛片| 欧美一区二区三区在线看| 一区二区三区在线观看网站| 不卡av免费在线观看| 国产欧美日韩精品一区| 国产91精品精华液一区二区三区| av不卡在线观看| 欧美激情中文不卡| 国产成人亚洲精品狼色在线| 日韩一区二区免费视频| 麻豆成人免费电影| 欧美一区二区人人喊爽| 青青草一区二区三区| 日韩亚洲欧美在线| 美女任你摸久久| 久久婷婷国产综合国色天香 | 欧美乱妇一区二区三区不卡视频| 亚洲激情五月婷婷| 在线观看av一区二区| 精品美女一区二区| 免费成人深夜小野草| 精品国产乱码久久久久久图片| 日本网站在线观看一区二区三区| 91精品国产91久久综合桃花 | 久久久精品欧美丰满| 国产a区久久久| 亚洲欧美激情视频在线观看一区二区三区| 成人黄动漫网站免费app| 中文字幕中文字幕一区| 麻豆精品精品国产自在97香蕉| 精品国产欧美一区二区| 国产高清一区日本| 亚洲欧美日韩久久精品| 欧美久久久久久久久中文字幕| 日本在线观看不卡视频| 国产丝袜美腿一区二区三区| www.性欧美| 日本一道高清亚洲日美韩| 欧美tk—视频vk| a美女胸又www黄视频久久| 亚洲柠檬福利资源导航| 欧美一区二区大片| 成人精品视频.| 亚洲一卡二卡三卡四卡| 91极品视觉盛宴| 亚洲欧美在线视频观看| 欧美日韩国产精品自在自线| 久久精品国产亚洲aⅴ | 国产呦萝稀缺另类资源| 中文字幕在线不卡视频| 欧美一激情一区二区三区| 成人av动漫网站| 麻豆91精品91久久久的内涵| 国产精品久久久久久久久久免费看| 欧美人与禽zozo性伦| 成人午夜激情视频| 蜜臀av一区二区在线免费观看| 中文字幕精品三区| 精品福利在线导航| 欧美日韩1234| 91麻豆国产福利精品| 国产在线乱码一区二区三区| 日韩精品一区二区三区视频在线观看 | 天堂在线一区二区| 中文文精品字幕一区二区| 欧美日韩国产免费一区二区 | 欧美一级理论性理论a| 一本大道av伊人久久综合| 国产一区福利在线| 免费在线看成人av| 亚洲综合免费观看高清完整版| 久久久蜜桃精品| 精品国产免费人成电影在线观看四季 | 最新不卡av在线| 久久久亚洲午夜电影| 91精品国模一区二区三区| 日本福利一区二区| 97精品国产97久久久久久久久久久久| 天天色图综合网| 欧美韩国日本一区| 亚洲欧美日韩一区二区| 一区二区视频在线| 麻豆精品在线播放| 亚洲国产精品一区二区www在线| 91网站在线播放| 欧美日韩成人综合天天影院| 日韩精品一区二区三区视频 | 一区二区三区自拍| 日本不卡一二三| 国产不卡视频在线观看| 欧美人妇做爰xxxⅹ性高电影| 精品国产成人系列| 亚洲精品免费一二三区| 久久国产婷婷国产香蕉| 色婷婷精品大在线视频| 日韩欧美你懂的| 一区二区三区在线看| 国内欧美视频一区二区 | av一区二区三区| 91超碰这里只有精品国产| 国产精品久久久久久户外露出| 蜜臀久久99精品久久久画质超高清| av在线播放成人| 久久久久国产精品人| 五月综合激情日本mⅴ| 91在线视频免费观看| 日韩欧美国产电影| 亚洲成人中文在线| 色又黄又爽网站www久久| 亚洲精品一区二区三区精华液| 亚洲福利电影网| 91国偷自产一区二区三区观看| 国产欧美1区2区3区| 欧美a级理论片| 欧美日韩高清一区二区| 亚洲乱码精品一二三四区日韩在线| 国内精品在线播放| 91精品国产免费| 亚洲不卡av一区二区三区| 色综合一区二区| 不卡视频在线看| 久久综合色8888| 蜜桃精品在线观看| 欧美一区午夜视频在线观看| 一区二区三区国产豹纹内裤在线| 懂色一区二区三区免费观看| 精品久久人人做人人爰| 美国毛片一区二区三区| 在线观看免费一区| 亚洲愉拍自拍另类高清精品| 波多野结衣中文字幕一区二区三区| 久久精品视频免费观看| 国产精品一区不卡| 国产精品高潮呻吟| 99精品国产一区二区三区不卡| 国产精品私人自拍|