2 * Copyright 2000, International Business Machines Corporation and others.
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
13 Institution: The Information Technology Center, Carnegie-Mellon University
17 #include <afsconfig.h>
18 #include <afs/param.h>
23 #include <sys/types.h>
38 #include <sys/fcntl.h>
42 #include <afs/afsint.h>
44 #include <afs/afssyscalls.h>
48 #include "afs/assert.h"
51 /* returns 0 on success, errno on failure */
52 int ReallyRead(DirHandle *file, int block, char *data)
57 fdP = IH_OPEN(file->dirh_handle);
62 if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) {
67 code = FDH_READ(fdP, data, AFS_PAGESIZE);
68 if (code != AFS_PAGESIZE) {
80 /* returns 0 on success, errno on failure */
81 int ReallyWrite(DirHandle *file, int block, char *data)
84 extern int VolumeChanged;
89 fdP = IH_OPEN(file->dirh_handle);
94 if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) {
99 code = FDH_WRITE(fdP, data, AFS_PAGESIZE);
100 if (code != AFS_PAGESIZE) {
105 FDH_REALLYCLOSE(fdP);
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.
117 void SetSalvageDirHandle(DirHandle *dir, afs_int32 volume, Device device,
120 static SalvageCacheCheck = 1;
121 memset(dir, 0, sizeof(DirHandle));
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++;
131 void FidZap(DirHandle *file)
134 IH_RELEASE(file->dirh_handle);
135 memset(file, 0, sizeof(DirHandle));
138 void FidZero(DirHandle *file)
140 memset(file, 0, sizeof(DirHandle));
143 int FidEq(DirHandle *afile, DirHandle *bfile)
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;
152 int FidVolEq(DirHandle *afile, afs_int32 vid)
154 if (afile->dirh_volume != vid) return 0;
158 void FidCpy(DirHandle *tofile, DirHandle *fromfile)
161 IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);