[GHC] #4363: openFile sharing permissions are inconsistent across platforms
GHC
cvs-ghc at haskell.org
Thu Mar 8 17:04:24 CET 2012
#4363: openFile sharing permissions are inconsistent across platforms
---------------------------------+------------------------------------------
Reporter: jystic | Owner:
Type: bug | Status: new
Priority: high | Milestone: 7.6.1
Component: libraries/base | Version: 6.12.3
Keywords: | Os: Windows
Architecture: Unknown/Multiple | Failure: Incorrect result at runtime
Difficulty: | Testcase:
Blockedby: | Blocking:
Related: |
---------------------------------+------------------------------------------
Comment(by jystic):
I've read through the mailing list archives and I can understand where
Duncan is coming from. The lazy IO problem certainly complicates matters.
Would it be feasible to implementing in-process locking on Windows?
It seems to me like that would be a solution which is good enough to solve
this specific problem. Sure it would be great to offer a more advanced
file API in the long term, but it could be a while before the community
comes to a consensus on the right design.
I see that the POSIX file locking code uses the device and inode as a
unique identifier for files. Unfortunately, Windows doesn't return
sensible information for st_ino when using fstat. You can however get a
similar thing using GetFileInformationByHandle.
Here's an example I just tested out using gcc on Windows.
{{{
#include <stdio.h>
#include <share.h>
#include <fcntl.h>
#include <windows.h>
int main()
{
const wchar_t *file = L"file.txt";
int fd;
HANDLE h;
BY_HANDLE_FILE_INFORMATION info;
long long inode;
int device;
/* assuming file already exists */
fd = _wsopen(file, O_RDWR | _O_NOINHERIT, _SH_DENYWR, 0);
/* convert file descriptor to windows handle */
h = (HANDLE)_get_osfhandle(fd);
if (GetFileInformationByHandle(h, &info))
{
device = info.dwVolumeSerialNumber;
inode = info.nFileIndexLow | ((long long)info.nFileIndexHigh <<
32);
printf("device: %x\n", device);
printf("inode: %I64x\n", inode);
}
return 0;
}
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4363#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list