コード例 #1
0
int has_efi_directory(PedPartition* part)
{
    int is_busy = ped_partition_is_busy(part);

    GError* error = NULL;

    char* mount_point = NULL;
    char *path = ped_partition_get_path(part);

    if (!is_busy) {
        mount_point = g_dir_make_tmp("efi_detectorXXXXXX", &error);
        if (error != NULL) {
            g_warning("[%s] create efi_detector failed :%s\n", __func__,
                      error->message);
            g_error_free(error);
            error = NULL;
        }
        char* cmd = g_strdup_printf ("mount -t vfat %s %s", path, mount_point);
        g_spawn_command_line_sync (cmd, NULL, NULL, NULL, &error);
        g_free(cmd);
        if (error != NULL) {
            g_warning("[%s] Can't detect whether is $ESP, cmd: %s, error: %s",
                      __func__, cmd, error->message);
            g_error_free(error);
            error = NULL;
            return FALSE;
        }
    }

    if (mount_point == NULL) {
        mount_point = get_partition_mount_point(path);
    }
    g_free(path);

    char* esp_path = g_build_filename(mount_point, "EFI", NULL);
    int is_esp = g_file_test (esp_path, G_FILE_TEST_IS_DIR);
    g_free(esp_path);

    if (!is_busy) {
        char* cmd = g_strdup_printf ("umount -l %s", mount_point);
        g_spawn_command_line_sync (cmd, NULL, NULL, NULL, &error);
        g_free(cmd);
        if (error != NULL) {
            g_warning("[%s] Can't detect whether is $ESP, cmd: %s, error: %s",
                      __func__, cmd, error->message);
            g_error_free(error);
            g_free(mount_point);
            return is_esp;
        }

        //don't rm the dir if umount failed.
        g_rmdir(mount_point);
        g_free(mount_point);
    }

    return is_esp;
}
コード例 #2
0
void MParted::MParted_Core::scanDevicePartitions(MParted::Device &device) {
    device.partitions.clear();

    // Initialise
    PedPartition *pedPartition = NULL;
    MParted::Partition *extendedPartition = NULL;

    while ((pedPartition = ped_disk_next_partition(pedDisk, pedPartition))) {
        //if there's no end, there's no partition ;)
        if (pedPartition->geom.end <= -1)
            continue;

        MParted::Partition partition;
        partition.devicePath = device.path;
        partition.sector_size = device.sector_size;
        partition.busy = ped_partition_is_busy(pedPartition);
        partition.partitionNumber = pedPartition->num;
        partition.sector_start = pedPartition->geom.start;
        partition.sector_end = pedPartition->geom.end;

        // Get partition path
        partition.path = Utils::charToStringFree(ped_partition_get_path(pedPartition)); // we have to free the result of ped_partition_get_path()
        if (partition.path.isEmpty())
            partition.path = "Partition path not found";


        switch (pedPartition->type) {
            case PED_PARTITION_LOGICAL:
                partition.insideExtended = true;

            case PED_PARTITION_NORMAL:
                partition.type = pedPartition->type == 0 ?	MParted::TYPE_PRIMARY : MParted::TYPE_LOGICAL;
                partition.filesystem = getFilesystem(pedPartition);

                // Find filesystem class and set used sectors, label and uuid
                for (int i = 0; i < filesystems.size(); i++) {
                    MParted::Filesystem *fs = filesystems[i];

                    if (fs->getFilesystemType() != partition.filesystem)
                        continue;

                    fs->setUsedSectors(partition);
                    fs->readLabel(partition);
                    fs->readUUID(partition);
                    break;
                }

                break ;
            case PED_PARTITION_EXTENDED:
                partition.type = MParted::TYPE_EXTENDED;
                partition.filesystem = MParted::FS_EXTENDED;

                break ;
            default:
                continue;
        }

        // Add partition to list
        if (partition.type == MParted::TYPE_LOGICAL && extendedPartition != NULL)
            extendedPartition->logicals.append(partition);
        else
            device.partitions.append(partition);

        // Save pointer of extended partition, if it is one
        if (partition.type == MParted::TYPE_EXTENDED)
            extendedPartition = &device.partitions.last();
    }

    // Update unallocated space
    UnallocatedUtils::updateUnallocated(device);
}