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