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 DiskPartition64 *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;
524 afs_foff_t lcode = 0;
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;
563 howMany = status.st_blksize;
564 #endif /* AFS_AIX_ENV */
565 #endif /* AFS_NT40_ENV */
568 size = FDH_SIZE(handleP);
569 #ifdef AFS_LARGEFILE_ENV
572 SplitInt64(size, hi, lo);
574 code = DumpInt32(iodp, 'f', lo);
576 code = DumpDouble(iodp, 'h', hi, lo);
579 #else /* !AFS_LARGEFILE_ENV */
580 code = DumpInt32(iodp, 'f', size);
581 #endif /* !AFS_LARGEFILE_ENV */
583 return VOLSERDUMPERROR;
586 p = (unsigned char *)malloc((size_t)howMany);
588 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", howMany);
589 return VOLSERDUMPERROR;
592 for (nbytes = size; (nbytes && !error); nbytes -= howMany) {
593 if (nbytes < howMany)
596 /* Read the data - unless we know we can't */
597 n = (lcode ? 0 : FDH_READ(handleP, p, (size_t)howMany));
599 /* If read any good data and we null padded previously, log the
600 * amount that we had null padded.
602 if ((n > 0) && pad) {
603 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", pad, offset);
607 /* If didn't read enough data, null padd the rest of the buffer. This
608 * can happen if, for instance, the media has some bad spots. We don't
609 * want to quit the dump, so we start null padding.
612 /* Record the read error */
615 Log("1 Volser: DumpFile: Error %d reading inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
617 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
620 /* Pad the rest of the buffer with zeros. Remember offset we started
621 * padding. Keep total tally of padding.
623 memset(p + n, 0, howMany - n);
625 offset = (howBig - nbytes) + n;
626 pad += (howMany - n);
628 /* Now seek over the data we could not get. An error here means we
629 * can't do the next read.
631 lcode = FDH_SEEK(handleP, (size_t)((size - nbytes) + howMany), SEEK_SET);
632 if (lcode != ((size - nbytes) + howMany)) {
634 Log("1 Volser: DumpFile: Error %d seeking in inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
636 Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
644 /* Now write the data out */
645 if (iod_Write(iodp, (char *)p, (size_t)howMany) != howMany)
646 error = VOLSERDUMPERROR;
647 #ifndef AFS_PTHREAD_ENV
652 if (pad) { /* Any padding we hadn't reported yet */
653 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n",
662 DumpVolumeHeader(register struct iod *iodp, register Volume * vp)
665 static char nullString[1] = ""; /*The ``contents'' of motd */
668 code = DumpTag(iodp, D_VOLUMEHEADER);
670 code = DumpInt32(iodp, 'i', V_id(vp));
673 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
675 code = DumpString(iodp, 'n', V_name(vp));
677 code = DumpBool(iodp, 's', V_inService(vp));
679 code = DumpBool(iodp, 'b', V_blessed(vp));
681 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
683 code = DumpByte(iodp, 't', (byte) V_type(vp));
685 code = DumpInt32(iodp, 'p', V_parentId(vp));
688 code = DumpInt32(iodp, 'c', V_cloneId(vp));
690 code = DumpInt32(iodp, 'q', V_maxquota(vp));
692 code = DumpInt32(iodp, 'm', V_minquota(vp));
694 code = DumpInt32(iodp, 'd', V_diskused(vp));
696 code = DumpInt32(iodp, 'f', V_filecount(vp));
698 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
700 code = DumpInt32(iodp, 'o', V_owner(vp));
702 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
704 code = DumpInt32(iodp, 'A', V_accessDate(vp));
706 code = DumpInt32(iodp, 'U', V_updateDate(vp));
708 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
710 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
712 code = DumpString(iodp, 'O', V_offlineMessage(vp));
714 * We do NOT dump the detailed volume statistics residing in the old
715 * motd field, since we cannot tell from the info in a dump whether
716 * statistics data has been put there. Instead, we dump a null string,
717 * just as if that was what the motd contained.
720 code = DumpString(iodp, 'M', nullString);
723 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
724 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
726 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
728 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
730 code = DumpInt32(iodp, 'V', V_volUpCounter(vp));
735 DumpEnd(register struct iod *iodp)
737 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
740 /* Guts of the dump code */
742 /* Dump a whole volume */
744 DumpVolume(register struct rx_call *call, register Volume * vp,
745 afs_int32 fromtime, int dumpAllDirs)
749 register struct iod *iodp = &iod;
750 iod_Init(iodp, call);
753 code = DumpDumpHeader(iodp, vp, fromtime);
756 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
758 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
759 if (rx_Error(iodp->call)) {
760 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
761 rx_Error(iodp->call));
762 return VOLSERDUMPERROR;
765 code = DumpEnd(iodp);
770 /* Dump a volume to multiple places*/
772 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
773 afs_int32 fromtime, int dumpAllDirs, int *codes)
777 iod_InitMulti(&iod, calls, ncalls, codes);
780 code = DumpDumpHeader(&iod, vp, fromtime);
782 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
784 code = DumpEnd(&iod);
788 /* A partial dump (no dump header) */
790 DumpPartial(register struct iod *iodp, register Volume * vp,
791 afs_int32 fromtime, int dumpAllDirs)
795 code = DumpVolumeHeader(iodp, vp);
797 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
799 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
804 DumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
805 afs_int32 fromtime, int forcedump)
807 register int code = 0;
808 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
809 char buf[SIZEOF_LARGEDISKVNODE];
810 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
811 StreamHandle_t *file;
815 register int vnodeIndex, nVnodes;
817 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
819 file = FDH_FDOPEN(fdP, "r+");
820 assert(file != NULL);
821 size = OS_SIZE(fdP->fd_fd);
823 nVnodes = (size / vcp->diskSize) - 1;
825 assert((nVnodes + 1) * vcp->diskSize == size);
826 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
830 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
831 nVnodes--, vnodeIndex++) {
832 flag = forcedump || (vnode->serverModifyTime >= fromtime);
833 /* Note: the >= test is very important since some old volumes may not have
834 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
835 * does dump the file! */
838 DumpVnode(iodp, vnode, V_id(vp),
839 bitNumberToVnodeNumber(vnodeIndex, class), flag);
840 #ifndef AFS_PTHREAD_ENV
842 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
851 DumpDumpHeader(register struct iod *iodp, register Volume * vp,
855 int UseLatestReadOnlyClone = 1;
856 afs_int32 dumpTimes[2];
857 iodp->device = vp->device;
858 iodp->parentId = V_parentId(vp);
859 iodp->dumpPartition = vp->partition;
861 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
865 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
867 code = DumpString(iodp, 'n', V_name(vp));
868 dumpTimes[0] = fromtime;
869 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
871 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
876 DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
877 int vnodeNumber, int dumpEverything)
883 if (!v || v->type == vNull)
886 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
890 code = DumpByte(iodp, 't', (byte) v->type);
892 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
894 code = DumpInt32(iodp, 'v', v->dataVersion);
896 code = DumpInt32(iodp, 'm', v->unixModifyTime);
898 code = DumpInt32(iodp, 'a', v->author);
900 code = DumpInt32(iodp, 'o', v->owner);
901 if (!code && v->group)
902 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
904 code = DumpShort(iodp, 'b', v->modeBits);
906 code = DumpInt32(iodp, 'p', v->parent);
908 code = DumpInt32(iodp, 's', v->serverModifyTime);
909 if (v->type == vDirectory) {
910 acl_HtonACL(VVnodeDiskACL(v));
913 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
916 if (VNDISK_GET_INO(v)) {
917 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
920 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);
922 return VOLSERREAD_DUMPERROR;
924 code = DumpFile(iodp, vnodeNumber, fdP);
933 ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep,
936 int i, nVnodes, offset, code, index = 0;
940 StreamHandle_t *afile;
942 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
943 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
944 register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
946 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
947 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
950 afile = FDH_FDOPEN(fdP, "r+");
954 for (i = 0; i < *sizep; i++) {
957 STREAM_SEEK(afile, Buf[i], 0);
958 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
960 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
963 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
964 V_id(vp), bitNumberToVnodeNumber(i, class),
965 (afs_uintmax_t) VNDISK_GET_INO(vnode));
967 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
971 STREAM_SEEK(afile, Buf[i], 0);
972 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
978 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
981 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
982 OS_SYNC(afile->str_fd);
984 size = OS_SIZE(fdP->fd_fd);
988 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
991 Log("RestoreVolume ProcessIndex: Set up %d inodes for volume %d\n",
994 Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32));
1000 memset((char *)Buf, 0, nVnodes * sizeof(afs_int32));
1001 STREAM_SEEK(afile, offset = vcp->diskSize, 0);
1003 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1007 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1008 Buf[(offset >> vcp->logSize) - 1] = offset;
1011 offset += vcp->diskSize;
1014 Log("RestoreVolume ProcessIndex: found %d inodes\n", cnt);
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);
1045 if (!ReadDumpHeader(iodp, &header)) {
1046 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1047 return VOLSERREAD_DUMPERROR;
1049 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1050 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1051 return VOLSERREAD_DUMPERROR;
1053 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1054 return VOLSERREAD_DUMPERROR;
1057 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1059 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1061 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1062 error = VOLSERREAD_DUMPERROR;
1066 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1067 vol.type = cookie->type;
1068 vol.cloneId = cookie->clone;
1069 vol.parentId = cookie->parent;
1073 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1074 error = VOLSERREAD_DUMPERROR;
1077 tag = iod_getc(iodp);
1078 if (tag != D_VOLUMEHEADER)
1081 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1082 error = VOLSERREAD_DUMPERROR;
1086 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1087 || endMagic != DUMPENDMAGIC) {
1088 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1089 error = VOLSERREAD_DUMPERROR;
1094 if (iod_getc(iodp) != EOF) {
1095 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1096 error = VOLSERREAD_DUMPERROR;
1101 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1103 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1105 error = VOLSERREAD_DUMPERROR;
1111 ClearVolumeStats(&vol);
1112 CopyVolumeHeader(&vol, &V_disk(vp));
1113 V_destroyMe(vp) = 0;
1114 VUpdateVolume(&vupdate, vp);
1116 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1117 error = VOLSERREAD_DUMPERROR;
1121 /* Free the malloced space above */
1130 ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
1131 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2,
1134 afs_int32 vnodeNumber;
1135 char buf[SIZEOF_LARGEDISKVNODE];
1137 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1138 struct VnodeDiskObject oldvnode;
1141 struct VnodeClassInfo *vcp;
1146 tag = iod_getc(iodp);
1147 V_pref(vp, nearInode);
1148 while (tag == D_VNODE) {
1150 memset(buf, 0, sizeof(buf));
1151 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1154 if (!ReadInt32(iodp, &vnode->uniquifier))
1155 return VOLSERREAD_DUMPERROR;
1158 Log("ReadVnodes: setup %d/%d\n", vnodeNumber, vnode->uniquifier);
1160 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1164 vnode->type = (VnodeType) iod_getc(iodp);
1169 if (!ReadShort(iodp, &tlc))
1170 return VOLSERREAD_DUMPERROR;
1171 vnode->linkCount = (signed int)tlc;
1175 if (!ReadInt32(iodp, &vnode->dataVersion))
1176 return VOLSERREAD_DUMPERROR;
1179 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1180 return VOLSERREAD_DUMPERROR;
1183 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1184 return VOLSERREAD_DUMPERROR;
1187 if (!ReadInt32(iodp, &vnode->author))
1188 return VOLSERREAD_DUMPERROR;
1191 if (!ReadInt32(iodp, &vnode->owner))
1192 return VOLSERREAD_DUMPERROR;
1195 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1196 return VOLSERREAD_DUMPERROR;
1199 unsigned short modeBits;
1200 if (!ReadShort(iodp, &modeBits))
1201 return VOLSERREAD_DUMPERROR;
1202 vnode->modeBits = (unsigned int)modeBits;
1206 if (!ReadInt32(iodp, &vnode->parent))
1207 return VOLSERREAD_DUMPERROR;
1210 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1211 VAclDiskSize(vnode));
1212 acl_NtohACL(VVnodeDiskACL(vnode));
1214 #ifdef AFS_LARGEFILE_ENV
1220 afs_fsize_t vnodeLength;
1223 IH_CREATE(V_linkHandle(vp), V_device(vp),
1224 VPartitionPath(V_partition(vp)), nearInode,
1225 V_parentId(vp), vnodeNumber,
1226 vnode->uniquifier, vnode->dataVersion);
1227 if (!VALID_INO(ino)) {
1228 perror("unable to allocate inode");
1229 Log("1 Volser: ReadVnodes: Restore aborted\n");
1230 return VOLSERREAD_DUMPERROR;
1233 VNDISK_SET_INO(vnode, ino);
1234 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1235 fdP = IH_OPEN(tmpH);
1238 return VOLSERREAD_DUMPERROR;
1241 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1242 VNDISK_SET_LEN(vnode, vnodeLength);
1243 FDH_REALLYCLOSE(fdP);
1246 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1247 (afs_uintmax_t) ino);
1248 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1249 return VOLSERREAD_DUMPERROR;
1256 class = vnodeIdToClass(vnodeNumber);
1257 vcp = &VnodeClassInfo[class];
1259 /* Mark this vnode as in this dump - so we don't delete it later */
1261 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1262 if (class == vLarge) {
1263 if (Lbuf && (idx < s1))
1266 if (Sbuf && (idx < s2))
1272 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1274 Log("1 Volser: ReadVnodes: Error opening vnode index; restore aborted\n");
1275 return VOLSERREAD_DUMPERROR;
1277 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1279 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1280 FDH_REALLYCLOSE(fdP);
1281 return VOLSERREAD_DUMPERROR;
1283 if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) ==
1285 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1286 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1290 vnode->vnodeMagic = vcp->magic;
1291 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1293 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1294 FDH_REALLYCLOSE(fdP);
1295 return VOLSERREAD_DUMPERROR;
1297 if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
1298 Log("1 Volser: ReadVnodes: Error writing vnode index; restore aborted\n");
1299 FDH_REALLYCLOSE(fdP);
1300 return VOLSERREAD_DUMPERROR;
1305 iod_ungetc(iodp, tag);
1311 /* called with disk file only. Note that we don't have to worry about rx_Read
1312 * needing to read an ungetc'd character, since the ReadInt32 will have read
1316 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1321 afs_fsize_t filesize;
1322 afs_fsize_t written = 0;
1323 register afs_uint32 size = 8192;
1324 register afs_fsize_t nbytes;
1329 #ifdef AFS_64BIT_ENV
1331 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1332 #ifdef AFS_LARGEFILE_ENV
1334 if (!ReadInt32(iodp, &filesize_high)) {
1339 #endif /* !AFS_LARGEFILE_ENV */
1340 if (!ReadInt32(iodp, &filesize_low)) {
1344 FillInt64(filesize, filesize_high, filesize_low);
1346 #else /* !AFS_64BIT_ENV */
1347 if (!ReadInt32(iodp, &filesize)) {
1351 #endif /* !AFS_64BIT_ENV */
1352 p = (unsigned char *)malloc(size);
1357 for (nbytes = filesize; nbytes; nbytes -= size) {
1361 if ((code = iod_Read(iodp, p, size)) != size) {
1362 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);
1366 lcode = FDH_WRITE(handleP, p, size);
1369 if (lcode != size) {
1370 Log("1 Volser: WriteFile: Error writing (%d,%u) bytes to vnode %d; restore aborted\n", (int)(lcode>>32), (int)(lcode & 0xffffffff), vn);
1380 ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp)
1383 afs_uint32 beginMagic;
1384 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1385 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1386 || beginMagic != DUMPBEGINMAGIC)
1390 while ((tag = iod_getc(iodp)) > D_MAX) {
1391 unsigned short arrayLength;
1395 if (!ReadInt32(iodp, &hp->volumeId))
1399 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1402 if (!ReadShort(iodp, &arrayLength))
1404 hp->nDumpTimes = (arrayLength >> 1);
1405 for (i = 0; i < hp->nDumpTimes; i++)
1406 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1407 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1412 if (!hp->volumeId || !hp->nDumpTimes) {
1415 iod_ungetc(iodp, tag);
1420 /* ----- Below are the calls that calculate dump size ----- */
1423 SizeDumpVolumeHeader(register struct iod *iodp, register Volume * vp,
1424 register struct volintSize *v_size)
1427 static char nullString[1] = ""; /*The ``contents'' of motd */
1430 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1431 FillInt64(addvar,0, 1);
1432 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1433 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1434 FillInt64(addvar,0, 5);
1435 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1436 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1437 FillInt64(addvar,0, 5);
1438 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1439 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1440 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1441 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1442 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1443 FillInt64(addvar,0, 2);
1444 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1445 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1446 FillInt64(addvar,0, 2);
1447 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1448 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1449 FillInt64(addvar,0, 5);
1450 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1451 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1452 FillInt64(addvar,0, 2);
1453 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1454 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1455 FillInt64(addvar,0, 5);
1456 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1457 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1458 FillInt64(addvar,0, 5);
1459 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1460 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1461 FillInt64(addvar,0, 5);
1462 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1463 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1464 FillInt64(addvar,0, 5);
1465 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1466 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1467 FillInt64(addvar,0, 5);
1468 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1469 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1470 FillInt64(addvar,0, 5);
1471 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1472 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1473 FillInt64(addvar,0, 5);
1474 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1475 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1476 FillInt64(addvar,0, 5);
1477 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1478 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1479 FillInt64(addvar,0, 5);
1480 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1481 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1482 FillInt64(addvar,0, 5);
1483 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1484 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1485 FillInt64(addvar,0, 5);
1486 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1487 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1488 FillInt64(addvar,0, 5);
1489 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1490 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1491 FillInt64(addvar,0, 5);
1492 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1493 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1494 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1495 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1497 /* * We do NOT dump the detailed volume statistics residing in the old */
1498 /* * motd field, since we cannot tell from the info in a dump whether */
1499 /* * statistics data has been put there. Instead, we dump a null string, */
1500 /* * just as if that was what the motd contained. */
1502 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1503 FillInt64(addvar,0, (2 + strlen(nullString)));
1504 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1505 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1506 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1507 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1508 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1509 FillInt64(addvar,0, 5);
1510 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1511 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1512 FillInt64(addvar,0, 5);
1513 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1514 /* if (!code) code = DumpInt32(iodp, 'V', V_volUpCounter(vp)); */
1515 FillInt64(addvar,0, 5);
1516 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1521 SizeDumpEnd(register struct iod *iodp, register struct volintSize *v_size)
1525 FillInt64(addvar,0, 5);
1526 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1531 SizeDumpVolume(register struct rx_call *call, register Volume * vp,
1532 afs_int32 fromtime, int dumpAllDirs,
1533 register struct volintSize *v_size)
1536 register struct iod *iodp = (struct iod *)0;
1537 /* iod_Init(iodp, call); */
1540 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1542 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1544 code = SizeDumpEnd(iodp, v_size);
1550 SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
1551 afs_int32 fromtime, register struct volintSize *v_size)
1554 int UseLatestReadOnlyClone = 1;
1555 /* afs_int32 dumpTimes[2]; */
1557 /* iodp->device = vp->device; */
1558 /* iodp->parentId = V_parentId(vp); */
1559 /* iodp->dumpPartition = vp->partition; */
1561 ZeroInt64(v_size->dump_size); /* initialize the size */
1562 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1563 FillInt64(addvar,0, 9);
1564 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1565 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1566 FillInt64(addvar,0, 5);
1567 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1568 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1569 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1570 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1571 /* dumpTimes[0] = fromtime; */
1572 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1573 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1574 FillInt64(addvar,0, (3 + 4 * 2));
1575 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1580 SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
1581 int vnodeNumber, int dumpEverything,
1582 register struct volintSize *v_size)
1587 if (!v || v->type == vNull)
1589 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1590 FillInt64(addvar,0, 9);
1591 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1592 if (!dumpEverything)
1594 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1595 FillInt64(addvar,0, 2);
1596 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1597 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1598 FillInt64(addvar,0, 3);
1599 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1600 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1601 FillInt64(addvar,0, 5);
1602 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1603 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1604 FillInt64(addvar,0, 5);
1605 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1606 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1607 FillInt64(addvar,0, 5);
1608 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1609 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1610 FillInt64(addvar,0, 5);
1611 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1612 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1614 FillInt64(addvar,0, 5);
1615 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1617 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1618 FillInt64(addvar,0, 3);
1619 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1620 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1621 FillInt64(addvar,0, 5);
1622 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1623 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1624 FillInt64(addvar,0, 5);
1625 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1626 if (v->type == vDirectory) {
1627 /* acl_HtonACL(VVnodeDiskACL(v)); */
1628 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1629 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1630 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1633 if (VNDISK_GET_INO(v)) {
1634 FillInt64(addvar,0, (v->length + 5));
1635 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1640 /* A partial dump (no dump header) */
1642 SizeDumpPartial(register struct iod *iodp, register Volume * vp,
1643 afs_int32 fromtime, int dumpAllDirs,
1644 register struct volintSize *v_size)
1648 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1651 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1654 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1659 SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
1660 afs_int32 fromtime, int forcedump,
1661 register struct volintSize *v_size)
1663 register int code = 0;
1664 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1665 char buf[SIZEOF_LARGEDISKVNODE];
1666 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1667 StreamHandle_t *file;
1671 register int vnodeIndex, nVnodes;
1673 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1674 assert(fdP != NULL);
1675 file = FDH_FDOPEN(fdP, "r+");
1676 assert(file != NULL);
1677 size = OS_SIZE(fdP->fd_fd);
1679 nVnodes = (size / vcp->diskSize) - 1;
1681 assert((nVnodes + 1) * vcp->diskSize == size);
1682 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
1685 for (vnodeIndex = 0;
1686 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1687 nVnodes--, vnodeIndex++) {
1688 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1689 /* Note: the >= test is very important since some old volumes may not have
1690 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1691 * does dump the file! */
1694 SizeDumpVnode(iodp, vnode, V_id(vp),
1695 bitNumberToVnodeNumber(vnodeIndex, class), flag,