コード例 #1
0
ファイル: main.c プロジェクト: baruch/disksurvey-old
static void do_scrub(sg_t *sg, uint64_t num_blocks, uint32_t block_size)
{
	uint64_t block_offset;
	uint32_t blocks_to_read = 1024*1024/block_size;
	progress_t progress;

	find_num_blocks_to_read(sg, &blocks_to_read, block_size);

	progress_init(&progress);
	for (block_offset = 0; block_offset < num_blocks; block_offset += blocks_to_read) {
		progress_update(&progress, block_offset, num_blocks);
		if (num_blocks - block_offset < blocks_to_read)
			blocks_to_read = num_blocks - block_offset;

		switch (do_scrub_read(sg, block_offset, blocks_to_read, block_size)) {
		case READ_OK: break;
		case READ_ERROR: fprintf(stderr, "Error while reading data\n"); return;
		case READ_MEDIUM_ERR:
			fprintf(stderr, "Medium error reading at offset %llu\n", (unsigned long long)block_offset);
			break;
		}
	}

	progress_update(&progress, num_blocks, num_blocks);
	printf("\n");
}
コード例 #2
0
ファイル: progress.c プロジェクト: coyizumi/cs111
/* make it look pretty at the end - display done bytes (usually total) */
int
progress_complete(progress_t *prog, uint64_t done)
{
	progress_update(prog, done);
	progress_draw(prog);
	printf("\n");
	return 1;
}
コード例 #3
0
ファイル: progress.c プロジェクト: alenl/jamplus
PROGRESS*
progress_start(int total)
{
    PROGRESS* p = malloc(sizeof(PROGRESS));
    p->total = total;
    p->stampcount = 0;
    progress_update(p, 0);
    return p;
}
コード例 #4
0
static void ap_gtk_timeout_start (APUpdateType type) {
  APProgressBar *progress_bar;

  progress_bar = g_hash_table_lookup (progress_bars, GINT_TO_POINTER(type));
  if (progress_bar->timeout) {
    purple_timeout_remove (progress_bar->timeout);
  }
  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar->bar), 0);
  progress_bar->timeout = 
          purple_timeout_add (BAH, progress_update, progress_bar);
  progress_update (progress_bar);
}
コード例 #5
0
ファイル: progress.c プロジェクト: galois17/partclone
extern void update_pui(struct progress_bar *prog, unsigned long long copied, unsigned long long current, int done){
    
    if (done != 1) {
	if ((difftime(time(0), prog->resolution_time) < prog->interval_time) && copied != 0)
	    return;
	
    }
    if (prog->pui == NCURSES)
        Ncurses_progress_update(prog, copied, current, done);
    else if (prog->pui == TEXT)
        progress_update(prog, copied, current, done);
}
コード例 #6
0
ファイル: progress.c プロジェクト: garlick/isp
int
main(int argc, char *argv[])
{
    prog_t p;
    int i;

    fprintf(stderr, "foo  ");
    progress_create(&p, 70);
    for (i = 1; i <= 100000000L; i++)
        progress_update(p, (double)i/100000000L);
    progress_destroy(p);
    exit(0);
}
コード例 #7
0
ファイル: policy_view.c プロジェクト: 0xroot/setools3
/**
 * Perform the rule query within a thread.
 */
static gpointer policy_view_find_terules_runner(gpointer data)
{
	struct find_terules_datum *run = (struct find_terules_datum *)data;
	run->results = NULL;
	qpol_policy_t *q = apol_policy_get_qpol(run->policy);
	if (!qpol_policy_has_capability(q, QPOL_CAP_SYN_RULES)) {
		progress_update(run->progress, "Searching AV rules");
		run->retval = apol_avrule_get_by_query(run->policy, run->query, &run->results);
		run->is_syn_rules = 0;
	} else {
		qpol_policy_build_syn_rule_table(q);
		progress_update(run->progress, "Searching syntactic AV rules");
		run->retval = apol_syn_avrule_get_by_query(run->policy, run->query, &run->results);
		run->is_syn_rules = 1;
	}
	if (run->retval == 0) {
		progress_done(run->progress);
	} else {
		progress_abort(run->progress, NULL);
	}
	return NULL;
}
コード例 #8
0
ファイル: view_rtl_liquid.c プロジェクト: rzel/dim3
void view_dim3rtl_map_liquid_mesh_stop(void)
{
	int					n;
	map_liquid_type		*liq;
			
		// build the meshes

	for (n=0;n!=map.liquid.nliquid;n++) {
		liq=&map.liquid.liquids[n];
		rtlSceneMeshDelete(view_rtl_draw_scene_id,liq->rtl_mesh_id);

		progress_update();
	}
}
コード例 #9
0
ファイル: mke2fs.c プロジェクト: OPSF/uClinux
/*
 * Helper function which zeros out _num_ blocks starting at _blk_.  In
 * case of an error, the details of the error is returned via _ret_blk_
 * and _ret_count_ if they are non-NULL pointers.  Returns 0 on
 * success, and an error code on an error.
 *
 * As a special case, if the first argument is NULL, then it will
 * attempt to free the static zeroizing buffer.  (This is to keep
 * programs that check for memory leaks happy.)
 */
static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num,
			     struct progress_struct *progress,
			     blk_t *ret_blk, int *ret_count)
{
	int		j, count, next_update, next_update_incr;
	static char	*buf;
	errcode_t	retval;

	/* If fs is null, clean up the static buffer and return */
	if (!fs) {
		if (buf) {
			free(buf);
			buf = 0;
		}
		return 0;
	}
	/* Allocate the zeroizing buffer if necessary */
	if (!buf) {
		buf = malloc(fs->blocksize * STRIDE_LENGTH);
		if (!buf) {
			com_err("malloc", ENOMEM,
				_("while allocating zeroizing buffer"));
			exit(1);
		}
		memset(buf, 0, fs->blocksize * STRIDE_LENGTH);
	}
	/* OK, do the write loop */
	next_update = 0;
	next_update_incr = num / 100;
	if (next_update_incr < 1)
		next_update_incr = 1;
	for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) {
		count = num - j;
		if (count > STRIDE_LENGTH)
			count = STRIDE_LENGTH;
		retval = io_channel_write_blk(fs->io, blk, count, buf);
		if (retval) {
			if (ret_count)
				*ret_count = count;
			if (ret_blk)
				*ret_blk = blk;
			return retval;
		}
		if (progress && j > next_update) {
			next_update += num / 100;
			progress_update(progress, blk);
		}
	}
	return 0;
}	
コード例 #10
0
ファイル: progress.c プロジェクト: chaos/scrub
void 
progress_destroy(prog_t ctx)
{
    if (ctx) {
        assert(ctx->magic == PROGRESS_MAGIC);
        ctx->bar = 'x';
        progress_update(ctx, 1.0);
        ctx->magic = 0;
        if (ctx->batch)
            printf("|\n");
        else
            printf("\n");
        free(ctx);
    }
}
コード例 #11
0
ファイル: mke2fs.c プロジェクト: OPSF/uClinux
static void write_inode_tables(ext2_filsys fs)
{
	errcode_t	retval;
	blk_t		blk;
	dgrp_t		i;
	int		num;
	struct progress_struct progress;
	int		lazy_flag = 0;

	if (quiet)
		memset(&progress, 0, sizeof(progress));
	else
		progress_init(&progress, _("Writing inode tables: "),
			      fs->group_desc_count);

	if (EXT2_HAS_COMPAT_FEATURE(fs->super, 
				    EXT2_FEATURE_COMPAT_LAZY_BG))
		lazy_flag = 1;

	for (i = 0; i < fs->group_desc_count; i++) {
		progress_update(&progress, i);
		
		blk = fs->group_desc[i].bg_inode_table;
		num = fs->inode_blocks_per_group;

		if (!(lazy_flag &&
		      (fs->group_desc[i].bg_flags & EXT2_BG_INODE_UNINIT))) {
			retval = zero_blocks(fs, blk, num, 0, &blk, &num);
			if (retval) {
				fprintf(stderr, _("\nCould not write %d "
				"blocks in inode table starting at %u: %s\n"),
					num, blk, error_message(retval));
				exit(1);
			}
		}
		if (sync_kludge) {
			if (sync_kludge == 1)
				sync();
			else if ((i % sync_kludge) == 0)
				sync();
		}
	}
	zero_blocks(0, 0, 0, 0, 0, 0);
	progress_close(&progress);
}
コード例 #12
0
ファイル: puttygen.c プロジェクト: rdebath/sgt
static DWORD WINAPI generate_rsa_key_thread(void *param)
{
    struct rsa_key_thread_params *params =
	(struct rsa_key_thread_params *) param;
    struct progress prog;
    prog.progbar = params->progressbar;

    progress_update(&prog, PROGFN_INITIALISE, 0, 0);

    if (params->is_dsa)
	dsa_generate(params->dsskey, params->keysize, progress_update, &prog);
    else
	rsa_generate(params->key, params->keysize, progress_update, &prog);

    PostMessage(params->dialog, WM_DONEKEY, 0, 0);

    sfree(params);
    return 0;
}
コード例 #13
0
ファイル: trace.c プロジェクト: Annovae/DrawKit
  /* call downstream function with each path */
  list_forall (p, plist) {
    TRY(calc_sums(p->priv));
    TRY(calc_lon(p->priv));
    TRY(bestpolygon(p->priv));
    TRY(adjust_vertices(p->priv));
    TRY(smooth(&p->priv->curve, p->sign, param->alphamax));
    if (param->opticurve) {
      TRY(opticurve(p->priv, param->opttolerance));
      p->priv->fcurve = &p->priv->ocurve;
    } else {
      p->priv->fcurve = &p->priv->curve;
    }
    privcurve_to_curve(p->priv->fcurve, &p->curve);

    if (progress->callback) {
      cn += p->priv->len;
      progress_update(cn/nn, progress);
    }
  }
コード例 #14
0
ファイル: bvh_build.cpp プロジェクト: BlueLabelStudio/blender
/* single threaded spatial split builder */
BVHNode* BVHBuild::build_node(const BVHRange& range, int level)
{
	/* progress update */
	progress_update();
	if(progress.get_cancel())
		return NULL;

	/* small enough or too deep => create leaf. */
	if(!(range.size() > 0 && params.top_level && level == 0)) {
		if(params.small_enough_for_leaf(range.size(), level)) {
			progress_count += range.size();
			return create_leaf_node(range);
		}
	}

	/* splitting test */
	BVHMixedSplit split(this, range, level);

	if(!(range.size() > 0 && params.top_level && level == 0)) {
		if(split.no_split) {
			progress_count += range.size();
			return create_leaf_node(range);
		}
	}
	
	/* do split */
	BVHRange left, right;
	split.split(this, left, right, range);

	progress_total += left.size() + right.size() - range.size();
	size_t total = progress_total;

	/* leaft node */
	BVHNode *leftnode = build_node(left, level + 1);

	/* right node (modify start for splits) */
	right.set_start(right.start() + progress_total - total);
	BVHNode *rightnode = build_node(right, level + 1);

	/* inner node */
	return new InnerNode(range.bounds(), leftnode, rightnode);
}
コード例 #15
0
ファイル: bvh_build.cpp プロジェクト: BlueLabelStudio/blender
void BVHBuild::thread_build_node(InnerNode *inner, int child, BVHObjectBinning *range, int level)
{
	if(progress.get_cancel())
		return;

	/* build nodes */
	BVHNode *node = build_node(*range, level);

	/* set child in inner node */
	inner->children[child] = node;

	/* update progress */
	if(range->size() < THREAD_TASK_SIZE) {
		/*rotate(node, INT_MAX, 5);*/

		thread_scoped_lock lock(build_mutex);

		progress_count += range->size();
		progress_update();
	}
}
コード例 #16
0
ファイル: progress.c プロジェクト: mdbooth/partclone
extern void update_pui(struct progress_bar *prog, unsigned long long copied, unsigned long long current, int done){
    if (prog->pui == NCURSES)
        Ncurses_progress_update(prog, copied, current, done);
    else if (prog->pui == TEXT)
        progress_update(prog, copied, current, done);
}
コード例 #17
0
ファイル: make1.c プロジェクト: 0xb1dd1e/jamplus
static void
make1b( TARGET *t )
{
	TARGETS	*c;
	const char *failed;
#ifdef OPT_MULTIPASS_EXT
	int missing;
#endif
#ifdef OPT_BUILTIN_NEEDS_EXT
	int childmightnotupdate;
	int childscancontents;
	int childupdated;
#endif

#ifdef OPT_DEBUG_MAKE1_LOG_EXT
	if (DEBUG_MAKE1) {
	    printf( "make1b\t--\t%s (asynccnt %d)\n" ,
		    t->name, t->asynccnt);
	}
#endif
	/* If any dependents are still outstanding, wait until they */
	/* call make1b() to signal their completion. */

	if( --t->asynccnt )
	    return;

#ifdef OPT_INTERRUPT_FIX
	if( intr )
	    return;
#endif

	failed = "dependents";
#ifdef OPT_MULTIPASS_EXT
	missing = 0;
#endif
#ifdef OPT_BUILTIN_NEEDS_EXT
	childmightnotupdate = 0;
	childscancontents = 0;
	childupdated = 0;
#endif

#ifdef OPT_SEMAPHORE
	if( t->semaphore && t->semaphore->asynccnt )
	{
	    /* We can't launch yet.  Try again when the semaphore is free */
#ifdef OPT_BUILTIN_NEEDS_EXT
	    t->semaphore->parents = targetentry( t->semaphore->parents, t, 0 );
#else
	    t->semaphore->parents = targetentry( t->semaphore->parents, t );
#endif
	    t->asynccnt++;

	    if( DEBUG_EXECCMD )
		printf( "SEM: %s is busy, delaying launch of %s\n",
			t->semaphore->name, t->name);
	    return;
	}
#endif
	/* Now ready to build target 't'... if dependents built ok. */

	/* Collect status from dependents */

	for( c = t->depends; c; c = c->next ) {
	    if ( !(t->flags & T_FLAG_INTERNAL) && c->target->asynccnt ) {
//			printf("warning: Trying to build '%s' before dependent '%s' is done!\n", t->name, c->target->name);
		}
#ifdef OPT_BUILTIN_NEEDS_EXT
	    /* Only test a target's MightNotUpdate flag if the target's build was successful. */
	    if( c->target->status == EXEC_CMD_OK ) {
		if ( c->target->flags & T_FLAG_MIGHTNOTUPDATE ) {
		    time_t timestamp;

		    /* Mark that we've seen a MightNotUpdate flag in this set of children. */
		    childmightnotupdate = 1;

		    /* Grab the generated target's timestamp. */
		    if ( file_time( c->target->boundname, &timestamp ) == 0 ) {
			/* If the child's timestamp is greater that the target's timestamp, then it updated. */
				if ( timestamp > t->time ) {
					if ( c->target->flags & T_FLAG_SCANCONTENTS ) {
						childscancontents = 1;
						if ( getcachedmd5sum( c->target, 1 ) )
							childupdated = 1;
					} else
						childupdated = 1;
				} else {
					childscancontents = 1;
				}
		    }
		}
		/* If it didn't have the MightNotUpdate flag but did update, mark it. */
		else if ( c->target->fate > T_FATE_STABLE  &&  !c->needs ) {
			if ( c->target->flags & T_FLAG_SCANCONTENTS ) {
				childscancontents = 1;
				if ( getcachedmd5sum( c->target, 1 ) )
					childupdated = 1;
			} else
				childupdated = 1;
		}
	    }
#endif

	    if( c->target->status > t->status )
	{
	    failed = c->target->name;
	    t->status = c->target->status;
#ifdef OPT_MULTIPASS_EXT
		if ( ( c->target->fate == T_FATE_MISSING  &&  ! ( c->target->flags & T_FLAG_NOCARE )  &&  !c->target->actions ) || t->status == EXEC_CMD_NEXTPASS )
		{
			missing = 1;
			if ( queuedjamfiles )
			{
				ACTIONS *actions;

				t->status = EXEC_CMD_NEXTPASS;

				for( actions = t->actions; actions; actions = actions->next )
				{
					actions->action->pass++;
				}
			}
		}
#endif
	}

#ifdef OPT_NOCARE_NODES_EXT
	/* CWM */
	/* If actions on deps have failed, but if this is a 'nocare' target */
	/* then continue anyway. */

	if( ( t->flags & T_FLAG_NOCARE ) && t->status == EXEC_CMD_FAIL )
	{
		printf( "...dependency on %s failed, but don't care...\n", t->name );
		t->status = EXEC_CMD_OK;
	}
#endif
	}

#ifdef OPT_BUILTIN_NEEDS_EXT
	/* If we found a MightNotUpdate flag and there was an update, mark the fate as updated. */
	if ( childmightnotupdate  &&  childupdated  &&  t->fate == T_FATE_STABLE )
	      t->fate = T_FATE_UPDATE;
	if ( childscancontents ) {
		if ( !childupdated ) {
			if ( t->includes ) {
				for( c = t->includes->depends; c; c = c->next ) {
					if ( c->target->fate > T_FATE_STABLE  &&  !c->needs ) {
						if ( c->target->flags & T_FLAG_SCANCONTENTS ) {
							if ( getcachedmd5sum( c->target, 1 )  ||  !md5matchescommandline( c->target ) ) {
								childupdated = 1;
								break;
							}
						} else {
							childupdated = 1;
							break;
						}
					}
				}
			}

			if ( !childupdated )
				t->fate = T_FATE_STABLE;
		} else if ( t->fate == T_FATE_STABLE )
			t->fate = T_FATE_UPDATE;
	}
	if ( t->fate == T_FATE_UPDATE  &&  !childupdated  &&  t->status != EXEC_CMD_NEXTPASS )
		if ( md5matchescommandline( t ) )
		    t->fate = T_FATE_STABLE;
	if ( t->flags & ( T_FLAG_MIGHTNOTUPDATE | T_FLAG_SCANCONTENTS )  &&  t->actions ) {
#ifdef OPT_ACTIONS_WAIT_FIX
	    /* See http://maillist.perforce.com/pipermail/jamming/2003-December/002252.html */
	    /* Determine if an action is already running on behalf of another target, and if so, */
	    /* bail out of make1b() prior to calling make1cmds() by adding more parents to the */
	    /* in-progress target and incrementing the asynccnt of the new target. */
	    make1wait( t );
	    if ( t->asynccnt != 0 )
		return;
#endif
	}
#endif

	/* If actions on deps have failed, bail. */
	/* Otherwise, execute all actions to make target */

#ifdef OPT_MULTIPASS_EXT
	if( t->status == EXEC_CMD_FAIL && t->actions && !missing )
#else
	if( t->status == EXEC_CMD_FAIL && t->actions )
#endif
	{
	    ++counts->skipped;
	    printf( "*** skipped %s for lack of %s...\n", t->name, failed );
	}

	if( t->status == EXEC_CMD_OK )
	    switch( t->fate )
	{
	case T_FATE_INIT:
	case T_FATE_MAKING:
	    /* shouldn't happen */

	case T_FATE_STABLE:
	case T_FATE_NEWER:
	    break;

	case T_FATE_CANTFIND:
	case T_FATE_CANTMAKE:
	    t->status = EXEC_CMD_FAIL;
	    break;

	case T_FATE_ISTMP:
	    if( DEBUG_MAKEQ )
		printf( "*** using %s...\n", t->name );
	    break;

	case T_FATE_TOUCHED:
	case T_FATE_MISSING:
	case T_FATE_NEEDTMP:
	case T_FATE_OUTDATED:
	case T_FATE_UPDATE:
	    /* Set "on target" vars, build actions, unset vars */
	    /* Set "progress" so that make1c() counts this target among */
	    /* the successes/failures. */

#ifdef OPT_DEBUG_MAKE1_LOG_EXT
	    if (DEBUG_MAKE1) {
		printf( "make1b\t--\t%s (has actions)\n" , t->name );
	    }
#endif
	    if( t->actions )
	    {
#ifdef OPT_ACTIONS_WAIT_FIX
		/* See http://maillist.perforce.com/pipermail/jamming/2003-December/002252.html */
		/* Determine if an action is already running on behalf of another target, and if so, */
		/* bail out of make1b() prior to calling make1cmds() by adding more parents to the */
		/* in-progress target and incrementing the asynccnt of the new target. */
		make1wait( t );
		if ( t->asynccnt != 0 )
		    return;
#endif
		++counts->total;

#ifndef OPT_IMPROVED_PROGRESS_EXT
		if( DEBUG_MAKE && !( counts->total % 100 ) )
		    printf( "*** on %dth target...\n", counts->total );
#else
		{
		    double est_remaining;

		    est_remaining =
			progress_update(globs.progress, counts->total);

		    if (est_remaining > 0) {
			int minutes = (int)est_remaining / 60;
			int seconds = (int)est_remaining % 60;

			if (minutes > 0 || seconds > 0) {
			    printf("*** completed %.0f%% (",
				   ((double)counts->total * 100 /
				    globs.updating));
			    if (minutes > 0)
				printf("%d min ", minutes);
			    if (seconds >= 0)
				printf("%d sec ", seconds);
			    printf("remaining)...\n");
			}
		    }
		}
#endif

#ifdef OPT_BUILTIN_MD5CACHE_EXT
		pushsettings( t->settings );
		filecache_fillvalues( t );
		popsettings( t->settings );
		t->cmds = (char *)make1cmds( t, t->actions );
#else
		pushsettings( t->settings );
		t->cmds = (char *)make1cmds( t->actions );
		popsettings( t->settings );
#endif

		t->progress = T_MAKE_RUNNING;
	    }

	    break;
	}

#ifdef OPT_SEMAPHORE
	/* If there is a semaphore, indicate that its in use */
	if( t->semaphore )
	{
	    ++(t->semaphore->asynccnt);

	    if( DEBUG_EXECCMD )
		printf( "SEM: %s now used by %s\n", t->semaphore->name,
		       t->name );
	}
#endif
	/* Call make1c() to begin the execution of the chain of commands */
	/* needed to build target.  If we're not going to build target */
	/* (because of dependency failures or because no commands need to */
	/* be run) the chain will be empty and make1c() will directly */
	/* signal the completion of target. */

	make1c( t );
}
コード例 #18
0
void recurse_dir(MediaScan *s, const char *path, int recurse_count) {
  char *dir, *p;
  char tmp_full_path[MAX_PATH_STR_LEN];
  DIR *dirp;
  struct dirent *dp;
  struct dirq *subdirq;         // list of subdirs of the current directory
  struct dirq_entry *parent_entry = NULL; // entry for current dir in s->_dirq
  char redirect_dir[MAX_PATH_STR_LEN];

  if (recurse_count > RECURSE_LIMIT) {
    LOG_ERROR("Hit recurse limit of %d scanning path %s\n", RECURSE_LIMIT, path);
    return;
  }

  if (path[0] != '/') {         // XXX Win32
    // Get full path
    char *buf = (char *)malloc((size_t)MAX_PATH_STR_LEN);
    if (buf == NULL) {
      FATAL("Out of memory for directory scan\n");
      return;
    }

    dir = getcwd(buf, (size_t)MAX_PATH_STR_LEN);
    strcat(dir, "/");
    strcat(dir, path);
  }
  else {
#ifdef USING_TCMALLOC
    // strdup will cause tcmalloc to crash on free
    dir = (char *)malloc((size_t)MAX_PATH_STR_LEN);
    strcpy(dir, path);
#else
    dir = strdup(path);
#endif
  }

  // Strip trailing slash if any
  p = &dir[0];
  while (*p != 0) {
    if (p[1] == 0 && *p == '/')
      *p = 0;
    p++;
  }

  LOG_INFO("Recursed into %s\n", dir);

#if defined(__APPLE__)
  if (isAlias(dir)) {
    if (CheckMacAlias(dir, redirect_dir)) {
      LOG_INFO("Resolving Alias %s to %s\n", dir, redirect_dir);
      strcpy(dir, redirect_dir);
    }
    else {
      LOG_ERROR("Failure to follow symlink or alias, skipping directory\n");
      goto out;
    }
  }
#elif defined(__linux__)
  if (isAlias(dir)) {
    FollowLink(dir, redirect_dir);
    LOG_INFO("Resolving symlink %s to %s\n", dir, redirect_dir);
    strcpy(dir, redirect_dir);
  }
#endif

  if ((dirp = opendir(dir)) == NULL) {
    LOG_ERROR("Unable to open directory %s: %s\n", dir, strerror(errno));
    goto out;
  }

  subdirq = malloc(sizeof(struct dirq));
  SIMPLEQ_INIT(subdirq);

  while ((dp = readdir(dirp)) != NULL) {
    char *name = dp->d_name;

    // skip all dot files
    if (name[0] != '.') {
      // Check if scan should be aborted
      if (unlikely(s->_want_abort))
        break;

      // XXX some platforms may be missing d_type/DT_DIR
      if (dp->d_type == DT_DIR) {
        // Add to list of subdirectories we need to recurse into
        struct dirq_entry *subdir_entry = malloc(sizeof(struct dirq_entry));

        // Construct full path
        //*tmp_full_path = 0;
        strcpy(tmp_full_path, dir);
        strcat(tmp_full_path, "/");
        strcat(tmp_full_path, name);

        if (_should_scan_dir(s, tmp_full_path)) {
          subdir_entry->dir = strdup(tmp_full_path);
          SIMPLEQ_INSERT_TAIL(subdirq, subdir_entry, entries);

          LOG_INFO(" subdir: %s\n", tmp_full_path);
        }
        else {
          LOG_INFO(" skipping subdir: %s\n", tmp_full_path);
        }
      }
      else {
        enum media_type type = _should_scan(s, name);

        LOG_INFO("name %s = type %d\n", name, type);

        if (type) {
          struct fileq_entry *entry;

          // Check if this file is a shortcut and if so resolve it
#if defined(__APPLE__)
          if (isAlias(name)) {
            char full_name[MAX_PATH_STR_LEN];

            LOG_INFO("Mac Alias detected\n");

            strcpy(full_name, dir);
            strcat(full_name, "\\");
            strcat(full_name, name);
            parse_lnk(full_name, redirect_dir, MAX_PATH_STR_LEN);
            if (PathIsDirectory(redirect_dir)) {
              struct dirq_entry *subdir_entry = malloc(sizeof(struct dirq_entry));

              subdir_entry->dir = strdup(redirect_dir);
              SIMPLEQ_INSERT_TAIL(subdirq, subdir_entry, entries);

              LOG_INFO(" subdir: %s\n", tmp_full_path);
              type = 0;
            }

          }
#elif defined(__linux__)
          if (isAlias(name)) {
            char full_name[MAX_PATH_STR_LEN];

            printf("Linux Alias detected\n");

            strcpy(full_name, dir);
            strcat(full_name, "\\");
            strcat(full_name, name);
            FollowLink(full_name, redirect_dir);
            if (PathIsDirectory(redirect_dir)) {
              struct dirq_entry *subdir_entry = malloc(sizeof(struct dirq_entry));

              subdir_entry->dir = strdup(redirect_dir);
              SIMPLEQ_INSERT_TAIL(subdirq, subdir_entry, entries);

              LOG_INFO(" subdir: %s\n", tmp_full_path);
              type = 0;
            }

          }
#endif
          if (parent_entry == NULL) {
            // Add parent directory to list of dirs with files
            parent_entry = malloc(sizeof(struct dirq_entry));
            parent_entry->dir = strdup(dir);
            parent_entry->files = malloc(sizeof(struct fileq));
            SIMPLEQ_INIT(parent_entry->files);
            SIMPLEQ_INSERT_TAIL((struct dirq *)s->_dirq, parent_entry, entries);
          }

          // Add scannable file to this directory list
          entry = malloc(sizeof(struct fileq_entry));
          entry->file = strdup(name);
          entry->type = type;
          SIMPLEQ_INSERT_TAIL(parent_entry->files, entry, entries);

          s->progress->total++;

          LOG_INFO(" [%5d] file: %s\n", s->progress->total, entry->file);
        }
      }
    }
  }

  closedir(dirp);

  // Send progress update
  if (s->on_progress && !s->_want_abort)
    if (progress_update(s->progress, dir))
      send_progress(s);

  // process subdirs
  while (!SIMPLEQ_EMPTY(subdirq)) {
    struct dirq_entry *subdir_entry = SIMPLEQ_FIRST(subdirq);
    SIMPLEQ_REMOVE_HEAD(subdirq, entries);
    if (!s->_want_abort)
      recurse_dir(s, subdir_entry->dir, recurse_count);
    free(subdir_entry);
  }

  free(subdirq);

out:
  free(dir);
}
コード例 #19
0
ファイル: retr.c プロジェクト: catufunwa/wget
int
fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
              wgint *qtyread, wgint *qtywritten, double *elapsed, int flags,
              FILE *out2)
{
  int ret = 0;
#undef max
#define max(a,b) ((a) > (b) ? (a) : (b))
  int dlbufsize = max (BUFSIZ, 8 * 1024);
  char *dlbuf = xmalloc (dlbufsize);

  struct ptimer *timer = NULL;
  double last_successful_read_tm = 0;

  /* The progress gauge, set according to the user preferences. */
  void *progress = NULL;

  /* Non-zero if the progress gauge is interactive, i.e. if it can
     continually update the display.  When true, smaller timeout
     values are used so that the gauge can update the display when
     data arrives slowly. */
  bool progress_interactive = false;

  bool exact = !!(flags & rb_read_exactly);

  /* Used only by HTTP/HTTPS chunked transfer encoding.  */
  bool chunked = flags & rb_chunked_transfer_encoding;
  wgint skip = 0;

  /* How much data we've read/written.  */
  wgint sum_read = 0;
  wgint sum_written = 0;
  wgint remaining_chunk_size = 0;

  if (flags & rb_skip_startpos)
    skip = startpos;

  if (opt.verbose)
    {
      /* If we're skipping STARTPOS bytes, pass 0 as the INITIAL
         argument to progress_create because the indicator doesn't
         (yet) know about "skipping" data.  */
      wgint start = skip ? 0 : startpos;
      progress = progress_create (start, start + toread);
      progress_interactive = progress_interactive_p (progress);
    }

  if (opt.limit_rate)
    limit_bandwidth_reset ();

  /* A timer is needed for tracking progress, for throttling, and for
     tracking elapsed time.  If either of these are requested, start
     the timer.  */
  if (progress || opt.limit_rate || elapsed)
    {
      timer = ptimer_new ();
      last_successful_read_tm = 0;
    }

  /* Use a smaller buffer for low requested bandwidths.  For example,
     with --limit-rate=2k, it doesn't make sense to slurp in 16K of
     data and then sleep for 8s.  With buffer size equal to the limit,
     we never have to sleep for more than one second.  */
  if (opt.limit_rate && opt.limit_rate < dlbufsize)
    dlbufsize = opt.limit_rate;

  /* Read from FD while there is data to read.  Normally toread==0
     means that it is unknown how much data is to arrive.  However, if
     EXACT is set, then toread==0 means what it says: that no data
     should be read.  */
  while (!exact || (sum_read < toread))
    {
      int rdsize;
      double tmout = opt.read_timeout;

      if (chunked)
        {
          if (remaining_chunk_size == 0)
            {
              char *line = fd_read_line (fd);
              char *endl;
              if (line == NULL)
                {
                  ret = -1;
                  break;
                }
              else if (out2 != NULL)
                fwrite (line, 1, strlen (line), out2);

              remaining_chunk_size = strtol (line, &endl, 16);
              xfree (line);

              if (remaining_chunk_size == 0)
                {
                  ret = 0;
                  line = fd_read_line (fd);
                  if (line == NULL)
                    ret = -1;
                  else
                    {
                      if (out2 != NULL)
                        fwrite (line, 1, strlen (line), out2);
                      xfree (line);
                    }
                  break;
                }
            }

          rdsize = MIN (remaining_chunk_size, dlbufsize);
        }
      else
        rdsize = exact ? MIN (toread - sum_read, dlbufsize) : dlbufsize;

      if (progress_interactive)
        {
          /* For interactive progress gauges, always specify a ~1s
             timeout, so that the gauge can be updated regularly even
             when the data arrives very slowly or stalls.  */
          tmout = 0.95;
          if (opt.read_timeout)
            {
              double waittm;
              waittm = ptimer_read (timer) - last_successful_read_tm;
              if (waittm + tmout > opt.read_timeout)
                {
                  /* Don't let total idle time exceed read timeout. */
                  tmout = opt.read_timeout - waittm;
                  if (tmout < 0)
                    {
                      /* We've already exceeded the timeout. */
                      ret = -1, errno = ETIMEDOUT;
                      break;
                    }
                }
            }
        }
      ret = fd_read (fd, dlbuf, rdsize, tmout);

      if (progress_interactive && ret < 0 && errno == ETIMEDOUT)
        ret = 0;                /* interactive timeout, handled above */
      else if (ret <= 0)
        break;                  /* EOF or read error */

      if (progress || opt.limit_rate || elapsed)
        {
          ptimer_measure (timer);
          if (ret > 0)
            last_successful_read_tm = ptimer_read (timer);
        }

      if (ret > 0)
        {
          sum_read += ret;
          int write_res = write_data (out, out2, dlbuf, ret, &skip, &sum_written);
          if (write_res < 0)
            {
              ret = (write_res == -3) ? -3 : -2;
              goto out;
            }
          if (chunked)
            {
              remaining_chunk_size -= ret;
              if (remaining_chunk_size == 0)
                {
                  char *line = fd_read_line (fd);
                  if (line == NULL)
                    {
                      ret = -1;
                      break;
                    }
                  else
                    {
                      if (out2 != NULL)
                        fwrite (line, 1, strlen (line), out2);
                      xfree (line);
                    }
                }
            }
        }

      if (opt.limit_rate)
        limit_bandwidth (ret, timer);

      if (progress)
        progress_update (progress, ret, ptimer_read (timer));
#ifdef WINDOWS
      if (toread > 0 && !opt.quiet)
        ws_percenttitle (100.0 *
                         (startpos + sum_read) / (startpos + toread));
#endif
    }
  if (ret < -1)
    ret = -1;

 out:
  if (progress)
    progress_finish (progress, ptimer_read (timer));

  if (elapsed)
    *elapsed = ptimer_read (timer);
  if (timer)
    ptimer_destroy (timer);

  if (qtyread)
    *qtyread += sum_read;
  if (qtywritten)
    *qtywritten += sum_written;

  free (dlbuf);

  return ret;
}
コード例 #20
0
ファイル: retr.c プロジェクト: tjmidnight/Overwatch
int
fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
              wgint *qtyread, wgint *qtywritten, double *elapsed, int flags)
{
  double receive_message_time = 0; // VisualWget
  double send_message_time = 0; // VisualWget
  int ret = 0;

  static char dlbuf[16384];
  int dlbufsize = sizeof (dlbuf);

  struct ptimer *timer = NULL;
  double last_successful_read_tm = 0;

  /* The progress gauge, set according to the user preferences. */
  void *progress = NULL;

  /* Non-zero if the progress gauge is interactive, i.e. if it can
     continually update the display.  When true, smaller timeout
     values are used so that the gauge can update the display when
     data arrives slowly. */
  bool progress_interactive = false;

  bool exact = !!(flags & rb_read_exactly);
  wgint skip = 0;

  /* How much data we've read/written.  */
  wgint sum_read = 0;
  wgint sum_written = 0;

  if (flags & rb_skip_startpos)
    skip = startpos;

  if (opt.visualwget_listening_port != -1) // VisualWget: Send a start position and the number of bytes remain.
    {
      wgint sp = skip ? 0 : startpos;
      char *msg = (char *) xmalloc (2 + numdigit (sp) + 1 + numdigit (toread) + 2);

      sprintf (msg, "1 %I64d %I64d\n", sp, toread);
      SendMessageToVisualWget (msg);
      xfree (msg);
    }

  if (opt.verbose)
    {
      /* If we're skipping STARTPOS bytes, pass 0 as the INITIAL
         argument to progress_create because the indicator doesn't
         (yet) know about "skipping" data.  */
      progress = progress_create (skip ? 0 : startpos, startpos + toread);
      progress_interactive = progress_interactive_p (progress);
    }

  limit_bandwidth_reset (); // VisualWget: Always reset.

  /* A timer is needed for tracking progress, for throttling, and for
     tracking elapsed time.  If either of these are requested, start
     the timer.  */
  if (progress || opt.limit_rate || elapsed || opt.visualwget_listening_port != -1) // VisualWget
    {
      timer = ptimer_new ();
      last_successful_read_tm = 0;
    }

  /* Read from FD while there is data to read.  Normally toread==0
     means that it is unknown how much data is to arrive.  However, if
     EXACT is set, then toread==0 means what it says: that no data
     should be read.  */
  while (!exact || (sum_read < toread))
    {
      int rdsize;
      double tmout = opt.read_timeout;
      if (progress_interactive)
        {
          /* For interactive progress gauges, always specify a ~1s
             timeout, so that the gauge can be updated regularly even
             when the data arrives very slowly or stalls.  */
          tmout = 0.95;
          if (opt.read_timeout)
            {
              double waittm;
              waittm = ptimer_read (timer) - last_successful_read_tm;
              if (waittm + tmout > opt.read_timeout)
                {
                  /* Don't let total idle time exceed read timeout. */
                  tmout = opt.read_timeout - waittm;
                  if (tmout < 0)
                    {
                      /* We've already exceeded the timeout. */
                      ret = -1, errno = ETIMEDOUT;
                      break;
                    }
                }
            }
        }

      //
      // VisualWget: Receive message every 0.1 second
      // BUG FIXED: http://groups.google.com/group/visualwget-discuss/browse_thread/thread/5ef2e324c70722aa
      //
      if (receive_message_time == 0
          || ptimer_read (timer) - receive_message_time > 0.1)
        {
          receive_message_time = ptimer_read (timer);
          ReceiveMessagesFromVisualWget ();
        }

      /* Use a smaller buffer for low requested bandwidths.  For example,
         with --limit-rate=2k, it doesn't make sense to slurp in 16K of
         data and then sleep for 8s.  With buffer size equal to the limit,
         we never have to sleep for more than one second.  */
      if (opt.limit_rate && opt.limit_rate < sizeof (dlbuf)) // VisualWget: Set a correct download buffer size.
        dlbufsize = opt.limit_rate;
      else
        dlbufsize = sizeof (dlbuf);

      rdsize = exact ? MIN (toread - sum_read, dlbufsize) : dlbufsize;
      ret = fd_read (fd, dlbuf, rdsize, tmout);

      if (progress_interactive && ret < 0 && errno == ETIMEDOUT)
        ret = 0;                /* interactive timeout, handled above */
      else if (ret <= 0)
        break;                  /* EOF or read error */

      if (progress || opt.limit_rate || opt.visualwget_listening_port != -1) // VisualWget
        {
          ptimer_measure (timer);
          if (ret > 0)
            last_successful_read_tm = ptimer_read (timer);
        }

      if (opt.limit_rate) // VisualWget: Do this before writing data in order to prevent an incorrect information getting sent to VisualWget.
        limit_bandwidth (ret, timer);

      if (ret > 0)
        {
          sum_read += ret;
          if (!write_data (out, dlbuf, ret, &skip, &sum_written))
            {
              ret = -2;
              goto out;
            }

          // VisualWget: Send the total number of bytes read and elapsed time.
          if (send_message_time == 0
              || ptimer_read (timer) - send_message_time > 0.1
              || sum_read == toread)
            {
              send_message_time = ptimer_read (timer);

              if (opt.visualwget_listening_port != -1)
                {
                  wgint elapsed_time = (wgint) (ptimer_read (timer) * 1000);
                  char *msg = (char *) xmalloc (2 + numdigit (sum_read) + 1 + numdigit (elapsed_time) + 2);

                  sprintf (msg, "2 %I64d %I64d\n", sum_read, elapsed_time);
                  SendMessageToVisualWget (msg);
                  xfree (msg);
                }
            }
        }

      if (progress)
        progress_update (progress, ret, ptimer_read (timer));
#ifdef WINDOWS
      if (toread > 0 && !opt.quiet)
        ws_percenttitle (100.0 *
                         (startpos + sum_read) / (startpos + toread));
#endif
    }
  if (ret < -1)
    ret = -1;

 out:
  if (progress)
    progress_finish (progress, ptimer_read (timer));

  if (elapsed)
    *elapsed = ptimer_read (timer);
  if (timer)
    ptimer_destroy (timer);

  if (qtyread)
    *qtyread += sum_read;
  if (qtywritten)
    *qtywritten += sum_written;

  return ret;
}
コード例 #21
0
ファイル: retr.c プロジェクト: kmekler/symblog
/* Reads the contents of file descriptor FD, until it is closed, or a
   read error occurs.  The data is read in 8K chunks, and stored to
   stream fp, which should have been open for writing.  If BUF is
   non-NULL and its file descriptor is equal to FD, flush RBUF first.
   This function will *not* use the rbuf_* functions!

   The EXPECTED argument is passed to show_progress() unchanged, but
   otherwise ignored.

   If opt.verbose is set, the progress is also shown.  RESTVAL
   represents a value from which to start downloading (which will be
   shown accordingly).  If RESTVAL is non-zero, the stream should have
   been open for appending.

   The function exits and returns codes of 0, -1 and -2 if the
   connection was closed, there was a read error, or if it could not
   write to the output stream, respectively.

   IMPORTANT: The function flushes the contents of the buffer in
   rbuf_flush() before actually reading from fd.  If you wish to read
   from fd immediately, flush or discard the buffer.  */
int
get_contents (int fd, FILE *fp, long *len, long restval, long expected,
	      struct rbuf *rbuf, int use_expected, long *elapsed)
{
  int res = 0;
  static char c[8192];
  void *progress = NULL;
  struct wget_timer *timer = wtimer_allocate ();
  long dltime = 0, last_dltime = 0;

  *len = restval;

  if (opt.verbose)
    progress = progress_create (restval, expected);

  if (rbuf && RBUF_FD (rbuf) == fd)
    {
      int sz = 0;
      while ((res = rbuf_flush (rbuf, c, sizeof (c))) != 0)
	{
	  fwrite (c, sizeof (char), res, fp);
	  *len += res;
	  sz += res;
	}
      if (sz)
	fflush (fp);
      if (ferror (fp))
	{
	  res = -2;
	  goto out;
	}
      if (opt.verbose)
	progress_update (progress, sz, 0);
    }

  if (opt.limit_rate)
    limit_bandwidth_reset ();
  wtimer_reset (timer);

  /* Read from fd while there is available data.

     Normally, if expected is 0, it means that it is not known how
     much data is expected.  However, if use_expected is specified,
     then expected being zero means exactly that.  */
  while (!use_expected || (*len < expected))
    {
      int amount_to_read = (use_expected
			    ? MIN (expected - *len, sizeof (c))
			    : sizeof (c));
#ifdef HAVE_SSL
      if (rbuf->ssl!=NULL)
	res = ssl_iread (rbuf->ssl, c, amount_to_read);
      else
#endif /* HAVE_SSL */
	res = iread (fd, c, amount_to_read);

      if (res > 0)
	{
	  fwrite (c, sizeof (char), res, fp);
	  /* Always flush the contents of the network packet.  This
	     should not be adverse to performance, as the network
	     packets typically won't be too tiny anyway.  */
	  fflush (fp);
	  if (ferror (fp))
	    {
	      res = -2;
	      goto out;
	    }

	  /* If bandwidth is not limited, one call to wtimer_elapsed
	     is sufficient.  */
	  dltime = wtimer_elapsed (timer);
	  if (opt.limit_rate)
	    {
	      limit_bandwidth (res, dltime - last_dltime);
	      dltime = wtimer_elapsed (timer);
	      last_dltime = dltime;
	    }

	  if (opt.verbose)
	    progress_update (progress, res, dltime);
	  *len += res;
	}
      else
	break;
    }
  if (res < -1)
    res = -1;

 out:
  if (opt.verbose)
    progress_finish (progress, dltime);
  if (elapsed)
    *elapsed = dltime;
  wtimer_delete (timer);

  return res;
}
コード例 #22
0
ファイル: overlap.c プロジェクト: nlchap0/nlctools
void nemo_main(void){
   int i,numwritten=0,nummissed=0;
   int numimages=0;
   stream fp_in,fp,fp2;
   string *sp,logic;
   int count,n;
   int edge_dist;             /* exclude sources this many pixels from the edge */
   string inFile;             /* name of input file */
   char line[MAX_LINELEN];    /* a line of text from the inFile */
   int racol,deccol,maxcol;   /* column numbers for ra/dec in file */
   double ra,dec;             /* the values of ra/dec for a given line */
   int nentries;              /* number of valid entries, used for progress tracking */

   inFile    = getparam("in");
   edge_dist = getiparam("edge");
   logic     = getparam("logic");

   sp = burststring(getparam("col"),", \n");
   n  = xstrlen(sp,sizeof(string)) - 1;
   if (n != 2) error("You must specify ra,dec columns for col keyword!");
   racol = natoi(sp[0]) - 1;
   deccol = natoi(sp[1]) - 1;
   freestrings(sp);
   if (racol >= deccol)
      maxcol = racol;
   else
      maxcol = deccol;


   sp = burststring(getparam("fits"),", \n");
   n  = xstrlen(sp,sizeof(string))-1;
   for (i=0; i<n; i++){
      ini_mask(sp[i],i);
      numimages++;
   }
   freestrings(sp);
   
   sp = burststring(getparam("out"),", \n");
   n  = xstrlen(sp,sizeof(string))-1;
   if (n == 1){
      fp  = stropen(sp[0],"w");
      fp2 = stropen("/dev/null","w!");
   } else if (n == 2){
      fp  = stropen(sp[0],"w");
      fp2 = stropen(sp[1],"w");
   }else
      error("You must give one or two output files!\n");
   freestrings(sp);

   nentries = nemo_file_lines(inFile,0);
   progress_init("overlap percent complete:",nentries);
   nentries = 0;
   
   fp_in = stropen(inFile,"r");
   while (fgets(line,MAX_LINELEN,fp_in)){
      progress_update(nentries);
      if (line[0] != '#'){
         nentries += 1;
         sp = burststring(line," \t\n");
         n  = xstrlen(sp,sizeof(string)) - 2; /* zero based */
         if (n < maxcol)
            error("Insufficient columns on line!");
         ra  = natof(sp[racol]);
         dec = natof(sp[deccol]);
         freestrings(sp);
         count = 0;
         for (i=0; i< numimages; i++)
            count+= is_edge(ra,dec,edge_dist,i);
         if(streq(logic,"or") && (count<numimages)){
            fprintf(fp,line);
            numwritten++;
         }
         else if(streq(logic,"and") && (count==0) && (numimages > 0)){
            fprintf(fp,line);
            numwritten++;
         }
         else {
            fprintf(fp2,line);
            nummissed++;
         }
      }
   }
   strclose(fp_in);
   strclose(fp);
   strclose(fp2);
   progress_finish();

   printf("Sources outside regions: %d\n",nummissed);
   printf("Sources inside regions: %d\n",numwritten);
   printf("Number of images: %d\n",numimages);
}
コード例 #23
0
// Called by ms_scan either in a thread or synchronously
static void *do_scan(void *userdata) {
  MediaScan *s = ((thread_data_type *)userdata)->s;
  int i;
  struct dirq *dir_head = (struct dirq *)s->_dirq;
  struct dirq_entry *dir_entry = NULL;
  struct fileq *file_head = NULL;
  struct fileq_entry *file_entry = NULL;
  char tmp_full_path[MAX_PATH_STR_LEN];

  // Initialize the cache database
  if (!init_bdb(s)) {
    MediaScanError *e = error_create("", MS_ERROR_CACHE, "Unable to initialize libmediascan cache");
    send_error(s, e);
    goto out;
  }

  if (s->flags & MS_CLEARDB) {
    reset_bdb(s);
  }

  if (s->progress == NULL) {
    MediaScanError *e = error_create("", MS_ERROR_TYPE_INVALID_PARAMS, "Progress object not created");
    send_error(s, e);
    goto out;
  }

  // Build a list of all directories and paths
  // We do this first so we can present an accurate scan eta later
  progress_start_phase(s->progress, "Discovering");

  for (i = 0; i < s->npaths; i++) {
    LOG_INFO("Scanning %s\n", s->paths[i]);
    recurse_dir(s, s->paths[i], 0);
  }

  // Scan all files found
  progress_start_phase(s->progress, "Scanning");

  while (!SIMPLEQ_EMPTY(dir_head)) {
    dir_entry = SIMPLEQ_FIRST(dir_head);

    file_head = dir_entry->files;
    while (!SIMPLEQ_EMPTY(file_head)) {
      // check if the scan has been aborted
      if (s->_want_abort) {
        LOG_DEBUG("Aborting scan\n");
        goto aborted;
      }

      file_entry = SIMPLEQ_FIRST(file_head);

      // Construct full path
      strcpy(tmp_full_path, dir_entry->dir);
#ifdef WIN32
      strcat(tmp_full_path, "\\");
#else
      strcat(tmp_full_path, "/");
#endif
      strcat(tmp_full_path, file_entry->file);

      ms_scan_file(s, tmp_full_path, file_entry->type);

      // Send progress update if necessary
      if (s->on_progress) {
        s->progress->done++;

        if (progress_update(s->progress, tmp_full_path))
          send_progress(s);
      }

      SIMPLEQ_REMOVE_HEAD(file_head, entries);
      free(file_entry->file);
      free(file_entry);
    }

    SIMPLEQ_REMOVE_HEAD(dir_head, entries);
    free(dir_entry->dir);
    free(dir_entry->files);
    free(dir_entry);
  }

  // Send final progress callback
  if (s->on_progress) {
    progress_update(s->progress, NULL);
    send_progress(s);
  }

  LOG_DEBUG("Finished scanning\n");

out:
  if (s->on_finish)
    send_finish(s);

aborted:
  if (s->async) {
    LOG_MEM("destroy thread_data @ %p\n", userdata);
    free(userdata);
  }

  return NULL;
}
コード例 #24
0
ファイル: fwdownload.c プロジェクト: orit-mell/freebsd
/* 
 * Download firmware stored in buf to cam_dev. If simulation mode
 * is enabled, only show what packet sizes would be sent to the 
 * device but do not sent any actual packets
 */
static int
fw_download_img(struct cam_device *cam_dev, const struct fw_vendor *vp,
    char *buf, int img_size, int sim_mode, int printerrors, int retry_count,
    int timeout, const char *imgname, const char *type)
{
	struct scsi_write_buffer cdb;
	progress_t progress;
	int size;
	union ccb *ccb;
	int pkt_count = 0;
	int max_pkt_size;
	u_int32_t pkt_size = 0;
	char *pkt_ptr = buf;
	u_int32_t offset;
	int last_pkt = 0;
	int16_t *ptr;

	if ((ccb = cam_getccb(cam_dev)) == NULL) {
		warnx("Could not allocate CCB");
		return (1);
	}
	if (strcmp(type, "scsi") == 0) {
		scsi_test_unit_ready(&ccb->csio, 0, NULL, MSG_SIMPLE_Q_TAG,
		    SSD_FULL_SIZE, 5000);
	} else if (strcmp(type, "ata") == 0) {
		/* cam_getccb cleans up the header, caller has to zero the payload */
		bzero(&(&ccb->ccb_h)[1],
		      sizeof(struct ccb_ataio) - sizeof(struct ccb_hdr));

		ptr = (uint16_t *)malloc(sizeof(struct ata_params));

		if (ptr == NULL) {
			cam_freeccb(ccb);
			warnx("can't malloc memory for identify\n");
			return(1);
		}
		bzero(ptr, sizeof(struct ata_params));
		cam_fill_ataio(&ccb->ataio,
                      1,
                      NULL,
                      /*flags*/CAM_DIR_IN,
                      MSG_SIMPLE_Q_TAG,
                      /*data_ptr*/(uint8_t *)ptr,
                      /*dxfer_len*/sizeof(struct ata_params),
                      timeout ? timeout : 30 * 1000);
		ata_28bit_cmd(&ccb->ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
	} else {
		warnx("weird disk type '%s'", type);
		return 1;
	}
	/* Disable freezing the device queue. */
	ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
	if (cam_send_ccb(cam_dev, ccb) < 0) {
		warnx("Error sending identify/test unit ready");
		if (printerrors)
			cam_error_print(cam_dev, ccb, CAM_ESF_ALL,
			    CAM_EPF_ALL, stderr);
		cam_freeccb(ccb);
		return(1);
	}
	if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
		warnx("Device is not ready");
		if (printerrors)
			cam_error_print(cam_dev, ccb, CAM_ESF_ALL,
			    CAM_EPF_ALL, stderr);
		cam_freeccb(ccb);
		return (1);
	}
	max_pkt_size = vp->max_pkt_size;
	if (vp->max_pkt_size == 0 && strcmp(type, "ata") == 0) {
		max_pkt_size = UNKNOWN_MAX_PKT_SIZE;
	}
	pkt_size = vp->max_pkt_size;
	progress_init(&progress, imgname, size = img_size);
	/* Download single fw packets. */
	do {
		if (img_size <= max_pkt_size) {
			last_pkt = 1;
			pkt_size = img_size;
		}
		progress_update(&progress, size - img_size);
		progress_draw(&progress);
		bzero(&cdb, sizeof(cdb));
		if (strcmp(type, "scsi") == 0) {
			cdb.opcode  = WRITE_BUFFER;
			cdb.control = 0;
			/* Parameter list length. */
			scsi_ulto3b(pkt_size, &cdb.length[0]);
			offset = vp->inc_cdb_offset ? (pkt_ptr - buf) : 0;
			scsi_ulto3b(offset, &cdb.offset[0]);
			cdb.byte2 = last_pkt ? vp->cdb_byte2_last : vp->cdb_byte2;
			cdb.buffer_id = vp->inc_cdb_buffer_id ? pkt_count : 0;
			/* Zero out payload of ccb union after ccb header. */
			bzero((u_char *)ccb + sizeof(struct ccb_hdr),
			    sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
			/* Copy previously constructed cdb into ccb_scsiio struct. */
			bcopy(&cdb, &ccb->csio.cdb_io.cdb_bytes[0],
			    sizeof(struct scsi_write_buffer));
			/* Fill rest of ccb_scsiio struct. */
			if (!sim_mode) {
				cam_fill_csio(&ccb->csio,		/* ccb_scsiio	*/
				    retry_count,			/* retries	*/
				    NULL,				/* cbfcnp	*/
				    CAM_DIR_OUT | CAM_DEV_QFRZDIS,	/* flags	*/
				    CAM_TAG_ACTION_NONE,		/* tag_action	*/
				    (u_char *)pkt_ptr,			/* data_ptr	*/
				    pkt_size,				/* dxfer_len	*/
				    SSD_FULL_SIZE,			/* sense_len	*/
				    sizeof(struct scsi_write_buffer),	/* cdb_len	*/
				    timeout ? timeout : CMD_TIMEOUT);	/* timeout	*/
			}
		} else if (strcmp(type, "ata") == 0) {
			bzero(&(&ccb->ccb_h)[1],
			      sizeof(struct ccb_ataio) - sizeof(struct ccb_hdr));
			if (!sim_mode) {
				uint32_t	off;

				cam_fill_ataio(&ccb->ataio,
					(last_pkt) ? 256 : retry_count,
					NULL,
					/*flags*/CAM_DIR_OUT | CAM_DEV_QFRZDIS,
					CAM_TAG_ACTION_NONE,
					/*data_ptr*/(uint8_t *)pkt_ptr,
					/*dxfer_len*/pkt_size,
					timeout ? timeout : 30 * 1000);
				off = (uint32_t)(pkt_ptr - buf);
				ata_28bit_cmd(&ccb->ataio, ATA_DOWNLOAD_MICROCODE,
					USE_OFFSETS_FEATURE,
					ATA_MAKE_LBA(off, pkt_size),
					ATA_MAKE_SECTORS(pkt_size));
			}
		}
		if (!sim_mode) {
			/* Execute the command. */
			if (cam_send_ccb(cam_dev, ccb) < 0 ||
			    (ccb->ccb_h.status & CAM_STATUS_MASK) !=
			    CAM_REQ_CMP) {
				warnx("Error writing image to device");
				if (printerrors)
					cam_error_print(cam_dev, ccb, CAM_ESF_ALL,
						   CAM_EPF_ALL, stderr);
				goto bailout;
			}
		}
		/* Prepare next round. */
		pkt_count++;
		pkt_ptr += pkt_size;
		img_size -= pkt_size;
	} while(!last_pkt);
	progress_complete(&progress, size - img_size);
	cam_freeccb(ccb);
	return (0);
bailout:
	progress_complete(&progress, size - img_size);
	cam_freeccb(ccb);
	return (1);
}
コード例 #25
0
ファイル: net_util.c プロジェクト: alkap007/ali3606
int dump_data(UrlResource *rsrc, int sock, FILE *out, libnet_callback notify)
{
	Progress *p = NULL;
	int bytes_read   = 0;
	ssize_t written	   = 0;
	char *buf = NULL;
	int lenth, final, final2 = 0;
	int buflen;
	if ((out == NULL) && (rsrc->buffer == NULL) && (NULL == rsrc->strfile_handle))
		return 0;

	/* if we already have all of it */
	if ( !(rsrc->options ) )
	{
		if ( rsrc->outfile_size &&(rsrc->outfile_offset >= rsrc->outfile_size) )
		{
			LIBNET_DEBUG( "you already have all of `%s', skipping", rsrc->outfile);
			//S_CLOSE(sock);
			return 0;
		}
	}

	p = progress_new();
	p->tranfer_callback = notify;
	if(NULL == rsrc->strfile_handle)
	{
		progress_init(p, rsrc, rsrc->outfile_size);
		progress_update(p, rsrc->outfile_offset);
		buflen = BUFSIZE;
	}else
	{
		progress_init(p, rsrc, rsrc->outfile_size);
		buflen = BUFSIZE * 3;
	}
	p->offset = rsrc->outfile_offset;

	if ( out && (rsrc->outfile_offset > 0) && (rsrc->options & OPT_RESUME))
	{
		fseek(out, rsrc->outfile_offset, SEEK_SET);
		LIBNET_DEBUG("ftell = %d \n", ftell(out));
	}
	buf = MALLOC(buflen);
	if(rsrc->strfile_handle)
	{
		fd_set set;
		struct timeval tv = {30, 0};
		FD_ZERO(&set);
		FD_SET(sock, &set);
		while (lwip_select(sock + 1, &set, NULL, NULL, &tv) > 0 && (rsrc->running))
		{
			bytes_read = S_READ(sock, buf, buflen);
			if(0 >= bytes_read)
				break;
			lenth = bytes_read;
			final += bytes_read;
			final2 += bytes_read;
			while(lenth)
			{
				written = httpstrfile_writedatatobuff(rsrc->strfile_handle, buf + (bytes_read - lenth), (UINT32)lenth);
				lenth -= written;
				osal_task_sleep(1);
			}
			if(0x20000 <= final2)
			{
//				libc_printf("final = %d/%d\n", final, rsrc->outfile_size);
				progress_update(p, final2);
				final2 = 0;
			}			
		}
コード例 #26
0
ファイル: file.c プロジェクト: svn2github/htmldoc
char *					/* O - Pathname or NULL */
file_find(const char *path,		/* I - Path "dir;dir;dir" */
          const char *s)		/* I - File to find */
{
  int		i;			/* Looping var */
  int		retry;			/* Current retry */
  char		*temp,			/* Current position in filename */
		method[HTTP_MAX_URI],	/* Method/scheme */
		username[HTTP_MAX_URI],	/* Username:password */
		hostname[HTTP_MAX_URI],	/* Hostname */
		resource[HTTP_MAX_URI];	/* Resource */
  int		port;			/* Port number */
  const char	*connhost;		/* Host to connect to */
  int		connport;		/* Port to connect to */
  char		connpath[HTTP_MAX_URI],	/* Path for GET */
		connauth[HTTP_MAX_VALUE];/* Auth string */
  http_status_t	status;			/* Status of request... */
  FILE		*fp;			/* Web file */
  int		bytes,			/* Bytes read */
		count,			/* Number of bytes so far */
		total;			/* Total bytes in file */
  static char	filename[HTTP_MAX_URI];	/* Current filename */


 /*
  * If the filename is NULL, return NULL...
  */

  if (s == NULL)
    return (NULL);

  if (strncmp(s, "http:", 5) == 0 ||
      (path != NULL && strncmp(path, "http:", 5) == 0))
    strcpy(method, "http");
#ifdef HAVE_LIBSSL
  else if (strncmp(s, "https:", 6) == 0 ||
           (path != NULL && strncmp(path, "https:", 6) == 0))
    strcpy(method, "https");
#endif /* HAVE_LIBSSL */
  else
    strcpy(method, "file");

  if (strcmp(method, "file") == 0)
  {
   /*
    * If the path is NULL or empty, return the filename...
    */

    if (path == NULL || !path[0])
      return ((char *)s);

   /*
    * Else loop through the path string until we reach the end...
    */

    while (*path != '\0')
    {
     /*
      * Copy the path directory...
      */

      temp = filename;

      while (*path != ';' && *path && temp < (filename + sizeof(filename) - 1))
	*temp++ = *path++;

      if (*path == ';')
	path ++;

     /*
      * Append a slash as needed...
      */

      if (temp > filename && temp < (filename + sizeof(filename) - 1) &&
          s[0] != '/')
	*temp++ = '/';

     /*
      * Append the filename...
      */

      strncpy(temp, s, sizeof(filename) - (temp - filename));
      filename[sizeof(filename) - 1] = '\0';

     /*
      * See if the file exists...
      */

      if (!access(filename, 0))
	return (filename);
    }
  }
  else
  {
   /*
    * Remote file; look it up in the web cache, and then try getting it
    * from the remote system...
    */

    for (i = 0; i < web_files; i ++)
      if (web_cache[i].url && strcmp(web_cache[i].url, s) == 0)
        return (web_cache[i].name);

#ifdef HAVE_LIBSSL
    if (strncmp(s, "http:", 5) == 0 || strncmp(s, "https:", 6) == 0)
#else
    if (strncmp(s, "http:", 5) == 0)
#endif /* HAVE_LIBSSL */
      httpSeparate(s, method, username, hostname, &port, resource);
    else if (s[0] == '/')
    {
      httpSeparate(path, method, username, hostname, &port, resource);
      strcpy(resource, s);
    }
    else
    {
      if (strncmp(s, "./", 2) == 0)
        snprintf(filename, sizeof(filename), "%s/%s", path, s + 2);
      else
        snprintf(filename, sizeof(filename), "%s/%s", path, s);

      httpSeparate(filename, method, username, hostname, &port, resource);
    }

    for (status = HTTP_ERROR, retry = 0;
         status == HTTP_ERROR && retry < 5;
         retry ++)
    {
      if (proxy_port)
      {
       /*
        * Send request to proxy host...
        */

        connhost = proxy_host;
        connport = proxy_port;
        snprintf(connpath, sizeof(connpath), "%s://%s:%d%s", method,
                 hostname, port, resource);
      }
      else
      {
       /*
        * Send request to host directly...
        */

        connhost = hostname;
        connport = port;
        strcpy(connpath, resource);
      }

      if (http != NULL && strcasecmp(http->hostname, hostname) != 0)
      {
        httpClose(http);
        http = NULL;
      }

      if (http == NULL)
      {
        progress_show("Connecting to %s...", connhost);
        atexit(file_cleanup);

#ifdef HAVE_LIBSSL
        if (strcmp(method, "http") == 0)
          http = httpConnect(connhost, connport);
	else
          http = httpConnectEncrypt(connhost, connport, HTTP_ENCRYPT_ALWAYS);
#else
        http = httpConnect(connhost, connport);
#endif /* HAVE_LIBSSL */

        if (http == NULL)
	{
          progress_hide();
          progress_error("Unable to connect to %s!", connhost);
          return (NULL);
        }
      }

      progress_show("Getting %s...", connpath);

      httpClearFields(http);
      httpSetField(http, HTTP_FIELD_HOST, hostname);
      httpSetField(http, HTTP_FIELD_USER_AGENT, "HTMLDOC v" SVERSION);
      httpSetField(http, HTTP_FIELD_CONNECTION, "Keep-Alive");

      if (username[0])
      {
        strcpy(connauth, "Basic ");
        httpEncode64(connauth + 6, username);
        httpSetField(http, HTTP_FIELD_AUTHORIZATION, connauth);
      }

      if (!httpGet(http, connpath))
	while ((status = httpUpdate(http)) == HTTP_CONTINUE);
      else
	status = HTTP_ERROR;

      if (status >= HTTP_MOVED_PERMANENTLY && status <= HTTP_SEE_OTHER)
      {
       /*
        * Flush text...
	*/

	httpFlush(http);

       /*
        * Grab new location from HTTP data...
	*/

        httpSeparate(httpGetField(http, HTTP_FIELD_LOCATION), method, username,
	             hostname, &port, resource);
        status = HTTP_ERROR;
      }
    }

    if (status != HTTP_OK)
    {
      progress_hide();
      progress_error("HTTP error %d: %s!", status, httpStatus(status));
      httpFlush(http);
      return (NULL);
    }

    if ((fp = file_temp(filename, sizeof(filename))) == NULL)
    {
      progress_hide();
      progress_error("Unable to create temporary file \"%s\": %s", filename,
                     strerror(errno));
      httpFlush(http);
      return (NULL);
    }

    if ((total = atoi(httpGetField(http, HTTP_FIELD_CONTENT_LENGTH))) == 0)
      total = 8192;

    count = 0;
    while ((bytes = httpRead(http, resource, sizeof(resource))) > 0)
    {
      count += bytes;
      progress_update((100 * count / total) % 101);
      fwrite(resource, 1, bytes, fp);
    }

    progress_hide();

    fclose(fp);

    web_cache[web_files - 1].name = strdup(filename);
    web_cache[web_files - 1].url  = strdup(s);

    return (filename);
  }

  return (NULL);
}
コード例 #27
0
ファイル: view_rtl_liquid.c プロジェクト: rzel/dim3
void view_dim3rtl_map_liquid_mesh_start(void)
{
	int					n,k,mesh_id,
						nvertex,div_count;
	short				v_idx;
	short				*vk,*ray_polys;
	map_liquid_type		*liq;
			
		// build the meshes

	for (n=0;n!=map.liquid.nliquid;n++) {
		liq=&map.liquid.liquids[n];

			// add the mesh

		mesh_id=rtlSceneMeshAdd(view_rtl_draw_scene_id,0);
		if (mesh_id<0) return;

		liq->rtl_mesh_id=mesh_id;

			// setup data sizes

		div_count=liquid_wave_get_divisions(liq);
		nvertex=(div_count+1)*2;
		
		rtlSceneMeshSetVertex(view_rtl_draw_scene_id,mesh_id,RL_MESH_FORMAT_VERTEX_3_FLOAT,nvertex,NULL);
		rtlSceneMeshSetUV(view_rtl_draw_scene_id,mesh_id,RL_MESH_FORMAT_UV_2_FLOAT,nvertex,NULL);
		rtlSceneMeshSetNormal(view_rtl_draw_scene_id,mesh_id,RL_MESH_FORMAT_NORMAL_3_FLOAT,nvertex,NULL);
		rtlSceneMeshSetTangent(view_rtl_draw_scene_id,mesh_id,RL_MESH_FORMAT_TANGENT_3_FLOAT,nvertex,NULL);

			// add in the data

		view_dim3rtl_map_liquid_create_draw_data(liq);

			// create the polygons
			// liquids are auto-generated, so we actually
			// have a single unique index for all
			// vertex, uv, normal, and tangents

		ray_polys=(short*)malloc((div_count*(2+(4*4)))*sizeof(short));
		vk=ray_polys;

		v_idx=0;

		for (k=0;k!=div_count;k++) {
			*vk++=4;
			*vk++=(short)map.textures[liq->txt_idx].frames[0].bitmap.rl_material_id;

			*vk++=v_idx;			// top-left
			*vk++=v_idx;
			*vk++=v_idx;
			*vk++=v_idx;

			*vk++=v_idx+1;			// bottom-left
			*vk++=v_idx+1;
			*vk++=v_idx+1;
			*vk++=v_idx+1;

			*vk++=v_idx+3;			// bottom-right
			*vk++=v_idx+3;
			*vk++=v_idx+3;
			*vk++=v_idx+3;

			*vk++=v_idx+2;			// top-right
			*vk++=v_idx+2;
			*vk++=v_idx+2;
			*vk++=v_idx+2;

			v_idx+=2;
		}

		rtlSceneMeshSetPoly(view_rtl_draw_scene_id,mesh_id,RL_MESH_FORMAT_POLY_SHORT_VERTEX_UV_NORMAL_TANGENT,div_count,ray_polys);
		free(ray_polys);

		progress_update();
	}
}