コード例 #1
0
ファイル: partman_devices.c プロジェクト: AOSC-Dev/calamares
static long long
process_device(PedDevice *dev)
{
    if (dev->read_only)
        return -1;
    if (is_cdrom(dev->path) || is_floppy(dev->path))
        return -1;
    /* Exclude compcache (http://code.google.com/p/compcache/) */
    if (strstr(dev->path, "/dev/ramzswap") != NULL ||
        strstr(dev->path, "/dev/zram") != NULL)
        return -1;
    return dev->length * dev->sector_size;
}
コード例 #2
0
void
process_device(PedDevice *dev)
{
	if (dev->read_only)
		return;
	if (is_cdrom(dev->path) || is_floppy(dev->path))
		return;
	/* Exclude compcache (http://code.google.com/p/compcache/) */
	if (strstr(dev->path, "/dev/ccache") != NULL)
		return;
	printf("%s\t%lli\t%s\n",
	       dev->path,
	       dev->length * PED_SECTOR_SIZE_DEFAULT,
	       dev->model);
}
コード例 #3
0
ファイル: parted_devices.c プロジェクト: 27Paolo/ubiquity
void
process_device(PedDevice *dev)
{
	if (dev->read_only)
		return;
	if (is_cdrom(dev->path) || is_floppy(dev->path))
		return;
	/* Exclude compcache (http://code.google.com/p/compcache/) */
	if (strstr(dev->path, "/dev/ramzswap") != NULL ||
	    strstr(dev->path, "/dev/zram") != NULL)
		return;
	printf("%s\t%lli\t%s\n",
	       dev->path,
	       dev->length * dev->sector_size,
	       dev->model);
}
コード例 #4
0
ファイル: CDUtils.cpp プロジェクト: gamax92/Ishiiruka
// Returns a pointer to an array of strings with the device names
std::vector<std::string> cdio_get_devices()
{
    std::vector<std::string> drives;
    // Scan the system for DVD/CD-ROM drives.
    for (unsigned int i = 0; checklist[i].format; ++i)
    {
        for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j)
        {
            std::string drive = StringFromFormat(checklist[i].format, j);
            if (is_cdrom(drive, nullptr))
            {
                drives.push_back(std::move(drive));
            }
        }
    }
    return drives;
}
コード例 #5
0
ファイル: CDUtils.cpp プロジェクト: Everscent/dolphin-emu
// Returns a pointer to an array of strings with the device names
std::vector<std::string> cdio_get_devices ()
{
	unsigned int i;
	char drive[40];
	std::vector<std::string> drives;

	// Scan the system for DVD/CD-ROM drives.
	for ( i=0; checklist[i].format; ++i )
	{
		unsigned int j;
		for ( j=checklist[i].num_min; j<=checklist[i].num_max; ++j )
		{
			sprintf(drive, checklist[i].format, j);
			if ( (is_cdrom(drive, NULL)) > 0 )
			{
				std::string str = drive;
				drives.push_back(str);
			}
		}
	}
	return drives;
}
コード例 #6
0
int
main(int argc, char *argv[])
{
  PedDevice *dev;
  char *status = "readwrite";
  char *type = "disk";
  ped_exception_fetch_all();
  ped_device_probe_all();
  for (dev = NULL; NULL != (dev = ped_device_get_next(dev));) {
    if (dev->read_only)
      status = "readonly";
    if (is_cdrom(dev->path))
      type = "cdrom";
    printf("%s\t%s\t%s\t%lli\t%s\n",
	   dev->path,
	   type,
	   status,
	   dev->length * PED_SECTOR_SIZE,
	   dev->model);
  }
  return 0;
}
コード例 #7
0
ファイル: CDUtils.cpp プロジェクト: gamax92/Ishiiruka
// Returns a vector with the device names
std::vector<std::string> cdio_get_devices()
{
    std::vector<std::string> drives;

    const DWORD buffsize = GetLogicalDriveStrings(0, nullptr);
    std::vector<TCHAR> buff(buffsize);
    if (GetLogicalDriveStrings(buffsize, buff.data()) == buffsize - 1)
    {
        auto drive = buff.data();
        while (*drive)
        {
            if (is_cdrom(drive))
            {
                std::string str(TStrToUTF8(drive));
                str.pop_back(); // we don't want the final backslash
                drives.push_back(std::move(str));
            }

            // advance to next drive
            while (*drive++) {}
        }
    }
    return drives;
}
コード例 #8
0
ファイル: CDUtils.cpp プロジェクト: Everscent/dolphin-emu
// Returns a vector with the device names
std::vector<std::string> cdio_get_devices()
{
	std::vector<std::string> drives;

	const DWORD buffsize = GetLogicalDriveStrings(0, NULL);
	std::unique_ptr<char[]> buff(new char[buffsize]);
	if (GetLogicalDriveStrings(buffsize, buff.get()) == buffsize - 1)
	{
		const char* drive = buff.get();
		while (*drive)
		{
			if (is_cdrom(drive))
			{
				std::string str(drive);
				str.pop_back();	// we don't want the final backslash
				drives.push_back(std::move(str));
			}

			// advance to next drive
			while (*drive++) {}
		}
	}
	return drives;
}
コード例 #9
0
ファイル: find-parts.c プロジェクト: Sunderland93/ubiquity
int
get_all_partitions(struct partition *parts[], const int max_parts, bool ignore_fs_type, PedPartitionFlag require_flag)
{
    struct partition *p;
    int part_count = 0;
    PedDevice *dev = NULL;
    PedDisk *disk;
    PedPartition *part;

    ped_device_probe_all();
    while ((dev = ped_device_get_next(dev)) != NULL) {
        if (dev->read_only)
            continue;
        if (strstr(dev->path, "/dev/mtd") == dev->path)
            continue;
        if (is_cdrom(dev->path))
            continue;
        if (!ped_disk_probe(dev))
            continue;
        disk = ped_disk_new(dev);

        part = NULL;
        while ((part = ped_disk_next_partition(disk, part)) != NULL) {
            if (part->type & (PED_PARTITION_METADATA | PED_PARTITION_FREESPACE | PED_PARTITION_EXTENDED))
                continue;

            if (part_count >= max_parts)
                break;

#ifndef FIND_PARTS_MAIN
            /* allow other udebs to block partitions */
            if(block_partition(ped_partition_get_path(part)) != 0)
                continue;
#endif

            if (require_flag && !ped_partition_get_flag(part, require_flag))
                continue;

            p = malloc(sizeof(*p));
            p->path = ped_partition_get_path(part);
            if (strstr(p->path, "/dev/hd") == p->path) {
                static char *targets[] = { "master", "slave" };
                char drive;
                int part;

                if (sscanf(p->path, "/dev/hd%c%d", &drive, &part) == 2
                        && drive >= 'a' && drive <= 'z')
                    p->description = xasprintf("IDE%d %s\\, part. %d",
                            (drive - 'a') / 2 + 1, targets[(drive - 'a') % 2],
                            part);
                else
                    p->description = strdup(p->path);
            } else if (strstr(p->path, "/dev/sd") == p->path) {
                char drive;
                int host, bus, target, lun, part;
                int done = 0;

                if (sscanf(p->path, "/dev/sd%c%d", &drive, &part) == 2
                        && drive >= 'a' && drive <= 'z') {
                    struct stat st;
                    char *disk, *disk_pos, *sys_device;
                    disk = strdup(p->path + 5);
                    for (disk_pos = disk + strlen(disk) - 1; disk_pos > disk;
                         --disk_pos) {
                        if (*disk_pos >= '0' && *disk_pos <= '9')
                            *disk_pos = 0;
                        else
                            break;
                    }
                    sys_device = malloc(strlen(disk) + 19);
                    sprintf(sys_device, "/sys/block/%s/device", disk);
                    /* TODO: device symlinks are allegedly slated to go
                     * away, but it's not entirely clear what their
                     * replacement will be yet ...
                     */
                    if (lstat(sys_device, &st) == 0 && S_ISLNK(st.st_mode)) {
                        char buf[512];
                        memset(buf, 0, 512);
                        if (readlink(sys_device, buf, 511) > 0) {
                            const char *bus_id = basename(buf);
                            if (sscanf(bus_id, "%d:%d:%d:%d",
                                        &host, &bus, &target, &lun) == 4) {
                                p->description = xasprintf("SCSI%d (%d\\,%d\\,%d) part. %d",
                                        host + 1, bus, target, lun, part);
                                done = 1;
                            }
                        }
                    }
                }
                if (!done)
                    p->description = strdup(p->path);
            } else
                p->description = strdup(p->path);
            p->fstype = NULL;
            p->fsid = NULL;
            p->size = 0L;
            p->op.filesystem = NULL;
            p->op.mountpoint = NULL;
            p->op.done = 0;
            test_lvm(p);
            test_evms(p);
            test_raid(p);
            /* FIXME: Other tests? */

            get_partition_info(p, part, dev, ignore_fs_type);
            parts[part_count++] = p;
        }

        if (part_count >= max_parts)
            break;
    }

    return part_count;
}
コード例 #10
0
ファイル: main.c プロジェクト: bsv798/pcsxr
// fill_drives_list: retrieves available cd drives. At the moment it use a quite
// ugly "brute force" method: we check for the most common location for cdrom
// in /dev and chech if they are cdrom devices.
// If your cdrom path is not listed here you'll have to type it in the dialog
// entry yourself (or add it here and recompile).
// Are there any other common entry to add to the list? (especially scsi, I
// deliberately ignored old non standard cdroms... )
// If you come up with a better method let me know!!
void fill_drives_list(GtkWidget *widget) {
	int i;
	GtkListStore *store;
	GtkTreeIter iter;

#if defined (__linux__)
	static const char *cdrom_devices[] = {
		"/dev/cdrom",
		"/dev/cdrom0",
		"/dev/cdrom1",
		"/dev/cdrom2",
		"/dev/cdrom3",
		"/dev/cdroms/cdrom0",
		"/dev/cdroms/cdrom1",
		"/dev/cdroms/cdrom2",
		"/dev/cdroms/cdrom3",
		"/dev/hda",
		"/dev/hdb",
		"/dev/hdc",
		"/dev/hdd",
		"/dev/sda",
		"/dev/sdb",
		"/dev/sdc",
		"/dev/sdd",
		"/dev/scd0",
		"/dev/scd1",
		"/dev/scd2",
		"/dev/scd3",
		"/dev/optcd",
		""};
#elif defined (__FreeBSD__)
	static const char *cdrom_devices[] = {
		"/dev/cd0",
		"/dev/cd1",
		"/dev/cd2",
		"/dev/cd3",
		""};
#elif defined (__sun)
	char cdrom_devices[256][256];
	FILE *fp;
	char buf[256], *devname, *nick;

	memset(cdrom_devices, 0, sizeof(cdrom_devices));

	i = 0;

	fp = popen("eject -l", "r");

	if (fp != NULL) {
		while (!feof(fp) && i < 256) {
			fgets(buf, 256, fp);

			devname = strtok(buf, " ");
			nick = strtok(NULL, " ");

			if (devname == NULL || nick == NULL) continue;

			if (strstr(nick, "cdrom") != NULL) {
				strcpy(cdrom_devices[i++], devname);
			}
		}

		pclose(fp);
	}
#else
	static const char *cdrom_devices[] = { "" };
#endif

	store = gtk_list_store_new(1, G_TYPE_STRING);

	// first we put our current drive
	if (CdromDev[0] != '\0') {
		gtk_list_store_append(store, &iter);
		gtk_list_store_set(store, &iter, 0, CdromDev, -1);
	}

	i = 0;

	// scan cdrom_devices for real cdrom and add them to list
	while (cdrom_devices[i][0] != '\0') {
		// check that is not our current dev (already in list)
		if (strcmp(cdrom_devices[i], CdromDev) != 0) {
			// check that is a cdrom device
			if (is_cdrom(cdrom_devices[i])) {
				gtk_list_store_append(store, &iter);
				gtk_list_store_set(store, &iter, 0, cdrom_devices[i], -1);
			}
		}
		++i;
	}

	gtk_combo_box_set_model(GTK_COMBO_BOX(widget), GTK_TREE_MODEL(store));
	gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(widget), 0);
}