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>
17 #include <afs/afs_assert.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, ...);
55 /* Forward Declarations */
56 static int DumpDumpHeader(struct iod *iodp, Volume * vp,
58 static int DumpPartial(struct iod *iodp, Volume * vp,
59 afs_int32 fromtime, int dumpAllDirs);
60 static int DumpVnodeIndex(struct iod *iodp, Volume * vp,
61 VnodeClass class, afs_int32 fromtime,
63 static int DumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
64 int volid, int vnodeNumber, int dumpEverything);
65 static int ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp);
66 static int ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
67 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf,
68 afs_int32 s2, afs_int32 delo);
69 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
70 FdHandle_t * handleP, int tag,
73 static int SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
75 struct volintSize *size);
76 static int SizeDumpPartial(struct iod *iodp, Volume * vp,
77 afs_int32 fromtime, int dumpAllDirs,
78 struct volintSize *size);
79 static int SizeDumpVnodeIndex(struct iod *iodp, Volume * vp,
80 VnodeClass class, afs_int32 fromtime,
82 struct volintSize *size);
83 static int SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
84 int volid, int vnodeNumber, int dumpEverything,
85 struct volintSize *size);
87 #define MAX_SECTIONS 3
89 #define MAX_TLV_TAG 0x60
90 #define MAX_STANDARD_TAG 0x7a
91 static afs_uint32 oldtags[MAX_SECTIONS][16];
92 int oldtagsInited = 0;
95 RegisterTag(afs_int32 section, unsigned char tag)
97 afs_uint32 off = tag >> 5;
98 afs_uint32 mask = 1 << (tag & 0x1f);
99 oldtags[section][off] |= mask;
103 initNonStandardTags(void)
105 RegisterTag(0, 'n'); /* volume name */
106 RegisterTag(0, 't'); /* fromtime, V_backupDate */
107 RegisterTag(1, 'A'); /* V_accessDate */
108 RegisterTag(1, 'C'); /* V_creationDate */
109 RegisterTag(1, 'D'); /* V_dayUseDate */
110 RegisterTag(1, 'E'); /* V_expirationDate */
111 RegisterTag(1, 'M'); /* nullstring (motd) */
112 RegisterTag(1, 'U'); /* V_updateDate */
113 RegisterTag(1, 'W'); /* V_weekUse */
114 RegisterTag(1, 'Z'); /* V_dayUse */
115 RegisterTag(1, 'O'); /* V_offlineMessage */
116 RegisterTag(1, 'b'); /* V_blessed */
117 RegisterTag(1, 'n'); /* V_name */
118 RegisterTag(1, 's'); /* V_inService */
119 RegisterTag(1, 't'); /* V_type */
120 RegisterTag(2, 'A'); /* VVnodeDiskACL */
121 RegisterTag(2, 'b'); /* modeBits */
122 RegisterTag(2, 'f'); /* small file */
123 RegisterTag(2, 'h'); /* large file */
124 RegisterTag(2, 'l'); /* linkcount */
125 RegisterTag(2, 't'); /* type */
130 iod_Init(struct iod *iodp, struct rx_call *call)
133 iodp->haveOldChar = 0;
135 iodp->calls = (struct rx_call **)0;
139 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
144 iodp->haveOldChar = 0;
145 iodp->ncalls = ncalls;
147 iodp->call = (struct rx_call *)0;
150 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
151 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
153 /* For the single dump case, it's ok to just return the "bytes written"
154 * that rx_Write returns, since all the callers of iod_Write abort when
155 * the returned value is less than they expect. For the multi dump case,
156 * I don't think we want half the replicas to go bad just because one
157 * connection timed out, but if they all time out, then we should give up.
160 iod_Write(struct iod *iodp, char *buf, int nbytes)
165 osi_Assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
166 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
169 code = rx_Write(iodp->call, buf, nbytes);
173 for (i = 0; i < iodp->ncalls; i++) {
174 if (iodp->calls[i] && !iodp->codes[i]) {
175 code = rx_Write(iodp->calls[i], buf, nbytes);
176 if (code != nbytes) { /* everything gets merged into a single error */
177 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
178 } /* standard dump does, anyways */
183 } /* for all calls */
192 iod_ungetc(struct iod *iodp, int achar)
194 iodp->oldChar = achar;
195 iodp->haveOldChar = 1;
199 iod_getc(struct iod *iodp)
203 if (iodp->haveOldChar) {
204 iodp->haveOldChar = 0;
205 return iodp->oldChar;
207 if (iod_Read(iodp, (char *) &t, 1) == 1)
213 ReadShort(struct iod *iodp, unsigned short *sp)
222 *sp = (b1 << 8) | b0;
227 ReadInt32(struct iod *iodp, afs_uint32 * lp)
229 afs_uint32 b3, b2, b1, b0;
242 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
247 ReadString(struct iod *iodp, char *to, int maxa)
256 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
260 while ((c = iod_getc(iodp)) && c != EOF);
266 ReadByteString(struct iod *iodp, byte * to,
270 *to++ = iod_getc(iodp);
274 * returns 1 on success and 0 otherwise
277 ReadStandardTagLen(struct iod *iodp, unsigned char tag, afs_int32 section,
281 afs_uint32 off = tag >> 5;
282 afs_uint32 mask = 1 << (tag & 0x1f);
283 unsigned char len, buf[8], *p;
286 initNonStandardTags();
288 if (tag < MIN_TLV_TAG
289 || tag > MAX_STANDARD_TAG
290 || section >= MAX_SECTIONS
291 || (oldtags[section][ off] & mask)) {
292 Log("Trying to use ReadStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
295 if (tag <= MAX_TLV_TAG) {
296 len = iod_getc(iodp);
301 if ((code = iod_Read(iodp, (char *)buf, len)) != len)
302 return VOLSERDUMPERROR;
304 p = (unsigned char *)&buf;
305 for (i=0; i<len; i++) {
306 *length = ((*length) << 8) | *p++;
310 if (tag < MAX_STANDARD_TAG)
316 static char skipbuf[256];
319 SkipData(struct iod *iodp, afs_size_t length)
321 while (length > 256) {
322 if (iod_Read(iodp, (char *)&skipbuf, 256) != 256)
326 if (iod_Read(iodp, (char *)&skipbuf, length) != length)
331 static char *secname[3] = {"ReadDumpHeader", "ReadVolumeHeader", "ReadVnodes"};
334 HandleUnknownTag(struct iod *iodp, int tag, afs_int32 section,
337 afs_size_t taglen = 0;
341 Log("%s: unknown critical tag x%02x, aborting\n",
342 secname[section], tag);
345 Log("%s: unknown tag x%02x found, skipping\n", secname[section], tag);
346 if (tag >= 0x06 && tag <= 0x60) {
347 if (!ReadStandardTagLen(iodp, tag, 1, &taglen)) {
348 Log("%s: error reading length field for tag x%02x, aborting\n",
349 secname[section], tag);
352 if (!SkipData(iodp, taglen)) {
353 Log("%s: error skipping %llu bytes for tag x%02x, aborting\n",
354 secname[section], taglen, tag);
359 if (tag >= 0x61 && tag <= 0x7a) {
360 if (!ReadInt32(iodp, &trash)) {
361 Log("%s: error skipping int32 for tag x%02x, aborting\n",
362 secname[section], tag);
367 if (tag >= 0x7b && tag < 0x80) /* dataless tag */
369 Log("%s: unknown invalid tag x%02x, aborting\n", secname[section], tag);
374 ReadVolumeHeader(struct iod *iodp, VolumeDiskData * vol)
378 afs_int32 critical = 0;
379 memset(vol, 0, sizeof(*vol));
380 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
385 if (!ReadInt32(iodp, &vol->id))
386 return VOLSERREAD_DUMPERROR;
389 if (!ReadInt32(iodp, &trash))
390 return VOLSERREAD_DUMPERROR;
393 ReadString(iodp, vol->name, sizeof(vol->name));
394 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
397 vol->inService = iod_getc(iodp);
400 vol->blessed = iod_getc(iodp);
403 if (!ReadInt32(iodp, &vol->uniquifier))
404 return VOLSERREAD_DUMPERROR;
407 vol->type = iod_getc(iodp);
410 if (!ReadInt32(iodp, &vol->parentId))
411 return VOLSERREAD_DUMPERROR;
414 if (!ReadInt32(iodp, &vol->cloneId))
415 return VOLSERREAD_DUMPERROR;
418 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
419 return VOLSERREAD_DUMPERROR;
422 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
423 return VOLSERREAD_DUMPERROR;
426 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
427 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
430 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
431 return VOLSERREAD_DUMPERROR;
434 if (!ReadInt32(iodp, &vol->accountNumber))
435 return VOLSERREAD_DUMPERROR;
438 if (!ReadInt32(iodp, &vol->owner))
439 return VOLSERREAD_DUMPERROR;
442 if (!ReadInt32(iodp, &vol->creationDate))
443 return VOLSERREAD_DUMPERROR;
446 if (!ReadInt32(iodp, &vol->accessDate))
447 return VOLSERREAD_DUMPERROR;
450 if (!ReadInt32(iodp, &vol->updateDate))
451 return VOLSERREAD_DUMPERROR;
454 if (!ReadInt32(iodp, &vol->expirationDate))
455 return VOLSERREAD_DUMPERROR;
458 if (!ReadInt32(iodp, &vol->backupDate))
459 return VOLSERREAD_DUMPERROR;
462 ReadString(iodp, vol->offlineMessage,
463 sizeof(vol->offlineMessage));
467 * Detailed volume statistics are never stored in dumps,
468 * so we just restore either the null string if this volume
469 * had already been set to store statistics, or the old motd
470 * contents otherwise. It doesn't matter, since this field
471 * will soon get initialized anyway.
473 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
476 unsigned short length;
479 if (!ReadShort(iodp, &length))
480 return VOLSERREAD_DUMPERROR;
481 for (i = 0; i < length; i++) {
482 if (!ReadInt32(iodp, &data))
483 return VOLSERREAD_DUMPERROR;
484 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
485 vol->weekUse[i] = data;
490 if (!ReadInt32(iodp, &vol->dayUseDate))
491 return VOLSERREAD_DUMPERROR;
494 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
495 return VOLSERREAD_DUMPERROR;
498 if (!ReadInt32(iodp, (afs_uint32 *) &trash/*volUpdateCounter*/))
499 return VOLSERREAD_DUMPERROR;
505 if (!HandleUnknownTag(iodp, tag, 1, critical))
506 return VOLSERREAD_DUMPERROR;
509 iod_ungetc(iodp, tag);
514 DumpTag(struct iod *iodp, int tag)
519 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
524 DumpByte(struct iod *iodp, char tag, byte value)
527 byte *p = (unsigned char *)tbuffer;
530 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
533 #define afs_putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
534 #define afs_putshort(p, v) *p++ = v>>8, *p++ = v
537 DumpDouble(struct iod *iodp, char tag, afs_uint32 value1,
541 byte *p = (unsigned char *)tbuffer;
543 afs_putint32(p, value1);
544 afs_putint32(p, value2);
545 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
549 DumpInt32(struct iod *iodp, char tag, afs_uint32 value)
552 byte *p = (unsigned char *)tbuffer;
554 afs_putint32(p, value);
555 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
559 DumpArrayInt32(struct iod *iodp, char tag,
560 afs_uint32 * array, int nelem)
565 byte *p = (unsigned char *)tbuffer;
567 afs_putshort(p, nelem);
568 code = iod_Write(iodp, tbuffer, 3);
570 return VOLSERDUMPERROR;
572 p = (unsigned char *)tbuffer;
573 v = *array++; /*this was register */
576 code = iod_Write(iodp, tbuffer, 4);
578 return VOLSERDUMPERROR;
584 DumpShort(struct iod *iodp, char tag, unsigned int value)
587 byte *p = (unsigned char *)tbuffer;
591 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
595 DumpBool(struct iod *iodp, char tag, unsigned int value)
598 byte *p = (unsigned char *)tbuffer;
601 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
605 DumpString(struct iod *iodp, char tag, char *s)
609 code = iod_Write(iodp, &tag, 1);
611 return VOLSERDUMPERROR;
613 code = iod_Write(iodp, s, n);
615 return VOLSERDUMPERROR;
620 DumpByteString(struct iod *iodp, char tag, byte * bs,
625 code = iod_Write(iodp, &tag, 1);
627 return VOLSERDUMPERROR;
628 code = iod_Write(iodp, (char *)bs, nbytes);
630 return VOLSERDUMPERROR;
635 DumpStandardTag(struct iod *iodp, char tag, afs_uint32 section)
638 afs_uint32 off = tag >> 5;
639 afs_uint32 mask = 1 << (tag & 0x1f);
642 initNonStandardTags();
644 if (tag < MIN_TLV_TAG
645 || tag > MAX_STANDARD_TAG
646 || section >= MAX_SECTIONS
647 || (oldtags[section][ off] & mask)) {
648 Log("Trying to use DumpStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
649 return VOLSERDUMPERROR;
651 code = iod_Write(iodp, &tag, 1);
653 return VOLSERDUMPERROR;
659 DumpStandardTagLen(struct iod *iodp, char tag, afs_uint32 section,
666 if (tag < MIN_TLV_TAG || tag > MAX_TLV_TAG) {
667 Log("Trying to use DumpStandardTagLen with tag 0x%02x for section %d, aborting\n", tag, section);
668 return VOLSERDUMPERROR;
670 code = DumpStandardTag(iodp, tag, section);
674 if (length < 128) { /* byte after tag contains length */
677 } else { /* byte after tag contains length of length field | 0x80 */
678 for (len=0; length; length=length >> 8) {
686 code = iod_Write(iodp, p, len);
688 return VOLSERDUMPERROR;
693 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
695 int code = 0, error = 0;
697 afs_foff_t offset = 0;
698 afs_sfsize_t nbytes, howBig;
701 afs_foff_t howFar = 0;
706 struct afs_stat status;
709 #include <sys/statfs.h>
710 #if defined(AFS_AIX52_ENV)
711 struct statfs64 tstatfs;
712 #else /* !AFS_AIX52_ENV */
713 struct statfs tstatfs;
714 #endif /* !AFS_AIX52_ENV */
719 howBig = _filelength(handleP->fd_fd);
723 afs_fstat(handleP->fd_fd, &status);
724 howBig = status.st_size;
727 /* Unfortunately in AIX valuable fields such as st_blksize are
728 * gone from the stat structure.
730 #if defined(AFS_AIX52_ENV)
731 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
732 #else /* !AFS_AIX52_ENV */
733 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
734 #endif /* !AFS_AIX52_ENV */
735 if (statfs_code != 0) {
736 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
737 return VOLSERDUMPERROR;
739 howMany = tstatfs.f_bsize;
741 howMany = status.st_blksize;
742 #endif /* AFS_AIX_ENV */
743 #endif /* AFS_NT40_ENV */
746 SplitInt64(howBig, hi, lo);
748 code = DumpInt32(iodp, 'f', lo);
750 code = DumpDouble(iodp, 'h', hi, lo);
753 return VOLSERDUMPERROR;
758 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", (unsigned)howMany);
759 return VOLSERDUMPERROR;
762 for (nbytes = howBig; (nbytes && !error); nbytes -= howMany) {
763 if (nbytes < howMany)
767 n = FDH_PREAD(handleP, p, howMany, howFar);
770 /* If read any good data and we null padded previously, log the
771 * amount that we had null padded.
773 if ((n > 0) && pad) {
774 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %lld\n", pad, (long long)offset);
778 /* If didn't read enough data, null padd the rest of the buffer. This
779 * can happen if, for instance, the media has some bad spots. We don't
780 * want to quit the dump, so we start null padding.
783 /* Record the read error */
786 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d: %s\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode, afs_error_message(errno));
788 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
791 /* Pad the rest of the buffer with zeros. Remember offset we started
792 * padding. Keep total tally of padding.
794 memset(p + n, 0, howMany - n);
796 offset = (howBig - nbytes) + n;
797 pad += (howMany - n);
799 /* Now seek over the data we could not get. An error here means we
800 * can't do the next read.
802 howFar = (size_t)((howBig - nbytes) + howMany);
805 /* Now write the data out */
806 if (iod_Write(iodp, (char *)p, howMany) != howMany)
807 error = VOLSERDUMPERROR;
808 #ifndef AFS_PTHREAD_ENV
813 if (pad) { /* Any padding we hadn't reported yet */
814 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %lld\n",
815 pad, (long long)offset);
823 DumpVolumeHeader(struct iod *iodp, Volume * vp)
826 static char nullString[1] = ""; /*The ``contents'' of motd */
829 code = DumpTag(iodp, D_VOLUMEHEADER);
831 code = DumpInt32(iodp, 'i', V_id(vp));
834 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
836 code = DumpString(iodp, 'n', V_name(vp));
838 code = DumpBool(iodp, 's', V_inService(vp));
840 code = DumpBool(iodp, 'b', V_blessed(vp));
842 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
844 code = DumpByte(iodp, 't', (byte) V_type(vp));
846 code = DumpInt32(iodp, 'p', V_parentId(vp));
849 code = DumpInt32(iodp, 'c', V_cloneId(vp));
851 code = DumpInt32(iodp, 'q', V_maxquota(vp));
853 code = DumpInt32(iodp, 'm', V_minquota(vp));
855 code = DumpInt32(iodp, 'd', V_diskused(vp));
857 code = DumpInt32(iodp, 'f', V_filecount(vp));
859 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
861 code = DumpInt32(iodp, 'o', V_owner(vp));
863 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
865 code = DumpInt32(iodp, 'A', V_accessDate(vp));
867 code = DumpInt32(iodp, 'U', V_updateDate(vp));
869 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
871 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
873 code = DumpString(iodp, 'O', V_offlineMessage(vp));
875 * We do NOT dump the detailed volume statistics residing in the old
876 * motd field, since we cannot tell from the info in a dump whether
877 * statistics data has been put there. Instead, we dump a null string,
878 * just as if that was what the motd contained.
881 code = DumpString(iodp, 'M', nullString);
884 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
885 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
887 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
889 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
894 DumpEnd(struct iod *iodp)
896 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
899 /* Guts of the dump code */
901 /* Dump a whole volume */
903 DumpVolume(struct rx_call *call, Volume * vp,
904 afs_int32 fromtime, int dumpAllDirs)
908 struct iod *iodp = &iod;
909 iod_Init(iodp, call);
912 code = DumpDumpHeader(iodp, vp, fromtime);
915 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
917 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
918 if (rx_Error(iodp->call)) {
919 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
920 rx_Error(iodp->call));
921 return VOLSERDUMPERROR;
924 code = DumpEnd(iodp);
929 /* Dump a volume to multiple places*/
931 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
932 afs_int32 fromtime, int dumpAllDirs, int *codes)
936 iod_InitMulti(&iod, calls, ncalls, codes);
939 code = DumpDumpHeader(&iod, vp, fromtime);
941 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
943 code = DumpEnd(&iod);
947 /* A partial dump (no dump header) */
949 DumpPartial(struct iod *iodp, Volume * vp,
950 afs_int32 fromtime, int dumpAllDirs)
954 code = DumpVolumeHeader(iodp, vp);
956 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
958 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
963 DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
964 afs_int32 fromtime, int forcedump)
967 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
968 char buf[SIZEOF_LARGEDISKVNODE];
969 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
970 StreamHandle_t *file;
972 afs_sfsize_t size, nVnodes;
976 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
977 osi_Assert(fdP != NULL);
978 file = FDH_FDOPEN(fdP, "r+");
979 osi_Assert(file != NULL);
980 size = OS_SIZE(fdP->fd_fd);
981 osi_Assert(size != -1);
982 nVnodes = (size / vcp->diskSize) - 1;
984 osi_Assert((nVnodes + 1) * vcp->diskSize == size);
985 osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
989 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
990 nVnodes--, vnodeIndex++) {
991 flag = forcedump || (vnode->serverModifyTime >= fromtime);
992 /* Note: the >= test is very important since some old volumes may not have
993 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
994 * does dump the file! */
997 DumpVnode(iodp, vnode, V_id(vp),
998 bitNumberToVnodeNumber(vnodeIndex, class), flag);
999 #ifndef AFS_PTHREAD_ENV
1001 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
1010 DumpDumpHeader(struct iod *iodp, Volume * vp,
1014 int UseLatestReadOnlyClone = 1;
1015 afs_int32 dumpTimes[2];
1016 iodp->device = vp->device;
1017 iodp->parentId = V_parentId(vp);
1018 iodp->dumpPartition = vp->partition;
1020 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
1023 DumpInt32(iodp, 'v',
1024 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
1026 code = DumpString(iodp, 'n', V_name(vp));
1027 dumpTimes[0] = fromtime;
1028 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
1030 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
1035 DumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1036 int vnodeNumber, int dumpEverything)
1042 if (!v || v->type == vNull)
1045 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
1046 if (!dumpEverything)
1049 code = DumpByte(iodp, 't', (byte) v->type);
1051 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
1053 code = DumpInt32(iodp, 'v', v->dataVersion);
1055 code = DumpInt32(iodp, 'm', v->unixModifyTime);
1057 code = DumpInt32(iodp, 'a', v->author);
1059 code = DumpInt32(iodp, 'o', v->owner);
1060 if (!code && v->group)
1061 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
1063 code = DumpShort(iodp, 'b', v->modeBits);
1065 code = DumpInt32(iodp, 'p', v->parent);
1067 code = DumpInt32(iodp, 's', v->serverModifyTime);
1068 if (v->type == vDirectory) {
1069 acl_HtonACL(VVnodeDiskACL(v));
1072 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
1075 if (VNDISK_GET_INO(v)) {
1076 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1079 Log("1 Volser: DumpVnode: dump: Unable to open inode %llu for vnode %u (volume %i); not dumped, error %d\n", (afs_uintmax_t) VNDISK_GET_INO(v), vnodeNumber, volid, errno);
1081 return VOLSERREAD_DUMPERROR;
1083 code = DumpFile(iodp, vnodeNumber, fdP);
1092 ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep,
1095 int i, nVnodes, code;
1100 StreamHandle_t *afile;
1102 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1103 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1104 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1106 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1107 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1110 afile = FDH_FDOPEN(fdP, "r+");
1114 for (i = 0; i < *sizep; i++) {
1117 STREAM_ASEEK(afile, Buf[i]);
1118 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1120 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1123 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
1124 V_id(vp), bitNumberToVnodeNumber(i, class),
1125 (afs_uintmax_t) VNDISK_GET_INO(vnode));
1127 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1131 STREAM_ASEEK(afile, Buf[i]);
1132 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1138 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1141 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1142 OS_SYNC(afile->str_fd);
1144 size = OS_SIZE(fdP->fd_fd);
1145 osi_Assert(size != -1);
1148 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1151 Log("RestoreVolume ProcessIndex: Set up %d inodes for volume %d\n",
1154 Buf = malloc(nVnodes * sizeof(afs_foff_t));
1156 STREAM_CLOSE(afile);
1160 memset(Buf, 0, nVnodes * sizeof(afs_foff_t));
1161 STREAM_ASEEK(afile, offset = vcp->diskSize);
1163 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1167 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1168 Buf[(offset >> vcp->logSize) - 1] = offset;
1171 offset += vcp->diskSize;
1174 Log("RestoreVolume ProcessIndex: found %d inodes\n", cnt);
1180 STREAM_CLOSE(afile);
1187 RestoreVolume(struct rx_call *call, Volume * avp, int incremental,
1188 struct restoreCookie *cookie)
1191 struct DumpHeader header;
1192 afs_uint32 endMagic;
1193 Error error = 0, vupdate;
1196 struct iod *iodp = &iod;
1197 afs_foff_t *b1 = NULL, *b2 = NULL;
1198 int s1 = 0, s2 = 0, delo = 0, tdelo;
1201 iod_Init(iodp, call);
1205 if (!ReadDumpHeader(iodp, &header)) {
1206 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1207 return VOLSERREAD_DUMPERROR;
1209 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1210 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1211 return VOLSERREAD_DUMPERROR;
1213 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1214 return VOLSERREAD_DUMPERROR;
1217 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1219 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1221 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1222 error = VOLSERREAD_DUMPERROR;
1226 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1227 vol.type = cookie->type;
1228 vol.cloneId = cookie->clone;
1229 vol.parentId = cookie->parent;
1233 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1234 error = VOLSERREAD_DUMPERROR;
1237 tag = iod_getc(iodp);
1238 if (tag != D_VOLUMEHEADER)
1241 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1242 error = VOLSERREAD_DUMPERROR;
1246 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1247 || endMagic != DUMPENDMAGIC) {
1248 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1249 error = VOLSERREAD_DUMPERROR;
1254 if (iod_getc(iodp) != EOF) {
1255 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1256 error = VOLSERREAD_DUMPERROR;
1261 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1263 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1265 error = VOLSERREAD_DUMPERROR;
1271 ClearVolumeStats(&vol);
1272 CopyVolumeHeader(&vol, &V_disk(vp));
1273 V_destroyMe(vp) = 0;
1274 VUpdateVolume(&vupdate, vp);
1276 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1277 error = VOLSERREAD_DUMPERROR;
1281 /* Free the malloced space above */
1290 ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
1291 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf, afs_int32 s2,
1294 afs_int32 vnodeNumber;
1295 char buf[SIZEOF_LARGEDISKVNODE];
1297 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1298 struct VnodeDiskObject oldvnode;
1301 struct VnodeClassInfo *vcp;
1304 Inode nearInode AFS_UNUSED;
1305 afs_int32 critical = 0;
1307 tag = iod_getc(iodp);
1308 V_pref(vp, nearInode);
1309 while (tag == D_VNODE) {
1312 memset(buf, 0, sizeof(buf));
1313 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1316 if (!ReadInt32(iodp, &vnode->uniquifier))
1317 return VOLSERREAD_DUMPERROR;
1320 Log("ReadVnodes: setup %d/%d\n", vnodeNumber, vnode->uniquifier);
1322 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1328 vnode->type = (VnodeType) iod_getc(iodp);
1333 if (!ReadShort(iodp, &tlc))
1334 return VOLSERREAD_DUMPERROR;
1335 vnode->linkCount = (signed int)tlc;
1339 if (!ReadInt32(iodp, &vnode->dataVersion))
1340 return VOLSERREAD_DUMPERROR;
1343 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1344 return VOLSERREAD_DUMPERROR;
1347 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1348 return VOLSERREAD_DUMPERROR;
1351 if (!ReadInt32(iodp, &vnode->author))
1352 return VOLSERREAD_DUMPERROR;
1355 if (!ReadInt32(iodp, &vnode->owner))
1356 return VOLSERREAD_DUMPERROR;
1359 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1360 return VOLSERREAD_DUMPERROR;
1363 unsigned short modeBits;
1364 if (!ReadShort(iodp, &modeBits))
1365 return VOLSERREAD_DUMPERROR;
1366 vnode->modeBits = (unsigned int)modeBits;
1370 if (!ReadInt32(iodp, &vnode->parent))
1371 return VOLSERREAD_DUMPERROR;
1374 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1375 VAclDiskSize(vnode));
1376 acl_NtohACL(VVnodeDiskACL(vnode));
1382 afs_fsize_t vnodeLength;
1385 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1386 "file entries for vnode %lu in dump\n",
1387 (unsigned long)vnodeNumber);
1388 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1394 IH_CREATE(V_linkHandle(vp), V_device(vp),
1395 VPartitionPath(V_partition(vp)), nearInode,
1396 V_parentId(vp), vnodeNumber,
1397 vnode->uniquifier, vnode->dataVersion);
1398 if (!VALID_INO(ino)) {
1399 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1400 afs_error_message(errno));
1401 V_needsSalvaged(vp) = 1;
1402 return VOLSERREAD_DUMPERROR;
1405 VNDISK_SET_INO(vnode, ino);
1406 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1407 fdP = IH_OPEN(tmpH);
1409 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1410 afs_error_message(errno));
1412 V_needsSalvaged(vp) = 1;
1413 return VOLSERREAD_DUMPERROR;
1416 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1417 VNDISK_SET_LEN(vnode, vnodeLength);
1418 FDH_REALLYCLOSE(fdP);
1421 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1422 (afs_uintmax_t) ino);
1423 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1424 V_needsSalvaged(vp) = 1;
1425 return VOLSERREAD_DUMPERROR;
1433 if (!HandleUnknownTag(iodp, tag, 2, critical))
1434 return VOLSERREAD_DUMPERROR;
1438 class = vnodeIdToClass(vnodeNumber);
1439 vcp = &VnodeClassInfo[class];
1441 /* Mark this vnode as in this dump - so we don't delete it later */
1443 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1444 if (class == vLarge) {
1445 if (Lbuf && (idx < s1))
1448 if (Sbuf && (idx < s2))
1454 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1456 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1457 afs_error_message(errno));
1458 V_needsSalvaged(vp) = 1;
1459 return VOLSERREAD_DUMPERROR;
1461 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1463 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1464 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1468 vnode->vnodeMagic = vcp->magic;
1469 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1470 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1471 afs_error_message(errno));
1472 FDH_REALLYCLOSE(fdP);
1473 V_needsSalvaged(vp) = 1;
1474 return VOLSERREAD_DUMPERROR;
1479 iod_ungetc(iodp, tag);
1485 /* called with disk file only. Note that we don't have to worry about rx_Read
1486 * needing to read an ungetc'd character, since the ReadInt32 will have read
1489 * if handleP == NULL, don't write the file anywhere; just read and discard
1493 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1498 afs_fsize_t filesize;
1499 afs_fsize_t written = 0;
1507 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1509 if (!ReadInt32(iodp, &filesize_high)) {
1514 if (!ReadInt32(iodp, &filesize_low)) {
1518 FillInt64(filesize, filesize_high, filesize_low);
1520 p = (unsigned char *)malloc(size);
1525 for (nbytes = filesize; nbytes; nbytes -= size) {
1529 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1530 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));
1535 nBytes = FDH_PWRITE(handleP, p, size, written);
1538 if (nBytes != size) {
1539 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1550 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1553 afs_uint32 beginMagic;
1554 afs_int32 critical = 0;
1555 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1556 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1557 || beginMagic != DUMPBEGINMAGIC)
1561 while ((tag = iod_getc(iodp)) > D_MAX) {
1562 unsigned short arrayLength;
1568 if (!ReadInt32(iodp, &hp->volumeId))
1572 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1575 if (!ReadShort(iodp, &arrayLength))
1577 hp->nDumpTimes = (arrayLength >> 1);
1578 for (i = 0; i < hp->nDumpTimes; i++)
1579 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1580 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1587 if (!HandleUnknownTag(iodp, tag, 0, critical))
1588 return VOLSERREAD_DUMPERROR;
1591 if (!hp->volumeId || !hp->nDumpTimes) {
1594 iod_ungetc(iodp, tag);
1599 /* ----- Below are the calls that calculate dump size ----- */
1602 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1603 struct volintSize *v_size)
1606 static char nullString[1] = ""; /*The ``contents'' of motd */
1609 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1610 FillInt64(addvar,0, 1);
1611 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1612 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1613 FillInt64(addvar,0, 5);
1614 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1615 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1616 FillInt64(addvar,0, 5);
1617 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1618 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1619 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1620 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1621 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1622 FillInt64(addvar,0, 2);
1623 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1624 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1625 FillInt64(addvar,0, 2);
1626 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1627 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1628 FillInt64(addvar,0, 5);
1629 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1630 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1631 FillInt64(addvar,0, 2);
1632 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1633 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1634 FillInt64(addvar,0, 5);
1635 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1636 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1637 FillInt64(addvar,0, 5);
1638 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1639 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1640 FillInt64(addvar,0, 5);
1641 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1642 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1643 FillInt64(addvar,0, 5);
1644 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1645 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1646 FillInt64(addvar,0, 5);
1647 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1648 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1649 FillInt64(addvar,0, 5);
1650 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1651 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1652 FillInt64(addvar,0, 5);
1653 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1654 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1655 FillInt64(addvar,0, 5);
1656 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1657 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1658 FillInt64(addvar,0, 5);
1659 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1660 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1661 FillInt64(addvar,0, 5);
1662 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1663 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1664 FillInt64(addvar,0, 5);
1665 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1666 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1667 FillInt64(addvar,0, 5);
1668 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1669 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1670 FillInt64(addvar,0, 5);
1671 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1672 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1673 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1674 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1676 /* * We do NOT dump the detailed volume statistics residing in the old */
1677 /* * motd field, since we cannot tell from the info in a dump whether */
1678 /* * statistics data has been put there. Instead, we dump a null string, */
1679 /* * just as if that was what the motd contained. */
1681 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1682 FillInt64(addvar,0, (2 + strlen(nullString)));
1683 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1684 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1685 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1686 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1687 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1688 FillInt64(addvar,0, 5);
1689 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1690 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1691 FillInt64(addvar,0, 5);
1692 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1697 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1701 FillInt64(addvar,0, 5);
1702 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1707 SizeDumpVolume(struct rx_call *call, Volume * vp,
1708 afs_int32 fromtime, int dumpAllDirs,
1709 struct volintSize *v_size)
1712 struct iod *iodp = (struct iod *)0;
1713 /* iod_Init(iodp, call); */
1716 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1718 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1720 code = SizeDumpEnd(iodp, v_size);
1726 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1727 afs_int32 fromtime, struct volintSize *v_size)
1730 /* int UseLatestReadOnlyClone = 1; */
1731 /* afs_int32 dumpTimes[2]; */
1733 /* iodp->device = vp->device; */
1734 /* iodp->parentId = V_parentId(vp); */
1735 /* iodp->dumpPartition = vp->partition; */
1737 ZeroInt64(v_size->dump_size); /* initialize the size */
1738 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1739 FillInt64(addvar,0, 9);
1740 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1741 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1742 FillInt64(addvar,0, 5);
1743 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1744 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1745 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1746 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1747 /* dumpTimes[0] = fromtime; */
1748 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1749 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1750 FillInt64(addvar,0, (3 + 4 * 2));
1751 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1756 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1757 int vnodeNumber, int dumpEverything,
1758 struct volintSize *v_size)
1763 if (!v || v->type == vNull)
1765 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1766 FillInt64(addvar,0, 9);
1767 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1768 if (!dumpEverything)
1770 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1771 FillInt64(addvar,0, 2);
1772 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1773 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1774 FillInt64(addvar,0, 3);
1775 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1776 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1777 FillInt64(addvar,0, 5);
1778 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1779 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1780 FillInt64(addvar,0, 5);
1781 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1782 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1783 FillInt64(addvar,0, 5);
1784 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1785 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1786 FillInt64(addvar,0, 5);
1787 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1788 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1790 FillInt64(addvar,0, 5);
1791 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1793 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1794 FillInt64(addvar,0, 3);
1795 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1796 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1797 FillInt64(addvar,0, 5);
1798 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1799 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1800 FillInt64(addvar,0, 5);
1801 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1802 if (v->type == vDirectory) {
1803 /* acl_HtonACL(VVnodeDiskACL(v)); */
1804 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1805 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1806 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1809 if (VNDISK_GET_INO(v)) {
1810 FillInt64(addvar,0, (v->length + 5));
1811 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1816 /* A partial dump (no dump header) */
1818 SizeDumpPartial(struct iod *iodp, Volume * vp,
1819 afs_int32 fromtime, int dumpAllDirs,
1820 struct volintSize *v_size)
1824 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1827 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1830 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1835 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1836 afs_int32 fromtime, int forcedump,
1837 struct volintSize *v_size)
1840 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1841 char buf[SIZEOF_LARGEDISKVNODE];
1842 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1843 StreamHandle_t *file;
1845 afs_sfsize_t size, nVnodes;
1849 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1850 osi_Assert(fdP != NULL);
1851 file = FDH_FDOPEN(fdP, "r+");
1852 osi_Assert(file != NULL);
1853 size = OS_SIZE(fdP->fd_fd);
1854 osi_Assert(size != -1);
1855 nVnodes = (size / vcp->diskSize) - 1;
1857 osi_Assert((nVnodes + 1) * vcp->diskSize == size);
1858 osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1861 for (vnodeIndex = 0;
1862 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1863 nVnodes--, vnodeIndex++) {
1864 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1865 /* Note: the >= test is very important since some old volumes may not have
1866 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1867 * does dump the file! */
1870 SizeDumpVnode(iodp, vnode, V_id(vp),
1871 bitNumberToVnodeNumber(vnodeIndex, class), flag,