La maggior parte del codice tmpfs è in mm/shmem.c
. I nuovi inode vengono creati da
static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
int mode, dev_t dev, unsigned long flags)
ma delega quasi tutto al codice del file system generico.
In particolare, il campo i_ino
viene compilato in 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;
}
Ed effettivamente basta usare un contatore di incremento (last_ino).
La maggior parte degli altri file system utilizza le informazioni dai file su disco per in seguito ignorare il campo i_ino
.
Si noti che è perfettamente possibile per questo avvolgere tutto intorno. Il kernel ha anche un campo di "generazione" che viene riempito in vari modi. mm/shmem.c
utilizza l'ora corrente.
Grazie per averlo scoperto. Cosa intendi con "avvolgere tutto intorno"? –
Torna a zero quando si verifica un overflow – slezica