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>
23 #include <sys/param.h>
26 #include <netinet/in.h>
37 #ifdef AFS_PTHREAD_ENV
39 #else /* AFS_PTHREAD_ENV */
40 #include <afs/assert.h>
41 #endif /* AFS_PTHREAD_ENV */
44 #include <afs/afsint.h>
46 #include <afs/errors.h>
49 #include <afs/ihandle.h>
50 #include <afs/vnode.h>
51 #include <afs/volume.h>
52 #include <afs/partition.h>
54 #include <afs/daemon_com.h>
55 #include <afs/fssync.h>
62 #define afs_stat stat64
63 #define afs_fstat fstat64
64 #else /* !O_LARGEFILE */
66 #define afs_fstat fstat
67 #endif /* !O_LARGEFILE */
68 #endif /* !AFS_NT40_ENV */
70 /*@printflike@*/ extern void Log(const char *format, ...);
74 /* This iod stuff is a silly little package to emulate the old qi_in stuff, which
75 emulated the stdio stuff. There is a big assumption here, that the
76 rx_Read will never be called directly, by a routine like readFile, when
77 there is an old character that was pushed back with iod_ungetc. This
78 is really bletchy, and is here for compatibility only. Eventually,
79 we should define a volume format that doesn't require
80 the pushing back of characters (i.e. characters should not double both
81 as an end marker and a begin marker) */
83 struct rx_call *call; /* call to which to write, might be an array */
84 int device; /* dump device ID for volume */
85 int parentId; /* dump parent ID for volume */
86 struct DiskPartition *dumpPartition; /* Dump partition. */
87 struct rx_call **calls; /* array of pointers to calls */
88 int ncalls; /* how many calls/codes in array */
89 int *codes; /* one return code for each call */
90 char haveOldChar; /* state for pushing back a character */
95 /* Forward Declarations */
96 static int DumpDumpHeader(register struct iod *iodp, register Volume * vp,
98 static int DumpPartial(register struct iod *iodp, register Volume * vp,
99 afs_int32 fromtime, int dumpAllDirs);
100 static int DumpVnodeIndex(register struct iod *iodp, Volume * vp,
101 VnodeClass class, afs_int32 fromtime,
103 static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
104 int volid, int vnodeNumber, int dumpEverything);
105 static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp);
106 static int ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
107 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf,
108 afs_int32 s2, afs_int32 delo);
109 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
110 FdHandle_t * handleP, int tag,
113 static int SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
115 register struct volintSize *size);
116 static int SizeDumpPartial(register struct iod *iodp, register Volume * vp,
117 afs_int32 fromtime, int dumpAllDirs,
118 register struct volintSize *size);
119 static int SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp,
120 VnodeClass class, afs_int32 fromtime,
122 register struct volintSize *size);
123 static int SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
124 int volid, int vnodeNumber, int dumpEverything,
125 register struct volintSize *size);
128 iod_Init(register struct iod *iodp, register struct rx_call *call)
131 iodp->haveOldChar = 0;
133 iodp->calls = (struct rx_call **)0;
137 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
142 iodp->haveOldChar = 0;
143 iodp->ncalls = ncalls;
145 iodp->call = (struct rx_call *)0;
148 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
149 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
151 /* For the single dump case, it's ok to just return the "bytes written"
152 * that rx_Write returns, since all the callers of iod_Write abort when
153 * the returned value is less than they expect. For the multi dump case,
154 * I don't think we want half the replicas to go bad just because one
155 * connection timed out, but if they all time out, then we should give up.
158 iod_Write(struct iod *iodp, char *buf, int nbytes)
163 assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
164 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
167 code = rx_Write(iodp->call, buf, nbytes);
171 for (i = 0; i < iodp->ncalls; i++) {
172 if (iodp->calls[i] && !iodp->codes[i]) {
173 code = rx_Write(iodp->calls[i], buf, nbytes);
174 if (code != nbytes) { /* everything gets merged into a single error */
175 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
176 } /* standard dump does, anyways */
181 } /* for all calls */
190 iod_ungetc(struct iod *iodp, int achar)
192 iodp->oldChar = achar;
193 iodp->haveOldChar = 1;
197 iod_getc(register struct iod *iodp)
201 if (iodp->haveOldChar) {
202 iodp->haveOldChar = 0;
203 return iodp->oldChar;
205 if (iod_Read(iodp, &t, 1) == 1)
211 ReadShort(register struct iod *iodp, register unsigned short *sp)
220 *sp = (b1 << 8) | b0;
225 ReadInt32(register struct iod *iodp, afs_uint32 * lp)
227 afs_uint32 register b3, b2, b1, b0;
240 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
245 ReadString(register struct iod *iodp, register char *to, register int maxa)
255 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
259 while ((c = iod_getc(iodp)) && c != EOF);
265 ReadByteString(register struct iod *iodp, register byte * to,
269 *to++ = iod_getc(iodp);
273 ReadVolumeHeader(register struct iod *iodp, VolumeDiskData * vol)
277 memset(vol, 0, sizeof(*vol));
278 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
281 if (!ReadInt32(iodp, &vol->id))
282 return VOLSERREAD_DUMPERROR;
285 if (!ReadInt32(iodp, &trash))
286 return VOLSERREAD_DUMPERROR;
289 ReadString(iodp, vol->name, sizeof(vol->name));
290 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
293 vol->inService = iod_getc(iodp);
296 vol->blessed = iod_getc(iodp);
299 if (!ReadInt32(iodp, &vol->uniquifier))
300 return VOLSERREAD_DUMPERROR;
303 vol->type = iod_getc(iodp);
306 if (!ReadInt32(iodp, &vol->parentId))
307 return VOLSERREAD_DUMPERROR;
310 if (!ReadInt32(iodp, &vol->cloneId))
311 return VOLSERREAD_DUMPERROR;
314 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
315 return VOLSERREAD_DUMPERROR;
318 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
319 return VOLSERREAD_DUMPERROR;
322 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
323 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
326 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
327 return VOLSERREAD_DUMPERROR;
330 if (!ReadInt32(iodp, &vol->accountNumber))
331 return VOLSERREAD_DUMPERROR;
334 if (!ReadInt32(iodp, &vol->owner))
335 return VOLSERREAD_DUMPERROR;
338 if (!ReadInt32(iodp, &vol->creationDate))
339 return VOLSERREAD_DUMPERROR;
342 if (!ReadInt32(iodp, &vol->accessDate))
343 return VOLSERREAD_DUMPERROR;
346 if (!ReadInt32(iodp, &vol->updateDate))
347 return VOLSERREAD_DUMPERROR;
350 if (!ReadInt32(iodp, &vol->expirationDate))
351 return VOLSERREAD_DUMPERROR;
354 if (!ReadInt32(iodp, &vol->backupDate))
355 return VOLSERREAD_DUMPERROR;
358 ReadString(iodp, vol->offlineMessage,
359 sizeof(vol->offlineMessage));
363 * Detailed volume statistics are never stored in dumps,
364 * so we just restore either the null string if this volume
365 * had already been set to store statistics, or the old motd
366 * contents otherwise. It doesn't matter, since this field
367 * will soon get initialized anyway.
369 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
372 unsigned short length;
375 if (!ReadShort(iodp, &length))
376 return VOLSERREAD_DUMPERROR;
377 for (i = 0; i < length; i++) {
378 if (!ReadInt32(iodp, &data))
379 return VOLSERREAD_DUMPERROR;
380 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
381 vol->weekUse[i] = data;
386 if (!ReadInt32(iodp, &vol->dayUseDate))
387 return VOLSERREAD_DUMPERROR;
390 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
391 return VOLSERREAD_DUMPERROR;
394 if (!ReadInt32(iodp, (afs_uint32 *) & vol->volUpdateCounter))
395 return VOLSERREAD_DUMPERROR;
399 iod_ungetc(iodp, tag);
404 DumpTag(register struct iod *iodp, register int tag)
409 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
414 DumpByte(register struct iod *iodp, char tag, byte value)
417 register byte *p = (unsigned char *)tbuffer;
420 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
423 #define putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
424 #define putshort(p, v) *p++ = v>>8, *p++ = v
427 DumpDouble(register struct iod *iodp, char tag, register afs_uint32 value1,
428 register afs_uint32 value2)
431 register byte *p = (unsigned char *)tbuffer;
435 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
439 DumpInt32(register struct iod *iodp, char tag, register afs_uint32 value)
442 register byte *p = (unsigned char *)tbuffer;
445 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
449 DumpArrayInt32(register struct iod *iodp, char tag,
450 register afs_uint32 * array, register int nelem)
453 register afs_uint32 v;
455 register byte *p = (unsigned char *)tbuffer;
458 code = iod_Write(iodp, tbuffer, 3);
460 return VOLSERDUMPERROR;
462 p = (unsigned char *)tbuffer;
463 v = *array++; /*this was register */
466 code = iod_Write(iodp, tbuffer, 4);
468 return VOLSERDUMPERROR;
474 DumpShort(register struct iod *iodp, char tag, unsigned int value)
477 register byte *p = (unsigned char *)tbuffer;
481 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
485 DumpBool(register struct iod *iodp, char tag, unsigned int value)
488 register byte *p = (unsigned char *)tbuffer;
491 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
495 DumpString(register struct iod *iodp, char tag, register char *s)
499 code = iod_Write(iodp, &tag, 1);
501 return VOLSERDUMPERROR;
503 code = iod_Write(iodp, s, n);
505 return VOLSERDUMPERROR;
510 DumpByteString(register struct iod *iodp, char tag, register byte * bs,
515 code = iod_Write(iodp, &tag, 1);
517 return VOLSERDUMPERROR;
518 code = iod_Write(iodp, (char *)bs, nbytes);
520 return VOLSERDUMPERROR;
525 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
527 int code = 0, error = 0;
528 afs_int32 pad = 0, offset;
529 afs_sfsize_t n, nbytes, howMany, howBig;
533 struct afs_stat status;
537 #include <sys/statfs.h>
538 #if defined(AFS_AIX52_ENV) && defined(AFS_LARGEFILE_ENV)
539 struct statfs64 tstatfs;
540 #else /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
541 struct statfs tstatfs;
542 #endif /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
547 howBig = _filelength(handleP->fd_fd);
551 afs_fstat(handleP->fd_fd, &status);
552 howBig = status.st_size;
555 /* Unfortunately in AIX valuable fields such as st_blksize are
556 * gone from the stat structure.
558 #if defined(AFS_AIX52_ENV) && defined(AFS_LARGEFILE_ENV)
559 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
560 #else /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
561 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
562 #endif /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
563 if (statfs_code != 0) {
564 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
565 return VOLSERDUMPERROR;
567 howMany = (afs_sfsize_t) tstatfs.f_bsize;
568 Log("DumpFile: fstatfs returned block size of %lld; howMany=%lld", tstatfs.f_bsize, howMany);
570 howMany = status.st_blksize;
571 #endif /* AFS_AIX_ENV */
572 #endif /* AFS_NT40_ENV */
575 size = FDH_SIZE(handleP);
576 #ifdef AFS_LARGEFILE_ENV
579 SplitInt64(size, hi, lo);
581 code = DumpInt32(iodp, 'f', lo);
583 code = DumpDouble(iodp, 'h', hi, lo);
586 #else /* !AFS_LARGEFILE_ENV */
587 code = DumpInt32(iodp, 'f', size);
588 #endif /* !AFS_LARGEFILE_ENV */
590 return VOLSERDUMPERROR;
593 p = (unsigned char *)malloc((size_t)howMany);
595 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", howMany);
596 return VOLSERDUMPERROR;
599 for (nbytes = size; (nbytes && !error); nbytes -= howMany) {
600 if (nbytes < howMany)
603 /* Read the data - unless we know we can't */
604 n = (lcode ? 0 : FDH_READ(handleP, p, (size_t)howMany));
606 /* If read any good data and we null padded previously, log the
607 * amount that we had null padded.
609 if ((n > 0) && pad) {
610 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", pad, offset);
614 /* If didn't read enough data, null padd the rest of the buffer. This
615 * can happen if, for instance, the media has some bad spots. We don't
616 * want to quit the dump, so we start null padding.
619 /* Record the read error */
622 Log("1 Volser: DumpFile: Error %d reading inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
624 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
627 /* Pad the rest of the buffer with zeros. Remember offset we started
628 * padding. Keep total tally of padding.
630 memset(p + n, 0, howMany - n);
632 offset = (howBig - nbytes) + n;
633 pad += (howMany - n);
635 /* Now seek over the data we could not get. An error here means we
636 * can't do the next read.
638 lcode = FDH_SEEK(handleP, (size_t)((size - nbytes) + howMany), SEEK_SET);
639 if (lcode != ((size - nbytes) + howMany)) {
641 Log("1 Volser: DumpFile: Error %d seeking in inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
643 Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
651 /* Now write the data out */
652 if (iod_Write(iodp, (char *)p, (size_t)howMany) != howMany)
653 error = VOLSERDUMPERROR;
654 #ifndef AFS_PTHREAD_ENV
659 if (pad) { /* Any padding we hadn't reported yet */
660 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n",
669 DumpVolumeHeader(register struct iod *iodp, register Volume * vp)
672 static char nullString[1] = ""; /*The ``contents'' of motd */
675 code = DumpTag(iodp, D_VOLUMEHEADER);
677 code = DumpInt32(iodp, 'i', V_id(vp));
680 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
682 code = DumpString(iodp, 'n', V_name(vp));
684 code = DumpBool(iodp, 's', V_inService(vp));
686 code = DumpBool(iodp, 'b', V_blessed(vp));
688 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
690 code = DumpByte(iodp, 't', (byte) V_type(vp));
692 code = DumpInt32(iodp, 'p', V_parentId(vp));
695 code = DumpInt32(iodp, 'c', V_cloneId(vp));
697 code = DumpInt32(iodp, 'q', V_maxquota(vp));
699 code = DumpInt32(iodp, 'm', V_minquota(vp));
701 code = DumpInt32(iodp, 'd', V_diskused(vp));
703 code = DumpInt32(iodp, 'f', V_filecount(vp));
705 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
707 code = DumpInt32(iodp, 'o', V_owner(vp));
709 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
711 code = DumpInt32(iodp, 'A', V_accessDate(vp));
713 code = DumpInt32(iodp, 'U', V_updateDate(vp));
715 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
717 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
719 code = DumpString(iodp, 'O', V_offlineMessage(vp));
721 * We do NOT dump the detailed volume statistics residing in the old
722 * motd field, since we cannot tell from the info in a dump whether
723 * statistics data has been put there. Instead, we dump a null string,
724 * just as if that was what the motd contained.
727 code = DumpString(iodp, 'M', nullString);
730 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
731 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
733 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
735 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
737 code = DumpInt32(iodp, 'V', V_volUpCounter(vp));
742 DumpEnd(register struct iod *iodp)
744 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
747 /* Guts of the dump code */
749 /* Dump a whole volume */
751 DumpVolume(register struct rx_call *call, register Volume * vp,
752 afs_int32 fromtime, int dumpAllDirs)
756 register struct iod *iodp = &iod;
757 iod_Init(iodp, call);
760 code = DumpDumpHeader(iodp, vp, fromtime);
763 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
765 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
766 if (rx_Error(iodp->call)) {
767 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
768 rx_Error(iodp->call));
769 return VOLSERDUMPERROR;
772 code = DumpEnd(iodp);
777 /* Dump a volume to multiple places*/
779 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
780 afs_int32 fromtime, int dumpAllDirs, int *codes)
784 iod_InitMulti(&iod, calls, ncalls, codes);
787 code = DumpDumpHeader(&iod, vp, fromtime);
789 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
791 code = DumpEnd(&iod);
795 /* A partial dump (no dump header) */
797 DumpPartial(register struct iod *iodp, register Volume * vp,
798 afs_int32 fromtime, int dumpAllDirs)
802 code = DumpVolumeHeader(iodp, vp);
804 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
806 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
811 DumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
812 afs_int32 fromtime, int forcedump)
814 register int code = 0;
815 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
816 char buf[SIZEOF_LARGEDISKVNODE];
817 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
818 StreamHandle_t *file;
822 register int vnodeIndex, nVnodes;
824 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
826 file = FDH_FDOPEN(fdP, "r+");
827 assert(file != NULL);
828 size = OS_SIZE(fdP->fd_fd);
830 nVnodes = (size / vcp->diskSize) - 1;
832 assert((nVnodes + 1) * vcp->diskSize == size);
833 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
837 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
838 nVnodes--, vnodeIndex++) {
839 flag = forcedump || (vnode->serverModifyTime >= fromtime);
840 /* Note: the >= test is very important since some old volumes may not have
841 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
842 * does dump the file! */
845 DumpVnode(iodp, vnode, V_id(vp),
846 bitNumberToVnodeNumber(vnodeIndex, class), flag);
847 #ifndef AFS_PTHREAD_ENV
849 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
858 DumpDumpHeader(register struct iod *iodp, register Volume * vp,
862 int UseLatestReadOnlyClone = 1;
863 afs_int32 dumpTimes[2];
864 iodp->device = vp->device;
865 iodp->parentId = V_parentId(vp);
866 iodp->dumpPartition = vp->partition;
868 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
872 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
874 code = DumpString(iodp, 'n', V_name(vp));
875 dumpTimes[0] = fromtime;
876 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
878 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
883 DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
884 int vnodeNumber, int dumpEverything)
890 if (!v || v->type == vNull)
893 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
897 code = DumpByte(iodp, 't', (byte) v->type);
899 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
901 code = DumpInt32(iodp, 'v', v->dataVersion);
903 code = DumpInt32(iodp, 'm', v->unixModifyTime);
905 code = DumpInt32(iodp, 'a', v->author);
907 code = DumpInt32(iodp, 'o', v->owner);
908 if (!code && v->group)
909 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
911 code = DumpShort(iodp, 'b', v->modeBits);
913 code = DumpInt32(iodp, 'p', v->parent);
915 code = DumpInt32(iodp, 's', v->serverModifyTime);
916 if (v->type == vDirectory) {
917 acl_HtonACL(VVnodeDiskACL(v));
920 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
923 if (VNDISK_GET_INO(v)) {
924 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
927 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);
929 return VOLSERREAD_DUMPERROR;
931 code = DumpFile(iodp, vnodeNumber, fdP);
940 ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep,
943 int i, nVnodes, offset, code, index = 0;
947 StreamHandle_t *afile;
949 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
950 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
951 register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
953 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
954 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
957 afile = FDH_FDOPEN(fdP, "r+");
961 for (i = 0; i < *sizep; i++) {
964 STREAM_SEEK(afile, Buf[i], 0);
965 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
967 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
970 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
971 V_id(vp), bitNumberToVnodeNumber(i, class),
972 (afs_uintmax_t) VNDISK_GET_INO(vnode));
974 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
978 STREAM_SEEK(afile, Buf[i], 0);
979 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
985 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
988 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
989 OS_SYNC(afile->str_fd);
991 size = OS_SIZE(fdP->fd_fd);
995 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
997 Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32));
1003 memset((char *)Buf, 0, nVnodes * sizeof(afs_int32));
1004 STREAM_SEEK(afile, offset = vcp->diskSize, 0);
1006 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1010 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1011 Buf[(offset >> vcp->logSize) - 1] = offset;
1014 offset += vcp->diskSize;
1020 STREAM_CLOSE(afile);
1027 RestoreVolume(register struct rx_call *call, Volume * avp, int incremental,
1028 struct restoreCookie *cookie)
1031 struct DumpHeader header;
1032 afs_uint32 endMagic;
1033 Error error = 0, vupdate;
1034 register Volume *vp;
1036 register struct iod *iodp = &iod;
1037 afs_int32 *b1 = NULL, *b2 = NULL;
1038 int s1 = 0, s2 = 0, delo = 0, tdelo;
1041 iod_Init(iodp, call);
1044 if (V_parentId(vp) == V_id(vp))
1047 if (!ReadDumpHeader(iodp, &header)) {
1048 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1049 return VOLSERREAD_DUMPERROR;
1051 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1052 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1053 return VOLSERREAD_DUMPERROR;
1055 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1056 return VOLSERREAD_DUMPERROR;
1059 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1061 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1063 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1064 error = VOLSERREAD_DUMPERROR;
1068 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1069 vol.type = cookie->type;
1070 vol.cloneId = cookie->clone;
1071 vol.parentId = cookie->parent;
1075 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1076 error = VOLSERREAD_DUMPERROR;
1079 tag = iod_getc(iodp);
1080 if (tag != D_VOLUMEHEADER)
1083 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1084 error = VOLSERREAD_DUMPERROR;
1088 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1089 || endMagic != DUMPENDMAGIC) {
1090 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1091 error = VOLSERREAD_DUMPERROR;
1096 if (iod_getc(iodp) != EOF) {
1097 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1098 error = VOLSERREAD_DUMPERROR;
1103 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1105 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1107 error = VOLSERREAD_DUMPERROR;
1113 ClearVolumeStats(&vol);
1114 CopyVolumeHeader(&vol, &V_disk(vp));
1115 V_destroyMe(vp) = 0;
1116 VUpdateVolume(&vupdate, vp);
1118 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1119 error = VOLSERREAD_DUMPERROR;
1123 /* Free the malloced space above */
1132 ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
1133 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2,
1136 afs_int32 vnodeNumber;
1137 char buf[SIZEOF_LARGEDISKVNODE];
1139 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1140 struct VnodeDiskObject oldvnode;
1143 struct VnodeClassInfo *vcp;
1148 tag = iod_getc(iodp);
1149 V_pref(vp, nearInode);
1150 while (tag == D_VNODE) {
1152 memset(buf, 0, sizeof(buf));
1153 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1156 if (!ReadInt32(iodp, &vnode->uniquifier))
1157 return VOLSERREAD_DUMPERROR;
1158 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1162 vnode->type = (VnodeType) iod_getc(iodp);
1167 if (!ReadShort(iodp, &tlc))
1168 return VOLSERREAD_DUMPERROR;
1169 vnode->linkCount = (signed int)tlc;
1173 if (!ReadInt32(iodp, &vnode->dataVersion))
1174 return VOLSERREAD_DUMPERROR;
1177 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1178 return VOLSERREAD_DUMPERROR;
1181 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1182 return VOLSERREAD_DUMPERROR;
1185 if (!ReadInt32(iodp, &vnode->author))
1186 return VOLSERREAD_DUMPERROR;
1189 if (!ReadInt32(iodp, &vnode->owner))
1190 return VOLSERREAD_DUMPERROR;
1193 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1194 return VOLSERREAD_DUMPERROR;
1197 unsigned short modeBits;
1198 if (!ReadShort(iodp, &modeBits))
1199 return VOLSERREAD_DUMPERROR;
1200 vnode->modeBits = (unsigned int)modeBits;
1204 if (!ReadInt32(iodp, &vnode->parent))
1205 return VOLSERREAD_DUMPERROR;
1208 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1209 VAclDiskSize(vnode));
1210 acl_NtohACL(VVnodeDiskACL(vnode));
1212 #ifdef AFS_LARGEFILE_ENV
1218 afs_fsize_t vnodeLength;
1221 IH_CREATE(V_linkHandle(vp), V_device(vp),
1222 VPartitionPath(V_partition(vp)), nearInode,
1223 V_parentId(vp), vnodeNumber,
1224 vnode->uniquifier, vnode->dataVersion);
1225 if (!VALID_INO(ino)) {
1226 perror("unable to allocate inode");
1227 Log("1 Volser: ReadVnodes: Restore aborted\n");
1228 return VOLSERREAD_DUMPERROR;
1231 VNDISK_SET_INO(vnode, ino);
1232 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1233 fdP = IH_OPEN(tmpH);
1236 return VOLSERREAD_DUMPERROR;
1239 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1240 VNDISK_SET_LEN(vnode, vnodeLength);
1241 FDH_REALLYCLOSE(fdP);
1244 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1245 (afs_uintmax_t) ino);
1246 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1247 return VOLSERREAD_DUMPERROR;
1254 class = vnodeIdToClass(vnodeNumber);
1255 vcp = &VnodeClassInfo[class];
1257 /* Mark this vnode as in this dump - so we don't delete it later */
1259 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1260 if (class == vLarge) {
1261 if (Lbuf && (idx < s1))
1264 if (Sbuf && (idx < s2))
1270 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1272 Log("1 Volser: ReadVnodes: Error opening vnode index; restore aborted\n");
1273 return VOLSERREAD_DUMPERROR;
1275 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1277 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1278 FDH_REALLYCLOSE(fdP);
1279 return VOLSERREAD_DUMPERROR;
1281 if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) ==
1283 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1284 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1288 vnode->vnodeMagic = vcp->magic;
1289 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1291 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1292 FDH_REALLYCLOSE(fdP);
1293 return VOLSERREAD_DUMPERROR;
1295 if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
1296 Log("1 Volser: ReadVnodes: Error writing vnode index; restore aborted\n");
1297 FDH_REALLYCLOSE(fdP);
1298 return VOLSERREAD_DUMPERROR;
1303 iod_ungetc(iodp, tag);
1309 /* called with disk file only. Note that we don't have to worry about rx_Read
1310 * needing to read an ungetc'd character, since the ReadInt32 will have read
1314 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1319 afs_fsize_t filesize;
1320 afs_fsize_t written = 0;
1321 register afs_uint32 size = 8192;
1322 register afs_fsize_t nbytes;
1327 #ifdef AFS_64BIT_ENV
1329 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1330 #ifdef AFS_LARGEFILE_ENV
1332 if (!ReadInt32(iodp, &filesize_high)) {
1337 #endif /* !AFS_LARGEFILE_ENV */
1338 if (!ReadInt32(iodp, &filesize_low)) {
1342 FillInt64(filesize, filesize_high, filesize_low);
1344 #else /* !AFS_64BIT_ENV */
1345 if (!ReadInt32(iodp, &filesize)) {
1349 #endif /* !AFS_64BIT_ENV */
1350 p = (unsigned char *)malloc(size);
1355 for (nbytes = filesize; nbytes; nbytes -= size) {
1359 if ((code = iod_Read(iodp, p, size)) != size) {
1360 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);
1364 lcode = FDH_WRITE(handleP, p, size);
1367 if (lcode != size) {
1368 Log("1 Volser: WriteFile: Error writing (%d,%u) bytes to vnode %d; restore aborted\n", (int)(lcode>>32), (int)(lcode & 0xffffffff), vn);
1378 ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp)
1381 afs_uint32 beginMagic;
1382 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1383 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1384 || beginMagic != DUMPBEGINMAGIC)
1388 while ((tag = iod_getc(iodp)) > D_MAX) {
1389 unsigned short arrayLength;
1393 if (!ReadInt32(iodp, &hp->volumeId))
1397 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1400 if (!ReadShort(iodp, &arrayLength))
1402 hp->nDumpTimes = (arrayLength >> 1);
1403 for (i = 0; i < hp->nDumpTimes; i++)
1404 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1405 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1410 if (!hp->volumeId || !hp->nDumpTimes) {
1413 iod_ungetc(iodp, tag);
1418 /* ----- Below are the calls that calculate dump size ----- */
1421 SizeDumpVolumeHeader(register struct iod *iodp, register Volume * vp,
1422 register struct volintSize *v_size)
1425 static char nullString[1] = ""; /*The ``contents'' of motd */
1428 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1429 FillInt64(addvar,0, 1);
1430 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1431 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1432 FillInt64(addvar,0, 5);
1433 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1434 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1435 FillInt64(addvar,0, 5);
1436 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1437 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1438 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1439 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1440 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1441 FillInt64(addvar,0, 2);
1442 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1443 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1444 FillInt64(addvar,0, 2);
1445 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1446 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1447 FillInt64(addvar,0, 5);
1448 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1449 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1450 FillInt64(addvar,0, 2);
1451 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1452 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1453 FillInt64(addvar,0, 5);
1454 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1455 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1456 FillInt64(addvar,0, 5);
1457 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1458 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1459 FillInt64(addvar,0, 5);
1460 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1461 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1462 FillInt64(addvar,0, 5);
1463 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1464 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1465 FillInt64(addvar,0, 5);
1466 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1467 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1468 FillInt64(addvar,0, 5);
1469 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1470 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1471 FillInt64(addvar,0, 5);
1472 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1473 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1474 FillInt64(addvar,0, 5);
1475 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1476 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1477 FillInt64(addvar,0, 5);
1478 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1479 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1480 FillInt64(addvar,0, 5);
1481 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1482 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1483 FillInt64(addvar,0, 5);
1484 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1485 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1486 FillInt64(addvar,0, 5);
1487 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1488 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1489 FillInt64(addvar,0, 5);
1490 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1491 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1492 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1493 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1495 /* * We do NOT dump the detailed volume statistics residing in the old */
1496 /* * motd field, since we cannot tell from the info in a dump whether */
1497 /* * statistics data has been put there. Instead, we dump a null string, */
1498 /* * just as if that was what the motd contained. */
1500 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1501 FillInt64(addvar,0, (2 + strlen(nullString)));
1502 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1503 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1504 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1505 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1506 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1507 FillInt64(addvar,0, 5);
1508 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1509 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1510 FillInt64(addvar,0, 5);
1511 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1512 /* if (!code) code = DumpInt32(iodp, 'V', V_volUpCounter(vp)); */
1513 FillInt64(addvar,0, 5);
1514 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1519 SizeDumpEnd(register struct iod *iodp, register struct volintSize *v_size)
1523 FillInt64(addvar,0, 5);
1524 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1529 SizeDumpVolume(register struct rx_call *call, register Volume * vp,
1530 afs_int32 fromtime, int dumpAllDirs,
1531 register struct volintSize *v_size)
1534 register struct iod *iodp = (struct iod *)0;
1535 /* iod_Init(iodp, call); */
1538 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1540 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1542 code = SizeDumpEnd(iodp, v_size);
1548 SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
1549 afs_int32 fromtime, register struct volintSize *v_size)
1552 int UseLatestReadOnlyClone = 1;
1553 /* afs_int32 dumpTimes[2]; */
1555 /* iodp->device = vp->device; */
1556 /* iodp->parentId = V_parentId(vp); */
1557 /* iodp->dumpPartition = vp->partition; */
1559 ZeroInt64(v_size->dump_size); /* initialize the size */
1560 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1561 FillInt64(addvar,0, 9);
1562 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1563 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1564 FillInt64(addvar,0, 5);
1565 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1566 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1567 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1568 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1569 /* dumpTimes[0] = fromtime; */
1570 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1571 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1572 FillInt64(addvar,0, (3 + 4 * 2));
1573 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1578 SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
1579 int vnodeNumber, int dumpEverything,
1580 register struct volintSize *v_size)
1585 if (!v || v->type == vNull)
1587 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1588 FillInt64(addvar,0, 9);
1589 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1590 if (!dumpEverything)
1592 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1593 FillInt64(addvar,0, 2);
1594 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1595 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1596 FillInt64(addvar,0, 3);
1597 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1598 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1599 FillInt64(addvar,0, 5);
1600 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1601 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1602 FillInt64(addvar,0, 5);
1603 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1604 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1605 FillInt64(addvar,0, 5);
1606 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1607 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1608 FillInt64(addvar,0, 5);
1609 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1610 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1612 FillInt64(addvar,0, 5);
1613 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1615 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1616 FillInt64(addvar,0, 3);
1617 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1618 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1619 FillInt64(addvar,0, 5);
1620 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1621 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1622 FillInt64(addvar,0, 5);
1623 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1624 if (v->type == vDirectory) {
1625 /* acl_HtonACL(VVnodeDiskACL(v)); */
1626 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1627 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1628 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1631 if (VNDISK_GET_INO(v)) {
1632 FillInt64(addvar,0, (v->length + 5));
1633 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1638 /* A partial dump (no dump header) */
1640 SizeDumpPartial(register struct iod *iodp, register Volume * vp,
1641 afs_int32 fromtime, int dumpAllDirs,
1642 register struct volintSize *v_size)
1646 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1649 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1652 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1657 SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
1658 afs_int32 fromtime, int forcedump,
1659 register struct volintSize *v_size)
1661 register int code = 0;
1662 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1663 char buf[SIZEOF_LARGEDISKVNODE];
1664 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1665 StreamHandle_t *file;
1669 register int vnodeIndex, nVnodes;
1671 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1672 assert(fdP != NULL);
1673 file = FDH_FDOPEN(fdP, "r+");
1674 assert(file != NULL);
1675 size = OS_SIZE(fdP->fd_fd);
1677 nVnodes = (size / vcp->diskSize) - 1;
1679 assert((nVnodes + 1) * vcp->diskSize == size);
1680 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
1683 for (vnodeIndex = 0;
1684 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1685 nVnodes--, vnodeIndex++) {
1686 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1687 /* Note: the >= test is very important since some old volumes may not have
1688 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1689 * does dump the file! */
1692 SizeDumpVnode(iodp, vnode, V_id(vp),
1693 bitNumberToVnodeNumber(vnodeIndex, class), flag,