Skip to content
Advertisement

How to mount image using mount(2)

I cannot mount some IMAGE on the MacOSX 10.10 via C function mount().

I use following code

...
    char ImgPath[m_IMGName.size() + 1];
    memcpy(ImgPath, m_IMGName.c_str(), m_IMGName.size() + 1);
    struct hfs_mount_args data;
    data.fspec = ImgPath;
    if(mount("hfs+", m_TargetPath.c_str(), MNT_RDONLY, &data)){
        throw SysCallTestExeption(errno, "mount() is failed!", GET_FILE_LINE_FUNC_ARG);
    }
...

And when I start the program I get the error “mount() is failed! Error(Operation not supported by device).”

And image was mounted if I use the following command:

sudo hdiutil attach -mountpoint "${MountPointPath}" "${Image}"

Also, when I use mount() on the Linux – All is OK. Following Linux code:

...
if(mount(m_IMGName.c_str(), m_TargetPath.c_str(), m_FSType.c_str(), 0, m_Opts.c_str())){
        throw SysCallTestExeption(errno, "mount() is failed!", GET_FILE_LINE_FUNC_ARG);
    }
...

Advertisement

Answer

There is no hfs+ type in

mount("hfs+", m_TargetPath.c_str(), MNT_RDONLY, &data)

You should use hfs to handle both HFS and HFS+. Look for example at mount_hfs command source:

#define HFS_MOUNT_TYPE              "hfs"
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement