[LTP] [PATCH] syscalls/fsmount: add coverage for fsmount01.c
YouZhi Zhao
zhaoyouzhi@uniontech.com
Fri Aug 30 09:11:01 CEST 2024
Can I create a file and write a file verification after adding the setting for MOUNT_STTR_RDONLY
Signed-off-by: Youzhi Zhao <zhaoyouzhi@uniontech.com>
---
testcases/kernel/syscalls/fsmount/fsmount01.c | 31 ++++++++++++++++---
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/syscalls/fsmount/fsmount01.c b/testcases/kernel/syscalls/fsmount/fsmount01.c
index 5f755863f..8bf4a5a0a 100644
--- a/testcases/kernel/syscalls/fsmount/fsmount01.c
+++ b/testcases/kernel/syscalls/fsmount/fsmount01.c
@@ -10,6 +10,7 @@
#include "lapi/fsmount.h"
#define MNTPOINT "mntpoint"
+#define TEST_FILE MNTPOINT "/testfile"
#define TCASE_ENTRY(_flags, _attrs) {.name = "Flag " #_flags ", Attr " #_attrs, .flags = _flags, .attrs = _attrs}
@@ -36,6 +37,24 @@ static struct tcase {
TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_NODIRATIME),
};
+static void verify_mount_readonly(void)
+{
+ int fd;
+
+ fd = open(TEST_FILE, O_WRONLY | O_CREAT, 0644);
+ if (fd == -1) {
+ if (errno == EROFS) {
+ tst_res(TPASS, "MOUNT_ATTR_RDONLY verified: Cannot create file, filesystem is read-only.");
+ } else {
+ tst_res(TFAIL | TTERRNO, "Failed to create file for unknown reason.");
+ }
+ } else {
+ tst_res(TFAIL, "MOUNT_ATTR_RDONLY verification failed: File created on supposed read-only filesystem.");
+ close(fd);
+ unlink(TEST_FILE);
+ }
+}
+
static void run(unsigned int n)
{
struct tcase *tc = &tcases[n];
@@ -81,10 +100,14 @@ static void run(unsigned int n)
return;
}
- if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
- SAFE_UMOUNT(MNTPOINT);
- tst_res(TPASS, "%s: fsmount() passed", tc->name);
- }
+ if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
+ if (tc->attrs & MOUNT_ATTR_RDONLY) {
+ verify_mount_readonly();
+ } else {
+ tst_res(TPASS, "%s: fsmount() passed", tc->name);
+ }
+ SAFE_UMOUNT(MNTPOINT);
+ }
}
static struct tst_test test = {
--
2.43.0
More information about the ltp
mailing list