开发者

using mount(2) function in C

I've have been de开发者_JAVA技巧sperately searching for a tutorial on how to use the mount() function properly (they are very good at hiding this knowledge).

I need to use it to MNT_UPDATE " / "(/dev/disk0s2 in this case) in single user mode but I can't find an example or tutorial on how to use the function.

ps. Please no "Use system()" pps. I know /sbin/mount exists for a reason, I'm doing this for education purposes


As you have probably already read in the man page, you use it like this:

int ret = mount("hfs", "/", MNT_UPDATE, some_data);

The trick is what goes into "data". It is a filesystem-specific structure that can be found by grepping for the filesystem name in system headers. For example, for HFS it's in /usr/include/hfs/hfs_mount.h:

struct hfs_mount_args {
    char     *fspec; /* <--- This is the device to mount */
    uid_t     hfs_uid;
    gid_t     hfs_gid;
    mode_t    hfs_mask;
    u_int32_t hfs_encoding;
    struct    timezone hfs_timezone;
    int       flags;
    int       journal_tbuffer_size;
    int       journal_flags;
    int       journal_disable;
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜