Search code examples
c++winapifilesystemsfilesystemwatcherntfs

Dynamically merge content of NTFS folders into virtual one


I need to merge content of multiple NTFS folders into one based on some rules. These rules will ensure that there is no conflicting names. The goal is to do all that programatically (c# and/or c++).

The simplest solution I had is to create NTFS Link (or Junction) into the target folder pointing to each file in the source folder.

This would work so far, but the problem I have is that additional files will not occur and removed files will not disappear.

Well, of course I can run a background process (service) listening at the file system's source folders and performing appropriate modifications of NTFS Links on thy fly, but is this the way to go?

The first question is: 1. What is the most elegant way of doing that? 2. I have seen multiple programs which for instance can mount content of a ZIP or ISO file to some NTFS folder. How do they work?


Solution

  • Mapping something to an existing folder is possible in two ways:

    1. Filesystem filter driver filters FS requests to the existing folder and shows modified content of the folder.
    2. Filesystem driver creates a virtual filesystem and mounts it as a junction point on NTFS drive.

    Both methods require a corresponding kernel-mode driver.

    Applications that expose a ZIP (or other similar file) use one of the above methods. ISO files, being images of the disk, can be exposed directly as virtual disks and also mounted to NTFS folder. In the latter case kernel-mode disk driver is needed.

    Your particular task can be accomplished using our Callback File System (CBFS) product. CBFS offers a pre-created kernel-mode driver and lets you write your filesystem-related code in user mode. CBFS includes Mapper sample that does almost what you are looking for - it shows contents of an existing folder as a new virtual filesystem, which you can mount to NTFS folder (CBFS supports this). Non-commercial licenses are available for public non-commercial projects. APIs are offered for .NET, C++, Java and Delphi.