nmount or mount (2)

aharonf

New Member


Messages: 6

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

Daemon

Reaction score: 184
Messages: 1,012

When in doubt, look at other people's code.

excerpt from /usr/src/sbin/mount_ufs/mount_ufs.c
Code:
 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 ([red]nmount(iov, iovlen, mntflags)[/red] < 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

Well-Known Member

Reaction score: 81
Messages: 379

build_iovec isn't a syscall though, you need to copy it as well, from sbin/mount/getmntopts.c.
 
Top