static const char *detect_fs(const char *path) { int fd; const char *ret; fd = open(path, O_RDONLY); if (fd < 0) { dbg_perror("open"); return 0; } if (is_vfat(fd)) ret = "vfat"; else if (is_iso9660(fd)) ret = "iso9660"; else ret = is_extN(fd); close(fd); return ret; }
device_instance * pk_disklabel_create_instance(device_instance *raw_disk, const char *args) { int partition; char *filename; /* parse the arguments */ if (args == NULL) { partition = 0; filename = NULL; } else { partition = strtoul((char*)args, &filename, 0); if (filename == args) partition = -1; /* not specified */ if (*filename == ',') filename++; if (*filename == '\0') filename = NULL; /* easier */ } if (partition == 0) { /* select the raw disk */ return raw_disk; } else { unsigned8 boot_block[512]; /* get the boot block for examination */ if (device_instance_seek(raw_disk, 0, 0) < 0) device_error(device_instance_device(raw_disk), "Problem seeking on raw disk"); if (device_instance_read(raw_disk, &boot_block, sizeof(boot_block)) != sizeof(boot_block)) device_error(device_instance_device(raw_disk), "Problem reading boot block"); if (partition < 0) { /* select the active partition */ if (block0_is_bpb(boot_block)) { device_error(device_instance_device(raw_disk), "Unimplemented active BPB"); } else if (block0_is_fdisk(boot_block)) { int active = block0_is_fdisk(boot_block); device_error(device_instance_device(raw_disk), "Unimplemented active FDISK (%d)", active); } else if (is_iso9660(raw_disk)) { device_error(device_instance_device(raw_disk), "Unimplemented active ISO9660"); } else if (block0_is_mac_disk(boot_block)) { device_error(device_instance_device(raw_disk), "Unimplemented active MAC DISK"); } else { device_error(device_instance_device(raw_disk), "Unreconized bootblock"); } } else { /* select the specified disk partition */ if (block0_is_bpb(boot_block)) { device_error(device_instance_device(raw_disk), "Unimplemented BPB"); } else if (block0_is_fdisk(boot_block)) { /* return an instance */ ppcboot_partition_t *partition_table = (ppcboot_partition_t*) &boot_block[446]; ppcboot_partition_t *partition_entry; disklabel *label; if (partition > 4) device_error(device_instance_device(raw_disk), "Only FDISK partitions 1..4 supported"); partition_entry = &partition_table[partition - 1]; label = ZALLOC(disklabel); label->raw_disk = raw_disk; label->pos = 0; label->sector_begin = 512 * sector2uw(partition_entry->sector_begin); label->sector_length = 512 * sector2uw(partition_entry->sector_length); PTRACE(disklabel, ("partition %ld, sector-begin %ld, length %ld\n", (long)partition, (long)label->sector_begin, (long)label->sector_length)); if (filename != NULL) device_error(device_instance_device(raw_disk), "FDISK file names not yet supported"); return device_create_instance_from(NULL, raw_disk, label, NULL, args, &package_disklabel_callbacks); } else if (block0_is_mac_disk(boot_block)) { device_error(device_instance_device(raw_disk), "Unimplemented MAC DISK"); } else { device_error(device_instance_device(raw_disk), "Unreconized bootblock"); } } } return NULL; }