示例#1
0
文件: main.c 项目: kivantium/syspro
void *get(void *arg) {
    int i;
    for(i=0; i<1000; ++i) {
        bb_get();
    }
    pthread_exit(NULL);
}
示例#2
0
文件: fat.c 项目: RamseyK/dd_reader
/*
 * Read's the FAT volume boot record in the byte buffer and sets the relevant information in the partition structure's boot_sector
 */
void fat_read_boot_sector(byte_buffer *bb, fat_partition *part) {
	part->boot_sector = fat_new_boot_sector();
	fat_bs *bs = part->boot_sector;

	// Jump instruction
	bb_get_bytes_in(bb, bs->jmp, sizeof(bs->jmp));

	// OEM ID string
	bb_get_bytes_in(bb, bs->oem_id, sizeof(bs->oem_id));

	// BPB
	bs->bpb.bytes_per_sector = bb_get_short(bb);
	bs->bpb.sectors_per_cluster = bb_get(bb);
	bs->bpb.reserved_sectors = bb_get_short(bb);
	bs->bpb.num_fats = bb_get(bb);
	bs->bpb.root_entries_f16 = bb_get_short(bb);
	bs->bpb.total_sectors_16bit = bb_get_short(bb);
	bs->bpb.media_descriptor = bb_get(bb);
	bs->bpb.sectors_per_fat_f16 = bb_get_short(bb);
	bs->bpb.sectors_per_track = bb_get_short(bb);
	bs->bpb.num_heads = bb_get_short(bb);
	bs->bpb.hidden_sectors = bb_get_int(bb);
	bs->bpb.total_sectors_32bit = bb_get_int(bb);

	// Make proper determination of the FAT partition type according to MSFT docs
	uint32_t cluster_count = fat_count_clusters(part);
	if(cluster_count < 4085) {
		part->type = PT_FAT12;
	} else if(cluster_count < 65525) {
		part->type = PT_FAT16B;
	} else {
		part->type = PT_FAT32;
	}
	//printf("Detected FAT type: %s\n", get_partition_str(part->type)); // delete this after testing

	// FAT32 portion of the BPB
	if(part->type == PT_FAT32) {
		bs->bpb.sectors_per_fat_f32 = bb_get_int(bb);
		bs->bpb.eflags_f32 = bb_get_short(bb);
		bs->bpb.version_f32 = bb_get_short(bb);
		bs->bpb.root_cluster_f32 = bb_get_int(bb);
		bs->bpb.fsinfo_sector_f32 = bb_get_short(bb);
		bs->bpb.backup_sector_f32 = bb_get_short(bb);
		bb_skip(bb, sizeof(bs->bpb.reserved_f32)); // Skip 12 byte reserved
	}

	// EBPB
	bs->ebpb.physical_drive_num = bb_get(bb);
	bs->ebpb.reserved = bb_get(bb);
	bs->ebpb.eb_sig = bb_get(bb);
	bs->ebpb.volume_serial = bb_get_int(bb);
	bb_get_bytes_in(bb, bs->ebpb.volume_label, sizeof(bs->ebpb.volume_label));
	bb_get_bytes_in(bb, bs->ebpb.system_id, sizeof(bs->ebpb.system_id));

	// Bootstrap code
	if(part->type == PT_FAT32) {
		bs->bootstrap_code = bb_get_bytes(bb, FAT32_BOOTSTRAP_SIZE);
	} else {
		bs->bootstrap_code = bb_get_bytes(bb, FAT16_BOOTSTRAP_SIZE);
	}

	// End signature
	bs->sig_end1 = bb_get(bb);
	bs->sig_end2 = bb_get(bb);
	if(bs->sig_end1 != 0x55 || bs->sig_end2 != 0xAA) {
		printf("Warning: FAT VBR boot signature does not match 0x55 0xAA!. sig1: %X, sig2: %X\n", bs->sig_end1, bs->sig_end2);
	}
}