コード例 #1
0
ファイル: walb_util.c プロジェクト: herumi/walb
/**
 * Write super sector to the log device.
 *
 * @fd file descripter of log device.
 * @super_sect super sector data.
 *
 * RETURN:
 *   true in success, or false.
 */
bool write_super_sector_raw(int fd, const struct walb_super_sector* super_sect)
{
	u32 sect_sz;
	u8 *buf;
	struct walb_super_sector *p;
	u32 csum;
	u64 off0, off1;
	bool ret0, ret1;

	ASSERT(super_sect);

	sect_sz = super_sect->physical_bs;

	/* Memory image of sector. */
	if (posix_memalign((void **)&buf, PAGE_SIZE, sect_sz) != 0) {
		return false;
	}
	memset(buf, 0, sect_sz);
	memcpy(buf, super_sect, sizeof(*super_sect));
	p = (struct walb_super_sector *)buf;

	/* Set sector type. */
	p->sector_type = SECTOR_TYPE_SUPER;

	/* Calculate checksum. */
	p->checksum = 0;
	csum = checksum(buf, sect_sz, 0);
	print_binary_hex(buf, sect_sz);/* debug */
	p->checksum = csum;
	print_binary_hex(buf, sect_sz);/* debug */
	ASSERT(checksum(buf, sect_sz, 0) == 0);

	/* Really write sector data. */
	off0 = get_super_sector0_offset_2(super_sect);
	off1 = get_super_sector1_offset_2(super_sect);
	ret0 = write_sector_raw(fd, buf, sect_sz, off0);
	ret1 = write_sector_raw(fd, buf, sect_sz, off1);

	free(buf);
	return ret0 && ret1;
}
コード例 #2
0
ファイル: disk.c プロジェクト: Swelo0/prog_systeme_avance
void write_sector(int sector, uchar* buf){
	packet p;
	p.size = 0x10;
	p.reserved = 0;
	p.sect_count = 1;
	p.buf_offset = buf;
	//p.buf_segment -> assembleur;
	p.first_sect[0] = sector;
	p.first_sect[1] = 0;
	p.first_sect[2] = 0;
	p.first_sect[3] = 0;
	write_sector_raw(0x80, &p);
}