亚洲欧美第一页_禁久久精品乱码_粉嫩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中文字幕| 久久久精品免费网站| 日韩黄色免费电影| 日韩欧美第一区| 国产在线播放一区三区四| 久久综合狠狠综合久久综合88| 久久99精品久久久久婷婷| 精品国产污污免费网站入口| 国产精品一区二区无线| 国产片一区二区三区| av一区二区久久| 夜夜嗨av一区二区三区网页| 911精品国产一区二区在线| 另类人妖一区二区av| 久久色在线观看| 91在线视频播放地址| 五月婷婷久久综合| 久久伊99综合婷婷久久伊| av一二三不卡影片| 视频一区视频二区在线观看| 2020国产精品自拍| 色婷婷久久综合| 另类的小说在线视频另类成人小视频在线| 久久色.com| 欧美性生活一区| 激情都市一区二区| 国产精品久久777777| 欧美久久久久久久久中文字幕| 国内精品久久久久影院色| 1000精品久久久久久久久| 在线成人午夜影院| 成人性生交大片免费看中文网站| 亚洲主播在线观看| 久久影院视频免费| 欧美日韩激情一区二区三区| 国产精品一区专区| 午夜精品影院在线观看| 欧美激情在线免费观看| 欧美一区二区视频观看视频 | 亚洲女厕所小便bbb| 欧美一区二区网站| 色欲综合视频天天天| 国产在线播放一区二区三区| 夜夜嗨av一区二区三区四季av| 久久久蜜臀国产一区二区| 精品视频一区二区三区免费| 国产a视频精品免费观看| 日韩国产一二三区| 亚洲精品一二三四区| 国产亚洲欧美日韩俺去了| 欧美疯狂性受xxxxx喷水图片| 成人高清免费观看| 国产呦萝稀缺另类资源| 日韩在线观看一区二区| 亚洲免费在线看| 国产精品看片你懂得| 精品国产成人系列| 欧美一区二区高清| 欧美丰满嫩嫩电影| 欧美午夜精品免费| 色天使色偷偷av一区二区| 成人av手机在线观看| 国产成人午夜电影网| 国产自产v一区二区三区c| 日本亚洲一区二区| 天天做天天摸天天爽国产一区| 亚洲自拍偷拍麻豆| 一区二区三区影院| 亚洲人成网站色在线观看| 欧美激情一区在线观看| 国产欧美日韩不卡| 欧美国产一区在线| 午夜精品福利久久久| 一区二区三区产品免费精品久久75| 欧美激情在线免费观看| 久久久99免费| 国产午夜精品福利| 国产精品日韩成人| 中文字幕一区二区在线播放| 国产精品福利一区二区| 中文字幕在线不卡一区| 中文字幕视频一区二区三区久| 国产精品久久久爽爽爽麻豆色哟哟| 国产女主播一区| 国产精品久久久久影视| 亚洲男同性恋视频| 亚洲一区二区三区四区的| 午夜精品一区二区三区电影天堂| 性欧美疯狂xxxxbbbb| 免费在线观看精品| 国产乱淫av一区二区三区| 丁香另类激情小说| 91亚洲男人天堂| 欧美日韩五月天| 日韩欧美色电影| 国产日韩精品一区二区三区| 国产精品毛片高清在线完整版| 亚洲精品视频在线观看免费 | 国产日韩欧美综合在线| 国产精品国产自产拍高清av王其| 亚洲三级久久久| 午夜精品一区在线观看| 久88久久88久久久| 99视频一区二区三区| 欧美曰成人黄网| 日韩免费高清视频| 国产精品视频第一区| 一区二区三区中文字幕电影| 日韩高清国产一区在线| 国产精品亚洲视频| 色综合久久中文字幕综合网 | 国产高清成人在线| 日本韩国欧美一区二区三区| 在线播放91灌醉迷j高跟美女| 精品国产一区二区国模嫣然| 国产精品青草久久| 亚洲小少妇裸体bbw| 精品一区二区三区久久| 91日韩在线专区| 日韩一区二区精品葵司在线| 国产精品乱码一区二三区小蝌蚪| 亚洲一卡二卡三卡四卡| 国产一区二区伦理| 欧美系列亚洲系列| 国产日韩欧美一区二区三区乱码| 亚洲在线视频一区| 国产99久久精品| 宅男在线国产精品| 亚洲三级免费观看| 狠狠v欧美v日韩v亚洲ⅴ| 91久久国产最好的精华液| 精品国产伦一区二区三区免费| 一区二区高清在线| 国产成人在线免费| 777xxx欧美| 一区二区三区国产精品| 国产a视频精品免费观看| 555夜色666亚洲国产免| 亚洲免费观看高清完整版在线观看熊 | 色综合久久综合网欧美综合网| 欧美一级黄色录像| 亚洲综合一区在线| 99久久国产综合精品麻豆| 精品国产免费人成电影在线观看四季| 一区二区三区中文在线观看| 欧美日韩亚洲不卡| 亚洲欧美偷拍卡通变态| 高清在线成人网| 欧美大尺度电影在线| 午夜精品久久久久久久| 91免费视频观看| 国产精品第一页第二页第三页| 另类调教123区| 欧美一三区三区四区免费在线看 | 国产做a爰片久久毛片| 91麻豆精品国产无毒不卡在线观看| 亚洲欧洲日产国码二区| 成人一级片网址| 国产欧美日韩亚州综合| 激情亚洲综合在线| 日韩精品一区二区三区视频播放| 日韩精品一卡二卡三卡四卡无卡| 色婷婷久久久久swag精品| 日韩理论片中文av| 99久久婷婷国产综合精品电影| 国产精品污网站| 处破女av一区二区| 国产精品久久久久三级| 成人小视频免费在线观看| 久久久久久久精| 国产精品一区在线观看乱码| 久久综合九色综合97婷婷女人| 久久aⅴ国产欧美74aaa| 精品少妇一区二区| 国产麻豆精品在线| 国产三级三级三级精品8ⅰ区| 国产精品一区专区| 中文字幕av一区 二区| av亚洲精华国产精华精华| 亚洲视频在线观看一区| 91欧美激情一区二区三区成人| 亚洲黄色av一区| 欧美精品xxxxbbbb| 黄一区二区三区| 国产精品热久久久久夜色精品三区 | 日日骚欧美日韩| 一区二区三区波多野结衣在线观看| 日本久久精品电影| 日韩vs国产vs欧美| 久久只精品国产| av资源网一区| 亚洲成人免费av| 2020日本不卡一区二区视频| 不卡高清视频专区| 亚洲午夜久久久久久久久电影网| 欧美一区二区免费视频| 国产乱码精品一区二区三区五月婷 | 7777精品伊人久久久大香线蕉的 | 欧美精品xxxxbbbb|