/*
* 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
* uses your current umask. Mode bits for directories are 0777 (then
* AND'ed with the umask). Mode bits for files are the owner mode bits
* duplicated accross group and user (then AND'ed with the umask).
- * 5. For restores of full dumps, if a directory says it has a file and
- * the file is not found, then a symbolic link "AFSFile-<#>" will
- * appear in that restored tree. Restores of incremental dumps remove
- * all these files at the end (expensive because it is a tree search).
- * 6. If a file or directory was found in the dump but found not to be
- * connected to the hierarchical tree, then the file or directory
- * will be connected at the root of the tree as "__ORPHANEDIR__.<#>"
- * or "__ORPHANFILE__.<#>".
+ * 5. For restores of full dumps, if a directory says it has a file and
+ * the file is not found, then a symbolic link "AFSFile-<#>" will
+ * appear in that restored tree. Restores of incremental dumps remove
+ * all these files at the end (expensive because it is a tree search).
+ * 6. If a file or directory was found in the dump but found not to be
+ * connected to the hierarchical tree, then the file or directory
+ * will be connected at the root of the tree as "__ORPHANEDIR__.<#>"
+ * or "__ORPHANFILE__.<#>".
* 7. ACLs are not restored.
*
*/
#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
#include <afs/afsint.h>
#include <afs/nfs.h>
+#include <rx/rx_queue.h>
#include <lock.h>
#include <afs/ihandle.h>
#include <afs/vnode.h>
#include <afs/volume.h>
-#include "volint.h"
-#include "dump.h"
#include <afs/cmd.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <stdio.h>
-#include <errno.h>
-#include <netinet/in.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <string.h>
-
+#include "volint.h"
+#include "dump.h"
char rootdir[MAXPATHLEN];
char mntroot[MAXPATHLEN];
FILE *dumpfile;
afs_int32
-readvalue(size)
+readvalue(int size)
{
afs_int32 value, s;
int code;
ptr = (char *)&value;
s = sizeof(value) - size;
- if (size < 0) {
- fprintf(stderr, "Too much data in afs_int32\n");
+ if (s < 0) {
+ fprintf(stderr, "Too much data for afs_int32\n");
return 0;
}
}
char
-readchar()
+readchar(void)
{
char value;
int code;
- char *ptr;
value = '\0';
code = fread(&value, 1, 1, dumpfile);
char buf[BUFSIZE];
void
-readdata(buffer, size)
- char *buffer;
- afs_sfsize_t size;
+readdata(char *buffer, afs_sfsize_t size)
{
int code;
afs_int32 s;
}
afs_int32
-ReadDumpHeader(dh)
- struct DumpHeader *dh; /* Defined in dump.h */
+ReadDumpHeader(struct DumpHeader *dh)
{
- int code, i, done;
+ int i, done;
char tag, c;
- afs_int32 magic;
+ afs_int32 magic AFS_UNUSED;
/* memset(&dh, 0, sizeof(dh)); */
case 't':
dh->nDumpTimes = ntohl(readvalue(2)) >> 1;
+ if (dh->nDumpTimes > MAXDUMPTIMES) {
+ fprintf(stderr, "Too many dump times in header (%d > %d)\n",
+ dh->nDumpTimes, MAXDUMPTIMES);
+ dh->nDumpTimes = MAXDUMPTIMES;
+ }
for (i = 0; i < dh->nDumpTimes; i++) {
dh->dumpTimes[i].from = ntohl(readvalue(4));
dh->dumpTimes[i].to = ntohl(readvalue(4));
};
afs_int32
-ReadVolumeHeader(count)
- afs_int32 count;
+ReadVolumeHeader(afs_int32 count)
{
struct volumeHeader vh;
- int code, i, done, entries;
+ int i, done;
char tag, c;
/* memset(&vh, 0, sizeof(vh)); */
break;
case 'v':
- ntohl(readvalue(4)); /* version stamp - ignore */
+ (void)ntohl(readvalue(4)); /* version stamp - ignore */
break;
case 'n':
#define MAXNAMELEN 256
afs_int32
-ReadVNode(count)
- afs_int32 count;
+ReadVNode(afs_int32 count)
{
struct vNode vn;
- int code, i, done, entries;
- char tag, c;
+ int code, i, done;
+ char tag;
char dirname[MAXNAMELEN], linkname[MAXNAMELEN], lname[MAXNAMELEN];
char parentdir[MAXNAMELEN], vflink[MAXNAMELEN];
char filename[MAXNAMELEN], fname[MAXNAMELEN];
int len;
afs_int32 vnode;
afs_int32 mode = 0;
+ afs_uint32 hi, lo;
/* memset(&vn, 0, sizeof(vn)); */
vn.dataSize = 0;
readdata(vn.acl, 192); /* Skip ACL data */
break;
-#ifdef AFS_LARGEFILE_ENV
case 'h':
- {
- afs_uint32 hi, lo;
- hi = ntohl(readvalue(4));
- lo = ntohl(readvalue(4));
- FillInt64(vn.dataSize, hi, lo);
- }
+ hi = ntohl(readvalue(4));
+ lo = ntohl(readvalue(4));
+ FillInt64(vn.dataSize, hi, lo);
goto common_vnode;
-#endif /* !AFS_LARGEFILE_ENV */
case 'f':
vn.dataSize = ntohl(readvalue(4));
if (vnode == 1)
strncpy(parentdir, rootdir, sizeof parentdir);
else {
- afs_snprintf(parentdir, sizeof parentdir, "%s/%s%d", rootdir,
- ADIR, vnode);
+ snprintf(parentdir, sizeof parentdir,
+ "%s" OS_DIRSEP "%s%d", rootdir, ADIR, vnode);
len = readlink(parentdir, linkname, MAXNAMELEN);
if (len < 0) {
/* parentdir does not exist. So create an orphan dir.
* and then link the parentdir to the orphaned dir.
*/
- afs_snprintf(linkname, sizeof linkname, "%s/%s%d",
- rootdir, ODIR, vnode);
+ snprintf(linkname, sizeof linkname, "%s" OS_DIRSEP "%s%d",
+ rootdir, ODIR, vnode);
code = mkdir(linkname, 0777);
if ((code < 0) && (errno != EEXIST)) {
fprintf(stderr,
}
/* Link the parentdir to it - now parentdir exists */
- afs_snprintf(linkname, sizeof linkname, "%s%d/", ODIR,
- vnode);
+ snprintf(linkname, sizeof linkname, "%s%d/", ODIR,
+ vnode);
code = symlink(linkname, parentdir);
if (code) {
fprintf(stderr,
buffer = NULL;
- buffer = (char *)malloc(vn.dataSize);
+ buffer = malloc(vn.dataSize);
readdata(buffer, vn.dataSize);
page0 = (struct Page0 *)buffer;
if (this_vn & 1) {
/*ADIRENTRY*/
/* dirname is the directory to create.
- * vflink is what will link to it.
+ * vflink is what will link to it.
*/
- afs_snprintf(dirname, sizeof dirname, "%s/%s",
- parentdir, this_name);
- afs_snprintf(vflink, sizeof vflink, "%s/%s%d",
- rootdir, ADIR, this_vn);
+ snprintf(dirname, sizeof dirname,
+ "%s" OS_DIRSEP "%s",
+ parentdir, this_name);
+ snprintf(vflink, sizeof vflink,
+ "%s" OS_DIRSEP "%s%d",
+ rootdir, ADIR, this_vn);
/* The link and directory may already exist */
len = readlink(vflink, linkname, MAXNAMELEN);
* It was created originally as orphaned.
*/
linkname[len - 1] = '\0'; /* remove '/' at end */
- afs_snprintf(lname, sizeof lname, "%s/%s",
- rootdir, linkname);
+ snprintf(lname, sizeof lname,
+ "%s" OS_DIRSEP "%s",
+ rootdir, linkname);
code = rename(lname, dirname);
if (code) {
fprintf(stderr,
/* Now create/update the link to the new/moved directory */
if (vn.vnode == 1)
- afs_snprintf(dirname, sizeof dirname, "%s/",
- this_name);
+ snprintf(dirname, sizeof dirname, "%s/",
+ this_name);
else
- afs_snprintf(dirname, sizeof dirname,
- "%s%d/%s/", ADIR, vn.vnode,
- this_name);
+ snprintf(dirname, sizeof dirname, "%s%d/%s/",
+ ADIR, vn.vnode, this_name);
unlink(vflink);
code = symlink(dirname, vflink);
if (code) {
* by creating a link within the directory. Restoring
* the file will later remove the link.
*/
- else {
- /*AFILEENTRY*/ afs_snprintf(vflink,
- sizeof vflink,
- "%s/%s%d", parentdir,
- AFILE, this_vn);
+ else {
+ /*AFILEENTRY*/
+ snprintf(vflink, sizeof vflink,
+ "%s" OS_DIRSEP "%s%d", parentdir,
+ AFILE, this_vn);
code = symlink(this_name, vflink);
if ((code < 0) && (errno != EEXIST)) {
int fid;
int lfile;
afs_sfsize_t size, s;
+ ssize_t count;
/* Check if its vnode-file-link exists. If not,
* then the file will be an orphaned file.
*/
lfile = 1;
- afs_snprintf(filename, sizeof filename, "%s/%s%d", parentdir,
- AFILE, vn.vnode);
+ snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d",
+ parentdir, AFILE, vn.vnode);
len = readlink(filename, fname, MAXNAMELEN);
if (len < 0) {
- afs_snprintf(filename, sizeof filename, "%s/%s%d",
- rootdir, OFILE, vn.vnode);
+ snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d",
+ rootdir, OFILE, vn.vnode);
lfile = 0; /* no longer a linked file; a direct path */
}
/* Write the file out */
fid = open(filename, (O_CREAT | O_WRONLY | O_TRUNC), mode);
+ if (fid < 0) {
+ fprintf(stderr, "Open %s: Errno = %d\n", filename, errno);
+ goto open_fail;
+ }
size = vn.dataSize;
while (size > 0) {
s = (afs_int32) ((size > BUFSIZE) ? BUFSIZE : size);
code = fread(buf, 1, s, dumpfile);
- if (code > 0) {
- (void)write(fid, buf, code);
- size -= code;
- }
if (code != s) {
if (code < 0)
fprintf(stderr, "Code = %d; Errno = %d\n", code,
errno);
else {
char tmp[100];
- (void)afs_snprintf(tmp, sizeof tmp,
- "Read %llu bytes out of %llu",
- (afs_uintmax_t) (vn.dataSize -
- size),
- (afs_uintmax_t) vn.dataSize);
+ snprintf(tmp, sizeof tmp,
+ "Read %llu bytes out of %llu",
+ (afs_uintmax_t) (vn.dataSize - size),
+ (afs_uintmax_t) vn.dataSize);
fprintf(stderr, "%s\n", tmp);
}
break;
}
+ if (code > 0) {
+ count = write(fid, buf, code);
+ if (count < 0) {
+ fprintf(stderr, "Count = %ld, Errno = %d\n",
+ (long)count, errno);
+ break;
+ } else if (count != code) {
+ fprintf(stderr, "Wrote %llu bytes out of %llu\n",
+ (afs_uintmax_t) count,
+ (afs_uintmax_t) code);
+ break;
+ }
+ size -= code;
+ }
}
close(fid);
if (size != 0) {
filename, fname);
}
+open_fail:
/* Remove the link to the file */
if (lfile) {
unlink(filename);
* also be a mount point. If the volume is being restored to AFS, this
* will become a mountpoint. If not, it becomes a symlink to no-where.
*/
- int fid;
- afs_int32 size, s;
+ afs_int32 s;
/* Check if its vnode-file-link exists and create pathname
* of the symbolic link. If it doesn't exist,
* then the link will be an orphaned link.
*/
- afs_snprintf(linkname, sizeof linkname, "%s/%s%d", parentdir,
- AFILE, vn.vnode);
- len = readlink(linkname, fname, MAXNAMELEN);
+ snprintf(linkname, sizeof linkname, "%s" OS_DIRSEP "%s%d",
+ parentdir, AFILE, vn.vnode);
+ len = readlink(linkname, fname, MAXNAMELEN - 1);
if (len < 0) {
- afs_snprintf(filename, sizeof filename, "%s/%s%d",
- rootdir, OFILE, vn.vnode);
+ snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d",
+ rootdir, OFILE, vn.vnode);
} else {
fname[len] = '\0';
- afs_snprintf(filename, sizeof filename, "%s/%s",
- parentdir, fname);
+ snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s",
+ parentdir, fname);
}
/* Read the link in, delete it, and then create it */
static int
WorkerBee(struct cmd_syndesc *as, void *arock)
{
- int code = 0, c, len;
+ int code = 0, len;
afs_int32 type, count, vcount;
DIR *dirP, *dirQ;
struct dirent *dirE, *dirF;
- char fname[MAXNAMELEN], name[MAXNAMELEN], lname[MAXNAMELEN],
- mname[MAXNAMELEN];
- char thisdir[MAXPATHLEN], *t;
+ char name[2*MAXNAMELEN+1];
+ char thisdir[MAXPATHLEN+4], *t;
struct DumpHeader dh; /* Defined in dump.h */
#if 0/*ndef HAVE_GETCWD*/ /* XXX enable when autoconf happens */
extern char *getwd();
dirP = opendir(rootdir);
while (dirP && (dirE = readdir(dirP))) {
if (strncmp(dirE->d_name, ADIR, strlen(ADIR)) == 0) {
- afs_snprintf(name, sizeof name, "%s/%s", rootdir,
- dirE->d_name);
+ snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir,
+ dirE->d_name);
dirQ = opendir(name);
while (dirQ && (dirF = readdir(dirQ))) {
if (strncmp(dirF->d_name, AFILE, strlen(AFILE)) == 0) {
- afs_snprintf(name, sizeof name, "%s/%s/%s", rootdir,
- dirE->d_name, dirF->d_name);
+ snprintf(name, sizeof name, "%s" OS_DIRSEP "%s/%s",
+ rootdir, dirE->d_name, dirF->d_name);
unlink(name);
}
}
closedir(dirQ);
} else if (strncmp(dirE->d_name, AFILE, strlen(AFILE)) == 0) {
- afs_snprintf(name, sizeof name, "%s/%s", rootdir,
- dirE->d_name);
+ snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir,
+ dirE->d_name);
unlink(name);
}
}
dirP = opendir(rootdir);
while (dirP && (dirE = readdir(dirP))) {
if (strncmp(dirE->d_name, ADIR, strlen(ADIR)) == 0) {
- afs_snprintf(name, sizeof name, "%s/%s", rootdir, dirE->d_name);
+ snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir,
+ dirE->d_name);
unlink(name);
}
}
return (code);
}
-main(argc, argv)
- int argc;
- char **argv;
+int
+main(int argc, char **argv)
{
struct cmd_syndesc *ts;
- struct cmd_item *ti;
setlinebuf(stdout);
- ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "vldb check");
+ ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, 0, "vldb check");
cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "restore dir");
cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL, "name extension");