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>
14 #include <sys/types.h>
22 #include <sys/param.h>
25 #include <netinet/in.h>
29 #ifdef AFS_PTHREAD_ENV
31 #else /* AFS_PTHREAD_ENV */
32 #include <afs/assert.h>
33 #endif /* AFS_PTHREAD_ENV */
36 #include <afs/afsint.h>
38 #include <afs/errors.h>
41 #include <afs/ihandle.h>
42 #include <afs/vnode.h>
43 #include <afs/volume.h>
44 #include <afs/partition.h>
46 #include <afs/daemon_com.h>
47 #include <afs/fssync.h>
54 #define afs_stat stat64
55 #define afs_fstat fstat64
56 #else /* !O_LARGEFILE */
58 #define afs_fstat fstat
59 #endif /* !O_LARGEFILE */
60 #endif /* !AFS_NT40_ENV */
62 /*@printflike@*/ extern void Log(const char *format, ...);
66 /* This iod stuff is a silly little package to emulate the old qi_in stuff, which
67 emulated the stdio stuff. There is a big assumption here, that the
68 rx_Read will never be called directly, by a routine like readFile, when
69 there is an old character that was pushed back with iod_ungetc. This
70 is really bletchy, and is here for compatibility only. Eventually,
71 we should define a volume format that doesn't require
72 the pushing back of characters (i.e. characters should not double both
73 as an end marker and a begin marker) */
75 struct rx_call *call; /* call to which to write, might be an array */
76 int device; /* dump device ID for volume */
77 int parentId; /* dump parent ID for volume */
78 struct DiskPartition64 *dumpPartition; /* Dump partition. */
79 struct rx_call **calls; /* array of pointers to calls */
80 int ncalls; /* how many calls/codes in array */
81 int *codes; /* one return code for each call */
82 char haveOldChar; /* state for pushing back a character */
87 /* Forward Declarations */
88 static int DumpDumpHeader(register struct iod *iodp, register Volume * vp,
90 static int DumpPartial(register struct iod *iodp, register Volume * vp,
91 afs_int32 fromtime, int dumpAllDirs);
92 static int DumpVnodeIndex(register struct iod *iodp, Volume * vp,
93 VnodeClass class, afs_int32 fromtime,
95 static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
96 int volid, int vnodeNumber, int dumpEverything);
97 static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp);
98 static int ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
99 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf,
100 afs_int32 s2, afs_int32 delo);
101 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
102 FdHandle_t * handleP, int tag,
105 static int SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
107 register struct volintSize *size);
108 static int SizeDumpPartial(register struct iod *iodp, register Volume * vp,
109 afs_int32 fromtime, int dumpAllDirs,
110 register struct volintSize *size);
111 static int SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp,
112 VnodeClass class, afs_int32 fromtime,
114 register struct volintSize *size);
115 static int SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
116 int volid, int vnodeNumber, int dumpEverything,
117 register struct volintSize *size);
120 iod_Init(register struct iod *iodp, register struct rx_call *call)
123 iodp->haveOldChar = 0;
125 iodp->calls = (struct rx_call **)0;
129 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
134 iodp->haveOldChar = 0;
135 iodp->ncalls = ncalls;
137 iodp->call = (struct rx_call *)0;
140 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
141 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
143 /* For the single dump case, it's ok to just return the "bytes written"
144 * that rx_Write returns, since all the callers of iod_Write abort when
145 * the returned value is less than they expect. For the multi dump case,
146 * I don't think we want half the replicas to go bad just because one
147 * connection timed out, but if they all time out, then we should give up.
150 iod_Write(struct iod *iodp, char *buf, int nbytes)
155 assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
156 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
159 code = rx_Write(iodp->call, buf, nbytes);
163 for (i = 0; i < iodp->ncalls; i++) {
164 if (iodp->calls[i] && !iodp->codes[i]) {
165 code = rx_Write(iodp->calls[i], buf, nbytes);
166 if (code != nbytes) { /* everything gets merged into a single error */
167 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
168 } /* standard dump does, anyways */
173 } /* for all calls */
182 iod_ungetc(struct iod *iodp, int achar)
184 iodp->oldChar = achar;
185 iodp->haveOldChar = 1;
189 iod_getc(register struct iod *iodp)
193 if (iodp->haveOldChar) {
194 iodp->haveOldChar = 0;
195 return iodp->oldChar;
197 if (iod_Read(iodp, &t, 1) == 1)
203 ReadShort(register struct iod *iodp, register unsigned short *sp)
212 *sp = (b1 << 8) | b0;
217 ReadInt32(register struct iod *iodp, afs_uint32 * lp)
219 afs_uint32 register b3, b2, b1, b0;
232 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
237 ReadString(register struct iod *iodp, register char *to, register int maxa)
247 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
251 while ((c = iod_getc(iodp)) && c != EOF);
257 ReadByteString(register struct iod *iodp, register byte * to,
261 *to++ = iod_getc(iodp);
265 ReadVolumeHeader(register struct iod *iodp, VolumeDiskData * vol)
269 memset(vol, 0, sizeof(*vol));
270 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
273 if (!ReadInt32(iodp, &vol->id))
274 return VOLSERREAD_DUMPERROR;
277 if (!ReadInt32(iodp, &trash))
278 return VOLSERREAD_DUMPERROR;
281 ReadString(iodp, vol->name, sizeof(vol->name));
282 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
285 vol->inService = iod_getc(iodp);
288 vol->blessed = iod_getc(iodp);
291 if (!ReadInt32(iodp, &vol->uniquifier))
292 return VOLSERREAD_DUMPERROR;
295 vol->type = iod_getc(iodp);
298 if (!ReadInt32(iodp, &vol->parentId))
299 return VOLSERREAD_DUMPERROR;
302 if (!ReadInt32(iodp, &vol->cloneId))
303 return VOLSERREAD_DUMPERROR;
306 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
307 return VOLSERREAD_DUMPERROR;
310 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
311 return VOLSERREAD_DUMPERROR;
314 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
315 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
318 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
319 return VOLSERREAD_DUMPERROR;
322 if (!ReadInt32(iodp, &vol->accountNumber))
323 return VOLSERREAD_DUMPERROR;
326 if (!ReadInt32(iodp, &vol->owner))
327 return VOLSERREAD_DUMPERROR;
330 if (!ReadInt32(iodp, &vol->creationDate))
331 return VOLSERREAD_DUMPERROR;
334 if (!ReadInt32(iodp, &vol->accessDate))
335 return VOLSERREAD_DUMPERROR;
338 if (!ReadInt32(iodp, &vol->updateDate))
339 return VOLSERREAD_DUMPERROR;
342 if (!ReadInt32(iodp, &vol->expirationDate))
343 return VOLSERREAD_DUMPERROR;
346 if (!ReadInt32(iodp, &vol->backupDate))
347 return VOLSERREAD_DUMPERROR;
350 ReadString(iodp, vol->offlineMessage,
351 sizeof(vol->offlineMessage));
355 * Detailed volume statistics are never stored in dumps,
356 * so we just restore either the null string if this volume
357 * had already been set to store statistics, or the old motd
358 * contents otherwise. It doesn't matter, since this field
359 * will soon get initialized anyway.
361 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
364 unsigned short length;
367 if (!ReadShort(iodp, &length))
368 return VOLSERREAD_DUMPERROR;
369 for (i = 0; i < length; i++) {
370 if (!ReadInt32(iodp, &data))
371 return VOLSERREAD_DUMPERROR;
372 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
373 vol->weekUse[i] = data;
378 if (!ReadInt32(iodp, &vol->dayUseDate))
379 return VOLSERREAD_DUMPERROR;
382 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
383 return VOLSERREAD_DUMPERROR;
386 if (!ReadInt32(iodp, (afs_uint32 *) &trash/*volUpdateCounter*/))
387 return VOLSERREAD_DUMPERROR;
391 iod_ungetc(iodp, tag);
396 DumpTag(register struct iod *iodp, register int tag)
401 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
406 DumpByte(register struct iod *iodp, char tag, byte value)
409 register byte *p = (unsigned char *)tbuffer;
412 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
415 #define putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
416 #define putshort(p, v) *p++ = v>>8, *p++ = v
419 DumpDouble(register struct iod *iodp, char tag, register afs_uint32 value1,
420 register afs_uint32 value2)
423 register byte *p = (unsigned char *)tbuffer;
427 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
431 DumpInt32(register struct iod *iodp, char tag, register afs_uint32 value)
434 register byte *p = (unsigned char *)tbuffer;
437 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
441 DumpArrayInt32(register struct iod *iodp, char tag,
442 register afs_uint32 * array, register int nelem)
445 register afs_uint32 v;
447 register byte *p = (unsigned char *)tbuffer;
450 code = iod_Write(iodp, tbuffer, 3);
452 return VOLSERDUMPERROR;
454 p = (unsigned char *)tbuffer;
455 v = *array++; /*this was register */
458 code = iod_Write(iodp, tbuffer, 4);
460 return VOLSERDUMPERROR;
466 DumpShort(register struct iod *iodp, char tag, unsigned int value)
469 register byte *p = (unsigned char *)tbuffer;
473 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
477 DumpBool(register struct iod *iodp, char tag, unsigned int value)
480 register byte *p = (unsigned char *)tbuffer;
483 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
487 DumpString(register struct iod *iodp, char tag, register char *s)
491 code = iod_Write(iodp, &tag, 1);
493 return VOLSERDUMPERROR;
495 code = iod_Write(iodp, s, n);
497 return VOLSERDUMPERROR;
502 DumpByteString(register struct iod *iodp, char tag, register byte * bs,
507 code = iod_Write(iodp, &tag, 1);
509 return VOLSERDUMPERROR;
510 code = iod_Write(iodp, (char *)bs, nbytes);
512 return VOLSERDUMPERROR;
517 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
519 int code = 0, error = 0;
521 afs_int32 offset = 0;
522 afs_sfsize_t n, nbytes, howMany, howBig;
523 afs_foff_t lcode = 0;
526 struct afs_stat status;
530 #include <sys/statfs.h>
531 #if defined(AFS_AIX52_ENV) && defined(AFS_LARGEFILE_ENV)
532 struct statfs64 tstatfs;
533 #else /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
534 struct statfs tstatfs;
535 #endif /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
540 howBig = _filelength(handleP->fd_fd);
544 afs_fstat(handleP->fd_fd, &status);
545 howBig = status.st_size;
548 /* Unfortunately in AIX valuable fields such as st_blksize are
549 * gone from the stat structure.
551 #if defined(AFS_AIX52_ENV) && defined(AFS_LARGEFILE_ENV)
552 statfs_code = fstatfs64(handleP->fd_fd, &tstatfs);
553 #else /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
554 statfs_code = fstatfs(handleP->fd_fd, &tstatfs);
555 #endif /* !AFS_AIX52_ENV || !AFS_LARGEFILE_ENV */
556 if (statfs_code != 0) {
557 Log("DumpFile: fstatfs returned error code %d on descriptor %d\n", errno, handleP->fd_fd);
558 return VOLSERDUMPERROR;
560 howMany = (afs_sfsize_t) tstatfs.f_bsize;
562 howMany = status.st_blksize;
563 #endif /* AFS_AIX_ENV */
564 #endif /* AFS_NT40_ENV */
567 size = FDH_SIZE(handleP);
568 #ifdef AFS_LARGEFILE_ENV
571 SplitInt64(size, hi, lo);
573 code = DumpInt32(iodp, 'f', lo);
575 code = DumpDouble(iodp, 'h', hi, lo);
578 #else /* !AFS_LARGEFILE_ENV */
579 code = DumpInt32(iodp, 'f', size);
580 #endif /* !AFS_LARGEFILE_ENV */
582 return VOLSERDUMPERROR;
585 p = (unsigned char *)malloc((size_t)howMany);
587 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", howMany);
588 return VOLSERDUMPERROR;
591 for (nbytes = size; (nbytes && !error); nbytes -= howMany) {
592 if (nbytes < howMany)
595 /* Read the data - unless we know we can't */
596 n = (lcode ? 0 : FDH_READ(handleP, p, (size_t)howMany));
598 /* If read any good data and we null padded previously, log the
599 * amount that we had null padded.
601 if ((n > 0) && pad) {
602 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", pad, offset);
606 /* If didn't read enough data, null padd the rest of the buffer. This
607 * can happen if, for instance, the media has some bad spots. We don't
608 * want to quit the dump, so we start null padding.
611 /* Record the read error */
614 Log("1 Volser: DumpFile: Error %d reading inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
616 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
619 /* Pad the rest of the buffer with zeros. Remember offset we started
620 * padding. Keep total tally of padding.
622 memset(p + n, 0, howMany - n);
624 offset = (howBig - nbytes) + n;
625 pad += (howMany - n);
627 /* Now seek over the data we could not get. An error here means we
628 * can't do the next read.
630 lcode = FDH_SEEK(handleP, (size_t)((size - nbytes) + howMany), SEEK_SET);
631 if (lcode != ((size - nbytes) + howMany)) {
633 Log("1 Volser: DumpFile: Error %d seeking in inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
635 Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
643 /* Now write the data out */
644 if (iod_Write(iodp, (char *)p, (size_t)howMany) != howMany)
645 error = VOLSERDUMPERROR;
646 #ifndef AFS_PTHREAD_ENV
651 if (pad) { /* Any padding we hadn't reported yet */
652 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n",
661 DumpVolumeHeader(register struct iod *iodp, register Volume * vp)
664 static char nullString[1] = ""; /*The ``contents'' of motd */
667 code = DumpTag(iodp, D_VOLUMEHEADER);
669 code = DumpInt32(iodp, 'i', V_id(vp));
672 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
674 code = DumpString(iodp, 'n', V_name(vp));
676 code = DumpBool(iodp, 's', V_inService(vp));
678 code = DumpBool(iodp, 'b', V_blessed(vp));
680 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
682 code = DumpByte(iodp, 't', (byte) V_type(vp));
684 code = DumpInt32(iodp, 'p', V_parentId(vp));
687 code = DumpInt32(iodp, 'c', V_cloneId(vp));
689 code = DumpInt32(iodp, 'q', V_maxquota(vp));
691 code = DumpInt32(iodp, 'm', V_minquota(vp));
693 code = DumpInt32(iodp, 'd', V_diskused(vp));
695 code = DumpInt32(iodp, 'f', V_filecount(vp));
697 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
699 code = DumpInt32(iodp, 'o', V_owner(vp));
701 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
703 code = DumpInt32(iodp, 'A', V_accessDate(vp));
705 code = DumpInt32(iodp, 'U', V_updateDate(vp));
707 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
709 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
711 code = DumpString(iodp, 'O', V_offlineMessage(vp));
713 * We do NOT dump the detailed volume statistics residing in the old
714 * motd field, since we cannot tell from the info in a dump whether
715 * statistics data has been put there. Instead, we dump a null string,
716 * just as if that was what the motd contained.
719 code = DumpString(iodp, 'M', nullString);
722 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
723 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
725 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
727 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
732 DumpEnd(register struct iod *iodp)
734 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
737 /* Guts of the dump code */
739 /* Dump a whole volume */
741 DumpVolume(register struct rx_call *call, register Volume * vp,
742 afs_int32 fromtime, int dumpAllDirs)
746 register struct iod *iodp = &iod;
747 iod_Init(iodp, call);
750 code = DumpDumpHeader(iodp, vp, fromtime);
753 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
755 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
756 if (rx_Error(iodp->call)) {
757 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
758 rx_Error(iodp->call));
759 return VOLSERDUMPERROR;
762 code = DumpEnd(iodp);
767 /* Dump a volume to multiple places*/
769 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
770 afs_int32 fromtime, int dumpAllDirs, int *codes)
774 iod_InitMulti(&iod, calls, ncalls, codes);
777 code = DumpDumpHeader(&iod, vp, fromtime);
779 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
781 code = DumpEnd(&iod);
785 /* A partial dump (no dump header) */
787 DumpPartial(register struct iod *iodp, register Volume * vp,
788 afs_int32 fromtime, int dumpAllDirs)
792 code = DumpVolumeHeader(iodp, vp);
794 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
796 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
801 DumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
802 afs_int32 fromtime, int forcedump)
804 register int code = 0;
805 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
806 char buf[SIZEOF_LARGEDISKVNODE];
807 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
808 StreamHandle_t *file;
812 register int vnodeIndex, nVnodes;
814 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
816 file = FDH_FDOPEN(fdP, "r+");
817 assert(file != NULL);
818 size = OS_SIZE(fdP->fd_fd);
820 nVnodes = (size / vcp->diskSize) - 1;
822 assert((nVnodes + 1) * vcp->diskSize == size);
823 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
827 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
828 nVnodes--, vnodeIndex++) {
829 flag = forcedump || (vnode->serverModifyTime >= fromtime);
830 /* Note: the >= test is very important since some old volumes may not have
831 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
832 * does dump the file! */
835 DumpVnode(iodp, vnode, V_id(vp),
836 bitNumberToVnodeNumber(vnodeIndex, class), flag);
837 #ifndef AFS_PTHREAD_ENV
839 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
848 DumpDumpHeader(register struct iod *iodp, register Volume * vp,
852 int UseLatestReadOnlyClone = 1;
853 afs_int32 dumpTimes[2];
854 iodp->device = vp->device;
855 iodp->parentId = V_parentId(vp);
856 iodp->dumpPartition = vp->partition;
858 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
862 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
864 code = DumpString(iodp, 'n', V_name(vp));
865 dumpTimes[0] = fromtime;
866 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
868 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
873 DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
874 int vnodeNumber, int dumpEverything)
880 if (!v || v->type == vNull)
883 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
887 code = DumpByte(iodp, 't', (byte) v->type);
889 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
891 code = DumpInt32(iodp, 'v', v->dataVersion);
893 code = DumpInt32(iodp, 'm', v->unixModifyTime);
895 code = DumpInt32(iodp, 'a', v->author);
897 code = DumpInt32(iodp, 'o', v->owner);
898 if (!code && v->group)
899 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
901 code = DumpShort(iodp, 'b', v->modeBits);
903 code = DumpInt32(iodp, 'p', v->parent);
905 code = DumpInt32(iodp, 's', v->serverModifyTime);
906 if (v->type == vDirectory) {
907 acl_HtonACL(VVnodeDiskACL(v));
910 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
913 if (VNDISK_GET_INO(v)) {
914 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
917 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);
919 return VOLSERREAD_DUMPERROR;
921 code = DumpFile(iodp, vnodeNumber, fdP);
930 ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep,
933 int i, nVnodes, offset, code, index = 0;
937 StreamHandle_t *afile;
939 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
940 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
941 register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
943 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
944 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
947 afile = FDH_FDOPEN(fdP, "r+");
951 for (i = 0; i < *sizep; i++) {
954 STREAM_SEEK(afile, Buf[i], 0);
955 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
957 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
960 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
961 V_id(vp), bitNumberToVnodeNumber(i, class),
962 (afs_uintmax_t) VNDISK_GET_INO(vnode));
964 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
968 STREAM_SEEK(afile, Buf[i], 0);
969 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
975 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
978 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
979 OS_SYNC(afile->str_fd);
981 size = OS_SIZE(fdP->fd_fd);
985 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
988 Log("RestoreVolume ProcessIndex: Set up %d inodes for volume %d\n",
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;
1011 Log("RestoreVolume ProcessIndex: found %d inodes\n", cnt);
1017 STREAM_CLOSE(afile);
1024 RestoreVolume(register struct rx_call *call, Volume * avp, int incremental,
1025 struct restoreCookie *cookie)
1028 struct DumpHeader header;
1029 afs_uint32 endMagic;
1030 Error error = 0, vupdate;
1031 register Volume *vp;
1033 register struct iod *iodp = &iod;
1034 afs_int32 *b1 = NULL, *b2 = NULL;
1035 int s1 = 0, s2 = 0, delo = 0, tdelo;
1038 iod_Init(iodp, call);
1042 if (!ReadDumpHeader(iodp, &header)) {
1043 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1044 return VOLSERREAD_DUMPERROR;
1046 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1047 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1048 return VOLSERREAD_DUMPERROR;
1050 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1051 return VOLSERREAD_DUMPERROR;
1054 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1056 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1058 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1059 error = VOLSERREAD_DUMPERROR;
1063 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1064 vol.type = cookie->type;
1065 vol.cloneId = cookie->clone;
1066 vol.parentId = cookie->parent;
1070 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1071 error = VOLSERREAD_DUMPERROR;
1074 tag = iod_getc(iodp);
1075 if (tag != D_VOLUMEHEADER)
1078 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1079 error = VOLSERREAD_DUMPERROR;
1083 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1084 || endMagic != DUMPENDMAGIC) {
1085 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1086 error = VOLSERREAD_DUMPERROR;
1091 if (iod_getc(iodp) != EOF) {
1092 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1093 error = VOLSERREAD_DUMPERROR;
1098 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1100 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1102 error = VOLSERREAD_DUMPERROR;
1108 ClearVolumeStats(&vol);
1109 CopyVolumeHeader(&vol, &V_disk(vp));
1110 V_destroyMe(vp) = 0;
1111 VUpdateVolume(&vupdate, vp);
1113 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1114 error = VOLSERREAD_DUMPERROR;
1118 /* Free the malloced space above */
1127 ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
1128 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2,
1131 afs_int32 vnodeNumber;
1132 char buf[SIZEOF_LARGEDISKVNODE];
1134 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1135 struct VnodeDiskObject oldvnode;
1138 struct VnodeClassInfo *vcp;
1143 tag = iod_getc(iodp);
1144 V_pref(vp, nearInode);
1145 while (tag == D_VNODE) {
1147 memset(buf, 0, sizeof(buf));
1148 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1151 if (!ReadInt32(iodp, &vnode->uniquifier))
1152 return VOLSERREAD_DUMPERROR;
1155 Log("ReadVnodes: setup %d/%d\n", vnodeNumber, vnode->uniquifier);
1157 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1161 vnode->type = (VnodeType) iod_getc(iodp);
1166 if (!ReadShort(iodp, &tlc))
1167 return VOLSERREAD_DUMPERROR;
1168 vnode->linkCount = (signed int)tlc;
1172 if (!ReadInt32(iodp, &vnode->dataVersion))
1173 return VOLSERREAD_DUMPERROR;
1176 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1177 return VOLSERREAD_DUMPERROR;
1180 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1181 return VOLSERREAD_DUMPERROR;
1184 if (!ReadInt32(iodp, &vnode->author))
1185 return VOLSERREAD_DUMPERROR;
1188 if (!ReadInt32(iodp, &vnode->owner))
1189 return VOLSERREAD_DUMPERROR;
1192 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1193 return VOLSERREAD_DUMPERROR;
1196 unsigned short modeBits;
1197 if (!ReadShort(iodp, &modeBits))
1198 return VOLSERREAD_DUMPERROR;
1199 vnode->modeBits = (unsigned int)modeBits;
1203 if (!ReadInt32(iodp, &vnode->parent))
1204 return VOLSERREAD_DUMPERROR;
1207 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1208 VAclDiskSize(vnode));
1209 acl_NtohACL(VVnodeDiskACL(vnode));
1211 #ifdef AFS_LARGEFILE_ENV
1217 afs_fsize_t vnodeLength;
1220 IH_CREATE(V_linkHandle(vp), V_device(vp),
1221 VPartitionPath(V_partition(vp)), nearInode,
1222 V_parentId(vp), vnodeNumber,
1223 vnode->uniquifier, vnode->dataVersion);
1224 if (!VALID_INO(ino)) {
1225 Log("1 Volser: ReadVnodes: IH_CREATE: %s - restore aborted\n",
1226 afs_error_message(errno));
1227 return VOLSERREAD_DUMPERROR;
1230 VNDISK_SET_INO(vnode, ino);
1231 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1232 fdP = IH_OPEN(tmpH);
1234 Log("1 Volser: ReadVnodes: IH_OPEN: %s - restore aborted\n",
1235 afs_error_message(errno));
1237 return VOLSERREAD_DUMPERROR;
1240 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1241 VNDISK_SET_LEN(vnode, vnodeLength);
1242 FDH_REALLYCLOSE(fdP);
1245 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1246 (afs_uintmax_t) ino);
1247 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1248 return VOLSERREAD_DUMPERROR;
1255 class = vnodeIdToClass(vnodeNumber);
1256 vcp = &VnodeClassInfo[class];
1258 /* Mark this vnode as in this dump - so we don't delete it later */
1260 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1261 if (class == vLarge) {
1262 if (Lbuf && (idx < s1))
1265 if (Sbuf && (idx < s2))
1271 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1273 Log("1 Volser: ReadVnodes: Error opening vnode index; restore aborted\n");
1274 return VOLSERREAD_DUMPERROR;
1276 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1278 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1279 FDH_REALLYCLOSE(fdP);
1280 return VOLSERREAD_DUMPERROR;
1282 if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) ==
1284 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1285 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1289 vnode->vnodeMagic = vcp->magic;
1290 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1292 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1293 FDH_REALLYCLOSE(fdP);
1294 return VOLSERREAD_DUMPERROR;
1296 if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
1297 Log("1 Volser: ReadVnodes: Error writing vnode index; restore aborted\n");
1298 FDH_REALLYCLOSE(fdP);
1299 return VOLSERREAD_DUMPERROR;
1304 iod_ungetc(iodp, tag);
1310 /* called with disk file only. Note that we don't have to worry about rx_Read
1311 * needing to read an ungetc'd character, since the ReadInt32 will have read
1315 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1320 afs_fsize_t filesize;
1321 afs_fsize_t written = 0;
1322 register afs_uint32 size = 8192;
1323 register afs_fsize_t nbytes;
1328 #ifdef AFS_64BIT_ENV
1330 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1331 #ifdef AFS_LARGEFILE_ENV
1333 if (!ReadInt32(iodp, &filesize_high)) {
1338 #endif /* !AFS_LARGEFILE_ENV */
1339 if (!ReadInt32(iodp, &filesize_low)) {
1343 FillInt64(filesize, filesize_high, filesize_low);
1345 #else /* !AFS_64BIT_ENV */
1346 if (!ReadInt32(iodp, &filesize)) {
1350 #endif /* !AFS_64BIT_ENV */
1351 p = (unsigned char *)malloc(size);
1356 for (nbytes = filesize; nbytes; nbytes -= size) {
1360 if ((code = iod_Read(iodp, p, size)) != size) {
1361 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);
1365 lcode = FDH_WRITE(handleP, p, size);
1368 if (lcode != size) {
1369 Log("1 Volser: WriteFile: Error writing (%d,%u) bytes to vnode %d; restore aborted\n", (int)(lcode>>32), (int)(lcode & 0xffffffff), vn);
1379 ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp)
1382 afs_uint32 beginMagic;
1383 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1384 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1385 || beginMagic != DUMPBEGINMAGIC)
1389 while ((tag = iod_getc(iodp)) > D_MAX) {
1390 unsigned short arrayLength;
1394 if (!ReadInt32(iodp, &hp->volumeId))
1398 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1401 if (!ReadShort(iodp, &arrayLength))
1403 hp->nDumpTimes = (arrayLength >> 1);
1404 for (i = 0; i < hp->nDumpTimes; i++)
1405 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1406 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1411 if (!hp->volumeId || !hp->nDumpTimes) {
1414 iod_ungetc(iodp, tag);
1419 /* ----- Below are the calls that calculate dump size ----- */
1422 SizeDumpVolumeHeader(register struct iod *iodp, register Volume * vp,
1423 register struct volintSize *v_size)
1426 static char nullString[1] = ""; /*The ``contents'' of motd */
1429 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1430 FillInt64(addvar,0, 1);
1431 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1432 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1433 FillInt64(addvar,0, 5);
1434 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1435 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1436 FillInt64(addvar,0, 5);
1437 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1438 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1439 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1440 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1441 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1442 FillInt64(addvar,0, 2);
1443 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1444 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1445 FillInt64(addvar,0, 2);
1446 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1447 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1448 FillInt64(addvar,0, 5);
1449 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1450 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1451 FillInt64(addvar,0, 2);
1452 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1453 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1454 FillInt64(addvar,0, 5);
1455 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1456 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1457 FillInt64(addvar,0, 5);
1458 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1459 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1460 FillInt64(addvar,0, 5);
1461 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1462 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1463 FillInt64(addvar,0, 5);
1464 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1465 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1466 FillInt64(addvar,0, 5);
1467 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1468 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1469 FillInt64(addvar,0, 5);
1470 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1471 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1472 FillInt64(addvar,0, 5);
1473 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1474 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1475 FillInt64(addvar,0, 5);
1476 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1477 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1478 FillInt64(addvar,0, 5);
1479 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1480 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1481 FillInt64(addvar,0, 5);
1482 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1483 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1484 FillInt64(addvar,0, 5);
1485 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1486 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1487 FillInt64(addvar,0, 5);
1488 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1489 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1490 FillInt64(addvar,0, 5);
1491 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1492 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1493 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1494 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1496 /* * We do NOT dump the detailed volume statistics residing in the old */
1497 /* * motd field, since we cannot tell from the info in a dump whether */
1498 /* * statistics data has been put there. Instead, we dump a null string, */
1499 /* * just as if that was what the motd contained. */
1501 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1502 FillInt64(addvar,0, (2 + strlen(nullString)));
1503 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1504 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1505 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1506 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1507 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1508 FillInt64(addvar,0, 5);
1509 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1510 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1511 FillInt64(addvar,0, 5);
1512 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1517 SizeDumpEnd(register struct iod *iodp, register struct volintSize *v_size)
1521 FillInt64(addvar,0, 5);
1522 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1527 SizeDumpVolume(register struct rx_call *call, register Volume * vp,
1528 afs_int32 fromtime, int dumpAllDirs,
1529 register struct volintSize *v_size)
1532 register struct iod *iodp = (struct iod *)0;
1533 /* iod_Init(iodp, call); */
1536 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1538 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1540 code = SizeDumpEnd(iodp, v_size);
1546 SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
1547 afs_int32 fromtime, register struct volintSize *v_size)
1550 int UseLatestReadOnlyClone = 1;
1551 /* afs_int32 dumpTimes[2]; */
1553 /* iodp->device = vp->device; */
1554 /* iodp->parentId = V_parentId(vp); */
1555 /* iodp->dumpPartition = vp->partition; */
1557 ZeroInt64(v_size->dump_size); /* initialize the size */
1558 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1559 FillInt64(addvar,0, 9);
1560 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1561 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1562 FillInt64(addvar,0, 5);
1563 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1564 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1565 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1566 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1567 /* dumpTimes[0] = fromtime; */
1568 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1569 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1570 FillInt64(addvar,0, (3 + 4 * 2));
1571 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1576 SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
1577 int vnodeNumber, int dumpEverything,
1578 register struct volintSize *v_size)
1583 if (!v || v->type == vNull)
1585 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1586 FillInt64(addvar,0, 9);
1587 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1588 if (!dumpEverything)
1590 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1591 FillInt64(addvar,0, 2);
1592 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1593 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1594 FillInt64(addvar,0, 3);
1595 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1596 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1597 FillInt64(addvar,0, 5);
1598 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1599 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1600 FillInt64(addvar,0, 5);
1601 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1602 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1603 FillInt64(addvar,0, 5);
1604 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1605 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1606 FillInt64(addvar,0, 5);
1607 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1608 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1610 FillInt64(addvar,0, 5);
1611 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1613 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1614 FillInt64(addvar,0, 3);
1615 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1616 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1617 FillInt64(addvar,0, 5);
1618 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1619 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1620 FillInt64(addvar,0, 5);
1621 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1622 if (v->type == vDirectory) {
1623 /* acl_HtonACL(VVnodeDiskACL(v)); */
1624 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1625 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1626 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1629 if (VNDISK_GET_INO(v)) {
1630 FillInt64(addvar,0, (v->length + 5));
1631 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1636 /* A partial dump (no dump header) */
1638 SizeDumpPartial(register struct iod *iodp, register Volume * vp,
1639 afs_int32 fromtime, int dumpAllDirs,
1640 register struct volintSize *v_size)
1644 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1647 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1650 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1655 SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
1656 afs_int32 fromtime, int forcedump,
1657 register struct volintSize *v_size)
1659 register int code = 0;
1660 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1661 char buf[SIZEOF_LARGEDISKVNODE];
1662 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1663 StreamHandle_t *file;
1667 register int vnodeIndex, nVnodes;
1669 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1670 assert(fdP != NULL);
1671 file = FDH_FDOPEN(fdP, "r+");
1672 assert(file != NULL);
1673 size = OS_SIZE(fdP->fd_fd);
1675 nVnodes = (size / vcp->diskSize) - 1;
1677 assert((nVnodes + 1) * vcp->diskSize == size);
1678 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
1681 for (vnodeIndex = 0;
1682 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1683 nVnodes--, vnodeIndex++) {
1684 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1685 /* Note: the >= test is very important since some old volumes may not have
1686 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1687 * does dump the file! */
1690 SizeDumpVnode(iodp, vnode, V_id(vp),
1691 bitNumberToVnodeNumber(vnodeIndex, class), flag,