views:

145

answers:

2

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?

A: 

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))
ennuikiller
I think pathmax.h is some mac fail.
Matt Joiner
+1  A: 

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.

jilles
POSIX disagrees with you - and the question is correct that the [`pathconf()`](http://www.opengroup.org/onlinepubs/9699919799/functions/fpathconf.html) function can return different values depending on the filename you pass to it, which means it can vary depending on the file system represented by that directory. However, POSIX does also say: _The value returned shall not be more restrictive than the corresponding value available to the application when it was compiled with the implementation's `<limits.h>` or `<unistd.h>`._
Jonathan Leffler
I think different `{PATH_MAX}` values per directory are for user mode file system implementations (not fuse, but open() interpreting the name in the same address space). Even then, applications cannot use the differing values race-free (if they go to the trouble of calling `pathconf()` for each component). Moreover, some things like calling `realpath()` with a non-null buffer pointer become undefined when `{PATH_MAX}` is not a constant, but this does not deny an implementation accepting longer pathnames.
jilles