void figure(const char *fn) { struct af_figure_media_buf afb; int fd = open(fn,O_RDONLY); if(fd<0) err(1,"%s",fn); if(af_figure_media(fd,&afb)){ err(1,"af_figure_media"); } printf("sector size: %d\n",afb.sector_size); printf("total sectors: %"PRId64"\n",afb.total_sectors); printf("max read blocks: %"PRId64"\n",afb.max_read_blocks); exit(0); }
/* Return the size of the raw file */ static int64_t raw_filesize(AFFILE *af) { struct raw_private *rp = RAW_PRIVATE(af); struct stat sb; if(fstat(fileno(rp->raw),&sb)==0){ if(sb.st_mode & S_IFREG){ // only do this for regular files return sb.st_size; } /* See if this is a device that we can figure */ struct af_figure_media_buf afb; if(af_figure_media(fileno(rp->raw),&afb)==0){ if(afb.total_sectors>0 && afb.sector_size>0){ return afb.total_sectors * afb.sector_size; } } } return 0; // no clue }
static int raw_vstat(AFFILE *af,struct af_vnode_info *vni) { struct raw_private *rp = RAW_PRIVATE(af); vni->imagesize = -1; vni->pagesize = RAW_PAGESIZE; // decent page size vni->supports_metadata = 0; vni->changable_pagesize = 1; // change it at any time vni->changable_sectorsize = 1; // change it at any time /* If we can stat the file, use that. */ fflush(rp->raw); struct stat sb; if(fstat(fileno(rp->raw),&sb)==0){ if(sb.st_mode & S_IFREG){ // only do this for regular files vni->imagesize = sb.st_size; } } if(vni->imagesize==-1){ /* See if this is a device that we can figure */ struct af_figure_media_buf afb; if(af_figure_media(fileno(rp->raw),&afb)==0){ if(afb.total_sectors>0 && afb.sector_size>0){ vni->imagesize = afb.total_sectors * afb.sector_size; } } } vni->supports_compression = 0; vni->has_pages = 1; if(rp->raw_popen){ /* popen files require special handling */ vni->has_pages = 0; vni->use_eof = 1; vni->at_eof = feof(rp->raw); // are we there yet? } return 0; }