arm/158950: arm/sheevaplug fails fsx when mmap operations are enabled

Kristof Provost kristof at sigsegv.be
Mon Apr 23 10:00:37 UTC 2012


The following reply was made to PR arm/158950; it has been noted by GNATS.

From: Kristof Provost <kristof at sigsegv.be>
To: bug-followup at FreeBSD.org, kirk at ba23.org
Cc:  
Subject: Re: arm/158950: arm/sheevaplug fails fsx when mmap operations are
 enabled
Date: Mon, 23 Apr 2012 11:58:51 +0200

 The problem still occurs in current (r234281).
 
 Interestingly it only seems to occur when using a USB stick. It doesn't
 happen when using NFS, or a loop-mounted file system (over NFS).
 
 The following code frequently (but not always!) triggers the problem as
 well:
 
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 
 #define FILE_NAME "test.img"
 
 /* Also occurs with offset = 0, but not as frequently */
 #define OFFSET 4096
 
 int main(int argc, char **argv) {
 	int fd, i;
 	char buff[1024];
 	char *map;
 
 	(void)argc;
 	(void)argv;
 
 	/* Make sure the file doesn't exist when we start */
 	unlink(FILE_NAME);
 
 	fd = open(FILE_NAME, O_CREAT | O_RDWR);
 	if (fd < 0) {
 		perror("Failed to open " FILE_NAME);
 		return 1;
 	}
 
 	/* mmap write (beyond what is currently written) */
 	for (i = 0; i < 1024; i++) {
 		buff[i] = i % 128;
 	}
 
 	/* Truncate the file up */
 	ftruncate(fd, OFFSET + 1024);
 
 	map = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, OFFSET);
 	if (map == (char*)-1) {
 		perror("Failed to mmap ");
 		return 1;
 	}
 
 	memcpy(map, buff, 1024);
 
 	msync(map, 1024, MS_SYNC);
 	munmap(map, 1024);
 
 	/* Now read() and check if all bytes are written correctly */
 	lseek(fd, OFFSET, SEEK_SET);
 	read(fd, buff, 1024);
 
 	for (i = 0; i < 1024; i++) {
 		if (buff[i] != (i % 128))
 			printf("After mmap: offset %d is %d, not %d as expected\n",
 			    i, buff[i], i % 128);
 	}
 
 	close(fd);
 
 	return 0;
 }
 


More information about the freebsd-arm mailing list