1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <linux/limits.h>
#include "zdtmtst.h"
const char *test_doc = "Check mounts of external devices";
const char *test_author = "Andrei Vagin <avagin@virtuozzo.com";
char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);
int main(int argc, char **argv)
{
char *loop, fd, dfd, fd2;
struct stat st, stp, st2;
char dname[PATH_MAX], dname2[PATH_MAX];
test_init(argc, argv);
snprintf(dname, sizeof(dname), "%s/test_dir", dirname);
snprintf(dname2, sizeof(dname2), "%s/test_dir2", dirname);
mkdir(dirname, 0777);
loop = getenv("ZDTM_MNT_EXT_DEV");
if (loop == NULL) {
pr_perror("ZDTM_MNT_EXT_DEV is not set");
return 1;
}
if (mount(loop, dirname, "ext4", 0, NULL) == -1) {
pr_perror("mount");
return -1;
}
dfd = open(dirname, O_RDONLY);
if (dfd < 0) {
pr_perror("open");
return -1;
}
fd = openat(dfd, "test_file", O_RDWR | O_CREAT, 0666);
if (fd < 0) {
pr_perror("open");
return -1;
}
if (fstat(fd, &st) < 0) {
pr_perror("stat");
return 1;
}
mkdir(dname, 0777);
mkdir(dname2, 0777);
if (mount(dname, dname2, NULL, MS_BIND, NULL)) {
pr_perror("mount");
return 1;
}
fd2 = openat(dfd, "test_dir2/test_file2", O_RDWR | O_CREAT, 0666);
if (fd2 < 0) {
pr_perror("open");
return -1;
}
if (fstat(fd2, &st2) < 0) {
pr_perror("stat");
return 1;
}
test_daemon();
test_waitsig();
if (fstat(fd, &stp) < 0) {
pr_perror("stat");
return 1;
}
if (st.st_ino != stp.st_ino) {
fail("file1");
return 1;
}
if (fstat(fd2, &stp) < 0) {
pr_perror("stat");
return 1;
}
if (st2.st_ino != stp.st_ino) {
fail("file2");
return 1;
}
if (umount2(dname2, MNT_DETACH)) {
pr_perror("umount");
return 1;
}
pass();
return 0;
}
|