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 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1086 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);
1088 return VOLSERREAD_DUMPERROR;
1090 code = DumpFile(iodp, vnodeNumber, fdP);
1099 ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep,
1102 int i, nVnodes, code;
1107 StreamHandle_t *afile;
1109 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1110 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1111 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1113 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1114 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1117 afile = FDH_FDOPEN(fdP, "r+");
1121 for (i = 0; i < *sizep; i++) {
1124 STREAM_ASEEK(afile, Buf[i]);
1125 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1127 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1130 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
1131 V_id(vp), bitNumberToVnodeNumber(i, class),
1132 (afs_uintmax_t) VNDISK_GET_INO(vnode));
1134 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1138 STREAM_ASEEK(afile, Buf[i]);
1139 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1145 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1148 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1149 OS_SYNC(afile->str_fd);
1151 size = OS_SIZE(fdP->fd_fd);
1152 opr_Assert(size != -1);
1155 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1157 Buf = calloc(nVnodes, sizeof(afs_foff_t));
1159 STREAM_CLOSE(afile);
1163 STREAM_ASEEK(afile, offset = vcp->diskSize);
1165 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1169 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1170 Buf[(offset >> vcp->logSize) - 1] = offset;
1173 offset += vcp->diskSize;
1179 STREAM_CLOSE(afile);
1186 RestoreVolume(struct rx_call *call, Volume * avp, int incremental,
1187 struct restoreCookie *cookie)
1190 struct DumpHeader header;
1191 afs_uint32 endMagic;
1192 Error error = 0, vupdate;
1195 struct iod *iodp = &iod;
1196 afs_foff_t *b1 = NULL, *b2 = NULL;
1197 int s1 = 0, s2 = 0, delo = 0, tdelo;
1199 VolumeDiskData saved_header;
1201 iod_Init(iodp, call);
1205 if (DoPreserveVolumeStats) {
1206 CopyVolumeStats(&V_disk(vp), &saved_header);
1209 if (!ReadDumpHeader(iodp, &header)) {
1210 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1211 return VOLSERREAD_DUMPERROR;
1213 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1214 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1215 return VOLSERREAD_DUMPERROR;
1217 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1218 return VOLSERREAD_DUMPERROR;
1221 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1223 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1225 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1226 error = VOLSERREAD_DUMPERROR;
1230 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1231 vol.type = cookie->type;
1232 vol.cloneId = cookie->clone;
1233 vol.parentId = cookie->parent;
1235 V_needsSalvaged(vp) = 0;
1239 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1240 error = VOLSERREAD_DUMPERROR;
1243 tag = iod_getc(iodp);
1244 if (tag != D_VOLUMEHEADER)
1247 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1248 error = VOLSERREAD_DUMPERROR;
1252 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1253 || endMagic != DUMPENDMAGIC) {
1254 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1255 error = VOLSERREAD_DUMPERROR;
1260 if (iod_getc(iodp) != EOF) {
1261 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1262 error = VOLSERREAD_DUMPERROR;
1267 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1269 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1271 error = VOLSERREAD_DUMPERROR;
1277 if (DoPreserveVolumeStats) {
1278 CopyVolumeStats(&saved_header, &vol);
1280 ClearVolumeStats(&vol);
1282 if (V_needsSalvaged(vp)) {
1283 /* needsSalvaged may have been set while we tried to write volume data.
1284 * prevent it from getting overwritten. */
1285 vol.needsSalvaged = V_needsSalvaged(vp);
1287 CopyVolumeHeader(&vol, &V_disk(vp));
1288 V_destroyMe(vp) = 0;
1289 VUpdateVolume(&vupdate, vp);
1291 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1292 error = VOLSERREAD_DUMPERROR;
1296 /* Free the malloced space above */
1305 ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
1306 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf, afs_int32 s2,
1309 afs_int32 vnodeNumber;
1310 char buf[SIZEOF_LARGEDISKVNODE];
1312 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1313 struct VnodeDiskObject oldvnode;
1316 struct VnodeClassInfo *vcp;
1319 Inode nearInode AFS_UNUSED;
1320 afs_int32 critical = 0;
1322 tag = iod_getc(iodp);
1323 V_pref(vp, nearInode);
1324 while (tag == D_VNODE) {
1327 memset(buf, 0, sizeof(buf));
1328 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1331 if (!ReadInt32(iodp, &vnode->uniquifier))
1332 return VOLSERREAD_DUMPERROR;
1334 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1340 vnode->type = (VnodeType) iod_getc(iodp);
1345 if (!ReadShort(iodp, &tlc))
1346 return VOLSERREAD_DUMPERROR;
1347 vnode->linkCount = (signed int)tlc;
1351 if (!ReadInt32(iodp, &vnode->dataVersion))
1352 return VOLSERREAD_DUMPERROR;
1355 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1356 return VOLSERREAD_DUMPERROR;
1359 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1360 return VOLSERREAD_DUMPERROR;
1363 if (!ReadInt32(iodp, &vnode->author))
1364 return VOLSERREAD_DUMPERROR;
1367 if (!ReadInt32(iodp, &vnode->owner))
1368 return VOLSERREAD_DUMPERROR;
1371 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1372 return VOLSERREAD_DUMPERROR;
1375 unsigned short modeBits;
1376 if (!ReadShort(iodp, &modeBits))
1377 return VOLSERREAD_DUMPERROR;
1378 vnode->modeBits = (unsigned int)modeBits;
1382 if (!ReadInt32(iodp, &vnode->parent))
1383 return VOLSERREAD_DUMPERROR;
1386 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1387 VAclDiskSize(vnode));
1388 acl_NtohACL(VVnodeDiskACL(vnode));
1394 afs_fsize_t vnodeLength;
1397 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1398 "file entries for vnode %lu in dump\n",
1399 (unsigned long)vnodeNumber);
1400 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1406 IH_CREATE(V_linkHandle(vp), V_device(vp),
1407 VPartitionPath(V_partition(vp)), nearInode,
1408 V_parentId(vp), vnodeNumber,
1409 vnode->uniquifier, vnode->dataVersion);
1410 if (!VALID_INO(ino)) {
1411 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1412 afs_error_message(errno));
1413 V_needsSalvaged(vp) = 1;
1414 return VOLSERREAD_DUMPERROR;
1417 VNDISK_SET_INO(vnode, ino);
1418 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1419 fdP = IH_OPEN(tmpH);
1421 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1422 afs_error_message(errno));
1424 V_needsSalvaged(vp) = 1;
1425 return VOLSERREAD_DUMPERROR;
1428 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1429 VNDISK_SET_LEN(vnode, vnodeLength);
1430 FDH_REALLYCLOSE(fdP);
1433 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1434 (afs_uintmax_t) ino);
1435 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1436 V_needsSalvaged(vp) = 1;
1437 return VOLSERREAD_DUMPERROR;
1445 if (!HandleUnknownTag(iodp, tag, 2, critical))
1446 return VOLSERREAD_DUMPERROR;
1450 class = vnodeIdToClass(vnodeNumber);
1451 vcp = &VnodeClassInfo[class];
1453 /* Mark this vnode as in this dump - so we don't delete it later */
1455 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1456 if (class == vLarge) {
1457 if (Lbuf && (idx < s1))
1460 if (Sbuf && (idx < s2))
1466 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1468 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1469 afs_error_message(errno));
1470 V_needsSalvaged(vp) = 1;
1471 return VOLSERREAD_DUMPERROR;
1473 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1475 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1476 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1480 vnode->vnodeMagic = vcp->magic;
1481 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1482 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1483 afs_error_message(errno));
1484 FDH_REALLYCLOSE(fdP);
1485 V_needsSalvaged(vp) = 1;
1486 return VOLSERREAD_DUMPERROR;
1491 iod_ungetc(iodp, tag);
1497 /* called with disk file only. Note that we don't have to worry about rx_Read
1498 * needing to read an ungetc'd character, since the ReadInt32 will have read
1501 * if handleP == NULL, don't write the file anywhere; just read and discard
1505 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1510 afs_fsize_t filesize;
1511 afs_fsize_t written = 0;
1519 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1521 if (!ReadInt32(iodp, &filesize_high)) {
1526 if (!ReadInt32(iodp, &filesize_low)) {
1530 FillInt64(filesize, filesize_high, filesize_low);
1537 for (nbytes = filesize; nbytes; nbytes -= size) {
1541 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1542 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));
1547 nBytes = FDH_PWRITE(handleP, p, size, written);
1550 if (nBytes != size) {
1551 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1562 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1565 afs_uint32 beginMagic;
1566 afs_int32 critical = 0;
1567 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1568 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1569 || beginMagic != DUMPBEGINMAGIC)
1573 while ((tag = iod_getc(iodp)) > D_MAX) {
1574 unsigned short arrayLength;
1580 if (!ReadInt32(iodp, &hp->volumeId))
1584 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1587 if (!ReadShort(iodp, &arrayLength))
1589 hp->nDumpTimes = (arrayLength >> 1);
1590 for (i = 0; i < hp->nDumpTimes; i++)
1591 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1592 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1599 if (!HandleUnknownTag(iodp, tag, 0, critical))
1600 return VOLSERREAD_DUMPERROR;
1603 if (!hp->volumeId || !hp->nDumpTimes) {
1606 iod_ungetc(iodp, tag);
1611 /* ----- Below are the calls that calculate dump size ----- */
1614 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1615 struct volintSize *v_size)
1618 static char nullString[1] = ""; /*The ``contents'' of motd */
1621 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1622 FillInt64(addvar,0, 1);
1623 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1624 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1625 FillInt64(addvar,0, 5);
1626 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1627 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1628 FillInt64(addvar,0, 5);
1629 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1630 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1631 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1632 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1633 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1634 FillInt64(addvar,0, 2);
1635 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1636 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1637 FillInt64(addvar,0, 2);
1638 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1639 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1640 FillInt64(addvar,0, 5);
1641 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1642 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1643 FillInt64(addvar,0, 2);
1644 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1645 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1646 FillInt64(addvar,0, 5);
1647 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1648 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1649 FillInt64(addvar,0, 5);
1650 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1651 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1652 FillInt64(addvar,0, 5);
1653 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1654 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1655 FillInt64(addvar,0, 5);
1656 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1657 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1658 FillInt64(addvar,0, 5);
1659 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1660 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1661 FillInt64(addvar,0, 5);
1662 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1663 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1664 FillInt64(addvar,0, 5);
1665 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1666 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1667 FillInt64(addvar,0, 5);
1668 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1669 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1670 FillInt64(addvar,0, 5);
1671 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1672 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1673 FillInt64(addvar,0, 5);
1674 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1675 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1676 FillInt64(addvar,0, 5);
1677 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1678 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1679 FillInt64(addvar,0, 5);
1680 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1681 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1682 FillInt64(addvar,0, 5);
1683 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1684 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1685 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1686 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1688 /* * We do NOT dump the detailed volume statistics residing in the old */
1689 /* * motd field, since we cannot tell from the info in a dump whether */
1690 /* * statistics data has been put there. Instead, we dump a null string, */
1691 /* * just as if that was what the motd contained. */
1693 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1694 FillInt64(addvar,0, (2 + strlen(nullString)));
1695 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1696 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1697 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1698 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1699 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1700 FillInt64(addvar,0, 5);
1701 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1702 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1703 FillInt64(addvar,0, 5);
1704 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1709 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1713 FillInt64(addvar,0, 5);
1714 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1719 SizeDumpVolume(struct rx_call *call, Volume * vp,
1720 afs_int32 fromtime, int dumpAllDirs,
1721 struct volintSize *v_size)
1724 struct iod *iodp = (struct iod *)0;
1725 /* iod_Init(iodp, call); */
1728 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1730 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1732 code = SizeDumpEnd(iodp, v_size);
1738 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1739 afs_int32 fromtime, struct volintSize *v_size)
1742 /* int UseLatestReadOnlyClone = 1; */
1743 /* afs_int32 dumpTimes[2]; */
1745 /* iodp->device = vp->device; */
1746 /* iodp->parentId = V_parentId(vp); */
1747 /* iodp->dumpPartition = vp->partition; */
1749 ZeroInt64(v_size->dump_size); /* initialize the size */
1750 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1751 FillInt64(addvar,0, 9);
1752 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1753 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1754 FillInt64(addvar,0, 5);
1755 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1756 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1757 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1758 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1759 /* dumpTimes[0] = fromtime; */
1760 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1761 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1762 FillInt64(addvar,0, (3 + 4 * 2));
1763 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1768 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1769 int vnodeNumber, int dumpEverything,
1770 struct volintSize *v_size)
1775 if (!v || v->type == vNull)
1777 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1778 FillInt64(addvar,0, 9);
1779 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1780 if (!dumpEverything)
1782 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1783 FillInt64(addvar,0, 2);
1784 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1785 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1786 FillInt64(addvar,0, 3);
1787 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1788 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1789 FillInt64(addvar,0, 5);
1790 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1791 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1792 FillInt64(addvar,0, 5);
1793 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1794 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1795 FillInt64(addvar,0, 5);
1796 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1797 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1798 FillInt64(addvar,0, 5);
1799 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1800 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1802 FillInt64(addvar,0, 5);
1803 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1805 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1806 FillInt64(addvar,0, 3);
1807 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1808 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1809 FillInt64(addvar,0, 5);
1810 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1811 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1812 FillInt64(addvar,0, 5);
1813 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1814 if (v->type == vDirectory) {
1815 /* acl_HtonACL(VVnodeDiskACL(v)); */
1816 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1817 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1818 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1821 if (VNDISK_GET_INO(v)) {
1822 FillInt64(addvar,0, (v->length + 5));
1823 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1828 /* A partial dump (no dump header) */
1830 SizeDumpPartial(struct iod *iodp, Volume * vp,
1831 afs_int32 fromtime, int dumpAllDirs,
1832 struct volintSize *v_size)
1836 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1839 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1842 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1847 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1848 afs_int32 fromtime, int forcedump,
1849 struct volintSize *v_size)
1852 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1853 char buf[SIZEOF_LARGEDISKVNODE];
1854 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1855 StreamHandle_t *file;
1857 afs_sfsize_t size, nVnodes;
1861 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1862 opr_Assert(fdP != NULL);
1863 file = FDH_FDOPEN(fdP, "r+");
1864 opr_Assert(file != NULL);
1865 size = OS_SIZE(fdP->fd_fd);
1866 opr_Assert(size != -1);
1867 nVnodes = (size / vcp->diskSize) - 1;
1869 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
1870 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1873 for (vnodeIndex = 0;
1874 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1875 nVnodes--, vnodeIndex++) {
1876 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1877 /* Note: the >= test is very important since some old volumes may not have
1878 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1879 * does dump the file! */
1882 SizeDumpVnode(iodp, vnode, V_id(vp),
1883 bitNumberToVnodeNumber(vnodeIndex, class), flag,