static int issec2352(FILEH fh) { long fpos; UINT8 buf[2048]; UINT secsize; UINT fsize; fpos = (16 * 2352) + 16; if (file_seek(fh, fpos, FSEEK_SET) != fpos) { goto sec2352_err; } if (file_read(fh, buf, sizeof(buf)) != sizeof(buf)) { goto sec2352_err; } if (memcmp(buf, cd001, 7) != 0) { goto sec2352_err; } secsize = LOADINTELWORD(buf + 128); if (secsize != 2048) { goto sec2352_err; } fsize = file_getsize(fh); if ((fsize % 2352) != 0) { goto sec2352_err; } return(fsize / 2352); sec2352_err: return(-1); }
long issec2448(FILEH fh) { #ifdef CHECK_ISO9660 long fpos; UINT8 buf[2048]; UINT secsize; #endif UINT fsize; #ifdef CHECK_ISO9660 fpos = (16 * 2448) + 16; if (file_seek(fh, fpos, FSEEK_SET) != fpos) { goto sec2448_err; } if (file_read(fh, buf, sizeof(buf)) != sizeof(buf)) { goto sec2448_err; } if (memcmp(buf, cd001, 7) != 0) { goto sec2448_err; } secsize = LOADINTELWORD(buf + 128); if (secsize != 2048) { goto sec2448_err; } #endif fsize = file_getsize(fh); if ((fsize % 2448) != 0) { goto sec2448_err; } return(fsize / 2448); sec2448_err: return(-1); }
/* filename: nombre de un fichero. * file_info: structura donde se guardara la informacion. * retorna: 1 si todo ha ido bien en otro caso 0. */ int file_get_file_info(const char *filename, struct file_info *inf) { int ret; long filesize; if(!filename || !inf) return 0; filesize = file_getsize(filename); if(0 >= filesize || MAX_32BIT < filesize) return 0; memset(inf, 0, sizeof(*inf)); inf->size = filesize; ret = file_extension(filename, inf->ext, FILE_MAX_EXTENSION_NAME); if(0 >= ret) return 0; return 1; }
static int blockset_open_file(struct blockstore *blockStore, struct blockset *bs) { uint64 offset; mtime_t ts; int res; res = file_open(bs->filename, 0 /* R/O */, 0 /* !unbuf */, &bs->desc); if (res) { return res; } bs->filesize = file_getsize(bs->desc); if (bs->filesize < 0) { return errno; } if (bs->filesize > 0) { char *s = print_size(bs->filesize); char *name = file_getname(bs->filename); Log(LGPFX" reading file %s -- %s -- %llu headers.\n", name, s, bs->filesize / sizeof(btc_block_header)); free(name); free(s); } ts = time_get(); offset = 0; while (offset < bs->filesize) { btc_block_header buf[10000]; size_t numRead; size_t numBytes; int numHeaders; int i; numBytes = MIN(bs->filesize - offset, sizeof buf); res = file_pread(bs->desc, offset, buf, numBytes, &numRead); if (res != 0) { break; } if (btc->stop != 0) { res = 1; NOT_TESTED(); break; } numHeaders = numRead / sizeof(btc_block_header); for (i = 0; i < numHeaders; i++) { struct blockentry *be; uint256 hash; be = blockstore_alloc_entry(buf + i); be->written = 1; hash256_calc(buf + i, sizeof buf[0], &hash); if (!blockstore_validate_chkpt(&hash, blockStore->height + 1)) { return 1; } blockstore_add_entry(blockStore, be, &hash); if (i == numHeaders - 1) { bitcui_set_status("loading headers .. %llu%%", (offset + numBytes) * 100 / bs->filesize); } if (i == numHeaders - 1 || (numBytes < sizeof buf && i > numHeaders - 256)) { bitcui_set_last_block_info(&hash, blockStore->height, be->header.timestamp); } } offset += numRead; } ts = time_get() - ts; char hashStr[80]; char *latStr; uint256_snprintf_reverse(hashStr, sizeof hashStr, &blockStore->best_hash); Log(LGPFX" loaded blocks up to %s\n", hashStr); latStr = print_latency(ts); Log(LGPFX" this took %s\n", latStr); free(latStr); return res; }