vfs_link(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

okay so this is vfs_link(9) from the Kernel API Manual and it's literally the function that creates a new link. no cap, that's the whole vibe. let's get into it πŸŽ€


✨ NAME ✨

vfs_link β€” create a new link 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

int vfs_link (struct dentry *old_dentry , struct mnt_idmap *idmap ,
       struct inode *dir , struct dentry *new_dentry , struct delegated_inode
       *delegated_inode );

πŸ’– ARGUMENTS πŸ’–

  • old_dentry β€” the object to be linked, i.e. the thing we're linking from. the moment. the main character πŸ‘‘
  • idmap β€” idmap of the mount. yes bestie it matters, keep reading πŸ‘€
  • dir β€” new parent. this is where the new link lives, it's giving new home energy 🏑
  • new_dentry β€” where to create the new link. literally the spot πŸ’…
  • delegated_inode β€” returns an inode needing a delegation break. dramatic, we know 😭

πŸ”₯ DESCRIPTION πŸ”₯

The caller must hold dir->i_rwsem exclusively. that's not optional, that's the rule, periodt πŸ’€

If vfs_link discovers a delegation on the to-be-linked file in need of breaking, it will return -EWOULDBLOCK and return a reference to the inode in delegated_inode. The caller should then break the delegation and retry. Because breaking a delegation may take a long time, the caller should drop the i_rwsem before doing so. no cap, do not sit there holding the lock while you sort out your delegation drama πŸ™ˆ

Alternatively, a caller may pass NULL for delegated_inode. This may be appropriate for callers that expect the underlying filesystem not to be NFS exported. lowkey the "i don't want the extra paperwork" option ✨

If the inode has been found through an idmapped mount the idmap of the vfsmount must be passed through idmap. This function will then take care to map the inode according to idmap before checking permissions. On non-idmapped mounts or if permission checking is to be performed on the raw inode simply pass nop_mnt_idmap. so close to iconic behavior, the function handles the mapping for you 🫢

⚠️ real talk: hold dir->i_rwsem exclusively, drop it before breaking a delegation, and pick your idmap on purpose β€” nop_mnt_idmap if you're not idmapped or you want raw inode permission checks. iykyk.

πŸŽ€ SEE ALSO πŸŽ€

Kernel file ./fs/namei.c and honestly the whole friend group:

they all ate, honestly πŸ’œ


and that's the whole page bestie πŸ’– this one's from ./fs, dated October 2026 β€” go forth and link responsibly, mwah πŸ˜˜πŸ¦‹

πŸ“¦ where this page comes from