Beispiel #1
0
static void
dir_rmdirdotdot(const atf_tc_t *tc, const char *mp)
{
	char pb[MAXPATHLEN];
	int xerrno;

	USES_DIRS;

	FSTEST_ENTER();
	RL(rump_sys_mkdir("test", 0777));
	RL(rump_sys_chdir("test"));

	RL(rump_sys_mkdir("subtest", 0777));
	RL(rump_sys_chdir("subtest"));

	md(pb, mp, "test/subtest");
	RL(rump_sys_rmdir(pb));
	md(pb, mp, "test");
	RL(rump_sys_rmdir(pb));

	if (FSTYPE_NFS(tc))
		xerrno = ESTALE;
	else
		xerrno = ENOENT;
	ATF_REQUIRE_ERRNO(xerrno, rump_sys_chdir("..") == -1);
	FSTEST_EXIT();
}
Beispiel #2
0
ATF_TC_BODY(multilayer, tc)
{
	struct union_args unionargs;

	rump_init();

	if (rump_sys_mkdir("/Tunion", 0777) == -1)
		atf_tc_fail_errno("mkdir mp1");
	if (rump_sys_mkdir("/Tunion2", 0777) == -1)
		atf_tc_fail_errno("mkdir mp2");
	if (rump_sys_mkdir("/Tunion2/A", 0777) == -1)
		atf_tc_fail_errno("mkdir A");
	if (rump_sys_mkdir("/Tunion2/B", 0777) == -1)
		atf_tc_fail_errno("mkdir B");

	unionargs.target = __UNCONST("/Tunion2/A");
	unionargs.mntflags = UNMNT_BELOW;

	if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0,
	    &unionargs, sizeof(unionargs)) == -1)
		atf_tc_fail_errno("union mount");

	unionargs.target = __UNCONST("/Tunion2/B");
	unionargs.mntflags = UNMNT_BELOW;

	rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
}
Beispiel #3
0
static void
rename_dotdot(const atf_tc_t *tc, const char *mp)
{

	if (FSTYPE_RUMPFS(tc))
		atf_tc_skip("rename not supported by file system");

	USES_DIRS;

	if (rump_sys_chdir(mp) == -1)
		atf_tc_fail_errno("chdir mountpoint");

	if (rump_sys_mkdir("dir1", 0777) == -1)
		atf_tc_fail_errno("mkdir 1");
	if (rump_sys_mkdir("dir2", 0777) == -1)
		atf_tc_fail_errno("mkdir 2");

	if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL)
		atf_tc_fail_errno("self-dotdot to");

	if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL)
		atf_tc_fail_errno("self-dotdot from");

	if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL)
		atf_tc_fail("other-dotdot");

	rump_sys_chdir("/");
}
Beispiel #4
0
ATF_TC_BODY(nullrevoke, tc)
{
	char path[MAXPATHLEN];
	struct ptmget ptg;
	int ptm;

	rump_init();

	/*
	 * mount /dev/pts
	 */
	mountptyfs("/dev/pts", 0);

	/*
	 * null mount /dev/pts to /null/dev/pts
	 */
	if (rump_sys_mkdir("/null", 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create /null");
	}
	if (rump_sys_mkdir("/null/dev", 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create /null/dev");
	}

	mountnull("/dev/pts", "/null/dev/pts", 0);

	/*
	 * get slave/master pair.
	 */
	ptm = rump_sys_open("/dev/ptm", O_RDWR);
	if (rump_sys_ioctl(ptm, TIOCPTMGET, &ptg) == -1)
		atf_tc_fail_errno("get pty");

	/*
	 * Build nullfs path to slave.
	 */
	strcpy(path, "/null");
	strcat(path, ptg.sn);

	/*
	 * Open slave tty via nullfs.
	 */
	if (rump_sys_open(path, O_RDWR) == -1)
		atf_tc_fail_errno("slave null open");

	/*
	 * Close slave opened with /dev/ptm.  Need purely non-null refs to it.
	 */
	rump_sys_close(ptg.sfd);

	/* revoke slave tty. */
	rump_sys_revoke(path);

	/* done */
}
Beispiel #5
0
static void
dir_notempty(const atf_tc_t *tc, const char *mountpath)
{
	char pb[MAXPATHLEN], pb2[MAXPATHLEN];
	int fd, rv;

	USES_DIRS;

	/* check we can create directories */
	sprintf(pb, "%s/dir", mountpath);
	if (rump_sys_mkdir(pb, 0777) == -1)
		atf_tc_fail_errno("mkdir");

	sprintf(pb2, "%s/dir/file", mountpath);
	fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
	if (fd == -1)
		atf_tc_fail_errno("create file");
	rump_sys_close(fd);

	rv = rump_sys_rmdir(pb);
	if (FSTYPE_ZFS(tc))
		atf_tc_expect_fail("PR kern/47656: Test known to be broken");
	if (rv != -1 || errno != ENOTEMPTY)
		atf_tc_fail("non-empty directory removed succesfully");

	if (rump_sys_unlink(pb2) == -1)
		atf_tc_fail_errno("cannot remove dir/file");

	if (rump_sys_rmdir(pb) == -1)
		atf_tc_fail_errno("remove directory");
}
Beispiel #6
0
ATF_TC_BODY(makecn, tc)
{
	struct componentname *cn;
	char pathstr[MAXPATHLEN] = TESTFILE;
	struct vnode *vp;
	extern struct vnode *rumpns_rootvnode;

	rump_init();

	/*
	 * Strategy is to create a componentname, edit the passed
	 * string, and then do a lookup with the componentname.
	 */
	RL(rump_sys_mkdir("/" TESTFILE, 0777));

	/* need stable lwp for componentname */
	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));

	/* try it once with the right path */
	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
	rump_pub_freecn(cn, RUMPCN_FREECRED);

	/* and then with modification-in-the-middle */
	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
	strcpy(pathstr, "/muuta");
	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
	rump_pub_freecn(cn, RUMPCN_FREECRED);
}
Beispiel #7
0
ATF_TC_BODY(devnull2, tc)
{
	struct union_args unionargs;
	int fd, res;

	rump_init();

	if (rump_sys_mkdir("/mp", 0777) == -1)
		atf_tc_fail_errno("mkdir mp");

	unionargs.target = __UNCONST("/dev");
	unionargs.mntflags = UNMNT_BELOW;

	if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
	    &unionargs, sizeof(unionargs)) == -1)
		atf_tc_fail_errno("union mount");

	fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND);
	if (fd == -1)
		atf_tc_fail_errno("open");

	res = rump_sys_write(fd, &fd, sizeof(fd));
	if (res != sizeof(fd))
		atf_tc_fail("write");
}
Beispiel #8
0
int
lfs_fstest_mount(const atf_tc_t *tc, void *buf, const char *path, int flags)
{
	struct lfstestargs *args = buf;
	int res;

	res = rump_sys_mkdir(path, 0777);
	if (res == -1)
		return res;

	res = rump_sys_mount(MOUNT_LFS, path, flags, &args->ta_uargs,
	    sizeof(args->ta_uargs));
	if (res == -1)
		return res;

	strcpy(args->ta_mntpath, path);
	res = pthread_create(&args->ta_cleanerthread, NULL, cleaner, args);
	if (res)
		return res;

	/* wait for cleaner to initialize */
	sem_wait(&args->ta_cleanerloop);

	return 0;
}
Beispiel #9
0
ATF_TC_BODY(key, tc)
{

	RZ(rump_init());

	RL(open("hostfile", O_RDWR | O_CREAT, 0777));

	RZ(rump_pub_etfs_register("/key", "hostfile", RUMP_ETFS_REG));
	ATF_REQUIRE_EQ(rump_pub_etfs_register("key", "hostfile", RUMP_ETFS_REG),
	    EINVAL);

	RL(rump_sys_open("/key", O_RDONLY));
	RL(rump_sys_open("////////key", O_RDONLY));

	RZ(rump_pub_etfs_register("////key//with/slashes", "hostfile",
	    RUMP_ETFS_REG));

	RL(rump_sys_open("/key//with/slashes", O_RDONLY));
	RL(rump_sys_open("key//with/slashes", O_RDONLY));
	ATF_REQUIRE_ERRNO(ENOENT,
	    rump_sys_open("/key/with/slashes", O_RDONLY) == -1);

	RL(rump_sys_mkdir("/a", 0777));
	ATF_REQUIRE_ERRNO(ENOENT,
	    rump_sys_open("/a/key//with/slashes", O_RDONLY) == -1);
}
Beispiel #10
0
static void
lookup_complex(const atf_tc_t *tc, const char *mountpath)
{
	char pb[MAXPATHLEN];
	struct stat sb1, sb2;

	USES_DIRS;

	if (FSTYPE_UDF(tc))
		atf_tc_expect_fail("PR kern/49033");

	sprintf(pb, "%s/dir", mountpath);
	if (rump_sys_mkdir(pb, 0777) == -1)
		atf_tc_fail_errno("mkdir");
	if (rump_sys_stat(pb, &sb1) == -1)
		atf_tc_fail_errno("stat 1");

	sprintf(pb, "%s/./dir/../././dir/.", mountpath);
	if (rump_sys_stat(pb, &sb2) == -1)
		atf_tc_fail_errno("stat 2");

	if (memcmp(&sb1, &sb2, sizeof(sb1)) != 0) {
		printf("what\tsb1\t\tsb2\n");

#define FIELD(FN)	\
		printf(#FN "\t%lld\t%lld\n", \
		(long long)sb1.FN, (long long)sb2.FN)
#define TIME(FN)	\
		printf(#FN "\t%lld.%ld\t%lld.%ld\n", \
		(long long)sb1.FN.tv_sec, sb1.FN.tv_nsec, \
		(long long)sb2.FN.tv_sec, sb2.FN.tv_nsec)

		FIELD(st_dev);
		FIELD(st_mode);
		FIELD(st_ino);
		FIELD(st_nlink);
		FIELD(st_uid);
		FIELD(st_gid);
		FIELD(st_rdev);
		TIME(st_atim);
		TIME(st_mtim);
		TIME(st_ctim);
		TIME(st_birthtim);
		FIELD(st_size);
		FIELD(st_blocks);
		FIELD(st_flags);
		FIELD(st_gen);

#undef FIELD
#undef TIME

		atf_tc_fail("stat results differ, see ouput for more details");
	}
	if (FSTYPE_UDF(tc))
		atf_tc_fail("random failure of PR kern/49033 "
			    "did not happen this time");
}
Beispiel #11
0
static void
mountnull(const char *what, const char *mp, int flags)
{
	struct null_args nargs;

	if (rump_sys_mkdir(what, 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create %s", what);
	}
	if (rump_sys_mkdir(mp, 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create %s", mp);
	}
	memset(&nargs, 0, sizeof(nargs));
	nargs.nulla_target = __UNCONST(what);
	if (rump_sys_mount(MOUNT_NULL, mp, flags, &nargs, sizeof(nargs)) == -1)
		atf_tc_fail_errno("could not mount nullfs");
}
Beispiel #12
0
int
msdosfs_fstest_mount(const atf_tc_t *tc, void *buf, const char *path, int flags)
{
	int res;
	struct msdosfstestargs *args = buf;

	res = rump_sys_mkdir(path, 0777);
	if (res == -1)
		return res;

	res = rump_sys_mount(MOUNT_MSDOS, path, flags, &args->ta_uargs,
	    sizeof(args->ta_uargs));
	return res;
}
Beispiel #13
0
static void
mountptyfs(const char *mp, int flags)
{
	struct ptyfs_args args;

	if (rump_sys_mkdir(mp, 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create %s", mp);
	}
	memset(&args, 0, sizeof(args));
	args.version = PTYFS_ARGSVERSION;
	args.mode = 0777;
	if (rump_sys_mount(MOUNT_PTYFS, mp, flags, &args, sizeof(args)) == -1)
		atf_tc_fail_errno("could not mount ptyfs");
}
Beispiel #14
0
int
main(int argc, char *argv[])
{
	struct rump_ufs_args args;
	char imgpath[MAXPATHLEN+1];
	union u u;
	char buf[8192];
	int fd;

	/*
	 * the driver doesn't support endian swapping, so pick image
	 * with matching endianness.
	 */
	u.i = 0x12345678;
	if (u.c == 0x12) {
		snprintf(imgpath, sizeof(imgpath),
		    "%s/%s", argv[1], "sysvbfs_be.img");
	} else {
		snprintf(imgpath, sizeof(imgpath),
		    "%s/%s", argv[1], "sysvbfs_le.img");
	}
		

        rump_init();

#define MYFSDEV "/de-vice"
	rump_pub_etfs_register(MYFSDEV, imgpath, RUMP_ETFS_BLK);
	args.fspec =  (void *)(uintptr_t)MYFSDEV;

	if (rump_sys_mkdir("/mnt", 0755) == -1)
		die("mkdir /mnt");
	if (rump_sys_mount(RUMP_MOUNT_SYSVBFS, "/mnt", RUMP_MNT_RDONLY,
	    &args, sizeof(args)) == -1)
		die("mount");
	if ((fd = rump_sys_open("/mnt/README", 0)) == -1)
		die("open file");
	memset(buf, 0, sizeof(buf));
	if (rump_sys_read(fd, buf, sizeof(buf)) <= 0)
		die("read version");
	if (strcmp(buf, EXPECTED) != 0)
		die("got unexpected result");
	rump_sys_close(fd);
	if (rump_sys_unmount("/mnt", 0) == -1)
		die("unmount failed");

	return 0;
}
static void
dirperms(const atf_tc_t *tc, const char *mp)
{
	char name[] = "dir.test/file.test";
	char *dir = dirname(name);
	int fd;

	if (FSTYPE_SYSVBFS(tc))
		atf_tc_skip("directories not supported by file system");

	FSTEST_ENTER();

	if (rump_sys_mkdir(dir, 0777) == -1)
		atf_tc_fail_errno("mkdir");

	rump_pub_lwproc_rfork(RUMP_RFCFDG);
	if (rump_sys_setuid(1) == -1)
		atf_tc_fail_errno("setuid");
	if (FSTYPE_ZFS(tc))
		atf_tc_expect_fail("PR kern/47656: Test known to be broken");
        if (rump_sys_open(name, O_RDWR|O_CREAT, 0666) != -1 || errno != EACCES)
		atf_tc_fail_errno("open");
	rump_pub_lwproc_releaselwp();

	if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1)
		atf_tc_fail_errno("open");
	if (rump_sys_close(fd) == -1)
		atf_tc_fail_errno("close");

	rump_pub_lwproc_rfork(RUMP_RFCFDG);
	if (rump_sys_setuid(1) == -1)
		atf_tc_fail_errno("setuid");
        if (rump_sys_unlink(name) != -1 || errno != EACCES)
		atf_tc_fail_errno("unlink");
	rump_pub_lwproc_releaselwp();

        if (rump_sys_unlink(name) == -1)
		atf_tc_fail_errno("unlink");

	if (rump_sys_rmdir(dir) == -1)
		atf_tc_fail_errno("rmdir");

	FSTEST_EXIT();
}
Beispiel #16
0
static void
lookup_complex(const atf_tc_t *tc, const char *mountpath)
{
	char pb[MAXPATHLEN];
	struct stat sb1, sb2;

	USES_DIRS;

	sprintf(pb, "%s/dir", mountpath);
	if (rump_sys_mkdir(pb, 0777) == -1)
		atf_tc_fail_errno("mkdir");
	if (rump_sys_stat(pb, &sb1) == -1)
		atf_tc_fail_errno("stat 1");

	sprintf(pb, "%s/./dir/../././dir/.", mountpath);
	if (rump_sys_stat(pb, &sb2) == -1)
		atf_tc_fail_errno("stat 2");

	ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
}
Beispiel #17
0
static void
dir_simple(const atf_tc_t *tc, const char *mountpath)
{
	char pb[MAXPATHLEN];
	struct stat sb;

	USES_DIRS;

	/* check we can create directories */
	sprintf(pb, "%s/dir", mountpath);
	if (rump_sys_mkdir(pb, 0777) == -1)
		atf_tc_fail_errno("mkdir");
	if (rump_sys_stat(pb, &sb) == -1)
		atf_tc_fail_errno("stat new directory");

	/* check we can remove then and that it makes them unreachable */
	if (rump_sys_rmdir(pb) == -1)
		atf_tc_fail_errno("rmdir");
	if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT)
		atf_tc_fail("ENOENT expected from stat");
}
Beispiel #18
0
int
main()
{
	char buf[8192];
	int fd;

        rump_init();
	if (rump_sys_mkdir("/kern", 0755) == -1)
		die("mkdir /kern");
	if (rump_sys_mount("kernfs", "/kern", 0, NULL, 0) == -1)
		die("mount kernfs");
	if ((fd = rump_sys_open("/kern/version", 0)) == -1)
		die("open /kern/version");
	printf("\nReading version info from /kern:\n");
	if (rump_sys_read(fd, buf, sizeof(buf)) <= 0)
		die("read version");
	printf("\n%s", buf);
	rump_sys_reboot(0, NULL);

	return 0;
}
Beispiel #19
0
void
rumpkern_demo(void)
{
	char buf[256];
	ssize_t nn;
	int fd, rv;

	printk(KERN_INFO "reading rump kernel version from kernfs/version:\n");
	rv = rump_sys_mkdir("/mnt", 0777);
	BUG_ON(rv == -1);

	rv = rump_sys_mount("kernfs", "/mnt", 0, NULL, 0);
	BUG_ON(rv == -1);

	fd = rump_sys_open("/mnt/version", RUMP_O_RDONLY, 0);
	BUG_ON(rv == -1);

	nn = rump_sys_read(fd, buf, sizeof(buf));
	BUG_ON(nn < 1);
	buf[nn] = '\0';

	printk(KERN_INFO "%s", buf);
}
Beispiel #20
0
static void
rename_dir(const atf_tc_t *tc, const char *mp)
{
	char pb1[MAXPATHLEN], pb2[MAXPATHLEN], pb3[MAXPATHLEN];
	struct stat ref, sb;

	if (FSTYPE_RUMPFS(tc))
		atf_tc_skip("rename not supported by file system");

	USES_DIRS;

	md(pb1, mp, "dir1");
	if (rump_sys_mkdir(pb1, 0777) == -1)
		atf_tc_fail_errno("mkdir 1");

	md(pb2, mp, "dir2");
	if (rump_sys_mkdir(pb2, 0777) == -1)
		atf_tc_fail_errno("mkdir 2");
	md(pb2, mp, "dir2/subdir");
	if (rump_sys_mkdir(pb2, 0777) == -1)
		atf_tc_fail_errno("mkdir 3");

	md(pb3, mp, "dir1/file");
	if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
		atf_tc_fail_errno("create file");
	if (rump_sys_stat(pb3, &ref) == -1)
		atf_tc_fail_errno("stat of file");

	/*
	 * First try ops which should succeed.
	 */

	/* rename within directory */
	md(pb3, mp, "dir3");
	if (rump_sys_rename(pb1, pb3) == -1)
		atf_tc_fail_errno("rename 1");
	checkfile(pb3, &ref);

	/* rename directory onto itself (two ways, should fail) */
	md(pb1, mp, "dir3/.");
	if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
		atf_tc_fail_errno("rename 2");
	if (FSTYPE_ZFS(tc))
		atf_tc_expect_fail("PR kern/47656: Test known to be broken");
	if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
		atf_tc_fail_errno("rename 3");

	checkfile(pb3, &ref);

	/* rename father of directory into directory */
	md(pb1, mp, "dir2/dir");
	md(pb2, mp, "dir2");
	if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
		atf_tc_fail_errno("rename 4");

	/* same for grandfather */
	md(pb1, mp, "dir2/subdir/dir2");
	if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
		atf_tc_fail("rename 5");

	checkfile(pb3, &ref);

	/* rename directory over a non-empty directory */
	if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY)
		atf_tc_fail("rename 6");

	/* cross-directory rename */
	md(pb1, mp, "dir3");
	md(pb2, mp, "dir2/somedir");
	if (rump_sys_rename(pb1, pb2) == -1)
		atf_tc_fail_errno("rename 7");
	checkfile(pb2, &ref);

	/* move to parent directory */
	md(pb1, mp, "dir2/somedir/../../dir3");
	if (rump_sys_rename(pb2, pb1) == -1)
		atf_tc_fail_errno("rename 8");
	md(pb1, mp, "dir2/../dir3");
	checkfile(pb1, &ref);

	/* atomic cross-directory rename */
	md(pb3, mp, "dir2/subdir");
	if (rump_sys_rename(pb1, pb3) == -1)
		atf_tc_fail_errno("rename 9");
	checkfile(pb3, &ref);

	/* rename directory over an empty directory */
	md(pb1, mp, "parent");
	md(pb2, mp, "parent/dir1");
	md(pb3, mp, "parent/dir2");
	RL(rump_sys_mkdir(pb1, 0777));
	RL(rump_sys_mkdir(pb2, 0777));
	RL(rump_sys_mkdir(pb3, 0777));
	RL(rump_sys_rename(pb2, pb3));

	RL(rump_sys_stat(pb1, &sb));
	if (! FSTYPE_MSDOS(tc))
		ATF_CHECK_EQ(sb.st_nlink, 3);
	RL(rump_sys_rmdir(pb3));
	RL(rump_sys_rmdir(pb1));
}
Beispiel #21
0
static int
mount_struct(_Bool verbose, struct mount_data_s *mntdp)
{
	fsu_fs_t *fs;
	int rv;

	fs = mntdp->mntd_fs;

	/*
	 * Switch the default process to the native syscalls.
	 * The bad thing about this is that it will fail in unobvious
	 * way if programs using this go multithreaded, but worry about
	 * that if it happens.
	 */
	rump_i_know_what_i_am_doing_with_sysents = 1;
	rump_pub_lwproc_sysent_usenative();

	rv = fs->fs_parseargs(mntdp->mntd_argc, mntdp->mntd_argv, fs->fs_args,
	    &(mntdp->mntd_flags), mntdp->mntd_canon_dev, mntdp->mntd_canon_dir);
	if (rv != 0)
		return -1;

	if (rump_sys_mkdir(MOUNT_DIRECTORY, 0777) == -1 && errno != EEXIST)
		err(-1, "mkdir");
	strcpy(mntdp->mntd_canon_dir, MOUNT_DIRECTORY);

	rv = fsu_load_fs(fs->fs_name);

	if (rv == 0) {
		rv = rump_sys_mount(fs->fs_name, mntdp->mntd_canon_dir,
		    mntdp->mntd_flags, fs->fs_args, fs->fs_args_size);
#if 0
		/*
		 * This will result in a lot of spam for fs type autodetection,
		 * so need to come up with a better scheme here.
		 */
		if (rv == -1)
			warn("mount failed");
#endif
	}

	if (rv == 0) {
		/* fork a rump kernel process to chroot() to the mountpoint */
		if ((rv = rump_pub_lwproc_rfork(RUMP_RFCFDG)) != 0) {
			warnx("fork failed!");
			rump_sys_unmount(MOUNT_DIRECTORY, 0);
		} else {
			atexit(fsu_unmount);
			rump_sys_chroot(MOUNT_DIRECTORY);
		}
	}
#ifdef WITH_SMBFS
	if (strcmp(fs->fs_name, MOUNT_SMBFS) == 0) {
		extern struct smb_ctx sctx;

		smb_ctx_done(&sctx);
	}
#endif
	if (rv != 0 && verbose) {
		warn(NULL);
		fprintf(stderr, "%s is not a valid %s image\n",
		    mntdp->mntd_fsdevice, fs->fs_name);
	}

	return rv;
}
Beispiel #22
0
int
main(int argc, char *argv[])
{
	const char *ethername, *ethername_ro;
	const char *serveraddr, *serveraddr_ro;
	const char *netmask;
	const char *exportpath;
	const char *imagename;
	char ifname[IFNAMSIZ], ifname_ro[IFNAMSIZ];
	void *fsarg;
	pthread_t t;
	int rv;

	/* for netcfg */
	noatf = 1;

	/* use defaults? */
	if (argc == 1) {
		ethername = "etherbus";
		ethername_ro = "etherbus_ro";
		serveraddr = "10.3.2.1";
		serveraddr_ro = "10.4.2.1";
		netmask = "255.255.255.0";
		exportpath = "/myexport";
		imagename = "ffs.img";
	} else {
		ethername = argv[1];
		ethername_ro = argv[2];
		serveraddr = argv[3];
		serveraddr_ro = argv[4];
		netmask = argv[5];
		exportpath = argv[6];
		imagename = argv[7];
	}

	rump_init();
	svc_fdset_init(SVC_FDSET_MT);

	rv = rump_pub_etfs_register("/etc/exports", "./exports", RUMP_ETFS_REG);
	if (rv) {
		errx(1, "register /etc/exports: %s", strerror(rv));
	}

	/* mini-mtree for mountd */
	static const char *const dirs[] = { "/var", "/var/run", "/var/db" };
	for (size_t i = 0; i < __arraycount(dirs); i++)
		if (rump_sys_mkdir(dirs[i], 0777) == -1)
			err(1, "can't mkdir `%s'", dirs[i]);

	if (ffs_fstest_newfs(NULL, &fsarg,
	    imagename, FSTEST_IMGSIZE, NULL) != 0)
		err(1, "newfs failed");
	if (ffs_fstest_mount(NULL, fsarg, exportpath, 0) != 0)
		err(1, "mount failed");

#if 0
	/*
	 * Serve from host instead of dedicated mount?
	 * THIS IS MORE EVIL THAN MURRAY THE DEMONIC TALKING SKULL!
	 */

	if (ukfs_modload("/usr/lib/librumpfs_syspuffs.so") < 1)
		errx(1, "modload");

	mount_syspuffs_parseargs(__arraycount(pnullarg), pnullarg,
	    &args, &mntflags, canon_dev, canon_dir);
	if ((ukfs = ukfs_mount(MOUNT_PUFFS, "/", UKFS_DEFAULTMP, MNT_RDONLY,
	    &args, sizeof(args))) == NULL)
		err(1, "mount");

	if (ukfs_modload("/usr/lib/librumpfs_nfsserver.so") < 1)
		errx(1, "modload");
#endif

	if (sem_init(&gensem, 1, 0) == -1)
		err(1, "gensem init");

	/* create interface */
	netcfg_rump_makeshmif(ethername, ifname);
	netcfg_rump_if(ifname, serveraddr, netmask);

	netcfg_rump_makeshmif(ethername_ro, ifname_ro);
	netcfg_rump_if(ifname_ro, serveraddr_ro, netmask);

	/*
	 * No syslogging, thanks.
	 * XXX: "0" does not modify the mask, so pick something
	 * which is unlikely to cause any logging
	 */
	setlogmask(0x10000000);

	if (pthread_create(&t, NULL, rpcbind_main, NULL) == -1)
		err(1, "rpcbind");
	sem_wait(&gensem);

	if (pthread_create(&t, NULL, mountd_main, NULL) == -1)
		err(1, "mountd");
	sem_wait(&gensem);

	rv = 0;
	/* signal the other process we're almost done */
	if (write(3, &rv, 4) != 4)
		errx(1, "magic write failed");

	{
	char *nfsargv[] = { __UNCONST("nfsd"), NULL };
	nfsd_main(1, nfsargv);
	}
	/*NOTREACHED*/

	return 0;
}