revert-large-file-support-20030328
[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 RCSID("$Header$");
21
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <errno.h>
25 #ifdef AFS_NT40_ENV
26 #include <fcntl.h>
27 #else
28 #include <sys/file.h>
29 #include <unistd.h>
30 #ifdef HAVE_STRING_H
31 #include <string.h>
32 #else
33 #ifdef HAVE_STRINGS_H
34 #include <strings.h>
35 #endif
36 #endif
37 #ifdef  AFS_SUN5_ENV
38 #include <sys/fcntl.h>
39 #endif
40 #endif
41 #include <rx/xdr.h>
42 #include <afs/afsint.h>
43 #include <errno.h>
44 #include <afs/afssyscalls.h>
45 #include "ihandle.h"
46 #include "nfs.h"
47 #include "salvage.h"
48 #include "afs/assert.h"
49 #include "afs/dir.h"
50
51 /* returns 0 on success, errno on failure */
52 int ReallyRead(DirHandle *file, int block, char *data)
53 {
54     FdHandle_t *fdP;
55     int code;
56     errno = 0;
57     fdP = IH_OPEN(file->dirh_handle);
58     if (fdP == NULL) {
59         code = errno;
60         return code;
61     }
62     if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) {
63         code = errno;
64         FDH_REALLYCLOSE(fdP);
65         return code;
66     }
67     code = FDH_READ(fdP, data, AFS_PAGESIZE);
68     if (code != AFS_PAGESIZE) {
69         if (code < 0)
70             code = errno;
71         else 
72             code = EIO;
73         FDH_REALLYCLOSE(fdP);
74         return code;
75     }
76     FDH_CLOSE(fdP);
77     return 0;
78 }
79
80 /* returns 0 on success, errno on failure */
81 int ReallyWrite(DirHandle *file, int block, char *data)
82 {
83     FdHandle_t *fdP;
84     extern int VolumeChanged;
85     int code;
86
87     errno = 0;
88
89     fdP = IH_OPEN(file->dirh_handle);
90     if (fdP == NULL) {
91         code = errno;
92         return code;
93     }
94     if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) {
95         code = errno;
96         FDH_REALLYCLOSE(fdP);
97         return code;
98     }
99     code = FDH_WRITE(fdP, data, AFS_PAGESIZE);
100     if (code != AFS_PAGESIZE) {
101         if (code < 0)
102             code = errno;
103         else 
104             code = EIO;
105         FDH_REALLYCLOSE(fdP);
106         return code;
107     }
108     FDH_CLOSE(fdP);
109     VolumeChanged = 1;
110     return 0;
111 }
112
113 /* SetSalvageDirHandle:
114  * Create a handle to a directory entry and reference it (IH_INIT).
115  * The handle needs to be dereferenced with the FidZap() routine.
116  */
117 void SetSalvageDirHandle(DirHandle *dir, afs_int32 volume, Device device,
118                          Inode inode)
119 {
120     static SalvageCacheCheck = 1;
121     memset(dir, 0, sizeof(DirHandle));
122
123     dir->dirh_device = device;
124     dir->dirh_volume = volume;
125     dir->dirh_inode = inode;
126     IH_INIT(dir->dirh_handle, device, volume,  inode);
127     /* Always re-read for a new dirhandle */
128     dir->dirh_cacheCheck = SalvageCacheCheck++;
129 }
130
131 void FidZap(DirHandle *file)
132
133 {
134     IH_RELEASE(file->dirh_handle);
135     memset(file, 0, sizeof(DirHandle));
136 }
137
138 void FidZero(DirHandle *file)
139 {
140     memset(file, 0, sizeof(DirHandle));
141 }
142
143 int FidEq(DirHandle *afile, DirHandle *bfile)
144 {
145     if (afile->dirh_volume != bfile->dirh_volume) return 0;
146     if (afile->dirh_device != bfile->dirh_device) return 0;
147     if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck) return 0;
148     if (afile->dirh_inode != bfile->dirh_inode) return 0;
149     return 1;
150 }
151
152 int FidVolEq(DirHandle *afile, afs_int32 vid)
153 {
154     if (afile->dirh_volume != vid) return 0;
155     return 1;
156 }
157
158 void FidCpy(DirHandle *tofile, DirHandle *fromfile)
159 {
160     *tofile = *fromfile;
161     IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
162 }
163
164 void Die(char *msg)
165 {
166     printf("%s\n",msg);
167     assert(1==2);
168 }
169