为文件系统定义 PATH_MAX?

发布于 2024-09-11 10:03:29 字数 449 浏览 11 评论 0原文

我目前正在编写一个文件系统。 statvfs (甚至 statfs) 结构包含一个字段,指定该路径中名称的最大长度。由于 PATH_MAXpathconf< 中定义/a> 手册页(getconf),这意味着它是在每个目录的基础上定义的(因此,由底层文件系统确定)。如何指定这个值?

I'm presently writing a filesystem. The statvfs (and even the statfs) structs contain a field specifying the maximum length of a name in that path. As PATH_MAX is defined in the pathconf manpage (getconf), this means it is defined on a per-directory basis (and thus, determined by the underlying filesystem). How does one specify this value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

已下线请稍等 2024-09-18 10:03:29

PATH_MAX 主要表现为文件系统函数调用接口的属性,因此我认为让它在目录之间变化没有多大意义。

例如,重命名或移动其中包含大型目录树的目录可能会使最长的绝对路径名更长,并且限制它会很复杂且效率低下。

相反,PATH_MAX 允许内核将传递的路径名复制到临时未分页内存,然后可以对其进行处理,而无需在每次访问时允许页面错误。分配大量此类内存可能会阻止内核正在执行的大多数其他操作,甚至导致内核恐慌。

PATH_MAX mostly behaves as a property of the file system function call interface, so I don't think it makes much sense to have it vary across directories.

For example, renaming or moving a directory with large directory trees in it may make the longest absolute pathname longer and it would be complicated and inefficient to limit that.

Instead, PATH_MAX serves to allow the kernel to copy passed pathnames to temporary unpaged memory, which can then be processed without needing to allow for a page fault at each access. Allocating huge amounts of such memory may block most other things the kernel is doing or even cause kernel panics.

成熟稳重的好男人 2024-09-18 10:03:29

由于这个问题被标记为“FUSE”...

我刚刚在处理 FUSE 文件系统时遇到了这个问题。我给 FUSE 开发人员写了一封电子邮件,寻求澄清。当前 libfuse 维护者的回复(2018 年 1 月):没有办法指定 FUSE 文件系统 [驱动程序] 中的最大路径长度。

<块引用>

FUSE 文件系统是否有办法通知其上运行的软件
关于正确的最大路径长度?

目前不行,不。

<块引用>

如果没有,应该有吗?

也许是的。欢迎补丁:-)

供参考:完整电子邮件线程

Since this question is tagged "FUSE" ...

I just ran into this issue while working on a FUSE filesystem. I wrote an e-mail to the FUSE developers, seeking clarification. Reply from the current libfuse maintainer (January 2018): There is not a way to specify the maximum path length in a FUSE filesystem [driver].

Is there a way for a FUSE filesystem to inform software running on top
of it about the correct maximum path length?

Not at the moment, no.

If not, should there be?

Probably yes. Patches welcome :-)

For reference: Full e-mail thread

堇色安年 2024-09-18 10:03:29

在 Linux 上,glibc 的 pathconf 实现返回 PATH_MAX 的编译时常量值,因此没有运行时魔法 FUSE 或任何其他人可以执行调整它。 (请参阅 sysdeps/unix/sysv/linux/pathconf.c,它会进入 sysdeps/posix/pathconf.c。)您的问题“如何指定文件系统的 PATH_MAX?”的答案是“你不能。glibc 不允许你,FUSE 只是信使。”

最终的结果是陷入困境。 这是一篇博客文章,讨论了关心和不关心 PATH_MAX 的代码。 依赖不长于 PATH_MAX 的路径的软件很久以前就被其他文件系统破坏了,因此您可以安全地忽略 PATH_MAX。

在 MacOS X(可能还有其他 BSD)上:pathconf 的实现完全在内核中,并且可以根据文件系统进行交换。 OSXFUSE 包含一个 NOOP 版本的 pathconf,它应该返回通常的编译时常量。然而,在我的测试中,它似乎捕获了另一个返回 ENXIO 的 NOOP 函数,并且我无法让 pathconf 工作。

额外奖励:对于 NAME_MAX,实现 statfs 并设置 f_namemax。

On Linux, glibc's implementation of pathconf returns a compile-time constant value of PATH_MAX so there is no runtime magic FUSE or anyone else can perform to adjust it. (See sysdeps/unix/sysv/linux/pathconf.c which falls through to sysdeps/posix/pathconf.c.) The answer to your question "How do I specify my filesystem's PATH_MAX?" is "You can't. glibc doesn't let you and FUSE is just the messenger."

The end result is a sticky situation. Here's a blog post that discusses the code that does and does not care about PATH_MAX. Software that relies on paths no longer than PATH_MAX was broken long ago by other filesystems so it's safe for you to ignore PATH_MAX.

On MacOS X (and probably other BSDs): The implementation of pathconf is entirely in the kernel and can be swapped out per filesystem. OSXFUSE includes a NOOP version of pathconf which should return the usual compile-time constants. However, in my tests it seems to be catching another NOOP function along the way which returns an ENXIO and I can't get pathconf to work.

Bonus: for NAME_MAX, implement statfs and set f_namemax.

何以笙箫默 2024-09-18 10:03:29

POSIX 允许_PC_PATH_MAX 根据当前目录而变化,但这并不意味着改变它的系统不兼容。

PATH_MAX 存在的真正原因是内核在对其进行任何实际工作之前将路径名复制到内核空间中。

您关于 statvfs 中存在 PATH_MAX 相关字段的断言是错误的。这与 NAME_MAX 有关,这是不同的事情。

POSIX allows _PC_PATH_MAX to vary based on the current directory, but that doesn't mean that systems which don't vary it aren't compliant.

The real reason for PATH_MAX existing is that the kernel copies the pathname into kernelspace before doing any actual work with it.

Your assertion that there is a PATH_MAX-related field in statvfs is just wrong. That's related to NAME_MAX, which is a different thing.

泪眸﹌ 2024-09-18 10:03:29

我对其他操作系统了解不够,但恕我直言,这是至少在 FreeBSD 5.2.1 中的系统范围设置

PATH_MAX 位于 #62 sys/syslimits.h

因为 static int ufs_pathconf() 返回 UFS FS 的 PATHCONF 信息,以您指定的方式使用此变量。

/*
 * Return POSIX pathconf information applicable to ufs filesystems.
 */
int
ufs_pathconf(ap)
    struct vop_pathconf_args /* {
        struct vnode *a_vp;
        int a_name;
        int *a_retval;
    } */ *ap;
{

    switch (ap->a_name) {
    .
    .
    .
    .
    case _PC_PATH_MAX:
        *ap->a_retval = PATH_MAX;
        return (0);
    .
    .
    .
    .

    default:
        return (EINVAL);
    }
    /* NOTREACHED */
}

I do not enough about other OSes but imho this is a system-wide setting in at least FreeBSD 5.2.1

PATH_MAX is found in #62 sys/syslimits.h

Because static int ufs_pathconf() which returns the PATHCONF information for UFS FS, uses this variable in the manner you specified.

/*
 * Return POSIX pathconf information applicable to ufs filesystems.
 */
int
ufs_pathconf(ap)
    struct vop_pathconf_args /* {
        struct vnode *a_vp;
        int a_name;
        int *a_retval;
    } */ *ap;
{

    switch (ap->a_name) {
    .
    .
    .
    .
    case _PC_PATH_MAX:
        *ap->a_retval = PATH_MAX;
        return (0);
    .
    .
    .
    .

    default:
        return (EINVAL);
    }
    /* NOTREACHED */
}
↘紸啶 2024-09-18 10:03:29

PATH_MAX 是系统范围的设置,通常在 pathmax.h 中定义为:

define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \
            : pathconf ("/", _PC_PATH_MAX))

PATH_MAX is a system wide setting and is usually defined in pathmax.h as:

define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \
            : pathconf ("/", _PC_PATH_MAX))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文