Line data Source code
1 : #include "../burp.h" 2 : #include "../alloc.h" 3 : #include "../fsops.h" 4 : #include "../log.h" 5 : #include "manios.h" 6 : #include "manio.h" 7 : 8 5 : static struct manios *manios_alloc(void) 9 : { 10 5 : return (struct manios *)calloc_w(1, sizeof(struct manios), __func__); 11 : } 12 : 13 5 : struct manios *manios_open_phase2( 14 : struct sdirs *sdirs, 15 : man_off_t *pos_phase1, 16 : man_off_t *pos_current) 17 : { 18 5 : struct manios *m=NULL; 19 : 20 5 : if(!(m=manios_alloc()) 21 5 : || !(m->phase1=manio_open_phase1(sdirs->phase1data, "rb")) 22 5 : || !(m->changed=manio_open_phase2(sdirs->changed, "ab")) 23 5 : || !(m->unchanged=manio_open_phase2(sdirs->unchanged, "ab")) 24 5 : || !(m->counters_d=manio_open_phase2( 25 5 : sdirs->counters_d, "ab")) 26 5 : || !(m->counters_n=manio_open_phase2( 27 5 : sdirs->counters_n, "ab")) 28 5 : || (pos_phase1 && manio_seek(m->phase1, pos_phase1))) 29 0 : goto error; 30 : 31 5 : if(!(m->current=manio_open(sdirs->cmanifest, "rb"))) 32 : { 33 0 : if(pos_current) 34 : { 35 0 : logp("Want to seek but could not open %s\n", 36 : sdirs->cmanifest); 37 0 : goto error; 38 : } 39 0 : if(is_reg_lstat(sdirs->cmanifest)==1) 40 : { 41 0 : logp("Could not open %s\n", sdirs->cmanifest); 42 0 : goto error; 43 : } 44 : } 45 5 : if(pos_current && manio_seek(m->current, pos_current)) 46 0 : goto error; 47 : 48 5 : return m; 49 0 : error: 50 0 : manios_close(&m); 51 0 : return NULL; 52 : } 53 : 54 10 : int manios_close(struct manios **manios) 55 : { 56 10 : int ret=0; 57 10 : if(!manios || !*manios) return 0; 58 5 : ret|=manio_close(&(*manios)->current); 59 5 : ret|=manio_close(&(*manios)->phase1); 60 5 : ret|=manio_close(&(*manios)->changed); 61 5 : ret|=manio_close(&(*manios)->unchanged); 62 5 : ret|=manio_close(&(*manios)->counters_d); 63 5 : ret|=manio_close(&(*manios)->counters_n); 64 5 : free_v((void **)manios); 65 5 : return ret; 66 : }