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)");
108 int status1
, status2
;
112 status1
= system("which mkntfs > /dev/null 2>&1");
113 status2
= system("which ntfs-3g > /dev/null 2>&1");
114 if (WEXITSTATUS(status1
) != 0 || WEXITSTATUS(status2
) != 0)
115 skip("mkntfs or ntfs-3g not found, skipping test");
119 main(int argc
, char *argv
[])
126 return(-1); /* Unreachable */