[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200810010210.3305322-8-mfo@canonical.com>
Date: Sun, 9 Aug 2020 22:02:10 -0300
From: Mauricio Faria de Oliveira <mfo@...onical.com>
To: Jan Kara <jack@...e.cz>
Cc: linux-ext4@...r.kernel.org,
dann frazier <dann.frazier@...onical.com>,
Mauricio Faria de Oliveira <mauricio.foliveira@...il.com>,
Jan Kara <jack@...e.com>
Subject: [RFC PATCH v2/TEST CASE]
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
int main() {
int fd, rc;
char *addr;
const int PAGE_SIZE = sysconf(_SC_PAGESIZE);
rc = unlink("file");
if (rc < 0 && errno != ENOENT ) {
perror("unlink");
return 1;
}
fd = open("file", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd < 0) {
perror("open");
return 1;
}
addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (addr < 0) {
perror("mmap");
return 1;
}
rc = pwrite(fd, "a", 1, 0);
if (rc < 0) {
perror("pwrite");
close(fd);
return 1;
}
addr[0] = 'B';
addr[1] = 'U';
addr[2] = 'G';
while (1) {
printf("Press enter to change buffer contents\n");
getchar();
addr[3]++;
printf("Buffer contents changed\n");
}
// This is not reached.
rc = munmap(addr, PAGE_SIZE);
if (rc < 0) {
perror("munmap");
return 1;
}
close(fd);
return 0;
}
Powered by blists - more mailing lists