title: memory mapped files
body: <p>I wrote a code for writing the content to the mapped buffer which mapped by using the mmap() system call.
  After I did some the changes in the mapped buffer,then I called the msync().It should update to the file on disk.</p>
  
  <p>But,It doesn't made any changes to the file on disk.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #include&lt;unistd.h&gt; 
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include&lt;sys/mman.h&gt;
  #include&lt;fcntl.h&gt;
  #define FILEMODE S_IRWXU | S_IRGRP | S_IROTH
  #define MAX 150
  
  main(int argc,char *argv[])
  {
  int fd,ret,len;
  long int len_file;
  struct stat st;
  char *addr;
  char buf[MAX];
  
  
  if(argc &gt; 1)
  {
      if((fd = open(argv[1],O_RDWR | O_APPEND | O_CREAT ,FILEMODE)) &lt; 0)
          perror("Error in file opening");
  
      if((ret=fstat(fd,&amp;st)) &lt; 0)
          perror("Error in fstat");
  
      len_file = st.st_size;
  
             /*len_file having the total length of the file(fd).*/
  
  
      if((addr=mmap(NULL,len_file,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0)) == MAP_FAILED)
          perror("Error in mmap");
  
      len = len_file; 
  
      while((fgets(buf,MAX,stdin)) != NULL)
      {
          strcat(addr+len,buf);
          printf( "Val:%s\n",addr ) ; //Checking purpose
          len = len + (strlen(buf));
      }
      if((msync(addr,len,MS_SYNC)) &lt; 0)
          perror("Error in msync");
  
      if( munmap(addr,len) == -1)
          printf("Error:\n");
      printf("addr %p\n",addr);
  }
  else
  {
      printf("Usage a.out &lt;filename&gt;\n");
  }
  }
  </code></pre>