曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 6096|回复: 0
打印 上一主题 下一主题

文件系统 , inode

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34387
跳转到指定楼层
楼主
发表于 2008-11-16 22:18:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一个 block 为 4K
ext3:the Third Extended Linux Filesystem
-----------------------------------------
Inodes
在一个分区被格式化为 ext2 或 ext3 时会自动产生 Inode-number,一个 inode 表包含着所有文件的列表。一个文件或一个目录对应着一个 Inode-no,如下图示:
 

即有多少个inode-no 就会有多少个文件和目录。inode-table 如下图示:


An inode (index node) is an entry in the table,containing information about a file(the metadata),including:
 .File type,permissions,link count,UID,GID
 .The file's size and various time stamps
 .Other data about the file
 .Pointers to the file's data blocks on disk
注:link count 其实就是 hard link (硬连接).
    Time stamp(Access time,Modify time Change time<AT,MT,CT>)
    存取一个文件需要 pointer,其指向文件所在磁盘上的 block.

操作系统找到一个文件的流程:首先先找到 inode-no,根据 inode-no 从 inode-table 中进入到inode的描述信息栏,接着找到 pointer,从而找到文件所在磁盘上的位置--即 block.
---------------------------------------------------------------
Directories
 .The human way to reference a file is by file name(我们是通过文件名称来查找文件的)
 .The computer's reference for a file is the inode number(电脑通过inode-no来查找文件)
 .A directory is a mapping between the human name for the file and the computer's inode number
  (目录其实是一个 文件名称(file name) 和 inode-no 的映射关系表,如下图示:)
 

可以用命令 ls -li ,可以看到文件所对应的节点号--inode-no

命令 和 inode 的关系
1、cp and Inodes
  .The cp command:
      .Allocates a free inode number,placing a new entry in the inode table
      (在复制时,分配一个新的 inode-no,然后放在inode-talbe中,并写进相关数据--metadata)
      .Creates a directory entry,referencing the files human file name to the inode number
       (文件是要目录下的,所以 cp 出一个新的文件时,就会同时产生这个目录的一个入口,即把文件名和
         inode-no 对应起来)
      .copies data into the new file (上述工作做好后,最后就是复制文件的内容了)

2、mv and Inodes
  .If the destination of the mv command is on the same file system as the source, the mv command:
     .Creates a new directory entry with the new file name
     .Deletes the old directory entry with old file name
     .Has no impact on the inode table( except for a time stamp ) or the location of data on the disk
      no data is moved!
若移动的文件的目的地是和原来的文件是在同一个文件系统里面的话,系统就会对新的文件名建立一个目录入口(inode-no 和文件名的对应),同时删除掉旧的目录入口。这里,不会变更原来inode-table中的位置和不会改变在磁盘中的文件,在inode-table中改变的是时间戳.]

3、rm and Inodes
  .The rm command:
     .Derements the link count,thus releasing the inode number to be reused
     .Places data blocks in the free list
     .Removes the directory entry
  .Data is not actually removed,but will be overwritten when the data blocks are used by another file
删除一个文件,先是减少 link count(linkcount 是硬连接数,有多少个硬连接,count就有多少),加入减为0,则释放 inode-no,以为后用。接着回收 datablocks到 free list 中,表明这个 data blocks下次有新数据进来时是可用的。注意的是,rm后,数据并不是真正的被删除了,必须等到新的数据写到原来占用的datablock上覆盖后,才是真正删除了这些数据。

4、Symbolic (or Soft) Links(也会占用一个 inode-no)
  .A symbolic link points to another file
     .ls -l displays the link name and the referenced file
     .File type: l(小写L)for symbolic link
     .The content of a symbolic link is the name of the file it reference
用法:
    ln -s filename [linkname]    //软连接,相当于windows上的建立一个快捷方式

5、Hard Links(不同的文件名称对应到一个inode-no)
  .Cannot span drives or partitions(因为每一个分区的inode-no都是独立的,故不能跨越驱动器或分区)
 用法:
   ln filename [linkname]
和 inode-no 的关系如下图示:
 

建立了一个硬连接后,不会改变新建立一个inode number,自然也就不会在 innode-talble 中新增一个 innode 入口,但是原来的 inode-no 对应的表栏里的 link count 会加 1.
--------------------------------------------------------------
The Seven Fundamental Filetypes
.- regular file
.d directory
.l symbolic link
.b block spacial file (块设备,硬盘等)
.c character spacial file (字符设备,键盘鼠标等)
.p named pipe(如 /dev/initctl)
.s socket(套接字,如 /dev/gpmctl )

------------------------------------------------------------------
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2024-5-19 19:05 , Processed in 0.079572 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表