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;
530 afs_foff_t lcode = 0;
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;
569 howMany = status.st_blksize;
570 #endif /* AFS_AIX_ENV */
571 #endif /* AFS_NT40_ENV */
574 size = FDH_SIZE(handleP);
575 #ifdef AFS_LARGEFILE_ENV
578 SplitInt64(size, hi, lo);
580 code = DumpInt32(iodp, 'f', lo);
582 code = DumpDouble(iodp, 'h', hi, lo);
585 #else /* !AFS_LARGEFILE_ENV */
586 code = DumpInt32(iodp, 'f', size);
587 #endif /* !AFS_LARGEFILE_ENV */
589 return VOLSERDUMPERROR;
592 p = (unsigned char *)malloc((size_t)howMany);
594 Log("1 Volser: DumpFile: not enough memory to allocate %u bytes\n", howMany);
595 return VOLSERDUMPERROR;
598 for (nbytes = size; (nbytes && !error); nbytes -= howMany) {
599 if (nbytes < howMany)
602 /* Read the data - unless we know we can't */
603 n = (lcode ? 0 : FDH_READ(handleP, p, (size_t)howMany));
605 /* If read any good data and we null padded previously, log the
606 * amount that we had null padded.
608 if ((n > 0) && pad) {
609 Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", pad, offset);
613 /* If didn't read enough data, null padd the rest of the buffer. This
614 * can happen if, for instance, the media has some bad spots. We don't
615 * want to quit the dump, so we start null padding.
618 /* Record the read error */
621 Log("1 Volser: DumpFile: Error %d reading inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
623 Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
626 /* Pad the rest of the buffer with zeros. Remember offset we started
627 * padding. Keep total tally of padding.
629 memset(p + n, 0, howMany - n);
631 offset = (howBig - nbytes) + n;
632 pad += (howMany - n);
634 /* Now seek over the data we could not get. An error here means we
635 * can't do the next read.
637 lcode = FDH_SEEK(handleP, (size_t)((size - nbytes) + howMany), SEEK_SET);
638 if (lcode != ((size - nbytes) + howMany)) {
640 Log("1 Volser: DumpFile: Error %d seeking in inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
642 Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
650 /* Now write the data out */
651 if (iod_Write(iodp, (char *)p, (size_t)howMany) != howMany)
652 error = VOLSERDUMPERROR;
653 #ifndef AFS_PTHREAD_ENV
658 if (pad) { /* Any padding we hadn't reported yet */
659 Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n",
668 DumpVolumeHeader(register struct iod *iodp, register Volume * vp)
671 static char nullString[1] = ""; /*The ``contents'' of motd */
674 code = DumpTag(iodp, D_VOLUMEHEADER);
676 code = DumpInt32(iodp, 'i', V_id(vp));
679 code = DumpInt32(iodp, 'v', V_stamp(vp).version);
681 code = DumpString(iodp, 'n', V_name(vp));
683 code = DumpBool(iodp, 's', V_inService(vp));
685 code = DumpBool(iodp, 'b', V_blessed(vp));
687 code = DumpInt32(iodp, 'u', V_uniquifier(vp));
689 code = DumpByte(iodp, 't', (byte) V_type(vp));
691 code = DumpInt32(iodp, 'p', V_parentId(vp));
694 code = DumpInt32(iodp, 'c', V_cloneId(vp));
696 code = DumpInt32(iodp, 'q', V_maxquota(vp));
698 code = DumpInt32(iodp, 'm', V_minquota(vp));
700 code = DumpInt32(iodp, 'd', V_diskused(vp));
702 code = DumpInt32(iodp, 'f', V_filecount(vp));
704 code = DumpInt32(iodp, 'a', V_accountNumber(vp));
706 code = DumpInt32(iodp, 'o', V_owner(vp));
708 code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */
710 code = DumpInt32(iodp, 'A', V_accessDate(vp));
712 code = DumpInt32(iodp, 'U', V_updateDate(vp));
714 code = DumpInt32(iodp, 'E', V_expirationDate(vp));
716 code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */
718 code = DumpString(iodp, 'O', V_offlineMessage(vp));
720 * We do NOT dump the detailed volume statistics residing in the old
721 * motd field, since we cannot tell from the info in a dump whether
722 * statistics data has been put there. Instead, we dump a null string,
723 * just as if that was what the motd contained.
726 code = DumpString(iodp, 'M', nullString);
729 DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp),
730 sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]));
732 code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
734 code = DumpInt32(iodp, 'Z', V_dayUse(vp));
736 code = DumpInt32(iodp, 'V', V_volUpCounter(vp));
741 DumpEnd(register struct iod *iodp)
743 return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
746 /* Guts of the dump code */
748 /* Dump a whole volume */
750 DumpVolume(register struct rx_call *call, register Volume * vp,
751 afs_int32 fromtime, int dumpAllDirs)
755 register struct iod *iodp = &iod;
756 iod_Init(iodp, call);
759 code = DumpDumpHeader(iodp, vp, fromtime);
762 code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
764 /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/
765 if (rx_Error(iodp->call)) {
766 Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n",
767 rx_Error(iodp->call));
768 return VOLSERDUMPERROR;
771 code = DumpEnd(iodp);
776 /* Dump a volume to multiple places*/
778 DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp,
779 afs_int32 fromtime, int dumpAllDirs, int *codes)
783 iod_InitMulti(&iod, calls, ncalls, codes);
786 code = DumpDumpHeader(&iod, vp, fromtime);
788 code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
790 code = DumpEnd(&iod);
794 /* A partial dump (no dump header) */
796 DumpPartial(register struct iod *iodp, register Volume * vp,
797 afs_int32 fromtime, int dumpAllDirs)
801 code = DumpVolumeHeader(iodp, vp);
803 code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
805 code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
810 DumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
811 afs_int32 fromtime, int forcedump)
813 register int code = 0;
814 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
815 char buf[SIZEOF_LARGEDISKVNODE];
816 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
817 StreamHandle_t *file;
821 register int vnodeIndex, nVnodes;
823 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
825 file = FDH_FDOPEN(fdP, "r+");
826 assert(file != NULL);
827 size = OS_SIZE(fdP->fd_fd);
829 nVnodes = (size / vcp->diskSize) - 1;
831 assert((nVnodes + 1) * vcp->diskSize == size);
832 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
836 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
837 nVnodes--, vnodeIndex++) {
838 flag = forcedump || (vnode->serverModifyTime >= fromtime);
839 /* Note: the >= test is very important since some old volumes may not have
840 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
841 * does dump the file! */
844 DumpVnode(iodp, vnode, V_id(vp),
845 bitNumberToVnodeNumber(vnodeIndex, class), flag);
846 #ifndef AFS_PTHREAD_ENV
848 IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
857 DumpDumpHeader(register struct iod *iodp, register Volume * vp,
861 int UseLatestReadOnlyClone = 1;
862 afs_int32 dumpTimes[2];
863 iodp->device = vp->device;
864 iodp->parentId = V_parentId(vp);
865 iodp->dumpPartition = vp->partition;
867 code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
871 UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp));
873 code = DumpString(iodp, 'n', V_name(vp));
874 dumpTimes[0] = fromtime;
875 dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */
877 code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2);
882 DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
883 int vnodeNumber, int dumpEverything)
889 if (!v || v->type == vNull)
892 code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
896 code = DumpByte(iodp, 't', (byte) v->type);
898 code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
900 code = DumpInt32(iodp, 'v', v->dataVersion);
902 code = DumpInt32(iodp, 'm', v->unixModifyTime);
904 code = DumpInt32(iodp, 'a', v->author);
906 code = DumpInt32(iodp, 'o', v->owner);
907 if (!code && v->group)
908 code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */
910 code = DumpShort(iodp, 'b', v->modeBits);
912 code = DumpInt32(iodp, 'p', v->parent);
914 code = DumpInt32(iodp, 's', v->serverModifyTime);
915 if (v->type == vDirectory) {
916 acl_HtonACL(VVnodeDiskACL(v));
919 DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v),
922 if (VNDISK_GET_INO(v)) {
923 IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
926 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);
928 return VOLSERREAD_DUMPERROR;
930 code = DumpFile(iodp, vnodeNumber, fdP);
939 ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep,
942 int i, nVnodes, offset, code, index = 0;
946 StreamHandle_t *afile;
948 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
949 char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
950 register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
952 memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */
953 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
956 afile = FDH_FDOPEN(fdP, "r+");
960 for (i = 0; i < *sizep; i++) {
963 STREAM_SEEK(afile, Buf[i], 0);
964 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
966 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
969 Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n",
970 V_id(vp), bitNumberToVnodeNumber(i, class),
971 (afs_uintmax_t) VNDISK_GET_INO(vnode));
973 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
977 STREAM_SEEK(afile, Buf[i], 0);
978 (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */
984 Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
987 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
988 OS_SYNC(afile->str_fd);
990 size = OS_SIZE(fdP->fd_fd);
994 vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
996 Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32));
1002 memset((char *)Buf, 0, nVnodes * sizeof(afs_int32));
1003 STREAM_SEEK(afile, offset = vcp->diskSize, 0);
1005 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1009 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1010 Buf[(offset >> vcp->logSize) - 1] = offset;
1013 offset += vcp->diskSize;
1019 STREAM_CLOSE(afile);
1026 RestoreVolume(register struct rx_call *call, Volume * avp, int incremental,
1027 struct restoreCookie *cookie)
1030 struct DumpHeader header;
1031 afs_uint32 endMagic;
1032 Error error = 0, vupdate;
1033 register Volume *vp;
1035 register struct iod *iodp = &iod;
1036 afs_int32 *b1 = NULL, *b2 = NULL;
1037 int s1 = 0, s2 = 0, delo = 0, tdelo;
1040 iod_Init(iodp, call);
1043 if (V_parentId(vp) == V_id(vp))
1046 if (!ReadDumpHeader(iodp, &header)) {
1047 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1048 return VOLSERREAD_DUMPERROR;
1050 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1051 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1052 return VOLSERREAD_DUMPERROR;
1054 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1055 return VOLSERREAD_DUMPERROR;
1058 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1060 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1062 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1063 error = VOLSERREAD_DUMPERROR;
1067 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1068 vol.type = cookie->type;
1069 vol.cloneId = cookie->clone;
1070 vol.parentId = cookie->parent;
1074 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1075 error = VOLSERREAD_DUMPERROR;
1078 tag = iod_getc(iodp);
1079 if (tag != D_VOLUMEHEADER)
1082 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1083 error = VOLSERREAD_DUMPERROR;
1087 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1088 || endMagic != DUMPENDMAGIC) {
1089 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1090 error = VOLSERREAD_DUMPERROR;
1095 if (iod_getc(iodp) != EOF) {
1096 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1097 error = VOLSERREAD_DUMPERROR;
1102 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1104 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1106 error = VOLSERREAD_DUMPERROR;
1112 ClearVolumeStats(&vol);
1113 CopyVolumeHeader(&vol, &V_disk(vp));
1114 V_destroyMe(vp) = 0;
1115 VUpdateVolume(&vupdate, vp);
1117 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1118 error = VOLSERREAD_DUMPERROR;
1122 /* Free the malloced space above */
1131 ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
1132 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2,
1135 afs_int32 vnodeNumber;
1136 char buf[SIZEOF_LARGEDISKVNODE];
1138 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1139 struct VnodeDiskObject oldvnode;
1142 struct VnodeClassInfo *vcp;
1147 tag = iod_getc(iodp);
1148 V_pref(vp, nearInode);
1149 while (tag == D_VNODE) {
1151 memset(buf, 0, sizeof(buf));
1152 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1155 if (!ReadInt32(iodp, &vnode->uniquifier))
1156 return VOLSERREAD_DUMPERROR;
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 perror("unable to allocate inode");
1226 Log("1 Volser: ReadVnodes: Restore aborted\n");
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);
1235 return VOLSERREAD_DUMPERROR;
1238 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1239 VNDISK_SET_LEN(vnode, vnodeLength);
1240 FDH_REALLYCLOSE(fdP);
1243 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1244 (afs_uintmax_t) ino);
1245 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1246 return VOLSERREAD_DUMPERROR;
1253 class = vnodeIdToClass(vnodeNumber);
1254 vcp = &VnodeClassInfo[class];
1256 /* Mark this vnode as in this dump - so we don't delete it later */
1258 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1259 if (class == vLarge) {
1260 if (Lbuf && (idx < s1))
1263 if (Sbuf && (idx < s2))
1269 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1271 Log("1 Volser: ReadVnodes: Error opening vnode index; restore aborted\n");
1272 return VOLSERREAD_DUMPERROR;
1274 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1276 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1277 FDH_REALLYCLOSE(fdP);
1278 return VOLSERREAD_DUMPERROR;
1280 if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) ==
1282 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1283 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1287 vnode->vnodeMagic = vcp->magic;
1288 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1290 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1291 FDH_REALLYCLOSE(fdP);
1292 return VOLSERREAD_DUMPERROR;
1294 if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
1295 Log("1 Volser: ReadVnodes: Error writing vnode index; restore aborted\n");
1296 FDH_REALLYCLOSE(fdP);
1297 return VOLSERREAD_DUMPERROR;
1302 iod_ungetc(iodp, tag);
1308 /* called with disk file only. Note that we don't have to worry about rx_Read
1309 * needing to read an ungetc'd character, since the ReadInt32 will have read
1313 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1318 afs_fsize_t filesize;
1319 afs_fsize_t written = 0;
1320 register afs_uint32 size = 8192;
1321 register afs_fsize_t nbytes;
1326 #ifdef AFS_64BIT_ENV
1328 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1329 #ifdef AFS_LARGEFILE_ENV
1331 if (!ReadInt32(iodp, &filesize_high)) {
1336 #endif /* !AFS_LARGEFILE_ENV */
1337 if (!ReadInt32(iodp, &filesize_low)) {
1341 FillInt64(filesize, filesize_high, filesize_low);
1343 #else /* !AFS_64BIT_ENV */
1344 if (!ReadInt32(iodp, &filesize)) {
1348 #endif /* !AFS_64BIT_ENV */
1349 p = (unsigned char *)malloc(size);
1354 for (nbytes = filesize; nbytes; nbytes -= size) {
1358 if ((code = iod_Read(iodp, p, size)) != size) {
1359 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);
1363 lcode = FDH_WRITE(handleP, p, size);
1366 if (lcode != size) {
1367 Log("1 Volser: WriteFile: Error writing (%d,%u) bytes to vnode %d; restore aborted\n", (int)(lcode>>32), (int)(lcode & 0xffffffff), vn);
1377 ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp)
1380 afs_uint32 beginMagic;
1381 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1382 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1383 || beginMagic != DUMPBEGINMAGIC)
1387 while ((tag = iod_getc(iodp)) > D_MAX) {
1388 unsigned short arrayLength;
1392 if (!ReadInt32(iodp, &hp->volumeId))
1396 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1399 if (!ReadShort(iodp, &arrayLength))
1401 hp->nDumpTimes = (arrayLength >> 1);
1402 for (i = 0; i < hp->nDumpTimes; i++)
1403 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1404 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1409 if (!hp->volumeId || !hp->nDumpTimes) {
1412 iod_ungetc(iodp, tag);
1417 /* ----- Below are the calls that calculate dump size ----- */
1420 SizeDumpVolumeHeader(register struct iod *iodp, register Volume * vp,
1421 register struct volintSize *v_size)
1424 static char nullString[1] = ""; /*The ``contents'' of motd */
1427 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1428 FillInt64(addvar,0, 1);
1429 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1430 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1431 FillInt64(addvar,0, 5);
1432 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1433 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1434 FillInt64(addvar,0, 5);
1435 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1436 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1437 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1438 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1439 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1440 FillInt64(addvar,0, 2);
1441 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1442 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1443 FillInt64(addvar,0, 2);
1444 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1445 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1446 FillInt64(addvar,0, 5);
1447 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1448 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1449 FillInt64(addvar,0, 2);
1450 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1451 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1452 FillInt64(addvar,0, 5);
1453 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1454 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1455 FillInt64(addvar,0, 5);
1456 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1457 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1458 FillInt64(addvar,0, 5);
1459 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1460 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1461 FillInt64(addvar,0, 5);
1462 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1463 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1464 FillInt64(addvar,0, 5);
1465 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1466 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1467 FillInt64(addvar,0, 5);
1468 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1469 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1470 FillInt64(addvar,0, 5);
1471 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1472 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1473 FillInt64(addvar,0, 5);
1474 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1475 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1476 FillInt64(addvar,0, 5);
1477 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1478 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1479 FillInt64(addvar,0, 5);
1480 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1481 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1482 FillInt64(addvar,0, 5);
1483 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1484 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1485 FillInt64(addvar,0, 5);
1486 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1487 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1488 FillInt64(addvar,0, 5);
1489 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1490 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1491 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1492 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1494 /* * We do NOT dump the detailed volume statistics residing in the old */
1495 /* * motd field, since we cannot tell from the info in a dump whether */
1496 /* * statistics data has been put there. Instead, we dump a null string, */
1497 /* * just as if that was what the motd contained. */
1499 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1500 FillInt64(addvar,0, (2 + strlen(nullString)));
1501 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1502 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1503 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1504 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1505 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1506 FillInt64(addvar,0, 5);
1507 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1508 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1509 FillInt64(addvar,0, 5);
1510 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1511 /* if (!code) code = DumpInt32(iodp, 'V', V_volUpCounter(vp)); */
1512 FillInt64(addvar,0, 5);
1513 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1518 SizeDumpEnd(register struct iod *iodp, register struct volintSize *v_size)
1522 FillInt64(addvar,0, 5);
1523 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1528 SizeDumpVolume(register struct rx_call *call, register Volume * vp,
1529 afs_int32 fromtime, int dumpAllDirs,
1530 register struct volintSize *v_size)
1533 register struct iod *iodp = (struct iod *)0;
1534 /* iod_Init(iodp, call); */
1537 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1539 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1541 code = SizeDumpEnd(iodp, v_size);
1547 SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
1548 afs_int32 fromtime, register struct volintSize *v_size)
1551 int UseLatestReadOnlyClone = 1;
1552 /* afs_int32 dumpTimes[2]; */
1554 /* iodp->device = vp->device; */
1555 /* iodp->parentId = V_parentId(vp); */
1556 /* iodp->dumpPartition = vp->partition; */
1558 ZeroInt64(v_size->dump_size); /* initialize the size */
1559 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1560 FillInt64(addvar,0, 9);
1561 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1562 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1563 FillInt64(addvar,0, 5);
1564 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1565 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1566 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1567 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1568 /* dumpTimes[0] = fromtime; */
1569 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1570 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1571 FillInt64(addvar,0, (3 + 4 * 2));
1572 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1577 SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
1578 int vnodeNumber, int dumpEverything,
1579 register struct volintSize *v_size)
1584 if (!v || v->type == vNull)
1586 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1587 FillInt64(addvar,0, 9);
1588 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1589 if (!dumpEverything)
1591 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1592 FillInt64(addvar,0, 2);
1593 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1594 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1595 FillInt64(addvar,0, 3);
1596 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1597 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1598 FillInt64(addvar,0, 5);
1599 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1600 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1601 FillInt64(addvar,0, 5);
1602 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1603 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1604 FillInt64(addvar,0, 5);
1605 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1606 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1607 FillInt64(addvar,0, 5);
1608 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1609 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1611 FillInt64(addvar,0, 5);
1612 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1614 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1615 FillInt64(addvar,0, 3);
1616 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1617 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1618 FillInt64(addvar,0, 5);
1619 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1620 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1621 FillInt64(addvar,0, 5);
1622 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1623 if (v->type == vDirectory) {
1624 /* acl_HtonACL(VVnodeDiskACL(v)); */
1625 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1626 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1627 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1630 if (VNDISK_GET_INO(v)) {
1631 FillInt64(addvar,0, (v->length + 5));
1632 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1637 /* A partial dump (no dump header) */
1639 SizeDumpPartial(register struct iod *iodp, register Volume * vp,
1640 afs_int32 fromtime, int dumpAllDirs,
1641 register struct volintSize *v_size)
1645 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1648 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1651 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1656 SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
1657 afs_int32 fromtime, int forcedump,
1658 register struct volintSize *v_size)
1660 register int code = 0;
1661 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1662 char buf[SIZEOF_LARGEDISKVNODE];
1663 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1664 StreamHandle_t *file;
1668 register int vnodeIndex, nVnodes;
1670 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1671 assert(fdP != NULL);
1672 file = FDH_FDOPEN(fdP, "r+");
1673 assert(file != NULL);
1674 size = OS_SIZE(fdP->fd_fd);
1676 nVnodes = (size / vcp->diskSize) - 1;
1678 assert((nVnodes + 1) * vcp->diskSize == size);
1679 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
1682 for (vnodeIndex = 0;
1683 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1684 nVnodes--, vnodeIndex++) {
1685 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1686 /* Note: the >= test is very important since some old volumes may not have
1687 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1688 * does dump the file! */
1691 SizeDumpVnode(iodp, vnode, V_id(vp),
1692 bitNumberToVnodeNumber(vnodeIndex, class), flag,