static int vbr_write(struct exfat_dev* dev)
{
	struct exfat_super_block sb;
	uint32_t checksum;
	le32_t* sector = malloc(get_sector_size());
	size_t i;

	if (sector == NULL)
	{
		exfat_error("failed to allocate sector-sized block of memory");
		return 1;
	}

	init_sb(&sb);
	if (exfat_write(dev, &sb, sizeof(struct exfat_super_block)) < 0)
	{
		free(sector);
		exfat_error("failed to write super block sector");
		return 1;
	}
	checksum = exfat_vbr_start_checksum(&sb, sizeof(struct exfat_super_block));

	memset(sector, 0, get_sector_size());
	sector[get_sector_size() / sizeof(sector[0]) - 1] =
			cpu_to_le32(0xaa550000);
	for (i = 0; i < 8; i++)
	{
		if (exfat_write(dev, sector, get_sector_size()) < 0)
		{
			free(sector);
			exfat_error("failed to write a sector with boot signature");
			return 1;
		}
		checksum = exfat_vbr_add_checksum(sector, get_sector_size(), checksum);
	}

	memset(sector, 0, get_sector_size());
	for (i = 0; i < 2; i++)
	{
		if (exfat_write(dev, sector, get_sector_size()) < 0)
		{
			free(sector);
			exfat_error("failed to write an empty sector");
			return 1;
		}
		checksum = exfat_vbr_add_checksum(sector, get_sector_size(), checksum);
	}

	for (i = 0; i < get_sector_size() / sizeof(sector[0]); i++)
		sector[i] = cpu_to_le32(checksum);
	if (exfat_write(dev, sector, get_sector_size()) < 0)
	{
		free(sector);
		exfat_error("failed to write checksum sector");
		return 1;
	}

	free(sector);
	return 0;
}
Exemplo n.º 2
0
Arquivo: check.c Projeto: 0mp/freebsd
static
atf_error_t
init_sbs(const atf_fs_path_t *outfile, atf_process_stream_t *outsb,
         const atf_fs_path_t *errfile, atf_process_stream_t *errsb)
{
    atf_error_t err;

    err = init_sb(outfile, outsb);
    if (atf_is_error(err))
        goto out;

    err = init_sb(errfile, errsb);
    if (atf_is_error(err)) {
        atf_process_stream_fini(outsb);
        goto out;
    }

out:
    return err;
}
Exemplo n.º 3
0
/* Load on-disk super block, and call setup_sb() with it */
int load_sb(struct sb *sb)
{
	struct disksuper *super = &sb->super;
	int err;

	/* At least initialize sb, even if load is failed */
	init_sb(sb);

	err = devio(READ, sb_dev(sb), SB_LOC, super, SB_LEN);
	if (err)
		return err;
	if (memcmp(super->magic, TUX3_MAGIC, sizeof(super->magic)))
		return -EINVAL;

	__setup_sb(sb, super);

	return 0;
}
Exemplo n.º 4
0
/* Initialize and setup sb by on-disk super block */
void setup_sb(struct sb *sb, struct disksuper *super)
{
	init_sb(sb);
	__setup_sb(sb, super);
}
Exemplo n.º 5
0
void init(void)
  {
    int i;

    randomize();

    printf("-------------------------------------------\n");
    printf("Sound Mixing Library v1.21 by Ethan Brodsky\n");
    if (!detect_settings(&baseio, &irq, &dma, &dma16))
      {
        printf("ERROR:  Invalid or non-existant BLASTER environment variable!\n");
        exit(EXIT_FAILURE);
      }
    else
      {
        if (!init_sb(baseio, irq, dma, dma16))
          {
            printf("ERROR:  Error initializing sound card!\n");
            exit(EXIT_FAILURE);
          }
      }

    printf("BaseIO=%Xh     IRQ%u     DMA8=%u     DMA16=%u\n", baseio, irq, dma, dma16);

    printf("DSP version %.2f:  ", dspversion);
    if (sixteenbit)
      printf("16-bit, ");
    else
      printf("8-bit, ");
    if (autoinit)
      printf("Auto-initialized\n");
    else
      printf("Single-cycle\n");

    if (!init_xms())
      {
        printf("ERROR:  Can not initialize extended memory\n");
        printf("HIMEM.SYS must be installed\n");
        exit(EXIT_FAILURE);
      }
    else
      {
        printf("Extended memory successfully initialized\n");
        printf("Free XMS memory: %uk    ", getfreexms());
        if (!getfreexms())
          {
            printf("ERROR:  Insufficient free XMS\n");
            exit(EXIT_FAILURE);
          }
        else
          {
            printf("Loading sounds\n");
#ifdef SHAREDEMB
            init_sharing();
#endif
            open_sound_resource_file(resource_file);

            for (i=0; i < NUMSOUNDS; i++)
              load_sound(&(sound[i]), sound_key[i]);
            atexit(ourexitproc);

            close_sound_resource_file();
          }
      }
    init_mixing();
    printf("\n");
  }
Exemplo n.º 6
0
int alloc_bb (BB_struct * bp)
{
  char command[MAX_STRING_LEN];
  int i, sbnum;
  extern void srand48 (long);
  int errors = 0;
  Ctrl_str *cp;

  cp = bp->ctrl;                /** aargh! \todo straghten this out!  --  general*/
  /*THUINET 18/02/05 */
  int isol, ele_num, ele_1;
  int iphs, iphs_tot;

  /*FIN THUINET 18/02/05 */

   /************************************************/
  /* malloc an array of pointers to SB structures */
   /************************************************/
  fprintf (stderr, "Entering alloc_bb ...\n");
  fprintf (stderr, "mallocing an array of pointers to SB str...\n");
  if (!(bp->sb = (SB_struct * *)malloc (bp->ntsb * sizeof (SB_struct *)))) {
    fprintf (stderr, "ERROR: SB_struct pointer array malloc failed\n");
    return (1);
  }
  for (sbnum = 0; sbnum < bp->ntsb; sbnum++) {
    if (init_sb (bp, sbnum) != 0) {
      fprintf (stderr, "exiting due to init_sb failure");
      exit (2);
    }
  }
  /* create the mask and set to zero */
  fprintf (stderr, "callocing SB mask ...\n");
  if (!(bp->sb_mask = (int *) calloc (bp->ntsb, sizeof (int)))) {
    fprintf (stderr, "ERROR: SB_mask array  malloc failed\n");
    return (1);
  }

  /*and the supplementary pointer value structures */

  /*fraction solid */
  if (!(bp->c_fs_values = (Value_struct *) calloc (1, sizeof (Value_struct)))) {
    fprintf (stderr, "ERROR: c_fs pointer values malloc failed\n");
    return (1);
  } else {
    if (!(bp->c_fs_values->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) {
      fprintf (stderr, "ERROR: c_fs values malloc failed\n");
      return (1);
    }
    bp->c_fs_values->part_coef = 1;     /*correct conc. profile output if not C_LIQ */

    sprintf (bp->c_fs_values->id_string, "FS_");
  }

  /*schiel fraction solid */
  if (!(bp->sch_fs_values = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) {
    fprintf (stderr, "ERROR: sch_fs pointer values malloc failed\n");
    return (1);
  } else {
    if (!(bp->sch_fs_values->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) {
      fprintf (stderr, "ERROR: sch_fs values malloc failed\n");
      return (1);
    }
    sprintf (bp->sch_fs_values->id_string, "SCH_");
  }

  /*first solute (gas) */
  if (!(bp->c_sol_values = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) {
    fprintf (stderr, "ERROR: c_sol pointer values malloc failed\n");
    return (1);
  } else {
    if (!(bp->c_sol_values->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) {
      fprintf (stderr, "ERROR: c_sol values malloc failed\n");
      return (1);
    }
    sprintf (bp->c_sol_values->id_string, "G_");
    bp->c_sol_values->disp_max = cp->gas_disp_max;
  }

  /*second solute (alloy) */
  if (!(bp->c_sol_alloy_values = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) {
    fprintf (stderr, "ERROR: c_sol_alloy pointer values malloc failed\n");
    exit (1);
  } else {
    if (!(bp->c_sol_alloy_values->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) {
      fprintf (stderr, "ERROR: c_sol_alloy values malloc failed\n");
      return (1);
    }
    sprintf (bp->c_sol_alloy_values->id_string, "A_");
    bp->c_sol_alloy_values->disp_max = cp->alloy_disp_max;
  }

  /*and the supplementary int pointer arrays */

  /*grain number */
  if (!(bp->gr_array = (int **) calloc (bp->ntsb, sizeof (int *)))) {
    fprintf (stderr, "ERROR:  pointer values malloc failed\n");
    return (1);
  }

  /*finite element number */
  if (!(bp->c_elm_array = (int **) calloc (bp->ntsb, sizeof (int *)))) {
    fprintf (stderr, "ERROR:  pointer values malloc failed\n");
    return (1);
  }
  /* holder for closed block (int) */
  if (!(bp->intclosed = (int *) calloc (bp->ncsb, sizeof (int)))) {
    fprintf (stderr, "ERROR:  pointer values malloc failed\n");
    return (1);
  }
  /* holder for closed block (float) */
  if (!(bp->floatclosed = (CA_FLOAT *) calloc (bp->ncsb, sizeof (CA_FLOAT)))) {
    fprintf (stderr, "ERROR:  pointer values malloc failed\n");
    return (1);
  }

   /*******************************************/
  /* Init cubeptr structure for matrix copy  */
   /*******************************************/
  init_cube (bp);
  init_facecode (&(bp->cubeptr), bp->nc, bp->dim);

   /************************************************/
  /* Malloc temp CA_FLOAT and int arrays          */
   /************************************************/
  i = (bp->nc[0] + 2) * (bp->nc[1] + 2) * (bp->nc[2] + 2);
  fprintf (stderr, "%s: total, nx, ny, nz, %d, %d, %d, %d\n", __func__, i, bp->nc[0], bp->nc[1], bp->nc[2]);
/** \todo put temporary buffer arrays into the subblocks -- multiblock */
  if (!(bp->ftmp_one = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
    fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
    return (1);
  }

  if (!(bp->ftmp_two = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
    fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
    return (1);
  }

  if (!(bp->ftmp_three = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
    fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
    return (1);
  }

  /*by Wei WANG 11-07-02 */
  if (!(bp->ftmp_four = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
    fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
    return (1);
  }

  /*by Wei WANG 11-07-02 */
  if (!(bp->ftmp_five = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
    fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
    return (1);
  }

  /* modified to protect by options */
  /**todo: Fine tune the options so as to avoid unnecessary memory allcation */
  if ((bp->ctrl->curvature_3D !=0) || (bp->ctrl->curvature_2D != 0)){
     /*xly 2004/09/06 */
     if (!(bp->ftmp_nx = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
       fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
       return (1);
     }
     /*xly 2004/09/06 */
     if (!(bp->ftmp_ny = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
       fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
       return (1);
     }
      /*dn00 2005/10/21*/
      if (!(bp->ftmp_nz = (CA_FLOAT * ) calloc(i, sizeof(CA_FLOAT)))) {
         fprintf(stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
         return(1);
      }
   }
  /*by THUINET 18-02-05 */

  /* L Thuinet polycomponent data arrays */
  if (bp->ctrl->diffuse_alloy_poly == 1) {

    ele_num = cp->NUM_COMP;     /* number of elements in the alloy */
    ele_1 = ele_num - 1;
    iphs_tot = cp->NUM_PHS;     /* number of solid phases */

    if (!(bp->itmp_nat_cell = (int *) calloc (i, sizeof (int)))) {
      fprintf (stderr, "ERROR: tmp int array malloc failed\n");
      return (1);
    }

    if (!(bp->itmp_nat_grain = (int *) calloc (i, sizeof (int)))) {
      fprintf (stderr, "ERROR: tmp int array malloc failed\n");
      return (1);
    }

  } else {
    ele_num = 2;
    ele_1 = 1;
    iphs_tot = 1;               /* number of solid phases */
  }

  /* loop through solutes */
  for (isol = 0; isol < ele_1; isol++) {
    if (!(bp->ftmp_cl_poly[isol] = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
      fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
      return (1);
    }
    if (!(bp->ftmp_ce_poly[isol] = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
      fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
      return (1);
    }
    /* Value structures for polycomponent */
    if (!(bp->poly_c_eqv_values[isol] = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) {
      fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__);
      return (1);
    } else {
      if (!(bp->poly_c_eqv_values[isol]->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) {
        fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__);
        return (1);
      }
      sprintf (bp->poly_c_eqv_values[isol]->id_string, "A_%i", isol);
      bp->poly_c_eqv_values[isol]->disp_max = cp->alloy_disp_max;
    }
    if (!(bp->poly_c_sol_values[isol] = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) {
      fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__);
      return (1);
    } else {
      if (!(bp->poly_c_sol_values[isol]->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) {
        fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__);
        return (1);
      }
      sprintf (bp->poly_c_sol_values[isol]->id_string, "A_%i", isol);
      bp->poly_c_sol_values[isol]->disp_max = cp->alloy_disp_max;
    }

  }                             /* end of isol loop through solutes */

  /* loop through phases */
  for (iphs = 0; iphs < iphs_tot; iphs++) {
    if (!(bp->ftmp_one_poly[iphs] = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
      fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
      return (1);
    }
    /* Value structures for polycomponent phases */
    if (!(bp->poly_c_fs_values[iphs] = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) {
      fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__);
      return (1);
    } else {
      if (!(bp->poly_c_fs_values[iphs]->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) {
        fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__);
        return (1);
      }
      sprintf (bp->poly_c_fs_values[iphs]->id_string, "FS_%i", iphs);
      bp->poly_c_fs_values[iphs]->disp_max = 1.0;
    }
  }                             /* end of iphs loop through phases */
  /*FIN THUINET 18-02-05 */

  /* malloc buffer for decented octahedron *//*by Wei WANG 11-07-02 */
  if (cp->decentred_octahedron) {       /*malloced only if decentred_ocathedron algorithm used */
    if (!(bp->ftmp_dc_d = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
      fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
      return (1);
    }

    if (!(bp->ftmp_dc_x = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
      fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
      return (1);
    }

    if (!(bp->ftmp_dc_y = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
      fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
      return (1);
    }

    if (!(bp->ftmp_dc_z = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
      fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n");
      return (1);
    }
  }
#ifdef OLD_TUNDER
  if (!(bp->old_Tunder = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) {
    fprintf (stderr, "ERROR: old_Tunder array malloc failed\n");
    return (1);
  }
#endif /*OLD_TUNDER */
  if (!(bp->itmp_one = (int *) calloc (i, sizeof (int)))) {
    fprintf (stderr, "ERROR: tmp int array malloc failed\n");
    return (1);
  }

  /*by Wei WANG 11-07-02 */
  if (!(bp->itmp_two = (int *) calloc (i, sizeof (int)))) {
    fprintf (stderr, "ERROR: tmp int array malloc failed\n");
    return (1);
  }

   /************************************************/
   /* malloc an array of grain structures          */
   /************************************************/
  if (!(bp->gr = (Ind_grain * *)calloc (bp->nprops.gd_max_total, sizeof (Ind_grain *)))) {
    fprintf (stderr, "ERROR: Ind_grain array malloc failed\n");
    return (1);
  }

  if (bp->ctrl->fgrid_input) {
    /* the finite element grid structure */
    if (!(bp->fg = (FGrid_str *) calloc (1, sizeof (FGrid_str)))) {
      fprintf (stderr, "ERROR: fg structure malloc failed\n");
      return (1);
    }
    /* the finite element grid structure */
    if (!(bp->fg_next = (FGrid_str *) calloc (1, sizeof (FGrid_str)))) {
      fprintf (stderr, "ERROR: fg structure malloc failed\n");
      return (1);
    }
  }

   /*************************************/
  /* Print out checks on input data... */
   /*************************************/
  fprintf (stderr, "sb_mask nsb: %d, %d, %d\n", bp->nsb[0], bp->nsb[1], bp->nsb[2]);
  fprintf (stderr, "Exiting alloc_bb().\n");
  return (0);
}