etc/services - sync with NetBSD-8
[minix.git] / minix / tests / test65.c
bloba58619346227e1e405063e14b330919e8d253d89
1 #include <sys/mount.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <sys/wait.h>
5 #include <fcntl.h>
6 #include <stdio.h>
7 #include <unistd.h>
9 int max_error = 0;
10 #include "common.h"
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);
26 void
27 basic_test(void)
29 /* Write a string to a file, read it back, and confirm it's identical */
30 int status;
31 char cmd_buf[1024];
32 char file_buf[sizeof(TESTSTRING)*10];
33 int fd;
35 subtest = 3;
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 */
45 system("sync");
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);
56 (void) close(fd);
57 system("umount " RAMDISK SILENT);
58 if (strncmp(file_buf, TESTSTRING, strlen(TESTSTRING))) e(3);
61 void
62 skip(char const *msg)
64 system("umount " RAMDISK SILENT);
65 printf("%s\n", msg);
66 quit();
69 void
70 bomb(char const *msg)
72 system("umount " RAMDISK SILENT);
73 printf("%s\n", msg);
74 e(99);
75 quit();
78 void
79 create_partition(void)
81 int status;
82 char mntcmd[1024];
84 subtest = 1;
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)");
105 void
106 verify_tools(void)
108 int status1, status2;
110 subtest = 1;
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[])
121 start(65);
122 verify_tools();
123 create_partition();
124 basic_test();
125 quit();
126 return(-1); /* Unreachable */