📜 ⬆️ ⬇️

Create your file system in Windows OS on .Net

There are a great many file systems. These include file systems for storage media (FAT *, NTFS, ext *, etc.), network file systems (NFS, CIFS, etc.), virtual file systems, and a great many others . Did you,% habrauser%, have a need for your own, non-existent file system? How to do it for Windows on a managed-code (.net), and will be discussed.

In general, to create your own file system (hereinafter called FS), you need to write the driver of this file system and register it with the OS. Because Since the driver interacts with the OS kernel, then creating it on a managed code is not a trivial matter, and the performance of such a driver will be at a low level. In this regard, it is more expedient to have a FS driver written in native code and some intermediate layer between this driver and the managed code. Such a driver exists in the Dokan project, as well as a set of DokanNet classes for interacting with this driver in managed code. Both projects are distributed under the GPLv3 license.

Let's try to figure out how it works.


')
Dokan is a Windows kernel-based driver with which any applications from userspace can interact. The driver exists for both 32-bit systems and 64-bit systems. The driver does not carry the implementation of any FS, but only acts as a proxy, passing all input-output operations (IO) from the OS kernel into the userspace. The implementation of the FS functionality lies on our shoulders, we create the basic functions of the FS, such as opening / closing a file, reading from a file, writing to a file, etc., which will be called by the Dokan driver when corresponding events occur in the system. At the time of registration of our file system in the Dokan driver, we specify some parameters of our file system (the number of threads handling I / O operations, the mount point of our file system (Dokan supports mounting as a removable or network drive and only to the root file system), automatic unmounting our FS, in case of errors in the work, and some other parameters). After this, a new disk appears in the OS at the root of the file system, with which any applications and the OS itself interact, as with a regular disk. What operations are allowed to be performed in this FS depends only on the developer of this FS, that is, on us.

DokanNet is a wrapper over the Dokan driver. Allows you to develop your file system on a managed code. DokanNet describes the DokanOperations interface that you need to implement to register our file system in the Dokan driver. The author of DokanNet along with the source code of the project itself put 2 examples of working with this wrapper:

Sample codes are easily readable and allow you to familiarize yourself with the features provided by the Dokan driver.

The implementation of the DokanOperations interface comes down to the implementation of the following functions:


As we can see, the functionality provided by the Dokan driver and DokanNet wrapper is very rich. Based on this project, the SSHFS FS has been developed . Anyone can develop a file system that meets their requirements. I stopped on the development of HttpFS, which will allow to mount files on remote Http-servers into the system. But more about that in the next article ...

Source: https://habr.com/ru/post/111186/


All Articles