Bug 9132 - mmap with MAP_PRIVATE, PAGE_READ|PAGE_WRITE does not work
mmap with MAP_PRIVATE, PAGE_READ|PAGE_WRITE does not work
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: kernel (Show other bugs)
6.0
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Michael K. Johnson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-02-04 15:26 EST by Raju Govindarajan
Modified: 2008-05-01 11:37 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-02-04 15:29:58 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Test file to reproduce bug, with comments (1.96 KB, text/plain)
2000-02-04 15:29 EST, Raju Govindarajan
no flags Details

  None (edit)
Description Raju Govindarajan 2000-02-04 15:26:44 EST
Sample code and problem description follows:

//=========================================================
// e-mail fixes to rgovi@yahoo.com, nara19@yahoo.com
//=========================================================

#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);
}
Comment 1 Raju Govindarajan 2000-02-04 15:29:59 EST
Created attachment 92 [details]
Test file to reproduce bug, with comments
Comment 2 Alan Cox 2000-08-08 15:21:23 EDT
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

Note You need to log in before you can comment on or make changes to this bug.