fs/9p/fid.c
Source file repositories/reference/linux-study-clean/fs/9p/fid.c
File Facts
- System
- Linux kernel
- Corpus path
fs/9p/fid.c- Extension
.c- Size
- 7499 bytes
- Lines
- 317
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/errno.hlinux/fs.hlinux/slab.hlinux/sched.hnet/9p/9p.hnet/9p/client.hv9fs.hv9fs_vfs.hfid.h
Detected Declarations
function Copyrightfunction v9fs_fid_addfunction v9fs_is_writeablefunction v9fs_open_fid_addfunction hlist_for_each_entryfunction build_path_from_dentryfunction dentry
Annotated Snippet
if (any || uid_eq(fid->uid, uid)) {
if (want_writeable && !v9fs_is_writeable(fid->mode)) {
p9_debug(P9_DEBUG_VFS, " mode: %x not writeable?\n",
fid->mode);
continue;
}
p9_fid_get(fid);
ret = fid;
break;
}
}
spin_unlock(&inode->i_lock);
return ret;
}
/**
* v9fs_open_fid_add - add an open fid to an inode
* @inode: inode that the fid is being added to
* @pfid: fid to add, NULLed out
*
*/
void v9fs_open_fid_add(struct inode *inode, struct p9_fid **pfid)
{
struct p9_fid *fid = *pfid;
spin_lock(&inode->i_lock);
hlist_add_head(&fid->ilist, (struct hlist_head *)&inode->i_private);
spin_unlock(&inode->i_lock);
*pfid = NULL;
}
/**
* v9fs_fid_find - retrieve a fid that belongs to the specified uid
* @dentry: dentry to look for fid in
* @uid: return fid that belongs to the specified user
* @any: if non-zero, return any fid associated with the dentry
*
*/
static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any)
{
struct v9fs_dentry *v9fs_dentry = to_v9fs_dentry(dentry);
struct p9_fid *fid, *ret;
p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p) uid %d any %d\n",
dentry, dentry, from_kuid(&init_user_ns, uid),
any);
ret = NULL;
/* we'll recheck under lock if there's anything to look in */
if (!hlist_empty(&v9fs_dentry->head)) {
spin_lock(&dentry->d_lock);
hlist_for_each_entry(fid, &v9fs_dentry->head, dlist) {
if (any || uid_eq(fid->uid, uid)) {
ret = fid;
p9_fid_get(ret);
break;
}
}
spin_unlock(&dentry->d_lock);
}
if (!ret && dentry->d_inode)
ret = v9fs_fid_find_inode(dentry->d_inode, false, uid, any);
return ret;
}
/*
* We need to hold v9ses->rename_sem as long as we hold references
* to returned path array. Array element contain pointers to
* dentry names.
*/
static int build_path_from_dentry(struct v9fs_session_info *v9ses,
struct dentry *dentry, const unsigned char ***names)
{
int n = 0, i;
const unsigned char **wnames;
struct dentry *ds;
for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent)
n++;
wnames = kmalloc_array(n, sizeof(char *), GFP_KERNEL);
if (!wnames)
goto err_out;
for (ds = dentry, i = (n-1); i >= 0; i--, ds = ds->d_parent)
wnames[i] = ds->d_name.name;
Annotation
- Immediate include surface: `linux/module.h`, `linux/errno.h`, `linux/fs.h`, `linux/slab.h`, `linux/sched.h`, `net/9p/9p.h`, `net/9p/client.h`, `v9fs.h`.
- Detected declarations: `function Copyright`, `function v9fs_fid_add`, `function v9fs_is_writeable`, `function v9fs_open_fid_add`, `function hlist_for_each_entry`, `function build_path_from_dentry`, `function dentry`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.