You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux内核4.13伪文件系统目录无法列出,提示“No such file or directory”

Troubleshooting Your 4.13 Pseudo Filesystem ls Failure

Alright, let's break down why your custom pseudo filesystem mounts fine but throws ls: cannot access 'mountedfs/data': No such file or directory—this is a super common pitfall when implementing VFS interfaces in Linux 4.13, even when your superblock and root dentry look good. Here are the key areas to debug:

1. Your Root Directory Inode Missing a lookup Operation

The ls command relies on the root directory's inode operations to find child entries like data. If your root inode doesn't have a properly assigned i_op->lookup function, the VFS has no way to resolve the data path.

  • Fix Check: Make sure you've defined an inode_operations struct for your root directory with a lookup handler, and assigned it when creating the root inode:
    static const struct inode_operations womfs_root_iops = {
        .lookup = womfs_lookup, // Your custom lookup function
    };
    
    // When creating your root inode:
    struct inode *root_inode = womfs_get_inode(sb, S_IFDIR | 0755, 0);
    if (root_inode) {
        root_inode->i_op = &womfs_root_iops;
        root_inode->i_nlink = 2; // Critical for directories: links to self and parent
    }
    

2. Faulty lookup Function Implementation

Even if you have a lookup function, it might not correctly create or return the data entry's dentry/inode. Common mistakes here include:

  • Returning NULL or an error code when the requested name is data
  • Forgetting to associate the inode with the dentry using d_add()
  • Setting the wrong inode type (e.g., S_IFREG for a file, S_IFDIR for a directory)

Example Correct Lookup Handler:

struct dentry *womfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
{
    struct inode *inode;

    // Check if the requested entry is "data"
    if (strcmp(dentry->d_name.name, "data") != 0) {
        return ERR_PTR(-ENOENT); // Return "no such file" for unknown entries
    }

    // Create the inode for your "data" file (adjust mode as needed)
    inode = womfs_get_inode(dir->i_sb, S_IFREG | 0644, 0);
    if (!inode) {
        return ERR_PTR(-ENOMEM);
    }

    // Link the inode to the dentry and mark it valid
    d_add(dentry, inode);
    return NULL;
}

3. Root Inode Misconfigured as a Non-Directory

If your root inode's i_mode isn't set to S_IFDIR, the VFS won't treat it as a traversable directory, and ls will fail to enumerate its contents. Also, directories require an i_nlink value of at least 2 (one for the directory itself, one for the .. entry).

  • Quick Check: Verify when creating your root inode that you set:
    root_inode->i_mode = S_IFDIR | 0755;
    root_inode->i_nlink = 2;
    

4. Root Dentry & Inode Association Issues

You mentioned your root dentry was created without issues, but double-check that you properly linked it to the root inode. If you used d_make_root(), this is handled automatically, but if you created the dentry manually, you need to call d_instantiate():

// If using manual dentry creation:
struct dentry *root_dentry = d_alloc_root(root_inode);
if (root_dentry) {
    d_instantiate(root_dentry, root_inode);
    sb->s_root = root_dentry;
}

5. Unfinished Initialization (Re: Your womf... Call)

If that truncated womf... call is part of an asynchronous initialization routine (e.g., waking up a worker to populate the filesystem), it’s possible ls is running before your data entry is fully created. Ensure any background initialization completes before the filesystem is marked ready, or add synchronization in your lookup function to wait for the entry to exist.

Start with verifying the lookup function and root inode operations—those are the most frequent causes of this exact error.

内容的提问来源于stack exchange,提问作者slashingweapon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:31:05