2000-11-04 10:01:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2000, International Business Machines Corporation and others.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This software has been released under the terms of the IBM Public
|
|
|
|
* License. For details, see the LICENSE file in the top-level source
|
|
|
|
* directory or online at http://www.openafs.org/dl/license10.html
|
|
|
|
*/
|
2000-11-04 02:13:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
System: VICE-TWO
|
|
|
|
Module: physio.c
|
|
|
|
Institution: The Information Technology Center, Carnegie-Mellon University
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2001-07-05 17:20:00 +01:00
|
|
|
#include <afsconfig.h>
|
2001-07-12 21:58:15 +01:00
|
|
|
#include <afs/param.h>
|
2001-07-05 17:20:00 +01:00
|
|
|
|
2003-07-16 01:28:24 +01:00
|
|
|
RCSID
|
|
|
|
("$Header$");
|
2001-07-05 17:20:00 +01:00
|
|
|
|
2000-11-04 02:13:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef AFS_NT40_ENV
|
|
|
|
#include <fcntl.h>
|
|
|
|
#else
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <unistd.h>
|
2002-08-21 20:52:17 +01:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
2000-11-04 02:13:13 +00:00
|
|
|
#ifdef AFS_SUN5_ENV
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#include <rx/xdr.h>
|
|
|
|
#include <afs/afsint.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <afs/afssyscalls.h>
|
|
|
|
#include "nfs.h"
|
2003-06-02 16:35:59 +01:00
|
|
|
#include "ihandle.h"
|
2000-11-04 02:13:13 +00:00
|
|
|
#include "salvage.h"
|
|
|
|
#include "afs/assert.h"
|
|
|
|
#include "afs/dir.h"
|
|
|
|
|
|
|
|
/* returns 0 on success, errno on failure */
|
2003-07-16 01:28:24 +01:00
|
|
|
int
|
|
|
|
ReallyRead(DirHandle * file, int block, char *data)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
|
|
|
FdHandle_t *fdP;
|
|
|
|
int code;
|
|
|
|
errno = 0;
|
|
|
|
fdP = IH_OPEN(file->dirh_handle);
|
|
|
|
if (fdP == NULL) {
|
|
|
|
code = errno;
|
|
|
|
return code;
|
|
|
|
}
|
2003-07-16 01:28:24 +01:00
|
|
|
if (FDH_SEEK(fdP, block * AFS_PAGESIZE, SEEK_SET) < 0) {
|
2000-11-04 02:13:13 +00:00
|
|
|
code = errno;
|
|
|
|
FDH_REALLYCLOSE(fdP);
|
|
|
|
return code;
|
|
|
|
}
|
2003-08-08 22:40:42 +01:00
|
|
|
code = FDH_READ(fdP, data, (afs_fsize_t) AFS_PAGESIZE);
|
2000-11-04 02:13:13 +00:00
|
|
|
if (code != AFS_PAGESIZE) {
|
|
|
|
if (code < 0)
|
|
|
|
code = errno;
|
2003-07-16 01:28:24 +01:00
|
|
|
else
|
2000-11-04 02:13:13 +00:00
|
|
|
code = EIO;
|
|
|
|
FDH_REALLYCLOSE(fdP);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
FDH_CLOSE(fdP);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns 0 on success, errno on failure */
|
2003-07-16 01:28:24 +01:00
|
|
|
int
|
|
|
|
ReallyWrite(DirHandle * file, int block, char *data)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
|
|
|
FdHandle_t *fdP;
|
|
|
|
extern int VolumeChanged;
|
|
|
|
int code;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
fdP = IH_OPEN(file->dirh_handle);
|
|
|
|
if (fdP == NULL) {
|
|
|
|
code = errno;
|
|
|
|
return code;
|
|
|
|
}
|
2003-07-16 01:28:24 +01:00
|
|
|
if (FDH_SEEK(fdP, block * AFS_PAGESIZE, SEEK_SET) < 0) {
|
2000-11-04 02:13:13 +00:00
|
|
|
code = errno;
|
|
|
|
FDH_REALLYCLOSE(fdP);
|
|
|
|
return code;
|
|
|
|
}
|
2003-08-08 22:40:42 +01:00
|
|
|
code = FDH_WRITE(fdP, data, (afs_fsize_t) AFS_PAGESIZE);
|
2000-11-04 02:13:13 +00:00
|
|
|
if (code != AFS_PAGESIZE) {
|
|
|
|
if (code < 0)
|
|
|
|
code = errno;
|
2003-07-16 01:28:24 +01:00
|
|
|
else
|
2000-11-04 02:13:13 +00:00
|
|
|
code = EIO;
|
|
|
|
FDH_REALLYCLOSE(fdP);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
FDH_CLOSE(fdP);
|
|
|
|
VolumeChanged = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SetSalvageDirHandle:
|
|
|
|
* Create a handle to a directory entry and reference it (IH_INIT).
|
|
|
|
* The handle needs to be dereferenced with the FidZap() routine.
|
|
|
|
*/
|
2003-07-16 01:28:24 +01:00
|
|
|
void
|
|
|
|
SetSalvageDirHandle(DirHandle * dir, afs_int32 volume, Device device,
|
|
|
|
Inode inode)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
|
|
|
static SalvageCacheCheck = 1;
|
convert-from-bsd-to-posix-string-and-memory-functions-20010807
bcopy, bcmp, bzero, index, rindex, you're all cut.
memcpy, memcmp, memset, strchr, strrchr, show us how it's done
====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================
fix reference to memset the right thing
====================
make change to arguments globally and not just for e.g. linux/darwin/fbsd
====================
fix a minor flub in how this was done
====================
correct another bad memcpy coversion
====================
fix up more inadvertant turds
====================
fix two errors found by chas williams
2001-08-08 04:05:55 +01:00
|
|
|
memset(dir, 0, sizeof(DirHandle));
|
2000-11-04 02:13:13 +00:00
|
|
|
|
|
|
|
dir->dirh_device = device;
|
|
|
|
dir->dirh_volume = volume;
|
|
|
|
dir->dirh_inode = inode;
|
2003-07-16 01:28:24 +01:00
|
|
|
IH_INIT(dir->dirh_handle, device, volume, inode);
|
2000-11-04 02:13:13 +00:00
|
|
|
/* Always re-read for a new dirhandle */
|
|
|
|
dir->dirh_cacheCheck = SalvageCacheCheck++;
|
|
|
|
}
|
|
|
|
|
2003-07-16 01:28:24 +01:00
|
|
|
void
|
|
|
|
FidZap(DirHandle * file)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
|
|
|
IH_RELEASE(file->dirh_handle);
|
convert-from-bsd-to-posix-string-and-memory-functions-20010807
bcopy, bcmp, bzero, index, rindex, you're all cut.
memcpy, memcmp, memset, strchr, strrchr, show us how it's done
====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================
fix reference to memset the right thing
====================
make change to arguments globally and not just for e.g. linux/darwin/fbsd
====================
fix a minor flub in how this was done
====================
correct another bad memcpy coversion
====================
fix up more inadvertant turds
====================
fix two errors found by chas williams
2001-08-08 04:05:55 +01:00
|
|
|
memset(file, 0, sizeof(DirHandle));
|
2000-11-04 02:13:13 +00:00
|
|
|
}
|
|
|
|
|
2003-07-16 01:28:24 +01:00
|
|
|
void
|
|
|
|
FidZero(DirHandle * file)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
convert-from-bsd-to-posix-string-and-memory-functions-20010807
bcopy, bcmp, bzero, index, rindex, you're all cut.
memcpy, memcmp, memset, strchr, strrchr, show us how it's done
====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================
fix reference to memset the right thing
====================
make change to arguments globally and not just for e.g. linux/darwin/fbsd
====================
fix a minor flub in how this was done
====================
correct another bad memcpy coversion
====================
fix up more inadvertant turds
====================
fix two errors found by chas williams
2001-08-08 04:05:55 +01:00
|
|
|
memset(file, 0, sizeof(DirHandle));
|
2000-11-04 02:13:13 +00:00
|
|
|
}
|
|
|
|
|
2003-07-16 01:28:24 +01:00
|
|
|
int
|
|
|
|
FidEq(DirHandle * afile, DirHandle * bfile)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
2003-07-16 01:28:24 +01:00
|
|
|
if (afile->dirh_volume != bfile->dirh_volume)
|
|
|
|
return 0;
|
|
|
|
if (afile->dirh_device != bfile->dirh_device)
|
|
|
|
return 0;
|
|
|
|
if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck)
|
|
|
|
return 0;
|
|
|
|
if (afile->dirh_inode != bfile->dirh_inode)
|
|
|
|
return 0;
|
2000-11-04 02:13:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-07-16 01:28:24 +01:00
|
|
|
int
|
|
|
|
FidVolEq(DirHandle * afile, afs_int32 vid)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
2003-07-16 01:28:24 +01:00
|
|
|
if (afile->dirh_volume != vid)
|
|
|
|
return 0;
|
2000-11-04 02:13:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-07-16 01:28:24 +01:00
|
|
|
void
|
|
|
|
FidCpy(DirHandle * tofile, DirHandle * fromfile)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
|
|
|
*tofile = *fromfile;
|
|
|
|
IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
|
|
|
|
}
|
|
|
|
|
2003-07-16 01:28:24 +01:00
|
|
|
void
|
|
|
|
Die(char *msg)
|
2000-11-04 02:13:13 +00:00
|
|
|
{
|
2003-07-16 01:28:24 +01:00
|
|
|
printf("%s\n", msg);
|
|
|
|
assert(1 == 2);
|
2000-11-04 02:13:13 +00:00
|
|
|
}
|