afsconfig-and-rcsid-all-around-20010705
[openafs.git] / src / viced / 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 /*  physio.c    - Physical I/O routines for the buffer package          */
11 /*                                                                      */
12 /*  Date: 5/1/85                                                        */
13 /*                                                                      */
14 /************************************************************************/
15
16 #include <afs/param.h>
17 #include <afsconfig.h>
18
19 RCSID("$Header$");
20
21 #include <stdio.h>
22 #include <errno.h>
23 #ifdef AFS_NT40_ENV
24 #include <fcntl.h>
25 #else
26 #include <sys/file.h>
27 #include <sys/time.h>
28 #include <unistd.h>
29 #endif
30 #include <afs/nfs.h>
31 #include <afs/assert.h>
32 #include <lwp.h>
33 #include <lock.h>
34 #include <time.h>
35 #include <afs/afsint.h>
36 #include <afs/ihandle.h>
37 #include <afs/vnode.h>
38 #include <afs/volume.h>
39 #include "viced.h"
40 #ifdef PAGESIZE
41 #undef PAGESIZE
42 #endif
43 #define PAGESIZE 2048
44
45 extern int LogLevel;
46
47 afs_int32 lpErrno, lpCount;
48
49 /* returns 0 on success, errno on failure */
50 int ReallyRead (file, block, data)
51 DirHandle     * file;
52 int             block;
53 char          * data;
54 {
55     int code;
56     FdHandle_t *fdP;
57
58     fdP = IH_OPEN(file->dirh_handle);
59     if (fdP == NULL) {
60         code = errno;
61         ViceLog (0,
62                  ("ReallyRead(): open failed device %X inode %X errno %d\n",
63                   file->dirh_handle->ih_dev,
64                   PrintInode(NULL, file->dirh_handle->ih_ino), code));
65         return code;
66     }
67     if (FDH_SEEK(fdP, block * PAGESIZE, SEEK_SET) < 0) {
68         code = errno;
69         ViceLog (0,
70                  ("ReallyRead(): lseek failed device %X inode %X errno %d\n",
71                   file->dirh_handle->ih_dev,
72                   PrintInode(NULL, file->dirh_handle->ih_ino), code));
73         FDH_REALLYCLOSE(fdP);
74         return code;
75     }
76     code = FDH_READ(fdP, data, PAGESIZE);
77     if (code != PAGESIZE) {
78         if (code < 0)
79             code = errno;
80         else
81             code = EIO;
82         ViceLog (0,
83                  ("ReallyRead(): read failed device %X inode %X errno %d\n",
84                   file->dirh_handle->ih_dev,
85                   PrintInode(NULL, file->dirh_handle->ih_ino), code));
86         FDH_REALLYCLOSE(fdP);
87         return code;
88     }
89     FDH_CLOSE(fdP);
90     return 0;
91
92 }
93
94 /* returns 0 on success, errno on failure */
95 int ReallyWrite (file, block, data)
96 DirHandle     * file;
97 int             block;
98 char          * data;
99 {
100     afs_int32 count;
101     FdHandle_t *fdP;
102
103     fdP = IH_OPEN(file->dirh_handle);
104     if (fdP == NULL) {
105         ViceLog (0,
106                  ("ReallyWrite(): open failed device %X inode %X errno %d\n",
107                   file->dirh_handle->ih_dev,
108                   PrintInode(NULL, file->dirh_handle->ih_ino), errno));
109         lpErrno = errno;
110         return 0;
111     }
112     if (FDH_SEEK(fdP, block * PAGESIZE, SEEK_SET) < 0) {
113         ViceLog (0,
114                  ("ReallyWrite(): lseek failed device %X inode %X errno %d\n",
115                   file->dirh_handle->ih_dev,
116                   PrintInode(NULL, file->dirh_handle->ih_ino), errno));
117         lpErrno = errno;
118         FDH_REALLYCLOSE(fdP);
119         return 0;
120     }
121     if ((count = FDH_WRITE(fdP, data, PAGESIZE)) != PAGESIZE) {
122         ViceLog (0,
123                  ("ReallyWrite(): write failed device %X inode %X errno %d\n",
124                   file->dirh_handle->ih_dev,
125                   PrintInode(NULL, file->dirh_handle->ih_ino), errno));
126         lpCount = count;
127         lpErrno = errno;
128         FDH_REALLYCLOSE(fdP);
129         return 0;
130     }
131     FDH_CLOSE(fdP);
132     return 0;
133 }
134
135
136 SetDirHandle(dir, vnode)
137 register DirHandle *dir;
138 register Vnode *vnode;
139 {
140     register Volume *vp = vnode->volumePtr;
141     register IHandle_t *h;
142     IH_COPY(h, vnode->handle);
143     dir->dirh_ino = h->ih_ino;
144     dir->dirh_dev = h->ih_dev;
145     dir->dirh_vid = h->ih_vid;
146     dir->dirh_cacheCheck = vp->cacheCheck;
147     dir->dirh_unique = vnode->disk.uniquifier;
148     dir->dirh_vnode = vnode->vnodeNumber;
149     dir->dirh_handle = h;
150 }
151
152 FidZap (file)
153 DirHandle     * file;
154
155 {
156     IH_RELEASE(file->dirh_handle);
157     bzero((char *)file, sizeof(DirHandle));
158 }
159
160 FidZero (file)
161 DirHandle     * file;
162
163 {
164     bzero((char *)file, sizeof(DirHandle));
165 }
166
167 FidEq (afile, bfile)
168 DirHandle      * afile;
169 DirHandle      * bfile;
170
171 {
172     if (afile->dirh_ino != bfile->dirh_ino) return 0;
173     if (afile->dirh_dev != bfile->dirh_dev) return 0;
174     if (afile->dirh_vid != bfile->dirh_vid) return 0;
175     if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck) return 0;
176     if (afile->dirh_unique != bfile->dirh_unique) return 0;
177     if (afile->dirh_vnode != bfile->dirh_vnode) return 0;
178
179     return 1;
180 }
181
182 FidVolEq (afile, vid)
183 DirHandle      * afile;
184 afs_int32            vid;
185
186 {
187     if (afile->dirh_vid != vid) return 0;
188     return 1;
189 }
190
191 FidCpy (tofile, fromfile)
192 DirHandle      * tofile;
193 DirHandle      * fromfile;
194
195 {
196     *tofile = *fromfile;
197     IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
198 }