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 <afs/afsint.h>
21 #include <afs/errors.h>
24 #include <afs/ihandle.h>
25 #include <afs/vnode.h>
26 #include <afs/volume.h>
27 #include <afs/partition.h>
28 #include <afs/daemon_com.h>
29 #include <afs/fssync.h>
31 #include <afs/com_err.h>
32 #include <afs/vol_prototypes.h>
37 #include "dumpstuff.h"
41 #define afs_stat stat64
42 #define afs_fstat fstat64
43 #else /* !O_LARGEFILE */
45 #define afs_fstat fstat
46 #endif /* !O_LARGEFILE */
47 #endif /* !AFS_NT40_ENV */
49 /*@printflike@*/ extern void Log(const char *format, ...);
54 /* Forward Declarations */
55 static int DumpDumpHeader(struct iod *iodp, Volume * vp,
57 static int DumpPartial(struct iod *iodp, Volume * vp,
58 afs_int32 fromtime, int dumpAllDirs);
59 static int DumpVnodeIndex(struct iod *iodp, Volume * vp,
60 VnodeClass class, afs_int32 fromtime,
62 static int DumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
63 int volid, int vnodeNumber, int dumpEverything);
64 static int ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp);
65 static int ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
66 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf,
67 afs_int32 s2, afs_int32 delo);
68 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
69 FdHandle_t * handleP, int tag,
72 static int SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
74 struct volintSize *size);
75 static int SizeDumpPartial(struct iod *iodp, Volume * vp,
76 afs_int32 fromtime, int dumpAllDirs,
77 struct volintSize *size);
78 static int SizeDumpVnodeIndex(struct iod *iodp, Volume * vp,
79 VnodeClass class, afs_int32 fromtime,
81 struct volintSize *size);
82 static int SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v,
83 int volid, int vnodeNumber, int dumpEverything,
84 struct volintSize *size);
86 #define MAX_SECTIONS 3
88 #define MAX_TLV_TAG 0x60
89 #define MAX_STANDARD_TAG 0x7a
90 static afs_uint32 oldtags[MAX_SECTIONS][16];
91 int oldtagsInited = 0;
94 RegisterTag(afs_int32 section, unsigned char tag)
96 afs_uint32 off = tag >> 5;
97 afs_uint32 mask = 1 << (tag & 0x1f);
98 oldtags[section][off] |= mask;
102 initNonStandardTags(void)
104 RegisterTag(0, 'n'); /* volume name */
105 RegisterTag(0, 't'); /* fromtime, V_backupDate */
106 RegisterTag(1, 'A'); /* V_accessDate */
107 RegisterTag(1, 'C'); /* V_creationDate */
108 RegisterTag(1, 'D'); /* V_dayUseDate */
109 RegisterTag(1, 'E'); /* V_expirationDate */
110 RegisterTag(1, 'M'); /* nullstring (motd) */
111 RegisterTag(1, 'U'); /* V_updateDate */
112 RegisterTag(1, 'W'); /* V_weekUse */
113 RegisterTag(1, 'Z'); /* V_dayUse */
114 RegisterTag(1, 'O'); /* V_offlineMessage */
115 RegisterTag(1, 'b'); /* V_blessed */
116 RegisterTag(1, 'n'); /* V_name */
117 RegisterTag(1, 's'); /* V_inService */
118 RegisterTag(1, 't'); /* V_type */
119 RegisterTag(2, 'A'); /* VVnodeDiskACL */
120 RegisterTag(2, 'b'); /* modeBits */
121 RegisterTag(2, 'f'); /* small file */
122 RegisterTag(2, 'h'); /* large file */
123 RegisterTag(2, 'l'); /* linkcount */
124 RegisterTag(2, 't'); /* type */
129 iod_Init(struct iod *iodp, struct rx_call *call)
132 iodp->haveOldChar = 0;
134 iodp->calls = (struct rx_call **)0;
138 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
143 iodp->haveOldChar = 0;
144 iodp->ncalls = ncalls;
146 iodp->call = (struct rx_call *)0;
149 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
150 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
152 /* For the single dump case, it's ok to just return the "bytes written"
153 * that rx_Write returns, since all the callers of iod_Write abort when
154 * the returned value is less than they expect. For the multi dump case,
155 * I don't think we want half the replicas to go bad just because one
156 * connection timed out, but if they all time out, then we should give up.
159 iod_Write(struct iod *iodp, char *buf, int nbytes)
164 osi_Assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
165 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
168 code = rx_Write(iodp->call, buf, nbytes);
172 for (i = 0; i < iodp->ncalls; i++) {
173 if (iodp->calls[i] && !iodp->codes[i]) {
174 code = rx_Write(iodp->calls[i], buf, nbytes);
175 if (code != nbytes) { /* everything gets merged into a single error */
176 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
177 } /* standard dump does, anyways */
182 } /* for all calls */
191 iod_ungetc(struct iod *iodp, int achar)
193 iodp->oldChar = achar;
194 iodp->haveOldChar = 1;
198 iod_getc(struct iod *iodp)
202 if (iodp->haveOldChar) {
203 iodp->haveOldChar = 0;
204 return iodp->oldChar;
206 if (iod_Read(iodp, (char *) &t, 1) == 1)
212 ReadShort(struct iod *iodp, unsigned short *sp)
221 *sp = (b1 << 8) | b0;
226 ReadInt32(struct iod *iodp, afs_uint32 * lp)
228 afs_uint32 b3, b2, b1, b0;
241 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
246 ReadString(struct iod *iodp, char *to, int maxa)
255 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
259 while ((c = iod_getc(iodp)) && c != EOF);
265 ReadByteString(struct iod *iodp, byte * to,
269 *to++ = iod_getc(iodp);
273 * returns 1 on success and 0 otherwise
276 ReadStandardTagLen(struct iod *iodp, unsigned char tag, afs_int32 section,
280 afs_uint32 off = tag >> 5;
281 afs_uint32 mask = 1 << (tag & 0x1f);
282 unsigned char len, buf[8], *p;
285 initNonStandardTags();
287 if (tag < MIN_TLV_TAG
288 || tag > MAX_STANDARD_TAG
289 || section >= MAX_SECTIONS
290 || (oldtags[section][ off] & mask)) {
291 Log("Trying to use ReadStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
294 if (tag <= MAX_TLV_TAG) {
295 len = iod_getc(iodp);
300 if ((code = iod_Read(iodp, (char *)buf, len)) != len)
301 return VOLSERDUMPERROR;
303 p = (unsigned char *)&buf;
304 for (i=0; i<len; i++) {
305 *length = ((*length) << 8) | *p++;
309 if (tag < MAX_STANDARD_TAG)
315 static char skipbuf[256];
318 SkipData(struct iod *iodp, afs_size_t length)
320 while (length > 256) {
321 if (iod_Read(iodp, (char *)&skipbuf, 256) != 256)
325 if (iod_Read(iodp, (char *)&skipbuf, length) != length)
330 static char *secname[3] = {"ReadDumpHeader", "ReadVolumeHeader", "ReadVnodes"};
333 HandleUnknownTag(struct iod *iodp, int tag, afs_int32 section,
336 afs_size_t taglen = 0;
340 Log("%s: unknown critical tag x%02x, aborting\n",
341 secname[section], tag);
344 Log("%s: unknown tag x%02x found, skipping\n", secname[section], tag);
345 if (tag >= 0x06 && tag <= 0x60) {
346 if (!ReadStandardTagLen(iodp, tag, 1, &taglen)) {
347 Log("%s: error reading length field for tag x%02x, aborting\n",
348 secname[section], tag);
351 if (!SkipData(iodp, taglen)) {
352 Log("%s: error skipping %llu bytes for tag x%02x, aborting\n",
353 secname[section], taglen, tag);
358 if (tag >= 0x61 && tag <= 0x7a) {
359 if (!ReadInt32(iodp, &trash)) {
360 Log("%s: error skipping int32 for tag x%02x, aborting\n",
361 secname[section], tag);
366 if (tag >= 0x7b && tag < 0x80) /* dataless tag */
368 Log("%s: unknown invalid tag x%02x, aborting\n", secname[section], tag);
373 ReadVolumeHeader(struct iod *iodp, VolumeDiskData * vol)
377 afs_int32 critical = 0;
378 memset(vol, 0, sizeof(*vol));
379 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
384 if (!ReadInt32(iodp, &vol->id))
385 return VOLSERREAD_DUMPERROR;
388 if (!ReadInt32(iodp, &trash))
389 return VOLSERREAD_DUMPERROR;
392 ReadString(iodp, vol->name, sizeof(vol->name));
393 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
396 vol->inService = iod_getc(iodp);
399 vol->blessed = iod_getc(iodp);
402 if (!ReadInt32(iodp, &vol->uniquifier))
403 return VOLSERREAD_DUMPERROR;
406 vol->type = iod_getc(iodp);
409 if (!ReadInt32(iodp, &vol->parentId))
410 return VOLSERREAD_DUMPERROR;
413 if (!ReadInt32(iodp, &vol->cloneId))
414 return VOLSERREAD_DUMPERROR;
417 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
418 return VOLSERREAD_DUMPERROR;
421 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
422 return VOLSERREAD_DUMPERROR;
425 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
426 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
429 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
430 return VOLSERREAD_DUMPERROR;
433 if (!ReadInt32(iodp, &vol->accountNumber))
434 return VOLSERREAD_DUMPERROR;
437 if (!ReadInt32(iodp, &vol->owner))
438 return VOLSERREAD_DUMPERROR;
441 if (!ReadInt32(iodp, &vol->creationDate))
442 return VOLSERREAD_DUMPERROR;
445 if (!ReadInt32(iodp, &vol->accessDate))
446 return VOLSERREAD_DUMPERROR;
449 if (!ReadInt32(iodp, &vol->updateDate))
450 return VOLSERREAD_DUMPERROR;
453 if (!ReadInt32(iodp, &vol->expirationDate))
454 return VOLSERREAD_DUMPERROR;
457 if (!ReadInt32(iodp, &vol->backupDate))
458 return VOLSERREAD_DUMPERROR;
461 ReadString(iodp, vol->offlineMessage,
462 sizeof(vol->offlineMessage));
466 * Detailed volume statistics are never stored in dumps,
467 * so we just restore either the null string if this volume
468 * had already been set to store statistics, or the old motd
469 * contents otherwise. It doesn't matter, since this field
470 * will soon get initialized anyway.
472 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
475 unsigned short length;
478 if (!ReadShort(iodp, &length))
479 return VOLSERREAD_DUMPERROR;
480 for (i = 0; i < length; i++) {
481 if (!ReadInt32(iodp, &data))
482 return VOLSERREAD_DUMPERROR;
483 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
484 vol->weekUse[i] = data;
489 if (!ReadInt32(iodp, &vol->dayUseDate))
490 return VOLSERREAD_DUMPERROR;
493 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
494 return VOLSERREAD_DUMPERROR;
497 if (!ReadInt32(iodp, (afs_uint32 *) &trash/*volUpdateCounter*/))
498 return VOLSERREAD_DUMPERROR;
504 if (!HandleUnknownTag(iodp, tag, 1, critical))
505 return VOLSERREAD_DUMPERROR;
508 iod_ungetc(iodp, tag);
513 DumpTag(struct iod *iodp, int tag)
518 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
523 DumpByte(struct iod *iodp, char tag, byte value)
526 byte *p = (unsigned char *)tbuffer;
529 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
532 #define afs_putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
533 #define afs_putshort(p, v) *p++ = v>>8, *p++ = v
536 DumpDouble(struct iod *iodp, char tag, afs_uint32 value1,
540 byte *p = (unsigned char *)tbuffer;
542 afs_putint32(p, value1);
543 afs_putint32(p, value2);
544 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
548 DumpInt32(struct iod *iodp, char tag, afs_uint32 value)
551 byte *p = (unsigned char *)tbuffer;
553 afs_putint32(p, value);
554 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
558 DumpArrayInt32(struct iod *iodp, char tag,
559 afs_uint32 * array, int nelem)
564 byte *p = (unsigned char *)tbuffer;
566 afs_putshort(p, nelem);
567 code = iod_Write(iodp, tbuffer, 3);
569 return VOLSERDUMPERROR;
571 p = (unsigned char *)tbuffer;
572 v = *array++; /*this was register */
575 code = iod_Write(iodp, tbuffer, 4);
577 return VOLSERDUMPERROR;
583 DumpShort(struct iod *iodp, char tag, unsigned int value)
586 byte *p = (unsigned char *)tbuffer;
590 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
594 DumpBool(struct iod *iodp, char tag, unsigned int value)
597 byte *p = (unsigned char *)tbuffer;
600 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
604 DumpString(struct iod *iodp, char tag, char *s)
608 code = iod_Write(iodp, &tag, 1);
610 return VOLSERDUMPERROR;
612 code = iod_Write(iodp, s, n);
614 return VOLSERDUMPERROR;
619 DumpByteString(struct iod *iodp, char tag, byte * bs,
624 code = iod_Write(iodp, &tag, 1);
626 return VOLSERDUMPERROR;
627 code = iod_Write(iodp, (char *)bs, nbytes);
629 return VOLSERDUMPERROR;
634 DumpStandardTag(struct iod *iodp, char tag, afs_uint32 section)
637 afs_uint32 off = tag >> 5;
638 afs_uint32 mask = 1 << (tag & 0x1f);
641 initNonStandardTags();
643 if (tag < MIN_TLV_TAG
644 || tag > MAX_STANDARD_TAG
645 || section >= MAX_SECTIONS
646 || (oldtags[section][ off] & mask)) {
647 Log("Trying to use DumpStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
648 return VOLSERDUMPERROR;
650 code = iod_Write(iodp, &tag, 1);
652 return VOLSERDUMPERROR;
658 DumpStandardTagLen(struct iod *iodp, char tag, afs_uint32 section,
665 if (tag < MIN_TLV_TAG || tag > MAX_TLV_TAG) {
666 Log("Trying to use DumpStandardTagLen with tag 0x%02x for section %d, aborting\n", tag, section);
667 return VOLSERDUMPERROR;
669 code = DumpStandardTag(iodp, tag, section);
673 if (length < 128) { /* byte after tag contains length */
676 } else { /* byte after tag contains length of length field | 0x80 */
677 for (len=0; length; length=length >> 8) {
685 code = iod_Write(iodp, p, len);
687 return VOLSERDUMPERROR;
692 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
694 int code = 0, error = 0;
696 afs_foff_t offset = 0;
697 afs_sfsize_t nbytes, howBig;
700 afs_foff_t howFar = 0;
705 struct afs_stat status;
707 LARGE_INTEGER fileSize;
710 #include <sys/statfs.h>
711 #if defined(AFS_AIX52_ENV)
712 struct statfs64 tstatfs;
713 #else /* !AFS_AIX52_ENV */
714 struct statfs tstatfs;
715 #endif /* !AFS_AIX52_ENV */
720 if (!GetFileSizeEx(handleP->fd_fd, &fileSize)) {
721 Log("DumpFile: GetFileSizeEx returned error code %d on descriptor %d\n", GetLastError(), handleP->fd_fd);
722 return VOLSERDUMPERROR;
724 howBig = fileSize.QuadPart;
728 afs_fstat(handleP->fd_fd, &status);
729 howBig = status.st_size;
732 /* Unfortunately in AIX valuable fields such as st_blksize are
733 * gone from the stat structure.
735 #if defined(AFS_AIX52_ENV)
736 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
737 #else /* !AFS_AIX52_ENV */
738 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
739 #endif /* !AFS_AIX52_ENV */
740 if (statfs_code != 0) {
741 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
742 return VOLSERDUMPERROR;
744 howMany = tstatfs.f_bsize;
746 howMany = status.st_blksize;
747 #endif /* AFS_AIX_ENV */
748 #endif /* AFS_NT40_ENV */
751 SplitInt64(howBig, hi, lo);
753 code = DumpInt32(iodp, 'f', lo);
755 code = DumpDouble(iodp, 'h', hi, lo);
758 return VOLSERDUMPERROR;
763 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", (unsigned)howMany);
764 return VOLSERDUMPERROR;
767 for (nbytes = howBig; (nbytes && !error); nbytes -= howMany) {
768 if (nbytes < howMany)
772 n = FDH_PREAD(handleP, p, howMany, howFar);
775 /* If read any good data and we null padded previously, log the
776 * amount that we had null padded.
778 if ((n > 0) && pad) {
779 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %lld\n", pad, (long long)offset);
783 /* If didn't read enough data, null padd the rest of the buffer. This
784 * can happen if, for instance, the media has some bad spots. We don't
785 * want to quit the dump, so we start null padding.
788 /* Record the read error */
791 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));
793 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
796 /* Pad the rest of the buffer with zeros. Remember offset we started
797 * padding. Keep total tally of padding.
799 memset(p + n, 0, howMany - n);
801 offset = (howBig - nbytes) + n;
802 pad += (howMany - n);
804 /* Now seek over the data we could not get. An error here means we
805 * can't do the next read.
807 howFar = (size_t)((howBig - nbytes) + howMany);
810 /* Now write the data out */
811 if (iod_Write(iodp, (char *)p, howMany) != howMany)
812 error = VOLSERDUMPERROR;
813 #ifndef AFS_PTHREAD_ENV
818 if (pad) { /* Any padding we hadn't reported yet */
819 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %lld\n",
820 pad, (long long)offset);
828 DumpVolumeHeader(struct iod *iodp, Volume * vp)
831 static char nullString[1] = ""; /*The ``contents'' of motd */
834 code = DumpTag(iodp, D_VOLUMEHEADER);
836 code = DumpInt32(iodp, 'i', V_id(vp));
839 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
841 code = DumpString(iodp, 'n', V_name(vp));
843 code = DumpBool(iodp, 's', V_inService(vp));
845 code = DumpBool(iodp, 'b', V_blessed(vp));
847 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
849 code = DumpByte(iodp, 't', (byte) V_type(vp));
851 code = DumpInt32(iodp, 'p', V_parentId(vp));
854 code = DumpInt32(iodp, 'c', V_cloneId(vp));
856 code = DumpInt32(iodp, 'q', V_maxquota(vp));
858 code = DumpInt32(iodp, 'm', V_minquota(vp));
860 code = DumpInt32(iodp, 'd', V_diskused(vp));
862 code = DumpInt32(iodp, 'f', V_filecount(vp));
864 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
866 code = DumpInt32(iodp, 'o', V_owner(vp));
868 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
870 code = DumpInt32(iodp, 'A', V_accessDate(vp));
872 code = DumpInt32(iodp, 'U', V_updateDate(vp));
874 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
876 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
878 code = DumpString(iodp, 'O', V_offlineMessage(vp));
880 * We do NOT dump the detailed volume statistics residing in the old
881 * motd field, since we cannot tell from the info in a dump whether
882 * statistics data has been put there. Instead, we dump a null string,
883 * just as if that was what the motd contained.
886 code = DumpString(iodp, 'M', nullString);
889 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
890 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
892 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
894 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
899 DumpEnd(struct iod *iodp)
901 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
904 /* Guts of the dump code */
906 /* Dump a whole volume */
908 DumpVolume(struct rx_call *call, Volume * vp,
909 afs_int32 fromtime, int dumpAllDirs)
913 struct iod *iodp = &iod;
914 iod_Init(iodp, call);
917 code = DumpDumpHeader(iodp, vp, fromtime);
920 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
922 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
923 if (rx_Error(iodp->call)) {
924 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
925 rx_Error(iodp->call));
926 return VOLSERDUMPERROR;
929 code = DumpEnd(iodp);
934 /* Dump a volume to multiple places*/
936 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
937 afs_int32 fromtime, int dumpAllDirs, int *codes)
941 iod_InitMulti(&iod, calls, ncalls, codes);
944 code = DumpDumpHeader(&iod, vp, fromtime);
946 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
948 code = DumpEnd(&iod);
952 /* A partial dump (no dump header) */
954 DumpPartial(struct iod *iodp, Volume * vp,
955 afs_int32 fromtime, int dumpAllDirs)
959 code = DumpVolumeHeader(iodp, vp);
961 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
963 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
968 DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
969 afs_int32 fromtime, int forcedump)
972 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
973 char buf[SIZEOF_LARGEDISKVNODE];
974 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
975 StreamHandle_t *file;
977 afs_sfsize_t size, nVnodes;
981 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
982 osi_Assert(fdP != NULL);
983 file = FDH_FDOPEN(fdP, "r+");
984 osi_Assert(file != NULL);
985 size = OS_SIZE(fdP->fd_fd);
986 osi_Assert(size != -1);
987 nVnodes = (size / vcp->diskSize) - 1;
989 osi_Assert((nVnodes + 1) * vcp->diskSize == size);
990 osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
994 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
995 nVnodes--, vnodeIndex++) {
996 flag = forcedump || (vnode->serverModifyTime >= fromtime);
997 /* Note: the >= test is very important since some old volumes may not have
998 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
999 * does dump the file! */
1002 DumpVnode(iodp, vnode, V_id(vp),
1003 bitNumberToVnodeNumber(vnodeIndex, class), flag);
1004 #ifndef AFS_PTHREAD_ENV
1006 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
1015 DumpDumpHeader(struct iod *iodp, Volume * vp,
1019 int UseLatestReadOnlyClone = 1;
1020 afs_int32 dumpTimes[2];
1021 iodp->device = vp->device;
1022 iodp->parentId = V_parentId(vp);
1023 iodp->dumpPartition = vp->partition;
1025 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
1028 DumpInt32(iodp, 'v',
1029 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
1031 code = DumpString(iodp, 'n', V_name(vp));
1032 dumpTimes[0] = fromtime;
1033 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
1035 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
1040 DumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1041 int vnodeNumber, int dumpEverything)
1047 if (!v || v->type == vNull)
1050 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
1051 if (!dumpEverything)
1054 code = DumpByte(iodp, 't', (byte) v->type);
1056 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
1058 code = DumpInt32(iodp, 'v', v->dataVersion);
1060 code = DumpInt32(iodp, 'm', v->unixModifyTime);
1062 code = DumpInt32(iodp, 'a', v->author);
1064 code = DumpInt32(iodp, 'o', v->owner);
1065 if (!code && v->group)
1066 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
1068 code = DumpShort(iodp, 'b', v->modeBits);
1070 code = DumpInt32(iodp, 'p', v->parent);
1072 code = DumpInt32(iodp, 's', v->serverModifyTime);
1073 if (v->type == vDirectory) {
1074 acl_HtonACL(VVnodeDiskACL(v));
1077 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
1080 if (VNDISK_GET_INO(v)) {
1081 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1084 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);
1086 return VOLSERREAD_DUMPERROR;
1088 code = DumpFile(iodp, vnodeNumber, fdP);
1097 ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep,
1100 int i, nVnodes, code;
1105 StreamHandle_t *afile;
1107 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1108 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1109 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1111 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1112 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1115 afile = FDH_FDOPEN(fdP, "r+");
1119 for (i = 0; i < *sizep; i++) {
1122 STREAM_ASEEK(afile, Buf[i]);
1123 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1125 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1128 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
1129 V_id(vp), bitNumberToVnodeNumber(i, class),
1130 (afs_uintmax_t) VNDISK_GET_INO(vnode));
1132 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1136 STREAM_ASEEK(afile, Buf[i]);
1137 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1143 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1146 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1147 OS_SYNC(afile->str_fd);
1149 size = OS_SIZE(fdP->fd_fd);
1150 osi_Assert(size != -1);
1153 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1155 Buf = malloc(nVnodes * sizeof(afs_foff_t));
1157 STREAM_CLOSE(afile);
1161 memset(Buf, 0, nVnodes * sizeof(afs_foff_t));
1162 STREAM_ASEEK(afile, offset = vcp->diskSize);
1164 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1168 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1169 Buf[(offset >> vcp->logSize) - 1] = offset;
1172 offset += vcp->diskSize;
1178 STREAM_CLOSE(afile);
1185 RestoreVolume(struct rx_call *call, Volume * avp, int incremental,
1186 struct restoreCookie *cookie)
1189 struct DumpHeader header;
1190 afs_uint32 endMagic;
1191 Error error = 0, vupdate;
1194 struct iod *iodp = &iod;
1195 afs_foff_t *b1 = NULL, *b2 = NULL;
1196 int s1 = 0, s2 = 0, delo = 0, tdelo;
1199 iod_Init(iodp, call);
1203 if (!ReadDumpHeader(iodp, &header)) {
1204 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1205 return VOLSERREAD_DUMPERROR;
1207 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1208 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1209 return VOLSERREAD_DUMPERROR;
1211 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1212 return VOLSERREAD_DUMPERROR;
1215 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1217 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1219 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1220 error = VOLSERREAD_DUMPERROR;
1224 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1225 vol.type = cookie->type;
1226 vol.cloneId = cookie->clone;
1227 vol.parentId = cookie->parent;
1229 V_needsSalvaged(vp) = 0;
1233 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1234 error = VOLSERREAD_DUMPERROR;
1237 tag = iod_getc(iodp);
1238 if (tag != D_VOLUMEHEADER)
1241 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1242 error = VOLSERREAD_DUMPERROR;
1246 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1247 || endMagic != DUMPENDMAGIC) {
1248 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1249 error = VOLSERREAD_DUMPERROR;
1254 if (iod_getc(iodp) != EOF) {
1255 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1256 error = VOLSERREAD_DUMPERROR;
1261 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1263 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1265 error = VOLSERREAD_DUMPERROR;
1271 ClearVolumeStats(&vol);
1272 if (V_needsSalvaged(vp)) {
1273 /* needsSalvaged may have been set while we tried to write volume data.
1274 * prevent it from getting overwritten. */
1275 vol.needsSalvaged = V_needsSalvaged(vp);
1277 CopyVolumeHeader(&vol, &V_disk(vp));
1278 V_destroyMe(vp) = 0;
1279 VUpdateVolume(&vupdate, vp);
1281 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1282 error = VOLSERREAD_DUMPERROR;
1286 /* Free the malloced space above */
1295 ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
1296 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf, afs_int32 s2,
1299 afs_int32 vnodeNumber;
1300 char buf[SIZEOF_LARGEDISKVNODE];
1302 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1303 struct VnodeDiskObject oldvnode;
1306 struct VnodeClassInfo *vcp;
1309 Inode nearInode AFS_UNUSED;
1310 afs_int32 critical = 0;
1312 tag = iod_getc(iodp);
1313 V_pref(vp, nearInode);
1314 while (tag == D_VNODE) {
1317 memset(buf, 0, sizeof(buf));
1318 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1321 if (!ReadInt32(iodp, &vnode->uniquifier))
1322 return VOLSERREAD_DUMPERROR;
1324 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1330 vnode->type = (VnodeType) iod_getc(iodp);
1335 if (!ReadShort(iodp, &tlc))
1336 return VOLSERREAD_DUMPERROR;
1337 vnode->linkCount = (signed int)tlc;
1341 if (!ReadInt32(iodp, &vnode->dataVersion))
1342 return VOLSERREAD_DUMPERROR;
1345 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1346 return VOLSERREAD_DUMPERROR;
1349 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1350 return VOLSERREAD_DUMPERROR;
1353 if (!ReadInt32(iodp, &vnode->author))
1354 return VOLSERREAD_DUMPERROR;
1357 if (!ReadInt32(iodp, &vnode->owner))
1358 return VOLSERREAD_DUMPERROR;
1361 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1362 return VOLSERREAD_DUMPERROR;
1365 unsigned short modeBits;
1366 if (!ReadShort(iodp, &modeBits))
1367 return VOLSERREAD_DUMPERROR;
1368 vnode->modeBits = (unsigned int)modeBits;
1372 if (!ReadInt32(iodp, &vnode->parent))
1373 return VOLSERREAD_DUMPERROR;
1376 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1377 VAclDiskSize(vnode));
1378 acl_NtohACL(VVnodeDiskACL(vnode));
1384 afs_fsize_t vnodeLength;
1387 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1388 "file entries for vnode %lu in dump\n",
1389 (unsigned long)vnodeNumber);
1390 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1396 IH_CREATE(V_linkHandle(vp), V_device(vp),
1397 VPartitionPath(V_partition(vp)), nearInode,
1398 V_parentId(vp), vnodeNumber,
1399 vnode->uniquifier, vnode->dataVersion);
1400 if (!VALID_INO(ino)) {
1401 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1402 afs_error_message(errno));
1403 V_needsSalvaged(vp) = 1;
1404 return VOLSERREAD_DUMPERROR;
1407 VNDISK_SET_INO(vnode, ino);
1408 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1409 fdP = IH_OPEN(tmpH);
1411 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1412 afs_error_message(errno));
1414 V_needsSalvaged(vp) = 1;
1415 return VOLSERREAD_DUMPERROR;
1418 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1419 VNDISK_SET_LEN(vnode, vnodeLength);
1420 FDH_REALLYCLOSE(fdP);
1423 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1424 (afs_uintmax_t) ino);
1425 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1426 V_needsSalvaged(vp) = 1;
1427 return VOLSERREAD_DUMPERROR;
1435 if (!HandleUnknownTag(iodp, tag, 2, critical))
1436 return VOLSERREAD_DUMPERROR;
1440 class = vnodeIdToClass(vnodeNumber);
1441 vcp = &VnodeClassInfo[class];
1443 /* Mark this vnode as in this dump - so we don't delete it later */
1445 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1446 if (class == vLarge) {
1447 if (Lbuf && (idx < s1))
1450 if (Sbuf && (idx < s2))
1456 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1458 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1459 afs_error_message(errno));
1460 V_needsSalvaged(vp) = 1;
1461 return VOLSERREAD_DUMPERROR;
1463 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1465 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1466 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1470 vnode->vnodeMagic = vcp->magic;
1471 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1472 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1473 afs_error_message(errno));
1474 FDH_REALLYCLOSE(fdP);
1475 V_needsSalvaged(vp) = 1;
1476 return VOLSERREAD_DUMPERROR;
1481 iod_ungetc(iodp, tag);
1487 /* called with disk file only. Note that we don't have to worry about rx_Read
1488 * needing to read an ungetc'd character, since the ReadInt32 will have read
1491 * if handleP == NULL, don't write the file anywhere; just read and discard
1495 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1500 afs_fsize_t filesize;
1501 afs_fsize_t written = 0;
1509 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1511 if (!ReadInt32(iodp, &filesize_high)) {
1516 if (!ReadInt32(iodp, &filesize_low)) {
1520 FillInt64(filesize, filesize_high, filesize_low);
1522 p = (unsigned char *)malloc(size);
1527 for (nbytes = filesize; nbytes; nbytes -= size) {
1531 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1532 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));
1537 nBytes = FDH_PWRITE(handleP, p, size, written);
1540 if (nBytes != size) {
1541 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1552 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1555 afs_uint32 beginMagic;
1556 afs_int32 critical = 0;
1557 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1558 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1559 || beginMagic != DUMPBEGINMAGIC)
1563 while ((tag = iod_getc(iodp)) > D_MAX) {
1564 unsigned short arrayLength;
1570 if (!ReadInt32(iodp, &hp->volumeId))
1574 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1577 if (!ReadShort(iodp, &arrayLength))
1579 hp->nDumpTimes = (arrayLength >> 1);
1580 for (i = 0; i < hp->nDumpTimes; i++)
1581 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1582 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1589 if (!HandleUnknownTag(iodp, tag, 0, critical))
1590 return VOLSERREAD_DUMPERROR;
1593 if (!hp->volumeId || !hp->nDumpTimes) {
1596 iod_ungetc(iodp, tag);
1601 /* ----- Below are the calls that calculate dump size ----- */
1604 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1605 struct volintSize *v_size)
1608 static char nullString[1] = ""; /*The ``contents'' of motd */
1611 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1612 FillInt64(addvar,0, 1);
1613 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1614 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1615 FillInt64(addvar,0, 5);
1616 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1617 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1618 FillInt64(addvar,0, 5);
1619 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1620 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1621 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1622 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1623 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1624 FillInt64(addvar,0, 2);
1625 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1626 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1627 FillInt64(addvar,0, 2);
1628 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1629 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1630 FillInt64(addvar,0, 5);
1631 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1632 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1633 FillInt64(addvar,0, 2);
1634 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1635 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1636 FillInt64(addvar,0, 5);
1637 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1638 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1639 FillInt64(addvar,0, 5);
1640 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1641 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1642 FillInt64(addvar,0, 5);
1643 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1644 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1645 FillInt64(addvar,0, 5);
1646 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1647 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1648 FillInt64(addvar,0, 5);
1649 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1650 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1651 FillInt64(addvar,0, 5);
1652 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1653 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1654 FillInt64(addvar,0, 5);
1655 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1656 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1657 FillInt64(addvar,0, 5);
1658 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1659 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1660 FillInt64(addvar,0, 5);
1661 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1662 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1663 FillInt64(addvar,0, 5);
1664 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1665 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1666 FillInt64(addvar,0, 5);
1667 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1668 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1669 FillInt64(addvar,0, 5);
1670 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1671 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1672 FillInt64(addvar,0, 5);
1673 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1674 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1675 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1676 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1678 /* * We do NOT dump the detailed volume statistics residing in the old */
1679 /* * motd field, since we cannot tell from the info in a dump whether */
1680 /* * statistics data has been put there. Instead, we dump a null string, */
1681 /* * just as if that was what the motd contained. */
1683 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1684 FillInt64(addvar,0, (2 + strlen(nullString)));
1685 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1686 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1687 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1688 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1689 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1690 FillInt64(addvar,0, 5);
1691 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1692 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1693 FillInt64(addvar,0, 5);
1694 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1699 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1703 FillInt64(addvar,0, 5);
1704 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1709 SizeDumpVolume(struct rx_call *call, Volume * vp,
1710 afs_int32 fromtime, int dumpAllDirs,
1711 struct volintSize *v_size)
1714 struct iod *iodp = (struct iod *)0;
1715 /* iod_Init(iodp, call); */
1718 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1720 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1722 code = SizeDumpEnd(iodp, v_size);
1728 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1729 afs_int32 fromtime, struct volintSize *v_size)
1732 /* int UseLatestReadOnlyClone = 1; */
1733 /* afs_int32 dumpTimes[2]; */
1735 /* iodp->device = vp->device; */
1736 /* iodp->parentId = V_parentId(vp); */
1737 /* iodp->dumpPartition = vp->partition; */
1739 ZeroInt64(v_size->dump_size); /* initialize the size */
1740 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1741 FillInt64(addvar,0, 9);
1742 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1743 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1744 FillInt64(addvar,0, 5);
1745 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1746 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1747 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1748 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1749 /* dumpTimes[0] = fromtime; */
1750 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1751 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1752 FillInt64(addvar,0, (3 + 4 * 2));
1753 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1758 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1759 int vnodeNumber, int dumpEverything,
1760 struct volintSize *v_size)
1765 if (!v || v->type == vNull)
1767 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1768 FillInt64(addvar,0, 9);
1769 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1770 if (!dumpEverything)
1772 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1773 FillInt64(addvar,0, 2);
1774 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1775 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1776 FillInt64(addvar,0, 3);
1777 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1778 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1779 FillInt64(addvar,0, 5);
1780 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1781 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1782 FillInt64(addvar,0, 5);
1783 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1784 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1785 FillInt64(addvar,0, 5);
1786 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1787 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1788 FillInt64(addvar,0, 5);
1789 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1790 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1792 FillInt64(addvar,0, 5);
1793 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1795 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1796 FillInt64(addvar,0, 3);
1797 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1798 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1799 FillInt64(addvar,0, 5);
1800 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1801 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1802 FillInt64(addvar,0, 5);
1803 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1804 if (v->type == vDirectory) {
1805 /* acl_HtonACL(VVnodeDiskACL(v)); */
1806 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1807 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1808 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1811 if (VNDISK_GET_INO(v)) {
1812 FillInt64(addvar,0, (v->length + 5));
1813 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1818 /* A partial dump (no dump header) */
1820 SizeDumpPartial(struct iod *iodp, Volume * vp,
1821 afs_int32 fromtime, int dumpAllDirs,
1822 struct volintSize *v_size)
1826 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1829 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1832 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1837 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1838 afs_int32 fromtime, int forcedump,
1839 struct volintSize *v_size)
1842 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1843 char buf[SIZEOF_LARGEDISKVNODE];
1844 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1845 StreamHandle_t *file;
1847 afs_sfsize_t size, nVnodes;
1851 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1852 osi_Assert(fdP != NULL);
1853 file = FDH_FDOPEN(fdP, "r+");
1854 osi_Assert(file != NULL);
1855 size = OS_SIZE(fdP->fd_fd);
1856 osi_Assert(size != -1);
1857 nVnodes = (size / vcp->diskSize) - 1;
1859 osi_Assert((nVnodes + 1) * vcp->diskSize == size);
1860 osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1863 for (vnodeIndex = 0;
1864 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1865 nVnodes--, vnodeIndex++) {
1866 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1867 /* Note: the >= test is very important since some old volumes may not have
1868 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1869 * does dump the file! */
1872 SizeDumpVnode(iodp, vnode, V_id(vp),
1873 bitNumberToVnodeNumber(vnodeIndex, class), flag,