예제 #1
0
int si2c_init(
	struct i2c_adapter *adap,
	si2c_const_param_t *src, si2c_param_t *dst)
{
	si2c_pid_t i = SI2C_PID_MAX;
	si2c_pid_t j = SI2C_PID_MAX;

	CINFO("%s E\n", __func__);

	if (!adap || !src || !dst) {
		CERR("%s err(-EINVAL)\n", __func__); 
		return -EINVAL;
	}

	if (si2c_adap != NULL) {
		CERR("%s err(-EBUSY)\n", __func__); 
		return -EBUSY;
	}

	si2c_adap = adap;

	for (i = 0; i < SI2C_PID_MAX; i++)
		for (j = 0; j < SI2C_PID_MAX; j++)
			if ((src[j].id == i) && (src[j].cmds != NULL)) {
				dst[i].id = src[j].id;
				dst[i].cmds = (si2c_cmd_t *)src[j].cmds;
				break;
			}

	CINFO("%s X\n", __func__);
	return 0;
}
예제 #2
0
int sgpio_init(sgpio_ctrl_t *gpios, uint32_t sz)
{
	uint32_t i = 0;
	int rc = 0;

	CINFO("%s E\n", __func__);

	for (i = 0; i < sz; i++) {
		rc = gpio_request(gpios[i].nr, gpios[i].label);
		CINFO("%s gpios[i].nr=%d, gpios[i].label=%s\n", __func__, gpios[i].nr, gpios[i].label);
		if (rc < 0) {			
			CERR("%s req err(%d, %s)\n", __func__, rc, gpios[i].label);

			gpio_free(gpios[i].nr);
			CINFO("%s gpio_free(%d) and retry request~ \n", __func__, gpios[i].nr);
			rc = gpio_request(gpios[i].nr, gpios[i].label);			
			if (rc < 0) {			
				CERR("%s after retry req err(%d, %s)\n", __func__, rc, gpios[i].label);
				return rc;
			}
		}
		rc = gpio_direction_output(gpios[i].nr, 0);
		//gpio_set_value_cansleep(gpios[i].nr, 0);
		if (rc < 0) {
			CERR("%s dir_out err(%d, %s)\n", __func__, rc, gpios[i].label);
			return rc;
		}
	}

	CINFO("%s X\n", __func__);
	return 0;
}
예제 #3
0
void si2c_release(void)
{
	CINFO("%s E\n", __func__);

	if (si2c_adap != NULL)
		si2c_adap = NULL;

	CINFO("%s X\n", __func__);
}
예제 #4
0
void sgpio_release(sgpio_ctrl_t *gpios, uint32_t sz)
{
	uint32_t i = 0;

	CINFO("%s E\n", __func__);

	for (i = 0; i < sz; i++)
		gpio_free(gpios[i].nr);

	CINFO("%s X\n", __func__);
}
예제 #5
0
void svreg_release(svreg_ctrl_t *vregs, uint32_t sz)
{
	uint32_t i = 0;

	CINFO("%s E\n", __func__);

	for (i = 0; i < sz; i++)
		if (vregs[i].vreg)
			regulator_put(vregs[i].vreg);

	CINFO("%s X\n", __func__);
}
예제 #6
0
int svreg_ctrl(svreg_ctrl_t *vregs, int id, int val)
{
	int rc = 0;

	/* PANTECH_CAMERA_TODO, How to verify id? */

	if (!vregs[id].vreg) {
		CERR("%s (-ENOENT, %d)\n", __func__, id);
		return -ENOENT;
	}

	if (val) {
		rc = regulator_enable(vregs[id].vreg);
		if (rc) {
			CERR("%s on err(%d, %s)\n", __func__, rc,
				vregs[id].vname);
			return rc;
		}
	} else {
		rc = regulator_disable(vregs[id].vreg);
		if (rc) {
			CERR("%s off err(%d, %s)\n", __func__, rc,
				vregs[id].vname);
			return rc;
		}
	}

	CINFO("%s set %s to %d\n", __func__, vregs[id].vname, val);
	return 0;
}
예제 #7
0
파일: proc.c 프로젝트: MatusKysel/Constable
static int rbac_proc_get_vs( struct class_handler_s *h, struct comm_s *comm, struct object_s *o, vs_t *vs, int n )
{ struct user_s *u;
    struct role_s *r;
    uid_t uid;
    uintptr_t session;
    int i;

    VALIDATE_ROLES();
    if( ((struct proc_class_handler_s*)h)->attr_uid[comm->conn]==NULL )
        return(0);
    object_get_val(o,((struct proc_class_handler_s*)h)->attr_uid[comm->conn],&uid,sizeof(uid));
    if( (u=rbac_user_find_by_uid(uid))==NULL )
    {	runtime("RBAC: Unknown uid %d",uid);
        return(-1);
    }
    session=(uintptr_t)CINFO(o,h,comm);
    i=0;
    while( session && i<USER_MAX_ROLES )
    {	if( (session & 0x01) && (r=u->roles[i]) )
        {	vs_add(r->vs[n],vs);
            //			if( n==AT_MEMBER )
            //				vs_add(r->vs_sub,vs);
        }
        session>>=1;
        i++;
    }
    return(0);
}
예제 #8
0
파일: proc.c 프로젝트: MatusKysel/Constable
static int rbac_proc_set_handler( struct class_handler_s *h, struct comm_s *comm, struct object_s *o )
{ struct user_s *u;
    struct role_s *r;
    uid_t uid;
    uintptr_t session;
    int i,a;

    VALIDATE_ROLES();
    if( ((struct proc_class_handler_s*)h)->attr_uid[comm->conn]==NULL )
        return(0);
    object_get_val(o,((struct proc_class_handler_s*)h)->attr_uid[comm->conn],&uid,sizeof(uid));
    if( (u=rbac_user_find_by_uid(uid))==NULL )
    {	runtime("RBAC: Unknown uid %d",uid);
        return(-1);
    }
    object_add_event(o,&(u->cinfo->events[comm->conn].event[0]));
    session=(uintptr_t)CINFO(o,h,comm);
    i=0;
    while( session && i<USER_MAX_ROLES )
    {	if( (session & 0x01) && (r=u->roles[i]) )
        {	for(a=0;a<NR_ACCESS_TYPES;a++)
                object_add_vs(o,a,r->vs[a]);
            object_add_vs(o,AT_MEMBER,r->vs_sub);
            object_add_event(o,&(r->cinfo_sub->events[comm->conn].event[0]));
            object_add_event(o,&(r->cinfo_sup->events[comm->conn].event[0]));
        }
        session>>=1;
        i++;
    }
    object_add_event(o,((struct event_names_s*)(h->user))->events[comm->conn]->mask);
    return(0);
}
예제 #9
0
파일: proc.c 프로젝트: MatusKysel/Constable
static int rbac_proc_setuid_handler_notify( struct comm_buffer_s *cb, struct event_handler_s *h, struct event_context_s *c )
{
    CINFO(&(c->subject),rbac_proc_ch,cb->comm)=~(uintptr_t)0;
    object_do_sethandler(&(c->subject));
    c->result=RESULT_OK;
    return(0);
}
예제 #10
0
파일: ct_main.c 프로젝트: finid/cyphertite
void
ct_print_traverse_end(void *state, char **filelist)
{
	int	*verbose = state;

	if (*verbose)
		CINFO("Done! Initiating backup...");
}
예제 #11
0
파일: ct_main.c 프로젝트: finid/cyphertite
void
ct_print_traverse_start(void *state, char **filelist)
{
	int	*verbose = state;

	if (*verbose)
		CINFO("Generating filelist, this may take a few minutes...");
}
예제 #12
0
static gboolean
meta1_dispatch_UPDATECONTAINERS(struct gridd_reply_ctx_s *reply,
		struct meta1_backend_s *m1, gpointer ignored)
{
	GError *err = NULL;
	GSList *list_of_cinfo = NULL, *l;

	(void) ignored;
	err = message_extract_body_encoded(reply->request, &list_of_cinfo,
			container_info_unmarshall);
	if (NULL != err) {
		reply->send_error(0, err);
		return TRUE;
	}

	if (!list_of_cinfo)
		reply->subject("empty");
	else if (!list_of_cinfo->next) {
		gchar strcid[65];
		container_id_to_string(CINFO(list_of_cinfo->data)->id, strcid, sizeof(strcid));
		reply->subject("%s|%"G_GINT64_FORMAT, strcid, CINFO(list_of_cinfo->data)->size);
	}
	else
		reply->subject("%u", g_slist_length(list_of_cinfo));

	for (l=list_of_cinfo; l ;l=l->next) {
		if (NULL != (err = _update_container_quota(m1, l->data))) {
			reply->send_error(0, err);
			break;
		}
	}

	if (list_of_cinfo) {
		g_slist_foreach(list_of_cinfo, g_free1, NULL);
		g_slist_free(list_of_cinfo);
		list_of_cinfo = NULL;
	}

	if (!err)
		reply->send_reply(200, "OK");
	return TRUE;
}
예제 #13
0
int svreg_init(svreg_ctrl_t *vregs, uint32_t sz)
{
	struct regulator *vreg = NULL;
	int uvolt = 0;
	uint32_t i = 0;
	int rc = 0;

	CINFO("%s E\n", __func__);

	for (i = 0; i < sz; i++) {
		vreg = regulator_get(NULL, vregs[i].vname);
		if (IS_ERR(vreg)) {
			CERR("%s err(-EBUSY, %s)\n", __func__, vregs[i].vname);
			return -EBUSY;
		}

		vregs[i].vreg = vreg;

		/* Some voltage sources don't have interface to set voltage 
		 * levels. You can check these limitations in appropriate 
		 * regulator platform drivers.
		 * (e.g. pmic8901-regulator.c, pmic8058-regulator.c,...)
		 * So we don't call 'regulator_set_voltage' for this kind 
		 * of voltage sources. IOW you should set voltage level
		 * correctly in board initialization code.
		 * (e.g. static struct rpm_vreg_pdata rpm_vreg_init_pdata[]) */
		if (vregs[i].arg == 0)
			continue;

		uvolt = vregs[i].arg * 1000;

		rc = regulator_set_voltage(vreg, uvolt, uvolt);
		if (rc < 0) {
			CERR("%s err(%d, %s)\n", __func__, rc, vregs[i].vname);
			return rc;
		}
	}

	CINFO("%s X\n", __func__);
	return 0;
}
예제 #14
0
int si2c_write_param(uint16_t sa, si2c_pid_t pid, si2c_param_t *params)
{
	int rc = 0;

	CINFO("%s E pid=%d\n", __func__, pid);

	if ((pid < 0) || (pid >= SI2C_PID_MAX) || !params) {
		CERR("%s err(-EINVAL)\n", __func__);
		return -EINVAL;
	}

	if (params[pid].cmds == NULL) {
		CERR("%s err(-ENOENT)\n", __func__);
		return -ENOENT;
	}

	rc = si2c_write_cmds(sa, params[pid].cmds);

	CINFO("%s X (%d)\n", __func__, rc);
	return rc;
}
예제 #15
0
int sgpio_init(sgpio_ctrl_t *gpios, uint32_t sz)
{
	uint32_t i = 0;
	int rc = 0;

	CINFO("%s E\n", __func__);

	for (i = 0; i < sz; i++) {
		rc = gpio_request(gpios[i].nr, gpios[i].label);
		if (rc < 0) {
			CERR("%s req err(%d, %s)\n", __func__, rc, gpios[i].label);
			return rc;
		}
		rc = gpio_direction_output(gpios[i].nr, 0);
		if (rc < 0) {
			CERR("%s dir_out err(%d, %s)\n", __func__, rc, gpios[i].label);
			return rc;
		}
	}

	CINFO("%s X\n", __func__);
	return 0;
}
예제 #16
0
static void
gt_clustered_set_union_find_append_elem(GtClusteredSetUF *cs_uf,
                                        GtUword c,
                                        GtUword elem,
                                        GT_UNUSED GtError *err)
{
  GtClusteredSetUFClusterInfo *cluster_info;
  cs_uf->cluster_elems[elem].cluster_num = c;
  cs_uf->cluster_elems[elem].next_elem = cs_uf->num_of_elems;
  cluster_info = CINFO(c);
  cs_uf->cluster_elems[cluster_info->last_elem].next_elem = elem;
  cluster_info->last_elem = elem;
  cluster_info->cluster_size++;
}
예제 #17
0
GtClusteredSetIterator*
gt_clustered_set_union_find_iterator_new(GtClusteredSet *cs,
                                         GtUword c,
                                         GT_UNUSED GtError *err)
{
  gt_assert(cs);
  GtClusteredSetUF *cs_uf = (GtClusteredSetUF*) cs;
  GtClusteredSetIterator *cs_i = gt_calloc(1, sizeof (GtClusteredSetIterator));
  GtUword i = 0, j = 0;
  if (SINGLETON(c)) {
    cs_i->length = (GtUword) 1;
    cs_i->curpos = (GtUword) 0;
    cs_i->elems = gt_calloc(1, sizeof (GtUword));
    cs_i->elems[j] = c;
  }
  else {
    if (CINFO(c)->cluster_size > 0) {
      GtClusteredSetUFClusterInfo *cluster_info;
      cluster_info = CINFO(c);
      cs_i->length = cluster_info->cluster_size;
      cs_i->curpos = (GtUword) 0;
      cs_i->elems = gt_calloc(cluster_info->cluster_size,
                              sizeof (GtUword));
      i = cluster_info->first_elem;

      do {
        cs_i->elems[j] = i;
        j++;
      } while ((i = cs_uf->cluster_elems[i].next_elem) < cs_uf->num_of_elems);

    } else {
      gt_free(cs_i);
      return NULL;
    }
  }
  return cs_i;
}
예제 #18
0
static void
gt_clustered_set_union_find_join_clusters(GtClusteredSetUF *cs_uf,
                                           GtUword c1,
                                           GtUword c2,
                                           GT_UNUSED GtError *err)
{
  GtClusteredSetUFClusterInfo *cluster_info_c1;
  GtClusteredSetUFClusterInfo *cluster_info_c2;

  cluster_info_c1 = CINFO(c1);
  cluster_info_c2 = CINFO(c2);

  gt_clustered_set_union_find_change_cluster_number(cs_uf,
                                                    cluster_info_c2->first_elem,
                                                    c1);

  cs_uf->cluster_elems[cluster_info_c1->last_elem].next_elem =
    cluster_info_c2->first_elem;

  cluster_info_c2->first_elem = cs_uf->num_of_elems;
  cluster_info_c1->cluster_size += cluster_info_c2->cluster_size;
  cluster_info_c1->last_elem = cluster_info_c2->last_elem;
  cluster_info_c2->cluster_size = (GtUword) 0;
}
예제 #19
0
int sgpio_ctrl(sgpio_ctrl_t *gpios, int id, int val)
{
	int rc = 0;

	/* PANTECH_CAMERA_TODO, How to verify id? */

	if (val != 0)
		val = 1;

	rc = gpio_direction_output(gpios[id].nr, val);
	if (rc < 0) {
		CERR("%s err(%d, %s)\n", __func__, rc, gpios[id].label);
		return rc;
	}

	CINFO("%s set %s to %d\n", __func__, gpios[id].label, val);
	return 0;
}
예제 #20
0
void
ct_extract(struct ct_global_state *state, struct ct_op *op)
{
	struct ct_extract_args	*cea = op->op_args;
	const char		*ctfile = cea->cea_local_ctfile;
	char			**filelist = cea->cea_filelist;
	int			 match_mode = cea->cea_matchmode;
	struct ct_extract_priv	*ex_priv = op->op_priv;
	int			ret;
	struct ct_trans		*trans;
	char			shat[SHA_DIGEST_STRING_LENGTH];

	/* if we were woken up due to fatal, just clean up local state */
	if (state->ct_dying != 0)
		goto dying;

	CNDBG(CT_LOG_TRANS, "entry");
	switch (ct_get_file_state(state)) {
	case CT_S_STARTING:
		if (ex_priv == NULL) {
			ex_priv = e_calloc(1, sizeof(*ex_priv));
			TAILQ_INIT(&ex_priv->extract_head);

			if ((ret = ct_match_compile(&ex_priv->inc_match,
			    match_mode, filelist)) != 0) {
				ct_fatal(state,
				    "failed to compile include pattern", ret);
				goto dying;
			}
			if (cea->cea_excllist != NULL &&
			    (ret = ct_match_compile(&ex_priv->ex_match,
			    match_mode, cea->cea_excllist)) != 0) {
				ct_fatal(state,
				    "failed to compile exclude pattern", ret);
				goto dying;
			}
			op->op_priv = ex_priv;
			RB_INIT(&ex_priv->pending_tree);
		}
		
		if ((ret = ct_file_extract_init(&state->extract_state,
		    cea->cea_tdir, cea->cea_attr,  cea->cea_follow_symlinks,
		    ex_priv->allfiles, cea->cea_log_state,
		    cea->cea_log_chown_failed)) != 0) {
			ct_fatal(state, "Can not initialize extract state",
			    ret);
			goto dying;
		}

		if (ct_extract_calculate_total(state, cea, ex_priv->inc_match,
		    ex_priv->ex_match) != 0) {
			CWARNX("failed to calculate stats");
			goto dying;
		}

		if ((ret = ct_extract_setup(&ex_priv->extract_head,
		    &ex_priv->xdr_ctx, ctfile, cea->cea_ctfile_basedir,
		    &ex_priv->allfiles)) != 0) {
			ct_fatal(state, "can't setup extract queue", ret);
			goto dying;
		}
		state->ct_print_ctfile_info(state->ct_print_state,
		    ex_priv->xdr_ctx.xs_filename, &ex_priv->xdr_ctx.xs_gh);
		/* XXX we should handle this better */
		if (state->ct_max_block_size <
		    ex_priv->xdr_ctx.xs_gh.cmg_chunk_size)
			CABORTX("block size negotiated with server %d is "
			    "smaller than file max block size %d",
			    state->ct_max_block_size,
			    ex_priv->xdr_ctx.xs_gh.cmg_chunk_size);
		/* create rb tree head, prepare to start inserting */
		if (ex_priv->allfiles) {
			ex_priv->fillrb = 1;
		}
		break;
	case CT_S_FINISHED:
		return;
	default:
		break;
	}

	ct_set_file_state(state, CT_S_RUNNING);
	while (1) {
		trans = ct_trans_alloc(state);
		if (trans == NULL) {
			/* system busy, return */
			CNDBG(CT_LOG_TRANS, "ran out of transactions, waiting");
			ct_set_file_state(state, CT_S_WAITING_TRANS);
			return;
		}
		trans->tr_statemachine = ct_state_extract;

		switch ((ret = ctfile_parse(&ex_priv->xdr_ctx))) {
		case XS_RET_FILE:
			if (ex_priv->fillrb == 0 &&
			    ex_priv->xdr_ctx.xs_hdr.cmh_nr_shas == -1) {
				if (ex_priv->allfiles == 0)
					CINFO("file %s has negative shas "
					    "and backup is not allfiles",
					    ex_priv->xdr_ctx.xs_hdr.cmh_filename);
				ex_priv->doextract = 0;
				goto skip; /* skip ze file for now */
			}

			trans = ct_trans_realloc_local(state, trans);
			trans->tr_fl_node = ex_priv->fl_ex_node = 
			    ct_alloc_fnode();

			ct_populate_fnode(state->extract_state,
			    &ex_priv->xdr_ctx, trans->tr_fl_node,
			    &trans->tr_state, ex_priv->allfiles,
			    cea->cea_strip_slash);
			if (trans->tr_state == TR_S_EX_SPECIAL) {
				trans->tr_complete =
				    ct_extract_complete_special;
			} else {
				trans->tr_complete =
				    ct_extract_complete_file_start;
			}
			trans->tr_cleanup = ct_extract_cleanup_fnode;

			if (ex_priv->haverb) {
				struct ct_pending_file *cpf;
				if ((cpf = ct_extract_find_entry(
				    &ex_priv->pending_tree,
				    trans->tr_fl_node->fn_fullname)) != NULL) {
					struct fnode *hardlink;
					/* copy permissions over */
					trans->tr_fl_node->fn_uid =
					    cpf->cpf_uid;
					trans->tr_fl_node->fn_gid =
					    cpf->cpf_gid;
					trans->tr_fl_node->fn_mode =
					    cpf->cpf_mode;
					trans->tr_fl_node->fn_mtime =
					    cpf->cpf_mtime;
					trans->tr_fl_node->fn_atime =
					    cpf->cpf_atime;

					/* copy list of pending links over */
					while ((hardlink =
					    TAILQ_FIRST(&cpf->cpf_links))) {
						TAILQ_REMOVE(&cpf->cpf_links,
						    hardlink, fn_list);
						TAILQ_INSERT_TAIL(
						    &trans->tr_fl_node->fn_hardlinks,
						    hardlink, fn_list);
					}
					
					ex_priv->doextract = 1;
					ct_extract_free_entry(
					    &ex_priv->pending_tree, cpf);
				} else {
					ex_priv->doextract = 0;
				}
				
			} else {
				ex_priv->doextract =
				    !ct_match(ex_priv->inc_match,
				    trans->tr_fl_node->fn_fullname);
				if (ex_priv->doextract &&
				    ex_priv->ex_match != NULL &&
				    !ct_match(ex_priv->ex_match,
				    trans->tr_fl_node->fn_fullname)) {
					ex_priv->doextract = 0;
				}
			}
			if (ex_priv->doextract &&
			    trans->tr_fl_node->fn_hardlink) {
				struct ct_pending_file	*file;
				if ((file = ct_extract_find_entry(
				    &ex_priv->pending_tree,
				    trans->tr_fl_node->fn_hlname)) != NULL) {
					CNDBG(CT_LOG_FILE,
					    "adding pending link for %s to %s",
					    file->cpf_name,
					    trans->tr_fl_node->fn_fullname);
					/* our reference to node passed */
					ct_pending_file_add_link(file,
					    trans->tr_fl_node);
					ex_priv->doextract = 0;
					goto skip;
				}
			}

			/*
			 * If we're on the first ctfile in an allfiles backup
			 * put the matches with -1 on the rb tree so we'll
			 * remember to extract it from older files.
			 */
			if (ex_priv->doextract == 1 && ex_priv->fillrb &&
			    ex_priv->xdr_ctx.xs_hdr.cmh_nr_shas == -1) {
				ct_extract_insert_entry(&ex_priv->pending_tree,
				    trans->tr_fl_node);

				ex_priv->doextract = 0;
				/* XXX reconsider the freeing */
			}
			if (ex_priv->doextract == 0) {
				ct_free_fnode(trans->tr_fl_node);
skip:
				ex_priv->fl_ex_node = NULL;
				ct_trans_free(state, trans);
				continue;
			}

			CNDBG(CT_LOG_CTFILE,
			    "file %s numshas %" PRId64,
			    trans->tr_fl_node->fn_fullname,
			    ex_priv->xdr_ctx.xs_hdr.cmh_nr_shas);

			/*
			 * special files we give our refcount up
			 * regular files we need a new one since we need to
			 * keep ours.
			 */
			if (trans->tr_state != TR_S_EX_SPECIAL) {
				ct_ref_fnode(trans->tr_fl_node);
			} else {
				ex_priv->fl_ex_node = NULL;
			}
			ct_queue_first(state, trans);
			break;
		case XS_RET_SHA:
			if (ex_priv->doextract == 0 ||
			    ex_priv->fl_ex_node->fn_skip_file != 0) {
				if (ctfile_parse_seek(&ex_priv->xdr_ctx)) {
					ct_fatal(state, "Can't seek past shas",
					    ex_priv->xdr_ctx.xs_errno);
					goto dying;
				}
				ct_trans_free(state, trans);
				continue;
			}

			/* use saved fnode */
			trans->tr_fl_node = ex_priv->fl_ex_node;

			if (memcmp(zerosha, ex_priv->xdr_ctx.xs_sha,
				SHA_DIGEST_LENGTH) == 0) {
				CWARNX("\"%s\" truncated during backup",
				    trans->tr_fl_node->fn_fullname);
				if (ctfile_parse_seek(&ex_priv->xdr_ctx)) {
					ct_fatal(state, "Can't seek past "
					    "truncation shas",
					    ex_priv->xdr_ctx.xs_errno);
					goto dying;
				}
				ct_trans_free(state, trans);
				continue;
			}

			if (ex_priv->xdr_ctx.xs_gh.cmg_flags & CT_MD_CRYPTO) {
				/*
				 * yes csha and sha are reversed, we want
				 * to download csha, but putting it in sha
				 * simplifies the code
				 */
				bcopy(ex_priv->xdr_ctx.xs_sha, trans->tr_csha,
				    sizeof(trans->tr_csha));
				bcopy(ex_priv->xdr_ctx.xs_csha, trans->tr_sha,
				    sizeof(trans->tr_sha));
				bcopy(ex_priv->xdr_ctx.xs_iv, trans->tr_iv,
				    sizeof(trans->tr_iv));
			} else {
				bcopy(ex_priv->xdr_ctx.xs_sha, trans->tr_sha,
				    sizeof(trans->tr_sha));
			}
			if (clog_mask_is_set(CT_LOG_SHA)) {
				ct_sha1_encode(trans->tr_sha, shat);
				CNDBG(CT_LOG_SHA, "extracting sha %s", shat);
			}
			trans->tr_state = TR_S_EX_SHA;
			trans->tr_complete = ct_extract_complete_file_read;
			trans->tr_dataslot = 0;
			ct_ref_fnode(trans->tr_fl_node);
			trans->tr_cleanup = ct_extract_cleanup_fnode;
			ct_queue_first(state, trans);
			break;
		case XS_RET_FILE_END:
			trans = ct_trans_realloc_local(state, trans);


			if (ex_priv->doextract == 0 ||
			    ex_priv->fl_ex_node->fn_skip_file != 0) {
				/* release our reference done with file */
				if (ex_priv->fl_ex_node) {
					ct_free_fnode(ex_priv->fl_ex_node);
					ex_priv->fl_ex_node = NULL;
				}
				ct_trans_free(state, trans);
				continue;
			}

			/* use saved fnode from state */
			trans->tr_fl_node = ex_priv->fl_ex_node;
			bcopy(ex_priv->xdr_ctx.xs_trl.cmt_sha, trans->tr_sha,
			    sizeof(trans->tr_sha));
			trans->tr_state = TR_S_EX_FILE_END;
			trans->tr_complete = ct_extract_complete_file_end;
			trans->tr_cleanup = ct_extract_cleanup_fnode;
			trans->tr_fl_node->fn_size =
			    ex_priv->xdr_ctx.xs_trl.cmt_orig_size;
			/*
			 * no reference here since we give our reference to the
			 * last transaction on that file. We are done with it.
			 */
			ex_priv->fl_ex_node = NULL;
			ct_queue_first(state, trans);
			break;
		case XS_RET_EOF:
			CNDBG(CT_LOG_CTFILE, "Hit end of ctfile");
			ctfile_parse_close(&ex_priv->xdr_ctx);
			/* if rb tree and rb is empty, goto end state */
			if ((ex_priv->haverb || ex_priv->fillrb) &&
			    ct_extract_rb_empty(&ex_priv->pending_tree)) {
				/*
				 * Cleanup extract queue, in case we had files
				 * left.
				 */
				ct_extract_cleanup_queue(
				    &ex_priv->extract_head);
				goto we_re_done_here;
			}


			if (!TAILQ_EMPTY(&ex_priv->extract_head)) {
				/*
				 * if allfiles and this was the first pass.
				 * free the current match lists
				 * switch to rb tree mode
				 */
				if (ex_priv->fillrb) {
					ct_match_unwind(ex_priv->inc_match);
					if (ex_priv->ex_match)
						ct_match_unwind(
						    ex_priv->ex_match);
					ex_priv->ex_match = NULL;
					ex_priv->inc_match = NULL;
					ex_priv->haverb = 1;
					ex_priv->fillrb = 0;
				}
				ct_trans_free(state, trans);
				/* reinits ex_priv->xdr_ctx */
				if ((ret =
				    ct_extract_open_next(&ex_priv->extract_head,
				    &ex_priv->xdr_ctx)) != 0) {
					ct_fatal(state,
					    "Can't open next ctfile", ret);
					goto dying;
				}
				state->ct_print_ctfile_info(
				    state->ct_print_state,
				    ex_priv->xdr_ctx.xs_filename,
				    &ex_priv->xdr_ctx.xs_gh);

				/* poke file into action */
				ct_wakeup_file(state->event_state);
			} else {
				/*
				 * If rb tree and it is still has entries,
				 * bitch about it
				 */
				/* XXX print out missing files */
				if ((ex_priv->haverb || ex_priv->fillrb) &&
				    ct_extract_rb_empty(
				    &ex_priv->pending_tree)) {
					CWARNX("out of ctfiles but some "
					    "files are not found");
				}

we_re_done_here:
				if (ex_priv->inc_match)
					ct_match_unwind(ex_priv->inc_match);
				if (ex_priv->ex_match)
					ct_match_unwind(
					    ex_priv->ex_match);
				ct_extract_pending_cleanup(
				    &ex_priv->pending_tree);
				e_free(&ex_priv);
				op->op_priv = NULL;
				trans->tr_state = TR_S_DONE;
				trans->tr_complete = ct_extract_complete_done;
				trans->tr_cleanup = ct_extract_cleanup_done;
				/*
				 * Technically this should be a local
				 * transaction. However, since we are done
				 * it doesn't really matter either way.
				 */
				ct_queue_first(state, trans);
				CNDBG(CT_LOG_TRANS, "extract finished");
				ct_set_file_state(state, CT_S_FINISHED);
			}
			return;
			break;
		case XS_RET_FAIL:
			ct_fatal(state, "Failed to parse ctfile",
			    ex_priv->xdr_ctx.xs_errno);
			goto dying;
			break;
		}
	}

	return;

dying:
	/* only if we hadn't sent the final transaction yet */
	if (ex_priv != NULL) {
		ct_extract_cleanup_queue(&ex_priv->extract_head);
		if (ex_priv->inc_match)
			ct_match_unwind(ex_priv->inc_match);
		if (ex_priv->ex_match)
			ct_match_unwind(ex_priv->ex_match);
		if (!ct_extract_rb_empty(&ex_priv->pending_tree)) {
			ct_extract_pending_cleanup(&ex_priv->pending_tree);
		}
		if (ex_priv->fl_ex_node != NULL) {
			ct_free_fnode(ex_priv->fl_ex_node);
		}
		/* XXX what about ex_priv->xdr_ctx ? */
		e_free(&ex_priv);
		op->op_priv = NULL;
		/* if ex_priv is gone then the trans will clean this up */
		if (state->extract_state)
			ct_file_extract_cleanup(state->extract_state);	
	}
	return;
}
예제 #21
0
파일: ct_match.c 프로젝트: finid/cyphertite
int
main(int argc, char *argv[])
{
	struct ct_match		*ctm = NULL;
	uint32_t		cflags;
	int			c, imode;
	char			*mode = NULL, *match = NULL;

	clog_init(1);
	cflags = CLOG_F_ENABLE | CLOG_F_STDERR;
	cflags |= CLOG_F_DBGENABLE | CLOG_F_FILE | CLOG_F_FUNC | CLOG_F_LINE |
	    CLOG_F_DTIME;
	if (clog_set_flags(cflags))
		errx(1, "illegal clog flags");
	CINFO("start");

	while ((c = getopt(argc, argv, "m:M:")) != -1) {
		switch (c) {
		case 'm':
			mode = optarg;
			break;
		case 'M':
			match = optarg;
			break;
		default:
			CFATALX("invalid option");
		}
	}
	argc -= optind;
	argv += optind;

	if (mode) {
		if (!strcmp(mode, "regex"))
			imode = CT_MATCH_REGEX;
		else if (!strcmp(mode, "rb"))
			imode = CT_MATCH_RB;
		else if (!strcmp(mode, "glob"))
			imode = CT_MATCH_GLOB;
		else
			CFATALX("invalid mode %s", mode);
	} else
		CFATALX("no mode");

	if (match == NULL)
		CFATALX("no match");

	CDBG("mode: %s", mode);

	ct_match_compile(&ctm, imode, argv);

	if (ct_match(ctm, match))
		printf("%s not matched\n", match);
	else
		printf("%s matched\n", match);

	ct_match_unwind(ctm);

	e_check_memory();

	return (0);
}
예제 #22
0
 DLIST_FOREACH(item, b)
 {
   CINFO(*item);
   NKIT_TEST_ASSERT(false);
 }
/**
 * PANTECH_CAMERA_TODO
 * Reads configuration file and translates these to command array then return
 * to caller. (Caller should release this array after use.)
 */
si2c_cmd_t *ptune_parse(const char *pname, const char *fbuf)
{
	si2c_cmd_t *cmds = NULL;
	uint32_t nol = 0;	// # of valid lines
	uint32_t noc = 0;	// # of commands (nol == noc)
	char *p = NULL;

	CINFO("%s E pname=%s\n", __func__, pname ? : "null");

	if (!pname || !fbuf) {
		CERR("%s pname/fbuf=null\n", __func__);
		return NULL;
	}

	ptune_bop = NULL;
	ptune_eop = NULL;

	ptune_bop = ptune_get_bop(fbuf, pname);
	if (!ptune_bop)
		goto load_fail;

	ptune_eop = ptune_get_eop(fbuf, pname);
	if (!ptune_eop)
		goto load_fail;

	if (ptune_bop >= ptune_eop) {
		CERR("%s invalid BOP/EOP\n", __func__);
		goto load_fail;
	}

	/* Counts # of lines (=commands). */
	nol = ptune_count_nol();
	if (nol == 0)
		goto load_fail;

	/* Allocates command array and return to caller. So caller SHOULD
	 * release this after use. */
	cmds = (si2c_cmd_t *)kmalloc(sizeof(si2c_cmd_t) * nol, GFP_KERNEL);
	if (!cmds) {
		CERR("%s no mem\n", __func__);
		goto load_fail;
	}

	/* Parses line by line (only valid lines), and completes command 
	 * array. */
	p = ptune_bop;
	for (;;) {
		p = ptune_get_nl(p);
		if (!p)
			goto load_fail;
		if (p == ptune_eop) {
			CDBG("%s EOP\n", __func__);
			break;
		}
		if (ptune_parse_cmd(p, &cmds[noc]) < 0)
			goto load_fail;

		noc += 1;
	}

	/* # of lines should be same with # of commands. We think specified 
	 * parameter is eventually not valid even if there're just one invalid
	 * line (=invalid command). */
	if (nol != noc) {
		CERR("%s nol != noc\n", __func__);
		goto load_fail;
	}

	/* Last entry should be SI2C_EOC (end of commands). */
	if (cmds[noc-1].id != SI2C_EOC) {
		CERR("%s no EOC\n", __func__);
		goto load_fail;
	}

	CINFO("%s X found %d commands\n", __func__, noc);
	return cmds;

load_fail:

	if (cmds)
		kfree(cmds);

	CERR("%s failed\n", __func__);
	return NULL;
}
예제 #24
0
int si2c_write_cmds(uint16_t sa, si2c_cmd_t *cmds)
{
	int rc = 0;

	CINFO("%s E\n", __func__);

	if (!cmds) {
		CERR("%s err(-EINVAL)\n", __func__);
		return -EINVAL;
	}

	while (cmds->id != SI2C_EOC) {
		//CDBG("%s id=%d\n", __func__, cmds->id);

		switch (cmds->id) {
		case SI2C_NOP:
			break;
		case SI2C_WR:
			rc = si2c_proc_cmd(SI2C_WR, sa, cmds);
			break;
		case SI2C_BWR:
			rc = si2c_proc_cmd(SI2C_BWR, sa, cmds);
			break;
		case SI2C_RD:
			rc = si2c_proc_cmd(SI2C_RD, sa, cmds);
			break;
		case SI2C_DELAY:
			rc = si2c_proc_cmd(SI2C_DELAY, sa, cmds);
			break;
		case SI2C_POLL:
			rc = si2c_proc_cmd(SI2C_POLL, sa, cmds);
			break;
		case SI2C_POLLN:
			rc = si2c_proc_cmd(SI2C_POLLN, sa, cmds);
			break;
		case SI2C_POLL_B1AND:
			rc = si2c_proc_cmd(SI2C_POLL_B1AND, sa, cmds);
			break;
		case SI2C_POLL_B1OR:
			rc = si2c_proc_cmd(SI2C_POLL_B1OR, sa, cmds);
			break;
		case SI2C_POLL_B0AND:
			rc = si2c_proc_cmd(SI2C_POLL_B0AND, sa, cmds);
			break;
		case SI2C_POLL_B0OR:
			rc = si2c_proc_cmd(SI2C_POLL_B0OR, sa, cmds);
			break;
		case SI2C_POLLV:
			rc = si2c_proc_cmd(SI2C_POLLV, sa, cmds);
			break;
		default:
			CERR("%s err(-EINVAL)\n", __func__);
			rc = -EINVAL;
			break;
		}

		if (rc < 0)
			return rc;

		if (cmds->id == SI2C_POLLV)
			cmds += 2;
		else
			cmds += 1;
	}

	CINFO("%s X\n", __func__);
	return 0;
}
예제 #25
0
int gt_clustered_set_union_find_merge_clusters(GtClusteredSet *cs,
                                               GtUword e1,
                                               GtUword e2,
                                               GtError *err)
{
  gt_assert(cs);
  int had_err = 0;
  GtClusteredSetUFClusterInfo *cluster_info_c1 = NULL;
  GtClusteredSetUFClusterInfo *cluster_info_c2 = NULL;
  GtUword target = 0, source = 0, c1 = 0, c2 = 0;
  GtClusteredSetUF *cs_uf = (GtClusteredSetUF*) cs;
  if (e1 == e2) {
    gt_error_set(err, "expected "GT_WU" to be unequal "GT_WU"", e1, e2 );
    had_err = -1;
  }

  if (e1 >= cs_uf->num_of_elems || e2 >= cs_uf->num_of_elems) {
    gt_error_set(err, ""GT_WU" and "GT_WU" must not be larger than "GT_WU"",
                 e1, e2, cs_uf->num_of_elems);
    had_err = -1;
  }

  if (!had_err) {
    if (SINGLETON(e1)) {
       /* printf(""GT_WU" is singleton\n", e1); */
      if (SINGLETON(e2)) {
        /* printf(""GT_WU" is singleton\n", e2);*/
        gt_clustered_set_union_find_make_new_cluster(cs_uf, e1, e2, err);
        gt_bittab_set_bit(cs_uf->in_cluster, e2);
      }
      else {
        c2 = cs_uf->cluster_elems[e2].cluster_num;
        CHECKCLUSTER(c2);
        gt_clustered_set_union_find_append_elem(cs_uf, c2, e1, err);
      }
      gt_bittab_set_bit(cs_uf->in_cluster, e1);
    }
    else {
      c1 = cs_uf->cluster_elems[e1].cluster_num;
      CHECKCLUSTER(c1);
      if (SINGLETON(e2)) {
        gt_clustered_set_union_find_append_elem(cs_uf, c1, e2, err);
        gt_bittab_set_bit(cs_uf->in_cluster, e2);
      }
      else {
        c2 = cs_uf->cluster_elems[e2].cluster_num;
        CHECKCLUSTER(c2);
        cluster_info_c1 = CINFO(c1);
        cluster_info_c2 = CINFO(c2);
        if (cluster_info_c1->cluster_size > cluster_info_c2->cluster_size) {
          target = c1;
          source = c2;
        }
        else {
          target = c1;
          source = c2;
        }
        if (target != source)
          gt_clustered_set_union_find_join_clusters(cs_uf, target, source, err);
      }
    }
  }
  return had_err;
}