Skip to content

Why is GENERC_WRITE flag set like this in dokan.c ? #1285

Closed

Description

@lymGitHub0123

in dokan.c,i find:
if ((*outDesiredAccess & FILE_GENERIC_WRITE)== FILE_GENERIC_WRITE) {
*outDesiredAccess |= GENERIC_WRITE;
genericWrite = TRUE;
}

Why not use "if ((*outDesiredAccess & FILE_GENERIC_WRITE) !=0) " ?

For example, if I only use "FILE_WRITE_DATA", outDesiredAccess will not be set GENERIC_WRITE.

Activity

  1. lymGitHub0123 commented on Apr 17, 2025

    @lymGitHub0123
    Author

    Another question, if I want to use outDesiredAccess(mean genericDesiredAccess in func mirrorCreateFile) and outDesiredAccess(mean creationDisposition in func mirrorCreateFile) to determine whether the operation in the current mirrorCreateFile is a write operation, what should I do? Please give me some advice. Thank u so much

  2. Liryna commented on Apr 17, 2025

    @Liryna
    Member

    Why not use "if ((*outDesiredAccess & FILE_GENERIC_WRITE) !=0) " ?

    This function is a helper to map the kernel FILE_GENERIC_WRITE to GENERIC_WRITE
    SYNCHRONIZE is present in all ``FILE_GENERIC_, if we would do !=0` , all `GENERIC_` would be set.
    I agree that maybe something better could be done here for when `FILE_GENERIC_` isn't set but `FILE_WRITE_DATA` only is set 👍

    determine whether the operation in the current mirrorCreateFile is a write operation, what should I do?

    https://github.com/dokan-dev/dokany/blob/master/samples/dokan_memfs/memfs_operations.cpp#L140-L154
    and you can check desiredaccess against FILE_GENERIC_WRITE and other bit it is composed of https://learn.microsoft.com/en-us/windows/win32/fileio/file-security-and-access-rights

  3. lymGitHub0123 commented on Apr 27, 2025

    @lymGitHub0123
    Author

    Why not use "if ((*outDesiredAccess & FILE_GENERIC_WRITE) !=0) " ?

    This function is a helper to map the kernel FILE_GENERIC_WRITE to GENERIC_WRITE SYNCHRONIZE is present in all ``FILE_GENERIC__, if we would do !=0` , all `GENERIC__` would be set. I agree that maybe something better could be done here for when `FILE_GENERIC_` isn't set but `FILE_WRITE_DATA` only is set 👍

    determine whether the operation in the current mirrorCreateFile is a write operation, what should I do?

    https://github.com/dokan-dev/dokany/blob/master/samples/dokan_memfs/memfs_operations.cpp#L140-L154 and you can check desiredaccess against FILE_GENERIC_WRITE and other bit it is composed of https://learn.microsoft.com/en-us/windows/win32/fileio/file-security-and-access-rights


    Thks for your reply. I have implemented a read-write separation demo based on mirror. c and implemented COW. However, I am currently experiencing an issue. While testing Steam CS2, the game entered normally and the human-machine battle started normally. But once real person matching is performed, there will be the following situations:

    1. If there is only one real person in the current battle (including me, there are two real people, and the rest are robots), the game is normal
    2. But once multiple real people are matched in the battle, the game will immediately not respond(looklike hangup).
      Is there any good troubleshooting idea for this?
      PS:
    3. I used processMonitor to filter cs2 process operations that are not 'Success', the output is
      QueryDirectory
      CreateFile
      ReadFile
      RegQueryValue
      FileSystemControl
      RegOpenKey
      The operation of Reg can be ignored. I found that there is a FileSystemControl part, why doesn't Dokany need to map it?

    Image

    1. In the same environment, there is no such problem when starting a real person battle of "League of Legends (LOL)".

    This has been bothering me for a long time, looking forward to your reply :-)

  4. lymGitHub0123 commented on Apr 27, 2025

    @lymGitHub0123
    Author

    Add another piece of information:
    1、The above situation of CS2 occurs in the lower layer (rootDir) where it is RO disk
    If the lower layer (rootDir) is RW disk, there won't be any problem.
    At first, I thought it was a read-write separation problem, such as attempting to write a read-only file causing a hang up. But I found that in RW disk, the game runs normally until the end, and the files in the entire lower layer have not been changed (I used the "everything" tool to analyze the file modification time of the latest modified lower directory)
    2、param is : mirror.exe /o /m /l e /f /p

  5. locked and limited conversation to collaborators on Apr 27, 2025
  6. converted this issue into a discussion #1291 on Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions