Is there a way to create a filesystem file that can be mounted in C++? I want to make a file containing a NTFS filesystem and mount it to a new partition. I want this done in C++ in Windows. Is there a library and perhaps some code examples that does this? I know windows has the diskpart tool which does exactly that but does it have a C++ API or something like that?
-
hope this can help you https://github.com/util-linux/util-linux/blob/master/disk-utils/mkfs.c . based on mkfs command, you can check its source . – long.kl Jan 25 '22 at 10:28
-
This is kind of what I need, but I forgot to mention I need it in a Windows environment. I will edit the question. – Ciprian Florin Jan 25 '22 at 10:41
-
Google for "libntfs-3g". This is a library to handle an NTFS block device with common filesystem operations (open, write, read, etc). You can use the C++ polymorphism to "mount" it. From externally, it will be a process reading/writing into the filesystem image. – peterh Jan 31 '22 at 01:49
1 Answers
To really "mount" the filesystem (ie. to be able to just "fopen" something inside that filesystem) you need support from the kernel. Either you let your operating system take care of it completely (e.g the VHD commands on windows; example use on stackoverflow). Alternatively can use libfuse/winfsp to interact with the kernel more directly, but afaik that requires a custom kernel driver.
If you have an image file with some filesystem inside and you just want to look whats inside, but don't need the C/C++ standard library commands (fopen, ifstream, etc.) to work, then something that can specifically read/write that combination of image file format and filesystem would also suffice.
For C# there would be the DiscUtils library which might do what you want, but I'm not aware of a similar c/c++ library with NTFS support.

- 19,662
- 1
- 29
- 40