largefile-do-offsets-correctly-when-64bit-but-not-largefile-20030313
[openafs.git] / src / volser / dumpstuff.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID("$Header$");
14
15 #include <sys/types.h>
16 #include <ctype.h>
17 #include <stdio.h>
18 #include <errno.h>
19 #ifdef AFS_NT40_ENV
20 #include <fcntl.h>
21 #else
22 #include <sys/param.h>
23 #include <sys/file.h>
24 #include <sys/uio.h>
25 #include <netinet/in.h>
26 #include <unistd.h>
27 #endif
28 #ifdef HAVE_STRING_H
29 #include <string.h>
30 #else
31 #ifdef HAVE_STRINGS_H
32 #include <strings.h>
33 #endif
34 #endif
35 #include <sys/stat.h>
36 #include <afs/assert.h>
37 #include <rx/xdr.h>
38 #include <rx/rx.h>
39 #include <afs/afsint.h>
40 #include <afs/nfs.h>
41 #include <afs/errors.h>
42 #include <lock.h>
43 #include <lwp.h>
44 #include <afs/ihandle.h>
45 #include <afs/vnode.h>
46 #include <afs/volume.h>
47 #include <afs/partition.h>
48 #include "dump.h"
49 #include <afs/fssync.h>
50 #include <afs/acl.h>
51 #include "volser.h"
52 #include "volint.h"
53
54 extern int DoLogging;
55
56 /* This iod stuff is a silly little package to emulate the old qi_in stuff, which
57    emulated the stdio stuff.  There is a big assumption here, that the
58    rx_Read will never be called directly, by a routine like readFile, when
59    there is an old character that was pushed back with iod_ungetc.  This
60    is really bletchy, and is here for compatibility only.  Eventually,
61    we should define a volume format that doesn't require
62    the pushing back of characters (i.e. characters should not double both
63    as an end marker and a begin marker) */
64 struct iod {
65     struct rx_call *call;       /* call to which to write, might be an array */
66     int device;                 /* dump device ID for volume */
67     int parentId;               /* dump parent ID for volume */
68     struct DiskPartition *dumpPartition; /* Dump partition. */
69     struct rx_call **calls;      /* array of pointers to calls */
70     int ncalls;                 /* how many calls/codes in array */
71     int *codes;                 /* one return code for each call */
72     char haveOldChar;           /* state for pushing back a character */
73     char oldChar;
74 };
75
76
77 /* Forward Declarations */
78 static int DumpDumpHeader(register struct iod *iodp, register Volume *vp,
79                           afs_int32 fromtime);
80 static int DumpPartial(register struct iod *iodp, register Volume *vp,
81                        afs_int32 fromtime, int dumpAllDirs);
82 static int DumpVnodeIndex(register struct iod *iodp, Volume *vp,
83                           VnodeClass class, afs_int32 fromtime, int forcedump);
84 static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
85                      int volid, int vnodeNumber, int dumpEverything);
86 static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp);
87 static int ReadVnodes(register struct iod *iodp, Volume *vp,
88                       int incremental, afs_int32 *Lbuf, afs_int32 s1,
89                       afs_int32 *Sbuf, afs_int32 s2, afs_int32 delo);
90 static afs_offs_t volser_WriteFile(int vn, struct iod *iodp,
91                                    FdHandle_t *handleP,
92                                    int tag, Error *status);
93
94
95 static void iod_Init(register struct iod *iodp, register struct rx_call *call)
96 {
97     iodp->call = call;
98     iodp->haveOldChar = 0;
99     iodp->ncalls = 1;
100     iodp->calls = (struct rx_call **) 0;
101 }
102
103 static void iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls,
104                    int *codes)
105 {
106
107   iodp->calls = calls;
108   iodp->haveOldChar = 0;
109   iodp->ncalls = ncalls;
110   iodp->codes = codes;
111   iodp->call = (struct rx_call *) 0;
112 }
113
114 /* N.B. iod_Read doesn't check for oldchar (see previous comment) */
115 #define iod_Read(iodp, buf, nbytes) rx_Read((iodp)->call, buf, nbytes)
116
117 /* For the single dump case, it's ok to just return the "bytes written"
118  * that rx_Write returns, since all the callers of iod_Write abort when
119  * the returned value is less than they expect.  For the multi dump case,
120  * I don't think we want half the replicas to go bad just because one 
121  * connection timed out, but if they all time out, then we should give up. 
122  */
123 static int iod_Write(struct iod *iodp, char *buf, int nbytes)
124 {
125   int code, i;
126   int one_success = 0;
127
128   assert ((iodp->call && iodp->ncalls == 1 && !iodp->calls) ||
129           (!iodp->call && iodp->ncalls >= 1 && iodp->calls));
130
131   if (iodp->call) {
132     code = rx_Write(iodp->call, buf, nbytes); 
133     return code;     
134   }
135
136   for (i=0; i < iodp->ncalls; i++) {
137     if (iodp->calls[i] && !iodp->codes[i]) {
138       code = rx_Write(iodp->calls[i], buf, nbytes);
139       if (code != nbytes) { /* everything gets merged into a single error */
140         iodp->codes[i] = VOLSERDUMPERROR;  /* but that's exactly what the */
141       }                                    /* standard dump does, anyways */
142       else {
143         one_success = TRUE;
144       }
145     }
146   } /* for all calls */
147
148 if (one_success)
149   return nbytes;
150 else return 0;
151 }
152
153 static void iod_ungetc(struct iod *iodp, int achar)
154 {
155     iodp->oldChar = achar;
156     iodp->haveOldChar = 1;
157 }
158
159 static int iod_getc(register struct iod *iodp)
160 {
161     unsigned char t;
162    
163     if (iodp->haveOldChar) {
164         iodp->haveOldChar = 0;
165         return iodp->oldChar;
166     }
167     if (iod_Read(iodp, &t, 1) == 1) return t;
168     return EOF;
169 }
170
171 static int ReadShort(register struct iod *iodp, register unsigned short *sp)
172 {
173     register b1,b0;
174     b1 = iod_getc(iodp);
175     b0 = iod_getc(iodp);
176     *sp = (b1<<8) | b0;
177     return b0 != EOF;
178 }
179
180 static int ReadInt32(register struct iod *iodp, afs_uint32 *lp)
181 {
182     afs_uint32 register b3,b2,b1,b0;
183     b3 = iod_getc(iodp);
184     b2 = iod_getc(iodp);
185     b1 = iod_getc(iodp);
186     b0 = iod_getc(iodp);
187     *lp = (((((b3<<8)|b2)<<8)|b1)<<8)|b0;
188     return b0 != EOF;
189 }
190
191 static void ReadString(register struct iod *iodp, register char *to,
192                       register int maxa)
193 {
194     register int c;
195     while (maxa--) {
196         if ((*to++ = iod_getc(iodp)) == 0)
197             break;
198     }
199     if (to[-1]) {
200         while ((c = iod_getc(iodp)) && c != EOF);
201         to[-1] = 0;
202     }
203 }
204
205 static void ReadByteString(register struct iod *iodp, register byte *to,
206                    register int size)
207 {
208     while (size--)
209         *to++ = iod_getc(iodp);
210 }
211
212 static int ReadVolumeHeader(register struct iod *iodp, VolumeDiskData *vol)
213 {
214     register tag;
215     afs_uint32 trash;
216     memset(vol, 0, sizeof(*vol));
217     while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
218         switch (tag) {
219             case 'i':
220                 if(!ReadInt32(iodp, &vol->id)) return VOLSERREAD_DUMPERROR;
221                 break;
222             case 'v':
223                 if(!ReadInt32(iodp, &trash)) return VOLSERREAD_DUMPERROR;
224                 break;
225             case 'n':
226                  ReadString(iodp, vol->name, sizeof(vol->name));
227                 /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */
228                 break;
229             case 's':
230                 vol->inService = iod_getc(iodp );
231                 break;
232             case 'b':
233                 vol->blessed = iod_getc(iodp );
234                 break;
235             case 'u':
236                 if(!ReadInt32(iodp, &vol->uniquifier)) return VOLSERREAD_DUMPERROR;
237                 break;
238             case 't':
239                 vol->type = iod_getc(iodp );
240                 break;
241             case 'p':
242                 if(!ReadInt32(iodp, &vol->parentId)) return VOLSERREAD_DUMPERROR;
243                 break;
244             case 'c':
245                 if(!ReadInt32(iodp, &vol->cloneId)) return VOLSERREAD_DUMPERROR;
246                 break;
247             case 'q':
248                 if(!ReadInt32(iodp, (afs_uint32 *)&vol->maxquota)) return VOLSERREAD_DUMPERROR;
249                 break;
250             case 'm':
251                 if(!ReadInt32(iodp, (afs_uint32 *)&vol->minquota)) return VOLSERREAD_DUMPERROR;
252                 break;
253             case 'd':
254                 if(!ReadInt32(iodp, (afs_uint32 *)&vol->diskused)) return VOLSERREAD_DUMPERROR; /* Bogus:  should calculate this */
255                 break;
256             case 'f':
257                 if(!ReadInt32(iodp, (afs_uint32 *)&vol->filecount)) return VOLSERREAD_DUMPERROR;
258                 break;
259             case 'a':
260                 if(!ReadInt32(iodp, &vol->accountNumber)) return VOLSERREAD_DUMPERROR;
261                 break;
262             case 'o':
263                 if(!ReadInt32(iodp, &vol->owner)) return VOLSERREAD_DUMPERROR;
264                 break;
265             case 'C':
266                 if(!ReadInt32(iodp, &vol->creationDate)) return VOLSERREAD_DUMPERROR;
267                 break;
268             case 'A':
269                 if(!ReadInt32(iodp, &vol->accessDate)) return VOLSERREAD_DUMPERROR;
270                 break;
271             case 'U':
272                 if(!ReadInt32(iodp, &vol->updateDate)) return VOLSERREAD_DUMPERROR;
273                 break;
274             case 'E':
275                 if(!ReadInt32(iodp, &vol->expirationDate)) return VOLSERREAD_DUMPERROR;
276                 break;
277             case 'B':
278                 if(!ReadInt32(iodp, &vol->backupDate)) return VOLSERREAD_DUMPERROR;
279                 break;
280             case 'O':
281                 ReadString(iodp, vol->offlineMessage, sizeof(vol->offlineMessage));
282                 break;
283             case 'M':
284                 /*
285                  * Detailed volume statistics are never stored in dumps,
286                  * so we just restore either the null string if this volume
287                  * had already been set to store statistics, or the old motd
288                  * contents otherwise.  It doesn't matter, since this field
289                  * will soon get initialized anyway.
290                  */
291                 ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE);
292                 break;
293             case 'W': {
294                 unsigned short length;
295                 int i;
296                 afs_uint32 data;
297                 if(!ReadShort(iodp, &length)) return VOLSERREAD_DUMPERROR;
298                 for (i = 0; i<length; i++) {
299                     if(!ReadInt32(iodp, &data)) return VOLSERREAD_DUMPERROR;
300                     if (i < sizeof(vol->weekUse)/sizeof(vol->weekUse[0]))
301                         vol->weekUse[i] = data;
302                 }
303                 break;
304             }
305             case 'D':
306                 if(!ReadInt32(iodp, &vol->dayUseDate)) return VOLSERREAD_DUMPERROR;
307                 break;
308             case 'Z':
309                 if(!ReadInt32(iodp, (afs_uint32 *)&vol->dayUse)) return VOLSERREAD_DUMPERROR;
310                 break;
311         }
312     }
313     iod_ungetc(iodp, tag);
314     return 0;
315 }
316
317 static int DumpTag(register struct iod *iodp, register int tag)
318 {
319     char p;
320     
321     p = tag;
322     return((iod_Write(iodp, &p, 1) == 1)? 0 : VOLSERDUMPERROR);
323     
324 }
325
326 static int DumpByte(register struct iod *iodp, char tag, byte value)
327 {
328     char tbuffer[2];
329     register byte *p = (unsigned char *) tbuffer;
330     *p++ = tag;
331     *p = value;
332     return((iod_Write(iodp, tbuffer, 2) == 2)? 0: VOLSERDUMPERROR);
333 }
334
335 #define putint32(p, v)  *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
336 #define putshort(p, v) *p++ = v>>8, *p++ = v
337
338 static int DumpDouble(register struct iod *iodp, char tag,
339                       register afs_uint32 value1, register afs_uint32 value2)
340 {
341     char tbuffer[9];
342     register byte *p = (unsigned char *) tbuffer;
343     *p++ = tag;
344     putint32(p, value1);
345     putint32(p, value2);
346     return((iod_Write(iodp, tbuffer, 9) == 9)? 0: VOLSERDUMPERROR);
347 }
348
349 static int DumpInt32(register struct iod *iodp, char tag,
350                      register afs_uint32 value)
351 {
352     char tbuffer[5];
353     register byte *p = (unsigned char *) tbuffer;
354     *p++ = tag;
355     putint32(p, value);
356     return((iod_Write(iodp, tbuffer, 5) == 5)? 0: VOLSERDUMPERROR);
357 }
358
359 static int DumpArrayInt32(register struct iod *iodp, char tag,
360                           register afs_uint32 *array, register int nelem)
361 {
362     char tbuffer[4];
363     register afs_uint32 v ;
364     int code = 0;
365     register byte *p = (unsigned char *) tbuffer;
366     *p++ = tag;
367     putshort(p, nelem);
368     code = iod_Write(iodp, tbuffer, 3);
369     if (code != 3) return VOLSERDUMPERROR;
370     while (nelem--) {
371         p = (unsigned char *) tbuffer;
372         v = *array++;/*this was register */
373         
374         putint32(p, v);
375         code = iod_Write(iodp, tbuffer, 4);
376         if(code != 4) return VOLSERDUMPERROR;
377     }
378     return 0;
379 }
380
381 static int DumpShort(register struct iod *iodp, char tag, unsigned int value)
382 {
383     char tbuffer[3];
384     register byte *p = (unsigned char *) tbuffer;
385     *p++ = tag;
386     *p++ = value>>8;
387     *p = value;
388     return((iod_Write(iodp, tbuffer, 3) == 3)? 0: VOLSERDUMPERROR);
389 }
390
391 static int DumpBool(register struct iod *iodp, char tag, unsigned int value)
392 {
393     char tbuffer[2];
394     register byte *p = (unsigned char *) tbuffer;
395     *p++ = tag;
396     *p = value;
397     return((iod_Write(iodp, tbuffer, 2) == 2)? 0: VOLSERDUMPERROR);
398 }
399
400 static int DumpString(register struct iod *iodp, char tag, register char *s)
401 {
402     register n;
403     int code = 0;
404     code = iod_Write(iodp, &tag, 1);
405     if(code != 1) return VOLSERDUMPERROR;
406     n = strlen(s)+1;
407     code = iod_Write(iodp, s, n);
408     if(code != n) return VOLSERDUMPERROR;
409     return 0;
410 }
411
412 static int DumpByteString(register struct iod *iodp, char tag,
413                           register byte *bs, register int nbytes)
414 {
415     int code = 0;
416
417     code = iod_Write(iodp, &tag, 1);
418     if(code != 1) return VOLSERDUMPERROR;
419     code = iod_Write(iodp, (char *)bs, nbytes);
420     if(code != nbytes) return VOLSERDUMPERROR;
421     return 0;
422 }
423     
424 static int DumpFile(struct iod *iodp, int vnode, FdHandle_t *handleP)
425 {
426     int   code = 0, lcode = 0, error = 0;
427     afs_int32 pad = 0, offset;
428     afs_size_t   n, nbytes, howMany, howBig;
429     byte  *p;
430 #ifdef AFS_LARGEFILE_ENV
431     struct stat64 status;
432 #else
433     struct stat status;
434 #endif
435     afs_size_t size;
436 #ifdef  AFS_AIX_ENV
437 #include <sys/statfs.h>
438     struct statfs tstatfs;
439 #endif
440
441 #ifdef AFS_NT40_ENV
442     howBig = _filelength(handleP->fd_fd);
443     howMany = 4096;
444
445 #else
446 #ifdef AFS_LARGEFILE_ENV
447     fstat64(handleP->fd_fd, &status);
448 #else /* !AFS_LARGEFILE_ENV */
449     fstat(handleP->fd_fd, &status);
450 #endif /* !AFS_LARGEFILE_ENV */
451     howBig = status.st_size;
452
453 #ifdef  AFS_AIX_ENV
454     /* Unfortunately in AIX valuable fields such as st_blksize are 
455      * gone from the stat structure.
456      */
457     fstatfs(handleP->fd_fd, &tstatfs);
458     howMany = tstatfs.f_bsize;
459 #else
460     howMany = status.st_blksize;
461 #endif /* AFS_AIX_ENV */
462 #endif /* AFS_NT40_ENV */
463
464
465     size = FDH_SIZE(handleP);
466 #ifdef AFS_LARGEFILE_ENV
467     {
468         afs_uint32      hi,lo;
469         SplitInt64(size, hi, lo);
470         if (hi == 0L) {
471             code = DumpInt32(iodp, 'f', lo);
472         } else {
473             code = DumpDouble(iodp, 'h', hi, lo);
474         }
475     }
476 #else /* !AFS_LARGEFILE_ENV */
477     code = DumpInt32(iodp, 'f', size);
478 #endif /* !AFS_LARGEFILE_ENV */
479     if (code) {
480        return VOLSERDUMPERROR;
481     }
482
483     p = (unsigned char *) malloc(howMany);
484     if (!p) {
485        Log("1 Volser: DumpFile: no memory");
486        return VOLSERDUMPERROR;
487     }
488
489     for (nbytes = size; (nbytes && !error); nbytes -= howMany) {
490         if (nbytes < howMany) 
491            howMany = nbytes;
492
493         /* Read the data - unless we know we can't */
494         n = (lcode ? 0 : FDH_READ(handleP, p, howMany));        
495
496         /* If read any good data and we null padded previously, log the
497          * amount that we had null padded.
498          */
499         if ((n > 0) && pad) {
500            Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n",
501                pad, offset);
502            pad = 0;
503         }
504
505         /* If didn't read enough data, null padd the rest of the buffer. This
506          * can happen if, for instance, the media has some bad spots. We don't
507          * want to quit the dump, so we start null padding.
508          */
509         if (n < howMany) {
510            /* Record the read error */
511            if (n < 0) {
512               n = 0;
513               Log("1 Volser: DumpFile: Error %d reading inode %s for vnode %d\n", 
514                   errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
515            }
516            else if (!pad) {
517               Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n",
518                   PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
519            }
520            
521            /* Pad the rest of the buffer with zeros. Remember offset we started 
522             * padding. Keep total tally of padding.
523             */
524            memset(p+n, 0, howMany-n);
525            if (!pad)
526               offset = (howBig - nbytes) + n;
527            pad += (howMany-n);
528            
529            /* Now seek over the data we could not get. An error here means we
530             * can't do the next read.
531             */
532            lcode = FDH_SEEK(handleP, ((size - nbytes) + howMany), SEEK_SET);
533            if (lcode != ((size - nbytes) + howMany)) {
534               if (lcode < 0) {
535                  Log("1 Volser: DumpFile: Error %d seeking in inode %s for vnode %d\n",
536                      errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
537               }
538               else {
539                  Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n",
540                      PrintInode(NULL, handleP->fd_ih->ih_ino), vnode);
541                  lcode = -1;
542               }
543            }
544            else {
545              lcode = 0;
546            }
547         }
548
549         /* Now write the data out */
550         if (iod_Write(iodp, (char *)p, howMany) != howMany) 
551            error = VOLSERDUMPERROR;
552         IOMGR_Poll();
553     }
554
555     if (pad) {                     /* Any padding we hadn't reported yet */
556        Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n",
557            pad, offset);
558     }
559
560     free(p);
561     return error;
562 }
563
564 static int DumpVolumeHeader(register struct iod *iodp, register Volume *vp)
565 {
566     int code = 0;
567     static char nullString[1] = "";  /*The ``contents'' of motd*/
568
569     if (!code) code = DumpTag(iodp, D_VOLUMEHEADER);
570     if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));}
571     if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version);
572     if (!code) code = DumpString(iodp, 'n',V_name(vp));
573     if (!code) code = DumpBool(iodp, 's',V_inService(vp));
574     if (!code) code = DumpBool(iodp, 'b',V_blessed(vp));
575     if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp));
576     if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp));
577     if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));}
578     if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp));
579     if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp));
580     if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp));
581     if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp));
582     if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp));
583     if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp));
584     if (!code) code = DumpInt32(iodp, 'o', V_owner(vp));
585     if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp));  /* Rw volume creation date */
586     if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp));
587     if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp));
588     if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp));
589     if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp));            /* Rw volume backup clone date */
590     if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp));
591     /*
592      * We do NOT dump the detailed volume statistics residing in the old
593      * motd field, since we cannot tell from the info in a dump whether
594      * statistics data has been put there.  Instead, we dump a null string,
595      * just as if that was what the motd contained.
596      */
597     if (!code) code = DumpString(iodp, 'M', nullString);
598     if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0]));
599     if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp));
600     if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp));
601     return code;
602 }
603
604 static int DumpEnd(register struct iod *iodp)
605 {
606     return(DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC));
607 }
608
609 /* Guts of the dump code */
610
611 /* Dump a whole volume */
612 int DumpVolume(register struct rx_call *call, register Volume *vp,
613                       afs_int32 fromtime, int dumpAllDirs)
614 {
615     struct iod iod;
616     int code = 0;
617     register struct iod *iodp = &iod;
618     iod_Init(iodp, call);
619     
620     if (!code) code = DumpDumpHeader(iodp, vp, fromtime);
621     
622     if (!code) code = DumpPartial(iodp, vp, fromtime, dumpAllDirs);
623     
624 /* hack follows.  Errors should be handled quite differently in this version of dump than they used to be.*/
625     if (rx_Error(iodp->call)) {
626         Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n", rx_Error(iodp->call));
627         return VOLSERDUMPERROR;
628     }
629     if (!code) code = DumpEnd(iodp);
630     
631     return code;
632 }
633
634 /* Dump a volume to multiple places*/
635 int DumpVolMulti(struct rx_call **calls, int ncalls, Volume *vp,
636                  afs_int32 fromtime, int dumpAllDirs, int *codes)
637 {
638     struct iod iod;
639     int code = 0;
640     iod_InitMulti(&iod, calls, ncalls, codes);
641     
642     if (!code) code = DumpDumpHeader(&iod, vp, fromtime);
643     if (!code) code = DumpPartial(&iod, vp, fromtime, dumpAllDirs);
644     if (!code) code = DumpEnd(&iod);
645     return code;
646 }
647
648 /* A partial dump (no dump header) */
649 static int DumpPartial(register struct iod *iodp, register Volume *vp,
650                        afs_int32 fromtime, int dumpAllDirs)
651 {
652     int code = 0;
653     if (!code) code = DumpVolumeHeader(iodp, vp);
654     if (!code) code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs);
655     if (!code) code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0);
656     return code;
657 }
658
659 static int DumpVnodeIndex(register struct iod *iodp, Volume *vp,
660                           VnodeClass class, afs_int32 fromtime, int forcedump)
661 {
662     register int code = 0;
663     register struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
664     char buf[SIZEOF_LARGEDISKVNODE];
665     struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf;
666     StreamHandle_t *file;
667     FdHandle_t *fdP;
668     int size;
669     int flag;
670     register int vnodeIndex, nVnodes;
671
672     fdP = IH_OPEN(vp->vnodeIndex[class].handle);
673     assert(fdP != NULL);
674     file = FDH_FDOPEN(fdP, "r+");
675     assert(file != NULL);
676     size = OS_SIZE(fdP->fd_fd);
677     assert(size != -1);
678     nVnodes = (size / vcp->diskSize) - 1;
679     if (nVnodes > 0) {
680         assert((nVnodes+1)*vcp->diskSize == size);
681         assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
682     }
683     else nVnodes = 0;
684     for (vnodeIndex = 0; nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code;
685       nVnodes--, vnodeIndex++) {
686         flag = forcedump || (vnode->serverModifyTime >= fromtime);
687         /* Note:  the >= test is very important since some old volumes may not have
688            a serverModifyTime.  For an epoch dump, this results in 0>=0 test, which
689            does dump the file! */
690         if (!code) code = DumpVnode(iodp, vnode, V_id(vp), bitNumberToVnodeNumber(vnodeIndex, class), flag);
691         if (!flag) IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */
692     }
693     STREAM_CLOSE(file);
694     FDH_CLOSE(fdP);
695     return code;
696 }
697
698 static int DumpDumpHeader(register struct iod *iodp, register Volume *vp,
699                           afs_int32 fromtime)
700 {
701     int code = 0;
702     int UseLatestReadOnlyClone = 1;
703     afs_int32 dumpTimes[2];
704     iodp->device = vp->device;
705     iodp->parentId = V_parentId(vp);
706     iodp->dumpPartition = vp->partition;
707     if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION);
708     if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp));
709     if (!code) code = DumpString(iodp, 'n',V_name(vp));
710     dumpTimes[0] = fromtime;
711     dumpTimes[1] = V_backupDate(vp);    /* Until the time the clone was made */
712     if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2);
713     return code;
714 }
715
716 static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v,
717                      int volid, int vnodeNumber, int dumpEverything)
718 {
719     int code = 0;
720     IHandle_t *ihP;
721     FdHandle_t *fdP;
722
723     if (!v || v->type == vNull)
724         return code;
725     if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier);
726     if (!dumpEverything)
727         return code;
728     if (!code) code = DumpByte(iodp, 't',(byte)v->type);
729     if (!code) code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */
730     if (!code) code = DumpInt32(iodp, 'v', v->dataVersion);
731     if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime);
732     if (!code) code = DumpInt32(iodp, 'a', v->author);
733     if (!code) code = DumpInt32(iodp, 'o', v->owner);
734     if (!code && v->group) code = DumpInt32(iodp, 'g', v->group);       /* default group is 0 */
735     if (!code) code = DumpShort(iodp, 'b', v->modeBits);
736     if (!code) code = DumpInt32(iodp, 'p', v->parent);
737     if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime);
738     if (v->type == vDirectory) {
739         acl_HtonACL(VVnodeDiskACL(v));
740         if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v));
741     }
742     if (VNDISK_GET_INO(v)) {
743         IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v));
744         fdP = IH_OPEN(ihP);
745         if (fdP == NULL) {
746             Log("1 Volser: DumpVnode: dump: Unable to open inode %d for vnode %d (volume %d); not dumped, error %d\n",
747                 VNDISK_GET_INO(v), vnodeNumber, volid, errno);
748             IH_RELEASE(ihP);
749             return VOLSERREAD_DUMPERROR;
750         }
751         code = DumpFile(iodp, vnodeNumber, fdP);
752         FDH_CLOSE(fdP);
753         IH_RELEASE(ihP);
754     }
755     return code;
756 }
757
758
759 int ProcessIndex(Volume *vp, VnodeClass class, afs_int32 **Bufp, int *sizep,
760                  int del)
761 {
762     int i, nVnodes, offset, code, index=0;
763     afs_int32 *Buf;
764     int cnt=0;  
765     int size;
766     StreamHandle_t *afile;
767     FdHandle_t *fdP;
768     struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
769     char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE];
770     register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf;
771     
772     memset(zero, 0, sizeof(zero));      /* zero out our proto-vnode */
773     fdP = IH_OPEN(vp->vnodeIndex[class].handle);
774     if (fdP == NULL)
775         return -1;
776     afile = FDH_FDOPEN(fdP, "r+");
777     if (del) {
778         int cnt1=0;
779         Buf = *Bufp;
780         for (i = 0; i<*sizep; i++) {
781             if (Buf[i]) {
782                 cnt++;
783                 STREAM_SEEK(afile, Buf[i], 0);    
784                 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
785                 if (code == 1) {
786                     if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
787                         cnt1++;
788                         if (DoLogging) {
789 #ifdef AFS_LARGEFILE_ENV
790                            afs_offs_t fileLen;
791                            VNDISK_GET_LEN(fileLen, vnode);
792                            Log("RestoreVolume %d Cleanup: Removing old vnode=%d inode=%d size=(0X%x,0X%x)\n", 
793                                V_id(vp), bitNumberToVnodeNumber(i,class),
794                                VNDISK_GET_INO(vnode),
795                                (unsigned) (fileLen >> 32),
796                                (unsigned) (fileLen & 0xffffffff));
797 #else /* !AFS_LARGEFILE_ENV */
798                            Log("RestoreVolume %d Cleanup: Removing old vnode=%d inode=%d size=%d\n", 
799                                V_id(vp), bitNumberToVnodeNumber(i,class),
800                                VNDISK_GET_INO(vnode), vnode->length);
801 #endif /* !AFS_LARGEFILE_ENV */
802                         }
803                         IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode),
804                              V_parentId(vp));
805                         DOPOLL;
806                     }
807                     STREAM_SEEK(afile, Buf[i], 0);
808                     (void ) STREAM_WRITE(zero, vcp->diskSize, 1, afile);        /* Zero it out */
809                 }
810                 Buf[i] = 0;
811             }
812         }
813         if (DoLogging) {
814            Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n",
815                cnt1, V_id(vp));
816         }
817         STREAM_FLUSH(afile);            /* ensure 0s are on the disk */
818         OS_SYNC(afile->str_fd);
819     } else {
820         size = OS_SIZE(fdP->fd_fd);
821         assert(size != -1);
822         nVnodes = (size <= vcp->diskSize ? 0 :
823                    size-vcp->diskSize) >> vcp->logSize;
824         if (nVnodes > 0) {
825             Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32));
826             if (Buf == NULL) return 1;
827             memset((char *)Buf, 0, nVnodes * sizeof(afs_int32));
828             STREAM_SEEK(afile, offset = vcp->diskSize, 0);
829             while (1) {
830                 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
831                 if (code != 1) {
832                     break;
833                 }
834                 if (vnode->type != vNull && VNDISK_GET_INO(vnode)) {
835                     Buf[(offset >> vcp->logSize)-1] = offset;
836                     cnt++;
837                 }
838                 offset += vcp->diskSize;
839             }
840             *Bufp = Buf;
841             *sizep = nVnodes;
842         }
843     }
844     STREAM_CLOSE(afile);
845     FDH_CLOSE(fdP);
846     return 0;
847 }
848
849
850 int RestoreVolume(register struct rx_call *call, Volume *avp,
851                   int incremental, struct restoreCookie *cookie)
852 {
853     VolumeDiskData vol;
854     struct DumpHeader header;
855     afs_uint32 endMagic;
856     Error error = 0, vupdate;
857     register Volume *vp;
858     struct iod iod;
859     register struct iod *iodp = &iod;
860     afs_int32 *b1=0, *b2=0;
861     int s1=0, s2=0, delo=0, tdelo;
862     int tag;
863
864     iod_Init(iodp, call);
865     
866     vp = avp;
867     if (!ReadDumpHeader(iodp, &header)){
868         Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n");
869         return VOLSERREAD_DUMPERROR;
870     }
871     if (iod_getc(iodp) != D_VOLUMEHEADER){
872         Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n");
873         return VOLSERREAD_DUMPERROR;
874     }
875     if(ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) return VOLSERREAD_DUMPERROR;
876
877     delo = ProcessIndex(vp, vLarge, &b1, &s1, 0);
878     if (!delo) delo = ProcessIndex(vp, vSmall, &b2, &s2, 0);
879     if (delo) {
880        if (b1) free((char *)b1);
881        if (b2) free((char *)b2);
882        b1 = b2 = 0;
883     }
884
885     strncpy(vol.name,cookie->name,VOLSER_OLDMAXVOLNAME);
886     vol.type = cookie->type;
887     vol.cloneId = cookie->clone;
888     vol.parentId = cookie->parent;
889     
890
891     tdelo = delo;
892     while (1) {
893        if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) {
894           error =  VOLSERREAD_DUMPERROR;
895           goto clean;
896        }
897        tag = iod_getc(iodp);
898        if (tag != D_VOLUMEHEADER)
899           break;
900        if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) {
901           error = VOLSERREAD_DUMPERROR;
902           goto out;
903        }
904        tdelo = -1;
905     }
906     if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic) || endMagic != DUMPENDMAGIC){
907        Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n");
908        error =  VOLSERREAD_DUMPERROR;
909        goto clean;
910     }
911
912
913     if (iod_getc(iodp) != EOF) {
914         Log("1 Volser: RestoreVolume: Unrecognized postamble in dump; restore aborted\n");
915         error = VOLSERREAD_DUMPERROR;
916         goto clean;
917     }
918
919     if (!delo) {
920         ProcessIndex(vp, vLarge, &b1, &s1, 1);
921         ProcessIndex(vp, vSmall, &b2, &s2, 1);
922     }
923
924  clean:
925     ClearVolumeStats(&vol);
926     CopyVolumeHeader(&vol, &V_disk(vp));
927     V_destroyMe(vp) = 0;
928     VUpdateVolume(&vupdate, vp);
929     if (vupdate) {
930         Log("1 Volser: RestoreVolume: Unable to rewrite volume header; restore aborted\n");
931         error = VOLSERREAD_DUMPERROR;
932         goto out;
933     }
934  out:
935     /* Free the malloced space above */
936     if (b1) free((char *)b1);
937     if (b2) free((char *)b2);
938     return error;
939 }
940
941 static int ReadVnodes(register struct iod *iodp, Volume *vp,
942                       int incremental, afs_int32 *Lbuf, afs_int32 s1,
943                       afs_int32 *Sbuf, afs_int32 s2, afs_int32 delo)
944 {
945     afs_int32 vnodeNumber;
946     char buf[SIZEOF_LARGEDISKVNODE];
947     register tag;
948     struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf;
949     struct VnodeDiskObject oldvnode;
950     int idx;
951     VnodeClass class;
952     struct VnodeClassInfo *vcp;
953     IHandle_t *tmpH;
954     FdHandle_t *fdP;
955     Inode       nearInode;
956
957     tag = iod_getc(iodp);
958     V_pref(vp, nearInode);
959     while (tag == D_VNODE) {
960         int haveStuff = 0;
961         memset(buf, 0, sizeof (buf));
962         if (!ReadInt32(iodp, (afs_uint32 *)&vnodeNumber))
963             break;
964
965         ReadInt32(iodp, &vnode->uniquifier);
966         while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) {
967             haveStuff = 1;
968             switch (tag) {
969                 case 't':
970                     vnode->type = (VnodeType) iod_getc(iodp);
971                     break;
972                 case 'l':
973                     {
974                         unsigned short tlc;
975                         ReadShort(iodp, &tlc);
976                         vnode->linkCount = (signed int)tlc;
977                     }
978                     break;
979                 case 'v':
980                     ReadInt32(iodp, &vnode->dataVersion);
981                     break;
982                 case 'm':
983                     ReadInt32(iodp, &vnode->unixModifyTime);
984                     break;
985                 case 's':
986                     ReadInt32(iodp, &vnode->serverModifyTime);
987                     break;
988                 case 'a':
989                     ReadInt32(iodp, &vnode->author);
990                     break;
991                 case 'o':
992                     ReadInt32(iodp, &vnode->owner);
993                     break;
994                 case 'g':
995                     ReadInt32(iodp, (afs_uint32 *)&vnode->group);
996                     break;
997                 case 'b': {
998                     unsigned short modeBits;
999                     ReadShort(iodp, &modeBits);
1000                     vnode->modeBits = (unsigned int)modeBits;
1001                     break;
1002                 }
1003                 case 'p':
1004                     ReadInt32(iodp, &vnode->parent);
1005                     break;
1006                 case 'A':
1007                     ReadByteString(iodp, (byte *)VVnodeDiskACL(vnode),
1008                                    VAclDiskSize(vnode));
1009                     acl_NtohACL(VVnodeDiskACL(vnode));
1010                     break;
1011 #ifdef AFS_LARGEFILE_ENV
1012                 case 'h':
1013 #endif
1014                 case 'f': {
1015                     Inode ino;
1016                     Error error;
1017                     afs_offs_t fileLen;
1018
1019                     ino = IH_CREATE(V_linkHandle(vp),
1020                                     V_device(vp),
1021                                     VPartitionPath(V_partition(vp)),
1022                                     nearInode, V_parentId(vp), vnodeNumber,
1023                                     vnode->uniquifier,
1024                                     vnode->dataVersion);
1025                     if (!VALID_INO(ino)) {
1026                         perror("unable to allocate inode");
1027                         Log("1 Volser: ReadVnodes: Restore aborted\n");
1028                         return VOLSERREAD_DUMPERROR;
1029                     }
1030                     nearInode = ino;
1031                     VNDISK_SET_INO(vnode, ino);
1032                     IH_INIT(tmpH, vp->device, V_parentId(vp), ino);
1033                     fdP = IH_OPEN(tmpH);
1034                     if (fdP == NULL) {
1035                         IH_RELEASE(tmpH);
1036                         return VOLSERREAD_DUMPERROR;
1037                     }
1038                     
1039                     fileLen = volser_WriteFile(vnodeNumber, iodp, fdP,
1040                                                      tag, &error);
1041                     VNDISK_SET_LEN(vnode, fileLen);
1042                     FDH_REALLYCLOSE(fdP);
1043                     IH_RELEASE(tmpH);
1044                     if (error) {
1045                         Log("1 Volser: ReadVnodes: IDEC inode %d\n", ino);
1046                         IH_DEC(V_linkHandle(vp), ino, V_parentId(vp));
1047                         return VOLSERREAD_DUMPERROR;
1048                     }
1049                     break;
1050                 }
1051             }
1052         }
1053
1054         class = vnodeIdToClass(vnodeNumber);
1055         vcp   = &VnodeClassInfo[class];
1056
1057         /* Mark this vnode as in this dump - so we don't delete it later */
1058         if (!delo) {
1059            idx = (vnodeIndexOffset(vcp,vnodeNumber) >> vcp->logSize) - 1;
1060            if (class == vLarge) {
1061               if (Lbuf && (idx < s1)) Lbuf[idx] = 0;
1062            } else {
1063               if (Sbuf && (idx < s2)) Sbuf[idx] = 0;
1064            }
1065         }
1066
1067         if (haveStuff) {
1068             FdHandle_t *fdP = IH_OPEN(vp->vnodeIndex[class].handle);
1069             if (fdP == NULL) {
1070                 Log("1 Volser: ReadVnodes: Error opening vnode index; restore aborted\n");
1071                 return VOLSERREAD_DUMPERROR;
1072             }
1073             if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) < 0) {
1074                 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1075                 FDH_REALLYCLOSE(fdP);
1076                 return VOLSERREAD_DUMPERROR;
1077             }
1078             if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) == sizeof(oldvnode)) {
1079                 if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) {
1080                     IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode),
1081                          V_parentId(vp));
1082                 }
1083             }
1084             vnode->vnodeMagic = vcp->magic;
1085             if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) < 0) {
1086                 Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n");
1087                 FDH_REALLYCLOSE(fdP);
1088                 return VOLSERREAD_DUMPERROR;
1089             }
1090             if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) {
1091                 Log("1 Volser: ReadVnodes: Error writing vnode index; restore aborted\n");
1092                 FDH_REALLYCLOSE(fdP);
1093                 return VOLSERREAD_DUMPERROR;
1094             }
1095             FDH_CLOSE(fdP);
1096         }
1097     }
1098     iod_ungetc(iodp, tag);
1099
1100
1101     return 0;
1102 }
1103
1104
1105 /* called with disk file only.  Note that we don't have to worry about rx_Read
1106  * needing to read an ungetc'd character, since the ReadInt32 will have read
1107  * it instead.
1108  */
1109 static afs_offs_t volser_WriteFile(int vn, struct iod *iodp, FdHandle_t *handleP,
1110                               int tag, Error *status)
1111 {
1112     afs_int32 code;
1113     afs_offs_t filesize;
1114     afs_offs_t written=0;
1115     register afs_uint32 size = 8192;
1116     register afs_offs_t nbytes;
1117     unsigned char *p;
1118
1119
1120     *status = 0;
1121 #ifdef AFS_64BIT_ENV
1122     {
1123         afs_uint32 filesize_high = 0L, filesize_low = 0L;
1124 #ifdef AFS_LARGEFILE_ENV
1125         if (tag == 'h') {
1126             if (!ReadInt32(iodp, &filesize_high) ) {
1127                 *status = 1;
1128                 return(0);
1129             }
1130         }
1131 #endif
1132         if (!ReadInt32(iodp, &filesize_low)) {
1133             *status = 1;
1134             return(0);
1135         }
1136         FillInt64(filesize, filesize_high, filesize_low);
1137     }
1138 #else /* !AFS_64BIT_ENV */
1139     if (!ReadInt32(iodp, &filesize)) {
1140         *status = 1;
1141         return(0);
1142     }
1143 #endif /* !AFS_64BIT_ENV */
1144     p = (unsigned char *) malloc(size);
1145     if (p == NULL) {
1146         *status = 2;
1147         return(0);
1148     }
1149     for (nbytes = filesize; nbytes; nbytes -= size) {
1150         if (nbytes < size)
1151             size = nbytes;
1152         
1153         if ((code = iod_Read(iodp, p, size)) != size) {
1154 #ifdef AFS_64BIT_ENV
1155             Log("1 Volser: WriteFile: Error reading dump file %d size=(0X%x,0X%x) nbytes=%d (%d of %d); restore aborted\n", vn,
1156                 (unsigned) (filesize >> 32),
1157                 (unsigned) (filesize & 0xffffffff),
1158                 nbytes, code, size);
1159 #else /* !AFS_LARGEFILE_ENV */
1160             Log("1 Volser: WriteFile: Error reading dump file %d size=%d nbytes=%d (%d of %d); restore aborted\n", vn, filesize, nbytes, code, size);
1161 #endif /* !AFS_LARGEFILE_ENV */
1162             *status = 3;
1163             break;
1164         }
1165         code = FDH_WRITE(handleP, p, size);
1166         if (code > 0) written += code;
1167         if (code != size) {
1168             Log("1 Volser: WriteFile: Error creating file in volume; restore aborted\n");
1169             *status = 4;
1170             break;
1171         }
1172     }
1173     free(p);
1174     return(written);
1175 }
1176
1177 static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp)
1178 {
1179     register tag;
1180     afs_uint32 beginMagic;
1181     if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic)
1182        || !ReadInt32(iodp, (afs_uint32 *)&hp->version)
1183        || beginMagic != DUMPBEGINMAGIC
1184        ) return 0;
1185     hp->volumeId = 0;
1186     hp->nDumpTimes = 0;
1187     while ((tag = iod_getc(iodp)) > D_MAX) {
1188         unsigned short arrayLength;
1189         register int i;
1190         switch(tag) {
1191             case 'v':
1192                 if (!ReadInt32(iodp, &hp->volumeId))
1193                     return 0;
1194                 break;
1195             case 'n':
1196                 ReadString(iodp, hp->volumeName, sizeof(hp->volumeName));
1197                 break;
1198             case 't':
1199                 if (!ReadShort(iodp, &arrayLength))
1200                     return 0;
1201                 hp->nDumpTimes = (arrayLength >> 1);
1202                 for (i = 0; i<hp->nDumpTimes; i++)
1203                     if (!ReadInt32(iodp, (afs_uint32 *)&hp->dumpTimes[i].from)
1204                         || !ReadInt32(iodp, (afs_uint32 *)&hp->dumpTimes[i].to))
1205                         return 0;
1206                 break;
1207         }
1208     }
1209     if (!hp->volumeId || !hp->nDumpTimes) {
1210         return 0;
1211     }
1212     iod_ungetc(iodp, tag);
1213     return 1;
1214 }