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>
16 #include <sys/types.h>
24 #include <sys/param.h>
27 #include <netinet/in.h>
31 #ifdef AFS_PTHREAD_ENV
33 #else /* AFS_PTHREAD_ENV */
34 #include <afs/assert.h>
35 #endif /* AFS_PTHREAD_ENV */
38 #include <afs/afsint.h>
40 #include <afs/errors.h>
43 #include <afs/ihandle.h>
44 #include <afs/vnode.h>
45 #include <afs/volume.h>
46 #include <afs/partition.h>
48 #include <afs/daemon_com.h>
49 #include <afs/fssync.h>
56 #define afs_stat stat64
57 #define afs_fstat fstat64
58 #else /* !O_LARGEFILE */
60 #define afs_fstat fstat
61 #endif /* !O_LARGEFILE */
62 #endif /* !AFS_NT40_ENV */
64 /*@printflike@*/ extern void Log(const char *format, ...);
68 /* This iod stuff is a silly little package to emulate the old qi_in stuff, which
69 emulated the stdio stuff. There is a big assumption here, that the
70 rx_Read will never be called directly, by a routine like readFile, when
71 there is an old character that was pushed back with iod_ungetc. This
72 is really bletchy, and is here for compatibility only. Eventually,
73 we should define a volume format that doesn't require
74 the pushing back of characters (i.e. characters should not double both
75 as an end marker and a begin marker) */
77 struct rx_call *call; /* call to which to write, might be an array */
78 int device; /* dump device ID for volume */
79 int parentId; /* dump parent ID for volume */
80 struct DiskPartition *dumpPartition; /* Dump partition. */
81 struct rx_call **calls; /* array of pointers to calls */
82 int ncalls; /* how many calls/codes in array */
83 int *codes; /* one return code for each call */
84 char haveOldChar; /* state for pushing back a character */
89 /* Forward Declarations */
90 static int DumpDumpHeader(register struct iod *iodp, register Volume * vp,
92 static int DumpPartial(register struct iod *iodp, register Volume * vp,
93 afs_int32 fromtime, int dumpAllDirs);
94 static int DumpVnodeIndex(register struct iod *iodp, Volume * vp,
95 VnodeClass class, afs_int32 fromtime,
97 static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
98 int volid, int vnodeNumber, int dumpEverything);
99 static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp);
100 static int ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
101 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf,
102 afs_int32 s2, afs_int32 delo);
103 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
104 FdHandle_t * handleP, int tag,
107 static int SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
109 register struct volintSize *size);
110 static int SizeDumpPartial(register struct iod *iodp, register Volume * vp,
111 afs_int32 fromtime, int dumpAllDirs,
112 register struct volintSize *size);
113 static int SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp,
114 VnodeClass class, afs_int32 fromtime,
116 register struct volintSize *size);
117 static int SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
118 int volid, int vnodeNumber, int dumpEverything,
119 register struct volintSize *size);
122 iod_Init(register struct iod *iodp, register struct rx_call *call)
125 iodp->haveOldChar = 0;
127 iodp->calls = (struct rx_call **)0;
131 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
136 iodp->haveOldChar = 0;
137 iodp->ncalls = ncalls;
139 iodp->call = (struct rx_call *)0;
142 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
143 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
145 /* For the single dump case, it's ok to just return the "bytes written"
146 * that rx_Write returns, since all the callers of iod_Write abort when
147 * the returned value is less than they expect. For the multi dump case,
148 * I don't think we want half the replicas to go bad just because one
149 * connection timed out, but if they all time out, then we should give up.
152 iod_Write(struct iod *iodp, char *buf, int nbytes)
157 assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
158 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
161 code = rx_Write(iodp->call, buf, nbytes);
165 for (i = 0; i < iodp->ncalls; i++) {
166 if (iodp->calls[i] && !iodp->codes[i]) {
167 code = rx_Write(iodp->calls[i], buf, nbytes);
168 if (code != nbytes) { /* everything gets merged into a single error */
169 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
170 } /* standard dump does, anyways */
175 } /* for all calls */
184 iod_ungetc(struct iod *iodp, int achar)
186 iodp->oldChar = achar;
187 iodp->haveOldChar = 1;
191 iod_getc(register struct iod *iodp)
195 if (iodp->haveOldChar) {
196 iodp->haveOldChar = 0;
197 return iodp->oldChar;
199 if (iod_Read(iodp, &t, 1) == 1)
205 ReadShort(register struct iod *iodp, register unsigned short *sp)
214 *sp = (b1 << 8) | b0;
219 ReadInt32(register struct iod *iodp, afs_uint32 * lp)
221 afs_uint32 register b3, b2, b1, b0;
234 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
239 ReadString(register struct iod *iodp, register char *to, register int maxa)
249 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
253 while ((c = iod_getc(iodp)) && c != EOF);
259 ReadByteString(register struct iod *iodp, register byte * to,
263 *to++ = iod_getc(iodp);
267 ReadVolumeHeader(register struct iod *iodp, VolumeDiskData * vol)
271 memset(vol, 0, sizeof(*vol));
272 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
275 if (!ReadInt32(iodp, &vol->id))
276 return VOLSERREAD_DUMPERROR;
279 if (!ReadInt32(iodp, &trash))
280 return VOLSERREAD_DUMPERROR;
283 ReadString(iodp, vol->name, sizeof(vol->name));
284 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
287 vol->inService = iod_getc(iodp);
290 vol->blessed = iod_getc(iodp);
293 if (!ReadInt32(iodp, &vol->uniquifier))
294 return VOLSERREAD_DUMPERROR;
297 vol->type = iod_getc(iodp);
300 if (!ReadInt32(iodp, &vol->parentId))
301 return VOLSERREAD_DUMPERROR;
304 if (!ReadInt32(iodp, &vol->cloneId))
305 return VOLSERREAD_DUMPERROR;
308 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
309 return VOLSERREAD_DUMPERROR;
312 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
313 return VOLSERREAD_DUMPERROR;
316 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
317 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
320 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
321 return VOLSERREAD_DUMPERROR;
324 if (!ReadInt32(iodp, &vol->accountNumber))
325 return VOLSERREAD_DUMPERROR;
328 if (!ReadInt32(iodp, &vol->owner))
329 return VOLSERREAD_DUMPERROR;
332 if (!ReadInt32(iodp, &vol->creationDate))
333 return VOLSERREAD_DUMPERROR;
336 if (!ReadInt32(iodp, &vol->accessDate))
337 return VOLSERREAD_DUMPERROR;
340 if (!ReadInt32(iodp, &vol->updateDate))
341 return VOLSERREAD_DUMPERROR;
344 if (!ReadInt32(iodp, &vol->expirationDate))
345 return VOLSERREAD_DUMPERROR;
348 if (!ReadInt32(iodp, &vol->backupDate))
349 return VOLSERREAD_DUMPERROR;
352 ReadString(iodp, vol->offlineMessage,
353 sizeof(vol->offlineMessage));
357 * Detailed volume statistics are never stored in dumps,
358 * so we just restore either the null string if this volume
359 * had already been set to store statistics, or the old motd
360 * contents otherwise. It doesn't matter, since this field
361 * will soon get initialized anyway.
363 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
366 unsigned short length;
369 if (!ReadShort(iodp, &length))
370 return VOLSERREAD_DUMPERROR;
371 for (i = 0; i < length; i++) {
372 if (!ReadInt32(iodp, &data))
373 return VOLSERREAD_DUMPERROR;
374 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
375 vol->weekUse[i] = data;
380 if (!ReadInt32(iodp, &vol->dayUseDate))
381 return VOLSERREAD_DUMPERROR;
384 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
385 return VOLSERREAD_DUMPERROR;
388 if (!ReadInt32(iodp, (afs_uint32 *) & vol->volUpdateCounter))
389 return VOLSERREAD_DUMPERROR;
393 iod_ungetc(iodp, tag);
398 DumpTag(register struct iod *iodp, register int tag)
403 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
408 DumpByte(register struct iod *iodp, char tag, byte value)
411 register byte *p = (unsigned char *)tbuffer;
414 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
417 #define putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
418 #define putshort(p, v) *p++ = v>>8, *p++ = v
421 DumpDouble(register struct iod *iodp, char tag, register afs_uint32 value1,
422 register afs_uint32 value2)
425 register byte *p = (unsigned char *)tbuffer;
429 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
433 DumpInt32(register struct iod *iodp, char tag, register afs_uint32 value)
436 register byte *p = (unsigned char *)tbuffer;
439 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
443 DumpArrayInt32(register struct iod *iodp, char tag,
444 register afs_uint32 * array, register int nelem)
447 register afs_uint32 v;
449 register byte *p = (unsigned char *)tbuffer;
452 code = iod_Write(iodp, tbuffer, 3);
454 return VOLSERDUMPERROR;
456 p = (unsigned char *)tbuffer;
457 v = *array++; /*this was register */
460 code = iod_Write(iodp, tbuffer, 4);
462 return VOLSERDUMPERROR;
468 DumpShort(register struct iod *iodp, char tag, unsigned int value)
471 register byte *p = (unsigned char *)tbuffer;
475 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
479 DumpBool(register struct iod *iodp, char tag, unsigned int value)
482 register byte *p = (unsigned char *)tbuffer;
485 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
489 DumpString(register struct iod *iodp, char tag, register char *s)
493 code = iod_Write(iodp, &tag, 1);
495 return VOLSERDUMPERROR;
497 code = iod_Write(iodp, s, n);
499 return VOLSERDUMPERROR;
504 DumpByteString(register struct iod *iodp, char tag, register byte * bs,
509 code = iod_Write(iodp, &tag, 1);
511 return VOLSERDUMPERROR;
512 code = iod_Write(iodp, (char *)bs, nbytes);
514 return VOLSERDUMPERROR;
519 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
521 int code = 0, error = 0;
522 afs_int32 pad = 0, offset;
523 afs_sfsize_t n, nbytes, howMany, howBig;
527 struct afs_stat status;
531 #include <sys/statfs.h>
532 #if defined(AFS_AIX52_ENV) && defined(AFS_LARGEFILE_ENV)
533 struct statfs64 tstatfs;
534 #else /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
535 struct statfs tstatfs;
536 #endif /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
541 howBig = _filelength(handleP->fd_fd);
545 afs_fstat(handleP->fd_fd, &status);
546 howBig = status.st_size;
549 /* Unfortunately in AIX valuable fields such as st_blksize are
550 * gone from the stat structure.
552 #if defined(AFS_AIX52_ENV) && defined(AFS_LARGEFILE_ENV)
553 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
554 #else /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
555 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
556 #endif /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
557 if (statfs_code != 0) {
558 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
559 return VOLSERDUMPERROR;
561 howMany = (afs_sfsize_t) tstatfs.f_bsize;
562 Log("DumpFile: fstatfs returned block size of %lld; howMany=%lld", tstatfs.f_bsize, howMany);
564 howMany = status.st_blksize;
565 #endif /* AFS_AIX_ENV */
566 #endif /* AFS_NT40_ENV */
569 size = FDH_SIZE(handleP);
570 #ifdef AFS_LARGEFILE_ENV
573 SplitInt64(size, hi, lo);
575 code = DumpInt32(iodp, 'f', lo);
577 code = DumpDouble(iodp, 'h', hi, lo);
580 #else /* !AFS_LARGEFILE_ENV */
581 code = DumpInt32(iodp, 'f', size);
582 #endif /* !AFS_LARGEFILE_ENV */
584 return VOLSERDUMPERROR;
587 p = (unsigned char *)malloc((size_t)howMany);
589 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", howMany);
590 return VOLSERDUMPERROR;
593 for (nbytes = size; (nbytes && !error); nbytes -= howMany) {
594 if (nbytes < howMany)
597 /* Read the data - unless we know we can't */
598 n = (lcode ? 0 : FDH_READ(handleP, p, (size_t)howMany));
600 /* If read any good data and we null padded previously, log the
601 * amount that we had null padded.
603 if ((n > 0) && pad) {
604 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", pad, offset);
608 /* If didn't read enough data, null padd the rest of the buffer. This
609 * can happen if, for instance, the media has some bad spots. We don't
610 * want to quit the dump, so we start null padding.
613 /* Record the read error */
616 Log("1 Volser: DumpFile: Error %d reading inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
618 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
621 /* Pad the rest of the buffer with zeros. Remember offset we started
622 * padding. Keep total tally of padding.
624 memset(p + n, 0, howMany - n);
626 offset = (howBig - nbytes) + n;
627 pad += (howMany - n);
629 /* Now seek over the data we could not get. An error here means we
630 * can't do the next read.
632 lcode = FDH_SEEK(handleP, (size_t)((size - nbytes) + howMany), SEEK_SET);
633 if (lcode != ((size - nbytes) + howMany)) {
635 Log("1 Volser: DumpFile: Error %d seeking in inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
637 Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
645 /* Now write the data out */
646 if (iod_Write(iodp, (char *)p, (size_t)howMany) != howMany)
647 error = VOLSERDUMPERROR;
648 #ifndef AFS_PTHREAD_ENV
653 if (pad) { /* Any padding we hadn't reported yet */
654 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n",
663 DumpVolumeHeader(register struct iod *iodp, register Volume * vp)
666 static char nullString[1] = ""; /*The ``contents'' of motd */
669 code = DumpTag(iodp, D_VOLUMEHEADER);
671 code = DumpInt32(iodp, 'i', V_id(vp));
674 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
676 code = DumpString(iodp, 'n', V_name(vp));
678 code = DumpBool(iodp, 's', V_inService(vp));
680 code = DumpBool(iodp, 'b', V_blessed(vp));
682 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
684 code = DumpByte(iodp, 't', (byte) V_type(vp));
686 code = DumpInt32(iodp, 'p', V_parentId(vp));
689 code = DumpInt32(iodp, 'c', V_cloneId(vp));
691 code = DumpInt32(iodp, 'q', V_maxquota(vp));
693 code = DumpInt32(iodp, 'm', V_minquota(vp));
695 code = DumpInt32(iodp, 'd', V_diskused(vp));
697 code = DumpInt32(iodp, 'f', V_filecount(vp));
699 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
701 code = DumpInt32(iodp, 'o', V_owner(vp));
703 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
705 code = DumpInt32(iodp, 'A', V_accessDate(vp));
707 code = DumpInt32(iodp, 'U', V_updateDate(vp));
709 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
711 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
713 code = DumpString(iodp, 'O', V_offlineMessage(vp));
715 * We do NOT dump the detailed volume statistics residing in the old
716 * motd field, since we cannot tell from the info in a dump whether
717 * statistics data has been put there. Instead, we dump a null string,
718 * just as if that was what the motd contained.
721 code = DumpString(iodp, 'M', nullString);
724 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
725 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
727 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
729 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
731 code = DumpInt32(iodp, 'V', V_volUpCounter(vp));
736 DumpEnd(register struct iod *iodp)
738 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
741 /* Guts of the dump code */
743 /* Dump a whole volume */
745 DumpVolume(register struct rx_call *call, register Volume * vp,
746 afs_int32 fromtime, int dumpAllDirs)
750 register struct iod *iodp = &iod;
751 iod_Init(iodp, call);
754 code = DumpDumpHeader(iodp, vp, fromtime);
757 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
759 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
760 if (rx_Error(iodp->call)) {
761 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
762 rx_Error(iodp->call));
763 return VOLSERDUMPERROR;
766 code = DumpEnd(iodp);
771 /* Dump a volume to multiple places*/
773 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
774 afs_int32 fromtime, int dumpAllDirs, int *codes)
778 iod_InitMulti(&iod, calls, ncalls, codes);
781 code = DumpDumpHeader(&iod, vp, fromtime);
783 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
785 code = DumpEnd(&iod);
789 /* A partial dump (no dump header) */
791 DumpPartial(register struct iod *iodp, register Volume * vp,
792 afs_int32 fromtime, int dumpAllDirs)
796 code = DumpVolumeHeader(iodp, vp);
798 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
800 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
805 DumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
806 afs_int32 fromtime, int forcedump)
808 register int code = 0;
809 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
810 char buf[SIZEOF_LARGEDISKVNODE];
811 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
812 StreamHandle_t *file;
816 register int vnodeIndex, nVnodes;
818 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
820 file = FDH_FDOPEN(fdP, "r+");
821 assert(file != NULL);
822 size = OS_SIZE(fdP->fd_fd);
824 nVnodes = (size / vcp->diskSize) - 1;
826 assert((nVnodes + 1) * vcp->diskSize == size);
827 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
831 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
832 nVnodes--, vnodeIndex++) {
833 flag = forcedump || (vnode->serverModifyTime >= fromtime);
834 /* Note: the >= test is very important since some old volumes may not have
835 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
836 * does dump the file! */
839 DumpVnode(iodp, vnode, V_id(vp),
840 bitNumberToVnodeNumber(vnodeIndex, class), flag);
841 #ifndef AFS_PTHREAD_ENV
843 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
852 DumpDumpHeader(register struct iod *iodp, register Volume * vp,
856 int UseLatestReadOnlyClone = 1;
857 afs_int32 dumpTimes[2];
858 iodp->device = vp->device;
859 iodp->parentId = V_parentId(vp);
860 iodp->dumpPartition = vp->partition;
862 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
866 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
868 code = DumpString(iodp, 'n', V_name(vp));
869 dumpTimes[0] = fromtime;
870 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
872 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
877 DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
878 int vnodeNumber, int dumpEverything)
884 if (!v || v->type == vNull)
887 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
891 code = DumpByte(iodp, 't', (byte) v->type);
893 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
895 code = DumpInt32(iodp, 'v', v->dataVersion);
897 code = DumpInt32(iodp, 'm', v->unixModifyTime);
899 code = DumpInt32(iodp, 'a', v->author);
901 code = DumpInt32(iodp, 'o', v->owner);
902 if (!code && v->group)
903 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
905 code = DumpShort(iodp, 'b', v->modeBits);
907 code = DumpInt32(iodp, 'p', v->parent);
909 code = DumpInt32(iodp, 's', v->serverModifyTime);
910 if (v->type == vDirectory) {
911 acl_HtonACL(VVnodeDiskACL(v));
914 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
917 if (VNDISK_GET_INO(v)) {
918 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
921 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);
923 return VOLSERREAD_DUMPERROR;
925 code = DumpFile(iodp, vnodeNumber, fdP);
934 ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep,
937 int i, nVnodes, offset, code, index = 0;
941 StreamHandle_t *afile;
943 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
944 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
945 register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
947 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
948 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
951 afile = FDH_FDOPEN(fdP, "r+");
955 for (i = 0; i < *sizep; i++) {
958 STREAM_SEEK(afile, Buf[i], 0);
959 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
961 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
964 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
965 V_id(vp), bitNumberToVnodeNumber(i, class),
966 (afs_uintmax_t) VNDISK_GET_INO(vnode));
968 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
972 STREAM_SEEK(afile, Buf[i], 0);
973 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
979 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
982 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
983 OS_SYNC(afile->str_fd);
985 size = OS_SIZE(fdP->fd_fd);
989 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
991 Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32));
997 memset((char *)Buf, 0, nVnodes * sizeof(afs_int32));
998 STREAM_SEEK(afile, offset = vcp->diskSize, 0);
1000 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1004 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1005 Buf[(offset >> vcp->logSize) - 1] = offset;
1008 offset += vcp->diskSize;
1014 STREAM_CLOSE(afile);
1021 RestoreVolume(register struct rx_call *call, Volume * avp, int incremental,
1022 struct restoreCookie *cookie)
1025 struct DumpHeader header;
1026 afs_uint32 endMagic;
1027 Error error = 0, vupdate;
1028 register Volume *vp;
1030 register struct iod *iodp = &iod;
1031 afs_int32 *b1 = NULL, *b2 = NULL;
1032 int s1 = 0, s2 = 0, delo = 0, tdelo;
1035 iod_Init(iodp, call);
1038 if (V_parentId(vp) == V_id(vp))
1041 if (!ReadDumpHeader(iodp, &header)) {
1042 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1043 return VOLSERREAD_DUMPERROR;
1045 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1046 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1047 return VOLSERREAD_DUMPERROR;
1049 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1050 return VOLSERREAD_DUMPERROR;
1053 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1055 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1057 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1058 error = VOLSERREAD_DUMPERROR;
1062 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1063 vol.type = cookie->type;
1064 vol.cloneId = cookie->clone;
1065 vol.parentId = cookie->parent;
1069 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1070 error = VOLSERREAD_DUMPERROR;
1073 tag = iod_getc(iodp);
1074 if (tag != D_VOLUMEHEADER)
1077 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1078 error = VOLSERREAD_DUMPERROR;
1082 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1083 || endMagic != DUMPENDMAGIC) {
1084 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1085 error = VOLSERREAD_DUMPERROR;
1090 if (iod_getc(iodp) != EOF) {
1091 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1092 error = VOLSERREAD_DUMPERROR;
1097 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1099 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1101 error = VOLSERREAD_DUMPERROR;
1107 ClearVolumeStats(&vol);
1108 CopyVolumeHeader(&vol, &V_disk(vp));
1109 V_destroyMe(vp) = 0;
1110 VUpdateVolume(&vupdate, vp);
1112 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1113 error = VOLSERREAD_DUMPERROR;
1117 /* Free the malloced space above */
1126 ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
1127 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2,
1130 afs_int32 vnodeNumber;
1131 char buf[SIZEOF_LARGEDISKVNODE];
1133 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1134 struct VnodeDiskObject oldvnode;
1137 struct VnodeClassInfo *vcp;
1142 tag = iod_getc(iodp);
1143 V_pref(vp, nearInode);
1144 while (tag == D_VNODE) {
1146 memset(buf, 0, sizeof(buf));
1147 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1150 if (!ReadInt32(iodp, &vnode->uniquifier))
1151 return VOLSERREAD_DUMPERROR;
1152 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1156 vnode->type = (VnodeType) iod_getc(iodp);
1161 if (!ReadShort(iodp, &tlc))
1162 return VOLSERREAD_DUMPERROR;
1163 vnode->linkCount = (signed int)tlc;
1167 if (!ReadInt32(iodp, &vnode->dataVersion))
1168 return VOLSERREAD_DUMPERROR;
1171 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1172 return VOLSERREAD_DUMPERROR;
1175 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1176 return VOLSERREAD_DUMPERROR;
1179 if (!ReadInt32(iodp, &vnode->author))
1180 return VOLSERREAD_DUMPERROR;
1183 if (!ReadInt32(iodp, &vnode->owner))
1184 return VOLSERREAD_DUMPERROR;
1187 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1188 return VOLSERREAD_DUMPERROR;
1191 unsigned short modeBits;
1192 if (!ReadShort(iodp, &modeBits))
1193 return VOLSERREAD_DUMPERROR;
1194 vnode->modeBits = (unsigned int)modeBits;
1198 if (!ReadInt32(iodp, &vnode->parent))
1199 return VOLSERREAD_DUMPERROR;
1202 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1203 VAclDiskSize(vnode));
1204 acl_NtohACL(VVnodeDiskACL(vnode));
1206 #ifdef AFS_LARGEFILE_ENV
1212 afs_fsize_t vnodeLength;
1215 IH_CREATE(V_linkHandle(vp), V_device(vp),
1216 VPartitionPath(V_partition(vp)), nearInode,
1217 V_parentId(vp), vnodeNumber,
1218 vnode->uniquifier, vnode->dataVersion);
1219 if (!VALID_INO(ino)) {
1220 perror("unable to allocate inode");
1221 Log("1 Volser: ReadVnodes: Restore aborted\n");
1222 return VOLSERREAD_DUMPERROR;
1225 VNDISK_SET_INO(vnode, ino);
1226 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1227 fdP = IH_OPEN(tmpH);
1230 return VOLSERREAD_DUMPERROR;
1233 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1234 VNDISK_SET_LEN(vnode, vnodeLength);
1235 FDH_REALLYCLOSE(fdP);
1238 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1239 (afs_uintmax_t) ino);
1240 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1241 return VOLSERREAD_DUMPERROR;
1248 class = vnodeIdToClass(vnodeNumber);
1249 vcp = &VnodeClassInfo[class];
1251 /* Mark this vnode as in this dump - so we don't delete it later */
1253 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1254 if (class == vLarge) {
1255 if (Lbuf && (idx < s1))
1258 if (Sbuf && (idx < s2))
1264 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1266 Log("1 Volser: ReadVnodes: Error opening vnode index; restore aborted\n");
1267 return VOLSERREAD_DUMPERROR;
1269 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1271 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1272 FDH_REALLYCLOSE(fdP);
1273 return VOLSERREAD_DUMPERROR;
1275 if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) ==
1277 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1278 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1282 vnode->vnodeMagic = vcp->magic;
1283 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1285 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1286 FDH_REALLYCLOSE(fdP);
1287 return VOLSERREAD_DUMPERROR;
1289 if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
1290 Log("1 Volser: ReadVnodes: Error writing vnode index; restore aborted\n");
1291 FDH_REALLYCLOSE(fdP);
1292 return VOLSERREAD_DUMPERROR;
1297 iod_ungetc(iodp, tag);
1303 /* called with disk file only. Note that we don't have to worry about rx_Read
1304 * needing to read an ungetc'd character, since the ReadInt32 will have read
1308 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1313 afs_fsize_t filesize;
1314 afs_fsize_t written = 0;
1315 register afs_uint32 size = 8192;
1316 register afs_fsize_t nbytes;
1321 #ifdef AFS_64BIT_ENV
1323 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1324 #ifdef AFS_LARGEFILE_ENV
1326 if (!ReadInt32(iodp, &filesize_high)) {
1331 #endif /* !AFS_LARGEFILE_ENV */
1332 if (!ReadInt32(iodp, &filesize_low)) {
1336 FillInt64(filesize, filesize_high, filesize_low);
1338 #else /* !AFS_64BIT_ENV */
1339 if (!ReadInt32(iodp, &filesize)) {
1343 #endif /* !AFS_64BIT_ENV */
1344 p = (unsigned char *)malloc(size);
1349 for (nbytes = filesize; nbytes; nbytes -= size) {
1353 if ((code = iod_Read(iodp, p, size)) != size) {
1354 Log("1 Volser: WriteFile: Error reading dump file %d size=%llu nbytes=%u (%d of %u); restore aborted\n", vn, (afs_uintmax_t) filesize, nbytes, code, size);
1358 lcode = FDH_WRITE(handleP, p, size);
1361 if (lcode != size) {
1362 Log("1 Volser: WriteFile: Error writing (%d,%u) bytes to vnode %d; restore aborted\n", (int)(lcode>>32), (int)(lcode & 0xffffffff), vn);
1372 ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp)
1375 afs_uint32 beginMagic;
1376 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1377 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1378 || beginMagic != DUMPBEGINMAGIC)
1382 while ((tag = iod_getc(iodp)) > D_MAX) {
1383 unsigned short arrayLength;
1387 if (!ReadInt32(iodp, &hp->volumeId))
1391 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1394 if (!ReadShort(iodp, &arrayLength))
1396 hp->nDumpTimes = (arrayLength >> 1);
1397 for (i = 0; i < hp->nDumpTimes; i++)
1398 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1399 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1404 if (!hp->volumeId || !hp->nDumpTimes) {
1407 iod_ungetc(iodp, tag);
1412 /* ----- Below are the calls that calculate dump size ----- */
1415 SizeDumpVolumeHeader(register struct iod *iodp, register Volume * vp,
1416 register struct volintSize *v_size)
1419 static char nullString[1] = ""; /*The ``contents'' of motd */
1422 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1423 FillInt64(addvar,0, 1);
1424 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1425 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1426 FillInt64(addvar,0, 5);
1427 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1428 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1429 FillInt64(addvar,0, 5);
1430 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1431 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1432 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1433 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1434 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1435 FillInt64(addvar,0, 2);
1436 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1437 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1438 FillInt64(addvar,0, 2);
1439 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1440 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1441 FillInt64(addvar,0, 5);
1442 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1443 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1444 FillInt64(addvar,0, 2);
1445 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1446 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1447 FillInt64(addvar,0, 5);
1448 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1449 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1450 FillInt64(addvar,0, 5);
1451 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1452 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1453 FillInt64(addvar,0, 5);
1454 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1455 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1456 FillInt64(addvar,0, 5);
1457 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1458 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1459 FillInt64(addvar,0, 5);
1460 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1461 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1462 FillInt64(addvar,0, 5);
1463 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1464 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1465 FillInt64(addvar,0, 5);
1466 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1467 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1468 FillInt64(addvar,0, 5);
1469 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1470 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1471 FillInt64(addvar,0, 5);
1472 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1473 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1474 FillInt64(addvar,0, 5);
1475 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1476 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1477 FillInt64(addvar,0, 5);
1478 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1479 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1480 FillInt64(addvar,0, 5);
1481 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1482 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1483 FillInt64(addvar,0, 5);
1484 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1485 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1486 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1487 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1489 /* * We do NOT dump the detailed volume statistics residing in the old */
1490 /* * motd field, since we cannot tell from the info in a dump whether */
1491 /* * statistics data has been put there. Instead, we dump a null string, */
1492 /* * just as if that was what the motd contained. */
1494 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1495 FillInt64(addvar,0, (2 + strlen(nullString)));
1496 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1497 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1498 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1499 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1500 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1501 FillInt64(addvar,0, 5);
1502 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1503 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1504 FillInt64(addvar,0, 5);
1505 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1506 /* if (!code) code = DumpInt32(iodp, 'V', V_volUpCounter(vp)); */
1507 FillInt64(addvar,0, 5);
1508 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1513 SizeDumpEnd(register struct iod *iodp, register struct volintSize *v_size)
1517 FillInt64(addvar,0, 5);
1518 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1523 SizeDumpVolume(register struct rx_call *call, register Volume * vp,
1524 afs_int32 fromtime, int dumpAllDirs,
1525 register struct volintSize *v_size)
1528 register struct iod *iodp = (struct iod *)0;
1529 /* iod_Init(iodp, call); */
1532 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1534 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1536 code = SizeDumpEnd(iodp, v_size);
1542 SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
1543 afs_int32 fromtime, register struct volintSize *v_size)
1546 int UseLatestReadOnlyClone = 1;
1547 /* afs_int32 dumpTimes[2]; */
1549 /* iodp->device = vp->device; */
1550 /* iodp->parentId = V_parentId(vp); */
1551 /* iodp->dumpPartition = vp->partition; */
1553 ZeroInt64(v_size->dump_size); /* initialize the size */
1554 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1555 FillInt64(addvar,0, 9);
1556 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1557 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1558 FillInt64(addvar,0, 5);
1559 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1560 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1561 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1562 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1563 /* dumpTimes[0] = fromtime; */
1564 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1565 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1566 FillInt64(addvar,0, (3 + 4 * 2));
1567 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1572 SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
1573 int vnodeNumber, int dumpEverything,
1574 register struct volintSize *v_size)
1579 if (!v || v->type == vNull)
1581 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1582 FillInt64(addvar,0, 9);
1583 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1584 if (!dumpEverything)
1586 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1587 FillInt64(addvar,0, 2);
1588 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1589 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1590 FillInt64(addvar,0, 3);
1591 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1592 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1593 FillInt64(addvar,0, 5);
1594 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1595 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1596 FillInt64(addvar,0, 5);
1597 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1598 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1599 FillInt64(addvar,0, 5);
1600 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1601 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1602 FillInt64(addvar,0, 5);
1603 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1604 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1606 FillInt64(addvar,0, 5);
1607 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1609 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1610 FillInt64(addvar,0, 3);
1611 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1612 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1613 FillInt64(addvar,0, 5);
1614 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1615 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1616 FillInt64(addvar,0, 5);
1617 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1618 if (v->type == vDirectory) {
1619 /* acl_HtonACL(VVnodeDiskACL(v)); */
1620 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1621 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1622 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1625 if (VNDISK_GET_INO(v)) {
1626 FillInt64(addvar,0, (v->length + 5));
1627 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1632 /* A partial dump (no dump header) */
1634 SizeDumpPartial(register struct iod *iodp, register Volume * vp,
1635 afs_int32 fromtime, int dumpAllDirs,
1636 register struct volintSize *v_size)
1640 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1643 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1646 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1651 SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
1652 afs_int32 fromtime, int forcedump,
1653 register struct volintSize *v_size)
1655 register int code = 0;
1656 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1657 char buf[SIZEOF_LARGEDISKVNODE];
1658 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1659 StreamHandle_t *file;
1663 register int vnodeIndex, nVnodes;
1665 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1666 assert(fdP != NULL);
1667 file = FDH_FDOPEN(fdP, "r+");
1668 assert(file != NULL);
1669 size = OS_SIZE(fdP->fd_fd);
1671 nVnodes = (size / vcp->diskSize) - 1;
1673 assert((nVnodes + 1) * vcp->diskSize == size);
1674 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
1677 for (vnodeIndex = 0;
1678 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1679 nVnodes--, vnodeIndex++) {
1680 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1681 /* Note: the >= test is very important since some old volumes may not have
1682 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1683 * does dump the file! */
1686 SizeDumpVnode(iodp, vnode, V_id(vp),
1687 bitNumberToVnodeNumber(vnodeIndex, class), flag,