}
}
-static void
-ReadByteString(struct iod *iodp, byte * to,
- int size)
+static int
+ReadByteString(struct iod *iodp, byte * to, int size)
{
- while (size--)
- *to++ = iod_getc(iodp);
+ int nbytes = 0;
+ int c;
+
+ while (size-- > 0 && (c = iod_getc(iodp)) != EOF) {
+ *to++ = c;
+ nbytes++;
+ }
+ return nbytes;
}
/*
if (!code)
code = DumpInt32(iodp, 's', v->serverModifyTime);
if (v->type == vDirectory) {
- acl_HtonACL(VVnodeDiskACL(v));
+ code = acl_HtonACL(VVnodeDiskACL(v));
+ if (code) {
+ Log("DumpVnode: Skipping invalid acl vnode %u (volume %"AFS_VOLID_FMT")\n",
+ vnodeNumber, afs_printable_VolumeId_lu(volid));
+ }
if (!code)
code =
DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
int s1 = 0, s2 = 0, delo = 0, tdelo;
int tag;
VolumeDiskData saved_header;
+ afs_uint32 uptime, crtime;
iod_Init(iodp, call);
Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
return VOLSERREAD_DUMPERROR;
}
- if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
+ if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
+ Log("1 Volser: RestoreVolume: Error reading volume header (id: %u); aborted\n",
+ V_id(vp));
return VOLSERREAD_DUMPERROR;
+ }
if (!delo)
delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
tdelo = delo;
while (1) {
if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
+ Log("1 Volser: RestoreVolume: Error reading vnodes (id: %u); aborted\n",
+ V_id(vp));
error = VOLSERREAD_DUMPERROR;
goto clean;
}
break;
if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
+ Log("1 Volser: RestoreVolume: Error reading volume header (id: %u); aborted\n",
+ V_id(vp));
error = VOLSERREAD_DUMPERROR;
goto out;
}
* prevent it from getting overwritten. */
vol.needsSalvaged = V_needsSalvaged(vp);
}
+ crtime = V_creationDate(vp);
+ uptime = V_updateDate(vp);
CopyVolumeHeader(&vol, &V_disk(vp));
V_destroyMe(vp) = 0;
VUpdateVolume(&vupdate, vp);
Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
error = VOLSERREAD_DUMPERROR;
goto out;
+ } else {
+ /*
+ * If the volume was not a new empty volume and the restored dump was
+ * older than the volume in question, this is probably a mistake, and
+ * may mean the resulting volume is corrupted. Log the following message
+ * to give a clue as to why this volume suddenly looks strange or corrupt.
+ */
+ if ((crtime != uptime) && (uptime > V_updateDate(vp))) {
+ Log("1 Volser: RestoreVolume: volume %s (%u) appears to have been partially or "
+ "completely restored to an earlier version (updateDate went from %u to %u). "
+ "This is allowed, but may indicate a mistake in whatever tool is restoring "
+ "this volume. If this volume appears corrupted, this is probably why.\n",
+ V_name(vp), V_id(vp), uptime, V_updateDate(vp));
+ }
}
out:
/* Free the malloced space above */
FdHandle_t *fdP;
Inode nearInode AFS_UNUSED;
afs_int32 critical = 0;
+ int nbytes;
tag = iod_getc(iodp);
V_pref(vp, nearInode);
return VOLSERREAD_DUMPERROR;
break;
case 'A':
- ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
+ nbytes = ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
VAclDiskSize(vnode));
- acl_NtohACL(VVnodeDiskACL(vnode));
+ if (nbytes != VAclDiskSize(vnode)) {
+ Log("ReadVnodes: could not read acl for vnode %lu in dump.\n",
+ (unsigned long)vnodeNumber);
+ return VOLSERREAD_DUMPERROR;
+ }
+ if (acl_NtohACL(VVnodeDiskACL(vnode)) != 0) {
+ Log("ReadVnodes: invalid acl for vnode %lu in dump.\n",
+ (unsigned long)vnodeNumber);
+ return VOLSERREAD_DUMPERROR;
+ }
break;
case 'h':
case 'f':{