getrlimit \
issetugid \
mkstemp \
+ pread \
+ preadv \
+ pwrite \
+ pwritev \
regcomp \
regerror \
regexec \
vsyslog \
])
+AC_MSG_CHECKING([for positional I/O])
+if test "$ac_cv_func_pread" = "yes" && \
+ test "$ac_cv_func_pwrite" = "yes"; then
+ AC_DEFINE(HAVE_PIO, 1, [define if you have pread() and pwrite()])
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+fi
+AC_MSG_CHECKING([for vectored positional I/O])
+if test "$ac_cv_func_preadv" = "yes" && \
+ test "$ac_cv_func_pwritev" = "yes"; then
+ AC_DEFINE(HAVE_PIOV, 1, [define if you have preadv() and pwritev()])
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+fi
+
AC_MSG_CHECKING([for POSIX regex library])
if test "$ac_cv_header_regex_h" = "yes" && \
test "$ac_cv_func_regcomp" = "yes" && \
ssize_t rdlen;
ssize_t wrlen;
afs_fsize_t size;
+ afs_foff_t done;
size_t length;
char *buff;
int rc; /* return code */
newFdP = IH_OPEN(newH);
assert(newFdP != NULL);
- FDH_SEEK(targFdP, off, SEEK_SET);
- FDH_SEEK(newFdP, off, SEEK_SET);
+ done = off;
while (size > 0) {
if (size > COPYBUFFSIZE) { /* more than a buffer */
length = COPYBUFFSIZE;
length = size;
size = 0;
}
- rdlen = FDH_READ(targFdP, buff, length);
- if (rdlen == length)
- wrlen = FDH_WRITE(newFdP, buff, length);
- else
+ rdlen = FDH_PREAD(targFdP, buff, length, done);
+ if (rdlen == length) {
+ wrlen = FDH_PWRITE(newFdP, buff, length, done);
+ done += rdlen;
+ } else
wrlen = 0;
/* Callers of this function are not prepared to recover
* from error that put the filesystem in an inconsistent
ssize_t rdlen;
ssize_t wrlen;
int rc = 0;
-
- FDH_SEEK(targFdP, off, SEEK_SET);
- FDH_SEEK(newFdP, off, SEEK_SET);
+ afs_foff_t done = off;
if (size > FDH_SIZE(targFdP) - off)
size = FDH_SIZE(targFdP) - off;
length = size;
size = 0;
}
- rdlen = FDH_READ(targFdP, buff, length);
- if (rdlen == length)
- wrlen = FDH_WRITE(newFdP, buff, length);
+ rdlen = FDH_PREAD(targFdP, buff, length, done);
+ if (rdlen == length) {
+ wrlen = FDH_PWRITE(newFdP, buff, length, done);
+ done += rdlen;
+ }
else
wrlen = 0;
return code;
}
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
static struct afs_buffer {
struct afs_buffer *next;
} *freeBufferList = 0;
static int afs_buffersAlloced = 0;
-static
+static int
FreeSendBuffer(struct afs_buffer *adata)
{
FS_LOCK;
/* allocate space for sender */
static char *
-AllocSendBuffer()
+AllocSendBuffer(void)
{
struct afs_buffer *tp;
return (char *)tp;
} /*AllocSendBuffer */
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
/*
* This routine returns the status info associated with the targetptr vnode
return EIO;
}
len = strlen((char *) LinkContents);
- code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
+ code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
if (code)
- ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
+ ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
FDH_CLOSE(fdP);
/*
* Set up and return modified status for the parent dir and new symlink
struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
IHandle_t *ihP;
FdHandle_t *fdP;
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
char *tbuffer;
-#else /* AFS_NT40_ENV */
+#else /* HAVE_PIOV */
struct iovec tiov[RX_MAXIOVECS];
int tnio;
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
afs_sfsize_t tlen;
afs_int32 optSize;
if (Pos + Len > tlen) /* get length we should send */
Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
- (void)FDH_SEEK(fdP, Pos, 0);
{
afs_int32 high, low;
SplitOffsetOrSize(Len, high, low);
#if FS_STATS_DETAILED
(*a_bytesToFetchP) = Len;
#endif /* FS_STATS_DETAILED */
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
tbuffer = AllocSendBuffer();
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
while (Len > 0) {
size_t wlen;
ssize_t nBytes;
wlen = optSize;
else
wlen = Len;
-#ifdef AFS_NT40_ENV
- nBytes = FDH_READ(fdP, tbuffer, wlen);
+#ifndef HAVE_PIOV
+ nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
if (nBytes != wlen) {
FDH_CLOSE(fdP);
FreeSendBuffer((struct afs_buffer *)tbuffer);
return EIO;
}
nBytes = rx_Write(Call, tbuffer, wlen);
-#else /* AFS_NT40_ENV */
+#else /* HAVE_PIOV */
nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
if (nBytes <= 0) {
FDH_CLOSE(fdP);
return EIO;
}
wlen = nBytes;
- nBytes = FDH_READV(fdP, tiov, tnio);
+ nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
if (nBytes != wlen) {
FDH_CLOSE(fdP);
VTakeOffline(volptr);
return EIO;
}
nBytes = rx_Writev(Call, tiov, tnio, wlen);
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
+ Pos += wlen;
#if FS_STATS_DETAILED
/*
* Bump the number of bytes actually sent by the number from this
#endif /* FS_STATS_DETAILED */
if (nBytes != wlen) {
FDH_CLOSE(fdP);
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
FreeSendBuffer((struct afs_buffer *)tbuffer);
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
return -31;
}
Len -= wlen;
}
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
FreeSendBuffer((struct afs_buffer *)tbuffer);
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
FDH_CLOSE(fdP);
FT_GetTimeOfDay(&StopTime, 0);
afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
Error errorCode = 0; /* Returned error code to caller */
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
char *tbuffer; /* data copying buffer */
-#else /* AFS_NT40_ENV */
+#else /* HAVE_PIOV */
struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
int tnio; /* temp for iovec size */
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
afs_sfsize_t tlen; /* temp for xfr length */
Inode tinode; /* inode for I/O */
afs_int32 optSize; /* optimal transfer size */
/* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
if (FileLength < DataLength)
FDH_TRUNC(fdP, FileLength);
- if (Pos > 0)
- FDH_SEEK(fdP, Pos, 0);
bytesTransfered = 0;
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
tbuffer = AllocSendBuffer();
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
/* if length == 0, the loop below isn't going to do anything, including
* extend the length of the inode, which it must do, since the file system
* assumes that the inode length == vnode's file length. So, we extend
/* Set the file's length; we've already done an lseek to the right
* spot above.
*/
- nBytes = FDH_WRITE(fdP, &tlen, 1);
+ nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
if (nBytes != 1) {
errorCode = -1;
goto done;
rlen = optSize; /* bound by buffer size */
else
rlen = (int)tlen;
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
errorCode = rx_Read(Call, tbuffer, rlen);
-#else /* AFS_NT40_ENV */
+#else /* HAVE_PIOV */
errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
if (errorCode <= 0) {
errorCode = -32;
break;
(*a_bytesStoredP) += errorCode;
#endif /* FS_STATS_DETAILED */
rlen = errorCode;
-#ifdef AFS_NT40_ENV
- nBytes = FDH_WRITE(fdP, tbuffer, rlen);
-#else /* AFS_NT40_ENV */
- nBytes = FDH_WRITEV(fdP, tiov, tnio);
-#endif /* AFS_NT40_ENV */
+#ifndef HAVE_PIOV
+ nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
+#else /* HAVE_PIOV */
+ nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
+#endif /* HAVE_PIOV */
if (nBytes != rlen) {
errorCode = VDISKFULL;
break;
}
bytesTransfered += rlen;
+ Pos += rlen;
}
}
done:
-#ifdef AFS_NT40_ENV
+#ifndef HAVE_PIOV
FreeSendBuffer((struct afs_buffer *)tbuffer);
-#endif /* AFS_NT40_ENV */
+#endif /* HAVE_PIOV */
if (sync) {
FDH_SYNC(fdP);
}
ih_ino), code));
return code;
}
- if (FDH_SEEK(fdP, block * PAGESIZE, SEEK_SET) < 0) {
- code = errno;
- ViceLog(0,
- ("ReallyRead(): lseek failed device %X inode %s errno %d\n",
- file->dirh_handle->ih_dev, PrintInode(NULL,
- file->dirh_handle->
- ih_ino), code));
- FDH_REALLYCLOSE(fdP);
- return code;
- }
- rdlen = FDH_READ(fdP, data, PAGESIZE);
+ rdlen = FDH_PREAD(fdP, data, PAGESIZE, ((afs_foff_t)block) * PAGESIZE);
if (rdlen != PAGESIZE) {
if (rdlen < 0)
code = errno;
lpErrno = errno;
return 0;
}
- if (FDH_SEEK(fdP, block * PAGESIZE, SEEK_SET) < 0) {
- ViceLog(0,
- ("ReallyWrite(): lseek failed device %X inode %s errno %d\n",
- file->dirh_handle->ih_dev, PrintInode(NULL,
- file->dirh_handle->
- ih_ino), errno));
- lpErrno = errno;
- FDH_REALLYCLOSE(fdP);
- return 0;
- }
- if ((count = FDH_WRITE(fdP, data, PAGESIZE)) != PAGESIZE) {
+ if ((count = FDH_PWRITE(fdP, data, PAGESIZE, ((afs_foff_t)block) * PAGESIZE)) != PAGESIZE) {
ViceLog(0,
("ReallyWrite(): write failed device %X inode %s errno %d\n",
file->dirh_handle->ih_dev, PrintInode(stmp,
rwfile = FDH_FDOPEN(rwFd, ReadWriteOriginal ? "r+" : "r");
if (!rwfile)
ERROR_EXIT(EIO);
- STREAM_SEEK(rwfile, vcp->diskSize, 0); /* Will fail if no vnodes */
+ STREAM_ASEEK(rwfile, vcp->diskSize); /* Will fail if no vnodes */
/* Open the clone volume's index file and seek to beginning */
IH_COPY(clHout, clvp->vnodeIndex[class].handle);
clfileout = FDH_FDOPEN(clFdOut, "a");
if (!clfileout)
ERROR_EXIT(EIO);
- code = STREAM_SEEK(clfileout, vcp->diskSize, 0);
+ code = STREAM_ASEEK(clfileout, vcp->diskSize);
if (code)
ERROR_EXIT(EIO);
clfilein = FDH_FDOPEN(clFdIn, "r");
if (!clfilein)
ERROR_EXIT(EIO);
- STREAM_SEEK(clfilein, vcp->diskSize, 0); /* Will fail if no vnodes */
+ STREAM_ASEEK(clfilein, vcp->diskSize); /* Will fail if no vnodes */
}
/* Initialize list of inodes to nuke */
rwvnode->dataVersion++;
#endif /* DVINC */
rwvnode->cloned = 1;
- code = STREAM_SEEK(rwfile, offset, 0);
+ code = STREAM_ASEEK(rwfile, offset);
if (code == -1)
goto clonefailed;
code = STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile);
if (code != 1)
goto clonefailed;
dircloned = 1;
- code = STREAM_SEEK(rwfile, offset + vcp->diskSize, 0);
+ code = STREAM_ASEEK(rwfile, offset + vcp->diskSize);
if (code == -1)
goto clonefailed;
#ifdef DVINC
/* And if the directory was marked clone, unmark it */
if (dircloned) {
rwvnode->cloned = 0;
- if (STREAM_SEEK(rwfile, offset, 0) != -1)
+ if (STREAM_ASEEK(rwfile, offset) != -1)
(void)STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile);
}
ERROR_EXIT(EIO);
/* Clean out any junk at end of clone file */
if (reclone) {
- STREAM_SEEK(clfilein, offset, 0);
+ STREAM_ASEEK(clfilein, offset);
while (STREAM_READ(clvnode, vcp->diskSize, 1, clfilein) == 1) {
if (clvnode->type != vNull && VNDISK_GET_INO(clvnode) != 0) {
ci_AddItem(&decHead, VNDISK_GET_INO(clvnode));
assert(fdP != NULL);
for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) {
fdP[i].fd_status = FD_HANDLE_AVAIL;
+ fdP[i].fd_refcnt = 0;
fdP[i].fd_ih = NULL;
fdP[i].fd_fd = INVALID_FD;
DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev);
/* Do we already have an open file handle for this Inode? */
for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) {
+#ifndef HAVE_PIO
+ /*
+ * If we don't have positional i/o, don't try to share fds, since
+ * we can't do so in a threadsafe way.
+ */
if (fdP->fd_status != FD_HANDLE_INUSE) {
assert(fdP->fd_status == FD_HANDLE_OPEN);
+#else /* HAVE_PIO */
+ if (fdP->fd_status != FD_HANDLE_AVAIL) {
+#endif /* HAVE_PIO */
+ fdP->fd_refcnt++;
+ if (fdP->fd_status == FD_HANDLE_OPEN) {
fdP->fd_status = FD_HANDLE_INUSE;
DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
+ }
ihP->ih_refcnt++;
IH_UNLOCK;
- (void)FDH_SEEK(fdP, 0, SEEK_SET);
return fdP;
}
}
fdP->fd_status = FD_HANDLE_INUSE;
fdP->fd_fd = fd;
fdP->fd_ih = ihP;
+ fdP->fd_refcnt++;
ihP->ih_refcnt++;
return fd_reallyclose(fdP);
}
+ fdP->fd_refcnt--;
+ if (fdP->fd_refcnt == 0) {
/* Put this descriptor back into the cache */
fdP->fd_status = FD_HANDLE_OPEN;
DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
+ }
/* If this is not the only reference to the Inode then we can decrement
* the reference count, otherwise we need to call ih_release.
ihP = fdP->fd_ih;
closeFd = fdP->fd_fd;
+ fdP->fd_refcnt--;
+ if (fdP->fd_refcnt == 0) {
DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
fdP->fd_status = FD_HANDLE_AVAIL;
+ fdP->fd_refcnt = 0;
fdP->fd_ih = NULL;
fdP->fd_fd = INVALID_FD;
+ }
/* All the file descriptor handles have been closed; reset
* the IH_REALLY_CLOSED flag indicating that ih_reallyclose
ihP->ih_flags &= ~IH_REALLY_CLOSED;
}
+ if (fdP->fd_refcnt == 0) {
IH_UNLOCK;
OS_CLOSE(closeFd);
IH_LOCK;
fdInUseCount -= 1;
+ }
/* If this is not the only reference to the Inode then we can decrement
* the reference count, otherwise we need to call ih_release. */
streamP->str_fd = fd;
streamP->str_buflen = 0;
streamP->str_bufoff = 0;
+ streamP->str_fdoff = 0;
streamP->str_error = 0;
streamP->str_eof = 0;
streamP->str_direction = STREAM_DIRECTION_NONE;
if (streamP->str_buflen == 0) {
streamP->str_bufoff = 0;
streamP->str_buflen =
- OS_READ(streamP->str_fd, streamP->str_buffer,
- STREAM_HANDLE_BUFSIZE);
+ OS_PREAD(streamP->str_fd, streamP->str_buffer,
+ STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
if (streamP->str_buflen < 0) {
streamP->str_error = errno;
streamP->str_buflen = 0;
streamP->str_eof = 1;
break;
}
+ streamP->str_fdoff += streamP->str_buflen;
}
bytesToRead = nbytes;
p = (char *)ptr;
while (nbytes > 0) {
if (streamP->str_buflen == 0) {
- rc = OS_WRITE(streamP->str_fd, streamP->str_buffer,
- STREAM_HANDLE_BUFSIZE);
+ rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
+ STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
if (rc < 0) {
streamP->str_error = errno;
bytesWritten = 0;
break;
}
+ streamP->str_fdoff += rc;
streamP->str_bufoff = 0;
streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
}
/* fseek for buffered I/O handles */
int
-stream_seek(StreamHandle_t * streamP, afs_foff_t offset, int whence)
+stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
{
ssize_t rc;
int retval = 0;
if (streamP->str_direction == STREAM_DIRECTION_WRITE
&& streamP->str_bufoff > 0) {
- rc = OS_WRITE(streamP->str_fd, streamP->str_buffer,
- streamP->str_bufoff);
+ rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
+ streamP->str_bufoff, streamP->str_fdoff);
if (rc < 0) {
streamP->str_error = errno;
retval = -1;
}
}
+ streamP->str_fdoff = offset;
streamP->str_bufoff = 0;
streamP->str_buflen = 0;
streamP->str_eof = 0;
streamP->str_direction = STREAM_DIRECTION_NONE;
- if (OS_SEEK(streamP->str_fd, offset, whence) < 0) {
- streamP->str_error = errno;
- retval = -1;
- }
return retval;
}
if (streamP->str_direction == STREAM_DIRECTION_WRITE
&& streamP->str_bufoff > 0) {
- rc = OS_WRITE(streamP->str_fd, streamP->str_buffer,
- streamP->str_bufoff);
+ rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
+ streamP->str_bufoff, streamP->str_fdoff);
if (rc < 0) {
streamP->str_error = errno;
retval = -1;
+ } else {
+ streamP->str_fdoff += rc;
}
streamP->str_bufoff = 0;
streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
assert(streamP != NULL);
if (streamP->str_direction == STREAM_DIRECTION_WRITE
&& streamP->str_bufoff > 0) {
- rc = OS_WRITE(streamP->str_fd, streamP->str_buffer,
- streamP->str_bufoff);
+ rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
+ streamP->str_bufoff, streamP->str_fdoff);
if (rc < 0) {
retval = -1;
+ } else {
+ streamP->str_fdoff += rc;
}
}
if (reallyClose) {
for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
OS_CLOSE(fdP->fd_fd);
fdP->fd_status = FD_HANDLE_AVAIL;
+ fdP->fd_refcnt = 0;
fdP->fd_fd = INVALID_FD;
fdP->fd_ih = NULL;
closeCount++;
return status.st_size;
}
#endif
+
+#ifndef HAVE_PIO
+ssize_t
+ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
+{
+ afs_foff_t code;
+ code = OS_SEEK(fd, offset, 0);
+ if (code < 0)
+ return code;
+ return OS_READ(fd, buf, count);
+}
+
+ssize_t
+ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
+{
+ afs_foff_t code;
+ code = OS_SEEK(fd, offset, 0);
+ if (code < 0)
+ return code;
+ return OS_WRITE(fd, buf, count);
+}
+#endif /* !HAVE_PIO */
/* file descriptor handle */
typedef struct FdHandle_s {
int fd_status; /* status flags */
+ int fd_refcnt; /* refcnt */
FD_t fd_fd; /* file descriptor */
struct IHandle_s *fd_ih; /* Pointer to Inode handle */
struct FdHandle_s *fd_next; /* LRU/Avail list pointers */
int str_direction; /* current read/write direction */
afs_sfsize_t str_buflen; /* bytes remaining in buffer */
afs_foff_t str_bufoff; /* current offset into buffer */
+ afs_foff_t str_fdoff; /* current offset into file */
int str_error; /* error code */
int str_eof; /* end of file flag */
struct StreamHandle_s *str_next; /* Avail list pointers */
extern afs_sfsize_t stream_write(void *ptr, afs_fsize_t size,
afs_fsize_t nitems,
StreamHandle_t * streamP);
-extern int stream_seek(StreamHandle_t * streamP, afs_foff_t offset,
- int whence);
+extern int stream_aseek(StreamHandle_t * streamP, afs_foff_t offset);
extern int stream_flush(StreamHandle_t * streamP);
extern int stream_close(StreamHandle_t * streamP, int reallyClose);
extern int ih_reallyclose(IHandle_t * ihP);
#define STREAM_WRITE(A, B, C, H) stream_write(A, B, C, H)
-#define STREAM_SEEK(H, A, B) stream_seek(H, A, B)
+#define STREAM_ASEEK(H, A) stream_aseek(H, A)
#define STREAM_FLUSH(H) stream_flush(H)
#define IH_CONDSYNC(H) ih_condsync(H)
+#ifdef HAVE_PIO
+#ifdef O_LARGEFILE
+#define OS_PREAD(FD, B, S, O) pread64(FD, B, S, O)
+#define OS_PWRITE(FD, B, S, O) pwrite64(FD, B, S, O)
+#else /* !O_LARGEFILE */
+#define OS_PREAD(FD, B, S, O) pread(FD, B, S, O)
+#define OS_PWRITE(FD, B, S, O) pwrite(FD, B, S, O)
+#endif /* !O_LARGEFILE */
+#else /* !HAVE_PIO */
+extern ssize_t ih_pread(int fd, void * buf, size_t count, afs_foff_t offset);
+extern ssize_t ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset);
+#define OS_PREAD(FD, B, S, O) ih_pread(FD, B, S, O)
+#define OS_PWRITE(FD, B, S, O) ih_pwrite(FD, B, S, O)
+#endif /* !HAVE_PIO */
+
#ifdef AFS_NAMEI_ENV
#ifdef AFS_NT40_ENV
extern int OS_CLOSE(int FD);
extern ssize_t OS_READ(int FD, void *B, size_t S);
extern ssize_t OS_WRITE(int FD, void *B, size_t S);
+extern ssize_t OS_PREAD(int FD, void *B, size_t S, afs_foff_t O);
+extern ssize_t OS_PWRITE(int FD, void *B, size_t S, afs_foff_t O);
extern int OS_SYNC(int FD);
extern afs_sfsize_t OS_SIZE(int FD);
extern int IH_INC(IHandle_t * H, Inode I, int /*@alt VolId, VolumeId @ */ P);
#define OS_OPEN(F, M, P) open(F, M, P)
#define OS_CLOSE(FD) close(FD)
-#define OS_READ(FD, B, S) read(FD, B, S)
-#define OS_WRITE(FD, B, S) write(FD, B, S)
#ifdef O_LARGEFILE
#define OS_SEEK(FD, O, F) lseek64(FD, (off64_t) (O), F)
#else /* !O_LARGEFILE */
#define FDH_WRITEV(H, I, N) writev((H)->fd_fd, I, N)
#endif
+#ifdef HAVE_PIOV
+#define FDH_PREADV(H, I, N, O) preadv((H)->fd_fd, I, N, O)
+#define FDH_PWRITEV(H, I, N, O) pwritev((H)->fd_fd, I, N, O)
+#endif
+
+#define FDH_PREAD(H, B, S, O) OS_PREAD((H)->fd_fd, B, S, O)
+#define FDH_PWRITE(H, B, S, O) OS_PWRITE((H)->fd_fd, B, S, O)
#define FDH_READ(H, B, S) OS_READ((H)->fd_fd, B, S)
#define FDH_WRITE(H, B, S) OS_WRITE((H)->fd_fd, B, S)
#define FDH_SEEK(H, O, F) OS_SEEK((H)->fd_fd, O, F)
#endif /* AFS_LINUX20_ENV */
static afs_int32
-convertVolumeInfo(int fdr, int fdw, afs_uint32 vid)
+convertVolumeInfo(FdHandle_t *fdhr, FdHandle_t *fdhw, afs_uint32 vid)
{
struct VolumeDiskData vd;
char *p;
- if (read(fdr, &vd, sizeof(struct VolumeDiskData)) !=
+ if (FDH_PREAD(fdhr, &vd, sizeof(struct VolumeDiskData), 0) !=
sizeof(struct VolumeDiskData)) {
Log("1 convertiVolumeInfo: read failed for %lu with code %d\n", vid,
errno);
memset(p, 0, 9);
}
- if (write(fdw, &vd, sizeof(struct VolumeDiskData)) !=
+ if (FDH_PWRITE(fdhw, &vd, sizeof(struct VolumeDiskData), 0) !=
sizeof(struct VolumeDiskData)) {
Log("1 convertiVolumeInfo: write failed for %lu with code %d\n", vid,
errno);
struct VolumeDiskHeader h;
IHandle_t *ih, *ih2;
FdHandle_t *fdP, *fdP2;
+ ssize_t offset;
char wpath[100];
char tmpDevName[100];
char buffer[128];
}
if (j == VI_VOLINFO)
- convertVolumeInfo(fdP->fd_fd, fdP2->fd_fd, ih2->ih_vid);
+ convertVolumeInfo(fdP, fdP2, ih2->ih_vid);
else {
+ offset = 0;
while (1) {
- len = read(fdP->fd_fd, buffer, sizeof(buffer));
+ len = FDH_PREAD(fdP, buffer, sizeof(buffer), offset);
if (len < 0)
return errno;
if (len == 0)
break;
- nBytes = write(fdP2->fd_fd, buffer, len);
+ nBytes = FDH_PWRITE(fdP2, buffer, len, offset);
if (nBytes != len) {
code = -1;
goto done;
}
+ offset += len;
}
}
/*@+fcnmacros +macrofcndecl@*/
#ifdef O_LARGEFILE
#ifdef S_SPLINT_S
-extern off64_t afs_lseek(int FD, off64_t O, int F);
#endif /*S_SPLINT_S */
-#define afs_lseek(FD, O, F) lseek64(FD, (off64_t)(O), F)
#define afs_stat stat64
#define afs_fstat fstat64
#define afs_open open64
#define afs_fopen fopen64
#else /* !O_LARGEFILE */
#ifdef S_SPLINT_S
-extern off_t afs_lseek(int FD, off_t O, int F);
#endif /*S_SPLINT_S */
-#define afs_lseek(FD, O, F) lseek(FD, (off_t)(O), F)
#define afs_stat stat
#define afs_fstat fstat
#define afs_open open
if (fdP == NULL)
return -1;
- if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) {
- FDH_REALLYCLOSE(fdP);
- return -1;
- }
-
- nBytes = FDH_READ(fdP, buf, size);
+ nBytes = FDH_PREAD(fdP, buf, size, offset);
FDH_CLOSE(fdP);
return nBytes;
}
if (fdP == NULL)
return -1;
- if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) {
- FDH_REALLYCLOSE(fdP);
- return -1;
- }
- nBytes = FDH_WRITE(fdP, buf, size);
+ nBytes = FDH_PWRITE(fdP, buf, size, offset);
FDH_CLOSE(fdP);
return nBytes;
}
namei_t name;
FdHandle_t *fdP;
struct afs_stat tstat;
+ afs_foff_t offset;
namei_HandleToName(&name, h);
if (afs_stat(name.n_path, &tstat) < 0)
return ENOMEM;
}
size = tstat.st_size;
- FDH_SEEK(fdP, 0, 0);
+ offset = 0;
while (size) {
tlen = size > 8192 ? 8192 : size;
- if (FDH_READ(fdP, buf, tlen) != tlen)
+ if (FDH_PREAD(fdP, buf, tlen, offset) != tlen)
break;
if (write(fd, buf, tlen) != tlen)
break;
size -= tlen;
+ offset += tlen;
}
close(fd);
FDH_REALLYCLOSE(fdP);
return -1;
}
- if (afs_lseek(h->fd_fd, offset, SEEK_SET) == -1)
- goto bad_getLinkByte;
-
- rc = read(h->fd_fd, (char *)&row, sizeof(row));
+ rc = FDH_PREAD(h, (char*)&row, sizeof(row), offset);
if ((rc == 0 || !((row >> index) & NAMEI_TAGMASK)) && fixup && nowrite)
return 1;
if (rc == 0 && fixup) {
goto bad_getLinkByte;
FDH_TRUNC(h, offset+sizeof(row));
row = 1 << index;
- rc = write(h->fd_fd, (char *)&row, sizeof(row));
+ rc = FDH_PWRITE(h, (char *)&row, sizeof(row), offset);
}
if (rc != sizeof(row)) {
goto bad_getLinkByte;
if (fixup && !((row >> index) & NAMEI_TAGMASK)) {
row |= 1<<index;
- if (afs_lseek(h->fd_fd, offset, SEEK_SET) == -1)
- goto bad_getLinkByte;
- rc = write(h->fd_fd, (char *)&row, sizeof(row));
+ rc = FDH_PWRITE(h, (char *)&row, sizeof(row), offset);
if (rc != sizeof(row))
goto bad_getLinkByte;
}
}
offset = (vno << LINKTABLE_SHIFT) + 8; /* * 2 + sizeof stamp */
- if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) {
- goto badGetFreeTag;
- }
- nBytes = read(fdP->fd_fd, (char *)&row, sizeof(row));
+ nBytes = FDH_PREAD(fdP, (char *)&row, sizeof(row), offset);
if (nBytes != sizeof(row)) {
if (nBytes != 0)
goto badGetFreeTag;
coldata = 1 << (col * 3);
row |= coldata;
- if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) {
- goto badGetFreeTag;
- }
- if (write(fdP->fd_fd, (char *)&row, sizeof(row)) != sizeof(row)) {
+ if (FDH_PWRITE(fdP, (char *)&row, sizeof(row), offset) != sizeof(row)) {
goto badGetFreeTag;
}
FDH_SYNC(fdP);
return -1;
}
}
- if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) {
- errno = EBADF;
- goto bad_SetLinkCount;
- }
-
- nBytes = read(fdP->fd_fd, (char *)&row, sizeof(row));
+ nBytes = FDH_PREAD(fdP, (char *)&row, sizeof(row), offset);
if (nBytes != sizeof(row)) {
if (nBytes != 0) {
errno = EBADF;
row &= (unsigned short)~junk;
row |= (unsigned short)count;
- if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) {
- errno = EBADF;
- goto bad_SetLinkCount;
- }
-
- if (write(fdP->fd_fd, (char *)&row, sizeof(short)) != sizeof(short)) {
+ if (FDH_PWRITE(fdP, (char *)&row, sizeof(short), offset) != sizeof(short)) {
errno = EBADF;
goto bad_SetLinkCount;
}
if (fdP == NULL)
return -1;
- if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) {
- FDH_REALLYCLOSE(fdP);
- return -1;
- }
-
- nBytes = FDH_READ(fdP, buf, size);
+ nBytes = FDH_PREAD(fdP, buf, size, offset);
FDH_CLOSE(fdP);
return nBytes;
}
if (fdP == NULL)
return -1;
- if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) {
- FDH_REALLYCLOSE(fdP);
- return -1;
- }
- nBytes = FDH_WRITE(fdP, buf, size);
+ nBytes = FDH_PWRITE(fdP, buf, size, offset);
FDH_CLOSE(fdP);
return nBytes;
}
code = errno;
return code;
}
- if (FDH_SEEK(fdP, ((afs_foff_t)block) * AFS_PAGESIZE, SEEK_SET) < 0) {
- code = errno;
- FDH_REALLYCLOSE(fdP);
- return code;
- }
- nBytes = FDH_READ(fdP, data, (afs_fsize_t) AFS_PAGESIZE);
+ nBytes = FDH_PREAD(fdP, data, (afs_fsize_t) AFS_PAGESIZE,
+ ((afs_foff_t)block) * AFS_PAGESIZE);
if (nBytes != AFS_PAGESIZE) {
if (nBytes < 0)
code = errno;
code = errno;
return code;
}
- if (FDH_SEEK(fdP, ((afs_foff_t)block) * AFS_PAGESIZE, SEEK_SET) < 0) {
- code = errno;
- FDH_REALLYCLOSE(fdP);
- return code;
- }
- nBytes = FDH_WRITE(fdP, data, (afs_fsize_t) AFS_PAGESIZE);
+ nBytes = FDH_PWRITE(fdP, data, (afs_fsize_t) AFS_PAGESIZE,
+ ((afs_foff_t)block) * AFS_PAGESIZE);
if (nBytes != AFS_PAGESIZE) {
if (nBytes < 0)
code = errno;
* We remember the inodes in an array, and idec them after zeroing them in the index.
* The reason for these contortions is to make volume deletion idempotent, even
* if we crash in the middle of a delete operation. */
- STREAM_SEEK(afile, offset, 0);
+ STREAM_ASEEK(afile, offset);
while (1) {
if (iindex >= MAXOBLITATONCE) {
break;
}
/* next, obliterate the index and fflush (and fsync) it */
- STREAM_SEEK(afile, *aoffset, 0); /* seek back to start of vnode index region */
+ STREAM_ASEEK(afile, *aoffset); /* seek back to start of vnode index region */
memset(buf, 0, sizeof(buf)); /* zero out our proto-vnode */
for (i = 0; i < nscanned; i++) {
if (STREAM_WRITE(buf, vcp->diskSize, 1, afile) != 1)
*ec = EIO;
goto error_encountered;
}
- if (FDH_SEEK(fdP, off, SEEK_SET) < 0) {
- Log("VAllocVnode: can't seek on index file!\n");
- *ec = EIO;
- goto error_encountered;
- }
if (off + vcp->diskSize <= size) {
- if (FDH_READ(fdP, &vnp->disk, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PREAD(fdP, &vnp->disk, vcp->diskSize, off) != vcp->diskSize) {
Log("VAllocVnode: can't read index file!\n");
*ec = EIO;
goto error_encountered;
goto error_encountered;
}
memset(buf, 0, 16 * 1024);
- if ((FDH_WRITE(fdP, buf, 16 * 1024)) != 16 * 1024) {
+ if ((FDH_PWRITE(fdP, buf, 16 * 1024, off)) != 16 * 1024) {
Log("VAllocVnode: can't grow vnode index: write failed\n");
*ec = EIO;
free(buf);
PrintInode(stmp, vp->vnodeIndex[class].handle->ih_ino));
*ec = VIO;
goto error_encountered_nolock;
- } else if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, Vn_id(vnp)), SEEK_SET)
- < 0) {
- Log("VnLoad: can't seek on index file vn=%u\n", Vn_id(vnp));
- *ec = VIO;
- goto error_encountered_nolock;
- } else if ((nBytes = FDH_READ(fdP, (char *)&vnp->disk, vcp->diskSize))
+ } else if ((nBytes = FDH_PREAD(fdP, (char *)&vnp->disk, vcp->diskSize, vnodeIndexOffset(vcp, Vn_id(vnp))))
!= vcp->diskSize) {
/* Don't take volume off line if the inumber is out of range
* or the inode table is full. */
Log("VnStore: can't open index file!\n");
goto error_encountered;
}
- if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) {
- Log("VnStore: can't seek on index file! fdp=%"AFS_PTR_FMT
- " offset=%d, errno=%d\n",
- fdP, (int) offset, errno);
- goto error_encountered;
- }
-
- nBytes = FDH_WRITE(fdP, &vnp->disk, vcp->diskSize);
+ nBytes = FDH_PWRITE(fdP, &vnp->disk, vcp->diskSize, offset);
if (nBytes != vcp->diskSize) {
/* Don't force volume offline if the inumber is out of
* range or the inode table is full.
nVnodes = (size / diskSize) - 1;
if (nVnodes > 0) {
- STREAM_SEEK(file, diskSize, 0);
+ STREAM_ASEEK(file, diskSize);
} else
nVnodes = 0;
total = bad = 0;
while (1) {
ssize_t nBytes;
- len = FDH_READ(fdP1, buffer, sizeof(buffer));
+ len = FDH_PREAD(fdP1, buffer, sizeof(buffer), total);
if (len < 0) {
FDH_REALLYCLOSE(fdP1);
IH_RELEASE(ih1);
version.magic = LINKTABLEMAGIC;
version.version = LINKTABLEVERSION;
- if (FDH_WRITE(fdP, (char *)&version, sizeof(version))
+ if (FDH_PWRITE(fdP, (char *)&version, sizeof(version), 0)
!= sizeof(version))
Abort("Can't truncate link table for volume %u (error = %d)\n",
isp->RWvolumeId, errno);
sp->description, errno);
if (!recreate
- && (FDH_READ(fdP, (char *)&header, sp->size) != sp->size
+ && (FDH_PREAD(fdP, (char *)&header, sp->size, 0) != sp->size
|| header.fileHeader.magic != sp->stamp.magic)) {
if (check) {
Log("Part of the header (%s) is corrupted\n", sp->description);
header.volumeInfo.needsCallback = 0;
gettimeofday(&tp, 0);
header.volumeInfo.creationDate = tp.tv_sec;
- if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
- Abort
- ("Unable to seek to beginning of volume header file (%s) (errno = %d)\n",
- sp->description, errno);
- }
nBytes =
- FDH_WRITE(fdP, (char *)&header.volumeInfo,
- sizeof(header.volumeInfo));
+ FDH_PWRITE(fdP, (char *)&header.volumeInfo,
+ sizeof(header.volumeInfo), 0);
if (nBytes != sizeof(header.volumeInfo)) {
if (nBytes < 0)
Abort
sp->description);
}
} else {
- if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
- Abort
- ("Unable to seek to beginning of volume header file (%s) (errno = %d)\n",
- sp->description, errno);
- }
- nBytes = FDH_WRITE(fdP, (char *)&sp->stamp, sizeof(sp->stamp));
+ nBytes = FDH_PWRITE(fdP, (char *)&sp->stamp, sizeof(sp->stamp), 0);
if (nBytes != sizeof(sp->stamp)) {
if (nBytes < 0)
Abort
nVnodes = (size / vcp->diskSize) - 1;
if (nVnodes > 0) {
assert((nVnodes + 1) * vcp->diskSize == size);
- assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
+ assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
} else {
nVnodes = 0;
}
if (size > 1024)
size = 1024;
- nBytes = FDH_READ(fdP, buf, size);
+ nBytes = FDH_PREAD(fdP, buf, size, 0);
if (nBytes == size) {
buf[size] = '\0';
if ( (*buf != '#' && *buf != '%') || buf[strlen(buf)-1] != '.' ) {
vip->nVnodes = (size / vcp->diskSize) - 1;
if (vip->nVnodes > 0) {
assert((vip->nVnodes + 1) * vcp->diskSize == size);
- assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
+ assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
assert((vip->vnodes = (struct VnodeEssence *)
calloc(vip->nVnodes, sizeof(struct VnodeEssence))) != NULL);
if (class == vLarge) {
IHandle_t *srcH, *destH;
FdHandle_t *srcFdP, *destFdP;
ssize_t nBytes = 0;
+ afs_foff_t size = 0;
IH_INIT(srcH, device, rwvolume, inode1);
srcFdP = IH_OPEN(srcH);
assert(srcFdP != NULL);
IH_INIT(destH, device, rwvolume, inode2);
destFdP = IH_OPEN(destH);
- while ((nBytes = FDH_READ(srcFdP, buf, sizeof(buf))) > 0)
- assert(FDH_WRITE(destFdP, buf, nBytes) == nBytes);
+ while ((nBytes = FDH_PREAD(srcFdP, buf, sizeof(buf), size)) > 0) {
+ assert(FDH_PWRITE(destFdP, buf, nBytes, size) == nBytes);
+ size += nBytes;
+ }
assert(nBytes == 0);
FDH_REALLYCLOSE(srcFdP);
FDH_REALLYCLOSE(destFdP);
return;
}
- if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
- *ec = VSALVAGE;
- FDH_REALLYCLOSE(fdP);
- return;
- }
vsn = (struct versionStamp *)to;
- if (FDH_READ(fdP, to, size) != size || vsn->magic != magic) {
+ if (FDH_PREAD(fdP, to, size, 0) != size || vsn->magic != magic) {
*ec = VSALVAGE;
FDH_REALLYCLOSE(fdP);
return;
*ec = VSALVAGE;
return;
}
- if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
- *ec = VSALVAGE;
- FDH_REALLYCLOSE(fdP);
- return;
- }
- if (FDH_WRITE(fdP, (char *)&V_disk(vp), sizeof(V_disk(vp)))
+ if (FDH_PWRITE(fdP, (char *)&V_disk(vp), sizeof(V_disk(vp)), 0)
!= sizeof(V_disk(vp))) {
*ec = VSALVAGE;
FDH_REALLYCLOSE(fdP);
assert(vip->bitmap != NULL);
vip->bitmapOffset = 0;
#endif /* BITMAP_LATER */
- if (STREAM_SEEK(file, vcp->diskSize, 0) != -1) {
+ if (STREAM_ASEEK(file, vcp->diskSize) != -1) {
int bitNumber = 0;
for (bitNumber = 0; bitNumber < nVnodes + 100; bitNumber++) {
if (STREAM_READ(vnode, vcp->diskSize, 1, file) != 1)
PrintInode(stmp, *(p->inode)), errno);
goto bad;
}
- if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
- Log("VCreateVolume: Problem lseek inode %s (err=%d)\n",
- PrintInode(NULL, *(p->inode)), errno);
- FDH_REALLYCLOSE(fdP);
- goto bad;
- }
- if (FDH_WRITE(fdP, (char *)&p->stamp, sizeof(p->stamp)) !=
+ if (FDH_PWRITE(fdP, (char *)&p->stamp, sizeof(p->stamp), 0) !=
sizeof(p->stamp)) {
Log("VCreateVolume: Problem writing to inode %s (err=%d)\n",
PrintInode(stmp, *(p->inode)), errno);
PrintInode(stmp, tempHeader.volumeInfo), errno);
goto bad;
}
- if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
- Log("VCreateVolume: Problem lseek inode %s (err=%d)\n",
- PrintInode(NULL, tempHeader.volumeInfo), errno);
- FDH_REALLYCLOSE(fdP);
- goto bad;
- }
- if (FDH_WRITE(fdP, (char *)&vol, sizeof(vol)) != sizeof(vol)) {
+ if (FDH_PWRITE(fdP, (char *)&vol, sizeof(vol), 0) != sizeof(vol)) {
Log("VCreateVolume: Problem writing to inode %s (err=%d)\n",
PrintInode(stmp, tempHeader.volumeInfo), errno);
FDH_REALLYCLOSE(fdP);
afs_sfsize_t nbytes, howBig;
ssize_t n;
size_t howMany;
- afs_foff_t lcode = 0;
+ afs_foff_t howFar = 0;
byte *p;
afs_uint32 hi, lo;
afs_ino_str_t stmp;
if (nbytes < howMany)
howMany = nbytes;
- /* Read the data - unless we know we can't */
- n = (lcode ? 0 : FDH_READ(handleP, p, howMany));
+ /* Read the data */
+ n = FDH_PREAD(handleP, p, howMany, howFar);
+ howFar += n;
/* If read any good data and we null padded previously, log the
* amount that we had null padded.
/* Now seek over the data we could not get. An error here means we
* can't do the next read.
*/
- lcode = FDH_SEEK(handleP, (size_t)((size - nbytes) + howMany), SEEK_SET);
- if (lcode != ((size - nbytes) + howMany)) {
- if (lcode < 0) {
- Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d: %s\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode, afs_error_message(errno));
- } else {
- Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
- lcode = -1;
- }
- } else {
- lcode = 0;
- }
+ howFar = (size_t)((size - nbytes) + howMany);
}
/* Now write the data out */
nVnodes = (size / vcp->diskSize) - 1;
if (nVnodes > 0) {
assert((nVnodes + 1) * vcp->diskSize == size);
- assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
+ assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
} else
nVnodes = 0;
for (vnodeIndex = 0;
for (i = 0; i < *sizep; i++) {
if (Buf[i]) {
cnt++;
- STREAM_SEEK(afile, Buf[i], 0);
+ STREAM_ASEEK(afile, Buf[i]);
code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
if (code == 1) {
if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
V_parentId(vp));
DOPOLL;
}
- STREAM_SEEK(afile, Buf[i], 0);
+ STREAM_ASEEK(afile, Buf[i]);
(void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
}
Buf[i] = 0;
return -1;
}
memset(Buf, 0, nVnodes * sizeof(afs_int32));
- STREAM_SEEK(afile, offset = vcp->diskSize, 0);
+ STREAM_ASEEK(afile, offset = vcp->diskSize);
while (1) {
code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
if (code != 1) {
afs_error_message(errno));
return VOLSERREAD_DUMPERROR;
}
- if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
- 0) {
- Log("1 Volser: ReadVnodes: Error seeking into vnode index: %s; restore aborted\n",
- afs_error_message(errno));
- FDH_REALLYCLOSE(fdP);
- return VOLSERREAD_DUMPERROR;
- }
- if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) ==
+ if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
sizeof(oldvnode)) {
if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
}
}
vnode->vnodeMagic = vcp->magic;
- if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
- 0) {
- Log("1 Volser: ReadVnodes: Error seeking into vnode index: %s; restore aborted\n",
- afs_error_message(errno));
- FDH_REALLYCLOSE(fdP);
- return VOLSERREAD_DUMPERROR;
- }
- if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
afs_error_message(errno));
FDH_REALLYCLOSE(fdP);
break;
}
if (handleP) {
- nBytes = FDH_WRITE(handleP, p, size);
+ nBytes = FDH_PWRITE(handleP, p, size, written);
if (nBytes > 0)
written += nBytes;
if (nBytes != size) {
nVnodes = (size / vcp->diskSize) - 1;
if (nVnodes > 0) {
assert((nVnodes + 1) * vcp->diskSize == size);
- assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
+ assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
} else
nVnodes = 0;
for (vnodeIndex = 0;
code = errno;
return code;
}
- if (FDH_SEEK(fdP, ((afs_foff_t)block) * AFS_PAGESIZE, SEEK_SET) < 0) {
- code = errno;
- FDH_REALLYCLOSE(fdP);
- return code;
- }
- nBytes = FDH_READ(fdP, data, AFS_PAGESIZE);
+ nBytes = FDH_PREAD(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE);
if (nBytes != AFS_PAGESIZE) {
if (nBytes < 0)
code = errno;
code = errno;
return code;
}
- if (FDH_SEEK(fdP, ((afs_foff_t)block) * AFS_PAGESIZE, SEEK_SET) < 0) {
- code = errno;
- FDH_REALLYCLOSE(fdP);
- return code;
- }
- nBytes = FDH_WRITE(fdP, data, AFS_PAGESIZE);
+ nBytes = FDH_PWRITE(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE);
if (nBytes != AFS_PAGESIZE) {
if (nBytes < 0)
code = errno;
afs_sfsize_t nbytes, howBig;
ssize_t n;
size_t howMany;
+ afs_foff_t howFar = 0;
byte *p;
afs_uint32 hi, lo;
afs_ino_str_t stmp;
howMany = nbytes;
/* Read the data - unless we know we can't */
- n = (failed_seek ? 0 : FDH_READ(handleP, p, howMany));
+ n = (failed_seek ? 0 : FDH_PREAD(handleP, p, howMany, howFar));
+ howFar += n;
/* If read any good data and we null padded previously, log the
* amount that we had null padded.
/* Now seek over the data we could not get. An error here means we
* can't do the next read.
*/
- failed_seek = FDH_SEEK(handleP, ((size - nbytes) + howMany), SEEK_SET);
- if (failed_seek != ((size - nbytes) + howMany)) {
- if (failed_seek < 0) {
- fprintf(stderr,
- "Error %d seeking in inode %s for vnode %d\n",
- errno, PrintInode(NULL, handleP->fd_ih->ih_ino),
- vnode);
- } else {
- fprintf(stderr,
- "Error seeking in inode %s for vnode %d\n",
- PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
- failed_seek = -1;
- }
- } else {
- failed_seek = 0;
- }
+ howFar = ((size - nbytes) + howMany);
}
/* Now write the data out */
nVnodes = (size / vcp->diskSize) - 1;
if (nVnodes > 0) {
- STREAM_SEEK(file, vcp->diskSize, 0);
+ STREAM_ASEEK(file, vcp->diskSize);
} else
nVnodes = 0;
for (vnodeIndex = 0;
return EIO;
goto Bad_Extract;
}
- code = STREAM_SEEK(stream, vcp->diskSize, 0);
+ code = STREAM_ASEEK(stream, vcp->diskSize);
if (code)
goto Bad_Extract;
if (class == vLarge) {
if (*parent) {
offset = (*parent + 1 - class) << (vcp->logSize -1);
- code = STREAM_SEEK(stream, offset, 0);
+ code = STREAM_ASEEK(stream, offset);
if (STREAM_READ(vnode, vcp->diskSize, 1, stream) == 1)
memcpy(parentvd, vnode, vcp->diskSize);
else
FdHandle_t *infdP, *outfdP;
char *tbuf;
afs_sfsize_t size;
+ afs_foff_t offset;
infdP = IH_OPEN(inh);
if (!infdP) {
return EIO;
}
tbuf = malloc(2048);
- FDH_SEEK(infdP, 0, 0);
- FDH_SEEK(outfdP, 0, 0);
+ offset = 0;
size = FDH_SIZE(infdP);
while (size) {
size_t tlen;
tlen = size > 2048 ? 2048 : size;
- if (FDH_READ(infdP, tbuf, tlen) != tlen) {
+ if (FDH_PREAD(infdP, tbuf, tlen, offset) != tlen) {
sprintf(m->line, "Couldn't read directory %u.%u.%u\n",
infdP->fd_ih->ih_vid,
(afs_uint32)(infdP->fd_ih->ih_ino & NAMEI_VNODEMASK),
free(tbuf);
return EIO;
}
- if (FDH_WRITE(outfdP, tbuf, tlen) != tlen) {
+ if (FDH_PWRITE(outfdP, tbuf, tlen, offset) != tlen) {
sprintf(m->line, "Couldn't write directory %u.%u.%u\n",
outfdP->fd_ih->ih_vid,
(afs_uint32)(outfdP->fd_ih->ih_ino & NAMEI_VNODEMASK),
return EIO;
}
size -= tlen;
+ offset += tlen;
}
free(tbuf);
FDH_CLOSE(outfdP);
if (e->flag) {
afs_uint64 size;
offset = (e->vN + 1 - class) << (vcp->logSize -1);
- if (FDH_SEEK(fdP, offset, 0) != offset
- || FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) {
Log("Couldn't read in %s Index of volume %u at offset %"
AFS_UINT64_FMT "\n", class ? "small":"large",
V_id(vol), offset);
/* Now update the vnode and write it back to disk */
VNDISK_SET_INO(vnode, newino);
vnode->cloned = 0;
- if (FDH_SEEK(fdP, offset, 0) != offset
- || FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PWRITE(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) {
Log("Couldn't write in %s Index of volume %u at offset %"
AFS_UINT64_FMT "\n", class ? "small":"large",
V_id(vol), offset);
if (e->flag & CHANGEPARENT)
vnode->parent = 1; /* in new root-directory */
vnode->cloned = 0;
- if (FDH_SEEK(newfdP, offset, 0) != offset
- || FDH_WRITE(newfdP, vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PWRITE(newfdP, vnode, vcp->diskSize, offset) != vcp->diskSize) {
Log("Couldn't write in %s Index of volume %u to offset %"
AFS_UINT64_FMT "\n", class ? "small":"large",
V_id(newvol), offset);
afs_uint64 newoffset;
newoffset = vcp->diskSize;
- if (FDH_SEEK(newfdP, newoffset, 0) != newoffset
- || FDH_READ(newfdP, vnode2, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PREAD(newfdP, vnode2, vcp->diskSize, newoffset) != vcp->diskSize) {
Log("splitvolume: couldn't read in large Index of new volume %u at offset %u\n",
V_id(newvol), vcp->diskSize);
code = EIO;
goto Bad_Copy;
}
offset = (where + 1 - class) << (vcp->logSize -1);
- if (FDH_SEEK(fdP, offset, 0) != offset
- || FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) {
Log("Couldn't read in large Index of old volume %u at offset %"
AFS_UINT64_FMT "\n", V_id(vol), offset);
code = EIO;
vnode->cloned = 0;
vnode->parent = vnode2->parent;
vnode->serverModifyTime = vnode2->serverModifyTime;
- if (FDH_SEEK(newfdP, newoffset, 0) != newoffset
- || FDH_WRITE(newfdP, vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PWRITE(newfdP, vnode, vcp->diskSize, newoffset) != vcp->diskSize) {
Log("splitvolume: couldn't write in large Index of %u at offset %u\n",
V_id(newvol), vcp->diskSize);
code = EIO;
struct timeval now;
afs_uint32 newvN;
char symlink[32];
+ ssize_t rc;
FT_GetTimeOfDay(&now, 0);
fdP = IH_OPEN(vol->vnodeIndex[vSmall].handle);
return EIO;
}
offset = vcp->diskSize;
- if (FDH_SEEK(fdP, offset, 0) != offset) {
- Log("split volume: error seeking in small vnode index of %u\n", V_id(vol));
- return EIO;
- }
while (1) {
- if (FDH_READ(fdP, &vnode, vcp->diskSize) != vcp->diskSize)
- break;
+ rc = FDH_PREAD(fdP, &vnode, vcp->diskSize, offset);
+ if (rc != vcp->diskSize) {
+ if (rc < 0) {
+ Log("split volume: error reading small vnode index of %u\n", V_id(vol));
+ return EIO;
+ }
+ if (rc == 0)
+ break;
+ if (rc < vcp->diskSize)
+ break;
+ }
if (vnode.type == vNull)
break;
offset += vcp->diskSize;
V_id(vol), newvN, vnode.uniquifier);
return EIO;
}
- FDH_SEEK(fdP2, 0, 0);
sprintf(symlink, "#%s", V_name(newvol));
size = strlen(symlink) + 1;
- if (FDH_WRITE(fdP2, symlink, size) != size) {
+ if (FDH_PWRITE(fdP2, symlink, size, 0) != size) {
Log("split volume: couldn't write mountpoint %u.%u.%u\n",
V_id(vol), newvN, vnode.uniquifier);
return EIO;
#ifndef AFS_RXOSD_SUPPORT
vnode.vnodeMagic = SMALLVNODEMAGIC;
#endif
- if (FDH_SEEK(fdP, offset, 0) != offset
- || FDH_WRITE(fdP, &vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PWRITE(fdP, &vnode, vcp->diskSize, offset) != vcp->diskSize) {
Log("split volume: couldn't write vnode for mountpoint %u.%u.%u\n",
V_id(vol), newvN, vnode.uniquifier);
return EIO;
fdP = IH_OPEN(vol->vnodeIndex[class].handle);
offset = (vN + 1 - class) << (vcp->logSize -1);
parent->dataVersion++;
- if (FDH_SEEK(fdP, offset, 0) != offset
- || FDH_WRITE(fdP, parent, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PWRITE(fdP, parent, vcp->diskSize, offset) != vcp->diskSize) {
Log("split volume: couldn't write vnode for parent directory %u.%u.%u\n",
V_id(vol), vN, parent->uniquifier);
return EIO;
if (e->flag & NEEDED) {
afs_uint64 size;
offset = (e->vN + 1 - class) << (vcp->logSize -1);
- if (FDH_SEEK(fdP, offset, 0) != offset) {
- Log("Couldn't seek in %s Index of volume %u to offset %"
- AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol),
- offset);
- code = EIO;
- goto Bad_Delete;
- }
- if (FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) {
Log("Couldn't read in %s Index of volume %u at offset %"
AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol),
offset);
}
memset(vnode, 0, vcp->diskSize);
vnode->type = vNull;
- if (FDH_SEEK(fdP, offset, 0) != offset
- || FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
+ if (FDH_PWRITE(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) {
Log("Couldn't write in %s Index of volume %u to offset %"
AFS_UINT64_FMT "\n", class ? "small":"large",
V_id(vol), offset);
FdHandle_t *fdP;
afs_fsize_t length;
ssize_t nBytes;
- afs_foff_t off;
vnode = (struct VnodeDiskObject *)malloc(SIZEOF_LARGEDISKVNODE);
if (!vnode)
vp->vnodeIndex[vLarge].handle->ih_ino);
fdP = IH_OPEN(h);
assert(fdP != NULL);
- off = FDH_SEEK(fdP, vnodeIndexOffset(vcp, 1), SEEK_SET);
- assert(off >= 0);
- nBytes = FDH_WRITE(fdP, vnode, SIZEOF_LARGEDISKVNODE);
+ nBytes = FDH_PWRITE(fdP, vnode, SIZEOF_LARGEDISKVNODE, vnodeIndexOffset(vcp, 1));
assert(nBytes == SIZEOF_LARGEDISKVNODE);
FDH_REALLYCLOSE(fdP);
IH_RELEASE(h);