版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Linux的文件系统课程目标:►操作系统的运行级别►文件系统架构►设备管理Linux文件系统//bin/sbin/usr/var/etc/lib/home/tmp/optbinlocalsrcrc.dnamedhttpdrc5.dftprc3.dinit.dbinetcpubLinux各分区功能/boot系统启动过程中使用的文件/usr分区,系统存放软件的地方/home分区,是用户的home目录所在地,/var/log分区,是系统日志记录分区/tmp分区,用来存放临时文件/dev分区,存放设备文件。/opt分区,存放可选的安装的软件。/sbin分区,存放标准系统管理文件。/bin分区,存放标准系统实用程序。/etc目录,存放系统配置文件/lib分区,存放程序库各种各样的文件系统Linux的七个运行级别和含义0.halt(关机)1.single(单用户)2.multiuser,without
NFS
(多用户)3.Full
multiuser
mode(完全多用户)4.unused5.X11(图形界面)6.reboot(重新启动)文件类型普通文件文本文件二进制文件可执行程序,声音,图像文件目录文件链接文件硬链接软链接特殊文件特殊文件设备文件/dev/ttys1:标准终端/dev/hda:第一块IDE硬盘管道文件例:用户使用lp打印一个文件时,lp建立打印进程并向一个管道发送信息硬链接(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描述了目录与文件的关系树。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系统运行期间维护一张以struct
file
(在include/linux/fs.h中)作为节点的双向链表(系统打开文件表)。表头由first_file给出。struct
file
*first_file
=
NULL;
/*
fs/file_table.c
*/·对于每个进程,struct
task_struct中的files指向的files_struct结构中有一个fd指针数组,即维护一张进程打开文件表。数组元素即是指向系统打开文件表中某一节点的指针。VFS重要数据结构·files_struct
(在sched.h);·file
(在fs.h);·dentry
(在dcache.h);·superblock(在fs.h);·inode
(在fs.h)文件系统类型static
struct
file_system_type
*file_systems
=(struct
file_system_type
*)
NULL;struct
file_system_type
{struct
super_block
*(*read_super)();/*读出该文件系统在外存的super_block
*/const
char
*name;/*文件系统的类型名*/int
requires_dev;/*支持文件系统的设备*/struct
file_system_type
*
next;/*文件系统类型链表的后续指针*/};文件系统注册与注销文件系统类型的注册和注销函数int
register_filesystem(struct
file_system_type
*
fs)int
unregister_filesystem(struct
file_system_type
*
fs)file_systemsfile_system_typefile_system_typefile_system_type文件系统的安装(mount)/binusrdev
etcRoot
filesystem/usr
filesystemComplete
hierarchy
after
mounting
/usrbin/lib
man/binetcdevusrbinmanlib文件系统的安装(mount)安装点dentryrootd_mounted!=0i_sb下挂文件系统安装点vfsmountmnt_mountpointmnt_root已安装文件系统的描述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;};已安装文件系统的描述s_typemnt_sbvfsmntlistvfsmountmnt_sbsuper_blockfile_system_typefile_systems路径查找系统调用open、mkdir、rename、stat等要查找路径open_namei()path_init()path_walk()link_path_walk();返回时,struct
nameidata中的dentry和mnt标识找到的文件或目录/*include/linux/fs.h*//*找到的dentry指针*//*找到的文件所在文件系统*/struct
nameidata
{
struct
dentry
*dentry;struct
vfsmount
*mnt;struct
qstr
last;unsigned
int
flags;int
last_type;};ext2文件系统支持UNIX所有标准的文件系统特征,包括正文、目录、设备文件和连接文件等,这使得它很容易被UNIX程序员接受。事实上,
ext2的绝大多数的数据结构和系统调用与经典的UNIX一致能够管理海量存储介质。支持多达4TB的数据,即一个分区的容量最大可达4TB支持长文件名,最多可达255个字符,并且可扩展到1012个字符允许通过文件属性改变内核的行为;目录下的文件继承目录的属性支持文件系统数据“即时同步”特性,即内存中的数据一旦改变,立即更新硬盘上的数据使之一致实现了“快速连接”(fast
symbolic
links)的方式,使得连接文件只需要存放inode的空间允许用户定制文件系统的数据单元(block)的大小,可以是1024、2048或4096个字节,使之适应不同环境的要求使用专用文件记录文件系统的状态和错误信息,供下一次系统启动时决定是否需要检查文件系统ext2体系结构内存中的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.内、外存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()调用generic_file_read(),再调用do_generic_file_read()读入内核缓冲区,然后调用
file_read_actor()将读入内容传入用户空间。最后调用
update_atime()修改inodewrite()调用generic_file_write()写数据入缓冲区,如果是同步写(O_SYNC置位),则调用generic_osync_inode()将缓冲区中数据写入磁盘文件。直接读写(read、write时将O_DIRECT置位) generic_file_read()先读page
cache generic_file_write()先写入缓冲区
generic_file_direct_IO()直接读写(self-caching)ext3文件系统日志文件系统(journaling
file
system)利用数据库的日志技术(log,checkpoint)3种日志方式:journal,ordered,writeback日志记录在/.journal中(隐藏的文件)Kjournald—5sReiserfsproc文件系统/proc:一个虚
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- NYT 4521-2025 贝母生产全程质量控制技术规范标准立项发展报告
- 2027年嵩岳职业学院单招职业技能考试模拟试卷含答案详解(考试直接用)
- 2025年伊达职业学院高职单招职业技能考试题库附完整答案详解【各地真题】
- 2025年石家庄新能源职业学院单招综合素质考试题库附答案详解AB卷
- 2027年资江职业学院高职单招职业适应性测试考试模拟试卷带答案详解(达标题)
- 2024年岳阳技师学院君山高职部单招职业技能考试题库附完整答案详解(夺冠系列)
- 2025年湖南怀化技师学院高职单招职业适应性测试考试模拟试卷含完整答案详解【必刷】
- 二建矿业工程模拟试题及答案详解
- 光刻工保密水平考核试卷含答案
- 2026 年儿科高热惊厥急救护理处置培训课件
- 新生儿复苏操作技能考核评分标准(2025 版)中文版 逐项打分 + 合格判定细则
- 2025年广西卫生职业技术学院教职人员招聘笔试真题(含完整答案解析)
- 2026年医师定期考核试题题库中医入门试题及答案
- 山洪灾害预警识别知识
- 2026小红书有感运动IP方案
- 天然气管线保护施工方案
- 2025届中工国际工程股份有限公司校园招聘笔试历年参考题库附带答案详解
- 城市道路桥梁安全监测预警系统操作手册
- 2026计算机二级MS Office真题模拟押题含解析
- GB/Z 114.1-2026纳米制造技术规范纳米储能第1部分:空白详细规范电化学电容器用纳米多孔活性炭
- 消防培训机构设备管理制度
评论
0/150
提交评论