Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177549374
D61236.1794688115.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D61236.1794688115.diff
View Options
diff --git a/tests/sys/fs/fdescfs/fdescfs_test.c b/tests/sys/fs/fdescfs/fdescfs_test.c
--- a/tests/sys/fs/fdescfs/fdescfs_test.c
+++ b/tests/sys/fs/fdescfs/fdescfs_test.c
@@ -516,6 +516,77 @@
ATF_REQUIRE_EQ(0, unmount("mnt", 0));
}
+#define TEXT "Hello, world!\n"
+#define LEN 14
+
+FDESCFS_TC(truncate_ro,
+ "disallow truncating read-only files (plain)");
+ATF_TC_BODY(truncate_ro, tc)
+{
+ struct stat sb;
+ char fd_path[16];
+ int fd;
+
+ /* create read-only target file */
+ ATF_REQUIRE((fd = open("file", O_RDWR | O_CREAT, 0400)) >= 0);
+ ATF_REQUIRE_EQ(LEN, write(fd, TEXT, LEN));
+ ATF_REQUIRE_EQ(0, close(fd));
+
+ /* reopen the file read-only */
+ ATF_REQUIRE((fd = open("file", O_RDONLY)) >= 0);
+
+ /* mount fdescfs */
+ mount_fdescfs(NULL);
+
+ /* construct and stat path */
+ snprintf(fd_path, sizeof(fd_path), "mnt/%d", fd);
+ ATF_REQUIRE_EQ(0, stat(fd_path, &sb));
+ ATF_CHECK_EQ(S_IFCHR, sb.st_mode & S_IFMT);
+ ATF_CHECK_EQ(0555, sb.st_mode & ALLPERMS);
+ ATF_CHECK_EQ(0, sb.st_size);
+
+ /* attempt to truncate */
+ ATF_CHECK(truncate(fd_path, 0) < 0);
+ ATF_CHECK_EQ(LEN, lseek(fd, 0, SEEK_END));
+
+ /* done */
+ ATF_CHECK_EQ(0, close(fd));
+}
+
+FDESCFS_TC(nodup_truncate_ro,
+ "allow truncating read-only files (nodup)");
+ATF_TC_BODY(nodup_truncate_ro, tc)
+{
+ struct stat sb;
+ char fd_path[16];
+ int fd;
+
+ /* create read-only target file */
+ ATF_REQUIRE((fd = open("file", O_RDWR | O_CREAT, 0400)) >= 0);
+ ATF_REQUIRE_EQ(LEN, write(fd, TEXT, LEN));
+ ATF_REQUIRE_EQ(0, close(fd));
+
+ /* reopen the file read-only */
+ ATF_REQUIRE((fd = open("file", O_RDONLY)) >= 0);
+
+ /* mount fdescfs */
+ mount_fdescfs(nodup);
+
+ /* construct and stat path */
+ snprintf(fd_path, sizeof(fd_path), "mnt/%d", fd);
+ ATF_REQUIRE_EQ(0, stat(fd_path, &sb));
+ ATF_CHECK_EQ(S_IFREG, sb.st_mode & S_IFMT);
+ ATF_CHECK_EQ(0400, sb.st_mode & ALLPERMS);
+ ATF_CHECK_EQ(LEN, sb.st_size);
+
+ /* attempt to truncate */
+ ATF_CHECK(truncate(fd_path, LEN / 2) == 0);
+ ATF_CHECK_EQ(LEN / 2, lseek(fd, 0, SEEK_END));
+
+ /* done */
+ ATF_CHECK_EQ(0, close(fd));
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, traverse_dir);
@@ -535,5 +606,7 @@
ATF_TP_ADD_TC(tp, ioctl_caps);
ATF_TP_ADD_TC(tp, nodup_ioctl_caps);
ATF_TP_ADD_TC(tp, nodup_ioctl_cap_intersection);
+ ATF_TP_ADD_TC(tp, truncate_ro);
+ ATF_TP_ADD_TC(tp, nodup_truncate_ro);
return (atf_no_error());
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 14, 8:28 PM (9 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41642593
Default Alt Text
D61236.1794688115.diff (2 KB)
Attached To
Mode
D61236: tests: Add test for fdescfs truncation bug
Attached
Detach File
Event Timeline