2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
12 #include <afs/param.h>
13 #include <sys/types.h>
25 struct timeval tvp[2];
30 #define getcwd(x,y) getwd(x)
33 /* venus system tester */
34 if (argc != 2) return printf("usage: fulltest <dir-to-screw-up>\n");
37 if (chdir(dirName) < 0) return perror("chdir");
38 if (getcwd(tempName, 1024) == 0) {
39 return printf("Could not get working dir.\n");
41 /* now create some files */
42 fd1 = open("hi", O_CREAT | O_TRUNC | O_RDWR, 0666);
43 if (fd1 < 0) return perror("open1");
44 if (close(fd1) < 0) return perror("close1");
45 if (access("hi", 2) < 0) return printf("New file can not be written (access)\n");
46 if (chmod ("hi", 0741) < 0) return perror("chmod1");
47 if (stat("hi", &tstat) < 0) return perror("stat1");
48 if ((tstat.st_mode & 0777) != 0741) return printf("chmod failed to set mode properly\n");
50 fd1 = open("hi", O_RDWR);
51 if (fd1 < 0) return perror("open2");
52 if (fchmod(fd1, 0654) < 0) return perror("fchmod");
53 if (fstat(fd1, &tstat) < 0) return perror("fstat1");
54 if ((tstat.st_mode & 0777) != 0654) return printf("fchmod failed to set mode properly\n");
56 /* These appear to be defunct routines;
57 * I don't know what, if anything, replaced them */
58 if (osi_ExclusiveLockNoBlock(fd1) < 0) return perror("flock1");
59 if (osi_UnLock(fd1) < 0) return perror("flock/unlock");
62 /* How about shared lock portability? */
67 fl.l_whence = SEEK_SET;
71 if (fcntl(fd1, F_SETLK, &fl) == -1) return perror("fcntl1: RDLCK");
74 fl.l_whence = SEEK_SET;
78 if (fcntl(fd1, F_SETLK, &fl) == -1) return perror("fcntl2: UNLCK");
81 fl.l_whence = SEEK_SET;
85 if (fcntl(fd1, F_SETLK, &fl) == -1) return perror("fcntl3: WRLCK");
88 fl.l_whence = SEEK_SET;
92 if (fcntl(fd1, F_SETLK, &fl) == -1) return perror("fcntl4: UNLCK");
95 if (fsync(fd1) < 0) return perror("fsync");
96 if (write(fd1, "hi\n", 3) != 3) return perror("write");
97 if (ftruncate(fd1, 2) < 0) return perror("ftruncate");
98 if (close(fd1) < 0) return perror("close2");
100 fd1 = open("hi", O_RDONLY);
101 if (fd1 < 0) return perror("open3");
102 if (read(fd1, tempName, 100) != 2) return perror("read2");
103 if (close (fd1) < 0) return perror("close3");
105 if (link("hi", "bye") < 0) return perror("link");
106 if (stat("bye", &tstat) < 0) return perror("link/stat");
108 if (unlink("bye")<0) return perror("unlink");
110 if (symlink("hi", "bye") < 0) return perror("symlink");
111 if (readlink("bye", tempName, 100) != 2) return perror("readlink");
112 if (strncmp(tempName, "hi", 2) != 0) return printf("readlink contents");
113 if (mkdir("tdir", 0777) < 0) return perror("mkdir");
114 fd1 = open("tdir/fdsa", O_CREAT | O_TRUNC, 0777);
116 if (rmdir("tdir") == 0) return printf("removed non-empty dir\n");
117 if (unlink("tdir/fdsa") < 0) return perror("unlink tdir contents");
118 if (rmdir("tdir") < 0) return perror("rmdir");
120 fd1 = open (".", O_RDONLY);
121 if (fd1<0) return perror("open dot");
122 if (read(fd1, tempName, 20) < 20) perror("read dir");
125 fd1 = open("rotest", O_RDWR | O_CREAT, 0444);
126 if (fd1<0) return perror("open ronly");
127 fchown(fd1, 1, -1); /* don't check error code, may fail on Ultrix */
128 code = write(fd1, "test", 4);
130 printf("rotest short read (%d)\n", code);
134 if (code) return perror("close ronly");
135 code = stat("rotest", &tstat);
136 if (code < 0) return perror("stat ronly");
137 if (tstat.st_size != 4) {
138 printf("rotest short close\n");
141 if (unlink("rotest")<0) return perror("rotest unlink");
143 if (rename("hi", "bye") < 0) return perror("rename1");
144 if (stat("bye", &tstat) < 0) return perror("rename target invisible\n");
145 if (stat("hi", &tstat) == 0) return printf("rename source still there\n");
148 /* No truncate(2) on aix so the following are excluded */
149 if (truncate("bye", 1) < 0) return perror("truncate");
150 if (stat("bye", &tstat) < 0) return perror("truncate zapped");
151 if (tstat.st_size != 1) return printf("truncate failed\n");
153 if (utimes("bye", tvp) < 0) return perror("utimes");
154 if (unlink("bye") < 0) return perror("unlink bye");
159 printf("Test completed successfully.\n");