Exemplo n.º 1
0
/**
 * test_basic - check volume re-size capability.
 *
 * @type  volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
 *
 * Thus function returns %0 in case of success and %-1 in case of failure.
 */
static int test_basic(int type)
{
	struct ubi_mkvol_request req;
	const char *name = PROGRAM_NAME ":test_basic()";

	req.vol_id = UBI_VOL_NUM_AUTO;
	req.alignment = 1;
	req.bytes = MIN_AVAIL_EBS * dev_info.leb_size;
	req.vol_type = type;
	req.name = name;

	if (ubi_mkvol(libubi, node, &req)) {
		failed("ubi_mkvol");
		return -1;
	}

	req.bytes = dev_info.leb_size;
	if (ubi_rsvol(libubi, node, req.vol_id, req.bytes)) {
		failed("ubi_rsvol");
		goto remove;
	}

	if (check_volume(req.vol_id, &req))
		goto remove;

	req.bytes = (MIN_AVAIL_EBS + 1) * dev_info.leb_size;
	if (ubi_rsvol(libubi, node, req.vol_id, req.bytes)) {
		failed("ubi_rsvol");
		goto remove;
	}

	if (check_volume(req.vol_id, &req))
		goto remove;

	req.bytes -= 1;
	if (ubi_rsvol(libubi, node, req.vol_id, req.bytes)) {
		failed("ubi_rsvol");
		goto remove;
	}

	if (check_volume(req.vol_id, &req))
		goto remove;

	if (ubi_rmvol(libubi, node, req.vol_id)) {
		failed("ubi_rmvol");
		return -1;
	}

	return 0;

remove:
	ubi_rmvol(libubi, node, req.vol_id);
	return -1;
}
Exemplo n.º 2
0
/**
 * mkvol_multiple - test multiple volumes creation
 *
 * Thus function returns %0 if the test passed and %-1 if not.
 */
static int mkvol_multiple(void)
{
	struct ubi_mkvol_request req;
	int i, ret, max = dev_info.max_vol_count;
	const char *name = PROGRAM_NAME ":mkvol_multiple()";

	/* Create maximum number of volumes */
	for (i = 0; i < max; i++) {
		char nm[strlen(name) + 50];

		req.vol_id = UBI_VOL_NUM_AUTO;
		req.alignment = 1;
		req.bytes = 1;
		req.vol_type = UBI_STATIC_VOLUME;

		sprintf(nm, "%s:%d", name, i);
		req.name = nm;

		if (ubi_mkvol(libubi, node, &req)) {
			if (errno == ENFILE) {
				max = i;
				break;
			}
			failed("ubi_mkvol");
			errorm("vol_id %d", i);
			goto remove;
		}

		if (check_volume(req.vol_id, &req)) {
			errorm("vol_id %d", i);
			goto remove;
		}
	}

	for (i = 0; i < max; i++) {
		struct ubi_vol_info vol_info;

		if (ubi_rmvol(libubi, node, i)) {
			failed("ubi_rmvol");
			return -1;
		}

		/* Make sure volume does not exist */
		ret = ubi_get_vol_info1(libubi, dev_info.dev_num, i, &vol_info);
		if (ret == 0) {
			errorm("removed volume %d exists", i);
			goto remove;
		}
	}

	return 0;

remove:
	for (i = 0; i < dev_info.max_vol_count + 1; i++)
		ubi_rmvol(libubi, node, i);
	return -1;
}
Exemplo n.º 3
0
int main()
{
  vofi_cint nx=NMX,ny=NMY,nz=NMZ,ndim0=N3D;
  int i,j,k,itrue;
  vofi_real cc[NMX][NMY][NMZ],x0[NDIM],xloc[NDIM];
  double h0,fh,vol_n;

//* -------------------------------------------------------------------------- *
//* initialization of the color function with local Gauss integration          * 
//* -------------------------------------------------------------------------- *
   
  h0 = H/nx;                                                  //* grid spacing *
  itrue = 1;

  //* starting point to get fh *
  x0[0] = 0.5;
  x0[1] = 0.5; 
  x0[2] = 0.5; 

  //* get the characteristic value fh of the implicit function *
  fh = vofi_Get_fh(impl_func,x0,h0,ndim0,itrue);
 
  //* put now starting point in (X0,Y0,Z0) to initialize the color function *
  x0[0] = X0; 
  x0[1] = Y0; 
  x0[2] = Z0; 

  //* xloc: minor vertex of each cell of the grid *
  for (i=0; i<nx; i++)
    for (j=0; j<ny; j++) 
      for (k=0; k<nz; k++) {
      xloc[0] = x0[0] + i*h0;
      xloc[1] = x0[1] + j*h0;
      xloc[2] = x0[2] + k*h0;
      
      cc[i][j][k] = vofi_Get_cc(impl_func,xloc,h0,fh,ndim0);
   }

  //* final global check *
  vol_n = 0.0;

  for (i=0;i<nx; i++)
    for (j=0;j<ny; j++) 
      for (k=0;k<nz; k++) 
	 vol_n += cc[i][j][k];
  
  vol_n = vol_n*h0*h0*h0;

  check_volume(vol_n);

  return 0;
}
Exemplo n.º 4
0
/**
 * mkvol_alignment - create volumes with different alignments.
 *
 * Thus function returns %0 in case of success and %-1 in case of failure.
 */
static int mkvol_alignment(void)
{
	struct ubi_mkvol_request req;
	int i, vol_id, ebsz;
	const char *name = PROGRAM_NAME ":mkvol_alignment()";
	int alignments[] = ALIGNMENTS(dev_info.leb_size);

	for (i = 0; i < sizeof(alignments)/sizeof(int); i++) {
		req.vol_id = UBI_VOL_NUM_AUTO;

		/* Alignment should actually be multiple of min. I/O size */
		req.alignment = alignments[i];
		req.alignment -= req.alignment % dev_info.min_io_size;
		if (req.alignment == 0)
			req.alignment = dev_info.min_io_size;

		/* Bear in mind alignment reduces EB size */
		ebsz = dev_info.leb_size - dev_info.leb_size % req.alignment;
		req.bytes = (long long)dev_info.avail_lebs * ebsz;

		req.vol_type = UBI_DYNAMIC_VOLUME;
		req.name = name;

		if (ubi_mkvol(libubi, node, &req)) {
			failed("ubi_mkvol");
			errorm("alignment %d", req.alignment);
			return -1;
		}

		vol_id = req.vol_id;
		if (check_volume(vol_id, &req))
			goto remove;

		if (ubi_rmvol(libubi, node, vol_id)) {
			failed("ubi_rmvol");
			return -1;
		}
	}

	return 0;

remove:
	ubi_rmvol(libubi, node, vol_id);
	return -1;
}
Exemplo n.º 5
0
void  sound_buffer_data(LPWAVEHDR p)
{
 current_sound_fill--;
  if (!submit_sound_buffer())
  { lost_sound++;
    display_lost_sound();
	fill_sound_buffer(p); /* reuse buffer without encoding it */
    return;
  }
  if (!sound_recording)
    p->dwBytesRecorded = 0;
  check_volume(p,wavefmtex.nChannels == 2, wavefmtex.nSamplesPerSec);
  volume_compression(p, wavefmtex.nChannels == 2, wavefmtex.nSamplesPerSec);

  submit_encoder_input(p);    
  current_sound_bytes = current_sound_bytes + p->dwBytesRecorded;

}
Exemplo n.º 6
0
/**
 * mkvol_basic - simple test that checks basic volume creation capability.
 *
 * Thus function returns %0 in case of success and %-1 in case of failure.
 */
static int mkvol_basic(void)
{
	struct ubi_mkvol_request req;
	struct ubi_vol_info vol_info;
	int vol_id, ret;
	const char *name = PROGRAM_NAME ":mkvol_basic()";

	/* Create dynamic volume of maximum size */
	req.vol_id = UBI_VOL_NUM_AUTO;
	req.alignment = 1;
	req.bytes = dev_info.avail_bytes;
	req.vol_type = UBI_DYNAMIC_VOLUME;
	req.name = name;

	if (ubi_mkvol(libubi, node, &req)) {
		failed("ubi_mkvol");
		return -1;
	}

	vol_id = req.vol_id;
	if (check_volume(vol_id, &req))
		goto remove;

	if (ubi_rmvol(libubi, node, vol_id)) {
		failed("ubi_rmvol");
		return -1;
	}

	/* Create static volume of maximum size */
	req.vol_id = UBI_VOL_NUM_AUTO;
	req.alignment = 1;
	req.bytes = dev_info.avail_bytes;
	req.vol_type = UBI_STATIC_VOLUME;
	req.name = name;

	if (ubi_mkvol(libubi, node, &req)) {
		failed("ubi_mkvol");
		return -1;
	}

	vol_id = req.vol_id;
	if (check_volume(vol_id, &req))
		goto remove;

	if (ubi_rmvol(libubi, node, vol_id)) {
		failed("ubi_rmvol");
		return -1;
	}

	/* Make sure volume does not exist */
	ret = ubi_get_vol_info1(libubi, dev_info.dev_num, vol_id, &vol_info);
	if (ret == 0) {
		errorm("removed volume %d exists", vol_id);
		goto remove;
	}

	return 0;

remove:
	ubi_rmvol(libubi, node, vol_id);
	return -1;
}
Exemplo n.º 7
0
int
main(int ac, char **av)
{
	uint32_t status;
	hammer2_off_t total_space;
	hammer2_off_t free_space;
	hammer2_off_t reserved_space;
	int ch;
	int fd = -1;
	char *fsidstr;
	char *spfsidstr;
	char *rpfsidstr;

	/*
	 * Sanity check basic filesystem structures.  No cookies for us
	 * if it gets broken!
	 */
	assert(sizeof(hammer2_volume_data_t) == HAMMER2_VOLUME_BYTES);
	assert(sizeof(hammer2_inode_data_t) == HAMMER2_INODE_BYTES);
	assert(sizeof(hammer2_blockref_t) == HAMMER2_BLOCKREF_BYTES);

	/*
	 * Generate a filesystem id and lookup the filesystem type
	 */
	srandomdev();
	uuidgen(&Hammer2_FSId, 1);
	uuidgen(&Hammer2_SPFSId, 1);
	uuidgen(&Hammer2_RPFSId, 1);
	uuid_from_string(HAMMER2_UUID_STRING, &Hammer2_FSType, &status);
	/*uuid_name_lookup(&Hammer2_FSType, "DragonFly HAMMER2", &status);*/
	if (status != uuid_s_ok) {
		errx(1, "uuids file does not have the DragonFly "
			"HAMMER filesystem type");
	}

	/*
	 * Parse arguments
	 */
	while ((ch = getopt(ac, av, "fL:b:m:r:V:")) != -1) {
		switch(ch) {
		case 'f':
			ForceOpt = 1;
			break;
		case 'L':
			Label = optarg;
			if (strlen(Label) > HAMMER2_INODE_MAXNAME) {
				errx(1, "Root directory label too long "
					"(64 chars max)\n");
			}
			break;
		case 'b':
			BootAreaSize = getsize(optarg,
					 HAMMER2_NEWFS_ALIGN,
					 HAMMER2_BOOT_MAX_BYTES, 2);
			break;
		case 'r':
			AuxAreaSize = getsize(optarg,
					 HAMMER2_NEWFS_ALIGN,
					 HAMMER2_REDO_MAX_BYTES, 2);
			break;
		case 'V':
			Hammer2Version = strtol(optarg, NULL, 0);
			if (Hammer2Version < HAMMER2_VOL_VERSION_MIN ||
			    Hammer2Version >= HAMMER2_VOL_VERSION_WIP) {
				errx(1,
				     "I don't understand how to format "
				     "HAMMER2 version %d\n",
				     Hammer2Version);
			}
			break;
		default:
			usage();
			break;
		}
	}

	if (Hammer2Version < 0) {
		size_t olen = sizeof(Hammer2Version);
		Hammer2Version = HAMMER2_VOL_VERSION_DEFAULT;
		if (sysctlbyname("vfs.hammer2.supported_version",
				 &Hammer2Version, &olen, NULL, 0) == 0) {
			if (Hammer2Version >= HAMMER2_VOL_VERSION_WIP) {
				Hammer2Version = HAMMER2_VOL_VERSION_WIP - 1;
				fprintf(stderr,
					"newfs_hammer: WARNING: HAMMER2 VFS "
					"supports higher version than I "
					"understand,\n"
					"using version %d\n",
					Hammer2Version);
			}
		} else {
			fprintf(stderr,
				"newfs_hammer: WARNING: HAMMER2 VFS not "
				"loaded, cannot get version info.\n"
				"Using version %d\n",
				HAMMER2_VOL_VERSION_DEFAULT);
		}
	}

	/*
	 * Collect volume information.
	 */
	ac -= optind;
	av += optind;

	if (ac != 1) {
		fprintf(stderr, "Exactly one disk device must be specified\n");
		exit(1);
	}
	total_space = check_volume(av[0], &fd);

	/*
	 * ~typically 8MB alignment to avoid edge cases for reserved blocks
	 * and so raid stripes (if any) operate efficiently.
	 */
	total_space &= ~HAMMER2_VOLUME_ALIGNMASK64;

	/*
	 * Calculate defaults for the boot area size and round to the
	 * volume alignment boundary.
	 */
	if (BootAreaSize == 0) {
		BootAreaSize = HAMMER2_BOOT_NOM_BYTES;
		while (BootAreaSize > total_space / 20)
			BootAreaSize >>= 1;
		if (BootAreaSize < HAMMER2_BOOT_MIN_BYTES)
			BootAreaSize = HAMMER2_BOOT_MIN_BYTES;
	} else if (BootAreaSize < HAMMER2_BOOT_MIN_BYTES) {
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
  vofi_cint nx=NMX,ny=NMY,nz=NMZ,ndim0=N3D;
  int i,j,k,itrue;
  vofi_real cc[NMX][NMY][NMZ],x0[NDIM],xloc[NDIM];
  double h0,fh,vol_n;
  int randominput = 0;  
  int count;
  
  for (count = 1; count < argc; ++count)
  {
    if (!strcmp(argv[count], "-r") || !strcmp(argv[count], "--randominput")) 
    {
      randominput = 1;
    }
  }

/* -------------------------------------------------------------------------- *
 * initialization of the color function with local Gauss integration          * 
 * -------------------------------------------------------------------------- */
   
  h0 = H/nx;                                                  /* grid spacing */
  itrue = 1;

  /* starting point to get fh */
  x0[0] = 0.5;
  x0[1] = 0.5; 
  x0[2] = 0.5; 
  
  init(randominput);

  /* get the characteristic value fh of the implicit function */
  fh = vofi_Get_fh(impl_func,x0,h0,ndim0,itrue);
 
  /* put now starting point in (X0,Y0,Z0) to initialize the color function */
  x0[0] = X0; 
  x0[1] = Y0; 
  x0[2] = Z0; 

  /* xloc: minor vertex of each cell of the grid */
  for (i=0; i<nx; i++)
    for (j=0; j<ny; j++) 
      for (k=0; k<nz; k++) {
      xloc[0] = x0[0] + i*h0;
      xloc[1] = x0[1] + j*h0;
      xloc[2] = x0[2] + k*h0;
      
      cc[i][j][k] = vofi_Get_cc(impl_func,xloc,h0,fh,ndim0);
   }

  /* final global check */     
  vol_n = 0.0;

  for (i=0;i<nx; i++)
    for (j=0;j<ny; j++) 
      for (k=0;k<nz; k++) 
	 vol_n += cc[i][j][k];
  
  vol_n = vol_n*h0*h0*h0;

  check_volume(vol_n, randominput);

  return 0;
}
Exemplo n.º 9
0
PalFileMenu *PalFile::config_tree_build_children( ldh_tSession ldhses, ifstream *fp, 
	       int *line_cnt, const char *filename, PalFileMenu *parent)
{
  PalFileMenu	        *menu_p, *prev, *mp;
  PalFileMenu	        *return_menu = NULL;
  int			first = 1;
  int			nr;
  char			line[140];
  char			type[120];
  char			name[120];
  char			p1[120];
  char			p2[120];
  int                   found;
  int                   hide_children = 0;

    // Children might already exist
  if ( parent) {
    for ( menu_p = parent->child_list; menu_p; menu_p = menu_p->next) {
      prev = menu_p;
      first = 0;
    }
  }
  menu_p = 0;

  while ( 1)
  {
    if ( !fp->getline( line, sizeof( line)))
      break;
    dcli_remove_blank( line, line);
    (*line_cnt)++;
    if ( line[0] == 0)
      continue;
    if ( line[0] == '!' || line[0] == '#')
      continue;
    nr = sscanf( line, "%s %s %s %s", type, name, p1, p2);
    if ( nr < 1 )
      printf( "** Syntax error in file %s, line %d\n", filename, *line_cnt);

    if ( strcmp( type, "{") == 0)
    {
      if ( !hide_children) {
        if ( nr != 1 || !menu_p)
          printf( "** Syntax error in file %s, line %d\n", filename, *line_cnt);
        else
          mp = config_tree_build_children( ldhses, fp, line_cnt, filename,
		menu_p);
        if ( !menu_p->child_list)
          menu_p->child_list = mp;
      }
      else
	hide_children = 0;
    }
    else if ( strcmp( type, "}") == 0)
    {
      if ( nr != 1 )
        printf( "** Syntax error in file %s, line %d\n", filename, *line_cnt);
      return return_menu;
    }
    else if ( cdh_NoCaseStrcmp( type, "menu") == 0)
    {
      if ( !(nr == 2 || nr == 3))
        printf( "** Syntax error in file %s, line %d\n", filename, *line_cnt);

      if ( nr == 3 && ( ldhses && !check_volume( ldhses, p1))) {
        hide_children = 1;
        break;
      }

      // Check if it already exist
      found = 0;
      for ( menu_p = parent->child_list; menu_p; menu_p = menu_p->next) {
        if ( strcmp( menu_p->title, name) == 0) {
          found = 1;
          break;
        }
      } 

      if ( !found) {
        menu_p = new PalFileMenu( name, pal_eMenuType_Menu, parent);
        if ( first) {
          return_menu = menu_p;
          first = 0;
        }
        else
          prev->next = menu_p;
        prev = menu_p;
      }
    }
    else if ( cdh_NoCaseStrcmp( type, "class") == 0) {
      if ( !( nr == 2 || nr == 3))
        printf( "** Syntax error in file %s, line %d\n", filename, *line_cnt);

      if ( nr == 2 || ( nr == 3 && (!ldhses || check_volume( ldhses, p1)))) {
        menu_p = new PalFileMenu( name, pal_eMenuType_Class, parent);
        if ( first) {
          return_menu = menu_p;
          first = 0;
        }
        else
          prev->next = menu_p;
        prev = menu_p;
      }
    }
    else if ( cdh_NoCaseStrcmp( type, "classvolume") == 0)
    {
      if ( !(nr == 2 || nr == 3))
        printf( "** Syntax error in file %s, line %d\n", filename, *line_cnt);

      if ( nr == 2 || ( nr == 3 && (!ldhses || check_volume( ldhses, p1)))) {
        menu_p = new PalFileMenu( name, pal_eMenuType_ClassVolume, parent);
        if ( first) {
          return_menu = menu_p;
          first = 0;
        }
        else
          prev->next = menu_p;
        prev = menu_p;
      }
    }
  }

  return return_menu;
}
Exemplo n.º 10
0
int main (int argc, char ** argv)
{
    int opts = 0;
    int delay = 8000;
    short volume = 4;

    // Get the arguments
    while((opts = getopt(argc, argv,"d:v: tt")) != -1)
    {
        if (opts == 'd')
        {
            delay = atoi(optarg);
        }
        else if (opts == 'v')
        {
            volume = atoi(optarg);
        }
    }

    // Make sure delay is not negative
    // Make sure volume scale is at least 1
    check_delay(&delay);
    check_volume(&volume);

    // Open the files in binary mode to read, or write
    FILE *source = fopen(argv[optind], "rb");
    FILE *dest = fopen(argv[optind+1], "wb");

    // Handle incorrect source file input
    check_source(&source);

    // READ header from source - first 44 bytes as 11 ints
    int header[11] = {0};
    fread(header, sizeof(int), 11, source);

    // Change file size in the header
    header[1] += delay*2;
    header[10] += delay*2;

    // WRITE header to output file
    fwrite(header, sizeof(int), 11, dest);

    // Allocate mem to store delay number of shorts
    short *buffer;
    buffer = malloc((sizeof(short) * delay));

    // Copy samples before DELAY num of samples into buffer
    fseek(source, 44, SEEK_SET); // 44 bytes from start of file
    fread(buffer, sizeof(short), delay, source);


    // START READING THE SAMPLES ONE AT A TIME.
    fseek(source, 44, SEEK_SET); // 44 bytes from start of file
    short smp = 0; // This will hold the sample being read
    int s = 0; // Keeps track of the NUMBER OF samples read

    while (fread(&smp, sizeof(short), 1, source))
    {
        if (s < delay)
        {
            // If not at sample number DELAY yet, just write as they are...
            fwrite(&smp, sizeof(short), 1, dest);
        }
        else
        {
            // At sample number DELAY, write mixed in buffer[0] scaled by volume
            short temp = smp + (buffer[0] / volume);
            fwrite(&temp, sizeof(short), 1, dest);
        }

        // START OF BUFFER CODE
        // Append smp to the buffer AFTER "popping it"
        int i = 0;
        for (i = 0; i < delay-1; i++)
        {
            buffer[i] = buffer[i+1];
        }
        buffer[delay-1] = smp;
        // EOF BUFFER CODE

        s++; // Increment the number of samples
    }

    // Write the rest of the buffer scaled by volume to dest
    int i = 0;
    for (i = 0; i < delay; i++)
    {
        buffer[i] /= volume;
    }

    fwrite(buffer, sizeof(short), delay, dest);

    return 0;
}