title: Why the file could be written after changing the attribute to readonly under windows?
body: <p>Given one normal file, it could be read and written. Then I change this file attribute to <code>Read-only</code> through </p>
  
  <p><a href="https://i.stack.imgur.com/HDSDt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HDSDt.png" alt="enter image description here"></a></p>
  
  <p>However, this file still could be written through file handler. Here are my codes</p>
  
  <pre><code>#define CREATE_FILE_OPT FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_RANDOM_ACCESS
  std::string name("test.txt");
  HANDLE hfile = ::CreateFile(name.c_str(),
      GENERIC_READ | GENERIC_WRITE, NULL, NULL, OPEN_EXISTING, CREATE_FILE_OPT, NULL);
  
  if (hfile == INVALID_HANDLE_VALUE) {
      hfile = ::CreateFile(name.c_str(),
          GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_NEW, CREATE_FILE_OPT, NULL);
      if (hfile == INVALID_HANDLE_VALUE) {
          printf("so sad, invalid file handler....");
          return -1;
      }
  }
  
  int i = 0;
  char rbuf[] = "you are";
  DWORD bytesWritten;
  do {
      Sleep(5000);
      ++i;
      bytesWritten = 0;
      BOOL bret = ::WriteFile(hfile, rbuf, strlen(rbuf), &amp;bytesWritten, NULL);
      if (bret == FALSE) {
          printf("Cannot write bytes into file.....");
  
          DWORD err = GetLastError();
  
          printf("The error code is %d\n", err);
      }
      else
          printf("write %d bytes to file\n", bytesWritten);
  
      DWORD ret = GetFileAttributes(name.c_str());
      printf("The file attribute is %d\n", ret);
  
  } while (i &lt; 10000);
  </code></pre>
  
  <p>The file attribute is <code>32</code> before I change it to <code>Read-only</code>, but it will be <code>33</code> after this file is <code>Read-only</code>. </p>
  
  <p>I want to know why the file could be written after change it to <code>Read-only</code>? Is there any issue in my test codes?</p>
  
  <p>PS: test it in VS2015 under windows 7.</p>