Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / volser / physio.c
blobe431a364952cdab7ceddf48caf814771035e62af
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>
14 #include <sys/types.h>
15 #ifdef AFS_NT40_ENV
16 #include <fcntl.h>
17 #else
18 #include <sys/file.h>
19 #include <netinet/in.h>
20 #include <unistd.h>
21 #endif
22 #include <string.h>
23 #ifdef AFS_SUN5_ENV
24 #include <sys/fcntl.h>
25 #endif
26 #include <errno.h>
27 #include <rx/xdr.h>
28 #include <rx/rx.h>
29 #include <stdio.h>
30 #include <afs/afsint.h>
31 #include <afs/nfs.h>
32 #include <afs/afs_assert.h>
33 #include <afs/dir.h>
34 #include <afs/ihandle.h>
35 #include "vol.h"
36 #include "physio.h"
38 /* returns 0 on success, errno on failure */
39 int
40 ReallyRead(DirHandle * file, int block, char *data)
42 FdHandle_t *fdP;
43 int code;
44 ssize_t nBytes;
45 errno = 0;
46 fdP = IH_OPEN(file->dirh_handle);
47 if (fdP == NULL) {
48 code = errno;
49 return code;
51 nBytes = FDH_PREAD(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE);
52 if (nBytes != AFS_PAGESIZE) {
53 if (nBytes < 0)
54 code = errno;
55 else
56 code = EIO;
57 FDH_REALLYCLOSE(fdP);
58 return code;
60 FDH_CLOSE(fdP);
61 return 0;
64 /* returns 0 on success, errno on failure */
65 int
66 ReallyWrite(DirHandle * file, int block, char *data)
68 FdHandle_t *fdP;
69 extern int VolumeChanged;
70 int code;
71 ssize_t nBytes;
73 errno = 0;
75 fdP = IH_OPEN(file->dirh_handle);
76 if (fdP == NULL) {
77 code = errno;
78 return code;
80 nBytes = FDH_PWRITE(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE);
81 if (nBytes != AFS_PAGESIZE) {
82 if (nBytes < 0)
83 code = errno;
84 else
85 code = EIO;
86 FDH_REALLYCLOSE(fdP);
87 return code;
89 FDH_CLOSE(fdP);
90 VolumeChanged = 1;
91 return 0;
94 /* SetSalvageDirHandle:
95 * Create a handle to a directory entry and reference it (IH_INIT).
96 * The handle needs to be dereferenced with the FidZap() routine.
98 void
99 SetSalvageDirHandle(DirHandle * dir, afs_uint32 volume, afs_int32 device,
100 Inode inode)
102 private int SalvageCacheCheck = 1;
103 memset(dir, 0, sizeof(DirHandle));
105 dir->dirh_volume = volume;
106 dir->dirh_device = device;
107 dir->dirh_inode = inode;
108 IH_INIT(dir->dirh_handle, device, volume, inode);
110 /* Always re-read for a new dirhandle */
111 dir->dirh_cacheCheck = SalvageCacheCheck++;
114 void
115 FidZap(DirHandle * file)
117 IH_RELEASE(file->dirh_handle);
118 memset(file, 0, sizeof(DirHandle));
121 void
122 FidZero(DirHandle * file)
124 memset(file, 0, sizeof(DirHandle));
128 FidEq(DirHandle * afile, DirHandle * bfile)
130 if (afile->dirh_volume != bfile->dirh_volume)
131 return 0;
132 if (afile->dirh_device != bfile->dirh_device)
133 return 0;
134 if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck)
135 return 0;
136 if (afile->dirh_inode != bfile->dirh_inode)
137 return 0;
138 return 1;
142 FidVolEq(DirHandle * afile, afs_int32 vid)
144 if (afile->dirh_volume != vid)
145 return 0;
146 return 1;
149 void
150 FidCpy(DirHandle * tofile, DirHandle * fromfile)
152 *tofile = *fromfile;
153 IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
156 void
157 Die(char *msg)
159 printf("%s\n", msg);
160 osi_Panic("%s\n", msg);