0

We need to determine whether a file we have open has an open file mapping handle or mapped view.

The only method I have found which should work is to use SetEndOfFile to attempt to add a few bytes to the end of the file, and remove these again, and test for failure + ERROR_USER_MAPPED_FILE.

While the documentation for SetEndOfFile explicitly requires the file to not be mapped, this still seems like a fairly convoluted workaround. Is there an easier way?

  • for what this is need ? assume you somehow got this information. but after you got it and before analyze/use - situation can changed - file can be mapped or unmapped – RbMm Jan 24 '18 at 13:42
  • We manage the files and returning the file mapping handles - we just don't know whether they still exist. So we can lock out returning new handles while we do our bookkeeping, but we can't run the bookkeeping while handles are open. – H. Arlinghaus Jan 24 '18 at 13:56
  • 1
    hard understand what you doing and for what here need know are exist section on file or not. even if section exist, you anyway can create new section on file – RbMm Jan 24 '18 at 14:17
  • 1
    They exist until you close them. Sounds like you are trying to save the problem the wrong way. Wouldn't it be better to remember the handle? – David Heffernan Jan 24 '18 at 14:22
  • The client remembers the handle, and threads in the client map the data and work with it. The data provider does not care about the lifetime of the handles and the file mappings used by the threads in the clients, but it cannot remove unrelated metadata at the end of the file while a restricted range at the beginning of the file is open by a client. – H. Arlinghaus Jan 24 '18 at 15:00
  • anyway not clear for what you know are file mapped or no. you need return section handle to client - simply do it. for this not need know are file already mapped. and can be multiple sections on file at once. you want truncate file ? this of course impossible while file is mapped. but what knowledge about this give you ? you anyway can not truncate. simply try do what you need. if you got error - mean file still mapped. may be you faster need notification when file no more in use ? for this you need change client code, for notify on this – RbMm Jan 25 '18 at 10:48

0 Answers0