|
From: Sebastian M. E. <er...@pl...> - 2018-01-02 21:17:46
|
Hi everyone, I am building a relatively simple FUSE-based filesystem (path-based, "high level" API) mostly as an exercise for now. In this context, I am trying to wrap my head around PATH_MAX and _PC_PATH_MAX (primarily on Linux). I'd like to seek some clarification on how to deal with those two correctly in the context of FUSE and POSIX compliance. Please correct me if I am wrong. My understanding so far is that while PATH_MAX is an operating-system-wide constant (e.g. 4096 on Linux, specified in limits.h [1]), an individual file system (mounted somewhere) can return a different (e.g. smaller) value through _PC_PATH_MAX when probed with the pathconf or fpathconf system calls. Unfortunately, I could not locate any authoritative reference other than forum comments [2]. The POSIX standards are not very detailed as far as I can see [3], but I could be looking for this information at the wrong spot. Due to the implementation and concept of my filesystem, the maximum path length within it is effectively 2 bytes shorter than PATH_MAX. When I test my filesystem for POSIX compliance with "pjdfstest" [4], I see lots of errors popping up related to ENAMETOOLONG as one would expect. Looking at the tests' code, one can see that the test calls pathconf in the tested directory (i.e. the tested filesystem) [5] for retrieving the value of _PC_PATH_MAX (which is equal to PATH_MAX, 4096). I can "fix" most of my breaking tests related to maximum path lengths by subtracting 2 from the value returned by pathconf (changing this line [6] into "path_max=$((path_max-3))"). The above behavior begs the question whether my filesystem could influence the return value of pathconf when asked for the value of _PC_PATH_MAX. It would allow it to return the correct value and software running on top of it (like pjdfstest) could correctly determine the maximum path length. From what I gather, it is usually recommended when writing software to check for the maximum path length (and maximum name length) within individual directories at run-time instead of hard-coding PATH_MAX into the software in one way or the other. For this recommendation to make sense it would require a (FUSE) filesystem to return the correct value. Is there a way for a FUSE filesystem to inform software running on top of it about the correct maximum path length? If not, should there be? Or am I completely on the wrong track here? (Again looking at forum comments [7], it appears to me that this can be done by implementing the statfs call, but looking at the statvfs struct type [8], I do not understand through which field(s) this could be achieved.) Thanks for any help and suggestions. Regards, Sebastian [1] https://github.com/torvalds/linux/blob/ead751507de86d90fa250431e9990a8b881f713c/include/uapi/linux/limits.h [2] https://stackoverflow.com/questions/34278283/how-can-i-supply-pathconf-with-fuse [3] http://pubs.opengroup.org/onlinepubs/9699919799/functions/fpathconf.html [4] https://github.com/pjd/pjdfstest [5] https://github.com/pjd/pjdfstest/blob/9f74a0dca5822388d84fc3f914cc296d93c46213/tests/misc.sh#L150 [6] https://github.com/pjd/pjdfstest/blob/9f74a0dca5822388d84fc3f914cc296d93c46213/tests/misc.sh#L152 [7] https://stackoverflow.com/questions/3325602/what-is-the-relation-between-path-max-and-name-max-and-how-do-i-obtain#comment3451077_3325616 [8] https://linux.die.net/man/2/statvfs |