2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
19 #include <rx/rx_queue.h>
20 #include <afs/afsint.h>
22 #include <afs/errors.h>
25 #include <afs/ihandle.h>
26 #include <afs/vnode.h>
27 #include <afs/volume.h>
28 #include <afs/partition.h>
29 #include <afs/daemon_com.h>
30 #include <afs/fssync.h>
32 #include <afs/com_err.h>
33 #include <afs/vol_prototypes.h>
38 #include "dumpstuff.h"
42 #define afs_stat stat64
43 #define afs_fstat fstat64
44 #else /* !O_LARGEFILE */
46 #define afs_fstat fstat
47 #endif /* !O_LARGEFILE */
48 #endif /* !AFS_NT40_ENV */
50 /*@printflike@*/ extern void Log(const char *format, ...);
53 extern int DoPreserveVolumeStats;
56 /* Forward Declarations */
57 static int DumpDumpHeader(struct iod *iodp, Volume * vp,
59 static int DumpPartial(struct iod *iodp, Volume * vp,
60 afs_int32 fromtime, int dumpAllDirs);
61 static int DumpVnodeIndex(struct iod *iodp, Volume * vp,
62 VnodeClass class, afs_int32 fromtime,
64 static int DumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
65 VolumeId volid, int vnodeNumber, int dumpEverything);
66 static int ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp);
67 static int ReadVnodes(struct iod *iodp, Volume * vp, afs_foff_t * Lbuf,
68 afs_int32 s1, afs_foff_t * Sbuf, afs_int32 s2,
70 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
71 FdHandle_t * handleP, int tag,
74 static int SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
76 struct volintSize *size);
77 static int SizeDumpPartial(struct iod *iodp, Volume * vp,
78 afs_int32 fromtime, int dumpAllDirs,
79 struct volintSize *size);
80 static int SizeDumpVnodeIndex(struct iod *iodp, Volume * vp,
81 VnodeClass class, afs_int32 fromtime,
83 struct volintSize *size);
84 static int SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
85 VolumeId volid, int vnodeNumber, int dumpEverything,
86 struct volintSize *size);
88 #define MAX_SECTIONS 3
90 /* The TLV range must start above D_MAX */
91 #define MIN_TLV_TAG 21
92 #define MAX_TLV_TAG 0x60
93 #define MAX_STANDARD_TAG 0x7a
94 static afs_uint32 oldtags[MAX_SECTIONS][16];
95 int oldtagsInited = 0;
98 RegisterTag(afs_int32 section, unsigned char tag)
100 afs_uint32 off = tag >> 5;
101 afs_uint32 mask = 1 << (tag & 0x1f);
102 oldtags[section][off] |= mask;
106 initNonStandardTags(void)
108 RegisterTag(0, 'n'); /* volume name */
109 RegisterTag(0, 't'); /* fromtime, V_backupDate */
110 RegisterTag(1, 'A'); /* V_accessDate */
111 RegisterTag(1, 'C'); /* V_creationDate */
112 RegisterTag(1, 'D'); /* V_dayUseDate */
113 RegisterTag(1, 'E'); /* V_expirationDate */
114 RegisterTag(1, 'M'); /* nullstring (motd) */
115 RegisterTag(1, 'U'); /* V_updateDate */
116 RegisterTag(1, 'W'); /* V_weekUse */
117 RegisterTag(1, 'Z'); /* V_dayUse */
118 RegisterTag(1, 'O'); /* V_offlineMessage */
119 RegisterTag(1, 'b'); /* V_blessed */
120 RegisterTag(1, 'n'); /* V_name */
121 RegisterTag(1, 's'); /* V_inService */
122 RegisterTag(1, 't'); /* V_type */
123 RegisterTag(2, 'A'); /* VVnodeDiskACL */
124 RegisterTag(2, 'b'); /* modeBits */
125 RegisterTag(2, 'f'); /* small file */
126 RegisterTag(2, 'h'); /* large file */
127 RegisterTag(2, 'l'); /* linkcount */
128 RegisterTag(2, 't'); /* type */
133 iod_Init(struct iod *iodp, struct rx_call *call)
136 iodp->haveOldChar = 0;
138 iodp->calls = (struct rx_call **)0;
142 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
147 iodp->haveOldChar = 0;
148 iodp->ncalls = ncalls;
150 iodp->call = (struct rx_call *)0;
153 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
154 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
156 /* For the single dump case, it's ok to just return the "bytes written"
157 * that rx_Write returns, since all the callers of iod_Write abort when
158 * the returned value is less than they expect. For the multi dump case,
159 * I don't think we want half the replicas to go bad just because one
160 * connection timed out, but if they all time out, then we should give up.
163 iod_Write(struct iod *iodp, char *buf, int nbytes)
168 opr_Assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
169 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
172 code = rx_Write(iodp->call, buf, nbytes);
176 for (i = 0; i < iodp->ncalls; i++) {
177 if (iodp->calls[i] && !iodp->codes[i]) {
178 code = rx_Write(iodp->calls[i], buf, nbytes);
179 if (code != nbytes) { /* everything gets merged into a single error */
180 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
181 } /* standard dump does, anyways */
186 } /* for all calls */
195 iod_ungetc(struct iod *iodp, int achar)
197 iodp->oldChar = achar;
198 iodp->haveOldChar = 1;
202 iod_getc(struct iod *iodp)
206 if (iodp->haveOldChar) {
207 iodp->haveOldChar = 0;
208 return iodp->oldChar;
210 if (iod_Read(iodp, (char *) &t, 1) == 1)
216 ReadShort(struct iod *iodp, unsigned short *sp)
225 *sp = (b1 << 8) | b0;
230 ReadInt32(struct iod *iodp, afs_uint32 * lp)
232 afs_uint32 b3, b2, b1, b0;
245 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
250 ReadString(struct iod *iodp, char *to, int maxa)
259 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
263 while ((c = iod_getc(iodp)) && c != EOF);
269 ReadByteString(struct iod *iodp, byte * to, int size)
274 while (size-- > 0 && (c = iod_getc(iodp)) != EOF) {
282 * returns 1 on success and 0 otherwise
285 ReadStandardTagLen(struct iod *iodp, unsigned char tag, afs_int32 section,
289 afs_uint32 off = tag >> 5;
290 afs_uint32 mask = 1 << (tag & 0x1f);
292 unsigned char buf[8], *p;
295 initNonStandardTags();
297 if (tag < MIN_TLV_TAG
298 || tag > MAX_STANDARD_TAG
299 || section >= MAX_SECTIONS
300 || (oldtags[section][ off] & mask)) {
301 Log("Trying to use ReadStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
304 if (tag <= MAX_TLV_TAG) {
305 len = iod_getc(iodp);
307 return VOLSERDUMPERROR;
312 if ((code = iod_Read(iodp, (char *)buf, len)) != len)
313 return VOLSERDUMPERROR;
315 p = (unsigned char *)&buf;
316 for (i=0; i<len; i++) {
317 *length = ((*length) << 8) | *p++;
321 if (tag < MAX_STANDARD_TAG)
327 static char skipbuf[256];
330 SkipData(struct iod *iodp, afs_size_t length)
332 while (length > 256) {
333 if (iod_Read(iodp, (char *)&skipbuf, 256) != 256)
337 if (iod_Read(iodp, (char *)&skipbuf, length) != length)
342 static char *secname[3] = {"ReadDumpHeader", "ReadVolumeHeader", "ReadVnodes"};
345 HandleUnknownTag(struct iod *iodp, int tag, afs_int32 section,
348 afs_size_t taglen = 0;
352 Log("%s: unknown critical tag x%02x, aborting\n",
353 secname[section], tag);
356 Log("%s: unknown tag x%02x found, skipping\n", secname[section], tag);
357 if (tag >= 0x06 && tag <= 0x60) {
358 if (!ReadStandardTagLen(iodp, tag, 1, &taglen)) {
359 Log("%s: error reading length field for tag x%02x, aborting\n",
360 secname[section], tag);
363 if (!SkipData(iodp, taglen)) {
364 Log("%s: error skipping %llu bytes for tag x%02x, aborting\n",
365 secname[section], taglen, tag);
370 if (tag >= 0x61 && tag <= 0x7a) {
371 if (!ReadInt32(iodp, &trash)) {
372 Log("%s: error skipping int32 for tag x%02x, aborting\n",
373 secname[section], tag);
378 if (tag >= 0x7b && tag < 0x80) /* dataless tag */
380 Log("%s: unknown invalid tag x%02x, aborting\n", secname[section], tag);
385 ReadVolumeHeader(struct iod *iodp, VolumeDiskData * vol)
389 afs_int32 critical = 0;
390 memset(vol, 0, sizeof(*vol));
391 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
396 if (!ReadInt32(iodp, &vol->id))
397 return VOLSERREAD_DUMPERROR;
400 if (!ReadInt32(iodp, &trash))
401 return VOLSERREAD_DUMPERROR;
404 ReadString(iodp, vol->name, sizeof(vol->name));
405 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
408 vol->inService = iod_getc(iodp);
411 vol->blessed = iod_getc(iodp);
414 if (!ReadInt32(iodp, &vol->uniquifier))
415 return VOLSERREAD_DUMPERROR;
418 vol->type = iod_getc(iodp);
421 if (!ReadInt32(iodp, &vol->parentId))
422 return VOLSERREAD_DUMPERROR;
425 if (!ReadInt32(iodp, &vol->cloneId))
426 return VOLSERREAD_DUMPERROR;
429 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
430 return VOLSERREAD_DUMPERROR;
433 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
434 return VOLSERREAD_DUMPERROR;
437 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
438 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
441 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
442 return VOLSERREAD_DUMPERROR;
445 if (!ReadInt32(iodp, &vol->accountNumber))
446 return VOLSERREAD_DUMPERROR;
449 if (!ReadInt32(iodp, &vol->owner))
450 return VOLSERREAD_DUMPERROR;
453 if (!ReadInt32(iodp, &vol->creationDate))
454 return VOLSERREAD_DUMPERROR;
457 if (!ReadInt32(iodp, &vol->accessDate))
458 return VOLSERREAD_DUMPERROR;
461 if (!ReadInt32(iodp, &vol->updateDate))
462 return VOLSERREAD_DUMPERROR;
465 if (!ReadInt32(iodp, &vol->expirationDate))
466 return VOLSERREAD_DUMPERROR;
469 if (!ReadInt32(iodp, &vol->backupDate))
470 return VOLSERREAD_DUMPERROR;
473 ReadString(iodp, vol->offlineMessage,
474 sizeof(vol->offlineMessage));
478 * Detailed volume statistics are never stored in dumps,
479 * so we just restore either the null string if this volume
480 * had already been set to store statistics, or the old motd
481 * contents otherwise. It doesn't matter, since this field
482 * will soon get initialized anyway.
484 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
487 unsigned short length;
490 if (!ReadShort(iodp, &length))
491 return VOLSERREAD_DUMPERROR;
492 for (i = 0; i < length; i++) {
493 if (!ReadInt32(iodp, &data))
494 return VOLSERREAD_DUMPERROR;
495 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
496 vol->weekUse[i] = data;
501 if (!ReadInt32(iodp, &vol->dayUseDate))
502 return VOLSERREAD_DUMPERROR;
505 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
506 return VOLSERREAD_DUMPERROR;
509 if (!ReadInt32(iodp, (afs_uint32 *) &trash/*volUpdateCounter*/))
510 return VOLSERREAD_DUMPERROR;
516 if (!HandleUnknownTag(iodp, tag, 1, critical))
517 return VOLSERREAD_DUMPERROR;
520 iod_ungetc(iodp, tag);
525 DumpTag(struct iod *iodp, int tag)
530 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
535 DumpByte(struct iod *iodp, char tag, byte value)
538 byte *p = (unsigned char *)tbuffer;
541 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
544 #define afs_putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
545 #define afs_putshort(p, v) *p++ = v>>8, *p++ = v
548 DumpDouble(struct iod *iodp, char tag, afs_uint32 value1,
552 byte *p = (unsigned char *)tbuffer;
554 afs_putint32(p, value1);
555 afs_putint32(p, value2);
556 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
560 DumpInt32(struct iod *iodp, char tag, afs_uint32 value)
563 byte *p = (unsigned char *)tbuffer;
565 afs_putint32(p, value);
566 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
570 DumpArrayInt32(struct iod *iodp, char tag,
571 afs_uint32 * array, int nelem)
576 byte *p = (unsigned char *)tbuffer;
578 afs_putshort(p, nelem);
579 code = iod_Write(iodp, tbuffer, 3);
581 return VOLSERDUMPERROR;
583 p = (unsigned char *)tbuffer;
584 v = *array++; /*this was register */
587 code = iod_Write(iodp, tbuffer, 4);
589 return VOLSERDUMPERROR;
595 DumpShort(struct iod *iodp, char tag, unsigned int value)
598 byte *p = (unsigned char *)tbuffer;
602 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
606 DumpBool(struct iod *iodp, char tag, unsigned int value)
609 byte *p = (unsigned char *)tbuffer;
612 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
616 DumpString(struct iod *iodp, char tag, char *s)
620 code = iod_Write(iodp, &tag, 1);
622 return VOLSERDUMPERROR;
624 code = iod_Write(iodp, s, n);
626 return VOLSERDUMPERROR;
631 DumpByteString(struct iod *iodp, char tag, byte * bs,
636 code = iod_Write(iodp, &tag, 1);
638 return VOLSERDUMPERROR;
639 code = iod_Write(iodp, (char *)bs, nbytes);
641 return VOLSERDUMPERROR;
646 DumpStandardTag(struct iod *iodp, char tag, afs_uint32 section)
649 afs_uint32 off = tag >> 5;
650 afs_uint32 mask = 1 << (tag & 0x1f);
653 initNonStandardTags();
655 if (tag < MIN_TLV_TAG
656 || tag > MAX_STANDARD_TAG
657 || section >= MAX_SECTIONS
658 || (oldtags[section][ off] & mask)) {
659 Log("Trying to use DumpStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
660 return VOLSERDUMPERROR;
662 code = iod_Write(iodp, &tag, 1);
664 return VOLSERDUMPERROR;
670 DumpStandardTagLen(struct iod *iodp, char tag, afs_uint32 section,
677 if (tag < MIN_TLV_TAG || tag > MAX_TLV_TAG) {
678 Log("Trying to use DumpStandardTagLen with tag 0x%02x for section %d, aborting\n", tag, section);
679 return VOLSERDUMPERROR;
681 code = DumpStandardTag(iodp, tag, section);
685 if (length < 128) { /* byte after tag contains length */
688 } else { /* byte after tag contains length of length field | 0x80 */
689 for (len=0; length; length=length >> 8) {
697 code = iod_Write(iodp, p, len);
699 return VOLSERDUMPERROR;
704 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
706 int code = 0, error = 0;
707 afs_sfsize_t nbytes, howBig, howMany;
709 afs_foff_t howFar = 0;
714 code = FDH_BLOCKSIZE(handleP, &howBig, &howMany);
716 Log("DumpFile: FDH_BLOCKSIZE returned error code %d on descriptor %d\n",
717 code, handleP->fd_fd);
718 return VOLSERDUMPERROR;
721 SplitInt64(howBig, hi, lo);
723 code = DumpInt32(iodp, 'f', lo);
725 code = DumpDouble(iodp, 'h', hi, lo);
728 return VOLSERDUMPERROR;
733 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", (unsigned)howMany);
734 return VOLSERDUMPERROR;
737 for (nbytes = howBig; (nbytes && !error); ) {
738 if (nbytes < howMany)
742 n = FDH_PREAD(handleP, p, howMany, howFar);
744 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d: %s\n",
745 PrintInode(stmp, handleP->fd_ih->ih_ino), vnode,
746 afs_error_message(errno));
747 error = VOLSERDUMPERROR;
750 Log("1 Volser: DumpFile: Premature EOF reading inode %s for vnode %d\n",
751 PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
752 error = VOLSERDUMPERROR;
761 /* Now write the data out */
762 if (iod_Write(iodp, (char *)p, n) != n)
763 error = VOLSERDUMPERROR;
764 #ifndef AFS_PTHREAD_ENV
774 DumpVolumeHeader(struct iod *iodp, Volume * vp)
777 static char nullString[1] = ""; /*The ``contents'' of motd */
780 code = DumpTag(iodp, D_VOLUMEHEADER);
782 code = DumpInt32(iodp, 'i', V_id(vp));
785 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
787 code = DumpString(iodp, 'n', V_name(vp));
789 code = DumpBool(iodp, 's', V_inService(vp));
791 code = DumpBool(iodp, 'b', V_blessed(vp));
793 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
795 code = DumpByte(iodp, 't', (byte) V_type(vp));
797 code = DumpInt32(iodp, 'p', V_parentId(vp));
800 code = DumpInt32(iodp, 'c', V_cloneId(vp));
802 code = DumpInt32(iodp, 'q', V_maxquota(vp));
804 code = DumpInt32(iodp, 'm', V_minquota(vp));
806 code = DumpInt32(iodp, 'd', V_diskused(vp));
808 code = DumpInt32(iodp, 'f', V_filecount(vp));
810 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
812 code = DumpInt32(iodp, 'o', V_owner(vp));
814 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
816 code = DumpInt32(iodp, 'A', V_accessDate(vp));
818 code = DumpInt32(iodp, 'U', V_updateDate(vp));
820 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
822 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
824 code = DumpString(iodp, 'O', V_offlineMessage(vp));
826 * We do NOT dump the detailed volume statistics residing in the old
827 * motd field, since we cannot tell from the info in a dump whether
828 * statistics data has been put there. Instead, we dump a null string,
829 * just as if that was what the motd contained.
832 code = DumpString(iodp, 'M', nullString);
835 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
836 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
838 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
840 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
845 DumpEnd(struct iod *iodp)
847 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
850 /* Guts of the dump code */
852 /* Dump a whole volume */
854 DumpVolume(struct rx_call *call, Volume * vp,
855 afs_int32 fromtime, int dumpAllDirs)
859 struct iod *iodp = &iod;
860 iod_Init(iodp, call);
863 code = DumpDumpHeader(iodp, vp, fromtime);
866 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
868 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
869 if (rx_Error(iodp->call)) {
870 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
871 rx_Error(iodp->call));
872 return VOLSERDUMPERROR;
875 code = DumpEnd(iodp);
880 /* Dump a volume to multiple places*/
882 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
883 afs_int32 fromtime, int dumpAllDirs, int *codes)
887 iod_InitMulti(&iod, calls, ncalls, codes);
890 code = DumpDumpHeader(&iod, vp, fromtime);
892 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
894 code = DumpEnd(&iod);
898 /* A partial dump (no dump header) */
900 DumpPartial(struct iod *iodp, Volume * vp,
901 afs_int32 fromtime, int dumpAllDirs)
905 code = DumpVolumeHeader(iodp, vp);
907 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
909 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
914 DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
915 afs_int32 fromtime, int forcedump)
918 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
919 char buf[SIZEOF_LARGEDISKVNODE];
920 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
921 StreamHandle_t *file;
923 afs_sfsize_t size, nVnodes;
927 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
928 opr_Assert(fdP != NULL);
929 file = FDH_FDOPEN(fdP, "r+");
930 opr_Assert(file != NULL);
931 size = FDH_SIZE(fdP);
932 opr_Assert(size != -1);
933 nVnodes = (size / vcp->diskSize) - 1;
935 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
936 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
940 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
941 nVnodes--, vnodeIndex++) {
942 flag = forcedump || (vnode->serverModifyTime >= fromtime);
943 /* Note: the >= test is very important since some old volumes may not have
944 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
945 * does dump the file! */
948 DumpVnode(iodp, vnode, V_id(vp),
949 bitNumberToVnodeNumber(vnodeIndex, class), flag);
950 #ifndef AFS_PTHREAD_ENV
952 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
961 DumpDumpHeader(struct iod *iodp, Volume * vp,
965 int UseLatestReadOnlyClone = 1;
966 afs_int32 dumpTimes[2];
967 iodp->device = vp->device;
968 iodp->parentId = V_parentId(vp);
969 iodp->dumpPartition = vp->partition;
971 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
975 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
977 code = DumpString(iodp, 'n', V_name(vp));
978 dumpTimes[0] = fromtime;
979 switch (V_type(vp)) {
980 case readwriteVolume:
981 dumpTimes[1] = V_updateDate(vp); /* until last update */
984 dumpTimes[1] = V_creationDate(vp); /* until clone was updated */
987 /* until backup was made */
988 dumpTimes[1] = V_backupDate(vp) != 0 ? V_backupDate(vp) :
995 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
1000 DumpVnode(struct iod *iodp, struct VnodeDiskObject *v, VolumeId volid,
1001 int vnodeNumber, int dumpEverything)
1008 if (!v || v->type == vNull)
1011 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
1012 if (!dumpEverything)
1015 code = DumpByte(iodp, 't', (byte) v->type);
1017 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
1019 code = DumpInt32(iodp, 'v', v->dataVersion);
1021 code = DumpInt32(iodp, 'm', v->unixModifyTime);
1023 code = DumpInt32(iodp, 'a', v->author);
1025 code = DumpInt32(iodp, 'o', v->owner);
1026 if (!code && v->group)
1027 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
1029 code = DumpShort(iodp, 'b', v->modeBits);
1031 code = DumpInt32(iodp, 'p', v->parent);
1033 code = DumpInt32(iodp, 's', v->serverModifyTime);
1034 if (v->type == vDirectory) {
1035 code = acl_HtonACL(VVnodeDiskACL(v));
1037 Log("DumpVnode: Skipping invalid acl vnode %u (volume %"AFS_VOLID_FMT")\n",
1038 vnodeNumber, afs_printable_VolumeId_lu(volid));
1042 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
1045 if (VNDISK_GET_INO(v)) {
1046 afs_sfsize_t indexlen, disklen;
1047 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1050 Log("1 Volser: DumpVnode: dump: Unable to open inode %s "
1051 "for vnode %u (volume %" AFS_VOLID_FMT "); "
1052 "not dumped, error %d\n",
1053 PrintInode(stmp, VNDISK_GET_INO(v)), vnodeNumber,
1054 afs_printable_VolumeId_lu(volid), errno);
1056 return VOLSERREAD_DUMPERROR;
1058 VNDISK_GET_LEN(indexlen, v);
1059 disklen = FDH_SIZE(fdP);
1060 if (indexlen != disklen) {
1061 FDH_REALLYCLOSE(fdP);
1063 Log("DumpVnode: volume %"AFS_VOLID_FMT" "
1064 "vnode %lu has inconsistent length "
1065 "(index %lu disk %lu); aborting dump\n",
1066 afs_printable_VolumeId_lu(volid), (unsigned long)vnodeNumber,
1067 (unsigned long)indexlen, (unsigned long)disklen);
1068 return VOLSERREAD_DUMPERROR;
1070 code = DumpFile(iodp, vnodeNumber, fdP);
1079 ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep,
1082 int i, nVnodes, code;
1086 StreamHandle_t *afile;
1088 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1089 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1090 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1093 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1094 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1097 afile = FDH_FDOPEN(fdP, "r+");
1101 for (i = 0; i < *sizep; i++) {
1103 STREAM_ASEEK(afile, Buf[i]);
1104 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1106 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1109 Log("RestoreVolume %"AFS_VOLID_FMT" "
1110 "Cleanup: Removing old vnode=%u inode=%s "
1112 afs_printable_VolumeId_lu(V_id(vp)),
1113 bitNumberToVnodeNumber(i, class),
1114 PrintInode(stmp, VNDISK_GET_INO(vnode)));
1116 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1120 STREAM_ASEEK(afile, Buf[i]);
1121 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1127 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1130 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1131 OS_SYNC(afile->str_fd);
1133 size = FDH_SIZE(fdP);
1134 opr_Assert(size != -1);
1137 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1139 Buf = calloc(nVnodes, sizeof(afs_foff_t));
1141 STREAM_CLOSE(afile);
1145 STREAM_ASEEK(afile, offset = vcp->diskSize);
1147 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1151 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1152 Buf[(offset >> vcp->logSize) - 1] = offset;
1154 offset += vcp->diskSize;
1160 STREAM_CLOSE(afile);
1167 RestoreVolume(struct rx_call *call, Volume * avp, struct restoreCookie *cookie)
1170 struct DumpHeader header;
1171 afs_uint32 endMagic;
1172 Error error = 0, vupdate;
1175 struct iod *iodp = &iod;
1176 afs_foff_t *b1 = NULL, *b2 = NULL;
1177 int s1 = 0, s2 = 0, delo = 0, tdelo;
1179 VolumeDiskData saved_header;
1180 afs_uint32 uptime, crtime;
1182 iod_Init(iodp, call);
1186 if (DoPreserveVolumeStats) {
1187 CopyVolumeStats(&V_disk(vp), &saved_header);
1190 if (!ReadDumpHeader(iodp, &header)) {
1191 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1192 return VOLSERREAD_DUMPERROR;
1194 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1195 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1196 return VOLSERREAD_DUMPERROR;
1198 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1199 Log("1 Volser: RestoreVolume: Error reading volume header (id: %u); aborted\n",
1201 return VOLSERREAD_DUMPERROR;
1205 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1207 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1209 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1210 error = VOLSERREAD_DUMPERROR;
1214 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1215 vol.type = cookie->type;
1216 vol.cloneId = cookie->clone;
1217 vol.parentId = cookie->parent;
1219 V_needsSalvaged(vp) = 0;
1223 if (ReadVnodes(iodp, vp, b1, s1, b2, s2, tdelo)) {
1224 Log("1 Volser: RestoreVolume: Error reading vnodes (id: %u); aborted\n",
1226 error = VOLSERREAD_DUMPERROR;
1229 tag = iod_getc(iodp);
1230 if (tag != D_VOLUMEHEADER)
1233 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1234 Log("1 Volser: RestoreVolume: Error reading volume header (id: %u); aborted\n",
1236 error = VOLSERREAD_DUMPERROR;
1240 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1241 || endMagic != DUMPENDMAGIC) {
1242 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1243 error = VOLSERREAD_DUMPERROR;
1248 if (iod_getc(iodp) != EOF) {
1249 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1250 error = VOLSERREAD_DUMPERROR;
1255 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1257 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1259 error = VOLSERREAD_DUMPERROR;
1265 if (DoPreserveVolumeStats) {
1266 CopyVolumeStats(&saved_header, &vol);
1268 ClearVolumeStats(&vol);
1270 if (V_needsSalvaged(vp)) {
1271 /* needsSalvaged may have been set while we tried to write volume data.
1272 * prevent it from getting overwritten. */
1273 vol.needsSalvaged = V_needsSalvaged(vp);
1275 crtime = V_creationDate(vp);
1276 uptime = V_updateDate(vp);
1277 CopyVolumeHeader(&vol, &V_disk(vp));
1278 V_destroyMe(vp) = 0;
1279 VUpdateVolume(&vupdate, vp);
1281 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1282 error = VOLSERREAD_DUMPERROR;
1286 * If the volume was not a new empty volume and the restored dump was
1287 * older than the volume in question, this is probably a mistake, and
1288 * may mean the resulting volume is corrupted. Log the following message
1289 * to give a clue as to why this volume suddenly looks strange or corrupt.
1291 if ((crtime != uptime) && (uptime > V_updateDate(vp))) {
1292 Log("1 Volser: RestoreVolume: volume %s (%u) appears to have been partially or "
1293 "completely restored to an earlier version (updateDate went from %u to %u). "
1294 "This is allowed, but may indicate a mistake in whatever tool is restoring "
1295 "this volume. If this volume appears corrupted, this is probably why.\n",
1296 V_name(vp), V_id(vp), uptime, V_updateDate(vp));
1300 /* Free the malloced space above */
1309 ReadVnodes(struct iod *iodp, Volume * vp, afs_foff_t * Lbuf, afs_int32 s1,
1310 afs_foff_t * Sbuf, afs_int32 s2, afs_int32 delo)
1312 afs_int32 vnodeNumber;
1313 char buf[SIZEOF_LARGEDISKVNODE];
1315 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1316 struct VnodeDiskObject oldvnode;
1319 struct VnodeClassInfo *vcp;
1322 Inode nearInode AFS_UNUSED;
1323 afs_int32 critical = 0;
1326 tag = iod_getc(iodp);
1327 V_pref(vp, nearInode);
1328 while (tag == D_VNODE) {
1331 memset(buf, 0, sizeof(buf));
1332 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1335 if (!ReadInt32(iodp, &vnode->uniquifier))
1336 return VOLSERREAD_DUMPERROR;
1338 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1344 vnode->type = (VnodeType) iod_getc(iodp);
1349 if (!ReadShort(iodp, &tlc))
1350 return VOLSERREAD_DUMPERROR;
1351 vnode->linkCount = (signed int)tlc;
1355 if (!ReadInt32(iodp, &vnode->dataVersion))
1356 return VOLSERREAD_DUMPERROR;
1359 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1360 return VOLSERREAD_DUMPERROR;
1363 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1364 return VOLSERREAD_DUMPERROR;
1367 if (!ReadInt32(iodp, &vnode->author))
1368 return VOLSERREAD_DUMPERROR;
1371 if (!ReadInt32(iodp, &vnode->owner))
1372 return VOLSERREAD_DUMPERROR;
1375 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1376 return VOLSERREAD_DUMPERROR;
1379 unsigned short modeBits;
1380 if (!ReadShort(iodp, &modeBits))
1381 return VOLSERREAD_DUMPERROR;
1382 vnode->modeBits = (unsigned int)modeBits;
1386 if (!ReadInt32(iodp, &vnode->parent))
1387 return VOLSERREAD_DUMPERROR;
1390 nbytes = ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1391 VAclDiskSize(vnode));
1392 if (nbytes != VAclDiskSize(vnode)) {
1393 Log("ReadVnodes: could not read acl for vnode %lu in dump.\n",
1394 (unsigned long)vnodeNumber);
1395 return VOLSERREAD_DUMPERROR;
1397 if (acl_NtohACL(VVnodeDiskACL(vnode)) != 0) {
1398 Log("ReadVnodes: invalid acl for vnode %lu in dump.\n",
1399 (unsigned long)vnodeNumber);
1400 return VOLSERREAD_DUMPERROR;
1407 afs_fsize_t vnodeLength;
1410 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1411 "file entries for vnode %lu in dump\n",
1412 (unsigned long)vnodeNumber);
1413 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1419 IH_CREATE_INIT(V_linkHandle(vp), V_device(vp),
1420 VPartitionPath(V_partition(vp)), nearInode,
1421 V_parentId(vp), vnodeNumber,
1422 vnode->uniquifier, vnode->dataVersion);
1424 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1425 afs_error_message(errno));
1426 V_needsSalvaged(vp) = 1;
1427 return VOLSERREAD_DUMPERROR;
1431 VNDISK_SET_INO(vnode, ino);
1432 fdP = IH_OPEN(tmpH);
1434 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1435 afs_error_message(errno));
1437 V_needsSalvaged(vp) = 1;
1438 return VOLSERREAD_DUMPERROR;
1441 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1442 VNDISK_SET_LEN(vnode, vnodeLength);
1443 FDH_REALLYCLOSE(fdP);
1446 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1447 (afs_uintmax_t) ino);
1448 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1449 V_needsSalvaged(vp) = 1;
1450 return VOLSERREAD_DUMPERROR;
1458 if (!HandleUnknownTag(iodp, tag, 2, critical))
1459 return VOLSERREAD_DUMPERROR;
1463 class = vnodeIdToClass(vnodeNumber);
1464 vcp = &VnodeClassInfo[class];
1466 /* Mark this vnode as in this dump - so we don't delete it later */
1468 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1469 if (class == vLarge) {
1470 if (Lbuf && (idx < s1))
1473 if (Sbuf && (idx < s2))
1479 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1481 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1482 afs_error_message(errno));
1483 V_needsSalvaged(vp) = 1;
1484 return VOLSERREAD_DUMPERROR;
1486 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1488 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1489 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1493 vnode->vnodeMagic = vcp->magic;
1494 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1495 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1496 afs_error_message(errno));
1497 FDH_REALLYCLOSE(fdP);
1498 V_needsSalvaged(vp) = 1;
1499 return VOLSERREAD_DUMPERROR;
1504 iod_ungetc(iodp, tag);
1510 /* called with disk file only. Note that we don't have to worry about rx_Read
1511 * needing to read an ungetc'd character, since the ReadInt32 will have read
1514 * if handleP == NULL, don't write the file anywhere; just read and discard
1518 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1523 afs_fsize_t filesize;
1524 afs_fsize_t written = 0;
1532 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1534 if (!ReadInt32(iodp, &filesize_high)) {
1539 if (!ReadInt32(iodp, &filesize_low)) {
1543 FillInt64(filesize, filesize_high, filesize_low);
1550 for (nbytes = filesize; nbytes; nbytes -= size) {
1554 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1555 Log("1 Volser: WriteFile: Error reading dump file %d size=%llu nbytes=%u (%d of %u): %s; restore aborted\n", vn, (afs_uintmax_t) filesize, nbytes, code, (unsigned)size, afs_error_message(errno));
1560 nBytes = FDH_PWRITE(handleP, p, size, written);
1563 if (nBytes != size) {
1564 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1575 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1578 afs_uint32 beginMagic;
1579 afs_int32 critical = 0;
1580 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1581 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1582 || beginMagic != DUMPBEGINMAGIC)
1586 while ((tag = iod_getc(iodp)) > D_MAX) {
1587 unsigned short arrayLength;
1593 if (!ReadInt32(iodp, &hp->volumeId))
1597 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1600 if (!ReadShort(iodp, &arrayLength))
1602 hp->nDumpTimes = (arrayLength >> 1);
1603 for (i = 0; i < hp->nDumpTimes; i++)
1604 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1605 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1612 if (!HandleUnknownTag(iodp, tag, 0, critical))
1613 return VOLSERREAD_DUMPERROR;
1616 if (!hp->volumeId || !hp->nDumpTimes) {
1619 iod_ungetc(iodp, tag);
1624 /* ----- Below are the calls that calculate dump size ----- */
1627 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1628 struct volintSize *v_size)
1631 static char nullString[1] = ""; /*The ``contents'' of motd */
1634 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1635 FillInt64(addvar,0, 1);
1636 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1637 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1638 FillInt64(addvar,0, 5);
1639 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1640 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1641 FillInt64(addvar,0, 5);
1642 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1643 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1644 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1645 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1646 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1647 FillInt64(addvar,0, 2);
1648 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1649 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1650 FillInt64(addvar,0, 2);
1651 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1652 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1653 FillInt64(addvar,0, 5);
1654 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1655 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1656 FillInt64(addvar,0, 2);
1657 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1658 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1659 FillInt64(addvar,0, 5);
1660 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1661 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1662 FillInt64(addvar,0, 5);
1663 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1664 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1665 FillInt64(addvar,0, 5);
1666 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1667 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1668 FillInt64(addvar,0, 5);
1669 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1670 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1671 FillInt64(addvar,0, 5);
1672 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1673 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1674 FillInt64(addvar,0, 5);
1675 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1676 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1677 FillInt64(addvar,0, 5);
1678 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1679 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1680 FillInt64(addvar,0, 5);
1681 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1682 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1683 FillInt64(addvar,0, 5);
1684 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1685 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1686 FillInt64(addvar,0, 5);
1687 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1688 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1689 FillInt64(addvar,0, 5);
1690 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1691 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1692 FillInt64(addvar,0, 5);
1693 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1694 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1695 FillInt64(addvar,0, 5);
1696 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1697 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1698 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1699 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1701 /* * We do NOT dump the detailed volume statistics residing in the old */
1702 /* * motd field, since we cannot tell from the info in a dump whether */
1703 /* * statistics data has been put there. Instead, we dump a null string, */
1704 /* * just as if that was what the motd contained. */
1706 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1707 FillInt64(addvar,0, (2 + strlen(nullString)));
1708 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1709 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1710 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1711 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1712 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1713 FillInt64(addvar,0, 5);
1714 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1715 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1716 FillInt64(addvar,0, 5);
1717 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1722 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1726 FillInt64(addvar,0, 5);
1727 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1732 SizeDumpVolume(struct rx_call *call, Volume * vp,
1733 afs_int32 fromtime, int dumpAllDirs,
1734 struct volintSize *v_size)
1737 struct iod *iodp = (struct iod *)0;
1738 /* iod_Init(iodp, call); */
1741 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1743 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1745 code = SizeDumpEnd(iodp, v_size);
1751 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1752 afs_int32 fromtime, struct volintSize *v_size)
1755 /* int UseLatestReadOnlyClone = 1; */
1756 /* afs_int32 dumpTimes[2]; */
1758 /* iodp->device = vp->device; */
1759 /* iodp->parentId = V_parentId(vp); */
1760 /* iodp->dumpPartition = vp->partition; */
1762 ZeroInt64(v_size->dump_size); /* initialize the size */
1763 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1764 FillInt64(addvar,0, 9);
1765 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1766 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1767 FillInt64(addvar,0, 5);
1768 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1769 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1770 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1771 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1772 /* dumpTimes[0] = fromtime; */
1773 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1774 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1775 FillInt64(addvar,0, (3 + 4 * 2));
1776 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1781 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, VolumeId volid,
1782 int vnodeNumber, int dumpEverything,
1783 struct volintSize *v_size)
1788 if (!v || v->type == vNull)
1790 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1791 FillInt64(addvar,0, 9);
1792 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1793 if (!dumpEverything)
1795 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1796 FillInt64(addvar,0, 2);
1797 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1798 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1799 FillInt64(addvar,0, 3);
1800 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1801 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1802 FillInt64(addvar,0, 5);
1803 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1804 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1805 FillInt64(addvar,0, 5);
1806 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1807 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1808 FillInt64(addvar,0, 5);
1809 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1810 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1811 FillInt64(addvar,0, 5);
1812 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1813 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1815 FillInt64(addvar,0, 5);
1816 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1818 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1819 FillInt64(addvar,0, 3);
1820 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1821 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1822 FillInt64(addvar,0, 5);
1823 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1824 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1825 FillInt64(addvar,0, 5);
1826 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1827 if (v->type == vDirectory) {
1828 /* acl_HtonACL(VVnodeDiskACL(v)); */
1829 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1830 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1831 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1834 if (VNDISK_GET_INO(v)) {
1835 VNDISK_GET_LEN(addvar, v);
1836 if (v->vn_length_hi)
1840 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1845 /* A partial dump (no dump header) */
1847 SizeDumpPartial(struct iod *iodp, Volume * vp,
1848 afs_int32 fromtime, int dumpAllDirs,
1849 struct volintSize *v_size)
1853 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1856 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1859 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1864 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1865 afs_int32 fromtime, int forcedump,
1866 struct volintSize *v_size)
1869 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1870 char buf[SIZEOF_LARGEDISKVNODE];
1871 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1872 StreamHandle_t *file;
1874 afs_sfsize_t size, nVnodes;
1878 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1879 opr_Assert(fdP != NULL);
1880 file = FDH_FDOPEN(fdP, "r+");
1881 opr_Assert(file != NULL);
1882 size = FDH_SIZE(fdP);
1883 opr_Assert(size != -1);
1884 nVnodes = (size / vcp->diskSize) - 1;
1886 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
1887 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1890 for (vnodeIndex = 0;
1891 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1892 nVnodes--, vnodeIndex++) {
1893 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1894 /* Note: the >= test is very important since some old volumes may not have
1895 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1896 * does dump the file! */
1899 SizeDumpVnode(iodp, vnode, V_id(vp),
1900 bitNumberToVnodeNumber(vnodeIndex, class), flag,