zdir_patch_t * zdir_patch_new (const char *path, zfile_t *file, zdir_patch_op_t op, const char *alias) { zdir_patch_t *self = (zdir_patch_t *) zmalloc (sizeof (zdir_patch_t)); if (!self) return NULL; self->path = strdup (path); if (self->path) self->file = zfile_dup (file); if (!self->file) { zdir_patch_destroy (&self); return NULL; } self->op = op; // Calculate virtual path for patch (remove path, prefix alias) char *filename = zfile_filename (file, path); if (!filename) { zdir_patch_destroy (&self); return NULL; } assert (*filename != '/'); self->vpath = (char *) zmalloc (strlen (alias) + strlen (filename) + 2); if (alias [strlen (alias) - 1] == '/') sprintf (self->vpath, "%s%s", alias, filename); else sprintf (self->vpath, "%s/%s", alias, filename); return self; }
zdir_patch_t * zdir_patch_dup (zdir_patch_t *self) { zdir_patch_t *copy = (zdir_patch_t *) zmalloc (sizeof (zdir_patch_t)); copy->path = strdup (self->path); copy->file = zfile_dup (self->file); copy->op = self->op; copy->vpath = strdup (self->vpath); // Don't recalculate hash when we duplicate patch copy->digest = self->digest? strdup (self->digest): NULL; return copy; }
zdir_patch_t * zdir_patch_dup (zdir_patch_t *self) { if (self) { zdir_patch_t *copy = (zdir_patch_t *) zmalloc (sizeof (zdir_patch_t)); if (copy) { copy->op = self->op; copy->path = strdup (self->path); if (copy->path) copy->file = zfile_dup (self->file); if (copy->file) copy->vpath = strdup (self->vpath); if (copy->vpath) // Don't recalculate hash when we duplicate patch copy->digest = self->digest ? strdup (self->digest) : NULL; if (copy->digest == NULL) zdir_patch_destroy (©); } return copy; } else return NULL; }
JNIEXPORT jlong JNICALL Java_org_zeromq_czmq_Zfile__1_1dup (JNIEnv *env, jclass c, jlong self) { jlong dup_ = (jlong) (intptr_t) zfile_dup ((zfile_t *) (intptr_t) self); return dup_; }
static void get_next_patch_for_client (server_t *self, client_t *client) { // Get next patch for client if we're not doing one already if (client->patch == NULL) client->patch = (zdir_patch_t *) zlist_pop (client->patches); if (client->patch == NULL) { client->next_event = finished_event; return; } // Get virtual path from patch fmq_msg_set_filename (client->reply, zdir_patch_vpath (client->patch)); // We can process a delete patch right away if (zdir_patch_op (client->patch) == patch_delete) { fmq_msg_set_sequence (client->reply, client->sequence++); fmq_msg_set_operation (client->reply, FMQ_MSG_FILE_DELETE); client->next_event = send_delete_event; // No reliability in this version, assume patch delivered safely zdir_patch_destroy (&client->patch); } else if (zdir_patch_op (client->patch) == patch_create) { // Create patch refers to file, open that for input if needed if (client->file == NULL) { client->file = zfile_dup (zdir_patch_file (client->patch)); if (zfile_input (client->file)) { // File no longer available, skip it zdir_patch_destroy (&client->patch); zfile_destroy (&client->file); client->next_event = next_patch_event; return; } client->offset = 0; } // Get next chunk for file zchunk_t *chunk = zfile_read (client->file, CHUNK_SIZE, client->offset); assert (chunk); // Check if we have the credit to send chunk if (zchunk_size (chunk) <= client->credit) { fmq_msg_set_sequence (client->reply, client->sequence++); fmq_msg_set_operation (client->reply, FMQ_MSG_FILE_CREATE); fmq_msg_set_offset (client->reply, client->offset); fmq_msg_set_chunk (client->reply, zframe_new ( zchunk_data (chunk), zchunk_size (chunk))); client->offset += zchunk_size (chunk); client->credit -= zchunk_size (chunk); client->next_event = send_chunk_event; // Zero-sized chunk means end of file if (zchunk_size (chunk) == 0) { zfile_destroy (&client->file); zdir_patch_destroy (&client->patch); } } else client->next_event = no_credit_event; zchunk_destroy (&chunk); } }
static int parsechd (struct cdunit *cdu, struct zfile *zcue, const TCHAR *img) { chd_error err; struct cdrom_file *cdf; struct zfile *f = zfile_dup (zcue); if (!f) return 0; chd_file *cf = new chd_file(); err = cf->open(f, false, NULL); if (err != CHDERR_NONE) { write_log (_T("CHD '%s' err=%d\n"), zfile_getname (zcue), err); zfile_fclose (f); return 0; } if (!(cdf = cdrom_open (cf))) { write_log (_T("Couldn't open CHD '%s' as CD\n"), zfile_getname (zcue)); cf->close (); zfile_fclose (f); return 0; } cdu->chd_f = cf; cdu->chd_cdf = cdf; const cdrom_toc *stoc = cdrom_get_toc (cdf); cdu->tracks = stoc->numtrks; uae_u32 hunkcnt = cf->hunk_count (); uae_u32 hunksize = cf->hunk_bytes (); uae_u32 cbytes; chd_codec_type compr; for (int i = 0; i <cdu->tracks; i++) { int size; const cdrom_track_info *strack = &stoc->tracks[i]; struct cdtoc *dtrack = &cdu->toc[i]; dtrack->address = strack->physframeofs; dtrack->offset = strack->chdframeofs; dtrack->adr = cdrom_get_adr_control (cdf, i) >> 4; dtrack->ctrl = cdrom_get_adr_control (cdf, i) & 15; switch (strack->trktype) { case CD_TRACK_MODE1: case CD_TRACK_MODE2_FORM1: size = 2048; break; case CD_TRACK_MODE1_RAW: case CD_TRACK_MODE2_RAW: case CD_TRACK_AUDIO: default: size = 2352; break; case CD_TRACK_MODE2: case CD_TRACK_MODE2_FORM_MIX: size = 2336; break; case CD_TRACK_MODE2_FORM2: size = 2324; break; } dtrack->suboffset = size; dtrack->subcode = strack->subtype == CD_SUB_NONE ? 0 : strack->subtype == CD_SUB_RAW ? 1 : 2; dtrack->chdtrack = strack; dtrack->size = size; dtrack->enctype = ENC_CHD; dtrack->fname = my_strdup (zfile_getname (zcue)); dtrack->filesize = cf->logical_bytes (); dtrack->track = i + 1; dtrack[1].address = dtrack->address + strack->frames; if (cf->hunk_info(dtrack->offset * CD_FRAME_SIZE / hunksize, compr, cbytes) == CHDERR_NONE) { TCHAR tmp[100]; uae_u32 c = (uae_u32)compr; for (int j = 0; j < 4; j++) { uae_u8 b = c >> ((3 - j) * 8); if (c < 10) { b += '0'; } if (b < ' ' || b >= 127) b = '.'; tmp[j] = b; } tmp[4] = 0; dtrack->extrainfo = my_strdup (tmp); } }
static int parsemds (struct cdunit *cdu, struct zfile *zmds, const TCHAR *img) { MDS_Header *head; struct cdtoc *t; uae_u8 *mds = NULL; uae_u64 size; MDS_SessionBlock *sb; write_log (_T("MDS TOC: '%s'\n"), img); size = zfile_size (zmds); mds = xmalloc (uae_u8, size); if (!mds) goto end; if (zfile_fread (mds, size, 1, zmds) != 1) goto end; head = (MDS_Header*)mds; if (!memcmp (&head, MEDIA_DESCRIPTOR, strlen (MEDIA_DESCRIPTOR))) goto end; if (head->version[0] != 1) { write_log (_T("unsupported MDS version %d, only v.1 supported\n"), head->version[0]); goto end; } sb = (MDS_SessionBlock*)(mds + head->sessions_blocks_offset); cdu->tracks = sb->last_track - sb->first_track + 1; for (int i = 0; i < sb->num_all_blocks; i++) { MDS_TrackBlock *tb = (MDS_TrackBlock*)(mds + sb->tracks_blocks_offset + i * sizeof (MDS_TrackBlock)); int point = tb->point; int tracknum = -1; if (point == 0xa2) tracknum = cdu->tracks; else if (point >= 1 && point <= 99) tracknum = point - 1; if (tracknum >= 0) { MDS_Footer *footer = tb->footer_offset == 0 ? NULL : (MDS_Footer*)(mds + tb->footer_offset); MDS_TrackExtraBlock *teb = tb->extra_offset == 0 ? NULL : (MDS_TrackExtraBlock*)(mds + tb->extra_offset); t = &cdu->toc[tracknum]; t->adr = tb->adr_ctl >> 4; t->ctrl = tb->adr_ctl & 15; if (point == 0xa2) t->address = sb->session_end; else t->address = tb->start_sector; t->track = point; t->offset = tb->start_offset; t->size = tb->sector_size; if (point >= 100) continue; if (footer) { TCHAR *fname = NULL; if (footer->widechar_filename == 0) fname = au ((char*)(mds + footer->filename_offset)); else fname = my_strdup ((TCHAR*)(mds + footer->filename_offset)); if (fname[0] == '*' && fname[1] == '.') { TCHAR newname[MAX_DPATH]; _tcscpy (newname, img); TCHAR *ext = _tcsrchr (newname, '.'); if (ext) _tcscpy (ext, fname + 1); xfree (fname); fname = my_strdup (newname); } t->handle = zfile_fopen (fname, _T("rb"), ZFD_NORMAL); t->fname = my_strdup (fname); if (t->handle) t->filesize = zfile_size (t->handle); } if (tb->subchannel && t->handle) { t->suboffset = t->size; t->subcode = 1; // interleaved t->subhandle = zfile_dup (t->handle); t->skipsize = SUB_CHANNEL_SIZE; t->size -= SUB_CHANNEL_SIZE; } if ((t->ctrl & 0x0c) != 4) t->enctype = AUDENC_PCM; } }
/// // Duplicate a file item, returns a newly constructed item. If the file // is null, or memory was exhausted, returns null. QZfile * QZfile::dup () { QZfile *rv = new QZfile (zfile_dup (self)); return rv; }
/// // Duplicate a file item, returns a newly constructed item. If the file // is null, or memory was exhausted, returns null. QmlZfile *QmlZfile::dup () { QmlZfile *retQ_ = new QmlZfile (); retQ_->self = zfile_dup (self); return retQ_; };