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 /* The TLV range must start above D_MAX */
91 #define MIN_TLV_TAG 21
92 #define MAX_TLV_TAG 0x60
93 #define MAX_STANDARD_TAG 0x7a
94 static afs_uint32 oldtags[MAX_SECTIONS][16];
95 int oldtagsInited = 0;
98 RegisterTag(afs_int32 section, unsigned char tag)
100 afs_uint32 off = tag >> 5;
101 afs_uint32 mask = 1 << (tag & 0x1f);
102 oldtags[section][off] |= mask;
106 initNonStandardTags(void)
108 RegisterTag(0, 'n'); /* volume name */
109 RegisterTag(0, 't'); /* fromtime, V_backupDate */
110 RegisterTag(1, 'A'); /* V_accessDate */
111 RegisterTag(1, 'C'); /* V_creationDate */
112 RegisterTag(1, 'D'); /* V_dayUseDate */
113 RegisterTag(1, 'E'); /* V_expirationDate */
114 RegisterTag(1, 'M'); /* nullstring (motd) */
115 RegisterTag(1, 'U'); /* V_updateDate */
116 RegisterTag(1, 'W'); /* V_weekUse */
117 RegisterTag(1, 'Z'); /* V_dayUse */
118 RegisterTag(1, 'O'); /* V_offlineMessage */
119 RegisterTag(1, 'b'); /* V_blessed */
120 RegisterTag(1, 'n'); /* V_name */
121 RegisterTag(1, 's'); /* V_inService */
122 RegisterTag(1, 't'); /* V_type */
123 RegisterTag(2, 'A'); /* VVnodeDiskACL */
124 RegisterTag(2, 'b'); /* modeBits */
125 RegisterTag(2, 'f'); /* small file */
126 RegisterTag(2, 'h'); /* large file */
127 RegisterTag(2, 'l'); /* linkcount */
128 RegisterTag(2, 't'); /* type */
133 iod_Init(struct iod *iodp, struct rx_call *call)
136 iodp->haveOldChar = 0;
138 iodp->calls = (struct rx_call **)0;
142 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
147 iodp->haveOldChar = 0;
148 iodp->ncalls = ncalls;
150 iodp->call = (struct rx_call *)0;
153 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
154 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
156 /* For the single dump case, it's ok to just return the "bytes written"
157 * that rx_Write returns, since all the callers of iod_Write abort when
158 * the returned value is less than they expect. For the multi dump case,
159 * I don't think we want half the replicas to go bad just because one
160 * connection timed out, but if they all time out, then we should give up.
163 iod_Write(struct iod *iodp, char *buf, int nbytes)
168 opr_Assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
169 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
172 code = rx_Write(iodp->call, buf, nbytes);
176 for (i = 0; i < iodp->ncalls; i++) {
177 if (iodp->calls[i] && !iodp->codes[i]) {
178 code = rx_Write(iodp->calls[i], buf, nbytes);
179 if (code != nbytes) { /* everything gets merged into a single error */
180 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
181 } /* standard dump does, anyways */
186 } /* for all calls */
195 iod_ungetc(struct iod *iodp, int achar)
197 iodp->oldChar = achar;
198 iodp->haveOldChar = 1;
202 iod_getc(struct iod *iodp)
206 if (iodp->haveOldChar) {
207 iodp->haveOldChar = 0;
208 return iodp->oldChar;
210 if (iod_Read(iodp, (char *) &t, 1) == 1)
216 ReadShort(struct iod *iodp, unsigned short *sp)
225 *sp = (b1 << 8) | b0;
230 ReadInt32(struct iod *iodp, afs_uint32 * lp)
232 afs_uint32 b3, b2, b1, b0;
245 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
250 ReadString(struct iod *iodp, char *to, int maxa)
259 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
263 while ((c = iod_getc(iodp)) && c != EOF);
269 ReadByteString(struct iod *iodp, byte * to,
273 *to++ = iod_getc(iodp);
277 * returns 1 on success and 0 otherwise
280 ReadStandardTagLen(struct iod *iodp, unsigned char tag, afs_int32 section,
284 afs_uint32 off = tag >> 5;
285 afs_uint32 mask = 1 << (tag & 0x1f);
287 unsigned char buf[8], *p;
290 initNonStandardTags();
292 if (tag < MIN_TLV_TAG
293 || tag > MAX_STANDARD_TAG
294 || section >= MAX_SECTIONS
295 || (oldtags[section][ off] & mask)) {
296 Log("Trying to use ReadStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
299 if (tag <= MAX_TLV_TAG) {
300 len = iod_getc(iodp);
302 return VOLSERDUMPERROR;
307 if ((code = iod_Read(iodp, (char *)buf, len)) != len)
308 return VOLSERDUMPERROR;
310 p = (unsigned char *)&buf;
311 for (i=0; i<len; i++) {
312 *length = ((*length) << 8) | *p++;
316 if (tag < MAX_STANDARD_TAG)
322 static char skipbuf[256];
325 SkipData(struct iod *iodp, afs_size_t length)
327 while (length > 256) {
328 if (iod_Read(iodp, (char *)&skipbuf, 256) != 256)
332 if (iod_Read(iodp, (char *)&skipbuf, length) != length)
337 static char *secname[3] = {"ReadDumpHeader", "ReadVolumeHeader", "ReadVnodes"};
340 HandleUnknownTag(struct iod *iodp, int tag, afs_int32 section,
343 afs_size_t taglen = 0;
347 Log("%s: unknown critical tag x%02x, aborting\n",
348 secname[section], tag);
351 Log("%s: unknown tag x%02x found, skipping\n", secname[section], tag);
352 if (tag >= 0x06 && tag <= 0x60) {
353 if (!ReadStandardTagLen(iodp, tag, 1, &taglen)) {
354 Log("%s: error reading length field for tag x%02x, aborting\n",
355 secname[section], tag);
358 if (!SkipData(iodp, taglen)) {
359 Log("%s: error skipping %llu bytes for tag x%02x, aborting\n",
360 secname[section], taglen, tag);
365 if (tag >= 0x61 && tag <= 0x7a) {
366 if (!ReadInt32(iodp, &trash)) {
367 Log("%s: error skipping int32 for tag x%02x, aborting\n",
368 secname[section], tag);
373 if (tag >= 0x7b && tag < 0x80) /* dataless tag */
375 Log("%s: unknown invalid tag x%02x, aborting\n", secname[section], tag);
380 ReadVolumeHeader(struct iod *iodp, VolumeDiskData * vol)
384 afs_int32 critical = 0;
385 memset(vol, 0, sizeof(*vol));
386 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
391 if (!ReadInt32(iodp, &vol->id))
392 return VOLSERREAD_DUMPERROR;
395 if (!ReadInt32(iodp, &trash))
396 return VOLSERREAD_DUMPERROR;
399 ReadString(iodp, vol->name, sizeof(vol->name));
400 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
403 vol->inService = iod_getc(iodp);
406 vol->blessed = iod_getc(iodp);
409 if (!ReadInt32(iodp, &vol->uniquifier))
410 return VOLSERREAD_DUMPERROR;
413 vol->type = iod_getc(iodp);
416 if (!ReadInt32(iodp, &vol->parentId))
417 return VOLSERREAD_DUMPERROR;
420 if (!ReadInt32(iodp, &vol->cloneId))
421 return VOLSERREAD_DUMPERROR;
424 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
425 return VOLSERREAD_DUMPERROR;
428 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
429 return VOLSERREAD_DUMPERROR;
432 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
433 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
436 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
437 return VOLSERREAD_DUMPERROR;
440 if (!ReadInt32(iodp, &vol->accountNumber))
441 return VOLSERREAD_DUMPERROR;
444 if (!ReadInt32(iodp, &vol->owner))
445 return VOLSERREAD_DUMPERROR;
448 if (!ReadInt32(iodp, &vol->creationDate))
449 return VOLSERREAD_DUMPERROR;
452 if (!ReadInt32(iodp, &vol->accessDate))
453 return VOLSERREAD_DUMPERROR;
456 if (!ReadInt32(iodp, &vol->updateDate))
457 return VOLSERREAD_DUMPERROR;
460 if (!ReadInt32(iodp, &vol->expirationDate))
461 return VOLSERREAD_DUMPERROR;
464 if (!ReadInt32(iodp, &vol->backupDate))
465 return VOLSERREAD_DUMPERROR;
468 ReadString(iodp, vol->offlineMessage,
469 sizeof(vol->offlineMessage));
473 * Detailed volume statistics are never stored in dumps,
474 * so we just restore either the null string if this volume
475 * had already been set to store statistics, or the old motd
476 * contents otherwise. It doesn't matter, since this field
477 * will soon get initialized anyway.
479 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
482 unsigned short length;
485 if (!ReadShort(iodp, &length))
486 return VOLSERREAD_DUMPERROR;
487 for (i = 0; i < length; i++) {
488 if (!ReadInt32(iodp, &data))
489 return VOLSERREAD_DUMPERROR;
490 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
491 vol->weekUse[i] = data;
496 if (!ReadInt32(iodp, &vol->dayUseDate))
497 return VOLSERREAD_DUMPERROR;
500 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
501 return VOLSERREAD_DUMPERROR;
504 if (!ReadInt32(iodp, (afs_uint32 *) &trash/*volUpdateCounter*/))
505 return VOLSERREAD_DUMPERROR;
511 if (!HandleUnknownTag(iodp, tag, 1, critical))
512 return VOLSERREAD_DUMPERROR;
515 iod_ungetc(iodp, tag);
520 DumpTag(struct iod *iodp, int tag)
525 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
530 DumpByte(struct iod *iodp, char tag, byte value)
533 byte *p = (unsigned char *)tbuffer;
536 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
539 #define afs_putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
540 #define afs_putshort(p, v) *p++ = v>>8, *p++ = v
543 DumpDouble(struct iod *iodp, char tag, afs_uint32 value1,
547 byte *p = (unsigned char *)tbuffer;
549 afs_putint32(p, value1);
550 afs_putint32(p, value2);
551 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
555 DumpInt32(struct iod *iodp, char tag, afs_uint32 value)
558 byte *p = (unsigned char *)tbuffer;
560 afs_putint32(p, value);
561 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
565 DumpArrayInt32(struct iod *iodp, char tag,
566 afs_uint32 * array, int nelem)
571 byte *p = (unsigned char *)tbuffer;
573 afs_putshort(p, nelem);
574 code = iod_Write(iodp, tbuffer, 3);
576 return VOLSERDUMPERROR;
578 p = (unsigned char *)tbuffer;
579 v = *array++; /*this was register */
582 code = iod_Write(iodp, tbuffer, 4);
584 return VOLSERDUMPERROR;
590 DumpShort(struct iod *iodp, char tag, unsigned int value)
593 byte *p = (unsigned char *)tbuffer;
597 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
601 DumpBool(struct iod *iodp, char tag, unsigned int value)
604 byte *p = (unsigned char *)tbuffer;
607 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
611 DumpString(struct iod *iodp, char tag, char *s)
615 code = iod_Write(iodp, &tag, 1);
617 return VOLSERDUMPERROR;
619 code = iod_Write(iodp, s, n);
621 return VOLSERDUMPERROR;
626 DumpByteString(struct iod *iodp, char tag, byte * bs,
631 code = iod_Write(iodp, &tag, 1);
633 return VOLSERDUMPERROR;
634 code = iod_Write(iodp, (char *)bs, nbytes);
636 return VOLSERDUMPERROR;
641 DumpStandardTag(struct iod *iodp, char tag, afs_uint32 section)
644 afs_uint32 off = tag >> 5;
645 afs_uint32 mask = 1 << (tag & 0x1f);
648 initNonStandardTags();
650 if (tag < MIN_TLV_TAG
651 || tag > MAX_STANDARD_TAG
652 || section >= MAX_SECTIONS
653 || (oldtags[section][ off] & mask)) {
654 Log("Trying to use DumpStandardTag with tag 0x%02x for section %d, aborting\n", tag, section);
655 return VOLSERDUMPERROR;
657 code = iod_Write(iodp, &tag, 1);
659 return VOLSERDUMPERROR;
665 DumpStandardTagLen(struct iod *iodp, char tag, afs_uint32 section,
672 if (tag < MIN_TLV_TAG || tag > MAX_TLV_TAG) {
673 Log("Trying to use DumpStandardTagLen with tag 0x%02x for section %d, aborting\n", tag, section);
674 return VOLSERDUMPERROR;
676 code = DumpStandardTag(iodp, tag, section);
680 if (length < 128) { /* byte after tag contains length */
683 } else { /* byte after tag contains length of length field | 0x80 */
684 for (len=0; length; length=length >> 8) {
692 code = iod_Write(iodp, p, len);
694 return VOLSERDUMPERROR;
699 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
701 int code = 0, error = 0;
703 afs_foff_t offset = 0;
704 afs_sfsize_t nbytes, howBig;
707 afs_foff_t howFar = 0;
712 struct afs_stat status;
714 LARGE_INTEGER fileSize;
717 #include <sys/statfs.h>
718 #if defined(AFS_AIX52_ENV)
719 struct statfs64 tstatfs;
720 #else /* !AFS_AIX52_ENV */
721 struct statfs tstatfs;
722 #endif /* !AFS_AIX52_ENV */
727 if (!GetFileSizeEx(handleP->fd_fd, &fileSize)) {
728 Log("DumpFile: GetFileSizeEx returned error code %d on descriptor %d\n", GetLastError(), handleP->fd_fd);
729 return VOLSERDUMPERROR;
731 howBig = fileSize.QuadPart;
735 afs_fstat(handleP->fd_fd, &status);
736 howBig = status.st_size;
739 /* Unfortunately in AIX valuable fields such as st_blksize are
740 * gone from the stat structure.
742 #if defined(AFS_AIX52_ENV)
743 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
744 #else /* !AFS_AIX52_ENV */
745 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
746 #endif /* !AFS_AIX52_ENV */
747 if (statfs_code != 0) {
748 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
749 return VOLSERDUMPERROR;
751 howMany = tstatfs.f_bsize;
753 howMany = status.st_blksize;
754 #endif /* AFS_AIX_ENV */
755 #endif /* AFS_NT40_ENV */
758 SplitInt64(howBig, hi, lo);
760 code = DumpInt32(iodp, 'f', lo);
762 code = DumpDouble(iodp, 'h', hi, lo);
765 return VOLSERDUMPERROR;
770 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", (unsigned)howMany);
771 return VOLSERDUMPERROR;
774 for (nbytes = howBig; (nbytes && !error); nbytes -= howMany) {
775 if (nbytes < howMany)
779 n = FDH_PREAD(handleP, p, howMany, howFar);
782 /* If read any good data and we null padded previously, log the
783 * amount that we had null padded.
785 if ((n > 0) && pad) {
786 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %lld\n", pad, (long long)offset);
790 /* If didn't read enough data, null padd the rest of the buffer. This
791 * can happen if, for instance, the media has some bad spots. We don't
792 * want to quit the dump, so we start null padding.
795 /* Record the read error */
798 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d: %s\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode, afs_error_message(errno));
800 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(stmp, handleP->fd_ih->ih_ino), vnode);
803 /* Pad the rest of the buffer with zeros. Remember offset we started
804 * padding. Keep total tally of padding.
806 memset(p + n, 0, howMany - n);
808 offset = (howBig - nbytes) + n;
809 pad += (howMany - n);
811 /* Now seek over the data we could not get. An error here means we
812 * can't do the next read.
814 howFar = (size_t)((howBig - nbytes) + howMany);
817 /* Now write the data out */
818 if (iod_Write(iodp, (char *)p, howMany) != howMany)
819 error = VOLSERDUMPERROR;
820 #ifndef AFS_PTHREAD_ENV
825 if (pad) { /* Any padding we hadn't reported yet */
826 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %lld\n",
827 pad, (long long)offset);
835 DumpVolumeHeader(struct iod *iodp, Volume * vp)
838 static char nullString[1] = ""; /*The ``contents'' of motd */
841 code = DumpTag(iodp, D_VOLUMEHEADER);
843 code = DumpInt32(iodp, 'i', V_id(vp));
846 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
848 code = DumpString(iodp, 'n', V_name(vp));
850 code = DumpBool(iodp, 's', V_inService(vp));
852 code = DumpBool(iodp, 'b', V_blessed(vp));
854 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
856 code = DumpByte(iodp, 't', (byte) V_type(vp));
858 code = DumpInt32(iodp, 'p', V_parentId(vp));
861 code = DumpInt32(iodp, 'c', V_cloneId(vp));
863 code = DumpInt32(iodp, 'q', V_maxquota(vp));
865 code = DumpInt32(iodp, 'm', V_minquota(vp));
867 code = DumpInt32(iodp, 'd', V_diskused(vp));
869 code = DumpInt32(iodp, 'f', V_filecount(vp));
871 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
873 code = DumpInt32(iodp, 'o', V_owner(vp));
875 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
877 code = DumpInt32(iodp, 'A', V_accessDate(vp));
879 code = DumpInt32(iodp, 'U', V_updateDate(vp));
881 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
883 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
885 code = DumpString(iodp, 'O', V_offlineMessage(vp));
887 * We do NOT dump the detailed volume statistics residing in the old
888 * motd field, since we cannot tell from the info in a dump whether
889 * statistics data has been put there. Instead, we dump a null string,
890 * just as if that was what the motd contained.
893 code = DumpString(iodp, 'M', nullString);
896 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
897 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
899 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
901 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
906 DumpEnd(struct iod *iodp)
908 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
911 /* Guts of the dump code */
913 /* Dump a whole volume */
915 DumpVolume(struct rx_call *call, Volume * vp,
916 afs_int32 fromtime, int dumpAllDirs)
920 struct iod *iodp = &iod;
921 iod_Init(iodp, call);
924 code = DumpDumpHeader(iodp, vp, fromtime);
927 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
929 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
930 if (rx_Error(iodp->call)) {
931 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
932 rx_Error(iodp->call));
933 return VOLSERDUMPERROR;
936 code = DumpEnd(iodp);
941 /* Dump a volume to multiple places*/
943 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
944 afs_int32 fromtime, int dumpAllDirs, int *codes)
948 iod_InitMulti(&iod, calls, ncalls, codes);
951 code = DumpDumpHeader(&iod, vp, fromtime);
953 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
955 code = DumpEnd(&iod);
959 /* A partial dump (no dump header) */
961 DumpPartial(struct iod *iodp, Volume * vp,
962 afs_int32 fromtime, int dumpAllDirs)
966 code = DumpVolumeHeader(iodp, vp);
968 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
970 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
975 DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
976 afs_int32 fromtime, int forcedump)
979 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
980 char buf[SIZEOF_LARGEDISKVNODE];
981 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
982 StreamHandle_t *file;
984 afs_sfsize_t size, nVnodes;
988 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
989 opr_Assert(fdP != NULL);
990 file = FDH_FDOPEN(fdP, "r+");
991 opr_Assert(file != NULL);
992 size = OS_SIZE(fdP->fd_fd);
993 opr_Assert(size != -1);
994 nVnodes = (size / vcp->diskSize) - 1;
996 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
997 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1000 for (vnodeIndex = 0;
1001 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1002 nVnodes--, vnodeIndex++) {
1003 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1004 /* Note: the >= test is very important since some old volumes may not have
1005 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1006 * does dump the file! */
1009 DumpVnode(iodp, vnode, V_id(vp),
1010 bitNumberToVnodeNumber(vnodeIndex, class), flag);
1011 #ifndef AFS_PTHREAD_ENV
1013 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
1022 DumpDumpHeader(struct iod *iodp, Volume * vp,
1026 int UseLatestReadOnlyClone = 1;
1027 afs_int32 dumpTimes[2];
1028 iodp->device = vp->device;
1029 iodp->parentId = V_parentId(vp);
1030 iodp->dumpPartition = vp->partition;
1032 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
1035 DumpInt32(iodp, 'v',
1036 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
1038 code = DumpString(iodp, 'n', V_name(vp));
1039 dumpTimes[0] = fromtime;
1040 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
1042 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
1047 DumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1048 int vnodeNumber, int dumpEverything)
1054 if (!v || v->type == vNull)
1057 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
1058 if (!dumpEverything)
1061 code = DumpByte(iodp, 't', (byte) v->type);
1063 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
1065 code = DumpInt32(iodp, 'v', v->dataVersion);
1067 code = DumpInt32(iodp, 'm', v->unixModifyTime);
1069 code = DumpInt32(iodp, 'a', v->author);
1071 code = DumpInt32(iodp, 'o', v->owner);
1072 if (!code && v->group)
1073 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
1075 code = DumpShort(iodp, 'b', v->modeBits);
1077 code = DumpInt32(iodp, 'p', v->parent);
1079 code = DumpInt32(iodp, 's', v->serverModifyTime);
1080 if (v->type == vDirectory) {
1081 acl_HtonACL(VVnodeDiskACL(v));
1084 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
1087 if (VNDISK_GET_INO(v)) {
1088 afs_sfsize_t indexlen, disklen;
1089 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
1092 Log("1 Volser: DumpVnode: dump: Unable to open inode %llu for vnode %u (volume %i); not dumped, error %d\n", (afs_uintmax_t) VNDISK_GET_INO(v), vnodeNumber, volid, errno);
1094 return VOLSERREAD_DUMPERROR;
1096 VNDISK_GET_LEN(indexlen, v);
1097 disklen = FDH_SIZE(fdP);
1098 if (indexlen != disklen) {
1099 FDH_REALLYCLOSE(fdP);
1101 Log("DumpVnode: volume %lu vnode %lu has inconsistent length "
1102 "(index %lu disk %lu); aborting dump\n",
1103 (unsigned long)volid, (unsigned long)vnodeNumber,
1104 (unsigned long)indexlen, (unsigned long)disklen);
1105 return VOLSERREAD_DUMPERROR;
1107 code = DumpFile(iodp, vnodeNumber, fdP);
1116 ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep,
1119 int i, nVnodes, code;
1124 StreamHandle_t *afile;
1126 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1127 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
1128 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1130 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
1131 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1134 afile = FDH_FDOPEN(fdP, "r+");
1138 for (i = 0; i < *sizep; i++) {
1141 STREAM_ASEEK(afile, Buf[i]);
1142 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1144 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1147 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
1148 V_id(vp), bitNumberToVnodeNumber(i, class),
1149 (afs_uintmax_t) VNDISK_GET_INO(vnode));
1151 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
1155 STREAM_ASEEK(afile, Buf[i]);
1156 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
1162 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
1165 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
1166 OS_SYNC(afile->str_fd);
1168 size = OS_SIZE(fdP->fd_fd);
1169 opr_Assert(size != -1);
1172 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
1174 Buf = calloc(nVnodes, sizeof(afs_foff_t));
1176 STREAM_CLOSE(afile);
1180 STREAM_ASEEK(afile, offset = vcp->diskSize);
1182 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1186 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1187 Buf[(offset >> vcp->logSize) - 1] = offset;
1190 offset += vcp->diskSize;
1196 STREAM_CLOSE(afile);
1203 RestoreVolume(struct rx_call *call, Volume * avp, int incremental,
1204 struct restoreCookie *cookie)
1207 struct DumpHeader header;
1208 afs_uint32 endMagic;
1209 Error error = 0, vupdate;
1212 struct iod *iodp = &iod;
1213 afs_foff_t *b1 = NULL, *b2 = NULL;
1214 int s1 = 0, s2 = 0, delo = 0, tdelo;
1216 VolumeDiskData saved_header;
1218 iod_Init(iodp, call);
1222 if (DoPreserveVolumeStats) {
1223 CopyVolumeStats(&V_disk(vp), &saved_header);
1226 if (!ReadDumpHeader(iodp, &header)) {
1227 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1228 return VOLSERREAD_DUMPERROR;
1230 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1231 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1232 return VOLSERREAD_DUMPERROR;
1234 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1235 return VOLSERREAD_DUMPERROR;
1238 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1240 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1242 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1243 error = VOLSERREAD_DUMPERROR;
1247 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1248 vol.type = cookie->type;
1249 vol.cloneId = cookie->clone;
1250 vol.parentId = cookie->parent;
1252 V_needsSalvaged(vp) = 0;
1256 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1257 error = VOLSERREAD_DUMPERROR;
1260 tag = iod_getc(iodp);
1261 if (tag != D_VOLUMEHEADER)
1264 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1265 error = VOLSERREAD_DUMPERROR;
1269 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1270 || endMagic != DUMPENDMAGIC) {
1271 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1272 error = VOLSERREAD_DUMPERROR;
1277 if (iod_getc(iodp) != EOF) {
1278 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1279 error = VOLSERREAD_DUMPERROR;
1284 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1286 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1288 error = VOLSERREAD_DUMPERROR;
1294 if (DoPreserveVolumeStats) {
1295 CopyVolumeStats(&saved_header, &vol);
1297 ClearVolumeStats(&vol);
1299 if (V_needsSalvaged(vp)) {
1300 /* needsSalvaged may have been set while we tried to write volume data.
1301 * prevent it from getting overwritten. */
1302 vol.needsSalvaged = V_needsSalvaged(vp);
1304 CopyVolumeHeader(&vol, &V_disk(vp));
1305 V_destroyMe(vp) = 0;
1306 VUpdateVolume(&vupdate, vp);
1308 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1309 error = VOLSERREAD_DUMPERROR;
1313 /* Free the malloced space above */
1322 ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
1323 afs_foff_t * Lbuf, afs_int32 s1, afs_foff_t * Sbuf, afs_int32 s2,
1326 afs_int32 vnodeNumber;
1327 char buf[SIZEOF_LARGEDISKVNODE];
1329 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1330 struct VnodeDiskObject oldvnode;
1333 struct VnodeClassInfo *vcp;
1336 Inode nearInode AFS_UNUSED;
1337 afs_int32 critical = 0;
1339 tag = iod_getc(iodp);
1340 V_pref(vp, nearInode);
1341 while (tag == D_VNODE) {
1344 memset(buf, 0, sizeof(buf));
1345 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1348 if (!ReadInt32(iodp, &vnode->uniquifier))
1349 return VOLSERREAD_DUMPERROR;
1351 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1357 vnode->type = (VnodeType) iod_getc(iodp);
1362 if (!ReadShort(iodp, &tlc))
1363 return VOLSERREAD_DUMPERROR;
1364 vnode->linkCount = (signed int)tlc;
1368 if (!ReadInt32(iodp, &vnode->dataVersion))
1369 return VOLSERREAD_DUMPERROR;
1372 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1373 return VOLSERREAD_DUMPERROR;
1376 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1377 return VOLSERREAD_DUMPERROR;
1380 if (!ReadInt32(iodp, &vnode->author))
1381 return VOLSERREAD_DUMPERROR;
1384 if (!ReadInt32(iodp, &vnode->owner))
1385 return VOLSERREAD_DUMPERROR;
1388 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1389 return VOLSERREAD_DUMPERROR;
1392 unsigned short modeBits;
1393 if (!ReadShort(iodp, &modeBits))
1394 return VOLSERREAD_DUMPERROR;
1395 vnode->modeBits = (unsigned int)modeBits;
1399 if (!ReadInt32(iodp, &vnode->parent))
1400 return VOLSERREAD_DUMPERROR;
1403 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1404 VAclDiskSize(vnode));
1405 acl_NtohACL(VVnodeDiskACL(vnode));
1411 afs_fsize_t vnodeLength;
1414 Log("Volser: ReadVnodes: warning: ignoring duplicate "
1415 "file entries for vnode %lu in dump\n",
1416 (unsigned long)vnodeNumber);
1417 volser_WriteFile(vnodeNumber, iodp, NULL, tag, &error);
1423 IH_CREATE_INIT(V_linkHandle(vp), V_device(vp),
1424 VPartitionPath(V_partition(vp)), nearInode,
1425 V_parentId(vp), vnodeNumber,
1426 vnode->uniquifier, vnode->dataVersion);
1428 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1429 afs_error_message(errno));
1430 V_needsSalvaged(vp) = 1;
1431 return VOLSERREAD_DUMPERROR;
1435 VNDISK_SET_INO(vnode, ino);
1436 fdP = IH_OPEN(tmpH);
1438 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1439 afs_error_message(errno));
1441 V_needsSalvaged(vp) = 1;
1442 return VOLSERREAD_DUMPERROR;
1445 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1446 VNDISK_SET_LEN(vnode, vnodeLength);
1447 FDH_REALLYCLOSE(fdP);
1450 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1451 (afs_uintmax_t) ino);
1452 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1453 V_needsSalvaged(vp) = 1;
1454 return VOLSERREAD_DUMPERROR;
1462 if (!HandleUnknownTag(iodp, tag, 2, critical))
1463 return VOLSERREAD_DUMPERROR;
1467 class = vnodeIdToClass(vnodeNumber);
1468 vcp = &VnodeClassInfo[class];
1470 /* Mark this vnode as in this dump - so we don't delete it later */
1472 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1473 if (class == vLarge) {
1474 if (Lbuf && (idx < s1))
1477 if (Sbuf && (idx < s2))
1483 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1485 Log("1 Volser: ReadVnodes: Error opening vnode index: %s; restore aborted\n",
1486 afs_error_message(errno));
1487 V_needsSalvaged(vp) = 1;
1488 return VOLSERREAD_DUMPERROR;
1490 if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) ==
1492 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1493 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1497 vnode->vnodeMagic = vcp->magic;
1498 if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) {
1499 Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n",
1500 afs_error_message(errno));
1501 FDH_REALLYCLOSE(fdP);
1502 V_needsSalvaged(vp) = 1;
1503 return VOLSERREAD_DUMPERROR;
1508 iod_ungetc(iodp, tag);
1514 /* called with disk file only. Note that we don't have to worry about rx_Read
1515 * needing to read an ungetc'd character, since the ReadInt32 will have read
1518 * if handleP == NULL, don't write the file anywhere; just read and discard
1522 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1527 afs_fsize_t filesize;
1528 afs_fsize_t written = 0;
1536 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1538 if (!ReadInt32(iodp, &filesize_high)) {
1543 if (!ReadInt32(iodp, &filesize_low)) {
1547 FillInt64(filesize, filesize_high, filesize_low);
1554 for (nbytes = filesize; nbytes; nbytes -= size) {
1558 if ((code = iod_Read(iodp, (char *) p, size)) != size) {
1559 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));
1564 nBytes = FDH_PWRITE(handleP, p, size, written);
1567 if (nBytes != size) {
1568 Log("1 Volser: WriteFile: Error writing (%u) bytes to vnode %d; %s; restore aborted\n", (int)(nBytes & 0xffffffff), vn, afs_error_message(errno));
1579 ReadDumpHeader(struct iod *iodp, struct DumpHeader *hp)
1582 afs_uint32 beginMagic;
1583 afs_int32 critical = 0;
1584 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1585 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1586 || beginMagic != DUMPBEGINMAGIC)
1590 while ((tag = iod_getc(iodp)) > D_MAX) {
1591 unsigned short arrayLength;
1597 if (!ReadInt32(iodp, &hp->volumeId))
1601 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1604 if (!ReadShort(iodp, &arrayLength))
1606 hp->nDumpTimes = (arrayLength >> 1);
1607 for (i = 0; i < hp->nDumpTimes; i++)
1608 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1609 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1616 if (!HandleUnknownTag(iodp, tag, 0, critical))
1617 return VOLSERREAD_DUMPERROR;
1620 if (!hp->volumeId || !hp->nDumpTimes) {
1623 iod_ungetc(iodp, tag);
1628 /* ----- Below are the calls that calculate dump size ----- */
1631 SizeDumpVolumeHeader(struct iod *iodp, Volume * vp,
1632 struct volintSize *v_size)
1635 static char nullString[1] = ""; /*The ``contents'' of motd */
1638 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1639 FillInt64(addvar,0, 1);
1640 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1641 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1642 FillInt64(addvar,0, 5);
1643 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1644 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1645 FillInt64(addvar,0, 5);
1646 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1647 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1648 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1649 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1650 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1651 FillInt64(addvar,0, 2);
1652 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1653 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1654 FillInt64(addvar,0, 2);
1655 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1656 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1657 FillInt64(addvar,0, 5);
1658 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1659 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1660 FillInt64(addvar,0, 2);
1661 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1662 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1663 FillInt64(addvar,0, 5);
1664 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1665 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1666 FillInt64(addvar,0, 5);
1667 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1668 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1669 FillInt64(addvar,0, 5);
1670 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1671 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1672 FillInt64(addvar,0, 5);
1673 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1674 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1675 FillInt64(addvar,0, 5);
1676 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1677 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1678 FillInt64(addvar,0, 5);
1679 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1680 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1681 FillInt64(addvar,0, 5);
1682 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1683 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1684 FillInt64(addvar,0, 5);
1685 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1686 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1687 FillInt64(addvar,0, 5);
1688 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1689 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1690 FillInt64(addvar,0, 5);
1691 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1692 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1693 FillInt64(addvar,0, 5);
1694 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1695 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1696 FillInt64(addvar,0, 5);
1697 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1698 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1699 FillInt64(addvar,0, 5);
1700 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1701 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1702 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1703 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1705 /* * We do NOT dump the detailed volume statistics residing in the old */
1706 /* * motd field, since we cannot tell from the info in a dump whether */
1707 /* * statistics data has been put there. Instead, we dump a null string, */
1708 /* * just as if that was what the motd contained. */
1710 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1711 FillInt64(addvar,0, (2 + strlen(nullString)));
1712 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1713 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1714 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1715 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1716 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1717 FillInt64(addvar,0, 5);
1718 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1719 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1720 FillInt64(addvar,0, 5);
1721 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1726 SizeDumpEnd(struct iod *iodp, struct volintSize *v_size)
1730 FillInt64(addvar,0, 5);
1731 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1736 SizeDumpVolume(struct rx_call *call, Volume * vp,
1737 afs_int32 fromtime, int dumpAllDirs,
1738 struct volintSize *v_size)
1741 struct iod *iodp = (struct iod *)0;
1742 /* iod_Init(iodp, call); */
1745 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1747 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1749 code = SizeDumpEnd(iodp, v_size);
1755 SizeDumpDumpHeader(struct iod *iodp, Volume * vp,
1756 afs_int32 fromtime, struct volintSize *v_size)
1759 /* int UseLatestReadOnlyClone = 1; */
1760 /* afs_int32 dumpTimes[2]; */
1762 /* iodp->device = vp->device; */
1763 /* iodp->parentId = V_parentId(vp); */
1764 /* iodp->dumpPartition = vp->partition; */
1766 ZeroInt64(v_size->dump_size); /* initialize the size */
1767 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1768 FillInt64(addvar,0, 9);
1769 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1770 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1771 FillInt64(addvar,0, 5);
1772 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1773 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1774 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1775 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1776 /* dumpTimes[0] = fromtime; */
1777 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1778 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1779 FillInt64(addvar,0, (3 + 4 * 2));
1780 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1785 SizeDumpVnode(struct iod *iodp, struct VnodeDiskObject *v, int volid,
1786 int vnodeNumber, int dumpEverything,
1787 struct volintSize *v_size)
1792 if (!v || v->type == vNull)
1794 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1795 FillInt64(addvar,0, 9);
1796 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1797 if (!dumpEverything)
1799 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1800 FillInt64(addvar,0, 2);
1801 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1802 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1803 FillInt64(addvar,0, 3);
1804 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1805 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1806 FillInt64(addvar,0, 5);
1807 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1808 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1809 FillInt64(addvar,0, 5);
1810 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1811 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1812 FillInt64(addvar,0, 5);
1813 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1814 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1815 FillInt64(addvar,0, 5);
1816 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1817 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1819 FillInt64(addvar,0, 5);
1820 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1822 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1823 FillInt64(addvar,0, 3);
1824 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1825 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1826 FillInt64(addvar,0, 5);
1827 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1828 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1829 FillInt64(addvar,0, 5);
1830 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1831 if (v->type == vDirectory) {
1832 /* acl_HtonACL(VVnodeDiskACL(v)); */
1833 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1834 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1835 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1838 if (VNDISK_GET_INO(v)) {
1839 VNDISK_GET_LEN(addvar, v);
1840 if (v->vn_length_hi)
1844 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1849 /* A partial dump (no dump header) */
1851 SizeDumpPartial(struct iod *iodp, Volume * vp,
1852 afs_int32 fromtime, int dumpAllDirs,
1853 struct volintSize *v_size)
1857 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1860 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1863 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1868 SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class,
1869 afs_int32 fromtime, int forcedump,
1870 struct volintSize *v_size)
1873 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1874 char buf[SIZEOF_LARGEDISKVNODE];
1875 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1876 StreamHandle_t *file;
1878 afs_sfsize_t size, nVnodes;
1882 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1883 opr_Assert(fdP != NULL);
1884 file = FDH_FDOPEN(fdP, "r+");
1885 opr_Assert(file != NULL);
1886 size = OS_SIZE(fdP->fd_fd);
1887 opr_Assert(size != -1);
1888 nVnodes = (size / vcp->diskSize) - 1;
1890 opr_Assert((nVnodes + 1) * vcp->diskSize == size);
1891 opr_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0);
1894 for (vnodeIndex = 0;
1895 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1896 nVnodes--, vnodeIndex++) {
1897 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1898 /* Note: the >= test is very important since some old volumes may not have
1899 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1900 * does dump the file! */
1903 SizeDumpVnode(iodp, vnode, V_id(vp),
1904 bitNumberToVnodeNumber(vnodeIndex, class), flag,