static int64_t skip_cb(struct archive *arch, void *priv, int64_t request) { struct mp_archive_volume *vol = priv; if (!volume_seek(vol)) return -1; int64_t old = stream_tell(vol->src); stream_skip(vol->src, request); return stream_tell(vol->src) - old; }
static ssize_t read_cb(struct archive *arch, void *priv, const void **buffer) { struct mp_archive_volume *vol = priv; if (!volume_seek(vol)) return -1; int res = stream_read_partial(vol->src, vol->mpa->buffer, sizeof(vol->mpa->buffer)); *buffer = vol->mpa->buffer; return MPMAX(res, 0); }
u32 volume_write(volh handle, u32 sector, u32 count, void *data) { voldata *vh = (voldata*)handle; DWORD written; void *buffer; if (!count) return 0; if (!volume_seek(handle, sector)) return 0; buffer = VirtualAlloc(0, count*vh->ssize, MEM_COMMIT, PAGE_READWRITE); memcpy(buffer, data, count*vh->ssize); if (!WriteFile(vh->dh, buffer, count*vh->ssize, &written,0)) { written = 0; vh->pos = 0xFFFF; } else vh->pos+= written/vh->ssize; VirtualFree(buffer, 0, MEM_RELEASE); return written/vh->ssize; }
u32 volume_read (volh handle, u32 sector, u32 count, void *data) { voldata *vh = (voldata*)handle; DWORD readed; void *buffer; if (!count) return 0; if (!volume_seek(handle, sector)) return 0; buffer = VirtualAlloc(0, count*vh->ssize, MEM_COMMIT, PAGE_READWRITE); if (!ReadFile(vh->dh, buffer, count*vh->ssize, &readed,0)) { readed = 0; vh->pos = 0xFFFF; } else { memcpy(data, buffer, readed); vh->pos+= readed/vh->ssize; } VirtualFree(buffer, 0, MEM_RELEASE); return readed/vh->ssize; }