void affstats(const char *fname) { AFFILE *af = af_open(fname,O_RDONLY,0); if(!af) af_err(1,"af_open(%s)",fname); printf("%s\t",fname); uint32_t segsize=0; int64_t imagesize=0; int64_t blanksectors=0; int64_t badsectors=0; af_get_segq(af,AF_IMAGESIZE,&imagesize); if(af_get_seg(af,AF_PAGESIZE,&segsize,0,0)){ af_get_seg(af,AF_SEGSIZE_D,&segsize,0,0); // check for oldstype } af_get_segq(af,AF_BADSECTORS,&badsectors); af_get_segq(af,AF_BLANKSECTORS,&blanksectors); print_size(imagesize); printf("\t"); fflush(stdout); int64_t compressed_bytes = 0; int64_t uncompressed_bytes = 0; /* Now read through all of the segments and count the number of * data segments. We know the uncompressed size... */ af_rewind_seg(af); char segname[AF_MAX_NAME_LEN+1]; size_t datalen; while(af_get_next_seg(af,segname,sizeof(segname),0,0,&datalen)==0){ int64_t page_num = af_segname_page_number(segname); if(page_num>=0){ compressed_bytes += datalen; uncompressed_bytes += segsize; } } if(uncompressed_bytes > imagesize) uncompressed_bytes = imagesize; print_size(compressed_bytes); printf("\t"); print_size(uncompressed_bytes); printf(" %" I64d " %" I64d,blanksectors,badsectors); putchar('\n'); }
int fix(const char *infile) { char buf[1024]; int flags = (opt_fix ? O_RDWR : O_RDONLY) | O_BINARY; switch(af_identify_file_type(infile,1)){ case AF_IDENTIFY_ERR: perror(infile); return 0; default: fprintf(stderr,"%s is not an AFF file\n",infile); return 0; case AF_IDENTIFY_AFF: break; } printf("%s ",infile); int r=0; /* First see if the if the file begins with an AFF flag */ int fd = open(infile,flags,0666); if(fd<0) err(1,"fopen(%s)",infile); if(read(fd,buf,strlen(AF_HEADER)+1)!=strlen(AF_HEADER)+1) err(1,"can't read AFF file header. Stop."); if(strcmp(buf,AF_HEADER)!=0) err(1,"%s does not begin with an AF_HEADER. Stop.",infile); if(read(fd,buf,strlen(AF_SEGHEAD)+1)!=strlen(AF_SEGHEAD)+1) err(1,"Can't read AF_SEGHEAD after AF_HEADER. Stop."); if(strcmp(buf,AF_SEGHEAD)!=0) err(1,"%s does not have an AF_SEGHEAD after AF_SEGEADER. Stop.",infile); /* Figure out length */ off_t len = lseek(fd,0,SEEK_END); if(len<0) err(1,"Can't seek to end of %s. Stop.",infile); close(fd); AFFILE *af = af_open_with(infile,AF_HALF_OPEN|flags,0,&vnode_aff); printf("Scanning AFF file...\n"); r = (*af->v->open)(af); /* See if we can build a TOC */ if(r<0){ printf("AFF file corrupt at %"I64d" out of %"I64d" (%"I64d" bytes from end)\n", ftello(af->aseg),(int64_t)len,len-ftello(af->aseg)); if(opt_fix){ printf("Truncating... %d \n",fileno(af->aseg)); if(ftruncate(fileno(af->aseg),ftello(af->aseg))){ err(1,"ftruncate"); } } } /* See if it has a GID or an encrypted GID */ if(af_get_seg(af,AF_IMAGE_GID,0,0,0)!=0 && af_get_seg(af,AF_IMAGE_GID AF_AES256_SUFFIX,0,0,0)!=0){ printf("AFF file is missing a GID. "); if(opt_fix){ printf("Making one..."); if(af_make_gid(af)<0) af_err(1,"af_make_gid"); } putchar('\n'); } af_close(af); return 0; }