github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/dokan/dokan_header/dokan.h (about)

     1  /*
     2    Dokan : user-mode file system library for Windows
     3  
     4    Copyright (C) 2015 - 2018 Adrien J. <liryna.stark@gmail.com> and Maxime C. <maxime@islog.com>
     5    Copyright (C) 2007 - 2011 Hiroki Asakawa <info@dokan-dev.net>
     6  
     7    http://dokan-dev.github.io
     8  
     9  This program is free software; you can redistribute it and/or modify it under
    10  the terms of the GNU Lesser General Public License as published by the Free
    11  Software Foundation; either version 3 of the License, or (at your option) any
    12  later version.
    13  
    14  This program is distributed in the hope that it will be useful, but WITHOUT ANY
    15  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    16  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    17  
    18  You should have received a copy of the GNU Lesser General Public License along
    19  with this program. If not, see <http://www.gnu.org/licenses/>.
    20  */
    21  
    22  #ifndef DOKAN_H_
    23  #define DOKAN_H_
    24  
    25  /** Do not include NTSTATUS. Fix  duplicate preprocessor definitions */
    26  #define WIN32_NO_STATUS
    27  #include <windows.h>
    28  #undef WIN32_NO_STATUS
    29  #include <ntstatus.h>
    30  
    31  #include "fileinfo.h"
    32  #include "public.h"
    33  
    34  #ifdef _EXPORTING
    35  /** Export dokan API see also dokan.def for export */
    36  #define DOKANAPI __stdcall
    37  #else
    38  /** Import dokan API */
    39  #define DOKANAPI __declspec(dllimport) __stdcall
    40  #endif
    41  
    42  /** Change calling convention to standard call */
    43  #define DOKAN_CALLBACK __stdcall
    44  
    45  #ifdef __cplusplus
    46  extern "C" {
    47  #endif
    48  
    49  /** @file */
    50  
    51  /**
    52   * \defgroup Dokan Dokan
    53   * \brief Dokan Library const and methods
    54   */
    55  /** @{ */
    56  
    57  /** The current Dokan version (ver 1.2.0). \ref DOKAN_OPTIONS.Version */
    58  #define DOKAN_VERSION 120
    59  /** Minimum Dokan version (ver 1.1.0) accepted. */
    60  #define DOKAN_MINIMUM_COMPATIBLE_VERSION 110
    61  /** Maximum number of dokan instances.*/
    62  #define DOKAN_MAX_INSTANCES 32
    63  /** Driver file name including the DOKAN_MAJOR_API_VERSION */
    64  #define DOKAN_DRIVER_NAME L"dokan" DOKAN_MAJOR_API_VERSION L".sys"
    65  /** Network provider name including the DOKAN_MAJOR_API_VERSION */
    66  #define DOKAN_NP_NAME L"Dokan" DOKAN_MAJOR_API_VERSION
    67  
    68  /** @} */
    69  
    70  /**
    71   * \defgroup DOKAN_OPTION DOKAN_OPTION
    72   * \brief All DOKAN_OPTION flags used in DOKAN_OPTIONS.Options
    73   * \see DOKAN_FILE_INFO
    74   */
    75  /** @{ */
    76  
    77  /** Enable ouput debug message */
    78  #define DOKAN_OPTION_DEBUG 1
    79  /** Enable ouput debug message to stderr */
    80  #define DOKAN_OPTION_STDERR 2
    81  /** Use alternate stream */
    82  #define DOKAN_OPTION_ALT_STREAM 4
    83  /** Enable mount drive as write-protected */
    84  #define DOKAN_OPTION_WRITE_PROTECT 8
    85  /** Use network drive - Dokan network provider needs to be installed */
    86  #define DOKAN_OPTION_NETWORK 16
    87  /** Use removable drive */
    88  #define DOKAN_OPTION_REMOVABLE 32
    89  /** Use mount manager */
    90  #define DOKAN_OPTION_MOUNT_MANAGER 64
    91  /** Mount the drive on current session only */
    92  #define DOKAN_OPTION_CURRENT_SESSION 128
    93  /** Enable Lockfile/Unlockfile operations. Otherwise Dokan will take care of it */
    94  #define DOKAN_OPTION_FILELOCK_USER_MODE 256
    95  
    96  /** @} */
    97  
    98  /**
    99   * \struct DOKAN_OPTIONS
   100   * \brief Dokan mount options used to describe Dokan device behavior.
   101   * \see DokanMain
   102   */
   103  typedef struct _DOKAN_OPTIONS {
   104    /** Version of the Dokan features requested (version "123" is equal to Dokan version 1.2.3). */
   105    USHORT Version;
   106    /** Number of threads to be used internally by Dokan library. More threads will handle more events at the same time. */
   107    USHORT ThreadCount;
   108    /** Features enabled for the mount. See \ref DOKAN_OPTION. */
   109    ULONG Options;
   110    /** FileSystem can store anything here. */
   111    ULONG64 GlobalContext;
   112    /** Mount point. Can be "M:\" (drive letter) or "C:\mount\dokan" (path in NTFS). */
   113    LPCWSTR MountPoint;
   114    /**
   115    * UNC Name for the Network Redirector
   116    * \see <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff556761(v=vs.85).aspx">Support for UNC Naming</a>
   117    */
   118    LPCWSTR UNCName;
   119    /** Max timeout in milliseconds of each request before Dokan gives up. */
   120    ULONG Timeout;
   121    /** Allocation Unit Size of the volume. This will affect the file size. */
   122    ULONG AllocationUnitSize;
   123    /** Sector Size of the volume. This will affect the file size. */
   124    ULONG SectorSize;
   125  } DOKAN_OPTIONS, *PDOKAN_OPTIONS;
   126  
   127  /**
   128   * \struct DOKAN_FILE_INFO
   129   * \brief Dokan file information on the current operation.
   130   */
   131  typedef struct _DOKAN_FILE_INFO {
   132    /**
   133     * Context that can be used to carry information between operations.
   134     * The context can carry whatever type like \c HANDLE, struct, int,
   135     * internal reference that will help the implementation understand the request context of the event.
   136     */
   137    ULONG64 Context;
   138    /** Reserved. Used internally by Dokan library. Never modify. */
   139    ULONG64 DokanContext;
   140    /** A pointer to DOKAN_OPTIONS which was passed to DokanMain. */
   141    PDOKAN_OPTIONS DokanOptions;
   142    /**
   143     * Process ID for the thread that originally requested a given I/O operation.
   144     */
   145    ULONG ProcessId;
   146    /**
   147     * Requesting a directory file.
   148     * Must be set in \ref DOKAN_OPERATIONS.ZwCreateFile if the file appears to be a folder.
   149     */
   150    UCHAR IsDirectory;
   151    /** Flag if the file has to be deleted during DOKAN_OPERATIONS. Cleanup event. */
   152    UCHAR DeleteOnClose;
   153    /** Read or write is paging IO. */
   154    UCHAR PagingIo;
   155    /** Read or write is synchronous IO. */
   156    UCHAR SynchronousIo;
   157    /** Read or write directly from data source without cache */
   158    UCHAR Nocache;
   159    /**  If \c TRUE, write to the current end of file instead of using the Offset parameter. */
   160    UCHAR WriteToEndOfFile;
   161  } DOKAN_FILE_INFO, *PDOKAN_FILE_INFO;
   162  
   163  /**
   164   * \brief FillFindData Used to add an entry in FindFiles operation
   165   * \return 1 if buffer is full, otherwise 0 (currently it never returns 1)
   166   */
   167  typedef int(WINAPI *PFillFindData)(PWIN32_FIND_DATAW, PDOKAN_FILE_INFO);
   168  
   169  /**
   170   * \brief FillFindStreamData Used to add an entry in FindStreams
   171   * \return 1 if buffer is full, otherwise 0 (currently it never returns 1)
   172   */
   173  typedef int(WINAPI *PFillFindStreamData)(PWIN32_FIND_STREAM_DATA,
   174                                           PDOKAN_FILE_INFO);
   175  
   176  // clang-format off
   177  
   178  /**
   179   * \struct DOKAN_OPERATIONS
   180   * \brief Dokan API callbacks interface
   181   *
   182   * DOKAN_OPERATIONS is a struct of callbacks that describe all Dokan API operations
   183   * that will be called when Windows access to the filesystem.
   184   *
   185   * If an error occurs, return NTSTATUS (https://support.microsoft.com/en-us/kb/113996).
   186   * Win32 Error can be converted to \c NTSTATUS with \ref DokanNtStatusFromWin32
   187   *
   188   * All callbacks can be set to \c NULL or return \c STATUS_NOT_IMPLEMENTED
   189   * if supporting one of them is not desired. Be aware that returning such values to important callbacks
   190   * such as DOKAN_OPERATIONS.ZwCreateFile / DOKAN_OPERATIONS.ReadFile / ... would make the filesystem not work or become unstable.
   191   */
   192  typedef struct _DOKAN_OPERATIONS {
   193    /**
   194    * \brief CreateFile Dokan API callback
   195    *
   196    * CreateFile is called each time a request is made on a file system object.
   197    *
   198    * In case \c OPEN_ALWAYS & \c CREATE_ALWAYS are successfully opening an
   199    * existing file, \c STATUS_OBJECT_NAME_COLLISION should be returned instead of \c STATUS_SUCCESS .
   200    * This will inform Dokan that the file has been opened and not created during the request.
   201    *
   202    * If the file is a directory, CreateFile is also called.
   203    * In this case, CreateFile should return \c STATUS_SUCCESS when that directory
   204    * can be opened and DOKAN_FILE_INFO.IsDirectory has to be set to \c TRUE.
   205    * On the other hand, if DOKAN_FILE_INFO.IsDirectory is set to \c TRUE
   206    * but the path targets a file, \c STATUS_NOT_A_DIRECTORY must be returned.
   207    *
   208    * DOKAN_FILE_INFO.Context can be used to store Data (like \c HANDLE)
   209    * that can be retrieved in all other requests related to the Context.
   210    * To avoid memory leak, Context needs to be released in DOKAN_OPERATIONS.Cleanup.
   211    *
   212    * \param FileName File path requested by the Kernel on the FileSystem.
   213    * \param SecurityContext SecurityContext, see https://msdn.microsoft.com/en-us/library/windows/hardware/ff550613(v=vs.85).aspx
   214    * \param DesiredAccess Specifies an <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff540466(v=vs.85).aspx">ACCESS_MASK</a> value that determines the requested access to the object.
   215    * \param FileAttributes Specifies one or more FILE_ATTRIBUTE_XXX flags, which represent the file attributes to set if a file is created or overwritten.
   216    * \param ShareAccess Type of share access, which is specified as zero or any combination of FILE_SHARE_* flags.
   217    * \param CreateDisposition Specifies the action to perform if the file does or does not exist.
   218    * \param CreateOptions Specifies the options to apply when the driver creates or opens the file.
   219    * \param DokanFileInfo Information about the file or directory.
   220    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   221    * \see <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff566424(v=vs.85).aspx">See ZwCreateFile for more information about the parameters of this callback (MSDN).</a>
   222    * \see DokanMapKernelToUserCreateFileFlags
   223    */
   224    NTSTATUS(DOKAN_CALLBACK *ZwCreateFile)(LPCWSTR FileName,
   225        PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
   226        ACCESS_MASK DesiredAccess,
   227        ULONG FileAttributes,
   228        ULONG ShareAccess,
   229        ULONG CreateDisposition,
   230        ULONG CreateOptions,
   231        PDOKAN_FILE_INFO DokanFileInfo);
   232  
   233    /**
   234    * \brief Cleanup Dokan API callback
   235    *
   236    * Cleanup request before \ref CloseFile is called.
   237    *
   238    * When DOKAN_FILE_INFO.DeleteOnClose is \c TRUE, the file in Cleanup must be deleted.
   239    * See DeleteFile documentation for explanation.
   240    *
   241    * \param FileName File path requested by the Kernel on the FileSystem.
   242    * \param DokanFileInfo Information about the file or directory.
   243    * \see DeleteFile
   244    * \see DeleteDirectory
   245    */
   246    void(DOKAN_CALLBACK *Cleanup)(LPCWSTR FileName,
   247                                  PDOKAN_FILE_INFO DokanFileInfo);
   248  
   249    /**
   250    * \brief CloseFile Dokan API callback
   251    *
   252    * Clean remaining Context
   253    *
   254    * CloseFile is called at the end of the life of the context.
   255    * Anything remaining in \ref DOKAN_FILE_INFO.Context must be cleared before returning.
   256    *
   257    * \param FileName File path requested by the Kernel on the FileSystem.
   258    * \param DokanFileInfo Information about the file or directory.
   259    */
   260    void(DOKAN_CALLBACK *CloseFile)(LPCWSTR FileName,
   261      PDOKAN_FILE_INFO DokanFileInfo);
   262  
   263    /**
   264    * \brief ReadFile Dokan API callback
   265    *
   266    * ReadFile callback on the file previously opened in DOKAN_OPERATIONS.ZwCreateFile.
   267    * It can be called by different threads at the same time, so the read/context has to be thread safe.
   268    *
   269    * \param FileName File path requested by the Kernel on the FileSystem.
   270    * \param Buffer Read buffer that has to be filled with the read result.
   271    * \param BufferLength Buffer length and read size to continue with.
   272    * \param ReadLength Total data size that has been read.
   273    * \param Offset Offset from where the read has to be continued.
   274    * \param DokanFileInfo Information about the file or directory.
   275    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   276    * \see WriteFile
   277    */
   278    NTSTATUS(DOKAN_CALLBACK *ReadFile)(LPCWSTR FileName,
   279      LPVOID Buffer,
   280      DWORD BufferLength,
   281      LPDWORD ReadLength,
   282      LONGLONG Offset,
   283      PDOKAN_FILE_INFO DokanFileInfo);
   284  
   285    /**
   286    * \brief WriteFile Dokan API callback
   287    *
   288    * WriteFile callback on the file previously opened in DOKAN_OPERATIONS.ZwCreateFile
   289    * It can be called by different threads at the same time, sp the write/context has to be thread safe.
   290    *
   291    * \param FileName File path requested by the Kernel on the FileSystem.
   292    * \param Buffer Data that has to be written.
   293    * \param NumberOfBytesToWrite Buffer length and write size to continue with.
   294    * \param NumberOfBytesWritten Total number of bytes that have been written.
   295    * \param Offset Offset from where the write has to be continued.
   296    * \param DokanFileInfo Information about the file or directory.
   297    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   298    * \see ReadFile
   299    */
   300    NTSTATUS(DOKAN_CALLBACK *WriteFile)(LPCWSTR FileName,
   301      LPCVOID Buffer,
   302      DWORD NumberOfBytesToWrite,
   303      LPDWORD NumberOfBytesWritten,
   304      LONGLONG Offset,
   305      PDOKAN_FILE_INFO DokanFileInfo);
   306  
   307    /**
   308    * \brief FlushFileBuffers Dokan API callback
   309    *
   310    * Clears buffers for this context and causes any buffered data to be written to the file.
   311    *
   312    * \param FileName File path requested by the Kernel on the FileSystem.
   313    * \param DokanFileInfo Information about the file or directory.
   314    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   315    */
   316    NTSTATUS(DOKAN_CALLBACK *FlushFileBuffers)(LPCWSTR FileName,
   317      PDOKAN_FILE_INFO DokanFileInfo);
   318  
   319    /**
   320    * \brief GetFileInformation Dokan API callback
   321    *
   322    * Get specific information on a file.
   323    *
   324    * \param FileName File path requested by the Kernel on the FileSystem.
   325    * \param Buffer BY_HANDLE_FILE_INFORMATION struct to fill.
   326    * \param DokanFileInfo Information about the file or directory.
   327    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   328    */
   329    NTSTATUS(DOKAN_CALLBACK *GetFileInformation)(LPCWSTR FileName,
   330      LPBY_HANDLE_FILE_INFORMATION Buffer,
   331      PDOKAN_FILE_INFO DokanFileInfo);
   332  
   333    /**
   334    * \brief FindFiles Dokan API callback
   335    *
   336    * List all files in the requested path
   337    * \ref DOKAN_OPERATIONS.FindFilesWithPattern is checked first. If it is not implemented or
   338    * returns \c STATUS_NOT_IMPLEMENTED, then FindFiles is called, if implemented.
   339    *
   340    * \param FileName File path requested by the Kernel on the FileSystem.
   341    * \param FillFindData Callback that has to be called with PWIN32_FIND_DATAW that contain file information.
   342    * \param DokanFileInfo Information about the file or directory.
   343    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   344    * \see FindFilesWithPattern
   345    */
   346    NTSTATUS(DOKAN_CALLBACK *FindFiles)(LPCWSTR FileName,
   347      PFillFindData FillFindData,
   348      PDOKAN_FILE_INFO DokanFileInfo);
   349  
   350    /**
   351    * \brief FindFilesWithPattern Dokan API callback
   352    *
   353    * Same as \ref DOKAN_OPERATIONS.FindFiles but with a search pattern.
   354    *
   355    * \param PathName Path requested by the Kernel on the FileSystem.
   356    * \param SearchPattern Search pattern.
   357    * \param FillFindData Callback that has to be called with PWIN32_FIND_DATAW that contains file information.
   358    * \param DokanFileInfo Information about the file or directory.
   359    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   360    * \see FindFiles
   361    */
   362    NTSTATUS(DOKAN_CALLBACK *FindFilesWithPattern)(LPCWSTR PathName,
   363      LPCWSTR SearchPattern,
   364      PFillFindData FillFindData,
   365      PDOKAN_FILE_INFO DokanFileInfo);
   366  
   367    /**
   368    * \brief SetFileAttributes Dokan API callback
   369    *
   370    * Set file attributes on a specific file
   371    *
   372    * \param FileName File path requested by the Kernel on the FileSystem.
   373    * \param FileAttributes FileAttributes to set on file.
   374    * \param DokanFileInfo Information about the file or directory.
   375    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   376    */
   377    NTSTATUS(DOKAN_CALLBACK *SetFileAttributes)(LPCWSTR FileName,
   378      DWORD FileAttributes,
   379      PDOKAN_FILE_INFO DokanFileInfo);
   380  
   381    /**
   382    * \brief SetFileTime Dokan API callback
   383    *
   384    * Set file attributes on a specific file
   385    *
   386    * \param FileName File path requested by the Kernel on the FileSystem.
   387    * \param CreationTime Creation FILETIME.
   388    * \param LastAccessTime LastAccess FILETIME.
   389    * \param LastWriteTime LastWrite FILETIME.
   390    * \param DokanFileInfo Information about the file or directory.
   391    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   392    */
   393    NTSTATUS(DOKAN_CALLBACK *SetFileTime)(LPCWSTR FileName,
   394      CONST FILETIME *CreationTime,
   395      CONST FILETIME *LastAccessTime,
   396      CONST FILETIME *LastWriteTime,
   397      PDOKAN_FILE_INFO DokanFileInfo);
   398  
   399    /**
   400    * \brief DeleteFile Dokan API callback
   401    *
   402    * Check if it is possible to delete a file.
   403    *
   404    * DeleteFile will also be called with DOKAN_FILE_INFO.DeleteOnClose set to \c FALSE
   405    * to notify the driver when the file is no longer requested to be deleted.
   406    *
   407    * The file in DeleteFile should not be deleted, but instead the file
   408    * must be checked as to whether or not it can be deleted,
   409    * and \c STATUS_SUCCESS should be returned (when it can be deleted) or
   410    * appropriate error codes, such as \c STATUS_ACCESS_DENIED or
   411    * \c STATUS_OBJECT_NAME_NOT_FOUND, should be returned.
   412    *
   413    * When \c STATUS_SUCCESS is returned, a Cleanup call is received afterwards with
   414    * DOKAN_FILE_INFO.DeleteOnClose set to \c TRUE. Only then must the closing file
   415    * be deleted.
   416    *
   417    * \param FileName File path requested by the Kernel on the FileSystem.
   418    * \param DokanFileInfo Information about the file or directory.
   419    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   420    * \see DeleteDirectory
   421    * \see Cleanup
   422    */
   423    NTSTATUS(DOKAN_CALLBACK *DeleteFile)(LPCWSTR FileName,
   424      PDOKAN_FILE_INFO DokanFileInfo);
   425  
   426    /**
   427    * \brief DeleteDirectory Dokan API callback
   428    *
   429    * Check if it is possible to delete a directory.
   430    *
   431    * DeleteDirectory will also be called with DOKAN_FILE_INFO.DeleteOnClose set to \c FALSE
   432    * to notify the driver when the file is no longer requested to be deleted.
   433    *
   434    * The Directory in DeleteDirectory should not be deleted, but instead
   435    * must be checked as to whether or not it can be deleted,
   436    * and \c STATUS_SUCCESS should be returned (when it can be deleted) or
   437    * appropriate error codes, such as \c STATUS_ACCESS_DENIED,
   438    * \c STATUS_OBJECT_PATH_NOT_FOUND, or \c STATUS_DIRECTORY_NOT_EMPTY, should
   439    * be returned.
   440    *
   441    * When \c STATUS_SUCCESS is returned, a Cleanup call is received afterwards with
   442    * DOKAN_FILE_INFO.DeleteOnClose set to \c TRUE. Only then must the closing file
   443    * be deleted.
   444    *
   445    * \param FileName File path requested by the Kernel on the FileSystem.
   446    * \param DokanFileInfo Information about the file or directory.
   447    * \return \c STATUS_SUCCESS on success or \c NTSTATUS appropriate to the request result.
   448    * \ref DeleteFile
   449    * \ref Cleanup
   450    */
   451    NTSTATUS(DOKAN_CALLBACK *DeleteDirectory)(LPCWSTR FileName,
   452      PDOKAN_FILE_INFO DokanFileInfo);
   453  
   454    /**
   455    * \brief MoveFile Dokan API callback
   456    *
   457    * Move a file or directory to a new destination
   458    *
   459    * \param FileName Path for the file to be moved.
   460    * \param NewFileName Path for the new location of the file.
   461    * \param ReplaceIfExisting If destination already exists, can it be replaced?
   462    * \param DokanFileInfo Information about the file or directory.
   463    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   464    */
   465    NTSTATUS(DOKAN_CALLBACK *MoveFile)(LPCWSTR FileName,
   466      LPCWSTR NewFileName,
   467      BOOL ReplaceIfExisting,
   468      PDOKAN_FILE_INFO DokanFileInfo);
   469  
   470    /**
   471    * \brief SetEndOfFile Dokan API callback
   472    *
   473    * SetEndOfFile is used to truncate or extend a file (physical file size).
   474    *
   475    * \param FileName File path requested by the Kernel on the FileSystem.
   476    * \param ByteOffset File length to set.
   477    * \param DokanFileInfo Information about the file or directory.
   478    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   479    */
   480    NTSTATUS(DOKAN_CALLBACK *SetEndOfFile)(LPCWSTR FileName,
   481      LONGLONG ByteOffset,
   482      PDOKAN_FILE_INFO DokanFileInfo);
   483  
   484    /**
   485    * \brief SetAllocationSize Dokan API callback
   486    *
   487    * SetAllocationSize is used to truncate or extend a file.
   488    *
   489    * \param FileName File path requested by the Kernel on the FileSystem.
   490    * \param AllocSize File length to set.
   491    * \param DokanFileInfo Information about the file or directory.
   492    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   493    */
   494    NTSTATUS(DOKAN_CALLBACK *SetAllocationSize)(LPCWSTR FileName,
   495      LONGLONG AllocSize,
   496      PDOKAN_FILE_INFO DokanFileInfo);
   497  
   498    /**
   499    * \brief LockFile Dokan API callback
   500    *
   501    * Lock file at a specific offset and data length.
   502    * This is only used if \ref DOKAN_OPTION_FILELOCK_USER_MODE is enabled.
   503    *
   504    * \param FileName File path requested by the Kernel on the FileSystem.
   505    * \param ByteOffset Offset from where the lock has to be continued.
   506    * \param Length Data length to lock.
   507    * \param DokanFileInfo Information about the file or directory.
   508    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   509    * \see UnlockFile
   510    */
   511    NTSTATUS(DOKAN_CALLBACK *LockFile)(LPCWSTR FileName,
   512      LONGLONG ByteOffset,
   513      LONGLONG Length,
   514      PDOKAN_FILE_INFO DokanFileInfo);
   515  
   516    /**
   517    * \brief UnlockFile Dokan API callback
   518    *
   519    * Unlock file at a specific offset and data length.
   520    * This is only used if \ref DOKAN_OPTION_FILELOCK_USER_MODE is enabled.
   521    *
   522    * \param FileName File path requested by the Kernel on the FileSystem.
   523    * \param ByteOffset Offset from where the lock has to be continued.
   524    * \param Length Data length to lock.
   525    * \param DokanFileInfo Information about the file or directory.
   526    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   527    * \see LockFile
   528    */
   529    NTSTATUS(DOKAN_CALLBACK *UnlockFile)(LPCWSTR FileName,
   530      LONGLONG ByteOffset,
   531      LONGLONG Length,
   532      PDOKAN_FILE_INFO DokanFileInfo);
   533  
   534    /**
   535    * \brief GetDiskFreeSpace Dokan API callback
   536    *
   537    * Retrieves information about the amount of space that is available on a disk volume.
   538    * It consits of the total amount of space, the total amount of free space, and
   539    * the total amount of free space available to the user that is associated with the calling thread.
   540    *
   541    * Neither GetDiskFreeSpace nor \ref GetVolumeInformation
   542    * save the  DOKAN_FILE_INFO.Context.
   543    * Before these methods are called, \ref ZwCreateFile may not be called.
   544    * (ditto \ref CloseFile and \ref Cleanup)
   545    *
   546    * \param FreeBytesAvailable Amount of available space.
   547    * \param TotalNumberOfBytes Total size of storage space
   548    * \param TotalNumberOfFreeBytes Amount of free space
   549    * \param DokanFileInfo Information about the file or directory.
   550    * \return \c STATUS_SUCCESS on success or \c NTSTATUS appropriate to the request result.
   551    * \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx"> GetDiskFreeSpaceEx function (MSDN)</a>
   552    * \see GetVolumeInformation
   553    */
   554    NTSTATUS(DOKAN_CALLBACK *GetDiskFreeSpace)(PULONGLONG FreeBytesAvailable,
   555      PULONGLONG TotalNumberOfBytes,
   556      PULONGLONG TotalNumberOfFreeBytes,
   557      PDOKAN_FILE_INFO DokanFileInfo);
   558  
   559    /**
   560    * \brief GetVolumeInformation Dokan API callback
   561    *
   562    * Retrieves information about the file system and volume associated with the specified root directory.
   563    *
   564    * Neither GetVolumeInformation nor GetDiskFreeSpace
   565    * save the \ref DOKAN_FILE_INFO#Context.
   566    * Before these methods are called, \ref ZwCreateFile may not be called.
   567    * (ditto \ref CloseFile and \ref Cleanup)
   568    *
   569    * FileSystemName could be anything up to 10 characters.
   570    * But Windows check few feature availability based on file system name.
   571    * For this, it is recommended to set NTFS or FAT here.
   572    *
   573    * \c FILE_READ_ONLY_VOLUME is automatically added to the
   574    * FileSystemFlags if \ref DOKAN_OPTION_WRITE_PROTECT was
   575    * specified in DOKAN_OPTIONS when the volume was mounted.
   576    *
   577    * \param VolumeNameBuffer A pointer to a buffer that receives the name of a specified volume.
   578    * \param VolumeNameSize The length of a volume name buffer.
   579    * \param VolumeSerialNumber A pointer to a variable that receives the volume serial number.
   580    * \param MaximumComponentLength A pointer to a variable that receives the maximum length.
   581    * \param FileSystemFlags A pointer to a variable that receives flags associated with the specified file system.
   582    * \param FileSystemNameBuffer A pointer to a buffer that receives the name of the file system.
   583    * \param FileSystemNameSize The length of the file system name buffer.
   584    * \param DokanFileInfo Information about the file or directory.
   585    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   586    * \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx"> GetVolumeInformation function (MSDN)</a>
   587    * \see GetDiskFreeSpace
   588    */
   589    NTSTATUS(DOKAN_CALLBACK *GetVolumeInformation)(LPWSTR VolumeNameBuffer,
   590      DWORD VolumeNameSize,
   591      LPDWORD VolumeSerialNumber,
   592      LPDWORD MaximumComponentLength,
   593      LPDWORD FileSystemFlags,
   594      LPWSTR FileSystemNameBuffer,
   595      DWORD FileSystemNameSize,
   596      PDOKAN_FILE_INFO DokanFileInfo);
   597  
   598    /**
   599    * \brief Mounted Dokan API callback
   600    *
   601    * Called when Dokan successfully mounts the volume.
   602    *
   603    * \param DokanFileInfo Information about the file or directory.
   604    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   605    * \see Unmounted
   606    */
   607    NTSTATUS(DOKAN_CALLBACK *Mounted)(PDOKAN_FILE_INFO DokanFileInfo);
   608  
   609    /**
   610    * \brief Unmounted Dokan API callback
   611    *
   612    * Called when Dokan is unmounting the volume.
   613    *
   614    * \param DokanFileInfo Information about the file or directory.
   615    * \return \c STATUS_SUCCESS on success or \c NTSTATUS appropriate to the request result.
   616    * \see Unmounted
   617    */
   618    NTSTATUS(DOKAN_CALLBACK *Unmounted)(PDOKAN_FILE_INFO DokanFileInfo);
   619  
   620    /**
   621    * \brief GetFileSecurity Dokan API callback
   622    *
   623    * Get specified information about the security of a file or directory.
   624    *
   625    * Return \c STATUS_NOT_IMPLEMENTED to let dokan library build a sddl of the current process user with authenticate user rights for context menu.
   626    * Return \c STATUS_BUFFER_OVERFLOW if buffer size is too small.
   627    *
   628    * \since Supported since version 0.6.0. The version must be specified in \ref DOKAN_OPTIONS.Version.
   629    * \param FileName File path requested by the Kernel on the FileSystem.
   630    * \param SecurityInformation A SECURITY_INFORMATION value that identifies the security information being requested.
   631    * \param SecurityDescriptor A pointer to a buffer that receives a copy of the security descriptor of the requested file.
   632    * \param BufferLength Specifies the size, in bytes, of the buffer.
   633    * \param LengthNeeded A pointer to the variable that receives the number of bytes necessary to store the complete security descriptor.
   634    * \param DokanFileInfo Information about the file or directory.
   635    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   636    * \see SetFileSecurity
   637    * \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa446639(v=vs.85).aspx">GetFileSecurity function (MSDN)</a>
   638    */
   639    NTSTATUS(DOKAN_CALLBACK *GetFileSecurity)(LPCWSTR FileName,
   640      PSECURITY_INFORMATION SecurityInformation,
   641      PSECURITY_DESCRIPTOR SecurityDescriptor,
   642      ULONG BufferLength,
   643      PULONG LengthNeeded,
   644      PDOKAN_FILE_INFO DokanFileInfo);
   645  
   646    /**
   647    * \brief SetFileSecurity Dokan API callback
   648    *
   649    * Sets the security of a file or directory object.
   650    *
   651    * \since Supported since version 0.6.0. The version must be specified in \ref DOKAN_OPTIONS.Version.
   652    * \param FileName File path requested by the Kernel on the FileSystem.
   653    * \param SecurityInformation Structure that identifies the contents of the security descriptor pointed by \a SecurityDescriptor param.
   654    * \param SecurityDescriptor A pointer to a SECURITY_DESCRIPTOR structure.
   655    * \param BufferLength Specifies the size, in bytes, of the buffer.
   656    * \param DokanFileInfo Information about the file or directory.
   657    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   658    * \see GetFileSecurity
   659    * \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa379577(v=vs.85).aspx">SetFileSecurity function (MSDN)</a>
   660    */
   661    NTSTATUS(DOKAN_CALLBACK *SetFileSecurity)(LPCWSTR FileName,
   662      PSECURITY_INFORMATION SecurityInformation,
   663      PSECURITY_DESCRIPTOR SecurityDescriptor,
   664      ULONG BufferLength,
   665      PDOKAN_FILE_INFO DokanFileInfo);
   666  
   667    /**
   668    * \brief FindStreams Dokan API callback
   669    *
   670    * Retrieve all NTFS Streams informations on the file.
   671    * This is only called if \ref DOKAN_OPTION_ALT_STREAM is enabled.
   672    *
   673    * \since Supported since version 0.8.0. The version must be specified in \ref DOKAN_OPTIONS.Version.
   674    * \param FileName File path requested by the Kernel on the FileSystem.
   675    * \param FillFindStreamData Callback that has to be called with PWIN32_FIND_STREAM_DATA that contain stream information.
   676    * \param DokanFileInfo Information about the file or directory.
   677    * \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
   678    */
   679    NTSTATUS(DOKAN_CALLBACK *FindStreams)(LPCWSTR FileName,
   680      PFillFindStreamData FillFindStreamData,
   681      PDOKAN_FILE_INFO DokanFileInfo);
   682  
   683  } DOKAN_OPERATIONS, *PDOKAN_OPERATIONS;
   684  
   685  // clang-format on
   686  
   687  /**
   688   * \defgroup DokanMainResult DokanMainResult
   689   * \brief \ref DokanMain returns error codes
   690   */
   691  /** @{ */
   692  
   693  /** Dokan mount succeed. */
   694  #define DOKAN_SUCCESS 0
   695  /** Dokan mount error. */
   696  #define DOKAN_ERROR -1
   697  /** Dokan mount failed - Bad drive letter. */
   698  #define DOKAN_DRIVE_LETTER_ERROR -2
   699  /** Dokan mount failed - Can't install driver.  */
   700  #define DOKAN_DRIVER_INSTALL_ERROR -3
   701  /** Dokan mount failed - Driver answer that something is wrong. */
   702  #define DOKAN_START_ERROR -4
   703  /**
   704   * Dokan mount failed.
   705   * Can't assign a drive letter or mount point.
   706   * Probably already used by another volume.
   707   */
   708  #define DOKAN_MOUNT_ERROR -5
   709  /**
   710   * Dokan mount failed.
   711   * Mount point is invalid.
   712   */
   713  #define DOKAN_MOUNT_POINT_ERROR -6
   714  /**
   715   * Dokan mount failed.
   716   * Requested an incompatible version.
   717   */
   718  #define DOKAN_VERSION_ERROR -7
   719  
   720  /** @} */
   721  
   722  /**
   723   * \defgroup Dokan Dokan
   724   */
   725  /** @{ */
   726  
   727  /**
   728   * \brief Mount a new Dokan Volume.
   729   *
   730   * This function block until the device is unmounted.
   731   * If the mount fails, it will directly return a \ref DokanMainResult error.
   732   *
   733   * \param DokanOptions a \ref DOKAN_OPTIONS that describe the mount.
   734   * \param DokanOperations Instance of \ref DOKAN_OPERATIONS that will be called for each request made by the kernel.
   735   * \return \ref DokanMainResult status.
   736   */
   737  int DOKANAPI DokanMain(PDOKAN_OPTIONS DokanOptions,
   738                         PDOKAN_OPERATIONS DokanOperations);
   739  
   740  /**
   741   * \brief Unmount a Dokan device from a driver letter.
   742   *
   743   * \param DriveLetter Dokan driver letter to unmount.
   744   * \return \c TRUE if device was unmounted or False in case of failure or device not found.
   745   */
   746  BOOL DOKANAPI DokanUnmount(WCHAR DriveLetter);
   747  
   748  /**
   749   * \brief Unmount a Dokan device from a mount point
   750   *
   751   * \param MountPoint Mount point to unmount ("Z", "Z:", "Z:\", "Z:\MyMountPoint").
   752   * \return \c TRUE if device was unmounted or False in case of failure or device not found.
   753   */
   754  BOOL DOKANAPI DokanRemoveMountPoint(LPCWSTR MountPoint);
   755  
   756  /**
   757   * \brief Unmount a Dokan device from a mount point
   758   *
   759   * Same as \ref DokanRemoveMountPoint
   760   * If Safe is \c TRUE, it will broadcast to all desktops and Shells
   761   * Safe should not be used during DLL_PROCESS_DETACH
   762   *
   763   * \see DokanRemoveMountPoint
   764   *
   765   * \param MountPoint Mount point to unmount ("Z", "Z:", "Z:\", "Z:\MyMountPoint").
   766   * \param Safe Process is not in DLL_PROCESS_DETACH state.
   767   * \return True if device was unmounted or False in case of failure or device not found.
   768   */
   769  BOOL DOKANAPI DokanRemoveMountPointEx(LPCWSTR MountPoint, BOOL Safe);
   770  
   771  /**
   772   * \brief Checks whether Name matches Expression
   773   *
   774   * \param Expression Expression can contain wildcard characters (? and *)
   775   * \param Name Name to check
   776   * \param IgnoreCase Case sensitive or not
   777   * \return result if name matches the expression
   778   */
   779  BOOL DOKANAPI DokanIsNameInExpression(LPCWSTR Expression, LPCWSTR Name,
   780                                        BOOL IgnoreCase);
   781  
   782  /**
   783   * \brief Get the version of Dokan.
   784   * The returned ULONG is the version number without the dots.
   785   * \return The version of Dokan
   786   */
   787  ULONG DOKANAPI DokanVersion();
   788  
   789  /**
   790   * \brief Get the version of the Dokan driver.
   791   * The returned ULONG is the version number without the dots.
   792   * \return The version of Dokan driver.
   793   */
   794  ULONG DOKANAPI DokanDriverVersion();
   795  
   796  /**
   797   * \brief Extends the timeout of the current IO operation in driver.
   798   *
   799   * \param Timeout Extended time in milliseconds requested.
   800   * \param DokanFileInfo \ref DOKAN_FILE_INFO of the operation to extend.
   801   * \return If the operation was successful.
   802   */
   803  BOOL DOKANAPI DokanResetTimeout(ULONG Timeout, PDOKAN_FILE_INFO DokanFileInfo);
   804  
   805  /**
   806   * \brief Get the handle to Access Token.
   807   *
   808   * This method needs be called in <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> callback.
   809   * The caller must call <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx">CloseHandle</a>
   810   * for the returned handle.
   811   *
   812   * \param DokanFileInfo \ref DOKAN_FILE_INFO of the operation to extend.
   813   * \return A handle to the account token for the user on whose behalf the code is running.
   814   */
   815  HANDLE DOKANAPI DokanOpenRequestorToken(PDOKAN_FILE_INFO DokanFileInfo);
   816  
   817  /**
   818   * \brief Get active Dokan mount points.
   819   *
   820   * \param list Allocate array of DOKAN_CONTROL.
   821   * \param length Number of \ref DOKAN_CONTROL instances in list.
   822   * \param uncOnly Get only instances that have UNC Name.
   823   * \param nbRead Number of instances successfully retrieved.
   824   * \return List retrieved or not.
   825   */
   826  //BOOL DOKANAPI DokanGetMountPointList(PDOKAN_CONTROL list, ULONG length,
   827  //                                     BOOL uncOnly, PULONG nbRead);
   828  
   829  /**
   830   * \brief Convert \ref DOKAN_OPERATIONS.ZwCreateFile parameters to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> parameters.
   831   *
   832   * Dokan Kernel forward the DesiredAccess directly from the IRP_MJ_CREATE.
   833   * This DesiredAccess has been converted from generic rights (user CreateFile request) to standard rights and will be converted back here.
   834   * https://msdn.microsoft.com/windows/hardware/drivers/ifs/access-mask
   835   *
   836   * \param DesiredAccess DesiredAccess from \ref DOKAN_OPERATIONS.ZwCreateFile.
   837   * \param FileAttributes FileAttributes from \ref DOKAN_OPERATIONS.ZwCreateFile.
   838   * \param CreateOptions CreateOptions from \ref DOKAN_OPERATIONS.ZwCreateFile.
   839   * \param CreateDisposition CreateDisposition from \ref DOKAN_OPERATIONS.ZwCreateFile.
   840   * \param outDesiredAccess New <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> dwDesiredAccess.
   841   * \param outFileAttributesAndFlags New <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> dwFlagsAndAttributes.
   842   * \param outCreationDisposition New <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> dwCreationDisposition.
   843   * \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile function (MSDN)</a>
   844   */
   845  void DOKANAPI DokanMapKernelToUserCreateFileFlags(
   846  	ACCESS_MASK DesiredAccess, ULONG FileAttributes, ULONG CreateOptions, ULONG CreateDisposition,
   847  	ACCESS_MASK* outDesiredAccess, DWORD *outFileAttributesAndFlags, DWORD *outCreationDisposition);
   848  
   849  /**
   850   * \brief Convert WIN32 error to NTSTATUS
   851   *
   852   * https://support.microsoft.com/en-us/kb/113996
   853   *
   854   * \param Error Win32 Error to convert
   855   * \return NTSTATUS associate to the ERROR.
   856   */
   857  NTSTATUS DOKANAPI DokanNtStatusFromWin32(DWORD Error);
   858  
   859  /** @} */
   860  
   861  #ifdef __cplusplus
   862  }
   863  #endif
   864  
   865  #endif // DOKAN_H_