unix 创建html文件路径,Btrfs 创建目录和文件的操作

之前的笔记里有篇介绍ext3 dir-entry lookup(http://blog.chinaunix.net/u3/110888/showart_2156666.html)。对于目录/文件的创建及查找操作学习,算是了解一个文件系统的入口吧。

btrfs这部分代码太烦琐,暂时不想掉进code 细节,只从函数调用层面简单理解其操作逻辑。这一点和学习ext2/3的方式不一样,由于btrfs许多feature,听起来很酷,先理解这些feature是如何实现的。在网上找到的btrfs的文档不多,身边也没有比较方便的讨论环境,代码定得既乱而杂,目前入于不稳定版本,于是乎,换一种学习方式啦。(其实我真想弃而学习ext4)

1 目录创建 mkdir

简单地说分两步,

1) 创建目录inode,加入父目录所在的subvolume btrfs_root.

2)   add link,作为父目录的dir item,插入其inode对应leaf。(总体上看inode聚合成一个个小树)

第一个很简单,FS btrfs_root存放所有的inode.第二步可以与ext2/3相比较来看。 ext3中一个inode如果代表的是dir,其data block里存放的是本目录下的目录+文件对应的entry. btrfs中,menta-data是存放在leaf中的item,所以有个disk_key表示的dir-entries类型在leaf某偏移。data区则存放的是btrfs_dir_item,用于找到某entry对应的inode disk-key。 不同类型的item数据可在fs/btrfs/ctree里看到。

简单看下btrfs_mkdir operations:

1.reserve 5 items for new inode

2. start transaction

3. find a free object id from root tree

4. create new inode by btrfs_new_inode(). this function is interesting,it will build up the simple structure of a new inode in the btree..

5. initialize inode's i_op/i_fop

6. add link of inode and its parent for future lookup

2. 创建文件

it's nearly the same as mkdir() ,only different is after creating the new inode,need initialize its i_fop/op and i_mapping operatoins to default one.

3. btrfs_lookup

i was confused by the deep detail operations of lookup. acturally speaking, btrfs_lookup_dir_item() helper functin will do all tings.

The parent_inode_objectid + btrfs_dir_item_key+hash-name-offset is the search key ,after search the slot,cat get the specific item,and now it's okay to read item data to know the target inode's disk_key.  next ,you will get the inode by searching the root tree.

得赶紧闪了,我的车在楼下快被人偷了。  :--)

END.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值