MMAP(2) troubles on smbfs
Sławek Żak
zaks at prioris.mini.pw.edu.pl
Wed Nov 10 05:09:37 PST 2004
Hi,
I've noticed that msyncing the mmap pointer or fsyncing the file descriptor
is required when filesystem where mmap'ed file resides is smbfs. I use
MMAP_SHARED mode for mmap.
I attach a small test program. I've tried both 5.3-STABLE and 5.2-CURRENT
(built on March 2.) on the client and Samba, Windows XP on the server.
The same operation seems to work fine on both local filesystem and NFS
(ie. no syncing is necessary). Unmounting the filesystem doesn't help - the
changes are not flushed to the file.
/S
-------------- next part --------------
#include <sys/mman.h>
#include <stdio.h>
#include <fcntl.h>
int main()
{
int fd;
void *ptr;
fd = open("/mnt/tmp/file", O_RDWR);
if (fd < 0) {
perror("open");
exit(1);
}
ptr = mmap(NULL, 10, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap");
exit(1);
}
*(char *)ptr = '/';
#if 0
if (msync(ptr, 10, MS_SYNC) < 0) {
perror("msync");
exit(1);
}
if (fsync(fd) < 0) {
perror("fsync");
exit(1);
}
#endif
if (munmap(ptr, 10) < 0) {
perror("munmap");
exit(1);
}
if (close(fd) < 0) {
perror("close");
exit(1);
}
return 0;
}
More information about the freebsd-current
mailing list