Bug#570603: libc6: fallocate and posix_fallocate do weird system calls
Quoth Aurelien Jarno aurel...@aurel32.net, on 2010-02-20 11:38:22 +0100: On Fri, Feb 19, 2010 at 08:35:59PM -0600, Drake Wilson wrote: Two C source files are attached. One of them uses Linux fallocate() They are not. D'oh. Sorry! *brown paper bag* Let's try that again, then. *attach* Your filesystem does not support fallocate, so the glibc is emulating it with a pwrite. That makes a certain amount of sense in this context; I originally assumed I couldn't trust the return value of the syscall due to the strange parameters (and didn't think ext2 might not have fallocate). Reassigning. Thank you for the attention, and sorry for the initial incorrectness. --- Drake Wilson #define _GNU_SOURCE #include unistd.h #include fcntl.h int main(int argc, char *argv[]) { int const fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd == -1) return 1; int const err = fallocate(fd, 0, 0, (off_t)(1 20)); if (err == -1) return 1; return 0; } #define _XOPEN_SOURCE 600 #include unistd.h #include fcntl.h int main(int argc, char *argv[]) { int const fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd == -1) return 1; int const err = posix_fallocate(fd, 0, (off_t)(1 20)); if (err == -1) return 1; return 0; }
Bug#570603: libc6: fallocate and posix_fallocate do weird system calls
Package: libc6 Version: 2.10.2-6 Severity: normal Two C source files are attached. One of them uses Linux fallocate() and one uses posix_fallocate() from POSIX:2001. Both are ostensibly supported by eglibc. I'm running a stock kernel from unstable (some background text removed): $ uname -r 2.6.29-1-amd64 $ dpkg -l linux-image-2.6.29-1-amd64 ii linux-image-2.6.29-1-amd64 2.6.29-3 Linux 2.6.29 image on AMD64 Each of the C programs will attempt to open and truncate a file named file, then allocate one MiB of space for it, changing its size. Here's what happens instead: $ strace ./linux [...] open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 fallocate(3, 0, 4503599627370496, 6895618648722965280) = -1 EOPNOTSUPP (Operation not supported) The hexadecimal representations of those two numbers are 0x0010 and 0x5fb228a05fb10320. And: $ strace ./posix open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 fallocate(3, 0, 4503599627370496, 1048576) = -1 EOPNOTSUPP (Operation not supported) This is followed by an emulation of posix_fallocate using one-byte pwrites. Jesus. This is obviously bogus. This feels like libc screwing up the system call parameters, which is why I'm reporting it here, but I'm not certain of that. It could also potentially be strace or the kernel, in which case please reassign as necessary, as usual. --- Drake Wilson -- System Information: Debian Release: squeeze/sid APT prefers unstable APT policy: (990, 'unstable'), (500, 'testing'), (1, 'experimental') Architecture: amd64 (x86_64) Kernel: Linux 2.6.29-1-amd64 (SMP w/2 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/bash Versions of packages libc6 depends on: ii libc-bin 2.10.2-6 Embedded GNU C Library: Binaries ii libgcc1 1:4.4.3-2 GCC support library libc6 recommends no packages. Versions of packages libc6 suggests: ii debconf [debconf-2.0] 1.5.28 Debian configuration management sy ii glibc-doc 2.10.2-5 Embedded GNU C Library: Documentat ii locales 2.10.2-5 Embedded GNU C Library: National L -- debconf information: glibc/upgrade: true * glibc/disable-screensaver: glibc/restart-failed: * glibc/restart-services: ssh saslauthd rsync openbsd-inetd lprng exim4 cron atd -- To UNSUBSCRIBE, email to debian-glibc-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20100220023559.25550.37841.report...@drache
Bug#569517: libc6-dev: sys/stat.h should provide S_ISSOCK with sufficiently recent _POSIX_C_SOURCE
Package: libc6-dev Version: 2.10.2-6 Severity: wishlist File issock.c: #include sys/stat.h int foo(mode_t mode) { return S_ISSOCK(mode); } int main(int argc, char *argv[]) { return foo(0); } Compilation results: $ gcc -std=c99 -D_POSIX_C_SOURCE=200112L -o issock issock.c issock.c: In function ‘foo’: issock.c:2: warning: implicit declaration of function ‘S_ISSOCK’ /tmp/ccUoCGe4.o: In function `foo': issock.c:(.text+0x16): undefined reference to `S_ISSOCK' collect2: ld returned 1 exit status $ gcc -std=c99 -D_POSIX_C_SOURCE=200809L -o issock issock.c issock.c: In function ‘foo’: issock.c:2: warning: implicit declaration of function ‘S_ISSOCK’ /tmp/ccsSvaAx.o: In function `foo': issock.c:(.text+0x16): undefined reference to `S_ISSOCK' collect2: ld returned 1 exit status Using gcc -E -dM, it is possible to observe that S_ISSOCK does not get defined as a macro at any point. With -D_GNU_SOURCE or no feature test macros at all, issock.c compiles fine. /usr/include/sys/stat.h on my machine has at line 146: #if (defined __USE_BSD || defined __USE_UNIX98) \ defined __S_IFSOCK # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK) #endif This seems to be along the lines of only defining S_ISSOCK when BSD or X/Open features are being selected (my glance at __USE_UNIX98 yielded vague understanding at best), but according to [1], POSIX:2001 declares that sys/stat.h defines the macro S_ISSOCK without any extension tags (such as the XSI tag), which would seem to me to make it a POSIX feature. [1] http://www.opengroup.org/onlinepubs/95399/basedefs/sys/stat.h.html --- Drake Wilson -- System Information: Debian Release: squeeze/sid APT prefers unstable APT policy: (990, 'unstable'), (500, 'testing'), (1, 'experimental') Architecture: amd64 (x86_64) Kernel: Linux 2.6.29-1-amd64 (SMP w/2 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/bash Versions of packages libc6-dev depends on: ii libc-dev-bin 2.10.2-6 Embedded GNU C Library: Developmen ii libc6 2.10.2-6 Embedded GNU C Library: Shared lib ii linux-libc-dev2.6.32-6 Linux support headers for userspac Versions of packages libc6-dev recommends: ii gcc [c-compiler] 4:4.4.2-3 The GNU C compiler ii gcc-3.4 [c-compiler] 3.4.6-10 The GNU C compiler ii gcc-4.3 [c-compiler] 4.3.4-6The GNU C compiler ii gcc-4.4 [c-compiler] 4.4.3-2The GNU C compiler Versions of packages libc6-dev suggests: ii glibc-doc 2.10.2-5 Embedded GNU C Library: Documentat ii manpages-dev 3.23-1 Manual pages about using GNU/Linux -- no debconf information -- To UNSUBSCRIBE, email to debian-glibc-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org