Merge 1.8.0~pre4 packaging into master
[pkg-k5-afs_openafs.git] / src / volser / physio.c
blob3562cf8284f15ddd29b1434019450a01d919afb1
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #include <roken.h>
15 #include <rx/xdr.h>
16 #include <rx/rx.h>
17 #include <afs/afsint.h>
18 #include <afs/nfs.h>
19 #include <afs/dir.h>
20 #include <afs/ihandle.h>
22 #include "vol.h"
23 #include "physio.h"
25 /* returns 0 on success, errno on failure */
26 int
27 ReallyRead(DirHandle * file, int block, char *data)
29 FdHandle_t *fdP;
30 int code;
31 ssize_t nBytes;
32 errno = 0;
33 fdP = IH_OPEN(file->dirh_handle);
34 if (fdP == NULL) {
35 code = errno;
36 return code;
38 nBytes = FDH_PREAD(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE);
39 if (nBytes != AFS_PAGESIZE) {
40 if (nBytes < 0)
41 code = errno;
42 else
43 code = EIO;
44 FDH_REALLYCLOSE(fdP);
45 return code;
47 FDH_CLOSE(fdP);
48 return 0;
51 /* returns 0 on success, errno on failure */
52 int
53 ReallyWrite(DirHandle * file, int block, char *data)
55 FdHandle_t *fdP;
56 extern int VolumeChanged;
57 int code;
58 ssize_t nBytes;
60 errno = 0;
62 fdP = IH_OPEN(file->dirh_handle);
63 if (fdP == NULL) {
64 code = errno;
65 return code;
67 nBytes = FDH_PWRITE(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE);
68 if (nBytes != AFS_PAGESIZE) {
69 if (nBytes < 0)
70 code = errno;
71 else
72 code = EIO;
73 FDH_REALLYCLOSE(fdP);
74 return code;
76 FDH_CLOSE(fdP);
77 VolumeChanged = 1;
78 return 0;
81 /* SetSalvageDirHandle:
82 * Create a handle to a directory entry and reference it (IH_INIT).
83 * The handle needs to be dereferenced with the FidZap() routine.
85 void
86 SetSalvageDirHandle(DirHandle * dir, VolumeId volume, afs_int32 device,
87 Inode inode)
89 private int SalvageCacheCheck = 1;
90 memset(dir, 0, sizeof(DirHandle));
92 dir->dirh_volume = volume;
93 dir->dirh_device = device;
94 dir->dirh_inode = inode;
95 IH_INIT(dir->dirh_handle, device, volume, inode);
97 /* Always re-read for a new dirhandle */
98 dir->dirh_cacheCheck = SalvageCacheCheck++;
101 void
102 FidZap(DirHandle * file)
104 IH_RELEASE(file->dirh_handle);
105 memset(file, 0, sizeof(DirHandle));
108 void
109 FidZero(DirHandle * file)
111 memset(file, 0, sizeof(DirHandle));
115 FidEq(DirHandle * afile, DirHandle * bfile)
117 if (afile->dirh_volume != bfile->dirh_volume)
118 return 0;
119 if (afile->dirh_device != bfile->dirh_device)
120 return 0;
121 if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck)
122 return 0;
123 if (afile->dirh_inode != bfile->dirh_inode)
124 return 0;
125 return 1;
129 FidVolEq(DirHandle * afile, afs_int32 vid)
131 if (afile->dirh_volume != vid)
132 return 0;
133 return 1;
136 void
137 FidCpy(DirHandle * tofile, DirHandle * fromfile)
139 *tofile = *fromfile;
140 IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
143 void
144 Die(const char *msg)
146 printf("%s\n", msg);
147 osi_Panic("%s\n", msg);