linux doc下生成学号,如何在linux tmpfs中生成inode编号?

大部分tmpfs代码都是mm / shmem.c.新的inode是由创建的

static struct inode *shmem_get_inode(struct super_block *sb,const struct inode *dir,int mode,dev_t dev,unsigned long flags)

但它几乎将所有内容委托给通用文件系统代码.

特别是,字段i_ino填入fs / inode.c:

/**

* new_inode - obtain an inode

* @sb: superblock

*

* Allocates a new inode for given superblock. The default gfp_mask

* for allocations related to inode->i_mapping is GFP_HIGHUSER_MOVABLE.

* If HIGHMEM pages are unsuitable or it is known that pages allocated

* for the page cache are not reclaimable or migratable,* mapping_set_gfp_mask() must be called with suitable flags on the

* newly created inode's mapping

*

*/

struct inode *new_inode(struct super_block *sb)

{

/*

* On a 32bit,non LFS stat() call,glibc will generate an EOVERFLOW

* error if st_ino won't fit in target struct field. Use 32bit counter

* here to attempt to avoid that.

*/

static unsigned int last_ino;

struct inode *inode;

spin_lock_prefetch(&inode_lock);

inode = alloc_inode(sb);

if (inode) {

spin_lock(&inode_lock);

__inode_add_to_lists(sb,NULL,inode);

inode->i_ino = ++last_ino;

inode->i_state = 0;

spin_unlock(&inode_lock);

}

return inode;

}

它确实只使用递增计数器(last_ino).

大多数其他文件系统使用来自磁盘文件的信息稍后覆盖i_ino字段.

请注意,它完全可以包裹所有方式.内核还有一个“生成”字段,可以通过各种方式填充. mm / shmem.c使用当前时间.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值