~ubuntu-branches/ubuntu/karmic/openafs/karmic-updates

« back to all changes in this revision

Viewing changes to src/venus/test/fulltest.c

  • Committer: Bazaar Package Importer
  • Author(s): Russ Allbery
  • Date: 2008-09-22 19:07:02 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080922190702-59m13d7kn6gkw32d
Tags: 1.4.7.dfsg1-6
* Apply upstream patch to free /proc entries in the correct order.
  Thanks, Marc Dionne.  (Closes: #493914)
* Apply upstream deltas to support 2.6.27 kernels and to stop using
  COMMON_KERN_CFLAGS for all 2.6 kernels uniformly, which fixes
  problems on amd64 with newer kernels.  Thanks, Björn Torkelsson.
  (LP: #267504)
* Translation updates:
  - Swedish, thanks Martin Bagge.  (Closes: #493120)

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include <afs/param.h>
12
12
 
13
13
RCSID
14
 
    ("$Header: /cvs/openafs/src/venus/test/fulltest.c,v 1.6 2003/07/15 23:17:24 shadow Exp $");
 
14
    ("$Header: /cvs/openafs/src/venus/test/fulltest.c,v 1.6.2.1 2007/11/26 21:21:56 shadow Exp $");
15
15
 
16
16
#include <sys/types.h>
17
17
#include <sys/time.h>
18
18
#include <sys/stat.h>
19
19
#include <fcntl.h>
 
20
#include <stdio.h>
20
21
#include <unistd.h>
21
22
 
22
23
main(argc, argv)
40
41
    dirName = argv[1];
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");
46
47
    }
47
48
    /* now create some files */
48
49
    fd1 = open("hi", O_CREAT | O_TRUNC | O_RDWR, 0666);
49
50
    if (fd1 < 0)
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");
61
62
 
62
63
    fd1 = open("hi", O_RDWR);
63
64
    if (fd1 < 0)
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");
71
72
#if 0
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;}
78
79
#endif
79
80
 
80
81
/* How about shared lock portability? */
87
88
        fl.l_len = 0;
88
89
 
89
90
        if (fcntl(fd1, F_SETLK, &fl) == -1)
90
 
            return perror("fcntl1: RDLCK");
 
91
            {perror("fcntl1: RDLCK");return;}
91
92
 
92
93
        fl.l_type = F_UNLCK;
93
94
        fl.l_whence = SEEK_SET;
95
96
        fl.l_len = 0;
96
97
 
97
98
        if (fcntl(fd1, F_SETLK, &fl) == -1)
98
 
            return perror("fcntl2: UNLCK");
 
99
            {perror("fcntl2: UNLCK");return;}
99
100
 
100
101
        fl.l_type = F_WRLCK;
101
102
        fl.l_whence = SEEK_SET;
103
104
        fl.l_len = 0;
104
105
 
105
106
        if (fcntl(fd1, F_SETLK, &fl) == -1)
106
 
            return perror("fcntl3: WRLCK");
 
107
            {perror("fcntl3: WRLCK");return;}
107
108
 
108
109
        fl.l_type = F_UNLCK;
109
110
        fl.l_whence = SEEK_SET;
111
112
        fl.l_len = 0;
112
113
 
113
114
        if (fcntl(fd1, F_SETLK, &fl) == -1)
114
 
            return perror("fcntl4: UNLCK");
 
115
            {perror("fcntl4: UNLCK");return;}
115
116
    }
116
117
 
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;}
125
126
 
126
127
    fd1 = open("hi", O_RDONLY);
127
128
    if (fd1 < 0)
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;}
133
134
 
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;}
138
139
 
139
140
    if (unlink("bye") < 0)
140
 
        return perror("unlink");
 
141
        {perror("unlink");return;}
141
142
 
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);
151
152
    close(fd1);
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;}
158
159
 
159
160
    fd1 = open(".", O_RDONLY);
160
161
    if (fd1 < 0)
161
 
        return perror("open dot");
 
162
        {perror("open dot");return;}
162
163
    if (read(fd1, tempName, 20) < 20)
163
164
        perror("read dir");
164
165
    close(fd1);
165
166
 
166
167
    fd1 = open("rotest", O_RDWR | O_CREAT, 0444);
167
168
    if (fd1 < 0)
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);
171
172
    if (code != 4) {
174
175
    }
175
176
    code = close(fd1);
176
177
    if (code)
177
 
        return perror("close ronly");
 
178
        {perror("close ronly");return;}
178
179
    code = stat("rotest", &tstat);
179
180
    if (code < 0)
180
 
        return perror("stat ronly");
 
181
        {perror("stat ronly");return;}
181
182
    if (tstat.st_size != 4) {
182
183
        printf("rotest short close\n");
183
184
        exit(1);
184
185
    }
185
186
    if (unlink("rotest") < 0)
186
 
        return perror("rotest unlink");
 
187
        {perror("rotest unlink");return;}
187
188
 
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");
194
195
 
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");
203
204
#endif
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;}
208
209
 
209
210
    /* now finish up */
210
211
    chdir("..");
211
212
    rmdir(dirName);
212
213
    printf("Test completed successfully.\n");
 
214
    return 0;
213
215
}