Date: Thu, 27 Jul 2000 15:22:01 +0300 From: Dimitar Peikov <mitko@rila.bg> To: hackers@FreeBSD.ORG Subject: mmap syncs and file extends Message-ID: <00072715314205.05330@earth>
next in thread | raw e-mail | index | archive | help
Hi, hackers, I've try to use mmap() and resize the mapping. msync() syncronizes only t= he memory that was mmapped with mmap(). How can I extend the main file? Memo= ry is filled correctly, but I must write extended data to file by hand. In my examples 'x.txt' was 11 bytes (some text); Where I'm wrong? ---------- #include <unistd.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> =20 int main() { char *ptr; int fd, size=3D20; =20 fd =3D open("x.txt", O_RDWR | O_CREAT); ptr =3D mmap(0, 15, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ptr[0] =3D 'D'; ptr[6] =3D 'D'; ptr =3D mremap(ptr, 10, 20, 1); close(fd); ptr[10] =3D 'Y'; ptr[12] =3D 'X'; printf("1%C\n", ptr[12]); msync(ptr, size, MS_SYNC); munmap(ptr, size); } ---------- --=20 Dimitar Peikov Programmer "We Build e-Business" =20 RILA Solutions =20 27 Building, Acad.G.Bonchev Str. =20 1113 Sofia, Bulgaria =20 home: (+359 2) 595495 phone: (+359 2) 9797320=20 phone: (+359 2) 9797300=20 fax: (+359 2) 9733355 =20 http://www.rila.com=20 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?00072715314205.05330>