Import Upstream version 1.8.5
[hcoop/debian/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 <afsconfig.h>
17 #include <afs/param.h>
18
19 #include <roken.h>
20
21 #ifdef HAVE_SYS_FILE_H
22 #include <sys/file.h>
23 #endif
24
25 #include <rx/rx_queue.h>
26 #include <afs/nfs.h>
27 #include <lwp.h>
28 #include <lock.h>
29 #include <afs/afsint.h>
30 #include <afs/ihandle.h>
31 #include <afs/vnode.h>
32 #include <afs/volume.h>
33 #include "viced_prototypes.h"
34 #include "viced.h"
35 #ifdef PAGESIZE
36 #undef PAGESIZE
37 #endif
38 #define PAGESIZE 2048
39
40 afs_int32 lpErrno, lpCount;
41
42 /* returns 0 on success, errno on failure */
43 int
44 ReallyRead(DirHandle * file, int block, char *data)
45 {
46 int code;
47 ssize_t rdlen;
48 FdHandle_t *fdP;
49 afs_ino_str_t stmp;
50
51 fdP = IH_OPEN(file->dirh_handle);
52 if (fdP == NULL) {
53 code = errno;
54 ViceLog(0,
55 ("ReallyRead(): open failed device %X inode %s (volume=%" AFS_VOLID_FMT ") errno %d\n",
56 file->dirh_handle->ih_dev, PrintInode(stmp,
57 file->dirh_handle->
58 ih_ino),
59 afs_printable_VolumeId_lu(file->dirh_handle->ih_vid), code));
60 return code;
61 }
62 rdlen = FDH_PREAD(fdP, data, PAGESIZE, ((afs_foff_t)block) * PAGESIZE);
63 if (rdlen != PAGESIZE) {
64 if (rdlen < 0)
65 code = errno;
66 else
67 code = EIO;
68 ViceLog(0,
69 ("ReallyRead(): read failed device %X inode %s (volume=%" AFS_VOLID_FMT ") errno %d\n",
70 file->dirh_handle->ih_dev, PrintInode(stmp,
71 file->dirh_handle->
72 ih_ino),
73 afs_printable_VolumeId_lu(file->dirh_handle->ih_vid), code));
74 FDH_REALLYCLOSE(fdP);
75 return code;
76 }
77 FDH_CLOSE(fdP);
78 return 0;
79
80 }
81
82 /* returns 0 on success, errno on failure */
83 int
84 ReallyWrite(DirHandle * file, int block, char *data)
85 {
86 ssize_t count;
87 FdHandle_t *fdP;
88 afs_ino_str_t stmp;
89
90 fdP = IH_OPEN(file->dirh_handle);
91 if (fdP == NULL) {
92 ViceLog(0,
93 ("ReallyWrite(): open failed device %X inode %s (volume=%" AFS_VOLID_FMT ") errno %d\n",
94 file->dirh_handle->ih_dev, PrintInode(stmp,
95 file->dirh_handle->
96 ih_ino),
97 afs_printable_VolumeId_lu(file->dirh_handle->ih_vid), errno));
98 lpErrno = errno;
99 return 0;
100 }
101 if ((count = FDH_PWRITE(fdP, data, PAGESIZE, ((afs_foff_t)block) * PAGESIZE)) != PAGESIZE) {
102 ViceLog(0,
103 ("ReallyWrite(): write failed device %X inode %s (volume=%" AFS_VOLID_FMT ") errno %d\n",
104 file->dirh_handle->ih_dev, PrintInode(stmp,
105 file->dirh_handle->
106 ih_ino),
107 afs_printable_VolumeId_lu(file->dirh_handle->ih_vid), errno));
108 lpCount = count;
109 lpErrno = errno;
110 FDH_REALLYCLOSE(fdP);
111 return 0;
112 }
113 FDH_CLOSE(fdP);
114 return 0;
115 }
116
117
118 void
119 SetDirHandle(DirHandle * dir, Vnode * vnode)
120 {
121 Volume *vp = vnode->volumePtr;
122 IHandle_t *h;
123 IH_COPY(h, vnode->handle);
124 dir->dirh_ino = h->ih_ino;
125 dir->dirh_dev = h->ih_dev;
126 dir->dirh_vid = h->ih_vid;
127 dir->dirh_cacheCheck = vp->cacheCheck;
128 dir->dirh_unique = vnode->disk.uniquifier;
129 dir->dirh_vnode = vnode->vnodeNumber;
130 dir->dirh_handle = h;
131 }
132
133 void
134 FidZap(DirHandle * file)
135 {
136 IH_RELEASE(file->dirh_handle);
137 memset(file, 0, sizeof(DirHandle));
138 }
139
140 void
141 FidZero(DirHandle * file)
142 {
143 memset(file, 0, sizeof(DirHandle));
144 }
145
146 int
147 FidEq(DirHandle * afile, DirHandle * bfile)
148 {
149 if (afile->dirh_ino != bfile->dirh_ino)
150 return 0;
151 if (afile->dirh_dev != bfile->dirh_dev)
152 return 0;
153 if (afile->dirh_vid != bfile->dirh_vid)
154 return 0;
155 if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck)
156 return 0;
157 if (afile->dirh_unique != bfile->dirh_unique)
158 return 0;
159 if (afile->dirh_vnode != bfile->dirh_vnode)
160 return 0;
161
162 return 1;
163 }
164
165 int
166 FidVolEq(DirHandle * afile, VolumeId vid)
167 {
168 if (afile->dirh_vid != vid)
169 return 0;
170 return 1;
171 }
172
173 int
174 FidCpy(DirHandle * tofile, DirHandle * fromfile)
175 {
176 *tofile = *fromfile;
177 IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
178 return 0;
179 }