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