Restoring a file for HSM without shared_write access

I’m working on an HSM project for work and have run into the issue of
restoring a file when there isn’t shared write access to it. To verify
that that is the problem, I’ve added shared write access to files opened
without it that I need to restore. Obviously, this is not a
ready-for-prime-time solution to the problem :wink: Things I’m considering
as real solutions:

  1. Keep track of the owning process that isn’t sharing write access,
    and denying other creates if they request write access. This seems
    fraught with the peril of either missing a case when I should deny
    access and allow it, or when I shouldn’t deny access and disallow it.

  2. Open the file for the userland service with
    IO_IGNORE_SHARE_ACCESS_CHECK. This would have the advantage of not
    having to perfectly emulate the windows sharing stuff, but according to
    the docs “Indicates that the I/O manager should not perform share-access
    checks on the file object after it is created. However, the file system
    might still perform these checks.” Which means the FS could still
    prevent the restore service from restoring the file.

Option 2 sounds like the better approach if the FS allows it. I haven’t
tried either yet and thought I’d seek an opinion as to which would be a
better choice, or if there’s another option I should be looking at.
Thoughts please?

~Eric