12 #define TESTMNT "testmnt"
13 #define TESTFILE "test.txt"
14 #define TESTSTRING "foobar"
15 #define RAMDISK "/dev/ram5"
16 #define RAMDISK_SIZE "2048"
17 #define SILENT " > /dev/null 2>&1"
19 void basic_test(void);
20 void bomb(char const *msg
);
21 void skip(char const *msg
);
22 void create_partition(void);
23 void verify_tools(void);
28 /* Write a string to a file, read it back, and confirm it's identical */
31 char file_buf
[sizeof(TESTSTRING
)*10];
36 /* Write test string to test file */
37 snprintf(cmd_buf
, sizeof(cmd_buf
), "echo -n %s > %s/%s\n",
38 TESTSTRING
, TESTMNT
, TESTFILE
);
39 status
= system(cmd_buf
);
40 if (WEXITSTATUS(status
) != 0)
41 bomb("Unable to echo string to file");
43 /* Flush to disk and unmount, remount */
45 system("umount " RAMDISK SILENT
);
46 snprintf(cmd_buf
, sizeof(cmd_buf
), "mount -t ntfs-3g %s %s %s",
47 RAMDISK
, TESTMNT
, SILENT
);
48 status
= system(cmd_buf
);
49 if (WEXITSTATUS(status
!= 0))
50 bomb("Unable to mount NTFS partition (1)");
52 /* Open file and verify contents */
53 if ((fd
= open(TESTMNT
"/" TESTFILE
, O_RDONLY
)) < 0) e(1);
54 if (read(fd
, file_buf
, sizeof(file_buf
)) != strlen(TESTSTRING
)) e(2);
56 system("umount " RAMDISK SILENT
);
57 if (strncmp(file_buf
, TESTSTRING
, strlen(TESTSTRING
))) e(3);
63 system("umount " RAMDISK SILENT
);
71 system("umount " RAMDISK SILENT
);
78 create_partition(void)
85 if (getuid() != 0 && setuid(0) != 0) e(1);
86 status
= system("ramdisk " RAMDISK_SIZE
" " RAMDISK SILENT
);
87 if (WEXITSTATUS(status
) != 0)
88 bomb("Unable to create ramdisk");
90 status
= system("mkntfs " RAMDISK SILENT
);
91 if (WEXITSTATUS(status
) != 0)
92 bomb("Unable to create NTFS file system on " RAMDISK
);
94 if (mkdir(TESTMNT
, 0755) != 0)
95 bomb("Unable to create directory for mounting");
97 snprintf(mntcmd
, sizeof(mntcmd
), "mount -t ntfs-3g %s %s %s",
98 RAMDISK
, TESTMNT
, SILENT
);
99 status
= system(mntcmd
);
100 if (WEXITSTATUS(status
!= 0))
101 bomb("Unable to mount NTFS partition (1)");
110 status
= system("which mkntfs > /dev/null 2>&1");
111 if (WEXITSTATUS(status
) != 0) {
112 skip("mkntfs not found. Please install ntfsprogs (pkgin in "
115 status
= system("which ntfs-3g > /dev/null 2>&1");
116 if (WEXITSTATUS(status
) != 0) {
117 skip("ntfs-3g not found. Please install fuse-ntfs-3g-1.1120 "
118 "(pkgin in fuse-ntfs-3g-1.1120)");
123 main(int argc
, char *argv
[])
130 return(-1); /* Unreachable */