# pragma GCC diagnostic warning "-Wformat"
#endif
+#include <roken.h>
+
#include <ctype.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#include <time.h>
-#include <io.h>
-#else
-#include <sys/param.h>
-#include <sys/file.h>
-#include <sys/time.h>
-#endif
-#include <afs/cmd.h>
+#include <afs/cmd.h>
#include <rx/xdr.h>
#include <afs/afsint.h>
#include <afs/nfs.h>
#include <afs/dir.h>
#include <afs/com_err.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
-#ifdef _AIX
-#include <time.h>
-#endif
-
-#include <dirent.h>
-
#include "volser.h"
#include "volint.h"
#include "dump.h"
-#define putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
-#define putshort(p, v) *p++ = v>>8, *p++ = v
-
-#ifdef O_LARGEFILE
-#define afs_stat stat64
-#define afs_fstat fstat64
-#define afs_open open64
-#else /* !O_LARGEFILE */
-#define afs_stat stat
-#define afs_fstat fstat
-#define afs_open open
-#endif /* !O_LARGEFILE */
+#define afs_putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
+#define afs_putshort(p, v) *p++ = v>>8, *p++ = v
int VolumeChanged; /* needed by physio - leave alone */
int verbose = 0;
/* Forward Declarations */
-void HandleVolume(struct DiskPartition64 *partP, char *name, char *filename, int fromtime);
-Volume *AttachVolume(struct DiskPartition64 *dp, char *volname,
- struct VolumeHeader *header);
+static void HandleVolume(struct DiskPartition64 *partP, char *name,
+ char *filename, int fromtime);
+static Volume *AttachVolume(struct DiskPartition64 *dp, char *volname,
+ struct VolumeHeader *header);
static void DoMyVolDump(Volume * vp, struct DiskPartition64 *dp,
char *dumpfile, int fromtime);
char name[VMAXPATHLEN];
-int
+static int
ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
{
int code;
}
-Volume *
+static Volume *
AttachVolume(struct DiskPartition64 * dp, char *volname,
struct VolumeHeader * header)
{
exit(1);
}
- (void)afs_snprintf(name1, sizeof name1, VFORMAT, (unsigned long)volumeId);
+ snprintf(name1, sizeof name1, VFORMAT, (unsigned long)volumeId);
HandleVolume(partP, name1, fileName, fromtime);
return 0;
}
-void
+static void
HandleVolume(struct DiskPartition64 *dp, char *name, char *filename, int fromtime)
{
struct VolumeHeader header;
afs_int32 n;
- (void)afs_snprintf(headerName, sizeof headerName, "%s/%s",
- VPartitionPath(dp), name);
+ snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s",
+ VPartitionPath(dp), name);
if ((fd = afs_open(headerName, O_RDONLY)) == -1
|| afs_fstat(fd, &status) == -1) {
fprintf(stderr, "Cannot read volume header %s\n", name);
char tbuffer[9];
byte *p = (unsigned char *)tbuffer;
*p++ = tag;
- putint32(p, value1);
- putint32(p, value2);
+ afs_putint32(p, value1);
+ afs_putint32(p, value2);
res = write(dumpfd, tbuffer, 9);
return ((res == 9) ? 0 : VOLSERDUMPERROR);
char tbuffer[5];
byte *p = (unsigned char *)tbuffer;
*p++ = tag;
- putint32(p, value);
+ afs_putint32(p, value);
return ((write(dumpfd, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
}
int code = 0;
byte *p = (unsigned char *)tbuffer;
*p++ = tag;
- putshort(p, nelem);
+ afs_putshort(p, nelem);
code = write(dumpfd, tbuffer, 3);
if (code != 3)
return VOLSERDUMPERROR;
p = (unsigned char *)tbuffer;
v = *array++; /*this was register */
- putint32(p, v);
+ afs_putint32(p, v);
code = write(dumpfd, tbuffer, 4);
if (code != 4)
return VOLSERDUMPERROR;
{
int code = 0, failed_seek = 0, failed_write = 0;
afs_int32 pad = 0;
- afs_int32 offset = 0;
+ afs_foff_t offset = 0;
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;
#ifndef AFS_NT40_ENV
struct afs_stat status;
+#else
+ LARGE_INTEGER fileSize;
#endif
afs_sfsize_t size;
#ifdef AFS_AIX_ENV
fprintf(stderr, "dumping file for vnode %d\n", vnode);
#ifdef AFS_NT40_ENV
- howBig = _filelength(handleP->fd_fd);
+ if (!GetFileSizeEx(handleP->fd_fd, &fileSize)) {
+ Log("DumpFile: GetFileSizeEx returned error code %d on descriptor %d\n", GetLastError(), handleP->fd_fd);
+ return VOLSERDUMPERROR;
+ }
+ howBig = fileSize.QuadPart;
howMany = 4096;
#else
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.
*/
if ((n > 0) && pad) {
- fprintf(stderr, "Null padding file %d bytes at offset %u\n", pad,
- offset);
+ fprintf(stderr, "Null padding file %d bytes at offset %lld\n", pad,
+ (long long)offset);
pad = 0;
}
if (n < 0) {
n = 0;
fprintf(stderr, "Error %d reading inode %s for vnode %d\n",
- errno, PrintInode(NULL, handleP->fd_ih->ih_ino),
+ errno, PrintInode(stmp, handleP->fd_ih->ih_ino),
vnode);
} else if (!pad) {
fprintf(stderr, "Error reading inode %s for vnode %d\n",
- PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
+ PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
}
/* Pad the rest of the buffer with zeros. Remember offset we started
/* 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 */
}
if (pad) { /* Any padding we hadn't reported yet */
- fprintf(stderr, "Null padding file: %d bytes at offset %u\n", pad,
- offset);
+ fprintf(stderr, "Null padding file: %d bytes at offset %lld\n", pad,
+ (long long)offset);
}
free(p);
int code = 0;
IHandle_t *ihP;
FdHandle_t *fdP;
+ afs_ino_str_t stmp;
if (verbose)
fprintf(stderr, "dumping vnode %d\n", vnodeNumber);
if (fdP == NULL) {
fprintf(stderr,
"Unable to open inode %s for vnode %u (volume %i); not dumped, error %d\n",
- PrintInode(NULL, VNDISK_GET_INO(v)), vnodeNumber, volid,
+ PrintInode(stmp, VNDISK_GET_INO(v)), vnodeNumber, volid,
errno);
}
else
{
if (verbose)
fprintf(stderr, "about to dump inode %s for vnode %u\n",
- PrintInode(NULL, VNDISK_GET_INO(v)), vnodeNumber);
+ PrintInode(stmp, VNDISK_GET_INO(v)), vnodeNumber);
code = DumpFile(dumpfd, vnodeNumber, fdP, v);
FDH_CLOSE(fdP);
}
FdHandle_t *fdP;
afs_sfsize_t size;
int flag;
- int offset = 0;
+ afs_foff_t offset = 0;
int vnodeIndex, nVnodes = 0;
fdP = IH_OPEN(vp->vnodeIndex[class].handle);
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;
* a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
* does dump the file! */
if (verbose)
- fprintf(stderr, "about to dump %s vnode %u (vnode offset = %u)\n",
+ fprintf(stderr, "about to dump %s vnode %u (vnode offset = %lld)\n",
class == vSmall ? "vSmall" : "vLarge",
- bitNumberToVnodeNumber(vnodeIndex, class), offset);
+ bitNumberToVnodeNumber(vnodeIndex, class), (long long)offset);
if (!code)
code =
DumpVnode(dumpfd, vnode, V_id(vp),