91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 113KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-01
  • 語言: 其他
  • 標簽: xv6??

資源簡介

xv6是MIT寫的一個微linux,可以用來學習操作系統

資源截圖

代碼片段和文件信息

//?Buffer?cache.
//
//?The?buffer?cache?is?a?linked?list?of?buf?structures?holding
//?cached?copies?of?disk?block?contents.??Caching?disk?blocks
//?in?memory?reduces?the?number?of?disk?reads?and?also?provides
//?a?synchronization?point?for?disk?blocks?used?by?multiple?processes.
//?
//?Interface:
//?*?To?get?a?buffer?for?a?particular?disk?block?call?bread.
//?*?After?changing?buffer?data?call?bwrite?to?write?it?to?disk.
//?*?When?done?with?the?buffer?call?brelse.
//?*?Do?not?use?the?buffer?after?calling?brelse.
//?*?Only?one?process?at?a?time?can?use?a?buffer
//?????so?do?not?keep?them?longer?than?necessary.
//?
//?The?implementation?uses?three?state?flags?internally:
//?*?B_BUSY:?the?block?has?been?returned?from?bread
//?????and?has?not?been?passed?back?to?brelse.??
//?*?B_VALID:?the?buffer?data?has?been?read?from?the?disk.
//?*?B_DIRTY:?the?buffer?data?has?been?modified
//?????and?needs?to?be?written?to?disk.

#include?“types.h“
#include?“defs.h“
#include?“param.h“
#include?“spinlock.h“
#include?“buf.h“

struct?{
??struct?spinlock?lock;
??struct?buf?buf[NBUF];

??//?linked?list?of?all?buffers?through?prev/next.
??//?head.next?is?most?recently?used.
??struct?buf?head;
}?bcache;

void
binit(void)
{
??struct?buf?*b;

??initlock(&bcache.lock?“bcache“);

//PAGEBREAK!
??//?Create?linked?list?of?buffers
??bcache.head.prev?=?&bcache.head;
??bcache.head.next?=?&bcache.head;
??for(b?=?bcache.buf;?b?????b->next?=?bcache.head.next;
????b->prev?=?&bcache.head;
????b->dev?=?-1;
????bcache.head.next->prev?=?b;
????bcache.head.next?=?b;
??}
}

//?Look?through?buffer?cache?for?sector?on?device?dev.
//?If?not?found?allocate?fresh?block.
//?In?either?case?return?B_BUSY?buffer.
static?struct?buf*
bget(uint?dev?uint?sector)
{
??struct?buf?*b;

??acquire(&bcache.lock);

?loop:
??//?Is?the?sector?already?cached?
??for(b?=?bcache.head.next;?b?!=?&bcache.head;?b?=?b->next){
????if(b->dev?==?dev?&&?b->sector?==?sector){
??????if(!(b->flags?&?B_BUSY)){
????????b->flags?|=?B_BUSY;
????????release(&bcache.lock);
????????return?b;
??????}
??????sleep(b?&bcache.lock);
??????goto?loop;
????}
??}

??//?Not?cached;?recycle?some?non-busy?and?clean?buffer.
??for(b?=?bcache.head.prev;?b?!=?&bcache.head;?b?=?b->prev){
????if((b->flags?&?B_BUSY)?==?0?&&?(b->flags?&?B_DIRTY)?==?0){
??????b->dev?=?dev;
??????b->sector?=?sector;
??????b->flags?=?B_BUSY;
??????release(&bcache.lock);
??????return?b;
????}
??}
??panic(“bget:?no?buffers“);
}

//?Return?a?B_BUSY?buf?with?the?contents?of?the?indicated?disk?sector.
struct?buf*
bread(uint?dev?uint?sector)
{
??struct?buf?*b;

??b?=?bget(dev?sector);
??if(!(b->flags?&?B_VALID))
????iderw(b);
??return?b;
}

//?Write?b‘s?contents?to?disk.??Must?be?B_BUSY.
void
bwrite(struct?buf?*b)
{
??if((b->flags?&?B_BUSY)?==?0)
????panic(“bwrite“);
??b->flags?|=?B_DIRTY;
??iderw(b);
}

//?Release?a?B_BUSY?buffer.
//?Move?to?the?head?of?the?MRU?list.
void
brelse(struct?buf?*b)
{
??if((b->flags?&?B_BUSY)?==?0)
????panic(“brels

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-03-04?21:16??xv6-master\
?????文件?????????130??2013-03-04?21:16??xv6-master\.cvsignore
?????文件??????????86??2013-03-04?21:16??xv6-master\.dir-locals.el
?????文件?????????682??2013-03-04?21:16??xv6-master\.gdbinit.tmpl
?????文件?????????118??2013-03-04?21:16??xv6-master\.gitignore
?????文件?????????128??2013-03-04?21:16??xv6-master\BUGS
?????文件????????1174??2013-03-04?21:16??xv6-master\LICENSE
?????文件????????7933??2013-03-04?21:16??xv6-master\Makefile
?????文件????????4008??2013-03-04?21:16??xv6-master\Notes
?????文件????????1929??2013-03-04?21:16??xv6-master\README
?????文件????????3925??2013-03-04?21:16??xv6-master\TRICKS
?????文件?????????936??2013-03-04?21:16??xv6-master\asm.h
?????文件????????3262??2013-03-04?21:16??xv6-master\bio.c
?????文件????????2979??2013-03-04?21:16??xv6-master\bootasm.S
?????文件????????2255??2013-03-04?21:16??xv6-master\bootmain.c
?????文件?????????340??2013-03-04?21:16??xv6-master\buf.h
?????文件?????????513??2013-03-04?21:16??xv6-master\cat.c
?????文件????????5158??2013-03-04?21:16??xv6-master\console.c
?????文件?????????934??2013-03-04?21:16??xv6-master\cuth
?????文件????????5257??2013-03-04?21:16??xv6-master\defs.h
?????文件???????33514??2013-03-04?21:16??xv6-master\dot-bochsrc
?????文件?????????198??2013-03-04?21:16??xv6-master\echo.c
?????文件?????????755??2013-03-04?21:16??xv6-master\elf.h
?????文件????????1613??2013-03-04?21:16??xv6-master\entry.S
?????文件????????2044??2013-03-04?21:16??xv6-master\entryother.S
?????文件????????2307??2013-03-04?21:16??xv6-master\exec.c
?????文件??????????96??2013-03-04?21:16??xv6-master\fcntl.h
?????文件????????2809??2013-03-04?21:16??xv6-master\file.c
?????文件?????????767??2013-03-04?21:16??xv6-master\file.h
?????文件?????????766??2013-03-04?21:16??xv6-master\forktest.c
?????文件???????14877??2013-03-04?21:16??xv6-master\fs.c
............此處省略71個文件信息

評論

共有 條評論