Exemplo n.º 1
0
int32 _write_super_page (super_page *p_super_page)
{
    p_super_page->checksum = _checksum ((const char *)&(p_super_page->version), PAGE_SIZE - 1);
    _convert_super_page_byte_order (p_super_page, _little_big_endian (), p_super_page->byte_order);
 
    return _write_page (IDX_SUPER_PAGE, (const char *)p_super_page, PAGE_SIZE);
}
Exemplo n.º 2
0
uint8_t
ipmi_checksum (const void *buf, unsigned int buflen)
{
  uint8_t checksum;
  checksum = _checksum (buf, buflen, 0);
  return (-checksum);
}
Exemplo n.º 3
0
		void putFile(const char* filename,const char* nameInArchive)
		{
			char buff[BUFSIZ];
			std::FILE* in=std::fopen(filename,"rb");
			if(in==NULL)
			{
				std::stringstream err;
				err << "Cannot open " << filename << " "<< std::strerror(errno);
				throw std::runtime_error(err.str());
			}
			std::fseek(in, 0L, SEEK_END);
			long int len= std::ftell(in);
			std::fseek(in,0L,SEEK_SET);

			PosixTarHeader header;
			_init((void*)&header);
			_filename((void*)&header,nameInArchive);
			header.typeflag[0]=0;
			_size((void*)&header,len);
			_checksum((void*)&header);
			out.write((const char*)&header,sizeof(PosixTarHeader));

			std::size_t nRead=0;
			while((nRead=std::fread(buff,sizeof(char),BUFSIZ,in))>0)
			{
				out.write(buff,nRead);
			}
			std::fclose(in);

			_endRecord(len);
		}
Exemplo n.º 4
0
uint8_t
ipmi_checksum_final (const void *buf, unsigned int buflen, uint8_t checksum_initial)
{
  uint8_t checksum;

  if (!buf || !buflen)
    return (-checksum_initial);

  checksum = _checksum (buf, buflen, checksum_initial);
  return (-checksum);
}
Exemplo n.º 5
0
		void put(const char* filename,const char* content,std::size_t len)
		{
			PosixTarHeader header;
			_init((void*)&header);
			_filename((void*)&header,filename);
			header.typeflag[0]=0;
			_size((void*)&header,len);
			_checksum((void*)&header);
			out.write((const char*)&header,sizeof(PosixTarHeader));
			out.write(content,len);
			_endRecord(len);
		}
Exemplo n.º 6
0
int32 is_FS_exist ()
{
    INIT_SUPER_PAGE ();
    if (my_strncmp ((const void *)(g_p_super_page->magic), (const void *)"MyFS", 4)) {
        DESTROY_SUPER_PAGE ();
        return 0;
    }
    if (_checksum ((const char *)g_buffer_page, PAGE_SIZE)) {
        DESTROY_SUPER_PAGE ();
        return E_FS_CHCK;
    }
    return 1;
}
Exemplo n.º 7
0
uint8_t
ipmi_checksum_incremental (const void *buf, unsigned int buflen, uint8_t checksum_initial)
{
  return (_checksum (buf, buflen, checksum_initial));
}
Exemplo n.º 8
0
static int
dvh_write (const PedDisk* disk)
{
	DVHDiskData*		dvh_disk_data = disk->disk_specific;
	struct volume_header	vh;
	int			i;

	PED_ASSERT (dvh_disk_data != NULL);

	_flush_stale_flags (disk);

	memset (&vh, 0, sizeof (struct volume_header));

	vh.vh_magic = PED_CPU_TO_BE32 (VHMAGIC);
	vh.vh_rootpt = PED_CPU_TO_BE16 (dvh_disk_data->root - 1);
	vh.vh_swappt = PED_CPU_TO_BE16 (dvh_disk_data->swap - 1);

	if (dvh_disk_data->boot) {
		PedPartition* boot_part;
		boot_part = ped_disk_get_partition (disk, dvh_disk_data->boot);
		strcpy (vh.vh_bootfile, ped_partition_get_name (boot_part));
	}

	vh.vh_dp = dvh_disk_data->dev_params;
	/* Set up rudimentary device geometry */
	vh.vh_dp.dp_cyls
		= PED_CPU_TO_BE16 ((short)disk->dev->bios_geom.cylinders);
	vh.vh_dp.dp_trks0 = PED_CPU_TO_BE16 ((short)disk->dev->bios_geom.heads);
	vh.vh_dp.dp_secs
		= PED_CPU_TO_BE16 ((short)disk->dev->bios_geom.sectors);
	vh.vh_dp.dp_secbytes = PED_CPU_TO_BE16 ((short)disk->dev->sector_size);

	for (i = 0; i < NPARTAB; i++) {
		PedPartition* part = ped_disk_get_partition (disk, i + 1);
		if (part)
			_generate_partition (part, &vh.vh_pt[i]);
	}

	/* whole disk partition
	 * This is only ever written here, and never modified
	 * (or even shown) as it must contain the entire disk,
	 * and parted does not like overlapping partitions
	 */
	vh.vh_pt[PNUM_VOLUME].pt_nblks = PED_CPU_TO_BE32 (disk->dev->length);
	vh.vh_pt[PNUM_VOLUME].pt_firstlbn = PED_CPU_TO_BE32 (0);
	vh.vh_pt[PNUM_VOLUME].pt_type = PED_CPU_TO_BE32 (PTYPE_VOLUME);

	for (i = 0; i < NVDIR; i++) {
		PedPartition* part = ped_disk_get_partition (disk,
							     i + 1 + NPARTAB);
		if (part)
			_generate_boot_file (part, &vh.vh_vd[i]);
	}

	vh.vh_csum = 0;
	vh.vh_csum = PED_CPU_TO_BE32 (_checksum ((uint32_t*) &vh,
			       	      sizeof (struct volume_header)));

        return (ptt_write_sector (disk, &vh, sizeof vh)
                && ped_device_sync (disk->dev));
}
Exemplo n.º 9
0
static int
dvh_read (PedDisk* disk)
{
	DVHDiskData*		dvh_disk_data = disk->disk_specific;
	int			i;
	struct volume_header	vh;
	char			boot_name [BFNAMESIZE + 1];
#ifndef DISCOVER_ONLY
	int			write_back = 0;
#endif

	PED_ASSERT (dvh_disk_data != NULL);

	ped_disk_delete_all (disk);

	void *s0;
	if (!ptt_read_sector (disk->dev, 0, &s0))
		return 0;
	memcpy (&vh, s0, sizeof vh);
	free (s0);

	if (_checksum ((uint32_t*) &vh, sizeof (struct volume_header))) {
		if (ped_exception_throw (
			PED_EXCEPTION_ERROR,
			PED_EXCEPTION_IGNORE_CANCEL,
			_("Checksum is wrong, indicating the partition "
			  "table is corrupt."))
				== PED_EXCEPTION_CANCEL)
			return 0;
	}

	PED_ASSERT (PED_BE32_TO_CPU (vh.vh_magic) == VHMAGIC);

	dvh_disk_data->dev_params = vh.vh_dp;
	strncpy (boot_name, vh.vh_bootfile, BFNAMESIZE);
	boot_name[BFNAMESIZE] = 0;

	/* normal partitions */
	for (i = 0; i < NPARTAB; i++) {
		PedPartition* part;

		if (!vh.vh_pt[i].pt_nblks)
			continue;
		/* Skip the whole-disk partition, parted disklikes overlap */
		if (PED_BE32_TO_CPU (vh.vh_pt[i].pt_type) == PTYPE_VOLUME)
			continue;

		part = _parse_partition (disk, &vh.vh_pt[i]);
		if (!part)
			goto error_delete_all;

		part->fs_type = ped_file_system_probe (&part->geom);
		part->num = i + 1;

		if (PED_BE16_TO_CPU (vh.vh_rootpt) == i)
			ped_partition_set_flag (part, PED_PARTITION_ROOT, 1);
		if (PED_BE16_TO_CPU (vh.vh_swappt) == i)
			ped_partition_set_flag (part, PED_PARTITION_SWAP, 1);

		PedConstraint *constraint_exact
		  = ped_constraint_exact (&part->geom);
		bool ok = ped_disk_add_partition (disk, part, constraint_exact);
		ped_constraint_destroy (constraint_exact);
		if (!ok) {
			ped_partition_destroy (part);
			goto error_delete_all;
		}
	}

	if (!ped_disk_extended_partition (disk)) {
#ifdef DISCOVER_ONLY
		return 1;
#else
		switch (_handle_no_volume_header (disk)) {
			case PED_EXCEPTION_CANCEL:
				return 0;
			case PED_EXCEPTION_IGNORE:
				return 1;
			case PED_EXCEPTION_FIX:
				write_back = 1;
				break;
			default:
				break;
		}
#endif
	}

	/* boot partitions */
	for (i = 0; i < NVDIR; i++) {
		PedPartition* part;

		if (!vh.vh_vd[i].vd_nbytes)
			continue;

		part = _parse_boot_file (disk, &vh.vh_vd[i]);
		if (!part)
			goto error_delete_all;

		part->fs_type = ped_file_system_probe (&part->geom);
		part->num = NPARTAB + i + 1;

		if (!strcmp (boot_name, ped_partition_get_name (part)))
			ped_partition_set_flag (part, PED_PARTITION_BOOT, 1);

		PedConstraint *constraint_exact
		  = ped_constraint_exact (&part->geom);
		bool ok = ped_disk_add_partition (disk, part, constraint_exact);
		ped_constraint_destroy (constraint_exact);
		if (!ok) {
			ped_partition_destroy (part);
			goto error_delete_all;
		}
	}
#ifndef DISCOVER_ONLY
	if (write_back)
		dvh_write (disk);
#endif
	return 1;

error_delete_all:
	ped_disk_delete_all (disk);
	return 0;
}