#include #include #include #include #include #include #include #include #include #include #define fsmount "/mnt" #define fstype "fdescfs" #define fsmod "fdescfs" static void kmod_load(void) { int error; error = kldload(fsmod); assert(error != 0); } static void kmod_unload(void) { int id; id = kldfind(fsmod); if (id != -1) (void)kldunload(id); } static void * thread_kmod(void *data __unused) { for (;;) { kmod_load(); kmod_unload(); } return (NULL); } static void fs_mount(const char *mntpoint) { struct iovec iov[6]; iov[0].iov_base = "fstype"; iov[0].iov_len = sizeof("fstype"); iov[1].iov_base = fstype; iov[1].iov_len = sizeof(fstype); iov[2].iov_base = "fspath"; iov[2].iov_len = sizeof("fspath"); iov[3].iov_base = mntpoint; iov[3].iov_len = strlen(mntpoint) + 1; iov[4].iov_base = "from"; iov[4].iov_len = sizeof("from"); iov[5].iov_base = fstype; iov[5].iov_len = sizeof(fstype); nmount(iov, nitems(iov), 0); } static void * thread_mount(void *data __unused) { for (;;) { fs_mount(fsmount); unmount(fsmount, 0); } return (NULL); } int main(int argc, char *argv[]) { pthread_t hdl[2]; int error; unmount(fsmount, 0); kmod_unload(); error = pthread_create(&hdl[0], NULL, thread_kmod, NULL); assert(error == 0); error = pthread_create(&hdl[1], NULL, thread_mount, NULL); assert(error == 0); pthread_join(hdl[0], NULL); pthread_join(hdl[1], NULL); }