天天看点

文件系统学习2 inode

硬链接的inode相同,dentry不同;软连接的inode不同。

所以硬链接不可以跨越分区,而软连接可以。

我们找文件的本质是根据文件的目录属性dentry找inode---->文件内容

为索引节点分配空间
struct inode *ext2_alloc_inode(struct super_block *sb)
	=>struct inode *ext2_alloc_inode(struct super_block *sb)
		=>struct ext2_inode_info *ei = (struct ext2_inode_info *)kmem_cache_alloc(ext2_inode_cachep, GFP_KERNEL);
		=>return &ei->vfs_inode;//壳子是各种文件系统,核心是虚函数结构
           
删除inode
.delete_inode	= ext2_delete_inode,
	=>truncate_inode_pages(&inode->i_data, 0);//0表示从头开始删除
		//* Truncate the page cache, removing the pages that are between
		 //* specified offsets 删除磁盘页高速缓存
		=>truncate_inode_pages_range(mapping, lstart, (loff_t)-1);
	=>mark_inode_dirty(inode);
	=>ext2_update_inode(inode, inode_needs_sync(inode));//最后的参数表示同步还是异步
	=>inode->i_size = 0;
	=>if (inode->i_blocks)
		ext2_truncate (inode);
	=>ext2_free_inode (inode);


这个函数在如下函数里面调用
void generic_delete_inode(struct inode *inode)
	=>void (*delete)(struct inode *) = op->delete_inode;
	=>delete(inode);
           
从磁盘读取inode填充VFS的Inode结构体
.read_inode	= ext2_read_inode
	=>void ext2_read_inode (struct inode * inode)
		=>struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);//从磁盘高速缓存获取原始的具体文件系统inode信息,应该隐含有增加磁盘页高速缓存引用计数增加的功能
		=>for (n = 0; n < EXT2_N_BLOCKS; n++)
			ei->i_data[n] = raw_inode->i_block[n];
		=>if (S_ISREG(inode->i_mode))
			inode->i_mapping->a_ops = &ext2_aops;
			inode->i_fop = &ext2_file_operations;
		=>else if (S_ISDIR(inode->i_mode))
			inode->i_op = &ext2_dir_inode_operations;
			inode->i_fop = &ext2_dir_operations;
			inode->i_mapping->a_ops = &ext2_aops;
		=>brelse (bh);//减少磁盘页高速缓存的引用计数
		=>ext2_set_inode_flags(inode);//设置内存inode标记
           
.write_inode	= ext2_write_inode
	=>int ext2_write_inode(struct inode *inode, int wait)
		=>ext2_update_inode(inode, wait)
			=>struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);//从磁盘页高速缓存读取原始节点
			=>raw_inode->i_mode = cpu_to_le16(inode->i_mode);//用内存的信息刷新原始节点结构体信息
			......
			=>mark_buffer_dirty(bh);//设置脏标志位
			=>if (do_sync)//同步的话需要马上刷新磁盘页高速缓存
				sync_dirty_buffer(bh);
			=>brelse (bh);
           

S_IFMT 0170000 文件类型的位遮罩

S_IFSOCK 0140000 socket

S_IFLNK 0120000 符号链接(symbolic link)

S_IFREG 0100000 一般文件

S_IFBLK 0060000 区块装置(block device)

S_IFDIR 0040000 目录

S_IFCHR 0020000 字符装置(character device)

S_IFIFO 0010000 先进先出(fifo)

S_ISUID 0004000 文件的(set user-id on execution)位

S_ISGID 0002000 文件的(set group-id on execution)位

S_ISVTX 0001000 文件的sticky位

S_IRWXU 00700 文件所有者的遮罩值(即所有权限值)

S_IRUSR 00400 文件所有者具可读取权限

S_IWUSR 00200 文件所有者具可写入权限

S_IXUSR 00100 文件所有者具可执行权限

S_IRWXG 00070 用户组的遮罩值(即所有权限值)

S_IRGRP 00040 用户组具可读取权限

S_IWGRP 00020 用户组具可写入权限

S_IXGRP 00010 用户组具可执行权限

S_IRWXO 00007 其他用户的遮罩值(即所有权限值)

S_IROTH 00004 其他用户具可读取权限

S_IWOTH 00002 其他用户具可写入权限

S_IXOTH 00001 其他用户具可执行权限

摘自《Linux C 函数库参考手册》

参考

Linux的inode的理解

http://www.linuxidc.com/Linux/2014-09/106457.htm

ext2文件系统之ext2_lookup函数源代码分析

http://blog.csdn.net/sanwenyublog/article/details/50830957

柳大的Linux讲义·基础篇(2)Linux文件系统的inode

http://blog.csdn.net/poechant/article/details/7214926

http://blog.csdn.net/shanshanpt/article/details/39059411

Linux文件系统(四)—三大缓冲区之inode缓冲区 (内存inode映像 )

【linux】内核中根据inode得到文件名

https://www.it610.com/article/4993393.htm

继续阅读