linux基礎(chǔ)知識-linux的文件系統(tǒng)_第1頁
linux基礎(chǔ)知識-linux的文件系統(tǒng)_第2頁
linux基礎(chǔ)知識-linux的文件系統(tǒng)_第3頁
linux基礎(chǔ)知識-linux的文件系統(tǒng)_第4頁
linux基礎(chǔ)知識-linux的文件系統(tǒng)_第5頁
已閱讀5頁,還剩28頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

Linux的文件系統(tǒng)課程目標(biāo):?操作系統(tǒng)的運(yùn)行級別?文件系統(tǒng)架構(gòu)?設(shè)備管理Linux文件系統(tǒng)//bin/sbin/usr/var/etc/lib/home/tmp/optbinlocalsrcrc.dnamedhttpdrc5.dftprc3.dinit.dbinetcpubLinux各分區(qū)功能/boot系統(tǒng)啟動過程中使用的文件/usr分區(qū),系統(tǒng)存放軟件的地方/home分區(qū),是用戶的home目錄所在地,/var/log分區(qū),是系統(tǒng)日志記錄分區(qū)/tmp分區(qū),用來存放臨時文件/dev分區(qū),存放設(shè)備文件。/opt分區(qū),存放可選的安裝的軟件。/sbin分區(qū),存放標(biāo)準(zhǔn)系統(tǒng)管理文件。/bin分區(qū),存放標(biāo)準(zhǔn)系統(tǒng)實用程序。/etc目錄,存放系統(tǒng)配置文件/lib分區(qū),存放程序庫各種各樣的文件系統(tǒng)Linux的七個運(yùn)行級別和含義0.halt(關(guān)機(jī))1.single(單用戶)2.multiuser,without

NFS

(多用戶)3.Full

multiuser

mode(完全多用戶)4.unused5.X11(圖形界面)6.reboot(重新啟動)文件類型普通文件文本文件二進(jìn)制文件可執(zhí)行程序,聲音,圖像文件目錄文件鏈接文件硬鏈接軟鏈接特殊文件特殊文件設(shè)備文件/dev/ttys1:標(biāo)準(zhǔn)終端/dev/hda:第一塊IDE硬盤管道文件例:用戶使用lp打印一個文件時,lp建立打印進(jìn)程并向一個管道發(fā)送信息硬鏈接(Hard

Link)[root@localhost

link]#

ls

-ltotal

1-rw-r--r--

1

root

root667

Oct

15

13:39

a[root@localhost

link]#

ln

a

b[root@localhost

link]#

ls

-ltotal

2-rw-r--r--

2

root-rw-r--r--

2

rootrootroot667

Oct

15

13:39

a667

Oct

15

13:39

b[root@localhost

link]#

rm

arm:

remove

`a"?

y[root@localhost

link]#

ls

-ltotal

1-rw-r--r--

1

root

root667

Oct

15

13:39

binode/root/linkab符號鏈接(Symbolic

link)[root@localhost

symlink]#

ls

-ltotal

1-rw-r--r--

1

root

root

667

Oct

15

13:39

a[root@localhost

symlink]#

ln

-s

a

b[root@localhost

symlink]#

ls

-ltotal

1-rw-r--r--

1

rootlrwxrwxrwx

1

rootrootroot667

Oct

15

13:39

a1

Oct

15

14:20

b

->

a[root@localhost

yy]#

rm

arm:

remove

`a"?

y[root@localhost

symlink]#

ls

-ltotal

0lrwxrwxrwx

1

root

root 1

Oct

15

14:20

b

->

a[root@localhost

symlink]#

cat

bcat:

b:

No

such

file

or

directoryinode/root/linkabVFS(Virtual

FileSystem)的作用Virtual

File

SystemExt2

Ext3...Buffer

CacheDevice

DriverSubsystemUser

ProgramsSystem

Call

InterfaceInter-processcommunicationProcess

ControlSchedulerMemorymanagementHardware基于VFS的文件訪問VFS的目錄項(dentry)VFS的dentry定義在include/linux/dcache.h中為了加快文件的查找,每一個曾被讀取的目錄或文件都可能在目錄高速緩存(directory

cache)中有一個dentry項;

dentry描述了目錄與文件的關(guān)系樹。VFS的目錄項(dentry)struct

dentry

{

/*include/linux/dcache.h*/atomic_t

d_count;unsigned

int

d_flags;struct

inode

*

d_inode;

/*

Where

the

name

belongs

to

-

NULL

is

negative

*//*

parent

directory

*//*

lookup

hash

list

*//*

d_count

=

0

LRU

list

*//*

child

of

parent

list

*//*

our

children

*//*

inode

alias

list

*/struct

dentry

*

d_parent;struct

list_head

d_hash;struct

list_head

d_lru;struct

list_head

d_child;struct

list_head

d_subdirs;struct

list_head

d_alias;int

d_mounted;struct

qstr

d_name;unsigned

long

d_time;/*

used

by

d_revalidate

*/struct

dentry_operations

*d_op;struct

super_block

*

d_sb;

/*

The

root

of

the

dentry

tree

*/unsigned

long

d_vfs_flags;void

*

d_fsdata;

/*

fs-specific

data

*/unsigned

char

d_iname[DNAME_INLINE_LEN];

/*

small

names

*/};打開文件表linux系統(tǒng)運(yùn)行期間維護(hù)一張以struct

file

(在include/linux/fs.h中)作為節(jié)點的雙向鏈表(系統(tǒng)打開文件表)。表頭由first_file給出。struct

file

*first_file

=

NULL;

/*

fs/file_table.c

*/·對于每個進(jìn)程,struct

task_struct中的files指向的files_struct結(jié)構(gòu)中有一個fd指針數(shù)組,即維護(hù)一張進(jìn)程打開文件表。數(shù)組元素即是指向系統(tǒng)打開文件表中某一節(jié)點的指針。VFS重要數(shù)據(jù)結(jié)構(gòu)·files_struct

(在sched.h);·file

(在fs.h);·dentry

(在dcache.h);·superblock(在fs.h);·inode

(在fs.h)文件系統(tǒng)類型static

struct

file_system_type

*file_systems

=(struct

file_system_type

*)

NULL;struct

file_system_type

{struct

super_block

*(*read_super)();/*讀出該文件系統(tǒng)在外存的super_block

*/const

char

*name;/*文件系統(tǒng)的類型名*/int

requires_dev;/*支持文件系統(tǒng)的設(shè)備*/struct

file_system_type

*

next;/*文件系統(tǒng)類型鏈表的后續(xù)指針*/};文件系統(tǒng)注冊與注銷文件系統(tǒng)類型的注冊和注銷函數(shù)int

register_filesystem(struct

file_system_type

*

fs)int

unregister_filesystem(struct

file_system_type

*

fs)file_systemsfile_system_typefile_system_typefile_system_type文件系統(tǒng)的安裝(mount)/binusrdev

etcRoot

filesystem/usr

filesystemComplete

hierarchy

after

mounting

/usrbin/lib

man/binetcdevusrbinmanlib文件系統(tǒng)的安裝(mount)安裝點dentryrootd_mounted!=0i_sb下掛文件系統(tǒng)安裝點vfsmountmnt_mountpointmnt_root已安裝文件系統(tǒng)的描述static

LIST_HEAD(vfsmntlist);struct

vfsmount{struct

list_head

mnt_hash;struct

vfsmount

*mnt_parent;

/*

fs

we

are

mounted

on

*/struct

dentry

*mnt_mountpoint;

/*

dentry

of

mountpoint

*/struct

dentry

*mnt_root;

/*

root

of

the

mounted

tree

*/struct

super_block

*mnt_sb;

/*

pointer

to

superblock

*/struct

list_head

mnt_mounts;

/*

list

of

children,

anchored

here

*/struct

list_head

mnt_child;

/*

and

going

through

their

mnt_child*/atomic_t

mnt_count;int

mnt_flags;char

*mnt_devname;

/*

Name

of

device

e.g.

/dev/dsk/hda1

*/struct

list_head

mnt_list;};已安裝文件系統(tǒng)的描述s_typemnt_sbvfsmntlistvfsmountmnt_sbsuper_blockfile_system_typefile_systems路徑查找系統(tǒng)調(diào)用open、mkdir、rename、stat等要查找路徑open_namei()path_init()path_walk()link_path_walk();返回時,struct

nameidata中的dentry和mnt標(biāo)識找到的文件或目錄/*include/linux/fs.h*//*找到的dentry指針*//*找到的文件所在文件系統(tǒng)*/struct

nameidata

{

struct

dentry

*dentry;struct

vfsmount

*mnt;struct

qstr

last;unsigned

int

flags;int

last_type;};ext2文件系統(tǒng)支持UNIX所有標(biāo)準(zhǔn)的文件系統(tǒng)特征,包括正文、目錄、設(shè)備文件和連接文件等,這使得它很容易被UNIX程序員接受。事實上,

ext2的絕大多數(shù)的數(shù)據(jù)結(jié)構(gòu)和系統(tǒng)調(diào)用與經(jīng)典的UNIX一致能夠管理海量存儲介質(zhì)。支持多達(dá)4TB的數(shù)據(jù),即一個分區(qū)的容量最大可達(dá)4TB支持長文件名,最多可達(dá)255個字符,并且可擴(kuò)展到1012個字符允許通過文件屬性改變內(nèi)核的行為;目錄下的文件繼承目錄的屬性支持文件系統(tǒng)數(shù)據(jù)“即時同步”特性,即內(nèi)存中的數(shù)據(jù)一旦改變,立即更新硬盤上的數(shù)據(jù)使之一致實現(xiàn)了“快速連接”(fast

symbolic

links)的方式,使得連接文件只需要存放inode的空間允許用戶定制文件系統(tǒng)的數(shù)據(jù)單元(block)的大小,可以是1024、2048或4096個字節(jié),使之適應(yīng)不同環(huán)境的要求使用專用文件記錄文件系統(tǒng)的狀態(tài)和錯誤信息,供下一次系統(tǒng)啟動時決定是否需要檢查文件系統(tǒng)ext2體系結(jié)構(gòu)內(nèi)存中的ext2

inodeext2_inode_info

(在include/linux/ext2_fs_i.h)struct

ext2_inode_info

{

u32

i

data[15];

u32

i

flags;

u32

i

faddr;

u8

i

frag

no;

u8

i

frag

size;

u16

i

osync;

u32

i

file

acl;

u32

i

dir

acl;

u32

i

dtime;

u32

i

block

group;

u32

i

next

alloc

block;

u32

i

next

alloc

goal;

u32

i

prealloc

block;

u32

i

prealloc

count;

u32

i

dir

start

lookup;int

i_new_inode:1;

/*Is

afreshlyallocated

inode

*/};外存中的ext2

inodestruct

ext2_inode(在include/linux/ext2_fs.內(nèi)、外存inode的讀寫:

ext2_read_inode()ext2_update_inode()Ext2_inode文件讀寫read()和write()int

read(int

fd,

void

*buf,size_t

nbytes);int

write(int

fd,

void

*buf,size_t

nbytes);read()調(diào)用generic_file_read(),再調(diào)用do_generic_file_read()讀入內(nèi)核緩沖區(qū),然后調(diào)用

file_read_actor()將讀入內(nèi)容傳入用戶空間。最后調(diào)用

update_atime()修改inodewrite()調(diào)用generic_file_write()寫數(shù)據(jù)入緩沖區(qū),如果是同步寫(O_SYNC置位),則調(diào)用generic_osync_inode()將緩沖區(qū)中數(shù)據(jù)寫入磁盤文件。直接讀寫(read、write時將O_DIRECT置位) generic_file_read()先讀page

cache generic_file_write()先寫入緩沖區(qū)

generic_file_direct_IO()直接讀寫(self-caching)ext3文件系統(tǒng)日志文件系統(tǒng)(journaling

file

system)利用數(shù)據(jù)庫的日志技術(shù)(log,checkpoint)3種日志方式:journal,ordered,writeback日志記錄在/.journal中(隱藏的文件)Kjournald—5sReiserfsproc文件系統(tǒng)/proc:一個虛

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論