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("/"); }
static int move_to_dir(const char *from, const char *to, int flags) { const char *p; int rv; char path[PATH_MAX + 1]; struct stat file_stat; size_t len; len = strlen(to); rv = strlcpy(path, to, PATH_MAX + 1); if (rv != (int)len) { warn("%s", to); return -1; } rv = rump_sys_stat(from, &file_stat); if (rv == -1) { warn("%s", from); return -1; } p = strrchr(from, '/'); if (p == NULL) p = from; else ++p; rv = strlcat(path, p, PATH_MAX + 1); if (rv == -1) { warn("%s/%s", path, p); return -1; } if (flags & FSU_MV_VERBOSE) printf("%s -> %s\n", from, path); if (flags & FSU_MV_INTERACTIVE) { rv = rump_sys_stat(path, &file_stat); if (rv != -1 && !is_user_ok(to)) return 0; } rv = rump_sys_rename(from, path); if (rv == -1) { warn("%s", from); return -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 int move_to_file(const char *from, const char *to, int flags) { int rv; struct stat file_stat; if (flags & FSU_MV_VERBOSE) printf("%s -> %s\n", from, to); if (flags & FSU_MV_INTERACTIVE) { rv = rump_sys_stat(to, &file_stat); if (rv != -1 && !is_user_ok(to)) return 0; } rv = rump_sys_rename(from, to); if (rv == -1) { warn("%s or %s", from, to); return -1; } return 0; }
static void rename_reg_nodir(const atf_tc_t *tc, const char *mp) { bool haslinks; struct stat sb; ino_t f1ino, f2ino; 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"); if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc)) haslinks = false; else haslinks = true; if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1) atf_tc_fail_errno("create file"); if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1) atf_tc_fail_errno("create file"); if (rump_sys_stat("file1", &sb) == -1) atf_tc_fail_errno("stat"); f1ino = sb.st_ino; if (haslinks) { if (rump_sys_link("file1", "file_link") == -1) atf_tc_fail_errno("link"); if (rump_sys_stat("file_link", &sb) == -1) atf_tc_fail_errno("stat"); ATF_REQUIRE_EQ(sb.st_ino, f1ino); ATF_REQUIRE_EQ(sb.st_nlink, 2); } if (rump_sys_stat("file2", &sb) == -1) atf_tc_fail_errno("stat"); f2ino = sb.st_ino; if (rump_sys_rename("file1", "file3") == -1) atf_tc_fail_errno("rename 1"); if (rump_sys_stat("file3", &sb) == -1) atf_tc_fail_errno("stat 1"); if (haslinks) { ATF_REQUIRE_EQ(sb.st_ino, f1ino); } if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT) atf_tc_fail_errno("source 1"); if (rump_sys_rename("file3", "file2") == -1) atf_tc_fail_errno("rename 2"); if (rump_sys_stat("file2", &sb) == -1) atf_tc_fail_errno("stat 2"); if (haslinks) { ATF_REQUIRE_EQ(sb.st_ino, f1ino); } if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT) atf_tc_fail_errno("source 2"); if (haslinks) { if (rump_sys_rename("file2", "file_link") == -1) atf_tc_fail_errno("rename hardlink"); if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT) atf_tc_fail_errno("source 3"); if (rump_sys_stat("file_link", &sb) == -1) atf_tc_fail_errno("stat 2"); ATF_REQUIRE_EQ(sb.st_ino, f1ino); ATF_REQUIRE_EQ(sb.st_nlink, 1); } rump_sys_chdir("/"); }
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)); }