Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SAL annotations to Dokan callbacks parameters #1073

Open
infeo opened this issue Mar 7, 2022 · 1 comment
Open

Add SAL annotations to Dokan callbacks parameters #1073

infeo opened this issue Mar 7, 2022 · 1 comment

Comments

@infeo
Copy link
Member

infeo commented Mar 7, 2022

Summary

Add to all callbacks SAL annotations to indicate the intent of pointer paramters.

Description

First of all, i'm not a c++ programmer, so I don't know if this makes sense or is even feasible.

This question arose to me during the migration fom Dokany 1.x to 2.x. Newer functions like DokanCloseHandle(...) are using SAL annotations to indicate the usage intent of function parameters and so, reduce misuse of them.

From my point of view, such annotations would be also benefical for the dokan callbacks, since it is not always clear, which parameter struct can and should be altered. Especially this holds for the DokanFileInfo struct, since this one cannot be looked up in any Windows documentation.

As an example, in the sample mirrorfs, in the dokanFileInfo struct the directory attribute is set:

if (fileAttr != INVALID_FILE_ATTRIBUTES &&
fileAttr & FILE_ATTRIBUTE_DIRECTORY) {
if (CreateOptions & FILE_NON_DIRECTORY_FILE) {
DbgPrint(L"\tCannot open a dir as a file\n");
return STATUS_FILE_IS_A_DIRECTORY;
}
DokanFileInfo->IsDirectory = TRUE;
// Needed by FindFirstFile to list files in it
// TODO: use ReOpenFile in MirrorFindFiles to set share read temporary
ShareAccess |= FILE_SHARE_READ;
}

I would assume the kernel driver is responsible for setting such attributes correctly, but it seems like we have to deal with it.

@ljluestc
Copy link

#include <sal.h>

// Example callback function with SAL annotations
NTSTATUS DOKAN_CALLBACK MyDokanCreateFile(
    LPCWSTR FileName,
    PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
    ACCESS_MASK DesiredAccess,
    ULONG FileAttributes,
    ULONG ShareAccess,
    ULONG CreateDisposition,
    ULONG CreateOptions,
    PDOKAN_FILE_INFO DokanFileInfo) 
{
    // Your implementation here
    return STATUS_SUCCESS;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants