在我看来,tmpfs不会重复使用inode数字,而是每次需要一个免费的inode时,通过+1序列创建一个新的inode号码.
你知道这是如何实现的/你能指点我一些源代码,我可以检查tmpfs中使用的算法吗?
我需要理解这一点,以便绕过使用inode号作为其缓存键的缓存系统的限制(因此,当过度重复使用inode时,会导致罕见但发生的冲突).如果我能证明它不断创建唯一的inode数字,那么tmpfs可以节省我的一天.
谢谢您的帮助,
杰罗姆瓦格纳
我不会直接回答你的问题,所以我提前为此道歉.
tmpfs的想法很好,但我不会让我的程序依赖于或多或少的模糊实现细节来生成密钥.为什么不尝试其他方法,例如将inode编号与其他信息组合在一起?也许修改日期:除非系统日期发生变化,否则两个文件在密钥生成时不可能获得相同的inode编号和修改日期.
干杯!
tmpfs 代码的大部分位于mm/shmem.c. 新的索引节点是由
static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
int mode, dev_t dev, unsigned long flags)
Run Code Online (Sandbox Code Playgroud)
但它将几乎所有内容委托给通用文件系统代码。
特别是,该字段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;
}
Run Code Online (Sandbox Code Playgroud)
它确实只使用了一个递增计数器(last_ino)。
大多数其他文件系统使用磁盘文件中的信息来稍后覆盖该i_ino字段。
请注意,这完全有可能完全环绕。内核还有一个“生成”字段,可以通过多种方式填充。 mm/shmem.c使用当前时间。
| 归档时间: |
|
| 查看次数: |
2971 次 |
| 最近记录: |