41
42
mkdir(dirName, 0777);
42
43
if (chdir(dirName) < 0)
43
return perror("chdir");
44
{perror("chdir");return;}
44
45
if (getcwd(tempName, 1024) == 0) {
45
46
return printf("Could not get working dir.\n");
47
48
/* now create some files */
48
49
fd1 = open("hi", O_CREAT | O_TRUNC | O_RDWR, 0666);
50
return perror("open1");
51
{perror("open1");return;}
51
52
if (close(fd1) < 0)
52
return perror("close1");
53
{perror("close1");return;}
53
54
if (access("hi", 2) < 0)
54
55
return printf("New file can not be written (access)\n");
55
56
if (chmod("hi", 0741) < 0)
56
return perror("chmod1");
57
{perror("chmod1");return;}
57
58
if (stat("hi", &tstat) < 0)
58
return perror("stat1");
59
{perror("stat1");return;}
59
60
if ((tstat.st_mode & 0777) != 0741)
60
61
return printf("chmod failed to set mode properly\n");
62
63
fd1 = open("hi", O_RDWR);
64
return perror("open2");
65
{perror("open2");return;}
65
66
if (fchmod(fd1, 0654) < 0)
66
return perror("fchmod");
67
{perror("fchmod");return;}
67
68
if (fstat(fd1, &tstat) < 0)
68
return perror("fstat1");
69
{perror("fstat1");return;}
69
70
if ((tstat.st_mode & 0777) != 0654)
70
71
return printf("fchmod failed to set mode properly\n");
72
73
/* These appear to be defunct routines;
73
74
* I don't know what, if anything, replaced them */
74
75
if (osi_ExclusiveLockNoBlock(fd1) < 0)
75
return perror("flock1");
76
{perror("flock1");return;}
76
77
if (osi_UnLock(fd1) < 0)
77
return perror("flock/unlock");
78
{perror("flock/unlock");return;}
80
81
/* How about shared lock portability? */
113
114
if (fcntl(fd1, F_SETLK, &fl) == -1)
114
return perror("fcntl4: UNLCK");
115
{perror("fcntl4: UNLCK");return;}
117
118
if (fsync(fd1) < 0)
118
return perror("fsync");
119
{perror("fsync");return;}
119
120
if (write(fd1, "hi\n", 3) != 3)
120
return perror("write");
121
{perror("write");return;}
121
122
if (ftruncate(fd1, 2) < 0)
122
return perror("ftruncate");
123
{perror("ftruncate");return;}
123
124
if (close(fd1) < 0)
124
return perror("close2");
125
{perror("close2");return;}
126
127
fd1 = open("hi", O_RDONLY);
128
return perror("open3");
129
{perror("open3");return;}
129
130
if (read(fd1, tempName, 100) != 2)
130
return perror("read2");
131
{perror("read2");return;}
131
132
if (close(fd1) < 0)
132
return perror("close3");
133
{perror("close3");return;}
134
135
if (link("hi", "bye") < 0)
135
return perror("link");
136
{perror("link");return;}
136
137
if (stat("bye", &tstat) < 0)
137
return perror("link/stat");
138
{perror("link/stat");return;}
139
140
if (unlink("bye") < 0)
140
return perror("unlink");
141
{perror("unlink");return;}
142
143
if (symlink("hi", "bye") < 0)
143
return perror("symlink");
144
{perror("symlink");return;}
144
145
if (readlink("bye", tempName, 100) != 2)
145
return perror("readlink");
146
{perror("readlink");return;}
146
147
if (strncmp(tempName, "hi", 2) != 0)
147
148
return printf("readlink contents");
148
149
if (mkdir("tdir", 0777) < 0)
149
return perror("mkdir");
150
{perror("mkdir");return;}
150
151
fd1 = open("tdir/fdsa", O_CREAT | O_TRUNC, 0777);
152
153
if (rmdir("tdir") == 0)
153
154
return printf("removed non-empty dir\n");
154
155
if (unlink("tdir/fdsa") < 0)
155
return perror("unlink tdir contents");
156
{perror("unlink tdir contents");return;}
156
157
if (rmdir("tdir") < 0)
157
return perror("rmdir");
158
{perror("rmdir");return;}
159
160
fd1 = open(".", O_RDONLY);
161
return perror("open dot");
162
{perror("open dot");return;}
162
163
if (read(fd1, tempName, 20) < 20)
163
164
perror("read dir");
166
167
fd1 = open("rotest", O_RDWR | O_CREAT, 0444);
168
return perror("open ronly");
169
{perror("open ronly");return;}
169
170
fchown(fd1, 1, -1); /* don't check error code, may fail on Ultrix */
170
171
code = write(fd1, "test", 4);
175
176
code = close(fd1);
177
return perror("close ronly");
178
{perror("close ronly");return;}
178
179
code = stat("rotest", &tstat);
180
return perror("stat ronly");
181
{perror("stat ronly");return;}
181
182
if (tstat.st_size != 4) {
182
183
printf("rotest short close\n");
185
186
if (unlink("rotest") < 0)
186
return perror("rotest unlink");
187
{perror("rotest unlink");return;}
188
189
if (rename("hi", "bye") < 0)
189
return perror("rename1");
190
{perror("rename1");return;}
190
191
if (stat("bye", &tstat) < 0)
191
return perror("rename target invisible\n");
192
{perror("rename target invisible\n");return;}
192
193
if (stat("hi", &tstat) == 0)
193
194
return printf("rename source still there\n");
195
196
#ifndef AFS_AIX_ENV
196
197
/* No truncate(2) on aix so the following are excluded */
197
198
if (truncate("bye", 1) < 0)
198
return perror("truncate");
199
{perror("truncate");return;}
199
200
if (stat("bye", &tstat) < 0)
200
return perror("truncate zapped");
201
{perror("truncate zapped");return;}
201
202
if (tstat.st_size != 1)
202
203
return printf("truncate failed\n");
204
205
if (utimes("bye", tvp) < 0)
205
return perror("utimes");
206
{perror("utimes");return;}
206
207
if (unlink("bye") < 0)
207
return perror("unlink bye");
208
{perror("unlink bye");return;}
209
210
/* now finish up */
212
213
printf("Test completed successfully.\n");