2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <sys/types.h>
24 #include <sys/param.h>
27 #include <netinet/in.h>
31 #ifdef AFS_PTHREAD_ENV
33 #else /* AFS_PTHREAD_ENV */
34 #include <afs/assert.h>
35 #endif /* AFS_PTHREAD_ENV */
38 #include <afs/afsint.h>
40 #include <afs/errors.h>
43 #include <afs/ihandle.h>
44 #include <afs/vnode.h>
45 #include <afs/volume.h>
46 #include <afs/partition.h>
48 #include <afs/daemon_com.h>
49 #include <afs/fssync.h>
56 #define afs_stat stat64
57 #define afs_fstat fstat64
58 #else /* !O_LARGEFILE */
60 #define afs_fstat fstat
61 #endif /* !O_LARGEFILE */
62 #endif /* !AFS_NT40_ENV */
64 /*@printflike@*/ extern void Log(const char *format, ...);
68 /* This iod stuff is a silly little package to emulate the old qi_in stuff, which
69 emulated the stdio stuff. There is a big assumption here, that the
70 rx_Read will never be called directly, by a routine like readFile, when
71 there is an old character that was pushed back with iod_ungetc. This
72 is really bletchy, and is here for compatibility only. Eventually,
73 we should define a volume format that doesn't require
74 the pushing back of characters (i.e. characters should not double both
75 as an end marker and a begin marker) */
77 struct rx_call *call; /* call to which to write, might be an array */
78 int device; /* dump device ID for volume */
79 int parentId; /* dump parent ID for volume */
80 struct DiskPartition *dumpPartition; /* Dump partition. */
81 struct rx_call **calls; /* array of pointers to calls */
82 int ncalls; /* how many calls/codes in array */
83 int *codes; /* one return code for each call */
84 char haveOldChar; /* state for pushing back a character */
89 /* Forward Declarations */
90 static int DumpDumpHeader(register struct iod *iodp, register Volume * vp,
92 static int DumpPartial(register struct iod *iodp, register Volume * vp,
93 afs_int32 fromtime, int dumpAllDirs);
94 static int DumpVnodeIndex(register struct iod *iodp, Volume * vp,
95 VnodeClass class, afs_int32 fromtime,
97 static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
98 int volid, int vnodeNumber, int dumpEverything);
99 static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp);
100 static int ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
101 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf,
102 afs_int32 s2, afs_int32 delo);
103 static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp,
104 FdHandle_t * handleP, int tag,
107 static int SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
109 register struct volintSize *size);
110 static int SizeDumpPartial(register struct iod *iodp, register Volume * vp,
111 afs_int32 fromtime, int dumpAllDirs,
112 register struct volintSize *size);
113 static int SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp,
114 VnodeClass class, afs_int32 fromtime,
116 register struct volintSize *size);
117 static int SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
118 int volid, int vnodeNumber, int dumpEverything,
119 register struct volintSize *size);
122 iod_Init(register struct iod *iodp, register struct rx_call *call)
125 iodp->haveOldChar = 0;
127 iodp->calls = (struct rx_call **)0;
131 iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
136 iodp->haveOldChar = 0;
137 iodp->ncalls = ncalls;
139 iodp->call = (struct rx_call *)0;
142 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
143 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
145 /* For the single dump case, it's ok to just return the "bytes written"
146 * that rx_Write returns, since all the callers of iod_Write abort when
147 * the returned value is less than they expect. For the multi dump case,
148 * I don't think we want half the replicas to go bad just because one
149 * connection timed out, but if they all time out, then we should give up.
152 iod_Write(struct iod *iodp, char *buf, int nbytes)
157 assert((iodp->call && iodp->ncalls == 1 && !iodp->calls)
158 || (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
161 code = rx_Write(iodp->call, buf, nbytes);
165 for (i = 0; i < iodp->ncalls; i++) {
166 if (iodp->calls[i] && !iodp->codes[i]) {
167 code = rx_Write(iodp->calls[i], buf, nbytes);
168 if (code != nbytes) { /* everything gets merged into a single error */
169 iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */
170 } /* standard dump does, anyways */
175 } /* for all calls */
184 iod_ungetc(struct iod *iodp, int achar)
186 iodp->oldChar = achar;
187 iodp->haveOldChar = 1;
191 iod_getc(register struct iod *iodp)
195 if (iodp->haveOldChar) {
196 iodp->haveOldChar = 0;
197 return iodp->oldChar;
199 if (iod_Read(iodp, &t, 1) == 1)
205 ReadShort(register struct iod *iodp, register unsigned short *sp)
214 *sp = (b1 << 8) | b0;
219 ReadInt32(register struct iod *iodp, afs_uint32 * lp)
221 afs_uint32 register b3, b2, b1, b0;
234 *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0;
239 ReadString(register struct iod *iodp, register char *to, register int maxa)
249 if ((*to++ = c = iod_getc(iodp)) == 0 || c == EOF)
253 while ((c = iod_getc(iodp)) && c != EOF);
259 ReadByteString(register struct iod *iodp, register byte * to,
263 *to++ = iod_getc(iodp);
267 ReadVolumeHeader(register struct iod *iodp, VolumeDiskData * vol)
271 memset(vol, 0, sizeof(*vol));
272 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
275 if (!ReadInt32(iodp, &vol->id))
276 return VOLSERREAD_DUMPERROR;
279 if (!ReadInt32(iodp, &trash))
280 return VOLSERREAD_DUMPERROR;
283 ReadString(iodp, vol->name, sizeof(vol->name));
284 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
287 vol->inService = iod_getc(iodp);
290 vol->blessed = iod_getc(iodp);
293 if (!ReadInt32(iodp, &vol->uniquifier))
294 return VOLSERREAD_DUMPERROR;
297 vol->type = iod_getc(iodp);
300 if (!ReadInt32(iodp, &vol->parentId))
301 return VOLSERREAD_DUMPERROR;
304 if (!ReadInt32(iodp, &vol->cloneId))
305 return VOLSERREAD_DUMPERROR;
308 if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota))
309 return VOLSERREAD_DUMPERROR;
312 if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota))
313 return VOLSERREAD_DUMPERROR;
316 if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused))
317 return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */
320 if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount))
321 return VOLSERREAD_DUMPERROR;
324 if (!ReadInt32(iodp, &vol->accountNumber))
325 return VOLSERREAD_DUMPERROR;
328 if (!ReadInt32(iodp, &vol->owner))
329 return VOLSERREAD_DUMPERROR;
332 if (!ReadInt32(iodp, &vol->creationDate))
333 return VOLSERREAD_DUMPERROR;
336 if (!ReadInt32(iodp, &vol->accessDate))
337 return VOLSERREAD_DUMPERROR;
340 if (!ReadInt32(iodp, &vol->updateDate))
341 return VOLSERREAD_DUMPERROR;
344 if (!ReadInt32(iodp, &vol->expirationDate))
345 return VOLSERREAD_DUMPERROR;
348 if (!ReadInt32(iodp, &vol->backupDate))
349 return VOLSERREAD_DUMPERROR;
352 ReadString(iodp, vol->offlineMessage,
353 sizeof(vol->offlineMessage));
357 * Detailed volume statistics are never stored in dumps,
358 * so we just restore either the null string if this volume
359 * had already been set to store statistics, or the old motd
360 * contents otherwise. It doesn't matter, since this field
361 * will soon get initialized anyway.
363 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
366 unsigned short length;
369 if (!ReadShort(iodp, &length))
370 return VOLSERREAD_DUMPERROR;
371 for (i = 0; i < length; i++) {
372 if (!ReadInt32(iodp, &data))
373 return VOLSERREAD_DUMPERROR;
374 if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0]))
375 vol->weekUse[i] = data;
380 if (!ReadInt32(iodp, &vol->dayUseDate))
381 return VOLSERREAD_DUMPERROR;
384 if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse))
385 return VOLSERREAD_DUMPERROR;
388 if (!ReadInt32(iodp, (afs_uint32 *) & vol->volUpdateCounter))
389 return VOLSERREAD_DUMPERROR;
393 iod_ungetc(iodp, tag);
398 DumpTag(register struct iod *iodp, register int tag)
403 return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR);
408 DumpByte(register struct iod *iodp, char tag, byte value)
411 register byte *p = (unsigned char *)tbuffer;
414 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
417 #define putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
418 #define putshort(p, v) *p++ = v>>8, *p++ = v
421 DumpDouble(register struct iod *iodp, char tag, register afs_uint32 value1,
422 register afs_uint32 value2)
425 register byte *p = (unsigned char *)tbuffer;
429 return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR);
433 DumpInt32(register struct iod *iodp, char tag, register afs_uint32 value)
436 register byte *p = (unsigned char *)tbuffer;
439 return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR);
443 DumpArrayInt32(register struct iod *iodp, char tag,
444 register afs_uint32 * array, register int nelem)
447 register afs_uint32 v;
449 register byte *p = (unsigned char *)tbuffer;
452 code = iod_Write(iodp, tbuffer, 3);
454 return VOLSERDUMPERROR;
456 p = (unsigned char *)tbuffer;
457 v = *array++; /*this was register */
460 code = iod_Write(iodp, tbuffer, 4);
462 return VOLSERDUMPERROR;
468 DumpShort(register struct iod *iodp, char tag, unsigned int value)
471 register byte *p = (unsigned char *)tbuffer;
475 return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR);
479 DumpBool(register struct iod *iodp, char tag, unsigned int value)
482 register byte *p = (unsigned char *)tbuffer;
485 return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR);
489 DumpString(register struct iod *iodp, char tag, register char *s)
493 code = iod_Write(iodp, &tag, 1);
495 return VOLSERDUMPERROR;
497 code = iod_Write(iodp, s, n);
499 return VOLSERDUMPERROR;
504 DumpByteString(register struct iod *iodp, char tag, register byte * bs,
509 code = iod_Write(iodp, &tag, 1);
511 return VOLSERDUMPERROR;
512 code = iod_Write(iodp, (char *)bs, nbytes);
514 return VOLSERDUMPERROR;
519 DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
521 int code = 0, error = 0;
522 afs_int32 pad = 0, offset;
523 afs_sfsize_t n, nbytes, howMany, howBig;
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;
990 Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32));
996 memset((char *)Buf, 0, nVnodes * sizeof(afs_int32));
997 STREAM_SEEK(afile, offset = vcp->diskSize, 0);
999 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
1003 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
1004 Buf[(offset >> vcp->logSize) - 1] = offset;
1007 offset += vcp->diskSize;
1013 STREAM_CLOSE(afile);
1020 RestoreVolume(register struct rx_call *call, Volume * avp, int incremental,
1021 struct restoreCookie *cookie)
1024 struct DumpHeader header;
1025 afs_uint32 endMagic;
1026 Error error = 0, vupdate;
1027 register Volume *vp;
1029 register struct iod *iodp = &iod;
1030 afs_int32 *b1 = NULL, *b2 = NULL;
1031 int s1 = 0, s2 = 0, delo = 0, tdelo;
1034 iod_Init(iodp, call);
1038 if (!ReadDumpHeader(iodp, &header)) {
1039 Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
1040 return VOLSERREAD_DUMPERROR;
1042 if (iod_getc(iodp) != D_VOLUMEHEADER) {
1043 Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
1044 return VOLSERREAD_DUMPERROR;
1046 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR)
1047 return VOLSERREAD_DUMPERROR;
1050 delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
1052 delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
1054 Log("1 Volser: RestoreVolume: ProcessIndex failed; not restored\n");
1055 error = VOLSERREAD_DUMPERROR;
1059 strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME);
1060 vol.type = cookie->type;
1061 vol.cloneId = cookie->clone;
1062 vol.parentId = cookie->parent;
1066 if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
1067 error = VOLSERREAD_DUMPERROR;
1070 tag = iod_getc(iodp);
1071 if (tag != D_VOLUMEHEADER)
1074 if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
1075 error = VOLSERREAD_DUMPERROR;
1079 if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic)
1080 || endMagic != DUMPENDMAGIC) {
1081 Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
1082 error = VOLSERREAD_DUMPERROR;
1087 if (iod_getc(iodp) != EOF) {
1088 Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
1089 error = VOLSERREAD_DUMPERROR;
1094 delo = ProcessIndex(vp, vLarge, &b1, &s1, 1);
1096 delo = ProcessIndex(vp, vSmall, &b2, &s2, 1);
1098 error = VOLSERREAD_DUMPERROR;
1104 ClearVolumeStats(&vol);
1105 CopyVolumeHeader(&vol, &V_disk(vp));
1106 V_destroyMe(vp) = 0;
1107 VUpdateVolume(&vupdate, vp);
1109 Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
1110 error = VOLSERREAD_DUMPERROR;
1114 /* Free the malloced space above */
1123 ReadVnodes(register struct iod *iodp, Volume * vp, int incremental,
1124 afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2,
1127 afs_int32 vnodeNumber;
1128 char buf[SIZEOF_LARGEDISKVNODE];
1130 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1131 struct VnodeDiskObject oldvnode;
1134 struct VnodeClassInfo *vcp;
1139 tag = iod_getc(iodp);
1140 V_pref(vp, nearInode);
1141 while (tag == D_VNODE) {
1143 memset(buf, 0, sizeof(buf));
1144 if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber))
1147 if (!ReadInt32(iodp, &vnode->uniquifier))
1148 return VOLSERREAD_DUMPERROR;
1149 while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
1153 vnode->type = (VnodeType) iod_getc(iodp);
1158 if (!ReadShort(iodp, &tlc))
1159 return VOLSERREAD_DUMPERROR;
1160 vnode->linkCount = (signed int)tlc;
1164 if (!ReadInt32(iodp, &vnode->dataVersion))
1165 return VOLSERREAD_DUMPERROR;
1168 if (!ReadInt32(iodp, &vnode->unixModifyTime))
1169 return VOLSERREAD_DUMPERROR;
1172 if (!ReadInt32(iodp, &vnode->serverModifyTime))
1173 return VOLSERREAD_DUMPERROR;
1176 if (!ReadInt32(iodp, &vnode->author))
1177 return VOLSERREAD_DUMPERROR;
1180 if (!ReadInt32(iodp, &vnode->owner))
1181 return VOLSERREAD_DUMPERROR;
1184 if (!ReadInt32(iodp, (afs_uint32 *) & vnode->group))
1185 return VOLSERREAD_DUMPERROR;
1188 unsigned short modeBits;
1189 if (!ReadShort(iodp, &modeBits))
1190 return VOLSERREAD_DUMPERROR;
1191 vnode->modeBits = (unsigned int)modeBits;
1195 if (!ReadInt32(iodp, &vnode->parent))
1196 return VOLSERREAD_DUMPERROR;
1199 ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
1200 VAclDiskSize(vnode));
1201 acl_NtohACL(VVnodeDiskACL(vnode));
1203 #ifdef AFS_LARGEFILE_ENV
1209 afs_fsize_t vnodeLength;
1212 IH_CREATE(V_linkHandle(vp), V_device(vp),
1213 VPartitionPath(V_partition(vp)), nearInode,
1214 V_parentId(vp), vnodeNumber,
1215 vnode->uniquifier, vnode->dataVersion);
1216 if (!VALID_INO(ino)) {
1217 perror("unable to allocate inode");
1218 Log("1 Volser: ReadVnodes: Restore aborted\n");
1219 return VOLSERREAD_DUMPERROR;
1222 VNDISK_SET_INO(vnode, ino);
1223 IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1224 fdP = IH_OPEN(tmpH);
1227 return VOLSERREAD_DUMPERROR;
1230 volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error);
1231 VNDISK_SET_LEN(vnode, vnodeLength);
1232 FDH_REALLYCLOSE(fdP);
1235 Log("1 Volser: ReadVnodes: IDEC inode %llu\n",
1236 (afs_uintmax_t) ino);
1237 IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1238 return VOLSERREAD_DUMPERROR;
1245 class = vnodeIdToClass(vnodeNumber);
1246 vcp = &VnodeClassInfo[class];
1248 /* Mark this vnode as in this dump - so we don't delete it later */
1250 idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1;
1251 if (class == vLarge) {
1252 if (Lbuf && (idx < s1))
1255 if (Sbuf && (idx < s2))
1261 FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1263 Log("1 Volser: ReadVnodes: Error opening vnode index; restore aborted\n");
1264 return VOLSERREAD_DUMPERROR;
1266 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1268 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1269 FDH_REALLYCLOSE(fdP);
1270 return VOLSERREAD_DUMPERROR;
1272 if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) ==
1274 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1275 IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1279 vnode->vnodeMagic = vcp->magic;
1280 if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) <
1282 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1283 FDH_REALLYCLOSE(fdP);
1284 return VOLSERREAD_DUMPERROR;
1286 if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
1287 Log("1 Volser: ReadVnodes: Error writing vnode index; restore aborted\n");
1288 FDH_REALLYCLOSE(fdP);
1289 return VOLSERREAD_DUMPERROR;
1294 iod_ungetc(iodp, tag);
1300 /* called with disk file only. Note that we don't have to worry about rx_Read
1301 * needing to read an ungetc'd character, since the ReadInt32 will have read
1305 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag,
1310 afs_fsize_t filesize;
1311 afs_fsize_t written = 0;
1312 register afs_uint32 size = 8192;
1313 register afs_fsize_t nbytes;
1318 #ifdef AFS_64BIT_ENV
1320 afs_uint32 filesize_high = 0L, filesize_low = 0L;
1321 #ifdef AFS_LARGEFILE_ENV
1323 if (!ReadInt32(iodp, &filesize_high)) {
1328 #endif /* !AFS_LARGEFILE_ENV */
1329 if (!ReadInt32(iodp, &filesize_low)) {
1333 FillInt64(filesize, filesize_high, filesize_low);
1335 #else /* !AFS_64BIT_ENV */
1336 if (!ReadInt32(iodp, &filesize)) {
1340 #endif /* !AFS_64BIT_ENV */
1341 p = (unsigned char *)malloc(size);
1346 for (nbytes = filesize; nbytes; nbytes -= size) {
1350 if ((code = iod_Read(iodp, p, size)) != size) {
1351 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);
1355 lcode = FDH_WRITE(handleP, p, size);
1358 if (lcode != size) {
1359 Log("1 Volser: WriteFile: Error writing (%d,%u) bytes to vnode %d; restore aborted\n", (int)(lcode>>32), (int)(lcode & 0xffffffff), vn);
1369 ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp)
1372 afs_uint32 beginMagic;
1373 if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1374 || !ReadInt32(iodp, (afs_uint32 *) & hp->version)
1375 || beginMagic != DUMPBEGINMAGIC)
1379 while ((tag = iod_getc(iodp)) > D_MAX) {
1380 unsigned short arrayLength;
1384 if (!ReadInt32(iodp, &hp->volumeId))
1388 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1391 if (!ReadShort(iodp, &arrayLength))
1393 hp->nDumpTimes = (arrayLength >> 1);
1394 for (i = 0; i < hp->nDumpTimes; i++)
1395 if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from)
1396 || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to))
1401 if (!hp->volumeId || !hp->nDumpTimes) {
1404 iod_ungetc(iodp, tag);
1409 /* ----- Below are the calls that calculate dump size ----- */
1412 SizeDumpVolumeHeader(register struct iod *iodp, register Volume * vp,
1413 register struct volintSize *v_size)
1416 static char nullString[1] = ""; /*The ``contents'' of motd */
1419 /* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */
1420 FillInt64(addvar,0, 1);
1421 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1422 /* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */
1423 FillInt64(addvar,0, 5);
1424 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1425 /* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */
1426 FillInt64(addvar,0, 5);
1427 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1428 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1429 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1430 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1431 /* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */
1432 FillInt64(addvar,0, 2);
1433 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1434 /* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */
1435 FillInt64(addvar,0, 2);
1436 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1437 /* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */
1438 FillInt64(addvar,0, 5);
1439 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1440 /* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */
1441 FillInt64(addvar,0, 2);
1442 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1443 /* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */
1444 FillInt64(addvar,0, 5);
1445 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1446 /* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */
1447 FillInt64(addvar,0, 5);
1448 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1449 /* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */
1450 FillInt64(addvar,0, 5);
1451 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1452 /* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */
1453 FillInt64(addvar,0, 5);
1454 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1455 /* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */
1456 FillInt64(addvar,0, 5);
1457 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1458 /* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */
1459 FillInt64(addvar,0, 5);
1460 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1461 /* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */
1462 FillInt64(addvar,0, 5);
1463 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1464 /* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */
1465 FillInt64(addvar,0, 5);
1466 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1467 /* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */
1468 FillInt64(addvar,0, 5);
1469 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1470 /* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */
1471 FillInt64(addvar,0, 5);
1472 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1473 /* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */
1474 FillInt64(addvar,0, 5);
1475 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1476 /* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */
1477 FillInt64(addvar,0, 5);
1478 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1479 /* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */
1480 FillInt64(addvar,0, 5);
1481 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1482 /* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */
1483 FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp))));
1484 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1486 /* * We do NOT dump the detailed volume statistics residing in the old */
1487 /* * motd field, since we cannot tell from the info in a dump whether */
1488 /* * statistics data has been put there. Instead, we dump a null string, */
1489 /* * just as if that was what the motd contained. */
1491 /* if (!code) code = DumpString(iodp, 'M', nullString); */
1492 FillInt64(addvar,0, (2 + strlen(nullString)));
1493 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1494 /* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */
1495 FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0]))));
1496 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1497 /* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */
1498 FillInt64(addvar,0, 5);
1499 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1500 /* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */
1501 FillInt64(addvar,0, 5);
1502 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1503 /* if (!code) code = DumpInt32(iodp, 'V', V_volUpCounter(vp)); */
1504 FillInt64(addvar,0, 5);
1505 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1510 SizeDumpEnd(register struct iod *iodp, register struct volintSize *v_size)
1514 FillInt64(addvar,0, 5);
1515 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1520 SizeDumpVolume(register struct rx_call *call, register Volume * vp,
1521 afs_int32 fromtime, int dumpAllDirs,
1522 register struct volintSize *v_size)
1525 register struct iod *iodp = (struct iod *)0;
1526 /* iod_Init(iodp, call); */
1529 code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size);
1531 code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size);
1533 code = SizeDumpEnd(iodp, v_size);
1539 SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp,
1540 afs_int32 fromtime, register struct volintSize *v_size)
1543 int UseLatestReadOnlyClone = 1;
1544 /* afs_int32 dumpTimes[2]; */
1546 /* iodp->device = vp->device; */
1547 /* iodp->parentId = V_parentId(vp); */
1548 /* iodp->dumpPartition = vp->partition; */
1550 ZeroInt64(v_size->dump_size); /* initialize the size */
1551 /* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */
1552 FillInt64(addvar,0, 9);
1553 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1554 /* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */
1555 FillInt64(addvar,0, 5);
1556 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1557 /* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */
1558 FillInt64(addvar,0, (2 + strlen(V_name(vp))));
1559 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1560 /* dumpTimes[0] = fromtime; */
1561 /* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */
1562 /* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */
1563 FillInt64(addvar,0, (3 + 4 * 2));
1564 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1569 SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid,
1570 int vnodeNumber, int dumpEverything,
1571 register struct volintSize *v_size)
1576 if (!v || v->type == vNull)
1578 /* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */
1579 FillInt64(addvar,0, 9);
1580 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1581 if (!dumpEverything)
1583 /* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */
1584 FillInt64(addvar,0, 2);
1585 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1586 /* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */
1587 FillInt64(addvar,0, 3);
1588 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1589 /* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */
1590 FillInt64(addvar,0, 5);
1591 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1592 /* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */
1593 FillInt64(addvar,0, 5);
1594 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1595 /* if (!code) code = DumpInt32(iodp, 'a', v->author); */
1596 FillInt64(addvar,0, 5);
1597 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1598 /* if (!code) code = DumpInt32(iodp, 'o', v->owner); */
1599 FillInt64(addvar,0, 5);
1600 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1601 /* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */
1603 FillInt64(addvar,0, 5);
1604 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1606 /* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */
1607 FillInt64(addvar,0, 3);
1608 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1609 /* if (!code) code = DumpInt32(iodp, 'p', v->parent); */
1610 FillInt64(addvar,0, 5);
1611 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1612 /* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */
1613 FillInt64(addvar,0, 5);
1614 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1615 if (v->type == vDirectory) {
1616 /* acl_HtonACL(VVnodeDiskACL(v)); */
1617 /* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */
1618 FillInt64(addvar,0, (1 + VAclDiskSize(v)));
1619 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1622 if (VNDISK_GET_INO(v)) {
1623 FillInt64(addvar,0, (v->length + 5));
1624 AddUInt64(v_size->dump_size, addvar, &v_size->dump_size);
1629 /* A partial dump (no dump header) */
1631 SizeDumpPartial(register struct iod *iodp, register Volume * vp,
1632 afs_int32 fromtime, int dumpAllDirs,
1633 register struct volintSize *v_size)
1637 code = SizeDumpVolumeHeader(iodp, vp, v_size);
1640 SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs,
1643 code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size);
1648 SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class,
1649 afs_int32 fromtime, int forcedump,
1650 register struct volintSize *v_size)
1652 register int code = 0;
1653 register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1654 char buf[SIZEOF_LARGEDISKVNODE];
1655 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1656 StreamHandle_t *file;
1660 register int vnodeIndex, nVnodes;
1662 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1663 assert(fdP != NULL);
1664 file = FDH_FDOPEN(fdP, "r+");
1665 assert(file != NULL);
1666 size = OS_SIZE(fdP->fd_fd);
1668 nVnodes = (size / vcp->diskSize) - 1;
1670 assert((nVnodes + 1) * vcp->diskSize == size);
1671 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
1674 for (vnodeIndex = 0;
1675 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
1676 nVnodes--, vnodeIndex++) {
1677 flag = forcedump || (vnode->serverModifyTime >= fromtime);
1678 /* Note: the >= test is very important since some old volumes may not have
1679 * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which
1680 * does dump the file! */
1683 SizeDumpVnode(iodp, vnode, V_id(vp),
1684 bitNumberToVnodeNumber(vnodeIndex, class), flag,