ATF_TC_BODY(rfork, tc) { struct stat sb; struct lwp *l, *l2; int fd; RZ(rump_init()); ATF_REQUIRE_EQ(rump_pub_lwproc_rfork(RUMP_RFFDG|RUMP_RFCFDG), EINVAL); RZ(rump_pub_lwproc_rfork(0)); l = rump_pub_lwproc_curlwp(); RL(fd = rump_sys_open("/file", O_RDWR | O_CREAT, 0777)); /* ok, first check rfork(RUMP_RFCFDG) does *not* preserve fd's */ RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); ATF_REQUIRE_ERRNO(EBADF, rump_sys_write(fd, &fd, sizeof(fd)) == -1); /* then check that rfork(0) does */ rump_pub_lwproc_switch(l); RZ(rump_pub_lwproc_rfork(0)); ATF_REQUIRE_EQ(rump_sys_write(fd, &fd, sizeof(fd)), sizeof(fd)); RL(rump_sys_fstat(fd, &sb)); l2 = rump_pub_lwproc_curlwp(); /* * check that the shared fd table is really shared by * closing fd in parent */ rump_pub_lwproc_switch(l); RL(rump_sys_close(fd)); rump_pub_lwproc_switch(l2); ATF_REQUIRE_ERRNO(EBADF, rump_sys_fstat(fd, &sb) == -1); /* redo, this time copying the fd table instead of sharing it */ rump_pub_lwproc_releaselwp(); rump_pub_lwproc_switch(l); RL(fd = rump_sys_open("/file", O_RDWR, 0777)); RZ(rump_pub_lwproc_rfork(RUMP_RFFDG)); ATF_REQUIRE_EQ(rump_sys_write(fd, &fd, sizeof(fd)), sizeof(fd)); RL(rump_sys_fstat(fd, &sb)); l2 = rump_pub_lwproc_curlwp(); /* check that the fd table is copied */ rump_pub_lwproc_switch(l); RL(rump_sys_close(fd)); rump_pub_lwproc_switch(l2); RL(rump_sys_fstat(fd, &sb)); ATF_REQUIRE_EQ(sb.st_size, sizeof(fd)); }
static void read_fault(const atf_tc_t *tc, const char *mp) { char ch = 123; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777)); ATF_REQUIRE_EQ(rump_sys_write(fd, &ch, 1), 1); RL(rump_sys_close(fd)); RL(fd = rump_sys_open("file", O_RDONLY | O_SYNC | O_RSYNC)); ATF_REQUIRE_ERRNO(EFAULT, rump_sys_read(fd, NULL, 1) == -1); RL(rump_sys_close(fd)); FSTEST_EXIT(); }
ATF_TC_BODY(large_blk, tc) { char buf[128]; char cmpbuf[128]; ssize_t n; int rv, tfd; /* * mount mfs. it would be nice if this would not be required, * but a) tmpfs doesn't "support" sparse files b) we don't really * know what fs atf workdir is on anyway. */ if (mkdir("mfsdir", 0777) == -1) atf_tc_fail_errno("mkdir failed"); if (system("mount_mfs -s 64m -o nosuid,nodev mfs mfsdir") != 0) atf_tc_skip("could not mount mfs"); /* create a 8TB sparse file */ rv = system("dd if=/dev/zero of=" IMG_ON_MFS " bs=1 count=1 seek=8t"); ATF_REQUIRE_EQ(rv, 0); /* * map it and issue write at 6TB, then unmap+remap and check * we get the same stuff back */ rump_init(); ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH1, IMG_ON_MFS, RUMP_ETFS_BLK), 0); tfd = rump_sys_open(TESTPATH1, O_RDWR); ATF_REQUIRE(tfd != -1); memset(buf, 12, sizeof(buf)); n = rump_sys_pwrite(tfd, buf, sizeof(buf), 6*1024*1024*1024ULL*1024ULL); ATF_REQUIRE_EQ(n, sizeof(buf)); ATF_REQUIRE_EQ(rump_sys_close(tfd), 0); ATF_REQUIRE_EQ(rump_pub_etfs_remove(TESTPATH1), 0); ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH2, IMG_ON_MFS, RUMP_ETFS_BLK), 0); tfd = rump_sys_open(TESTPATH2, O_RDWR); ATF_REQUIRE(tfd != -1); memset(buf, 0, sizeof(buf)); n = rump_sys_pread(tfd, buf, sizeof(buf), 6*1024*1024*1024ULL*1024ULL); ATF_REQUIRE_EQ(n, sizeof(buf)); memset(cmpbuf, 12, sizeof(cmpbuf)); ATF_REQUIRE_EQ(memcmp(cmpbuf, buf, 128), 0); }
ATF_TC_BODY(reregister_reg, tc) { char buf[1024]; int localfd, etcfd; ssize_t n; int tfd; etcfd = open("/etc/passwd", O_RDONLY); ATF_REQUIRE(etcfd != -1); localfd = open("./testfile", O_RDWR | O_CREAT, 0666); ATF_REQUIRE(localfd != -1); ATF_REQUIRE_EQ(write(localfd, TESTSTR1, TESTSTR1SZ), TESTSTR1SZ); /* testfile now contains test string */ rump_init(); ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH1, "/etc/passwd", RUMP_ETFS_REG), 0); tfd = rump_sys_open(TESTPATH1, O_RDONLY); ATF_REQUIRE(tfd != -1); ATF_REQUIRE(rump_sys_read(tfd, buf, sizeof(buf)) > 0); rump_sys_close(tfd); rump_pub_etfs_remove(TESTPATH1); ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH2, "./testfile", RUMP_ETFS_REG), 0); tfd = rump_sys_open(TESTPATH2, O_RDWR); ATF_REQUIRE(tfd != -1); memset(buf, 0, sizeof(buf)); ATF_REQUIRE((n = rump_sys_read(tfd, buf, sizeof(buf))) > 0); /* check that we have what we expected */ ATF_REQUIRE_STREQ(buf, TESTSTR1); /* ... while here, check that writing works too */ ATF_REQUIRE_EQ(rump_sys_lseek(tfd, 0, SEEK_SET), 0); ATF_REQUIRE(TESTSTR1SZ <= TESTSTR2SZ); ATF_REQUIRE_EQ(rump_sys_write(tfd, TESTSTR2, TESTSTR2SZ), TESTSTR2SZ); memset(buf, 0, sizeof(buf)); ATF_REQUIRE_EQ(lseek(localfd, 0, SEEK_SET), 0); ATF_REQUIRE(read(localfd, buf, sizeof(buf)) > 0); ATF_REQUIRE_STREQ(buf, TESTSTR2); close(etcfd); close(localfd); }
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"); }
static void wrrd_after_unlink(const atf_tc_t *tc, const char *mp) { int value = 0x11; int v2; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("file", O_RDWR|O_CREAT, 0666)); RL(rump_sys_unlink("file")); RL(rump_sys_pwrite(fd, &value, sizeof(value), 654321)); /* * We can't easily invalidate the buffer since we hold a * reference, but try to get them to flush anyway. */ RL(rump_sys_fsync(fd)); RL(rump_sys_pread(fd, &v2, sizeof(v2), 654321)); rump_sys_close(fd); ATF_REQUIRE_EQ(value, v2); FSTEST_EXIT(); }
static void holywrite(const atf_tc_t *tc, const char *mp) { char buf[1024]; char *b2, *b3; size_t therange = getpagesize()+1; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("file", O_RDWR|O_CREAT|O_TRUNC, 0666)); memset(buf, 'A', sizeof(buf)); RL(rump_sys_pwrite(fd, buf, 1, getpagesize())); memset(buf, 'B', sizeof(buf)); RL(rump_sys_pwrite(fd, buf, 2, getpagesize()-1)); REQUIRE_LIBC(b2 = malloc(2 * getpagesize()), NULL); REQUIRE_LIBC(b3 = malloc(2 * getpagesize()), NULL); RL(rump_sys_pread(fd, b2, therange, 0)); memset(b3, 0, therange); memset(b3 + getpagesize() - 1, 'B', 2); ATF_REQUIRE_EQ(memcmp(b2, b3, therange), 0); rump_sys_close(fd); FSTEST_EXIT(); }
static void * wrkwrkwrk(void *unused) { int fd, fail; fail = 0; rump_sys_chdir(FSTEST_MNTNAME); while (!quit) { fd = rump_sys_open("file", O_RDWR | O_CREAT); if (fd == -1) { if (errno == EACCES) { fail++; break; } } rump_sys_close(fd); if (rump_sys_unlink("file") == -1) { if (errno == EACCES) { fail++; break; } } } rump_sys_chdir("/"); quit = 1; return fail ? wrkwrkwrk : NULL; }
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"); }
ATF_TC_BODY(range_blk, tc) { char buf[32000]; char cmpbuf[32000]; ssize_t n; int rv, tfd; /* create a 64000 byte file with 16 1's at offset = 32000 */ rv = system("dd if=/dev/zero of=disk.img bs=1000 count=64"); ATF_REQUIRE_EQ(rv, 0); rv = system("yes | tr '\\ny' '\\1' " "| dd of=disk.img conv=notrunc bs=1 count=16 seek=32000"); ATF_REQUIRE_EQ(rv, 0); /* map the file at [16000,48000]. this puts our 1's at offset 16000 */ rump_init(); ATF_REQUIRE_EQ(rump_pub_etfs_register_withsize(TESTPATH1, "disk.img", RUMP_ETFS_BLK, 16000, 32000), 0); tfd = rump_sys_open(TESTPATH1, O_RDWR); ATF_REQUIRE(tfd != -1); n = rump_sys_read(tfd, buf, sizeof(buf)); ATF_REQUIRE_EQ(n, sizeof(buf)); ATF_REQUIRE_EQ(rump_sys_close(tfd), 0); ATF_REQUIRE_EQ(rump_pub_etfs_remove(TESTPATH1), 0); /* check that we got what is expected */ memset(cmpbuf, 0, sizeof(cmpbuf)); memset(cmpbuf+16000, 1, 16); ATF_REQUIRE_EQ(memcmp(buf, cmpbuf, sizeof(buf)), 0); }
void mainthread(void *cmdline) { int rv, fd; rv = rump_init(); bmk_printf("rump kernel init complete, rv %d\n", rv); writestr(1, "Hello, stdout!\n"); bmk_printf("open(/notexisting): "); fd = rump_sys_open("/notexisting", 0); if (fd == -1) { int errno = *bmk_sched_geterrno(); if (errno == RUMP_ENOENT) { bmk_printf("No such file or directory. All is well.\n"); } else { bmk_printf("Something went wrong. errno = %d\n", errno); } } else { bmk_printf("Success?! fd=%d\n", fd); } rump_sys_reboot(0, NULL); }
int main(int argc, char *argv[]) { int fd; int err; prop_dictionary_t dict_in, dict_out; struct plistref prefp; char *xml; err = rump_init(); if (err != 0) printf("rump_init failed with %s\n", strerror(err)); fd = rump_sys_open("/dev/mapper/control", O_RDWR, 0); if (fd == -1) printf("Cannot open control device.\n"); dict_in = prop_dictionary_internalize_from_file("prop2.plist"); dict_out = prop_dictionary_create(); prop_dictionary_externalize_to_pref(dict_in, &prefp); err = rump_sys_ioctl(fd, NETBSD_DM_IOCTL, &prefp); if ( err < 0) printf("ioctl failed %d\n", err); dict_out = prop_dictionary_internalize(prefp.pref_plist); xml = prop_dictionary_externalize(dict_out); printf("%s\n",xml); rump_sys_close(fd); }
static void fcntl_lock(const atf_tc_t *tc, const char *mp) { int fd, fd2; struct flock l; struct lwp *lwp1, *lwp2; FSTEST_ENTER(); l.l_pid = 0; l.l_start = l.l_len = 1024; l.l_type = F_RDLCK | F_WRLCK; l.l_whence = SEEK_END; lwp1 = rump_pub_lwproc_curlwp(); RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755)); RL(rump_sys_ftruncate(fd, 8192)); /* PR kern/43321 */ if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); RL(rump_sys_fcntl(fd, F_SETLK, &l)); /* Next, we fork and try to lock the same area */ RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); lwp2 = rump_pub_lwproc_curlwp(); RL(fd2 = rump_sys_open(TESTFILE, O_RDWR, 0)); ATF_REQUIRE_ERRNO(EAGAIN, rump_sys_fcntl(fd2, F_SETLK, &l)); /* Switch back and unlock... */ rump_pub_lwproc_switch(lwp1); l.l_type = F_UNLCK; RL(rump_sys_fcntl(fd, F_SETLK, &l)); /* ... and try to lock again */ rump_pub_lwproc_switch(lwp2); l.l_type = F_RDLCK | F_WRLCK; RL(rump_sys_fcntl(fd2, F_SETLK, &l)); RL(rump_sys_close(fd2)); rump_pub_lwproc_releaselwp(); RL(rump_sys_close(fd)); FSTEST_EXIT(); }
/* main */ int main (int argc, char *argv[]) { error_t err; mach_port_t bootstrap; struct trivfs_control *fsys; err = argp_parse(&argp, argc, argv, 0, NULL, NULL); if (err) { error(1, err, "argp_parse"); } task_get_bootstrap_port(mach_task_self(), &bootstrap); if (bootstrap == MACH_PORT_NULL) { error(1, 0, "must be started as translator"); } /* reply to our parent */ err = trivfs_startup(bootstrap, 0, NULL, NULL, NULL, NULL, &fsys); if (err) { error(3, err, "trivfs_startup"); } /* launch translator */ init_logging(); info("start oss translator"); info("init rump"); rump_init(); debug("open rump audio device"); audio_fd = rump_sys_open(RUMP_AUDIO_DEVICE, O_WRONLY); if (audio_fd < 0) { err("rump_open(%s, O_WRONLY): %s", RUMP_AUDIO_DEVICE, rump_strerror(errno)); return EIO; } /* set default parameters */ audio_info_t info; AUDIO_INITINFO(&info); info.play.sample_rate = 44100; info.play.channels = 1; info.play.precision = 16; info.play.encoding = AUDIO_ENCODING_LINEAR; info.play.samples = 0; if (rump_sys_ioctl(audio_fd, AUDIO_SETINFO, &info)) { err("rump_sys_ioctl AUDIO_SETINFO: %s", rump_strerror(errno)); return EIO; } /* wait for orders */ info("wait for orders"); ports_manage_port_operations_one_thread(fsys->pi.bucket, oss_demuxer, 0); 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(); }
static void create_exist(const atf_tc_t *tc, const char *mp) { const char *name = "hoge"; int fd; RL(rump_sys_chdir(mp)); RL(fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666)); RL(rump_sys_close(fd)); RL(rump_sys_unlink(name)); RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)); RL(rump_sys_close(fd)); RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)); RL(rump_sys_close(fd)); ATF_REQUIRE_ERRNO(EEXIST, (fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666))); RL(rump_sys_unlink(name)); RL(rump_sys_chdir("/")); }
static void overwritebody(const atf_tc_t *tc, off_t count, bool dotrunc) { char *buf; int fd; REQUIRE_LIBC(buf = malloc(count), NULL); FSTEST_ENTER(); RL(fd = rump_sys_open("testi", O_CREAT | O_RDWR, 0666)); ATF_REQUIRE_EQ(rump_sys_write(fd, buf, count), count); RL(rump_sys_close(fd)); RL(fd = rump_sys_open("testi", O_RDWR)); if (dotrunc) RL(rump_sys_ftruncate(fd, 0)); ATF_REQUIRE_EQ(rump_sys_write(fd, buf, count), count); RL(rump_sys_close(fd)); FSTEST_EXIT(); }
static void times(const atf_tc_t *tc, const char *mp) { const char *name = "file.test"; int fd; unsigned int i, j; struct timeval tmv[2]; static struct timeval tmvs[] = { { QUAD_MIN, 0 }, { 0, 0 }, { QUAD_MAX, 999999 } }; FSTEST_ENTER(); 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 (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_utimes(name, NULL) != -1 || errno != EACCES) atf_tc_fail_errno("utimes"); rump_pub_lwproc_releaselwp(); if (rump_sys_utimes(name, NULL) == -1) atf_tc_fail_errno("utimes"); for (i = 0; i < sizeof(tmvs) / sizeof(tmvs[0]); i++) { for (j = 0; j < sizeof(tmvs) / sizeof(tmvs[0]); j++) { tmv[0] = tmvs[i]; tmv[1] = tmvs[j]; rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_utimes(name, tmv) != -1 || errno != EPERM) atf_tc_fail_errno("utimes"); rump_pub_lwproc_releaselwp(); if (rump_sys_utimes(name, tmv) == -1) atf_tc_fail_errno("utimes"); } } if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); FSTEST_EXIT(); }
static void shrinkfile(const atf_tc_t *tc, const char *mp) { int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("file", O_RDWR|O_CREAT|O_TRUNC, 0666)); RL(rump_sys_ftruncate(fd, 2)); RL(rump_sys_ftruncate(fd, 1)); rump_sys_close(fd); FSTEST_EXIT(); }
static void attrs(const atf_tc_t *tc, const char *mp) { struct stat sb, sb2; struct timeval tv[2]; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755)); RL(rump_sys_close(fd)); RL(rump_sys_stat(TESTFILE, &sb)); if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { RL(rump_sys_chown(TESTFILE, 1, 2)); sb.st_uid = 1; sb.st_gid = 2; RL(rump_sys_chmod(TESTFILE, 0123)); sb.st_mode = (sb.st_mode & ~ACCESSPERMS) | 0123; } tv[0].tv_sec = 1000000000; /* need something >1980 for msdosfs */ tv[0].tv_usec = 1; tv[1].tv_sec = 1000000002; /* need even seconds for msdosfs */ tv[1].tv_usec = 3; RL(rump_sys_utimes(TESTFILE, tv)); RL(rump_sys_utimes(TESTFILE, tv)); /* XXX: utimes & birthtime */ sb.st_atimespec.tv_sec = 1000000000; sb.st_atimespec.tv_nsec = 1000; sb.st_mtimespec.tv_sec = 1000000002; sb.st_mtimespec.tv_nsec = 3000; RL(rump_sys_stat(TESTFILE, &sb2)); #define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a) if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { CHECK(st_uid); CHECK(st_gid); CHECK(st_mode); } if (!FSTYPE_MSDOS(tc)) { /* msdosfs has only access date, not time */ CHECK(st_atimespec.tv_sec); } CHECK(st_mtimespec.tv_sec); if (!(FSTYPE_EXT2FS(tc) || FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc) || FSTYPE_V7FS(tc))) { CHECK(st_atimespec.tv_nsec); CHECK(st_mtimespec.tv_nsec); } #undef CHECK FSTEST_EXIT(); }
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); }
static time_t lock_it(void) { struct stat st; if (rump_sys_stat(LOCKFILE, &st) != 0) st.st_mtime = 0; int f = rump_sys_open(LOCKFILE, O_WRONLY|O_CREAT|O_TRUNC, 0666); if (f == -1) return 0; rump_sys_close(f); return st.st_mtime; }
ATF_TC_BODY(RNDADDDATA2, tc) { rnddata_t rd; int fd; rump_init(); fd = rump_sys_open("/dev/random", O_RDWR, 0); if (fd == -1) atf_tc_fail_errno("cannot open /dev/random"); rd.entropy = 1; rd.len = -1; ATF_REQUIRE_ERRNO(EINVAL, rump_sys_ioctl(fd, RNDADDDATA, &rd) == -1); }
ATF_TC_BODY(reregister_blk, tc) { char buf[512 * 128]; char cmpbuf[512 * 128]; int rv, tfd; /* first, create some image files */ rv = system("dd if=/dev/zero bs=512 count=64 " "| tr '\\0' '\\1' > disk1.img"); ATF_REQUIRE_EQ(rv, 0); rv = system("dd if=/dev/zero bs=512 count=128 " "| tr '\\0' '\\2' > disk2.img"); ATF_REQUIRE_EQ(rv, 0); rump_init(); ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH1, "./disk1.img", RUMP_ETFS_BLK), 0); tfd = rump_sys_open(TESTPATH1, O_RDONLY); ATF_REQUIRE(tfd != -1); ATF_REQUIRE_EQ(rump_sys_read(tfd, buf, sizeof(buf)), 64*512); memset(cmpbuf, 1, sizeof(cmpbuf)); ATF_REQUIRE_EQ(memcmp(buf, cmpbuf, 64*512), 0); ATF_REQUIRE_EQ(rump_sys_close(tfd), 0); ATF_REQUIRE_EQ(rump_pub_etfs_remove(TESTPATH1), 0); ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH2, "./disk2.img", RUMP_ETFS_BLK), 0); tfd = rump_sys_open(TESTPATH2, O_RDONLY); ATF_REQUIRE(tfd != -1); ATF_REQUIRE_EQ(rump_sys_read(tfd, buf, sizeof(buf)), 128*512); memset(cmpbuf, 2, sizeof(cmpbuf)); ATF_REQUIRE_EQ(memcmp(buf, cmpbuf, 128*512), 0); ATF_REQUIRE_EQ(rump_sys_close(tfd), 0); ATF_REQUIRE_EQ(rump_pub_etfs_remove(TESTPATH2), 0); }
int main(int argc, char *argv[]) { struct wscons_event *wev; int shift = 0; char buf[128]; int fd; rump_boot_sethowto(RUMP_AB_VERBOSE); rump_init(); fd = rump_sys_open("/dev/wskbd", 0); if (fd == -1) err(1, "open"); while (rump_sys_read(fd, buf, sizeof(buf)) > 0) { const char *typestr; /* XXX: timespec in 5.0 vs. -current */ wev = (void *)buf; switch (wev->type) { case WSCONS_EVENT_KEY_UP: typestr = "up"; if (wev->value == 0xe1 || wev->value == 0xe5) shift = 0; break; case WSCONS_EVENT_KEY_DOWN: typestr = "down"; if (wev->value == 0xe1 || wev->value == 0xe5) shift = SHIFT; break; default: typestr = "unknown"; break; } printf("event type: %d (%s)\n", wev->type, typestr); printf("value 0x%x", wev->value); /* * There's probably a value-to-readable tool somewhere * in the tree, but i'm not sure where or how to use it, * so I'll just punt with the supersimple version for now. */ if (wev->value >= 0x04 && wev->value <= 0x1d) printf(" (%c)", wev->value - 0x04 + 'a' + shift); printf("\n"); } }
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; }
int main(int argc, char *argv[]) { pthread_t pt; struct md_conf md; int fd, error; if (argc != 2) exit(1); md.md_addr = calloc(1, MDSIZE); md.md_size = MDSIZE; md.md_type = MD_UMEM_SERVER; error = rump_daemonize_begin(); REQUIRE(error, "rump_daemonize_begin"); error = rump_init(); REQUIRE(error, "rump_init"); error = rump_init_server("unix://commsock"); REQUIRE(error, "init server"); if ((fd = rump_sys_open(argv[1], O_RDWR)) == -1) err(1, "open"); /* * Now, configuring the md driver also causes our process * to start acting as the worker for the md. Splitting it * into two steps in the driver is not easy, since md is * supposed to be unconfigured when the process dies * (process may exit between calling ioctl1 and ioctl2). * So, start a probe thread which attempts to read the md * and declares the md as configured when the read is * succesful. */ error = pthread_create(&pt, NULL, prober, argv[1]); REQUIRE(error, "pthread_create"); pthread_detach(pt); if (rump_sys_ioctl(fd, MD_SETCONF, &md) == -1) { rump_daemonize_done(errno); exit(1); } return 0; }
static void rename_nametoolong(const atf_tc_t *tc, const char *mp) { char *name; int res, fd; long val; size_t len; if (FSTYPE_RUMPFS(tc)) atf_tc_skip("rename not supported by file system"); if (rump_sys_chdir(mp) == -1) atf_tc_fail_errno("chdir mountpoint"); val = rump_sys_pathconf(".", _PC_NAME_MAX); if (val == -1) atf_tc_fail_errno("pathconf"); len = val + 1; name = malloc(len+1); if (name == NULL) atf_tc_fail_errno("malloc"); memset(name, 'a', len); *(name+len) = '\0'; fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666); if (fd == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); val = rump_sys_pathconf(".", _PC_NO_TRUNC); if (val == -1) atf_tc_fail_errno("pathconf"); res = rump_sys_rename("dummy", name); if (val != 0 && (res != -1 || errno != ENAMETOOLONG)) atf_tc_fail_errno("rename"); if (val == 0 && rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); free(name); rump_sys_chdir("/"); }
static void flags(const atf_tc_t *tc, const char *mp) { const char *name = "file.test"; int fd, fflags; struct stat st; FSTEST_ENTER(); 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"); if (rump_sys_stat(name, &st) == -1) atf_tc_fail_errno("stat"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_chflags(name, st.st_flags) == -1) { if (errno == EOPNOTSUPP) atf_tc_skip("file flags not supported by file system"); atf_tc_fail_errno("chflags"); } fflags = st.st_flags | UF_IMMUTABLE; rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); fflags |= UF_IMMUTABLE; if (rump_sys_chflags(name, fflags) != -1 || errno != EPERM) atf_tc_fail_errno("chflags"); rump_pub_lwproc_releaselwp(); if (rump_sys_chflags(name, fflags) == -1) atf_tc_fail_errno("chflags"); fflags &= ~UF_IMMUTABLE; if (rump_sys_chflags(name, fflags) == -1) atf_tc_fail_errno("chflags"); if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); FSTEST_EXIT(); }
int main(int argc, char *argv[]) { char buf[8192]; ssize_t n; int probeonly = 0; int fd_src, fd_dst; if (argc != 2) errx(1, "need 2 args"); if (strcmp(argv[1], "probe") == 0) probeonly = 1; if (probeonly) rump_boot_sethowto(RUMP_AB_VERBOSE); rump_init(); if (probeonly) exit(0); fd_dst = rump_sys_open("/dev/ulpt0", O_RDWR); if (fd_dst == -1) err(1, "printer open"); fd_src = open(argv[1], O_RDONLY); if (fd_src == -1) err(1, "open source"); for (;;) { n = read(fd_src, buf, sizeof(buf)); if (n == 0) break; if (n == -1) err(1, "read"); if (rump_sys_write(fd_dst, buf, n) != n) err(1, "write to printer"); } rump_sys_close(fd_dst); printf("done\n"); }