* kernel notifies us that the FS has been mounted successfully.
mfs_mount(addr
, len
, name
, dir
, flags
)
signal(SIGUSR1
, sighandler
);
fatal("cannot create pipe: %s", strerror(errno
));
fatal("cannot fork: %s", strerror(errno
));
* child: disassociate from controlling terminal,
* and mount the filesystem.
if (pfeife
[0] != 2) close(pfeife
[0]);
if (pfeife
[1] != 2) close(pfeife
[1]);
sprintf(nmbuf
, "MFS:%d", getpid());
margs
.flags
= MFSMNT_SIGPPID
;
if (mount(MOUNT_MFS
, dir
, flags
, &margs
) == -1)
fatal("mounting MFS: %s", strerror(errno
));
* parent; if the mount system call fails, the
* child will write error messages to the pipe.
* We duplicate those messages to our stdout.
* If the mount succeedet, we will receive a SIGUSR1
* (and exit with status 0).
while ((red
= read(pfeife
[0], buf
, sizeof(buf
))) > 0)
addr
= mmap(0, size
, PROT_READ
| PROT_WRITE
,
MAP_ANON
| MAP_SHARED
, -1, 0);
fatal("cannot allocate memory: %s", strerror(errno
));
mfs_mountfile(file
, dir
, flags
)
fd
= open(file
, O_RDWR
| O_EXLOCK
);
if ((fd
== -1) || (fstat(fd
, &st
) == -1))
fatal("%s: %s", file
, strerror(errno
));
addr
= mmap(0, st
.st_size
, PROT_READ
| PROT_WRITE
,
MAP_FILE
| MAP_SHARED
, fd
, 0);
if (addr
== (caddr_t
) -1)
fatal("cannot mmap file: %s", strerror(errno
));
mfs_mount(addr
, st
.st_size
, file
, dir
, flags
);
fatal("compiled without MFS support");
void mfs_mountfile() {mfs_malloc();}