13 #define TESTMNT "testmnt"
14 #define TESTFILE "test.txt"
15 #define TESTSTRING "foobar"
16 #define RAMDISK "/dev/ram5"
17 #define RAMDISK_SIZE "2048"
18 #define SILENT " > /dev/null 2>&1"
20 void basic_test(void);
21 void bomb(char const *msg
);
22 void skip(char const *msg
);
23 void create_partition(void);
24 void verify_tools(void);
29 /* Write a string to a file, read it back, and confirm it's identical */
32 char file_buf
[sizeof(TESTSTRING
)*10];
37 /* Write test string to test file */
38 snprintf(cmd_buf
, sizeof(cmd_buf
), "echo -n %s > %s/%s\n",
39 TESTSTRING
, TESTMNT
, TESTFILE
);
40 status
= system(cmd_buf
);
41 if (WEXITSTATUS(status
) != 0)
42 bomb("Unable to echo string to file");
44 /* Flush to disk and unmount, remount */
46 system("umount " RAMDISK SILENT
);
47 snprintf(cmd_buf
, sizeof(cmd_buf
), "mount -t ntfs-3g %s %s %s",
48 RAMDISK
, TESTMNT
, SILENT
);
49 status
= system(cmd_buf
);
50 if (WEXITSTATUS(status
) != 0)
51 bomb("Unable to mount NTFS partition (1)");
53 /* Open file and verify contents */
54 if ((fd
= open(TESTMNT
"/" TESTFILE
, O_RDONLY
)) < 0) e(1);
55 if (read(fd
, file_buf
, sizeof(file_buf
)) != strlen(TESTSTRING
)) e(2);
57 system("umount " RAMDISK SILENT
);
58 if (strncmp(file_buf
, TESTSTRING
, strlen(TESTSTRING
))) e(3);
64 system("umount " RAMDISK SILENT
);
72 system("umount " RAMDISK SILENT
);
79 create_partition(void)
86 if (getuid() != 0 && setuid(0) != 0) e(1);
87 status
= system("ramdisk " RAMDISK_SIZE
" " RAMDISK SILENT
);
88 if (WEXITSTATUS(status
) != 0)
89 bomb("Unable to create ramdisk");
91 status
= system("mkntfs " RAMDISK SILENT
);
92 if (WEXITSTATUS(status
) != 0)
93 bomb("Unable to create NTFS file system on " RAMDISK
);
95 if (mkdir(TESTMNT
, 0755) != 0)
96 bomb("Unable to create directory for mounting");
98 snprintf(mntcmd
, sizeof(mntcmd
), "mount -t ntfs-3g %s %s %s",
99 RAMDISK
, TESTMNT
, SILENT
);
100 status
= system(mntcmd
);
101 if (WEXITSTATUS(status
) != 0)
102 bomb("Unable to mount NTFS partition (1)");
111 status
= system("which mkntfs > /dev/null 2>&1");
112 if (WEXITSTATUS(status
) != 0) {
113 skip("mkntfs not found. Please install ntfsprogs (pkgin in "
116 status
= system("which ntfs-3g > /dev/null 2>&1");
117 if (WEXITSTATUS(status
) != 0) {
118 skip("ntfs-3g not found. Please install fuse-ntfs-3g-1.1120 "
119 "(pkgin in fuse-ntfs-3g-1.1120)");
124 main(int argc
, char *argv
[])
131 return(-1); /* Unreachable */