Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPathVar fails for large files #33

Open
nomeata opened this issue Dec 23, 2014 · 0 comments
Open

getPathVar fails for large files #33

nomeata opened this issue Dec 23, 2014 · 0 comments

Comments

@nomeata
Copy link

nomeata commented Dec 23, 2014

Joeys reports at http://bugs.debian.org/773821:

import System.Posix.Files
import Control.Exception
import Foreign.C.Types
main = print =<< (try (getPathVar "." FileNameLimit) :: IO (Either IOException CLong))

This program can fail on a system with a large disk:

Left .: getPathVar: failed (Value too large for defined data type)

statfs(".", 0xffa8ad50)                 = -1 EOVERFLOW (Value too large for defined data type)

The problem is, getPathVar is using statfs, not statfs64.

Here's a C program that uses statfs64:

#define _LARGEFILE64_SOURCE 1
#include <sys/vfs.h>
#include <stdio.h>

main () {
        struct statfs64 buf;
        statfs64(".", &buf);
        printf("%li\n", buf.f_namelen);
}

And strace shows just how large some of the fields are, which is why
statfs() overflows.

statfs64(".", 84, {f_type=0x2fc12fc1, f_bsize=131072, f_blocks=67107265, f_bfree=66904371, f_bavail=66904371, f_files=17127878964, f_ffree=17127519173, f_fsid={-676822403, 15770009}, f_namelen=255, f_frsize=131072, f_flags=4128}) = 0

An added problem is that getPathVar is implemented using pathconf,
rather than using statfs directly. It seems that setting _LARGEFILE64_SOURCE
does not cause pathconf to use statfs64. This may be a glibc bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants