Beispiel #1
0
/*
 * Initialize the disk driver.
 * Read the partition table.
 */
static void ideInitialize(void) {
  unsigned int totalSectors;

  /* determine disk size */
  waitDiskReady();
  totalSectors = *DISK_CAP;
  if (totalSectors == 0) {
    panic("IDE disk not found");
  }
  /* read partition table */
  readPartitionTable();
  if (debugIdeDisk) {
    printf("IDE disk has %d (0x%X) sectors\n",
           totalSectors, totalSectors);
    showPartitionTable();
  }
  /* disk queue is empty */
  ideTab.b_actf = NULL;
  ideTab.b_actl = NULL;
  /* no disk operation in progress, no errors */
  ideTab.b_active = 0;
  ideTab.b_errcnt = 0;
  /* set ISR and enable interrupts */
  setISR(DISK_IRQ, ideISR);
  setMask(getMask() | (1 << DISK_IRQ));
  /* the disk is now initialized */
  ideInitialized = TRUE;
}
Beispiel #2
0
PartitionEntry* FileSystem::getPartitionTable(int sector, int sectorOffset) {

  PartitionEntry *entry = NULL;
  PartitionEntry *first = NULL;

  // MBR or EBR
  int partitionQt;
  if (sectorOffset == 0){
    partitionQt= 4;
  } else {
      partitionQt= 2;
  }

  for (int i = 1; i <= partitionQt; i++) {
    PartitionEntry *temp = readPartitionTable(sector, i, sectorOffset);
    if (entry == NULL) {
      entry = temp;
      first = entry;
    } else if (temp != NULL) {
      entry->next = temp;
      entry = entry->next;
    }
  }

  PartitionEntry *temp = first;
  PartitionEntry *end = entry;
  while (temp != end->next) {
    if (temp->type == EXTENDED_PARTITION) {
      if (extBootRecordOffset == 0)
        extBootRecordOffset = temp->startSector;
      entry->next = getPartitionTable(temp->startSector, temp->startSector);
      PartitionEntry *current = entry->next;
      PartitionEntry *prev = entry;
      while (current != NULL) {
        if (current->type == EXTENDED_PARTITION || current->type == 0) {
          if (current->next == NULL) {
            free(current);
            prev->next = NULL;
          } else {
            prev->next = current->next;
            free(current);
            current = prev->next;
            continue;
          }
        }
        prev = current;
        current = current->next;
      }
    }
    while (entry->next != NULL)
      entry = entry->next;
    temp = temp->next;
  }
  return first;
}