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 #include <afs/afs_assert.h>
32 #include <afs/afsint.h>
34 #include <afs/errors.h>
37 #include <afs/ihandle.h>
38 #include <afs/vnode.h>
39 #include <afs/volume.h>
40 #include <afs/partition.h>
42 #include <afs/daemon_com.h>
43 #include <afs/fssync.h>
45 #include <afs/com_err.h>
46 #include <afs/vol_prototypes.h>
49 #include "dumpstuff.h"
53 #define afs_stat stat64
54 #define afs_fstat fstat64
55 #else /* !O_LARGEFILE */
57 #define afs_fstat fstat
58 #endif /* !O_LARGEFILE */
59 #endif /* !AFS_NT40_ENV */
61 /*@printflike@*/ extern void Log(const char *format, ...);
66 /* Forward Declarations */
67 static int DumpDumpHeader(struct iod *iodp, Volume * vp,
69 static int DumpPartial(struct iod *iodp, Volume * vp,
70 afs_int32 fromtime, int dumpAllDirs);
71 static int DumpVnodeIndex(struct iod *iodp, Volume * vp,
72 VnodeClass class, afs_int32 fromtime,
74 static int DumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
75 int volid, int vnodeNumber, int dumpEverything);
76 static int ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp);
77 static int ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
78 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf,
79 afs_int32 s2, afs_int32 delo);
80 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
81 FdHandle_t * handleP, int tag,
84 static int SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
86 struct volintSize *size);
87 static int SizeDumpPartial(struct iod *iodp, Volume * vp,
88 afs_int32 fromtime, int dumpAllDirs,
89 struct volintSize *size);
90 static int SizeDumpVnodeIndex(struct iod *iodp, Volume * vp,
91 VnodeClass class, afs_int32 fromtime,
93 struct volintSize *size);
94 static int SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
95 int volid, int vnodeNumber, int dumpEverything,
96 struct volintSize *size);
98 #define MAX_SECTIONS 3
100 #define MAX_TLV_TAG 0x60
101 #define MAX_STANDARD_TAG 0x7a
102 static afs_uint32 oldtags[MAX_SECTIONS][16];
103 int oldtagsInited = 0;
106 RegisterTag(afs_int32 section, unsigned char tag)
108 afs_uint32 off = tag >> 5;
109 afs_uint32 mask = 1 << (tag & 0x1f);
110 oldtags[section][off] |= mask;
114 initNonStandardTags(void)
116 RegisterTag(0, 'n'); /* volume name */
117 RegisterTag(0, 't'); /* fromtime, V_backupDate */
118 RegisterTag(1, 'A'); /* V_accessDate */
119 RegisterTag(1, 'C'); /* V_creationDate */
120 RegisterTag(1, 'D'); /* V_dayUseDate */
121 RegisterTag(1, 'E'); /* V_expirationDate */
122 RegisterTag(1, 'M'); /* nullstring (motd) */
123 RegisterTag(1, 'U'); /* V_updateDate */
124 RegisterTag(1, 'W'); /* V_weekUse */
125 RegisterTag(1, 'Z'); /* V_dayUse */
126 RegisterTag(1, 'O'); /* V_offlineMessage */
127 RegisterTag(1, 'b'); /* V_blessed */
128 RegisterTag(1, 'n'); /* V_name */
129 RegisterTag(1, 's'); /* V_inService */
130 RegisterTag(1, 't'); /* V_type */
131 RegisterTag(2, 'A'); /* VVnodeDiskACL */
132 RegisterTag(2, 'b'); /* modeBits */
133 RegisterTag(2, 'f'); /* small file */
134 RegisterTag(2, 'h'); /* large file */
135 RegisterTag(2, 'l'); /* linkcount */
136 RegisterTag(2, 't'); /* type */
141 iod_Init(struct iod *iodp, struct rx_call *call)
144 iodp->haveOldChar = 0;
146 iodp->calls = (struct rx_call **)0;
150 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
155 iodp->haveOldChar = 0;
156 iodp->ncalls = ncalls;
158 iodp->call = (struct rx_call *)0;
161 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
162 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
164 /* For the single dump case, it's ok to just return the "bytes written"
165 * that rx_Write returns, since all the callers of iod_Write abort when
166 * the returned value is less than they expect. For the multi dump case,
167 * I don't think we want half the replicas to go bad just because one
168 * connection timed out, but if they all time out, then we should give up.
171 iod_Write(struct iod *iodp, char *buf, int nbytes)
176 osi_Assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
177 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
180 code = rx_Write(iodp->call, buf, nbytes);
184 for (i = 0; i < iodp->ncalls; i++) {
185 if (iodp->calls[i] && !iodp->codes[i]) {
186 code = rx_Write(iodp->calls[i], buf, nbytes);
187 if (code != nbytes) { /* everything gets merged into a single error */
188 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
189 } /* standard dump does, anyways */
194 } /* for all calls */
203 iod_ungetc(struct iod *iodp, int achar)
205 iodp->oldChar = achar;
206 iodp->haveOldChar = 1;
210 iod_getc(struct iod *iodp)
214 if (iodp->haveOldChar) {
215 iodp->haveOldChar = 0;
216 return iodp->oldChar;
218 if (iod_Read(iodp, (char *) &t, 1) == 1)
224 ReadShort(struct iod *iodp, unsigned short *sp)
233 *sp = (b1 << 8) | b0;
238 ReadInt32(struct iod *iodp, afs_uint32 * lp)
240 afs_uint32 b3, b2, b1, b0;
253 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
258 ReadString(struct iod *iodp, char *to, int maxa)
267 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
271 while ((c = iod_getc(iodp)) && c != EOF);
277 ReadByteString(struct iod *iodp, byte * to,
281 *to++ = iod_getc(iodp);
285 * returns 1 on success and 0 otherwise
288 ReadStandardTagLen(struct iod *iodp, unsigned char tag, afs_int32 section,
292 afs_uint32 off = tag >> 5;
293 afs_uint32 mask = 1 << (tag & 0x1f);
294 unsigned char len, buf[8], *p;
297 initNonStandardTags();
299 if (tag < MIN_TLV_TAG
300 || tag > MAX_STANDARD_TAG
301 || section >= MAX_SECTIONS
302 || (oldtags[section][ off] & mask)) {
303 Log("Trying to use ReadStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
306 if (tag <= MAX_TLV_TAG) {
307 len = iod_getc(iodp);
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 putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
545 #define putshort(p, v) *p++ = v>>8, *p++ = v
548 DumpDouble(struct iod *iodp, char tag, afs_uint32 value1,
552 byte *p = (unsigned char *)tbuffer;
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;
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;
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;
708 afs_int32 offset = 0;
709 afs_sfsize_t nbytes, howBig;
712 afs_foff_t howFar = 0;
717 struct afs_stat status;
721 #include <sys/statfs.h>
722 #if defined(AFS_AIX52_ENV)
723 struct statfs64 tstatfs;
724 #else /* !AFS_AIX52_ENV */
725 struct statfs tstatfs;
726 #endif /* !AFS_AIX52_ENV */
731 howBig = _filelength(handleP->fd_fd);
735 afs_fstat(handleP->fd_fd, &status);
736 howBig = status.st_size;
739 /* Unfortunately in AIX valuable fields such as st_blksize are
740 * gone from the stat structure.
742 #if defined(AFS_AIX52_ENV)
743 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
744 #else /* !AFS_AIX52_ENV */
745 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
746 #endif /* !AFS_AIX52_ENV */
747 if (statfs_code != 0) {
748 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
749 return VOLSERDUMPERROR;
751 howMany = tstatfs.f_bsize;
753 howMany = status.st_blksize;
754 #endif /* AFS_AIX_ENV */
755 #endif /* AFS_NT40_ENV */
758 size = FDH_SIZE(handleP);
759 SplitInt64(size, hi, lo);
761 code = DumpInt32(iodp, 'f', lo);
763 code = DumpDouble(iodp, 'h', hi, lo);
766 return VOLSERDUMPERROR;
771 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", (unsigned)howMany);
772 return VOLSERDUMPERROR;
775 for (nbytes = size; (nbytes && !error); nbytes -= howMany) {
776 if (nbytes < howMany)
780 n = FDH_PREAD(handleP, p, howMany, howFar);
783 /* If read any good data and we null padded previously, log the
784 * amount that we had null padded.
786 if ((n > 0) && pad) {
787 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", pad, offset);
791 /* If didn't read enough data, null padd the rest of the buffer. This
792 * can happen if, for instance, the media has some bad spots. We don't
793 * want to quit the dump, so we start null padding.
796 /* Record the read error */
799 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));
801 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
804 /* Pad the rest of the buffer with zeros. Remember offset we started
805 * padding. Keep total tally of padding.
807 memset(p + n, 0, howMany - n);
809 offset = (howBig - nbytes) + n;
810 pad += (howMany - n);
812 /* Now seek over the data we could not get. An error here means we
813 * can't do the next read.
815 howFar = (size_t)((size - nbytes) + howMany);
818 /* Now write the data out */
819 if (iod_Write(iodp, (char *)p, howMany) != howMany)
820 error = VOLSERDUMPERROR;
821 #ifndef AFS_PTHREAD_ENV
826 if (pad) { /* Any padding we hadn't reported yet */
827 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n",
836 DumpVolumeHeader(struct iod *iodp, Volume * vp)
839 static char nullString[1] = ""; /*The ``contents'' of motd */
842 code = DumpTag(iodp, D_VOLUMEHEADER);
844 code = DumpInt32(iodp, 'i', V_id(vp));
847 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
849 code = DumpString(iodp, 'n', V_name(vp));
851 code = DumpBool(iodp, 's', V_inService(vp));
853 code = DumpBool(iodp, 'b', V_blessed(vp));
855 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
857 code = DumpByte(iodp, 't', (byte) V_type(vp));
859 code = DumpInt32(iodp, 'p', V_parentId(vp));
862 code = DumpInt32(iodp, 'c', V_cloneId(vp));
864 code = DumpInt32(iodp, 'q', V_maxquota(vp));
866 code = DumpInt32(iodp, 'm', V_minquota(vp));
868 code = DumpInt32(iodp, 'd', V_diskused(vp));
870 code = DumpInt32(iodp, 'f', V_filecount(vp));
872 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
874 code = DumpInt32(iodp, 'o', V_owner(vp));
876 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
878 code = DumpInt32(iodp, 'A', V_accessDate(vp));
880 code = DumpInt32(iodp, 'U', V_updateDate(vp));
882 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
884 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
886 code = DumpString(iodp, 'O', V_offlineMessage(vp));
888 * We do NOT dump the detailed volume statistics residing in the old
889 * motd field, since we cannot tell from the info in a dump whether
890 * statistics data has been put there. Instead, we dump a null string,
891 * just as if that was what the motd contained.
894 code = DumpString(iodp, 'M', nullString);
897 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
898 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
900 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
902 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
907 DumpEnd(struct iod *iodp)
909 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
912 /* Guts of the dump code */
914 /* Dump a whole volume */
916 DumpVolume(struct rx_call *call, Volume * vp,
917 afs_int32 fromtime, int dumpAllDirs)
921 struct iod *iodp = &iod;
922 iod_Init(iodp, call);
925 code = DumpDumpHeader(iodp, vp, fromtime);
928 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
930 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
931 if (rx_Error(iodp->call)) {
932 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
933 rx_Error(iodp->call));
934 return VOLSERDUMPERROR;
937 code = DumpEnd(iodp);
942 /* Dump a volume to multiple places*/
944 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
945 afs_int32 fromtime, int dumpAllDirs, int *codes)
949 iod_InitMulti(&iod, calls, ncalls, codes);
952 code = DumpDumpHeader(&iod, vp, fromtime);
954 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
956 code = DumpEnd(&iod);
960 /* A partial dump (no dump header) */
962 DumpPartial(struct iod *iodp, Volume * vp,
963 afs_int32 fromtime, int dumpAllDirs)
967 code = DumpVolumeHeader(iodp, vp);
969 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
971 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
976 DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
977 afs_int32 fromtime, int forcedump)
980 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
981 char buf[SIZEOF_LARGEDISKVNODE];
982 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
983 StreamHandle_t *file;
985 afs_sfsize_t size, nVnodes;
989 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
990 osi_Assert(fdP != NULL);
991 file = FDH_FDOPEN(fdP, "r+");
992 osi_Assert(file != NULL);
993 size = OS_SIZE(fdP->fd_fd);
994 osi_Assert(size != -1);
995 nVnodes = (size / vcp->diskSize) - 1;
997 osi_Assert((nVnodes + 1) * vcp->diskSize == size);
998 osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1001 for (vnodeIndex = 0;
1002 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1003 nVnodes--, vnodeIndex++) {
1004 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1005 /* Note: the >= test is very important since some old volumes may not have
1006 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1007 * does dump the file! */
1010 DumpVnode(iodp, vnode, V_id(vp),
1011 bitNumberToVnodeNumber(vnodeIndex, class), flag);
1012 #ifndef AFS_PTHREAD_ENV
1014 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
1023 DumpDumpHeader(struct iod *iodp, Volume * vp,
1027 int UseLatestReadOnlyClone = 1;
1028 afs_int32 dumpTimes[2];
1029 iodp->device = vp->device;
1030 iodp->parentId = V_parentId(vp);
1031 iodp->dumpPartition = vp->partition;
1033 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
1036 DumpInt32(iodp, 'v',
1037 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
1039 code = DumpString(iodp, 'n', V_name(vp));
1040 dumpTimes[0] = fromtime;
1041 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
1043 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
1048 DumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1049 int vnodeNumber, int dumpEverything)
1055 if (!v || v->type == vNull)
1058 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
1059 if (!dumpEverything)
1062 code = DumpByte(iodp, 't', (byte) v->type);
1064 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
1066 code = DumpInt32(iodp, 'v', v->dataVersion);
1068 code = DumpInt32(iodp, 'm', v->unixModifyTime);
1070 code = DumpInt32(iodp, 'a', v->author);
1072 code = DumpInt32(iodp, 'o', v->owner);
1073 if (!code && v->group)
1074 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
1076 code = DumpShort(iodp, 'b', v->modeBits);
1078 code = DumpInt32(iodp, 'p', v->parent);
1080 code = DumpInt32(iodp, 's', v->serverModifyTime);
1081 if (v->type == vDirectory) {
1082 acl_HtonACL(VVnodeDiskACL(v));
1085 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
1088 if (VNDISK_GET_INO(v)) {
1089 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1092 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);
1094 return VOLSERREAD_DUMPERROR;
1096 code = DumpFile(iodp, vnodeNumber, fdP);
1105 ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep,
1108 int i, nVnodes, offset, code;
1112 StreamHandle_t *afile;
1114 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1115 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1116 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1118 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1119 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1122 afile = FDH_FDOPEN(fdP, "r+");
1126 for (i = 0; i < *sizep; i++) {
1129 STREAM_ASEEK(afile, Buf[i]);
1130 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1132 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1135 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
1136 V_id(vp), bitNumberToVnodeNumber(i, class),
1137 (afs_uintmax_t) VNDISK_GET_INO(vnode));
1139 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1143 STREAM_ASEEK(afile, Buf[i]);
1144 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1150 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1153 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1154 OS_SYNC(afile->str_fd);
1156 size = OS_SIZE(fdP->fd_fd);
1157 osi_Assert(size != -1);
1160 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1163 Log("RestoreVolume ProcessIndex: Set up %d inodes for volume %d\n",
1166 Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32));
1168 STREAM_CLOSE(afile);
1172 memset(Buf, 0, nVnodes * sizeof(afs_int32));
1173 STREAM_ASEEK(afile, offset = vcp->diskSize);
1175 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1179 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1180 Buf[(offset >> vcp->logSize) - 1] = offset;
1183 offset += vcp->diskSize;
1186 Log("RestoreVolume ProcessIndex: found %d inodes\n", cnt);
1192 STREAM_CLOSE(afile);
1199 RestoreVolume(struct rx_call *call, Volume * avp, int incremental,
1200 struct restoreCookie *cookie)
1203 struct DumpHeader header;
1204 afs_uint32 endMagic;
1205 Error error = 0, vupdate;
1208 struct iod *iodp = &iod;
1209 afs_int32 *b1 = NULL, *b2 = NULL;
1210 int s1 = 0, s2 = 0, delo = 0, tdelo;
1213 iod_Init(iodp, call);
1217 if (!ReadDumpHeader(iodp, &header)) {
1218 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1219 return VOLSERREAD_DUMPERROR;
1221 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1222 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1223 return VOLSERREAD_DUMPERROR;
1225 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1226 return VOLSERREAD_DUMPERROR;
1229 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1231 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1233 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1234 error = VOLSERREAD_DUMPERROR;
1238 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1239 vol.type = cookie->type;
1240 vol.cloneId = cookie->clone;
1241 vol.parentId = cookie->parent;
1245 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1246 error = VOLSERREAD_DUMPERROR;
1249 tag = iod_getc(iodp);
1250 if (tag != D_VOLUMEHEADER)
1253 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1254 error = VOLSERREAD_DUMPERROR;
1258 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1259 || endMagic != DUMPENDMAGIC) {
1260 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1261 error = VOLSERREAD_DUMPERROR;
1266 if (iod_getc(iodp) != EOF) {
1267 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1268 error = VOLSERREAD_DUMPERROR;
1273 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1275 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1277 error = VOLSERREAD_DUMPERROR;
1283 ClearVolumeStats(&vol);
1284 CopyVolumeHeader(&vol, &V_disk(vp));
1285 V_destroyMe(vp) = 0;
1286 VUpdateVolume(&vupdate, vp);
1288 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1289 error = VOLSERREAD_DUMPERROR;
1293 /* Free the malloced space above */
1302 ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
1303 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2,
1306 afs_int32 vnodeNumber;
1307 char buf[SIZEOF_LARGEDISKVNODE];
1309 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1310 struct VnodeDiskObject oldvnode;
1313 struct VnodeClassInfo *vcp;
1317 afs_int32 critical = 0;
1319 tag = iod_getc(iodp);
1320 V_pref(vp, nearInode);
1321 while (tag == D_VNODE) {
1324 memset(buf, 0, sizeof(buf));
1325 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1328 if (!ReadInt32(iodp, &vnode->uniquifier))
1329 return VOLSERREAD_DUMPERROR;
1332 Log("ReadVnodes: setup %d/%d\n", vnodeNumber, vnode->uniquifier);
1334 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1340 vnode->type = (VnodeType) iod_getc(iodp);
1345 if (!ReadShort(iodp, &tlc))
1346 return VOLSERREAD_DUMPERROR;
1347 vnode->linkCount = (signed int)tlc;
1351 if (!ReadInt32(iodp, &vnode->dataVersion))
1352 return VOLSERREAD_DUMPERROR;
1355 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1356 return VOLSERREAD_DUMPERROR;
1359 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1360 return VOLSERREAD_DUMPERROR;
1363 if (!ReadInt32(iodp, &vnode->author))
1364 return VOLSERREAD_DUMPERROR;
1367 if (!ReadInt32(iodp, &vnode->owner))
1368 return VOLSERREAD_DUMPERROR;
1371 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1372 return VOLSERREAD_DUMPERROR;
1375 unsigned short modeBits;
1376 if (!ReadShort(iodp, &modeBits))
1377 return VOLSERREAD_DUMPERROR;
1378 vnode->modeBits = (unsigned int)modeBits;
1382 if (!ReadInt32(iodp, &vnode->parent))
1383 return VOLSERREAD_DUMPERROR;
1386 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1387 VAclDiskSize(vnode));
1388 acl_NtohACL(VVnodeDiskACL(vnode));
1394 afs_fsize_t vnodeLength;
1397 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1398 "file entries for vnode %lu in dump\n",
1399 (unsigned long)vnodeNumber);
1400 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1406 IH_CREATE(V_linkHandle(vp), V_device(vp),
1407 VPartitionPath(V_partition(vp)), nearInode,
1408 V_parentId(vp), vnodeNumber,
1409 vnode->uniquifier, vnode->dataVersion);
1410 if (!VALID_INO(ino)) {
1411 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1412 afs_error_message(errno));
1413 return VOLSERREAD_DUMPERROR;
1416 VNDISK_SET_INO(vnode, ino);
1417 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1418 fdP = IH_OPEN(tmpH);
1420 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1421 afs_error_message(errno));
1423 return VOLSERREAD_DUMPERROR;
1426 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1427 VNDISK_SET_LEN(vnode, vnodeLength);
1428 FDH_REALLYCLOSE(fdP);
1431 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1432 (afs_uintmax_t) ino);
1433 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1434 return VOLSERREAD_DUMPERROR;
1442 if (!HandleUnknownTag(iodp, tag, 2, critical))
1443 return VOLSERREAD_DUMPERROR;
1447 class = vnodeIdToClass(vnodeNumber);
1448 vcp = &VnodeClassInfo[class];
1450 /* Mark this vnode as in this dump - so we don't delete it later */
1452 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1453 if (class == vLarge) {
1454 if (Lbuf && (idx < s1))
1457 if (Sbuf && (idx < s2))
1463 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1465 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1466 afs_error_message(errno));
1467 return VOLSERREAD_DUMPERROR;
1469 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1471 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1472 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1476 vnode->vnodeMagic = vcp->magic;
1477 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1478 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1479 afs_error_message(errno));
1480 FDH_REALLYCLOSE(fdP);
1481 return VOLSERREAD_DUMPERROR;
1486 iod_ungetc(iodp, tag);
1492 /* called with disk file only. Note that we don't have to worry about rx_Read
1493 * needing to read an ungetc'd character, since the ReadInt32 will have read
1496 * if handleP == NULL, don't write the file anywhere; just read and discard
1500 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1505 afs_fsize_t filesize;
1506 afs_fsize_t written = 0;
1514 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1516 if (!ReadInt32(iodp, &filesize_high)) {
1521 if (!ReadInt32(iodp, &filesize_low)) {
1525 FillInt64(filesize, filesize_high, filesize_low);
1527 p = (unsigned char *)malloc(size);
1532 for (nbytes = filesize; nbytes; nbytes -= size) {
1536 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1537 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));
1542 nBytes = FDH_PWRITE(handleP, p, size, written);
1545 if (nBytes != size) {
1546 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1557 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1560 afs_uint32 beginMagic;
1561 afs_int32 critical = 0;
1562 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1563 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1564 || beginMagic != DUMPBEGINMAGIC)
1568 while ((tag = iod_getc(iodp)) > D_MAX) {
1569 unsigned short arrayLength;
1575 if (!ReadInt32(iodp, &hp->volumeId))
1579 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1582 if (!ReadShort(iodp, &arrayLength))
1584 hp->nDumpTimes = (arrayLength >> 1);
1585 for (i = 0; i < hp->nDumpTimes; i++)
1586 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1587 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1594 if (!HandleUnknownTag(iodp, tag, 0, critical))
1595 return VOLSERREAD_DUMPERROR;
1598 if (!hp->volumeId || !hp->nDumpTimes) {
1601 iod_ungetc(iodp, tag);
1606 /* ----- Below are the calls that calculate dump size ----- */
1609 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1610 struct volintSize *v_size)
1613 static char nullString[1] = ""; /*The ``contents'' of motd */
1616 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1617 FillInt64(addvar,0, 1);
1618 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1619 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1620 FillInt64(addvar,0, 5);
1621 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1622 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1623 FillInt64(addvar,0, 5);
1624 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1625 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1626 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1627 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1628 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1629 FillInt64(addvar,0, 2);
1630 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1631 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1632 FillInt64(addvar,0, 2);
1633 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1634 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1635 FillInt64(addvar,0, 5);
1636 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1637 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1638 FillInt64(addvar,0, 2);
1639 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1640 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1641 FillInt64(addvar,0, 5);
1642 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1643 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1644 FillInt64(addvar,0, 5);
1645 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1646 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1647 FillInt64(addvar,0, 5);
1648 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1649 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1650 FillInt64(addvar,0, 5);
1651 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1652 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1653 FillInt64(addvar,0, 5);
1654 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1655 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1656 FillInt64(addvar,0, 5);
1657 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1658 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1659 FillInt64(addvar,0, 5);
1660 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1661 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1662 FillInt64(addvar,0, 5);
1663 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1664 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1665 FillInt64(addvar,0, 5);
1666 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1667 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1668 FillInt64(addvar,0, 5);
1669 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1670 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1671 FillInt64(addvar,0, 5);
1672 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1673 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1674 FillInt64(addvar,0, 5);
1675 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1676 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1677 FillInt64(addvar,0, 5);
1678 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1679 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1680 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1681 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1683 /* * We do NOT dump the detailed volume statistics residing in the old */
1684 /* * motd field, since we cannot tell from the info in a dump whether */
1685 /* * statistics data has been put there. Instead, we dump a null string, */
1686 /* * just as if that was what the motd contained. */
1688 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1689 FillInt64(addvar,0, (2 + strlen(nullString)));
1690 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1691 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1692 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1693 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1694 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1695 FillInt64(addvar,0, 5);
1696 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1697 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1698 FillInt64(addvar,0, 5);
1699 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1704 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1708 FillInt64(addvar,0, 5);
1709 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1714 SizeDumpVolume(struct rx_call *call, Volume * vp,
1715 afs_int32 fromtime, int dumpAllDirs,
1716 struct volintSize *v_size)
1719 struct iod *iodp = (struct iod *)0;
1720 /* iod_Init(iodp, call); */
1723 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1725 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1727 code = SizeDumpEnd(iodp, v_size);
1733 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1734 afs_int32 fromtime, struct volintSize *v_size)
1737 /* int UseLatestReadOnlyClone = 1; */
1738 /* afs_int32 dumpTimes[2]; */
1740 /* iodp->device = vp->device; */
1741 /* iodp->parentId = V_parentId(vp); */
1742 /* iodp->dumpPartition = vp->partition; */
1744 ZeroInt64(v_size->dump_size); /* initialize the size */
1745 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1746 FillInt64(addvar,0, 9);
1747 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1748 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1749 FillInt64(addvar,0, 5);
1750 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1751 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1752 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1753 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1754 /* dumpTimes[0] = fromtime; */
1755 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1756 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1757 FillInt64(addvar,0, (3 + 4 * 2));
1758 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1763 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1764 int vnodeNumber, int dumpEverything,
1765 struct volintSize *v_size)
1770 if (!v || v->type == vNull)
1772 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1773 FillInt64(addvar,0, 9);
1774 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1775 if (!dumpEverything)
1777 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1778 FillInt64(addvar,0, 2);
1779 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1780 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1781 FillInt64(addvar,0, 3);
1782 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1783 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1784 FillInt64(addvar,0, 5);
1785 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1786 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1787 FillInt64(addvar,0, 5);
1788 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1789 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1790 FillInt64(addvar,0, 5);
1791 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1792 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1793 FillInt64(addvar,0, 5);
1794 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1795 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1797 FillInt64(addvar,0, 5);
1798 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1800 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1801 FillInt64(addvar,0, 3);
1802 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1803 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1804 FillInt64(addvar,0, 5);
1805 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1806 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1807 FillInt64(addvar,0, 5);
1808 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1809 if (v->type == vDirectory) {
1810 /* acl_HtonACL(VVnodeDiskACL(v)); */
1811 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1812 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1813 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1816 if (VNDISK_GET_INO(v)) {
1817 FillInt64(addvar,0, (v->length + 5));
1818 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1823 /* A partial dump (no dump header) */
1825 SizeDumpPartial(struct iod *iodp, Volume * vp,
1826 afs_int32 fromtime, int dumpAllDirs,
1827 struct volintSize *v_size)
1831 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1834 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1837 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1842 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1843 afs_int32 fromtime, int forcedump,
1844 struct volintSize *v_size)
1847 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1848 char buf[SIZEOF_LARGEDISKVNODE];
1849 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1850 StreamHandle_t *file;
1852 afs_sfsize_t size, nVnodes;
1856 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1857 osi_Assert(fdP != NULL);
1858 file = FDH_FDOPEN(fdP, "r+");
1859 osi_Assert(file != NULL);
1860 size = OS_SIZE(fdP->fd_fd);
1861 osi_Assert(size != -1);
1862 nVnodes = (size / vcp->diskSize) - 1;
1864 osi_Assert((nVnodes + 1) * vcp->diskSize == size);
1865 osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1868 for (vnodeIndex = 0;
1869 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1870 nVnodes--, vnodeIndex++) {
1871 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1872 /* Note: the >= test is very important since some old volumes may not have
1873 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1874 * does dump the file! */
1877 SizeDumpVnode(iodp, vnode, V_id(vp),
1878 bitNumberToVnodeNumber(vnodeIndex, class), flag,