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>
14 #include <sys/types.h>
22 #include <sys/param.h>
25 #include <netinet/in.h>
29 #ifdef AFS_PTHREAD_ENV
31 #else /* AFS_PTHREAD_ENV */
32 #include <afs/assert.h>
33 #endif /* AFS_PTHREAD_ENV */
36 #include <afs/afsint.h>
38 #include <afs/errors.h>
41 #include <afs/ihandle.h>
42 #include <afs/vnode.h>
43 #include <afs/volume.h>
44 #include <afs/partition.h>
46 #include <afs/daemon_com.h>
47 #include <afs/fssync.h>
49 #include <afs/com_err.h>
50 #include <afs/vol_prototypes.h>
53 #include "dumpstuff.h"
57 #define afs_stat stat64
58 #define afs_fstat fstat64
59 #else /* !O_LARGEFILE */
61 #define afs_fstat fstat
62 #endif /* !O_LARGEFILE */
63 #endif /* !AFS_NT40_ENV */
65 /*@printflike@*/ extern void Log(const char *format, ...);
70 /* Forward Declarations */
71 static int DumpDumpHeader(struct iod *iodp, Volume * vp,
73 static int DumpPartial(struct iod *iodp, Volume * vp,
74 afs_int32 fromtime, int dumpAllDirs);
75 static int DumpVnodeIndex(struct iod *iodp, Volume * vp,
76 VnodeClass class, afs_int32 fromtime,
78 static int DumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
79 int volid, int vnodeNumber, int dumpEverything);
80 static int ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp);
81 static int ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
82 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf,
83 afs_int32 s2, afs_int32 delo);
84 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
85 FdHandle_t * handleP, int tag,
88 static int SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
90 struct volintSize *size);
91 static int SizeDumpPartial(struct iod *iodp, Volume * vp,
92 afs_int32 fromtime, int dumpAllDirs,
93 struct volintSize *size);
94 static int SizeDumpVnodeIndex(struct iod *iodp, Volume * vp,
95 VnodeClass class, afs_int32 fromtime,
97 struct volintSize *size);
98 static int SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
99 int volid, int vnodeNumber, int dumpEverything,
100 struct volintSize *size);
102 #define MAX_SECTIONS 3
103 #define MIN_TLV_TAG 5
104 #define MAX_TLV_TAG 0x60
105 #define MAX_STANDARD_TAG 0x7a
106 static afs_uint32 oldtags[MAX_SECTIONS][16];
107 int oldtagsInited = 0;
110 RegisterTag(afs_int32 section, unsigned char tag)
112 afs_uint32 off = tag >> 5;
113 afs_uint32 mask = 1 << (tag & 0x1f);
114 oldtags[section][off] |= mask;
118 initNonStandardTags(void)
120 RegisterTag(0, 'n'); /* volume name */
121 RegisterTag(0, 't'); /* fromtime, V_backupDate */
122 RegisterTag(1, 'A'); /* V_accessDate */
123 RegisterTag(1, 'C'); /* V_creationDate */
124 RegisterTag(1, 'D'); /* V_dayUseDate */
125 RegisterTag(1, 'E'); /* V_expirationDate */
126 RegisterTag(1, 'M'); /* nullstring (motd) */
127 RegisterTag(1, 'U'); /* V_updateDate */
128 RegisterTag(1, 'W'); /* V_weekUse */
129 RegisterTag(1, 'Z'); /* V_dayUse */
130 RegisterTag(1, 'O'); /* V_offlineMessage */
131 RegisterTag(1, 'b'); /* V_blessed */
132 RegisterTag(1, 'n'); /* V_name */
133 RegisterTag(1, 's'); /* V_inService */
134 RegisterTag(1, 't'); /* V_type */
135 RegisterTag(2, 'A'); /* VVnodeDiskACL */
136 RegisterTag(2, 'b'); /* modeBits */
137 RegisterTag(2, 'f'); /* small file */
138 RegisterTag(2, 'h'); /* large file */
139 RegisterTag(2, 'l'); /* linkcount */
140 RegisterTag(2, 't'); /* type */
145 iod_Init(struct iod *iodp, struct rx_call *call)
148 iodp->haveOldChar = 0;
150 iodp->calls = (struct rx_call **)0;
154 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
159 iodp->haveOldChar = 0;
160 iodp->ncalls = ncalls;
162 iodp->call = (struct rx_call *)0;
165 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
166 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
168 /* For the single dump case, it's ok to just return the "bytes written"
169 * that rx_Write returns, since all the callers of iod_Write abort when
170 * the returned value is less than they expect. For the multi dump case,
171 * I don't think we want half the replicas to go bad just because one
172 * connection timed out, but if they all time out, then we should give up.
175 iod_Write(struct iod *iodp, char *buf, int nbytes)
180 assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
181 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
184 code = rx_Write(iodp->call, buf, nbytes);
188 for (i = 0; i < iodp->ncalls; i++) {
189 if (iodp->calls[i] && !iodp->codes[i]) {
190 code = rx_Write(iodp->calls[i], buf, nbytes);
191 if (code != nbytes) { /* everything gets merged into a single error */
192 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
193 } /* standard dump does, anyways */
198 } /* for all calls */
207 iod_ungetc(struct iod *iodp, int achar)
209 iodp->oldChar = achar;
210 iodp->haveOldChar = 1;
214 iod_getc(struct iod *iodp)
218 if (iodp->haveOldChar) {
219 iodp->haveOldChar = 0;
220 return iodp->oldChar;
222 if (iod_Read(iodp, (char *) &t, 1) == 1)
228 ReadShort(struct iod *iodp, unsigned short *sp)
237 *sp = (b1 << 8) | b0;
242 ReadInt32(struct iod *iodp, afs_uint32 * lp)
244 afs_uint32 b3, b2, b1, b0;
257 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
262 ReadString(struct iod *iodp, char *to, int maxa)
271 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
275 while ((c = iod_getc(iodp)) && c != EOF);
281 ReadByteString(struct iod *iodp, byte * to,
285 *to++ = iod_getc(iodp);
289 * returns 1 on success and 0 otherwise
292 ReadStandardTagLen(struct iod *iodp, unsigned char tag, afs_int32 section,
296 afs_uint32 off = tag >> 5;
297 afs_uint32 mask = 1 << (tag & 0x1f);
298 unsigned char len, buf[8], *p;
301 initNonStandardTags();
303 if (tag < MIN_TLV_TAG
304 || tag > MAX_STANDARD_TAG
305 || section >= MAX_SECTIONS
306 || (oldtags[section][ off] & mask)) {
307 Log("Trying to use ReadStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
310 if (tag <= MAX_TLV_TAG) {
311 len = iod_getc(iodp);
316 if ((code = iod_Read(iodp, (char *)buf, len)) != len)
317 return VOLSERDUMPERROR;
319 p = (unsigned char *)&buf;
320 for (i=0; i<len; i++) {
321 *length = ((*length) << 8) | *p++;
325 if (tag < MAX_STANDARD_TAG)
331 static char skipbuf[256];
334 SkipData(struct iod *iodp, afs_size_t length)
336 while (length > 256) {
337 if (iod_Read(iodp, (char *)&skipbuf, 256) != 256)
341 if (iod_Read(iodp, (char *)&skipbuf, length) != length)
346 static char *secname[3] = {"ReadDumpHeader", "ReadVolumeHeader", "ReadVnodes"};
349 HandleUnknownTag(struct iod *iodp, int tag, afs_int32 section,
352 afs_size_t taglen = 0;
356 Log("%s: unknown critical tag x%02x, aborting\n",
357 secname[section], tag);
360 Log("%s: unknown tag x%02x found, skipping\n", secname[section], tag);
361 if (tag >= 0x06 && tag <= 0x60) {
362 if (!ReadStandardTagLen(iodp, tag, 1, &taglen)) {
363 Log("%s: error reading length field for tag x%02x, aborting\n",
364 secname[section], tag);
367 if (!SkipData(iodp, taglen)) {
368 Log("%s: error skipping %llu bytes for tag x%02x, aborting\n",
369 secname[section], taglen, tag);
374 if (tag >= 0x61 && tag <= 0x7a) {
375 if (!ReadInt32(iodp, &trash)) {
376 Log("%s: error skipping int32 for tag x%02x, aborting\n",
377 secname[section], tag);
382 if (tag >= 0x7b && tag < 0x80) /* dataless tag */
384 Log("%s: unknown invalid tag x%02x, aborting\n", secname[section], tag);
389 ReadVolumeHeader(struct iod *iodp, VolumeDiskData * vol)
393 afs_int32 critical = 0;
394 memset(vol, 0, sizeof(*vol));
395 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
400 if (!ReadInt32(iodp, &vol->id))
401 return VOLSERREAD_DUMPERROR;
404 if (!ReadInt32(iodp, &trash))
405 return VOLSERREAD_DUMPERROR;
408 ReadString(iodp, vol->name, sizeof(vol->name));
409 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
412 vol->inService = iod_getc(iodp);
415 vol->blessed = iod_getc(iodp);
418 if (!ReadInt32(iodp, &vol->uniquifier))
419 return VOLSERREAD_DUMPERROR;
422 vol->type = iod_getc(iodp);
425 if (!ReadInt32(iodp, &vol->parentId))
426 return VOLSERREAD_DUMPERROR;
429 if (!ReadInt32(iodp, &vol->cloneId))
430 return VOLSERREAD_DUMPERROR;
433 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
434 return VOLSERREAD_DUMPERROR;
437 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
438 return VOLSERREAD_DUMPERROR;
441 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
442 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
445 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
446 return VOLSERREAD_DUMPERROR;
449 if (!ReadInt32(iodp, &vol->accountNumber))
450 return VOLSERREAD_DUMPERROR;
453 if (!ReadInt32(iodp, &vol->owner))
454 return VOLSERREAD_DUMPERROR;
457 if (!ReadInt32(iodp, &vol->creationDate))
458 return VOLSERREAD_DUMPERROR;
461 if (!ReadInt32(iodp, &vol->accessDate))
462 return VOLSERREAD_DUMPERROR;
465 if (!ReadInt32(iodp, &vol->updateDate))
466 return VOLSERREAD_DUMPERROR;
469 if (!ReadInt32(iodp, &vol->expirationDate))
470 return VOLSERREAD_DUMPERROR;
473 if (!ReadInt32(iodp, &vol->backupDate))
474 return VOLSERREAD_DUMPERROR;
477 ReadString(iodp, vol->offlineMessage,
478 sizeof(vol->offlineMessage));
482 * Detailed volume statistics are never stored in dumps,
483 * so we just restore either the null string if this volume
484 * had already been set to store statistics, or the old motd
485 * contents otherwise. It doesn't matter, since this field
486 * will soon get initialized anyway.
488 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
491 unsigned short length;
494 if (!ReadShort(iodp, &length))
495 return VOLSERREAD_DUMPERROR;
496 for (i = 0; i < length; i++) {
497 if (!ReadInt32(iodp, &data))
498 return VOLSERREAD_DUMPERROR;
499 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
500 vol->weekUse[i] = data;
505 if (!ReadInt32(iodp, &vol->dayUseDate))
506 return VOLSERREAD_DUMPERROR;
509 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
510 return VOLSERREAD_DUMPERROR;
513 if (!ReadInt32(iodp, (afs_uint32 *) &trash/*volUpdateCounter*/))
514 return VOLSERREAD_DUMPERROR;
520 if (!HandleUnknownTag(iodp, tag, 1, critical))
521 return VOLSERREAD_DUMPERROR;
524 iod_ungetc(iodp, tag);
529 DumpTag(struct iod *iodp, int tag)
534 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
539 DumpByte(struct iod *iodp, char tag, byte value)
542 byte *p = (unsigned char *)tbuffer;
545 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
548 #define putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
549 #define putshort(p, v) *p++ = v>>8, *p++ = v
552 DumpDouble(struct iod *iodp, char tag, afs_uint32 value1,
556 byte *p = (unsigned char *)tbuffer;
560 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
564 DumpInt32(struct iod *iodp, char tag, afs_uint32 value)
567 byte *p = (unsigned char *)tbuffer;
570 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
574 DumpArrayInt32(struct iod *iodp, char tag,
575 afs_uint32 * array, int nelem)
580 byte *p = (unsigned char *)tbuffer;
583 code = iod_Write(iodp, tbuffer, 3);
585 return VOLSERDUMPERROR;
587 p = (unsigned char *)tbuffer;
588 v = *array++; /*this was register */
591 code = iod_Write(iodp, tbuffer, 4);
593 return VOLSERDUMPERROR;
599 DumpShort(struct iod *iodp, char tag, unsigned int value)
602 byte *p = (unsigned char *)tbuffer;
606 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
610 DumpBool(struct iod *iodp, char tag, unsigned int value)
613 byte *p = (unsigned char *)tbuffer;
616 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
620 DumpString(struct iod *iodp, char tag, char *s)
624 code = iod_Write(iodp, &tag, 1);
626 return VOLSERDUMPERROR;
628 code = iod_Write(iodp, s, n);
630 return VOLSERDUMPERROR;
635 DumpByteString(struct iod *iodp, char tag, byte * bs,
640 code = iod_Write(iodp, &tag, 1);
642 return VOLSERDUMPERROR;
643 code = iod_Write(iodp, (char *)bs, nbytes);
645 return VOLSERDUMPERROR;
650 DumpStandardTag(struct iod *iodp, char tag, afs_uint32 section)
653 afs_uint32 off = tag >> 5;
654 afs_uint32 mask = 1 << (tag & 0x1f);
657 initNonStandardTags();
659 if (tag < MIN_TLV_TAG
660 || tag > MAX_STANDARD_TAG
661 || section >= MAX_SECTIONS
662 || (oldtags[section][ off] & mask)) {
663 Log("Trying to use DumpStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
664 return VOLSERDUMPERROR;
666 code = iod_Write(iodp, &tag, 1);
668 return VOLSERDUMPERROR;
674 DumpStandardTagLen(struct iod *iodp, char tag, afs_uint32 section,
681 if (tag < MIN_TLV_TAG || tag > MAX_TLV_TAG) {
682 Log("Trying to use DumpStandardTagLen with tag 0x%02x for section %d, aborting\n", tag, section);
683 return VOLSERDUMPERROR;
685 code = DumpStandardTag(iodp, tag, section);
689 if (length < 128) { /* byte after tag contains length */
692 } else { /* byte after tag contains length of length field | 0x80 */
693 for (len=0; length; length=length >> 8) {
701 code = iod_Write(iodp, p, len);
703 return VOLSERDUMPERROR;
708 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
710 int code = 0, error = 0;
712 afs_int32 offset = 0;
713 afs_sfsize_t nbytes, howBig;
716 afs_foff_t howFar = 0;
721 struct afs_stat status;
725 #include <sys/statfs.h>
726 #if defined(AFS_AIX52_ENV)
727 struct statfs64 tstatfs;
728 #else /* !AFS_AIX52_ENV */
729 struct statfs tstatfs;
730 #endif /* !AFS_AIX52_ENV */
735 howBig = _filelength(handleP->fd_fd);
739 afs_fstat(handleP->fd_fd, &status);
740 howBig = status.st_size;
743 /* Unfortunately in AIX valuable fields such as st_blksize are
744 * gone from the stat structure.
746 #if defined(AFS_AIX52_ENV)
747 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
748 #else /* !AFS_AIX52_ENV */
749 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
750 #endif /* !AFS_AIX52_ENV */
751 if (statfs_code != 0) {
752 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
753 return VOLSERDUMPERROR;
755 howMany = tstatfs.f_bsize;
757 howMany = status.st_blksize;
758 #endif /* AFS_AIX_ENV */
759 #endif /* AFS_NT40_ENV */
762 size = FDH_SIZE(handleP);
763 SplitInt64(size, hi, lo);
765 code = DumpInt32(iodp, 'f', lo);
767 code = DumpDouble(iodp, 'h', hi, lo);
770 return VOLSERDUMPERROR;
775 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", (unsigned)howMany);
776 return VOLSERDUMPERROR;
779 for (nbytes = size; (nbytes && !error); nbytes -= howMany) {
780 if (nbytes < howMany)
784 n = FDH_PREAD(handleP, p, howMany, howFar);
787 /* If read any good data and we null padded previously, log the
788 * amount that we had null padded.
790 if ((n > 0) && pad) {
791 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", pad, offset);
795 /* If didn't read enough data, null padd the rest of the buffer. This
796 * can happen if, for instance, the media has some bad spots. We don't
797 * want to quit the dump, so we start null padding.
800 /* Record the read error */
803 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));
805 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
808 /* Pad the rest of the buffer with zeros. Remember offset we started
809 * padding. Keep total tally of padding.
811 memset(p + n, 0, howMany - n);
813 offset = (howBig - nbytes) + n;
814 pad += (howMany - n);
816 /* Now seek over the data we could not get. An error here means we
817 * can't do the next read.
819 howFar = (size_t)((size - nbytes) + howMany);
822 /* Now write the data out */
823 if (iod_Write(iodp, (char *)p, howMany) != howMany)
824 error = VOLSERDUMPERROR;
825 #ifndef AFS_PTHREAD_ENV
830 if (pad) { /* Any padding we hadn't reported yet */
831 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n",
840 DumpVolumeHeader(struct iod *iodp, Volume * vp)
843 static char nullString[1] = ""; /*The ``contents'' of motd */
846 code = DumpTag(iodp, D_VOLUMEHEADER);
848 code = DumpInt32(iodp, 'i', V_id(vp));
851 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
853 code = DumpString(iodp, 'n', V_name(vp));
855 code = DumpBool(iodp, 's', V_inService(vp));
857 code = DumpBool(iodp, 'b', V_blessed(vp));
859 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
861 code = DumpByte(iodp, 't', (byte) V_type(vp));
863 code = DumpInt32(iodp, 'p', V_parentId(vp));
866 code = DumpInt32(iodp, 'c', V_cloneId(vp));
868 code = DumpInt32(iodp, 'q', V_maxquota(vp));
870 code = DumpInt32(iodp, 'm', V_minquota(vp));
872 code = DumpInt32(iodp, 'd', V_diskused(vp));
874 code = DumpInt32(iodp, 'f', V_filecount(vp));
876 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
878 code = DumpInt32(iodp, 'o', V_owner(vp));
880 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
882 code = DumpInt32(iodp, 'A', V_accessDate(vp));
884 code = DumpInt32(iodp, 'U', V_updateDate(vp));
886 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
888 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
890 code = DumpString(iodp, 'O', V_offlineMessage(vp));
892 * We do NOT dump the detailed volume statistics residing in the old
893 * motd field, since we cannot tell from the info in a dump whether
894 * statistics data has been put there. Instead, we dump a null string,
895 * just as if that was what the motd contained.
898 code = DumpString(iodp, 'M', nullString);
901 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
902 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
904 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
906 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
911 DumpEnd(struct iod *iodp)
913 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
916 /* Guts of the dump code */
918 /* Dump a whole volume */
920 DumpVolume(struct rx_call *call, Volume * vp,
921 afs_int32 fromtime, int dumpAllDirs)
925 struct iod *iodp = &iod;
926 iod_Init(iodp, call);
929 code = DumpDumpHeader(iodp, vp, fromtime);
932 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
934 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
935 if (rx_Error(iodp->call)) {
936 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
937 rx_Error(iodp->call));
938 return VOLSERDUMPERROR;
941 code = DumpEnd(iodp);
946 /* Dump a volume to multiple places*/
948 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
949 afs_int32 fromtime, int dumpAllDirs, int *codes)
953 iod_InitMulti(&iod, calls, ncalls, codes);
956 code = DumpDumpHeader(&iod, vp, fromtime);
958 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
960 code = DumpEnd(&iod);
964 /* A partial dump (no dump header) */
966 DumpPartial(struct iod *iodp, Volume * vp,
967 afs_int32 fromtime, int dumpAllDirs)
971 code = DumpVolumeHeader(iodp, vp);
973 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
975 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
980 DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
981 afs_int32 fromtime, int forcedump)
984 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
985 char buf[SIZEOF_LARGEDISKVNODE];
986 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
987 StreamHandle_t *file;
989 afs_sfsize_t size, nVnodes;
993 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
995 file = FDH_FDOPEN(fdP, "r+");
996 assert(file != NULL);
997 size = OS_SIZE(fdP->fd_fd);
999 nVnodes = (size / vcp->diskSize) - 1;
1001 assert((nVnodes + 1) * vcp->diskSize == size);
1002 assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1005 for (vnodeIndex = 0;
1006 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1007 nVnodes--, vnodeIndex++) {
1008 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1009 /* Note: the >= test is very important since some old volumes may not have
1010 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1011 * does dump the file! */
1014 DumpVnode(iodp, vnode, V_id(vp),
1015 bitNumberToVnodeNumber(vnodeIndex, class), flag);
1016 #ifndef AFS_PTHREAD_ENV
1018 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
1027 DumpDumpHeader(struct iod *iodp, Volume * vp,
1031 int UseLatestReadOnlyClone = 1;
1032 afs_int32 dumpTimes[2];
1033 iodp->device = vp->device;
1034 iodp->parentId = V_parentId(vp);
1035 iodp->dumpPartition = vp->partition;
1037 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
1040 DumpInt32(iodp, 'v',
1041 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
1043 code = DumpString(iodp, 'n', V_name(vp));
1044 dumpTimes[0] = fromtime;
1045 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
1047 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
1052 DumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1053 int vnodeNumber, int dumpEverything)
1059 if (!v || v->type == vNull)
1062 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
1063 if (!dumpEverything)
1066 code = DumpByte(iodp, 't', (byte) v->type);
1068 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
1070 code = DumpInt32(iodp, 'v', v->dataVersion);
1072 code = DumpInt32(iodp, 'm', v->unixModifyTime);
1074 code = DumpInt32(iodp, 'a', v->author);
1076 code = DumpInt32(iodp, 'o', v->owner);
1077 if (!code && v->group)
1078 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
1080 code = DumpShort(iodp, 'b', v->modeBits);
1082 code = DumpInt32(iodp, 'p', v->parent);
1084 code = DumpInt32(iodp, 's', v->serverModifyTime);
1085 if (v->type == vDirectory) {
1086 acl_HtonACL(VVnodeDiskACL(v));
1089 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
1092 if (VNDISK_GET_INO(v)) {
1093 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1096 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);
1098 return VOLSERREAD_DUMPERROR;
1100 code = DumpFile(iodp, vnodeNumber, fdP);
1109 ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep,
1112 int i, nVnodes, offset, code;
1116 StreamHandle_t *afile;
1118 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1119 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1120 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1122 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1123 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1126 afile = FDH_FDOPEN(fdP, "r+");
1130 for (i = 0; i < *sizep; i++) {
1133 STREAM_ASEEK(afile, Buf[i]);
1134 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1136 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1139 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
1140 V_id(vp), bitNumberToVnodeNumber(i, class),
1141 (afs_uintmax_t) VNDISK_GET_INO(vnode));
1143 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1147 STREAM_ASEEK(afile, Buf[i]);
1148 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1154 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1157 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1158 OS_SYNC(afile->str_fd);
1160 size = OS_SIZE(fdP->fd_fd);
1164 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1167 Log("RestoreVolume ProcessIndex: Set up %d inodes for volume %d\n",
1170 Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32));
1172 STREAM_CLOSE(afile);
1176 memset(Buf, 0, nVnodes * sizeof(afs_int32));
1177 STREAM_ASEEK(afile, offset = vcp->diskSize);
1179 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1183 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1184 Buf[(offset >> vcp->logSize) - 1] = offset;
1187 offset += vcp->diskSize;
1190 Log("RestoreVolume ProcessIndex: found %d inodes\n", cnt);
1196 STREAM_CLOSE(afile);
1203 RestoreVolume(struct rx_call *call, Volume * avp, int incremental,
1204 struct restoreCookie *cookie)
1207 struct DumpHeader header;
1208 afs_uint32 endMagic;
1209 Error error = 0, vupdate;
1212 struct iod *iodp = &iod;
1213 afs_int32 *b1 = NULL, *b2 = NULL;
1214 int s1 = 0, s2 = 0, delo = 0, tdelo;
1217 iod_Init(iodp, call);
1221 if (!ReadDumpHeader(iodp, &header)) {
1222 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1223 return VOLSERREAD_DUMPERROR;
1225 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1226 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1227 return VOLSERREAD_DUMPERROR;
1229 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1230 return VOLSERREAD_DUMPERROR;
1233 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1235 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1237 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1238 error = VOLSERREAD_DUMPERROR;
1242 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1243 vol.type = cookie->type;
1244 vol.cloneId = cookie->clone;
1245 vol.parentId = cookie->parent;
1249 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1250 error = VOLSERREAD_DUMPERROR;
1253 tag = iod_getc(iodp);
1254 if (tag != D_VOLUMEHEADER)
1257 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1258 error = VOLSERREAD_DUMPERROR;
1262 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1263 || endMagic != DUMPENDMAGIC) {
1264 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1265 error = VOLSERREAD_DUMPERROR;
1270 if (iod_getc(iodp) != EOF) {
1271 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1272 error = VOLSERREAD_DUMPERROR;
1277 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1279 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1281 error = VOLSERREAD_DUMPERROR;
1287 ClearVolumeStats(&vol);
1288 CopyVolumeHeader(&vol, &V_disk(vp));
1289 V_destroyMe(vp) = 0;
1290 VUpdateVolume(&vupdate, vp);
1292 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1293 error = VOLSERREAD_DUMPERROR;
1297 /* Free the malloced space above */
1306 ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
1307 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2,
1310 afs_int32 vnodeNumber;
1311 char buf[SIZEOF_LARGEDISKVNODE];
1313 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1314 struct VnodeDiskObject oldvnode;
1317 struct VnodeClassInfo *vcp;
1321 afs_int32 critical = 0;
1323 tag = iod_getc(iodp);
1324 V_pref(vp, nearInode);
1325 while (tag == D_VNODE) {
1328 memset(buf, 0, sizeof(buf));
1329 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1332 if (!ReadInt32(iodp, &vnode->uniquifier))
1333 return VOLSERREAD_DUMPERROR;
1336 Log("ReadVnodes: setup %d/%d\n", vnodeNumber, vnode->uniquifier);
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 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1391 VAclDiskSize(vnode));
1392 acl_NtohACL(VVnodeDiskACL(vnode));
1398 afs_fsize_t vnodeLength;
1401 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1402 "file entries for vnode %lu in dump\n",
1403 (unsigned long)vnodeNumber);
1404 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1410 IH_CREATE(V_linkHandle(vp), V_device(vp),
1411 VPartitionPath(V_partition(vp)), nearInode,
1412 V_parentId(vp), vnodeNumber,
1413 vnode->uniquifier, vnode->dataVersion);
1414 if (!VALID_INO(ino)) {
1415 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1416 afs_error_message(errno));
1417 return VOLSERREAD_DUMPERROR;
1420 VNDISK_SET_INO(vnode, ino);
1421 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1422 fdP = IH_OPEN(tmpH);
1424 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1425 afs_error_message(errno));
1427 return VOLSERREAD_DUMPERROR;
1430 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1431 VNDISK_SET_LEN(vnode, vnodeLength);
1432 FDH_REALLYCLOSE(fdP);
1435 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1436 (afs_uintmax_t) ino);
1437 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1438 return VOLSERREAD_DUMPERROR;
1446 if (!HandleUnknownTag(iodp, tag, 2, critical))
1447 return VOLSERREAD_DUMPERROR;
1451 class = vnodeIdToClass(vnodeNumber);
1452 vcp = &VnodeClassInfo[class];
1454 /* Mark this vnode as in this dump - so we don't delete it later */
1456 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1457 if (class == vLarge) {
1458 if (Lbuf && (idx < s1))
1461 if (Sbuf && (idx < s2))
1467 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1469 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1470 afs_error_message(errno));
1471 return VOLSERREAD_DUMPERROR;
1473 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1475 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1476 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1480 vnode->vnodeMagic = vcp->magic;
1481 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1482 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1483 afs_error_message(errno));
1484 FDH_REALLYCLOSE(fdP);
1485 return VOLSERREAD_DUMPERROR;
1490 iod_ungetc(iodp, tag);
1496 /* called with disk file only. Note that we don't have to worry about rx_Read
1497 * needing to read an ungetc'd character, since the ReadInt32 will have read
1500 * if handleP == NULL, don't write the file anywhere; just read and discard
1504 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1509 afs_fsize_t filesize;
1510 afs_fsize_t written = 0;
1518 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1520 if (!ReadInt32(iodp, &filesize_high)) {
1525 if (!ReadInt32(iodp, &filesize_low)) {
1529 FillInt64(filesize, filesize_high, filesize_low);
1531 p = (unsigned char *)malloc(size);
1536 for (nbytes = filesize; nbytes; nbytes -= size) {
1540 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1541 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));
1546 nBytes = FDH_PWRITE(handleP, p, size, written);
1549 if (nBytes != size) {
1550 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1561 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1564 afs_uint32 beginMagic;
1565 afs_int32 critical = 0;
1566 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1567 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1568 || beginMagic != DUMPBEGINMAGIC)
1572 while ((tag = iod_getc(iodp)) > D_MAX) {
1573 unsigned short arrayLength;
1579 if (!ReadInt32(iodp, &hp->volumeId))
1583 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1586 if (!ReadShort(iodp, &arrayLength))
1588 hp->nDumpTimes = (arrayLength >> 1);
1589 for (i = 0; i < hp->nDumpTimes; i++)
1590 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1591 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1598 if (!HandleUnknownTag(iodp, tag, 0, critical))
1599 return VOLSERREAD_DUMPERROR;
1602 if (!hp->volumeId || !hp->nDumpTimes) {
1605 iod_ungetc(iodp, tag);
1610 /* ----- Below are the calls that calculate dump size ----- */
1613 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1614 struct volintSize *v_size)
1617 static char nullString[1] = ""; /*The ``contents'' of motd */
1620 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1621 FillInt64(addvar,0, 1);
1622 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1623 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1624 FillInt64(addvar,0, 5);
1625 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1626 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1627 FillInt64(addvar,0, 5);
1628 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1629 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1630 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1631 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1632 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1633 FillInt64(addvar,0, 2);
1634 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1635 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1636 FillInt64(addvar,0, 2);
1637 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1638 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1639 FillInt64(addvar,0, 5);
1640 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1641 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1642 FillInt64(addvar,0, 2);
1643 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1644 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1645 FillInt64(addvar,0, 5);
1646 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1647 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1648 FillInt64(addvar,0, 5);
1649 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1650 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1651 FillInt64(addvar,0, 5);
1652 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1653 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1654 FillInt64(addvar,0, 5);
1655 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1656 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1657 FillInt64(addvar,0, 5);
1658 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1659 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1660 FillInt64(addvar,0, 5);
1661 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1662 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1663 FillInt64(addvar,0, 5);
1664 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1665 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1666 FillInt64(addvar,0, 5);
1667 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1668 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1669 FillInt64(addvar,0, 5);
1670 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1671 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1672 FillInt64(addvar,0, 5);
1673 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1674 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1675 FillInt64(addvar,0, 5);
1676 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1677 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1678 FillInt64(addvar,0, 5);
1679 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1680 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1681 FillInt64(addvar,0, 5);
1682 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1683 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1684 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1685 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1687 /* * We do NOT dump the detailed volume statistics residing in the old */
1688 /* * motd field, since we cannot tell from the info in a dump whether */
1689 /* * statistics data has been put there. Instead, we dump a null string, */
1690 /* * just as if that was what the motd contained. */
1692 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1693 FillInt64(addvar,0, (2 + strlen(nullString)));
1694 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1695 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1696 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1697 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1698 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1699 FillInt64(addvar,0, 5);
1700 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1701 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1702 FillInt64(addvar,0, 5);
1703 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1708 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1712 FillInt64(addvar,0, 5);
1713 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1718 SizeDumpVolume(struct rx_call *call, Volume * vp,
1719 afs_int32 fromtime, int dumpAllDirs,
1720 struct volintSize *v_size)
1723 struct iod *iodp = (struct iod *)0;
1724 /* iod_Init(iodp, call); */
1727 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1729 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1731 code = SizeDumpEnd(iodp, v_size);
1737 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1738 afs_int32 fromtime, struct volintSize *v_size)
1741 /* int UseLatestReadOnlyClone = 1; */
1742 /* afs_int32 dumpTimes[2]; */
1744 /* iodp->device = vp->device; */
1745 /* iodp->parentId = V_parentId(vp); */
1746 /* iodp->dumpPartition = vp->partition; */
1748 ZeroInt64(v_size->dump_size); /* initialize the size */
1749 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1750 FillInt64(addvar,0, 9);
1751 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1752 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1753 FillInt64(addvar,0, 5);
1754 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1755 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1756 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1757 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1758 /* dumpTimes[0] = fromtime; */
1759 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1760 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1761 FillInt64(addvar,0, (3 + 4 * 2));
1762 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1767 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1768 int vnodeNumber, int dumpEverything,
1769 struct volintSize *v_size)
1774 if (!v || v->type == vNull)
1776 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1777 FillInt64(addvar,0, 9);
1778 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1779 if (!dumpEverything)
1781 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1782 FillInt64(addvar,0, 2);
1783 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1784 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1785 FillInt64(addvar,0, 3);
1786 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1787 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1788 FillInt64(addvar,0, 5);
1789 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1790 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1791 FillInt64(addvar,0, 5);
1792 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1793 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1794 FillInt64(addvar,0, 5);
1795 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1796 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1797 FillInt64(addvar,0, 5);
1798 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1799 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1801 FillInt64(addvar,0, 5);
1802 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1804 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1805 FillInt64(addvar,0, 3);
1806 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1807 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1808 FillInt64(addvar,0, 5);
1809 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1810 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1811 FillInt64(addvar,0, 5);
1812 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1813 if (v->type == vDirectory) {
1814 /* acl_HtonACL(VVnodeDiskACL(v)); */
1815 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1816 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1817 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1820 if (VNDISK_GET_INO(v)) {
1821 FillInt64(addvar,0, (v->length + 5));
1822 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1827 /* A partial dump (no dump header) */
1829 SizeDumpPartial(struct iod *iodp, Volume * vp,
1830 afs_int32 fromtime, int dumpAllDirs,
1831 struct volintSize *v_size)
1835 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1838 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1841 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1846 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1847 afs_int32 fromtime, int forcedump,
1848 struct volintSize *v_size)
1851 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1852 char buf[SIZEOF_LARGEDISKVNODE];
1853 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1854 StreamHandle_t *file;
1856 afs_sfsize_t size, nVnodes;
1860 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1861 assert(fdP != NULL);
1862 file = FDH_FDOPEN(fdP, "r+");
1863 assert(file != NULL);
1864 size = OS_SIZE(fdP->fd_fd);
1866 nVnodes = (size / vcp->diskSize) - 1;
1868 assert((nVnodes + 1) * vcp->diskSize == size);
1869 assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1872 for (vnodeIndex = 0;
1873 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1874 nVnodes--, vnodeIndex++) {
1875 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1876 /* Note: the >= test is very important since some old volumes may not have
1877 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1878 * does dump the file! */
1881 SizeDumpVnode(iodp, vnode, V_id(vp),
1882 bitNumberToVnodeNumber(vnodeIndex, class), flag,