Bug 9132
| Summary: | mmap with MAP_PRIVATE, PAGE_READ|PAGE_WRITE does not work | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Retired] Red Hat Linux | Reporter: | Raju Govindarajan <rgovi> | ||||
| Component: | kernel | Assignee: | Michael K. Johnson <johnsonm> | ||||
| Status: | CLOSED NOTABUG | QA Contact: | |||||
| Severity: | high | Docs Contact: | |||||
| Priority: | medium | ||||||
| Version: | 6.0 | CC: | rgovi | ||||
| Target Milestone: | --- | ||||||
| Target Release: | --- | ||||||
| Hardware: | i386 | ||||||
| OS: | Linux | ||||||
| Whiteboard: | |||||||
| Fixed In Version: | Doc Type: | Bug Fix | |||||
| Doc Text: | Story Points: | --- | |||||
| Clone Of: | Environment: | ||||||
| Last Closed: | 2000-02-04 20:29:58 UTC | Type: | --- | ||||
| Regression: | --- | Mount Type: | --- | ||||
| Documentation: | --- | CRM: | |||||
| Verified Versions: | Category: | --- | |||||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
| Cloudforms Team: | --- | Target Upstream Version: | |||||
| Embargoed: | |||||||
| Attachments: |
|
||||||
Created attachment 92 [details]
Test file to reproduce bug, with comments
I dont see what there is a bug. you create a private (copy on write) map which doesnt get written back to the file. And you observe mmap doesnt extend files -also correct behaviour |
Sample code and problem description follows: //========================================================= // e-mail fixes to rgovi, nara19 //========================================================= #include <unistd.h> #include <sys/mman.h> #include <stdio.h> #include <stdlib.h> int main() { //========================================================= // sample try.me file is a 1 line file with about 20 chars // e.g. : What is on the menu? //========================================================= FILE *f = fopen("try.me", "r+"); char*pData; if (!f) { printf("Unable to open file\n"); exit(-1); } //========================================================= // if MAP_SHARED is used, then changes to mmapped file are visible // immediately, however MAP_PRIVATE does not seem to work //========================================================= pData =(char*)mmap((void *)0, 4096, PROT_WRITE|PROT_READ, MAP_PRIVATE, fileno(f), 0); if (!pData) { printf("Unable to map file\n"); exit(-1); } //========================================================= // the following changes show up in the mmap memory, but are NOT // written to the file //========================================================= pData[0] = 'F'; pData[1] = 'o'; pData[2] = 'o'; pData[3] = 'd'; //========================================================= // Even if MAP_SHARED is used, write beyond the current size of the // file do not show up in the file // Instead, the file must be unmapped, it has to be resize using // ftruncate, and then re-mapped.: //========================================================= strcpy(pData, "Some long string longer than the original size of file"); munmap(pData, 4096); //========================================================= // data still does not show up after this fclose - // original file remains unchanged //========================================================= fclose(f); exit(0); }