int archwriter_write_volheader(carchwriter *ai) { struct s_writebuf *wb=NULL; cdico *voldico; assert(ai); if ((wb=writebuf_alloc())==NULL) { msgprintf(MSG_STACK, "writebuf_alloc() failed\n"); return -1; } if ((voldico=dico_alloc())==NULL) { msgprintf(MSG_STACK, "voldico=dico_alloc() failed\n"); return -1; } // prepare header dico_add_u32(voldico, 0, VOLUMEHEADKEY_VOLNUM, ai->curvol); dico_add_u32(voldico, 0, VOLUMEHEADKEY_ARCHID, ai->archid); dico_add_string(voldico, 0, VOLUMEHEADKEY_FILEFORMATVER, FSA_FILEFORMAT); dico_add_string(voldico, 0, VOLUMEHEADKEY_PROGVERCREAT, FSA_VERSION); // write header to buffer if (writebuf_add_header(wb, voldico, FSA_MAGIC_VOLH, ai->archid, FSA_FILESYSID_NULL)!=0) { errprintf("archio_write_header() failed\n"); return -1; } // write header to file if (archwriter_write_buffer(ai, wb)!=0) { errprintf("archwriter_write_buffer() failed\n"); return -1; } dico_destroy(voldico); writebuf_destroy(wb); return 0; }
int archwriter_write_volfooter(carchwriter *ai, bool lastvol) { struct s_writebuf *wb=NULL; cdico *voldico; assert(ai); if ((wb=writebuf_alloc())==NULL) { errprintf("writebuf_alloc() failed\n"); return -1; } if ((voldico=dico_alloc())==NULL) { errprintf("voldico=dico_alloc() failed\n"); return -1; } // prepare header dico_add_u32(voldico, 0, VOLUMEFOOTKEY_VOLNUM, ai->curvol); dico_add_u32(voldico, 0, VOLUMEFOOTKEY_ARCHID, ai->archid); dico_add_u32(voldico, 0, VOLUMEFOOTKEY_LASTVOL, lastvol); // write header to buffer if (writebuf_add_header(wb, voldico, FSA_MAGIC_VOLF, ai->archid, FSA_FILESYSID_NULL)!=0) { msgprintf(MSG_STACK, "archio_write_header() failed\n"); return -1; } // write header to file if (archwriter_write_buffer(ai, wb)!=0) { msgprintf(MSG_STACK, "archwriter_write_data(size=%ld) failed\n", (long)wb->size); return -1; } dico_destroy(voldico); writebuf_destroy(wb); return 0; }
// add headers and datblock at the end of the queue int regmulti_save_enqueue(cregmulti *m, cqueue *q, int fsid) { cblockinfo blkinfo; char *dynblock; u32 offset=0; u64 filesize; int i; if (!m) { errprintf("invalid param\n"); return -1; } // don't do anything if block is empty if (m->count==0) return 0; for (i=0; i < m->count; i++) { if (m->objhead[i]==NULL) { errprintf("error: objhead[%d]==NULL\n", i); return -1; } // get file size from header if (dico_get_u64(m->objhead[i], DICO_OBJ_SECTION_STDATTR, DISKITEMKEY_SIZE, &filesize)!=0) { errprintf("Cannot read filesize DISKITEMKEY_SIZE from archive\n"); return -1; } // the extraction function needs to know how many small-files are packed together if (dico_add_u32(m->objhead[i], DICO_OBJ_SECTION_STDATTR, DISKITEMKEY_MULTIFILESCOUNT, (u32)m->count)!=0) { errprintf("dico_add_u32(DISKITEMKEY_MULTIFILESCOUNT) failed\n"); return -1; } // the extraction function needs to know where the data for this file are in the block if (dico_add_u32(m->objhead[i], DICO_OBJ_SECTION_STDATTR, DISKITEMKEY_MULTIFILESOFFSET, (u32)offset)!=0) { errprintf("dico_add_u32(DISKITEMKEY_MULTIFILESCOUNT) failed\n"); return -1; } offset+=(u32)filesize; if (queue_add_header(q, m->objhead[i], FSA_MAGIC_OBJT, fsid)!=0) { errprintf("queue_add_header() failed\n"); return -1; } } // make a copy of the static block to dynamic memory if ((dynblock=malloc(m->usedsize)) == NULL) { errprintf("malloc(%ld) failed: out of memory\n", (long)m->usedsize); return -1; } memcpy(dynblock, m->data, m->usedsize); memset(&blkinfo, 0, sizeof(blkinfo)); blkinfo.blkrealsize=m->usedsize; blkinfo.blkdata=(char*)dynblock; blkinfo.blkoffset=0; // no meaning for multi-regfiles blkinfo.blkfsid=fsid; if (queue_add_block(q, &blkinfo, QITEM_STATUS_TODO)!=0) { errprintf("queue_add_block() failed\n"); return -1; } return 0; }