예제 #1
0
파일: ext2_disk.c 프로젝트: descent/osdev
void ext2_disk_read_block(uint32_t block_no, uint8_t *buf) {
	if (!block_no) return;
	spin_lock(&lock);
	int oldest = -1;
	uint32_t oldest_age = UINT32_MAX;
	for (uint32_t i = 0; i < CACHEENTRIES; ++i) {
		if (DC[i].block_no == block_no) {
			DC[i].last_use = ext2_time();
			memcpy(buf, &DC[i].block, BLOCKSIZE);
			spin_unlock(&lock);
			return;
		}
		if (DC[i].last_use < oldest_age) {
			oldest = i;
			oldest_age = DC[i].last_use;
		}
	}

	for (uint32_t i = 0; i < BLOCKSIZE / SECTORSIZE; ++i) {
		ide_read_sector(DISK_PORT, 0, btos(block_no) + i, (uint8_t *)((uint32_t)&(DC[oldest].block) + SECTORSIZE * i));
	}

	if (DC[oldest].dirty) {
		ext2_flush_dirty(oldest);
	}
	memcpy(buf, &DC[oldest].block, BLOCKSIZE);
	DC[oldest].block_no = block_no;
	DC[oldest].last_use = ext2_time();
	DC[oldest].dirty = 0;
	spin_unlock(&lock);
}
예제 #2
0
파일: mbr.c 프로젝트: Atomication/toaruos
int read_partition_map(int device) {

	ide_init(DISK_PORT);

	ide_read_sector(DISK_PORT, 0, 0, (uint8_t *)&mbr);

	if (mbr.signature[0] == 0x55 && mbr.signature[1] == 0xAA) {
		debug_print(INFO, "Partition table found.");

		for (int i = 0; i < 4; ++i) {
			if (mbr.partitions[i].status & 0x80) {
				debug_print(NOTICE, "Partition #%d: @%d+%d", i+1, mbr.partitions[i].lba_first_sector, mbr.partitions[i].sector_count);
			} else {
				debug_print(NOTICE, "Partition #%d: inactive", i+1);
			}
		}

		return 0;
	} else {
		debug_print(ERROR, "Did not find partition table.");
		debug_print(ERROR, "Signature was 0x%x 0x%x instead of 0x55 0xAA", mbr.signature[0], mbr.signature[1]);

		debug_print(ERROR, "Parsing anyone yields:");

		for (int i = 0; i < 4; ++i) {
			if (mbr.partitions[i].status & 0x80) {
				debug_print(NOTICE, "Partition #%d: @%d+%d", i+1, mbr.partitions[i].lba_first_sector, mbr.partitions[i].sector_count);
			} else {
				debug_print(NOTICE, "Partition #%d: inactive", i+1);
			}
		}


	}

	return 1;
}