tags 627782 - unreproducible
reassign 627782 linux-2.6 2.6.39-2
retitle 627782 fcntl(F_SETFL, O_APPEND) has no effect on aufs filesystem
thanks
If a file is opened for writing without the O_APPEND flag, adding that
flag later via the fcntl() system call succeeds, but is a no-op.
Opening a file with the O_APPEND flag works as expected.
This is reproducible with aufs on ext4 using the attached test program.
Thanks,
Nikolaus
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#define FILENAME "append-testfile"
#define MARK "End-of-file"
static char buf[60];
int main(int argc, char *argv[])
{
int fd, r;
memset(buf, '-', sizeof(buf));
fd = open(FILENAME, O_WRONLY|O_TRUNC|O_CREAT, 0644);
if (fd == -1) {
perror("initial open");
return 1;
}
r = write(fd, buf, sizeof(buf));
if (r == -1) {
perror("initial write");
return 1;
}
r = close(fd);
if (r == -1) {
perror("initial close");
return 1;
}
if (argc > 1 && !strcmp(argv[1], "-a")) {
/* Works */
puts("Opening with O_APPEND.");
fd = open(FILENAME, O_RDWR|O_APPEND);
if (fd == -1) {
perror("second open");
return 1;
}
} else {
/* Broken on aufs + ext4 */
puts("Opening without O_APPEND.");
fd = open(FILENAME, O_RDWR);
if (fd == -1) {
perror("second open");
return 1;
}
puts("Setting O_APPEND via fcnl(2).");
r = fcntl(fd, F_SETFL, O_APPEND);
if (r == -1) {
perror("fcntl(F_SETFL)");
return 1;
}
r = fcntl(fd, F_GETFL);
if (r == -1) {
perror("fcntl(F_GETFL)");
return 1;
}
puts("fcntl successful.");
if (r & O_APPEND)
puts("O_APPEND is now set.");
else
puts("ERROR: O_APPEND not set.");
}
r = write(fd, MARK, strlen(MARK));
if (r == -1) {
perror("second write");
return 1;
}
r = close(fd);
if (r == -1) {
perror("second close");
return 1;
}
puts("Written file `" FILENAME "'.");
return 0;
}