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 int 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 int volid, int vnodeNumber, int dumpEverything,
86 struct volintSize *size);
88 #define MAX_SECTIONS 3
90 #define MAX_TLV_TAG 0x60
91 #define MAX_STANDARD_TAG 0x7a
92 static afs_uint32 oldtags[MAX_SECTIONS][16];
93 int oldtagsInited = 0;
96 RegisterTag(afs_int32 section, unsigned char tag)
98 afs_uint32 off = tag >> 5;
99 afs_uint32 mask = 1 << (tag & 0x1f);
100 oldtags[section][off] |= mask;
104 initNonStandardTags(void)
106 RegisterTag(0, 'n'); /* volume name */
107 RegisterTag(0, 't'); /* fromtime, V_backupDate */
108 RegisterTag(1, 'A'); /* V_accessDate */
109 RegisterTag(1, 'C'); /* V_creationDate */
110 RegisterTag(1, 'D'); /* V_dayUseDate */
111 RegisterTag(1, 'E'); /* V_expirationDate */
112 RegisterTag(1, 'M'); /* nullstring (motd) */
113 RegisterTag(1, 'U'); /* V_updateDate */
114 RegisterTag(1, 'W'); /* V_weekUse */
115 RegisterTag(1, 'Z'); /* V_dayUse */
116 RegisterTag(1, 'O'); /* V_offlineMessage */
117 RegisterTag(1, 'b'); /* V_blessed */
118 RegisterTag(1, 'n'); /* V_name */
119 RegisterTag(1, 's'); /* V_inService */
120 RegisterTag(1, 't'); /* V_type */
121 RegisterTag(2, 'A'); /* VVnodeDiskACL */
122 RegisterTag(2, 'b'); /* modeBits */
123 RegisterTag(2, 'f'); /* small file */
124 RegisterTag(2, 'h'); /* large file */
125 RegisterTag(2, 'l'); /* linkcount */
126 RegisterTag(2, 't'); /* type */
131 iod_Init(struct iod *iodp, struct rx_call *call)
134 iodp->haveOldChar = 0;
136 iodp->calls = (struct rx_call **)0;
140 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
145 iodp->haveOldChar = 0;
146 iodp->ncalls = ncalls;
148 iodp->call = (struct rx_call *)0;
151 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
152 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
154 /* For the single dump case, it's ok to just return the "bytes written"
155 * that rx_Write returns, since all the callers of iod_Write abort when
156 * the returned value is less than they expect. For the multi dump case,
157 * I don't think we want half the replicas to go bad just because one
158 * connection timed out, but if they all time out, then we should give up.
161 iod_Write(struct iod *iodp, char *buf, int nbytes)
166 opr_Assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
167 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
170 code = rx_Write(iodp->call, buf, nbytes);
174 for (i = 0; i < iodp->ncalls; i++) {
175 if (iodp->calls[i] && !iodp->codes[i]) {
176 code = rx_Write(iodp->calls[i], buf, nbytes);
177 if (code != nbytes) { /* everything gets merged into a single error */
178 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
179 } /* standard dump does, anyways */
184 } /* for all calls */
193 iod_ungetc(struct iod *iodp, int achar)
195 iodp->oldChar = achar;
196 iodp->haveOldChar = 1;
200 iod_getc(struct iod *iodp)
204 if (iodp->haveOldChar) {
205 iodp->haveOldChar = 0;
206 return iodp->oldChar;
208 if (iod_Read(iodp, (char *) &t, 1) == 1)
214 ReadShort(struct iod *iodp, unsigned short *sp)
223 *sp = (b1 << 8) | b0;
228 ReadInt32(struct iod *iodp, afs_uint32 * lp)
230 afs_uint32 b3, b2, b1, b0;
243 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
248 ReadString(struct iod *iodp, char *to, int maxa)
257 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
261 while ((c = iod_getc(iodp)) && c != EOF);
267 ReadByteString(struct iod *iodp, byte * to,
271 *to++ = iod_getc(iodp);
275 * returns 1 on success and 0 otherwise
278 ReadStandardTagLen(struct iod *iodp, unsigned char tag, afs_int32 section,
282 afs_uint32 off = tag >> 5;
283 afs_uint32 mask = 1 << (tag & 0x1f);
284 unsigned char len, buf[8], *p;
287 initNonStandardTags();
289 if (tag < MIN_TLV_TAG
290 || tag > MAX_STANDARD_TAG
291 || section >= MAX_SECTIONS
292 || (oldtags[section][ off] & mask)) {
293 Log("Trying to use ReadStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
296 if (tag <= MAX_TLV_TAG) {
297 len = iod_getc(iodp);
302 if ((code = iod_Read(iodp, (char *)buf, len)) != len)
303 return VOLSERDUMPERROR;
305 p = (unsigned char *)&buf;
306 for (i=0; i<len; i++) {
307 *length = ((*length) << 8) | *p++;
311 if (tag < MAX_STANDARD_TAG)
317 static char skipbuf[256];
320 SkipData(struct iod *iodp, afs_size_t length)
322 while (length > 256) {
323 if (iod_Read(iodp, (char *)&skipbuf, 256) != 256)
327 if (iod_Read(iodp, (char *)&skipbuf, length) != length)
332 static char *secname[3] = {"ReadDumpHeader", "ReadVolumeHeader", "ReadVnodes"};
335 HandleUnknownTag(struct iod *iodp, int tag, afs_int32 section,
338 afs_size_t taglen = 0;
342 Log("%s: unknown critical tag x%02x, aborting\n",
343 secname[section], tag);
346 Log("%s: unknown tag x%02x found, skipping\n", secname[section], tag);
347 if (tag >= 0x06 && tag <= 0x60) {
348 if (!ReadStandardTagLen(iodp, tag, 1, &taglen)) {
349 Log("%s: error reading length field for tag x%02x, aborting\n",
350 secname[section], tag);
353 if (!SkipData(iodp, taglen)) {
354 Log("%s: error skipping %llu bytes for tag x%02x, aborting\n",
355 secname[section], taglen, tag);
360 if (tag >= 0x61 && tag <= 0x7a) {
361 if (!ReadInt32(iodp, &trash)) {
362 Log("%s: error skipping int32 for tag x%02x, aborting\n",
363 secname[section], tag);
368 if (tag >= 0x7b && tag < 0x80) /* dataless tag */
370 Log("%s: unknown invalid tag x%02x, aborting\n", secname[section], tag);
375 ReadVolumeHeader(struct iod *iodp, VolumeDiskData * vol)
379 afs_int32 critical = 0;
380 memset(vol, 0, sizeof(*vol));
381 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
386 if (!ReadInt32(iodp, &vol->id))
387 return VOLSERREAD_DUMPERROR;
390 if (!ReadInt32(iodp, &trash))
391 return VOLSERREAD_DUMPERROR;
394 ReadString(iodp, vol->name, sizeof(vol->name));
395 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
398 vol->inService = iod_getc(iodp);
401 vol->blessed = iod_getc(iodp);
404 if (!ReadInt32(iodp, &vol->uniquifier))
405 return VOLSERREAD_DUMPERROR;
408 vol->type = iod_getc(iodp);
411 if (!ReadInt32(iodp, &vol->parentId))
412 return VOLSERREAD_DUMPERROR;
415 if (!ReadInt32(iodp, &vol->cloneId))
416 return VOLSERREAD_DUMPERROR;
419 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
420 return VOLSERREAD_DUMPERROR;
423 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
424 return VOLSERREAD_DUMPERROR;
427 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
428 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
431 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
432 return VOLSERREAD_DUMPERROR;
435 if (!ReadInt32(iodp, &vol->accountNumber))
436 return VOLSERREAD_DUMPERROR;
439 if (!ReadInt32(iodp, &vol->owner))
440 return VOLSERREAD_DUMPERROR;
443 if (!ReadInt32(iodp, &vol->creationDate))
444 return VOLSERREAD_DUMPERROR;
447 if (!ReadInt32(iodp, &vol->accessDate))
448 return VOLSERREAD_DUMPERROR;
451 if (!ReadInt32(iodp, &vol->updateDate))
452 return VOLSERREAD_DUMPERROR;
455 if (!ReadInt32(iodp, &vol->expirationDate))
456 return VOLSERREAD_DUMPERROR;
459 if (!ReadInt32(iodp, &vol->backupDate))
460 return VOLSERREAD_DUMPERROR;
463 ReadString(iodp, vol->offlineMessage,
464 sizeof(vol->offlineMessage));
468 * Detailed volume statistics are never stored in dumps,
469 * so we just restore either the null string if this volume
470 * had already been set to store statistics, or the old motd
471 * contents otherwise. It doesn't matter, since this field
472 * will soon get initialized anyway.
474 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
477 unsigned short length;
480 if (!ReadShort(iodp, &length))
481 return VOLSERREAD_DUMPERROR;
482 for (i = 0; i < length; i++) {
483 if (!ReadInt32(iodp, &data))
484 return VOLSERREAD_DUMPERROR;
485 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
486 vol->weekUse[i] = data;
491 if (!ReadInt32(iodp, &vol->dayUseDate))
492 return VOLSERREAD_DUMPERROR;
495 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
496 return VOLSERREAD_DUMPERROR;
499 if (!ReadInt32(iodp, (afs_uint32 *) &trash/*volUpdateCounter*/))
500 return VOLSERREAD_DUMPERROR;
506 if (!HandleUnknownTag(iodp, tag, 1, critical))
507 return VOLSERREAD_DUMPERROR;
510 iod_ungetc(iodp, tag);
515 DumpTag(struct iod *iodp, int tag)
520 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
525 DumpByte(struct iod *iodp, char tag, byte value)
528 byte *p = (unsigned char *)tbuffer;
531 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
534 #define afs_putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
535 #define afs_putshort(p, v) *p++ = v>>8, *p++ = v
538 DumpDouble(struct iod *iodp, char tag, afs_uint32 value1,
542 byte *p = (unsigned char *)tbuffer;
544 afs_putint32(p, value1);
545 afs_putint32(p, value2);
546 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
550 DumpInt32(struct iod *iodp, char tag, afs_uint32 value)
553 byte *p = (unsigned char *)tbuffer;
555 afs_putint32(p, value);
556 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
560 DumpArrayInt32(struct iod *iodp, char tag,
561 afs_uint32 * array, int nelem)
566 byte *p = (unsigned char *)tbuffer;
568 afs_putshort(p, nelem);
569 code = iod_Write(iodp, tbuffer, 3);
571 return VOLSERDUMPERROR;
573 p = (unsigned char *)tbuffer;
574 v = *array++; /*this was register */
577 code = iod_Write(iodp, tbuffer, 4);
579 return VOLSERDUMPERROR;
585 DumpShort(struct iod *iodp, char tag, unsigned int value)
588 byte *p = (unsigned char *)tbuffer;
592 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
596 DumpBool(struct iod *iodp, char tag, unsigned int value)
599 byte *p = (unsigned char *)tbuffer;
602 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
606 DumpString(struct iod *iodp, char tag, char *s)
610 code = iod_Write(iodp, &tag, 1);
612 return VOLSERDUMPERROR;
614 code = iod_Write(iodp, s, n);
616 return VOLSERDUMPERROR;
621 DumpByteString(struct iod *iodp, char tag, byte * bs,
626 code = iod_Write(iodp, &tag, 1);
628 return VOLSERDUMPERROR;
629 code = iod_Write(iodp, (char *)bs, nbytes);
631 return VOLSERDUMPERROR;
636 DumpStandardTag(struct iod *iodp, char tag, afs_uint32 section)
639 afs_uint32 off = tag >> 5;
640 afs_uint32 mask = 1 << (tag & 0x1f);
643 initNonStandardTags();
645 if (tag < MIN_TLV_TAG
646 || tag > MAX_STANDARD_TAG
647 || section >= MAX_SECTIONS
648 || (oldtags[section][ off] & mask)) {
649 Log("Trying to use DumpStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
650 return VOLSERDUMPERROR;
652 code = iod_Write(iodp, &tag, 1);
654 return VOLSERDUMPERROR;
660 DumpStandardTagLen(struct iod *iodp, char tag, afs_uint32 section,
667 if (tag < MIN_TLV_TAG || tag > MAX_TLV_TAG) {
668 Log("Trying to use DumpStandardTagLen with tag 0x%02x for section %d, aborting\n", tag, section);
669 return VOLSERDUMPERROR;
671 code = DumpStandardTag(iodp, tag, section);
675 if (length < 128) { /* byte after tag contains length */
678 } else { /* byte after tag contains length of length field | 0x80 */
679 for (len=0; length; length=length >> 8) {
687 code = iod_Write(iodp, p, len);
689 return VOLSERDUMPERROR;
694 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
696 int code = 0, error = 0;
698 afs_foff_t offset = 0;
699 afs_sfsize_t nbytes, howBig;
702 afs_foff_t howFar = 0;
707 struct afs_stat status;
709 LARGE_INTEGER fileSize;
712 #include <sys/statfs.h>
713 #if defined(AFS_AIX52_ENV)
714 struct statfs64 tstatfs;
715 #else /* !AFS_AIX52_ENV */
716 struct statfs tstatfs;
717 #endif /* !AFS_AIX52_ENV */
722 if (!GetFileSizeEx(handleP->fd_fd, &fileSize)) {
723 Log("DumpFile: GetFileSizeEx returned error code %d on descriptor %d\n", GetLastError(), handleP->fd_fd);
724 return VOLSERDUMPERROR;
726 howBig = fileSize.QuadPart;
730 afs_fstat(handleP->fd_fd, &status);
731 howBig = status.st_size;
734 /* Unfortunately in AIX valuable fields such as st_blksize are
735 * gone from the stat structure.
737 #if defined(AFS_AIX52_ENV)
738 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
739 #else /* !AFS_AIX52_ENV */
740 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
741 #endif /* !AFS_AIX52_ENV */
742 if (statfs_code != 0) {
743 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
744 return VOLSERDUMPERROR;
746 howMany = tstatfs.f_bsize;
748 howMany = status.st_blksize;
749 #endif /* AFS_AIX_ENV */
750 #endif /* AFS_NT40_ENV */
753 SplitInt64(howBig, hi, lo);
755 code = DumpInt32(iodp, 'f', lo);
757 code = DumpDouble(iodp, 'h', hi, lo);
760 return VOLSERDUMPERROR;
765 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", (unsigned)howMany);
766 return VOLSERDUMPERROR;
769 for (nbytes = howBig; (nbytes && !error); nbytes -= howMany) {
770 if (nbytes < howMany)
774 n = FDH_PREAD(handleP, p, howMany, howFar);
777 /* If read any good data and we null padded previously, log the
778 * amount that we had null padded.
780 if ((n > 0) && pad) {
781 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %lld\n", pad, (long long)offset);
785 /* If didn't read enough data, null padd the rest of the buffer. This
786 * can happen if, for instance, the media has some bad spots. We don't
787 * want to quit the dump, so we start null padding.
790 /* Record the read error */
793 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));
795 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
798 /* Pad the rest of the buffer with zeros. Remember offset we started
799 * padding. Keep total tally of padding.
801 memset(p + n, 0, howMany - n);
803 offset = (howBig - nbytes) + n;
804 pad += (howMany - n);
806 /* Now seek over the data we could not get. An error here means we
807 * can't do the next read.
809 howFar = (size_t)((howBig - nbytes) + howMany);
812 /* Now write the data out */
813 if (iod_Write(iodp, (char *)p, howMany) != howMany)
814 error = VOLSERDUMPERROR;
815 #ifndef AFS_PTHREAD_ENV
820 if (pad) { /* Any padding we hadn't reported yet */
821 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %lld\n",
822 pad, (long long)offset);
830 DumpVolumeHeader(struct iod *iodp, Volume * vp)
833 static char nullString[1] = ""; /*The ``contents'' of motd */
836 code = DumpTag(iodp, D_VOLUMEHEADER);
838 code = DumpInt32(iodp, 'i', V_id(vp));
841 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
843 code = DumpString(iodp, 'n', V_name(vp));
845 code = DumpBool(iodp, 's', V_inService(vp));
847 code = DumpBool(iodp, 'b', V_blessed(vp));
849 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
851 code = DumpByte(iodp, 't', (byte) V_type(vp));
853 code = DumpInt32(iodp, 'p', V_parentId(vp));
856 code = DumpInt32(iodp, 'c', V_cloneId(vp));
858 code = DumpInt32(iodp, 'q', V_maxquota(vp));
860 code = DumpInt32(iodp, 'm', V_minquota(vp));
862 code = DumpInt32(iodp, 'd', V_diskused(vp));
864 code = DumpInt32(iodp, 'f', V_filecount(vp));
866 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
868 code = DumpInt32(iodp, 'o', V_owner(vp));
870 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
872 code = DumpInt32(iodp, 'A', V_accessDate(vp));
874 code = DumpInt32(iodp, 'U', V_updateDate(vp));
876 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
878 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
880 code = DumpString(iodp, 'O', V_offlineMessage(vp));
882 * We do NOT dump the detailed volume statistics residing in the old
883 * motd field, since we cannot tell from the info in a dump whether
884 * statistics data has been put there. Instead, we dump a null string,
885 * just as if that was what the motd contained.
888 code = DumpString(iodp, 'M', nullString);
891 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
892 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
894 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
896 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
901 DumpEnd(struct iod *iodp)
903 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
906 /* Guts of the dump code */
908 /* Dump a whole volume */
910 DumpVolume(struct rx_call *call, Volume * vp,
911 afs_int32 fromtime, int dumpAllDirs)
915 struct iod *iodp = &iod;
916 iod_Init(iodp, call);
919 code = DumpDumpHeader(iodp, vp, fromtime);
922 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
924 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
925 if (rx_Error(iodp->call)) {
926 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
927 rx_Error(iodp->call));
928 return VOLSERDUMPERROR;
931 code = DumpEnd(iodp);
936 /* Dump a volume to multiple places*/
938 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
939 afs_int32 fromtime, int dumpAllDirs, int *codes)
943 iod_InitMulti(&iod, calls, ncalls, codes);
946 code = DumpDumpHeader(&iod, vp, fromtime);
948 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
950 code = DumpEnd(&iod);
954 /* A partial dump (no dump header) */
956 DumpPartial(struct iod *iodp, Volume * vp,
957 afs_int32 fromtime, int dumpAllDirs)
961 code = DumpVolumeHeader(iodp, vp);
963 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
965 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
970 DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
971 afs_int32 fromtime, int forcedump)
974 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
975 char buf[SIZEOF_LARGEDISKVNODE];
976 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
977 StreamHandle_t *file;
979 afs_sfsize_t size, nVnodes;
983 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
984 opr_Assert(fdP != NULL);
985 file = FDH_FDOPEN(fdP, "r+");
986 opr_Assert(file != NULL);
987 size = OS_SIZE(fdP->fd_fd);
988 opr_Assert(size != -1);
989 nVnodes = (size / vcp->diskSize) - 1;
991 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
992 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
996 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
997 nVnodes--, vnodeIndex++) {
998 flag = forcedump || (vnode->serverModifyTime >= fromtime);
999 /* Note: the >= test is very important since some old volumes may not have
1000 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1001 * does dump the file! */
1004 DumpVnode(iodp, vnode, V_id(vp),
1005 bitNumberToVnodeNumber(vnodeIndex, class), flag);
1006 #ifndef AFS_PTHREAD_ENV
1008 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
1017 DumpDumpHeader(struct iod *iodp, Volume * vp,
1021 int UseLatestReadOnlyClone = 1;
1022 afs_int32 dumpTimes[2];
1023 iodp->device = vp->device;
1024 iodp->parentId = V_parentId(vp);
1025 iodp->dumpPartition = vp->partition;
1027 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
1030 DumpInt32(iodp, 'v',
1031 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
1033 code = DumpString(iodp, 'n', V_name(vp));
1034 dumpTimes[0] = fromtime;
1035 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
1037 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
1042 DumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1043 int vnodeNumber, int dumpEverything)
1049 if (!v || v->type == vNull)
1052 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
1053 if (!dumpEverything)
1056 code = DumpByte(iodp, 't', (byte) v->type);
1058 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
1060 code = DumpInt32(iodp, 'v', v->dataVersion);
1062 code = DumpInt32(iodp, 'm', v->unixModifyTime);
1064 code = DumpInt32(iodp, 'a', v->author);
1066 code = DumpInt32(iodp, 'o', v->owner);
1067 if (!code && v->group)
1068 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
1070 code = DumpShort(iodp, 'b', v->modeBits);
1072 code = DumpInt32(iodp, 'p', v->parent);
1074 code = DumpInt32(iodp, 's', v->serverModifyTime);
1075 if (v->type == vDirectory) {
1076 acl_HtonACL(VVnodeDiskACL(v));
1079 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
1082 if (VNDISK_GET_INO(v)) {
1083 afs_sfsize_t indexlen, disklen;
1084 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1087 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);
1089 return VOLSERREAD_DUMPERROR;
1091 VNDISK_GET_LEN(indexlen, v);
1092 disklen = FDH_SIZE(fdP);
1093 if (indexlen != disklen) {
1094 FDH_REALLYCLOSE(fdP);
1096 Log("DumpVnode: volume %lu vnode %lu has inconsistent length "
1097 "(index %lu disk %lu); aborting dump\n",
1098 (unsigned long)volid, (unsigned long)vnodeNumber,
1099 (unsigned long)indexlen, (unsigned long)disklen);
1100 return VOLSERREAD_DUMPERROR;
1102 code = DumpFile(iodp, vnodeNumber, fdP);
1111 ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep,
1114 int i, nVnodes, code;
1119 StreamHandle_t *afile;
1121 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1122 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1123 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1125 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1126 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1129 afile = FDH_FDOPEN(fdP, "r+");
1133 for (i = 0; i < *sizep; i++) {
1136 STREAM_ASEEK(afile, Buf[i]);
1137 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1139 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1142 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
1143 V_id(vp), bitNumberToVnodeNumber(i, class),
1144 (afs_uintmax_t) VNDISK_GET_INO(vnode));
1146 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1150 STREAM_ASEEK(afile, Buf[i]);
1151 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1157 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1160 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1161 OS_SYNC(afile->str_fd);
1163 size = OS_SIZE(fdP->fd_fd);
1164 opr_Assert(size != -1);
1167 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1169 Buf = calloc(nVnodes, sizeof(afs_foff_t));
1171 STREAM_CLOSE(afile);
1175 STREAM_ASEEK(afile, offset = vcp->diskSize);
1177 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1181 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1182 Buf[(offset >> vcp->logSize) - 1] = offset;
1185 offset += vcp->diskSize;
1191 STREAM_CLOSE(afile);
1198 RestoreVolume(struct rx_call *call, Volume * avp, int incremental,
1199 struct restoreCookie *cookie)
1202 struct DumpHeader header;
1203 afs_uint32 endMagic;
1204 Error error = 0, vupdate;
1207 struct iod *iodp = &iod;
1208 afs_foff_t *b1 = NULL, *b2 = NULL;
1209 int s1 = 0, s2 = 0, delo = 0, tdelo;
1211 VolumeDiskData saved_header;
1213 iod_Init(iodp, call);
1217 if (DoPreserveVolumeStats) {
1218 CopyVolumeStats(&V_disk(vp), &saved_header);
1221 if (!ReadDumpHeader(iodp, &header)) {
1222 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1223 return VOLSERREAD_DUMPERROR;
1225 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1226 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1227 return VOLSERREAD_DUMPERROR;
1229 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1230 return VOLSERREAD_DUMPERROR;
1233 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1235 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1237 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1238 error = VOLSERREAD_DUMPERROR;
1242 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1243 vol.type = cookie->type;
1244 vol.cloneId = cookie->clone;
1245 vol.parentId = cookie->parent;
1247 V_needsSalvaged(vp) = 0;
1251 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1252 error = VOLSERREAD_DUMPERROR;
1255 tag = iod_getc(iodp);
1256 if (tag != D_VOLUMEHEADER)
1259 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1260 error = VOLSERREAD_DUMPERROR;
1264 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1265 || endMagic != DUMPENDMAGIC) {
1266 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1267 error = VOLSERREAD_DUMPERROR;
1272 if (iod_getc(iodp) != EOF) {
1273 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1274 error = VOLSERREAD_DUMPERROR;
1279 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1281 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1283 error = VOLSERREAD_DUMPERROR;
1289 if (DoPreserveVolumeStats) {
1290 CopyVolumeStats(&saved_header, &vol);
1292 ClearVolumeStats(&vol);
1294 if (V_needsSalvaged(vp)) {
1295 /* needsSalvaged may have been set while we tried to write volume data.
1296 * prevent it from getting overwritten. */
1297 vol.needsSalvaged = V_needsSalvaged(vp);
1299 CopyVolumeHeader(&vol, &V_disk(vp));
1300 V_destroyMe(vp) = 0;
1301 VUpdateVolume(&vupdate, vp);
1303 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1304 error = VOLSERREAD_DUMPERROR;
1308 /* Free the malloced space above */
1317 ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
1318 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf, afs_int32 s2,
1321 afs_int32 vnodeNumber;
1322 char buf[SIZEOF_LARGEDISKVNODE];
1324 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1325 struct VnodeDiskObject oldvnode;
1328 struct VnodeClassInfo *vcp;
1331 Inode nearInode AFS_UNUSED;
1332 afs_int32 critical = 0;
1334 tag = iod_getc(iodp);
1335 V_pref(vp, nearInode);
1336 while (tag == D_VNODE) {
1339 memset(buf, 0, sizeof(buf));
1340 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1343 if (!ReadInt32(iodp, &vnode->uniquifier))
1344 return VOLSERREAD_DUMPERROR;
1346 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1352 vnode->type = (VnodeType) iod_getc(iodp);
1357 if (!ReadShort(iodp, &tlc))
1358 return VOLSERREAD_DUMPERROR;
1359 vnode->linkCount = (signed int)tlc;
1363 if (!ReadInt32(iodp, &vnode->dataVersion))
1364 return VOLSERREAD_DUMPERROR;
1367 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1368 return VOLSERREAD_DUMPERROR;
1371 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1372 return VOLSERREAD_DUMPERROR;
1375 if (!ReadInt32(iodp, &vnode->author))
1376 return VOLSERREAD_DUMPERROR;
1379 if (!ReadInt32(iodp, &vnode->owner))
1380 return VOLSERREAD_DUMPERROR;
1383 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1384 return VOLSERREAD_DUMPERROR;
1387 unsigned short modeBits;
1388 if (!ReadShort(iodp, &modeBits))
1389 return VOLSERREAD_DUMPERROR;
1390 vnode->modeBits = (unsigned int)modeBits;
1394 if (!ReadInt32(iodp, &vnode->parent))
1395 return VOLSERREAD_DUMPERROR;
1398 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1399 VAclDiskSize(vnode));
1400 acl_NtohACL(VVnodeDiskACL(vnode));
1406 afs_fsize_t vnodeLength;
1409 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1410 "file entries for vnode %lu in dump\n",
1411 (unsigned long)vnodeNumber);
1412 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1418 IH_CREATE(V_linkHandle(vp), V_device(vp),
1419 VPartitionPath(V_partition(vp)), nearInode,
1420 V_parentId(vp), vnodeNumber,
1421 vnode->uniquifier, vnode->dataVersion);
1422 if (!VALID_INO(ino)) {
1423 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1424 afs_error_message(errno));
1425 V_needsSalvaged(vp) = 1;
1426 return VOLSERREAD_DUMPERROR;
1429 VNDISK_SET_INO(vnode, ino);
1430 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1431 fdP = IH_OPEN(tmpH);
1433 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1434 afs_error_message(errno));
1436 V_needsSalvaged(vp) = 1;
1437 return VOLSERREAD_DUMPERROR;
1440 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1441 VNDISK_SET_LEN(vnode, vnodeLength);
1442 FDH_REALLYCLOSE(fdP);
1445 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1446 (afs_uintmax_t) ino);
1447 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1448 V_needsSalvaged(vp) = 1;
1449 return VOLSERREAD_DUMPERROR;
1457 if (!HandleUnknownTag(iodp, tag, 2, critical))
1458 return VOLSERREAD_DUMPERROR;
1462 class = vnodeIdToClass(vnodeNumber);
1463 vcp = &VnodeClassInfo[class];
1465 /* Mark this vnode as in this dump - so we don't delete it later */
1467 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1468 if (class == vLarge) {
1469 if (Lbuf && (idx < s1))
1472 if (Sbuf && (idx < s2))
1478 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1480 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1481 afs_error_message(errno));
1482 V_needsSalvaged(vp) = 1;
1483 return VOLSERREAD_DUMPERROR;
1485 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1487 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1488 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1492 vnode->vnodeMagic = vcp->magic;
1493 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1494 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1495 afs_error_message(errno));
1496 FDH_REALLYCLOSE(fdP);
1497 V_needsSalvaged(vp) = 1;
1498 return VOLSERREAD_DUMPERROR;
1503 iod_ungetc(iodp, tag);
1509 /* called with disk file only. Note that we don't have to worry about rx_Read
1510 * needing to read an ungetc'd character, since the ReadInt32 will have read
1513 * if handleP == NULL, don't write the file anywhere; just read and discard
1517 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1522 afs_fsize_t filesize;
1523 afs_fsize_t written = 0;
1531 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1533 if (!ReadInt32(iodp, &filesize_high)) {
1538 if (!ReadInt32(iodp, &filesize_low)) {
1542 FillInt64(filesize, filesize_high, filesize_low);
1549 for (nbytes = filesize; nbytes; nbytes -= size) {
1553 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1554 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));
1559 nBytes = FDH_PWRITE(handleP, p, size, written);
1562 if (nBytes != size) {
1563 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1574 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1577 afs_uint32 beginMagic;
1578 afs_int32 critical = 0;
1579 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1580 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1581 || beginMagic != DUMPBEGINMAGIC)
1585 while ((tag = iod_getc(iodp)) > D_MAX) {
1586 unsigned short arrayLength;
1592 if (!ReadInt32(iodp, &hp->volumeId))
1596 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1599 if (!ReadShort(iodp, &arrayLength))
1601 hp->nDumpTimes = (arrayLength >> 1);
1602 for (i = 0; i < hp->nDumpTimes; i++)
1603 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1604 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1611 if (!HandleUnknownTag(iodp, tag, 0, critical))
1612 return VOLSERREAD_DUMPERROR;
1615 if (!hp->volumeId || !hp->nDumpTimes) {
1618 iod_ungetc(iodp, tag);
1623 /* ----- Below are the calls that calculate dump size ----- */
1626 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1627 struct volintSize *v_size)
1630 static char nullString[1] = ""; /*The ``contents'' of motd */
1633 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1634 FillInt64(addvar,0, 1);
1635 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1636 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1637 FillInt64(addvar,0, 5);
1638 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1639 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1640 FillInt64(addvar,0, 5);
1641 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1642 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1643 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1644 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1645 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1646 FillInt64(addvar,0, 2);
1647 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1648 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1649 FillInt64(addvar,0, 2);
1650 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1651 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1652 FillInt64(addvar,0, 5);
1653 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1654 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1655 FillInt64(addvar,0, 2);
1656 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1657 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1658 FillInt64(addvar,0, 5);
1659 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1660 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1661 FillInt64(addvar,0, 5);
1662 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1663 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1664 FillInt64(addvar,0, 5);
1665 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1666 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1667 FillInt64(addvar,0, 5);
1668 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1669 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1670 FillInt64(addvar,0, 5);
1671 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1672 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1673 FillInt64(addvar,0, 5);
1674 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1675 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1676 FillInt64(addvar,0, 5);
1677 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1678 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1679 FillInt64(addvar,0, 5);
1680 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1681 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1682 FillInt64(addvar,0, 5);
1683 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1684 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1685 FillInt64(addvar,0, 5);
1686 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1687 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1688 FillInt64(addvar,0, 5);
1689 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1690 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1691 FillInt64(addvar,0, 5);
1692 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1693 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1694 FillInt64(addvar,0, 5);
1695 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1696 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1697 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1698 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1700 /* * We do NOT dump the detailed volume statistics residing in the old */
1701 /* * motd field, since we cannot tell from the info in a dump whether */
1702 /* * statistics data has been put there. Instead, we dump a null string, */
1703 /* * just as if that was what the motd contained. */
1705 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1706 FillInt64(addvar,0, (2 + strlen(nullString)));
1707 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1708 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1709 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1710 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1711 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1712 FillInt64(addvar,0, 5);
1713 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1714 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1715 FillInt64(addvar,0, 5);
1716 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1721 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1725 FillInt64(addvar,0, 5);
1726 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1731 SizeDumpVolume(struct rx_call *call, Volume * vp,
1732 afs_int32 fromtime, int dumpAllDirs,
1733 struct volintSize *v_size)
1736 struct iod *iodp = (struct iod *)0;
1737 /* iod_Init(iodp, call); */
1740 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1742 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1744 code = SizeDumpEnd(iodp, v_size);
1750 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1751 afs_int32 fromtime, struct volintSize *v_size)
1754 /* int UseLatestReadOnlyClone = 1; */
1755 /* afs_int32 dumpTimes[2]; */
1757 /* iodp->device = vp->device; */
1758 /* iodp->parentId = V_parentId(vp); */
1759 /* iodp->dumpPartition = vp->partition; */
1761 ZeroInt64(v_size->dump_size); /* initialize the size */
1762 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1763 FillInt64(addvar,0, 9);
1764 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1765 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1766 FillInt64(addvar,0, 5);
1767 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1768 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1769 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1770 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1771 /* dumpTimes[0] = fromtime; */
1772 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1773 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1774 FillInt64(addvar,0, (3 + 4 * 2));
1775 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1780 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1781 int vnodeNumber, int dumpEverything,
1782 struct volintSize *v_size)
1787 if (!v || v->type == vNull)
1789 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1790 FillInt64(addvar,0, 9);
1791 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1792 if (!dumpEverything)
1794 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1795 FillInt64(addvar,0, 2);
1796 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1797 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1798 FillInt64(addvar,0, 3);
1799 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1800 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1801 FillInt64(addvar,0, 5);
1802 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1803 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1804 FillInt64(addvar,0, 5);
1805 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1806 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1807 FillInt64(addvar,0, 5);
1808 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1809 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1810 FillInt64(addvar,0, 5);
1811 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1812 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1814 FillInt64(addvar,0, 5);
1815 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1817 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1818 FillInt64(addvar,0, 3);
1819 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1820 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1821 FillInt64(addvar,0, 5);
1822 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1823 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1824 FillInt64(addvar,0, 5);
1825 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1826 if (v->type == vDirectory) {
1827 /* acl_HtonACL(VVnodeDiskACL(v)); */
1828 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1829 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1830 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1833 if (VNDISK_GET_INO(v)) {
1834 FillInt64(addvar,0, (v->length + 5));
1835 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1840 /* A partial dump (no dump header) */
1842 SizeDumpPartial(struct iod *iodp, Volume * vp,
1843 afs_int32 fromtime, int dumpAllDirs,
1844 struct volintSize *v_size)
1848 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1851 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1854 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1859 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1860 afs_int32 fromtime, int forcedump,
1861 struct volintSize *v_size)
1864 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1865 char buf[SIZEOF_LARGEDISKVNODE];
1866 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1867 StreamHandle_t *file;
1869 afs_sfsize_t size, nVnodes;
1873 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1874 opr_Assert(fdP != NULL);
1875 file = FDH_FDOPEN(fdP, "r+");
1876 opr_Assert(file != NULL);
1877 size = OS_SIZE(fdP->fd_fd);
1878 opr_Assert(size != -1);
1879 nVnodes = (size / vcp->diskSize) - 1;
1881 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
1882 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1885 for (vnodeIndex = 0;
1886 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1887 nVnodes--, vnodeIndex++) {
1888 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1889 /* Note: the >= test is very important since some old volumes may not have
1890 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1891 * does dump the file! */
1894 SizeDumpVnode(iodp, vnode, V_id(vp),
1895 bitNumberToVnodeNumber(vnodeIndex, class), flag,