資源簡(jiǎn)介
linux0.01版本的內(nèi)核源碼,帶中文注釋,非常適合學(xué)習(xí)linux

代碼片段和文件信息
/*
*?linux/fs/bitmap.c
*
*?(C)?1991?Linus?Torvalds
*/
/*?bitmap.c?contains?the?code?that?handles?the?inode?and?block?bitmaps?*/
/*?bitmap.c?程序含有處理i?節(jié)點(diǎn)和磁盤塊位圖的代碼?*/
#include? //?字符串頭文件。主要定義了一些有關(guān)字符串操作的嵌入函數(shù)。
//?主要使用了其中的memset()函數(shù)。
#include? //?調(diào)度程序頭文件,定義了任務(wù)結(jié)構(gòu)task_struct、初始任務(wù)0?的數(shù)據(jù),
//?還有一些有關(guān)描述符參數(shù)設(shè)置和獲取的嵌入式匯編函數(shù)宏語句。
#include? //?內(nèi)核頭文件。含有一些內(nèi)核常用函數(shù)的原形定義。
////?將指定地址(addr)處的一塊內(nèi)存清零。嵌入?yún)R編程序宏。
//?輸入:eax?=?0,ecx?=?數(shù)據(jù)塊大小BLOCK_SIZE/4,edi?=?addr。
#define?clear_block(addr)?\
__asm__(?“cld\n\t“?\ //?清方向位。
“rep\n\t“?\ //?重復(fù)執(zhí)行存儲(chǔ)數(shù)據(jù)(0)。
“stosl“::“a“?(0)?“c“?(BLOCK_SIZE?/?4)?“D“?((long)?(addr)):“cx“?“di“)
////?置位指定地址開始的第nr?個(gè)位偏移處的比特位(nr?可以大于32!)。返回原比特位(0?或1)。
//?輸入:%0?-?eax(返回值),%1?-?eax(0);%2?-?nr,位偏移值;%3?-?(addr),addr?的內(nèi)容。
#define?set_bit(nraddr)?({\
register?int?res?__asm__(?“ax“);?\
__asm__?__volatile__(?“btsl?%2%3\n\tsetb?%%al“:?\
“=a“?(res):?““?(0)?“r“?(nr)?“m“?(*(addr)));?\
res;})
////?復(fù)位指定地址開始的第nr?位偏移處的比特位。返回原比特位的反碼(1?或0)。
//?輸入:%0?-?eax(返回值),%1?-?eax(0);%2?-?nr,位偏移值;%3?-?(addr),addr?的內(nèi)容。
#define?clear_bit(nraddr)?({\
register?int?res?__asm__(?“ax“);?\
__asm__?__volatile__(?“btrl?%2%3\n\tsetnb?%%al“:?\
“=a“?(res):?““?(0)?“r“?(nr)?“m“?(*(addr)));?\
res;})
////?從addr?開始尋找第1?個(gè)0?值比特位。
//?輸入:%0?-?ecx(返回值);%1?-?ecx(0);%2?-?esi(addr)。
//?在addr?指定地址開始的位圖中尋找第1?個(gè)是0?的比特位,并將其距離addr?的比特位偏移值返回。
#define?find_first_zero(addr)?({?\
int?__res;?\
__asm__(?“cld\n“?\ //?清方向位。
??“1:\tlodsl\n\t“?\ //?取[esi]??eax。
??“notl?%%eax\n\t“?\ //?eax?中每位取反。
??“bsfl?%%eax%%edx\n\t“?\ //?從位0?掃描eax?中是1?的第1?個(gè)位,其偏移值??edx。
??“je?2f\n\t“?\ //?如果eax?中全是0,則向前跳轉(zhuǎn)到標(biāo)號(hào)2?處(40?行)。
??“addl?%%edx%%ecx\n\t“?\ //?偏移值加入ecx(ecx?中是位圖中首個(gè)是0?的比特位的偏移值)
??“jmp?3f\n“?\ //?向前跳轉(zhuǎn)到標(biāo)號(hào)3?處(結(jié)束)。
??“2:\taddl?$32%%ecx\n\t“?\ //?沒有找到0?比特位,則將ecx?加上1?個(gè)長(zhǎng)字的位偏移量32。
??“cmpl?$8192%%ecx\n\t“?\ //?已經(jīng)掃描了8192?位(1024?字節(jié))了嗎?
??“jl?1b\n“?\ //?若還沒有掃描完1?塊數(shù)據(jù),則向前跳轉(zhuǎn)到標(biāo)號(hào)1?處,繼續(xù)。
??“3:“?\ //?結(jié)束。此時(shí)ecx?中是位偏移量。
:?“=c“?(__res):?“c“?(0)?“S“?(addr):“ax“?“dx“?“si“);
__res;
}
)
////?釋放設(shè)備dev?上數(shù)據(jù)區(qū)中的邏輯塊block。
//?復(fù)位指定邏輯塊block?的邏輯塊位圖比特位。
//?參數(shù):dev?是設(shè)備號(hào),block?是邏輯塊號(hào)(盤塊號(hào))。
?????void?free_block?(int?dev?int?block)
?????{
???????struct?super_block?*sb;
???????struct?buffer_head?*bh;
//?取指定設(shè)備dev?的超級(jí)塊,如果指定設(shè)備不存在,則出錯(cuò)死機(jī)。
???????if?(!(sb?=?get_super?(dev)))
?panic?(“trying?to?free?block?on?nonexistent?device“);
//?若邏輯塊號(hào)小于首個(gè)邏輯塊號(hào)或者大于設(shè)備上總邏輯塊數(shù),則出錯(cuò),死機(jī)。
???????if?(block?s_firstdatazone?||?block?>=?sb->s_nzones)
?panic?(“trying?to?free?block?not?in?datazone“);
//?從hash?表中尋找該塊數(shù)據(jù)。若找到了則判斷其有效性,并清已修改和更新標(biāo)志,釋放該數(shù)據(jù)塊。
//?該段代碼的主要用途是如果該邏輯塊當(dāng)前存在于高速緩沖中,就釋放對(duì)應(yīng)的緩沖塊。
???????bh?=?get_hash_table?(dev?block);
???????if?(bh)
?{
???if?(bh->b_count?!=?1)
?????{
???????printk?(“trying?to?free?block?(%04x:%d)?count=%d\n“
???????dev?block?bh->b_count);
???????return;
?????}
???bh->b_dirt?=?0; //?復(fù)位臟(已修改)標(biāo)志位。
???bh->b_uptodate?=?0; //?復(fù)位更新標(biāo)志。
???brelse?(bh);
?}
//?計(jì)算block?在數(shù)據(jù)區(qū)開始算起的數(shù)據(jù)邏輯塊號(hào)(從1?開始計(jì)數(shù))。然后對(duì)邏輯塊(區(qū)塊)位圖進(jìn)行操作,
//?復(fù)位對(duì)應(yīng)的比特位。若對(duì)應(yīng)比特位原來即是0,則出錯(cuò),死機(jī)。
???????block?-=?sb->s_firstdatazone?-?1; //?block?=?block?-?(?-1)?;
?????
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2009-08-15?18:29??boot\
?????文件???????12790??2004-01-08?21:38??boot\bootsect.s
?????文件???????13541??2004-01-08?21:38??boot\head.s
?????文件???????12721??2004-01-08?21:38??boot\setup.s
?????目錄???????????0??2009-08-15?18:29??fs\
?????文件????????8658??2004-09-02?13:12??fs\bitmap.c
?????文件????????4046??2004-09-02?13:12??fs\block_dev.c
?????文件???????18130??2004-09-02?13:12??fs\buffer.c
?????文件????????4193??2004-09-02?13:12??fs\char_dev.c
?????文件???????19351??2004-09-02?13:12??fs\exec.c
?????文件????????3413??2004-09-02?13:12??fs\fcntl.c
?????文件????????4933??2004-09-02?13:12??fs\file_dev.c
?????文件?????????209??2004-09-02?13:12??fs\file_table.c
?????文件???????15283??2004-09-02?13:12??fs\inode.c
?????文件????????1987??2004-09-02?13:12??fs\ioctl.c
?????文件????????6964??2004-01-08?21:45??fs\Makefile
?????文件???????38095??2004-09-02?13:12??fs\namei.c
?????文件???????10243??2004-09-02?13:12??fs\open.c
?????文件????????5552??2004-09-02?13:12??fs\pipe.c
?????文件????????6003??2004-09-02?13:12??fs\read_write.c
?????文件????????2756??2004-09-02?13:12??fs\stat.c
?????文件???????13896??2004-09-02?13:12??fs\super.c
?????文件????????2521??2004-09-02?13:12??fs\truncate.c
?????目錄???????????0??2009-08-15?18:29??include\
?????文件????????8415??2004-09-02?13:14??include\a.out.h
?????目錄???????????0??2009-08-15?18:29??include\asm\
?????文件?????????772??2004-09-02?13:14??include\asm\io.h
?????文件????????1057??2004-01-08?22:13??include\asm\memory.h
?????文件????????2556??2004-09-02?13:14??include\asm\segment.h
?????文件????????4176??2004-09-02?13:14??include\asm\system.h
?????文件?????????589??2004-09-02?13:14??include\const.h
............此處省略80個(gè)文件信息
評(píng)論
共有 條評(píng)論