* [PATCH] posix_fadvise bug (unexpected success on FIFO/pipe)
@ 2005-12-08 16:44 Valentine Barshak
0 siblings, 0 replies; 2+ messages in thread
From: Valentine Barshak @ 2005-12-08 16:44 UTC (permalink / raw)
To: lkml; +Cc: Andrew Morton
[-- Attachment #1: Type: text/plain, Size: 440 bytes --]
Hello, all.
I have the following problem with posix_fadvise :
the system call succeeds on a pipe or FIFO, although it has to fail with
ESPIPE (EINVAL on linux) return value.
Looks like a kernel bug.
I've attached a small test for posix_fadvise and a patch for linux
kernel 2.6.14 that fixes the problem.
The patch makes posix_fadvise return ESPIPE on FIFO/pipe in order to be
fully POSIX-compliant.
Please, take a look at these.
Thanks.
[-- Attachment #2: posix_fadvise_test.c --]
[-- Type: text/x-csrc, Size: 792 bytes --]
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
int main()
{
int retval, fd;
if (mkfifo("fifo", 0666) < 0) {
printf("create fifo error\n");
return 1;
}
fd = open("fifo", O_RDWR);
if (fd < 0) {
printf("open fifo error\n");
remove("fifo");
return 1;
}
retval = posix_fadvise(fd, 0, 0, POSIX_FADV_NORMAL);
if (retval) {
printf("Expected fail - The fd argument is associated with a pipe or FIFO.\n");
if (retval != ESPIPE)
printf("Unexpected ERRNO %d (Expected %d)\n", retval, ESPIPE);
} else
printf("Unexpected success - The fd argument is associated with a pipe or FIFO.\n");
close(fd);
remove("fifo");
if (retval)
return 0;
return 1;
}
[-- Attachment #3: fadv.patch --]
[-- Type: text/x-patch, Size: 409 bytes --]
--- a/mm/fadvise.c 2005-10-10 22:54:29.000000000 +0400
+++ b/mm/fadvise.c 2005-12-06 23:04:19.980711464 +0300
@@ -37,6 +37,11 @@
if (!file)
return -EBADF;
+ if (S_ISFIFO(file->f_dentry->d_inode->i_mode)) {
+ ret = -ESPIPE;
+ goto out;
+ }
+
mapping = file->f_mapping;
if (!mapping || len < 0) {
ret = -EINVAL;
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] posix_fadvise bug (unexpected success on FIFO/pipe)
@ 2005-12-09 12:58 Valentine Barshak
0 siblings, 0 replies; 2+ messages in thread
From: Valentine Barshak @ 2005-12-09 12:58 UTC (permalink / raw)
To: lkml; +Cc: Alan Cox
[-- Attachment #1: Type: text/plain, Size: 235 bytes --]
Hello all.
This patch adds a FIFO/pipe check to posix_fadvise system call.
If the specified file descriptor is pipe or FIFO, the system call
returns ESPIPE error.
Thank you.
Signed-off-by: Valentine Barshak <vbarshak@ru.mvista.com>
[-- Attachment #2: fadv.patch --]
[-- Type: text/x-patch, Size: 409 bytes --]
--- a/mm/fadvise.c 2005-10-10 22:54:29.000000000 +0400
+++ b/mm/fadvise.c 2005-12-06 23:04:19.980711464 +0300
@@ -37,6 +37,11 @@
if (!file)
return -EBADF;
+ if (S_ISFIFO(file->f_dentry->d_inode->i_mode)) {
+ ret = -ESPIPE;
+ goto out;
+ }
+
mapping = file->f_mapping;
if (!mapping || len < 0) {
ret = -EINVAL;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-12-09 12:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-09 12:58 [PATCH] posix_fadvise bug (unexpected success on FIFO/pipe) Valentine Barshak
-- strict thread matches above, loose matches on Subject: below --
2005-12-08 16:44 Valentine Barshak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox