Machine dependent _write failures with EINVAL error code

后端 未结 5 863
日久生厌
日久生厌 2021-01-03 09:48

This has some lengthy background before the actual question, however, it bears some explaining to hopefully weed out some red herrings.

Our application, developed in

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-03 10:09

    We had a very similar problem which we managed to reproduce quite easily. We first compiled the following program:

    #include 
    #include 
    #include 
    #include 
    #include 
    
    int main(int argc, char *argv[])
    { int len = 70000000;
      int handle= creat(argv[1], S_IWRITE | S_IREAD);
      setmode (handle, _O_BINARY);
      void *buf = malloc(len);
      int byteswritten = write(handle, buf, len);
      if (byteswritten == len)
        printf("Write successful.\n");
      else
        printf("Write failed.\n");
      close(handle);
      return 0;
    }
    

    Now, let's say you are working on the computer mycomputer and that C:\inbox maps to a shared folder \\mycomputer\inbox. Then the observe the following effect:

    C:\>a.exe C:\inbox\x
    Write successful.
    
    C:\>a.exe \\mycomputer\inbox\x
    Write failed.
    

    Note that if len is changed to 60000000, there is no problem...

    Based on this web page support.microsoft.com/kb/899149, we think it is a "limitation of the operating system" (the same effect has been observed with fwrite). Our work around is to try to cut the write in 63 MB pieces if it fails. This problem has apparently been corrected on Windows Vista.

    I hope this helps! Simon

提交回复
热议问题