int test(int a, char** v){ /* la forma de ejecutar es qemu -kernel bin/kernel.bin -hda disk.img ** o tambien con -hda disk0.img que tiene cosas escritas parece y es mas facil ver cosas*/ char buffer2[512],buffer[512]; int i; for(i=0;i<512;i++){ buffer[i]='C'; } printf("\n"); ata_write(ATA0, buffer, 512, 1, 256); ata_read(ATA0, buffer2, 512, 1, 0); printf("lei esto\n"); for(i=0 ; i<512 ;i++){ printf("%c", buffer2[i]); } printf("\n"); ata_read(ATA0, buffer2, 512, 2, 0); printf("lei esto\n"); for(i=0 ; i<512 ;i++){ printf("%c", buffer2[i]); } return 0; }
/* Reads LBA0, and sets up the partition entries for the disk. */ void parse_mbr(ata_device_t *dev) { assert(dev != NULL); assert(sizeof(struct mbr_ptable) == 16); memset(dev->partition, 0, sizeof(partition_t) * 4); /* If this device is nonexistant or an ATAPI device, set all partitions to * not present. */ if (!dev->exists || dev->is_atapi) { for (int i=0; i < 3; i++) { dev->partition[i].exists = false; } return; } /* Read the MBR from disk */ unsigned char *buf = kmalloc(512); int ret = ata_read(dev, /* LBA = */ 0, buf, 1); assert(ret != 0); /* Last 2 bytes of the MBR should be 0xAA55. * If they're not, set all partitions to not present and return. */ if (*( (uint16 *)(buf + 510) ) != 0xAA55) { for (int i=0; i < 3; i++) { dev->partition[i].exists = false; } return; } /* Loop through the partition table. */ for (int i = 0; i < 3; i++) { /* A bit ugly, but... eh. Partition entry 1 (1-indexed) is at offset 446, #2 at offset 446+16, etc. */ struct mbr_ptable *part = ((struct mbr_ptable *)(buf + 446)) + i; /* Check whether this partition exists or not */ if (part->system_id == 0 || part->total_sectors == 0) { dev->partition[i].exists = false; continue; } else dev->partition[i].exists = true; /* Set the bootable flag */ if (part->system_id & 0x80) dev->partition[i].bootable = true; /* Copy the system ID byte and the partition location/size */ dev->partition[i].type = part->system_id; dev->partition[i].start_lba = part->rel_sector; dev->partition[i].total_sectors = part->total_sectors; } }
void fat16_read_mbr(uint16_t *buf) { ata_read(0,1,buf,1); }
//crappy function that blindly reads n sectors to array.. void fat16_read_file_array(fat_entry *entry, uint16_t *buf, uint32_t num_sectors, uint32_t byteswap) { ata_read(fat16_cluster_to_lba_offset(entry->start_cluster),num_sectors,buf,byteswap); }
void fat16_read_root_dir(fat_entry *entry) { //uint32_t lba_offs = (__SWAP16(fat_boot.reserved_sectors) + __SWAP16(fat_boot.fat_size_sectors) * fat_boot.number_of_fats) * __SWAP16(fat_boot.sector_size); //ata_read((lba_offs/512)+__SWAP32(part_table[selected_part].lba_offset),32,tmp_dir,1); //memcpy(entry,tmp_dir,sizeof(fat_entry)*num_entries); ata_read(root_dir_start_lba,((__SWAP16(fat_boot.root_dir_entries))*0x20)/512,(uint16_t *)entry,1); }
void fat16_read_fat(uint16_t *fatbuf) { ata_read(fat_start_lba, (__SWAP16(fat_boot.fat_size_sectors)* __SWAP16(fat_boot.sector_size))/512, fatbuf,1); }
void fat16_read_fat_boot(fat_boot_sector *boot) { ata_read(boot_start_lba,1,tmp,1); memcpy(boot, tmp, sizeof(tmp)); }