Date: Mon, 25 Apr 2022 13:01:00 GMT From: Mark Johnston <markj@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 00193c79b420 - stable/13 - path_test: Verify that operations on unlinked files work Message-ID: <202204251301.23PD10SM019301@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=00193c79b4206ba8d576ae12a002340d7d1bd4ec commit 00193c79b4206ba8d576ae12a002340d7d1bd4ec Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2022-04-18 21:46:04 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-04-25 12:59:18 +0000 path_test: Verify that operations on unlinked files work Sponsored by: The FreeBSD Foundation (cherry picked from commit b13ac678420292f5994b0b6e0f27995b9399268b) --- tests/sys/file/path_test.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/sys/file/path_test.c b/tests/sys/file/path_test.c index b4411b67f26d..216782a5f2bc 100644 --- a/tests/sys/file/path_test.c +++ b/tests/sys/file/path_test.c @@ -898,6 +898,38 @@ ATF_TC_BODY(path_unix, tc) CHECKED_CLOSE(pathfd); } +/* + * Check that we can perform operations using an O_PATH fd for an unlinked file. + */ +ATF_TC_WITHOUT_HEAD(path_unlinked); +ATF_TC_BODY(path_unlinked, tc) +{ + char path[PATH_MAX]; + struct stat sb; + int pathfd; + + mktfile(path, "path_rights.XXXXXX"); + + pathfd = open(path, O_PATH); + ATF_REQUIRE_MSG(pathfd >= 0, FMT_ERR("open")); + + ATF_REQUIRE_MSG(fstatat(pathfd, "", &sb, AT_EMPTY_PATH) == 0, + FMT_ERR("fstatat")); + ATF_REQUIRE(sb.st_nlink == 1); + ATF_REQUIRE_MSG(fstat(pathfd, &sb) == 0, FMT_ERR("fstat")); + ATF_REQUIRE(sb.st_nlink == 1); + + ATF_REQUIRE_MSG(unlink(path) == 0, FMT_ERR("unlink")); + + ATF_REQUIRE_MSG(fstatat(pathfd, "", &sb, AT_EMPTY_PATH) == 0, + FMT_ERR("fstatat")); + ATF_REQUIRE(sb.st_nlink == 0); + ATF_REQUIRE_MSG(fstat(pathfd, &sb) == 0, FMT_ERR("fstat")); + ATF_REQUIRE(sb.st_nlink == 0); + + CHECKED_CLOSE(pathfd); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, path_access); @@ -920,6 +952,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, path_pipe_fstatat); ATF_TP_ADD_TC(tp, path_rights); ATF_TP_ADD_TC(tp, path_unix); + ATF_TP_ADD_TC(tp, path_unlinked); return (atf_no_error()); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202204251301.23PD10SM019301>