Exemplo n.º 1
0
man_off_t *do_resume(struct sdirs *sdirs,
                     struct dpth *dpth, struct conf **cconfs)
{
    man_off_t *p1pos=NULL;
    struct manio *cmanio=NULL;
    struct manio *umanio=NULL;
    struct manio *p1manio=NULL;
    enum protocol protocol=get_protocol(cconfs);

    logp("Begin phase1 (read previous file system scan)\n");
    if(!(p1manio=manio_open_phase1(sdirs->phase1data, "rb", protocol))
            || read_phase1(p1manio, cconfs))
        goto end;
    manio_close(&p1manio);

    // First, open them in append mode, so that they will be created if
    // they do not exist.
    if(!(cmanio=manio_open_phase2(sdirs->changed, "ab", protocol))
            || !(umanio=manio_open_phase2(sdirs->unchanged, "ab", protocol)))
        goto end;
    manio_close(&cmanio);
    manio_close(&umanio);

    if(!(p1pos=do_resume_work(sdirs, dpth, cconfs))) goto end;

    if(dpth_incr(dpth)) goto end;

    logp("End phase1 (read previous file system scan)\n");
end:
    manio_close(&p1manio);
    manio_close(&cmanio);
    manio_close(&umanio);
    return p1pos;
}
Exemplo n.º 2
0
char *dpth_mk(struct dpth *dpth)
{
	static char save_path[32];
	static struct lock *lock=NULL;
	while(1)
	{
		snprintf(save_path, sizeof(save_path), "%04X/%04X/%04X/%04X",
			dpth->prim, dpth->seco, dpth->tert, dpth->sig);
		if(!dpth->need_data_lock) return save_path;

		if(!lock && !(lock=lock_alloc())) goto error;
		if(get_data_lock(lock, dpth, save_path)) goto error;
		switch(lock->status)
		{
			case GET_LOCK_GOT: break;
			case GET_LOCK_NOT_GOT:
				// Increment and try again.
				if(dpth_incr(dpth)) goto error;
				continue;
			case GET_LOCK_ERROR:
			default:
				goto error;
		}

		dpth->need_data_lock=0; // Got it.
		if(add_lock_to_list(dpth, lock, save_path)) goto error;
		lock=NULL;
		return save_path;
	}
error:
	lock_free(&lock);
	return NULL;
}
Exemplo n.º 3
0
int dpth_incr_sig(struct dpth *dpth)
{
	if(++dpth->sig<DATA_FILE_SIG_MAX) return 0;
	dpth->sig=0;
	dpth->need_data_lock=1;
	return dpth_incr(dpth);
}
Exemplo n.º 4
0
static int start_to_receive_new_file(struct asfd *asfd,
	struct sdirs *sdirs, struct conf **cconfs,
	struct sbuf *sb, struct dpth *dpth)
{
	int ret=-1;
	char *rpath=NULL;
	int istreedata=0;

//logp("start to receive: %s\n", sb->path.buf);

	if(!(rpath=set_new_datapth(asfd,
		sdirs, cconfs, sb, dpth, &istreedata)))
			goto end;
	
	if(!(sb->protocol1->fzp=fzp_open(rpath, "wb")))
	{
		log_and_send(asfd, "make file failed");
		goto end;
	}
	if(!istreedata) dpth_incr(dpth);
	ret=0;
end:
	free_w(&rpath);
	return ret;
}