include-afsconfig-before-param-h-20010712
[openafs.git] / src / vol / 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         System:         VICE-TWO
12         Module:         physio.c
13         Institution:    The Information Technology Center, Carnegie-Mellon University
14
15  */
16
17 #include <afsconfig.h>
18 #include <afs/param.h>
19
20 RCSID("$Header$");
21
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <errno.h>
25 #ifdef AFS_NT40_ENV
26 #include <fcntl.h>
27 #else
28 #include <sys/file.h>
29 #include <unistd.h>
30 #ifdef  AFS_SUN5_ENV
31 #include <sys/fcntl.h>
32 #endif
33 #endif
34 #include <rx/xdr.h>
35 #include <afs/afsint.h>
36 #include <errno.h>
37 #include <afs/afssyscalls.h>
38 #include "ihandle.h"
39 #include "nfs.h"
40 #include "salvage.h"
41 #include "afs/assert.h"
42 #include "afs/dir.h"
43
44 /* returns 0 on success, errno on failure */
45 int ReallyRead (file, block, data)
46 DirHandle     * file;
47 int             block;
48 char          * data;
49 {
50     FdHandle_t *fdP;
51     int code;
52     errno = 0;
53     fdP = IH_OPEN(file->dirh_handle);
54     if (fdP == NULL) {
55         code = errno;
56         return code;
57     }
58     if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) {
59         code = errno;
60         FDH_REALLYCLOSE(fdP);
61         return code;
62     }
63     code = FDH_READ(fdP, data, AFS_PAGESIZE);
64     if (code != AFS_PAGESIZE) {
65         if (code < 0)
66             code = errno;
67         else 
68             code = EIO;
69         FDH_REALLYCLOSE(fdP);
70         return code;
71     }
72     FDH_CLOSE(fdP);
73     return 0;
74 }
75
76 /* returns 0 on success, errno on failure */
77 int ReallyWrite (file, block, data)
78 DirHandle     * file;
79 int             block;
80 char          * data;
81 {
82     FdHandle_t *fdP;
83     extern int VolumeChanged;
84     int code;
85
86     errno = 0;
87
88     fdP = IH_OPEN(file->dirh_handle);
89     if (fdP == NULL) {
90         code = errno;
91         return code;
92     }
93     if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) {
94         code = errno;
95         FDH_REALLYCLOSE(fdP);
96         return code;
97     }
98     code = FDH_WRITE(fdP, data, AFS_PAGESIZE);
99     if (code != AFS_PAGESIZE) {
100         if (code < 0)
101             code = errno;
102         else 
103             code = EIO;
104         FDH_REALLYCLOSE(fdP);
105         return code;
106     }
107     FDH_CLOSE(fdP);
108     VolumeChanged = 1;
109     return 0;
110 }
111
112 /* SetSalvageDirHandle:
113  * Create a handle to a directory entry and reference it (IH_INIT).
114  * The handle needs to be dereferenced with the FidZap() routine.
115  */
116 SetSalvageDirHandle(dir, volume, device, inode)
117 DirHandle *dir;
118 afs_int32 volume;
119 Inode inode;
120 Device device;
121 {
122     static SalvageCacheCheck = 1;
123     bzero(dir, sizeof(DirHandle));
124
125     dir->dirh_device = device;
126     dir->dirh_volume = volume;
127     dir->dirh_inode = inode;
128     IH_INIT(dir->dirh_handle, device, volume,  inode);
129     /* Always re-read for a new dirhandle */
130     dir->dirh_cacheCheck = SalvageCacheCheck++;
131 }
132
133 FidZap (file)
134 DirHandle     * file;
135
136 {
137     IH_RELEASE(file->dirh_handle);
138     bzero(file, sizeof(DirHandle));
139 }
140
141 FidZero (file)
142 DirHandle     * file;
143
144 {
145     bzero(file, sizeof(DirHandle));
146 }
147
148 FidEq (afile, bfile)
149 DirHandle      * afile;
150 DirHandle      * bfile;
151
152 {
153     if (afile->dirh_volume != bfile->dirh_volume) return 0;
154     if (afile->dirh_device != bfile->dirh_device) return 0;
155     if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck) return 0;
156     if (afile->dirh_inode != bfile->dirh_inode) return 0;
157     return 1;
158 }
159
160 FidVolEq (afile, vid)
161 DirHandle      * afile;
162 afs_int32            vid;
163
164 {
165     if (afile->dirh_volume != vid) return 0;
166     return 1;
167 }
168
169 FidCpy (tofile, fromfile)
170 DirHandle      * tofile;
171 DirHandle      * fromfile;
172
173 {
174     *tofile = *fromfile;
175     IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
176 }
177
178 Die (msg)
179 char  * msg;
180
181 {
182     printf("%s\n",msg);
183     assert(1==2);
184 }
185