2a58f089e4392ca384642738c5ec8b33bc128b2e
[openafs.git] / src / dir / test / physio.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * File         physio.cx
12  * NOTE         This is NOT the standard physio.cx for venus or, yet alone, vice.
13  *              It is a test one for use in src/dir.
14  *
15  */
16
17 /* First we have the kernel hacks' include files. */
18 #include <afsconfig.h>
19 #include <afs/param.h>
20
21
22 #include <sys/param.h>
23 #ifdef AFS_VFSINCL_ENV
24 #include <ufs/fsdir.h>
25 #else /* AFS_VFSINCL_ENV */
26 #include <sys/dir.h>
27 #endif /* AFS_VFSINCL_ENV */
28 #include <sys/user.h>
29 #define VIRTUE 1
30 #include <afs/remote.h>
31 #undef VIRTUE
32 #include <sys/file.h>
33 #include <sys/stat.h>
34 #include <errno.h>
35 #include <itc.h>
36 #include <stdio.h>
37 #include <rx/xdr.h>
38
39 /* Here are the include file(s) for the light-weight process facility. */
40 #include "lwp.h"
41 #include "lock.h"
42
43 #define PAGESIZE 2048
44
45 ReallyRead(fid, block, data)
46      long *fid;                 /* View the fid as longs. */
47      long block;
48      char *data;
49 {                               /* Do a real read. */
50     char fname[100];
51     int s, code;
52     sprintf(fname, "F%d", *fid);
53     s = open(fname, O_RDONLY, 0644);
54     if (s < 0)
55         Die("can't open cache file");
56     code = lseek(s, PAGESIZE * block, 0);
57     if (code < 0)
58         Die("r:lseek");
59     code = read(s, data, PAGESIZE);
60     if (code < 0) {
61         Die("read");
62     }
63     close(s);
64     return 0;
65 }
66
67 ReallyWrite(fid, block, data)
68      long *fid;                 /* View the fid as longs. */
69      long block;
70      char *data;
71 {                               /* Do a real write. */
72     char fname[100];
73     int s, code;
74     sprintf(fname, "F%d", *fid);
75     s = open(fname, O_RDWR | O_CREAT, 0644);
76     if (s < 0)
77         Die("can't find cache file");
78     code = lseek(s, PAGESIZE * block, 0);
79     if (code < 0)
80         Die("w:lseek");
81     code = write(s, data, PAGESIZE);
82     if (code < 0)
83         Die("write");
84     close(s);
85     return 0;
86 }
87
88
89 /* The following three routines provide the fid routines used by the buffer and directory packages. */
90
91 int
92 FidZap(afid)
93      long *afid;
94 {                               /* Zero out a file */
95     *afid = 0;
96 }
97
98 int
99 FidZero(afid)
100      long *afid;
101 {                               /* Zero out a file */
102     *afid = 0;
103 }
104
105 int
106 FidEq(afid, bfid)
107      long *afid, *bfid;
108 {                               /* Compare two fids for equality. */
109     if (*afid != *bfid)
110         return 0;
111     return 1;
112 }
113
114 int
115 FidVolEq(afid, bfid)
116      long *afid, *bfid;
117 {                               /* Is fid in a particular volume */
118     return 1;
119 }
120
121 int
122 FidCpy(dfid, sfid)
123      long *dfid, *sfid;
124 {                               /* Assign one fid to another. */
125     *dfid = *sfid;
126 }
127
128 Die(arg)
129      char *arg;
130 {                               /* Print an error message and then exit. */
131     int i, j;
132     printf("Fatal error: %s\n", arg);
133
134     i = 1;
135     j = 0;
136     i = i / j;
137
138     exit(1);
139 }