PDA

View Full Version : nmount or mount (2)


aharonf
March 20th, 2009, 21:52
I am trying to mount a ufs device using the function calls mount() or nmount(). The man pages are extremely elusive on this. Does anyone have a sample code I could use?

Aharon :q

Carpetsmoker
March 20th, 2009, 22:28
When in doubt, look at other people's code.

excerpt from /usr/src/sbin/mount_ufs/mount_ufs.c

iov = NULL;
iovlen = 0;
build_iovec(&iov, &iovlen, "fstype", "ufs", -1);
build_iovec(&iov, &iovlen, "fspath", mntpath, -1);
build_iovec(&iov, &iovlen, "from", dev, -1);
build_iovec(&iov, &iovlen, "flags", &ufs_flags, sizeof ufs_flags);
build_iovec(&iov, &iovlen, "export", &export, sizeof export);
if (nmount(iov, iovlen, mntflags) < 0)
err(1, "%s", dev);
exit(0);


A small example of mount() can be found in /usr/src/sbin/mount/mount_ufs.c ... There are probably more examples to be found:
find /usr/src -type f -exec grep -H mount\( {} \;
(Better use textproc/p5-ack btw.)

Mel_Flynn
March 20th, 2009, 23:14
build_iovec isn't a syscall though, you need to copy it as well, from sbin/mount/getmntopts.c.