I'm attempting to mount an external drive in my C++ application. I originally tried to use mount(2) but this fails:
int ret = mount(deviceName.c_str(), mountPoint.c_str(), fsType.c_str(), 0, NULL);
errno is 19, ENODEV
(filesystem type not configured in kernel)
However, if I switch to using mount(8) it works fine:
std::string cmd = "mount -t " + fsType + " " + deviceName + " " + mountPoint;
int ret = system(cmd.c_str());
Does mount(2) have a different list of acceptable filesystem types? This is an ntfs device, so I was using ntfs-3g
as the fstype. I checked /proc/filesystems and saw that this was not listed, so I tried fuseblk
but that just changes the error to 22, EINVAL
.
What is the correct way to mount NTFS devices using mount(2)?
mount.2
is just a kernel call. mount.8
is a complete external tool which is extended beyond what kernel does.
I think you may be looking for libmount which is a library implementing the whole mounting magic done by mount.8
. Newer mount versions use it as well. It's provided in util-linux.