salvager: do not redefine SalvageVolumeGroup
[openafs.git] / src / vol / 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 /*
11         System:         VICE-TWO
12         Module:         physio.c
13         Institution:    The Information Technology Center, Carnegie-Mellon University
14
15  */
16
17 #include <afsconfig.h>
18 #include <afs/param.h>
19
20 #include <roken.h>
21
22 #include <assert.h>
23
24 #ifdef HAVE_SYS_FILE_H
25 #include <sys/file.h>
26 #endif
27
28 #include <rx/xdr.h>
29 #include <afs/afsint.h>
30 #include <errno.h>
31 #include <afs/afssyscalls.h>
32 #include "nfs.h"
33 #include "ihandle.h"
34 #include "salvage.h"
35 #include <afs/dir.h>
36 #include "vol_internal.h"
37
38 /* returns 0 on success, errno on failure */
39 int
40 ReallyRead(DirHandle * file, int block, char *data)
41 {
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;
50     }
51     nBytes = FDH_PREAD(fdP, data, (afs_fsize_t) AFS_PAGESIZE,
52                        ((afs_foff_t)block) * AFS_PAGESIZE);
53     if (nBytes != AFS_PAGESIZE) {
54         if (nBytes < 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
67 ReallyWrite(DirHandle * file, int block, char *data)
68 {
69     FdHandle_t *fdP;
70     int code;
71     ssize_t nBytes;
72
73     errno = 0;
74
75     fdP = IH_OPEN(file->dirh_handle);
76     if (fdP == NULL) {
77         code = errno;
78         return code;
79     }
80     nBytes = FDH_PWRITE(fdP, data, (afs_fsize_t) AFS_PAGESIZE,
81                         ((afs_foff_t)block) * AFS_PAGESIZE);
82     if (nBytes != AFS_PAGESIZE) {
83         if (nBytes < 0)
84             code = errno;
85         else
86             code = EIO;
87         FDH_REALLYCLOSE(fdP);
88         return code;
89     }
90     FDH_CLOSE(fdP);
91     *(file->volumeChanged) = 1;
92     return 0;
93 }
94
95 /* SetSalvageDirHandle:
96  * Create a handle to a directory entry and reference it (IH_INIT).
97  * The handle needs to be dereferenced with the FidZap() routine.
98  */
99 void
100 SetSalvageDirHandle(DirHandle * dir, afs_int32 volume, Device device,
101                     Inode inode, int *volumeChanged)
102 {
103     static int SalvageCacheCheck = 1;
104     memset(dir, 0, sizeof(DirHandle));
105
106     dir->dirh_device = device;
107     dir->dirh_volume = volume;
108     dir->dirh_inode = inode;
109     IH_INIT(dir->dirh_handle, device, volume, inode);
110     /* Always re-read for a new dirhandle */
111     dir->dirh_cacheCheck = SalvageCacheCheck++;
112     dir->volumeChanged = volumeChanged;
113 }
114
115 void
116 FidZap(DirHandle * file)
117 {
118     IH_RELEASE(file->dirh_handle);
119     memset(file, 0, sizeof(DirHandle));
120 }
121
122 void
123 FidZero(DirHandle * file)
124 {
125     memset(file, 0, sizeof(DirHandle));
126 }
127
128 int
129 FidEq(DirHandle * afile, DirHandle * bfile)
130 {
131     if (afile->dirh_volume != bfile->dirh_volume)
132         return 0;
133     if (afile->dirh_device != bfile->dirh_device)
134         return 0;
135     if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck)
136         return 0;
137     if (afile->dirh_inode != bfile->dirh_inode)
138         return 0;
139     return 1;
140 }
141
142 int
143 FidVolEq(DirHandle * afile, afs_int32 vid)
144 {
145     if (afile->dirh_volume != vid)
146         return 0;
147     return 1;
148 }
149
150 void
151 FidCpy(DirHandle * tofile, DirHandle * fromfile)
152 {
153     *tofile = *fromfile;
154     IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
155 }
156
157 void
158 Die(char *msg)
159 {
160     printf("%s\n", msg);
161     osi_Panic("%s\n", msg);
162 }