Date: Mon, 5 Feb 2001 15:58:41 -0800 (PST) From: ikqumei@computer.org To: freebsd-gnats-submit@FreeBSD.org Subject: i386/24886: Cant msync memory mapped file onto desk. Message-ID: <200102052358.f15Nwfi06015@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 24886
>Category: i386
>Synopsis: Cant msync memory mapped file onto desk.
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Feb 05 16:00:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Iyad Qumei
>Release: 4.0
>Organization:
Digital Transit, Inc.
>Environment:
FreeBSD freebsd.irntdomain.com 4.0-RELEASE FreeBSD 4.0-RELEASE #0: Mon Mar 20 22:50:22 GMT 2000 root@monster.cdrom.com:/usr/src/sys/compile/GENERIC i386
>Description:
I wrote a simple program to demonstrate the problem. Basically, I use mmap to exchange information between files. After this is done, I try to msync the information back to desk. The new information does not seem to be saved. The return value from msync is 0, and no error registed through errno.
I used simple text files with this program.
< source code begin >
#include <stdio.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <limits.h>
#include <errno.h>
#include <unistd.h>
bool ResizeFile( int fd, int new_sz );
int main()
{
int hOldFile=0, hNewFile=0;
char *ofbuf=NULL, *nfbuf=NULL;
long new_sz=155, ofsz=133;
char *ofile="oldf.txt";
char *nfile="newf.txt";
hOldFile = open( ofile, O_RDWR );
hNewFile = open( nfile, O_RDWR );
if( hOldFile )
ofbuf = (char*)mmap(NULL, ofsz, PROT_READ|PROT_WRITE, /*MAP_DENYWRITE*/MAP_PRIVATE, hOldFile, 0);
if ( !ResizeFile( hOldFile, new_sz ) )
{
close(hOldFile);
close(hNewFile);
return 1;
}
nfbuf = (char*) mmap(NULL, new_sz, PROT_READ|PROT_WRITE, MAP_PRIVATE, hNewFile, 0);
for( int i=0; i<new_sz; i++ )
ofbuf[i] = nfbuf[i];
if ( msync( ofbuf, /*MPPH.new_sz*/ 0 , MS_SYNC) )
perror( "Error msync ofbuf" );
munmap( ofbuf, new_sz );
close(hOldFile);
if( msync( nfbuf, new_sz, MS_SYNC ) )
perror( "Error msync nfbuf" );
munmap( nfbuf, new_sz );
close(hNewFile);
}
bool SetEndOfFile( int fd )
{
long int new_size;
new_size = lseek(fd,0L,SEEK_CUR);
if( -1 == new_size )
return ( -1 );
if ( write( fd, "\0", 1) <= 0 )
return ( -1 );
if( ftruncate(fd, new_size) != -1 )
return true;
return false;
}
bool ResizeFile( int fd, int new_sz )
{
if ( new_sz != lseek( fd, new_sz, SEEK_SET ) )
return false;
if (!SetEndOfFile(fd) )
return false;
if ( 0 != lseek(fd,0,SEEK_SET))
return false;
return true;
}
>How-To-Repeat:
I used two text files,
<oldf.txt, 133bytes>
auto testing:
Functional spec and Software design spec as guide to features testing.
Generator testing:
command line testing.
<newf.txt, 155bytes>
auto testing:
Functional spec and Software design spec as guide to features testing.
Generator testing:
command line testing.
Just added a line.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102052358.f15Nwfi06015>
