2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
19 #include <rx/rx_queue.h>
20 #include <afs/afsint.h>
22 #include <afs/errors.h>
25 #include <afs/ihandle.h>
26 #include <afs/vnode.h>
27 #include <afs/volume.h>
28 #include <afs/partition.h>
29 #include <afs/daemon_com.h>
30 #include <afs/fssync.h>
32 #include <afs/com_err.h>
33 #include <afs/vol_prototypes.h>
38 #include "dumpstuff.h"
42 #define afs_stat stat64
43 #define afs_fstat fstat64
44 #else /* !O_LARGEFILE */
46 #define afs_fstat fstat
47 #endif /* !O_LARGEFILE */
48 #endif /* !AFS_NT40_ENV */
50 /*@printflike@*/ extern void Log(const char *format, ...);
53 extern int DoPreserveVolumeStats;
56 /* Forward Declarations */
57 static int DumpDumpHeader(struct iod *iodp, Volume * vp,
59 static int DumpPartial(struct iod *iodp, Volume * vp,
60 afs_int32 fromtime, int dumpAllDirs);
61 static int DumpVnodeIndex(struct iod *iodp, Volume * vp,
62 VnodeClass class, afs_int32 fromtime,
64 static int DumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
65 VolumeId volid, int vnodeNumber, int dumpEverything);
66 static int ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp);
67 static int ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
68 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf,
69 afs_int32 s2, afs_int32 delo);
70 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
71 FdHandle_t * handleP, int tag,
74 static int SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
76 struct volintSize *size);
77 static int SizeDumpPartial(struct iod *iodp, Volume * vp,
78 afs_int32 fromtime, int dumpAllDirs,
79 struct volintSize *size);
80 static int SizeDumpVnodeIndex(struct iod *iodp, Volume * vp,
81 VnodeClass class, afs_int32 fromtime,
83 struct volintSize *size);
84 static int SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
85 VolumeId volid, int vnodeNumber, int dumpEverything,
86 struct volintSize *size);
88 #define MAX_SECTIONS 3
90 /* The TLV range must start above D_MAX */
91 #define MIN_TLV_TAG 21
92 #define MAX_TLV_TAG 0x60
93 #define MAX_STANDARD_TAG 0x7a
94 static afs_uint32 oldtags[MAX_SECTIONS][16];
95 int oldtagsInited = 0;
98 RegisterTag(afs_int32 section, unsigned char tag)
100 afs_uint32 off = tag >> 5;
101 afs_uint32 mask = 1 << (tag & 0x1f);
102 oldtags[section][off] |= mask;
106 initNonStandardTags(void)
108 RegisterTag(0, 'n'); /* volume name */
109 RegisterTag(0, 't'); /* fromtime, V_backupDate */
110 RegisterTag(1, 'A'); /* V_accessDate */
111 RegisterTag(1, 'C'); /* V_creationDate */
112 RegisterTag(1, 'D'); /* V_dayUseDate */
113 RegisterTag(1, 'E'); /* V_expirationDate */
114 RegisterTag(1, 'M'); /* nullstring (motd) */
115 RegisterTag(1, 'U'); /* V_updateDate */
116 RegisterTag(1, 'W'); /* V_weekUse */
117 RegisterTag(1, 'Z'); /* V_dayUse */
118 RegisterTag(1, 'O'); /* V_offlineMessage */
119 RegisterTag(1, 'b'); /* V_blessed */
120 RegisterTag(1, 'n'); /* V_name */
121 RegisterTag(1, 's'); /* V_inService */
122 RegisterTag(1, 't'); /* V_type */
123 RegisterTag(2, 'A'); /* VVnodeDiskACL */
124 RegisterTag(2, 'b'); /* modeBits */
125 RegisterTag(2, 'f'); /* small file */
126 RegisterTag(2, 'h'); /* large file */
127 RegisterTag(2, 'l'); /* linkcount */
128 RegisterTag(2, 't'); /* type */
133 iod_Init(struct iod *iodp, struct rx_call *call)
136 iodp->haveOldChar = 0;
138 iodp->calls = (struct rx_call **)0;
142 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
147 iodp->haveOldChar = 0;
148 iodp->ncalls = ncalls;
150 iodp->call = (struct rx_call *)0;
153 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
154 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
156 /* For the single dump case, it's ok to just return the "bytes written"
157 * that rx_Write returns, since all the callers of iod_Write abort when
158 * the returned value is less than they expect. For the multi dump case,
159 * I don't think we want half the replicas to go bad just because one
160 * connection timed out, but if they all time out, then we should give up.
163 iod_Write(struct iod *iodp, char *buf, int nbytes)
168 opr_Assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
169 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
172 code = rx_Write(iodp->call, buf, nbytes);
176 for (i = 0; i < iodp->ncalls; i++) {
177 if (iodp->calls[i] && !iodp->codes[i]) {
178 code = rx_Write(iodp->calls[i], buf, nbytes);
179 if (code != nbytes) { /* everything gets merged into a single error */
180 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
181 } /* standard dump does, anyways */
186 } /* for all calls */
195 iod_ungetc(struct iod *iodp, int achar)
197 iodp->oldChar = achar;
198 iodp->haveOldChar = 1;
202 iod_getc(struct iod *iodp)
206 if (iodp->haveOldChar) {
207 iodp->haveOldChar = 0;
208 return iodp->oldChar;
210 if (iod_Read(iodp, (char *) &t, 1) == 1)
216 ReadShort(struct iod *iodp, unsigned short *sp)
225 *sp = (b1 << 8) | b0;
230 ReadInt32(struct iod *iodp, afs_uint32 * lp)
232 afs_uint32 b3, b2, b1, b0;
245 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
250 ReadString(struct iod *iodp, char *to, int maxa)
259 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
263 while ((c = iod_getc(iodp)) && c != EOF);
269 ReadByteString(struct iod *iodp, byte * to,
273 *to++ = iod_getc(iodp);
277 * returns 1 on success and 0 otherwise
280 ReadStandardTagLen(struct iod *iodp, unsigned char tag, afs_int32 section,
284 afs_uint32 off = tag >> 5;
285 afs_uint32 mask = 1 << (tag & 0x1f);
287 unsigned char buf[8], *p;
290 initNonStandardTags();
292 if (tag < MIN_TLV_TAG
293 || tag > MAX_STANDARD_TAG
294 || section >= MAX_SECTIONS
295 || (oldtags[section][ off] & mask)) {
296 Log("Trying to use ReadStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
299 if (tag <= MAX_TLV_TAG) {
300 len = iod_getc(iodp);
302 return VOLSERDUMPERROR;
307 if ((code = iod_Read(iodp, (char *)buf, len)) != len)
308 return VOLSERDUMPERROR;
310 p = (unsigned char *)&buf;
311 for (i=0; i<len; i++) {
312 *length = ((*length) << 8) | *p++;
316 if (tag < MAX_STANDARD_TAG)
322 static char skipbuf[256];
325 SkipData(struct iod *iodp, afs_size_t length)
327 while (length > 256) {
328 if (iod_Read(iodp, (char *)&skipbuf, 256) != 256)
332 if (iod_Read(iodp, (char *)&skipbuf, length) != length)
337 static char *secname[3] = {"ReadDumpHeader", "ReadVolumeHeader", "ReadVnodes"};
340 HandleUnknownTag(struct iod *iodp, int tag, afs_int32 section,
343 afs_size_t taglen = 0;
347 Log("%s: unknown critical tag x%02x, aborting\n",
348 secname[section], tag);
351 Log("%s: unknown tag x%02x found, skipping\n", secname[section], tag);
352 if (tag >= 0x06 && tag <= 0x60) {
353 if (!ReadStandardTagLen(iodp, tag, 1, &taglen)) {
354 Log("%s: error reading length field for tag x%02x, aborting\n",
355 secname[section], tag);
358 if (!SkipData(iodp, taglen)) {
359 Log("%s: error skipping %llu bytes for tag x%02x, aborting\n",
360 secname[section], taglen, tag);
365 if (tag >= 0x61 && tag <= 0x7a) {
366 if (!ReadInt32(iodp, &trash)) {
367 Log("%s: error skipping int32 for tag x%02x, aborting\n",
368 secname[section], tag);
373 if (tag >= 0x7b && tag < 0x80) /* dataless tag */
375 Log("%s: unknown invalid tag x%02x, aborting\n", secname[section], tag);
380 ReadVolumeHeader(struct iod *iodp, VolumeDiskData * vol)
384 afs_int32 critical = 0;
385 memset(vol, 0, sizeof(*vol));
386 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
391 if (!ReadInt32(iodp, &vol->id))
392 return VOLSERREAD_DUMPERROR;
395 if (!ReadInt32(iodp, &trash))
396 return VOLSERREAD_DUMPERROR;
399 ReadString(iodp, vol->name, sizeof(vol->name));
400 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
403 vol->inService = iod_getc(iodp);
406 vol->blessed = iod_getc(iodp);
409 if (!ReadInt32(iodp, &vol->uniquifier))
410 return VOLSERREAD_DUMPERROR;
413 vol->type = iod_getc(iodp);
416 if (!ReadInt32(iodp, &vol->parentId))
417 return VOLSERREAD_DUMPERROR;
420 if (!ReadInt32(iodp, &vol->cloneId))
421 return VOLSERREAD_DUMPERROR;
424 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
425 return VOLSERREAD_DUMPERROR;
428 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
429 return VOLSERREAD_DUMPERROR;
432 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
433 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
436 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
437 return VOLSERREAD_DUMPERROR;
440 if (!ReadInt32(iodp, &vol->accountNumber))
441 return VOLSERREAD_DUMPERROR;
444 if (!ReadInt32(iodp, &vol->owner))
445 return VOLSERREAD_DUMPERROR;
448 if (!ReadInt32(iodp, &vol->creationDate))
449 return VOLSERREAD_DUMPERROR;
452 if (!ReadInt32(iodp, &vol->accessDate))
453 return VOLSERREAD_DUMPERROR;
456 if (!ReadInt32(iodp, &vol->updateDate))
457 return VOLSERREAD_DUMPERROR;
460 if (!ReadInt32(iodp, &vol->expirationDate))
461 return VOLSERREAD_DUMPERROR;
464 if (!ReadInt32(iodp, &vol->backupDate))
465 return VOLSERREAD_DUMPERROR;
468 ReadString(iodp, vol->offlineMessage,
469 sizeof(vol->offlineMessage));
473 * Detailed volume statistics are never stored in dumps,
474 * so we just restore either the null string if this volume
475 * had already been set to store statistics, or the old motd
476 * contents otherwise. It doesn't matter, since this field
477 * will soon get initialized anyway.
479 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
482 unsigned short length;
485 if (!ReadShort(iodp, &length))
486 return VOLSERREAD_DUMPERROR;
487 for (i = 0; i < length; i++) {
488 if (!ReadInt32(iodp, &data))
489 return VOLSERREAD_DUMPERROR;
490 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
491 vol->weekUse[i] = data;
496 if (!ReadInt32(iodp, &vol->dayUseDate))
497 return VOLSERREAD_DUMPERROR;
500 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
501 return VOLSERREAD_DUMPERROR;
504 if (!ReadInt32(iodp, (afs_uint32 *) &trash/*volUpdateCounter*/))
505 return VOLSERREAD_DUMPERROR;
511 if (!HandleUnknownTag(iodp, tag, 1, critical))
512 return VOLSERREAD_DUMPERROR;
515 iod_ungetc(iodp, tag);
520 DumpTag(struct iod *iodp, int tag)
525 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
530 DumpByte(struct iod *iodp, char tag, byte value)
533 byte *p = (unsigned char *)tbuffer;
536 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
539 #define afs_putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
540 #define afs_putshort(p, v) *p++ = v>>8, *p++ = v
543 DumpDouble(struct iod *iodp, char tag, afs_uint32 value1,
547 byte *p = (unsigned char *)tbuffer;
549 afs_putint32(p, value1);
550 afs_putint32(p, value2);
551 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
555 DumpInt32(struct iod *iodp, char tag, afs_uint32 value)
558 byte *p = (unsigned char *)tbuffer;
560 afs_putint32(p, value);
561 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
565 DumpArrayInt32(struct iod *iodp, char tag,
566 afs_uint32 * array, int nelem)
571 byte *p = (unsigned char *)tbuffer;
573 afs_putshort(p, nelem);
574 code = iod_Write(iodp, tbuffer, 3);
576 return VOLSERDUMPERROR;
578 p = (unsigned char *)tbuffer;
579 v = *array++; /*this was register */
582 code = iod_Write(iodp, tbuffer, 4);
584 return VOLSERDUMPERROR;
590 DumpShort(struct iod *iodp, char tag, unsigned int value)
593 byte *p = (unsigned char *)tbuffer;
597 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
601 DumpBool(struct iod *iodp, char tag, unsigned int value)
604 byte *p = (unsigned char *)tbuffer;
607 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
611 DumpString(struct iod *iodp, char tag, char *s)
615 code = iod_Write(iodp, &tag, 1);
617 return VOLSERDUMPERROR;
619 code = iod_Write(iodp, s, n);
621 return VOLSERDUMPERROR;
626 DumpByteString(struct iod *iodp, char tag, byte * bs,
631 code = iod_Write(iodp, &tag, 1);
633 return VOLSERDUMPERROR;
634 code = iod_Write(iodp, (char *)bs, nbytes);
636 return VOLSERDUMPERROR;
641 DumpStandardTag(struct iod *iodp, char tag, afs_uint32 section)
644 afs_uint32 off = tag >> 5;
645 afs_uint32 mask = 1 << (tag & 0x1f);
648 initNonStandardTags();
650 if (tag < MIN_TLV_TAG
651 || tag > MAX_STANDARD_TAG
652 || section >= MAX_SECTIONS
653 || (oldtags[section][ off] & mask)) {
654 Log("Trying to use DumpStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
655 return VOLSERDUMPERROR;
657 code = iod_Write(iodp, &tag, 1);
659 return VOLSERDUMPERROR;
665 DumpStandardTagLen(struct iod *iodp, char tag, afs_uint32 section,
672 if (tag < MIN_TLV_TAG || tag > MAX_TLV_TAG) {
673 Log("Trying to use DumpStandardTagLen with tag 0x%02x for section %d, aborting\n", tag, section);
674 return VOLSERDUMPERROR;
676 code = DumpStandardTag(iodp, tag, section);
680 if (length < 128) { /* byte after tag contains length */
683 } else { /* byte after tag contains length of length field | 0x80 */
684 for (len=0; length; length=length >> 8) {
692 code = iod_Write(iodp, p, len);
694 return VOLSERDUMPERROR;
699 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
701 int code = 0, error = 0;
703 afs_foff_t offset = 0;
704 afs_sfsize_t nbytes, howBig;
707 afs_foff_t howFar = 0;
712 struct afs_stat status;
714 LARGE_INTEGER fileSize;
717 #include <sys/statfs.h>
718 #if defined(AFS_AIX52_ENV)
719 struct statfs64 tstatfs;
720 #else /* !AFS_AIX52_ENV */
721 struct statfs tstatfs;
722 #endif /* !AFS_AIX52_ENV */
727 if (!GetFileSizeEx(handleP->fd_fd, &fileSize)) {
728 Log("DumpFile: GetFileSizeEx returned error code %d on descriptor %d\n", GetLastError(), handleP->fd_fd);
729 return VOLSERDUMPERROR;
731 howBig = fileSize.QuadPart;
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 SplitInt64(howBig, hi, lo);
760 code = DumpInt32(iodp, 'f', lo);
762 code = DumpDouble(iodp, 'h', hi, lo);
765 return VOLSERDUMPERROR;
770 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", (unsigned)howMany);
771 return VOLSERDUMPERROR;
774 for (nbytes = howBig; (nbytes && !error); nbytes -= howMany) {
775 if (nbytes < howMany)
779 n = FDH_PREAD(handleP, p, howMany, howFar);
782 /* If read any good data and we null padded previously, log the
783 * amount that we had null padded.
785 if ((n > 0) && pad) {
786 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %lld\n", pad, (long long)offset);
790 /* If didn't read enough data, null padd the rest of the buffer. This
791 * can happen if, for instance, the media has some bad spots. We don't
792 * want to quit the dump, so we start null padding.
795 /* Record the read error */
798 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));
800 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
803 /* Pad the rest of the buffer with zeros. Remember offset we started
804 * padding. Keep total tally of padding.
806 memset(p + n, 0, howMany - n);
808 offset = (howBig - nbytes) + n;
809 pad += (howMany - n);
811 /* Now seek over the data we could not get. An error here means we
812 * can't do the next read.
814 howFar = (size_t)((howBig - nbytes) + howMany);
817 /* Now write the data out */
818 if (iod_Write(iodp, (char *)p, howMany) != howMany)
819 error = VOLSERDUMPERROR;
820 #ifndef AFS_PTHREAD_ENV
825 if (pad) { /* Any padding we hadn't reported yet */
826 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %lld\n",
827 pad, (long long)offset);
835 DumpVolumeHeader(struct iod *iodp, Volume * vp)
838 static char nullString[1] = ""; /*The ``contents'' of motd */
841 code = DumpTag(iodp, D_VOLUMEHEADER);
843 code = DumpInt32(iodp, 'i', V_id(vp));
846 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
848 code = DumpString(iodp, 'n', V_name(vp));
850 code = DumpBool(iodp, 's', V_inService(vp));
852 code = DumpBool(iodp, 'b', V_blessed(vp));
854 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
856 code = DumpByte(iodp, 't', (byte) V_type(vp));
858 code = DumpInt32(iodp, 'p', V_parentId(vp));
861 code = DumpInt32(iodp, 'c', V_cloneId(vp));
863 code = DumpInt32(iodp, 'q', V_maxquota(vp));
865 code = DumpInt32(iodp, 'm', V_minquota(vp));
867 code = DumpInt32(iodp, 'd', V_diskused(vp));
869 code = DumpInt32(iodp, 'f', V_filecount(vp));
871 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
873 code = DumpInt32(iodp, 'o', V_owner(vp));
875 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
877 code = DumpInt32(iodp, 'A', V_accessDate(vp));
879 code = DumpInt32(iodp, 'U', V_updateDate(vp));
881 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
883 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
885 code = DumpString(iodp, 'O', V_offlineMessage(vp));
887 * We do NOT dump the detailed volume statistics residing in the old
888 * motd field, since we cannot tell from the info in a dump whether
889 * statistics data has been put there. Instead, we dump a null string,
890 * just as if that was what the motd contained.
893 code = DumpString(iodp, 'M', nullString);
896 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
897 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
899 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
901 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
906 DumpEnd(struct iod *iodp)
908 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
911 /* Guts of the dump code */
913 /* Dump a whole volume */
915 DumpVolume(struct rx_call *call, Volume * vp,
916 afs_int32 fromtime, int dumpAllDirs)
920 struct iod *iodp = &iod;
921 iod_Init(iodp, call);
924 code = DumpDumpHeader(iodp, vp, fromtime);
927 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
929 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
930 if (rx_Error(iodp->call)) {
931 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
932 rx_Error(iodp->call));
933 return VOLSERDUMPERROR;
936 code = DumpEnd(iodp);
941 /* Dump a volume to multiple places*/
943 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
944 afs_int32 fromtime, int dumpAllDirs, int *codes)
948 iod_InitMulti(&iod, calls, ncalls, codes);
951 code = DumpDumpHeader(&iod, vp, fromtime);
953 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
955 code = DumpEnd(&iod);
959 /* A partial dump (no dump header) */
961 DumpPartial(struct iod *iodp, Volume * vp,
962 afs_int32 fromtime, int dumpAllDirs)
966 code = DumpVolumeHeader(iodp, vp);
968 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
970 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
975 DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
976 afs_int32 fromtime, int forcedump)
979 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
980 char buf[SIZEOF_LARGEDISKVNODE];
981 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
982 StreamHandle_t *file;
984 afs_sfsize_t size, nVnodes;
988 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
989 opr_Assert(fdP != NULL);
990 file = FDH_FDOPEN(fdP, "r+");
991 opr_Assert(file != NULL);
992 size = OS_SIZE(fdP->fd_fd);
993 opr_Assert(size != -1);
994 nVnodes = (size / vcp->diskSize) - 1;
996 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
997 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1000 for (vnodeIndex = 0;
1001 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1002 nVnodes--, vnodeIndex++) {
1003 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1004 /* Note: the >= test is very important since some old volumes may not have
1005 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1006 * does dump the file! */
1009 DumpVnode(iodp, vnode, V_id(vp),
1010 bitNumberToVnodeNumber(vnodeIndex, class), flag);
1011 #ifndef AFS_PTHREAD_ENV
1013 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
1022 DumpDumpHeader(struct iod *iodp, Volume * vp,
1026 int UseLatestReadOnlyClone = 1;
1027 afs_int32 dumpTimes[2];
1028 iodp->device = vp->device;
1029 iodp->parentId = V_parentId(vp);
1030 iodp->dumpPartition = vp->partition;
1032 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
1035 DumpInt32(iodp, 'v',
1036 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
1038 code = DumpString(iodp, 'n', V_name(vp));
1039 dumpTimes[0] = fromtime;
1040 switch (V_type(vp)) {
1041 case readwriteVolume:
1042 dumpTimes[1] = V_updateDate(vp); /* until last update */
1044 case readonlyVolume:
1045 dumpTimes[1] = V_creationDate(vp); /* until clone was updated */
1048 /* until backup was made */
1049 dumpTimes[1] = V_backupDate(vp) != 0 ? V_backupDate(vp) :
1056 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
1061 DumpVnode(struct iod *iodp, struct VnodeDiskObject *v, VolumeId volid,
1062 int vnodeNumber, int dumpEverything)
1069 if (!v || v->type == vNull)
1072 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
1073 if (!dumpEverything)
1076 code = DumpByte(iodp, 't', (byte) v->type);
1078 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
1080 code = DumpInt32(iodp, 'v', v->dataVersion);
1082 code = DumpInt32(iodp, 'm', v->unixModifyTime);
1084 code = DumpInt32(iodp, 'a', v->author);
1086 code = DumpInt32(iodp, 'o', v->owner);
1087 if (!code && v->group)
1088 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
1090 code = DumpShort(iodp, 'b', v->modeBits);
1092 code = DumpInt32(iodp, 'p', v->parent);
1094 code = DumpInt32(iodp, 's', v->serverModifyTime);
1095 if (v->type == vDirectory) {
1096 acl_HtonACL(VVnodeDiskACL(v));
1099 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
1102 if (VNDISK_GET_INO(v)) {
1103 afs_sfsize_t indexlen, disklen;
1104 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1107 Log("1 Volser: DumpVnode: dump: Unable to open inode %s "
1108 "for vnode %u (volume %" AFS_VOLID_FMT "); "
1109 "not dumped, error %d\n",
1110 PrintInode(stmp, VNDISK_GET_INO(v)), vnodeNumber,
1111 afs_printable_VolumeId_lu(volid), errno);
1113 return VOLSERREAD_DUMPERROR;
1115 VNDISK_GET_LEN(indexlen, v);
1116 disklen = FDH_SIZE(fdP);
1117 if (indexlen != disklen) {
1118 FDH_REALLYCLOSE(fdP);
1120 Log("DumpVnode: volume %"AFS_VOLID_FMT" "
1121 "vnode %lu has inconsistent length "
1122 "(index %lu disk %lu); aborting dump\n",
1123 afs_printable_VolumeId_lu(volid), (unsigned long)vnodeNumber,
1124 (unsigned long)indexlen, (unsigned long)disklen);
1125 return VOLSERREAD_DUMPERROR;
1127 code = DumpFile(iodp, vnodeNumber, fdP);
1136 ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep,
1139 int i, nVnodes, code;
1144 StreamHandle_t *afile;
1146 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1147 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1148 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1151 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1152 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1155 afile = FDH_FDOPEN(fdP, "r+");
1159 for (i = 0; i < *sizep; i++) {
1162 STREAM_ASEEK(afile, Buf[i]);
1163 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1165 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1168 Log("RestoreVolume %"AFS_VOLID_FMT" "
1169 "Cleanup: Removing old vnode=%u inode=%s "
1171 afs_printable_VolumeId_lu(V_id(vp)),
1172 bitNumberToVnodeNumber(i, class),
1173 PrintInode(stmp, VNDISK_GET_INO(vnode)));
1175 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1179 STREAM_ASEEK(afile, Buf[i]);
1180 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1186 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1189 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1190 OS_SYNC(afile->str_fd);
1192 size = OS_SIZE(fdP->fd_fd);
1193 opr_Assert(size != -1);
1196 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1198 Buf = calloc(nVnodes, sizeof(afs_foff_t));
1200 STREAM_CLOSE(afile);
1204 STREAM_ASEEK(afile, offset = vcp->diskSize);
1206 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1210 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1211 Buf[(offset >> vcp->logSize) - 1] = offset;
1214 offset += vcp->diskSize;
1220 STREAM_CLOSE(afile);
1227 RestoreVolume(struct rx_call *call, Volume * avp, int incremental,
1228 struct restoreCookie *cookie)
1231 struct DumpHeader header;
1232 afs_uint32 endMagic;
1233 Error error = 0, vupdate;
1236 struct iod *iodp = &iod;
1237 afs_foff_t *b1 = NULL, *b2 = NULL;
1238 int s1 = 0, s2 = 0, delo = 0, tdelo;
1240 VolumeDiskData saved_header;
1242 iod_Init(iodp, call);
1246 if (DoPreserveVolumeStats) {
1247 CopyVolumeStats(&V_disk(vp), &saved_header);
1250 if (!ReadDumpHeader(iodp, &header)) {
1251 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1252 return VOLSERREAD_DUMPERROR;
1254 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1255 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1256 return VOLSERREAD_DUMPERROR;
1258 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1259 return VOLSERREAD_DUMPERROR;
1262 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1264 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1266 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1267 error = VOLSERREAD_DUMPERROR;
1271 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1272 vol.type = cookie->type;
1273 vol.cloneId = cookie->clone;
1274 vol.parentId = cookie->parent;
1276 V_needsSalvaged(vp) = 0;
1280 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1281 error = VOLSERREAD_DUMPERROR;
1284 tag = iod_getc(iodp);
1285 if (tag != D_VOLUMEHEADER)
1288 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1289 error = VOLSERREAD_DUMPERROR;
1293 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1294 || endMagic != DUMPENDMAGIC) {
1295 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1296 error = VOLSERREAD_DUMPERROR;
1301 if (iod_getc(iodp) != EOF) {
1302 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1303 error = VOLSERREAD_DUMPERROR;
1308 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1310 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1312 error = VOLSERREAD_DUMPERROR;
1318 if (DoPreserveVolumeStats) {
1319 CopyVolumeStats(&saved_header, &vol);
1321 ClearVolumeStats(&vol);
1323 if (V_needsSalvaged(vp)) {
1324 /* needsSalvaged may have been set while we tried to write volume data.
1325 * prevent it from getting overwritten. */
1326 vol.needsSalvaged = V_needsSalvaged(vp);
1328 CopyVolumeHeader(&vol, &V_disk(vp));
1329 V_destroyMe(vp) = 0;
1330 VUpdateVolume(&vupdate, vp);
1332 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1333 error = VOLSERREAD_DUMPERROR;
1337 /* Free the malloced space above */
1346 ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
1347 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf, afs_int32 s2,
1350 afs_int32 vnodeNumber;
1351 char buf[SIZEOF_LARGEDISKVNODE];
1353 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1354 struct VnodeDiskObject oldvnode;
1357 struct VnodeClassInfo *vcp;
1360 Inode nearInode AFS_UNUSED;
1361 afs_int32 critical = 0;
1363 tag = iod_getc(iodp);
1364 V_pref(vp, nearInode);
1365 while (tag == D_VNODE) {
1368 memset(buf, 0, sizeof(buf));
1369 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1372 if (!ReadInt32(iodp, &vnode->uniquifier))
1373 return VOLSERREAD_DUMPERROR;
1375 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1381 vnode->type = (VnodeType) iod_getc(iodp);
1386 if (!ReadShort(iodp, &tlc))
1387 return VOLSERREAD_DUMPERROR;
1388 vnode->linkCount = (signed int)tlc;
1392 if (!ReadInt32(iodp, &vnode->dataVersion))
1393 return VOLSERREAD_DUMPERROR;
1396 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1397 return VOLSERREAD_DUMPERROR;
1400 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1401 return VOLSERREAD_DUMPERROR;
1404 if (!ReadInt32(iodp, &vnode->author))
1405 return VOLSERREAD_DUMPERROR;
1408 if (!ReadInt32(iodp, &vnode->owner))
1409 return VOLSERREAD_DUMPERROR;
1412 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1413 return VOLSERREAD_DUMPERROR;
1416 unsigned short modeBits;
1417 if (!ReadShort(iodp, &modeBits))
1418 return VOLSERREAD_DUMPERROR;
1419 vnode->modeBits = (unsigned int)modeBits;
1423 if (!ReadInt32(iodp, &vnode->parent))
1424 return VOLSERREAD_DUMPERROR;
1427 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1428 VAclDiskSize(vnode));
1429 acl_NtohACL(VVnodeDiskACL(vnode));
1435 afs_fsize_t vnodeLength;
1438 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1439 "file entries for vnode %lu in dump\n",
1440 (unsigned long)vnodeNumber);
1441 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1447 IH_CREATE_INIT(V_linkHandle(vp), V_device(vp),
1448 VPartitionPath(V_partition(vp)), nearInode,
1449 V_parentId(vp), vnodeNumber,
1450 vnode->uniquifier, vnode->dataVersion);
1452 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1453 afs_error_message(errno));
1454 V_needsSalvaged(vp) = 1;
1455 return VOLSERREAD_DUMPERROR;
1459 VNDISK_SET_INO(vnode, ino);
1460 fdP = IH_OPEN(tmpH);
1462 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1463 afs_error_message(errno));
1465 V_needsSalvaged(vp) = 1;
1466 return VOLSERREAD_DUMPERROR;
1469 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1470 VNDISK_SET_LEN(vnode, vnodeLength);
1471 FDH_REALLYCLOSE(fdP);
1474 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1475 (afs_uintmax_t) ino);
1476 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1477 V_needsSalvaged(vp) = 1;
1478 return VOLSERREAD_DUMPERROR;
1486 if (!HandleUnknownTag(iodp, tag, 2, critical))
1487 return VOLSERREAD_DUMPERROR;
1491 class = vnodeIdToClass(vnodeNumber);
1492 vcp = &VnodeClassInfo[class];
1494 /* Mark this vnode as in this dump - so we don't delete it later */
1496 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1497 if (class == vLarge) {
1498 if (Lbuf && (idx < s1))
1501 if (Sbuf && (idx < s2))
1507 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1509 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1510 afs_error_message(errno));
1511 V_needsSalvaged(vp) = 1;
1512 return VOLSERREAD_DUMPERROR;
1514 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1516 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1517 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1521 vnode->vnodeMagic = vcp->magic;
1522 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1523 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1524 afs_error_message(errno));
1525 FDH_REALLYCLOSE(fdP);
1526 V_needsSalvaged(vp) = 1;
1527 return VOLSERREAD_DUMPERROR;
1532 iod_ungetc(iodp, tag);
1538 /* called with disk file only. Note that we don't have to worry about rx_Read
1539 * needing to read an ungetc'd character, since the ReadInt32 will have read
1542 * if handleP == NULL, don't write the file anywhere; just read and discard
1546 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1551 afs_fsize_t filesize;
1552 afs_fsize_t written = 0;
1560 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1562 if (!ReadInt32(iodp, &filesize_high)) {
1567 if (!ReadInt32(iodp, &filesize_low)) {
1571 FillInt64(filesize, filesize_high, filesize_low);
1578 for (nbytes = filesize; nbytes; nbytes -= size) {
1582 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1583 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));
1588 nBytes = FDH_PWRITE(handleP, p, size, written);
1591 if (nBytes != size) {
1592 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1603 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1606 afs_uint32 beginMagic;
1607 afs_int32 critical = 0;
1608 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1609 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1610 || beginMagic != DUMPBEGINMAGIC)
1614 while ((tag = iod_getc(iodp)) > D_MAX) {
1615 unsigned short arrayLength;
1621 if (!ReadInt32(iodp, &hp->volumeId))
1625 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1628 if (!ReadShort(iodp, &arrayLength))
1630 hp->nDumpTimes = (arrayLength >> 1);
1631 for (i = 0; i < hp->nDumpTimes; i++)
1632 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1633 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1640 if (!HandleUnknownTag(iodp, tag, 0, critical))
1641 return VOLSERREAD_DUMPERROR;
1644 if (!hp->volumeId || !hp->nDumpTimes) {
1647 iod_ungetc(iodp, tag);
1652 /* ----- Below are the calls that calculate dump size ----- */
1655 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1656 struct volintSize *v_size)
1659 static char nullString[1] = ""; /*The ``contents'' of motd */
1662 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1663 FillInt64(addvar,0, 1);
1664 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1665 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1666 FillInt64(addvar,0, 5);
1667 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1668 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1669 FillInt64(addvar,0, 5);
1670 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1671 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1672 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1673 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1674 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1675 FillInt64(addvar,0, 2);
1676 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1677 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1678 FillInt64(addvar,0, 2);
1679 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1680 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1681 FillInt64(addvar,0, 5);
1682 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1683 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1684 FillInt64(addvar,0, 2);
1685 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1686 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1687 FillInt64(addvar,0, 5);
1688 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1689 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1690 FillInt64(addvar,0, 5);
1691 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1692 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1693 FillInt64(addvar,0, 5);
1694 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1695 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1696 FillInt64(addvar,0, 5);
1697 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1698 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1699 FillInt64(addvar,0, 5);
1700 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1701 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1702 FillInt64(addvar,0, 5);
1703 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1704 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1705 FillInt64(addvar,0, 5);
1706 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1707 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1708 FillInt64(addvar,0, 5);
1709 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1710 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1711 FillInt64(addvar,0, 5);
1712 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1713 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1714 FillInt64(addvar,0, 5);
1715 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1716 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1717 FillInt64(addvar,0, 5);
1718 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1719 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1720 FillInt64(addvar,0, 5);
1721 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1722 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1723 FillInt64(addvar,0, 5);
1724 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1725 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1726 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1727 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1729 /* * We do NOT dump the detailed volume statistics residing in the old */
1730 /* * motd field, since we cannot tell from the info in a dump whether */
1731 /* * statistics data has been put there. Instead, we dump a null string, */
1732 /* * just as if that was what the motd contained. */
1734 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1735 FillInt64(addvar,0, (2 + strlen(nullString)));
1736 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1737 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1738 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1739 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1740 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1741 FillInt64(addvar,0, 5);
1742 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1743 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1744 FillInt64(addvar,0, 5);
1745 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1750 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1754 FillInt64(addvar,0, 5);
1755 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1760 SizeDumpVolume(struct rx_call *call, Volume * vp,
1761 afs_int32 fromtime, int dumpAllDirs,
1762 struct volintSize *v_size)
1765 struct iod *iodp = (struct iod *)0;
1766 /* iod_Init(iodp, call); */
1769 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1771 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1773 code = SizeDumpEnd(iodp, v_size);
1779 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1780 afs_int32 fromtime, struct volintSize *v_size)
1783 /* int UseLatestReadOnlyClone = 1; */
1784 /* afs_int32 dumpTimes[2]; */
1786 /* iodp->device = vp->device; */
1787 /* iodp->parentId = V_parentId(vp); */
1788 /* iodp->dumpPartition = vp->partition; */
1790 ZeroInt64(v_size->dump_size); /* initialize the size */
1791 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1792 FillInt64(addvar,0, 9);
1793 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1794 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1795 FillInt64(addvar,0, 5);
1796 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1797 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1798 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1799 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1800 /* dumpTimes[0] = fromtime; */
1801 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1802 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1803 FillInt64(addvar,0, (3 + 4 * 2));
1804 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1809 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, VolumeId volid,
1810 int vnodeNumber, int dumpEverything,
1811 struct volintSize *v_size)
1816 if (!v || v->type == vNull)
1818 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1819 FillInt64(addvar,0, 9);
1820 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1821 if (!dumpEverything)
1823 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1824 FillInt64(addvar,0, 2);
1825 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1826 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1827 FillInt64(addvar,0, 3);
1828 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1829 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1830 FillInt64(addvar,0, 5);
1831 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1832 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1833 FillInt64(addvar,0, 5);
1834 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1835 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1836 FillInt64(addvar,0, 5);
1837 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1838 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1839 FillInt64(addvar,0, 5);
1840 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1841 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1843 FillInt64(addvar,0, 5);
1844 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1846 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1847 FillInt64(addvar,0, 3);
1848 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1849 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1850 FillInt64(addvar,0, 5);
1851 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1852 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1853 FillInt64(addvar,0, 5);
1854 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1855 if (v->type == vDirectory) {
1856 /* acl_HtonACL(VVnodeDiskACL(v)); */
1857 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1858 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1859 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1862 if (VNDISK_GET_INO(v)) {
1863 VNDISK_GET_LEN(addvar, v);
1864 if (v->vn_length_hi)
1868 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1873 /* A partial dump (no dump header) */
1875 SizeDumpPartial(struct iod *iodp, Volume * vp,
1876 afs_int32 fromtime, int dumpAllDirs,
1877 struct volintSize *v_size)
1881 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1884 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1887 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1892 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1893 afs_int32 fromtime, int forcedump,
1894 struct volintSize *v_size)
1897 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1898 char buf[SIZEOF_LARGEDISKVNODE];
1899 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1900 StreamHandle_t *file;
1902 afs_sfsize_t size, nVnodes;
1906 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1907 opr_Assert(fdP != NULL);
1908 file = FDH_FDOPEN(fdP, "r+");
1909 opr_Assert(file != NULL);
1910 size = OS_SIZE(fdP->fd_fd);
1911 opr_Assert(size != -1);
1912 nVnodes = (size / vcp->diskSize) - 1;
1914 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
1915 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1918 for (vnodeIndex = 0;
1919 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1920 nVnodes--, vnodeIndex++) {
1921 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1922 /* Note: the >= test is very important since some old volumes may not have
1923 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1924 * does dump the file! */
1927 SizeDumpVnode(iodp, vnode, V_id(vp),
1928 bitNumberToVnodeNumber(vnodeIndex, class), flag,