大部分的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
使用当前时间。
感谢您挖掘出来。 “一路包裹”是什么意思? – 2010-12-10 23:10:12
发生溢出时回零 – slezica 2010-12-11 00:14:00