Пример #1
0
void playerinit(Player *p, int x, int y)
{
	p->lives = 3;

	bodyinit(&p->body, x * Twidth + hboff.x, y * Theight + hboff.y, 21, 29);
	p->hitback = 0;

	armorinit();

	ow = resrcacq(sfx, "sfx/ow.wav", NULL);
	assert(ow != NULL);

	for(int i = 0; i < ArmorMax; i++){
		loadanim(&p->as[Left][Stand][i], 0, 1, 1, i);
		loadanim(&p->as[Left][Walk][i], 1, 4, 100, i);
		loadanim(&p->as[Left][Jump][i], 2, 1, 1, i);
		loadanim(&p->as[Right][Stand][i], 3, 1, 1, i);
		loadanim(&p->as[Right][Walk][i], 4, 4, 100, i);
		loadanim(&p->as[Right][Jump][i], 5, 1, 1, i);
	}

	p->dir = Right;
	p->act = Stand;
	p->imgloc = (Point){ x * Twidth, y * Theight };

	p->bi.x = p->bi.y = p->bi.z = -1;
	p->stats[StatHp] = 10;
	p->stats[StatDex] = 5;
	p->stats[StatStr] = 5;
	p->stats[StatMag] = 5;
	p->stats[StatGuts] = 5;
	p->stats[StatLuck] = 5;

	p->sw.row = 0;
	p->sw.dir = Mvright;
	p->sw.cur = -1;
	invitinit(&p->wear[EqpWep], ItemSilverSwd);
	invitinit(&p->wear[EqpHead], ItemIronHelm);
	invitinit(&p->wear[EqpBody], ItemIronBody);
	invitinit(&p->wear[EqpArms], ItemIronGlove);
	invitinit(&p->wear[EqpLegs], ItemIronBoot);
	resetstats(p);
	p->curhp = p->stats[StatHp] + p->eqp[StatHp];
	mvsw(p);
}
Пример #2
0
static void
runtests(struct alg *alg, int count, int size, u_long cmd, int threads, int profile)
{
    int i, status;
    double t;
    void *region;
    struct timeval *tvp;
    struct timeval total;
    int otiming;

    if (size % alg->blocksize) {
        if (verbose)
            printf("skipping blocksize %u 'cuz not a multiple of "
                   "%s blocksize %u\n",
                   size, alg->name, alg->blocksize);
        return;
    }

    region = mmap(NULL, threads * sizeof (struct timeval),
                  PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
    if (region == MAP_FAILED) {
        perror("mmap");
        return;
    }
    tvp = (struct timeval *) region;
#ifdef __FreeBSD__
    if (profile) {
        size_t tlen = sizeof (otiming);
        int timing = 1;

        resetstats();
        if (sysctlbyname("debug.crypto_timing", &otiming, &tlen,
                         &timing, sizeof (timing)) < 0)
            perror("debug.crypto_timing");
    }
#endif

    if (threads > 1) {
        for (i = 0; i < threads; i++)
            if (fork() == 0) {
                runtest(alg, count, size, cmd, &tvp[i]);
                exit(0);
            }
        while (waitpid(WAIT_MYPGRP, &status, 0) != -1)
            ;
    } else
        runtest(alg, count, size, cmd, tvp);

    t = 0;
    for (i = 0; i < threads; i++)
        t += (((double)tvp[i].tv_sec * 1000000 + tvp[i].tv_usec) / 1000000);
    if (t) {
        int nops = alg->ishash ? count : 2*count;

#if 0
        t /= threads;
        printf("%6.3lf sec, %7d %6s crypts, %7d bytes, %8.0lf byte/sec, %7.1lf Mb/sec\n",
               t, nops, alg->name, size, (double)nops*size / t,
               (double)nops*size / t * 8 / 1024 / 1024);
#else
        nops *= threads;
        printf("%8.3lf sec, %7d %6s crypts, %7d bytes, %8.0lf byte/sec, %7.1lf Mb/sec\n",
               t, nops, alg->name, size, (double)nops*size / t,
               (double)nops*size / t * 8 / 1024 / 1024);
#endif
    }
#ifdef __FreeBSD__
    if (profile) {
        struct cryptostats stats;
        size_t slen = sizeof (stats);

        if (sysctlbyname("debug.crypto_timing", NULL, NULL,
                         &otiming, sizeof (otiming)) < 0)
            perror("debug.crypto_timing");
        if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, 0) < 0)
            perror("kern.cryptostats");
        if (stats.cs_invoke.count) {
            printt("dispatch->invoke", &stats.cs_invoke);
            printt("invoke->done", &stats.cs_done);
            printt("done->cb", &stats.cs_cb);
            printt("cb->finis", &stats.cs_finis);
        }
    }
#endif
    fflush(stdout);
}
Пример #3
0
event * iodriver_request (int iodriverno, ioreq_event *curr)
{
   ioreq_event *temp = NULL;
   ioreq_event *ret = NULL;
   ioreq_event *retlist = NULL;
   int numreqs;
/*
   printf ("Entered iodriver_request - simtime %f, devno %d, blkno %lld, cause %d\n", simtime, curr->devno, curr->blkno, curr->cause);
   fprintf (outputfile, "Entered iodriver_request - simtime %f, devno %d, blkno %lld, cause %d\n", simtime, curr->devno, curr->blkno, curr->cause);
   fprintf (stderr, "Entered iodriver_request - simtime %f, devno %d, blkno %lld, cause %d\n", simtime, curr->devno, curr->blkno, curr->cause);
*/
   if (NULL != OUTIOS) {
      fprintf(OUTIOS, "%.6f,%d,%lld,%d,%x,%d,%p\n", simtime, curr->devno, curr->blkno, curr->bcount, curr->flags, OVERALLQUEUE->base.listlen + 1, curr );
      fflush( OUTIOS );
   }

#if 0
   fprintf (stderr, "Entered iodriver_request - simtime %f, devno %d, blkno %lld, cause %d\n", simtime, curr->devno, curr->blkno, curr->cause);
#endif

   /* add to the overall queue to start tracking */
   ret = ioreq_copy (curr);
   ioqueue_add_new_request (OVERALLQUEUE, ret);
   ret = NULL;
 
   disksim->totalreqs++;
   if ((disksim->checkpoint_iocnt > 0) && ((disksim->totalreqs % disksim->checkpoint_iocnt) == 0)) {
      disksim_register_checkpoint (simtime);
   }
   if (disksim->totalreqs == disksim->warmup_iocnt) {
      warmuptime = simtime;
      resetstats();
   }
   numreqs = logorg_maprequest(sysorgs, numsysorgs, curr);
   temp = curr->next;
   for (; numreqs>0; numreqs--) {
          /* Request list size must match numreqs */
      ASSERT(curr != NULL);
      curr->next = NULL;
      if ((iodrivers[iodriverno]->consttime == IODRIVER_TRACED_QUEUE_TIMES) || (iodrivers[iodriverno]->consttime == IODRIVER_TRACED_BOTH_TIMES)) {
         ret = ioreq_copy(curr);
         ret->time = simtime + (double) ret->tempint1 / (double) 1000;
         ret->type = IO_TRACE_REQUEST_START;
         addtointq((event *) ret);
         ret = NULL;
         if ((curr->slotno == 1) && (ioqueue_get_number_in_queue(iodrivers[iodriverno]->devices[(curr->devno)].queue) == 0)) {
            iodrivers[(iodriverno)]->devices[(curr->devno)].flag = 2;
            iodrivers[(iodriverno)]->devices[(curr->devno)].lastevent = simtime;
         }
      }
      ret = handle_new_request(iodrivers[iodriverno], curr);

      if ((ret) && (iodrivers[iodriverno]->type == STANDALONE) && (ret->time == 0.0)) {
         ret->type = IO_ACCESS_ARRIVE;
         ret->time = simtime;
         iodriver_schedule(iodriverno, ret);
      } else if (ret) {
         ret->type = IO_ACCESS_ARRIVE;
         ret->next = retlist;
         ret->prev = NULL;
         retlist = ret;
      }
      curr = temp;
      temp = (temp) ? temp->next : NULL;
   }
   if (iodrivers[iodriverno]->type == STANDALONE) {
      while (retlist) {
         ret = retlist;
         retlist = ret->next;
         ret->next = NULL;
         ret->time += simtime;
         addtointq((event *) ret);
      }
   }
/*
fprintf (outputfile, "leaving iodriver_request: retlist %p\n", retlist);
*/
   return((event *) retlist);
}
Пример #4
0
/* ioctl routine */
int
vinumioctl(dev_t dev,
    u_long cmd,
    caddr_t data,
    int flag,
    struct thread *td)
{
    unsigned int objno;
    int error = 0;
    struct sd *sd;
    struct plex *plex;
    struct volume *vol;
    unsigned int index;					    /* for transferring config info */
    unsigned int sdno;					    /* for transferring config info */
    int fe;						    /* free list element number */
    struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* struct to return */

    /* First, decide what we're looking at */
    switch (DEVTYPE(dev)) {
    case VINUM_SUPERDEV_TYPE:				    /* ordinary super device */
	ioctl_reply = (struct _ioctl_reply *) data;	    /* save the address to reply to */
	switch (cmd) {
#ifdef VINUMDEBUG
	case VINUM_DEBUG:
	    if (((struct debuginfo *) data)->changeit)	    /* change debug settings */
		debug = (((struct debuginfo *) data)->param);
	    else {
		if (debug & DEBUG_REMOTEGDB)
		    boothowto |= RB_GDB;		    /* serial debug line */
		else
		    boothowto &= ~RB_GDB;		    /* local ddb */
		Debugger("vinum debug");
	    }
	    ioctl_reply = (struct _ioctl_reply *) data;	    /* reinstate the address to reply to */
	    ioctl_reply->error = 0;
	    return 0;
#endif

	case VINUM_CREATE:				    /* create a vinum object */
	    error = lock_config();			    /* get the config for us alone */
	    if (error)					    /* can't do it, */
		return error;				    /* give up */
	    error = setjmp(command_fail);		    /* come back here on error */
	    if (error == 0)				    /* first time, */
		ioctl_reply->error = parse_user_config((char *) data, /* update the config */
		    &keyword_set);
	    else if (ioctl_reply->error == 0) {		    /* longjmp, but no error status */
		ioctl_reply->error = EINVAL;		    /* note that something's up */
		ioctl_reply->msg[0] = '\0';		    /* no message? */
	    }
	    unlock_config();
	    return 0;					    /* must be 0 to return the real error info */

	case VINUM_GETCONFIG:				    /* get the configuration information */
	    bcopy(&vinum_conf, data, sizeof(vinum_conf));
	    return 0;

	    /* start configuring the subsystem */
	case VINUM_STARTCONFIG:
	    return start_config(*(int *) data);		    /* just lock it.  Parameter is 'force' */

	    /*
	     * Move the individual parts of the config to user space.
	     *
	     * Specify the index of the object in the first word of data,
	     * and return the object there
	     */
	case VINUM_DRIVECONFIG:
	    index = *(int *) data;			    /* get the index */
	    if (index >= (unsigned) vinum_conf.drives_allocated) /* can't do it */
		return ENXIO;				    /* bang */
	    bcopy(&DRIVE[index], data, sizeof(struct _drive)); /* copy the config item out */
	    return 0;

	case VINUM_SDCONFIG:
	    index = *(int *) data;			    /* get the index */
	    if (index >= (unsigned) vinum_conf.subdisks_allocated) /* can't do it */
		return ENXIO;				    /* bang */
	    bcopy(&SD[index], data, sizeof(struct _sd));    /* copy the config item out */
	    return 0;

	case VINUM_PLEXCONFIG:
	    index = *(int *) data;			    /* get the index */
	    if (index >= (unsigned) vinum_conf.plexes_allocated) /* can't do it */
		return ENXIO;				    /* bang */
	    bcopy(&PLEX[index], data, sizeof(struct _plex)); /* copy the config item out */
	    return 0;

	case VINUM_VOLCONFIG:
	    index = *(int *) data;			    /* get the index */
	    if (index >= (unsigned) vinum_conf.volumes_allocated) /* can't do it */
		return ENXIO;				    /* bang */
	    bcopy(&VOL[index], data, sizeof(struct _volume)); /* copy the config item out */
	    return 0;

	case VINUM_PLEXSDCONFIG:
	    index = *(int *) data;			    /* get the plex index */
	    sdno = ((int *) data)[1];			    /* and the sd index */
	    if ((index >= (unsigned) vinum_conf.plexes_allocated) /* plex doesn't exist */
	    ||(sdno >= PLEX[index].subdisks))		    /* or it doesn't have this many subdisks */
		return ENXIO;				    /* bang */
	    bcopy(&SD[PLEX[index].sdnos[sdno]],		    /* copy the config item out */
		data,
		sizeof(struct _sd));
	    return 0;

	    /*
	     * We get called in two places: one from the
	     * userland config routines, which call us
	     * to complete the config and save it.  This
	     * call supplies the value 0 as a parameter.
	     *
	     * The other place is from the user "saveconfig"
	     * routine, which can only work if we're *not*
	     * configuring.  In this case, supply parameter 1.
	     */
	case VINUM_SAVECONFIG:
	    if (VFLAGS & VF_CONFIGURING) {		    /* must be us, the others are asleep */
		if (*(int *) data == 0)			    /* finish config */
		    finish_config(1);			    /* finish the configuration and update it */
		else
		    return EBUSY;			    /* can't do it now */
	    }
	    save_config();				    /* save configuration to disk */
	    return 0;

	case VINUM_RELEASECONFIG:			    /* release the config */
	    if (VFLAGS & VF_CONFIGURING) {		    /* must be us, the others are asleep */
		finish_config(0);			    /* finish the configuration, don't change it */
		save_config();				    /* save configuration to disk */
	    } else
		error = EINVAL;				    /* release what config? */
	    return error;

	case VINUM_INIT:
	    ioctl_reply = (struct _ioctl_reply *) data;	    /* reinstate the address to reply to */
	    ioctl_reply->error = 0;
	    return 0;

	case VINUM_RESETCONFIG:
	    if (vinum_inactive(0)) {			    /* if the volumes are not active */
		/*
		 * Note the open count.  We may be called from v, so we'll be open.
		 * Keep the count so we don't underflow
		 */
		free_vinum(1);				    /* clean up everything */
		log(LOG_NOTICE, "vinum: CONFIGURATION OBLITERATED\n");
		ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */
		ioctl_reply->error = 0;
		return 0;
	    }
	    return EBUSY;

	case VINUM_SETSTATE:
	    setstate((struct vinum_ioctl_msg *) data);	    /* set an object state */
	    return 0;

	    /*
	     * Set state by force, without changing
	     * anything else.
	     */
	case VINUM_SETSTATE_FORCE:
	    setstate_by_force((struct vinum_ioctl_msg *) data);	/* set an object state */
	    return 0;

#ifdef VINUMDEBUG
	case VINUM_MEMINFO:
	    vinum_meminfo(data);
	    return 0;

	case VINUM_MALLOCINFO:
	    return vinum_mallocinfo(data);

	case VINUM_RQINFO:
	    return vinum_rqinfo(data);
#endif

	case VINUM_LABEL:				    /* label a volume */
	    ioctl_reply->error = write_volume_label(*(int *) data); /* index of the volume to label */
	    ioctl_reply->msg[0] = '\0';			    /* no message */
	    return 0;

	case VINUM_REMOVE:
	    remove((struct vinum_ioctl_msg *) data);	    /* remove an object */
	    return 0;

	case VINUM_GETFREELIST:				    /* get a drive free list element */
	    index = *(int *) data;			    /* get the drive index */
	    fe = ((int *) data)[1];			    /* and the free list element */
	    if ((index >= (unsigned) vinum_conf.drives_allocated) /* plex doesn't exist */
	    ||(DRIVE[index].state == drive_unallocated))
		return ENODEV;
	    if (fe >= DRIVE[index].freelist_entries)	    /* no such entry */
		return ENOENT;
	    bcopy(&DRIVE[index].freelist[fe],
		data,
		sizeof(struct drive_freelist));
	    return 0;

	case VINUM_RESETSTATS:
	    resetstats((struct vinum_ioctl_msg *) data);    /* reset object stats */
	    return 0;

	    /* attach an object to a superordinate object */
	case VINUM_ATTACH:
	    attachobject((struct vinum_ioctl_msg *) data);
	    return 0;

	    /* detach an object from a superordinate object */
	case VINUM_DETACH:
	    detachobject((struct vinum_ioctl_msg *) data);
	    return 0;

	    /* rename an object */
	case VINUM_RENAME:
	    renameobject((struct vinum_rename_msg *) data);
	    return 0;

	    /* replace an object */
	case VINUM_REPLACE:
	    replaceobject((struct vinum_ioctl_msg *) data);
	    return 0;

	case VINUM_DAEMON:
	    vinum_daemon();				    /* perform the daemon */
	    return 0;

	case VINUM_FINDDAEMON:				    /* check for presence of daemon */
	    return vinum_finddaemon();
	    return 0;

	case VINUM_SETDAEMON:				    /* set daemon flags */
	    return vinum_setdaemonopts(*(int *) data);

	case VINUM_GETDAEMON:				    /* get daemon flags */
	    *(int *) data = daemon_options;
	    return 0;

	case VINUM_PARITYOP:				    /* check/rebuild RAID-4/5 parity */
	    parityops((struct vinum_ioctl_msg *) data);
	    return 0;

	    /* move an object */
	case VINUM_MOVE:
	    moveobject((struct vinum_ioctl_msg *) data);
	    return 0;

	default:
	    /* FALLTHROUGH */
	    break;
	}

    case VINUM_DRIVE_TYPE:
    default:
	log(LOG_WARNING,
	    "vinumioctl: invalid ioctl from process %d (%s): %lx\n",
	    curthread->td_proc->p_pid,
	    curthread->td_proc->p_comm,
	    cmd);
	return EINVAL;

    case VINUM_SD_TYPE:
    case VINUM_RAWSD_TYPE:
	objno = Sdno(dev);

	sd = &SD[objno];

	switch (cmd) {
      case DIOCGDINFO:				    /* get disk label */
	    get_volume_label(sd->name, 1, sd->sectors, (struct disklabel *) data);
	    break;

	    /*
	     * We don't have this stuff on hardware,
	     * so just pretend to do it so that
	     * utilities don't get upset.
	     */
	case DIOCWDINFO:				    /* write partition info */
	case DIOCSDINFO:				    /* set partition info */
	    return 0;					    /* not a titty */

	default:
	    return ENOTTY;				    /* not my kind of ioctl */
	}

	return 0;					    /* pretend we did it */

    case VINUM_RAWPLEX_TYPE:
    case VINUM_PLEX_TYPE:
	objno = Plexno(dev);

	plex = &PLEX[objno];

	switch (cmd) {
	case DIOCGDINFO:				    /* get disk label */
	    get_volume_label(plex->name, 1, plex->length, (struct disklabel *) data);
	    break;

	    /*
	     * We don't have this stuff on hardware,
	     * so just pretend to do it so that
	     * utilities don't get upset.
	     */
	case DIOCWDINFO:				    /* write partition info */
	case DIOCSDINFO:				    /* set partition info */
	    return 0;					    /* not a titty */

	default:
	    return ENOTTY;				    /* not my kind of ioctl */
	}

	return 0;					    /* pretend we did it */

    case VINUM_VOLUME_TYPE:
	objno = Volno(dev);

	if ((unsigned) objno >= (unsigned) vinum_conf.volumes_allocated) /* not a valid volume */
	    return ENXIO;
	vol = &VOL[objno];
	if (vol->state != volume_up)			    /* not up, */
	    return EIO;					    /* I/O error */

	switch (cmd) {

	case DIOCGMEDIASIZE:
	    *(off_t *)data = vol->size << DEV_BSHIFT;
	    break;

	case DIOCGSECTORSIZE:
	    *(u_int *)data = DEV_BSIZE;
	    break;

	    /*
	     * We don't have this stuff on hardware,
	     * so just pretend to do it so that
	     * utilities don't get upset.
	     */
	case DIOCWDINFO:				    /* write partition info */
	case DIOCSDINFO:				    /* set partition info */
	    return 0;					    /* not a titty */

	case DIOCWLABEL:				    /* set or reset label writeable */
	    if ((flag & FWRITE) == 0)			    /* not writeable? */
		return EACCES;				    /* no, die */
	    if (*(int *) data != 0)			    /* set it? */
		vol->flags |= VF_WLABEL;		    /* yes */
	    else
		vol->flags &= ~VF_WLABEL;		    /* no, reset */
	    break;

	default:
	    return ENOTTY;				    /* not my kind of ioctl */
	}
	break;
    }
    return 0;						    /* XXX */
}
Пример #5
0
/* ioctl routine */
int
vinumioctl(struct dev_ioctl_args *ap)
{
    cdev_t dev = ap->a_head.a_dev;
    u_long cmd = ap->a_cmd;
    caddr_t data = ap->a_data;
    int error;
    unsigned int index;					    /* for transferring config info */
    unsigned int sdno;					    /* for transferring config info */
    unsigned int objno;
    struct volume *vol;
    struct partinfo *dpart;
    int fe;						    /* free list element number */
    struct _ioctl_reply *ioctl_reply;			    /* struct to return */

    error = 0;

    /* First, decide what we're looking at */
    switch (DEVTYPE(dev)) {
    case VINUM_SUPERDEV_TYPE:				    /* ordinary super device */
	ioctl_reply = (struct _ioctl_reply *) data;	    /* save the address to reply to */
	switch (cmd) {
#ifdef VINUMDEBUG
	case VINUM_DEBUG:
	    if (((struct debuginfo *) data)->changeit)	    /* change debug settings */
		debug = (((struct debuginfo *) data)->param);
	    else {
		if (debug & DEBUG_REMOTEGDB)
		    boothowto |= RB_GDB;		    /* serial debug line */
		else
		    boothowto &= ~RB_GDB;		    /* local ddb */
		Debugger("vinum debug");
	    }
	    ioctl_reply = (struct _ioctl_reply *) data;	    /* reinstate the address to reply to */
	    ioctl_reply->error = 0;
	    break;
#endif

	case VINUM_CREATE:				    /* create a vinum object */
	    error = lock_config();			    /* get the config for us alone */
	    if (error)					    /* can't do it, */
		break;
	    error = setjmp(command_fail);		    /* come back here on error */
	    if (error == 0)				    /* first time, */
		ioctl_reply->error = parse_user_config((char *) data, /* update the config */
		    &keyword_set);
	    else if (ioctl_reply->error == 0) {		    /* longjmp, but no error status */
		error = 0;
		ioctl_reply->error = EINVAL;		    /* note that something's up */
		ioctl_reply->msg[0] = '\0';		    /* no message? */
	    }
	    unlock_config();
	    break;

	case VINUM_GETCONFIG:				    /* get the configuration information */
	    bcopy(&vinum_conf, data, sizeof(vinum_conf));
	    break;

	    /* start configuring the subsystem */
	case VINUM_STARTCONFIG:
	    error = start_config(*(int *) data);	    /* just lock it.  Parameter is 'force' */
	    break;

	case VINUM_DRIVECONFIG:
	    /*
	     * Move the individual parts of the config to user space.
	     *
	     * Specify the index of the object in the first word of data,
	     * and return the object there
	     */
	    index = *(int *) data;
	    if (index >= (unsigned)vinum_conf.drives_allocated) {
		error = ENXIO;
	    } else {
		bcopy(&DRIVE[index], data, sizeof(struct drive));
	    }
	    break;

	case VINUM_SDCONFIG:
	    index = *(int *) data;
	    if (index >= (unsigned) vinum_conf.subdisks_allocated) {
		error = ENXIO;
	    } else {
		bcopy(&SD[index], data, sizeof(struct sd));
	    }
	    break;

	case VINUM_PLEXCONFIG:
	    index = *(int *) data;
	    if (index >= (unsigned) vinum_conf.plexes_allocated) {
		error = ENXIO;
	    } else {
		bcopy(&PLEX[index], data, sizeof(struct plex));
	    }
	    break;

	case VINUM_VOLCONFIG:
	    index = *(int *) data;
	    if (index >= (unsigned) vinum_conf.volumes_allocated) {
		error = ENXIO;
	    } else {
		bcopy(&VOL[index], data, sizeof(struct volume));
	    }
	    break;

	case VINUM_PLEXSDCONFIG:
	    index = ((int *)data)[0];			    /* get the plex index */
	    sdno = ((int *)data)[1];			    /* and the sd index */
	    if ((index >= (unsigned) vinum_conf.plexes_allocated)
		||(sdno >= PLEX[index].subdisks)) {
		error = ENXIO;
	    } else {
		bcopy(&SD[PLEX[index].sdnos[sdno]], data, sizeof(struct sd));
	    }
	    break;
	case VINUM_SAVECONFIG:
	    /*
	     * We get called in two places: one from the
	     * userland config routines, which call us
	     * to complete the config and save it.  This
	     * call supplies the value 0 as a parameter.
	     *
	     * The other place is from the user "saveconfig"
	     * routine, which can only work if we're *not*
	     * configuring.  In this case, supply parameter 1.
	     */
	    if (VFLAGS & VF_CONFIGURING) {		    /* must be us, the others are asleep */
		if (*(int *) data == 0)			    /* finish config */
		    finish_config(1);			    /* finish the configuration and update it */
		else
		    error = EBUSY;
	    }
	    if (error == 0)
		save_config();				    /* save configuration to disk */
	    break;

	case VINUM_RELEASECONFIG:			    /* release the config */
	    if (VFLAGS & VF_CONFIGURING) {		    /* must be us, the others are asleep */
		finish_config(0);			    /* finish the configuration, don't change it */
		save_config();				    /* save configuration to disk */
	    } else {
		error = EINVAL;				    /* release what config? */
	    }
	    break;

	case VINUM_INIT:
	    ioctl_reply = (struct _ioctl_reply *) data;	    /* reinstate the address to reply to */
	    ioctl_reply->error = 0;
	    break;

	case VINUM_RESETCONFIG:
	    if (vinum_inactive(0)) {			    /* if the volumes are not active */
		/*
		 * Note the open count.  We may be called from v, so we'll be open.
		 * Keep the count so we don't underflow
		 */
		free_vinum(1);				    /* clean up everything */
		log(LOG_NOTICE, "vinum: CONFIGURATION OBLITERATED\n");
		ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */
		ioctl_reply->error = 0;
	    } else {
		error = EBUSY;
	    }

	case VINUM_SETSTATE:
	    setstate((struct vinum_ioctl_msg *) data);	    /* set an object state */
	    break;

	    /*
	     * Set state by force, without changing
	     * anything else.
	     */
	case VINUM_SETSTATE_FORCE:
	    setstate_by_force((struct vinum_ioctl_msg *) data);	/* set an object state */
	    break;

#ifdef VINUMDEBUG
	case VINUM_MEMINFO:
	    vinum_meminfo(data);
	    break;

	case VINUM_MALLOCINFO:
	    error = vinum_mallocinfo(data);
	    break;

	case VINUM_RQINFO:
	    error = vinum_rqinfo(data);
	    break;
#endif

	case VINUM_REMOVE:
	    remove((struct vinum_ioctl_msg *) data);	    /* remove an object */
	    break;

	case VINUM_GETFREELIST:				    /* get a drive free list element */
	    index = *(int *) data;			    /* get the drive index */
	    fe = ((int *) data)[1];			    /* and the free list element */
	    if ((index >= (unsigned) vinum_conf.drives_allocated) /* plex doesn't exist */
		||(DRIVE[index].state == drive_unallocated)) {
		error = ENODEV;
	    } else if (fe >= DRIVE[index].freelist_entries) {
		error = ENOENT;
	    } else {
		bcopy(&DRIVE[index].freelist[fe], data,
		      sizeof(struct drive_freelist));
	    }
	    break;

	case VINUM_RESETSTATS:
	    resetstats((struct vinum_ioctl_msg *) data);    /* reset object stats */
	    break;

	    /* attach an object to a superordinate object */
	case VINUM_ATTACH:
	    attachobject((struct vinum_ioctl_msg *) data);
	    break;

	    /* detach an object from a superordinate object */
	case VINUM_DETACH:
	    detachobject((struct vinum_ioctl_msg *) data);
	    break;

	    /* rename an object */
	case VINUM_RENAME:
	    renameobject((struct vinum_rename_msg *) data);
	    break;

	    /* replace an object */
	case VINUM_REPLACE:
	    replaceobject((struct vinum_ioctl_msg *) data);
	    break;

	case VINUM_DAEMON:
	    vinum_daemon();				    /* perform the daemon */
	    break;

	case VINUM_FINDDAEMON:				    /* check for presence of daemon */
	    error = vinum_finddaemon();
	    break;

	case VINUM_SETDAEMON:				    /* set daemon flags */
	    error = vinum_setdaemonopts(*(int *) data);
	    break;

	case VINUM_GETDAEMON:				    /* get daemon flags */
	    *(int *) data = daemon_options;
	    break;

	case VINUM_PARITYOP:				    /* check/rebuild RAID-4/5 parity */
	    parityops((struct vinum_ioctl_msg *) data);
	    break;

	    /* move an object */
	case VINUM_MOVE:
	    moveobject((struct vinum_ioctl_msg *) data);
	    break;
	default:
	    error = EINVAL;
	    break;
	}
	break;
    case VINUM_LABEL:
    case VINUM_DRIVE_TYPE:
    case VINUM_SD_TYPE:
    case VINUM_RAWSD_TYPE:
    case VINUM_RAWPLEX_TYPE:
    case VINUM_PLEX_TYPE:
	error = EINVAL;
	break;
    case VINUM_VOLUME_TYPE:
	objno = Volno(dev);

	if ((unsigned)objno >= (unsigned)vinum_conf.volumes_allocated) {
	    error = ENXIO;
	    break;
	}
	vol = &VOL[objno];
	if (vol->state != volume_up) {
	    error = EIO;
	    break;
	}

	switch(cmd) {
	case DIOCGPART:
	    dpart = (void *)data;

	    bzero(dpart, sizeof(*dpart));
	    dpart->media_offset  = 0;
	    dpart->media_size    = (u_int64_t)vol->size * DEV_BSIZE;
	    dpart->media_blocks  = vol->size;
	    dpart->media_blksize = DEV_BSIZE;
	    dpart->fstype = FS_BSDFFS;
	    break;
	default:
	    error = EINVAL;
	}
	break;
    default:
	error = EINVAL;
	break;
    }
    if (error) {
	log(LOG_WARNING,
	    "vinumioctl: invalid ioctl from process %d (%s): %lx\n",
	    curproc->p_pid,
	    curproc->p_comm,
	    cmd);
    }
    return error;
}
Пример #6
0
bool LDPCVerify::verify(QByteArray &from,QByteArray &to)
{
    message.clear();

    if(!vars.N||!vars.M)
    {
        qDebug("Error: Parity Check Matrix is Empty");
        return false;
    }

    tmpvars.copyglobaltolocal();
    vars.copylocaltoglobal();

    ::table=table;

    // Print header for table.
    if (table)
    {
        printf("  block chkerrs srcerrs\n");
    }

    resetstats();

    sblk.resize(N-M);
    cblk.resize(N);
    chks.resize(M);

    // Verify successive blocks.

    int n;
    for (n = 0; ; n++)
    {

        sblk=from.mid(n*(N-M),N-M);
        cblk=to.mid(n*N,N);

        if((sblk.size()<(N-M))||(cblk.size()<N))break;

        // Check that received block is a code word, and if not find the number of
        // parity check errors.

        int chkerr = check(H,cblk.data(),chks.data());

        // Check against source block

        int srcerr = 0;

        for (int i = M; i<N; i++)
        {
            if (cblk[cols[i]]!=sblk[i-M])
            {
                srcerr += 1;
            }
        }

        bit_errs += srcerr;

        // Print table entry.

        if (table)
        {
            printf("%6d %7d %7d\n",n,chkerr,srcerr);
        }

        // Increment totals.

        if (chkerr) tot_chkerrs += 1;
        if (srcerr) tot_srcerrs += 1;
        if (srcerr && chkerr) tot_botherrs += 1;

    }

    ber=(double)bit_errs/(n*(N-M));

    message=(QString::asprintf("Block counts: tot %d, with chk errs %d, with src errs %d, both %d\n",n, tot_chkerrs, tot_srcerrs, tot_botherrs)+QString::asprintf("Bit error rate (on message bits only): %.3e",ber));

    qDebug("Block counts: tot %d, with chk errs %d, with src errs %d, both %d",n, tot_chkerrs, tot_srcerrs, tot_botherrs);
    qDebug("Bit error rate (on message bits only): %.3e",ber);

    tmpvars.copylocaltoglobal();

    if(table)fflush(stdout);

    return true;
}
Пример #7
0
LDPCVerify::LDPCVerify(LDPCCode &ldpccode, int _table)
{
    vars.clearglobal();
    resetstats();
    init(ldpccode, _table);
}
Пример #8
0
LDPCVerify::LDPCVerify()
{
    vars.clearglobal();
    resetstats();
}
Пример #9
0
LDPCVerify::LDPCVerify(QVector<int> &ParityCheckMatrix, QVector<int> &GeneratorMatrix, int _table)
{
    vars.clearglobal();
    resetstats();
    init(ParityCheckMatrix,GeneratorMatrix, _table);
}