Bug 9132 - mmap with MAP_PRIVATE, PAGE_READ|PAGE_WRITE does not work
Summary: mmap with MAP_PRIVATE, PAGE_READ|PAGE_WRITE does not work
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: kernel   
(Show other bugs)
Version: 6.0
Hardware: i386 Linux
medium
high
Target Milestone: ---
Assignee: Michael K. Johnson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-02-04 20:26 UTC by Raju Govindarajan
Modified: 2008-05-01 15:37 UTC (History)
1 user (show)

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: ---


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

Description Raju Govindarajan 2000-02-04 20:26:44 UTC
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 20:29:59 UTC
Created attachment 92 [details]
Test file to reproduce bug, with comments

Comment 2 Alan Cox 2000-08-08 19:21:23 UTC
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.