Commit aab2d1e8 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

zdtm: check read-only tempfs mount

Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 84cc1e12
......@@ -189,6 +189,7 @@ generate_test_list()
ns/static/session00
ns/static/session01
ns/static/tempfs
ns/static/tempfs_ro
ns/static/mnt_ro_bind
ns/static/mount_paths
ns/static/bind-mount
......@@ -331,6 +332,7 @@ vt
rtc
maps007
tempfs
tempfs_ro
mnt_ro_bind
bind-mount
mountpoints
......
......@@ -183,6 +183,7 @@ TST_DIR = \
overmount_fifo \
overmount_sock \
tempfs \
tempfs_ro \
mnt_ro_bind \
mount_paths \
bind-mount \
......
#include <stdbool.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <linux/limits.h>
#include "zdtmtst.h"
const char *test_doc = "Check read-only tmpfs mount";
const char *test_author = "Andrew Vagin <avagin@openvz.org>";
char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);
#define TEST_WORD "testtest"
int main(int argc, char **argv)
{
int fd, ret = 1;
char buf[1024], fname[PATH_MAX];
test_init(argc, argv);
mkdir(dirname, 0700);
if (mount("none", dirname, "tmpfs", 0, "") < 0) {
fail("Can't mount tmpfs");
return 1;
}
snprintf(fname, sizeof(buf), "%s/test.file", dirname);
fd = open(fname, O_RDWR | O_CREAT, 0644);
if (fd < 0) {
err("open failed");
goto err;
}
if (write(fd, TEST_WORD, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
err("write() failed");
goto err;
}
close(fd);
if (mount(NULL, dirname, "tmpfs", MS_REMOUNT | MS_RDONLY, NULL) < 0) {
fail("Can't mount tmpfs");
return 1;
}
test_daemon();
test_waitsig();
fd = open(fname, O_RDONLY);
if (fd < 0) {
err("open failed");
goto err;
}
buf[sizeof(TEST_WORD) + 1] = '\0';
if (read(fd, buf, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
fail("Read failed");
goto err;
}
close(fd);
if (strcmp(buf, TEST_WORD)) {
fail("File corrupted");
goto err;
}
pass();
ret = 0;
err:
umount2(dirname, MNT_DETACH);
rmdir(dirname);
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment